Deleted Added
full compact
if_nfe.c (175872) if_nfe.c (176859)
1/* $OpenBSD: if_nfe.c,v 1.54 2006/04/07 12:38:12 jsg Exp $ */
2
3/*-
4 * Copyright (c) 2006 Shigeaki Tagashira <shigeaki@se.hiroshima-u.ac.jp>
5 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
6 * Copyright (c) 2005, 2006 Jonathan Gray <jsg@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any

--- 7 unchanged lines hidden (view full) ---

16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/* Driver for NVIDIA nForce MCP Fast Ethernet and Gigabit Ethernet */
22
23#include <sys/cdefs.h>
1/* $OpenBSD: if_nfe.c,v 1.54 2006/04/07 12:38:12 jsg Exp $ */
2
3/*-
4 * Copyright (c) 2006 Shigeaki Tagashira <shigeaki@se.hiroshima-u.ac.jp>
5 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
6 * Copyright (c) 2005, 2006 Jonathan Gray <jsg@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any

--- 7 unchanged lines hidden (view full) ---

16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/* Driver for NVIDIA nForce MCP Fast Ethernet and Gigabit Ethernet */
22
23#include <sys/cdefs.h>
24__FBSDID("$FreeBSD: head/sys/dev/nfe/if_nfe.c 175872 2008-02-01 19:36:27Z phk $");
24__FBSDID("$FreeBSD: head/sys/dev/nfe/if_nfe.c 176859 2008-03-06 01:47:53Z yongari $");
25
26#ifdef HAVE_KERNEL_OPTION_HEADERS
27#include "opt_device_polling.h"
28#endif
29
30#include <sys/param.h>
31#include <sys/endian.h>
32#include <sys/systm.h>

--- 51 unchanged lines hidden (view full) ---

84static void nfe_link_task(void *, int);
85static void nfe_set_intr(struct nfe_softc *);
86static __inline void nfe_enable_intr(struct nfe_softc *);
87static __inline void nfe_disable_intr(struct nfe_softc *);
88static int nfe_ioctl(struct ifnet *, u_long, caddr_t);
89static void nfe_alloc_msix(struct nfe_softc *, int);
90static int nfe_intr(void *);
91static void nfe_int_task(void *, int);
25
26#ifdef HAVE_KERNEL_OPTION_HEADERS
27#include "opt_device_polling.h"
28#endif
29
30#include <sys/param.h>
31#include <sys/endian.h>
32#include <sys/systm.h>

--- 51 unchanged lines hidden (view full) ---

84static void nfe_link_task(void *, int);
85static void nfe_set_intr(struct nfe_softc *);
86static __inline void nfe_enable_intr(struct nfe_softc *);
87static __inline void nfe_disable_intr(struct nfe_softc *);
88static int nfe_ioctl(struct ifnet *, u_long, caddr_t);
89static void nfe_alloc_msix(struct nfe_softc *, int);
90static int nfe_intr(void *);
91static void nfe_int_task(void *, int);
92static void *nfe_jalloc(struct nfe_softc *);
93static void nfe_jfree(void *, void *);
94static __inline void nfe_discard_rxbuf(struct nfe_softc *, int);
95static __inline void nfe_discard_jrxbuf(struct nfe_softc *, int);
96static int nfe_newbuf(struct nfe_softc *, int);
97static int nfe_jnewbuf(struct nfe_softc *, int);
98static int nfe_rxeof(struct nfe_softc *, int);
99static int nfe_jrxeof(struct nfe_softc *, int);
100static void nfe_txeof(struct nfe_softc *);
101static int nfe_encap(struct nfe_softc *, struct mbuf **);

--- 37 unchanged lines hidden (view full) ---

