cxgb_main.c (170789) | cxgb_main.c (170869) |
---|---|
1/************************************************************************** 2 3Copyright (c) 2007, Chelsio Inc. 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are met: 8 --- 14 unchanged lines hidden (view full) --- 23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26POSSIBILITY OF SUCH DAMAGE. 27 28***************************************************************************/ 29 30#include <sys/cdefs.h> | 1/************************************************************************** 2 3Copyright (c) 2007, Chelsio Inc. 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are met: 8 --- 14 unchanged lines hidden (view full) --- 23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26POSSIBILITY OF SUCH DAMAGE. 27 28***************************************************************************/ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/cxgb/cxgb_main.c 170789 2007-06-15 20:02:02Z kmacy $"); | 31__FBSDID("$FreeBSD: head/sys/dev/cxgb/cxgb_main.c 170869 2007-06-17 04:33:38Z kmacy $"); |
32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/bus.h> 37#include <sys/module.h> 38#include <sys/pciio.h> 39#include <sys/conf.h> --- 51 unchanged lines hidden (view full) --- 91static int cxgb_ioctl(struct ifnet *, unsigned long, caddr_t); 92static void cxgb_start(struct ifnet *); 93static void cxgb_start_proc(void *, int ncount); 94static int cxgb_media_change(struct ifnet *); 95static void cxgb_media_status(struct ifnet *, struct ifmediareq *); 96static int setup_sge_qsets(adapter_t *); 97static void cxgb_async_intr(void *); 98static void cxgb_ext_intr_handler(void *, int); | 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/bus.h> 37#include <sys/module.h> 38#include <sys/pciio.h> 39#include <sys/conf.h> --- 51 unchanged lines hidden (view full) --- 91static int cxgb_ioctl(struct ifnet *, unsigned long, caddr_t); 92static void cxgb_start(struct ifnet *); 93static void cxgb_start_proc(void *, int ncount); 94static int cxgb_media_change(struct ifnet *); 95static void cxgb_media_status(struct ifnet *, struct ifmediareq *); 96static int setup_sge_qsets(adapter_t *); 97static void cxgb_async_intr(void *); 98static void cxgb_ext_intr_handler(void *, int); |
99static void cxgb_down(struct adapter *sc); | 99static void cxgb_tick_handler(void *, int); 100static void cxgb_down_locked(struct adapter *sc); |
100static void cxgb_tick(void *); 101static void setup_rss(adapter_t *sc); 102 103/* Attachment glue for the PCI controller end of the device. Each port of 104 * the device is attached separately, as defined later. 105 */ 106static int cxgb_controller_probe(device_t); 107static int cxgb_controller_attach(device_t); --- 205 unchanged lines hidden (view full) --- 313 FW_VERSION_MINOR, FW_VERSION_MICRO); 314 315 fw = firmware_get(buf); 316 317 if (fw == NULL) { 318 device_printf(sc->dev, "Could not find firmware image %s\n", buf); 319 return (ENOENT); 320 } | 101static void cxgb_tick(void *); 102static void setup_rss(adapter_t *sc); 103 104/* Attachment glue for the PCI controller end of the device. Each port of 105 * the device is attached separately, as defined later. 106 */ 107static int cxgb_controller_probe(device_t); 108static int cxgb_controller_attach(device_t); --- 205 unchanged lines hidden (view full) --- 314 FW_VERSION_MINOR, FW_VERSION_MICRO); 315 316 fw = firmware_get(buf); 317 318 if (fw == NULL) { 319 device_printf(sc->dev, "Could not find firmware image %s\n", buf); 320 return (ENOENT); 321 } |
321 | |
322 status = t3_load_fw(sc, (const uint8_t *)fw->data, fw->datasize); 323 324 firmware_put(fw, FIRMWARE_UNLOAD); 325 326 return (status); 327} 328 329static int 330cxgb_controller_attach(device_t dev) 331{ 332 device_t child; 333 const struct adapter_info *ai; 334 struct adapter *sc; 335 int i, reg, msi_needed, error = 0; 336 uint32_t vers; 337 int port_qsets = 1; | 322 status = t3_load_fw(sc, (const uint8_t *)fw->data, fw->datasize); 323 324 firmware_put(fw, FIRMWARE_UNLOAD); 325 326 return (status); 327} 328 329static int 330cxgb_controller_attach(device_t dev) 331{ 332 device_t child; 333 const struct adapter_info *ai; 334 struct adapter *sc; 335 int i, reg, msi_needed, error = 0; 336 uint32_t vers; 337 int port_qsets = 1; |
338 | 338 |
339 sc = device_get_softc(dev); 340 sc->dev = dev; 341 sc->msi_count = 0; 342 343 /* find the PCIe link width and set max read request to 4KB*/ 344 if (pci_find_extcap(dev, PCIY_EXPRESS, ®) == 0) { 345 uint16_t lnk, pectl; 346 lnk = pci_read_config(dev, reg + 0x12, 2); --- 16 unchanged lines hidden (view full) --- 363 */ 364 sc->regs_rid = PCIR_BAR(0); 365 if ((sc->regs_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 366 &sc->regs_rid, RF_ACTIVE)) == NULL) { 367 device_printf(dev, "Cannot allocate BAR\n"); 368 return (ENXIO); 369 } 370 | 339 sc = device_get_softc(dev); 340 sc->dev = dev; 341 sc->msi_count = 0; 342 343 /* find the PCIe link width and set max read request to 4KB*/ 344 if (pci_find_extcap(dev, PCIY_EXPRESS, ®) == 0) { 345 uint16_t lnk, pectl; 346 lnk = pci_read_config(dev, reg + 0x12, 2); --- 16 unchanged lines hidden (view full) --- 363 */ 364 sc->regs_rid = PCIR_BAR(0); 365 if ((sc->regs_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 366 &sc->regs_rid, RF_ACTIVE)) == NULL) { 367 device_printf(dev, "Cannot allocate BAR\n"); 368 return (ENXIO); 369 } 370 |
371 mtx_init(&sc->sge.reg_lock, "SGE reg lock", NULL, MTX_DEF); 372 mtx_init(&sc->lock, "cxgb controller lock", NULL, MTX_DEF); 373 mtx_init(&sc->mdio_lock, "cxgb mdio", NULL, MTX_DEF); 374 mtx_init(&sc->elmer_lock, "cxgb elmer", NULL, MTX_DEF); | 371 snprintf(sc->lockbuf, ADAPTER_LOCK_NAME_LEN, "cxgb controller lock %d", 372 device_get_unit(dev)); 373 ADAPTER_LOCK_INIT(sc, sc->lockbuf); 374 375 snprintf(sc->reglockbuf, ADAPTER_LOCK_NAME_LEN, "SGE reg lock %d", 376 device_get_unit(dev)); 377 snprintf(sc->mdiolockbuf, ADAPTER_LOCK_NAME_LEN, "cxgb mdio lock %d", 378 device_get_unit(dev)); 379 snprintf(sc->elmerlockbuf, ADAPTER_LOCK_NAME_LEN, "cxgb elmer lock %d", 380 device_get_unit(dev)); |
375 | 381 |
382 MTX_INIT(&sc->sge.reg_lock, sc->reglockbuf, NULL, MTX_DEF); 383 MTX_INIT(&sc->mdio_lock, sc->mdiolockbuf, NULL, MTX_DEF); 384 MTX_INIT(&sc->elmer_lock, sc->elmerlockbuf, NULL, MTX_DEF); 385 |
|
376 sc->bt = rman_get_bustag(sc->regs_res); 377 sc->bh = rman_get_bushandle(sc->regs_res); 378 sc->mmio_len = rman_get_size(sc->regs_res); 379 380 ai = cxgb_get_adapter_info(dev); 381 if (t3_prep_adapter(sc, ai, 1) < 0) { 382 printf("prep adapter failed\n"); 383 error = ENODEV; --- 60 unchanged lines hidden (view full) --- 444 if (sc->tq == NULL) { 445 device_printf(dev, "failed to allocate controller task queue\n"); 446 goto out; 447 } 448 449 taskqueue_start_threads(&sc->tq, 1, PI_NET, "%s taskq", 450 device_get_nameunit(dev)); 451 TASK_INIT(&sc->ext_intr_task, 0, cxgb_ext_intr_handler, sc); | 386 sc->bt = rman_get_bustag(sc->regs_res); 387 sc->bh = rman_get_bushandle(sc->regs_res); 388 sc->mmio_len = rman_get_size(sc->regs_res); 389 390 ai = cxgb_get_adapter_info(dev); 391 if (t3_prep_adapter(sc, ai, 1) < 0) { 392 printf("prep adapter failed\n"); 393 error = ENODEV; --- 60 unchanged lines hidden (view full) --- 454 if (sc->tq == NULL) { 455 device_printf(dev, "failed to allocate controller task queue\n"); 456 goto out; 457 } 458 459 taskqueue_start_threads(&sc->tq, 1, PI_NET, "%s taskq", 460 device_get_nameunit(dev)); 461 TASK_INIT(&sc->ext_intr_task, 0, cxgb_ext_intr_handler, sc); |
462 TASK_INIT(&sc->tick_task, 0, cxgb_tick_handler, sc); |
|
452 453 454 /* Create a periodic callout for checking adapter status */ | 463 464 465 /* Create a periodic callout for checking adapter status */ |
455 callout_init_mtx(&sc->cxgb_tick_ch, &sc->lock, CALLOUT_RETURNUNLOCKED); | 466 callout_init(&sc->cxgb_tick_ch, TRUE); |
456 457 if (t3_check_fw_version(sc) != 0) { 458 /* 459 * Warn user that a firmware update will be attempted in init. 460 */ 461 device_printf(dev, "firmware needs to be updated to version %d.%d.%d\n", 462 FW_VERSION_MAJOR, FW_VERSION_MINOR, FW_VERSION_MICRO); 463 sc->flags &= ~FW_UPTODATE; --- 67 unchanged lines hidden (view full) --- 531 return (0); 532} 533 534static void 535cxgb_free(struct adapter *sc) 536{ 537 int i; 538 | 467 468 if (t3_check_fw_version(sc) != 0) { 469 /* 470 * Warn user that a firmware update will be attempted in init. 471 */ 472 device_printf(dev, "firmware needs to be updated to version %d.%d.%d\n", 473 FW_VERSION_MAJOR, FW_VERSION_MINOR, FW_VERSION_MICRO); 474 sc->flags &= ~FW_UPTODATE; --- 67 unchanged lines hidden (view full) --- 542 return (0); 543} 544 545static void 546cxgb_free(struct adapter *sc) 547{ 548 int i; 549 |
539 cxgb_down(sc); | 550 ADAPTER_LOCK(sc); 551 /* 552 * drops the lock 553 */ 554 cxgb_down_locked(sc); |
540 541#ifdef MSI_SUPPORTED 542 if (sc->flags & (USING_MSI | USING_MSIX)) { 543 device_printf(sc->dev, "releasing msi message(s)\n"); 544 pci_release_msi(sc->dev); 545 } else { 546 device_printf(sc->dev, "no msi message to release\n"); 547 } 548#endif 549 if (sc->msix_regs_res != NULL) { 550 bus_release_resource(sc->dev, SYS_RES_MEMORY, sc->msix_regs_rid, 551 sc->msix_regs_res); 552 } 553 | 555 556#ifdef MSI_SUPPORTED 557 if (sc->flags & (USING_MSI | USING_MSIX)) { 558 device_printf(sc->dev, "releasing msi message(s)\n"); 559 pci_release_msi(sc->dev); 560 } else { 561 device_printf(sc->dev, "no msi message to release\n"); 562 } 563#endif 564 if (sc->msix_regs_res != NULL) { 565 bus_release_resource(sc->dev, SYS_RES_MEMORY, sc->msix_regs_rid, 566 sc->msix_regs_res); 567 } 568 |
554 /* 555 * XXX need to drain the ifq by hand until 556 * it is taught about mbuf iovecs 557 */ 558 callout_drain(&sc->cxgb_tick_ch); 559 | |
560 t3_sge_deinit_sw(sc); 561 562 if (sc->tq != NULL) { 563 taskqueue_drain(sc->tq, &sc->ext_intr_task); | 569 t3_sge_deinit_sw(sc); 570 571 if (sc->tq != NULL) { 572 taskqueue_drain(sc->tq, &sc->ext_intr_task); |
573 taskqueue_drain(sc->tq, &sc->tick_task); |
|
564 taskqueue_free(sc->tq); 565 } | 574 taskqueue_free(sc->tq); 575 } |
576 577 tsleep(&sc, 0, "cxgb unload", hz); |
|
566 567 for (i = 0; i < (sc)->params.nports; ++i) { 568 if (sc->portdev[i] != NULL) 569 device_delete_child(sc->dev, sc->portdev[i]); 570 } 571 572 bus_generic_detach(sc->dev); 573#ifdef notyet 574 if (is_offload(sc)) { 575 cxgb_adapter_unofld(sc); 576 if (isset(&sc->open_device_map, OFFLOAD_DEVMAP_BIT)) 577 offload_close(&sc->tdev); 578 } 579#endif 580 t3_free_sge_resources(sc); 581 t3_sge_free(sc); | 578 579 for (i = 0; i < (sc)->params.nports; ++i) { 580 if (sc->portdev[i] != NULL) 581 device_delete_child(sc->dev, sc->portdev[i]); 582 } 583 584 bus_generic_detach(sc->dev); 585#ifdef notyet 586 if (is_offload(sc)) { 587 cxgb_adapter_unofld(sc); 588 if (isset(&sc->open_device_map, OFFLOAD_DEVMAP_BIT)) 589 offload_close(&sc->tdev); 590 } 591#endif 592 t3_free_sge_resources(sc); 593 t3_sge_free(sc); |
582 | 594 595 cxgb_offload_exit(); 596 |
583 if (sc->regs_res != NULL) 584 bus_release_resource(sc->dev, SYS_RES_MEMORY, sc->regs_rid, 585 sc->regs_res); 586 | 597 if (sc->regs_res != NULL) 598 bus_release_resource(sc->dev, SYS_RES_MEMORY, sc->regs_rid, 599 sc->regs_res); 600 |
587 mtx_destroy(&sc->mdio_lock); 588 mtx_destroy(&sc->sge.reg_lock); 589 mtx_destroy(&sc->lock); | 601 MTX_DESTROY(&sc->mdio_lock); 602 MTX_DESTROY(&sc->sge.reg_lock); 603 MTX_DESTROY(&sc->elmer_lock); 604 ADAPTER_LOCK_DEINIT(sc); |
590 591 return; 592} 593 594/** 595 * setup_sge_qsets - configure SGE Tx/Rx/response queues 596 * @sc: the controller softc 597 * --- 155 unchanged lines hidden (view full) --- 753 754 755static int 756cxgb_port_attach(device_t dev) 757{ 758 struct port_info *p; 759 struct ifnet *ifp; 760 int err, media_flags; | 605 606 return; 607} 608 609/** 610 * setup_sge_qsets - configure SGE Tx/Rx/response queues 611 * @sc: the controller softc 612 * --- 155 unchanged lines hidden (view full) --- 768 769 770static int 771cxgb_port_attach(device_t dev) 772{ 773 struct port_info *p; 774 struct ifnet *ifp; 775 int err, media_flags; |
761 char buf[64]; | |
762 763 p = device_get_softc(dev); 764 | 776 777 p = device_get_softc(dev); 778 |
765 snprintf(buf, sizeof(buf), "cxgb port %d", p->port); 766 mtx_init(&p->lock, buf, 0, MTX_DEF); | 779 snprintf(p->lockbuf, PORT_NAME_LEN, "cxgb port lock %d:%d", 780 device_get_unit(device_get_parent(dev)), p->port); 781 PORT_LOCK_INIT(p, p->lockbuf); |
767 768 /* Allocate an ifnet object and set it up */ 769 ifp = p->ifp = if_alloc(IFT_ETHER); 770 if (ifp == NULL) { 771 device_printf(dev, "Cannot allocate ifnet\n"); 772 return (ENOMEM); 773 } 774 --- 54 unchanged lines hidden (view full) --- 829 ifmedia_add(&p->media, media_flags, 0, NULL); 830 ifmedia_set(&p->media, media_flags); 831 } else { 832 ifmedia_add(&p->media, IFM_ETHER | IFM_AUTO, 0, NULL); 833 ifmedia_set(&p->media, IFM_ETHER | IFM_AUTO); 834 } 835 836 | 782 783 /* Allocate an ifnet object and set it up */ 784 ifp = p->ifp = if_alloc(IFT_ETHER); 785 if (ifp == NULL) { 786 device_printf(dev, "Cannot allocate ifnet\n"); 787 return (ENOMEM); 788 } 789 --- 54 unchanged lines hidden (view full) --- 844 ifmedia_add(&p->media, media_flags, 0, NULL); 845 ifmedia_set(&p->media, media_flags); 846 } else { 847 ifmedia_add(&p->media, IFM_ETHER | IFM_AUTO, 0, NULL); 848 ifmedia_set(&p->media, IFM_ETHER | IFM_AUTO); 849 } 850 851 |
837 snprintf(buf, sizeof(buf), "cxgb_port_taskq%d", p->port); | 852 snprintf(p->taskqbuf, TASKQ_NAME_LEN, "cxgb_port_taskq%d", p->port); |
838#ifdef TASKQUEUE_CURRENT 839 /* Create a port for handling TX without starvation */ | 853#ifdef TASKQUEUE_CURRENT 854 /* Create a port for handling TX without starvation */ |
840 p->tq = taskqueue_create(buf, M_NOWAIT, | 855 p->tq = taskqueue_create(p->taskqbuf, M_NOWAIT, |
841 taskqueue_thread_enqueue, &p->tq); 842#else 843 /* Create a port for handling TX without starvation */ 844 p->tq = taskqueue_create_fast(buf, M_NOWAIT, 845 taskqueue_thread_enqueue, &p->tq); 846#endif 847 848 if (p->tq == NULL) { --- 16 unchanged lines hidden (view full) --- 865 866 p = device_get_softc(dev); 867 868 PORT_LOCK(p); 869 if (p->ifp->if_drv_flags & IFF_DRV_RUNNING) 870 cxgb_stop_locked(p); 871 PORT_UNLOCK(p); 872 | 856 taskqueue_thread_enqueue, &p->tq); 857#else 858 /* Create a port for handling TX without starvation */ 859 p->tq = taskqueue_create_fast(buf, M_NOWAIT, 860 taskqueue_thread_enqueue, &p->tq); 861#endif 862 863 if (p->tq == NULL) { --- 16 unchanged lines hidden (view full) --- 880 881 p = device_get_softc(dev); 882 883 PORT_LOCK(p); 884 if (p->ifp->if_drv_flags & IFF_DRV_RUNNING) 885 cxgb_stop_locked(p); 886 PORT_UNLOCK(p); 887 |
873 mtx_destroy(&p->lock); | |
874 if (p->tq != NULL) { 875 taskqueue_drain(p->tq, &p->start_task); 876 taskqueue_free(p->tq); 877 p->tq = NULL; 878 } | 888 if (p->tq != NULL) { 889 taskqueue_drain(p->tq, &p->start_task); 890 taskqueue_free(p->tq); 891 p->tq = NULL; 892 } |
879 | 893 894 PORT_LOCK_DEINIT(p); |
880 ether_ifdetach(p->ifp); 881 if_free(p->ifp); 882 883 if (p->port_cdev != NULL) 884 destroy_dev(p->port_cdev); 885 886 return (0); 887} --- 375 unchanged lines hidden (view full) --- 1263 goto out; 1264} 1265 1266 1267/* 1268 * Release resources when all the ports and offloading have been stopped. 1269 */ 1270static void | 895 ether_ifdetach(p->ifp); 896 if_free(p->ifp); 897 898 if (p->port_cdev != NULL) 899 destroy_dev(p->port_cdev); 900 901 return (0); 902} --- 375 unchanged lines hidden (view full) --- 1278 goto out; 1279} 1280 1281 1282/* 1283 * Release resources when all the ports and offloading have been stopped. 1284 */ 1285static void |
1271cxgb_down(struct adapter *sc) | 1286cxgb_down_locked(struct adapter *sc) |
1272{ 1273 int i; 1274 1275 t3_sge_stop(sc); | 1287{ 1288 int i; 1289 1290 t3_sge_stop(sc); |
1276 ADAPTER_LOCK(sc); | |
1277 t3_intr_disable(sc); | 1291 t3_intr_disable(sc); |
1278 ADAPTER_UNLOCK(sc); 1279 | |
1280 1281 if (sc->intr_tag != NULL) { 1282 bus_teardown_intr(sc->dev, sc->irq_res, sc->intr_tag); 1283 sc->intr_tag = NULL; 1284 } 1285 if (sc->irq_res != NULL) { 1286 device_printf(sc->dev, "de-allocating interrupt irq_rid=%d irq_res=%p\n", 1287 sc->irq_rid, sc->irq_res); 1288 bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irq_rid, 1289 sc->irq_res); 1290 sc->irq_res = NULL; 1291 } 1292 1293 if (sc->flags & USING_MSIX) 1294 cxgb_teardown_msix(sc); | 1292 1293 if (sc->intr_tag != NULL) { 1294 bus_teardown_intr(sc->dev, sc->irq_res, sc->intr_tag); 1295 sc->intr_tag = NULL; 1296 } 1297 if (sc->irq_res != NULL) { 1298 device_printf(sc->dev, "de-allocating interrupt irq_rid=%d irq_res=%p\n", 1299 sc->irq_rid, sc->irq_res); 1300 bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irq_rid, 1301 sc->irq_res); 1302 sc->irq_res = NULL; 1303 } 1304 1305 if (sc->flags & USING_MSIX) 1306 cxgb_teardown_msix(sc); |
1307 ADAPTER_UNLOCK(sc); |
|
1295 | 1308 |
1309 callout_drain(&sc->cxgb_tick_ch); |
|
1296 callout_drain(&sc->sge_timer_ch); | 1310 callout_drain(&sc->sge_timer_ch); |
1311 |
|
1297 if (sc->tq != NULL) 1298 taskqueue_drain(sc->tq, &sc->slow_intr_task); 1299 for (i = 0; i < sc->params.nports; i++) 1300 if (sc->port[i].tq != NULL) 1301 taskqueue_drain(sc->port[i].tq, &sc->port[i].timer_reclaim_task); 1302 1303} 1304 --- 53 unchanged lines hidden (view full) --- 1358 1359 /* Call back all registered clients */ 1360 cxgb_remove_clients(tdev); 1361 tdev->lldev = NULL; 1362 cxgb_set_dummy_ops(tdev); 1363 t3_tp_set_offload_mode(adapter, 0); 1364 clrbit(&adapter->open_device_map, OFFLOAD_DEVMAP_BIT); 1365 | 1312 if (sc->tq != NULL) 1313 taskqueue_drain(sc->tq, &sc->slow_intr_task); 1314 for (i = 0; i < sc->params.nports; i++) 1315 if (sc->port[i].tq != NULL) 1316 taskqueue_drain(sc->port[i].tq, &sc->port[i].timer_reclaim_task); 1317 1318} 1319 --- 53 unchanged lines hidden (view full) --- 1373 1374 /* Call back all registered clients */ 1375 cxgb_remove_clients(tdev); 1376 tdev->lldev = NULL; 1377 cxgb_set_dummy_ops(tdev); 1378 t3_tp_set_offload_mode(adapter, 0); 1379 clrbit(&adapter->open_device_map, OFFLOAD_DEVMAP_BIT); 1380 |
1366 ADAPTER_LOCK(adapter); | |
1367 if (!adapter->open_device_map) 1368 cxgb_down(adapter); | 1381 if (!adapter->open_device_map) 1382 cxgb_down(adapter); |
1369 ADAPTER_UNLOCK(adapter); | |
1370 1371 cxgb_offload_deactivate(adapter); 1372 return (0); 1373} 1374#endif 1375 1376static void 1377cxgb_init(void *arg) --- 7 unchanged lines hidden (view full) --- 1385 1386static void 1387cxgb_init_locked(struct port_info *p) 1388{ 1389 struct ifnet *ifp; 1390 adapter_t *sc = p->adapter; 1391 int err; 1392 | 1383 1384 cxgb_offload_deactivate(adapter); 1385 return (0); 1386} 1387#endif 1388 1389static void 1390cxgb_init(void *arg) --- 7 unchanged lines hidden (view full) --- 1398 1399static void 1400cxgb_init_locked(struct port_info *p) 1401{ 1402 struct ifnet *ifp; 1403 adapter_t *sc = p->adapter; 1404 int err; 1405 |
1393 mtx_assert(&p->lock, MA_OWNED); | 1406 PORT_LOCK_ASSERT_OWNED(p); |
1394 ifp = p->ifp; 1395 1396 ADAPTER_LOCK(p->adapter); 1397 if ((sc->open_device_map == 0) && ((err = cxgb_up(sc)) < 0)) { 1398 ADAPTER_UNLOCK(p->adapter); 1399 cxgb_stop_locked(p); 1400 return; 1401 } | 1407 ifp = p->ifp; 1408 1409 ADAPTER_LOCK(p->adapter); 1410 if ((sc->open_device_map == 0) && ((err = cxgb_up(sc)) < 0)) { 1411 ADAPTER_UNLOCK(p->adapter); 1412 cxgb_stop_locked(p); 1413 return; 1414 } |
1402 if (p->adapter->open_device_map == 0) | 1415 if (p->adapter->open_device_map == 0) { |
1403 t3_intr_clear(sc); | 1416 t3_intr_clear(sc); |
1404 | 1417 t3_sge_init_adapter(sc); 1418 } |
1405 setbit(&p->adapter->open_device_map, p->port); 1406 ADAPTER_UNLOCK(p->adapter); 1407 1408 if (is_offload(sc) && !ofld_disable) { 1409 err = offload_open(p); 1410 if (err) 1411 log(LOG_WARNING, 1412 "Could not initialize offload capabilities\n"); 1413 } 1414 cxgb_link_start(p); 1415 t3_link_changed(sc, p->port); 1416 ifp->if_baudrate = p->link_config.speed * 1000000; 1417 1418 t3_port_intr_enable(sc, p->port); 1419 1420 callout_reset(&sc->cxgb_tick_ch, sc->params.stats_update_period * hz, 1421 cxgb_tick, sc); | 1419 setbit(&p->adapter->open_device_map, p->port); 1420 ADAPTER_UNLOCK(p->adapter); 1421 1422 if (is_offload(sc) && !ofld_disable) { 1423 err = offload_open(p); 1424 if (err) 1425 log(LOG_WARNING, 1426 "Could not initialize offload capabilities\n"); 1427 } 1428 cxgb_link_start(p); 1429 t3_link_changed(sc, p->port); 1430 ifp->if_baudrate = p->link_config.speed * 1000000; 1431 1432 t3_port_intr_enable(sc, p->port); 1433 1434 callout_reset(&sc->cxgb_tick_ch, sc->params.stats_update_period * hz, 1435 cxgb_tick, sc); |
1422 | 1436 |
1423 ifp->if_drv_flags |= IFF_DRV_RUNNING; 1424 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 1425} 1426 1427static void 1428cxgb_set_rxmode(struct port_info *p) 1429{ 1430 struct t3_rx_mode rm; 1431 struct cmac *mac = &p->mac; 1432 | 1437 ifp->if_drv_flags |= IFF_DRV_RUNNING; 1438 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 1439} 1440 1441static void 1442cxgb_set_rxmode(struct port_info *p) 1443{ 1444 struct t3_rx_mode rm; 1445 struct cmac *mac = &p->mac; 1446 |
1433 mtx_assert(&p->lock, MA_OWNED); | 1447 PORT_LOCK_ASSERT_OWNED(p); |
1434 1435 t3_init_rx_mode(&rm, p); 1436 t3_mac_set_rx_mode(mac, &rm); 1437} 1438 1439static void 1440cxgb_stop_locked(struct port_info *p) 1441{ 1442 struct ifnet *ifp; 1443 | 1448 1449 t3_init_rx_mode(&rm, p); 1450 t3_mac_set_rx_mode(mac, &rm); 1451} 1452 1453static void 1454cxgb_stop_locked(struct port_info *p) 1455{ 1456 struct ifnet *ifp; 1457 |
1444 mtx_assert(&p->lock, MA_OWNED); 1445 mtx_assert(&p->adapter->lock, MA_NOTOWNED); | 1458 PORT_LOCK_ASSERT_OWNED(p); 1459 ADAPTER_LOCK_ASSERT_NOTOWNED(p->adapter); |
1446 1447 ifp = p->ifp; 1448 1449 t3_port_intr_disable(p->adapter, p->port); 1450 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 1451 p->phy.ops->power_down(&p->phy, 1); 1452 t3_mac_disable(&p->mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX); 1453 1454 ADAPTER_LOCK(p->adapter); 1455 clrbit(&p->adapter->open_device_map, p->port); | 1460 1461 ifp = p->ifp; 1462 1463 t3_port_intr_disable(p->adapter, p->port); 1464 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 1465 p->phy.ops->power_down(&p->phy, 1); 1466 t3_mac_disable(&p->mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX); 1467 1468 ADAPTER_LOCK(p->adapter); 1469 clrbit(&p->adapter->open_device_map, p->port); |
1456 /* 1457 * XXX cancel check_task 1458 */ 1459 if (p->adapter->open_device_map == 0) 1460 cxgb_down(p->adapter); 1461 ADAPTER_UNLOCK(p->adapter); | 1470 1471 1472 if (p->adapter->open_device_map == 0) { 1473 cxgb_down_locked(p->adapter); 1474 } else 1475 ADAPTER_UNLOCK(p->adapter); 1476 |
1462} 1463 1464static int 1465cxgb_set_mtu(struct port_info *p, int mtu) 1466{ 1467 struct ifnet *ifp = p->ifp; 1468 int error = 0; 1469 --- 36 unchanged lines hidden (view full) --- 1506 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) 1507 cxgb_init_locked(p); 1508 arp_ifinit(ifp, ifa); 1509 } else 1510 error = ether_ioctl(ifp, command, data); 1511 PORT_UNLOCK(p); 1512 break; 1513 case SIOCSIFFLAGS: | 1477} 1478 1479static int 1480cxgb_set_mtu(struct port_info *p, int mtu) 1481{ 1482 struct ifnet *ifp = p->ifp; 1483 int error = 0; 1484 --- 36 unchanged lines hidden (view full) --- 1521 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) 1522 cxgb_init_locked(p); 1523 arp_ifinit(ifp, ifa); 1524 } else 1525 error = ether_ioctl(ifp, command, data); 1526 PORT_UNLOCK(p); 1527 break; 1528 case SIOCSIFFLAGS: |
1514 PORT_LOCK(p); | 1529 callout_drain(&p->adapter->cxgb_tick_ch); 1530 PORT_LOCK(p); |
1515 if (ifp->if_flags & IFF_UP) { 1516 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1517 flags = p->if_flags; 1518 if (((ifp->if_flags ^ flags) & IFF_PROMISC) || 1519 ((ifp->if_flags ^ flags) & IFF_ALLMULTI)) 1520 cxgb_set_rxmode(p); | 1531 if (ifp->if_flags & IFF_UP) { 1532 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1533 flags = p->if_flags; 1534 if (((ifp->if_flags ^ flags) & IFF_PROMISC) || 1535 ((ifp->if_flags ^ flags) & IFF_ALLMULTI)) 1536 cxgb_set_rxmode(p); |
1521 | |
1522 } else 1523 cxgb_init_locked(p); 1524 p->if_flags = ifp->if_flags; | 1537 } else 1538 cxgb_init_locked(p); 1539 p->if_flags = ifp->if_flags; |
1525 } else { 1526 callout_stop(&p->adapter->cxgb_tick_ch); 1527 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1528 cxgb_stop_locked(p); 1529 } else { 1530 adapter_t *sc = p->adapter; 1531 callout_reset(&sc->cxgb_tick_ch, 1532 sc->params.stats_update_period * hz, 1533 cxgb_tick, sc); 1534 } | 1540 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) 1541 cxgb_stop_locked(p); 1542 1543 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1544 adapter_t *sc = p->adapter; 1545 callout_reset(&sc->cxgb_tick_ch, 1546 sc->params.stats_update_period * hz, 1547 cxgb_tick, sc); |
1535 } 1536 PORT_UNLOCK(p); 1537 break; 1538 case SIOCSIFMEDIA: 1539 case SIOCGIFMEDIA: 1540 error = ifmedia_ioctl(ifp, ifr, &p->media, command); 1541 break; 1542 case SIOCSIFCAP: --- 198 unchanged lines hidden (view full) --- 1741 1742static void 1743cxgb_async_intr(void *data) 1744{ 1745 adapter_t *sc = data; 1746 1747 if (cxgb_debug) 1748 device_printf(sc->dev, "cxgb_async_intr\n"); | 1548 } 1549 PORT_UNLOCK(p); 1550 break; 1551 case SIOCSIFMEDIA: 1552 case SIOCGIFMEDIA: 1553 error = ifmedia_ioctl(ifp, ifr, &p->media, command); 1554 break; 1555 case SIOCSIFCAP: --- 198 unchanged lines hidden (view full) --- 1754 1755static void 1756cxgb_async_intr(void *data) 1757{ 1758 adapter_t *sc = data; 1759 1760 if (cxgb_debug) 1761 device_printf(sc->dev, "cxgb_async_intr\n"); |
1749 1750 t3_slow_intr_handler(sc); 1751 | 1762 /* 1763 * May need to sleep - defer to taskqueue 1764 */ 1765 taskqueue_enqueue(sc->tq, &sc->slow_intr_task); |
1752} 1753 1754static void 1755cxgb_ext_intr_handler(void *arg, int count) 1756{ 1757 adapter_t *sc = (adapter_t *)arg; 1758 1759 if (cxgb_debug) --- 59 unchanged lines hidden (view full) --- 1819 PORT_UNLOCK(p); 1820 } 1821} 1822 1823static void 1824cxgb_tick(void *arg) 1825{ 1826 adapter_t *sc = (adapter_t *)arg; | 1766} 1767 1768static void 1769cxgb_ext_intr_handler(void *arg, int count) 1770{ 1771 adapter_t *sc = (adapter_t *)arg; 1772 1773 if (cxgb_debug) --- 59 unchanged lines hidden (view full) --- 1833 PORT_UNLOCK(p); 1834 } 1835} 1836 1837static void 1838cxgb_tick(void *arg) 1839{ 1840 adapter_t *sc = (adapter_t *)arg; |
1841 1842 taskqueue_enqueue(sc->tq, &sc->tick_task); 1843 1844 if (sc->open_device_map != 0) 1845 callout_reset(&sc->cxgb_tick_ch, sc->params.stats_update_period * hz, 1846 cxgb_tick, sc); 1847} 1848 1849static void 1850cxgb_tick_handler(void *arg, int count) 1851{ 1852 adapter_t *sc = (adapter_t *)arg; |
|
1827 const struct adapter_params *p = &sc->params; 1828 | 1853 const struct adapter_params *p = &sc->params; 1854 |
1855 ADAPTER_LOCK(sc); |
|
1829 if (p->linkpoll_period) 1830 check_link_status(sc); | 1856 if (p->linkpoll_period) 1857 check_link_status(sc); |
1831 callout_reset(&sc->cxgb_tick_ch, sc->params.stats_update_period * hz, 1832 cxgb_tick, sc); | |
1833 1834 /* 1835 * adapter lock can currently only be acquire after the 1836 * port lock 1837 */ 1838 ADAPTER_UNLOCK(sc); 1839 1840 if (p->rev == T3_REV_B2) --- 466 unchanged lines hidden --- | 1858 1859 /* 1860 * adapter lock can currently only be acquire after the 1861 * port lock 1862 */ 1863 ADAPTER_UNLOCK(sc); 1864 1865 if (p->rev == T3_REV_B2) --- 466 unchanged lines hidden --- |