mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging
# gpg: Signature made Thu 02 Jun 2016 07:23:18 BST using RSA key ID 398D6211 # gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>" # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211 * remotes/jasowang/tags/net-pull-request: (31 commits) Add ENET device to i.MX6 SOC. Add ENET/Gbps Ethernet support to FEC device i.MX: move FEC device to a register array structure. i.MX: Rename i.MX FEC defines to ENET_XXX i.MX: reset TX/RX descriptors when FEC is disabled. i.MX: Fix FEC code for ECR register reset value. i.MX: Fix FEC code for MDIO address selection i.MX: Fix FEC code for MDIO operation selection net: handle optional VLAN header in checksum computation. net: improve UDP/TCP checksum computation. e1000e: Introduce qtest for e1000e device net: Introduce e1000e device emulation e1000: Move out code that will be reused in e1000e e1000_regs: Add definitions for Intel 82574-specific bits vmxnet3: Use pci_dma_* API instead of cpu_physical_memory_* net_pkt: Extend packet abstraction as required by e1000e functionality rtl8139: Move more TCP definitions to common header net_pkt: Name vmxnet3 packet abstractions more generic vmxnet3: Use common MAC address tracing macros net: Add macros for MAC address tracing ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
+18
@@ -954,6 +954,14 @@ S: Maintained
|
||||
F: hw/*/xilinx_*
|
||||
F: include/hw/xilinx.h
|
||||
|
||||
Network packet abstractions
|
||||
M: Dmitry Fleytman <dmitry@daynix.com>
|
||||
S: Maintained
|
||||
F: include/net/eth.h
|
||||
F: net/eth.c
|
||||
F: hw/net/net_rx_pkt*
|
||||
F: hw/net/net_tx_pkt*
|
||||
|
||||
Vmware
|
||||
M: Dmitry Fleytman <dmitry@daynix.com>
|
||||
S: Maintained
|
||||
@@ -973,6 +981,16 @@ F: hw/acpi/nvdimm.c
|
||||
F: hw/mem/nvdimm.c
|
||||
F: include/hw/mem/nvdimm.h
|
||||
|
||||
e1000x
|
||||
M: Dmitry Fleytman <dmitry@daynix.com>
|
||||
S: Maintained
|
||||
F: hw/net/e1000x*
|
||||
|
||||
e1000e
|
||||
M: Dmitry Fleytman <dmitry@daynix.com>
|
||||
S: Maintained
|
||||
F: hw/net/e1000e*
|
||||
|
||||
Subsystems
|
||||
----------
|
||||
Audio
|
||||
|
||||
@@ -18,6 +18,7 @@ CONFIG_MEGASAS_SCSI_PCI=y
|
||||
CONFIG_MPTSAS_SCSI_PCI=y
|
||||
CONFIG_RTL8139_PCI=y
|
||||
CONFIG_E1000_PCI=y
|
||||
CONFIG_E1000E_PCI=y
|
||||
CONFIG_VMXNET3_PCI=y
|
||||
CONFIG_IDE_CORE=y
|
||||
CONFIG_IDE_QDEV=y
|
||||
|
||||
@@ -191,6 +191,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
|
||||
}
|
||||
|
||||
qdev_set_nic_properties(DEVICE(&s->fec), &nd_table[0]);
|
||||
|
||||
object_property_set_bool(OBJECT(&s->fec), true, "realized", &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
|
||||
@@ -105,6 +105,10 @@ static void fsl_imx6_init(Object *obj)
|
||||
snprintf(name, NAME_SIZE, "spi%d", i + 1);
|
||||
object_property_add_child(obj, name, OBJECT(&s->spi[i]), NULL);
|
||||
}
|
||||
|
||||
object_initialize(&s->eth, sizeof(s->eth), TYPE_IMX_ENET);
|
||||
qdev_set_parent_bus(DEVICE(&s->eth), sysbus_get_default());
|
||||
object_property_add_child(obj, "eth", OBJECT(&s->eth), NULL);
|
||||
}
|
||||
|
||||
static void fsl_imx6_realize(DeviceState *dev, Error **errp)
|
||||
@@ -381,6 +385,19 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
|
||||
spi_table[i].irq));
|
||||
}
|
||||
|
||||
object_property_set_bool(OBJECT(&s->eth), true, "realized", &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
sysbus_mmio_map(SYS_BUS_DEVICE(&s->eth), 0, FSL_IMX6_ENET_ADDR);
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->eth), 0,
|
||||
qdev_get_gpio_in(DEVICE(&s->a9mpcore),
|
||||
FSL_IMX6_ENET_MAC_IRQ));
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->eth), 1,
|
||||
qdev_get_gpio_in(DEVICE(&s->a9mpcore),
|
||||
FSL_IMX6_ENET_MAC_1588_IRQ));
|
||||
|
||||
/* ROM memory */
|
||||
memory_region_init_rom_device(&s->rom, NULL, NULL, NULL, "imx6.rom",
|
||||
FSL_IMX6_ROM_SIZE, &err);
|
||||
|
||||
@@ -6,9 +6,10 @@ common-obj-$(CONFIG_NE2000_PCI) += ne2000.o
|
||||
common-obj-$(CONFIG_EEPRO100_PCI) += eepro100.o
|
||||
common-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
|
||||
common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
|
||||
common-obj-$(CONFIG_E1000_PCI) += e1000.o
|
||||
common-obj-$(CONFIG_E1000_PCI) += e1000.o e1000x_common.o
|
||||
common-obj-$(CONFIG_E1000E_PCI) += e1000e.o e1000e_core.o e1000x_common.o
|
||||
common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
|
||||
common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
|
||||
common-obj-$(CONFIG_VMXNET3_PCI) += net_tx_pkt.o net_rx_pkt.o
|
||||
common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
|
||||
|
||||
common-obj-$(CONFIG_SMC91C111) += smc91c111.o
|
||||
|
||||
+95
-322
File diff suppressed because it is too large
Load Diff
+346
-3
File diff suppressed because it is too large
Load Diff
+739
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Core code for QEMU e1000e emulation
|
||||
*
|
||||
* Software developer's manuals:
|
||||
* http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf
|
||||
*
|
||||
* Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
|
||||
* Developed by Daynix Computing LTD (http://www.daynix.com)
|
||||
*
|
||||
* Authors:
|
||||
* Dmitry Fleytman <dmitry@daynix.com>
|
||||
* Leonid Bloch <leonid@daynix.com>
|
||||
* Yan Vugenfirer <yan@daynix.com>
|
||||
*
|
||||
* Based on work done by:
|
||||
* Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
|
||||
* Copyright (c) 2008 Qumranet
|
||||
* Based on work done by:
|
||||
* Copyright (c) 2007 Dan Aloni
|
||||
* Copyright (c) 2004 Antony T Curtis
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define E1000E_PHY_PAGE_SIZE (0x20)
|
||||
#define E1000E_PHY_PAGES (0x07)
|
||||
#define E1000E_MAC_SIZE (0x8000)
|
||||
#define E1000E_EEPROM_SIZE (64)
|
||||
#define E1000E_MSIX_VEC_NUM (5)
|
||||
#define E1000E_NUM_QUEUES (2)
|
||||
|
||||
typedef struct E1000Core E1000ECore;
|
||||
|
||||
enum { PHY_R = BIT(0),
|
||||
PHY_W = BIT(1),
|
||||
PHY_RW = PHY_R | PHY_W,
|
||||
PHY_ANYPAGE = BIT(2) };
|
||||
|
||||
typedef struct E1000IntrDelayTimer_st {
|
||||
QEMUTimer *timer;
|
||||
bool running;
|
||||
uint32_t delay_reg;
|
||||
uint32_t delay_resolution_ns;
|
||||
E1000ECore *core;
|
||||
} E1000IntrDelayTimer;
|
||||
|
||||
struct E1000Core {
|
||||
uint32_t mac[E1000E_MAC_SIZE];
|
||||
uint16_t phy[E1000E_PHY_PAGES][E1000E_PHY_PAGE_SIZE];
|
||||
uint16_t eeprom[E1000E_EEPROM_SIZE];
|
||||
|
||||
uint32_t rxbuf_sizes[E1000_PSRCTL_BUFFS_PER_DESC];
|
||||
uint32_t rx_desc_buf_size;
|
||||
uint32_t rxbuf_min_shift;
|
||||
uint8_t rx_desc_len;
|
||||
|
||||
QEMUTimer *autoneg_timer;
|
||||
|
||||
struct e1000e_tx {
|
||||
e1000x_txd_props props;
|
||||
|
||||
bool skip_cp;
|
||||
struct NetTxPkt *tx_pkt;
|
||||
} tx[E1000E_NUM_QUEUES];
|
||||
|
||||
struct NetRxPkt *rx_pkt;
|
||||
|
||||
bool has_vnet;
|
||||
int max_queue_num;
|
||||
|
||||
/* Interrupt moderation management */
|
||||
uint32_t delayed_causes;
|
||||
|
||||
E1000IntrDelayTimer radv;
|
||||
E1000IntrDelayTimer rdtr;
|
||||
E1000IntrDelayTimer raid;
|
||||
|
||||
E1000IntrDelayTimer tadv;
|
||||
E1000IntrDelayTimer tidv;
|
||||
|
||||
E1000IntrDelayTimer itr;
|
||||
bool itr_intr_pending;
|
||||
|
||||
E1000IntrDelayTimer eitr[E1000E_MSIX_VEC_NUM];
|
||||
bool eitr_intr_pending[E1000E_MSIX_VEC_NUM];
|
||||
|
||||
VMChangeStateEntry *vmstate;
|
||||
|
||||
uint32_t itr_guest_value;
|
||||
uint32_t eitr_guest_value[E1000E_MSIX_VEC_NUM];
|
||||
|
||||
uint16_t vet;
|
||||
|
||||
uint8_t permanent_mac[ETH_ALEN];
|
||||
|
||||
NICState *owner_nic;
|
||||
PCIDevice *owner;
|
||||
void (*owner_start_recv)(PCIDevice *d);
|
||||
};
|
||||
|
||||
void
|
||||
e1000e_core_write(E1000ECore *core, hwaddr addr, uint64_t val, unsigned size);
|
||||
|
||||
uint64_t
|
||||
e1000e_core_read(E1000ECore *core, hwaddr addr, unsigned size);
|
||||
|
||||
void
|
||||
e1000e_core_pci_realize(E1000ECore *regs,
|
||||
const uint16_t *eeprom_templ,
|
||||
uint32_t eeprom_size,
|
||||
const uint8_t *macaddr);
|
||||
|
||||
void
|
||||
e1000e_core_reset(E1000ECore *core);
|
||||
|
||||
void
|
||||
e1000e_core_pre_save(E1000ECore *core);
|
||||
|
||||
int
|
||||
e1000e_core_post_load(E1000ECore *core);
|
||||
|
||||
void
|
||||
e1000e_core_set_link_status(E1000ECore *core);
|
||||
|
||||
void
|
||||
e1000e_core_pci_uninit(E1000ECore *core);
|
||||
|
||||
int
|
||||
e1000e_can_receive(E1000ECore *core);
|
||||
|
||||
ssize_t
|
||||
e1000e_receive(E1000ECore *core, const uint8_t *buf, size_t size);
|
||||
|
||||
ssize_t
|
||||
e1000e_receive_iov(E1000ECore *core, const struct iovec *iov, int iovcnt);
|
||||
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* QEMU e1000(e) emulation - shared code
|
||||
*
|
||||
* Copyright (c) 2008 Qumranet
|
||||
*
|
||||
* Based on work done by:
|
||||
* Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
|
||||
* Copyright (c) 2007 Dan Aloni
|
||||
* Copyright (c) 2004 Antony T Curtis
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "net/net.h"
|
||||
|
||||
#include "e1000x_common.h"
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
bool e1000x_rx_ready(PCIDevice *d, uint32_t *mac)
|
||||
{
|
||||
bool link_up = mac[STATUS] & E1000_STATUS_LU;
|
||||
bool rx_enabled = mac[RCTL] & E1000_RCTL_EN;
|
||||
bool pci_master = d->config[PCI_COMMAND] & PCI_COMMAND_MASTER;
|
||||
|
||||
if (!link_up || !rx_enabled || !pci_master) {
|
||||
trace_e1000x_rx_can_recv_disabled(link_up, rx_enabled, pci_master);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool e1000x_is_vlan_packet(const uint8_t *buf, uint16_t vet)
|
||||
{
|
||||
uint16_t eth_proto = be16_to_cpup((uint16_t *)(buf + 12));
|
||||
bool res = (eth_proto == vet);
|
||||
|
||||
trace_e1000x_vlan_is_vlan_pkt(res, eth_proto, vet);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool e1000x_rx_group_filter(uint32_t *mac, const uint8_t *buf)
|
||||
{
|
||||
static const int mta_shift[] = { 4, 3, 2, 0 };
|
||||
uint32_t f, ra[2], *rp, rctl = mac[RCTL];
|
||||
|
||||
for (rp = mac + RA; rp < mac + RA + 32; rp += 2) {
|
||||
if (!(rp[1] & E1000_RAH_AV)) {
|
||||
continue;
|
||||
}
|
||||
ra[0] = cpu_to_le32(rp[0]);
|
||||
ra[1] = cpu_to_le32(rp[1]);
|
||||
if (!memcmp(buf, (uint8_t *)ra, 6)) {
|
||||
trace_e1000x_rx_flt_ucast_match((int)(rp - mac - RA) / 2,
|
||||
MAC_ARG(buf));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
trace_e1000x_rx_flt_ucast_mismatch(MAC_ARG(buf));
|
||||
|
||||
f = mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3];
|
||||
f = (((buf[5] << 8) | buf[4]) >> f) & 0xfff;
|
||||
if (mac[MTA + (f >> 5)] & (1 << (f & 0x1f))) {
|
||||
e1000x_inc_reg_if_not_full(mac, MPRC);
|
||||
return true;
|
||||
}
|
||||
|
||||
trace_e1000x_rx_flt_inexact_mismatch(MAC_ARG(buf),
|
||||
(rctl >> E1000_RCTL_MO_SHIFT) & 3,
|
||||
f >> 5,
|
||||
mac[MTA + (f >> 5)]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool e1000x_hw_rx_enabled(uint32_t *mac)
|
||||
{
|
||||
if (!(mac[STATUS] & E1000_STATUS_LU)) {
|
||||
trace_e1000x_rx_link_down(mac[STATUS]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(mac[RCTL] & E1000_RCTL_EN)) {
|
||||
trace_e1000x_rx_disabled(mac[RCTL]);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool e1000x_is_oversized(uint32_t *mac, size_t size)
|
||||
{
|
||||
/* this is the size past which hardware will
|
||||
drop packets when setting LPE=0 */
|
||||
static const int maximum_ethernet_vlan_size = 1522;
|
||||
/* this is the size past which hardware will
|
||||
drop packets when setting LPE=1 */
|
||||
static const int maximum_ethernet_lpe_size = 16384;
|
||||
|
||||
if ((size > maximum_ethernet_lpe_size ||
|
||||
(size > maximum_ethernet_vlan_size
|
||||
&& !(mac[RCTL] & E1000_RCTL_LPE)))
|
||||
&& !(mac[RCTL] & E1000_RCTL_SBP)) {
|
||||
e1000x_inc_reg_if_not_full(mac, ROC);
|
||||
trace_e1000x_rx_oversized(size);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void e1000x_restart_autoneg(uint32_t *mac, uint16_t *phy, QEMUTimer *timer)
|
||||
{
|
||||
e1000x_update_regs_on_link_down(mac, phy);
|
||||
trace_e1000x_link_negotiation_start();
|
||||
timer_mod(timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
|
||||
}
|
||||
|
||||
void e1000x_reset_mac_addr(NICState *nic, uint32_t *mac_regs,
|
||||
uint8_t *mac_addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
mac_regs[RA] = 0;
|
||||
mac_regs[RA + 1] = E1000_RAH_AV;
|
||||
for (i = 0; i < 4; i++) {
|
||||
mac_regs[RA] |= mac_addr[i] << (8 * i);
|
||||
mac_regs[RA + 1] |=
|
||||
(i < 2) ? mac_addr[i + 4] << (8 * i) : 0;
|
||||
}
|
||||
|
||||
qemu_format_nic_info_str(qemu_get_queue(nic), mac_addr);
|
||||
trace_e1000x_mac_indicate(MAC_ARG(mac_addr));
|
||||
}
|
||||
|
||||
void e1000x_update_regs_on_autoneg_done(uint32_t *mac, uint16_t *phy)
|
||||
{
|
||||
e1000x_update_regs_on_link_up(mac, phy);
|
||||
phy[PHY_LP_ABILITY] |= MII_LPAR_LPACK;
|
||||
phy[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE;
|
||||
trace_e1000x_link_negotiation_done();
|
||||
}
|
||||
|
||||
void
|
||||
e1000x_core_prepare_eeprom(uint16_t *eeprom,
|
||||
const uint16_t *templ,
|
||||
uint32_t templ_size,
|
||||
uint16_t dev_id,
|
||||
const uint8_t *macaddr)
|
||||
{
|
||||
uint16_t checksum = 0;
|
||||
int i;
|
||||
|
||||
memmove(eeprom, templ, templ_size);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
eeprom[i] = (macaddr[2 * i + 1] << 8) | macaddr[2 * i];
|
||||
}
|
||||
|
||||
eeprom[11] = eeprom[13] = dev_id;
|
||||
|
||||
for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
|
||||
checksum += eeprom[i];
|
||||
}
|
||||
|
||||
checksum = (uint16_t) EEPROM_SUM - checksum;
|
||||
|
||||
eeprom[EEPROM_CHECKSUM_REG] = checksum;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
e1000x_rxbufsize(uint32_t rctl)
|
||||
{
|
||||
rctl &= E1000_RCTL_BSEX | E1000_RCTL_SZ_16384 | E1000_RCTL_SZ_8192 |
|
||||
E1000_RCTL_SZ_4096 | E1000_RCTL_SZ_2048 | E1000_RCTL_SZ_1024 |
|
||||
E1000_RCTL_SZ_512 | E1000_RCTL_SZ_256;
|
||||
switch (rctl) {
|
||||
case E1000_RCTL_BSEX | E1000_RCTL_SZ_16384:
|
||||
return 16384;
|
||||
case E1000_RCTL_BSEX | E1000_RCTL_SZ_8192:
|
||||
return 8192;
|
||||
case E1000_RCTL_BSEX | E1000_RCTL_SZ_4096:
|
||||
return 4096;
|
||||
case E1000_RCTL_SZ_1024:
|
||||
return 1024;
|
||||
case E1000_RCTL_SZ_512:
|
||||
return 512;
|
||||
case E1000_RCTL_SZ_256:
|
||||
return 256;
|
||||
}
|
||||
return 2048;
|
||||
}
|
||||
|
||||
void
|
||||
e1000x_update_rx_total_stats(uint32_t *mac,
|
||||
size_t data_size,
|
||||
size_t data_fcs_size)
|
||||
{
|
||||
static const int PRCregs[6] = { PRC64, PRC127, PRC255, PRC511,
|
||||
PRC1023, PRC1522 };
|
||||
|
||||
e1000x_increase_size_stats(mac, PRCregs, data_fcs_size);
|
||||
e1000x_inc_reg_if_not_full(mac, TPR);
|
||||
mac[GPRC] = mac[TPR];
|
||||
/* TOR - Total Octets Received:
|
||||
* This register includes bytes received in a packet from the <Destination
|
||||
* Address> field through the <CRC> field, inclusively.
|
||||
* Always include FCS length (4) in size.
|
||||
*/
|
||||
e1000x_grow_8reg_if_not_full(mac, TORL, data_size + 4);
|
||||
mac[GORCL] = mac[TORL];
|
||||
mac[GORCH] = mac[TORH];
|
||||
}
|
||||
|
||||
void
|
||||
e1000x_increase_size_stats(uint32_t *mac, const int *size_regs, int size)
|
||||
{
|
||||
if (size > 1023) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[5]);
|
||||
} else if (size > 511) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[4]);
|
||||
} else if (size > 255) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[3]);
|
||||
} else if (size > 127) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[2]);
|
||||
} else if (size > 64) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[1]);
|
||||
} else if (size == 64) {
|
||||
e1000x_inc_reg_if_not_full(mac, size_regs[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
e1000x_read_tx_ctx_descr(struct e1000_context_desc *d,
|
||||
e1000x_txd_props *props)
|
||||
{
|
||||
uint32_t op = le32_to_cpu(d->cmd_and_length);
|
||||
|
||||
props->ipcss = d->lower_setup.ip_fields.ipcss;
|
||||
props->ipcso = d->lower_setup.ip_fields.ipcso;
|
||||
props->ipcse = le16_to_cpu(d->lower_setup.ip_fields.ipcse);
|
||||
props->tucss = d->upper_setup.tcp_fields.tucss;
|
||||
props->tucso = d->upper_setup.tcp_fields.tucso;
|
||||
props->tucse = le16_to_cpu(d->upper_setup.tcp_fields.tucse);
|
||||
props->paylen = op & 0xfffff;
|
||||
props->hdr_len = d->tcp_seg_setup.fields.hdr_len;
|
||||
props->mss = le16_to_cpu(d->tcp_seg_setup.fields.mss);
|
||||
props->ip = (op & E1000_TXD_CMD_IP) ? 1 : 0;
|
||||
props->tcp = (op & E1000_TXD_CMD_TCP) ? 1 : 0;
|
||||
props->tse = (op & E1000_TXD_CMD_TSE) ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* QEMU e1000(e) emulation - shared code
|
||||
*
|
||||
* Copyright (c) 2008 Qumranet
|
||||
*
|
||||
* Based on work done by:
|
||||
* Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
|
||||
* Copyright (c) 2007 Dan Aloni
|
||||
* Copyright (c) 2004 Antony T Curtis
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "e1000_regs.h"
|
||||
|
||||
#define defreg(x) x = (E1000_##x >> 2)
|
||||
enum {
|
||||
defreg(CTRL), defreg(EECD), defreg(EERD), defreg(GPRC),
|
||||
defreg(GPTC), defreg(ICR), defreg(ICS), defreg(IMC),
|
||||
defreg(IMS), defreg(LEDCTL), defreg(MANC), defreg(MDIC),
|
||||
defreg(MPC), defreg(PBA), defreg(RCTL), defreg(RDBAH0),
|
||||
defreg(RDBAL0), defreg(RDH0), defreg(RDLEN0), defreg(RDT0),
|
||||
defreg(STATUS), defreg(SWSM), defreg(TCTL), defreg(TDBAH),
|
||||
defreg(TDBAL), defreg(TDH), defreg(TDLEN), defreg(TDT),
|
||||
defreg(TDLEN1), defreg(TDBAL1), defreg(TDBAH1), defreg(TDH1),
|
||||
defreg(TDT1), defreg(TORH), defreg(TORL), defreg(TOTH),
|
||||
defreg(TOTL), defreg(TPR), defreg(TPT), defreg(TXDCTL),
|
||||
defreg(WUFC), defreg(RA), defreg(MTA), defreg(CRCERRS),
|
||||
defreg(VFTA), defreg(VET), defreg(RDTR), defreg(RADV),
|
||||
defreg(TADV), defreg(ITR), defreg(SCC), defreg(ECOL),
|
||||
defreg(MCC), defreg(LATECOL), defreg(COLC), defreg(DC),
|
||||
defreg(TNCRS), defreg(SEC), defreg(CEXTERR), defreg(RLEC),
|
||||
defreg(XONRXC), defreg(XONTXC), defreg(XOFFRXC), defreg(XOFFTXC),
|
||||
defreg(FCRUC), defreg(AIT), defreg(TDFH), defreg(TDFT),
|
||||
defreg(TDFHS), defreg(TDFTS), defreg(TDFPC), defreg(WUC),
|
||||
defreg(WUS), defreg(POEMB), defreg(PBS), defreg(RDFH),
|
||||
defreg(RDFT), defreg(RDFHS), defreg(RDFTS), defreg(RDFPC),
|
||||
defreg(PBM), defreg(IPAV), defreg(IP4AT), defreg(IP6AT),
|
||||
defreg(WUPM), defreg(FFLT), defreg(FFMT), defreg(FFVT),
|
||||
defreg(TARC0), defreg(TARC1), defreg(IAM), defreg(EXTCNF_CTRL),
|
||||
defreg(GCR), defreg(TIMINCA), defreg(EIAC), defreg(CTRL_EXT),
|
||||
defreg(IVAR), defreg(MFUTP01), defreg(MFUTP23), defreg(MANC2H),
|
||||
defreg(MFVAL), defreg(MDEF), defreg(FACTPS), defreg(FTFT),
|
||||
defreg(RUC), defreg(ROC), defreg(RFC), defreg(RJC),
|
||||
defreg(PRC64), defreg(PRC127), defreg(PRC255), defreg(PRC511),
|
||||
defreg(PRC1023), defreg(PRC1522), defreg(PTC64), defreg(PTC127),
|
||||
defreg(PTC255), defreg(PTC511), defreg(PTC1023), defreg(PTC1522),
|
||||
defreg(GORCL), defreg(GORCH), defreg(GOTCL), defreg(GOTCH),
|
||||
defreg(RNBC), defreg(BPRC), defreg(MPRC), defreg(RFCTL),
|
||||
defreg(PSRCTL), defreg(MPTC), defreg(BPTC), defreg(TSCTFC),
|
||||
defreg(IAC), defreg(MGTPRC), defreg(MGTPDC), defreg(MGTPTC),
|
||||
defreg(TSCTC), defreg(RXCSUM), defreg(FUNCTAG), defreg(GSCL_1),
|
||||
defreg(GSCL_2), defreg(GSCL_3), defreg(GSCL_4), defreg(GSCN_0),
|
||||
defreg(GSCN_1), defreg(GSCN_2), defreg(GSCN_3), defreg(GCR2),
|
||||
defreg(RAID), defreg(RSRPD), defreg(TIDV), defreg(EITR),
|
||||
defreg(MRQC), defreg(RETA), defreg(RSSRK), defreg(RDBAH1),
|
||||
defreg(RDBAL1), defreg(RDLEN1), defreg(RDH1), defreg(RDT1),
|
||||
defreg(PBACLR), defreg(FCAL), defreg(FCAH), defreg(FCT),
|
||||
defreg(FCRTH), defreg(FCRTL), defreg(FCTTV), defreg(FCRTV),
|
||||
defreg(FLA), defreg(EEWR), defreg(FLOP), defreg(FLOL),
|
||||
defreg(FLSWCTL), defreg(FLSWCNT), defreg(RXDCTL), defreg(RXDCTL1),
|
||||
defreg(MAVTV0), defreg(MAVTV1), defreg(MAVTV2), defreg(MAVTV3),
|
||||
defreg(TXSTMPL), defreg(TXSTMPH), defreg(SYSTIML), defreg(SYSTIMH),
|
||||
defreg(RXCFGL), defreg(RXUDP), defreg(TIMADJL), defreg(TIMADJH),
|
||||
defreg(RXSTMPH), defreg(RXSTMPL), defreg(RXSATRL), defreg(RXSATRH),
|
||||
defreg(FLASHT), defreg(TIPG), defreg(RDH), defreg(RDT),
|
||||
defreg(RDLEN), defreg(RDBAH), defreg(RDBAL),
|
||||
defreg(TXDCTL1),
|
||||
defreg(FLSWDATA),
|
||||
defreg(CTRL_DUP),
|
||||
defreg(EXTCNF_SIZE),
|
||||
defreg(EEMNGCTL),
|
||||
defreg(EEMNGDATA),
|
||||
defreg(FLMNGCTL),
|
||||
defreg(FLMNGDATA),
|
||||
defreg(FLMNGCNT),
|
||||
defreg(TSYNCRXCTL),
|
||||
defreg(TSYNCTXCTL),
|
||||
|
||||
/* Aliases */
|
||||
defreg(RDH0_A), defreg(RDT0_A), defreg(RDTR_A), defreg(RDFH_A),
|
||||
defreg(RDFT_A), defreg(TDH_A), defreg(TDT_A), defreg(TIDV_A),
|
||||
defreg(TDFH_A), defreg(TDFT_A), defreg(RA_A), defreg(RDBAL0_A),
|
||||
defreg(TDBAL_A), defreg(TDLEN_A), defreg(VFTA_A), defreg(RDLEN0_A),
|
||||
defreg(FCRTL_A), defreg(FCRTH_A)
|
||||
};
|
||||
|
||||
static inline void
|
||||
e1000x_inc_reg_if_not_full(uint32_t *mac, int index)
|
||||
{
|
||||
if (mac[index] != 0xffffffff) {
|
||||
mac[index]++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
e1000x_grow_8reg_if_not_full(uint32_t *mac, int index, int size)
|
||||
{
|
||||
uint64_t sum = mac[index] | (uint64_t)mac[index + 1] << 32;
|
||||
|
||||
if (sum + size < sum) {
|
||||
sum = ~0ULL;
|
||||
} else {
|
||||
sum += size;
|
||||
}
|
||||
mac[index] = sum;
|
||||
mac[index + 1] = sum >> 32;
|
||||
}
|
||||
|
||||
static inline int
|
||||
e1000x_vlan_enabled(uint32_t *mac)
|
||||
{
|
||||
return ((mac[CTRL] & E1000_CTRL_VME) != 0);
|
||||
}
|
||||
|
||||
static inline int
|
||||
e1000x_is_vlan_txd(uint32_t txd_lower)
|
||||
{
|
||||
return ((txd_lower & E1000_TXD_CMD_VLE) != 0);
|
||||
}
|
||||
|
||||
static inline int
|
||||
e1000x_vlan_rx_filter_enabled(uint32_t *mac)
|
||||
{
|
||||
return ((mac[RCTL] & E1000_RCTL_VFE) != 0);
|
||||
}
|
||||
|
||||
static inline int
|
||||
e1000x_fcs_len(uint32_t *mac)
|
||||
{
|
||||
/* FCS aka Ethernet CRC-32. We don't get it from backends and can't
|
||||
* fill it in, just pad descriptor length by 4 bytes unless guest
|
||||
* told us to strip it off the packet. */
|
||||
return (mac[RCTL] & E1000_RCTL_SECRC) ? 0 : 4;
|
||||
}
|
||||
|
||||
static inline void
|
||||
e1000x_update_regs_on_link_down(uint32_t *mac, uint16_t *phy)
|
||||
{
|
||||
mac[STATUS] &= ~E1000_STATUS_LU;
|
||||
phy[PHY_STATUS] &= ~MII_SR_LINK_STATUS;
|
||||
phy[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE;
|
||||
phy[PHY_LP_ABILITY] &= ~MII_LPAR_LPACK;
|
||||
}
|
||||
|
||||
static inline void
|
||||
e1000x_update_regs_on_link_up(uint32_t *mac, uint16_t *phy)
|
||||
{
|
||||
mac[STATUS] |= E1000_STATUS_LU;
|
||||
phy[PHY_STATUS] |= MII_SR_LINK_STATUS;
|
||||
}
|
||||
|
||||
void e1000x_update_rx_total_stats(uint32_t *mac,
|
||||
size_t data_size,
|
||||
size_t data_fcs_size);
|
||||
|
||||
void e1000x_core_prepare_eeprom(uint16_t *eeprom,
|
||||
const uint16_t *templ,
|
||||
uint32_t templ_size,
|
||||
uint16_t dev_id,
|
||||
const uint8_t *macaddr);
|
||||
|
||||
uint32_t e1000x_rxbufsize(uint32_t rctl);
|
||||
|
||||
bool e1000x_rx_ready(PCIDevice *d, uint32_t *mac);
|
||||
|
||||
bool e1000x_is_vlan_packet(const uint8_t *buf, uint16_t vet);
|
||||
|
||||
bool e1000x_rx_group_filter(uint32_t *mac, const uint8_t *buf);
|
||||
|
||||
bool e1000x_hw_rx_enabled(uint32_t *mac);
|
||||
|
||||
bool e1000x_is_oversized(uint32_t *mac, size_t size);
|
||||
|
||||
void e1000x_restart_autoneg(uint32_t *mac, uint16_t *phy, QEMUTimer *timer);
|
||||
|
||||
void e1000x_reset_mac_addr(NICState *nic, uint32_t *mac_regs,
|
||||
uint8_t *mac_addr);
|
||||
|
||||
void e1000x_update_regs_on_autoneg_done(uint32_t *mac, uint16_t *phy);
|
||||
|
||||
void e1000x_increase_size_stats(uint32_t *mac, const int *size_regs, int size);
|
||||
|
||||
typedef struct e1000x_txd_props {
|
||||
unsigned char sum_needed;
|
||||
uint8_t ipcss;
|
||||
uint8_t ipcso;
|
||||
uint16_t ipcse;
|
||||
uint8_t tucss;
|
||||
uint8_t tucso;
|
||||
uint16_t tucse;
|
||||
uint32_t paylen;
|
||||
uint8_t hdr_len;
|
||||
uint16_t mss;
|
||||
int8_t ip;
|
||||
int8_t tcp;
|
||||
bool tse;
|
||||
bool cptse;
|
||||
} e1000x_txd_props;
|
||||
|
||||
void e1000x_read_tx_ctx_descr(struct e1000_context_desc *d,
|
||||
e1000x_txd_props *props);
|
||||
+772
-253
File diff suppressed because it is too large
Load Diff
@@ -83,6 +83,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
|
||||
if (!mipsnet_can_receive(nc))
|
||||
return 0;
|
||||
|
||||
if (size >= sizeof(s->rx_buffer)) {
|
||||
return 0;
|
||||
}
|
||||
s->busy = 1;
|
||||
|
||||
/* Just accept everything. */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* QEMU RX packets abstraction
|
||||
*
|
||||
* Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
|
||||
*
|
||||
* Developed by Daynix Computing LTD (http://www.daynix.com)
|
||||
*
|
||||
* Authors:
|
||||
* Dmitry Fleytman <dmitry@daynix.com>
|
||||
* Tamir Shomer <tamirs@daynix.com>
|
||||
* Yan Vugenfirer <yan@daynix.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NET_RX_PKT_H
|
||||
#define NET_RX_PKT_H
|
||||
|
||||
#include "net/eth.h"
|
||||
|
||||
/* defines to enable packet dump functions */
|
||||
/*#define NET_RX_PKT_DEBUG*/
|
||||
|
||||
struct NetRxPkt;
|
||||
|
||||
/**
|
||||
* Clean all rx packet resources
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_uninit(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* Init function for rx packet functionality
|
||||
*
|
||||
* @pkt: packet pointer
|
||||
* @has_virt_hdr: device uses virtio header
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_init(struct NetRxPkt **pkt, bool has_virt_hdr);
|
||||
|
||||
/**
|
||||
* returns total length of data attached to rx context
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
* Return: nothing
|
||||
*
|
||||
*/
|
||||
size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* parse and set packet analysis results
|
||||
*
|
||||
* @pkt: packet
|
||||
* @data: pointer to the data buffer to be parsed
|
||||
* @len: data length
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, const void *data,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* fetches packet analysis results
|
||||
*
|
||||
* @pkt: packet
|
||||
* @isip4: whether the packet given is IPv4
|
||||
* @isip6: whether the packet given is IPv6
|
||||
* @isudp: whether the packet given is UDP
|
||||
* @istcp: whether the packet given is TCP
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_get_protocols(struct NetRxPkt *pkt,
|
||||
bool *isip4, bool *isip6,
|
||||
bool *isudp, bool *istcp);
|
||||
|
||||
/**
|
||||
* fetches L3 header offset
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
size_t net_rx_pkt_get_l3_hdr_offset(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* fetches L4 header offset
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* fetches L5 header offset
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* fetches IP6 header analysis results
|
||||
*
|
||||
* Return: pointer to analysis results structure which is stored in internal
|
||||
* packet area.
|
||||
*
|
||||
*/
|
||||
eth_ip6_hdr_info *net_rx_pkt_get_ip6_info(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* fetches IP4 header analysis results
|
||||
*
|
||||
* Return: pointer to analysis results structure which is stored in internal
|
||||
* packet area.
|
||||
*
|
||||
*/
|
||||
eth_ip4_hdr_info *net_rx_pkt_get_ip4_info(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* fetches L4 header analysis results
|
||||
*
|
||||
* Return: pointer to analysis results structure which is stored in internal
|
||||
* packet area.
|
||||
*
|
||||
*/
|
||||
eth_l4_hdr_info *net_rx_pkt_get_l4_info(struct NetRxPkt *pkt);
|
||||
|
||||
typedef enum {
|
||||
NetPktRssIpV4,
|
||||
NetPktRssIpV4Tcp,
|
||||
NetPktRssIpV6Tcp,
|
||||
NetPktRssIpV6,
|
||||
NetPktRssIpV6Ex
|
||||
} NetRxPktRssType;
|
||||
|
||||
/**
|
||||
* calculates RSS hash for packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @type: RSS hash type
|
||||
*
|
||||
* Return: Toeplitz RSS hash.
|
||||
*
|
||||
*/
|
||||
uint32_t
|
||||
net_rx_pkt_calc_rss_hash(struct NetRxPkt *pkt,
|
||||
NetRxPktRssType type,
|
||||
uint8_t *key);
|
||||
|
||||
/**
|
||||
* fetches IP identification for the packet
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* check if given packet is a TCP ACK packet
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_is_tcp_ack(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* check if given packet contains TCP data
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_has_tcp_data(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* returns virtio header stored in rx context
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: virtio header
|
||||
*
|
||||
*/
|
||||
struct virtio_net_hdr *net_rx_pkt_get_vhdr(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* returns packet type
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: packet type
|
||||
*
|
||||
*/
|
||||
eth_pkt_types_e net_rx_pkt_get_packet_type(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* returns vlan tag
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: VLAN tag
|
||||
*
|
||||
*/
|
||||
uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* tells whether vlan was stripped from the packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: VLAN stripped sign
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* notifies caller if the packet has virtio header
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: true if packet has virtio header, false otherwize
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* attach scatter-gather data to rx packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @iov: received data scatter-gather list
|
||||
* @iovcnt number of elements in iov
|
||||
* @iovoff data start offset in the iov
|
||||
* @strip_vlan: should the module strip vlan from data
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt,
|
||||
const struct iovec *iov,
|
||||
int iovcnt, size_t iovoff,
|
||||
bool strip_vlan);
|
||||
|
||||
/**
|
||||
* attach scatter-gather data to rx packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @iov: received data scatter-gather list
|
||||
* @iovcnt number of elements in iov
|
||||
* @iovoff data start offset in the iov
|
||||
* @strip_vlan: should the module strip vlan from data
|
||||
* @vet: VLAN tag Ethernet type
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt,
|
||||
const struct iovec *iov, int iovcnt,
|
||||
size_t iovoff, bool strip_vlan,
|
||||
uint16_t vet);
|
||||
|
||||
/**
|
||||
* attach data to rx packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @data: pointer to the data buffer
|
||||
* @len: data length
|
||||
* @strip_vlan: should the module strip vlan from data
|
||||
*
|
||||
*/
|
||||
static inline void
|
||||
net_rx_pkt_attach_data(struct NetRxPkt *pkt, const void *data,
|
||||
size_t len, bool strip_vlan)
|
||||
{
|
||||
const struct iovec iov = {
|
||||
.iov_base = (void *) data,
|
||||
.iov_len = len
|
||||
};
|
||||
|
||||
net_rx_pkt_attach_iovec(pkt, &iov, 1, 0, strip_vlan);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns io vector that holds the attached data
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: pointer to IOVec
|
||||
*
|
||||
*/
|
||||
struct iovec *net_rx_pkt_get_iovec(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* returns io vector length that holds the attached data
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: IOVec length
|
||||
*
|
||||
*/
|
||||
uint16_t net_rx_pkt_get_iovec_len(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* prints rx packet data if debug is enabled
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_dump(struct NetRxPkt *pkt);
|
||||
|
||||
/**
|
||||
* copy passed vhdr data to packet context
|
||||
*
|
||||
* @pkt: packet
|
||||
* @vhdr: VHDR buffer
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt,
|
||||
struct virtio_net_hdr *vhdr);
|
||||
|
||||
/**
|
||||
* copy passed vhdr data to packet context
|
||||
*
|
||||
* @pkt: packet
|
||||
* @iov: VHDR iov
|
||||
* @iovcnt: VHDR iov array size
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt *pkt,
|
||||
const struct iovec *iov, int iovcnt);
|
||||
|
||||
/**
|
||||
* save packet type in packet context
|
||||
*
|
||||
* @pkt: packet
|
||||
* @packet_type: the packet type
|
||||
*
|
||||
*/
|
||||
void net_rx_pkt_set_packet_type(struct NetRxPkt *pkt,
|
||||
eth_pkt_types_e packet_type);
|
||||
|
||||
/**
|
||||
* validate TCP/UDP checksum of the packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @csum_valid: checksum validation result
|
||||
* @ret: true if validation was performed, false in case packet is
|
||||
* not TCP/UDP or checksum validation is not possible
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid);
|
||||
|
||||
/**
|
||||
* validate IPv4 checksum of the packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @csum_valid: checksum validation result
|
||||
* @ret: true if validation was performed, false in case packet is
|
||||
* not TCP/UDP or checksum validation is not possible
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_validate_l3_csum(struct NetRxPkt *pkt, bool *csum_valid);
|
||||
|
||||
/**
|
||||
* fix IPv4 checksum of the packet
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: true if checksum was fixed, false in case packet is
|
||||
* not TCP/UDP or checksum correction is not possible
|
||||
*
|
||||
*/
|
||||
bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* QEMU TX packets abstraction
|
||||
*
|
||||
* Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
|
||||
*
|
||||
* Developed by Daynix Computing LTD (http://www.daynix.com)
|
||||
*
|
||||
* Authors:
|
||||
* Dmitry Fleytman <dmitry@daynix.com>
|
||||
* Tamir Shomer <tamirs@daynix.com>
|
||||
* Yan Vugenfirer <yan@daynix.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NET_TX_PKT_H
|
||||
#define NET_TX_PKT_H
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "net/eth.h"
|
||||
#include "exec/hwaddr.h"
|
||||
|
||||
/* define to enable packet dump functions */
|
||||
/*#define NET_TX_PKT_DEBUG*/
|
||||
|
||||
struct NetTxPkt;
|
||||
|
||||
/**
|
||||
* Init function for tx packet functionality
|
||||
*
|
||||
* @pkt: packet pointer
|
||||
* @pci_dev: PCI device processing this packet
|
||||
* @max_frags: max tx ip fragments
|
||||
* @has_virt_hdr: device uses virtio header.
|
||||
*/
|
||||
void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
|
||||
uint32_t max_frags, bool has_virt_hdr);
|
||||
|
||||
/**
|
||||
* Clean all tx packet resources.
|
||||
*
|
||||
* @pkt: packet.
|
||||
*/
|
||||
void net_tx_pkt_uninit(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* get virtio header
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: virtio header
|
||||
*/
|
||||
struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* build virtio header (will be stored in module context)
|
||||
*
|
||||
* @pkt: packet
|
||||
* @tso_enable: TSO enabled
|
||||
* @csum_enable: CSO enabled
|
||||
* @gso_size: MSS size for TSO
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
|
||||
bool csum_enable, uint32_t gso_size);
|
||||
|
||||
/**
|
||||
* updates vlan tag, and adds vlan header with custom ethernet type
|
||||
* in case it is missing.
|
||||
*
|
||||
* @pkt: packet
|
||||
* @vlan: VLAN tag
|
||||
* @vlan_ethtype: VLAN header Ethernet type
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
|
||||
uint16_t vlan, uint16_t vlan_ethtype);
|
||||
|
||||
/**
|
||||
* updates vlan tag, and adds vlan header in case it is missing
|
||||
*
|
||||
* @pkt: packet
|
||||
* @vlan: VLAN tag
|
||||
*
|
||||
*/
|
||||
static inline void
|
||||
net_tx_pkt_setup_vlan_header(struct NetTxPkt *pkt, uint16_t vlan)
|
||||
{
|
||||
net_tx_pkt_setup_vlan_header_ex(pkt, vlan, ETH_P_VLAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* populate data fragment into pkt context.
|
||||
*
|
||||
* @pkt: packet
|
||||
* @pa: physical address of fragment
|
||||
* @len: length of fragment
|
||||
*
|
||||
*/
|
||||
bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* Fix ip header fields and calculate IP header and pseudo header checksums.
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* Calculate the IP header checksum.
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* get length of all populated data.
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: total data length
|
||||
*
|
||||
*/
|
||||
size_t net_tx_pkt_get_total_len(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* get packet type
|
||||
*
|
||||
* @pkt: packet
|
||||
* @ret: packet type
|
||||
*
|
||||
*/
|
||||
eth_pkt_types_e net_tx_pkt_get_packet_type(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* prints packet data if debug is enabled
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_dump(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* reset tx packet private context (needed to be called between packets)
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
void net_tx_pkt_reset(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* Send packet to qemu. handles sw offloads if vhdr is not supported.
|
||||
*
|
||||
* @pkt: packet
|
||||
* @nc: NetClientState
|
||||
* @ret: operation result
|
||||
*
|
||||
*/
|
||||
bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc);
|
||||
|
||||
/**
|
||||
* Redirect packet directly to receive path (emulate loopback phy).
|
||||
* Handles sw offloads if vhdr is not supported.
|
||||
*
|
||||
* @pkt: packet
|
||||
* @nc: NetClientState
|
||||
* @ret: operation result
|
||||
*
|
||||
*/
|
||||
bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);
|
||||
|
||||
/**
|
||||
* parse raw packet data and analyze offload requirements.
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
bool net_tx_pkt_parse(struct NetTxPkt *pkt);
|
||||
|
||||
/**
|
||||
* indicates if there are data fragments held by this packet object.
|
||||
*
|
||||
* @pkt: packet
|
||||
*
|
||||
*/
|
||||
bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt);
|
||||
|
||||
#endif
|
||||
@@ -1867,11 +1867,6 @@ static int rtl8139_transmit_one(RTL8139State *s, int descriptor)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* structures and macros for task offloading */
|
||||
#define TCP_HEADER_DATA_OFFSET(tcp) (((be16_to_cpu(tcp->th_offset_flags) >> 12)&0xf) << 2)
|
||||
#define TCP_FLAGS_ONLY(flags) ((flags)&0x3f)
|
||||
#define TCP_HEADER_FLAGS(tcp) TCP_FLAGS_ONLY(be16_to_cpu(tcp->th_offset_flags))
|
||||
|
||||
#define TCP_HEADER_CLEAR_FLAGS(tcp, off) ((tcp)->th_offset_flags &= cpu_to_be16(~TCP_FLAGS_ONLY(off)))
|
||||
|
||||
/* produces ones' complement sum of data */
|
||||
|
||||
+81
-74
@@ -30,8 +30,8 @@
|
||||
#include "vmxnet3.h"
|
||||
#include "vmxnet_debug.h"
|
||||
#include "vmware_utils.h"
|
||||
#include "vmxnet_tx_pkt.h"
|
||||
#include "vmxnet_rx_pkt.h"
|
||||
#include "net_tx_pkt.h"
|
||||
#include "net_rx_pkt.h"
|
||||
|
||||
#define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
|
||||
#define VMXNET3_MSIX_BAR_SIZE 0x2000
|
||||
@@ -314,13 +314,13 @@ typedef struct {
|
||||
bool peer_has_vhdr;
|
||||
|
||||
/* TX packets to QEMU interface */
|
||||
struct VmxnetTxPkt *tx_pkt;
|
||||
struct NetTxPkt *tx_pkt;
|
||||
uint32_t offload_mode;
|
||||
uint32_t cso_or_gso_size;
|
||||
uint16_t tci;
|
||||
bool needs_vlan;
|
||||
|
||||
struct VmxnetRxPkt *rx_pkt;
|
||||
struct NetRxPkt *rx_pkt;
|
||||
|
||||
bool tx_sop;
|
||||
bool skip_current_tx_pkt;
|
||||
@@ -474,7 +474,7 @@ static void vmxnet3_set_variable_mac(VMXNET3State *s, uint32_t h, uint32_t l)
|
||||
s->conf.macaddr.a[4] = VMXNET3_GET_BYTE(h, 0);
|
||||
s->conf.macaddr.a[5] = VMXNET3_GET_BYTE(h, 1);
|
||||
|
||||
VMW_CFPRN("Variable MAC: " VMXNET_MF, VMXNET_MA(s->conf.macaddr.a));
|
||||
VMW_CFPRN("Variable MAC: " MAC_FMT, MAC_ARG(s->conf.macaddr.a));
|
||||
|
||||
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
|
||||
}
|
||||
@@ -546,18 +546,18 @@ vmxnet3_setup_tx_offloads(VMXNET3State *s)
|
||||
{
|
||||
switch (s->offload_mode) {
|
||||
case VMXNET3_OM_NONE:
|
||||
vmxnet_tx_pkt_build_vheader(s->tx_pkt, false, false, 0);
|
||||
net_tx_pkt_build_vheader(s->tx_pkt, false, false, 0);
|
||||
break;
|
||||
|
||||
case VMXNET3_OM_CSUM:
|
||||
vmxnet_tx_pkt_build_vheader(s->tx_pkt, false, true, 0);
|
||||
net_tx_pkt_build_vheader(s->tx_pkt, false, true, 0);
|
||||
VMW_PKPRN("L4 CSO requested\n");
|
||||
break;
|
||||
|
||||
case VMXNET3_OM_TSO:
|
||||
vmxnet_tx_pkt_build_vheader(s->tx_pkt, true, true,
|
||||
net_tx_pkt_build_vheader(s->tx_pkt, true, true,
|
||||
s->cso_or_gso_size);
|
||||
vmxnet_tx_pkt_update_ip_checksums(s->tx_pkt);
|
||||
net_tx_pkt_update_ip_checksums(s->tx_pkt);
|
||||
VMW_PKPRN("GSO offload requested.");
|
||||
break;
|
||||
|
||||
@@ -590,12 +590,12 @@ static void
|
||||
vmxnet3_on_tx_done_update_stats(VMXNET3State *s, int qidx,
|
||||
Vmxnet3PktStatus status)
|
||||
{
|
||||
size_t tot_len = vmxnet_tx_pkt_get_total_len(s->tx_pkt);
|
||||
size_t tot_len = net_tx_pkt_get_total_len(s->tx_pkt);
|
||||
struct UPT1_TxStats *stats = &s->txq_descr[qidx].txq_stats;
|
||||
|
||||
switch (status) {
|
||||
case VMXNET3_PKT_STATUS_OK:
|
||||
switch (vmxnet_tx_pkt_get_packet_type(s->tx_pkt)) {
|
||||
switch (net_tx_pkt_get_packet_type(s->tx_pkt)) {
|
||||
case ETH_PKT_BCAST:
|
||||
stats->bcastPktsTxOK++;
|
||||
stats->bcastBytesTxOK += tot_len;
|
||||
@@ -643,7 +643,7 @@ vmxnet3_on_rx_done_update_stats(VMXNET3State *s,
|
||||
Vmxnet3PktStatus status)
|
||||
{
|
||||
struct UPT1_RxStats *stats = &s->rxq_descr[qidx].rxq_stats;
|
||||
size_t tot_len = vmxnet_rx_pkt_get_total_len(s->rx_pkt);
|
||||
size_t tot_len = net_rx_pkt_get_total_len(s->rx_pkt);
|
||||
|
||||
switch (status) {
|
||||
case VMXNET3_PKT_STATUS_OUT_OF_BUF:
|
||||
@@ -654,7 +654,7 @@ vmxnet3_on_rx_done_update_stats(VMXNET3State *s,
|
||||
stats->pktsRxError++;
|
||||
break;
|
||||
case VMXNET3_PKT_STATUS_OK:
|
||||
switch (vmxnet_rx_pkt_get_packet_type(s->rx_pkt)) {
|
||||
switch (net_rx_pkt_get_packet_type(s->rx_pkt)) {
|
||||
case ETH_PKT_BCAST:
|
||||
stats->bcastPktsRxOK++;
|
||||
stats->bcastBytesRxOK += tot_len;
|
||||
@@ -715,10 +715,10 @@ vmxnet3_send_packet(VMXNET3State *s, uint32_t qidx)
|
||||
}
|
||||
|
||||
/* debug prints */
|
||||
vmxnet3_dump_virt_hdr(vmxnet_tx_pkt_get_vhdr(s->tx_pkt));
|
||||
vmxnet_tx_pkt_dump(s->tx_pkt);
|
||||
vmxnet3_dump_virt_hdr(net_tx_pkt_get_vhdr(s->tx_pkt));
|
||||
net_tx_pkt_dump(s->tx_pkt);
|
||||
|
||||
if (!vmxnet_tx_pkt_send(s->tx_pkt, qemu_get_queue(s->nic))) {
|
||||
if (!net_tx_pkt_send(s->tx_pkt, qemu_get_queue(s->nic))) {
|
||||
status = VMXNET3_PKT_STATUS_DISCARD;
|
||||
goto func_exit;
|
||||
}
|
||||
@@ -746,7 +746,7 @@ static void vmxnet3_process_tx_queue(VMXNET3State *s, int qidx)
|
||||
data_len = (txd.len > 0) ? txd.len : VMXNET3_MAX_TX_BUF_SIZE;
|
||||
data_pa = le64_to_cpu(txd.addr);
|
||||
|
||||
if (!vmxnet_tx_pkt_add_raw_fragment(s->tx_pkt,
|
||||
if (!net_tx_pkt_add_raw_fragment(s->tx_pkt,
|
||||
data_pa,
|
||||
data_len)) {
|
||||
s->skip_current_tx_pkt = true;
|
||||
@@ -759,9 +759,9 @@ static void vmxnet3_process_tx_queue(VMXNET3State *s, int qidx)
|
||||
}
|
||||
|
||||
if (txd.eop) {
|
||||
if (!s->skip_current_tx_pkt && vmxnet_tx_pkt_parse(s->tx_pkt)) {
|
||||
if (!s->skip_current_tx_pkt && net_tx_pkt_parse(s->tx_pkt)) {
|
||||
if (s->needs_vlan) {
|
||||
vmxnet_tx_pkt_setup_vlan_header(s->tx_pkt, s->tci);
|
||||
net_tx_pkt_setup_vlan_header(s->tx_pkt, s->tci);
|
||||
}
|
||||
|
||||
vmxnet3_send_packet(s, qidx);
|
||||
@@ -773,7 +773,7 @@ static void vmxnet3_process_tx_queue(VMXNET3State *s, int qidx)
|
||||
vmxnet3_complete_packet(s, qidx, txd_idx);
|
||||
s->tx_sop = true;
|
||||
s->skip_current_tx_pkt = false;
|
||||
vmxnet_tx_pkt_reset(s->tx_pkt);
|
||||
net_tx_pkt_reset(s->tx_pkt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -802,7 +802,9 @@ vmxnet3_pop_rxc_descr(VMXNET3State *s, int qidx, uint32_t *descr_gen)
|
||||
hwaddr daddr =
|
||||
vmxnet3_ring_curr_cell_pa(&s->rxq_descr[qidx].comp_ring);
|
||||
|
||||
cpu_physical_memory_read(daddr, &rxcd, sizeof(struct Vmxnet3_RxCompDesc));
|
||||
pci_dma_read(PCI_DEVICE(s), daddr,
|
||||
&rxcd, sizeof(struct Vmxnet3_RxCompDesc));
|
||||
|
||||
ring_gen = vmxnet3_ring_curr_gen(&s->rxq_descr[qidx].comp_ring);
|
||||
|
||||
if (rxcd.gen != ring_gen) {
|
||||
@@ -928,7 +930,7 @@ vmxnet3_get_next_rx_descr(VMXNET3State *s, bool is_head,
|
||||
* in the case the host OS performs forwarding, it will forward an
|
||||
* incorrectly checksummed packet.
|
||||
*/
|
||||
static void vmxnet3_rx_need_csum_calculate(struct VmxnetRxPkt *pkt,
|
||||
static void vmxnet3_rx_need_csum_calculate(struct NetRxPkt *pkt,
|
||||
const void *pkt_data,
|
||||
size_t pkt_len)
|
||||
{
|
||||
@@ -937,16 +939,16 @@ static void vmxnet3_rx_need_csum_calculate(struct VmxnetRxPkt *pkt,
|
||||
uint8_t *data;
|
||||
int len;
|
||||
|
||||
if (!vmxnet_rx_pkt_has_virt_hdr(pkt)) {
|
||||
if (!net_rx_pkt_has_virt_hdr(pkt)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vhdr = vmxnet_rx_pkt_get_vhdr(pkt);
|
||||
vhdr = net_rx_pkt_get_vhdr(pkt);
|
||||
if (!VMXNET_FLAG_IS_SET(vhdr->flags, VIRTIO_NET_HDR_F_NEEDS_CSUM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vmxnet_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
|
||||
net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
|
||||
if (!(isip4 || isip6) || !(istcp || isudp)) {
|
||||
return;
|
||||
}
|
||||
@@ -970,7 +972,7 @@ static void vmxnet3_rx_need_csum_calculate(struct VmxnetRxPkt *pkt,
|
||||
vhdr->flags |= VIRTIO_NET_HDR_F_DATA_VALID;
|
||||
}
|
||||
|
||||
static void vmxnet3_rx_update_descr(struct VmxnetRxPkt *pkt,
|
||||
static void vmxnet3_rx_update_descr(struct NetRxPkt *pkt,
|
||||
struct Vmxnet3_RxCompDesc *rxcd)
|
||||
{
|
||||
int csum_ok, is_gso;
|
||||
@@ -978,16 +980,16 @@ static void vmxnet3_rx_update_descr(struct VmxnetRxPkt *pkt,
|
||||
struct virtio_net_hdr *vhdr;
|
||||
uint8_t offload_type;
|
||||
|
||||
if (vmxnet_rx_pkt_is_vlan_stripped(pkt)) {
|
||||
if (net_rx_pkt_is_vlan_stripped(pkt)) {
|
||||
rxcd->ts = 1;
|
||||
rxcd->tci = vmxnet_rx_pkt_get_vlan_tag(pkt);
|
||||
rxcd->tci = net_rx_pkt_get_vlan_tag(pkt);
|
||||
}
|
||||
|
||||
if (!vmxnet_rx_pkt_has_virt_hdr(pkt)) {
|
||||
if (!net_rx_pkt_has_virt_hdr(pkt)) {
|
||||
goto nocsum;
|
||||
}
|
||||
|
||||
vhdr = vmxnet_rx_pkt_get_vhdr(pkt);
|
||||
vhdr = net_rx_pkt_get_vhdr(pkt);
|
||||
/*
|
||||
* Checksum is valid when lower level tell so or when lower level
|
||||
* requires checksum offload telling that packet produced/bridged
|
||||
@@ -1004,7 +1006,7 @@ static void vmxnet3_rx_update_descr(struct VmxnetRxPkt *pkt,
|
||||
goto nocsum;
|
||||
}
|
||||
|
||||
vmxnet_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
|
||||
net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
|
||||
if ((!istcp && !isudp) || (!isip4 && !isip6)) {
|
||||
goto nocsum;
|
||||
}
|
||||
@@ -1023,10 +1025,11 @@ nocsum:
|
||||
}
|
||||
|
||||
static void
|
||||
vmxnet3_physical_memory_writev(const struct iovec *iov,
|
||||
size_t start_iov_off,
|
||||
hwaddr target_addr,
|
||||
size_t bytes_to_copy)
|
||||
vmxnet3_pci_dma_writev(PCIDevice *pci_dev,
|
||||
const struct iovec *iov,
|
||||
size_t start_iov_off,
|
||||
hwaddr target_addr,
|
||||
size_t bytes_to_copy)
|
||||
{
|
||||
size_t curr_off = 0;
|
||||
size_t copied = 0;
|
||||
@@ -1036,9 +1039,9 @@ vmxnet3_physical_memory_writev(const struct iovec *iov,
|
||||
size_t chunk_len =
|
||||
MIN((curr_off + iov->iov_len) - start_iov_off, bytes_to_copy);
|
||||
|
||||
cpu_physical_memory_write(target_addr + copied,
|
||||
iov->iov_base + start_iov_off - curr_off,
|
||||
chunk_len);
|
||||
pci_dma_write(pci_dev, target_addr + copied,
|
||||
iov->iov_base + start_iov_off - curr_off,
|
||||
chunk_len);
|
||||
|
||||
copied += chunk_len;
|
||||
start_iov_off += chunk_len;
|
||||
@@ -1063,13 +1066,13 @@ vmxnet3_indicate_packet(VMXNET3State *s)
|
||||
uint32_t new_rxcd_gen = VMXNET3_INIT_GEN;
|
||||
hwaddr new_rxcd_pa = 0;
|
||||
hwaddr ready_rxcd_pa = 0;
|
||||
struct iovec *data = vmxnet_rx_pkt_get_iovec(s->rx_pkt);
|
||||
struct iovec *data = net_rx_pkt_get_iovec(s->rx_pkt);
|
||||
size_t bytes_copied = 0;
|
||||
size_t bytes_left = vmxnet_rx_pkt_get_total_len(s->rx_pkt);
|
||||
size_t bytes_left = net_rx_pkt_get_total_len(s->rx_pkt);
|
||||
uint16_t num_frags = 0;
|
||||
size_t chunk_size;
|
||||
|
||||
vmxnet_rx_pkt_dump(s->rx_pkt);
|
||||
net_rx_pkt_dump(s->rx_pkt);
|
||||
|
||||
while (bytes_left > 0) {
|
||||
|
||||
@@ -1088,15 +1091,15 @@ vmxnet3_indicate_packet(VMXNET3State *s)
|
||||
}
|
||||
|
||||
chunk_size = MIN(bytes_left, rxd.len);
|
||||
vmxnet3_physical_memory_writev(data, bytes_copied,
|
||||
le64_to_cpu(rxd.addr), chunk_size);
|
||||
vmxnet3_pci_dma_writev(PCI_DEVICE(s), data, bytes_copied,
|
||||
le64_to_cpu(rxd.addr), chunk_size);
|
||||
bytes_copied += chunk_size;
|
||||
bytes_left -= chunk_size;
|
||||
|
||||
vmxnet3_dump_rx_descr(&rxd);
|
||||
|
||||
if (ready_rxcd_pa != 0) {
|
||||
cpu_physical_memory_write(ready_rxcd_pa, &rxcd, sizeof(rxcd));
|
||||
pci_dma_write(PCI_DEVICE(s), ready_rxcd_pa, &rxcd, sizeof(rxcd));
|
||||
}
|
||||
|
||||
memset(&rxcd, 0, sizeof(struct Vmxnet3_RxCompDesc));
|
||||
@@ -1127,7 +1130,8 @@ vmxnet3_indicate_packet(VMXNET3State *s)
|
||||
if (ready_rxcd_pa != 0) {
|
||||
rxcd.eop = 1;
|
||||
rxcd.err = (bytes_left != 0);
|
||||
cpu_physical_memory_write(ready_rxcd_pa, &rxcd, sizeof(rxcd));
|
||||
|
||||
pci_dma_write(PCI_DEVICE(s), ready_rxcd_pa, &rxcd, sizeof(rxcd));
|
||||
|
||||
/* Flush RX descriptor changes */
|
||||
smp_wmb();
|
||||
@@ -1219,16 +1223,16 @@ static void vmxnet3_reset_interrupt_states(VMXNET3State *s)
|
||||
static void vmxnet3_reset_mac(VMXNET3State *s)
|
||||
{
|
||||
memcpy(&s->conf.macaddr.a, &s->perm_mac.a, sizeof(s->perm_mac.a));
|
||||
VMW_CFPRN("MAC address set to: " VMXNET_MF, VMXNET_MA(s->conf.macaddr.a));
|
||||
VMW_CFPRN("MAC address set to: " MAC_FMT, MAC_ARG(s->conf.macaddr.a));
|
||||
}
|
||||
|
||||
static void vmxnet3_deactivate_device(VMXNET3State *s)
|
||||
{
|
||||
if (s->device_active) {
|
||||
VMW_CBPRN("Deactivating vmxnet3...");
|
||||
vmxnet_tx_pkt_reset(s->tx_pkt);
|
||||
vmxnet_tx_pkt_uninit(s->tx_pkt);
|
||||
vmxnet_rx_pkt_uninit(s->rx_pkt);
|
||||
net_tx_pkt_reset(s->tx_pkt);
|
||||
net_tx_pkt_uninit(s->tx_pkt);
|
||||
net_rx_pkt_uninit(s->rx_pkt);
|
||||
s->device_active = false;
|
||||
}
|
||||
}
|
||||
@@ -1298,10 +1302,11 @@ static void vmxnet3_update_mcast_filters(VMXNET3State *s)
|
||||
VMXNET3_READ_DRV_SHARED64(s->drv_shmem,
|
||||
devRead.rxFilterConf.mfTablePA);
|
||||
|
||||
cpu_physical_memory_read(mcast_list_pa, s->mcast_list, list_bytes);
|
||||
pci_dma_read(PCI_DEVICE(s), mcast_list_pa, s->mcast_list, list_bytes);
|
||||
|
||||
VMW_CFPRN("Current multicast list len is %d:", s->mcast_list_len);
|
||||
for (i = 0; i < s->mcast_list_len; i++) {
|
||||
VMW_CFPRN("\t" VMXNET_MF, VMXNET_MA(s->mcast_list[i].a));
|
||||
VMW_CFPRN("\t" MAC_FMT, MAC_ARG(s->mcast_list[i].a));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1328,15 +1333,17 @@ static void vmxnet3_fill_stats(VMXNET3State *s)
|
||||
return;
|
||||
|
||||
for (i = 0; i < s->txq_num; i++) {
|
||||
cpu_physical_memory_write(s->txq_descr[i].tx_stats_pa,
|
||||
&s->txq_descr[i].txq_stats,
|
||||
sizeof(s->txq_descr[i].txq_stats));
|
||||
pci_dma_write(PCI_DEVICE(s),
|
||||
s->txq_descr[i].tx_stats_pa,
|
||||
&s->txq_descr[i].txq_stats,
|
||||
sizeof(s->txq_descr[i].txq_stats));
|
||||
}
|
||||
|
||||
for (i = 0; i < s->rxq_num; i++) {
|
||||
cpu_physical_memory_write(s->rxq_descr[i].rx_stats_pa,
|
||||
&s->rxq_descr[i].rxq_stats,
|
||||
sizeof(s->rxq_descr[i].rxq_stats));
|
||||
pci_dma_write(PCI_DEVICE(s),
|
||||
s->rxq_descr[i].rx_stats_pa,
|
||||
&s->rxq_descr[i].rxq_stats,
|
||||
sizeof(s->rxq_descr[i].rxq_stats));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1558,8 +1565,9 @@ static void vmxnet3_activate_device(VMXNET3State *s)
|
||||
|
||||
/* Preallocate TX packet wrapper */
|
||||
VMW_CFPRN("Max TX fragments is %u", s->max_tx_frags);
|
||||
vmxnet_tx_pkt_init(&s->tx_pkt, s->max_tx_frags, s->peer_has_vhdr);
|
||||
vmxnet_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr);
|
||||
net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s),
|
||||
s->max_tx_frags, s->peer_has_vhdr);
|
||||
net_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr);
|
||||
|
||||
/* Read rings memory locations for RX queues */
|
||||
for (i = 0; i < s->rxq_num; i++) {
|
||||
@@ -1965,7 +1973,7 @@ vmxnet3_rx_filter_may_indicate(VMXNET3State *s, const void *data,
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (vmxnet_rx_pkt_get_packet_type(s->rx_pkt)) {
|
||||
switch (net_rx_pkt_get_packet_type(s->rx_pkt)) {
|
||||
case ETH_PKT_UCAST:
|
||||
if (!VMXNET_FLAG_IS_SET(s->rx_mode, VMXNET3_RXM_UCAST)) {
|
||||
return false;
|
||||
@@ -2013,7 +2021,7 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
||||
}
|
||||
|
||||
if (s->peer_has_vhdr) {
|
||||
vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf);
|
||||
net_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf);
|
||||
buf += sizeof(struct virtio_net_hdr);
|
||||
size -= sizeof(struct virtio_net_hdr);
|
||||
}
|
||||
@@ -2026,13 +2034,13 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
|
||||
size = sizeof(min_buf);
|
||||
}
|
||||
|
||||
vmxnet_rx_pkt_set_packet_type(s->rx_pkt,
|
||||
net_rx_pkt_set_packet_type(s->rx_pkt,
|
||||
get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
|
||||
|
||||
if (vmxnet3_rx_filter_may_indicate(s, buf, size)) {
|
||||
vmxnet_rx_pkt_set_protocols(s->rx_pkt, buf, size);
|
||||
net_rx_pkt_set_protocols(s->rx_pkt, buf, size);
|
||||
vmxnet3_rx_need_csum_calculate(s->rx_pkt, buf, size);
|
||||
vmxnet_rx_pkt_attach_data(s->rx_pkt, buf, size, s->rx_vlan_stripping);
|
||||
net_rx_pkt_attach_data(s->rx_pkt, buf, size, s->rx_vlan_stripping);
|
||||
bytes_indicated = vmxnet3_indicate_packet(s) ? size : -1;
|
||||
if (bytes_indicated < size) {
|
||||
VMW_PKPRN("RX: %zu of %zu bytes indicated", bytes_indicated, size);
|
||||
@@ -2102,7 +2110,7 @@ static void vmxnet3_net_init(VMXNET3State *s)
|
||||
|
||||
s->link_status_and_speed = VMXNET3_LINK_SPEED | VMXNET3_LINK_STATUS_UP;
|
||||
|
||||
VMW_CFPRN("Permanent MAC: " VMXNET_MF, VMXNET_MA(s->perm_mac.a));
|
||||
VMW_CFPRN("Permanent MAC: " MAC_FMT, MAC_ARG(s->perm_mac.a));
|
||||
|
||||
s->nic = qemu_new_nic(&net_vmxnet3_info, &s->conf,
|
||||
object_get_typename(OBJECT(s)),
|
||||
@@ -2255,9 +2263,9 @@ static const MemoryRegionOps b1_ops = {
|
||||
},
|
||||
};
|
||||
|
||||
static uint8_t *vmxnet3_device_serial_num(VMXNET3State *s)
|
||||
static uint64_t vmxnet3_device_serial_num(VMXNET3State *s)
|
||||
{
|
||||
static uint64_t dsn_payload;
|
||||
uint64_t dsn_payload;
|
||||
uint8_t *dsnp = (uint8_t *)&dsn_payload;
|
||||
|
||||
dsnp[0] = 0xfe;
|
||||
@@ -2268,7 +2276,7 @@ static uint8_t *vmxnet3_device_serial_num(VMXNET3State *s)
|
||||
dsnp[5] = s->conf.macaddr.a[1];
|
||||
dsnp[6] = s->conf.macaddr.a[2];
|
||||
dsnp[7] = 0xff;
|
||||
return dsnp;
|
||||
return dsn_payload;
|
||||
}
|
||||
|
||||
static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp)
|
||||
@@ -2313,10 +2321,8 @@ static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp)
|
||||
pcie_endpoint_cap_init(pci_dev, VMXNET3_EXP_EP_OFFSET);
|
||||
}
|
||||
|
||||
pcie_add_capability(pci_dev, PCI_EXT_CAP_ID_DSN, 0x1,
|
||||
VMXNET3_DSN_OFFSET, PCI_EXT_CAP_DSN_SIZEOF);
|
||||
memcpy(pci_dev->config + VMXNET3_DSN_OFFSET + 4,
|
||||
vmxnet3_device_serial_num(s), sizeof(uint64_t));
|
||||
pcie_dev_ser_num_init(pci_dev, VMXNET3_DSN_OFFSET,
|
||||
vmxnet3_device_serial_num(s));
|
||||
}
|
||||
|
||||
register_savevm(dev, "vmxnet3-msix", -1, 1,
|
||||
@@ -2538,8 +2544,9 @@ static int vmxnet3_post_load(void *opaque, int version_id)
|
||||
VMXNET3State *s = opaque;
|
||||
PCIDevice *d = PCI_DEVICE(s);
|
||||
|
||||
vmxnet_tx_pkt_init(&s->tx_pkt, s->max_tx_frags, s->peer_has_vhdr);
|
||||
vmxnet_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr);
|
||||
net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s),
|
||||
s->max_tx_frags, s->peer_has_vhdr);
|
||||
net_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr);
|
||||
|
||||
if (s->msix_used) {
|
||||
if (!vmxnet3_use_msix_vectors(s, VMXNET3_MAX_INTRS)) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user