139#define DPRINTF(sc, ...)
140#define DPRINTFN(sc, n, ...)
141#endif
142
143#define NFE_LOCK(_sc) mtx_lock(&(_sc)->nfe_mtx)
144#define NFE_UNLOCK(_sc) mtx_unlock(&(_sc)->nfe_mtx)
145#define NFE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->nfe_mtx, MA_OWNED)
146
92static __inline void nfe_discard_rxbuf(struct nfe_softc *, int);
93static __inline void nfe_discard_jrxbuf(struct nfe_softc *, int);
94static int nfe_newbuf(struct nfe_softc *, int);
95static int nfe_jnewbuf(struct nfe_softc *, int);
96static int nfe_rxeof(struct nfe_softc *, int);
97static int nfe_jrxeof(struct nfe_softc *, int);
98static void nfe_txeof(struct nfe_softc *);
99static int nfe_encap(struct nfe_softc *, struct mbuf **);

--- 37 unchanged lines hidden (view full) ---

137#define DPRINTF(sc, ...)
138#define DPRINTFN(sc, n, ...)
139#endif
140
141#define NFE_LOCK(_sc) mtx_lock(&(_sc)->nfe_mtx)
142#define NFE_UNLOCK(_sc) mtx_unlock(&(_sc)->nfe_mtx)
143#define NFE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->nfe_mtx, MA_OWNED)
144
147#define NFE_JLIST_LOCK(_sc) mtx_lock(&(_sc)->nfe_jlist_mtx)
148#define NFE_JLIST_UNLOCK(_sc) mtx_unlock(&(_sc)->nfe_jlist_mtx)
149
150/* Tunables. */
151static int msi_disable = 0;
152static int msix_disable = 0;
153static int jumbo_disable = 0;
154TUNABLE_INT("hw.nfe.msi_disable", &msi_disable);
155TUNABLE_INT("hw.nfe.msix_disable", &msix_disable);
156TUNABLE_INT("hw.nfe.jumbo_disable", &jumbo_disable);
157

--- 162 unchanged lines hidden (view full) ---

320 bus_addr_t dma_addr_max;
321 int error = 0, i, msic, reg, rid;
322
323 sc = device_get_softc(dev);
324 sc->nfe_dev = dev;
325
326 mtx_init(&sc->nfe_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
327 MTX_DEF);
145/* Tunables. */
146static int msi_disable = 0;
147static int msix_disable = 0;
148static int jumbo_disable = 0;
149TUNABLE_INT("hw.nfe.msi_disable", &msi_disable);
150TUNABLE_INT("hw.nfe.msix_disable", &msix_disable);
151TUNABLE_INT("hw.nfe.jumbo_disable", &jumbo_disable);
152

--- 162 unchanged lines hidden (view full) ---

315 bus_addr_t dma_addr_max;
316 int error = 0, i, msic, reg, rid;
317
318 sc = device_get_softc(dev);
319 sc->nfe_dev = dev;
320
321 mtx_init(&sc->nfe_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
322 MTX_DEF);
328 mtx_init(&sc->nfe_jlist_mtx, "nfe_jlist_mtx", NULL, MTX_DEF);
329 callout_init_mtx(&sc->nfe_stat_ch, &sc->nfe_mtx, 0);
330 TASK_INIT(&sc->nfe_link_task, 0, nfe_link_task, sc);
323 callout_init_mtx(&sc->nfe_stat_ch, &sc->nfe_mtx, 0);
324 TASK_INIT(&sc->nfe_link_task, 0, nfe_link_task, sc);
331 SLIST_INIT(&sc->nfe_jfree_listhead);
332 SLIST_INIT(&sc->nfe_jinuse_listhead);
333
334 pci_enable_busmaster(dev);
335
336 rid = PCIR_BAR(0);
337 sc->nfe_res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
338 RF_ACTIVE);
339 if (sc->nfe_res[0] == NULL) {
340 device_printf(dev, "couldn't map memory resources\n");

--- 367 unchanged lines hidden (view full) ---

708 nfe_free_rx_ring(sc, &sc->rxq);
709 nfe_free_jrx_ring(sc, &sc->jrxq);
710
711 if (sc->nfe_parent_tag) {
712 bus_dma_tag_destroy(sc->nfe_parent_tag);
713 sc->nfe_parent_tag = NULL;
714 }
715
325
326 pci_enable_busmaster(dev);
327
328 rid = PCIR_BAR(0);
329 sc->nfe_res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
330 RF_ACTIVE);
331 if (sc->nfe_res[0] == NULL) {
332 device_printf(dev, "couldn't map memory resources\n");

--- 367 unchanged lines hidden (view full) ---

700 nfe_free_rx_ring(sc, &sc->rxq);
701 nfe_free_jrx_ring(sc, &sc->jrxq);
702
703 if (sc->nfe_parent_tag) {
704 bus_dma_tag_destroy(sc->nfe_parent_tag);
705 sc->nfe_parent_tag = NULL;
706 }
707
716 mtx_destroy(&sc->nfe_jlist_mtx);
717 mtx_destroy(&sc->nfe_mtx);
718
719 return (0);
720}
721
722
723static int
724nfe_suspend(device_t dev)

