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);
394 ixgb_free_pci_resources(adapter);
395 #if __FreeBSD_version >= 500000
396 if_free(adapter->ifp);
399 /* Free Transmit Descriptor ring */
400 if (adapter->tx_desc_base) {
401 ixgb_dma_free(adapter, &adapter->txdma);
402 adapter->tx_desc_base = NULL;
404 /* Free Receive Descriptor ring */
405 if (adapter->rx_desc_base) {
406 ixgb_dma_free(adapter, &adapter->rxdma);
407 adapter->rx_desc_base = NULL;
409 /* Remove from the adapter list */
410 if (ixgb_adapter_list == adapter)
411 ixgb_adapter_list = adapter->next;
412 if (adapter->next != NULL)
413 adapter->next->prev = adapter->prev;
414 if (adapter->prev != NULL)
415 adapter->prev->next = adapter->next;
417 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
420 IXGB_LOCK_DESTROY(adapter);
424 /*********************************************************************
426 * Shutdown entry point
428 **********************************************************************/
431 ixgb_shutdown(device_t dev)
433 struct adapter *adapter = device_get_softc(dev);
436 IXGB_UNLOCK(adapter);
441 /*********************************************************************
442 * Transmit entry point
444 * ixgb_start is called by the stack to initiate a transmit.
445 * The driver will remain in this routine as long as there are
446 * packets to transmit and transmit resources are available.
447 * In case resources are not available stack is notified and
448 * the packet is requeued.
449 **********************************************************************/
452 ixgb_start_locked(struct ifnet * ifp)
455 struct adapter *adapter = ifp->if_softc;
457 IXGB_LOCK_ASSERT(adapter);
459 if (!adapter->link_active)
462 while (ifp->if_snd.ifq_head != NULL) {
463 IF_DEQUEUE(&ifp->if_snd, m_head);
468 if (ixgb_encap(adapter, m_head)) {
469 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
470 IF_PREPEND(&ifp->if_snd, m_head);
473 /* Send a copy of the frame to the BPF listener */
474 #if __FreeBSD_version < 500000
476 bpf_mtap(ifp, m_head);
478 ETHER_BPF_MTAP(ifp, m_head);
480 /* Set timeout in case hardware has problems transmitting */
481 ifp->if_timer = IXGB_TX_TIMEOUT;
488 ixgb_start(struct ifnet *ifp)
490 struct adapter *adapter = ifp->if_softc;
493 ixgb_start_locked(ifp);
494 IXGB_UNLOCK(adapter);
498 /*********************************************************************
501 * ixgb_ioctl is called when the user wants to configure the
504 * return 0 on success, positive on failure
505 **********************************************************************/
508 ixgb_ioctl(struct ifnet * ifp, IOCTL_CMD_TYPE command, caddr_t data)
511 struct ifreq *ifr = (struct ifreq *) data;
512 struct adapter *adapter = ifp->if_softc;
514 if (adapter->in_detach)
520 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
521 ether_ioctl(ifp, command, data);
524 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
525 if (ifr->ifr_mtu > IXGB_MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) {
529 ifp->if_mtu = ifr->ifr_mtu;
530 adapter->hw.max_frame_size =
531 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
533 ixgb_init_locked(adapter);
534 IXGB_UNLOCK(adapter);
538 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
540 if (ifp->if_flags & IFF_UP) {
541 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
542 ixgb_init_locked(adapter);
544 ixgb_disable_promisc(adapter);
545 ixgb_set_promisc(adapter);
547 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
551 IXGB_UNLOCK(adapter);
555 IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI");
556 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
558 ixgb_disable_intr(adapter);
559 ixgb_set_multi(adapter);
560 ixgb_enable_intr(adapter);
561 IXGB_UNLOCK(adapter);
566 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
567 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
570 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)");
571 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
572 #ifdef DEVICE_POLLING
573 if (mask & IFCAP_POLLING) {
574 if (ifr->ifr_reqcap & IFCAP_POLLING) {
575 error = ether_poll_register(ixgb_poll, ifp);
579 ixgb_disable_intr(adapter);
580 ifp->if_capenable |= IFCAP_POLLING;
581 IXGB_UNLOCK(adapter);
583 error = ether_poll_deregister(ifp);
584 /* Enable interrupt even in error case */
586 ixgb_enable_intr(adapter);
587 ifp->if_capenable &= ~IFCAP_POLLING;
588 IXGB_UNLOCK(adapter);
591 #endif /* DEVICE_POLLING */
592 if (mask & IFCAP_HWCSUM) {
593 if (IFCAP_HWCSUM & ifp->if_capenable)
594 ifp->if_capenable &= ~IFCAP_HWCSUM;
596 ifp->if_capenable |= IFCAP_HWCSUM;
597 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
602 IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%X)\n", (int)command);
610 /*********************************************************************
611 * Watchdog entry point
613 * This routine is called whenever hardware quits transmitting.
615 **********************************************************************/
618 ixgb_watchdog(struct ifnet * ifp)
620 struct adapter *adapter;
621 adapter = ifp->if_softc;
624 * If we are in this routine because of pause frames, then don't
625 * reset the hardware.
627 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_TXOFF) {
628 ifp->if_timer = IXGB_TX_TIMEOUT;
631 printf("ixgb%d: watchdog timeout -- resetting\n", adapter->unit);
633 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
645 /*********************************************************************
648 * This routine is used in two ways. It is used by the stack as
649 * init entry point in network interface structure. It is also used
650 * by the driver as a hw/sw initialization routine to get to a
653 * return 0 on success, positive on failure
654 **********************************************************************/
657 ixgb_init_locked(struct adapter *adapter)
661 INIT_DEBUGOUT("ixgb_init: begin");
663 IXGB_LOCK_ASSERT(adapter);
667 /* Get the latest mac address, User can use a LAA */
668 bcopy(IF_LLADDR(adapter->ifp), adapter->hw.curr_mac_addr,
669 IXGB_ETH_LENGTH_OF_ADDRESS);
671 /* Initialize the hardware */
672 if (ixgb_hardware_init(adapter)) {
673 printf("ixgb%d: Unable to initialize the hardware\n",
677 ixgb_enable_vlans(adapter);
679 /* Prepare transmit descriptors and buffers */
680 if (ixgb_setup_transmit_structures(adapter)) {
681 printf("ixgb%d: Could not setup transmit structures\n",
686 ixgb_initialize_transmit_unit(adapter);
688 /* Setup Multicast table */
689 ixgb_set_multi(adapter);
691 /* Prepare receive descriptors and buffers */
692 if (ixgb_setup_receive_structures(adapter)) {
693 printf("ixgb%d: Could not setup receive structures\n",
698 ixgb_initialize_receive_unit(adapter);
700 /* Don't lose promiscuous settings */
701 ixgb_set_promisc(adapter);
704 ifp->if_drv_flags |= IFF_DRV_RUNNING;
705 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
708 if (ifp->if_capenable & IFCAP_TXCSUM)
709 ifp->if_hwassist = IXGB_CHECKSUM_FEATURES;
711 ifp->if_hwassist = 0;
714 /* Enable jumbo frames */
715 if (ifp->if_mtu > ETHERMTU) {
717 IXGB_WRITE_REG(&adapter->hw, MFS,
718 adapter->hw.max_frame_size << IXGB_MFS_SHIFT);
719 temp_reg = IXGB_READ_REG(&adapter->hw, CTRL0);
720 temp_reg |= IXGB_CTRL0_JFE;
721 IXGB_WRITE_REG(&adapter->hw, CTRL0, temp_reg);
723 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
724 ixgb_clear_hw_cntrs(&adapter->hw);
725 #ifdef DEVICE_POLLING
727 * Only disable interrupts if we are polling, make sure they are on
730 if (ifp->if_capenable & IFCAP_POLLING)
731 ixgb_disable_intr(adapter);
734 ixgb_enable_intr(adapter);
742 struct adapter *adapter = arg;
745 ixgb_init_locked(adapter);
746 IXGB_UNLOCK(adapter);
750 #ifdef DEVICE_POLLING
752 ixgb_poll_locked(struct ifnet * ifp, enum poll_cmd cmd, int count)
754 struct adapter *adapter = ifp->if_softc;
757 IXGB_LOCK_ASSERT(adapter);
759 if (cmd == POLL_AND_CHECK_STATUS) {
760 reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
761 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
762 callout_stop(&adapter->timer);
763 ixgb_check_for_link(&adapter->hw);
764 ixgb_print_link_status(adapter);
765 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
769 ixgb_process_receive_interrupts(adapter, count);
770 ixgb_clean_transmit_interrupts(adapter);
772 if (ifp->if_snd.ifq_head != NULL)
773 ixgb_start_locked(ifp);
777 ixgb_poll(struct ifnet * ifp, enum poll_cmd cmd, int count)
779 struct adapter *adapter = ifp->if_softc;
782 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
783 ixgb_poll_locked(ifp, cmd, count);
784 IXGB_UNLOCK(adapter);
786 #endif /* DEVICE_POLLING */
788 /*********************************************************************
790 * Interrupt Service routine
792 **********************************************************************/
797 u_int32_t loop_cnt = IXGB_MAX_INTR;
800 struct adapter *adapter = arg;
801 boolean_t rxdmt0 = FALSE;
807 #ifdef DEVICE_POLLING
808 if (ifp->if_capenable & IFCAP_POLLING) {
809 IXGB_UNLOCK(adapter);
814 reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
816 IXGB_UNLOCK(adapter);
820 if (reg_icr & IXGB_INT_RXDMT0)
824 if (reg_icr & IXGB_INT_RXDMT0)
825 adapter->sv_stats.icr_rxdmt0++;
826 if (reg_icr & IXGB_INT_RXO)
827 adapter->sv_stats.icr_rxo++;
828 if (reg_icr & IXGB_INT_RXT0)
829 adapter->sv_stats.icr_rxt0++;
830 if (reg_icr & IXGB_INT_TXDW)
831 adapter->sv_stats.icr_TXDW++;
834 /* Link status change */
835 if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
836 callout_stop(&adapter->timer);
837 ixgb_check_for_link(&adapter->hw);
838 ixgb_print_link_status(adapter);
839 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
842 while (loop_cnt > 0) {
843 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
844 ixgb_process_receive_interrupts(adapter, -1);
845 ixgb_clean_transmit_interrupts(adapter);
850 if (rxdmt0 && adapter->raidc) {
851 IXGB_WRITE_REG(&adapter->hw, IMC, IXGB_INT_RXDMT0);
852 IXGB_WRITE_REG(&adapter->hw, IMS, IXGB_INT_RXDMT0);
854 if (ifp->if_drv_flags & IFF_DRV_RUNNING && ifp->if_snd.ifq_head != NULL)
855 ixgb_start_locked(ifp);
857 IXGB_UNLOCK(adapter);
862 /*********************************************************************
864 * Media Ioctl callback
866 * This routine is called whenever the user queries the status of
867 * the interface using ifconfig.
869 **********************************************************************/
871 ixgb_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
873 struct adapter *adapter = ifp->if_softc;
875 INIT_DEBUGOUT("ixgb_media_status: begin");
877 ixgb_check_for_link(&adapter->hw);
878 ixgb_print_link_status(adapter);
880 ifmr->ifm_status = IFM_AVALID;
881 ifmr->ifm_active = IFM_ETHER;
883 if (!adapter->hw.link_up)
886 ifmr->ifm_status |= IFM_ACTIVE;
887 ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
892 /*********************************************************************
894 * Media Ioctl callback
896 * This routine is called when the user changes speed/duplex using
897 * media/mediopt option with ifconfig.
899 **********************************************************************/
901 ixgb_media_change(struct ifnet * ifp)
903 struct adapter *adapter = ifp->if_softc;
904 struct ifmedia *ifm = &adapter->media;
906 INIT_DEBUGOUT("ixgb_media_change: begin");
908 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
914 /*********************************************************************
916 * This routine maps the mbufs to tx descriptors.
918 * return 0 on success, positive on failure
919 **********************************************************************/
922 ixgb_encap(struct adapter * adapter, struct mbuf * m_head)
925 int i, j, error, nsegs;
927 #if __FreeBSD_version < 500000
928 struct ifvlan *ifv = NULL;
930 bus_dma_segment_t segs[IXGB_MAX_SCATTER];
932 struct ixgb_buffer *tx_buffer = NULL;
933 struct ixgb_tx_desc *current_tx_desc = NULL;
934 struct ifnet *ifp = adapter->ifp;
937 * Force a cleanup if number of TX descriptors available hits the
940 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
941 ixgb_clean_transmit_interrupts(adapter);
943 if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
944 adapter->no_tx_desc_avail1++;
948 * Map the packet for DMA.
950 if (bus_dmamap_create(adapter->txtag, BUS_DMA_NOWAIT, &map)) {
951 adapter->no_tx_map_avail++;
954 error = bus_dmamap_load_mbuf_sg(adapter->txtag, map, m_head, segs,
955 &nsegs, BUS_DMA_NOWAIT);
957 adapter->no_tx_dma_setup++;
958 printf("ixgb%d: ixgb_encap: bus_dmamap_load_mbuf failed; "
959 "error %u\n", adapter->unit, error);
960 bus_dmamap_destroy(adapter->txtag, map);
963 KASSERT(nsegs != 0, ("ixgb_encap: empty packet"));
965 if (nsegs > adapter->num_tx_desc_avail) {
966 adapter->no_tx_desc_avail2++;
967 bus_dmamap_destroy(adapter->txtag, map);
970 if (ifp->if_hwassist > 0) {
971 ixgb_transmit_checksum_setup(adapter, m_head,
976 /* Find out if we are in vlan mode */
977 #if __FreeBSD_version < 500000
978 if ((m_head->m_flags & (M_PROTO1 | M_PKTHDR)) == (M_PROTO1 | M_PKTHDR) &&
979 m_head->m_pkthdr.rcvif != NULL &&
980 m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
981 ifv = m_head->m_pkthdr.rcvif->if_softc;
982 #elseif __FreeBSD_version < 700000
983 mtag = VLAN_OUTPUT_TAG(ifp, m_head);
985 i = adapter->next_avail_tx_desc;
986 for (j = 0; j < nsegs; j++) {
987 tx_buffer = &adapter->tx_buffer_area[i];
988 current_tx_desc = &adapter->tx_desc_base[i];
990 current_tx_desc->buff_addr = htole64(segs[j].ds_addr);
991 current_tx_desc->cmd_type_len = (adapter->txd_cmd | segs[j].ds_len);
992 current_tx_desc->popts = txd_popts;
993 if (++i == adapter->num_tx_desc)
996 tx_buffer->m_head = NULL;
999 adapter->num_tx_desc_avail -= nsegs;
1000 adapter->next_avail_tx_desc = i;
1002 #if __FreeBSD_version < 500000
1004 /* Set the vlan id */
1005 current_tx_desc->vlan = ifv->ifv_tag;
1006 #elseif __FreeBSD_version < 700000
1008 /* Set the vlan id */
1009 current_tx_desc->vlan = VLAN_TAG_VALUE(mtag);
1011 if (m_head->m_flags & M_VLANTAG) {
1012 current_tx_desc->vlan = m_head->m_pkthdr.ether_vtag;
1015 /* Tell hardware to add tag */
1016 current_tx_desc->cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1018 tx_buffer->m_head = m_head;
1019 tx_buffer->map = map;
1020 bus_dmamap_sync(adapter->txtag, map, BUS_DMASYNC_PREWRITE);
1023 * Last Descriptor of Packet needs End Of Packet (EOP)
1025 current_tx_desc->cmd_type_len |= (IXGB_TX_DESC_CMD_EOP);
1028 * Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
1029 * that this frame is available to transmit.
1031 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1037 ixgb_set_promisc(struct adapter * adapter)
1041 struct ifnet *ifp = adapter->ifp;
1043 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1045 if (ifp->if_flags & IFF_PROMISC) {
1046 reg_rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1047 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1048 } else if (ifp->if_flags & IFF_ALLMULTI) {
1049 reg_rctl |= IXGB_RCTL_MPE;
1050 reg_rctl &= ~IXGB_RCTL_UPE;
1051 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1057 ixgb_disable_promisc(struct adapter * adapter)
1061 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1063 reg_rctl &= (~IXGB_RCTL_UPE);
1064 reg_rctl &= (~IXGB_RCTL_MPE);
1065 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1071 /*********************************************************************
1074 * This routine is called whenever multicast address list is updated.
1076 **********************************************************************/
1079 ixgb_set_multi(struct adapter * adapter)
1081 u_int32_t reg_rctl = 0;
1082 u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * IXGB_ETH_LENGTH_OF_ADDRESS];
1083 struct ifmultiaddr *ifma;
1085 struct ifnet *ifp = adapter->ifp;
1087 IOCTL_DEBUGOUT("ixgb_set_multi: begin");
1090 #if __FreeBSD_version < 500000
1091 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1093 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1095 if (ifma->ifma_addr->sa_family != AF_LINK)
1098 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1099 &mta[mcnt * IXGB_ETH_LENGTH_OF_ADDRESS], IXGB_ETH_LENGTH_OF_ADDRESS);
1102 IF_ADDR_UNLOCK(ifp);
1104 if (mcnt > MAX_NUM_MULTICAST_ADDRESSES) {
1105 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1106 reg_rctl |= IXGB_RCTL_MPE;
1107 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
1109 ixgb_mc_addr_list_update(&adapter->hw, mta, mcnt, 0);
1115 /*********************************************************************
1118 * This routine checks for link status and updates statistics.
1120 **********************************************************************/
1123 ixgb_local_timer(void *arg)
1126 struct adapter *adapter = arg;
1131 ixgb_check_for_link(&adapter->hw);
1132 ixgb_print_link_status(adapter);
1133 ixgb_update_stats_counters(adapter);
1134 if (ixgb_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) {
1135 ixgb_print_hw_stats(adapter);
1137 callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
1139 IXGB_UNLOCK(adapter);
1144 ixgb_print_link_status(struct adapter * adapter)
1146 if (adapter->hw.link_up) {
1147 if (!adapter->link_active) {
1148 printf("ixgb%d: Link is up %d Mbps %s \n",
1152 adapter->link_active = 1;
1155 if (adapter->link_active) {
1156 printf("ixgb%d: Link is Down \n", adapter->unit);
1157 adapter->link_active = 0;
1166 /*********************************************************************
1168 * This routine disables all traffic on the adapter by issuing a
1169 * global reset on the MAC and deallocates TX/RX buffers.
1171 **********************************************************************/
1174 ixgb_stop(void *arg)
1177 struct adapter *adapter = arg;
1180 IXGB_LOCK_ASSERT(adapter);
1182 INIT_DEBUGOUT("ixgb_stop: begin\n");
1183 ixgb_disable_intr(adapter);
1184 adapter->hw.adapter_stopped = FALSE;
1185 ixgb_adapter_stop(&adapter->hw);
1186 callout_stop(&adapter->timer);
1187 ixgb_free_transmit_structures(adapter);
1188 ixgb_free_receive_structures(adapter);
1191 /* Tell the stack that the interface is no longer active */
1192 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1198 /*********************************************************************
1200 * Determine hardware revision.
1202 **********************************************************************/
1204 ixgb_identify_hardware(struct adapter * adapter)
1206 device_t dev = adapter->dev;
1208 /* Make sure our PCI config space has the necessary stuff set */
1209 adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
1210 if (!((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) &&
1211 (adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN))) {
1212 printf("ixgb%d: Memory Access and/or Bus Master bits were not set!\n",
1214 adapter->hw.pci_cmd_word |=
1215 (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
1216 pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2);
1218 /* Save off the information about this board */
1219 adapter->hw.vendor_id = pci_get_vendor(dev);
1220 adapter->hw.device_id = pci_get_device(dev);
1221 adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
1222 adapter->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
1223 adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
1225 /* Set MacType, etc. based on this PCI info */
1226 switch (adapter->hw.device_id) {
1227 case IXGB_DEVICE_ID_82597EX:
1228 case IXGB_DEVICE_ID_82597EX_SR:
1229 adapter->hw.mac_type = ixgb_82597;
1232 INIT_DEBUGOUT1("Unknown device if 0x%x", adapter->hw.device_id);
1233 printf("ixgb%d: unsupported device id 0x%x\n", adapter->unit, adapter->hw.device_id);
1240 ixgb_allocate_pci_resources(struct adapter * adapter)
1243 device_t dev = adapter->dev;
1246 adapter->res_memory = bus_alloc_resource(dev, SYS_RES_MEMORY,
1249 if (!(adapter->res_memory)) {
1250 printf("ixgb%d: Unable to allocate bus resource: memory\n",
1254 adapter->osdep.mem_bus_space_tag =
1255 rman_get_bustag(adapter->res_memory);
1256 adapter->osdep.mem_bus_space_handle =
1257 rman_get_bushandle(adapter->res_memory);
1258 adapter->hw.hw_addr = (uint8_t *) & adapter->osdep.mem_bus_space_handle;
1261 adapter->res_interrupt = bus_alloc_resource(dev, SYS_RES_IRQ,
1263 RF_SHAREABLE | RF_ACTIVE);
1264 if (!(adapter->res_interrupt)) {
1265 printf("ixgb%d: Unable to allocate bus resource: interrupt\n",
1269 if (bus_setup_intr(dev, adapter->res_interrupt,
1270 INTR_TYPE_NET | INTR_MPSAFE,
1271 NULL, (void (*) (void *))ixgb_intr, adapter,
1272 &adapter->int_handler_tag)) {
1273 printf("ixgb%d: Error registering interrupt handler!\n",
1277 adapter->hw.back = &adapter->osdep;
1283 ixgb_free_pci_resources(struct adapter * adapter)
1285 device_t dev = adapter->dev;
1287 if (adapter->res_interrupt != NULL) {
1288 bus_teardown_intr(dev, adapter->res_interrupt,
1289 adapter->int_handler_tag);
1290 bus_release_resource(dev, SYS_RES_IRQ, 0,
1291 adapter->res_interrupt);
1293 if (adapter->res_memory != NULL) {
1294 bus_release_resource(dev, SYS_RES_MEMORY, IXGB_MMBA,
1295 adapter->res_memory);
1297 if (adapter->res_ioport != NULL) {
1298 bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid,
1299 adapter->res_ioport);
1304 /*********************************************************************
1306 * Initialize the hardware to a configuration as specified by the
1307 * adapter structure. The controller is reset, the EEPROM is
1308 * verified, the MAC address is set, then the shared initialization
1309 * routines are called.
1311 **********************************************************************/
1313 ixgb_hardware_init(struct adapter * adapter)
1315 /* Issue a global reset */
1316 adapter->hw.adapter_stopped = FALSE;
1317 ixgb_adapter_stop(&adapter->hw);
1319 /* Make sure we have a good EEPROM before we read from it */
1320 if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
1321 printf("ixgb%d: The EEPROM Checksum Is Not Valid\n",
1325 if (!ixgb_init_hw(&adapter->hw)) {
1326 printf("ixgb%d: Hardware Initialization Failed",
1334 /*********************************************************************
1336 * Setup networking device structure and register an interface.
1338 **********************************************************************/
1340 ixgb_setup_interface(device_t dev, struct adapter * adapter)
1343 INIT_DEBUGOUT("ixgb_setup_interface: begin");
1345 ifp = adapter->ifp = if_alloc(IFT_ETHER);
1347 panic("%s: can not if_alloc()\n", device_get_nameunit(dev));
1348 #if __FreeBSD_version >= 502000
1349 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1351 ifp->if_unit = adapter->unit;
1352 ifp->if_name = "ixgb";
1354 ifp->if_mtu = ETHERMTU;
1355 ifp->if_baudrate = 1000000000;
1356 ifp->if_init = ixgb_init;
1357 ifp->if_softc = adapter;
1358 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1359 ifp->if_ioctl = ixgb_ioctl;
1360 ifp->if_start = ixgb_start;
1361 ifp->if_watchdog = ixgb_watchdog;
1362 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 1;
1364 #if __FreeBSD_version < 500000
1365 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
1367 ether_ifattach(ifp, adapter->hw.curr_mac_addr);
1370 ifp->if_capabilities = IFCAP_HWCSUM;
1373 * Tell the upper layer(s) we support long frames.
1375 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1377 #if __FreeBSD_version >= 500000
1378 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
1381 ifp->if_capenable = ifp->if_capabilities;
1383 #ifdef DEVICE_POLLING
1384 ifp->if_capabilities |= IFCAP_POLLING;
1388 * Specify the media types supported by this adapter and register
1389 * callbacks to update media and link information
1391 ifmedia_init(&adapter->media, IFM_IMASK, ixgb_media_change,
1393 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
1395 ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX,
1397 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1398 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
1403 /********************************************************************
1404 * Manage DMA'able memory.
1405 *******************************************************************/
1407 ixgb_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
1411 *(bus_addr_t *) arg = segs->ds_addr;
1416 ixgb_dma_malloc(struct adapter * adapter, bus_size_t size,
1417 struct ixgb_dma_alloc * dma, int mapflags)
1421 r = bus_dma_tag_create(NULL, /* parent */
1422 PAGE_SIZE, 0, /* alignment, bounds */
1423 BUS_SPACE_MAXADDR, /* lowaddr */
1424 BUS_SPACE_MAXADDR, /* highaddr */
1425 NULL, NULL, /* filter, filterarg */
1428 size, /* maxsegsize */
1429 BUS_DMA_ALLOCNOW, /* flags */
1430 #if __FreeBSD_version >= 502000
1431 NULL, /* lockfunc */
1432 NULL, /* lockfuncarg */
1436 printf("ixgb%d: ixgb_dma_malloc: bus_dma_tag_create failed; "
1437 "error %u\n", adapter->unit, r);
1440 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
1441 BUS_DMA_NOWAIT, &dma->dma_map);
1443 printf("ixgb%d: ixgb_dma_malloc: bus_dmamem_alloc failed; "
1444 "error %u\n", adapter->unit, r);
1447 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
1451 mapflags | BUS_DMA_NOWAIT);
1453 printf("ixgb%d: ixgb_dma_malloc: bus_dmamap_load failed; "
1454 "error %u\n", adapter->unit, r);
1457 dma->dma_size = size;
1460 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1462 bus_dma_tag_destroy(dma->dma_tag);
1464 dma->dma_map = NULL;
1465 dma->dma_tag = NULL;
1472 ixgb_dma_free(struct adapter * adapter, struct ixgb_dma_alloc * dma)
1474 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
1475 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
1476 bus_dma_tag_destroy(dma->dma_tag);
1479 /*********************************************************************
1481 * Allocate memory for tx_buffer structures. The tx_buffer stores all
1482 * the information needed to transmit a packet on the wire.
1484 **********************************************************************/
1486 ixgb_allocate_transmit_structures(struct adapter * adapter)
1488 if (!(adapter->tx_buffer_area =
1489 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
1490 adapter->num_tx_desc, M_DEVBUF,
1491 M_NOWAIT | M_ZERO))) {
1492 printf("ixgb%d: Unable to allocate tx_buffer memory\n",
1496 bzero(adapter->tx_buffer_area,
1497 sizeof(struct ixgb_buffer) * adapter->num_tx_desc);
1502 /*********************************************************************
1504 * Allocate and initialize transmit structures.
1506 **********************************************************************/
1508 ixgb_setup_transmit_structures(struct adapter * adapter)
1511 * Setup DMA descriptor areas.
1513 if (bus_dma_tag_create(NULL, /* parent */
1514 PAGE_SIZE, 0, /* alignment, bounds */
1515 BUS_SPACE_MAXADDR, /* lowaddr */
1516 BUS_SPACE_MAXADDR, /* highaddr */
1517 NULL, NULL, /* filter, filterarg */
1518 MCLBYTES * IXGB_MAX_SCATTER, /* maxsize */
1519 IXGB_MAX_SCATTER, /* nsegments */
1520 MCLBYTES, /* maxsegsize */
1521 BUS_DMA_ALLOCNOW, /* flags */
1522 #if __FreeBSD_version >= 502000
1523 NULL, /* lockfunc */
1524 NULL, /* lockfuncarg */
1527 printf("ixgb%d: Unable to allocate TX DMA tag\n", adapter->unit);
1530 if (ixgb_allocate_transmit_structures(adapter))
1533 bzero((void *)adapter->tx_desc_base,
1534 (sizeof(struct ixgb_tx_desc)) * adapter->num_tx_desc);
1536 adapter->next_avail_tx_desc = 0;
1537 adapter->oldest_used_tx_desc = 0;
1539 /* Set number of descriptors available */
1540 adapter->num_tx_desc_avail = adapter->num_tx_desc;
1542 /* Set checksum context */
1543 adapter->active_checksum_context = OFFLOAD_NONE;
1548 /*********************************************************************
1550 * Enable transmit unit.
1552 **********************************************************************/
1554 ixgb_initialize_transmit_unit(struct adapter * adapter)
1557 u_int64_t tdba = adapter->txdma.dma_paddr;
1559 /* Setup the Base and Length of the Tx Descriptor Ring */
1560 IXGB_WRITE_REG(&adapter->hw, TDBAL,
1561 (tdba & 0x00000000ffffffffULL));
1562 IXGB_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1563 IXGB_WRITE_REG(&adapter->hw, TDLEN,
1564 adapter->num_tx_desc *
1565 sizeof(struct ixgb_tx_desc));
1567 /* Setup the HW Tx Head and Tail descriptor pointers */
1568 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
1569 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
1572 HW_DEBUGOUT2("Base = %x, Length = %x\n",
1573 IXGB_READ_REG(&adapter->hw, TDBAL),
1574 IXGB_READ_REG(&adapter->hw, TDLEN));
1576 IXGB_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
1579 /* Program the Transmit Control Register */
1580 reg_tctl = IXGB_READ_REG(&adapter->hw, TCTL);
1581 reg_tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
1582 IXGB_WRITE_REG(&adapter->hw, TCTL, reg_tctl);
1584 /* Setup Transmit Descriptor Settings for this adapter */
1585 adapter->txd_cmd = IXGB_TX_DESC_TYPE | IXGB_TX_DESC_CMD_RS;
1587 if (adapter->tx_int_delay > 0)
1588 adapter->txd_cmd |= IXGB_TX_DESC_CMD_IDE;
1592 /*********************************************************************
1594 * Free all transmit related data structures.
1596 **********************************************************************/
1598 ixgb_free_transmit_structures(struct adapter * adapter)
1600 struct ixgb_buffer *tx_buffer;
1603 INIT_DEBUGOUT("free_transmit_structures: begin");
1605 if (adapter->tx_buffer_area != NULL) {
1606 tx_buffer = adapter->tx_buffer_area;
1607 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
1608 if (tx_buffer->m_head != NULL) {
1609 bus_dmamap_unload(adapter->txtag, tx_buffer->map);
1610 bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
1611 m_freem(tx_buffer->m_head);
1613 tx_buffer->m_head = NULL;
1616 if (adapter->tx_buffer_area != NULL) {
1617 free(adapter->tx_buffer_area, M_DEVBUF);
1618 adapter->tx_buffer_area = NULL;
1620 if (adapter->txtag != NULL) {
1621 bus_dma_tag_destroy(adapter->txtag);
1622 adapter->txtag = NULL;
1627 /*********************************************************************
1629 * The offload context needs to be set when we transfer the first
1630 * packet of a particular protocol (TCP/UDP). We change the
1631 * context only if the protocol type changes.
1633 **********************************************************************/
1635 ixgb_transmit_checksum_setup(struct adapter * adapter,
1637 u_int8_t * txd_popts)
1639 struct ixgb_context_desc *TXD;
1640 struct ixgb_buffer *tx_buffer;
1643 if (mp->m_pkthdr.csum_flags) {
1645 if (mp->m_pkthdr.csum_flags & CSUM_TCP) {
1646 *txd_popts = IXGB_TX_DESC_POPTS_TXSM;
1647 if (adapter->active_checksum_context == OFFLOAD_TCP_IP)
1650 adapter->active_checksum_context = OFFLOAD_TCP_IP;
1651 } else if (mp->m_pkthdr.csum_flags & CSUM_UDP) {
1652 *txd_popts = IXGB_TX_DESC_POPTS_TXSM;
1653 if (adapter->active_checksum_context == OFFLOAD_UDP_IP)
1656 adapter->active_checksum_context = OFFLOAD_UDP_IP;
1667 * If we reach this point, the checksum offload context needs to be
1670 curr_txd = adapter->next_avail_tx_desc;
1671 tx_buffer = &adapter->tx_buffer_area[curr_txd];
1672 TXD = (struct ixgb_context_desc *) & adapter->tx_desc_base[curr_txd];
1675 TXD->tucss = ENET_HEADER_SIZE + sizeof(struct ip);
1680 if (adapter->active_checksum_context == OFFLOAD_TCP_IP) {
1682 ENET_HEADER_SIZE + sizeof(struct ip) +
1683 offsetof(struct tcphdr, th_sum);
1684 } else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) {
1686 ENET_HEADER_SIZE + sizeof(struct ip) +
1687 offsetof(struct udphdr, uh_sum);
1689 TXD->cmd_type_len = IXGB_CONTEXT_DESC_CMD_TCP | IXGB_TX_DESC_CMD_RS | IXGB_CONTEXT_DESC_CMD_IDE;
1691 tx_buffer->m_head = NULL;
1693 if (++curr_txd == adapter->num_tx_desc)
1696 adapter->num_tx_desc_avail--;
1697 adapter->next_avail_tx_desc = curr_txd;
1701 /**********************************************************************
1703 * Examine each tx_buffer in the used queue. If the hardware is done
1704 * processing the packet then free associated resources. The
1705 * tx_buffer is put back on the free queue.
1707 **********************************************************************/
1709 ixgb_clean_transmit_interrupts(struct adapter * adapter)
1712 struct ixgb_buffer *tx_buffer;
1713 struct ixgb_tx_desc *tx_desc;
1715 IXGB_LOCK_ASSERT(adapter);
1717 if (adapter->num_tx_desc_avail == adapter->num_tx_desc)
1721 adapter->clean_tx_interrupts++;
1723 num_avail = adapter->num_tx_desc_avail;
1724 i = adapter->oldest_used_tx_desc;
1726 tx_buffer = &adapter->tx_buffer_area[i];
1727 tx_desc = &adapter->tx_desc_base[i];
1729 while (tx_desc->status & IXGB_TX_DESC_STATUS_DD) {
1731 tx_desc->status = 0;
1734 if (tx_buffer->m_head) {
1735 bus_dmamap_sync(adapter->txtag, tx_buffer->map,
1736 BUS_DMASYNC_POSTWRITE);
1737 bus_dmamap_unload(adapter->txtag, tx_buffer->map);
1738 bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
1739 m_freem(tx_buffer->m_head);
1740 tx_buffer->m_head = NULL;
1742 if (++i == adapter->num_tx_desc)
1745 tx_buffer = &adapter->tx_buffer_area[i];
1746 tx_desc = &adapter->tx_desc_base[i];
1749 adapter->oldest_used_tx_desc = i;
1752 * If we have enough room, clear IFF_DRV_OACTIVE to tell the stack that
1753 * it is OK to send packets. If there are no pending descriptors,
1754 * clear the timeout. Otherwise, if some descriptors have been freed,
1755 * restart the timeout.
1757 if (num_avail > IXGB_TX_CLEANUP_THRESHOLD) {
1758 struct ifnet *ifp = adapter->ifp;
1760 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1761 if (num_avail == adapter->num_tx_desc)
1763 else if (num_avail == adapter->num_tx_desc_avail)
1764 ifp->if_timer = IXGB_TX_TIMEOUT;
1766 adapter->num_tx_desc_avail = num_avail;
1771 /*********************************************************************
1773 * Get a buffer from system mbuf buffer pool.
1775 **********************************************************************/
1777 ixgb_get_buf(int i, struct adapter * adapter,
1780 register struct mbuf *mp = nmp;
1781 struct ixgb_buffer *rx_buffer;
1790 mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1793 adapter->mbuf_alloc_failed++;
1796 mp->m_len = mp->m_pkthdr.len = MCLBYTES;
1798 mp->m_len = mp->m_pkthdr.len = MCLBYTES;
1799 mp->m_data = mp->m_ext.ext_buf;
1803 if (ifp->if_mtu <= ETHERMTU) {
1804 m_adj(mp, ETHER_ALIGN);
1806 rx_buffer = &adapter->rx_buffer_area[i];
1809 * Using memory from the mbuf cluster pool, invoke the bus_dma
1810 * machinery to arrange the memory mapping.
1812 error = bus_dmamap_load(adapter->rxtag, rx_buffer->map,
1813 mtod(mp, void *), mp->m_len,
1814 ixgb_dmamap_cb, &paddr, 0);
1819 rx_buffer->m_head = mp;
1820 adapter->rx_desc_base[i].buff_addr = htole64(paddr);
1821 bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
1826 /*********************************************************************
1828 * Allocate memory for rx_buffer structures. Since we use one
1829 * rx_buffer per received packet, the maximum number of rx_buffer's
1830 * that we'll need is equal to the number of receive descriptors
1831 * that we've allocated.
1833 **********************************************************************/
1835 ixgb_allocate_receive_structures(struct adapter * adapter)
1838 struct ixgb_buffer *rx_buffer;
1840 if (!(adapter->rx_buffer_area =
1841 (struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
1842 adapter->num_rx_desc, M_DEVBUF,
1843 M_NOWAIT | M_ZERO))) {
1844 printf("ixgb%d: Unable to allocate rx_buffer memory\n",
1848 bzero(adapter->rx_buffer_area,
1849 sizeof(struct ixgb_buffer) * adapter->num_rx_desc);
1851 error = bus_dma_tag_create(NULL, /* parent */
1852 PAGE_SIZE, 0, /* alignment, bounds */
1853 BUS_SPACE_MAXADDR, /* lowaddr */
1854 BUS_SPACE_MAXADDR, /* highaddr */
1855 NULL, NULL, /* filter, filterarg */
1856 MCLBYTES, /* maxsize */
1858 MCLBYTES, /* maxsegsize */
1859 BUS_DMA_ALLOCNOW, /* flags */
1860 #if __FreeBSD_version >= 502000
1861 NULL, /* lockfunc */
1862 NULL, /* lockfuncarg */
1866 printf("ixgb%d: ixgb_allocate_receive_structures: "
1867 "bus_dma_tag_create failed; error %u\n",
1868 adapter->unit, error);
1871 rx_buffer = adapter->rx_buffer_area;
1872 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
1873 error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT,
1876 printf("ixgb%d: ixgb_allocate_receive_structures: "
1877 "bus_dmamap_create failed; error %u\n",
1878 adapter->unit, error);
1883 for (i = 0; i < adapter->num_rx_desc; i++) {
1884 if (ixgb_get_buf(i, adapter, NULL) == ENOBUFS) {
1885 adapter->rx_buffer_area[i].m_head = NULL;
1886 adapter->rx_desc_base[i].buff_addr = 0;
1893 bus_dma_tag_destroy(adapter->rxtag);
1895 adapter->rxtag = NULL;
1896 free(adapter->rx_buffer_area, M_DEVBUF);
1897 adapter->rx_buffer_area = NULL;
1901 /*********************************************************************
1903 * Allocate and initialize receive structures.
1905 **********************************************************************/
1907 ixgb_setup_receive_structures(struct adapter * adapter)
1909 bzero((void *)adapter->rx_desc_base,
1910 (sizeof(struct ixgb_rx_desc)) * adapter->num_rx_desc);
1912 if (ixgb_allocate_receive_structures(adapter))
1915 /* Setup our descriptor pointers */
1916 adapter->next_rx_desc_to_check = 0;
1917 adapter->next_rx_desc_to_use = 0;
1921 /*********************************************************************
1923 * Enable receive unit.
1925 **********************************************************************/
1927 ixgb_initialize_receive_unit(struct adapter * adapter)
1930 u_int32_t reg_rxcsum;
1931 u_int32_t reg_rxdctl;
1933 u_int64_t rdba = adapter->rxdma.dma_paddr;
1938 * Make sure receives are disabled while setting up the descriptor
1941 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1942 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl & ~IXGB_RCTL_RXEN);
1944 /* Set the Receive Delay Timer Register */
1945 IXGB_WRITE_REG(&adapter->hw, RDTR,
1946 adapter->rx_int_delay);
1949 /* Setup the Base and Length of the Rx Descriptor Ring */
1950 IXGB_WRITE_REG(&adapter->hw, RDBAL,
1951 (rdba & 0x00000000ffffffffULL));
1952 IXGB_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
1953 IXGB_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc *
1954 sizeof(struct ixgb_rx_desc));
1956 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1957 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1959 IXGB_WRITE_REG(&adapter->hw, RDT, adapter->num_rx_desc - 1);
1963 reg_rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT
1964 | RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT
1965 | RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
1966 IXGB_WRITE_REG(&adapter->hw, RXDCTL, reg_rxdctl);
1970 if (adapter->raidc) {
1972 uint8_t poll_threshold;
1973 #define IXGB_RAIDC_POLL_DEFAULT 120
1975 poll_threshold = ((adapter->num_rx_desc - 1) >> 3);
1976 poll_threshold >>= 1;
1977 poll_threshold &= 0x3F;
1978 raidc = IXGB_RAIDC_EN | IXGB_RAIDC_RXT_GATE |
1979 (IXGB_RAIDC_POLL_DEFAULT << IXGB_RAIDC_POLL_SHIFT) |
1980 (adapter->rx_int_delay << IXGB_RAIDC_DELAY_SHIFT) |
1982 IXGB_WRITE_REG(&adapter->hw, RAIDC, raidc);
1984 /* Enable Receive Checksum Offload for TCP and UDP ? */
1985 if (ifp->if_capenable & IFCAP_RXCSUM) {
1986 reg_rxcsum = IXGB_READ_REG(&adapter->hw, RXCSUM);
1987 reg_rxcsum |= IXGB_RXCSUM_TUOFL;
1988 IXGB_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum);
1990 /* Setup the Receive Control Register */
1991 reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
1992 reg_rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
1993 reg_rctl |= IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | IXGB_RCTL_SECRC |
1995 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
1997 switch (adapter->rx_buffer_len) {
1999 case IXGB_RXBUFFER_2048:
2000 reg_rctl |= IXGB_RCTL_BSIZE_2048;
2002 case IXGB_RXBUFFER_4096:
2003 reg_rctl |= IXGB_RCTL_BSIZE_4096;
2005 case IXGB_RXBUFFER_8192:
2006 reg_rctl |= IXGB_RCTL_BSIZE_8192;
2008 case IXGB_RXBUFFER_16384:
2009 reg_rctl |= IXGB_RCTL_BSIZE_16384;
2013 reg_rctl |= IXGB_RCTL_RXEN;
2016 /* Enable Receives */
2017 IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
2022 /*********************************************************************
2024 * Free receive related data structures.
2026 **********************************************************************/
2028 ixgb_free_receive_structures(struct adapter * adapter)
2030 struct ixgb_buffer *rx_buffer;
2033 INIT_DEBUGOUT("free_receive_structures: begin");
2035 if (adapter->rx_buffer_area != NULL) {
2036 rx_buffer = adapter->rx_buffer_area;
2037 for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
2038 if (rx_buffer->map != NULL) {
2039 bus_dmamap_unload(adapter->rxtag, rx_buffer->map);
2040 bus_dmamap_destroy(adapter->rxtag, rx_buffer->map);
2042 if (rx_buffer->m_head != NULL)
2043 m_freem(rx_buffer->m_head);
2044 rx_buffer->m_head = NULL;
2047 if (adapter->rx_buffer_area != NULL) {
2048 free(adapter->rx_buffer_area, M_DEVBUF);
2049 adapter->rx_buffer_area = NULL;
2051 if (adapter->rxtag != NULL) {
2052 bus_dma_tag_destroy(adapter->rxtag);
2053 adapter->rxtag = NULL;
2058 /*********************************************************************
2060 * This routine executes in interrupt context. It replenishes
2061 * the mbufs in the descriptor and sends data which has been
2062 * dma'ed into host memory to upper layer.
2064 * We loop at most count times if count is > 0, or until done if
2067 *********************************************************************/
2069 ixgb_process_receive_interrupts(struct adapter * adapter, int count)
2073 #if __FreeBSD_version < 500000
2074 struct ether_header *eh;
2078 u_int8_t accept_frame = 0;
2080 int next_to_use = 0;
2082 /* Pointer to the receive descriptor being examined. */
2083 struct ixgb_rx_desc *current_desc;
2085 IXGB_LOCK_ASSERT(adapter);
2088 i = adapter->next_rx_desc_to_check;
2089 next_to_use = adapter->next_rx_desc_to_use;
2090 eop_desc = adapter->next_rx_desc_to_check;
2091 current_desc = &adapter->rx_desc_base[i];
2093 if (!((current_desc->status) & IXGB_RX_DESC_STATUS_DD)) {
2095 adapter->no_pkts_avail++;
2099 while ((current_desc->status & IXGB_RX_DESC_STATUS_DD) && (count != 0)) {
2101 mp = adapter->rx_buffer_area[i].m_head;
2102 bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map,
2103 BUS_DMASYNC_POSTREAD);
2105 if (current_desc->status & IXGB_RX_DESC_STATUS_EOP) {
2111 len = current_desc->length;
2113 if (current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
2114 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
2115 IXGB_RX_DESC_ERRORS_RXE)) {
2120 /* Assign correct length to the current fragment */
2123 if (adapter->fmp == NULL) {
2124 mp->m_pkthdr.len = len;
2125 adapter->fmp = mp; /* Store the first mbuf */
2128 /* Chain mbuf's together */
2129 mp->m_flags &= ~M_PKTHDR;
2130 adapter->lmp->m_next = mp;
2131 adapter->lmp = adapter->lmp->m_next;
2132 adapter->fmp->m_pkthdr.len += len;
2137 adapter->fmp->m_pkthdr.rcvif = ifp;
2139 #if __FreeBSD_version < 500000
2140 eh = mtod(adapter->fmp, struct ether_header *);
2142 /* Remove ethernet header from mbuf */
2143 m_adj(adapter->fmp, sizeof(struct ether_header));
2144 ixgb_receive_checksum(adapter, current_desc,
2147 if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
2148 VLAN_INPUT_TAG(eh, adapter->fmp,
2149 current_desc->special);
2151 ether_input(ifp, eh, adapter->fmp);
2153 ixgb_receive_checksum(adapter, current_desc,
2155 #if __FreeBSD_version < 700000
2156 if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
2157 VLAN_INPUT_TAG(ifp, adapter->fmp,
2158 current_desc->special);
2160 if (current_desc->status & IXGB_RX_DESC_STATUS_VP) {
2161 adapter->fmp->m_pkthdr.ether_vtag =
2162 current_desc->special;
2163 adapter->fmp->m_flags |= M_VLANTAG;
2167 if (adapter->fmp != NULL) {
2168 IXGB_UNLOCK(adapter);
2169 (*ifp->if_input) (ifp, adapter->fmp);
2173 adapter->fmp = NULL;
2174 adapter->lmp = NULL;
2176 adapter->rx_buffer_area[i].m_head = NULL;
2178 adapter->dropped_pkts++;
2179 if (adapter->fmp != NULL)
2180 m_freem(adapter->fmp);
2181 adapter->fmp = NULL;
2182 adapter->lmp = NULL;
2185 /* Zero out the receive descriptors status */
2186 current_desc->status = 0;
2188 /* Advance our pointers to the next descriptor */
2189 if (++i == adapter->num_rx_desc) {
2191 current_desc = adapter->rx_desc_base;
2195 adapter->next_rx_desc_to_check = i;
2198 i = (adapter->num_rx_desc - 1);
2201 * 82597EX: Workaround for redundent write back in receive descriptor ring (causes
2202 * memory corruption). Avoid using and re-submitting the most recently received RX
2203 * descriptor back to hardware.
2205 * if(Last written back descriptor == EOP bit set descriptor)
2206 * then avoid re-submitting the most recently received RX descriptor
2208 * if(Last written back descriptor != EOP bit set descriptor)
2209 * then avoid re-submitting the most recently received RX descriptors
2210 * till last EOP bit set descriptor.
2212 if (eop_desc != i) {
2213 if (++eop_desc == adapter->num_rx_desc)
2217 /* Replenish the descriptors with new mbufs till last EOP bit set descriptor */
2218 while (next_to_use != i) {
2219 current_desc = &adapter->rx_desc_base[next_to_use];
2220 if ((current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
2221 IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
2222 IXGB_RX_DESC_ERRORS_RXE))) {
2223 mp = adapter->rx_buffer_area[next_to_use].m_head;
2224 ixgb_get_buf(next_to_use, adapter, mp);
2226 if (ixgb_get_buf(next_to_use, adapter, NULL) == ENOBUFS)
2229 /* Advance our pointers to the next descriptor */
2230 if (++next_to_use == adapter->num_rx_desc) {
2232 current_desc = adapter->rx_desc_base;
2236 adapter->next_rx_desc_to_use = next_to_use;
2237 if (--next_to_use < 0)
2238 next_to_use = (adapter->num_rx_desc - 1);
2239 /* Advance the IXGB's Receive Queue #0 "Tail Pointer" */
2240 IXGB_WRITE_REG(&adapter->hw, RDT, next_to_use);
2245 /*********************************************************************
2247 * Verify that the hardware indicated that the checksum is valid.
2248 * Inform the stack about the status of checksum so that stack
2249 * doesn't spend time verifying the checksum.
2251 *********************************************************************/
2253 ixgb_receive_checksum(struct adapter * adapter,
2254 struct ixgb_rx_desc * rx_desc,
2257 if (rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) {
2258 mp->m_pkthdr.csum_flags = 0;
2261 if (rx_desc->status & IXGB_RX_DESC_STATUS_IPCS) {
2263 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_IPE)) {
2264 /* IP Checksum Good */
2265 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
2266 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2269 mp->m_pkthdr.csum_flags = 0;
2272 if (rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS) {
2274 if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE)) {
2275 mp->m_pkthdr.csum_flags |=
2276 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
2277 mp->m_pkthdr.csum_data = htons(0xffff);
2285 ixgb_enable_vlans(struct adapter * adapter)
2289 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2290 ctrl |= IXGB_CTRL0_VME;
2291 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2298 ixgb_enable_intr(struct adapter * adapter)
2300 IXGB_WRITE_REG(&adapter->hw, IMS, (IXGB_INT_RXT0 | IXGB_INT_TXDW |
2301 IXGB_INT_RXDMT0 | IXGB_INT_LSC | IXGB_INT_RXO));
2306 ixgb_disable_intr(struct adapter * adapter)
2308 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
2313 ixgb_write_pci_cfg(struct ixgb_hw * hw,
2317 pci_write_config(((struct ixgb_osdep *) hw->back)->dev, reg,
2321 /**********************************************************************
2323 * Update the board statistics counters.
2325 **********************************************************************/
2327 ixgb_update_stats_counters(struct adapter * adapter)
2331 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
2332 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
2333 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
2334 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
2335 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
2336 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
2337 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
2338 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
2339 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
2340 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
2342 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
2343 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
2344 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
2345 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
2346 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
2347 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
2348 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
2349 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
2350 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
2351 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
2352 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
2353 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
2354 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
2355 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
2356 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
2357 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
2358 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
2359 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
2360 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
2361 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
2362 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
2363 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
2364 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
2365 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
2366 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
2367 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
2368 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
2370 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
2371 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
2372 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
2373 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
2374 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
2375 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
2376 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
2377 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
2378 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
2379 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
2380 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
2381 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
2382 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
2383 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
2384 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
2385 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
2386 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
2387 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
2388 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
2389 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
2390 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
2391 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
2395 /* Fill out the OS statistics structure */
2396 ifp->if_ipackets = adapter->stats.gprcl;
2397 ifp->if_opackets = adapter->stats.gptcl;
2398 ifp->if_ibytes = adapter->stats.gorcl;
2399 ifp->if_obytes = adapter->stats.gotcl;
2400 ifp->if_imcasts = adapter->stats.mprcl;
2401 ifp->if_collisions = 0;
2405 adapter->dropped_pkts +
2406 adapter->stats.crcerrs +
2407 adapter->stats.rnbc +
2408 adapter->stats.mpc +
2409 adapter->stats.rlec;
2415 /**********************************************************************
2417 * This routine is called only when ixgb_display_debug_stats is enabled.
2418 * This routine provides a way to take a look at important statistics
2419 * maintained by the driver and hardware.
2421 **********************************************************************/
2423 ixgb_print_hw_stats(struct adapter * adapter)
2425 char buf_speed[100], buf_type[100];
2426 ixgb_bus_speed bus_speed;
2427 ixgb_bus_type bus_type;
2428 int unit = adapter->unit;
2431 printf("ixgb%d: Packets not Avail = %ld\n", unit,
2432 adapter->no_pkts_avail);
2433 printf("ixgb%d: CleanTxInterrupts = %ld\n", unit,
2434 adapter->clean_tx_interrupts);
2435 printf("ixgb%d: ICR RXDMT0 = %lld\n", unit,
2436 (long long)adapter->sv_stats.icr_rxdmt0);
2437 printf("ixgb%d: ICR RXO = %lld\n", unit,
2438 (long long)adapter->sv_stats.icr_rxo);
2439 printf("ixgb%d: ICR RXT0 = %lld\n", unit,
2440 (long long)adapter->sv_stats.icr_rxt0);
2441 printf("ixgb%d: ICR TXDW = %lld\n", unit,
2442 (long long)adapter->sv_stats.icr_TXDW);
2445 bus_speed = adapter->hw.bus.speed;
2446 bus_type = adapter->hw.bus.type;
2448 bus_speed == ixgb_bus_speed_33 ? "33MHz" :
2449 bus_speed == ixgb_bus_speed_66 ? "66MHz" :
2450 bus_speed == ixgb_bus_speed_100 ? "100MHz" :
2451 bus_speed == ixgb_bus_speed_133 ? "133MHz" :
2453 printf("ixgb%d: PCI_Bus_Speed = %s\n", unit,
2457 bus_type == ixgb_bus_type_pci ? "PCI" :
2458 bus_type == ixgb_bus_type_pcix ? "PCI-X" :
2460 printf("ixgb%d: PCI_Bus_Type = %s\n", unit,
2463 printf("ixgb%d: Tx Descriptors not Avail1 = %ld\n", unit,
2464 adapter->no_tx_desc_avail1);
2465 printf("ixgb%d: Tx Descriptors not Avail2 = %ld\n", unit,
2466 adapter->no_tx_desc_avail2);
2467 printf("ixgb%d: Std Mbuf Failed = %ld\n", unit,
2468 adapter->mbuf_alloc_failed);
2469 printf("ixgb%d: Std Cluster Failed = %ld\n", unit,
2470 adapter->mbuf_cluster_failed);
2472 printf("ixgb%d: Defer count = %lld\n", unit,
2473 (long long)adapter->stats.dc);
2474 printf("ixgb%d: Missed Packets = %lld\n", unit,
2475 (long long)adapter->stats.mpc);
2476 printf("ixgb%d: Receive No Buffers = %lld\n", unit,
2477 (long long)adapter->stats.rnbc);
2478 printf("ixgb%d: Receive length errors = %lld\n", unit,
2479 (long long)adapter->stats.rlec);
2480 printf("ixgb%d: Crc errors = %lld\n", unit,
2481 (long long)adapter->stats.crcerrs);
2482 printf("ixgb%d: Driver dropped packets = %ld\n", unit,
2483 adapter->dropped_pkts);
2485 printf("ixgb%d: XON Rcvd = %lld\n", unit,
2486 (long long)adapter->stats.xonrxc);
2487 printf("ixgb%d: XON Xmtd = %lld\n", unit,
2488 (long long)adapter->stats.xontxc);
2489 printf("ixgb%d: XOFF Rcvd = %lld\n", unit,
2490 (long long)adapter->stats.xoffrxc);
2491 printf("ixgb%d: XOFF Xmtd = %lld\n", unit,
2492 (long long)adapter->stats.xofftxc);
2494 printf("ixgb%d: Good Packets Rcvd = %lld\n", unit,
2495 (long long)adapter->stats.gprcl);
2496 printf("ixgb%d: Good Packets Xmtd = %lld\n", unit,
2497 (long long)adapter->stats.gptcl);
2499 printf("ixgb%d: Jumbo frames recvd = %lld\n", unit,
2500 (long long)adapter->stats.jprcl);
2501 printf("ixgb%d: Jumbo frames Xmtd = %lld\n", unit,
2502 (long long)adapter->stats.jptcl);
2509 ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS)
2513 struct adapter *adapter;
2516 error = sysctl_handle_int(oidp, &result, 0, req);
2518 if (error || !req->newptr)
2522 adapter = (struct adapter *) arg1;
2523 ixgb_print_hw_stats(adapter);