1 /*******************************************************************************
3 Copyright (c) 2001-2004, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
36 #ifdef HAVE_KERNEL_OPTION_HEADERS
37 #include "opt_device_polling.h"
40 #include <dev/ixgb/if_ixgb.h>
42 /*********************************************************************
43 * Set this to one to display debug statistics
44 *********************************************************************/
45 int ixgb_display_debug_stats = 0;
47 /*********************************************************************
48 * Linked list of board private structures for all NICs found
49 *********************************************************************/
51 struct adapter *ixgb_adapter_list = NULL;
55 /*********************************************************************
57 *********************************************************************/
59 char ixgb_driver_version[] = "1.0.6";
60 char ixgb_copyright[] = "Copyright (c) 2001-2004 Intel Corporation.";
62 /*********************************************************************
65 * Used by probe to select devices to load on
66 * Last field stores an index into ixgb_strings
67 * Last entry must be all 0s
69 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
70 *********************************************************************/
72 static ixgb_vendor_info_t ixgb_vendor_info_array[] =
74 /* Intel(R) PRO/10000 Network Connection */
75 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX, PCI_ANY_ID, PCI_ANY_ID, 0},
76 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR, PCI_ANY_ID, PCI_ANY_ID, 0},
77 /* required last entry */
81 /*********************************************************************
82 * Table of branding strings for all supported NICs.
83 *********************************************************************/
85 static char *ixgb_strings[] = {
86 "Intel(R) PRO/10GbE Network Driver"
89 /*********************************************************************
91 *********************************************************************/
92 static int ixgb_probe(device_t);
93 static int ixgb_attach(device_t);
94 static int ixgb_detach(device_t);
95 static int ixgb_shutdown(device_t);
96 static void ixgb_intr(void *);
97 static void ixgb_start(struct ifnet *);
98 static void ixgb_start_locked(struct ifnet *);
99 static int ixgb_ioctl(struct ifnet *, IOCTL_CMD_TYPE, caddr_t);
100 static void ixgb_watchdog(struct ifnet *);
101 static void ixgb_init(void *);
102 static void ixgb_init_locked(struct adapter *);
103 static void ixgb_stop(void *);
104 static void ixgb_media_status(struct ifnet *, struct ifmediareq *);
105 static int ixgb_media_change(struct ifnet *);
106 static void ixgb_identify_hardware(struct adapter *);
107 static int ixgb_allocate_pci_resources(struct adapter *);
108 static void ixgb_free_pci_resources(struct adapter *);
109 static void ixgb_local_timer(void *);
110 static int ixgb_hardware_init(struct adapter *);
111 static void ixgb_setup_interface(device_t, struct adapter *);
112 static int ixgb_setup_transmit_structures(struct adapter *);
113 static void ixgb_initialize_transmit_unit(struct adapter *);
114 static int ixgb_setup_receive_structures(struct adapter *);
115 static void ixgb_initialize_receive_unit(struct adapter *);
116 static void ixgb_enable_intr(struct adapter *);
117 static void ixgb_disable_intr(struct adapter *);
118 static void ixgb_free_transmit_structures(struct adapter *);
119 static void ixgb_free_receive_structures(struct adapter *);
120 static void ixgb_update_stats_counters(struct adapter *);
121 static void ixgb_clean_transmit_interrupts(struct adapter *);
122 static int ixgb_allocate_receive_structures(struct adapter *);
123 static int ixgb_allocate_transmit_structures(struct adapter *);
124 static void ixgb_process_receive_interrupts(struct adapter *, int);
126 ixgb_receive_checksum(struct adapter *,
127 struct ixgb_rx_desc * rx_desc,
130 ixgb_transmit_checksum_setup(struct adapter *,
133 static void ixgb_set_promisc(struct adapter *);
134 static void ixgb_disable_promisc(struct adapter *);
135 static void ixgb_set_multi(struct adapter *);
136 static void ixgb_print_hw_stats(struct adapter *);
137 static void ixgb_print_link_status(struct adapter *);
139 ixgb_get_buf(int i, struct adapter *,
141 static void ixgb_enable_vlans(struct adapter * adapter);
142 static int ixgb_encap(struct adapter * adapter, struct mbuf * m_head);
143 static int ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS);
145 ixgb_dma_malloc(struct adapter *, bus_size_t,
146 struct ixgb_dma_alloc *, int);
147 static void ixgb_dma_free(struct adapter *, struct ixgb_dma_alloc *);
148 #ifdef DEVICE_POLLING
149 static poll_handler_t ixgb_poll;
152 /*********************************************************************
153 * FreeBSD Device Interface Entry Points
154 *********************************************************************/
156 static device_method_t ixgb_methods[] = {
157 /* Device interface */
158 DEVMETHOD(device_probe, ixgb_probe),
159 DEVMETHOD(device_attach, ixgb_attach),
160 DEVMETHOD(device_detach, ixgb_detach),
161 DEVMETHOD(device_shutdown, ixgb_shutdown),
165 static driver_t ixgb_driver = {
166 "ixgb", ixgb_methods, sizeof(struct adapter),
169 static devclass_t ixgb_devclass;
170 DRIVER_MODULE(if_ixgb, pci, ixgb_driver, ixgb_devclass, 0, 0);
172 MODULE_DEPEND(if_ixgb, pci, 1, 1, 1);
173 MODULE_DEPEND(if_ixgb, ether, 1, 1, 1);
175 /* some defines for controlling descriptor fetches in h/w */
176 #define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
177 #define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is
178 * pushed this many descriptors from
180 #define RXDCTL_WTHRESH_DEFAULT 0 /* chip writes back at this many or RXT0 */
183 /*********************************************************************
184 * Device identification routine
186 * ixgb_probe determines if the driver should be loaded on
187 * adapter based on PCI vendor/device id of the adapter.
189 * return 0 on success, positive on failure
190 *********************************************************************/
193 ixgb_probe(device_t dev)
195 ixgb_vendor_info_t *ent;
197 u_int16_t pci_vendor_id = 0;
198 u_int16_t pci_device_id = 0;
199 u_int16_t pci_subvendor_id = 0;
200 u_int16_t pci_subdevice_id = 0;
201 char adapter_name[60];
203 INIT_DEBUGOUT("ixgb_probe: begin");
205 pci_vendor_id = pci_get_vendor(dev);
206 if (pci_vendor_id != IXGB_VENDOR_ID)
209 pci_device_id = pci_get_device(dev);
210 pci_subvendor_id = pci_get_subvendor(dev);
211 pci_subdevice_id = pci_get_subdevice(dev);
213 ent = ixgb_vendor_info_array;
214 while (ent->vendor_id != 0) {
215 if ((pci_vendor_id == ent->vendor_id) &&
216 (pci_device_id == ent->device_id) &&
218 ((pci_subvendor_id == ent->subvendor_id) ||
219 (ent->subvendor_id == PCI_ANY_ID)) &&
221 ((pci_subdevice_id == ent->subdevice_id) ||
222 (ent->subdevice_id == PCI_ANY_ID))) {
223 sprintf(adapter_name, "%s, Version - %s",
224 ixgb_strings[ent->index],
225 ixgb_driver_version);
226 device_set_desc_copy(dev, adapter_name);
227 return (BUS_PROBE_DEFAULT);
235 /*********************************************************************
236 * Device initialization routine
238 * The attach entry point is called when the driver is being loaded.
239 * This routine identifies the type of hardware, allocates all resources
240 * and initializes the hardware.
242 * return 0 on success, positive on failure
243 *********************************************************************/
246 ixgb_attach(device_t dev)
248 struct adapter *adapter;
252 printf("ixgb%d: %s\n", device_get_unit(dev), ixgb_copyright);
253 INIT_DEBUGOUT("ixgb_attach: begin");
255 /* Allocate, clear, and link in our adapter structure */
256 if (!(adapter = device_get_softc(dev))) {
257 printf("ixgb: adapter structure allocation failed\n");
260 bzero(adapter, sizeof(struct adapter));
262 adapter->osdep.dev = dev;
263 adapter->unit = device_get_unit(dev);
264 IXGB_LOCK_INIT(adapter, device_get_nameunit(dev));
266 if (ixgb_adapter_list != NULL)
267 ixgb_adapter_list->prev = adapter;
268 adapter->next = ixgb_adapter_list;
269 ixgb_adapter_list = adapter;
272 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
273 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
274 OID_AUTO, "stats", CTLTYPE_INT | CTLFLAG_RW,
276 ixgb_sysctl_stats, "I", "Statistics");
278 callout_init(&adapter->timer, CALLOUT_MPSAFE);
280 /* Determine hardware revision */
281 ixgb_identify_hardware(adapter);
283 /* Parameters (to be read from user) */
284 adapter->num_tx_desc = IXGB_MAX_TXD;
285 adapter->num_rx_desc = IXGB_MAX_RXD;
286 adapter->tx_int_delay = TIDV;
287 adapter->rx_int_delay = RDTR;
288 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
290 adapter->hw.fc.high_water = FCRTH;
291 adapter->hw.fc.low_water = FCRTL;
292 adapter->hw.fc.pause_time = FCPAUSE;
293 adapter->hw.fc.send_xon = TRUE;
294 adapter->hw.fc.type = FLOW_CONTROL;
297 /* Set the max frame size assuming standard ethernet sized frames */
298 adapter->hw.max_frame_size =
299 ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
301 if (ixgb_allocate_pci_resources(adapter)) {
302 printf("ixgb%d: Allocation of PCI resources failed\n",
307 tsize = IXGB_ROUNDUP(adapter->num_tx_desc *
308 sizeof(struct ixgb_tx_desc), 4096);
310 /* Allocate Transmit Descriptor ring */
311 if (ixgb_dma_malloc(adapter, tsize, &adapter->txdma, BUS_DMA_NOWAIT)) {
312 printf("ixgb%d: Unable to allocate TxDescriptor memory\n",
317 adapter->tx_desc_base = (struct ixgb_tx_desc *) adapter->txdma.dma_vaddr;
319 rsize = IXGB_ROUNDUP(adapter->num_rx_desc *
320 sizeof(struct ixgb_rx_desc), 4096);
322 /* Allocate Receive Descriptor ring */
323 if (ixgb_dma_malloc(adapter, rsize, &adapter->rxdma, BUS_DMA_NOWAIT)) {
324 printf("ixgb%d: Unable to allocate rx_desc memory\n",
329 adapter->rx_desc_base = (struct ixgb_rx_desc *) adapter->rxdma.dma_vaddr;
331 /* Initialize the hardware */
332 if (ixgb_hardware_init(adapter)) {
333 printf("ixgb%d: Unable to initialize the hardware\n",
338 /* Setup OS specific network interface */
339 ixgb_setup_interface(dev, adapter);
341 /* Initialize statistics */
342 ixgb_clear_hw_cntrs(&adapter->hw);
343 ixgb_update_stats_counters(adapter);
345 INIT_DEBUGOUT("ixgb_attach: end");
349 ixgb_dma_free(adapter, &adapter->rxdma);
351 ixgb_dma_free(adapter, &adapter->txdma);
354 ixgb_free_pci_resources(adapter);
355 sysctl_ctx_free(&adapter->sysctl_ctx);
360 /*********************************************************************
361 * Device removal routine
363 * The detach entry point is called when the driver is being removed.
364 * This routine stops the adapter and deallocates all the resources
365 * that were allocated for driver operation.
367 * return 0 on success, positive on failure
368 *********************************************************************/
371 ixgb_detach(device_t dev)
373 struct adapter *adapter = device_get_softc(dev);
374 struct ifnet *ifp = adapter->ifp;
376 INIT_DEBUGOUT("ixgb_detach: begin");
378 #ifdef DEVICE_POLLING
379 if (ifp->if_capenable & IFCAP_POLLING)
380 ether_poll_deregister(ifp);
384 adapter->in_detach = 1;
387 IXGB_UNLOCK(adapter);
389 #if __FreeBSD_version < 500000
390 ether_ifdetach(adapter->ifp, ETHER_BPF_SUPPORTED);
392 ether_ifdetach(adapter->ifp);
393 if_free(adapter->ifp);
395 ixgb_free_pci_resources(adapter);
398 /* Free Transmit Descriptor ring */
399 if (adapter->tx_desc_base) {
400 ixgb_dma_free(adapter, &adapter->txdma);
401 adapter->tx_desc_base = NULL;
403 /* Free Receive Descriptor ring */
404 if (adapter->rx_desc_base) {
405 ixgb_dma_free(adapter, &adapter->rxdma);
406 adapter->rx_desc_base = NULL;
408 /* Remove from the adapter list */
409 if (ixgb_adapter_list == adapter)
410 ixgb_adapter_list = adapter->next;
411 if (adapter->next != NULL)
412 adapter->next->prev = adapter->prev;
413 if (adapter->prev != NULL)
414 adapter->prev->next = adapter->next;
416 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
419 IXGB_LOCK_DESTROY(adapter);
423 /*********************************************************************
425 * Shutdown entry point
427 **********************************************************************/
430 ixgb_shutdown(device_t dev)
432 struct adapter *adapter = device_get_softc(dev);
435 IXGB_UNLOCK(adapter);
440 /*********************************************************************
441 * Transmit entry point
443 * ixgb_start is called by the stack to initiate a transmit.
444 * The driver will remain in this routine as long as there are
445 * packets to transmit and transmit resources are available.
446 * In case resources are not available stack is notified and
447 * the packet is requeued.
448 **********************************************************************/
451 ixgb_start_locked(struct ifnet * ifp)
454 struct adapter *adapter = ifp->if_softc;
456 IXGB_LOCK_ASSERT(adapter);
458 if (!adapter->link_active)
461 while (ifp->if_snd.ifq_head != NULL) {
462 IF_DEQUEUE(&ifp->if_snd, m_head);
467 if (ixgb_encap(adapter, m_head)) {
468 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
469 IF_PREPEND(&ifp->if_snd, m_head);
472 /* Send a copy of the frame to the BPF listener */
473 #if __FreeBSD_version < 500000
475 bpf_mtap(ifp, m_head);
477 ETHER_BPF_MTAP(ifp, m_head);
479 /* Set timeout in case hardware has problems transmitting */
480 ifp->if_timer = IXGB_TX_TIMEOUT;
487 ixgb_start(struct ifnet *ifp)
489 struct adapter *adapter = ifp->if_softc;
492 ixgb_start_locked(ifp);
493 IXGB_UNLOCK(adapter);
497 /*********************************************************************
500 * ixgb_ioctl is called when the user wants to configure the
503 * return 0 on success, positive on failure
504 **********************************************************************/
507 ixgb_ioctl(struct ifnet * ifp, IOCTL_CMD_TYPE command, caddr_t data)
510 struct ifreq *ifr = (struct ifreq *) data;
511 struct adapter *adapter = ifp->if_softc;
513 if (adapter->in_detach)
519 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
520 ether_ioctl(ifp, command, data);
523 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
524 if (ifr->ifr_mtu > IXGB_MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) {
528 ifp->if_mtu = ifr->ifr_mtu;
529 adapter->hw.max_frame_size =
530 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
532 ixgb_init_locked(adapter);
533 IXGB_UNLOCK(adapter);
537 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
539 if (ifp->if_flags & IFF_UP) {
540 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
541 ixgb_init_locked(adapter);
543 ixgb_disable_promisc(adapter);
544 ixgb_set_promisc(adapter);
546 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
550 IXGB_UNLOCK(adapter);
554 IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI");
555 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
557 ixgb_disable_intr(adapter);
558 ixgb_set_multi(adapter);
559 ixgb_enable_intr(adapter);
560 IXGB_UNLOCK(adapter);
565 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
566 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
569 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)");
570 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
571 #ifdef DEVICE_POLLING
572 if (mask & IFCAP_POLLING) {
573 if (ifr->ifr_reqcap & IFCAP_POLLING) {
574 error = ether_poll_register(ixgb_poll, ifp);
578 ixgb_disable_intr(adapter);
579 ifp->if_capenable |= IFCAP_POLLING;
580 IXGB_UNLOCK(adapter);
582 error = ether_poll_deregister(ifp);
583 /* Enable interrupt even in error case */
585 ixgb_enable_intr(adapter);
586 ifp->if_capenable &= ~IFCAP_POLLING;
587 IXGB_UNLOCK(adapter);
590 #endif /* DEVICE_POLLING */
591 if (mask & IFCAP_HWCSUM) {
592 if (IFCAP_HWCSUM & ifp->if_capenable)
593 ifp->if_capenable &= ~IFCAP_HWCSUM;
595 ifp->if_capenable |= IFCAP_HWCSUM;
596 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
601 IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%X)\n", (int)command);
609 /*********************************************************************
610 * Watchdog entry point
612 * This routine is called whenever hardware quits transmitting.
614 **********************************************************************/
617 ixgb_watchdog(struct ifnet * ifp)
619 struct adapter *adapter;
620 adapter = ifp->if_softc;
623 * If we are in this routine because of pause frames, then don't
624 * reset the hardware.
626 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_TXOFF) {
627 ifp->if_timer = IXGB_TX_TIMEOUT;
630 printf("ixgb%d: watchdog timeout -- resetting\n", adapter->unit);
632 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
644 /*********************************************************************
647 * This routine is used in two ways. It is used by the stack as
648 * init entry point in network interface structure. It is also used
649 * by the driver as a hw/sw initialization routine to get to a
652 * return 0 on success, positive on failure
653 **********************************************************************/
656 ixgb_init_locked(struct adapter *adapter)
660 INIT_DEBUGOUT("ixgb_init: begin");
662 IXGB_LOCK_ASSERT(adapter);
666 /* Get the latest mac address, User can use a LAA */
667 bcopy(IFP2ENADDR(adapter->ifp), adapter->hw.curr_mac_addr,
668 IXGB_ETH_LENGTH_OF_ADDRESS);
670 /* Initialize the hardware */
671 if (ixgb_hardware_init(adapter)) {
672 printf("ixgb%d: Unable to initialize the hardware\n",
676 ixgb_enable_vlans(adapter);
678 /* Prepare transmit descriptors and buffers */
679 if (ixgb_setup_transmit_structures(adapter)) {
680 printf("ixgb%d: Could not setup transmit structures\n",
685 ixgb_initialize_transmit_unit(adapter);
687 /* Setup Multicast table */
688 ixgb_set_multi(adapter);
690 /* Prepare receive descriptors and buffers */
691 if (ixgb_setup_receive_structures(adapter)) {
692 printf("ixgb%d: Could not setup receive structures\n",
697 ixgb_initialize_receive_unit(adapter);
699 /* Don't loose promiscuous settings */
700 ixgb_set_promisc(adapter);
703 ifp->if_drv_flags |= IFF_DRV_RUNNING;
704 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
707 if (ifp->if_capenable & IFCAP_TXCSUM)
708 ifp->if_hwassist = IXGB_CHECKSUM_FEATURES;
710 ifp->if_hwassist = 0;
713 /* Enable jumbo frames */
714 if (ifp->if_mtu > ETHERMTU) {
716 IXGB_WRITE_REG(&adapter->hw, MFS,
717 adapter->hw.max_frame_size << IXGB_MFS_SHIFT);
718 temp_reg = IXGB_READ_REG(&adapter->hw, CTRL0);
719 temp_reg |= IXGB_CTRL0_JFE;
720 IXGB_WRITE_REG(&adapter->hw, CTRL0, temp_reg);
722 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
723 ixgb_clear_hw_cntrs(&adapter->hw);
724 #ifdef DEVICE_POLLING
726 * Only disable interrupts if we are polling, make sure they are on
729 if (ifp->if_capenable & IFCAP_POLLING)
730 ixgb_disable_intr(adapter);
733 ixgb_enable_intr(adapter);
741 struct adapter *adapter = arg;
744 ixgb_init_locked(adapter);
745 IXGB_UNLOCK(adapter);
749 #ifdef DEVICE_POLLING
751 ixgb_poll_locked(struct ifnet * ifp, enum poll_cmd cmd, int count)
753 struct adapter *adapter = ifp->if_softc;
756 IXGB_LOCK_ASSERT(adapter);
758 if (cmd == POLL_AND_CHECK_STATUS) {
759 reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
760 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
761 callout_stop(&adapter->timer);
762 ixgb_check_for_link(&adapter->hw);
763 ixgb_print_link_status(adapter);
764 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
768 ixgb_process_receive_interrupts(adapter, count);
769 ixgb_clean_transmit_interrupts(adapter);
771 if (ifp->if_snd.ifq_head != NULL)
772 ixgb_start_locked(ifp);
776 ixgb_poll(struct ifnet * ifp, enum poll_cmd cmd, int count)
778 struct adapter *adapter = ifp->if_softc;
781 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
782 ixgb_poll_locked(ifp, cmd, count);
783 IXGB_UNLOCK(adapter);
785 #endif /* DEVICE_POLLING */
787 /*********************************************************************
789 * Interrupt Service routine
791 **********************************************************************/
796 u_int32_t loop_cnt = IXGB_MAX_INTR;
799 struct adapter *adapter = arg;
800 boolean_t rxdmt0 = FALSE;
806 #ifdef DEVICE_POLLING
807 if (ifp->if_capenable & IFCAP_POLLING) {
808 IXGB_UNLOCK(adapter);
813 reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
815 IXGB_UNLOCK(adapter);
819 if (reg_icr & IXGB_INT_RXDMT0)
823 if (reg_icr & IXGB_INT_RXDMT0)
824 adapter->sv_stats.icr_rxdmt0++;
825 if (reg_icr & IXGB_INT_RXO)
826 adapter->sv_stats.icr_rxo++;
827 if (reg_icr & IXGB_INT_RXT0)
828 adapter->sv_stats.icr_rxt0++;
829 if (reg_icr & IXGB_INT_TXDW)
830 adapter->sv_stats.icr_TXDW++;
833 /* Link status change */
834 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
835 callout_stop(&adapter->timer);
836 ixgb_check_for_link(&adapter->hw);
837 ixgb_print_link_status(adapter);
838 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
841 while (loop_cnt > 0) {
842 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
843 ixgb_process_receive_interrupts(adapter, -1);
844 ixgb_clean_transmit_interrupts(adapter);
849 if (rxdmt0 && adapter->raidc) {
850 IXGB_WRITE_REG(&adapter->hw, IMC, IXGB_INT_RXDMT0);
851 IXGB_WRITE_REG(&adapter->hw, IMS, IXGB_INT_RXDMT0);
853 if (ifp->if_drv_flags & IFF_DRV_RUNNING && ifp->if_snd.ifq_head != NULL)
854 ixgb_start_locked(ifp);
856 IXGB_UNLOCK(adapter);
861 /*********************************************************************
863 * Media Ioctl callback
865 * This routine is called whenever the user queries the status of
866 * the interface using ifconfig.
868 **********************************************************************/
870 ixgb_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
872 struct adapter *adapter = ifp->if_softc;
874 INIT_DEBUGOUT("ixgb_media_status: begin");
876 ixgb_check_for_link(&adapter->hw);
877 ixgb_print_link_status(adapter);
879 ifmr->ifm_status = IFM_AVALID;
880 ifmr->ifm_active = IFM_ETHER;
882 if (!adapter->hw.link_up)
885 ifmr->ifm_status |= IFM_ACTIVE;
886 ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
891 /*********************************************************************
893 * Media Ioctl callback
895 * This routine is called when the user changes speed/duplex using
896 * media/mediopt option with ifconfig.
898 **********************************************************************/
900 ixgb_media_change(struct ifnet * ifp)
902 struct adapter *adapter = ifp->if_softc;
903 struct ifmedia *ifm = &adapter->media;
905 INIT_DEBUGOUT("ixgb_media_change: begin");
907 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
913 /*********************************************************************
915 * This routine maps the mbufs to tx descriptors.
917 * return 0 on success, positive on failure
918 **********************************************************************/
921 ixgb_encap(struct adapter * adapter, struct mbuf * m_head)
924 int i, j, error, nsegs;
926 #if __FreeBSD_version < 500000
927 struct ifvlan *ifv = NULL;
931 bus_dma_segment_t segs[IXGB_MAX_SCATTER];
933 struct ixgb_buffer *tx_buffer = NULL;
934 struct ixgb_tx_desc *current_tx_desc = NULL;
935 struct ifnet *ifp = adapter->ifp;
938 * Force a cleanup if number of TX descriptors available hits the
941 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
942 ixgb_clean_transmit_interrupts(adapter);
944 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
945 adapter->no_tx_desc_avail1++;
949 * Map the packet for DMA.
951 if (bus_dmamap_create(adapter->txtag, BUS_DMA_NOWAIT, &map)) {
952 adapter->no_tx_map_avail++;
955 error = bus_dmamap_load_mbuf_sg(adapter->txtag, map, m_head, segs,
956 &nsegs, BUS_DMA_NOWAIT);
958 adapter->no_tx_dma_setup++;
959 printf("ixgb%d: ixgb_encap: bus_dmamap_load_mbuf failed; "
960 "error %u\n", adapter->unit, error);
961 bus_dmamap_destroy(adapter->txtag, map);
964 KASSERT(nsegs != 0, ("ixgb_encap: empty packet"));
966 if (nsegs > adapter->num_tx_desc_avail) {
967 adapter->no_tx_desc_avail2++;
968 bus_dmamap_destroy(adapter->txtag, map);
971 if (ifp->if_hwassist > 0) {
972 ixgb_transmit_checksum_setup(adapter, m_head,
977 /* Find out if we are in vlan mode */
978 #if __FreeBSD_version < 500000
979 if ((m_head->m_flags & (M_PROTO1 | M_PKTHDR)) == (M_PROTO1 | M_PKTHDR) &&
980 m_head->m_pkthdr.rcvif != NULL &&
981 m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
982 ifv = m_head->m_pkthdr.rcvif->if_softc;
984 mtag = VLAN_OUTPUT_TAG(ifp, m_head);
986 i = adapter->next_avail_tx_desc;
987 for (j = 0; j < nsegs; j++) {
988 tx_buffer = &adapter->tx_buffer_area[i];
989 current_tx_desc = &adapter->tx_desc_base[i];
991 current_tx_desc->buff_addr = htole64(segs[j].ds_addr);
992 current_tx_desc->cmd_type_len = (adapter->txd_cmd | segs[j].ds_len);
993 current_tx_desc->popts = txd_popts;
994 if (++i == adapter->num_tx_desc)
997 tx_buffer->m_head = NULL;
1000 adapter->num_tx_desc_avail -= nsegs;
1001 adapter->next_avail_tx_desc = i;
1003 #if __FreeBSD_version < 500000
1005 /* Set the vlan id */
1006 current_tx_desc->vlan = ifv->ifv_tag;
1009 /* Set the vlan id */
1010 current_tx_desc->vlan = VLAN_TAG_VALUE(mtag);
1013 /* Tell hardware to add tag */
1014 current_tx_desc->cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1016 tx_buffer->m_head = m_head;
1017 tx_buffer->map = map;
1018 bus_dmamap_sync(adapter->txtag, map, BUS_DMASYNC_PREWRITE);
1021 * Last Descriptor of Packet needs End Of Packet (EOP)
1023 current_tx_desc->cmd_type_len |= (IXGB_TX_DESC_CMD_EOP);
1026 * Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
1027 * that this frame is available to transmit.
1029 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1035 ixgb_set_promisc(struct adapter * adapter)
1039 struct ifnet *ifp = adapter->ifp;
1041 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1043 if (ifp->if_flags & IFF_PROMISC) {
1044 reg_rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1045 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1046 } else if (ifp->if_flags & IFF_ALLMULTI) {
1047 reg_rctl |= IXGB_RCTL_MPE;
1048 reg_rctl &= ~IXGB_RCTL_UPE;
1049 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1055 ixgb_disable_promisc(struct adapter * adapter)
1059 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1061 reg_rctl &= (~IXGB_RCTL_UPE);
1062 reg_rctl &= (~IXGB_RCTL_MPE);
1063 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1069 /*********************************************************************
1072 * This routine is called whenever multicast address list is updated.
1074 **********************************************************************/
1077 ixgb_set_multi(struct adapter * adapter)
1079 u_int32_t reg_rctl = 0;
1080 u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * IXGB_ETH_LENGTH_OF_ADDRESS];
1081 struct ifmultiaddr *ifma;
1083 struct ifnet *ifp = adapter->ifp;
1085 IOCTL_DEBUGOUT("ixgb_set_multi: begin");
1088 #if __FreeBSD_version < 500000
1089 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1091 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1093 if (ifma->ifma_addr->sa_family != AF_LINK)
1096 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1097 &mta[mcnt * IXGB_ETH_LENGTH_OF_ADDRESS], IXGB_ETH_LENGTH_OF_ADDRESS);
1100 IF_ADDR_UNLOCK(ifp);
1102 if (mcnt > MAX_NUM_MULTICAST_ADDRESSES) {
1103 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1104 reg_rctl |= IXGB_RCTL_MPE;
1105 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1107 ixgb_mc_addr_list_update(&adapter->hw, mta, mcnt, 0);
1113 /*********************************************************************
1116 * This routine checks for link status and updates statistics.
1118 **********************************************************************/
1121 ixgb_local_timer(void *arg)
1124 struct adapter *adapter = arg;
1129 ixgb_check_for_link(&adapter->hw);
1130 ixgb_print_link_status(adapter);
1131 ixgb_update_stats_counters(adapter);
1132 if (ixgb_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) {
1133 ixgb_print_hw_stats(adapter);
1135 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
1137 IXGB_UNLOCK(adapter);
1142 ixgb_print_link_status(struct adapter * adapter)
1144 if (adapter->hw.link_up) {
1145 if (!adapter->link_active) {
1146 printf("ixgb%d: Link is up %d Mbps %s \n",
1150 adapter->link_active = 1;
1153 if (adapter->link_active) {
1154 printf("ixgb%d: Link is Down \n", adapter->unit);
1155 adapter->link_active = 0;
1164 /*********************************************************************
1166 * This routine disables all traffic on the adapter by issuing a
1167 * global reset on the MAC and deallocates TX/RX buffers.
1169 **********************************************************************/
1172 ixgb_stop(void *arg)
1175 struct adapter *adapter = arg;
1178 IXGB_LOCK_ASSERT(adapter);
1180 INIT_DEBUGOUT("ixgb_stop: begin\n");
1181 ixgb_disable_intr(adapter);
1182 adapter->hw.adapter_stopped = FALSE;
1183 ixgb_adapter_stop(&adapter->hw);
1184 callout_stop(&adapter->timer);
1185 ixgb_free_transmit_structures(adapter);
1186 ixgb_free_receive_structures(adapter);
1189 /* Tell the stack that the interface is no longer active */
1190 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1196 /*********************************************************************
1198 * Determine hardware revision.
1200 **********************************************************************/
1202 ixgb_identify_hardware(struct adapter * adapter)
1204 device_t dev = adapter->dev;
1206 /* Make sure our PCI config space has the necessary stuff set */
1207 adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
1208 if (!((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) &&
1209 (adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN))) {
1210 printf("ixgb%d: Memory Access and/or Bus Master bits were not set!\n",
1212 adapter->hw.pci_cmd_word |=
1213 (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
1214 pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2);
1216 /* Save off the information about this board */
1217 adapter->hw.vendor_id = pci_get_vendor(dev);
1218 adapter->hw.device_id = pci_get_device(dev);
1219 adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
1220 adapter->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
1221 adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
1223 /* Set MacType, etc. based on this PCI info */
1224 switch (adapter->hw.device_id) {
1225 case IXGB_DEVICE_ID_82597EX:
1226 case IXGB_DEVICE_ID_82597EX_SR:
1227 adapter->hw.mac_type = ixgb_82597;
1230 INIT_DEBUGOUT1("Unknown device if 0x%x", adapter->hw.device_id);
1231 printf("ixgb%d: unsupported device id 0x%x\n", adapter->unit, adapter->hw.device_id);
1238 ixgb_allocate_pci_resources(struct adapter * adapter)
1241 device_t dev = adapter->dev;
1244 adapter->res_memory = bus_alloc_resource(dev, SYS_RES_MEMORY,
1247 if (!(adapter->res_memory)) {
1248 printf("ixgb%d: Unable to allocate bus resource: memory\n",
1252 adapter->osdep.mem_bus_space_tag =
1253 rman_get_bustag(adapter->res_memory);
1254 adapter->osdep.mem_bus_space_handle =
1255 rman_get_bushandle(adapter->res_memory);
1256 adapter->hw.hw_addr = (uint8_t *) & adapter->osdep.mem_bus_space_handle;
1259 adapter->res_interrupt = bus_alloc_resource(dev, SYS_RES_IRQ,
1261 RF_SHAREABLE | RF_ACTIVE);
1262 if (!(adapter->res_interrupt)) {
1263 printf("ixgb%d: Unable to allocate bus resource: interrupt\n",
1267 if (bus_setup_intr(dev, adapter->res_interrupt,
1268 INTR_TYPE_NET | INTR_MPSAFE,
1269 (void (*) (void *))ixgb_intr, adapter,
1270 &adapter->int_handler_tag)) {
1271 printf("ixgb%d: Error registering interrupt handler!\n",
1275 adapter->hw.back = &adapter->osdep;
1281 ixgb_free_pci_resources(struct adapter * adapter)
1283 device_t dev = adapter->dev;
1285 if (adapter->res_interrupt != NULL) {
1286 bus_teardown_intr(dev, adapter->res_interrupt,
1287 adapter->int_handler_tag);
1288 bus_release_resource(dev, SYS_RES_IRQ, 0,
1289 adapter->res_interrupt);
1291 if (adapter->res_memory != NULL) {
1292 bus_release_resource(dev, SYS_RES_MEMORY, IXGB_MMBA,
1293 adapter->res_memory);
1295 if (adapter->res_ioport != NULL) {
1296 bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid,
1297 adapter->res_ioport);
1302 /*********************************************************************
1304 * Initialize the hardware to a configuration as specified by the
1305 * adapter structure. The controller is reset, the EEPROM is
1306 * verified, the MAC address is set, then the shared initialization
1307 * routines are called.
1309 **********************************************************************/
1311 ixgb_hardware_init(struct adapter * adapter)
1313 /* Issue a global reset */
1314 adapter->hw.adapter_stopped = FALSE;
1315 ixgb_adapter_stop(&adapter->hw);
1317 /* Make sure we have a good EEPROM before we read from it */
1318 if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
1319 printf("ixgb%d: The EEPROM Checksum Is Not Valid\n",
1323 if (!ixgb_init_hw(&adapter->hw)) {
1324 printf("ixgb%d: Hardware Initialization Failed",
1332 /*********************************************************************
1334 * Setup networking device structure and register an interface.
1336 **********************************************************************/
1338 ixgb_setup_interface(device_t dev, struct adapter * adapter)
1341 INIT_DEBUGOUT("ixgb_setup_interface: begin");
1343 ifp = adapter->ifp = if_alloc(IFT_ETHER);
1345 panic("%s: can not if_alloc()\n", device_get_nameunit(dev));
1346 #if __FreeBSD_version >= 502000
1347 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1349 ifp->if_unit = adapter->unit;
1350 ifp->if_name = "ixgb";
1352 ifp->if_mtu = ETHERMTU;
1353 ifp->if_baudrate = 1000000000;
1354 ifp->if_init = ixgb_init;
1355 ifp->if_softc = adapter;
1356 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1357 ifp->if_ioctl = ixgb_ioctl;
1358 ifp->if_start = ixgb_start;
1359 ifp->if_watchdog = ixgb_watchdog;
1360 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 1;
1362 #if __FreeBSD_version < 500000
1363 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
1365 ether_ifattach(ifp, adapter->hw.curr_mac_addr);
1368 ifp->if_capabilities = IFCAP_HWCSUM;
1371 * Tell the upper layer(s) we support long frames.
1373 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1375 #if __FreeBSD_version >= 500000
1376 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
1379 ifp->if_capenable = ifp->if_capabilities;
1381 #ifdef DEVICE_POLLING
1382 ifp->if_capabilities |= IFCAP_POLLING;
1386 * Specify the media types supported by this adapter and register
1387 * callbacks to update media and link information
1389 ifmedia_init(&adapter->media, IFM_IMASK, ixgb_media_change,
1391 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
1393 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX,
1395 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1396 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
1401 /********************************************************************
1402 * Manage DMA'able memory.
1403 *******************************************************************/
1405 ixgb_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
1409 *(bus_addr_t *) arg = segs->ds_addr;
1414 ixgb_dma_malloc(struct adapter * adapter, bus_size_t size,
1415 struct ixgb_dma_alloc * dma, int mapflags)
1419 r = bus_dma_tag_create(NULL, /* parent */
1420 PAGE_SIZE, 0, /* alignment, bounds */
1421 BUS_SPACE_MAXADDR, /* lowaddr */
1422 BUS_SPACE_MAXADDR, /* highaddr */
1423 NULL, NULL, /* filter, filterarg */
1426 size, /* maxsegsize */
1427 BUS_DMA_ALLOCNOW, /* flags */
1428 #if __FreeBSD_version >= 502000
1429 NULL, /* lockfunc */
1430 NULL, /* lockfuncarg */
1434 printf("ixgb%d: ixgb_dma_malloc: bus_dma_tag_create failed; "
1435 "error %u\n", adapter->unit, r);
1438 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
1439 BUS_DMA_NOWAIT, &dma->dma_map);
1441 printf("ixgb%d: ixgb_dma_malloc: bus_dmamem_alloc failed; "
1442 "error %u\n", adapter->unit, r);
1445 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
1449 mapflags | BUS_DMA_NOWAIT);
1451 printf("ixgb%d: ixgb_dma_malloc: bus_dmamap_load failed; "
1452 "error %u\n", adapter->unit, r);
1455 dma->dma_size = size;
1458 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1460 bus_dma_tag_destroy(dma->dma_tag);
1462 dma->dma_map = NULL;
1463 dma->dma_tag = NULL;
1470 ixgb_dma_free(struct adapter * adapter, struct ixgb_dma_alloc * dma)
1472 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
1473 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1474 bus_dma_tag_destroy(dma->dma_tag);
1477 /*********************************************************************
1479 * Allocate memory for tx_buffer structures. The tx_buffer stores all
1480 * the information needed to transmit a packet on the wire.
1482 **********************************************************************/
1484 ixgb_allocate_transmit_structures(struct adapter * adapter)
1486 if (!(adapter->tx_buffer_area =
1487 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
1488 adapter->num_tx_desc, M_DEVBUF,
1489 M_NOWAIT | M_ZERO))) {
1490 printf("ixgb%d: Unable to allocate tx_buffer memory\n",
1494 bzero(adapter->tx_buffer_area,
1495 sizeof(struct ixgb_buffer) * adapter->num_tx_desc);
1500 /*********************************************************************
1502 * Allocate and initialize transmit structures.
1504 **********************************************************************/
1506 ixgb_setup_transmit_structures(struct adapter * adapter)
1509 * Setup DMA descriptor areas.
1511 if (bus_dma_tag_create(NULL, /* parent */
1512 PAGE_SIZE, 0, /* alignment, bounds */
1513 BUS_SPACE_MAXADDR, /* lowaddr */
1514 BUS_SPACE_MAXADDR, /* highaddr */
1515 NULL, NULL, /* filter, filterarg */
1516 MCLBYTES * IXGB_MAX_SCATTER, /* maxsize */
1517 IXGB_MAX_SCATTER, /* nsegments */
1518 MCLBYTES, /* maxsegsize */
1519 BUS_DMA_ALLOCNOW, /* flags */
1520 #if __FreeBSD_version >= 502000
1521 NULL, /* lockfunc */
1522 NULL, /* lockfuncarg */
1525 printf("ixgb%d: Unable to allocate TX DMA tag\n", adapter->unit);
1528 if (ixgb_allocate_transmit_structures(adapter))
1531 bzero((void *)adapter->tx_desc_base,
1532 (sizeof(struct ixgb_tx_desc)) * adapter->num_tx_desc);
1534 adapter->next_avail_tx_desc = 0;
1535 adapter->oldest_used_tx_desc = 0;
1537 /* Set number of descriptors available */
1538 adapter->num_tx_desc_avail = adapter->num_tx_desc;
1540 /* Set checksum context */
1541 adapter->active_checksum_context = OFFLOAD_NONE;
1546 /*********************************************************************
1548 * Enable transmit unit.
1550 **********************************************************************/
1552 ixgb_initialize_transmit_unit(struct adapter * adapter)
1555 u_int64_t tdba = adapter->txdma.dma_paddr;
1557 /* Setup the Base and Length of the Tx Descriptor Ring */
1558 IXGB_WRITE_REG(&adapter->hw, TDBAL,
1559 (tdba & 0x00000000ffffffffULL));
1560 IXGB_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1561 IXGB_WRITE_REG(&adapter->hw, TDLEN,
1562 adapter->num_tx_desc *
1563 sizeof(struct ixgb_tx_desc));
1565 /* Setup the HW Tx Head and Tail descriptor pointers */
1566 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
1567 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
1570 HW_DEBUGOUT2("Base = %x, Length = %x\n",
1571 IXGB_READ_REG(&adapter->hw, TDBAL),
1572 IXGB_READ_REG(&adapter->hw, TDLEN));
1574 IXGB_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
1577 /* Program the Transmit Control Register */
1578 reg_tctl = IXGB_READ_REG(&adapter->hw, TCTL);
1579 reg_tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
1580 IXGB_WRITE_REG(&adapter->hw, TCTL, reg_tctl);
1582 /* Setup Transmit Descriptor Settings for this adapter */
1583 adapter->txd_cmd = IXGB_TX_DESC_TYPE | IXGB_TX_DESC_CMD_RS;
1585 if (adapter->tx_int_delay > 0)
1586 adapter->txd_cmd |= IXGB_TX_DESC_CMD_IDE;
1590 /*********************************************************************
1592 * Free all transmit related data structures.
1594 **********************************************************************/
1596 ixgb_free_transmit_structures(struct adapter * adapter)
1598 struct ixgb_buffer *tx_buffer;
1601 INIT_DEBUGOUT("free_transmit_structures: begin");
1603 if (adapter->tx_buffer_area != NULL) {
1604 tx_buffer = adapter->tx_buffer_area;
1605 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
1606 if (tx_buffer->m_head != NULL) {
1607 bus_dmamap_unload(adapter->txtag, tx_buffer->map);
1608 bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
1609 m_freem(tx_buffer->m_head);
1611 tx_buffer->m_head = NULL;
1614 if (adapter->tx_buffer_area != NULL) {
1615 free(adapter->tx_buffer_area, M_DEVBUF);
1616 adapter->tx_buffer_area = NULL;
1618 if (adapter->txtag != NULL) {
1619 bus_dma_tag_destroy(adapter->txtag);
1620 adapter->txtag = NULL;
1625 /*********************************************************************
1627 * The offload context needs to be set when we transfer the first
1628 * packet of a particular protocol (TCP/UDP). We change the
1629 * context only if the protocol type changes.
1631 **********************************************************************/
1633 ixgb_transmit_checksum_setup(struct adapter * adapter,
1635 u_int8_t * txd_popts)
1637 struct ixgb_context_desc *TXD;
1638 struct ixgb_buffer *tx_buffer;
1641 if (mp->m_pkthdr.csum_flags) {
1643 if (mp->m_pkthdr.csum_flags & CSUM_TCP) {
1644 *txd_popts = IXGB_TX_DESC_POPTS_TXSM;
1645 if (adapter->active_checksum_context == OFFLOAD_TCP_IP)
1648 adapter->active_checksum_context = OFFLOAD_TCP_IP;
1649 } else if (mp->m_pkthdr.csum_flags & CSUM_UDP) {
1650 *txd_popts = IXGB_TX_DESC_POPTS_TXSM;
1651 if (adapter->active_checksum_context == OFFLOAD_UDP_IP)
1654 adapter->active_checksum_context = OFFLOAD_UDP_IP;
1665 * If we reach this point, the checksum offload context needs to be
1668 curr_txd = adapter->next_avail_tx_desc;
1669 tx_buffer = &adapter->tx_buffer_area[curr_txd];
1670 TXD = (struct ixgb_context_desc *) & adapter->tx_desc_base[curr_txd];
1673 TXD->tucss = ENET_HEADER_SIZE + sizeof(struct ip);
1678 if (adapter->active_checksum_context == OFFLOAD_TCP_IP) {
1680 ENET_HEADER_SIZE + sizeof(struct ip) +
1681 offsetof(struct tcphdr, th_sum);
1682 } else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) {
1684 ENET_HEADER_SIZE + sizeof(struct ip) +
1685 offsetof(struct udphdr, uh_sum);
1687 TXD->cmd_type_len = IXGB_CONTEXT_DESC_CMD_TCP | IXGB_TX_DESC_CMD_RS | IXGB_CONTEXT_DESC_CMD_IDE;
1689 tx_buffer->m_head = NULL;
1691 if (++curr_txd == adapter->num_tx_desc)
1694 adapter->num_tx_desc_avail--;
1695 adapter->next_avail_tx_desc = curr_txd;
1699 /**********************************************************************
1701 * Examine each tx_buffer in the used queue. If the hardware is done
1702 * processing the packet then free associated resources. The
1703 * tx_buffer is put back on the free queue.
1705 **********************************************************************/
1707 ixgb_clean_transmit_interrupts(struct adapter * adapter)
1710 struct ixgb_buffer *tx_buffer;
1711 struct ixgb_tx_desc *tx_desc;
1713 IXGB_LOCK_ASSERT(adapter);
1715 if (adapter->num_tx_desc_avail == adapter->num_tx_desc)
1719 adapter->clean_tx_interrupts++;
1721 num_avail = adapter->num_tx_desc_avail;
1722 i = adapter->oldest_used_tx_desc;
1724 tx_buffer = &adapter->tx_buffer_area[i];
1725 tx_desc = &adapter->tx_desc_base[i];
1727 while (tx_desc->status & IXGB_TX_DESC_STATUS_DD) {
1729 tx_desc->status = 0;
1732 if (tx_buffer->m_head) {
1733 bus_dmamap_sync(adapter->txtag, tx_buffer->map,
1734 BUS_DMASYNC_POSTWRITE);
1735 bus_dmamap_unload(adapter->txtag, tx_buffer->map);
1736 bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
1737 m_freem(tx_buffer->m_head);
1738 tx_buffer->m_head = NULL;
1740 if (++i == adapter->num_tx_desc)
1743 tx_buffer = &adapter->tx_buffer_area[i];
1744 tx_desc = &adapter->tx_desc_base[i];
1747 adapter->oldest_used_tx_desc = i;
1750 * If we have enough room, clear IFF_DRV_OACTIVE to tell the stack that
1751 * it is OK to send packets. If there are no pending descriptors,
1752 * clear the timeout. Otherwise, if some descriptors have been freed,
1753 * restart the timeout.
1755 if (num_avail > IXGB_TX_CLEANUP_THRESHOLD) {
1756 struct ifnet *ifp = adapter->ifp;
1758 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1759 if (num_avail == adapter->num_tx_desc)
1761 else if (num_avail == adapter->num_tx_desc_avail)
1762 ifp->if_timer = IXGB_TX_TIMEOUT;
1764 adapter->num_tx_desc_avail = num_avail;
1769 /*********************************************************************
1771 * Get a buffer from system mbuf buffer pool.
1773 **********************************************************************/
1775 ixgb_get_buf(int i, struct adapter * adapter,
1778 register struct mbuf *mp = nmp;
1779 struct ixgb_buffer *rx_buffer;
1788 mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1791 adapter->mbuf_alloc_failed++;
1794 mp->m_len = mp->m_pkthdr.len = MCLBYTES;
1796 mp->m_len = mp->m_pkthdr.len = MCLBYTES;
1797 mp->m_data = mp->m_ext.ext_buf;
1801 if (ifp->if_mtu <= ETHERMTU) {
1802 m_adj(mp, ETHER_ALIGN);
1804 rx_buffer = &adapter->rx_buffer_area[i];
1807 * Using memory from the mbuf cluster pool, invoke the bus_dma
1808 * machinery to arrange the memory mapping.
1810 error = bus_dmamap_load(adapter->rxtag, rx_buffer->map,
1811 mtod(mp, void *), mp->m_len,
1812 ixgb_dmamap_cb, &paddr, 0);
1817 rx_buffer->m_head = mp;
1818 adapter->rx_desc_base[i].buff_addr = htole64(paddr);
1819 bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
1824 /*********************************************************************
1826 * Allocate memory for rx_buffer structures. Since we use one
1827 * rx_buffer per received packet, the maximum number of rx_buffer's
1828 * that we'll need is equal to the number of receive descriptors
1829 * that we've allocated.
1831 **********************************************************************/
1833 ixgb_allocate_receive_structures(struct adapter * adapter)
1836 struct ixgb_buffer *rx_buffer;
1838 if (!(adapter->rx_buffer_area =
1839 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
1840 adapter->num_rx_desc, M_DEVBUF,
1841 M_NOWAIT | M_ZERO))) {
1842 printf("ixgb%d: Unable to allocate rx_buffer memory\n",
1846 bzero(adapter->rx_buffer_area,
1847 sizeof(struct ixgb_buffer) * adapter->num_rx_desc);
1849 error = bus_dma_tag_create(NULL, /* parent */
1850 PAGE_SIZE, 0, /* alignment, bounds */
1851 BUS_SPACE_MAXADDR, /* lowaddr */
1852 BUS_SPACE_MAXADDR, /* highaddr */
1853 NULL, NULL, /* filter, filterarg */
1854 MCLBYTES, /* maxsize */
1856 MCLBYTES, /* maxsegsize */
1857 BUS_DMA_ALLOCNOW, /* flags */
1858 #if __FreeBSD_version >= 502000
1859 NULL, /* lockfunc */
1860 NULL, /* lockfuncarg */
1864 printf("ixgb%d: ixgb_allocate_receive_structures: "
1865 "bus_dma_tag_create failed; error %u\n",
1866 adapter->unit, error);
1869 rx_buffer = adapter->rx_buffer_area;
1870 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
1871 error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT,
1874 printf("ixgb%d: ixgb_allocate_receive_structures: "
1875 "bus_dmamap_create failed; error %u\n",
1876 adapter->unit, error);
1881 for (i = 0; i < adapter->num_rx_desc; i++) {
1882 if (ixgb_get_buf(i, adapter, NULL) == ENOBUFS) {
1883 adapter->rx_buffer_area[i].m_head = NULL;
1884 adapter->rx_desc_base[i].buff_addr = 0;
1891 bus_dma_tag_destroy(adapter->rxtag);
1893 adapter->rxtag = NULL;
1894 free(adapter->rx_buffer_area, M_DEVBUF);
1895 adapter->rx_buffer_area = NULL;
1899 /*********************************************************************
1901 * Allocate and initialize receive structures.
1903 **********************************************************************/
1905 ixgb_setup_receive_structures(struct adapter * adapter)
1907 bzero((void *)adapter->rx_desc_base,
1908 (sizeof(struct ixgb_rx_desc)) * adapter->num_rx_desc);
1910 if (ixgb_allocate_receive_structures(adapter))
1913 /* Setup our descriptor pointers */
1914 adapter->next_rx_desc_to_check = 0;
1915 adapter->next_rx_desc_to_use = 0;
1919 /*********************************************************************
1921 * Enable receive unit.
1923 **********************************************************************/
1925 ixgb_initialize_receive_unit(struct adapter * adapter)
1928 u_int32_t reg_rxcsum;
1929 u_int32_t reg_rxdctl;
1931 u_int64_t rdba = adapter->rxdma.dma_paddr;
1936 * Make sure receives are disabled while setting up the descriptor
1939 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1940 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl & ~IXGB_RCTL_RXEN);
1942 /* Set the Receive Delay Timer Register */
1943 IXGB_WRITE_REG(&adapter->hw, RDTR,
1944 adapter->rx_int_delay);
1947 /* Setup the Base and Length of the Rx Descriptor Ring */
1948 IXGB_WRITE_REG(&adapter->hw, RDBAL,
1949 (rdba & 0x00000000ffffffffULL));
1950 IXGB_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
1951 IXGB_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc *
1952 sizeof(struct ixgb_rx_desc));
1954 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1955 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1957 IXGB_WRITE_REG(&adapter->hw, RDT, adapter->num_rx_desc - 1);
1961 reg_rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT
1962 | RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT
1963 | RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
1964 IXGB_WRITE_REG(&adapter->hw, RXDCTL, reg_rxdctl);
1968 if (adapter->raidc) {
1970 uint8_t poll_threshold;
1971 #define IXGB_RAIDC_POLL_DEFAULT 120
1973 poll_threshold = ((adapter->num_rx_desc - 1) >> 3);
1974 poll_threshold >>= 1;
1975 poll_threshold &= 0x3F;
1976 raidc = IXGB_RAIDC_EN | IXGB_RAIDC_RXT_GATE |
1977 (IXGB_RAIDC_POLL_DEFAULT << IXGB_RAIDC_POLL_SHIFT) |
1978 (adapter->rx_int_delay << IXGB_RAIDC_DELAY_SHIFT) |
1980 IXGB_WRITE_REG(&adapter->hw, RAIDC, raidc);
1982 /* Enable Receive Checksum Offload for TCP and UDP ? */
1983 if (ifp->if_capenable & IFCAP_RXCSUM) {
1984 reg_rxcsum = IXGB_READ_REG(&adapter->hw, RXCSUM);
1985 reg_rxcsum |= IXGB_RXCSUM_TUOFL;
1986 IXGB_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum);
1988 /* Setup the Receive Control Register */
1989 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1990 reg_rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
1991 reg_rctl |= IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | IXGB_RCTL_SECRC |
1993 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
1995 switch (adapter->rx_buffer_len) {
1997 case IXGB_RXBUFFER_2048:
1998 reg_rctl |= IXGB_RCTL_BSIZE_2048;
2000 case IXGB_RXBUFFER_4096:
2001 reg_rctl |= IXGB_RCTL_BSIZE_4096;
2003 case IXGB_RXBUFFER_8192:
2004 reg_rctl |= IXGB_RCTL_BSIZE_8192;
2006 case IXGB_RXBUFFER_16384:
2007 reg_rctl |= IXGB_RCTL_BSIZE_16384;
2011 reg_rctl |= IXGB_RCTL_RXEN;
2014 /* Enable Receives */
2015 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
2020 /*********************************************************************
2022 * Free receive related data structures.
2024 **********************************************************************/
2026 ixgb_free_receive_structures(struct adapter * adapter)
2028 struct ixgb_buffer *rx_buffer;
2031 INIT_DEBUGOUT("free_receive_structures: begin");
2033 if (adapter->rx_buffer_area != NULL) {
2034 rx_buffer = adapter->rx_buffer_area;
2035 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
2036 if (rx_buffer->map != NULL) {
2037 bus_dmamap_unload(adapter->rxtag, rx_buffer->map);
2038 bus_dmamap_destroy(adapter->rxtag, rx_buffer->map);
2040 if (rx_buffer->m_head != NULL)
2041 m_freem(rx_buffer->m_head);
2042 rx_buffer->m_head = NULL;
2045 if (adapter->rx_buffer_area != NULL) {
2046 free(adapter->rx_buffer_area, M_DEVBUF);
2047 adapter->rx_buffer_area = NULL;
2049 if (adapter->rxtag != NULL) {
2050 bus_dma_tag_destroy(adapter->rxtag);
2051 adapter->rxtag = NULL;
2056 /*********************************************************************
2058 * This routine executes in interrupt context. It replenishes
2059 * the mbufs in the descriptor and sends data which has been
2060 * dma'ed into host memory to upper layer.
2062 * We loop at most count times if count is > 0, or until done if
2065 *********************************************************************/
2067 ixgb_process_receive_interrupts(struct adapter * adapter, int count)
2071 #if __FreeBSD_version < 500000
2072 struct ether_header *eh;
2076 u_int8_t accept_frame = 0;
2078 int next_to_use = 0;
2080 /* Pointer to the receive descriptor being examined. */
2081 struct ixgb_rx_desc *current_desc;
2083 IXGB_LOCK_ASSERT(adapter);
2086 i = adapter->next_rx_desc_to_check;
2087 next_to_use = adapter->next_rx_desc_to_use;
2088 eop_desc = adapter->next_rx_desc_to_check;
2089 current_desc = &adapter->rx_desc_base[i];
2091 if (!((current_desc->status) & IXGB_RX_DESC_STATUS_DD)) {
2093 adapter->no_pkts_avail++;
2097 while ((current_desc->status & IXGB_RX_DESC_STATUS_DD) && (count != 0)) {
2099 mp = adapter->rx_buffer_area[i].m_head;
2100 bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map,
2101 BUS_DMASYNC_POSTREAD);
2103 if (current_desc->status & IXGB_RX_DESC_STATUS_EOP) {
2109 len = current_desc->length;
2111 if (current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
2112 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
2113 IXGB_RX_DESC_ERRORS_RXE)) {
2118 /* Assign correct length to the current fragment */
2121 if (adapter->fmp == NULL) {
2122 mp->m_pkthdr.len = len;
2123 adapter->fmp = mp; /* Store the first mbuf */
2126 /* Chain mbuf's together */
2127 mp->m_flags &= ~M_PKTHDR;
2128 adapter->lmp->m_next = mp;
2129 adapter->lmp = adapter->lmp->m_next;
2130 adapter->fmp->m_pkthdr.len += len;
2135 adapter->fmp->m_pkthdr.rcvif = ifp;
2137 #if __FreeBSD_version < 500000
2138 eh = mtod(adapter->fmp, struct ether_header *);
2140 /* Remove ethernet header from mbuf */
2141 m_adj(adapter->fmp, sizeof(struct ether_header));
2142 ixgb_receive_checksum(adapter, current_desc,
2145 if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
2146 VLAN_INPUT_TAG_NEW(eh, adapter->fmp,
2147 current_desc->special);
2149 ether_input(ifp, eh, adapter->fmp);
2151 ixgb_receive_checksum(adapter, current_desc,
2153 if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
2154 VLAN_INPUT_TAG_NEW(ifp, adapter->fmp,
2155 current_desc->special);
2157 if (adapter->fmp != NULL) {
2158 IXGB_UNLOCK(adapter);
2159 (*ifp->if_input) (ifp, adapter->fmp);
2163 adapter->fmp = NULL;
2164 adapter->lmp = NULL;
2166 adapter->rx_buffer_area[i].m_head = NULL;
2168 adapter->dropped_pkts++;
2169 if (adapter->fmp != NULL)
2170 m_freem(adapter->fmp);
2171 adapter->fmp = NULL;
2172 adapter->lmp = NULL;
2175 /* Zero out the receive descriptors status */
2176 current_desc->status = 0;
2178 /* Advance our pointers to the next descriptor */
2179 if (++i == adapter->num_rx_desc) {
2181 current_desc = adapter->rx_desc_base;
2185 adapter->next_rx_desc_to_check = i;
2188 i = (adapter->num_rx_desc - 1);
2191 * 82597EX: Workaround for redundent write back in receive descriptor ring (causes
2192 * memory corruption). Avoid using and re-submitting the most recently received RX
2193 * descriptor back to hardware.
2195 * if(Last written back descriptor == EOP bit set descriptor)
2196 * then avoid re-submitting the most recently received RX descriptor
2198 * if(Last written back descriptor != EOP bit set descriptor)
2199 * then avoid re-submitting the most recently received RX descriptors
2200 * till last EOP bit set descriptor.
2202 if (eop_desc != i) {
2203 if (++eop_desc == adapter->num_rx_desc)
2207 /* Replenish the descriptors with new mbufs till last EOP bit set descriptor */
2208 while (next_to_use != i) {
2209 current_desc = &adapter->rx_desc_base[next_to_use];
2210 if ((current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
2211 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
2212 IXGB_RX_DESC_ERRORS_RXE))) {
2213 mp = adapter->rx_buffer_area[next_to_use].m_head;
2214 ixgb_get_buf(next_to_use, adapter, mp);
2216 if (ixgb_get_buf(next_to_use, adapter, NULL) == ENOBUFS)
2219 /* Advance our pointers to the next descriptor */
2220 if (++next_to_use == adapter->num_rx_desc) {
2222 current_desc = adapter->rx_desc_base;
2226 adapter->next_rx_desc_to_use = next_to_use;
2227 if (--next_to_use < 0)
2228 next_to_use = (adapter->num_rx_desc - 1);
2229 /* Advance the IXGB's Receive Queue #0 "Tail Pointer" */
2230 IXGB_WRITE_REG(&adapter->hw, RDT, next_to_use);
2235 /*********************************************************************
2237 * Verify that the hardware indicated that the checksum is valid.
2238 * Inform the stack about the status of checksum so that stack
2239 * doesn't spend time verifying the checksum.
2241 *********************************************************************/
2243 ixgb_receive_checksum(struct adapter * adapter,
2244 struct ixgb_rx_desc * rx_desc,
2247 if (rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) {
2248 mp->m_pkthdr.csum_flags = 0;
2251 if (rx_desc->status & IXGB_RX_DESC_STATUS_IPCS) {
2253 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_IPE)) {
2254 /* IP Checksum Good */
2255 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
2256 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2259 mp->m_pkthdr.csum_flags = 0;
2262 if (rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS) {
2264 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE)) {
2265 mp->m_pkthdr.csum_flags |=
2266 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
2267 mp->m_pkthdr.csum_data = htons(0xffff);
2275 ixgb_enable_vlans(struct adapter * adapter)
2279 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2280 ctrl |= IXGB_CTRL0_VME;
2281 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2288 ixgb_enable_intr(struct adapter * adapter)
2290 IXGB_WRITE_REG(&adapter->hw, IMS, (IXGB_INT_RXT0 | IXGB_INT_TXDW |
2291 IXGB_INT_RXDMT0 | IXGB_INT_LSC | IXGB_INT_RXO));
2296 ixgb_disable_intr(struct adapter * adapter)
2298 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
2303 ixgb_write_pci_cfg(struct ixgb_hw * hw,
2307 pci_write_config(((struct ixgb_osdep *) hw->back)->dev, reg,
2311 /**********************************************************************
2313 * Update the board statistics counters.
2315 **********************************************************************/
2317 ixgb_update_stats_counters(struct adapter * adapter)
2321 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
2322 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
2323 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
2324 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
2325 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
2326 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
2327 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
2328 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
2329 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
2330 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
2332 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
2333 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
2334 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
2335 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
2336 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
2337 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
2338 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
2339 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
2340 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
2341 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
2342 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
2343 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
2344 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
2345 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
2346 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
2347 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
2348 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
2349 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
2350 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
2351 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
2352 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
2353 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
2354 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
2355 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
2356 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
2357 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
2358 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
2360 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
2361 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
2362 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
2363 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
2364 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
2365 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
2366 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
2367 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
2368 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
2369 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
2370 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
2371 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
2372 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
2373 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
2374 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
2375 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
2376 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
2377 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
2378 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
2379 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
2380 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
2381 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
2385 /* Fill out the OS statistics structure */
2386 ifp->if_ipackets = adapter->stats.gprcl;
2387 ifp->if_opackets = adapter->stats.gptcl;
2388 ifp->if_ibytes = adapter->stats.gorcl;
2389 ifp->if_obytes = adapter->stats.gotcl;
2390 ifp->if_imcasts = adapter->stats.mprcl;
2391 ifp->if_collisions = 0;
2395 adapter->dropped_pkts +
2396 adapter->stats.crcerrs +
2397 adapter->stats.rnbc +
2398 adapter->stats.mpc +
2399 adapter->stats.rlec;
2405 /**********************************************************************
2407 * This routine is called only when ixgb_display_debug_stats is enabled.
2408 * This routine provides a way to take a look at important statistics
2409 * maintained by the driver and hardware.
2411 **********************************************************************/
2413 ixgb_print_hw_stats(struct adapter * adapter)
2415 char buf_speed[100], buf_type[100];
2416 ixgb_bus_speed bus_speed;
2417 ixgb_bus_type bus_type;
2418 int unit = adapter->unit;
2421 printf("ixgb%d: Packets not Avail = %ld\n", unit,
2422 adapter->no_pkts_avail);
2423 printf("ixgb%d: CleanTxInterrupts = %ld\n", unit,
2424 adapter->clean_tx_interrupts);
2425 printf("ixgb%d: ICR RXDMT0 = %lld\n", unit,
2426 (long long)adapter->sv_stats.icr_rxdmt0);
2427 printf("ixgb%d: ICR RXO = %lld\n", unit,
2428 (long long)adapter->sv_stats.icr_rxo);
2429 printf("ixgb%d: ICR RXT0 = %lld\n", unit,
2430 (long long)adapter->sv_stats.icr_rxt0);
2431 printf("ixgb%d: ICR TXDW = %lld\n", unit,
2432 (long long)adapter->sv_stats.icr_TXDW);
2435 bus_speed = adapter->hw.bus.speed;
2436 bus_type = adapter->hw.bus.type;
2438 bus_speed == ixgb_bus_speed_33 ? "33MHz" :
2439 bus_speed == ixgb_bus_speed_66 ? "66MHz" :
2440 bus_speed == ixgb_bus_speed_100 ? "100MHz" :
2441 bus_speed == ixgb_bus_speed_133 ? "133MHz" :
2443 printf("ixgb%d: PCI_Bus_Speed = %s\n", unit,
2447 bus_type == ixgb_bus_type_pci ? "PCI" :
2448 bus_type == ixgb_bus_type_pcix ? "PCI-X" :
2450 printf("ixgb%d: PCI_Bus_Type = %s\n", unit,
2453 printf("ixgb%d: Tx Descriptors not Avail1 = %ld\n", unit,
2454 adapter->no_tx_desc_avail1);
2455 printf("ixgb%d: Tx Descriptors not Avail2 = %ld\n", unit,
2456 adapter->no_tx_desc_avail2);
2457 printf("ixgb%d: Std Mbuf Failed = %ld\n", unit,
2458 adapter->mbuf_alloc_failed);
2459 printf("ixgb%d: Std Cluster Failed = %ld\n", unit,
2460 adapter->mbuf_cluster_failed);
2462 printf("ixgb%d: Defer count = %lld\n", unit,
2463 (long long)adapter->stats.dc);
2464 printf("ixgb%d: Missed Packets = %lld\n", unit,
2465 (long long)adapter->stats.mpc);
2466 printf("ixgb%d: Receive No Buffers = %lld\n", unit,
2467 (long long)adapter->stats.rnbc);
2468 printf("ixgb%d: Receive length errors = %lld\n", unit,
2469 (long long)adapter->stats.rlec);
2470 printf("ixgb%d: Crc errors = %lld\n", unit,
2471 (long long)adapter->stats.crcerrs);
2472 printf("ixgb%d: Driver dropped packets = %ld\n", unit,
2473 adapter->dropped_pkts);
2475 printf("ixgb%d: XON Rcvd = %lld\n", unit,
2476 (long long)adapter->stats.xonrxc);
2477 printf("ixgb%d: XON Xmtd = %lld\n", unit,
2478 (long long)adapter->stats.xontxc);
2479 printf("ixgb%d: XOFF Rcvd = %lld\n", unit,
2480 (long long)adapter->stats.xoffrxc);
2481 printf("ixgb%d: XOFF Xmtd = %lld\n", unit,
2482 (long long)adapter->stats.xofftxc);
2484 printf("ixgb%d: Good Packets Rcvd = %lld\n", unit,
2485 (long long)adapter->stats.gprcl);
2486 printf("ixgb%d: Good Packets Xmtd = %lld\n", unit,
2487 (long long)adapter->stats.gptcl);
2489 printf("ixgb%d: Jumbo frames recvd = %lld\n", unit,
2490 (long long)adapter->stats.jprcl);
2491 printf("ixgb%d: Jumbo frames Xmtd = %lld\n", unit,
2492 (long long)adapter->stats.jptcl);
2499 ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS)
2503 struct adapter *adapter;
2506 error = sysctl_handle_int(oidp, &result, 0, req);
2508 if (error || !req->newptr)
2512 adapter = (struct adapter *) arg1;
2513 ixgb_print_hw_stats(adapter);