--- 251 unchanged lines hidden (view full) ---

976 }
977#ifdef NFE_DEBUG
978 if (nfedebug >= 2 && ntries == NFE_TIMEOUT)
979 device_printf(sc->nfe_dev, "could not write to PHY\n");
980#endif
981 return (0);
982}
983
708 mtx_destroy(&sc->nfe_mtx);
709
710 return (0);
711}
712
713
714static int
715nfe_suspend(device_t dev)

--- 251 unchanged lines hidden (view full) ---

967 }
968#ifdef NFE_DEBUG
969 if (nfedebug >= 2 && ntries == NFE_TIMEOUT)
970 device_printf(sc->nfe_dev, "could not write to PHY\n");
971#endif
972 return (0);
973}
974
984/*
985 * Allocate a jumbo buffer.
986 */
987static void *
988nfe_jalloc(struct nfe_softc *sc)
989{
990 struct nfe_jpool_entry *entry;
991
992 NFE_JLIST_LOCK(sc);
993
994 entry = SLIST_FIRST(&sc->nfe_jfree_listhead);
995
996 if (entry == NULL) {
997 NFE_JLIST_UNLOCK(sc);
998 return (NULL);
999 }
1000
1001 SLIST_REMOVE_HEAD(&sc->nfe_jfree_listhead, jpool_entries);
1002 SLIST_INSERT_HEAD(&sc->nfe_jinuse_listhead, entry, jpool_entries);
1003
1004 NFE_JLIST_UNLOCK(sc);
1005
1006 return (sc->jrxq.jslots[entry->slot]);
1007}
1008
1009/*
1010 * Release a jumbo buffer.
1011 */
1012static void
1013nfe_jfree(void *buf, void *args)
1014{
1015 struct nfe_softc *sc;
1016 struct nfe_jpool_entry *entry;
1017 int i;
1018
1019 /* Extract the softc struct pointer. */
1020 sc = (struct nfe_softc *)args;
1021 KASSERT(sc != NULL, ("%s: can't find softc pointer!", __func__));
1022
1023 NFE_JLIST_LOCK(sc);
1024 /* Calculate the slot this buffer belongs to. */
1025 i = ((vm_offset_t)buf
1026 - (vm_offset_t)sc->jrxq.jpool) / NFE_JLEN;
1027 KASSERT(i >= 0 && i < NFE_JSLOTS,
1028 ("%s: asked to free buffer that we don't manage!", __func__));
1029
1030 entry = SLIST_FIRST(&sc->nfe_jinuse_listhead);
1031 KASSERT(entry != NULL, ("%s: buffer not in use!", __func__));
1032 entry->slot = i;
1033 SLIST_REMOVE_HEAD(&sc->nfe_jinuse_listhead, jpool_entries);
1034 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, jpool_entries);
1035 if (SLIST_EMPTY(&sc->nfe_jinuse_listhead))
1036 wakeup(sc);
1037
1038 NFE_JLIST_UNLOCK(sc);
1039}
1040
1041struct nfe_dmamap_arg {
1042 bus_addr_t nfe_busaddr;
1043};
1044
1045static int
1046nfe_alloc_rx_ring(struct nfe_softc *sc, struct nfe_rx_ring *ring)
1047{
1048 struct nfe_dmamap_arg ctx;

--- 92 unchanged lines hidden (view full) ---

1141
1142
1143static void
1144nfe_alloc_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring)
1145{
1146 struct nfe_dmamap_arg ctx;
1147 struct nfe_rx_data *data;
1148 void *desc;
975struct nfe_dmamap_arg {
976 bus_addr_t nfe_busaddr;
977};
978
979static int
980nfe_alloc_rx_ring(struct nfe_softc *sc, struct nfe_rx_ring *ring)
981{
982 struct nfe_dmamap_arg ctx;

--- 92 unchanged lines hidden (view full) ---

1075
1076
1077static void
1078nfe_alloc_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring)
1079{
1080 struct nfe_dmamap_arg ctx;
1081 struct nfe_rx_data *data;
1082 void *desc;
1149 struct nfe_jpool_entry *entry;
1150 uint8_t *ptr;
1151 int i, error, descsize;
1152
1153 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0)
1154 return;
1155 if (jumbo_disable != 0) {
1156 device_printf(sc->nfe_dev, "disabling jumbo frame support\n");
1157 sc->nfe_jumbo_disable = 1;
1158 return;

--- 22 unchanged lines hidden (view full) ---

1181 NULL, NULL, /* lockfunc, lockarg */
1182 &ring->jrx_desc_tag);
1183 if (error != 0) {
1184 device_printf(sc->nfe_dev,
1185 "could not create jumbo ring DMA tag\n");
1186 goto fail;
1187 }
1188
1083 int i, error, descsize;
1084
1085 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0)
1086 return;
1087 if (jumbo_disable != 0) {
1088 device_printf(sc->nfe_dev, "disabling jumbo frame support\n");
1089 sc->nfe_jumbo_disable = 1;
1090 return;

--- 22 unchanged lines hidden (view full) ---

1113 NULL, NULL, /* lockfunc, lockarg */
1114 &ring->jrx_desc_tag);
1115 if (error != 0) {
1116 device_printf(sc->nfe_dev,
1117 "could not create jumbo ring DMA tag\n");
1118 goto fail;
1119 }
1120
1189 /* Create DMA tag for jumbo buffer blocks. */
1190 error = bus_dma_tag_create(sc->nfe_parent_tag,
1191 PAGE_SIZE, 0, /* alignment, boundary */
1192 BUS_SPACE_MAXADDR, /* lowaddr */
1193 BUS_SPACE_MAXADDR, /* highaddr */
1194 NULL, NULL, /* filter, filterarg */
1195 NFE_JMEM, /* maxsize */
1196 1, /* nsegments */
1197 NFE_JMEM, /* maxsegsize */
1198 0, /* flags */
1199 NULL, NULL, /* lockfunc, lockarg */
1200 &ring->jrx_jumbo_tag);
1201 if (error != 0) {
1202 device_printf(sc->nfe_dev,
1203 "could not create jumbo Rx buffer block DMA tag\n");
1204 goto fail;
1205 }
1206
1207 /* Create DMA tag for jumbo Rx buffers. */
1208 error = bus_dma_tag_create(sc->nfe_parent_tag,
1209 PAGE_SIZE, 0, /* alignment, boundary */
1210 BUS_SPACE_MAXADDR, /* lowaddr */
1211 BUS_SPACE_MAXADDR, /* highaddr */
1212 NULL, NULL, /* filter, filterarg */
1121 /* Create DMA tag for jumbo Rx buffers. */
1122 error = bus_dma_tag_create(sc->nfe_parent_tag,
1123 PAGE_SIZE, 0, /* alignment, boundary */
1124 BUS_SPACE_MAXADDR, /* lowaddr */
1125 BUS_SPACE_MAXADDR, /* highaddr */
1126 NULL, NULL, /* filter, filterarg */
1213 NFE_JLEN, /* maxsize */
1127 MJUM9BYTES, /* maxsize */
1214 1, /* nsegments */
1128 1, /* nsegments */
1215 NFE_JLEN, /* maxsegsize */
1129 MJUM9BYTES, /* maxsegsize */
1216 0, /* flags */
1217 NULL, NULL, /* lockfunc, lockarg */
1218 &ring->jrx_data_tag);
1219 if (error != 0) {
1220 device_printf(sc->nfe_dev,
1221 "could not create jumbo Rx buffer DMA tag\n");
1222 goto fail;
1223 }

--- 37 unchanged lines hidden (view full) ---

1261 &data->rx_data_map);
1262 if (error != 0) {
1263 device_printf(sc->nfe_dev,
1264 "could not create jumbo Rx DMA map\n");
1265 goto fail;
1266 }
1267 }
1268
1130 0, /* flags */
1131 NULL, NULL, /* lockfunc, lockarg */
1132 &ring->jrx_data_tag);
1133 if (error != 0) {
1134 device_printf(sc->nfe_dev,
1135 "could not create jumbo Rx buffer DMA tag\n");
1136 goto fail;
1137 }

