Changeset 28761

Show
Ignore:
Timestamp:
12/02/08 12:52:30 (5 weeks ago)
Author:
korli
Message:

* merge current nfe driver from FreeBSD
* now uses the generated miidevs header

Location:
haiku/trunk/src/add-ons/kernel/drivers/network/nforce/dev
Files:
1 removed
4 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/add-ons/kernel/drivers/network/nforce/dev/mii/Jamfile

    r23124 r28761  
    1414        ukphy_subr.c 
    1515        ; 
     16 
     17ObjectHdrs [ FGristFiles ciphy$(SUFOBJ) ] 
     18        : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR) libs compat freebsd_network ] ; 
     19Includes [ FGristFiles ciphy.c ] : <src!libs!compat!freebsd_network>miidevs.h ; 
  • haiku/trunk/src/add-ons/kernel/drivers/network/nforce/dev/nfe/if_nfe.c

    r23124 r28761  
    2222 
    2323#include <sys/cdefs.h> 
    24 __FBSDID("$FreeBSD: src/sys/dev/nfe/if_nfe.c,v 1.21 2007/09/14 05:12:25 yongari Exp $"); 
     24__FBSDID("$FreeBSD: src/sys/dev/nfe/if_nfe.c,v 1.30 2008/10/03 03:58:16 yongari Exp $"); 
    2525 
    2626#ifdef HAVE_KERNEL_OPTION_HEADERS 
     
    7777static int  nfe_suspend(device_t); 
    7878static int  nfe_resume(device_t); 
    79 static void nfe_shutdown(device_t); 
     79static int nfe_shutdown(device_t); 
    8080static void nfe_power(struct nfe_softc *); 
    8181static int  nfe_miibus_readreg(device_t, int, int); 
     
    9090static int nfe_intr(void *); 
    9191static void nfe_int_task(void *, int); 
    92 static void *nfe_jalloc(struct nfe_softc *); 
    93 static void nfe_jfree(void *, void *); 
    9492static __inline void nfe_discard_rxbuf(struct nfe_softc *, int); 
    9593static __inline void nfe_discard_jrxbuf(struct nfe_softc *, int); 
     
    9997static int  nfe_jrxeof(struct nfe_softc *, int); 
    10098static void nfe_txeof(struct nfe_softc *); 
    101 static struct mbuf *nfe_defrag(struct mbuf *, int, int); 
    10299static int  nfe_encap(struct nfe_softc *, struct mbuf **); 
    103100static void nfe_setmulti(struct nfe_softc *); 
     
    126123static int sysctl_int_range(SYSCTL_HANDLER_ARGS, int, int); 
    127124static int sysctl_hw_nfe_proc_limit(SYSCTL_HANDLER_ARGS); 
     125static void nfe_sysctl_node(struct nfe_softc *); 
     126static void nfe_stats_clear(struct nfe_softc *); 
     127static void nfe_stats_update(struct nfe_softc *); 
    128128 
    129129#ifdef NFE_DEBUG 
     
    145145#define NFE_UNLOCK(_sc)         mtx_unlock(&(_sc)->nfe_mtx) 
    146146#define NFE_LOCK_ASSERT(_sc)    mtx_assert(&(_sc)->nfe_mtx, MA_OWNED) 
    147  
    148 #define NFE_JLIST_LOCK(_sc)     mtx_lock(&(_sc)->nfe_jlist_mtx) 
    149 #define NFE_JLIST_UNLOCK(_sc)   mtx_unlock(&(_sc)->nfe_jlist_mtx) 
    150147 
    151148/* Tunables. */ 
     
    244241        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP67_LAN4, 
    245242            "NVIDIA nForce MCP67 Networking Adapter"}, 
     243        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP73_LAN1, 
     244            "NVIDIA nForce MCP73 Networking Adapter"}, 
     245        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP73_LAN2, 
     246            "NVIDIA nForce MCP73 Networking Adapter"}, 
     247        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP73_LAN3, 
     248            "NVIDIA nForce MCP73 Networking Adapter"}, 
     249        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP73_LAN4, 
     250            "NVIDIA nForce MCP73 Networking Adapter"}, 
     251        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP77_LAN1, 
     252            "NVIDIA nForce MCP77 Networking Adapter"}, 
     253        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP77_LAN2, 
     254            "NVIDIA nForce MCP77 Networking Adapter"}, 
     255        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP77_LAN3, 
     256            "NVIDIA nForce MCP77 Networking Adapter"}, 
     257        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP77_LAN4, 
     258            "NVIDIA nForce MCP77 Networking Adapter"}, 
     259        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP79_LAN1, 
     260            "NVIDIA nForce MCP79 Networking Adapter"}, 
     261        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP79_LAN2, 
     262            "NVIDIA nForce MCP79 Networking Adapter"}, 
     263        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP79_LAN3, 
     264            "NVIDIA nForce MCP79 Networking Adapter"}, 
     265        {PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_MCP79_LAN4, 
     266            "NVIDIA nForce MCP79 Networking Adapter"}, 
    246267        {0, 0, NULL} 
    247268}; 
     
    327348        mtx_init(&sc->nfe_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 
    328349            MTX_DEF); 
    329         mtx_init(&sc->nfe_jlist_mtx, "nfe_jlist_mtx", NULL, MTX_DEF); 
    330350        callout_init_mtx(&sc->nfe_stat_ch, &sc->nfe_mtx, 0); 
    331351        TASK_INIT(&sc->nfe_link_task, 0, nfe_link_task, sc); 
    332         SLIST_INIT(&sc->nfe_jfree_listhead); 
    333         SLIST_INIT(&sc->nfe_jinuse_listhead); 
    334352 
    335353        pci_enable_busmaster(dev); 
     
    440458        case PCI_PRODUCT_NVIDIA_MCP51_LAN1: 
    441459        case PCI_PRODUCT_NVIDIA_MCP51_LAN2: 
    442                 sc->nfe_flags |= NFE_40BIT_ADDR | NFE_PWR_MGMT; 
     460                sc->nfe_flags |= NFE_40BIT_ADDR | NFE_PWR_MGMT | NFE_MIB_V1; 
    443461                break; 
    444462        case PCI_PRODUCT_NVIDIA_CK804_LAN1: 
     
    446464        case PCI_PRODUCT_NVIDIA_MCP04_LAN1: 
    447465        case PCI_PRODUCT_NVIDIA_MCP04_LAN2: 
    448                 sc->nfe_flags |= NFE_JUMBO_SUP | NFE_40BIT_ADDR | NFE_HW_CSUM; 
     466                sc->nfe_flags |= NFE_JUMBO_SUP | NFE_40BIT_ADDR | NFE_HW_CSUM | 
     467                    NFE_MIB_V1; 
    449468                break; 
    450469        case PCI_PRODUCT_NVIDIA_MCP55_LAN1: 
    451470        case PCI_PRODUCT_NVIDIA_MCP55_LAN2: 
    452471                sc->nfe_flags |= NFE_JUMBO_SUP | NFE_40BIT_ADDR | NFE_HW_CSUM | 
    453                     NFE_HW_VLAN | NFE_PWR_MGMT | NFE_TX_FLOW_CTRL; 
     472                    NFE_HW_VLAN | NFE_PWR_MGMT | NFE_TX_FLOW_CTRL | NFE_MIB_V2; 
    454473                break; 
    455474 
     
    462481        case PCI_PRODUCT_NVIDIA_MCP67_LAN3: 
    463482        case PCI_PRODUCT_NVIDIA_MCP67_LAN4: 
     483        case PCI_PRODUCT_NVIDIA_MCP73_LAN1: 
     484        case PCI_PRODUCT_NVIDIA_MCP73_LAN2: 
     485        case PCI_PRODUCT_NVIDIA_MCP73_LAN3: 
     486        case PCI_PRODUCT_NVIDIA_MCP73_LAN4: 
    464487                sc->nfe_flags |= NFE_40BIT_ADDR | NFE_PWR_MGMT | 
    465                     NFE_TX_FLOW_CTRL; 
     488                    NFE_CORRECT_MACADDR | NFE_TX_FLOW_CTRL | NFE_MIB_V2; 
     489                break; 
     490        case PCI_PRODUCT_NVIDIA_MCP77_LAN1: 
     491        case PCI_PRODUCT_NVIDIA_MCP77_LAN2: 
     492        case PCI_PRODUCT_NVIDIA_MCP77_LAN3: 
     493        case PCI_PRODUCT_NVIDIA_MCP77_LAN4: 
     494                /* XXX flow control */ 
     495                sc->nfe_flags |= NFE_40BIT_ADDR | NFE_HW_CSUM | NFE_PWR_MGMT | 
     496                    NFE_CORRECT_MACADDR | NFE_MIB_V3; 
     497                break; 
     498        case PCI_PRODUCT_NVIDIA_MCP79_LAN1: 
     499        case PCI_PRODUCT_NVIDIA_MCP79_LAN2: 
     500        case PCI_PRODUCT_NVIDIA_MCP79_LAN3: 
     501        case PCI_PRODUCT_NVIDIA_MCP79_LAN4: 
     502                /* XXX flow control */ 
     503                sc->nfe_flags |= NFE_JUMBO_SUP | NFE_40BIT_ADDR | NFE_HW_CSUM | 
     504                    NFE_PWR_MGMT | NFE_CORRECT_MACADDR | NFE_MIB_V3; 
    466505                break; 
    467506        case PCI_PRODUCT_NVIDIA_MCP65_LAN1: 
     
    470509        case PCI_PRODUCT_NVIDIA_MCP65_LAN4: 
    471510                sc->nfe_flags |= NFE_JUMBO_SUP | NFE_40BIT_ADDR | 
    472                     NFE_PWR_MGMT | NFE_TX_FLOW_CTRL; 
     511                    NFE_PWR_MGMT | NFE_CORRECT_MACADDR | NFE_TX_FLOW_CTRL | 
     512                    NFE_MIB_V2; 
    473513                break; 
    474514        } 
     
    517557 
    518558        nfe_alloc_jrx_ring(sc, &sc->jrxq); 
    519  
    520         SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 
    521             SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 
    522             OID_AUTO, "process_limit", CTLTYPE_INT | CTLFLAG_RW, 
    523             &sc->nfe_process_limit, 0, sysctl_hw_nfe_proc_limit, "I", 
    524             "max number of Rx events to process"); 
    525  
    526         sc->nfe_process_limit = NFE_PROC_DEFAULT; 
    527         error = resource_int_value(device_get_name(dev), device_get_unit(dev), 
    528             "process_limit", &sc->nfe_process_limit); 
    529         if (error == 0) { 
    530                 if (sc->nfe_process_limit < NFE_PROC_MIN || 
    531                     sc->nfe_process_limit > NFE_PROC_MAX) { 
    532                         device_printf(dev, "process_limit value out of range; " 
    533                             "using default: %d\n", NFE_PROC_DEFAULT); 
    534                         sc->nfe_process_limit = NFE_PROC_DEFAULT; 
    535                 } 
    536         } 
     559        /* Create sysctl node. */ 
     560        nfe_sysctl_node(sc); 
    537561 
    538562        ifp->if_softc = sc; 
     
    715739        } 
    716740 
    717         mtx_destroy(&sc->nfe_jlist_mtx); 
    718741        mtx_destroy(&sc->nfe_mtx); 
    719742 
     
    9831006} 
    9841007 
    985 /* 
    986  * Allocate a jumbo buffer. 
    987  */ 
    988 static void * 
    989 nfe_jalloc(struct nfe_softc *sc) 
    990 { 
    991         struct nfe_jpool_entry *entry; 
    992  
    993         NFE_JLIST_LOCK(sc); 
    994  
    995         entry = SLIST_FIRST(&sc->nfe_jfree_listhead); 
    996  
    997         if (entry == NULL) { 
    998                 NFE_JLIST_UNLOCK(sc); 
    999                 return (NULL); 
    1000         } 
    1001  
    1002         SLIST_REMOVE_HEAD(&sc->nfe_jfree_listhead, jpool_entries); 
    1003         SLIST_INSERT_HEAD(&sc->nfe_jinuse_listhead, entry, jpool_entries); 
    1004  
    1005         NFE_JLIST_UNLOCK(sc); 
    1006  
    1007         return (sc->jrxq.jslots[entry->slot]); 
    1008 } 
    1009  
    1010 /* 
    1011  * Release a jumbo buffer. 
    1012  */ 
    1013 static void 
    1014 nfe_jfree(void *buf, void *args) 
    1015 { 
    1016         struct nfe_softc *sc; 
    1017         struct nfe_jpool_entry *entry; 
    1018         int i; 
    1019  
    1020         /* Extract the softc struct pointer. */ 
    1021         sc = (struct nfe_softc *)args; 
    1022         KASSERT(sc != NULL, ("%s: can't find softc pointer!", __func__)); 
    1023  
    1024         NFE_JLIST_LOCK(sc); 
    1025         /* Calculate the slot this buffer belongs to. */ 
    1026         i = ((vm_offset_t)buf 
    1027              - (vm_offset_t)sc->jrxq.jpool) / NFE_JLEN; 
    1028         KASSERT(i >= 0 && i < NFE_JSLOTS, 
    1029             ("%s: asked to free buffer that we don't manage!", __func__)); 
    1030  
    1031         entry = SLIST_FIRST(&sc->nfe_jinuse_listhead); 
    1032         KASSERT(entry != NULL, ("%s: buffer not in use!", __func__)); 
    1033         entry->slot = i; 
    1034         SLIST_REMOVE_HEAD(&sc->nfe_jinuse_listhead, jpool_entries); 
    1035         SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, jpool_entries); 
    1036         if (SLIST_EMPTY(&sc->nfe_jinuse_listhead)) 
    1037                 wakeup(sc); 
    1038  
    1039         NFE_JLIST_UNLOCK(sc); 
    1040 } 
    1041  
    10421008struct nfe_dmamap_arg { 
    10431009        bus_addr_t nfe_busaddr; 
     
    11481114        struct nfe_rx_data *data; 
    11491115        void *desc; 
    1150         struct nfe_jpool_entry *entry; 
    1151         uint8_t *ptr; 
    11521116        int i, error, descsize; 
    11531117 
     
    11881152        } 
    11891153 
    1190         /* Create DMA tag for jumbo buffer blocks. */ 
    1191         error = bus_dma_tag_create(sc->nfe_parent_tag, 
    1192             PAGE_SIZE, 0,                       /* alignment, boundary */ 
    1193             BUS_SPACE_MAXADDR,                  /* lowaddr */ 
    1194             BUS_SPACE_MAXADDR,                  /* highaddr */ 
    1195             NULL, NULL,                         /* filter, filterarg */ 
    1196             NFE_JMEM,                           /* maxsize */ 
    1197             1,                                  /* nsegments */ 
    1198             NFE_JMEM,                           /* maxsegsize */ 
    1199             0,                                  /* flags */ 
    1200             NULL, NULL,                         /* lockfunc, lockarg */ 
    1201             &ring->jrx_jumbo_tag); 
    1202         if (error != 0) { 
    1203                 device_printf(sc->nfe_dev, 
    1204                     "could not create jumbo Rx buffer block DMA tag\n"); 
    1205                 goto fail; 
    1206         } 
    1207  
    12081154        /* Create DMA tag for jumbo Rx buffers. */ 
    12091155        error = bus_dma_tag_create(sc->nfe_parent_tag, 
     
    12121158            BUS_SPACE_MAXADDR,                  /* highaddr */ 
    12131159            NULL, NULL,                         /* filter, filterarg */ 
    1214             NFE_JLEN,                           /* maxsize */ 
     1160            MJUM9BYTES,                         /* maxsize */ 
    12151161            1,                                  /* nsegments */ 
    1216             NFE_JLEN,                           /* maxsegsize */ 
     1162            MJUM9BYTES,                         /* maxsegsize */ 
    12171163            0,                                  /* flags */ 
    12181164            NULL, NULL,                         /* lockfunc, lockarg */ 
     
    12681214        } 
    12691215 
    1270         /* Allocate DMA'able memory and load the DMA map for jumbo buf. */ 
    1271         error = bus_dmamem_alloc(ring->jrx_jumbo_tag, (void **)&ring->jpool, 
    1272             BUS_DMA_WAITOK | BUS_DMA_COHERENT | BUS_DMA_ZERO, 
    1273             &ring->jrx_jumbo_map); 
    1274         if (error != 0) { 
    1275                 device_printf(sc->nfe_dev, 
    1276                     "could not allocate DMA'able memory for jumbo pool\n"); 
    1277                 goto fail; 
    1278         } 
    1279  
    1280         ctx.nfe_busaddr = 0; 
    1281         error = bus_dmamap_load(ring->jrx_jumbo_tag, ring->jrx_jumbo_map, 
    1282             ring->jpool, NFE_JMEM, nfe_dma_map_segs, &ctx, 0); 
    1283         if (error != 0) { 
    1284                 device_printf(sc->nfe_dev, 
    1285                     "could not load DMA'able memory for jumbo pool\n"); 
    1286                 goto fail; 
    1287         } 
    1288  
    1289         /* 
    1290          * Now divide it up into 9K pieces and save the addresses 
    1291          * in an array. 
    1292          */ 
    1293         ptr = ring->jpool; 
    1294         for (i = 0; i < NFE_JSLOTS; i++) { 
    1295                 ring->jslots[i] = ptr; 
    1296                 ptr += NFE_JLEN; 
    1297                 entry = malloc(sizeof(struct nfe_jpool_entry), M_DEVBUF, 
    1298                     M_WAITOK); 
    1299                 if (entry == NULL) { 
    1300                         device_printf(sc->nfe_dev, 
    1301                             "no memory for jumbo buffers!\n"); 
    1302                         error = ENOMEM; 
    1303                         goto fail; 
    1304                 } 
    1305                 entry->slot = i; 
    1306                 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, 
    1307                     jpool_entries); 
    1308         } 
    1309  
    13101216        return; 
    13111217 
     
    13651271                descsize = sizeof (struct nfe_desc32); 
    13661272        } 
    1367         bzero(desc, descsize * NFE_RX_RING_COUNT); 
     1273        bzero(desc, descsize * NFE_JUMBO_RX_RING_COUNT); 
    13681274        for (i = 0; i < NFE_JUMBO_RX_RING_COUNT; i++) { 
    13691275                if (nfe_jnewbuf(sc, i) != 0) 
     
    14321338nfe_free_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring) 
    14331339{ 
    1434         struct nfe_jpool_entry *entry; 
    14351340        struct nfe_rx_data *data; 
    14361341        void *desc; 
     
    14391344        if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0) 
    14401345                return; 
    1441  
    1442         NFE_JLIST_LOCK(sc); 
    1443         while ((entry = SLIST_FIRST(&sc->nfe_jinuse_listhead))) { 
    1444                 device_printf(sc->nfe_dev, 
    1445                     "asked to free buffer that is in use!\n"); 
    1446                 SLIST_REMOVE_HEAD(&sc->nfe_jinuse_listhead, jpool_entries); 
    1447                 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, 
    1448                     jpool_entries); 
    1449         } 
    1450  
    1451         while (!SLIST_EMPTY(&sc->nfe_jfree_listhead)) { 
    1452                 entry = SLIST_FIRST(&sc->nfe_jfree_listhead); 
    1453                 SLIST_REMOVE_HEAD(&sc->nfe_jfree_listhead, jpool_entries); 
    1454                 free(entry, M_DEVBUF); 
    1455         } 
    1456         NFE_JLIST_UNLOCK(sc); 
    14571346 
    14581347        if (sc->nfe_flags & NFE_40BIT_ADDR) { 
     
    14931382                ring->jrx_desc_map = NULL; 
    14941383        } 
    1495         /* Destroy jumbo buffer block. */ 
    1496         if (ring->jrx_jumbo_map != NULL) 
    1497                 bus_dmamap_unload(ring->jrx_jumbo_tag, ring->jrx_jumbo_map); 
    1498         if (ring->jrx_jumbo_map != NULL) { 
    1499                 bus_dmamem_free(ring->jrx_jumbo_tag, ring->jpool, 
    1500                     ring->jrx_jumbo_map); 
    1501                 ring->jpool = NULL; 
    1502                 ring->jrx_jumbo_map = NULL; 
    1503         } 
     1384 
    15041385        if (ring->jrx_desc_tag != NULL) { 
    15051386                bus_dma_tag_destroy(ring->jrx_desc_tag); 
     
    16901571        nfe_txeof(sc); 
    16911572        if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 
    1692                 taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_tx_task); 
     1573                taskqueue_enqueue_fast(sc->nfe_tq, &sc->nfe_tx_task); 
    16931574 
    16941575        if (cmd == POLL_AND_CHECK_STATUS) { 
     
    18991780                return (FILTER_STRAY); 
    19001781        nfe_disable_intr(sc); 
    1901         taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_int_task); 
     1782        taskqueue_enqueue_fast(sc->nfe_tq, &sc->nfe_int_task); 
    19021783 
    19031784        return (FILTER_HANDLED); 
     
    19531834 
    19541835        if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 
    1955                 taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_tx_task); 
     1836                taskqueue_enqueue_fast(sc->nfe_tq, &sc->nfe_tx_task); 
    19561837 
    19571838        NFE_UNLOCK(sc); 
    19581839 
    19591840        if (domore || (NFE_READ(sc, sc->nfe_irq_status) != 0)) { 
    1960                 taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_int_task); 
     1841                taskqueue_enqueue_fast(sc->nfe_tq, &sc->nfe_int_task); 
    19611842                return; 
    19621843        } 
     
    20851966        bus_dmamap_t map; 
    20861967        int nsegs; 
    2087         void *buf; 
    2088  
    2089         MGETHDR(m, M_DONTWAIT, MT_DATA); 
     1968 
     1969        m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, MJUM9BYTES); 
    20901970        if (m == NULL) 
    20911971                return (ENOBUFS); 
    2092         buf = nfe_jalloc(sc); 
    2093         if (buf == NULL) { 
    2094                 m_freem(m); 
    2095                 return (ENOBUFS); 
    2096         } 
    2097         /* Attach the buffer to the mbuf. */ 
    2098         MEXTADD(m, buf, NFE_JLEN, nfe_jfree, (struct nfe_softc *)sc, 0, 
    2099             EXT_NET_DRV); 
    21001972        if ((m->m_flags & M_EXT) == 0) { 
    21011973                m_freem(m); 
    21021974                return (ENOBUFS); 
    21031975        } 
    2104         m->m_pkthdr.len = m->m_len = NFE_JLEN; 
     1976        m->m_pkthdr.len = m->m_len = MJUM9BYTES; 
    21051977        m_adj(m, ETHER_ALIGN); 
    21061978 
     
    24382310} 
    24392311 
    2440 /* 
    2441  * It's copy of ath_defrag(ath(4)). 
    2442  * 
    2443  * Defragment an mbuf chain, returning at most maxfrags separate 
    2444  * mbufs+clusters.  If this is not possible NULL is returned and 
    2445  * the original mbuf chain is left in it's present (potentially 
    2446  * modified) state.  We use two techniques: collapsing consecutive 
    2447  * mbufs and replacing consecutive mbufs by a cluster. 
    2448  */ 
    2449 static struct mbuf * 
    2450 nfe_defrag(struct mbuf *m0, int how, int maxfrags) 
    2451 { 
    2452         struct mbuf *m, *n, *n2, **prev; 
    2453         u_int curfrags; 
    2454  
    2455         /* 
    2456          * Calculate the current number of frags. 
    2457          */ 
    2458         curfrags = 0; 
    2459         for (m = m0; m != NULL; m = m->m_next) 
    2460                 curfrags++; 
    2461         /* 
    2462          * First, try to collapse mbufs.  Note that we always collapse 
    2463          * towards the front so we don't need to deal with moving the 
    2464          * pkthdr.  This may be suboptimal if the first mbuf has much 
    2465          * less data than the following. 
    2466          */ 
    2467         m = m0; 
    2468 again: 
    2469         for (;;) { 
    2470                 n = m->m_next; 
    2471                 if (n == NULL) 
    2472                         break; 
    2473                 if ((m->m_flags & M_RDONLY) == 0 && 
    2474                     n->m_len < M_TRAILINGSPACE(m)) { 
    2475                         bcopy(mtod(n, void *), mtod(m, char *) + m->m_len, 
    2476                                 n->m_len); 
    2477                         m->m_len += n->m_len; 
    2478                         m->m_next = n->m_next; 
    2479                         m_free(n); 
    2480                         if (--curfrags <= maxfrags) 
    2481                                 return (m0); 
    2482                 } else 
    2483                         m = n; 
    2484         } 
    2485         KASSERT(maxfrags > 1, 
    2486                 ("maxfrags %u, but normal collapse failed", maxfrags)); 
    2487         /* 
    2488          * Collapse consecutive mbufs to a cluster. 
    2489          */ 
    2490         prev = &m0->m_next;             /* NB: not the first mbuf */ 
    2491         while ((n = *prev) != NULL) { 
    2492                 if ((n2 = n->m_next) != NULL && 
    2493                     n->m_len + n2->m_len < MCLBYTES) { 
    2494                         m = m_getcl(how, MT_DATA, 0); 
    2495                         if (m == NULL) 
    2496                                 goto bad; 
    2497                         bcopy(mtod(n, void *), mtod(m, void *), n->m_len); 
    2498                         bcopy(mtod(n2, void *), mtod(m, char *) + n->m_len, 
    2499                                 n2->m_len); 
    2500                         m->m_len = n->m_len + n2->m_len; 
    2501                         m->m_next = n2->m_next; 
    2502                         *prev = m; 
    2503                         m_free(n); 
    2504                         m_free(n2); 
    2505                         if (--curfrags <= maxfrags)     /* +1 cl -2 mbufs */ 
    2506                                 return m0; 
    2507                         /* 
    2508                          * Still not there, try the normal collapse 
    2509                          * again before we allocate another cluster. 
    2510                          */ 
    2511                         goto again; 
    2512                 } 
    2513                 prev = &n->m_next; 
    2514         } 
    2515         /* 
    2516          * No place where we can collapse to a cluster; punt. 
    2517          * This can occur if, for example, you request 2 frags 
    2518          * but the packet requires that both be clusters (we 
    2519          * never reallocate the first mbuf to avoid moving the 
    2520          * packet header). 
    2521          */ 
    2522 bad: 
    2523         return (NULL); 
    2524 } 
    2525  
    2526  
    25272312static int 
    25282313nfe_encap(struct nfe_softc *sc, struct mbuf **m_head) 
     
    25432328            &nsegs, BUS_DMA_NOWAIT); 
    25442329        if (error == EFBIG) { 
    2545                 m = nfe_defrag(*m_head, M_DONTWAIT, NFE_MAX_SCATTER); 
     2330                m = m_collapse(*m_head, M_DONTWAIT, NFE_MAX_SCATTER); 
    25462331                if (m == NULL) { 
    25472332                        m_freem(*m_head); 
     
    28092594                    "-- recovering\n"); 
    28102595                if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 
    2811                         taskqueue_enqueue_fast(taskqueue_fast, 
    2812                             &sc->nfe_tx_task); 
     2596                        taskqueue_enqueue_fast(sc->nfe_tq, &sc->nfe_tx_task); 
    28132597                return; 
    28142598        } 
     
    29722756 
    29732757        NFE_WRITE(sc, NFE_PHY_STATUS, 0xf); 
     2758 
     2759        /* Clear hardware stats. */ 
     2760        nfe_stats_clear(sc); 
    29742761 
    29752762#ifdef DEVICE_POLLING 
     
    30612848                } 
    30622849        } 
     2850        /* Update hardware stats. */ 
     2851        nfe_stats_update(sc); 
    30632852} 
    30642853 
     
    31122901        mii = device_get_softc(sc->nfe_miibus); 
    31132902        mii_tick(mii); 
     2903        nfe_stats_update(sc); 
    31142904        nfe_watchdog(ifp); 
    31152905        callout_reset(&sc->nfe_stat_ch, hz, nfe_tick, sc); 
     
    31172907 
    31182908 
    3119 static void 
     2909static int 
    31202910nfe_shutdown(device_t dev) 
    31212911{ 
     
    31302920        /* nfe_reset(sc); */ 
    31312921        NFE_UNLOCK(sc); 
     2922 
     2923        return (0); 
    31322924} 
    31332925 
     
    32173009            NFE_PROC_MAX)); 
    32183010} 
     3011 
     3012 
     3013#define NFE_SYSCTL_STAT_ADD32(c, h, n, p, d)    \ 
     3014            SYSCTL_ADD_UINT(c, h, OID_AUTO, n, CTLFLAG_RD, p, 0, d) 
     3015#define NFE_SYSCTL_STAT_ADD64(c, h, n, p, d)    \ 
     3016            SYSCTL_ADD_QUAD(c, h, OID_AUTO, n, CTLFLAG_RD, p, d) 
     3017