Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/xen/netback/netback.c
| Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | |||||||||
| struct xnb_pkt; | struct xnb_pkt; | ||||||||
| static void xnb_attach_failed(struct xnb_softc *xnb, | static void xnb_attach_failed(struct xnb_softc *xnb, | ||||||||
| int err, const char *fmt, ...) | int err, const char *fmt, ...) | ||||||||
| __printflike(3,4); | __printflike(3,4); | ||||||||
| static int xnb_shutdown(struct xnb_softc *xnb); | static int xnb_shutdown(struct xnb_softc *xnb); | ||||||||
| static int create_netdev(device_t dev); | static int create_netdev(device_t dev); | ||||||||
| static int xnb_detach(device_t dev); | static int xnb_detach(device_t dev); | ||||||||
| static int xnb_ifmedia_upd(struct ifnet *ifp); | static int xnb_ifmedia_upd(if_t ifp); | ||||||||
| static void xnb_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr); | static void xnb_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr); | ||||||||
| static void xnb_intr(void *arg); | static void xnb_intr(void *arg); | ||||||||
| static int xnb_send(netif_rx_back_ring_t *rxb, domid_t otherend, | static int xnb_send(netif_rx_back_ring_t *rxb, domid_t otherend, | ||||||||
| const struct mbuf *mbufc, gnttab_copy_table gnttab); | const struct mbuf *mbufc, gnttab_copy_table gnttab); | ||||||||
| static int xnb_recv(netif_tx_back_ring_t *txb, domid_t otherend, | static int xnb_recv(netif_tx_back_ring_t *txb, domid_t otherend, | ||||||||
| struct mbuf **mbufc, struct ifnet *ifnet, | struct mbuf **mbufc, if_t ifnet, | ||||||||
| gnttab_copy_table gnttab); | gnttab_copy_table gnttab); | ||||||||
| static int xnb_ring2pkt(struct xnb_pkt *pkt, | static int xnb_ring2pkt(struct xnb_pkt *pkt, | ||||||||
| const netif_tx_back_ring_t *tx_ring, | const netif_tx_back_ring_t *tx_ring, | ||||||||
| RING_IDX start); | RING_IDX start); | ||||||||
| static void xnb_txpkt2rsp(const struct xnb_pkt *pkt, | static void xnb_txpkt2rsp(const struct xnb_pkt *pkt, | ||||||||
| netif_tx_back_ring_t *ring, int error); | netif_tx_back_ring_t *ring, int error); | ||||||||
| static struct mbuf *xnb_pkt2mbufc(const struct xnb_pkt *pkt, struct ifnet *ifp); | static struct mbuf *xnb_pkt2mbufc(const struct xnb_pkt *pkt, if_t ifp); | ||||||||
| static int xnb_txpkt2gnttab(const struct xnb_pkt *pkt, | static int xnb_txpkt2gnttab(const struct xnb_pkt *pkt, | ||||||||
| struct mbuf *mbufc, | struct mbuf *mbufc, | ||||||||
| gnttab_copy_table gnttab, | gnttab_copy_table gnttab, | ||||||||
| const netif_tx_back_ring_t *txb, | const netif_tx_back_ring_t *txb, | ||||||||
| domid_t otherend_id); | domid_t otherend_id); | ||||||||
| static void xnb_update_mbufc(struct mbuf *mbufc, | static void xnb_update_mbufc(struct mbuf *mbufc, | ||||||||
| const gnttab_copy_table gnttab, int n_entries); | const gnttab_copy_table gnttab, int n_entries); | ||||||||
| static int xnb_mbufc2pkt(const struct mbuf *mbufc, | static int xnb_mbufc2pkt(const struct mbuf *mbufc, | ||||||||
| struct xnb_pkt *pkt, | struct xnb_pkt *pkt, | ||||||||
| RING_IDX start, int space); | RING_IDX start, int space); | ||||||||
| static int xnb_rxpkt2gnttab(const struct xnb_pkt *pkt, | static int xnb_rxpkt2gnttab(const struct xnb_pkt *pkt, | ||||||||
| const struct mbuf *mbufc, | const struct mbuf *mbufc, | ||||||||
| gnttab_copy_table gnttab, | gnttab_copy_table gnttab, | ||||||||
| const netif_rx_back_ring_t *rxb, | const netif_rx_back_ring_t *rxb, | ||||||||
| domid_t otherend_id); | domid_t otherend_id); | ||||||||
| static int xnb_rxpkt2rsp(const struct xnb_pkt *pkt, | static int xnb_rxpkt2rsp(const struct xnb_pkt *pkt, | ||||||||
| const gnttab_copy_table gnttab, int n_entries, | const gnttab_copy_table gnttab, int n_entries, | ||||||||
| netif_rx_back_ring_t *ring); | netif_rx_back_ring_t *ring); | ||||||||
| static void xnb_stop(struct xnb_softc*); | static void xnb_stop(struct xnb_softc*); | ||||||||
| static int xnb_ioctl(struct ifnet*, u_long, caddr_t); | static int xnb_ioctl(if_t, u_long, caddr_t); | ||||||||
| static void xnb_start_locked(struct ifnet*); | static void xnb_start_locked(if_t); | ||||||||
| static void xnb_start(struct ifnet*); | static void xnb_start(if_t); | ||||||||
| static void xnb_ifinit_locked(struct xnb_softc*); | static void xnb_ifinit_locked(struct xnb_softc*); | ||||||||
| static void xnb_ifinit(void*); | static void xnb_ifinit(void*); | ||||||||
| #ifdef XNB_DEBUG | #ifdef XNB_DEBUG | ||||||||
| static int xnb_unit_test_main(SYSCTL_HANDLER_ARGS); | static int xnb_unit_test_main(SYSCTL_HANDLER_ARGS); | ||||||||
| static int xnb_dump_rings(SYSCTL_HANDLER_ARGS); | static int xnb_dump_rings(SYSCTL_HANDLER_ARGS); | ||||||||
| #endif | #endif | ||||||||
| #if defined(INET) || defined(INET6) | #if defined(INET) || defined(INET6) | ||||||||
| static void xnb_add_mbuf_cksum(struct mbuf *mbufc); | static void xnb_add_mbuf_cksum(struct mbuf *mbufc); | ||||||||
| ▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | struct xnb_softc { | ||||||||
| device_t dev; | device_t dev; | ||||||||
| /* Media related fields */ | /* Media related fields */ | ||||||||
| /** Generic network media state */ | /** Generic network media state */ | ||||||||
| struct ifmedia sc_media; | struct ifmedia sc_media; | ||||||||
| /** Media carrier info */ | /** Media carrier info */ | ||||||||
| struct ifnet *xnb_ifp; | if_t xnb_ifp; | ||||||||
ehem_freebsd_m5p.com: Spacing change here. Looks like the line below got de-spaced at some other point. | |||||||||
| /** Our own private carrier state */ | /** Our own private carrier state */ | ||||||||
| unsigned carrier; | unsigned carrier; | ||||||||
| /** Device MAC Address */ | /** Device MAC Address */ | ||||||||
| uint8_t mac[ETHER_ADDR_LEN]; | uint8_t mac[ETHER_ADDR_LEN]; | ||||||||
| /* Xen related fields */ | /* Xen related fields */ | ||||||||
| ▲ Show 20 Lines • Show All 767 Lines • ▼ Show 20 Lines | |||||||||
| /** | /** | ||||||||
| * Create a network device. | * Create a network device. | ||||||||
| * @param handle device handle | * @param handle device handle | ||||||||
| */ | */ | ||||||||
| int | int | ||||||||
| create_netdev(device_t dev) | create_netdev(device_t dev) | ||||||||
| { | { | ||||||||
| struct ifnet *ifp; | if_t ifp; | ||||||||
| struct xnb_softc *xnb; | struct xnb_softc *xnb; | ||||||||
| int err = 0; | int err = 0; | ||||||||
| uint32_t handle; | uint32_t handle; | ||||||||
| xnb = device_get_softc(dev); | xnb = device_get_softc(dev); | ||||||||
| mtx_init(&xnb->sc_lock, "xnb_softc", "xen netback softc lock", MTX_DEF); | mtx_init(&xnb->sc_lock, "xnb_softc", "xen netback softc lock", MTX_DEF); | ||||||||
| mtx_init(&xnb->tx_lock, "xnb_tx", "xen netback tx lock", MTX_DEF); | mtx_init(&xnb->tx_lock, "xnb_tx", "xen netback tx lock", MTX_DEF); | ||||||||
| mtx_init(&xnb->rx_lock, "xnb_rx", "xen netback rx lock", MTX_DEF); | mtx_init(&xnb->rx_lock, "xnb_rx", "xen netback rx lock", MTX_DEF); | ||||||||
| Show All 27 Lines | create_netdev(device_t dev) | ||||||||
| if (err != 0) | if (err != 0) | ||||||||
| return (err); | return (err); | ||||||||
| snprintf(xnb->if_name, IFNAMSIZ, "xnb%" PRIu16 ".%" PRIu32, | snprintf(xnb->if_name, IFNAMSIZ, "xnb%" PRIu16 ".%" PRIu32, | ||||||||
| xenbus_get_otherend_id(dev), handle); | xenbus_get_otherend_id(dev), handle); | ||||||||
| if (err == 0) { | if (err == 0) { | ||||||||
| /* Set up ifnet structure */ | /* Set up ifnet structure */ | ||||||||
| ifp = xnb->xnb_ifp = if_alloc(IFT_ETHER); | ifp = xnb->xnb_ifp = if_alloc(IFT_ETHER); | ||||||||
| ifp->if_softc = xnb; | if_setsoftc(ifp, xnb); | ||||||||
| if_initname(ifp, xnb->if_name, IF_DUNIT_NONE); | if_initname(ifp, xnb->if_name, IF_DUNIT_NONE); | ||||||||
| ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); | ||||||||
| ifp->if_ioctl = xnb_ioctl; | if_setioctlfn(ifp, xnb_ioctl); | ||||||||
| ifp->if_start = xnb_start; | if_setstartfn(ifp, xnb_start); | ||||||||
| ifp->if_init = xnb_ifinit; | if_setinitfn(ifp, xnb_ifinit); | ||||||||
| ifp->if_mtu = ETHERMTU; | if_setmtu(ifp, ETHERMTU); | ||||||||
| ifp->if_snd.ifq_maxlen = NET_RX_RING_SIZE - 1; | if_setsendqlen(ifp, NET_RX_RING_SIZE - 1); | ||||||||
| ifp->if_hwassist = XNB_CSUM_FEATURES; | if_sethwassist(ifp, XNB_CSUM_FEATURES); | ||||||||
| ifp->if_capabilities = IFCAP_HWCSUM; | if_setcapabilities(ifp, IFCAP_HWCSUM); | ||||||||
| ifp->if_capenable = IFCAP_HWCSUM; | if_setcapenable(ifp, IFCAP_HWCSUM); | ||||||||
| ether_ifattach(ifp, xnb->mac); | ether_ifattach(ifp, xnb->mac); | ||||||||
| xnb->carrier = 0; | xnb->carrier = 0; | ||||||||
| } | } | ||||||||
| return err; | return err; | ||||||||
| } | } | ||||||||
| ▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | |||||||||
| * | * | ||||||||
| * \param arg Callback argument registerd during event channel | * \param arg Callback argument registerd during event channel | ||||||||
| * binding - the xnb_softc for this instance. | * binding - the xnb_softc for this instance. | ||||||||
| */ | */ | ||||||||
| static void | static void | ||||||||
| xnb_intr(void *arg) | xnb_intr(void *arg) | ||||||||
| { | { | ||||||||
| struct xnb_softc *xnb; | struct xnb_softc *xnb; | ||||||||
| struct ifnet *ifp; | if_t ifp; | ||||||||
| netif_tx_back_ring_t *txb; | netif_tx_back_ring_t *txb; | ||||||||
| RING_IDX req_prod_local; | RING_IDX req_prod_local; | ||||||||
| xnb = (struct xnb_softc *)arg; | xnb = (struct xnb_softc *)arg; | ||||||||
| ifp = xnb->xnb_ifp; | ifp = xnb->xnb_ifp; | ||||||||
| txb = &xnb->ring_configs[XNB_RING_TYPE_TX].back_ring.tx_ring; | txb = &xnb->ring_configs[XNB_RING_TYPE_TX].back_ring.tx_ring; | ||||||||
| mtx_lock(&xnb->tx_lock); | mtx_lock(&xnb->tx_lock); | ||||||||
| do { | do { | ||||||||
| int notify; | int notify; | ||||||||
| req_prod_local = txb->sring->req_prod; | req_prod_local = txb->sring->req_prod; | ||||||||
| xen_rmb(); | xen_rmb(); | ||||||||
| for (;;) { | for (;;) { | ||||||||
| struct mbuf *mbufc; | struct mbuf *mbufc; | ||||||||
| int err; | int err; | ||||||||
| err = xnb_recv(txb, xnb->otherend_id, &mbufc, ifp, | err = xnb_recv(txb, xnb->otherend_id, &mbufc, ifp, | ||||||||
| xnb->tx_gnttab); | xnb->tx_gnttab); | ||||||||
| if (err || (mbufc == NULL)) | if (err || (mbufc == NULL)) | ||||||||
| break; | break; | ||||||||
| /* Send the packet to the generic network stack */ | /* Send the packet to the generic network stack */ | ||||||||
| (*xnb->xnb_ifp->if_input)(xnb->xnb_ifp, mbufc); | if_input(xnb->xnb_ifp, mbufc); | ||||||||
| } | } | ||||||||
| RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(txb, notify); | RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(txb, notify); | ||||||||
| if (notify != 0) | if (notify != 0) | ||||||||
| xen_intr_signal(xnb->xen_intr_handle); | xen_intr_signal(xnb->xen_intr_handle); | ||||||||
| txb->sring->req_event = txb->req_cons + 1; | txb->sring->req_event = txb->req_cons + 1; | ||||||||
| xen_mb(); | xen_mb(); | ||||||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||||||
| * Create an mbuf chain to represent a packet. Initializes all of the headers | * Create an mbuf chain to represent a packet. Initializes all of the headers | ||||||||
| * in the mbuf chain, but does not copy the data. The returned chain must be | * in the mbuf chain, but does not copy the data. The returned chain must be | ||||||||
| * free()'d when no longer needed | * free()'d when no longer needed | ||||||||
| * \param[in] pkt A packet to model the mbuf chain after | * \param[in] pkt A packet to model the mbuf chain after | ||||||||
| * \return A newly allocated mbuf chain, possibly with clusters attached. | * \return A newly allocated mbuf chain, possibly with clusters attached. | ||||||||
| * NULL on failure | * NULL on failure | ||||||||
| */ | */ | ||||||||
| static struct mbuf* | static struct mbuf* | ||||||||
| xnb_pkt2mbufc(const struct xnb_pkt *pkt, struct ifnet *ifp) | xnb_pkt2mbufc(const struct xnb_pkt *pkt, if_t ifp) | ||||||||
| { | { | ||||||||
| /** | /** | ||||||||
| * \todo consider using a memory pool for mbufs instead of | * \todo consider using a memory pool for mbufs instead of | ||||||||
| * reallocating them for every packet | * reallocating them for every packet | ||||||||
| */ | */ | ||||||||
| /** \todo handle extra data */ | /** \todo handle extra data */ | ||||||||
| struct mbuf *m; | struct mbuf *m; | ||||||||
| ▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | |||||||||
| * networking stack | * networking stack | ||||||||
| * \param[in,out] gnttab Pointer to enough memory for a grant table. We make | * \param[in,out] gnttab Pointer to enough memory for a grant table. We make | ||||||||
| * this a function parameter so that we will take less | * this a function parameter so that we will take less | ||||||||
| * stack space. | * stack space. | ||||||||
| * \return An error code | * \return An error code | ||||||||
| */ | */ | ||||||||
| static int | static int | ||||||||
| xnb_recv(netif_tx_back_ring_t *txb, domid_t otherend, struct mbuf **mbufc, | xnb_recv(netif_tx_back_ring_t *txb, domid_t otherend, struct mbuf **mbufc, | ||||||||
| struct ifnet *ifnet, gnttab_copy_table gnttab) | if_t ifnet, gnttab_copy_table gnttab) | ||||||||
| { | { | ||||||||
| struct xnb_pkt pkt; | struct xnb_pkt pkt; | ||||||||
| /* number of tx requests consumed to build the last packet */ | /* number of tx requests consumed to build the last packet */ | ||||||||
| int num_consumed; | int num_consumed; | ||||||||
| int nr_ents; | int nr_ents; | ||||||||
| *mbufc = NULL; | *mbufc = NULL; | ||||||||
| num_consumed = xnb_ring2pkt(&pkt, txb, txb->req_cons); | num_consumed = xnb_ring2pkt(&pkt, txb, txb->req_cons); | ||||||||
| ▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Lines | default: | ||||||||
| break; | break; | ||||||||
| } | } | ||||||||
| } | } | ||||||||
| #endif /* INET || INET6 */ | #endif /* INET || INET6 */ | ||||||||
| static void | static void | ||||||||
| xnb_stop(struct xnb_softc *xnb) | xnb_stop(struct xnb_softc *xnb) | ||||||||
| { | { | ||||||||
| struct ifnet *ifp; | if_t ifp; | ||||||||
| mtx_assert(&xnb->sc_lock, MA_OWNED); | mtx_assert(&xnb->sc_lock, MA_OWNED); | ||||||||
| ifp = xnb->xnb_ifp; | ifp = xnb->xnb_ifp; | ||||||||
| ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | ||||||||
Not Done Inline ActionsExtra parentheses. ehem_freebsd_m5p.com: Extra parentheses. | |||||||||
| if_link_state_change(ifp, LINK_STATE_DOWN); | if_link_state_change(ifp, LINK_STATE_DOWN); | ||||||||
| } | } | ||||||||
| static int | static int | ||||||||
| xnb_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) | xnb_ioctl(if_t ifp, u_long cmd, caddr_t data) | ||||||||
| { | { | ||||||||
| struct xnb_softc *xnb = ifp->if_softc; | struct xnb_softc *xnb = if_getsoftc(ifp); | ||||||||
| struct ifreq *ifr = (struct ifreq*) data; | struct ifreq *ifr = (struct ifreq*) data; | ||||||||
| #ifdef INET | #ifdef INET | ||||||||
| struct ifaddr *ifa = (struct ifaddr*)data; | struct ifaddr *ifa = (struct ifaddr*)data; | ||||||||
| #endif | #endif | ||||||||
| int error = 0; | int error = 0; | ||||||||
| switch (cmd) { | switch (cmd) { | ||||||||
| case SIOCSIFFLAGS: | case SIOCSIFFLAGS: | ||||||||
| mtx_lock(&xnb->sc_lock); | mtx_lock(&xnb->sc_lock); | ||||||||
| if (ifp->if_flags & IFF_UP) { | if (if_getflags(ifp) & IFF_UP) { | ||||||||
| xnb_ifinit_locked(xnb); | xnb_ifinit_locked(xnb); | ||||||||
| } else { | } else { | ||||||||
| if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { | ||||||||
| xnb_stop(xnb); | xnb_stop(xnb); | ||||||||
| } | } | ||||||||
| } | } | ||||||||
| /* | /* | ||||||||
| * Note: netfront sets a variable named xn_if_flags | * Note: netfront sets a variable named xn_if_flags | ||||||||
| * here, but that variable is never read | * here, but that variable is never read | ||||||||
| */ | */ | ||||||||
| mtx_unlock(&xnb->sc_lock); | mtx_unlock(&xnb->sc_lock); | ||||||||
| break; | break; | ||||||||
| case SIOCSIFADDR: | case SIOCSIFADDR: | ||||||||
| #ifdef INET | #ifdef INET | ||||||||
| mtx_lock(&xnb->sc_lock); | mtx_lock(&xnb->sc_lock); | ||||||||
| if (ifa->ifa_addr->sa_family == AF_INET) { | if (ifa->ifa_addr->sa_family == AF_INET) { | ||||||||
| ifp->if_flags |= IFF_UP; | if_setflagbits(ifp, IFF_UP, 0); | ||||||||
| if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { | ||||||||
| ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | | if_setdrvflagbits(ifp, 0, | ||||||||
| IFF_DRV_OACTIVE); | IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | ||||||||
Not Done Inline ActionsAnother set of extra parentheses. ehem_freebsd_m5p.com: Another set of extra parentheses. | |||||||||
| if_link_state_change(ifp, | if_link_state_change(ifp, | ||||||||
| LINK_STATE_DOWN); | LINK_STATE_DOWN); | ||||||||
| ifp->if_drv_flags |= IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); | ||||||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||||||
| if_link_state_change(ifp, | if_link_state_change(ifp, | ||||||||
| LINK_STATE_UP); | LINK_STATE_UP); | ||||||||
| } | } | ||||||||
| arp_ifinit(ifp, ifa); | arp_ifinit(ifp, ifa); | ||||||||
| mtx_unlock(&xnb->sc_lock); | mtx_unlock(&xnb->sc_lock); | ||||||||
| } else { | } else { | ||||||||
| mtx_unlock(&xnb->sc_lock); | mtx_unlock(&xnb->sc_lock); | ||||||||
| #endif | #endif | ||||||||
| error = ether_ioctl(ifp, cmd, data); | error = ether_ioctl(ifp, cmd, data); | ||||||||
| #ifdef INET | #ifdef INET | ||||||||
| } | } | ||||||||
| #endif | #endif | ||||||||
| break; | break; | ||||||||
| case SIOCSIFCAP: | case SIOCSIFCAP: | ||||||||
| mtx_lock(&xnb->sc_lock); | mtx_lock(&xnb->sc_lock); | ||||||||
| if (ifr->ifr_reqcap & IFCAP_TXCSUM) { | if (ifr->ifr_reqcap & IFCAP_TXCSUM) { | ||||||||
| ifp->if_capenable |= IFCAP_TXCSUM; | if_setcapenablebit(ifp, IFCAP_TXCSUM, 0); | ||||||||
| ifp->if_hwassist |= XNB_CSUM_FEATURES; | if_sethwassistbits(ifp, XNB_CSUM_FEATURES, 0); | ||||||||
| } else { | } else { | ||||||||
| ifp->if_capenable &= ~(IFCAP_TXCSUM); | if_setcapenablebit(ifp, 0, IFCAP_TXCSUM); | ||||||||
| ifp->if_hwassist &= ~(XNB_CSUM_FEATURES); | if_sethwassistbits(ifp, 0, XNB_CSUM_FEATURES); | ||||||||
Done Inline Actions
no need for parenthesis zlei: no need for parenthesis | |||||||||
| } | } | ||||||||
| if ((ifr->ifr_reqcap & IFCAP_RXCSUM)) { | if ((ifr->ifr_reqcap & IFCAP_RXCSUM)) { | ||||||||
| ifp->if_capenable |= IFCAP_RXCSUM; | if_setcapenablebit(ifp, IFCAP_RXCSUM, 0); | ||||||||
| } else { | } else { | ||||||||
| ifp->if_capenable &= ~(IFCAP_RXCSUM); | if_setcapenablebit(ifp, 0, IFCAP_RXCSUM); | ||||||||
Not Done Inline ActionsYet another set of extras. ehem_freebsd_m5p.com: Yet another set of extras. | |||||||||
| } | } | ||||||||
| /* | /* | ||||||||
| * TODO enable TSO4 and LRO once we no longer need | * TODO enable TSO4 and LRO once we no longer need | ||||||||
| * to calculate checksums in software | * to calculate checksums in software | ||||||||
| */ | */ | ||||||||
| #if 0 | #if 0 | ||||||||
| if (ifr->if_reqcap |= IFCAP_TSO4) { | if (ifr->if_reqcap |= IFCAP_TSO4) { | ||||||||
| if (IFCAP_TXCSUM & ifp->if_capenable) { | if (IFCAP_TXCSUM & if_getcapenable(ifp)) { | ||||||||
| printf("xnb: Xen netif requires that " | printf("xnb: Xen netif requires that " | ||||||||
| "TXCSUM be enabled in order " | "TXCSUM be enabled in order " | ||||||||
| "to use TSO4\n"); | "to use TSO4\n"); | ||||||||
| error = EINVAL; | error = EINVAL; | ||||||||
| } else { | } else { | ||||||||
| ifp->if_capenable |= IFCAP_TSO4; | if_setcapenablebit(ifp, IFCAP_TSO4, 0); | ||||||||
| ifp->if_hwassist |= CSUM_TSO; | if_sethwassistbits(ifp, CSUM_TSO, 0); | ||||||||
| } | } | ||||||||
| } else { | } else { | ||||||||
| ifp->if_capenable &= ~(IFCAP_TSO4); | if_setcapenablebit(ifp, 0, IFCAP_TSO4); | ||||||||
| ifp->if_hwassist &= ~(CSUM_TSO); | if_sethwassistbits(ifp, 0, (CSUM_TSO)); | ||||||||
| } | } | ||||||||
Not Done Inline ActionsTwo for the price of one! ehem_freebsd_m5p.com: Two for the price of one! | |||||||||
| if (ifr->ifreqcap |= IFCAP_LRO) { | if (ifr->ifreqcap |= IFCAP_LRO) { | ||||||||
| ifp->if_capenable |= IFCAP_LRO; | if_setcapenablebit(ifp, IFCAP_LRO, 0); | ||||||||
| } else { | } else { | ||||||||
| ifp->if_capenable &= ~(IFCAP_LRO); | if_setcapenablebit(ifp, 0, IFCAP_LRO); | ||||||||
Not Done Inline ActionsLast one. ehem_freebsd_m5p.com: Last one. | |||||||||
| } | } | ||||||||
| #endif | #endif | ||||||||
| mtx_unlock(&xnb->sc_lock); | mtx_unlock(&xnb->sc_lock); | ||||||||
| break; | break; | ||||||||
| case SIOCSIFMTU: | case SIOCSIFMTU: | ||||||||
| ifp->if_mtu = ifr->ifr_mtu; | if_setmtu(ifp, ifr->ifr_mtu); | ||||||||
| ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); | ||||||||
| xnb_ifinit(xnb); | xnb_ifinit(xnb); | ||||||||
| break; | break; | ||||||||
| case SIOCADDMULTI: | case SIOCADDMULTI: | ||||||||
| case SIOCDELMULTI: | case SIOCDELMULTI: | ||||||||
| break; | break; | ||||||||
| case SIOCSIFMEDIA: | case SIOCSIFMEDIA: | ||||||||
| case SIOCGIFMEDIA: | case SIOCGIFMEDIA: | ||||||||
| error = ifmedia_ioctl(ifp, ifr, &xnb->sc_media, cmd); | error = ifmedia_ioctl(ifp, ifr, &xnb->sc_media, cmd); | ||||||||
| break; | break; | ||||||||
| default: | default: | ||||||||
| error = ether_ioctl(ifp, cmd, data); | error = ether_ioctl(ifp, cmd, data); | ||||||||
| break; | break; | ||||||||
| } | } | ||||||||
| return (error); | return (error); | ||||||||
| } | } | ||||||||
| static void | static void | ||||||||
| xnb_start_locked(struct ifnet *ifp) | xnb_start_locked(if_t ifp) | ||||||||
| { | { | ||||||||
| netif_rx_back_ring_t *rxb; | netif_rx_back_ring_t *rxb; | ||||||||
| struct xnb_softc *xnb; | struct xnb_softc *xnb; | ||||||||
| struct mbuf *mbufc; | struct mbuf *mbufc; | ||||||||
| RING_IDX req_prod_local; | RING_IDX req_prod_local; | ||||||||
| xnb = ifp->if_softc; | xnb = if_getsoftc(ifp); | ||||||||
| rxb = &xnb->ring_configs[XNB_RING_TYPE_RX].back_ring.rx_ring; | rxb = &xnb->ring_configs[XNB_RING_TYPE_RX].back_ring.rx_ring; | ||||||||
| if (!xnb->carrier) | if (!xnb->carrier) | ||||||||
| return; | return; | ||||||||
| do { | do { | ||||||||
| int out_of_space = 0; | int out_of_space = 0; | ||||||||
| int notify; | int notify; | ||||||||
| req_prod_local = rxb->sring->req_prod; | req_prod_local = rxb->sring->req_prod; | ||||||||
| xen_rmb(); | xen_rmb(); | ||||||||
| for (;;) { | for (;;) { | ||||||||
| int error; | int error; | ||||||||
| IF_DEQUEUE(&ifp->if_snd, mbufc); | mbufc = if_dequeue(ifp); | ||||||||
| if (mbufc == NULL) | if (mbufc == NULL) | ||||||||
| break; | break; | ||||||||
| error = xnb_send(rxb, xnb->otherend_id, mbufc, | error = xnb_send(rxb, xnb->otherend_id, mbufc, | ||||||||
| xnb->rx_gnttab); | xnb->rx_gnttab); | ||||||||
| switch (error) { | switch (error) { | ||||||||
| case EAGAIN: | case EAGAIN: | ||||||||
| /* | /* | ||||||||
| * Insufficient space in the ring. | * Insufficient space in the ring. | ||||||||
| * Requeue pkt and send when space is | * Requeue pkt and send when space is | ||||||||
| * available. | * available. | ||||||||
| */ | */ | ||||||||
| IF_PREPEND(&ifp->if_snd, mbufc); | if_sendq_prepend(ifp, mbufc); | ||||||||
| /* | /* | ||||||||
| * Perhaps the frontend missed an IRQ | * Perhaps the frontend missed an IRQ | ||||||||
| * and went to sleep. Notify it to wake | * and went to sleep. Notify it to wake | ||||||||
| * it up. | * it up. | ||||||||
| */ | */ | ||||||||
| out_of_space = 1; | out_of_space = 1; | ||||||||
| break; | break; | ||||||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | xnb_send(netif_rx_back_ring_t *ring, domid_t otherend, const struct mbuf *mbufc, | ||||||||
| } | } | ||||||||
| xnb_rxpkt2rsp(&pkt, gnttab, n_entries, ring); | xnb_rxpkt2rsp(&pkt, gnttab, n_entries, ring); | ||||||||
| return 0; | return 0; | ||||||||
| } | } | ||||||||
| static void | static void | ||||||||
| xnb_start(struct ifnet *ifp) | xnb_start(if_t ifp) | ||||||||
| { | { | ||||||||
| struct xnb_softc *xnb; | struct xnb_softc *xnb; | ||||||||
| xnb = ifp->if_softc; | xnb = if_getsoftc(ifp); | ||||||||
| mtx_lock(&xnb->rx_lock); | mtx_lock(&xnb->rx_lock); | ||||||||
| xnb_start_locked(ifp); | xnb_start_locked(ifp); | ||||||||
| mtx_unlock(&xnb->rx_lock); | mtx_unlock(&xnb->rx_lock); | ||||||||
| } | } | ||||||||
| /* equivalent of network_open() in Linux */ | /* equivalent of network_open() in Linux */ | ||||||||
| static void | static void | ||||||||
| xnb_ifinit_locked(struct xnb_softc *xnb) | xnb_ifinit_locked(struct xnb_softc *xnb) | ||||||||
| { | { | ||||||||
| struct ifnet *ifp; | if_t ifp; | ||||||||
| ifp = xnb->xnb_ifp; | ifp = xnb->xnb_ifp; | ||||||||
| mtx_assert(&xnb->sc_lock, MA_OWNED); | mtx_assert(&xnb->sc_lock, MA_OWNED); | ||||||||
| if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) | ||||||||
| return; | return; | ||||||||
| xnb_stop(xnb); | xnb_stop(xnb); | ||||||||
| ifp->if_drv_flags |= IFF_DRV_RUNNING; | if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); | ||||||||
| ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE); | ||||||||
| if_link_state_change(ifp, LINK_STATE_UP); | if_link_state_change(ifp, LINK_STATE_UP); | ||||||||
| } | } | ||||||||
| static void | static void | ||||||||
| xnb_ifinit(void *xsc) | xnb_ifinit(void *xsc) | ||||||||
| { | { | ||||||||
| struct xnb_softc *xnb = xsc; | struct xnb_softc *xnb = xsc; | ||||||||
| mtx_lock(&xnb->sc_lock); | mtx_lock(&xnb->sc_lock); | ||||||||
| xnb_ifinit_locked(xnb); | xnb_ifinit_locked(xnb); | ||||||||
| mtx_unlock(&xnb->sc_lock); | mtx_unlock(&xnb->sc_lock); | ||||||||
| } | } | ||||||||
| /** | /** | ||||||||
| * Callback used by the generic networking code to tell us when our carrier | * Callback used by the generic networking code to tell us when our carrier | ||||||||
| * state has changed. Since we don't have a physical carrier, we don't care | * state has changed. Since we don't have a physical carrier, we don't care | ||||||||
| */ | */ | ||||||||
| static int | static int | ||||||||
| xnb_ifmedia_upd(struct ifnet *ifp) | xnb_ifmedia_upd(if_t ifp) | ||||||||
| { | { | ||||||||
| return (0); | return (0); | ||||||||
| } | } | ||||||||
| /** | /** | ||||||||
| * Callback used by the generic networking code to ask us what our carrier | * Callback used by the generic networking code to ask us what our carrier | ||||||||
| * state is. Since we don't have a physical carrier, this is very simple | * state is. Since we don't have a physical carrier, this is very simple | ||||||||
| */ | */ | ||||||||
| static void | static void | ||||||||
| xnb_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) | xnb_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr) | ||||||||
| { | { | ||||||||
| ifmr->ifm_status = IFM_AVALID|IFM_ACTIVE; | ifmr->ifm_status = IFM_AVALID|IFM_ACTIVE; | ||||||||
| ifmr->ifm_active = IFM_ETHER|IFM_MANUAL; | ifmr->ifm_active = IFM_ETHER|IFM_MANUAL; | ||||||||
| } | } | ||||||||
| /*---------------------------- NewBus Registration ---------------------------*/ | /*---------------------------- NewBus Registration ---------------------------*/ | ||||||||
| static device_method_t xnb_methods[] = { | static device_method_t xnb_methods[] = { | ||||||||
| /* Device interface */ | /* Device interface */ | ||||||||
| Show All 24 Lines | |||||||||
Spacing change here. Looks like the line below got de-spaced at some other point.