--- 37 unchanged lines hidden (view full) ---

1175 &data->rx_data_map);
1176 if (error != 0) {
1177 device_printf(sc->nfe_dev,
1178 "could not create jumbo Rx DMA map\n");
1179 goto fail;
1180 }
1181 }
1182
1269 /* Allocate DMA'able memory and load the DMA map for jumbo buf. */
1270 error = bus_dmamem_alloc(ring->jrx_jumbo_tag, (void **)&ring->jpool,
1271 BUS_DMA_WAITOK | BUS_DMA_COHERENT | BUS_DMA_ZERO,
1272 &ring->jrx_jumbo_map);
1273 if (error != 0) {
1274 device_printf(sc->nfe_dev,
1275 "could not allocate DMA'able memory for jumbo pool\n");
1276 goto fail;
1277 }
1278
1279 ctx.nfe_busaddr = 0;
1280 error = bus_dmamap_load(ring->jrx_jumbo_tag, ring->jrx_jumbo_map,
1281 ring->jpool, NFE_JMEM, nfe_dma_map_segs, &ctx, 0);
1282 if (error != 0) {
1283 device_printf(sc->nfe_dev,
1284 "could not load DMA'able memory for jumbo pool\n");
1285 goto fail;
1286 }
1287
1288 /*
1289 * Now divide it up into 9K pieces and save the addresses
1290 * in an array.
1291 */
1292 ptr = ring->jpool;
1293 for (i = 0; i < NFE_JSLOTS; i++) {
1294 ring->jslots[i] = ptr;
1295 ptr += NFE_JLEN;
1296 entry = malloc(sizeof(struct nfe_jpool_entry), M_DEVBUF,
1297 M_WAITOK);
1298 if (entry == NULL) {
1299 device_printf(sc->nfe_dev,
1300 "no memory for jumbo buffers!\n");
1301 error = ENOMEM;
1302 goto fail;
1303 }
1304 entry->slot = i;
1305 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry,
1306 jpool_entries);
1307 }
1308
1309 return;
1310
1311fail:
1312 /*
1313 * Running without jumbo frame support is ok for most cases
1314 * so don't fail on creating dma tag/map for jumbo frame.
1315 */
1316 nfe_free_jrx_ring(sc, ring);

