From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45285 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFUg4-0000nb-Gv for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:34:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFUg1-0001oW-Rt for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:34:40 -0500 Received: from mail-gw0-f45.google.com ([74.125.83.45]:58004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFUg1-0001oG-P3 for qemu-devel@nongnu.org; Mon, 08 Nov 2010 11:34:37 -0500 Received: by gwj20 with SMTP id 20so3819941gwj.4 for ; Mon, 08 Nov 2010 08:34:37 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1289165136-28207-1-git-send-email-benjamin.poirier@polymtl.ca> References: <1289165136-28207-1-git-send-email-benjamin.poirier@polymtl.ca> Date: Mon, 8 Nov 2010 16:34:36 +0000 Message-ID: Subject: Re: [Qemu-devel] [PATCH 1/2] rtl8139: add vlan tag insertion From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Poirier Cc: qemu-devel@nongnu.org On Sun, Nov 7, 2010 at 9:25 PM, Benjamin Poirier wrote: > Add support to the emulated hardware to add vlan tags in packets going > from the guest to the network. > > Signed-off-by: Benjamin Poirier > Cc: Igor V. Kovalenko > --- > =A0hw/rtl8139.c | =A0 46 +++++++++++++++++++++++++++++++++++----------- > =A01 files changed, 35 insertions(+), 11 deletions(-) > > diff --git a/hw/rtl8139.c b/hw/rtl8139.c > index d92981d..ac294da 100644 > --- a/hw/rtl8139.c > +++ b/hw/rtl8139.c > @@ -47,6 +47,8 @@ > =A0* =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0D= arwin) > =A0*/ > > +#include > + > =A0#include "hw.h" > =A0#include "pci.h" > =A0#include "qemu-timer.h" > @@ -58,6 +60,10 @@ > > =A0#define PCI_FREQUENCY 33000000L > > +/* bytes in VLAN tag */ > +#define VLAN_TCI_LEN 2 > +#define VLAN_HDR_LEN (ETHER_TYPE_LEN + VLAN_TCI_LEN) > + > =A0/* debug RTL8139 card C+ mode only */ > =A0//#define DEBUG_RTL8139CP 1 > > @@ -1913,7 +1919,6 @@ static int rtl8139_cplus_transmit_one(RTL8139State = *s) > > =A0 =A0 cpu_physical_memory_read(cplus_tx_ring_desc, =A0 =A0(uint8_t *)&v= al, 4); > =A0 =A0 txdw0 =3D le32_to_cpu(val); > - =A0 =A0/* TODO: implement VLAN tagging support, VLAN tag data is read t= o txdw1 */ > =A0 =A0 cpu_physical_memory_read(cplus_tx_ring_desc+4, =A0(uint8_t *)&val= , 4); > =A0 =A0 txdw1 =3D le32_to_cpu(val); > =A0 =A0 cpu_physical_memory_read(cplus_tx_ring_desc+8, =A0(uint8_t *)&val= , 4); > @@ -1925,9 +1930,6 @@ static int rtl8139_cplus_transmit_one(RTL8139State = *s) > =A0 =A0 =A0 =A0 =A0 =A0descriptor, > =A0 =A0 =A0 =A0 =A0 =A0txdw0, txdw1, txbufLO, txbufHI)); > > - =A0 =A0/* TODO: the following discard cast should clean clang analyzer = output */ > - =A0 =A0(void)txdw1; > - > =A0/* w0 ownership flag */ > =A0#define CP_TX_OWN (1<<31) > =A0/* w0 end of ring flag */ > @@ -1951,8 +1953,8 @@ static int rtl8139_cplus_transmit_one(RTL8139State = *s) > =A0/* w0 bits 0...15 : buffer size */ > =A0#define CP_TX_BUFFER_SIZE (1<<16) > =A0#define CP_TX_BUFFER_SIZE_MASK (CP_TX_BUFFER_SIZE - 1) > -/* w1 tag available flag */ > -#define CP_RX_TAGC (1<<17) > +/* w1 add tag flag */ > +#define CP_TX_TAGC (1<<17) > =A0/* w1 bits 0...15 : VLAN tag */ > =A0#define CP_TX_VLAN_TAG_MASK ((1<<16) - 1) > =A0/* w2 low =A032bit of Rx buffer ptr */ > @@ -1978,12 +1980,22 @@ static int rtl8139_cplus_transmit_one(RTL8139Stat= e *s) > > =A0 =A0 DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : transmitting from descrip= tor %d\n", descriptor)); > > + =A0 =A0int vlan_extra_size =3D 0; > =A0 =A0 if (txdw0 & CP_TX_FS) > =A0 =A0 { > =A0 =A0 =A0 =A0 DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : descriptor %d is = first segment descriptor\n", descriptor)); > > + =A0 =A0 =A0 =A0DEBUG_PRINT(("RTL8139: +++ C+ Tx mode : add vlan tag: %u= tci: %u\n", > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0!!(txdw1 & CP_TX_TAGC), bswap16(txdw1 & > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CP_TX_VLAN_TAG_MASK))); Please use leXX_to_cpu() and cpu_to_leXX() instead of bswapXX() for little-endian conversion. This is more explicit than unconditional byteswapping and work on both big- and little-endian QEMU host architectures. Stefan