Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/netmap/if_ptnet.c
Show First 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | ptnet_attach(device_t dev) | ||||
sc->ifp = ifp = if_alloc(IFT_ETHER); | sc->ifp = ifp = if_alloc(IFT_ETHER); | ||||
if (ifp == NULL) { | if (ifp == NULL) { | ||||
device_printf(dev, "Failed to allocate ifnet\n"); | device_printf(dev, "Failed to allocate ifnet\n"); | ||||
err = ENOMEM; | err = ENOMEM; | ||||
goto err_path; | goto err_path; | ||||
} | } | ||||
if_initname(ifp, device_get_name(dev), device_get_unit(dev)); | if_initname(ifp, device_get_name(dev), device_get_unit(dev)); | ||||
ifp->if_baudrate = IF_Gbps(10); | if_setbaudrate(ifp, IF_Gbps(10)); | ||||
ifp->if_softc = sc; | if_setsoftc(ifp, sc); | ||||
ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX; | if_setflags(ifp, IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX); | ||||
ifp->if_init = ptnet_init; | if_setinitfn(ifp, ptnet_init); | ||||
ifp->if_ioctl = ptnet_ioctl; | if_setioctlfn(ifp, ptnet_ioctl); | ||||
ifp->if_get_counter = ptnet_get_counter; | if_setget_counter(ifp, ptnet_get_counter); | ||||
ifp->if_transmit = ptnet_transmit; | if_settransmitfn(ifp, ptnet_transmit); | ||||
ifp->if_qflush = ptnet_qflush; | if_setqflushfn(ifp, ptnet_qflush); | ||||
ifmedia_init(&sc->media, IFM_IMASK, ptnet_media_change, | ifmedia_init(&sc->media, IFM_IMASK, ptnet_media_change, | ||||
ptnet_media_status); | ptnet_media_status); | ||||
ifmedia_add(&sc->media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL); | ifmedia_add(&sc->media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL); | ||||
ifmedia_set(&sc->media, IFM_ETHER | IFM_10G_T | IFM_FDX); | ifmedia_set(&sc->media, IFM_ETHER | IFM_10G_T | IFM_FDX); | ||||
macreg = bus_read_4(sc->iomem, PTNET_IO_MAC_HI); | macreg = bus_read_4(sc->iomem, PTNET_IO_MAC_HI); | ||||
sc->hwaddr[0] = (macreg >> 8) & 0xff; | sc->hwaddr[0] = (macreg >> 8) & 0xff; | ||||
sc->hwaddr[1] = macreg & 0xff; | sc->hwaddr[1] = macreg & 0xff; | ||||
macreg = bus_read_4(sc->iomem, PTNET_IO_MAC_LO); | macreg = bus_read_4(sc->iomem, PTNET_IO_MAC_LO); | ||||
sc->hwaddr[2] = (macreg >> 24) & 0xff; | sc->hwaddr[2] = (macreg >> 24) & 0xff; | ||||
sc->hwaddr[3] = (macreg >> 16) & 0xff; | sc->hwaddr[3] = (macreg >> 16) & 0xff; | ||||
sc->hwaddr[4] = (macreg >> 8) & 0xff; | sc->hwaddr[4] = (macreg >> 8) & 0xff; | ||||
sc->hwaddr[5] = macreg & 0xff; | sc->hwaddr[5] = macreg & 0xff; | ||||
ether_ifattach(ifp, sc->hwaddr); | ether_ifattach(ifp, sc->hwaddr); | ||||
ifp->if_hdrlen = sizeof(struct ether_vlan_header); | if_setifheaderlen(ifp, sizeof(struct ether_vlan_header)); | ||||
ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU; | if_setcapabilitiesbit(ifp, IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU, 0); | ||||
if (sc->ptfeatures & PTNETMAP_F_VNET_HDR) { | if (sc->ptfeatures & PTNETMAP_F_VNET_HDR) { | ||||
/* Similarly to what the vtnet driver does, we can emulate | /* Similarly to what the vtnet driver does, we can emulate | ||||
* VLAN offloadings by inserting and removing the 802.1Q | * VLAN offloadings by inserting and removing the 802.1Q | ||||
* header during transmit and receive. We are then able | * header during transmit and receive. We are then able | ||||
* to do checksum offloading of VLAN frames. */ | * to do checksum offloading of VLAN frames. */ | ||||
ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6 | if_setcapabilitiesbit(ifp, IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6 | ||||
vmaffione: You have a typo here, since this is a multi line assignment | |||||
Done Inline ActionsNo idea at all how this was not caught by the compiler; pretty embarassing. jhibbits: No idea at all how this was not caught by the compiler; pretty embarassing. | |||||
Not Done Inline Actionsno worries, it's just unsettling if not catched by a compiler :) vmaffione: no worries, it's just unsettling if not catched by a compiler :) | |||||
| IFCAP_VLAN_HWCSUM | | IFCAP_VLAN_HWCSUM | ||||
| IFCAP_TSO | IFCAP_LRO | | IFCAP_TSO | IFCAP_LRO | ||||
| IFCAP_VLAN_HWTSO | | IFCAP_VLAN_HWTSO | ||||
| IFCAP_VLAN_HWTAGGING; | | IFCAP_VLAN_HWTAGGING, 0); | ||||
} | } | ||||
ifp->if_capenable = ifp->if_capabilities; | if_setcapenable(ifp, if_getcapabilities(ifp)); | ||||
#ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
/* Don't enable polling by default. */ | /* Don't enable polling by default. */ | ||||
ifp->if_capabilities |= IFCAP_POLLING; | if_setcapabilitiesbit(ifp, IFCAP_POLLING, 0); | ||||
#endif | #endif | ||||
snprintf(sc->lock_name, sizeof(sc->lock_name), | snprintf(sc->lock_name, sizeof(sc->lock_name), | ||||
"%s", device_get_nameunit(dev)); | "%s", device_get_nameunit(dev)); | ||||
mtx_init(&sc->lock, sc->lock_name, "ptnet core lock", MTX_DEF); | mtx_init(&sc->lock, sc->lock_name, "ptnet core lock", MTX_DEF); | ||||
callout_init_mtx(&sc->tick, &sc->lock, 0); | callout_init_mtx(&sc->tick, &sc->lock, 0); | ||||
/* Prepare a netmap_adapter struct instance to do netmap_attach(). */ | /* Prepare a netmap_adapter struct instance to do netmap_attach(). */ | ||||
nifp_offset = bus_read_4(sc->iomem, PTNET_IO_NIFP_OFS); | nifp_offset = bus_read_4(sc->iomem, PTNET_IO_NIFP_OFS); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
ptnet_detach(device_t dev) | ptnet_detach(device_t dev) | ||||
{ | { | ||||
struct ptnet_softc *sc = device_get_softc(dev); | struct ptnet_softc *sc = device_get_softc(dev); | ||||
int i; | int i; | ||||
ptnet_device_shutdown(sc); | ptnet_device_shutdown(sc); | ||||
#ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
if (sc->ifp->if_capenable & IFCAP_POLLING) { | if (if_getcapenable(sc->ifp) & IFCAP_POLLING) { | ||||
Done Inline ActionsThis must be wrongly changed by tools ;) zlei: This must be wrongly changed by tools ;)
Should be `if_getcapenable(sc->ifp)` | |||||
Done Inline ActionsAnd somehow this didn't get caught even in a LINT build. The script is rather naive, so I've had to do a lot of these fixes, caught by build failures. jhibbits: And somehow this didn't get caught even in a LINT build. The script is rather naive, so I've… | |||||
ether_poll_deregister(sc->ifp); | ether_poll_deregister(sc->ifp); | ||||
} | } | ||||
#endif | #endif | ||||
callout_drain(&sc->tick); | callout_drain(&sc->tick); | ||||
if (sc->queues) { | if (sc->queues) { | ||||
/* Drain taskqueues before calling if_detach. */ | /* Drain taskqueues before calling if_detach. */ | ||||
for (i = 0; i < sc->num_rings; i++) { | for (i = 0; i < sc->num_rings; i++) { | ||||
▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct ptnet_softc *sc = if_getsoftc(ifp); | struct ptnet_softc *sc = if_getsoftc(ifp); | ||||
device_t dev = sc->dev; | device_t dev = sc->dev; | ||||
struct ifreq *ifr = (struct ifreq *)data; | struct ifreq *ifr = (struct ifreq *)data; | ||||
int mask __unused, err = 0; | int mask __unused, err = 0; | ||||
switch (cmd) { | switch (cmd) { | ||||
case SIOCSIFFLAGS: | case SIOCSIFFLAGS: | ||||
device_printf(dev, "SIOCSIFFLAGS %x\n", ifp->if_flags); | device_printf(dev, "SIOCSIFFLAGS %x\n", if_getflags(ifp)); | ||||
Done Inline ActionsIs this removal intended ? zlei: Is this removal intended ? | |||||
Done Inline ActionsNot at all. jhibbits: Not at all. | |||||
PTNET_CORE_LOCK(sc); | PTNET_CORE_LOCK(sc); | ||||
if (ifp->if_flags & IFF_UP) { | if (if_getflags(ifp) & IFF_UP) { | ||||
/* Network stack wants the iff to be up. */ | /* Network stack wants the iff to be up. */ | ||||
err = ptnet_init_locked(sc); | err = ptnet_init_locked(sc); | ||||
} else { | } else { | ||||
/* Network stack wants the iff to be down. */ | /* Network stack wants the iff to be down. */ | ||||
err = ptnet_stop(sc); | err = ptnet_stop(sc); | ||||
} | } | ||||
/* We don't need to do nothing to support IFF_PROMISC, | /* We don't need to do nothing to support IFF_PROMISC, | ||||
* since that is managed by the backend port. */ | * since that is managed by the backend port. */ | ||||
PTNET_CORE_UNLOCK(sc); | PTNET_CORE_UNLOCK(sc); | ||||
break; | break; | ||||
case SIOCSIFCAP: | case SIOCSIFCAP: | ||||
device_printf(dev, "SIOCSIFCAP %x %x\n", | device_printf(dev, "SIOCSIFCAP %x %x\n", | ||||
ifr->ifr_reqcap, ifp->if_capenable); | ifr->ifr_reqcap, if_getcapenable(ifp)); | ||||
mask = ifr->ifr_reqcap ^ ifp->if_capenable; | mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); | ||||
#ifdef DEVICE_POLLING | #ifdef DEVICE_POLLING | ||||
if (mask & IFCAP_POLLING) { | if (mask & IFCAP_POLLING) { | ||||
struct ptnet_queue *pq; | struct ptnet_queue *pq; | ||||
int i; | int i; | ||||
if (ifr->ifr_reqcap & IFCAP_POLLING) { | if (ifr->ifr_reqcap & IFCAP_POLLING) { | ||||
err = ether_poll_register(ptnet_poll, ifp); | err = ether_poll_register(ptnet_poll, ifp); | ||||
if (err) { | if (err) { | ||||
break; | break; | ||||
} | } | ||||
/* Stop queues and sync with taskqueues. */ | /* Stop queues and sync with taskqueues. */ | ||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); | ||||
for (i = 0; i < sc->num_rings; i++) { | for (i = 0; i < sc->num_rings; i++) { | ||||
pq = sc-> queues + i; | pq = sc-> queues + i; | ||||
/* Make sure the worker sees the | /* Make sure the worker sees the | ||||
* IFF_DRV_RUNNING down. */ | * IFF_DRV_RUNNING down. */ | ||||
PTNET_Q_LOCK(pq); | PTNET_Q_LOCK(pq); | ||||
pq->atok->appl_need_kick = 0; | pq->atok->appl_need_kick = 0; | ||||
PTNET_Q_UNLOCK(pq); | PTNET_Q_UNLOCK(pq); | ||||
/* Wait for rescheduling to finish. */ | /* Wait for rescheduling to finish. */ | ||||
if (pq->taskq) { | if (pq->taskq) { | ||||
taskqueue_drain(pq->taskq, | taskqueue_drain(pq->taskq, | ||||
&pq->task); | &pq->task); | ||||
} | } | ||||
} | } | ||||
ifp->if_drv_flags |= IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); | ||||
} else { | } else { | ||||
err = ether_poll_deregister(ifp); | err = ether_poll_deregister(ifp); | ||||
for (i = 0; i < sc->num_rings; i++) { | for (i = 0; i < sc->num_rings; i++) { | ||||
pq = sc-> queues + i; | pq = sc-> queues + i; | ||||
PTNET_Q_LOCK(pq); | PTNET_Q_LOCK(pq); | ||||
pq->atok->appl_need_kick = 1; | pq->atok->appl_need_kick = 1; | ||||
PTNET_Q_UNLOCK(pq); | PTNET_Q_UNLOCK(pq); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#endif /* DEVICE_POLLING */ | #endif /* DEVICE_POLLING */ | ||||
ifp->if_capenable = ifr->ifr_reqcap; | if_setcapenable(ifp, ifr->ifr_reqcap); | ||||
break; | break; | ||||
case SIOCSIFMTU: | case SIOCSIFMTU: | ||||
/* We support any reasonable MTU. */ | /* We support any reasonable MTU. */ | ||||
if (ifr->ifr_mtu < ETHERMIN || | if (ifr->ifr_mtu < ETHERMIN || | ||||
ifr->ifr_mtu > PTNET_MAX_PKT_SIZE) { | ifr->ifr_mtu > PTNET_MAX_PKT_SIZE) { | ||||
err = EINVAL; | err = EINVAL; | ||||
} else { | } else { | ||||
PTNET_CORE_LOCK(sc); | PTNET_CORE_LOCK(sc); | ||||
ifp->if_mtu = ifr->ifr_mtu; | if_setmtu(ifp, ifr->ifr_mtu); | ||||
PTNET_CORE_UNLOCK(sc); | PTNET_CORE_UNLOCK(sc); | ||||
} | } | ||||
break; | break; | ||||
case SIOCSIFMEDIA: | case SIOCSIFMEDIA: | ||||
case SIOCGIFMEDIA: | case SIOCGIFMEDIA: | ||||
err = ifmedia_ioctl(ifp, ifr, &sc->media, cmd); | err = ifmedia_ioctl(ifp, ifr, &sc->media, cmd); | ||||
break; | break; | ||||
Show All 10 Lines | |||||
ptnet_init_locked(struct ptnet_softc *sc) | ptnet_init_locked(struct ptnet_softc *sc) | ||||
{ | { | ||||
if_t ifp = sc->ifp; | if_t ifp = sc->ifp; | ||||
struct netmap_adapter *na_dr = &sc->ptna->dr.up; | struct netmap_adapter *na_dr = &sc->ptna->dr.up; | ||||
struct netmap_adapter *na_nm = &sc->ptna->hwup.up; | struct netmap_adapter *na_nm = &sc->ptna->hwup.up; | ||||
unsigned int nm_buf_size; | unsigned int nm_buf_size; | ||||
int ret; | int ret; | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { | ||||
return 0; /* nothing to do */ | return 0; /* nothing to do */ | ||||
} | } | ||||
device_printf(sc->dev, "%s\n", __func__); | device_printf(sc->dev, "%s\n", __func__); | ||||
/* Translate offload capabilities according to if_capenable. */ | /* Translate offload capabilities according to if_capenable. */ | ||||
ifp->if_hwassist = 0; | if_sethwassist(ifp, 0); | ||||
if (ifp->if_capenable & IFCAP_TXCSUM) | if (if_getcapenable(ifp) & IFCAP_TXCSUM) | ||||
ifp->if_hwassist |= PTNET_CSUM_OFFLOAD; | if_sethwassistbits(ifp, PTNET_CSUM_OFFLOAD, 0); | ||||
if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) | if (if_getcapenable(ifp) & IFCAP_TXCSUM_IPV6) | ||||
ifp->if_hwassist |= PTNET_CSUM_OFFLOAD_IPV6; | if_sethwassistbits(ifp, PTNET_CSUM_OFFLOAD_IPV6, 0); | ||||
if (ifp->if_capenable & IFCAP_TSO4) | if (if_getcapenable(ifp) & IFCAP_TSO4) | ||||
ifp->if_hwassist |= CSUM_IP_TSO; | if_sethwassistbits(ifp, CSUM_IP_TSO, 0); | ||||
if (ifp->if_capenable & IFCAP_TSO6) | if (if_getcapenable(ifp) & IFCAP_TSO6) | ||||
ifp->if_hwassist |= CSUM_IP6_TSO; | if_sethwassistbits(ifp, CSUM_IP6_TSO, 0); | ||||
/* | /* | ||||
* Prepare the interface for netmap mode access. | * Prepare the interface for netmap mode access. | ||||
*/ | */ | ||||
netmap_update_config(na_dr); | netmap_update_config(na_dr); | ||||
ret = netmap_mem_finalize(na_dr->nm_mem, na_dr); | ret = netmap_mem_finalize(na_dr->nm_mem, na_dr); | ||||
if (ret) { | if (ret) { | ||||
Show All 34 Lines | ptnet_init_locked(struct ptnet_softc *sc) | ||||
KASSERT(nm_buf_size > 0, ("Invalid netmap buffer size")); | KASSERT(nm_buf_size > 0, ("Invalid netmap buffer size")); | ||||
sc->min_tx_space = PTNET_MAX_PKT_SIZE / nm_buf_size + 2; | sc->min_tx_space = PTNET_MAX_PKT_SIZE / nm_buf_size + 2; | ||||
device_printf(sc->dev, "%s: min_tx_space = %u\n", __func__, | device_printf(sc->dev, "%s: min_tx_space = %u\n", __func__, | ||||
sc->min_tx_space); | sc->min_tx_space); | ||||
#ifdef PTNETMAP_STATS | #ifdef PTNETMAP_STATS | ||||
callout_reset(&sc->tick, hz, ptnet_tick, sc); | callout_reset(&sc->tick, hz, ptnet_tick, sc); | ||||
#endif | #endif | ||||
ifp->if_drv_flags |= IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); | ||||
return 0; | return 0; | ||||
err_register: | err_register: | ||||
memset(&na_dr->na_lut, 0, sizeof(na_dr->na_lut)); | memset(&na_dr->na_lut, 0, sizeof(na_dr->na_lut)); | ||||
err_get_lut: | err_get_lut: | ||||
netmap_mem_rings_delete(na_dr); | netmap_mem_rings_delete(na_dr); | ||||
err_rings_create: | err_rings_create: | ||||
Show All 10 Lines | |||||
{ | { | ||||
if_t ifp = sc->ifp; | if_t ifp = sc->ifp; | ||||
struct netmap_adapter *na_dr = &sc->ptna->dr.up; | struct netmap_adapter *na_dr = &sc->ptna->dr.up; | ||||
struct netmap_adapter *na_nm = &sc->ptna->hwup.up; | struct netmap_adapter *na_nm = &sc->ptna->hwup.up; | ||||
int i; | int i; | ||||
device_printf(sc->dev, "%s\n", __func__); | device_printf(sc->dev, "%s\n", __func__); | ||||
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { | ||||
return 0; /* nothing to do */ | return 0; /* nothing to do */ | ||||
} | } | ||||
/* Clear the driver-ready flag, and synchronize with all the queues, | /* Clear the driver-ready flag, and synchronize with all the queues, | ||||
* so that after this loop we are sure nobody is working anymore with | * so that after this loop we are sure nobody is working anymore with | ||||
* the device. This scheme is taken from the vtnet driver. */ | * the device. This scheme is taken from the vtnet driver. */ | ||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); | ||||
callout_stop(&sc->tick); | callout_stop(&sc->tick); | ||||
for (i = 0; i < sc->num_rings; i++) { | for (i = 0; i < sc->num_rings; i++) { | ||||
PTNET_Q_LOCK(sc->queues + i); | PTNET_Q_LOCK(sc->queues + i); | ||||
PTNET_Q_UNLOCK(sc->queues + i); | PTNET_Q_UNLOCK(sc->queues + i); | ||||
} | } | ||||
ptnet_nm_register(na_dr, 0 /* off */); | ptnet_nm_register(na_dr, 0 /* off */); | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | ptnet_nm_register(struct netmap_adapter *na, int onoff) | ||||
if (onoff) { | if (onoff) { | ||||
if (sc->ptna->backend_users == 0) { | if (sc->ptna->backend_users == 0) { | ||||
/* Initialize notification enable fields in the CSB. */ | /* Initialize notification enable fields in the CSB. */ | ||||
for (i = 0; i < sc->num_rings; i++) { | for (i = 0; i < sc->num_rings; i++) { | ||||
pq = sc->queues + i; | pq = sc->queues + i; | ||||
pq->ktoa->kern_need_kick = 1; | pq->ktoa->kern_need_kick = 1; | ||||
pq->atok->appl_need_kick = | pq->atok->appl_need_kick = | ||||
(!(ifp->if_capenable & IFCAP_POLLING) | (!(if_getcapenable(ifp) & IFCAP_POLLING) | ||||
&& i >= sc->num_tx_rings); | && i >= sc->num_tx_rings); | ||||
} | } | ||||
/* Set the virtio-net header length. */ | /* Set the virtio-net header length. */ | ||||
ptnet_update_vnet_hdr(sc); | ptnet_update_vnet_hdr(sc); | ||||
/* Make sure the host adapter passed through is ready | /* Make sure the host adapter passed through is ready | ||||
* for txsync/rxsync. */ | * for txsync/rxsync. */ | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | if (!PTNET_Q_TRYLOCK(pq)) { | ||||
nm_prlim(1, "Deferring TX work"); | nm_prlim(1, "Deferring TX work"); | ||||
if (may_resched) { | if (may_resched) { | ||||
taskqueue_enqueue(pq->taskq, &pq->task); | taskqueue_enqueue(pq->taskq, &pq->task); | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) { | if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) { | ||||
PTNET_Q_UNLOCK(pq); | PTNET_Q_UNLOCK(pq); | ||||
nm_prlim(1, "Interface is down"); | nm_prlim(1, "Interface is down"); | ||||
return ENETDOWN; | return ENETDOWN; | ||||
} | } | ||||
atok = pq->atok; | atok = pq->atok; | ||||
ktoa = pq->ktoa; | ktoa = pq->ktoa; | ||||
kring = na->tx_rings[pq->kring_id]; | kring = na->tx_rings[pq->kring_id]; | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | ptnet_transmit(if_t ifp, struct mbuf *m) | ||||
if (err) { | if (err) { | ||||
/* ENOBUFS when the bufring is full */ | /* ENOBUFS when the bufring is full */ | ||||
nm_prlim(1, "%s: drbr_enqueue() failed %d\n", | nm_prlim(1, "%s: drbr_enqueue() failed %d\n", | ||||
__func__, err); | __func__, err); | ||||
pq->stats.errors ++; | pq->stats.errors ++; | ||||
return err; | return err; | ||||
} | } | ||||
if (ifp->if_capenable & IFCAP_POLLING) { | if (if_getcapenable(ifp) & IFCAP_POLLING) { | ||||
/* If polling is on, the transmit queues will be | /* If polling is on, the transmit queues will be | ||||
* drained by the poller. */ | * drained by the poller. */ | ||||
return 0; | return 0; | ||||
} | } | ||||
err = ptnet_drain_transmit_queue(pq, PTNET_TX_BUDGET, true); | err = ptnet_drain_transmit_queue(pq, PTNET_TX_BUDGET, true); | ||||
return (err < 0) ? err : 0; | return (err < 0) ? err : 0; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | ptnet_rx_eof(struct ptnet_queue *pq, unsigned int budget, bool may_resched) | ||||
unsigned int const lim = kring->nkr_num_slots - 1; | unsigned int const lim = kring->nkr_num_slots - 1; | ||||
unsigned int batch_count = 0; | unsigned int batch_count = 0; | ||||
if_t ifp = sc->ifp; | if_t ifp = sc->ifp; | ||||
unsigned int count = 0; | unsigned int count = 0; | ||||
uint32_t head; | uint32_t head; | ||||
PTNET_Q_LOCK(pq); | PTNET_Q_LOCK(pq); | ||||
if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) { | if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) { | ||||
goto unlock; | goto unlock; | ||||
} | } | ||||
kring->nr_kflags &= ~NKR_PENDINTR; | kring->nr_kflags &= ~NKR_PENDINTR; | ||||
head = ring->head; | head = ring->head; | ||||
while (count < budget) { | while (count < budget) { | ||||
uint32_t prev_head = head; | uint32_t prev_head = head; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | host_sync: | ||||
mhead->m_pkthdr.rcvif = ifp; | mhead->m_pkthdr.rcvif = ifp; | ||||
mhead->m_pkthdr.csum_flags = 0; | mhead->m_pkthdr.csum_flags = 0; | ||||
/* Store the queue idx in the packet header. */ | /* Store the queue idx in the packet header. */ | ||||
mhead->m_pkthdr.flowid = pq->kring_id; | mhead->m_pkthdr.flowid = pq->kring_id; | ||||
M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); | M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); | ||||
if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) { | if (if_getcapenable(ifp) & IFCAP_VLAN_HWTAGGING) { | ||||
struct ether_header *eh; | struct ether_header *eh; | ||||
eh = mtod(mhead, struct ether_header *); | eh = mtod(mhead, struct ether_header *); | ||||
if (eh->ether_type == htons(ETHERTYPE_VLAN)) { | if (eh->ether_type == htons(ETHERTYPE_VLAN)) { | ||||
ptnet_vlan_tag_remove(mhead); | ptnet_vlan_tag_remove(mhead); | ||||
/* | /* | ||||
* With the 802.1Q header removed, update the | * With the 802.1Q header removed, update the | ||||
* checksum starting location accordingly. | * checksum starting location accordingly. | ||||
Show All 20 Lines | if (++batch_count >= PTNET_RX_BATCH) { | ||||
batch_count = 0; | batch_count = 0; | ||||
} | } | ||||
if (likely(deliver)) { | if (likely(deliver)) { | ||||
pq->stats.packets ++; | pq->stats.packets ++; | ||||
pq->stats.bytes += mhead->m_pkthdr.len; | pq->stats.bytes += mhead->m_pkthdr.len; | ||||
PTNET_Q_UNLOCK(pq); | PTNET_Q_UNLOCK(pq); | ||||
(*ifp->if_input)(ifp, mhead); | if_input(ifp, mhead); | ||||
Done Inline ActionsWhy the comment? vmaffione: Why the comment? | |||||
Done Inline ActionsIt shouldn't be there, thought I removed them all. jhibbits: It shouldn't be there, thought I removed them all. | |||||
PTNET_Q_LOCK(pq); | PTNET_Q_LOCK(pq); | ||||
/* The ring->head index (and related indices) are | /* The ring->head index (and related indices) are | ||||
* updated under pq lock by ptnet_ring_update(). | * updated under pq lock by ptnet_ring_update(). | ||||
* Since we dropped the lock to call if_input(), we | * Since we dropped the lock to call if_input(), we | ||||
* must reload ring->head and restart processing the | * must reload ring->head and restart processing the | ||||
* ring from there. */ | * ring from there. */ | ||||
head = ring->head; | head = ring->head; | ||||
if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) { | if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) { | ||||
/* The interface has gone down while we didn't | /* The interface has gone down while we didn't | ||||
* have the lock. Stop any processing and exit. */ | * have the lock. Stop any processing and exit. */ | ||||
goto unlock; | goto unlock; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
escape: | escape: | ||||
if (batch_count) { | if (batch_count) { | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |
You have a typo here, since this is a multi line assignment