--- 41 unchanged lines hidden (view full) ---

1358 ring->jcur = ring->jnext = 0;
1359 if (sc->nfe_flags & NFE_40BIT_ADDR) {
1360 desc = ring->jdesc64;
1361 descsize = sizeof (struct nfe_desc64);
1362 } else {
1363 desc = ring->jdesc32;
1364 descsize = sizeof (struct nfe_desc32);
1365 }
1183 return;
1184
1185fail:
1186 /*
1187 * Running without jumbo frame support is ok for most cases
1188 * so don't fail on creating dma tag/map for jumbo frame.
1189 */
1190 nfe_free_jrx_ring(sc, ring);

--- 41 unchanged lines hidden (view full) ---

1232 ring->jcur = ring->jnext = 0;
1233 if (sc->nfe_flags & NFE_40BIT_ADDR) {
1234 desc = ring->jdesc64;
1235 descsize = sizeof (struct nfe_desc64);
1236 } else {
1237 desc = ring->jdesc32;
1238 descsize = sizeof (struct nfe_desc32);
1239 }
1366 bzero(desc, descsize * NFE_RX_RING_COUNT);
1240 bzero(desc, descsize * NFE_JUMBO_RX_RING_COUNT);
1367 for (i = 0; i < NFE_JUMBO_RX_RING_COUNT; i++) {
1368 if (nfe_jnewbuf(sc, i) != 0)
1369 return (ENOBUFS);
1370 }
1371
1372 bus_dmamap_sync(ring->jrx_desc_tag, ring->jrx_desc_map,
1373 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1374

--- 50 unchanged lines hidden (view full) ---

1425 ring->rx_desc_tag = NULL;
1426 }
1427}
1428
1429
1430static void
1431nfe_free_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring)
1432{
1241 for (i = 0; i < NFE_JUMBO_RX_RING_COUNT; i++) {
1242 if (nfe_jnewbuf(sc, i) != 0)
1243 return (ENOBUFS);
1244 }
1245
1246 bus_dmamap_sync(ring->jrx_desc_tag, ring->jrx_desc_map,
1247 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1248

--- 50 unchanged lines hidden (view full) ---

1299 ring->rx_desc_tag = NULL;
1300 }
1301}
1302
1303
1304static void
1305nfe_free_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring)
1306{
1433 struct nfe_jpool_entry *entry;
1434 struct nfe_rx_data *data;
1435 void *desc;
1436 int i, descsize;
1437
1438 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0)
1439 return;
1440
1307 struct nfe_rx_data *data;
1308 void *desc;
1309 int i, descsize;
1310
1311 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0)
1312 return;
1313
1441 NFE_JLIST_LOCK(sc);
1442 while ((entry = SLIST_FIRST(&sc->nfe_jinuse_listhead))) {
1443 device_printf(sc->nfe_dev,
1444 "asked to free buffer that is in use!\n");
1445 SLIST_REMOVE_HEAD(&sc->nfe_jinuse_listhead, jpool_entries);
1446 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry,
1447 jpool_entries);
1448 }
1449
1450 while (!SLIST_EMPTY(&sc->nfe_jfree_listhead)) {
1451 entry = SLIST_FIRST(&sc->nfe_jfree_listhead);
1452 SLIST_REMOVE_HEAD(&sc->nfe_jfree_listhead, jpool_entries);
1453 free(entry, M_DEVBUF);
1454 }
1455 NFE_JLIST_UNLOCK(sc);
1456
1457 if (sc->nfe_flags & NFE_40BIT_ADDR) {
1458 desc = ring->jdesc64;
1459 descsize = sizeof (struct nfe_desc64);
1460 } else {
1461 desc = ring->jdesc32;
1462 descsize = sizeof (struct nfe_desc32);
1463 }
1464

