35 36#include <dev/ixgb/if_ixgb.h> 37 38/********************************************************************* 39 * Set this to one to display debug statistics 40 *********************************************************************/ 41int ixgb_display_debug_stats = 0; 42 43/********************************************************************* 44 * Linked list of board private structures for all NICs found 45 *********************************************************************/ 46 47struct adapter *ixgb_adapter_list = NULL; 48 49 50 51/********************************************************************* 52 * Driver version 53 *********************************************************************/ 54 55char ixgb_driver_version[] = "1.0.6"; 56char ixgb_copyright[] = "Copyright (c) 2001-2004 Intel Corporation."; 57 58/********************************************************************* 59 * PCI Device ID Table 60 * 61 * Used by probe to select devices to load on 62 * Last field stores an index into ixgb_strings 63 * Last entry must be all 0s 64 * 65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } 66 *********************************************************************/ 67 68static ixgb_vendor_info_t ixgb_vendor_info_array[] = 69{ 70 /* Intel(R) PRO/10000 Network Connection */ 71 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX, PCI_ANY_ID, PCI_ANY_ID, 0}, 72 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR, PCI_ANY_ID, PCI_ANY_ID, 0}, 73 /* required last entry */ 74 {0, 0, 0, 0, 0} 75}; 76 77/********************************************************************* 78 * Table of branding strings for all supported NICs. 79 *********************************************************************/ 80 81static char *ixgb_strings[] = { 82 "Intel(R) PRO/10GbE Network Driver" 83}; 84 85/********************************************************************* 86 * Function prototypes 87 *********************************************************************/ 88static int ixgb_probe(device_t); 89static int ixgb_attach(device_t); 90static int ixgb_detach(device_t); 91static int ixgb_shutdown(device_t); 92static void ixgb_intr(void *); 93static void ixgb_start(struct ifnet *); 94static void ixgb_start_locked(struct ifnet *); 95static int ixgb_ioctl(struct ifnet *, IOCTL_CMD_TYPE, caddr_t); 96static void ixgb_watchdog(struct ifnet *); 97static void ixgb_init(void *); 98static void ixgb_init_locked(struct adapter *); 99static void ixgb_stop(void *); 100static void ixgb_media_status(struct ifnet *, struct ifmediareq *); 101static int ixgb_media_change(struct ifnet *); 102static void ixgb_identify_hardware(struct adapter *); 103static int ixgb_allocate_pci_resources(struct adapter *); 104static void ixgb_free_pci_resources(struct adapter *); 105static void ixgb_local_timer(void *); 106static int ixgb_hardware_init(struct adapter *); 107static void ixgb_setup_interface(device_t, struct adapter *); 108static int ixgb_setup_transmit_structures(struct adapter *); 109static void ixgb_initialize_transmit_unit(struct adapter *); 110static int ixgb_setup_receive_structures(struct adapter *); 111static void ixgb_initialize_receive_unit(struct adapter *); 112static void ixgb_enable_intr(struct adapter *); 113static void ixgb_disable_intr(struct adapter *); 114static void ixgb_free_transmit_structures(struct adapter *); 115static void ixgb_free_receive_structures(struct adapter *); 116static void ixgb_update_stats_counters(struct adapter *); 117static void ixgb_clean_transmit_interrupts(struct adapter *); 118static int ixgb_allocate_receive_structures(struct adapter *); 119static int ixgb_allocate_transmit_structures(struct adapter *); 120static void ixgb_process_receive_interrupts(struct adapter *, int); 121static void 122ixgb_receive_checksum(struct adapter *, 123 struct ixgb_rx_desc * rx_desc, 124 struct mbuf *); 125static void 126ixgb_transmit_checksum_setup(struct adapter *, 127 struct mbuf *, 128 u_int8_t *); 129static void ixgb_set_promisc(struct adapter *); 130static void ixgb_disable_promisc(struct adapter *); 131static void ixgb_set_multi(struct adapter *); 132static void ixgb_print_hw_stats(struct adapter *); 133static void ixgb_print_link_status(struct adapter *); 134static int 135ixgb_get_buf(int i, struct adapter *, 136 struct mbuf *); 137static void ixgb_enable_vlans(struct adapter * adapter); 138static int ixgb_encap(struct adapter * adapter, struct mbuf * m_head); 139static int ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS); 140static int 141ixgb_dma_malloc(struct adapter *, bus_size_t, 142 struct ixgb_dma_alloc *, int); 143static void ixgb_dma_free(struct adapter *, struct ixgb_dma_alloc *); 144 145/********************************************************************* 146 * FreeBSD Device Interface Entry Points 147 *********************************************************************/ 148 149static device_method_t ixgb_methods[] = { 150 /* Device interface */ 151 DEVMETHOD(device_probe, ixgb_probe), 152 DEVMETHOD(device_attach, ixgb_attach), 153 DEVMETHOD(device_detach, ixgb_detach), 154 DEVMETHOD(device_shutdown, ixgb_shutdown), 155 {0, 0} 156}; 157 158static driver_t ixgb_driver = { 159 "ixgb", ixgb_methods, sizeof(struct adapter), 160}; 161 162static devclass_t ixgb_devclass; 163DRIVER_MODULE(if_ixgb, pci, ixgb_driver, ixgb_devclass, 0, 0); 164 165MODULE_DEPEND(if_ixgb, pci, 1, 1, 1); 166MODULE_DEPEND(if_ixgb, ether, 1, 1, 1); 167 168/* some defines for controlling descriptor fetches in h/w */ 169#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */ 170#define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is 171 * pushed this many descriptors from 172 * head */ 173#define RXDCTL_WTHRESH_DEFAULT 0 /* chip writes back at this many or RXT0 */ 174 175 176/********************************************************************* 177 * Device identification routine 178 * 179 * ixgb_probe determines if the driver should be loaded on 180 * adapter based on PCI vendor/device id of the adapter. 181 * 182 * return 0 on success, positive on failure 183 *********************************************************************/ 184 185static int 186ixgb_probe(device_t dev) 187{ 188 ixgb_vendor_info_t *ent; 189 190 u_int16_t pci_vendor_id = 0; 191 u_int16_t pci_device_id = 0; 192 u_int16_t pci_subvendor_id = 0; 193 u_int16_t pci_subdevice_id = 0; 194 char adapter_name[60]; 195 196 INIT_DEBUGOUT("ixgb_probe: begin"); 197 198 pci_vendor_id = pci_get_vendor(dev); 199 if (pci_vendor_id != IXGB_VENDOR_ID) 200 return (ENXIO); 201 202 pci_device_id = pci_get_device(dev); 203 pci_subvendor_id = pci_get_subvendor(dev); 204 pci_subdevice_id = pci_get_subdevice(dev); 205 206 ent = ixgb_vendor_info_array; 207 while (ent->vendor_id != 0) { 208 if ((pci_vendor_id == ent->vendor_id) && 209 (pci_device_id == ent->device_id) && 210 211 ((pci_subvendor_id == ent->subvendor_id) || 212 (ent->subvendor_id == PCI_ANY_ID)) && 213 214 ((pci_subdevice_id == ent->subdevice_id) || 215 (ent->subdevice_id == PCI_ANY_ID))) { 216 sprintf(adapter_name, "%s, Version - %s", 217 ixgb_strings[ent->index], 218 ixgb_driver_version); 219 device_set_desc_copy(dev, adapter_name); 220 return (BUS_PROBE_DEFAULT); 221 } 222 ent++; 223 } 224 225 return (ENXIO); 226} 227 228/********************************************************************* 229 * Device initialization routine 230 * 231 * The attach entry point is called when the driver is being loaded. 232 * This routine identifies the type of hardware, allocates all resources 233 * and initializes the hardware. 234 * 235 * return 0 on success, positive on failure 236 *********************************************************************/ 237 238static int 239ixgb_attach(device_t dev) 240{ 241 struct adapter *adapter; 242 int tsize, rsize; 243 int error = 0; 244 245 printf("ixgb%d: %s\n", device_get_unit(dev), ixgb_copyright); 246 INIT_DEBUGOUT("ixgb_attach: begin"); 247 248 /* Allocate, clear, and link in our adapter structure */ 249 if (!(adapter = device_get_softc(dev))) { 250 printf("ixgb: adapter structure allocation failed\n"); 251 return (ENOMEM); 252 } 253 bzero(adapter, sizeof(struct adapter)); 254 adapter->dev = dev; 255 adapter->osdep.dev = dev; 256 adapter->unit = device_get_unit(dev); 257 IXGB_LOCK_INIT(adapter, device_get_nameunit(dev)); 258 259 if (ixgb_adapter_list != NULL) 260 ixgb_adapter_list->prev = adapter; 261 adapter->next = ixgb_adapter_list; 262 ixgb_adapter_list = adapter; 263 264 /* SYSCTL APIs */ 265 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 266 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 267 OID_AUTO, "stats", CTLTYPE_INT | CTLFLAG_RW, 268 (void *)adapter, 0, 269 ixgb_sysctl_stats, "I", "Statistics"); 270 271 callout_init(&adapter->timer, CALLOUT_MPSAFE); 272 273 /* Determine hardware revision */ 274 ixgb_identify_hardware(adapter); 275 276 /* Parameters (to be read from user) */ 277 adapter->num_tx_desc = IXGB_MAX_TXD; 278 adapter->num_rx_desc = IXGB_MAX_RXD; 279 adapter->tx_int_delay = TIDV; 280 adapter->rx_int_delay = RDTR; 281 adapter->rx_buffer_len = IXGB_RXBUFFER_2048; 282 283 adapter->hw.fc.high_water = FCRTH; 284 adapter->hw.fc.low_water = FCRTL; 285 adapter->hw.fc.pause_time = FCPAUSE; 286 adapter->hw.fc.send_xon = TRUE; 287 adapter->hw.fc.type = FLOW_CONTROL; 288 289 290 /* Set the max frame size assuming standard ethernet sized frames */ 291 adapter->hw.max_frame_size = 292 ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN; 293 294 if (ixgb_allocate_pci_resources(adapter)) { 295 printf("ixgb%d: Allocation of PCI resources failed\n", 296 adapter->unit); 297 error = ENXIO; 298 goto err_pci; 299 } 300 tsize = IXGB_ROUNDUP(adapter->num_tx_desc * 301 sizeof(struct ixgb_tx_desc), 4096); 302 303 /* Allocate Transmit Descriptor ring */ 304 if (ixgb_dma_malloc(adapter, tsize, &adapter->txdma, BUS_DMA_NOWAIT)) { 305 printf("ixgb%d: Unable to allocate TxDescriptor memory\n", 306 adapter->unit); 307 error = ENOMEM; 308 goto err_tx_desc; 309 } 310 adapter->tx_desc_base = (struct ixgb_tx_desc *) adapter->txdma.dma_vaddr; 311 312 rsize = IXGB_ROUNDUP(adapter->num_rx_desc * 313 sizeof(struct ixgb_rx_desc), 4096); 314 315 /* Allocate Receive Descriptor ring */ 316 if (ixgb_dma_malloc(adapter, rsize, &adapter->rxdma, BUS_DMA_NOWAIT)) { 317 printf("ixgb%d: Unable to allocate rx_desc memory\n", 318 adapter->unit); 319 error = ENOMEM; 320 goto err_rx_desc; 321 } 322 adapter->rx_desc_base = (struct ixgb_rx_desc *) adapter->rxdma.dma_vaddr; 323 324 /* Initialize the hardware */ 325 if (ixgb_hardware_init(adapter)) { 326 printf("ixgb%d: Unable to initialize the hardware\n", 327 adapter->unit); 328 error = EIO; 329 goto err_hw_init; 330 } 331 /* Setup OS specific network interface */ 332 ixgb_setup_interface(dev, adapter); 333 334 /* Initialize statistics */ 335 ixgb_clear_hw_cntrs(&adapter->hw); 336 ixgb_update_stats_counters(adapter); 337 338 INIT_DEBUGOUT("ixgb_attach: end"); 339 return (0); 340 341err_hw_init: 342 ixgb_dma_free(adapter, &adapter->rxdma); 343err_rx_desc: 344 ixgb_dma_free(adapter, &adapter->txdma); 345err_tx_desc: 346err_pci: 347 ixgb_free_pci_resources(adapter); 348 sysctl_ctx_free(&adapter->sysctl_ctx); 349 return (error); 350 351} 352 353/********************************************************************* 354 * Device removal routine 355 * 356 * The detach entry point is called when the driver is being removed. 357 * This routine stops the adapter and deallocates all the resources 358 * that were allocated for driver operation. 359 * 360 * return 0 on success, positive on failure 361 *********************************************************************/ 362 363static int 364ixgb_detach(device_t dev) 365{ 366 struct adapter *adapter = device_get_softc(dev); 367 struct ifnet *ifp = adapter->ifp; 368 369 INIT_DEBUGOUT("ixgb_detach: begin"); 370 371 IXGB_LOCK(adapter); 372 adapter->in_detach = 1; 373 374 ixgb_stop(adapter); 375 IXGB_UNLOCK(adapter); 376 377#if __FreeBSD_version < 500000 378 ether_ifdetach(adapter->ifp, ETHER_BPF_SUPPORTED); 379#else 380 ether_ifdetach(adapter->ifp);
|
387 /* Free Transmit Descriptor ring */ 388 if (adapter->tx_desc_base) { 389 ixgb_dma_free(adapter, &adapter->txdma); 390 adapter->tx_desc_base = NULL; 391 } 392 /* Free Receive Descriptor ring */ 393 if (adapter->rx_desc_base) { 394 ixgb_dma_free(adapter, &adapter->rxdma); 395 adapter->rx_desc_base = NULL; 396 } 397 /* Remove from the adapter list */ 398 if (ixgb_adapter_list == adapter) 399 ixgb_adapter_list = adapter->next; 400 if (adapter->next != NULL) 401 adapter->next->prev = adapter->prev; 402 if (adapter->prev != NULL) 403 adapter->prev->next = adapter->next; 404 405 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 406 ifp->if_timer = 0; 407 408 IXGB_LOCK_DESTROY(adapter); 409 return (0); 410} 411 412/********************************************************************* 413 * 414 * Shutdown entry point 415 * 416 **********************************************************************/ 417 418static int 419ixgb_shutdown(device_t dev) 420{ 421 struct adapter *adapter = device_get_softc(dev); 422 IXGB_LOCK(adapter); 423 ixgb_stop(adapter); 424 IXGB_UNLOCK(adapter); 425 return (0); 426} 427 428 429/********************************************************************* 430 * Transmit entry point 431 * 432 * ixgb_start is called by the stack to initiate a transmit. 433 * The driver will remain in this routine as long as there are 434 * packets to transmit and transmit resources are available. 435 * In case resources are not available stack is notified and 436 * the packet is requeued. 437 **********************************************************************/ 438 439static void 440ixgb_start_locked(struct ifnet * ifp) 441{ 442 struct mbuf *m_head; 443 struct adapter *adapter = ifp->if_softc; 444 445 IXGB_LOCK_ASSERT(adapter); 446 447 if (!adapter->link_active) 448 return; 449 450 while (ifp->if_snd.ifq_head != NULL) { 451 IF_DEQUEUE(&ifp->if_snd, m_head); 452 453 if (m_head == NULL) 454 break; 455 456 if (ixgb_encap(adapter, m_head)) { 457 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 458 IF_PREPEND(&ifp->if_snd, m_head); 459 break; 460 } 461 /* Send a copy of the frame to the BPF listener */ 462#if __FreeBSD_version < 500000 463 if (ifp->if_bpf) 464 bpf_mtap(ifp, m_head); 465#else 466 BPF_MTAP(ifp, m_head); 467#endif 468 /* Set timeout in case hardware has problems transmitting */ 469 ifp->if_timer = IXGB_TX_TIMEOUT; 470 471 } 472 return; 473} 474 475static void 476ixgb_start(struct ifnet *ifp) 477{ 478 struct adapter *adapter = ifp->if_softc; 479 480 IXGB_LOCK(adapter); 481 ixgb_start_locked(ifp); 482 IXGB_UNLOCK(adapter); 483 return; 484} 485 486/********************************************************************* 487 * Ioctl entry point 488 * 489 * ixgb_ioctl is called when the user wants to configure the 490 * interface. 491 * 492 * return 0 on success, positive on failure 493 **********************************************************************/ 494 495static int 496ixgb_ioctl(struct ifnet * ifp, IOCTL_CMD_TYPE command, caddr_t data) 497{ 498 int mask, error = 0; 499 struct ifreq *ifr = (struct ifreq *) data; 500 struct adapter *adapter = ifp->if_softc; 501 502 if (adapter->in_detach) 503 goto out; 504 505 switch (command) { 506 case SIOCSIFADDR: 507 case SIOCGIFADDR: 508 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)"); 509 ether_ioctl(ifp, command, data); 510 break; 511 case SIOCSIFMTU: 512 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)"); 513 if (ifr->ifr_mtu > IXGB_MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) { 514 error = EINVAL; 515 } else { 516 IXGB_LOCK(adapter); 517 ifp->if_mtu = ifr->ifr_mtu; 518 adapter->hw.max_frame_size = 519 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; 520 521 ixgb_init_locked(adapter); 522 IXGB_UNLOCK(adapter); 523 } 524 break; 525 case SIOCSIFFLAGS: 526 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)"); 527 IXGB_LOCK(adapter); 528 if (ifp->if_flags & IFF_UP) { 529 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 530 ixgb_init_locked(adapter); 531 } 532 ixgb_disable_promisc(adapter); 533 ixgb_set_promisc(adapter); 534 } else { 535 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 536 ixgb_stop(adapter); 537 } 538 } 539 IXGB_UNLOCK(adapter); 540 break; 541 case SIOCADDMULTI: 542 case SIOCDELMULTI: 543 IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI"); 544 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 545 IXGB_LOCK(adapter); 546 ixgb_disable_intr(adapter); 547 ixgb_set_multi(adapter); 548 ixgb_enable_intr(adapter); 549 IXGB_UNLOCK(adapter); 550 } 551 break; 552 case SIOCSIFMEDIA: 553 case SIOCGIFMEDIA: 554 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)"); 555 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command); 556 break; 557 case SIOCSIFCAP: 558 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)"); 559 mask = ifr->ifr_reqcap ^ ifp->if_capenable; 560 if (mask & IFCAP_HWCSUM) { 561 if (IFCAP_HWCSUM & ifp->if_capenable) 562 ifp->if_capenable &= ~IFCAP_HWCSUM; 563 else 564 ifp->if_capenable |= IFCAP_HWCSUM; 565 if (ifp->if_drv_flags & IFF_DRV_RUNNING) 566 ixgb_init(adapter); 567 } 568 break; 569 default: 570 IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%X)\n", (int)command); 571 error = EINVAL; 572 } 573 574out: 575 return (error); 576} 577 578/********************************************************************* 579 * Watchdog entry point 580 * 581 * This routine is called whenever hardware quits transmitting. 582 * 583 **********************************************************************/ 584 585static void 586ixgb_watchdog(struct ifnet * ifp) 587{ 588 struct adapter *adapter; 589 adapter = ifp->if_softc; 590 591 /* 592 * If we are in this routine because of pause frames, then don't 593 * reset the hardware. 594 */ 595 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_TXOFF) { 596 ifp->if_timer = IXGB_TX_TIMEOUT; 597 return; 598 } 599 printf("ixgb%d: watchdog timeout -- resetting\n", adapter->unit); 600 601 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 602 603 604 ixgb_stop(adapter); 605 ixgb_init(adapter); 606 607 608 ifp->if_oerrors++; 609 610 return; 611} 612 613/********************************************************************* 614 * Init entry point 615 * 616 * This routine is used in two ways. It is used by the stack as 617 * init entry point in network interface structure. It is also used 618 * by the driver as a hw/sw initialization routine to get to a 619 * consistent state. 620 * 621 * return 0 on success, positive on failure 622 **********************************************************************/ 623 624static void 625ixgb_init_locked(struct adapter *adapter) 626{ 627 struct ifnet *ifp; 628 629 INIT_DEBUGOUT("ixgb_init: begin"); 630 631 IXGB_LOCK_ASSERT(adapter); 632 633 ixgb_stop(adapter); 634 635 /* Get the latest mac address, User can use a LAA */ 636 bcopy(IFP2ENADDR(adapter->ifp), adapter->hw.curr_mac_addr, 637 IXGB_ETH_LENGTH_OF_ADDRESS); 638 639 /* Initialize the hardware */ 640 if (ixgb_hardware_init(adapter)) { 641 printf("ixgb%d: Unable to initialize the hardware\n", 642 adapter->unit); 643 return; 644 } 645 ixgb_enable_vlans(adapter); 646 647 /* Prepare transmit descriptors and buffers */ 648 if (ixgb_setup_transmit_structures(adapter)) { 649 printf("ixgb%d: Could not setup transmit structures\n", 650 adapter->unit); 651 ixgb_stop(adapter); 652 return; 653 } 654 ixgb_initialize_transmit_unit(adapter); 655 656 /* Setup Multicast table */ 657 ixgb_set_multi(adapter); 658 659 /* Prepare receive descriptors and buffers */ 660 if (ixgb_setup_receive_structures(adapter)) { 661 printf("ixgb%d: Could not setup receive structures\n", 662 adapter->unit); 663 ixgb_stop(adapter); 664 return; 665 } 666 ixgb_initialize_receive_unit(adapter); 667 668 /* Don't loose promiscuous settings */ 669 ixgb_set_promisc(adapter); 670 671 ifp = adapter->ifp; 672 ifp->if_drv_flags |= IFF_DRV_RUNNING; 673 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 674 675 676 if (ifp->if_capenable & IFCAP_TXCSUM) 677 ifp->if_hwassist = IXGB_CHECKSUM_FEATURES; 678 else 679 ifp->if_hwassist = 0; 680 681 682 /* Enable jumbo frames */ 683 if (ifp->if_mtu > ETHERMTU) { 684 uint32_t temp_reg; 685 IXGB_WRITE_REG(&adapter->hw, MFS, 686 adapter->hw.max_frame_size << IXGB_MFS_SHIFT); 687 temp_reg = IXGB_READ_REG(&adapter->hw, CTRL0); 688 temp_reg |= IXGB_CTRL0_JFE; 689 IXGB_WRITE_REG(&adapter->hw, CTRL0, temp_reg); 690 } 691 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter); 692 ixgb_clear_hw_cntrs(&adapter->hw); 693#ifdef DEVICE_POLLING 694 /* 695 * Only disable interrupts if we are polling, make sure they are on 696 * otherwise. 697 */ 698 if (ifp->if_flags & IFF_POLLING) 699 ixgb_disable_intr(adapter); 700 else 701#endif /* DEVICE_POLLING */ 702 ixgb_enable_intr(adapter); 703 704 return; 705} 706 707static void 708ixgb_init(void *arg) 709{ 710 struct adapter *adapter = arg; 711 712 IXGB_LOCK(adapter); 713 ixgb_init_locked(adapter); 714 IXGB_UNLOCK(adapter); 715 return; 716} 717 718#ifdef DEVICE_POLLING 719static poll_handler_t ixgb_poll; 720 721static void 722ixgb_poll_locked(struct ifnet * ifp, enum poll_cmd cmd, int count) 723{ 724 struct adapter *adapter = ifp->if_softc; 725 u_int32_t reg_icr; 726 727 IXGB_LOCK_ASSERT(adapter); 728 729 if (!(ifp->if_capenable & IFCAP_POLLING)) { 730 ether_poll_deregister(ifp); 731 cmd = POLL_DEREGISTER; 732 } 733 734 if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */ 735 ixgb_enable_intr(adapter); 736 return; 737 } 738 if (cmd == POLL_AND_CHECK_STATUS) { 739 reg_icr = IXGB_READ_REG(&adapter->hw, ICR); 740 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) { 741 callout_stop(&adapter->timer); 742 ixgb_check_for_link(&adapter->hw); 743 ixgb_print_link_status(adapter); 744 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, 745 adapter); 746 } 747 } 748 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 749 ixgb_process_receive_interrupts(adapter, count); 750 ixgb_clean_transmit_interrupts(adapter); 751 } 752 if (ifp->if_drv_flags & IFF_DRV_RUNNING && 753 ifp->if_snd.ifq_head != NULL) 754 ixgb_start_locked(ifp); 755} 756 757static void 758ixgb_poll(struct ifnet * ifp, enum poll_cmd cmd, int count) 759{ 760 struct adapter *adapter = ifp->if_softc; 761 762 IXGB_LOCK(adapter); 763 ixgb_poll_locked(ifp, cmd, count); 764 IXGB_UNLOCK(adapter); 765} 766#endif /* DEVICE_POLLING */ 767 768/********************************************************************* 769 * 770 * Interrupt Service routine 771 * 772 **********************************************************************/ 773 774static void 775ixgb_intr(void *arg) 776{ 777 u_int32_t loop_cnt = IXGB_MAX_INTR; 778 u_int32_t reg_icr; 779 struct ifnet *ifp; 780 struct adapter *adapter = arg; 781 boolean_t rxdmt0 = FALSE; 782 783 IXGB_LOCK(adapter); 784 785 ifp = adapter->ifp; 786 787#ifdef DEVICE_POLLING 788 if (ifp->if_flags & IFF_POLLING) { 789 IXGB_UNLOCK(adapter); 790 return; 791 } 792 793 if ((ifp->if_capenable & IFCAP_POLLING) && 794 ether_poll_register(ixgb_poll, ifp)) { 795 ixgb_disable_intr(adapter); 796 ixgb_poll_locked(ifp, 0, 1); 797 IXGB_UNLOCK(adapter); 798 return; 799 } 800#endif /* DEVICE_POLLING */ 801 802 reg_icr = IXGB_READ_REG(&adapter->hw, ICR); 803 if (reg_icr == 0) { 804 IXGB_UNLOCK(adapter); 805 return; 806 } 807 808 if (reg_icr & IXGB_INT_RXDMT0) 809 rxdmt0 = TRUE; 810 811#ifdef _SV_ 812 if (reg_icr & IXGB_INT_RXDMT0) 813 adapter->sv_stats.icr_rxdmt0++; 814 if (reg_icr & IXGB_INT_RXO) 815 adapter->sv_stats.icr_rxo++; 816 if (reg_icr & IXGB_INT_RXT0) 817 adapter->sv_stats.icr_rxt0++; 818 if (reg_icr & IXGB_INT_TXDW) 819 adapter->sv_stats.icr_TXDW++; 820#endif /* _SV_ */ 821 822 /* Link status change */ 823 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) { 824 callout_stop(&adapter->timer); 825 ixgb_check_for_link(&adapter->hw); 826 ixgb_print_link_status(adapter); 827 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, 828 adapter); 829 } 830 while (loop_cnt > 0) { 831 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 832 ixgb_process_receive_interrupts(adapter, -1); 833 ixgb_clean_transmit_interrupts(adapter); 834 } 835 loop_cnt--; 836 } 837 838 if (rxdmt0 && adapter->raidc) { 839 IXGB_WRITE_REG(&adapter->hw, IMC, IXGB_INT_RXDMT0); 840 IXGB_WRITE_REG(&adapter->hw, IMS, IXGB_INT_RXDMT0); 841 } 842 if (ifp->if_drv_flags & IFF_DRV_RUNNING && ifp->if_snd.ifq_head != NULL) 843 ixgb_start_locked(ifp); 844 845 IXGB_UNLOCK(adapter); 846 return; 847} 848 849 850/********************************************************************* 851 * 852 * Media Ioctl callback 853 * 854 * This routine is called whenever the user queries the status of 855 * the interface using ifconfig. 856 * 857 **********************************************************************/ 858static void 859ixgb_media_status(struct ifnet * ifp, struct ifmediareq * ifmr) 860{ 861 struct adapter *adapter = ifp->if_softc; 862 863 INIT_DEBUGOUT("ixgb_media_status: begin"); 864 865 ixgb_check_for_link(&adapter->hw); 866 ixgb_print_link_status(adapter); 867 868 ifmr->ifm_status = IFM_AVALID; 869 ifmr->ifm_active = IFM_ETHER; 870 871 if (!adapter->hw.link_up) 872 return; 873 874 ifmr->ifm_status |= IFM_ACTIVE; 875 ifmr->ifm_active |= IFM_1000_SX | IFM_FDX; 876 877 return; 878} 879 880/********************************************************************* 881 * 882 * Media Ioctl callback 883 * 884 * This routine is called when the user changes speed/duplex using 885 * media/mediopt option with ifconfig. 886 * 887 **********************************************************************/ 888static int 889ixgb_media_change(struct ifnet * ifp) 890{ 891 struct adapter *adapter = ifp->if_softc; 892 struct ifmedia *ifm = &adapter->media; 893 894 INIT_DEBUGOUT("ixgb_media_change: begin"); 895 896 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 897 return (EINVAL); 898 899 return (0); 900} 901 902/********************************************************************* 903 * 904 * This routine maps the mbufs to tx descriptors. 905 * 906 * return 0 on success, positive on failure 907 **********************************************************************/ 908 909static int 910ixgb_encap(struct adapter * adapter, struct mbuf * m_head) 911{ 912 u_int8_t txd_popts; 913 int i, j, error, nsegs; 914 915#if __FreeBSD_version < 500000 916 struct ifvlan *ifv = NULL; 917#else 918 struct m_tag *mtag; 919#endif 920 bus_dma_segment_t segs[IXGB_MAX_SCATTER]; 921 bus_dmamap_t map; 922 struct ixgb_buffer *tx_buffer = NULL; 923 struct ixgb_tx_desc *current_tx_desc = NULL; 924 struct ifnet *ifp = adapter->ifp; 925 926 /* 927 * Force a cleanup if number of TX descriptors available hits the 928 * threshold 929 */ 930 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) { 931 ixgb_clean_transmit_interrupts(adapter); 932 } 933 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) { 934 adapter->no_tx_desc_avail1++; 935 return (ENOBUFS); 936 } 937 /* 938 * Map the packet for DMA. 939 */ 940 if (bus_dmamap_create(adapter->txtag, BUS_DMA_NOWAIT, &map)) { 941 adapter->no_tx_map_avail++; 942 return (ENOMEM); 943 } 944 error = bus_dmamap_load_mbuf_sg(adapter->txtag, map, m_head, segs, 945 &nsegs, BUS_DMA_NOWAIT); 946 if (error != 0) { 947 adapter->no_tx_dma_setup++; 948 printf("ixgb%d: ixgb_encap: bus_dmamap_load_mbuf failed; " 949 "error %u\n", adapter->unit, error); 950 bus_dmamap_destroy(adapter->txtag, map); 951 return (error); 952 } 953 KASSERT(nsegs != 0, ("ixgb_encap: empty packet")); 954 955 if (nsegs > adapter->num_tx_desc_avail) { 956 adapter->no_tx_desc_avail2++; 957 bus_dmamap_destroy(adapter->txtag, map); 958 return (ENOBUFS); 959 } 960 if (ifp->if_hwassist > 0) { 961 ixgb_transmit_checksum_setup(adapter, m_head, 962 &txd_popts); 963 } else 964 txd_popts = 0; 965 966 /* Find out if we are in vlan mode */ 967#if __FreeBSD_version < 500000 968 if ((m_head->m_flags & (M_PROTO1 | M_PKTHDR)) == (M_PROTO1 | M_PKTHDR) && 969 m_head->m_pkthdr.rcvif != NULL && 970 m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN) 971 ifv = m_head->m_pkthdr.rcvif->if_softc; 972#else 973 mtag = VLAN_OUTPUT_TAG(ifp, m_head); 974#endif 975 i = adapter->next_avail_tx_desc; 976 for (j = 0; j < nsegs; j++) { 977 tx_buffer = &adapter->tx_buffer_area[i]; 978 current_tx_desc = &adapter->tx_desc_base[i]; 979 980 current_tx_desc->buff_addr = htole64(segs[j].ds_addr); 981 current_tx_desc->cmd_type_len = (adapter->txd_cmd | segs[j].ds_len); 982 current_tx_desc->popts = txd_popts; 983 if (++i == adapter->num_tx_desc) 984 i = 0; 985 986 tx_buffer->m_head = NULL; 987 } 988 989 adapter->num_tx_desc_avail -= nsegs; 990 adapter->next_avail_tx_desc = i; 991 992#if __FreeBSD_version < 500000 993 if (ifv != NULL) { 994 /* Set the vlan id */ 995 current_tx_desc->vlan = ifv->ifv_tag; 996#else 997 if (mtag != NULL) { 998 /* Set the vlan id */ 999 current_tx_desc->vlan = VLAN_TAG_VALUE(mtag); 1000#endif 1001 1002 /* Tell hardware to add tag */ 1003 current_tx_desc->cmd_type_len |= IXGB_TX_DESC_CMD_VLE; 1004 } 1005 tx_buffer->m_head = m_head; 1006 tx_buffer->map = map; 1007 bus_dmamap_sync(adapter->txtag, map, BUS_DMASYNC_PREWRITE); 1008 1009 /* 1010 * Last Descriptor of Packet needs End Of Packet (EOP) 1011 */ 1012 current_tx_desc->cmd_type_len |= (IXGB_TX_DESC_CMD_EOP); 1013 1014 /* 1015 * Advance the Transmit Descriptor Tail (Tdt), this tells the E1000 1016 * that this frame is available to transmit. 1017 */ 1018 IXGB_WRITE_REG(&adapter->hw, TDT, i); 1019 1020 return (0); 1021} 1022 1023static void 1024ixgb_set_promisc(struct adapter * adapter) 1025{ 1026 1027 u_int32_t reg_rctl; 1028 struct ifnet *ifp = adapter->ifp; 1029 1030 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL); 1031 1032 if (ifp->if_flags & IFF_PROMISC) { 1033 reg_rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE); 1034 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl); 1035 } else if (ifp->if_flags & IFF_ALLMULTI) { 1036 reg_rctl |= IXGB_RCTL_MPE; 1037 reg_rctl &= ~IXGB_RCTL_UPE; 1038 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl); 1039 } 1040 return; 1041} 1042 1043static void 1044ixgb_disable_promisc(struct adapter * adapter) 1045{ 1046 u_int32_t reg_rctl; 1047 1048 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL); 1049 1050 reg_rctl &= (~IXGB_RCTL_UPE); 1051 reg_rctl &= (~IXGB_RCTL_MPE); 1052 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl); 1053 1054 return; 1055} 1056 1057 1058/********************************************************************* 1059 * Multicast Update 1060 * 1061 * This routine is called whenever multicast address list is updated. 1062 * 1063 **********************************************************************/ 1064 1065static void 1066ixgb_set_multi(struct adapter * adapter) 1067{ 1068 u_int32_t reg_rctl = 0; 1069 u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * IXGB_ETH_LENGTH_OF_ADDRESS]; 1070 struct ifmultiaddr *ifma; 1071 int mcnt = 0; 1072 struct ifnet *ifp = adapter->ifp; 1073 1074 IOCTL_DEBUGOUT("ixgb_set_multi: begin"); 1075 1076 IF_ADDR_LOCK(ifp); 1077#if __FreeBSD_version < 500000 1078 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 1079#else 1080 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 1081#endif 1082 if (ifma->ifma_addr->sa_family != AF_LINK) 1083 continue; 1084 1085 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr), 1086 &mta[mcnt * IXGB_ETH_LENGTH_OF_ADDRESS], IXGB_ETH_LENGTH_OF_ADDRESS); 1087 mcnt++; 1088 } 1089 IF_ADDR_UNLOCK(ifp); 1090 1091 if (mcnt > MAX_NUM_MULTICAST_ADDRESSES) { 1092 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL); 1093 reg_rctl |= IXGB_RCTL_MPE; 1094 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl); 1095 } else 1096 ixgb_mc_addr_list_update(&adapter->hw, mta, mcnt, 0); 1097 1098 return; 1099} 1100 1101 1102/********************************************************************* 1103 * Timer routine 1104 * 1105 * This routine checks for link status and updates statistics. 1106 * 1107 **********************************************************************/ 1108 1109static void 1110ixgb_local_timer(void *arg) 1111{ 1112 struct ifnet *ifp; 1113 struct adapter *adapter = arg; 1114 ifp = adapter->ifp; 1115 1116 IXGB_LOCK(adapter); 1117 1118 ixgb_check_for_link(&adapter->hw); 1119 ixgb_print_link_status(adapter); 1120 ixgb_update_stats_counters(adapter); 1121 if (ixgb_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) { 1122 ixgb_print_hw_stats(adapter); 1123 } 1124 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter); 1125 1126 IXGB_UNLOCK(adapter); 1127 return; 1128} 1129 1130static void 1131ixgb_print_link_status(struct adapter * adapter) 1132{ 1133 if (adapter->hw.link_up) { 1134 if (!adapter->link_active) { 1135 printf("ixgb%d: Link is up %d Mbps %s \n", 1136 adapter->unit, 1137 10000, 1138 "Full Duplex"); 1139 adapter->link_active = 1; 1140 } 1141 } else { 1142 if (adapter->link_active) { 1143 printf("ixgb%d: Link is Down \n", adapter->unit); 1144 adapter->link_active = 0; 1145 } 1146 } 1147 1148 return; 1149} 1150 1151 1152 1153/********************************************************************* 1154 * 1155 * This routine disables all traffic on the adapter by issuing a 1156 * global reset on the MAC and deallocates TX/RX buffers. 1157 * 1158 **********************************************************************/ 1159 1160static void 1161ixgb_stop(void *arg) 1162{ 1163 struct ifnet *ifp; 1164 struct adapter *adapter = arg; 1165 ifp = adapter->ifp; 1166 1167 IXGB_LOCK_ASSERT(adapter); 1168 1169 INIT_DEBUGOUT("ixgb_stop: begin\n"); 1170 ixgb_disable_intr(adapter); 1171 adapter->hw.adapter_stopped = FALSE; 1172 ixgb_adapter_stop(&adapter->hw); 1173 callout_stop(&adapter->timer); 1174 ixgb_free_transmit_structures(adapter); 1175 ixgb_free_receive_structures(adapter); 1176 1177 1178 /* Tell the stack that the interface is no longer active */ 1179 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 1180 1181 return; 1182} 1183 1184 1185/********************************************************************* 1186 * 1187 * Determine hardware revision. 1188 * 1189 **********************************************************************/ 1190static void 1191ixgb_identify_hardware(struct adapter * adapter) 1192{ 1193 device_t dev = adapter->dev; 1194 1195 /* Make sure our PCI config space has the necessary stuff set */ 1196 adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); 1197 if (!((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) && 1198 (adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN))) { 1199 printf("ixgb%d: Memory Access and/or Bus Master bits were not set!\n", 1200 adapter->unit); 1201 adapter->hw.pci_cmd_word |= 1202 (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN); 1203 pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2); 1204 } 1205 /* Save off the information about this board */ 1206 adapter->hw.vendor_id = pci_get_vendor(dev); 1207 adapter->hw.device_id = pci_get_device(dev); 1208 adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1); 1209 adapter->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2); 1210 adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2); 1211 1212 /* Set MacType, etc. based on this PCI info */ 1213 switch (adapter->hw.device_id) { 1214 case IXGB_DEVICE_ID_82597EX: 1215 case IXGB_DEVICE_ID_82597EX_SR: 1216 adapter->hw.mac_type = ixgb_82597; 1217 break; 1218 default: 1219 INIT_DEBUGOUT1("Unknown device if 0x%x", adapter->hw.device_id); 1220 printf("ixgb%d: unsupported device id 0x%x\n", adapter->unit, adapter->hw.device_id); 1221 } 1222 1223 return; 1224} 1225 1226static int 1227ixgb_allocate_pci_resources(struct adapter * adapter) 1228{ 1229 int rid; 1230 device_t dev = adapter->dev; 1231 1232 rid = IXGB_MMBA; 1233 adapter->res_memory = bus_alloc_resource(dev, SYS_RES_MEMORY, 1234 &rid, 0, ~0, 1, 1235 RF_ACTIVE); 1236 if (!(adapter->res_memory)) { 1237 printf("ixgb%d: Unable to allocate bus resource: memory\n", 1238 adapter->unit); 1239 return (ENXIO); 1240 } 1241 adapter->osdep.mem_bus_space_tag = 1242 rman_get_bustag(adapter->res_memory); 1243 adapter->osdep.mem_bus_space_handle = 1244 rman_get_bushandle(adapter->res_memory); 1245 adapter->hw.hw_addr = (uint8_t *) & adapter->osdep.mem_bus_space_handle; 1246 1247 rid = 0x0; 1248 adapter->res_interrupt = bus_alloc_resource(dev, SYS_RES_IRQ, 1249 &rid, 0, ~0, 1, 1250 RF_SHAREABLE | RF_ACTIVE); 1251 if (!(adapter->res_interrupt)) { 1252 printf("ixgb%d: Unable to allocate bus resource: interrupt\n", 1253 adapter->unit); 1254 return (ENXIO); 1255 } 1256 if (bus_setup_intr(dev, adapter->res_interrupt, 1257 INTR_TYPE_NET | INTR_MPSAFE, 1258 (void (*) (void *))ixgb_intr, adapter, 1259 &adapter->int_handler_tag)) { 1260 printf("ixgb%d: Error registering interrupt handler!\n", 1261 adapter->unit); 1262 return (ENXIO); 1263 } 1264 adapter->hw.back = &adapter->osdep; 1265 1266 return (0); 1267} 1268 1269static void 1270ixgb_free_pci_resources(struct adapter * adapter) 1271{ 1272 device_t dev = adapter->dev; 1273 1274 if (adapter->res_interrupt != NULL) { 1275 bus_teardown_intr(dev, adapter->res_interrupt, 1276 adapter->int_handler_tag); 1277 bus_release_resource(dev, SYS_RES_IRQ, 0, 1278 adapter->res_interrupt); 1279 } 1280 if (adapter->res_memory != NULL) { 1281 bus_release_resource(dev, SYS_RES_MEMORY, IXGB_MMBA, 1282 adapter->res_memory); 1283 } 1284 if (adapter->res_ioport != NULL) { 1285 bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid, 1286 adapter->res_ioport); 1287 } 1288 return; 1289} 1290 1291/********************************************************************* 1292 * 1293 * Initialize the hardware to a configuration as specified by the 1294 * adapter structure. The controller is reset, the EEPROM is 1295 * verified, the MAC address is set, then the shared initialization 1296 * routines are called. 1297 * 1298 **********************************************************************/ 1299static int 1300ixgb_hardware_init(struct adapter * adapter) 1301{ 1302 /* Issue a global reset */ 1303 adapter->hw.adapter_stopped = FALSE; 1304 ixgb_adapter_stop(&adapter->hw); 1305 1306 /* Make sure we have a good EEPROM before we read from it */ 1307 if (!ixgb_validate_eeprom_checksum(&adapter->hw)) { 1308 printf("ixgb%d: The EEPROM Checksum Is Not Valid\n", 1309 adapter->unit); 1310 return (EIO); 1311 } 1312 if (!ixgb_init_hw(&adapter->hw)) { 1313 printf("ixgb%d: Hardware Initialization Failed", 1314 adapter->unit); 1315 return (EIO); 1316 } 1317 1318 return (0); 1319} 1320 1321/********************************************************************* 1322 * 1323 * Setup networking device structure and register an interface. 1324 * 1325 **********************************************************************/ 1326static void 1327ixgb_setup_interface(device_t dev, struct adapter * adapter) 1328{ 1329 struct ifnet *ifp; 1330 INIT_DEBUGOUT("ixgb_setup_interface: begin"); 1331 1332 ifp = adapter->ifp = if_alloc(IFT_ETHER); 1333 if (ifp == NULL) 1334 panic("%s: can not if_alloc()\n", device_get_nameunit(dev)); 1335#if __FreeBSD_version >= 502000 1336 if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 1337#else 1338 ifp->if_unit = adapter->unit; 1339 ifp->if_name = "ixgb"; 1340#endif 1341 ifp->if_mtu = ETHERMTU; 1342 ifp->if_baudrate = 1000000000; 1343 ifp->if_init = ixgb_init; 1344 ifp->if_softc = adapter; 1345 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 1346 ifp->if_ioctl = ixgb_ioctl; 1347 ifp->if_start = ixgb_start; 1348 ifp->if_watchdog = ixgb_watchdog; 1349 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 1; 1350 1351#if __FreeBSD_version < 500000 1352 ether_ifattach(ifp, ETHER_BPF_SUPPORTED); 1353#else 1354 ether_ifattach(ifp, adapter->hw.curr_mac_addr); 1355#endif 1356 1357 ifp->if_capabilities = IFCAP_HWCSUM; 1358#ifdef DEVICE_POLLING 1359 ifp->if_capabilities |= IFCAP_POLLING; 1360#endif 1361 1362 /* 1363 * Tell the upper layer(s) we support long frames. 1364 */ 1365 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); 1366 1367#if __FreeBSD_version >= 500000 1368 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; 1369#endif 1370 1371 ifp->if_capenable = ifp->if_capabilities; 1372 1373 /* 1374 * Specify the media types supported by this adapter and register 1375 * callbacks to update media and link information 1376 */ 1377 ifmedia_init(&adapter->media, IFM_IMASK, ixgb_media_change, 1378 ixgb_media_status); 1379 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX, 1380 0, NULL); 1381 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX, 1382 0, NULL); 1383 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL); 1384 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO); 1385 1386 return; 1387} 1388 1389/******************************************************************** 1390 * Manage DMA'able memory. 1391 *******************************************************************/ 1392static void 1393ixgb_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error) 1394{ 1395 if (error) 1396 return; 1397 *(bus_addr_t *) arg = segs->ds_addr; 1398 return; 1399} 1400 1401static int 1402ixgb_dma_malloc(struct adapter * adapter, bus_size_t size, 1403 struct ixgb_dma_alloc * dma, int mapflags) 1404{ 1405 int r; 1406 1407 r = bus_dma_tag_create(NULL, /* parent */ 1408 PAGE_SIZE, 0, /* alignment, bounds */ 1409 BUS_SPACE_MAXADDR, /* lowaddr */ 1410 BUS_SPACE_MAXADDR, /* highaddr */ 1411 NULL, NULL, /* filter, filterarg */ 1412 size, /* maxsize */ 1413 1, /* nsegments */ 1414 size, /* maxsegsize */ 1415 BUS_DMA_ALLOCNOW, /* flags */ 1416#if __FreeBSD_version >= 502000 1417 NULL, /* lockfunc */ 1418 NULL, /* lockfuncarg */ 1419#endif 1420 &dma->dma_tag); 1421 if (r != 0) { 1422 printf("ixgb%d: ixgb_dma_malloc: bus_dma_tag_create failed; " 1423 "error %u\n", adapter->unit, r); 1424 goto fail_0; 1425 } 1426 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr, 1427 BUS_DMA_NOWAIT, &dma->dma_map); 1428 if (r != 0) { 1429 printf("ixgb%d: ixgb_dma_malloc: bus_dmamem_alloc failed; " 1430 "error %u\n", adapter->unit, r); 1431 goto fail_1; 1432 } 1433 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, 1434 size, 1435 ixgb_dmamap_cb, 1436 &dma->dma_paddr, 1437 mapflags | BUS_DMA_NOWAIT); 1438 if (r != 0) { 1439 printf("ixgb%d: ixgb_dma_malloc: bus_dmamap_load failed; " 1440 "error %u\n", adapter->unit, r); 1441 goto fail_2; 1442 } 1443 dma->dma_size = size; 1444 return (0); 1445fail_2: 1446 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map); 1447fail_1: 1448 bus_dma_tag_destroy(dma->dma_tag); 1449fail_0: 1450 dma->dma_map = NULL; 1451 dma->dma_tag = NULL; 1452 return (r); 1453} 1454 1455 1456 1457static void 1458ixgb_dma_free(struct adapter * adapter, struct ixgb_dma_alloc * dma) 1459{ 1460 bus_dmamap_unload(dma->dma_tag, dma->dma_map); 1461 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map); 1462 bus_dma_tag_destroy(dma->dma_tag); 1463} 1464 1465/********************************************************************* 1466 * 1467 * Allocate memory for tx_buffer structures. The tx_buffer stores all 1468 * the information needed to transmit a packet on the wire. 1469 * 1470 **********************************************************************/ 1471static int 1472ixgb_allocate_transmit_structures(struct adapter * adapter) 1473{ 1474 if (!(adapter->tx_buffer_area = 1475 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) * 1476 adapter->num_tx_desc, M_DEVBUF, 1477 M_NOWAIT | M_ZERO))) { 1478 printf("ixgb%d: Unable to allocate tx_buffer memory\n", 1479 adapter->unit); 1480 return ENOMEM; 1481 } 1482 bzero(adapter->tx_buffer_area, 1483 sizeof(struct ixgb_buffer) * adapter->num_tx_desc); 1484 1485 return 0; 1486} 1487 1488/********************************************************************* 1489 * 1490 * Allocate and initialize transmit structures. 1491 * 1492 **********************************************************************/ 1493static int 1494ixgb_setup_transmit_structures(struct adapter * adapter) 1495{ 1496 /* 1497 * Setup DMA descriptor areas. 1498 */ 1499 if (bus_dma_tag_create(NULL, /* parent */ 1500 PAGE_SIZE, 0, /* alignment, bounds */ 1501 BUS_SPACE_MAXADDR, /* lowaddr */ 1502 BUS_SPACE_MAXADDR, /* highaddr */ 1503 NULL, NULL, /* filter, filterarg */ 1504 MCLBYTES * IXGB_MAX_SCATTER, /* maxsize */ 1505 IXGB_MAX_SCATTER, /* nsegments */ 1506 MCLBYTES, /* maxsegsize */ 1507 BUS_DMA_ALLOCNOW, /* flags */ 1508#if __FreeBSD_version >= 502000 1509 NULL, /* lockfunc */ 1510 NULL, /* lockfuncarg */ 1511#endif 1512 &adapter->txtag)) { 1513 printf("ixgb%d: Unable to allocate TX DMA tag\n", adapter->unit); 1514 return (ENOMEM); 1515 } 1516 if (ixgb_allocate_transmit_structures(adapter)) 1517 return ENOMEM; 1518 1519 bzero((void *)adapter->tx_desc_base, 1520 (sizeof(struct ixgb_tx_desc)) * adapter->num_tx_desc); 1521 1522 adapter->next_avail_tx_desc = 0; 1523 adapter->oldest_used_tx_desc = 0; 1524 1525 /* Set number of descriptors available */ 1526 adapter->num_tx_desc_avail = adapter->num_tx_desc; 1527 1528 /* Set checksum context */ 1529 adapter->active_checksum_context = OFFLOAD_NONE; 1530 1531 return 0; 1532} 1533 1534/********************************************************************* 1535 * 1536 * Enable transmit unit. 1537 * 1538 **********************************************************************/ 1539static void 1540ixgb_initialize_transmit_unit(struct adapter * adapter) 1541{ 1542 u_int32_t reg_tctl; 1543 u_int64_t tdba = adapter->txdma.dma_paddr; 1544 1545 /* Setup the Base and Length of the Tx Descriptor Ring */ 1546 IXGB_WRITE_REG(&adapter->hw, TDBAL, 1547 (tdba & 0x00000000ffffffffULL)); 1548 IXGB_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32)); 1549 IXGB_WRITE_REG(&adapter->hw, TDLEN, 1550 adapter->num_tx_desc * 1551 sizeof(struct ixgb_tx_desc)); 1552 1553 /* Setup the HW Tx Head and Tail descriptor pointers */ 1554 IXGB_WRITE_REG(&adapter->hw, TDH, 0); 1555 IXGB_WRITE_REG(&adapter->hw, TDT, 0); 1556 1557 1558 HW_DEBUGOUT2("Base = %x, Length = %x\n", 1559 IXGB_READ_REG(&adapter->hw, TDBAL), 1560 IXGB_READ_REG(&adapter->hw, TDLEN)); 1561 1562 IXGB_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay); 1563 1564 1565 /* Program the Transmit Control Register */ 1566 reg_tctl = IXGB_READ_REG(&adapter->hw, TCTL); 1567 reg_tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE; 1568 IXGB_WRITE_REG(&adapter->hw, TCTL, reg_tctl); 1569 1570 /* Setup Transmit Descriptor Settings for this adapter */ 1571 adapter->txd_cmd = IXGB_TX_DESC_TYPE | IXGB_TX_DESC_CMD_RS; 1572 1573 if (adapter->tx_int_delay > 0) 1574 adapter->txd_cmd |= IXGB_TX_DESC_CMD_IDE; 1575 return; 1576} 1577 1578/********************************************************************* 1579 * 1580 * Free all transmit related data structures. 1581 * 1582 **********************************************************************/ 1583static void 1584ixgb_free_transmit_structures(struct adapter * adapter) 1585{ 1586 struct ixgb_buffer *tx_buffer; 1587 int i; 1588 1589 INIT_DEBUGOUT("free_transmit_structures: begin"); 1590 1591 if (adapter->tx_buffer_area != NULL) { 1592 tx_buffer = adapter->tx_buffer_area; 1593 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) { 1594 if (tx_buffer->m_head != NULL) { 1595 bus_dmamap_unload(adapter->txtag, tx_buffer->map); 1596 bus_dmamap_destroy(adapter->txtag, tx_buffer->map); 1597 m_freem(tx_buffer->m_head); 1598 } 1599 tx_buffer->m_head = NULL; 1600 } 1601 } 1602 if (adapter->tx_buffer_area != NULL) { 1603 free(adapter->tx_buffer_area, M_DEVBUF); 1604 adapter->tx_buffer_area = NULL; 1605 } 1606 if (adapter->txtag != NULL) { 1607 bus_dma_tag_destroy(adapter->txtag); 1608 adapter->txtag = NULL; 1609 } 1610 return; 1611} 1612 1613/********************************************************************* 1614 * 1615 * The offload context needs to be set when we transfer the first 1616 * packet of a particular protocol (TCP/UDP). We change the 1617 * context only if the protocol type changes. 1618 * 1619 **********************************************************************/ 1620static void 1621ixgb_transmit_checksum_setup(struct adapter * adapter, 1622 struct mbuf * mp, 1623 u_int8_t * txd_popts) 1624{ 1625 struct ixgb_context_desc *TXD; 1626 struct ixgb_buffer *tx_buffer; 1627 int curr_txd; 1628 1629 if (mp->m_pkthdr.csum_flags) { 1630 1631 if (mp->m_pkthdr.csum_flags & CSUM_TCP) { 1632 *txd_popts = IXGB_TX_DESC_POPTS_TXSM; 1633 if (adapter->active_checksum_context == OFFLOAD_TCP_IP) 1634 return; 1635 else 1636 adapter->active_checksum_context = OFFLOAD_TCP_IP; 1637 } else if (mp->m_pkthdr.csum_flags & CSUM_UDP) { 1638 *txd_popts = IXGB_TX_DESC_POPTS_TXSM; 1639 if (adapter->active_checksum_context == OFFLOAD_UDP_IP) 1640 return; 1641 else 1642 adapter->active_checksum_context = OFFLOAD_UDP_IP; 1643 } else { 1644 *txd_popts = 0; 1645 return; 1646 } 1647 } else { 1648 *txd_popts = 0; 1649 return; 1650 } 1651 1652 /* 1653 * If we reach this point, the checksum offload context needs to be 1654 * reset. 1655 */ 1656 curr_txd = adapter->next_avail_tx_desc; 1657 tx_buffer = &adapter->tx_buffer_area[curr_txd]; 1658 TXD = (struct ixgb_context_desc *) & adapter->tx_desc_base[curr_txd]; 1659 1660 1661 TXD->tucss = ENET_HEADER_SIZE + sizeof(struct ip); 1662 TXD->tucse = 0; 1663 1664 TXD->mss = 0; 1665 1666 if (adapter->active_checksum_context == OFFLOAD_TCP_IP) { 1667 TXD->tucso = 1668 ENET_HEADER_SIZE + sizeof(struct ip) + 1669 offsetof(struct tcphdr, th_sum); 1670 } else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) { 1671 TXD->tucso = 1672 ENET_HEADER_SIZE + sizeof(struct ip) + 1673 offsetof(struct udphdr, uh_sum); 1674 } 1675 TXD->cmd_type_len = IXGB_CONTEXT_DESC_CMD_TCP | IXGB_TX_DESC_CMD_RS | IXGB_CONTEXT_DESC_CMD_IDE; 1676 1677 tx_buffer->m_head = NULL; 1678 1679 if (++curr_txd == adapter->num_tx_desc) 1680 curr_txd = 0; 1681 1682 adapter->num_tx_desc_avail--; 1683 adapter->next_avail_tx_desc = curr_txd; 1684 return; 1685} 1686 1687/********************************************************************** 1688 * 1689 * Examine each tx_buffer in the used queue. If the hardware is done 1690 * processing the packet then free associated resources. The 1691 * tx_buffer is put back on the free queue. 1692 * 1693 **********************************************************************/ 1694static void 1695ixgb_clean_transmit_interrupts(struct adapter * adapter) 1696{ 1697 int i, num_avail; 1698 struct ixgb_buffer *tx_buffer; 1699 struct ixgb_tx_desc *tx_desc; 1700 1701 IXGB_LOCK_ASSERT(adapter); 1702 1703 if (adapter->num_tx_desc_avail == adapter->num_tx_desc) 1704 return; 1705 1706#ifdef _SV_ 1707 adapter->clean_tx_interrupts++; 1708#endif 1709 num_avail = adapter->num_tx_desc_avail; 1710 i = adapter->oldest_used_tx_desc; 1711 1712 tx_buffer = &adapter->tx_buffer_area[i]; 1713 tx_desc = &adapter->tx_desc_base[i]; 1714 1715 while (tx_desc->status & IXGB_TX_DESC_STATUS_DD) { 1716 1717 tx_desc->status = 0; 1718 num_avail++; 1719 1720 if (tx_buffer->m_head) { 1721 bus_dmamap_sync(adapter->txtag, tx_buffer->map, 1722 BUS_DMASYNC_POSTWRITE); 1723 bus_dmamap_unload(adapter->txtag, tx_buffer->map); 1724 bus_dmamap_destroy(adapter->txtag, tx_buffer->map); 1725 m_freem(tx_buffer->m_head); 1726 tx_buffer->m_head = NULL; 1727 } 1728 if (++i == adapter->num_tx_desc) 1729 i = 0; 1730 1731 tx_buffer = &adapter->tx_buffer_area[i]; 1732 tx_desc = &adapter->tx_desc_base[i]; 1733 } 1734 1735 adapter->oldest_used_tx_desc = i; 1736 1737 /* 1738 * If we have enough room, clear IFF_DRV_OACTIVE to tell the stack that 1739 * it is OK to send packets. If there are no pending descriptors, 1740 * clear the timeout. Otherwise, if some descriptors have been freed, 1741 * restart the timeout. 1742 */ 1743 if (num_avail > IXGB_TX_CLEANUP_THRESHOLD) { 1744 struct ifnet *ifp = adapter->ifp; 1745 1746 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 1747 if (num_avail == adapter->num_tx_desc) 1748 ifp->if_timer = 0; 1749 else if (num_avail == adapter->num_tx_desc_avail) 1750 ifp->if_timer = IXGB_TX_TIMEOUT; 1751 } 1752 adapter->num_tx_desc_avail = num_avail; 1753 return; 1754} 1755 1756 1757/********************************************************************* 1758 * 1759 * Get a buffer from system mbuf buffer pool. 1760 * 1761 **********************************************************************/ 1762static int 1763ixgb_get_buf(int i, struct adapter * adapter, 1764 struct mbuf * nmp) 1765{ 1766 register struct mbuf *mp = nmp; 1767 struct ixgb_buffer *rx_buffer; 1768 struct ifnet *ifp; 1769 bus_addr_t paddr; 1770 int error; 1771 1772 ifp = adapter->ifp; 1773 1774 if (mp == NULL) { 1775 1776 mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); 1777 1778 if (mp == NULL) { 1779 adapter->mbuf_alloc_failed++; 1780 return (ENOBUFS); 1781 } 1782 mp->m_len = mp->m_pkthdr.len = MCLBYTES; 1783 } else { 1784 mp->m_len = mp->m_pkthdr.len = MCLBYTES; 1785 mp->m_data = mp->m_ext.ext_buf; 1786 mp->m_next = NULL; 1787 } 1788 1789 if (ifp->if_mtu <= ETHERMTU) { 1790 m_adj(mp, ETHER_ALIGN); 1791 } 1792 rx_buffer = &adapter->rx_buffer_area[i]; 1793 1794 /* 1795 * Using memory from the mbuf cluster pool, invoke the bus_dma 1796 * machinery to arrange the memory mapping. 1797 */ 1798 error = bus_dmamap_load(adapter->rxtag, rx_buffer->map, 1799 mtod(mp, void *), mp->m_len, 1800 ixgb_dmamap_cb, &paddr, 0); 1801 if (error) { 1802 m_free(mp); 1803 return (error); 1804 } 1805 rx_buffer->m_head = mp; 1806 adapter->rx_desc_base[i].buff_addr = htole64(paddr); 1807 bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD); 1808 1809 return (0); 1810} 1811 1812/********************************************************************* 1813 * 1814 * Allocate memory for rx_buffer structures. Since we use one 1815 * rx_buffer per received packet, the maximum number of rx_buffer's 1816 * that we'll need is equal to the number of receive descriptors 1817 * that we've allocated. 1818 * 1819 **********************************************************************/ 1820static int 1821ixgb_allocate_receive_structures(struct adapter * adapter) 1822{ 1823 int i, error; 1824 struct ixgb_buffer *rx_buffer; 1825 1826 if (!(adapter->rx_buffer_area = 1827 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) * 1828 adapter->num_rx_desc, M_DEVBUF, 1829 M_NOWAIT | M_ZERO))) { 1830 printf("ixgb%d: Unable to allocate rx_buffer memory\n", 1831 adapter->unit); 1832 return (ENOMEM); 1833 } 1834 bzero(adapter->rx_buffer_area, 1835 sizeof(struct ixgb_buffer) * adapter->num_rx_desc); 1836 1837 error = bus_dma_tag_create(NULL, /* parent */ 1838 PAGE_SIZE, 0, /* alignment, bounds */ 1839 BUS_SPACE_MAXADDR, /* lowaddr */ 1840 BUS_SPACE_MAXADDR, /* highaddr */ 1841 NULL, NULL, /* filter, filterarg */ 1842 MCLBYTES, /* maxsize */ 1843 1, /* nsegments */ 1844 MCLBYTES, /* maxsegsize */ 1845 BUS_DMA_ALLOCNOW, /* flags */ 1846#if __FreeBSD_version >= 502000 1847 NULL, /* lockfunc */ 1848 NULL, /* lockfuncarg */ 1849#endif 1850 &adapter->rxtag); 1851 if (error != 0) { 1852 printf("ixgb%d: ixgb_allocate_receive_structures: " 1853 "bus_dma_tag_create failed; error %u\n", 1854 adapter->unit, error); 1855 goto fail_0; 1856 } 1857 rx_buffer = adapter->rx_buffer_area; 1858 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) { 1859 error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT, 1860 &rx_buffer->map); 1861 if (error != 0) { 1862 printf("ixgb%d: ixgb_allocate_receive_structures: " 1863 "bus_dmamap_create failed; error %u\n", 1864 adapter->unit, error); 1865 goto fail_1; 1866 } 1867 } 1868 1869 for (i = 0; i < adapter->num_rx_desc; i++) { 1870 if (ixgb_get_buf(i, adapter, NULL) == ENOBUFS) { 1871 adapter->rx_buffer_area[i].m_head = NULL; 1872 adapter->rx_desc_base[i].buff_addr = 0; 1873 return (ENOBUFS); 1874 } 1875 } 1876 1877 return (0); 1878fail_1: 1879 bus_dma_tag_destroy(adapter->rxtag); 1880fail_0: 1881 adapter->rxtag = NULL; 1882 free(adapter->rx_buffer_area, M_DEVBUF); 1883 adapter->rx_buffer_area = NULL; 1884 return (error); 1885} 1886 1887/********************************************************************* 1888 * 1889 * Allocate and initialize receive structures. 1890 * 1891 **********************************************************************/ 1892static int 1893ixgb_setup_receive_structures(struct adapter * adapter) 1894{ 1895 bzero((void *)adapter->rx_desc_base, 1896 (sizeof(struct ixgb_rx_desc)) * adapter->num_rx_desc); 1897 1898 if (ixgb_allocate_receive_structures(adapter)) 1899 return ENOMEM; 1900 1901 /* Setup our descriptor pointers */ 1902 adapter->next_rx_desc_to_check = 0; 1903 adapter->next_rx_desc_to_use = 0; 1904 return (0); 1905} 1906 1907/********************************************************************* 1908 * 1909 * Enable receive unit. 1910 * 1911 **********************************************************************/ 1912static void 1913ixgb_initialize_receive_unit(struct adapter * adapter) 1914{ 1915 u_int32_t reg_rctl; 1916 u_int32_t reg_rxcsum; 1917 u_int32_t reg_rxdctl; 1918 struct ifnet *ifp; 1919 u_int64_t rdba = adapter->rxdma.dma_paddr; 1920 1921 ifp = adapter->ifp; 1922 1923 /* 1924 * Make sure receives are disabled while setting up the descriptor 1925 * ring 1926 */ 1927 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL); 1928 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl & ~IXGB_RCTL_RXEN); 1929 1930 /* Set the Receive Delay Timer Register */ 1931 IXGB_WRITE_REG(&adapter->hw, RDTR, 1932 adapter->rx_int_delay); 1933 1934 1935 /* Setup the Base and Length of the Rx Descriptor Ring */ 1936 IXGB_WRITE_REG(&adapter->hw, RDBAL, 1937 (rdba & 0x00000000ffffffffULL)); 1938 IXGB_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32)); 1939 IXGB_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc * 1940 sizeof(struct ixgb_rx_desc)); 1941 1942 /* Setup the HW Rx Head and Tail Descriptor Pointers */ 1943 IXGB_WRITE_REG(&adapter->hw, RDH, 0); 1944 1945 IXGB_WRITE_REG(&adapter->hw, RDT, adapter->num_rx_desc - 1); 1946 1947 1948 1949 reg_rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT 1950 | RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT 1951 | RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT; 1952 IXGB_WRITE_REG(&adapter->hw, RXDCTL, reg_rxdctl); 1953 1954 1955 adapter->raidc = 1; 1956 if (adapter->raidc) { 1957 uint32_t raidc; 1958 uint8_t poll_threshold; 1959#define IXGB_RAIDC_POLL_DEFAULT 120 1960 1961 poll_threshold = ((adapter->num_rx_desc - 1) >> 3); 1962 poll_threshold >>= 1; 1963 poll_threshold &= 0x3F; 1964 raidc = IXGB_RAIDC_EN | IXGB_RAIDC_RXT_GATE | 1965 (IXGB_RAIDC_POLL_DEFAULT << IXGB_RAIDC_POLL_SHIFT) | 1966 (adapter->rx_int_delay << IXGB_RAIDC_DELAY_SHIFT) | 1967 poll_threshold; 1968 IXGB_WRITE_REG(&adapter->hw, RAIDC, raidc); 1969 } 1970 /* Enable Receive Checksum Offload for TCP and UDP ? */ 1971 if (ifp->if_capenable & IFCAP_RXCSUM) { 1972 reg_rxcsum = IXGB_READ_REG(&adapter->hw, RXCSUM); 1973 reg_rxcsum |= IXGB_RXCSUM_TUOFL; 1974 IXGB_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum); 1975 } 1976 /* Setup the Receive Control Register */ 1977 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL); 1978 reg_rctl &= ~(3 << IXGB_RCTL_MO_SHIFT); 1979 reg_rctl |= IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | IXGB_RCTL_SECRC | 1980 IXGB_RCTL_CFF | 1981 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT); 1982 1983 switch (adapter->rx_buffer_len) { 1984 default: 1985 case IXGB_RXBUFFER_2048: 1986 reg_rctl |= IXGB_RCTL_BSIZE_2048; 1987 break; 1988 case IXGB_RXBUFFER_4096: 1989 reg_rctl |= IXGB_RCTL_BSIZE_4096; 1990 break; 1991 case IXGB_RXBUFFER_8192: 1992 reg_rctl |= IXGB_RCTL_BSIZE_8192; 1993 break; 1994 case IXGB_RXBUFFER_16384: 1995 reg_rctl |= IXGB_RCTL_BSIZE_16384; 1996 break; 1997 } 1998 1999 reg_rctl |= IXGB_RCTL_RXEN; 2000 2001 2002 /* Enable Receives */ 2003 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl); 2004 2005 return; 2006} 2007 2008/********************************************************************* 2009 * 2010 * Free receive related data structures. 2011 * 2012 **********************************************************************/ 2013static void 2014ixgb_free_receive_structures(struct adapter * adapter) 2015{ 2016 struct ixgb_buffer *rx_buffer; 2017 int i; 2018 2019 INIT_DEBUGOUT("free_receive_structures: begin"); 2020 2021 if (adapter->rx_buffer_area != NULL) { 2022 rx_buffer = adapter->rx_buffer_area; 2023 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) { 2024 if (rx_buffer->map != NULL) { 2025 bus_dmamap_unload(adapter->rxtag, rx_buffer->map); 2026 bus_dmamap_destroy(adapter->rxtag, rx_buffer->map); 2027 } 2028 if (rx_buffer->m_head != NULL) 2029 m_freem(rx_buffer->m_head); 2030 rx_buffer->m_head = NULL; 2031 } 2032 } 2033 if (adapter->rx_buffer_area != NULL) { 2034 free(adapter->rx_buffer_area, M_DEVBUF); 2035 adapter->rx_buffer_area = NULL; 2036 } 2037 if (adapter->rxtag != NULL) { 2038 bus_dma_tag_destroy(adapter->rxtag); 2039 adapter->rxtag = NULL; 2040 } 2041 return; 2042} 2043 2044/********************************************************************* 2045 * 2046 * This routine executes in interrupt context. It replenishes 2047 * the mbufs in the descriptor and sends data which has been 2048 * dma'ed into host memory to upper layer. 2049 * 2050 * We loop at most count times if count is > 0, or until done if 2051 * count < 0. 2052 * 2053 *********************************************************************/ 2054static void 2055ixgb_process_receive_interrupts(struct adapter * adapter, int count) 2056{ 2057 struct ifnet *ifp; 2058 struct mbuf *mp; 2059#if __FreeBSD_version < 500000 2060 struct ether_header *eh; 2061#endif 2062 int eop = 0; 2063 int len; 2064 u_int8_t accept_frame = 0; 2065 int i; 2066 int next_to_use = 0; 2067 int eop_desc; 2068 /* Pointer to the receive descriptor being examined. */ 2069 struct ixgb_rx_desc *current_desc; 2070 2071 IXGB_LOCK_ASSERT(adapter); 2072 2073 ifp = adapter->ifp; 2074 i = adapter->next_rx_desc_to_check; 2075 next_to_use = adapter->next_rx_desc_to_use; 2076 eop_desc = adapter->next_rx_desc_to_check; 2077 current_desc = &adapter->rx_desc_base[i]; 2078 2079 if (!((current_desc->status) & IXGB_RX_DESC_STATUS_DD)) { 2080#ifdef _SV_ 2081 adapter->no_pkts_avail++; 2082#endif 2083 return; 2084 } 2085 while ((current_desc->status & IXGB_RX_DESC_STATUS_DD) && (count != 0)) { 2086 2087 mp = adapter->rx_buffer_area[i].m_head; 2088 bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map, 2089 BUS_DMASYNC_POSTREAD); 2090 accept_frame = 1; 2091 if (current_desc->status & IXGB_RX_DESC_STATUS_EOP) { 2092 count--; 2093 eop = 1; 2094 } else { 2095 eop = 0; 2096 } 2097 len = current_desc->length; 2098 2099 if (current_desc->errors & (IXGB_RX_DESC_ERRORS_CE | 2100 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P | 2101 IXGB_RX_DESC_ERRORS_RXE)) { 2102 accept_frame = 0; 2103 } 2104 if (accept_frame) { 2105 2106 /* Assign correct length to the current fragment */ 2107 mp->m_len = len; 2108 2109 if (adapter->fmp == NULL) { 2110 mp->m_pkthdr.len = len; 2111 adapter->fmp = mp; /* Store the first mbuf */ 2112 adapter->lmp = mp; 2113 } else { 2114 /* Chain mbuf's together */ 2115 mp->m_flags &= ~M_PKTHDR; 2116 adapter->lmp->m_next = mp; 2117 adapter->lmp = adapter->lmp->m_next; 2118 adapter->fmp->m_pkthdr.len += len; 2119 } 2120 2121 if (eop) { 2122 eop_desc = i; 2123 adapter->fmp->m_pkthdr.rcvif = ifp; 2124 2125#if __FreeBSD_version < 500000 2126 eh = mtod(adapter->fmp, struct ether_header *); 2127 2128 /* Remove ethernet header from mbuf */ 2129 m_adj(adapter->fmp, sizeof(struct ether_header)); 2130 ixgb_receive_checksum(adapter, current_desc, 2131 adapter->fmp); 2132 2133 if (current_desc->status & IXGB_RX_DESC_STATUS_VP) 2134 VLAN_INPUT_TAG(eh, adapter->fmp, 2135 current_desc->special); 2136 else 2137 ether_input(ifp, eh, adapter->fmp); 2138#else 2139 ixgb_receive_checksum(adapter, current_desc, 2140 adapter->fmp); 2141 if (current_desc->status & IXGB_RX_DESC_STATUS_VP) 2142 VLAN_INPUT_TAG(ifp, adapter->fmp, 2143 current_desc->special, 2144 adapter->fmp = NULL); 2145 2146 if (adapter->fmp != NULL) { 2147 IXGB_UNLOCK(adapter); 2148 (*ifp->if_input) (ifp, adapter->fmp); 2149 IXGB_LOCK(adapter); 2150 } 2151#endif 2152 adapter->fmp = NULL; 2153 adapter->lmp = NULL; 2154 } 2155 adapter->rx_buffer_area[i].m_head = NULL; 2156 } else { 2157 adapter->dropped_pkts++; 2158 if (adapter->fmp != NULL) 2159 m_freem(adapter->fmp); 2160 adapter->fmp = NULL; 2161 adapter->lmp = NULL; 2162 } 2163 2164 /* Zero out the receive descriptors status */ 2165 current_desc->status = 0; 2166 2167 /* Advance our pointers to the next descriptor */ 2168 if (++i == adapter->num_rx_desc) { 2169 i = 0; 2170 current_desc = adapter->rx_desc_base; 2171 } else 2172 current_desc++; 2173 } 2174 adapter->next_rx_desc_to_check = i; 2175 2176 if (--i < 0) 2177 i = (adapter->num_rx_desc - 1); 2178 2179 /* 2180 * 82597EX: Workaround for redundent write back in receive descriptor ring (causes 2181 * memory corruption). Avoid using and re-submitting the most recently received RX 2182 * descriptor back to hardware. 2183 * 2184 * if(Last written back descriptor == EOP bit set descriptor) 2185 * then avoid re-submitting the most recently received RX descriptor 2186 * back to hardware. 2187 * if(Last written back descriptor != EOP bit set descriptor) 2188 * then avoid re-submitting the most recently received RX descriptors 2189 * till last EOP bit set descriptor. 2190 */ 2191 if (eop_desc != i) { 2192 if (++eop_desc == adapter->num_rx_desc) 2193 eop_desc = 0; 2194 i = eop_desc; 2195 } 2196 /* Replenish the descriptors with new mbufs till last EOP bit set descriptor */ 2197 while (next_to_use != i) { 2198 current_desc = &adapter->rx_desc_base[next_to_use]; 2199 if ((current_desc->errors & (IXGB_RX_DESC_ERRORS_CE | 2200 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P | 2201 IXGB_RX_DESC_ERRORS_RXE))) { 2202 mp = adapter->rx_buffer_area[next_to_use].m_head; 2203 ixgb_get_buf(next_to_use, adapter, mp); 2204 } else { 2205 if (ixgb_get_buf(next_to_use, adapter, NULL) == ENOBUFS) 2206 break; 2207 } 2208 /* Advance our pointers to the next descriptor */ 2209 if (++next_to_use == adapter->num_rx_desc) { 2210 next_to_use = 0; 2211 current_desc = adapter->rx_desc_base; 2212 } else 2213 current_desc++; 2214 } 2215 adapter->next_rx_desc_to_use = next_to_use; 2216 if (--next_to_use < 0) 2217 next_to_use = (adapter->num_rx_desc - 1); 2218 /* Advance the IXGB's Receive Queue #0 "Tail Pointer" */ 2219 IXGB_WRITE_REG(&adapter->hw, RDT, next_to_use); 2220 2221 return; 2222} 2223 2224/********************************************************************* 2225 * 2226 * Verify that the hardware indicated that the checksum is valid. 2227 * Inform the stack about the status of checksum so that stack 2228 * doesn't spend time verifying the checksum. 2229 * 2230 *********************************************************************/ 2231static void 2232ixgb_receive_checksum(struct adapter * adapter, 2233 struct ixgb_rx_desc * rx_desc, 2234 struct mbuf * mp) 2235{ 2236 if (rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) { 2237 mp->m_pkthdr.csum_flags = 0; 2238 return; 2239 } 2240 if (rx_desc->status & IXGB_RX_DESC_STATUS_IPCS) { 2241 /* Did it pass? */ 2242 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_IPE)) { 2243 /* IP Checksum Good */ 2244 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED; 2245 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID; 2246 2247 } else { 2248 mp->m_pkthdr.csum_flags = 0; 2249 } 2250 } 2251 if (rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS) { 2252 /* Did it pass? */ 2253 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE)) { 2254 mp->m_pkthdr.csum_flags |= 2255 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR); 2256 mp->m_pkthdr.csum_data = htons(0xffff); 2257 } 2258 } 2259 return; 2260} 2261 2262 2263static void 2264ixgb_enable_vlans(struct adapter * adapter) 2265{ 2266 uint32_t ctrl; 2267 2268 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0); 2269 ctrl |= IXGB_CTRL0_VME; 2270 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl); 2271 2272 return; 2273} 2274 2275 2276static void 2277ixgb_enable_intr(struct adapter * adapter) 2278{ 2279 IXGB_WRITE_REG(&adapter->hw, IMS, (IXGB_INT_RXT0 | IXGB_INT_TXDW | 2280 IXGB_INT_RXDMT0 | IXGB_INT_LSC | IXGB_INT_RXO)); 2281 return; 2282} 2283 2284static void 2285ixgb_disable_intr(struct adapter * adapter) 2286{ 2287 IXGB_WRITE_REG(&adapter->hw, IMC, ~0); 2288 return; 2289} 2290 2291void 2292ixgb_write_pci_cfg(struct ixgb_hw * hw, 2293 uint32_t reg, 2294 uint16_t * value) 2295{ 2296 pci_write_config(((struct ixgb_osdep *) hw->back)->dev, reg, 2297 *value, 2); 2298} 2299 2300/********************************************************************** 2301 * 2302 * Update the board statistics counters. 2303 * 2304 **********************************************************************/ 2305static void 2306ixgb_update_stats_counters(struct adapter * adapter) 2307{ 2308 struct ifnet *ifp; 2309 2310 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS); 2311 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL); 2312 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH); 2313 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL); 2314 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH); 2315 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL); 2316 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH); 2317 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL); 2318 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH); 2319 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC); 2320 2321 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC); 2322 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC); 2323 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC); 2324 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC); 2325 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC); 2326 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC); 2327 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC); 2328 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL); 2329 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH); 2330 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL); 2331 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH); 2332 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC); 2333 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC); 2334 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC); 2335 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL); 2336 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH); 2337 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL); 2338 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH); 2339 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL); 2340 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH); 2341 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL); 2342 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH); 2343 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C); 2344 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL); 2345 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH); 2346 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL); 2347 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH); 2348 2349 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL); 2350 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH); 2351 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL); 2352 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH); 2353 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL); 2354 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH); 2355 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC); 2356 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC); 2357 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC); 2358 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL); 2359 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH); 2360 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL); 2361 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH); 2362 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL); 2363 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH); 2364 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC); 2365 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC); 2366 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC); 2367 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC); 2368 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC); 2369 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC); 2370 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC); 2371 2372 ifp = adapter->ifp; 2373 2374 /* Fill out the OS statistics structure */ 2375 ifp->if_ipackets = adapter->stats.gprcl; 2376 ifp->if_opackets = adapter->stats.gptcl; 2377 ifp->if_ibytes = adapter->stats.gorcl; 2378 ifp->if_obytes = adapter->stats.gotcl; 2379 ifp->if_imcasts = adapter->stats.mprcl; 2380 ifp->if_collisions = 0; 2381 2382 /* Rx Errors */ 2383 ifp->if_ierrors = 2384 adapter->dropped_pkts + 2385 adapter->stats.crcerrs + 2386 adapter->stats.rnbc + 2387 adapter->stats.mpc + 2388 adapter->stats.rlec; 2389 2390 2391} 2392 2393 2394/********************************************************************** 2395 * 2396 * This routine is called only when ixgb_display_debug_stats is enabled. 2397 * This routine provides a way to take a look at important statistics 2398 * maintained by the driver and hardware. 2399 * 2400 **********************************************************************/ 2401static void 2402ixgb_print_hw_stats(struct adapter * adapter) 2403{ 2404 char buf_speed[100], buf_type[100]; 2405 ixgb_bus_speed bus_speed; 2406 ixgb_bus_type bus_type; 2407 int unit = adapter->unit; 2408 2409#ifdef _SV_ 2410 printf("ixgb%d: Packets not Avail = %ld\n", unit, 2411 adapter->no_pkts_avail); 2412 printf("ixgb%d: CleanTxInterrupts = %ld\n", unit, 2413 adapter->clean_tx_interrupts); 2414 printf("ixgb%d: ICR RXDMT0 = %lld\n", unit, 2415 (long long)adapter->sv_stats.icr_rxdmt0); 2416 printf("ixgb%d: ICR RXO = %lld\n", unit, 2417 (long long)adapter->sv_stats.icr_rxo); 2418 printf("ixgb%d: ICR RXT0 = %lld\n", unit, 2419 (long long)adapter->sv_stats.icr_rxt0); 2420 printf("ixgb%d: ICR TXDW = %lld\n", unit, 2421 (long long)adapter->sv_stats.icr_TXDW); 2422#endif /* _SV_ */ 2423 2424 bus_speed = adapter->hw.bus.speed; 2425 bus_type = adapter->hw.bus.type; 2426 sprintf(buf_speed, 2427 bus_speed == ixgb_bus_speed_33 ? "33MHz" : 2428 bus_speed == ixgb_bus_speed_66 ? "66MHz" : 2429 bus_speed == ixgb_bus_speed_100 ? "100MHz" : 2430 bus_speed == ixgb_bus_speed_133 ? "133MHz" : 2431 "UNKNOWN"); 2432 printf("ixgb%d: PCI_Bus_Speed = %s\n", unit, 2433 buf_speed); 2434 2435 sprintf(buf_type, 2436 bus_type == ixgb_bus_type_pci ? "PCI" : 2437 bus_type == ixgb_bus_type_pcix ? "PCI-X" : 2438 "UNKNOWN"); 2439 printf("ixgb%d: PCI_Bus_Type = %s\n", unit, 2440 buf_type); 2441 2442 printf("ixgb%d: Tx Descriptors not Avail1 = %ld\n", unit, 2443 adapter->no_tx_desc_avail1); 2444 printf("ixgb%d: Tx Descriptors not Avail2 = %ld\n", unit, 2445 adapter->no_tx_desc_avail2); 2446 printf("ixgb%d: Std Mbuf Failed = %ld\n", unit, 2447 adapter->mbuf_alloc_failed); 2448 printf("ixgb%d: Std Cluster Failed = %ld\n", unit, 2449 adapter->mbuf_cluster_failed); 2450 2451 printf("ixgb%d: Defer count = %lld\n", unit, 2452 (long long)adapter->stats.dc); 2453 printf("ixgb%d: Missed Packets = %lld\n", unit, 2454 (long long)adapter->stats.mpc); 2455 printf("ixgb%d: Receive No Buffers = %lld\n", unit, 2456 (long long)adapter->stats.rnbc); 2457 printf("ixgb%d: Receive length errors = %lld\n", unit, 2458 (long long)adapter->stats.rlec); 2459 printf("ixgb%d: Crc errors = %lld\n", unit, 2460 (long long)adapter->stats.crcerrs); 2461 printf("ixgb%d: Driver dropped packets = %ld\n", unit, 2462 adapter->dropped_pkts); 2463 2464 printf("ixgb%d: XON Rcvd = %lld\n", unit, 2465 (long long)adapter->stats.xonrxc); 2466 printf("ixgb%d: XON Xmtd = %lld\n", unit, 2467 (long long)adapter->stats.xontxc); 2468 printf("ixgb%d: XOFF Rcvd = %lld\n", unit, 2469 (long long)adapter->stats.xoffrxc); 2470 printf("ixgb%d: XOFF Xmtd = %lld\n", unit, 2471 (long long)adapter->stats.xofftxc); 2472 2473 printf("ixgb%d: Good Packets Rcvd = %lld\n", unit, 2474 (long long)adapter->stats.gprcl); 2475 printf("ixgb%d: Good Packets Xmtd = %lld\n", unit, 2476 (long long)adapter->stats.gptcl); 2477 2478 printf("ixgb%d: Jumbo frames recvd = %lld\n", unit, 2479 (long long)adapter->stats.jprcl); 2480 printf("ixgb%d: Jumbo frames Xmtd = %lld\n", unit, 2481 (long long)adapter->stats.jptcl); 2482 2483 return; 2484 2485} 2486 2487static int 2488ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS) 2489{ 2490 int error; 2491 int result; 2492 struct adapter *adapter; 2493 2494 result = -1; 2495 error = sysctl_handle_int(oidp, &result, 0, req); 2496 2497 if (error || !req->newptr) 2498 return (error); 2499 2500 if (result == 1) { 2501 adapter = (struct adapter *) arg1; 2502 ixgb_print_hw_stats(adapter); 2503 } 2504 return error; 2505}
|