--- 21 unchanged lines hidden (view full) ---

1486
1487 if (desc != NULL) {
1488 bus_dmamap_unload(ring->jrx_desc_tag, ring->jrx_desc_map);
1489 bus_dmamem_free(ring->jrx_desc_tag, desc, ring->jrx_desc_map);
1490 ring->jdesc64 = NULL;
1491 ring->jdesc32 = NULL;
1492 ring->jrx_desc_map = NULL;
1493 }
1314 if (sc->nfe_flags & NFE_40BIT_ADDR) {
1315 desc = ring->jdesc64;
1316 descsize = sizeof (struct nfe_desc64);
1317 } else {
1318 desc = ring->jdesc32;
1319 descsize = sizeof (struct nfe_desc32);
1320 }
1321

--- 21 unchanged lines hidden (view full) ---

1343
1344 if (desc != NULL) {
1345 bus_dmamap_unload(ring->jrx_desc_tag, ring->jrx_desc_map);
1346 bus_dmamem_free(ring->jrx_desc_tag, desc, ring->jrx_desc_map);
1347 ring->jdesc64 = NULL;
1348 ring->jdesc32 = NULL;
1349 ring->jrx_desc_map = NULL;
1350 }
1494 /* Destroy jumbo buffer block. */
1495 if (ring->jrx_jumbo_map != NULL)
1496 bus_dmamap_unload(ring->jrx_jumbo_tag, ring->jrx_jumbo_map);
1497 if (ring->jrx_jumbo_map != NULL) {
1498 bus_dmamem_free(ring->jrx_jumbo_tag, ring->jpool,
1499 ring->jrx_jumbo_map);
1500 ring->jpool = NULL;
1501 ring->jrx_jumbo_map = NULL;
1502 }
1351
1503 if (ring->jrx_desc_tag != NULL) {
1504 bus_dma_tag_destroy(ring->jrx_desc_tag);
1505 ring->jrx_desc_tag = NULL;
1506 }
1507}
1508
1509
1510static int

--- 567 unchanged lines hidden (view full) ---

2078{
2079 struct nfe_rx_data *data;
2080 struct nfe_desc32 *desc32;
2081 struct nfe_desc64 *desc64;
2082 struct mbuf *m;
2083 bus_dma_segment_t segs[1];
2084 bus_dmamap_t map;
2085 int nsegs;
1352 if (ring->jrx_desc_tag != NULL) {
1353 bus_dma_tag_destroy(ring->jrx_desc_tag);
1354 ring->jrx_desc_tag = NULL;
1355 }
1356}
1357
1358
1359static int

--- 567 unchanged lines hidden (view full) ---

1927{
1928 struct nfe_rx_data *data;
1929 struct nfe_desc32 *desc32;
1930 struct nfe_desc64 *desc64;
1931 struct mbuf *m;
1932 bus_dma_segment_t segs[1];
1933 bus_dmamap_t map;
1934 int nsegs;
2086 void *buf;
2087
1935
2088 MGETHDR(m, M_DONTWAIT, MT_DATA);
1936 m = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, MJUM9BYTES);
2089 if (m == NULL)
2090 return (ENOBUFS);
1937 if (m == NULL)
1938 return (ENOBUFS);
2091 buf = nfe_jalloc(sc);
2092 if (buf == NULL) {
2093 m_freem(m);
2094 return (ENOBUFS);
2095 }
2096 /* Attach the buffer to the mbuf. */
2097 MEXTADD(m, buf, NFE_JLEN, nfe_jfree, buf, (struct nfe_softc *)sc, 0,
2098 EXT_NET_DRV);
2099 if ((m->m_flags & M_EXT) == 0) {
2100 m_freem(m);
2101 return (ENOBUFS);
2102 }
1939 if ((m->m_flags & M_EXT) == 0) {
1940 m_freem(m);
1941 return (ENOBUFS);
1942 }
2103 m->m_pkthdr.len = m->m_len = NFE_JLEN;
1943 m->m_pkthdr.len = m->m_len = MJUM9BYTES;
2104 m_adj(m, ETHER_ALIGN);
2105
2106 if (bus_dmamap_load_mbuf_sg(sc->jrxq.jrx_data_tag,
2107 sc->jrxq.jrx_spare_map, m, segs, &nsegs, BUS_DMA_NOWAIT) != 0) {
2108 m_freem(m);
2109 return (ENOBUFS);
2110 }
2111 KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));

--- 1020 unchanged lines hidden ---
1944 m_adj(m, ETHER_ALIGN);
1945
1946 if (bus_dmamap_load_mbuf_sg(sc->jrxq.jrx_data_tag,
1947 sc->jrxq.jrx_spare_map, m, segs, &nsegs, BUS_DMA_NOWAIT) != 0) {
1948 m_freem(m);
1949 return (ENOBUFS);
1950 }
1951 KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));

--- 1020 unchanged lines hidden ---