1 /**************************************************************************
3 * Copyright (C) 2000-2008 Alacritech, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as representing
31 * official policies, either expressed or implied, of Alacritech, Inc.
33 * Parts developed by LinSysSoft Sahara team
35 **************************************************************************/
40 * The SXG driver for Alacritech's 10Gbe products.
42 * NOTE: This is the standard, non-accelerated version of Alacritech's
46 #include <linux/kernel.h>
47 #include <linux/string.h>
48 #include <linux/errno.h>
49 #include <linux/module.h>
50 #include <linux/moduleparam.h>
51 #include <linux/ioport.h>
52 #include <linux/slab.h>
53 #include <linux/interrupt.h>
54 #include <linux/timer.h>
55 #include <linux/pci.h>
56 #include <linux/spinlock.h>
57 #include <linux/init.h>
58 #include <linux/netdevice.h>
59 #include <linux/etherdevice.h>
60 #include <linux/ethtool.h>
61 #include <linux/skbuff.h>
62 #include <linux/delay.h>
63 #include <linux/types.h>
64 #include <linux/dma-mapping.h>
65 #include <linux/mii.h>
68 #include <linux/tcp.h>
69 #include <linux/ipv6.h>
71 #define SLIC_GET_STATS_ENABLED 0
72 #define LINUX_FREES_ADAPTER_RESOURCES 1
73 #define SXG_OFFLOAD_IP_CHECKSUM 0
74 #define SXG_POWER_MANAGEMENT_ENABLED 0
84 #include "sxgphycode-1.2.h"
85 #define SXG_UCODE_DBG 0 /* Turn on for debugging */
87 #include "saharadbgdownload-1.71.c"
88 #include "saharadbgdownloadB-1.10.c"
90 #include "saharadownload-1.55.c"
91 #include "saharadownloadB-1.8.c"
94 static int sxg_allocate_buffer_memory(struct adapter_t *adapter, u32 Size,
95 enum sxg_buffer_type BufferType);
96 static int sxg_allocate_rcvblock_complete(struct adapter_t *adapter,
98 dma_addr_t PhysicalAddress,
100 static void sxg_allocate_sgl_buffer_complete(struct adapter_t *adapter,
101 struct sxg_scatter_gather *SxgSgl,
102 dma_addr_t PhysicalAddress,
105 static void sxg_mcast_init_crc32(void);
106 static int sxg_entry_open(struct net_device *dev);
107 static int sxg_second_open(struct net_device * dev);
108 static int sxg_entry_halt(struct net_device *dev);
109 static int sxg_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
110 static int sxg_send_packets(struct sk_buff *skb, struct net_device *dev);
111 static int sxg_transmit_packet(struct adapter_t *adapter, struct sk_buff *skb);
112 static int sxg_dumb_sgl(struct sxg_x64_sgl *pSgl,
113 struct sxg_scatter_gather *SxgSgl);
115 static void sxg_handle_interrupt(struct adapter_t *adapter, int *work_done,
117 static void sxg_interrupt(struct adapter_t *adapter);
118 static int sxg_poll(struct napi_struct *napi, int budget);
119 static int sxg_process_isr(struct adapter_t *adapter, u32 MessageId);
120 static u32 sxg_process_event_queue(struct adapter_t *adapter, u32 RssId,
121 int *sxg_napi_continue, int *work_done, int budget);
122 static void sxg_complete_slow_send(struct adapter_t *adapter);
123 static struct sk_buff *sxg_slow_receive(struct adapter_t *adapter,
124 struct sxg_event *Event);
125 static void sxg_process_rcv_error(struct adapter_t *adapter, u32 ErrorStatus);
126 static bool sxg_mac_filter(struct adapter_t *adapter,
127 struct ether_header *EtherHdr, ushort length);
128 static struct net_device_stats *sxg_get_stats(struct net_device * dev);
129 void sxg_free_resources(struct adapter_t *adapter);
130 void sxg_free_rcvblocks(struct adapter_t *adapter);
131 void sxg_free_sgl_buffers(struct adapter_t *adapter);
132 void sxg_unmap_resources(struct adapter_t *adapter);
133 void sxg_free_mcast_addrs(struct adapter_t *adapter);
134 void sxg_collect_statistics(struct adapter_t *adapter);
135 static int sxg_register_interrupt(struct adapter_t *adapter);
136 static void sxg_remove_isr(struct adapter_t *adapter);
137 static irqreturn_t sxg_isr(int irq, void *dev_id);
139 static void sxg_watchdog(unsigned long data);
140 static void sxg_update_link_status (struct work_struct *work);
145 static int sxg_mac_set_address(struct net_device *dev, void *ptr);
147 static void sxg_mcast_set_list(struct net_device *dev);
149 static int sxg_adapter_set_hwaddr(struct adapter_t *adapter);
151 static int sxg_initialize_adapter(struct adapter_t *adapter);
152 static void sxg_stock_rcv_buffers(struct adapter_t *adapter);
153 static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
154 unsigned char Index);
155 int sxg_change_mtu (struct net_device *netdev, int new_mtu);
156 static int sxg_initialize_link(struct adapter_t *adapter);
157 static int sxg_phy_init(struct adapter_t *adapter);
158 static void sxg_link_event(struct adapter_t *adapter);
159 static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter);
160 static void sxg_link_state(struct adapter_t *adapter,
161 enum SXG_LINK_STATE LinkState);
162 static int sxg_write_mdio_reg(struct adapter_t *adapter,
163 u32 DevAddr, u32 RegAddr, u32 Value);
164 static int sxg_read_mdio_reg(struct adapter_t *adapter,
165 u32 DevAddr, u32 RegAddr, u32 *pValue);
166 static void sxg_set_mcast_addr(struct adapter_t *adapter);
168 static unsigned int sxg_first_init = 1;
169 static char *sxg_banner =
170 "Alacritech SLIC Technology(tm) Server and Storage \
171 10Gbe Accelerator (Non-Accelerated)\n";
173 static int sxg_debug = 1;
174 static int debug = -1;
175 static struct net_device *head_netdevice = NULL;
177 static struct sxgbase_driver sxg_global = {
180 static int intagg_delay = 100;
181 static u32 dynamic_intagg = 0;
183 char sxg_driver_name[] = "sxg_nic";
184 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
185 #define DRV_DESCRIPTION \
186 "Alacritech SLIC Techonology(tm) Non-Accelerated 10Gbe Driver"
187 #define DRV_COPYRIGHT \
188 "Copyright 2000-2008 Alacritech, Inc. All rights reserved."
190 MODULE_AUTHOR(DRV_AUTHOR);
191 MODULE_DESCRIPTION(DRV_DESCRIPTION);
192 MODULE_LICENSE("GPL");
194 module_param(dynamic_intagg, int, 0);
195 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
196 module_param(intagg_delay, int, 0);
197 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
199 static struct pci_device_id sxg_pci_tbl[] __devinitdata = {
200 {PCI_DEVICE(SXG_VENDOR_ID, SXG_DEVICE_ID)},
204 MODULE_DEVICE_TABLE(pci, sxg_pci_tbl);
206 static inline void sxg_reg32_write(void __iomem *reg, u32 value, bool flush)
213 static inline void sxg_reg64_write(struct adapter_t *adapter, void __iomem *reg,
216 u32 value_high = (u32) (value >> 32);
217 u32 value_low = (u32) (value & 0x00000000FFFFFFFF);
220 spin_lock_irqsave(&adapter->Bit64RegLock, flags);
221 writel(value_high, (void __iomem *)(&adapter->UcodeRegs[cpu].Upper));
222 writel(value_low, reg);
223 spin_unlock_irqrestore(&adapter->Bit64RegLock, flags);
226 static void sxg_init_driver(void)
228 if (sxg_first_init) {
229 DBG_ERROR("sxg: %s sxg_first_init set jiffies[%lx]\n",
232 spin_lock_init(&sxg_global.driver_lock);
236 static void sxg_dbg_macaddrs(struct adapter_t *adapter)
238 DBG_ERROR(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
239 adapter->netdev->name, adapter->currmacaddr[0],
240 adapter->currmacaddr[1], adapter->currmacaddr[2],
241 adapter->currmacaddr[3], adapter->currmacaddr[4],
242 adapter->currmacaddr[5]);
243 DBG_ERROR(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
244 adapter->netdev->name, adapter->macaddr[0],
245 adapter->macaddr[1], adapter->macaddr[2],
246 adapter->macaddr[3], adapter->macaddr[4],
247 adapter->macaddr[5]);
252 static struct sxg_driver SxgDriver;
255 static struct sxg_trace_buffer LSxgTraceBuffer;
257 static struct sxg_trace_buffer *SxgTraceBuffer = NULL;
262 int sxg_register_intr(struct adapter_t *adapter);
263 int sxg_enable_msi_x(struct adapter_t *adapter);
264 int sxg_add_msi_isr(struct adapter_t *adapter);
265 void sxg_remove_msix_isr(struct adapter_t *adapter);
266 int sxg_set_interrupt_capability(struct adapter_t *adapter);
268 int sxg_set_interrupt_capability(struct adapter_t *adapter)
272 ret = sxg_enable_msi_x(adapter);
273 if (ret != STATUS_SUCCESS) {
274 adapter->msi_enabled = FALSE;
275 DBG_ERROR("sxg_set_interrupt_capability MSI-X Disable\n");
277 adapter->msi_enabled = TRUE;
278 DBG_ERROR("sxg_set_interrupt_capability MSI-X Enable\n");
283 int sxg_register_intr(struct adapter_t *adapter)
287 if (adapter->msi_enabled) {
288 ret = sxg_add_msi_isr(adapter);
291 DBG_ERROR("MSI-X Enable Failed. Using Pin INT\n");
292 ret = sxg_register_interrupt(adapter);
293 if (ret != STATUS_SUCCESS) {
294 DBG_ERROR("sxg_register_interrupt Failed\n");
300 int sxg_enable_msi_x(struct adapter_t *adapter)
304 adapter->nr_msix_entries = 1;
305 adapter->msi_entries = kmalloc(adapter->nr_msix_entries *
306 sizeof(struct msix_entry),GFP_KERNEL);
307 if (!adapter->msi_entries) {
308 DBG_ERROR("%s:MSI Entries memory allocation Failed\n",__func__);
311 memset(adapter->msi_entries, 0, adapter->nr_msix_entries *
312 sizeof(struct msix_entry));
314 ret = pci_enable_msix(adapter->pcidev, adapter->msi_entries,
315 adapter->nr_msix_entries);
317 DBG_ERROR("Enabling MSI-X with %d vectors failed\n",
318 adapter->nr_msix_entries);
319 /*Should try with less vector returned.*/
320 kfree(adapter->msi_entries);
321 return STATUS_FAILURE; /*MSI-X Enable failed.*/
323 return (STATUS_SUCCESS);
326 int sxg_add_msi_isr(struct adapter_t *adapter)
330 if (!adapter->intrregistered) {
331 for (i=0; i<adapter->nr_msix_entries; i++) {
332 ret = request_irq (adapter->msi_entries[i].vector,
335 adapter->netdev->name,
338 DBG_ERROR("sxg: MSI-X request_irq (%s) "
339 "FAILED [%x]\n", adapter->netdev->name,
345 adapter->msi_enabled = TRUE;
346 adapter->intrregistered = 1;
347 adapter->IntRegistered = TRUE;
348 return (STATUS_SUCCESS);
351 void sxg_remove_msix_isr(struct adapter_t *adapter)
354 struct net_device *netdev = adapter->netdev;
356 for(i=0; i< adapter->nr_msix_entries;i++)
358 vector = adapter->msi_entries[i].vector;
359 DBG_ERROR("%s : Freeing IRQ vector#%d\n",__FUNCTION__,vector);
360 free_irq(vector,netdev);
365 static void sxg_remove_isr(struct adapter_t *adapter)
367 struct net_device *netdev = adapter->netdev;
368 if (adapter->msi_enabled)
369 sxg_remove_msix_isr(adapter);
371 free_irq(adapter->netdev->irq, netdev);
374 void sxg_reset_interrupt_capability(struct adapter_t *adapter)
376 if (adapter->msi_enabled) {
377 pci_disable_msix(adapter->pcidev);
378 kfree(adapter->msi_entries);
379 adapter->msi_entries = NULL;
385 * sxg_download_microcode
387 * Download Microcode to Sahara adapter
390 * adapter - A pointer to our adapter structure
391 * UcodeSel - microcode file selection
396 static bool sxg_download_microcode(struct adapter_t *adapter,
397 enum SXG_UCODE_SEL UcodeSel)
399 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
402 u32 *Instruction = NULL;
403 u32 BaseAddress, AddressOffset, Address;
409 u32 sectionStart[16];
411 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DnldUcod",
413 DBG_ERROR("sxg: %s ENTER\n", __func__);
416 case SXG_UCODE_SYSTEM: // System (operational) ucode
417 switch (adapter->asictype) {
419 DBG_ERROR("%s SAHARA CARD REVISION A\n",
421 numSections = SNumSections;
422 for (i = 0; i < numSections; i++) {
430 DBG_ERROR("%s SAHARA CARD REVISION B\n",
432 numSections = SBNumSections;
433 for (i = 0; i < numSections; i++) {
443 printk(KERN_ERR KBUILD_MODNAME
444 ": Woah, big error with the microcode!\n");
448 DBG_ERROR("sxg: RESET THE CARD\n");
449 /* First, reset the card */
450 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
454 * Download each section of the microcode as specified in
455 * its download file. The *download.c file is generated using
456 * the saharaobjtoc facility which converts the metastep .obj
457 * file to a .c file which contains a two dimentional array.
459 for (Section = 0; Section < numSections; Section++) {
460 DBG_ERROR("sxg: SECTION # %d\n", Section);
462 case SXG_UCODE_SYSTEM:
463 switch (adapter->asictype) {
465 Instruction = (u32 *) & SaharaUCode[Section][0];
468 Instruction = (u32 *) & SaharaUCodeB[Section][0];
477 BaseAddress = sectionStart[Section];
478 /* Size in instructions */
479 ThisSectionSize = sectionSize[Section] / 12;
480 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
482 Address = BaseAddress + AddressOffset;
483 ASSERT((Address & ~MICROCODE_ADDRESS_MASK) == 0);
484 /* Write instruction bits 31 - 0 */
485 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, FLUSH);
486 /* Write instruction bits 63-32 */
487 WRITE_REG(HwRegs->UcodeDataMiddle, *(Instruction + 1),
489 /* Write instruction bits 95-64 */
490 WRITE_REG(HwRegs->UcodeDataHigh, *(Instruction + 2),
492 /* Write instruction address with the WRITE bit set */
493 WRITE_REG(HwRegs->UcodeAddr,
494 (Address | MICROCODE_ADDRESS_WRITE), FLUSH);
496 * Sahara bug in the ucode download logic - the write to DataLow
497 * for the next instruction could get corrupted. To avoid this,
498 * write to DataLow again for this instruction (which may get
499 * corrupted, but it doesn't matter), then increment the address
500 * and write the data for the next instruction to DataLow. That
501 * write should succeed.
503 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, TRUE);
504 /* Advance 3 u32S to start of next instruction */
509 * Now repeat the entire operation reading the instruction back and
510 * checking for parity errors
512 for (Section = 0; Section < numSections; Section++) {
513 DBG_ERROR("sxg: check SECTION # %d\n", Section);
515 case SXG_UCODE_SYSTEM:
516 switch (adapter->asictype) {
518 Instruction = (u32 *) &
519 SaharaUCode[Section][0];
522 Instruction = (u32 *) &
523 SaharaUCodeB[Section][0];
531 BaseAddress = sectionStart[Section];
532 /* Size in instructions */
533 ThisSectionSize = sectionSize[Section] / 12;
534 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
536 Address = BaseAddress + AddressOffset;
537 /* Write the address with the READ bit set */
538 WRITE_REG(HwRegs->UcodeAddr,
539 (Address | MICROCODE_ADDRESS_READ), FLUSH);
540 /* Read it back and check parity bit. */
541 READ_REG(HwRegs->UcodeAddr, ValueRead);
542 if (ValueRead & MICROCODE_ADDRESS_PARITY) {
543 DBG_ERROR("sxg: %s PARITY ERROR\n",
546 return FALSE; /* Parity error */
548 ASSERT((ValueRead & MICROCODE_ADDRESS_MASK) == Address);
549 /* Read the instruction back and compare */
550 READ_REG(HwRegs->UcodeDataLow, ValueRead);
551 if (ValueRead != *Instruction) {
552 DBG_ERROR("sxg: %s MISCOMPARE LOW\n",
554 return FALSE; /* Miscompare */
556 READ_REG(HwRegs->UcodeDataMiddle, ValueRead);
557 if (ValueRead != *(Instruction + 1)) {
558 DBG_ERROR("sxg: %s MISCOMPARE MIDDLE\n",
560 return FALSE; /* Miscompare */
562 READ_REG(HwRegs->UcodeDataHigh, ValueRead);
563 if (ValueRead != *(Instruction + 2)) {
564 DBG_ERROR("sxg: %s MISCOMPARE HIGH\n",
566 return FALSE; /* Miscompare */
568 /* Advance 3 u32S to start of next instruction */
573 /* Everything OK, Go. */
574 WRITE_REG(HwRegs->UcodeAddr, MICROCODE_ADDRESS_GO, FLUSH);
577 * Poll the CardUp register to wait for microcode to initialize
578 * Give up after 10,000 attemps (500ms).
580 for (i = 0; i < 10000; i++) {
582 READ_REG(adapter->UcodeRegs[0].CardUp, ValueRead);
583 if (ValueRead == 0xCAFE) {
584 DBG_ERROR("sxg: %s BOO YA 0xCAFE\n", __func__);
589 DBG_ERROR("sxg: %s TIMEOUT\n", __func__);
591 return FALSE; /* Timeout */
594 * Now write the LoadSync register. This is used to
595 * synchronize with the card so it can scribble on the memory
596 * that contained 0xCAFE from the "CardUp" step above
598 if (UcodeSel == SXG_UCODE_SYSTEM) {
599 WRITE_REG(adapter->UcodeRegs[0].LoadSync, 0, FLUSH);
602 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDnldUcd",
604 DBG_ERROR("sxg: %s EXIT\n", __func__);
610 * sxg_allocate_resources - Allocate memory and locks
613 * adapter - A pointer to our adapter structure
617 static int sxg_allocate_resources(struct adapter_t *adapter)
619 int status = STATUS_SUCCESS;
620 u32 RssIds, IsrCount;
621 /* struct sxg_xmt_ring *XmtRing; */
622 /* struct sxg_rcv_ring *RcvRing; */
624 DBG_ERROR("%s ENTER\n", __func__);
626 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocRes",
629 /* Windows tells us how many CPUs it plans to use for */
631 RssIds = SXG_RSS_CPU_COUNT(adapter);
632 IsrCount = adapter->msi_enabled ? RssIds : 1;
634 DBG_ERROR("%s Setup the spinlocks\n", __func__);
636 /* Allocate spinlocks and initialize listheads first. */
637 spin_lock_init(&adapter->RcvQLock);
638 spin_lock_init(&adapter->SglQLock);
639 spin_lock_init(&adapter->XmtZeroLock);
640 spin_lock_init(&adapter->Bit64RegLock);
641 spin_lock_init(&adapter->AdapterLock);
642 atomic_set(&adapter->pending_allocations, 0);
644 DBG_ERROR("%s Setup the lists\n", __func__);
646 InitializeListHead(&adapter->FreeRcvBuffers);
647 InitializeListHead(&adapter->FreeRcvBlocks);
648 InitializeListHead(&adapter->AllRcvBlocks);
649 InitializeListHead(&adapter->FreeSglBuffers);
650 InitializeListHead(&adapter->AllSglBuffers);
653 * Mark these basic allocations done. This flags essentially
654 * tells the SxgFreeResources routine that it can grab spinlocks
655 * and reference listheads.
657 adapter->BasicAllocations = TRUE;
659 * Main allocation loop. Start with the maximum supported by
660 * the microcode and back off if memory allocation
661 * fails. If we hit a minimum, fail.
665 DBG_ERROR("%s Allocate XmtRings size[%x]\n", __func__,
666 (unsigned int)(sizeof(struct sxg_xmt_ring) * 1));
669 * Start with big items first - receive and transmit rings.
670 * At the moment I'm going to keep the ring size fixed and
671 * adjust the TCBs if we fail. Later we might
672 * consider reducing the ring size as well..
674 adapter->XmtRings = pci_alloc_consistent(adapter->pcidev,
675 sizeof(struct sxg_xmt_ring) *
677 &adapter->PXmtRings);
678 DBG_ERROR("%s XmtRings[%p]\n", __func__, adapter->XmtRings);
680 if (!adapter->XmtRings) {
681 goto per_tcb_allocation_failed;
683 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
685 DBG_ERROR("%s Allocate RcvRings size[%x]\n", __func__,
686 (unsigned int)(sizeof(struct sxg_rcv_ring) * 1));
688 pci_alloc_consistent(adapter->pcidev,
689 sizeof(struct sxg_rcv_ring) * 1,
690 &adapter->PRcvRings);
691 DBG_ERROR("%s RcvRings[%p]\n", __func__, adapter->RcvRings);
692 if (!adapter->RcvRings) {
693 goto per_tcb_allocation_failed;
695 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
696 adapter->ucode_stats = kzalloc(sizeof(struct sxg_ucode_stats), GFP_ATOMIC);
697 adapter->pucode_stats = pci_map_single(adapter->pcidev,
698 adapter->ucode_stats,
699 sizeof(struct sxg_ucode_stats),
701 // memset(adapter->ucode_stats, 0, sizeof(struct sxg_ucode_stats));
704 per_tcb_allocation_failed:
705 /* an allocation failed. Free any successful allocations. */
706 if (adapter->XmtRings) {
707 pci_free_consistent(adapter->pcidev,
708 sizeof(struct sxg_xmt_ring) * 1,
711 adapter->XmtRings = NULL;
713 if (adapter->RcvRings) {
714 pci_free_consistent(adapter->pcidev,
715 sizeof(struct sxg_rcv_ring) * 1,
718 adapter->RcvRings = NULL;
720 /* Loop around and try again.... */
721 if (adapter->ucode_stats) {
722 pci_unmap_single(adapter->pcidev,
723 sizeof(struct sxg_ucode_stats),
724 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
725 adapter->ucode_stats = NULL;
730 DBG_ERROR("%s Initialize RCV ZERO and XMT ZERO rings\n", __func__);
731 /* Initialize rcv zero and xmt zero rings */
732 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
733 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
735 /* Sanity check receive data structure format */
736 /* ASSERT((adapter->ReceiveBufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
737 (adapter->ReceiveBufferSize == SXG_RCV_JUMBO_BUFFER_SIZE)); */
738 ASSERT(sizeof(struct sxg_rcv_descriptor_block) ==
739 SXG_RCV_DESCRIPTOR_BLOCK_SIZE);
741 DBG_ERROR("%s Allocate EventRings size[%x]\n", __func__,
742 (unsigned int)(sizeof(struct sxg_event_ring) * RssIds));
744 /* Allocate event queues. */
745 adapter->EventRings = pci_alloc_consistent(adapter->pcidev,
746 sizeof(struct sxg_event_ring) *
748 &adapter->PEventRings);
750 if (!adapter->EventRings) {
751 /* Caller will call SxgFreeAdapter to clean up above
753 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF8",
754 adapter, SXG_MAX_ENTRIES, 0, 0);
755 status = STATUS_RESOURCES;
756 goto per_tcb_allocation_failed;
758 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
760 DBG_ERROR("%s Allocate ISR size[%x]\n", __func__, IsrCount);
762 adapter->Isr = pci_alloc_consistent(adapter->pcidev,
763 IsrCount, &adapter->PIsr);
765 /* Caller will call SxgFreeAdapter to clean up above
767 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF9",
768 adapter, SXG_MAX_ENTRIES, 0, 0);
769 status = STATUS_RESOURCES;
770 goto per_tcb_allocation_failed;
772 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
774 DBG_ERROR("%s Allocate shared XMT ring zero index location size[%x]\n",
775 __func__, (unsigned int)sizeof(u32));
777 /* Allocate shared XMT ring zero index location */
778 adapter->XmtRingZeroIndex = pci_alloc_consistent(adapter->pcidev,
782 if (!adapter->XmtRingZeroIndex) {
783 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF10",
784 adapter, SXG_MAX_ENTRIES, 0, 0);
785 status = STATUS_RESOURCES;
786 goto per_tcb_allocation_failed;
788 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
790 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlcResS",
791 adapter, SXG_MAX_ENTRIES, 0, 0);
799 * Set up PCI Configuration space
802 * pcidev - A pointer to our adapter structure
804 static void sxg_config_pci(struct pci_dev *pcidev)
809 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
810 DBG_ERROR("sxg: %s PCI command[%4.4x]\n", __func__, pci_command);
811 /* Set the command register */
812 new_command = pci_command | (
813 /* Memory Space Enable */
815 /* Bus master enable */
817 /* Memory write and invalidate */
818 PCI_COMMAND_INVALIDATE |
819 /* Parity error response */
823 /* Fast back-to-back */
824 PCI_COMMAND_FAST_BACK);
825 if (pci_command != new_command) {
826 DBG_ERROR("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
827 __func__, pci_command, new_command);
828 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
834 * @adapter : Pointer to the adapter structure for the card
835 * This function will read the configuration data from EEPROM/FLASH
837 static inline int sxg_read_config(struct adapter_t *adapter)
839 /* struct sxg_config data; */
840 struct sxg_config *config;
841 struct sw_cfg_data *data;
843 unsigned long status;
845 config = pci_alloc_consistent(adapter->pcidev,
846 sizeof(struct sxg_config), &p_addr);
850 * We cant get even this much memory. Raise a hell
853 printk(KERN_ERR"%s : Could not allocate memory for reading \
854 EEPROM\n", __FUNCTION__);
858 data = &config->SwCfg;
860 /* Initialize (reflective memory) status register */
861 WRITE_REG(adapter->UcodeRegs[0].ConfigStat, SXG_CFG_TIMEOUT, TRUE);
863 /* Send request to fetch configuration data */
864 WRITE_REG64(adapter, adapter->UcodeRegs[0].Config, p_addr, 0);
865 for(i=0; i<1000; i++) {
866 READ_REG(adapter->UcodeRegs[0].ConfigStat, status);
867 if (status != SXG_CFG_TIMEOUT)
869 mdelay(1); /* Do we really need this */
873 /* Config read from EEPROM succeeded */
874 case SXG_CFG_LOAD_EEPROM:
875 /* Config read from Flash succeeded */
876 case SXG_CFG_LOAD_FLASH:
878 * Copy the MAC address to adapter structure
879 * TODO: We are not doing the remaining part : FRU, etc
881 memcpy(adapter->macaddr, data->MacAddr[0].MacAddr,
882 sizeof(struct sxg_config_mac));
884 case SXG_CFG_TIMEOUT:
885 case SXG_CFG_LOAD_INVALID:
886 case SXG_CFG_LOAD_ERROR:
887 default: /* Fix default handler later */
888 printk(KERN_WARNING"%s : We could not read the config \
889 word. Status = %ld\n", __FUNCTION__, status);
892 pci_free_consistent(adapter->pcidev, sizeof(struct sw_cfg_data), data,
894 if (adapter->netdev) {
895 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
896 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
898 sxg_dbg_macaddrs(adapter);
903 static int sxg_entry_probe(struct pci_dev *pcidev,
904 const struct pci_device_id *pci_tbl_entry)
906 static int did_version = 0;
908 struct net_device *netdev;
909 struct adapter_t *adapter;
910 void __iomem *memmapped_ioaddr;
912 ulong mmio_start = 0;
914 unsigned char revision_id;
916 DBG_ERROR("sxg: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
917 __func__, jiffies, smp_processor_id());
919 /* Initialize trace buffer */
921 SxgTraceBuffer = &LSxgTraceBuffer;
922 SXG_TRACE_INIT(SxgTraceBuffer, TRACE_NOISY);
925 sxg_global.dynamic_intagg = dynamic_intagg;
927 err = pci_enable_device(pcidev);
929 DBG_ERROR("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
934 if (sxg_debug > 0 && did_version++ == 0) {
935 printk(KERN_INFO "%s\n", sxg_banner);
936 printk(KERN_INFO "%s\n", SXG_DRV_VERSION);
939 pci_read_config_byte(pcidev, PCI_REVISION_ID, &revision_id);
941 if (!(err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK))) {
942 DBG_ERROR("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
944 if ((err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK))) {
946 ("No usable DMA configuration, aborting err[%x]\n",
950 DBG_ERROR("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
953 DBG_ERROR("Call pci_request_regions\n");
955 err = pci_request_regions(pcidev, sxg_driver_name);
957 DBG_ERROR("pci_request_regions FAILED err[%x]\n", err);
961 DBG_ERROR("call pci_set_master\n");
962 pci_set_master(pcidev);
964 DBG_ERROR("call alloc_etherdev\n");
965 netdev = alloc_etherdev(sizeof(struct adapter_t));
968 goto err_out_exit_sxg_probe;
970 DBG_ERROR("alloc_etherdev for slic netdev[%p]\n", netdev);
972 SET_NETDEV_DEV(netdev, &pcidev->dev);
974 pci_set_drvdata(pcidev, netdev);
975 adapter = netdev_priv(netdev);
976 if (revision_id == 1) {
977 adapter->asictype = SAHARA_REV_A;
978 } else if (revision_id == 2) {
979 adapter->asictype = SAHARA_REV_B;
982 DBG_ERROR("%s Unexpected revision ID %x\n", __FUNCTION__, revision_id);
983 goto err_out_exit_sxg_probe;
985 adapter->netdev = netdev;
986 adapter->pcidev = pcidev;
988 mmio_start = pci_resource_start(pcidev, 0);
989 mmio_len = pci_resource_len(pcidev, 0);
991 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
992 mmio_start, mmio_len);
994 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
995 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
997 if (!memmapped_ioaddr) {
998 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
999 __func__, mmio_len, mmio_start);
1000 goto err_out_free_mmio_region_0;
1003 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, start[%lx] \
1004 len[%lx], IRQ %d.\n", __func__, memmapped_ioaddr, mmio_start,
1005 mmio_len, pcidev->irq);
1007 adapter->HwRegs = (void *)memmapped_ioaddr;
1008 adapter->base_addr = memmapped_ioaddr;
1010 mmio_start = pci_resource_start(pcidev, 2);
1011 mmio_len = pci_resource_len(pcidev, 2);
1013 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
1014 mmio_start, mmio_len);
1016 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
1017 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
1019 if (!memmapped_ioaddr) {
1020 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
1021 __func__, mmio_len, mmio_start);
1022 goto err_out_free_mmio_region_2;
1025 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, "
1026 "start[%lx] len[%lx], IRQ %d.\n", __func__,
1027 memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
1029 adapter->UcodeRegs = (void *)memmapped_ioaddr;
1031 adapter->State = SXG_STATE_INITIALIZING;
1033 * Maintain a list of all adapters anchored by
1034 * the global SxgDriver structure.
1036 adapter->Next = SxgDriver.Adapters;
1037 SxgDriver.Adapters = adapter;
1038 adapter->AdapterID = ++SxgDriver.AdapterID;
1040 /* Initialize CRC table used to determine multicast hash */
1041 sxg_mcast_init_crc32();
1043 adapter->JumboEnabled = FALSE;
1044 adapter->RssEnabled = FALSE;
1045 if (adapter->JumboEnabled) {
1046 adapter->FrameSize = JUMBOMAXFRAME;
1047 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
1049 adapter->FrameSize = ETHERMAXFRAME;
1050 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
1054 * status = SXG_READ_EEPROM(adapter);
1056 * goto sxg_init_bad;
1060 DBG_ERROR("sxg: %s ENTER sxg_config_pci\n", __func__);
1061 sxg_config_pci(pcidev);
1062 DBG_ERROR("sxg: %s EXIT sxg_config_pci\n", __func__);
1064 DBG_ERROR("sxg: %s ENTER sxg_init_driver\n", __func__);
1066 DBG_ERROR("sxg: %s EXIT sxg_init_driver\n", __func__);
1068 adapter->vendid = pci_tbl_entry->vendor;
1069 adapter->devid = pci_tbl_entry->device;
1070 adapter->subsysid = pci_tbl_entry->subdevice;
1071 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
1072 adapter->functionnumber = (pcidev->devfn & 0x7);
1073 adapter->memorylength = pci_resource_len(pcidev, 0);
1074 adapter->irq = pcidev->irq;
1075 adapter->next_netdevice = head_netdevice;
1076 head_netdevice = netdev;
1077 adapter->port = 0; /*adapter->functionnumber; */
1079 /* Allocate memory and other resources */
1080 DBG_ERROR("sxg: %s ENTER sxg_allocate_resources\n", __func__);
1081 status = sxg_allocate_resources(adapter);
1082 DBG_ERROR("sxg: %s EXIT sxg_allocate_resources status %x\n",
1084 if (status != STATUS_SUCCESS) {
1088 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __func__);
1089 if (sxg_download_microcode(adapter, SXG_UCODE_SYSTEM)) {
1090 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
1092 sxg_read_config(adapter);
1093 status = sxg_adapter_set_hwaddr(adapter);
1095 adapter->state = ADAPT_FAIL;
1096 adapter->linkstate = LINK_DOWN;
1097 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n", status);
1100 netdev->base_addr = (unsigned long)adapter->base_addr;
1101 netdev->irq = adapter->irq;
1102 netdev->open = sxg_entry_open;
1103 netdev->stop = sxg_entry_halt;
1104 netdev->hard_start_xmit = sxg_send_packets;
1105 netdev->do_ioctl = sxg_ioctl;
1106 netdev->change_mtu = sxg_change_mtu;
1108 netdev->set_mac_address = sxg_mac_set_address;
1110 netdev->get_stats = sxg_get_stats;
1111 netdev->set_multicast_list = sxg_mcast_set_list;
1112 SET_ETHTOOL_OPS(netdev, &sxg_nic_ethtool_ops);
1113 netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1114 err = sxg_set_interrupt_capability(adapter);
1115 if (err != STATUS_SUCCESS)
1116 DBG_ERROR("Cannot enable MSI-X capability\n");
1118 strcpy(netdev->name, "eth%d");
1119 /* strcpy(netdev->name, pci_name(pcidev)); */
1120 if ((err = register_netdev(netdev))) {
1121 DBG_ERROR("Cannot register net device, aborting. %s\n",
1126 netif_napi_add(netdev, &adapter->napi,
1127 sxg_poll, SXG_NETDEV_WEIGHT);
1128 netdev->watchdog_timeo = 2 * HZ;
1129 init_timer(&adapter->watchdog_timer);
1130 adapter->watchdog_timer.function = &sxg_watchdog;
1131 adapter->watchdog_timer.data = (unsigned long) adapter;
1132 INIT_WORK(&adapter->update_link_status, sxg_update_link_status);
1135 ("sxg: %s addr 0x%lx, irq %d, MAC addr \
1136 %02X:%02X:%02X:%02X:%02X:%02X\n",
1137 netdev->name, netdev->base_addr, pcidev->irq, netdev->dev_addr[0],
1138 netdev->dev_addr[1], netdev->dev_addr[2], netdev->dev_addr[3],
1139 netdev->dev_addr[4], netdev->dev_addr[5]);
1142 ASSERT(status == FALSE);
1143 /* sxg_free_adapter(adapter); */
1145 DBG_ERROR("sxg: %s EXIT status[%x] jiffies[%lx] cpu %d\n", __func__,
1146 status, jiffies, smp_processor_id());
1150 sxg_free_resources(adapter);
1152 err_out_free_mmio_region_2:
1154 mmio_start = pci_resource_start(pcidev, 2);
1155 mmio_len = pci_resource_len(pcidev, 2);
1156 release_mem_region(mmio_start, mmio_len);
1158 err_out_free_mmio_region_0:
1160 mmio_start = pci_resource_start(pcidev, 0);
1161 mmio_len = pci_resource_len(pcidev, 0);
1163 release_mem_region(mmio_start, mmio_len);
1165 err_out_exit_sxg_probe:
1167 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
1168 smp_processor_id());
1170 pci_disable_device(pcidev);
1171 DBG_ERROR("sxg: %s deallocate device\n", __FUNCTION__);
1173 printk("Exit %s, Sxg driver loading failed..\n", __FUNCTION__);
1179 * LINE BASE Interrupt routines..
1181 * sxg_disable_interrupt
1183 * DisableInterrupt Handler
1187 * adapter: Our adapter structure
1192 static void sxg_disable_interrupt(struct adapter_t *adapter)
1194 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DisIntr",
1195 adapter, adapter->InterruptsEnabled, 0, 0);
1196 /* For now, RSS is disabled with line based interrupts */
1197 ASSERT(adapter->RssEnabled == FALSE);
1198 /* Turn off interrupts by writing to the icr register. */
1199 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_DISABLE), TRUE);
1201 adapter->InterruptsEnabled = 0;
1203 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDisIntr",
1204 adapter, adapter->InterruptsEnabled, 0, 0);
1208 * sxg_enable_interrupt
1210 * EnableInterrupt Handler
1214 * adapter: Our adapter structure
1219 static void sxg_enable_interrupt(struct adapter_t *adapter)
1221 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "EnIntr",
1222 adapter, adapter->InterruptsEnabled, 0, 0);
1223 /* For now, RSS is disabled with line based interrupts */
1224 ASSERT(adapter->RssEnabled == FALSE);
1225 /* Turn on interrupts by writing to the icr register. */
1226 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_ENABLE), TRUE);
1228 adapter->InterruptsEnabled = 1;
1230 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XEnIntr",
1235 * sxg_isr - Process an line-based interrupt
1238 * Context - Our adapter structure
1239 * QueueDefault - Output parameter to queue to default CPU
1240 * TargetCpus - Output bitmap to schedule DPC's
1242 * Return Value: TRUE if our interrupt
1244 static irqreturn_t sxg_isr(int irq, void *dev_id)
1246 struct net_device *dev = (struct net_device *) dev_id;
1247 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
1249 if(adapter->state != ADAPT_UP)
1251 adapter->Stats.NumInts++;
1252 if (adapter->Isr[0] == 0) {
1254 * The SLIC driver used to experience a number of spurious
1255 * interrupts due to the delay associated with the masking of
1256 * the interrupt (we'd bounce back in here). If we see that
1257 * again with Sahara,add a READ_REG of the Icr register after
1258 * the WRITE_REG below.
1260 adapter->Stats.FalseInts++;
1264 * Move the Isr contents and clear the value in
1265 * shared memory, and mask interrupts
1267 /* ASSERT(adapter->IsrDpcsPending == 0); */
1268 #if XXXTODO /* RSS Stuff */
1270 * If RSS is enabled and the ISR specifies SXG_ISR_EVENT, then
1271 * schedule DPC's based on event queues.
1273 if (adapter->RssEnabled && (adapter->IsrCopy[0] & SXG_ISR_EVENT)) {
1275 i < adapter->RssSystemInfo->ProcessorInfo.RssCpuCount;
1277 struct sxg_event_ring *EventRing =
1278 &adapter->EventRings[i];
1279 struct sxg_event *Event =
1280 &EventRing->Ring[adapter->NextEvent[i]];
1282 adapter->RssSystemInfo->RssIdToCpu[i];
1283 if (Event->Status & EVENT_STATUS_VALID) {
1284 adapter->IsrDpcsPending++;
1285 CpuMask |= (1 << Cpu);
1290 * Now, either schedule the CPUs specified by the CpuMask,
1294 *QueueDefault = FALSE;
1296 adapter->IsrDpcsPending = 1;
1297 *QueueDefault = TRUE;
1299 *TargetCpus = CpuMask;
1301 sxg_interrupt(adapter);
1306 static void sxg_interrupt(struct adapter_t *adapter)
1308 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_MASK), TRUE);
1310 if (napi_schedule_prep(&adapter->napi)) {
1311 __napi_schedule(&adapter->napi);
1315 static void sxg_handle_interrupt(struct adapter_t *adapter, int *work_done,
1318 /* unsigned char RssId = 0; */
1320 int sxg_napi_continue = 1;
1321 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "HndlIntr",
1322 adapter, adapter->IsrCopy[0], 0, 0);
1323 /* For now, RSS is disabled with line based interrupts */
1324 ASSERT(adapter->RssEnabled == FALSE);
1326 adapter->IsrCopy[0] = adapter->Isr[0];
1327 adapter->Isr[0] = 0;
1329 /* Always process the event queue. */
1330 while (sxg_napi_continue)
1332 sxg_process_event_queue(adapter,
1333 (adapter->RssEnabled ? /*RssId */ 0 : 0),
1334 &sxg_napi_continue, work_done, budget);
1337 #if XXXTODO /* RSS stuff */
1338 if (--adapter->IsrDpcsPending) {
1340 ASSERT(adapter->RssEnabled);
1341 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DPCsPend",
1346 /* Last (or only) DPC processes the ISR and clears the interrupt. */
1347 NewIsr = sxg_process_isr(adapter, 0);
1348 /* Reenable interrupts */
1349 adapter->IsrCopy[0] = 0;
1350 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ClearIsr",
1351 adapter, NewIsr, 0, 0);
1353 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XHndlInt",
1356 static int sxg_poll(struct napi_struct *napi, int budget)
1358 struct adapter_t *adapter = container_of(napi, struct adapter_t, napi);
1361 sxg_handle_interrupt(adapter, &work_done, budget);
1363 if (work_done < budget) {
1364 napi_complete(napi);
1365 WRITE_REG(adapter->UcodeRegs[0].Isr, 0, TRUE);
1371 * sxg_process_isr - Process an interrupt. Called from the line-based and
1372 * message based interrupt DPC routines
1375 * adapter - Our adapter structure
1376 * Queue - The ISR that needs processing
1381 static int sxg_process_isr(struct adapter_t *adapter, u32 MessageId)
1383 u32 Isr = adapter->IsrCopy[MessageId];
1386 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ProcIsr",
1387 adapter, Isr, 0, 0);
1390 if (Isr & SXG_ISR_ERR) {
1391 if (Isr & SXG_ISR_PDQF) {
1392 adapter->Stats.PdqFull++;
1393 DBG_ERROR("%s: SXG_ISR_ERR PDQF!!\n", __func__);
1395 /* No host buffer */
1396 if (Isr & SXG_ISR_RMISS) {
1398 * There is a bunch of code in the SLIC driver which
1399 * attempts to process more receive events per DPC
1400 * if we start to fall behind. We'll probablyd
1401 * need to do something similar here, but hold
1402 * off for now. I don't want to make the code more
1403 * complicated than strictly needed.
1405 adapter->stats.rx_missed_errors++;
1406 if (adapter->stats.rx_missed_errors< 5) {
1407 DBG_ERROR("%s: SXG_ISR_ERR RMISS!!\n",
1412 if (Isr & SXG_ISR_DEAD) {
1414 * Set aside the crash info and set the adapter state
1417 adapter->CrashCpu = (unsigned char)
1418 ((Isr & SXG_ISR_CPU) >> SXG_ISR_CPU_SHIFT);
1419 adapter->CrashLocation = (ushort) (Isr & SXG_ISR_CRASH);
1420 adapter->Dead = TRUE;
1421 DBG_ERROR("%s: ISR_DEAD %x, CPU: %d\n", __func__,
1422 adapter->CrashLocation, adapter->CrashCpu);
1424 /* Event ring full */
1425 if (Isr & SXG_ISR_ERFULL) {
1427 * Same issue as RMISS, really. This means the
1428 * host is falling behind the card. Need to increase
1429 * event ring size, process more events per interrupt,
1430 * and/or reduce/remove interrupt aggregation.
1432 adapter->Stats.EventRingFull++;
1433 DBG_ERROR("%s: SXG_ISR_ERR EVENT RING FULL!!\n",
1436 /* Transmit drop - no DRAM buffers or XMT error */
1437 if (Isr & SXG_ISR_XDROP) {
1438 DBG_ERROR("%s: SXG_ISR_ERR XDROP!!\n", __func__);
1441 /* Slowpath send completions */
1442 if (Isr & SXG_ISR_SPSEND) {
1443 sxg_complete_slow_send(adapter);
1446 if (Isr & SXG_ISR_UPC) {
1447 /* Maybe change when debug is added.. */
1448 // ASSERT(adapter->DumpCmdRunning);
1449 adapter->DumpCmdRunning = FALSE;
1452 if (Isr & SXG_ISR_LINK) {
1453 if (adapter->state != ADAPT_DOWN) {
1454 adapter->link_status_changed = 1;
1455 schedule_work(&adapter->update_link_status);
1458 /* Debug - breakpoint hit */
1459 if (Isr & SXG_ISR_BREAK) {
1461 * At the moment AGDB isn't written to support interactive
1462 * debug sessions. When it is, this interrupt will be used to
1463 * signal AGDB that it has hit a breakpoint. For now, ASSERT.
1467 /* Heartbeat response */
1468 if (Isr & SXG_ISR_PING) {
1469 adapter->PingOutstanding = FALSE;
1471 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XProcIsr",
1472 adapter, Isr, NewIsr, 0);
1478 * sxg_rcv_checksum - Set the checksum for received packet
1481 * @adapter - Adapter structure on which packet is received
1482 * @skb - Packet which is receieved
1483 * @Event - Event read from hardware
1486 void sxg_rcv_checksum(struct adapter_t *adapter, struct sk_buff *skb,
1487 struct sxg_event *Event)
1489 skb->ip_summed = CHECKSUM_NONE;
1490 if (likely(adapter->flags & SXG_RCV_IP_CSUM_ENABLED)) {
1491 if (likely(adapter->flags & SXG_RCV_TCP_CSUM_ENABLED)
1492 && (Event->Status & EVENT_STATUS_TCPIP)) {
1493 if(!(Event->Status & EVENT_STATUS_TCPBAD))
1494 skb->ip_summed = CHECKSUM_UNNECESSARY;
1495 if(!(Event->Status & EVENT_STATUS_IPBAD))
1496 skb->ip_summed = CHECKSUM_UNNECESSARY;
1497 } else if(Event->Status & EVENT_STATUS_IPONLY) {
1498 if(!(Event->Status & EVENT_STATUS_IPBAD))
1499 skb->ip_summed = CHECKSUM_UNNECESSARY;
1505 * sxg_process_event_queue - Process our event queue
1508 * - adapter - Adapter structure
1509 * - RssId - The event queue requiring processing
1514 static u32 sxg_process_event_queue(struct adapter_t *adapter, u32 RssId,
1515 int *sxg_napi_continue, int *work_done, int budget)
1517 struct sxg_event_ring *EventRing = &adapter->EventRings[RssId];
1518 struct sxg_event *Event = &EventRing->Ring[adapter->NextEvent[RssId]];
1519 u32 EventsProcessed = 0, Batches = 0;
1520 struct sk_buff *skb;
1521 #ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
1522 struct sk_buff *prev_skb = NULL;
1523 struct sk_buff *IndicationList[SXG_RCV_ARRAYSIZE];
1525 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
1527 u32 ReturnStatus = 0;
1528 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
1530 ASSERT((adapter->State == SXG_STATE_RUNNING) ||
1531 (adapter->State == SXG_STATE_PAUSING) ||
1532 (adapter->State == SXG_STATE_PAUSED) ||
1533 (adapter->State == SXG_STATE_HALTING));
1535 * We may still have unprocessed events on the queue if
1536 * the card crashed. Don't process them.
1538 if (adapter->Dead) {
1542 * In theory there should only be a single processor that
1543 * accesses this queue, and only at interrupt-DPC time. So/
1544 * we shouldn't need a lock for any of this.
1546 while (Event->Status & EVENT_STATUS_VALID) {
1547 (*sxg_napi_continue) = 1;
1548 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "Event",
1549 Event, Event->Code, Event->Status,
1550 adapter->NextEvent);
1551 switch (Event->Code) {
1552 case EVENT_CODE_BUFFERS:
1553 /* struct sxg_ring_info Head & Tail == unsigned char */
1554 ASSERT(!(Event->CommandIndex & 0xFF00));
1555 sxg_complete_descriptor_blocks(adapter,
1556 Event->CommandIndex);
1558 case EVENT_CODE_SLOWRCV:
1560 --adapter->RcvBuffersOnCard;
1561 if ((skb = sxg_slow_receive(adapter, Event))) {
1563 #ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
1564 /* Add it to our indication list */
1565 SXG_ADD_RCV_PACKET(adapter, skb, prev_skb,
1566 IndicationList, num_skbs);
1568 * Linux, we just pass up each skb to the
1569 * protocol above at this point, there is no
1570 * capability of an indication list.
1573 /* CHECK skb_pull(skb, INIC_RCVBUF_HEADSIZE); */
1574 /* (rcvbuf->length & IRHDDR_FLEN_MSK); */
1575 rx_bytes = Event->Length;
1576 adapter->stats.rx_packets++;
1577 adapter->stats.rx_bytes += rx_bytes;
1578 sxg_rcv_checksum(adapter, skb, Event);
1579 skb->dev = adapter->netdev;
1580 netif_receive_skb(skb);
1585 DBG_ERROR("%s: ERROR Invalid EventCode %d\n",
1586 __func__, Event->Code);
1590 * See if we need to restock card receive buffers.
1591 * There are two things to note here:
1592 * First - This test is not SMP safe. The
1593 * adapter->BuffersOnCard field is protected via atomic
1594 * interlocked calls, but we do not protect it with respect
1595 * to these tests. The only way to do that is with a lock,
1596 * and I don't want to grab a lock every time we adjust the
1597 * BuffersOnCard count. Instead, we allow the buffer
1598 * replenishment to be off once in a while. The worst that
1599 * can happen is the card is given on more-or-less descriptor
1600 * block than the arbitrary value we've chosen. No big deal
1601 * In short DO NOT ADD A LOCK HERE, OR WHERE RcvBuffersOnCard
1603 * Second - We expect this test to rarely
1604 * evaluate to true. We attempt to refill descriptor blocks
1605 * as they are returned to us (sxg_complete_descriptor_blocks)
1606 * so The only time this should evaluate to true is when
1607 * sxg_complete_descriptor_blocks failed to allocate
1610 if (adapter->JumboEnabled)
1611 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
1613 if (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
1614 sxg_stock_rcv_buffers(adapter);
1617 * It's more efficient to just set this to zero.
1618 * But clearing the top bit saves potential debug info...
1620 Event->Status &= ~EVENT_STATUS_VALID;
1621 /* Advance to the next event */
1622 SXG_ADVANCE_INDEX(adapter->NextEvent[RssId], EVENT_RING_SIZE);
1623 Event = &EventRing->Ring[adapter->NextEvent[RssId]];
1625 if (EventsProcessed == EVENT_RING_BATCH) {
1626 /* Release a batch of events back to the card */
1627 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1628 EVENT_RING_BATCH, FALSE);
1629 EventsProcessed = 0;
1631 * If we've processed our batch limit, break out of the
1632 * loop and return SXG_ISR_EVENT to arrange for us to
1635 if (Batches++ == EVENT_BATCH_LIMIT) {
1636 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1637 TRACE_NOISY, "EvtLimit", Batches,
1638 adapter->NextEvent, 0, 0);
1639 ReturnStatus = SXG_ISR_EVENT;
1643 if (*work_done >= budget) {
1644 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1645 EventsProcessed, FALSE);
1646 EventsProcessed = 0;
1647 (*sxg_napi_continue) = 0;
1651 if (!(Event->Status & EVENT_STATUS_VALID))
1652 (*sxg_napi_continue) = 0;
1654 #ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
1655 /* Indicate any received dumb-nic frames */
1656 SXG_INDICATE_PACKETS(adapter, IndicationList, num_skbs);
1658 /* Release events back to the card. */
1659 if (EventsProcessed) {
1660 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1661 EventsProcessed, FALSE);
1663 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XPrcEvnt",
1664 Batches, EventsProcessed, adapter->NextEvent, num_skbs);
1666 return (ReturnStatus);
1670 * sxg_complete_slow_send - Complete slowpath or dumb-nic sends
1673 * adapter - A pointer to our adapter structure
1677 static void sxg_complete_slow_send(struct adapter_t *adapter)
1679 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
1680 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
1682 struct sxg_cmd *XmtCmd;
1683 unsigned long flags = 0;
1684 unsigned long sgl_flags = 0;
1685 unsigned int processed_count = 0;
1688 * NOTE - This lock is dropped and regrabbed in this loop.
1689 * This means two different processors can both be running/
1690 * through this loop. Be *very* careful.
1692 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
1694 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnds",
1695 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1697 while ((XmtRingInfo->Tail != *adapter->XmtRingZeroIndex)
1698 && processed_count++ < SXG_COMPLETE_SLOW_SEND_LIMIT) {
1700 * Locate the current Cmd (ring descriptor entry), and
1701 * associated SGL, and advance the tail
1703 SXG_RETURN_CMD(XmtRing, XmtRingInfo, XmtCmd, ContextType);
1704 ASSERT(ContextType);
1705 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1706 XmtRingInfo->Head, XmtRingInfo->Tail, XmtCmd, 0);
1707 /* Clear the SGL field. */
1710 switch (*ContextType) {
1713 struct sk_buff *skb;
1714 struct sxg_scatter_gather *SxgSgl =
1715 (struct sxg_scatter_gather *)ContextType;
1716 dma64_addr_t FirstSgeAddress;
1719 /* Dumb-nic send. Command context is the dumb-nic SGL */
1720 skb = (struct sk_buff *)ContextType;
1721 skb = SxgSgl->DumbPacket;
1722 FirstSgeAddress = XmtCmd->Buffer.FirstSgeAddress;
1723 FirstSgeLength = XmtCmd->Buffer.FirstSgeLength;
1724 /* Complete the send */
1725 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1726 TRACE_IMPORTANT, "DmSndCmp", skb, 0,
1728 ASSERT(adapter->Stats.XmtQLen);
1730 * Now drop the lock and complete the send
1731 * back to Microsoft. We need to drop the lock
1732 * because Microsoft can come back with a
1733 * chimney send, which results in a double trip
1736 spin_unlock_irqrestore(
1737 &adapter->XmtZeroLock, flags);
1739 SxgSgl->DumbPacket = NULL;
1740 SXG_COMPLETE_DUMB_SEND(adapter, skb,
1743 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL);
1744 /* and reacquire.. */
1745 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
1752 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
1753 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1754 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1761 * adapter - A pointer to our adapter structure
1762 * Event - Receive event
1766 static struct sk_buff *sxg_slow_receive(struct adapter_t *adapter,
1767 struct sxg_event *Event)
1769 u32 BufferSize = adapter->ReceiveBufferSize;
1770 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
1771 struct sk_buff *Packet;
1772 static int read_counter = 0;
1774 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *) Event->HostHandle;
1775 if(read_counter++ & 0x100)
1777 sxg_collect_statistics(adapter);
1780 ASSERT(RcvDataBufferHdr);
1781 ASSERT(RcvDataBufferHdr->State == SXG_BUFFER_ONCARD);
1782 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "SlowRcv", Event,
1783 RcvDataBufferHdr, RcvDataBufferHdr->State,
1784 /*RcvDataBufferHdr->VirtualAddress*/ 0);
1785 /* Drop rcv frames in non-running state */
1786 switch (adapter->State) {
1787 case SXG_STATE_RUNNING:
1789 case SXG_STATE_PAUSING:
1790 case SXG_STATE_PAUSED:
1791 case SXG_STATE_HALTING:
1799 * memcpy(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1800 * RcvDataBufferHdr->VirtualAddress, Event->Length);
1803 /* Change buffer state to UPSTREAM */
1804 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
1805 if (Event->Status & EVENT_STATUS_RCVERR) {
1806 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvError",
1807 Event, Event->Status, Event->HostHandle, 0);
1808 sxg_process_rcv_error(adapter, *(u32 *)
1809 SXG_RECEIVE_DATA_LOCATION
1810 (RcvDataBufferHdr));
1813 #if XXXTODO /* VLAN stuff */
1814 /* If there's a VLAN tag, extract it and validate it */
1815 if (((struct ether_header *)
1816 (SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)))->EtherType
1817 == ETHERTYPE_VLAN) {
1818 if (SxgExtractVlanHeader(adapter, RcvDataBufferHdr, Event) !=
1820 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY,
1822 SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1828 /* Dumb-nic frame. See if it passes our mac filter and update stats */
1830 if (!sxg_mac_filter(adapter,
1831 (struct ether_header *)(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)),
1833 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvFiltr",
1834 Event, SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1839 Packet = RcvDataBufferHdr->SxgDumbRcvPacket;
1840 SXG_ADJUST_RCV_PACKET(Packet, RcvDataBufferHdr, Event);
1841 Packet->protocol = eth_type_trans(Packet, adapter->netdev);
1843 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumbRcv",
1844 RcvDataBufferHdr, Packet, Event->Length, 0);
1845 /* Lastly adjust the receive packet length. */
1846 RcvDataBufferHdr->SxgDumbRcvPacket = NULL;
1847 RcvDataBufferHdr->PhysicalAddress = (dma_addr_t)NULL;
1848 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
1849 if (RcvDataBufferHdr->skb)
1851 spin_lock(&adapter->RcvQLock);
1852 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
1853 // adapter->RcvBuffersOnCard ++;
1854 spin_unlock(&adapter->RcvQLock);
1859 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DropRcv",
1860 RcvDataBufferHdr, Event->Length, 0, 0);
1861 adapter->stats.rx_dropped++;
1862 // adapter->Stats.RcvDiscards++;
1863 spin_lock(&adapter->RcvQLock);
1864 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
1865 spin_unlock(&adapter->RcvQLock);
1870 * sxg_process_rcv_error - process receive error and update
1874 * adapter - Adapter structure
1875 * ErrorStatus - 4-byte receive error status
1877 * Return Value : None
1879 static void sxg_process_rcv_error(struct adapter_t *adapter, u32 ErrorStatus)
1883 adapter->stats.rx_errors++;
1885 if (ErrorStatus & SXG_RCV_STATUS_TRANSPORT_ERROR) {
1886 Error = ErrorStatus & SXG_RCV_STATUS_TRANSPORT_MASK;
1888 case SXG_RCV_STATUS_TRANSPORT_CSUM:
1889 adapter->Stats.TransportCsum++;
1891 case SXG_RCV_STATUS_TRANSPORT_UFLOW:
1892 adapter->Stats.TransportUflow++;
1894 case SXG_RCV_STATUS_TRANSPORT_HDRLEN:
1895 adapter->Stats.TransportHdrLen++;
1899 if (ErrorStatus & SXG_RCV_STATUS_NETWORK_ERROR) {
1900 Error = ErrorStatus & SXG_RCV_STATUS_NETWORK_MASK;
1902 case SXG_RCV_STATUS_NETWORK_CSUM:
1903 adapter->Stats.NetworkCsum++;
1905 case SXG_RCV_STATUS_NETWORK_UFLOW:
1906 adapter->Stats.NetworkUflow++;
1908 case SXG_RCV_STATUS_NETWORK_HDRLEN:
1909 adapter->Stats.NetworkHdrLen++;
1913 if (ErrorStatus & SXG_RCV_STATUS_PARITY) {
1914 adapter->Stats.Parity++;
1916 if (ErrorStatus & SXG_RCV_STATUS_LINK_ERROR) {
1917 Error = ErrorStatus & SXG_RCV_STATUS_LINK_MASK;
1919 case SXG_RCV_STATUS_LINK_PARITY:
1920 adapter->Stats.LinkParity++;
1922 case SXG_RCV_STATUS_LINK_EARLY:
1923 adapter->Stats.LinkEarly++;
1925 case SXG_RCV_STATUS_LINK_BUFOFLOW:
1926 adapter->Stats.LinkBufOflow++;
1928 case SXG_RCV_STATUS_LINK_CODE:
1929 adapter->Stats.LinkCode++;
1931 case SXG_RCV_STATUS_LINK_DRIBBLE:
1932 adapter->Stats.LinkDribble++;
1934 case SXG_RCV_STATUS_LINK_CRC:
1935 adapter->Stats.LinkCrc++;
1937 case SXG_RCV_STATUS_LINK_OFLOW:
1938 adapter->Stats.LinkOflow++;
1940 case SXG_RCV_STATUS_LINK_UFLOW:
1941 adapter->Stats.LinkUflow++;
1951 * adapter - Adapter structure
1952 * pether - Ethernet header
1953 * length - Frame length
1955 * Return Value : TRUE if the frame is to be allowed
1957 static bool sxg_mac_filter(struct adapter_t *adapter,
1958 struct ether_header *EtherHdr, ushort length)
1961 struct net_device *dev = adapter->netdev;
1963 if (SXG_MULTICAST_PACKET(EtherHdr)) {
1964 if (SXG_BROADCAST_PACKET(EtherHdr)) {
1966 if (adapter->MacFilter & MAC_BCAST) {
1967 adapter->Stats.DumbRcvBcastPkts++;
1968 adapter->Stats.DumbRcvBcastBytes += length;
1973 if (adapter->MacFilter & MAC_ALLMCAST) {
1974 adapter->Stats.DumbRcvMcastPkts++;
1975 adapter->Stats.DumbRcvMcastBytes += length;
1978 if (adapter->MacFilter & MAC_MCAST) {
1979 struct dev_mc_list *mclist = dev->mc_list;
1981 ETHER_EQ_ADDR(mclist->da_addr,
1982 EtherHdr->ether_dhost,
1988 DumbRcvMcastBytes += length;
1991 mclist = mclist->next;
1995 } else if (adapter->MacFilter & MAC_DIRECTED) {
1997 * Not broadcast or multicast. Must be directed at us or
1998 * the card is in promiscuous mode. Either way, consider it
1999 * ours if MAC_DIRECTED is set
2001 adapter->Stats.DumbRcvUcastPkts++;
2002 adapter->Stats.DumbRcvUcastBytes += length;
2005 if (adapter->MacFilter & MAC_PROMISC) {
2006 /* Whatever it is, keep it. */
2012 static int sxg_register_interrupt(struct adapter_t *adapter)
2014 if (!adapter->intrregistered) {
2018 ("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x] %x\n",
2019 __func__, adapter, adapter->netdev->irq, NR_IRQS);
2021 spin_unlock_irqrestore(&sxg_global.driver_lock,
2024 retval = request_irq(adapter->netdev->irq,
2027 adapter->netdev->name, adapter->netdev);
2029 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2032 DBG_ERROR("sxg: request_irq (%s) FAILED [%x]\n",
2033 adapter->netdev->name, retval);
2036 adapter->intrregistered = 1;
2037 adapter->IntRegistered = TRUE;
2038 /* Disable RSS with line-based interrupts */
2039 adapter->RssEnabled = FALSE;
2040 DBG_ERROR("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x]\n",
2041 __func__, adapter, adapter->netdev->irq);
2043 return (STATUS_SUCCESS);
2046 static void sxg_deregister_interrupt(struct adapter_t *adapter)
2048 DBG_ERROR("sxg: %s ENTER adapter[%p]\n", __func__, adapter);
2050 slic_init_cleanup(adapter);
2052 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
2053 adapter->error_interrupts = 0;
2054 adapter->rcv_interrupts = 0;
2055 adapter->xmit_interrupts = 0;
2056 adapter->linkevent_interrupts = 0;
2057 adapter->upr_interrupts = 0;
2058 adapter->num_isrs = 0;
2059 adapter->xmit_completes = 0;
2060 adapter->rcv_broadcasts = 0;
2061 adapter->rcv_multicasts = 0;
2062 adapter->rcv_unicasts = 0;
2063 DBG_ERROR("sxg: %s EXIT\n", __func__);
2069 * Perform initialization of our slic interface.
2072 static int sxg_if_init(struct adapter_t *adapter)
2074 struct net_device *dev = adapter->netdev;
2077 DBG_ERROR("sxg: %s (%s) ENTER states[%d:%d] flags[%x]\n",
2078 __func__, adapter->netdev->name,
2080 adapter->linkstate, dev->flags);
2082 /* adapter should be down at this point */
2083 if (adapter->state != ADAPT_DOWN) {
2084 DBG_ERROR("sxg_if_init adapter->state != ADAPT_DOWN\n");
2087 ASSERT(adapter->linkstate == LINK_DOWN);
2089 adapter->devflags_prev = dev->flags;
2090 adapter->MacFilter = MAC_DIRECTED;
2092 DBG_ERROR("sxg: %s (%s) Set MAC options: ", __func__,
2093 adapter->netdev->name);
2094 if (dev->flags & IFF_BROADCAST) {
2095 adapter->MacFilter |= MAC_BCAST;
2096 DBG_ERROR("BCAST ");
2098 if (dev->flags & IFF_PROMISC) {
2099 adapter->MacFilter |= MAC_PROMISC;
2100 DBG_ERROR("PROMISC ");
2102 if (dev->flags & IFF_ALLMULTI) {
2103 adapter->MacFilter |= MAC_ALLMCAST;
2104 DBG_ERROR("ALL_MCAST ");
2106 if (dev->flags & IFF_MULTICAST) {
2107 adapter->MacFilter |= MAC_MCAST;
2108 DBG_ERROR("MCAST ");
2112 status = sxg_register_intr(adapter);
2113 if (status != STATUS_SUCCESS) {
2114 DBG_ERROR("sxg_if_init: sxg_register_intr FAILED %x\n",
2116 sxg_deregister_interrupt(adapter);
2120 adapter->state = ADAPT_UP;
2122 /* clear any pending events, then enable interrupts */
2123 DBG_ERROR("sxg: %s ENABLE interrupts(slic)\n", __func__);
2125 return (STATUS_SUCCESS);
2128 void sxg_set_interrupt_aggregation(struct adapter_t *adapter)
2131 * Top bit disables aggregation on xmt (SXG_AGG_XMT_DISABLE).
2132 * Make sure Max is less than 0x8000.
2134 adapter->max_aggregation = SXG_MAX_AGG_DEFAULT;
2135 adapter->min_aggregation = SXG_MIN_AGG_DEFAULT;
2136 WRITE_REG(adapter->UcodeRegs[0].Aggregation,
2137 ((adapter->max_aggregation << SXG_MAX_AGG_SHIFT) |
2138 adapter->min_aggregation),
2142 static int sxg_entry_open(struct net_device *dev)
2144 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
2147 int sxg_initial_rcv_data_buffers = SXG_INITIAL_RCV_DATA_BUFFERS;
2150 if (adapter->JumboEnabled == TRUE) {
2151 sxg_initial_rcv_data_buffers =
2152 SXG_INITIAL_JUMBO_RCV_DATA_BUFFERS;
2153 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo,
2154 SXG_JUMBO_RCV_RING_SIZE);
2158 * Allocate receive data buffers. We allocate a block of buffers and
2159 * a corresponding descriptor block at once. See sxghw.h:SXG_RCV_BLOCK
2162 for (i = 0; i < sxg_initial_rcv_data_buffers;
2163 i += SXG_RCV_DESCRIPTORS_PER_BLOCK)
2165 status = sxg_allocate_buffer_memory(adapter,
2166 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
2167 SXG_BUFFER_TYPE_RCV);
2168 if (status != STATUS_SUCCESS)
2172 * NBL resource allocation can fail in the 'AllocateComplete' routine,
2173 * which doesn't return status. Make sure we got the number of buffers
2177 if (adapter->FreeRcvBufferCount < sxg_initial_rcv_data_buffers) {
2178 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF6",
2179 adapter, adapter->FreeRcvBufferCount, SXG_MAX_ENTRIES,
2181 return (STATUS_RESOURCES);
2184 * The microcode expects it to be downloaded on every open.
2186 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __FUNCTION__);
2187 if (sxg_download_microcode(adapter, SXG_UCODE_SYSTEM)) {
2188 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
2190 sxg_read_config(adapter);
2192 adapter->state = ADAPT_FAIL;
2193 adapter->linkstate = LINK_DOWN;
2194 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n",
2200 sxg_second_open(adapter->netdev);
2202 return STATUS_SUCCESS;
2208 DBG_ERROR("sxg: %s adapter->activated[%d]\n", __func__,
2209 adapter->activated);
2211 ("sxg: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] port[%d]\n",
2212 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
2213 adapter->netdev, adapter, adapter->port);
2215 netif_stop_queue(adapter->netdev);
2217 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2218 if (!adapter->activated) {
2219 sxg_global.num_sxg_ports_active++;
2220 adapter->activated = 1;
2222 /* Initialize the adapter */
2223 DBG_ERROR("sxg: %s ENTER sxg_initialize_adapter\n", __func__);
2224 status = sxg_initialize_adapter(adapter);
2225 DBG_ERROR("sxg: %s EXIT sxg_initialize_adapter status[%x]\n",
2228 if (status == STATUS_SUCCESS) {
2229 DBG_ERROR("sxg: %s ENTER sxg_if_init\n", __func__);
2230 status = sxg_if_init(adapter);
2231 DBG_ERROR("sxg: %s EXIT sxg_if_init status[%x]\n", __func__,
2235 if (status != STATUS_SUCCESS) {
2236 if (adapter->activated) {
2237 sxg_global.num_sxg_ports_active--;
2238 adapter->activated = 0;
2240 spin_unlock_irqrestore(&sxg_global.driver_lock,
2244 DBG_ERROR("sxg: %s ENABLE ALL INTERRUPTS\n", __func__);
2245 sxg_set_interrupt_aggregation(adapter);
2246 napi_enable(&adapter->napi);
2248 /* Enable interrupts */
2249 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2251 DBG_ERROR("sxg: %s EXIT\n", __func__);
2253 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2254 return STATUS_SUCCESS;
2257 int sxg_second_open(struct net_device * dev)
2259 struct adapter_t *adapter = (struct adapter_t*) netdev_priv(dev);
2262 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2263 netif_start_queue(adapter->netdev);
2264 adapter->state = ADAPT_UP;
2265 adapter->linkstate = LINK_UP;
2267 status = sxg_initialize_adapter(adapter);
2268 sxg_set_interrupt_aggregation(adapter);
2269 napi_enable(&adapter->napi);
2270 /* Re-enable interrupts */
2271 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2273 sxg_register_intr(adapter);
2274 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2275 mod_timer(&adapter->watchdog_timer, jiffies);
2276 return (STATUS_SUCCESS);
2280 static void __devexit sxg_entry_remove(struct pci_dev *pcidev)
2285 struct net_device *dev = pci_get_drvdata(pcidev);
2286 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
2288 flush_scheduled_work();
2290 /* Deallocate Resources */
2291 unregister_netdev(dev);
2292 sxg_reset_interrupt_capability(adapter);
2293 sxg_free_resources(adapter);
2297 mmio_start = pci_resource_start(pcidev, 0);
2298 mmio_len = pci_resource_len(pcidev, 0);
2300 DBG_ERROR("sxg: %s rel_region(0) start[%x] len[%x]\n", __FUNCTION__,
2301 mmio_start, mmio_len);
2302 release_mem_region(mmio_start, mmio_len);
2304 mmio_start = pci_resource_start(pcidev, 2);
2305 mmio_len = pci_resource_len(pcidev, 2);
2307 DBG_ERROR("sxg: %s rel_region(2) start[%x] len[%x]\n", __FUNCTION__,
2308 mmio_start, mmio_len);
2309 release_mem_region(mmio_start, mmio_len);
2311 pci_disable_device(pcidev);
2313 DBG_ERROR("sxg: %s deallocate device\n", __func__);
2315 DBG_ERROR("sxg: %s EXIT\n", __func__);
2318 static int sxg_entry_halt(struct net_device *dev)
2320 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
2321 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
2323 u32 RssIds, IsrCount;
2324 unsigned long flags;
2326 RssIds = SXG_RSS_CPU_COUNT(adapter);
2327 IsrCount = adapter->msi_enabled ? RssIds : 1;
2328 /* Disable interrupts */
2329 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2330 SXG_DISABLE_ALL_INTERRUPTS(adapter);
2331 adapter->state = ADAPT_DOWN;
2332 adapter->linkstate = LINK_DOWN;
2334 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2335 sxg_deregister_interrupt(adapter);
2336 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
2339 del_timer_sync(&adapter->watchdog_timer);
2340 netif_stop_queue(dev);
2341 netif_carrier_off(dev);
2343 napi_disable(&adapter->napi);
2345 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 0, true);
2346 adapter->devflags_prev = 0;
2347 DBG_ERROR("sxg: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
2348 __func__, dev->name, adapter, adapter->state);
2350 spin_lock(&adapter->RcvQLock);
2351 /* Free all the blocks and the buffers, moved from remove() routine */
2352 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
2353 sxg_free_rcvblocks(adapter);
2357 InitializeListHead(&adapter->FreeRcvBuffers);
2358 InitializeListHead(&adapter->FreeRcvBlocks);
2359 InitializeListHead(&adapter->AllRcvBlocks);
2360 InitializeListHead(&adapter->FreeSglBuffers);
2361 InitializeListHead(&adapter->AllSglBuffers);
2363 adapter->FreeRcvBufferCount = 0;
2364 adapter->FreeRcvBlockCount = 0;
2365 adapter->AllRcvBlockCount = 0;
2366 adapter->RcvBuffersOnCard = 0;
2367 adapter->PendingRcvCount = 0;
2369 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
2370 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
2371 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
2372 for (i = 0; i < SXG_MAX_RING_SIZE; i++)
2373 adapter->RcvRingZeroInfo.Context[i] = NULL;
2374 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
2375 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
2377 spin_unlock(&adapter->RcvQLock);
2379 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
2380 adapter->AllSglBufferCount = 0;
2381 adapter->FreeSglBufferCount = 0;
2382 adapter->PendingXmtCount = 0;
2383 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
2384 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
2385 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2387 for (i = 0; i < SXG_MAX_RSS; i++) {
2388 adapter->NextEvent[i] = 0;
2390 atomic_set(&adapter->pending_allocations, 0);
2391 adapter->intrregistered = 0;
2392 sxg_remove_isr(adapter);
2393 DBG_ERROR("sxg: %s (%s) EXIT\n", __FUNCTION__, dev->name);
2394 return (STATUS_SUCCESS);
2397 static int sxg_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2400 /* DBG_ERROR("sxg: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);*/
2402 case SIOCSLICSETINTAGG:
2404 /* struct adapter_t *adapter = (struct adapter_t *)
2410 if (copy_from_user(data, rq->ifr_data, 28)) {
2411 DBG_ERROR("copy_from_user FAILED getting \
2417 "%s: set interrupt aggregation to %d\n",
2423 /* DBG_ERROR("sxg: %s UNSUPPORTED[%x]\n", __func__, cmd); */
2429 #define NORMAL_ETHFRAME 0
2432 * sxg_send_packets - Send a skb packet
2435 * skb - The packet to send
2436 * dev - Our linux net device that refs our adapter
2439 * 0 regardless of outcome XXXTODO refer to e1000 driver
2441 static int sxg_send_packets(struct sk_buff *skb, struct net_device *dev)
2443 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
2444 u32 status = STATUS_SUCCESS;
2447 * DBG_ERROR("sxg: %s ENTER sxg_send_packets skb[%p]\n", __FUNCTION__,
2451 /* Check the adapter state */
2452 switch (adapter->State) {
2453 case SXG_STATE_INITIALIZING:
2454 case SXG_STATE_HALTED:
2455 case SXG_STATE_SHUTDOWN:
2456 ASSERT(0); /* unexpected */
2458 case SXG_STATE_RESETTING:
2459 case SXG_STATE_SLEEP:
2460 case SXG_STATE_BOOTDIAG:
2461 case SXG_STATE_DIAG:
2462 case SXG_STATE_HALTING:
2463 status = STATUS_FAILURE;
2465 case SXG_STATE_RUNNING:
2466 if (adapter->LinkState != SXG_LINK_UP) {
2467 status = STATUS_FAILURE;
2472 status = STATUS_FAILURE;
2474 if (status != STATUS_SUCCESS) {
2478 status = sxg_transmit_packet(adapter, skb);
2479 if (status == STATUS_SUCCESS) {
2484 /* reject & complete all the packets if they cant be sent */
2485 if (status != STATUS_SUCCESS) {
2487 /* sxg_send_packets_fail(adapter, skb, status); */
2489 SXG_DROP_DUMB_SEND(adapter, skb);
2490 adapter->stats.tx_dropped++;
2491 return NETDEV_TX_BUSY;
2494 DBG_ERROR("sxg: %s EXIT sxg_send_packets status[%x]\n", __func__,
2498 return NETDEV_TX_OK;
2502 * sxg_transmit_packet
2504 * This function transmits a single packet.
2507 * adapter - Pointer to our adapter structure
2508 * skb - The packet to be sent
2510 * Return - STATUS of send
2512 static int sxg_transmit_packet(struct adapter_t *adapter, struct sk_buff *skb)
2514 struct sxg_x64_sgl *pSgl;
2515 struct sxg_scatter_gather *SxgSgl;
2516 unsigned long sgl_flags;
2517 /* void *SglBuffer; */
2518 /* u32 SglBufferLength; */
2521 * The vast majority of work is done in the shared
2522 * sxg_dumb_sgl routine.
2524 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSend",
2525 adapter, skb, 0, 0);
2527 /* Allocate a SGL buffer */
2528 SXG_GET_SGL_BUFFER(adapter, SxgSgl, 0);
2530 adapter->Stats.NoSglBuf++;
2531 adapter->stats.tx_errors++;
2532 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "SndPktF1",
2533 adapter, skb, 0, 0);
2534 return (STATUS_RESOURCES);
2536 ASSERT(SxgSgl->adapter == adapter);
2537 /*SglBuffer = SXG_SGL_BUFFER(SxgSgl);
2538 SglBufferLength = SXG_SGL_BUF_SIZE; */
2539 SxgSgl->VlanTag.VlanTci = 0;
2540 SxgSgl->VlanTag.VlanTpid = 0;
2541 SxgSgl->Type = SXG_SGL_DUMB;
2542 SxgSgl->DumbPacket = skb;
2545 /* Call the common sxg_dumb_sgl routine to complete the send. */
2546 return (sxg_dumb_sgl(pSgl, SxgSgl));
2554 * SxgSgl - struct sxg_scatter_gather
2557 * Status of send operation.
2559 static int sxg_dumb_sgl(struct sxg_x64_sgl *pSgl,
2560 struct sxg_scatter_gather *SxgSgl)
2562 struct adapter_t *adapter = SxgSgl->adapter;
2563 struct sk_buff *skb = SxgSgl->DumbPacket;
2564 /* For now, all dumb-nic sends go on RSS queue zero */
2565 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
2566 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
2567 struct sxg_cmd *XmtCmd = NULL;
2568 /* u32 Index = 0; */
2569 u32 DataLength = skb->len;
2570 /* unsigned int BufLen; */
2571 /* u32 SglOffset; */
2573 unsigned long flags;
2574 unsigned long queue_id=0;
2576 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSgl",
2577 pSgl, SxgSgl, 0, 0);
2579 /* Set aside a pointer to the sgl */
2580 SxgSgl->pSgl = pSgl;
2582 /* Sanity check that our SGL format is as we expect. */
2583 ASSERT(sizeof(struct sxg_x64_sge) == sizeof(struct sxg_x64_sge));
2584 /* Shouldn't be a vlan tag on this frame */
2585 ASSERT(SxgSgl->VlanTag.VlanTci == 0);
2586 ASSERT(SxgSgl->VlanTag.VlanTpid == 0);
2589 * From here below we work with the SGL placed in our
2593 SxgSgl->Sgl.NumberOfElements = 1;
2595 * Set ucode Queue ID based on bottom bits of destination TCP port.
2596 * This Queue ID splits slowpath/dumb-nic packet processing across
2597 * multiple threads on the card to improve performance. It is split
2598 * using the TCP port to avoid out-of-order packets that can result
2599 * from multithreaded processing. We use the destination port because
2600 * we expect to be run on a server, so in nearly all cases the local
2601 * port is likely to be constant (well-known server port) and the
2602 * remote port is likely to be random. The exception to this is iSCSI,
2603 * in which case we use the sport instead. Note
2604 * that original attempt at XOR'ing source and dest port resulted in
2605 * poor balance on NTTTCP/iometer applications since they tend to
2606 * line up (even-even, odd-odd..).
2609 if (skb->protocol == htons(ETH_P_IP)) {
2613 if ((ip->protocol == IPPROTO_TCP)&&(DataLength >= sizeof(
2615 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2616 (ntohs (tcp_hdr(skb)->source) &
2617 SXG_LARGE_SEND_QUEUE_MASK):
2618 (ntohs(tcp_hdr(skb)->dest) &
2619 SXG_LARGE_SEND_QUEUE_MASK));
2621 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2622 if ((ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) && (DataLength >=
2623 sizeof(struct tcphdr)) ) {
2624 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2625 (ntohs (tcp_hdr(skb)->source) &
2626 SXG_LARGE_SEND_QUEUE_MASK):
2627 (ntohs(tcp_hdr(skb)->dest) &
2628 SXG_LARGE_SEND_QUEUE_MASK));
2632 /* Grab the spinlock and acquire a command */
2633 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
2634 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2635 if (XmtCmd == NULL) {
2637 * Call sxg_complete_slow_send to see if we can
2638 * free up any XmtRingZero entries and then try again
2641 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2642 sxg_complete_slow_send(adapter);
2643 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
2644 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2645 if (XmtCmd == NULL) {
2646 adapter->Stats.XmtZeroFull++;
2650 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbCmd",
2651 XmtCmd, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
2653 adapter->stats.tx_packets++;
2654 adapter->stats.tx_bytes += DataLength;
2655 #if XXXTODO /* Stats stuff */
2656 if (SXG_MULTICAST_PACKET(EtherHdr)) {
2657 if (SXG_BROADCAST_PACKET(EtherHdr)) {
2658 adapter->Stats.DumbXmtBcastPkts++;
2659 adapter->Stats.DumbXmtBcastBytes += DataLength;
2661 adapter->Stats.DumbXmtMcastPkts++;
2662 adapter->Stats.DumbXmtMcastBytes += DataLength;
2665 adapter->Stats.DumbXmtUcastPkts++;
2666 adapter->Stats.DumbXmtUcastBytes += DataLength;
2670 * Fill in the command
2671 * Copy out the first SGE to the command and adjust for offset
2673 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
2677 * SAHARA SGL WORKAROUND
2678 * See if the SGL straddles a 64k boundary. If so, skip to
2679 * the start of the next 64k boundary and continue
2682 if ((adapter->asictype == SAHARA_REV_A) &&
2683 (SXG_INVALID_SGL(phys_addr,skb->data_len)))
2685 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2686 /* Silently drop this packet */
2687 printk(KERN_EMERG"Dropped a packet for 64k boundary problem\n");
2688 return STATUS_SUCCESS;
2690 memset(XmtCmd, '\0', sizeof(*XmtCmd));
2691 XmtCmd->Buffer.FirstSgeAddress = phys_addr;
2692 XmtCmd->Buffer.FirstSgeLength = DataLength;
2693 XmtCmd->Buffer.SgeOffset = 0;
2694 XmtCmd->Buffer.TotalLength = DataLength;
2695 XmtCmd->SgEntries = 1;
2698 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2700 * We need to set the Checkum in IP header to 0. This is
2701 * required by hardware.
2703 ip_hdr(skb)->check = 0x0;
2704 XmtCmd->CsumFlags.Flags |= SXG_SLOWCMD_CSUM_IP;
2705 XmtCmd->CsumFlags.Flags |= SXG_SLOWCMD_CSUM_TCP;
2706 /* Dont know if length will require a change in case of VLAN */
2707 XmtCmd->CsumFlags.MacLen = ETH_HLEN;
2708 XmtCmd->CsumFlags.IpHl = skb_network_header_len(skb) >>
2709 SXG_NW_HDR_LEN_SHIFT;
2712 * Advance transmit cmd descripter by 1.
2713 * NOTE - See comments in SxgTcpOutput where we write
2714 * to the XmtCmd register regarding CPU ID values and/or
2715 * multiple commands.
2716 * Top 16 bits specify queue_id. See comments about queue_id above
2718 /* Four queues at the moment */
2719 ASSERT((queue_id & ~SXG_LARGE_SEND_QUEUE_MASK) == 0);
2720 WRITE_REG(adapter->UcodeRegs[0].XmtCmd, ((queue_id << 16) | 1), TRUE);
2721 adapter->Stats.XmtQLen++; /* Stats within lock */
2722 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2723 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDumSgl2",
2724 XmtCmd, pSgl, SxgSgl, 0);
2725 return STATUS_SUCCESS;
2729 * NOTE - Only jump to this label AFTER grabbing the
2730 * XmtZeroLock, and DO NOT DROP IT between the
2731 * command allocation and the following abort.
2734 SXG_ABORT_CMD(XmtRingInfo);
2736 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2740 * Jump to this label if failure occurs before the
2741 * XmtZeroLock is grabbed
2743 adapter->stats.tx_errors++;
2744 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumSGFal",
2745 pSgl, SxgSgl, XmtRingInfo->Head, XmtRingInfo->Tail);
2746 /* SxgSgl->DumbPacket is the skb */
2747 // SXG_COMPLETE_DUMB_SEND(adapter, SxgSgl->DumbPacket);
2749 return STATUS_FAILURE;
2753 * Link management functions
2755 * sxg_initialize_link - Initialize the link stuff
2758 * adapter - A pointer to our adapter structure
2763 static int sxg_initialize_link(struct adapter_t *adapter)
2765 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
2772 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitLink",
2775 /* Reset PHY and XGXS module */
2776 WRITE_REG(HwRegs->LinkStatus, LS_SERDES_POWER_DOWN, TRUE);
2778 /* Reset transmit configuration register */
2779 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_RESET, TRUE);
2781 /* Reset receive configuration register */
2782 WRITE_REG(HwRegs->RcvConfig, RCV_CONFIG_RESET, TRUE);
2784 /* Reset all MAC modules */
2785 WRITE_REG(HwRegs->MacConfig0, AXGMAC_CFG0_SUB_RESET, TRUE);
2789 * XXXTODO - This assumes the MAC address (0a:0b:0c:0d:0e:0f)
2790 * is stored with the first nibble (0a) in the byte 0
2791 * of the Mac address. Possibly reverse?
2793 Value = *(u32 *) adapter->macaddr;
2794 WRITE_REG(HwRegs->LinkAddress0Low, Value, TRUE);
2795 /* also write the MAC address to the MAC. Endian is reversed. */
2796 WRITE_REG(HwRegs->MacAddressLow, ntohl(Value), TRUE);
2797 Value = (*(u16 *) & adapter->macaddr[4] & 0x0000FFFF);
2798 WRITE_REG(HwRegs->LinkAddress0High, Value | LINK_ADDRESS_ENABLE, TRUE);
2799 /* endian swap for the MAC (put high bytes in bits [31:16], swapped) */
2800 Value = ntohl(Value);
2801 WRITE_REG(HwRegs->MacAddressHigh, Value, TRUE);
2802 /* Link address 1 */
2803 WRITE_REG(HwRegs->LinkAddress1Low, 0, TRUE);
2804 WRITE_REG(HwRegs->LinkAddress1High, 0, TRUE);
2805 /* Link address 2 */
2806 WRITE_REG(HwRegs->LinkAddress2Low, 0, TRUE);
2807 WRITE_REG(HwRegs->LinkAddress2High, 0, TRUE);
2808 /* Link address 3 */
2809 WRITE_REG(HwRegs->LinkAddress3Low, 0, TRUE);
2810 WRITE_REG(HwRegs->LinkAddress3High, 0, TRUE);
2812 /* Enable MAC modules */
2813 WRITE_REG(HwRegs->MacConfig0, 0, TRUE);
2816 AxgMacReg1 = ( /* Enable XMT */
2817 AXGMAC_CFG1_XMT_EN |
2818 /* Enable receive */
2819 AXGMAC_CFG1_RCV_EN |
2820 /* short frame detection */
2821 AXGMAC_CFG1_SHORT_ASSERT |
2822 /* Verify frame length */
2823 AXGMAC_CFG1_CHECK_LEN |
2825 AXGMAC_CFG1_GEN_FCS |
2826 /* Pad frames to 64 bytes */
2827 AXGMAC_CFG1_PAD_64);
2829 if (adapter->XmtFcEnabled) {
2830 AxgMacReg1 |= AXGMAC_CFG1_XMT_PAUSE; /* Allow sending of pause */
2832 if (adapter->RcvFcEnabled) {
2833 AxgMacReg1 |= AXGMAC_CFG1_RCV_PAUSE; /* Enable detection of pause */
2836 WRITE_REG(HwRegs->MacConfig1, AxgMacReg1, TRUE);
2838 /* Set AXGMAC max frame length if jumbo. Not needed for standard MTU */
2839 if (adapter->JumboEnabled) {
2840 WRITE_REG(HwRegs->MacMaxFrameLen, AXGMAC_MAXFRAME_JUMBO, TRUE);
2843 * AMIIM Configuration Register -
2844 * The value placed in the AXGMAC_AMIIM_CFG_HALF_CLOCK portion
2845 * (bottom bits) of this register is used to determine the MDC frequency
2846 * as specified in the A-XGMAC Design Document. This value must not be
2847 * zero. The following value (62 or 0x3E) is based on our MAC transmit
2848 * clock frequency (MTCLK) of 312.5 MHz. Given a maximum MDIO clock
2849 * frequency of 2.5 MHz (see the PHY spec), we get:
2850 * 312.5/(2*(X+1)) < 2.5 ==> X = 62.
2851 * This value happens to be the default value for this register, so we
2852 * really don't have to do this.
2854 if (adapter->asictype == SAHARA_REV_B) {
2855 WRITE_REG(HwRegs->MacAmiimConfig, 0x0000001F, TRUE);
2857 WRITE_REG(HwRegs->MacAmiimConfig, 0x0000003E, TRUE);
2860 /* Power up and enable PHY and XAUI/XGXS/Serdes logic */
2861 WRITE_REG(HwRegs->LinkStatus,
2868 DBG_ERROR("After Power Up and enable PHY in sxg_initialize_link\n");
2871 * Per information given by Aeluros, wait 100 ms after removing reset.
2872 * It's not enough to wait for the self-clearing reset bit in reg 0 to
2877 /* Verify the PHY has come up by checking that the Reset bit has
2880 status = sxg_read_mdio_reg(adapter,
2881 MIIM_DEV_PHY_PMA, /* PHY PMA/PMD module */
2882 PHY_PMA_CONTROL1, /* PMA/PMD control register */
2884 DBG_ERROR("After sxg_read_mdio_reg Value[%x] fail=%x\n", Value,
2885 (Value & PMA_CONTROL1_RESET));
2886 if (status != STATUS_SUCCESS)
2887 return (STATUS_FAILURE);
2888 if (Value & PMA_CONTROL1_RESET) /* reset complete if bit is 0 */
2889 return (STATUS_FAILURE);
2891 /* The SERDES should be initialized by now - confirm */
2892 READ_REG(HwRegs->LinkStatus, Value);
2893 if (Value & LS_SERDES_DOWN) /* verify SERDES is initialized */
2894 return (STATUS_FAILURE);
2896 /* The XAUI link should also be up - confirm */
2897 if (!(Value & LS_XAUI_LINK_UP)) /* verify XAUI link is up */
2898 return (STATUS_FAILURE);
2900 /* Initialize the PHY */
2901 status = sxg_phy_init(adapter);
2902 if (status != STATUS_SUCCESS)
2903 return (STATUS_FAILURE);
2905 /* Enable the Link Alarm */
2907 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2908 * LASI_CONTROL - LASI control register
2909 * LASI_CTL_LS_ALARM_ENABLE - enable link alarm bit
2911 status = sxg_write_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2913 LASI_CTL_LS_ALARM_ENABLE);
2914 if (status != STATUS_SUCCESS)
2915 return (STATUS_FAILURE);
2917 /* XXXTODO - temporary - verify bit is set */
2919 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2920 * LASI_CONTROL - LASI control register
2922 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2926 if (status != STATUS_SUCCESS)
2927 return (STATUS_FAILURE);
2928 if (!(Value & LASI_CTL_LS_ALARM_ENABLE)) {
2929 DBG_ERROR("Error! LASI Control Alarm Enable bit not set!\n");
2931 /* Enable receive */
2932 MaxFrame = adapter->JumboEnabled ? JUMBOMAXFRAME : ETHERMAXFRAME;
2933 ConfigData = (RCV_CONFIG_ENABLE |
2934 RCV_CONFIG_ENPARSE |
2936 RCV_CONFIG_RCVPAUSE |
2939 RCV_CONFIG_HASH_16 |
2940 RCV_CONFIG_SOCKET | RCV_CONFIG_BUFSIZE(MaxFrame));
2942 if (adapter->asictype == SAHARA_REV_B) {
2943 ConfigData |= (RCV_CONFIG_HIPRICTL |
2944 RCV_CONFIG_NEWSTATUSFMT);
2946 WRITE_REG(HwRegs->RcvConfig, ConfigData, TRUE);
2948 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_ENABLE, TRUE);
2950 /* Mark the link as down. We'll get a link event when it comes up. */
2951 sxg_link_state(adapter, SXG_LINK_DOWN);
2953 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInitLnk",
2955 return (STATUS_SUCCESS);
2959 * sxg_phy_init - Initialize the PHY
2962 * adapter - A pointer to our adapter structure
2967 static int sxg_phy_init(struct adapter_t *adapter)
2970 struct phy_ucode *p;
2973 DBG_ERROR("ENTER %s\n", __func__);
2975 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2976 * 0xC205 - PHY ID register (?)
2977 * &Value - XXXTODO - add def
2979 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2982 if (status != STATUS_SUCCESS)
2983 return (STATUS_FAILURE);
2985 if (Value == 0x0012) {
2986 /* 0x0012 == AEL2005C PHY(?) - XXXTODO - add def */
2987 DBG_ERROR("AEL2005C PHY detected. Downloading PHY \
2990 /* Initialize AEL2005C PHY and download PHY microcode */
2991 for (p = PhyUcode; p->Addr != 0xFFFF; p++) {
2993 /* if address == 0, data == sleep time in ms */
2996 /* write the given data to the specified address */
2997 status = sxg_write_mdio_reg(adapter,
3003 if (status != STATUS_SUCCESS)
3004 return (STATUS_FAILURE);
3008 DBG_ERROR("EXIT %s\n", __func__);
3010 return (STATUS_SUCCESS);
3014 * sxg_link_event - Process a link event notification from the card
3017 * adapter - A pointer to our adapter structure
3022 static void sxg_link_event(struct adapter_t *adapter)
3024 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
3025 struct net_device *netdev = adapter->netdev;
3026 enum SXG_LINK_STATE LinkState;
3030 if (adapter->state == ADAPT_DOWN)
3032 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "LinkEvnt",
3034 DBG_ERROR("ENTER %s\n", __func__);
3036 /* Check the Link Status register. We should have a Link Alarm. */
3037 READ_REG(HwRegs->LinkStatus, Value);
3038 if (Value & LS_LINK_ALARM) {
3040 * We got a Link Status alarm. First, pause to let the
3041 * link state settle (it can bounce a number of times)
3045 /* Now clear the alarm by reading the LASI status register. */
3046 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
3047 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
3048 /* LASI status register */
3051 if (status != STATUS_SUCCESS) {
3052 DBG_ERROR("Error reading LASI Status MDIO register!\n");
3053 sxg_link_state(adapter, SXG_LINK_DOWN);
3057 * We used to assert that the LASI_LS_ALARM bit was set, as
3058 * it should be. But there appears to be cases during
3059 * initialization (when the PHY is reset and re-initialized)
3060 * when we get a link alarm, but the status bit is 0 when we
3061 * read it. Rather than trying to assure this never happens
3062 * (and nver being certain), just ignore it.
3064 * ASSERT(Value & LASI_STATUS_LS_ALARM);
3067 /* Now get and set the link state */
3068 LinkState = sxg_get_link_state(adapter);
3069 sxg_link_state(adapter, LinkState);
3070 DBG_ERROR("SXG: Link Alarm occurred. Link is %s\n",
3071 ((LinkState == SXG_LINK_UP) ? "UP" : "DOWN"));
3072 if (LinkState == SXG_LINK_UP) {
3073 netif_carrier_on(netdev);
3074 netif_tx_start_all_queues(netdev);
3076 netif_tx_stop_all_queues(netdev);
3077 netif_carrier_off(netdev);
3081 * XXXTODO - Assuming Link Attention is only being generated
3082 * for the Link Alarm pin (and not for a XAUI Link Status change)
3083 * , then it's impossible to get here. Yet we've gotten here
3084 * twice (under extreme conditions - bouncing the link up and
3085 * down many times a second). Needs further investigation.
3087 DBG_ERROR("SXG: sxg_link_event: Can't get here!\n");
3088 DBG_ERROR("SXG: Link Status == 0x%08X.\n", Value);
3091 DBG_ERROR("EXIT %s\n", __func__);
3096 * sxg_get_link_state - Determine if the link is up or down
3099 * adapter - A pointer to our adapter structure
3104 static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter)
3109 DBG_ERROR("ENTER %s\n", __func__);
3111 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "GetLink",
3115 * Per the Xenpak spec (and the IEEE 10Gb spec?), the link is up if
3116 * the following 3 bits (from 3 different MDIO registers) are all true.
3119 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
3120 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
3121 /* PMA/PMD Receive Signal Detect register */
3124 if (status != STATUS_SUCCESS)
3127 /* If PMA/PMD receive signal detect is 0, then the link is down */
3128 if (!(Value & PMA_RCV_DETECT))
3129 return (SXG_LINK_DOWN);
3131 /* MIIM_DEV_PHY_PCS - PHY PCS module */
3132 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PCS,
3133 /* PCS 10GBASE-R Status 1 register */
3134 PHY_PCS_10G_STATUS1,
3136 if (status != STATUS_SUCCESS)
3139 /* If PCS is not locked to receive blocks, then the link is down */
3140 if (!(Value & PCS_10B_BLOCK_LOCK))
3141 return (SXG_LINK_DOWN);
3143 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_XS,/* PHY XS module */
3144 /* XS Lane Status register */
3147 if (status != STATUS_SUCCESS)
3150 /* If XS transmit lanes are not aligned, then the link is down */
3151 if (!(Value & XS_LANE_ALIGN))
3152 return (SXG_LINK_DOWN);
3154 /* All 3 bits are true, so the link is up */
3155 DBG_ERROR("EXIT %s\n", __func__);
3157 return (SXG_LINK_UP);
3160 /* An error occurred reading an MDIO register. This shouldn't happen. */
3161 DBG_ERROR("Error reading an MDIO register!\n");
3163 return (SXG_LINK_DOWN);
3166 static void sxg_indicate_link_state(struct adapter_t *adapter,
3167 enum SXG_LINK_STATE LinkState)
3169 if (adapter->LinkState == SXG_LINK_UP) {
3170 DBG_ERROR("%s: LINK now UP, call netif_start_queue\n",
3172 netif_start_queue(adapter->netdev);
3174 DBG_ERROR("%s: LINK now DOWN, call netif_stop_queue\n",
3176 netif_stop_queue(adapter->netdev);
3181 * sxg_change_mtu - Change the Maximum Transfer Unit
3182 * * @returns 0 on success, negative on failure
3184 int sxg_change_mtu (struct net_device *netdev, int new_mtu)
3186 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(netdev);
3188 if (!((new_mtu == SXG_DEFAULT_MTU) || (new_mtu == SXG_JUMBO_MTU)))
3191 if(new_mtu == netdev->mtu)
3194 netdev->mtu = new_mtu;
3196 if (new_mtu == SXG_JUMBO_MTU) {
3197 adapter->JumboEnabled = TRUE;
3198 adapter->FrameSize = JUMBOMAXFRAME;
3199 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
3201 adapter->JumboEnabled = FALSE;
3202 adapter->FrameSize = ETHERMAXFRAME;
3203 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
3206 sxg_entry_halt(netdev);
3207 sxg_entry_open(netdev);
3212 * sxg_link_state - Set the link state and if necessary, indicate.
3213 * This routine the central point of processing for all link state changes.
3214 * Nothing else in the driver should alter the link state or perform
3215 * link state indications
3218 * adapter - A pointer to our adapter structure
3219 * LinkState - The link state
3224 static void sxg_link_state(struct adapter_t *adapter,
3225 enum SXG_LINK_STATE LinkState)
3227 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "LnkINDCT",
3228 adapter, LinkState, adapter->LinkState, adapter->State);
3230 DBG_ERROR("ENTER %s\n", __func__);
3233 * Hold the adapter lock during this routine. Maybe move
3234 * the lock to the caller.
3236 /* IMP TODO : Check if we can survive without taking this lock */
3237 // spin_lock(&adapter->AdapterLock);
3238 if (LinkState == adapter->LinkState) {
3239 /* Nothing changed.. */
3240 // spin_unlock(&adapter->AdapterLock);
3241 DBG_ERROR("EXIT #0 %s. Link status = %d\n",
3242 __func__, LinkState);
3245 /* Save the adapter state */
3246 adapter->LinkState = LinkState;
3248 /* Drop the lock and indicate link state */
3249 // spin_unlock(&adapter->AdapterLock);
3250 DBG_ERROR("EXIT #1 %s\n", __func__);
3252 sxg_indicate_link_state(adapter, LinkState);
3256 * sxg_write_mdio_reg - Write to a register on the MDIO bus
3259 * adapter - A pointer to our adapter structure
3260 * DevAddr - MDIO device number being addressed
3261 * RegAddr - register address for the specified MDIO device
3262 * Value - value to write to the MDIO register
3267 static int sxg_write_mdio_reg(struct adapter_t *adapter,
3268 u32 DevAddr, u32 RegAddr, u32 Value)
3270 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
3271 /* Address operation (written to MIIM field reg) */
3273 /* Write operation (written to MIIM field reg) */
3275 u32 Cmd;/* Command (written to MIIM command reg) */
3279 /* DBG_ERROR("ENTER %s\n", __func__); */
3281 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3284 /* Ensure values don't exceed field width */
3285 DevAddr &= 0x001F; /* 5-bit field */
3286 RegAddr &= 0xFFFF; /* 16-bit field */
3287 Value &= 0xFFFF; /* 16-bit field */
3289 /* Set MIIM field register bits for an MIIM address operation */
3290 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3291 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3292 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3293 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3295 /* Set MIIM field register bits for an MIIM write operation */
3296 WriteOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3297 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3298 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3299 (MIIM_OP_WRITE << AXGMAC_AMIIM_FIELD_OP_SHIFT) | Value;
3301 /* Set MIIM command register bits to execute an MIIM command */
3302 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3304 /* Reset the command register command bit (in case it's not 0) */
3305 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3307 /* MIIM write to set the address of the specified MDIO register */
3308 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3310 /* Write to MIIM Command Register to execute to address operation */
3311 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3313 /* Poll AMIIM Indicator register to wait for completion */
3314 Timeout = SXG_LINK_TIMEOUT;
3316 udelay(100); /* Timeout in 100us units */
3317 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3318 if (--Timeout == 0) {
3319 return (STATUS_FAILURE);
3321 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3323 /* Reset the command register command bit */
3324 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3326 /* MIIM write to set up an MDIO write operation */
3327 WRITE_REG(HwRegs->MacAmiimField, WriteOp, TRUE);
3329 /* Write to MIIM Command Register to execute the write operation */
3330 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3332 /* Poll AMIIM Indicator register to wait for completion */
3333 Timeout = SXG_LINK_TIMEOUT;
3335 udelay(100); /* Timeout in 100us units */
3336 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3337 if (--Timeout == 0) {
3338 return (STATUS_FAILURE);
3340 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3342 /* DBG_ERROR("EXIT %s\n", __func__); */
3344 return (STATUS_SUCCESS);
3348 * sxg_read_mdio_reg - Read a register on the MDIO bus
3351 * adapter - A pointer to our adapter structure
3352 * DevAddr - MDIO device number being addressed
3353 * RegAddr - register address for the specified MDIO device
3354 * pValue - pointer to where to put data read from the MDIO register
3359 static int sxg_read_mdio_reg(struct adapter_t *adapter,
3360 u32 DevAddr, u32 RegAddr, u32 *pValue)
3362 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
3363 u32 AddrOp; /* Address operation (written to MIIM field reg) */
3364 u32 ReadOp; /* Read operation (written to MIIM field reg) */
3365 u32 Cmd; /* Command (written to MIIM command reg) */
3369 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3371 DBG_ERROR("ENTER %s\n", __FUNCTION__);
3373 /* Ensure values don't exceed field width */
3374 DevAddr &= 0x001F; /* 5-bit field */
3375 RegAddr &= 0xFFFF; /* 16-bit field */
3377 /* Set MIIM field register bits for an MIIM address operation */
3378 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3379 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3380 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3381 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3383 /* Set MIIM field register bits for an MIIM read operation */
3384 ReadOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3385 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3386 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3387 (MIIM_OP_READ << AXGMAC_AMIIM_FIELD_OP_SHIFT);
3389 /* Set MIIM command register bits to execute an MIIM command */
3390 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3392 /* Reset the command register command bit (in case it's not 0) */
3393 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3395 /* MIIM write to set the address of the specified MDIO register */
3396 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3398 /* Write to MIIM Command Register to execute to address operation */
3399 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3401 /* Poll AMIIM Indicator register to wait for completion */
3402 Timeout = SXG_LINK_TIMEOUT;
3404 udelay(100); /* Timeout in 100us units */
3405 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3406 if (--Timeout == 0) {
3407 DBG_ERROR("EXIT %s with STATUS_FAILURE 1\n", __FUNCTION__);
3409 return (STATUS_FAILURE);
3411 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3413 /* Reset the command register command bit */
3414 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3416 /* MIIM write to set up an MDIO register read operation */
3417 WRITE_REG(HwRegs->MacAmiimField, ReadOp, TRUE);
3419 /* Write to MIIM Command Register to execute the read operation */
3420 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3422 /* Poll AMIIM Indicator register to wait for completion */
3423 Timeout = SXG_LINK_TIMEOUT;
3425 udelay(100); /* Timeout in 100us units */
3426 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3427 if (--Timeout == 0) {
3428 DBG_ERROR("EXIT %s with STATUS_FAILURE 2\n", __FUNCTION__);
3430 return (STATUS_FAILURE);
3432 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3434 /* Read the MDIO register data back from the field register */
3435 READ_REG(HwRegs->MacAmiimField, *pValue);
3436 *pValue &= 0xFFFF; /* data is in the lower 16 bits */
3438 DBG_ERROR("EXIT %s\n", __FUNCTION__);
3440 return (STATUS_SUCCESS);
3444 * Functions to obtain the CRC corresponding to the destination mac address.
3445 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
3447 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5
3448 * + x^4 + x^2 + x^1.
3450 * After the CRC for the 6 bytes is generated (but before the value is
3451 * complemented), we must then transpose the value and return bits 30-23.
3453 static u32 sxg_crc_table[256];/* Table of CRC's for all possible byte values */
3454 static u32 sxg_crc_init; /* Is table initialized */
3456 /* Contruct the CRC32 table */
3457 static void sxg_mcast_init_crc32(void)
3459 u32 c; /* CRC shit reg */
3460 u32 e = 0; /* Poly X-or pattern */
3461 int i; /* counter */
3462 int k; /* byte being shifted into crc */
3464 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
3466 for (i = 0; i < sizeof(p) / sizeof(int); i++) {
3467 e |= 1L << (31 - p[i]);
3470 for (i = 1; i < 256; i++) {
3472 for (k = 8; k; k--) {
3473 c = c & 1 ? (c >> 1) ^ e : c >> 1;
3475 sxg_crc_table[i] = c;
3480 * Return the MAC hast as described above.
3482 static unsigned char sxg_mcast_get_mac_hash(char *macaddr)
3487 unsigned char machash = 0;
3489 if (!sxg_crc_init) {
3490 sxg_mcast_init_crc32();
3494 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
3495 for (i = 0, p = macaddr; i < 6; ++p, ++i) {
3496 crc = (crc >> 8) ^ sxg_crc_table[(crc ^ *p) & 0xFF];
3499 /* Return bits 1-8, transposed */
3500 for (i = 1; i < 9; i++) {
3501 machash |= (((crc >> i) & 1) << (8 - i));
3507 static void sxg_mcast_set_mask(struct adapter_t *adapter)
3509 struct sxg_ucode_regs *sxg_regs = adapter->UcodeRegs;
3511 DBG_ERROR("%s ENTER (%s) MacFilter[%x] mask[%llx]\n", __FUNCTION__,
3512 adapter->netdev->name, (unsigned int)adapter->MacFilter,
3513 adapter->MulticastMask);
3515 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_PROMISC)) {
3517 * Turn on all multicast addresses. We have to do this for
3518 * promiscuous mode as well as ALLMCAST mode. It saves the
3519 * Microcode from having keep state about the MAC configuration
3521 /* DBG_ERROR("sxg: %s MacFilter = MAC_ALLMCAST | MAC_PROMISC\n \
3522 * SLUT MODE!!!\n",__func__);
3524 WRITE_REG(sxg_regs->McastLow, 0xFFFFFFFF, FLUSH);
3525 WRITE_REG(sxg_regs->McastHigh, 0xFFFFFFFF, FLUSH);
3526 /* DBG_ERROR("%s (%s) WRITE to slic_regs slic_mcastlow&high \
3527 * 0xFFFFFFFF\n",__func__, adapter->netdev->name);
3532 * Commit our multicast mast to the SLIC by writing to the
3533 * multicast address mask registers
3535 DBG_ERROR("%s (%s) WRITE mcastlow[%lx] mcasthigh[%lx]\n",
3536 __func__, adapter->netdev->name,
3537 ((ulong) (adapter->MulticastMask & 0xFFFFFFFF)),
3539 ((adapter->MulticastMask >> 32) & 0xFFFFFFFF)));
3541 WRITE_REG(sxg_regs->McastLow,
3542 (u32) (adapter->MulticastMask & 0xFFFFFFFF), FLUSH);
3543 WRITE_REG(sxg_regs->McastHigh,
3545 MulticastMask >> 32) & 0xFFFFFFFF), FLUSH);
3549 static void sxg_mcast_set_bit(struct adapter_t *adapter, char *address)
3551 unsigned char crcpoly;
3553 /* Get the CRC polynomial for the mac address */
3554 crcpoly = sxg_mcast_get_mac_hash(address);
3557 * We only have space on the SLIC for 64 entries. Lop
3558 * off the top two bits. (2^6 = 64)
3562 /* OR in the new bit into our 64 bit mask. */
3563 adapter->MulticastMask |= (u64) 1 << crcpoly;
3567 * Function takes MAC addresses from dev_mc_list and generates the Mask
3570 static void sxg_set_mcast_addr(struct adapter_t *adapter)
3572 struct dev_mc_list *mclist;
3573 struct net_device *dev = adapter->netdev;
3576 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_MCAST)) {
3577 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
3578 i++, mclist = mclist->next) {
3579 sxg_mcast_set_bit(adapter,mclist->da_addr);
3582 sxg_mcast_set_mask(adapter);
3585 static void sxg_mcast_set_list(struct net_device *dev)
3587 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
3590 if (dev->flags & IFF_PROMISC)
3591 adapter->MacFilter |= MAC_PROMISC;
3592 if (dev->flags & IFF_MULTICAST)
3593 adapter->MacFilter |= MAC_MCAST;
3594 if (dev->flags & IFF_ALLMULTI)
3595 adapter->MacFilter |= MAC_ALLMCAST;
3597 //XXX handle other flags as well
3598 sxg_set_mcast_addr(adapter);
3601 void sxg_free_sgl_buffers(struct adapter_t *adapter)
3603 struct list_entry *ple;
3604 struct sxg_scatter_gather *Sgl;
3606 while(!(IsListEmpty(&adapter->AllSglBuffers))) {
3607 ple = RemoveHeadList(&adapter->AllSglBuffers);
3608 Sgl = container_of(ple, struct sxg_scatter_gather, AllList);
3610 adapter->AllSglBufferCount--;
3614 void sxg_free_rcvblocks(struct adapter_t *adapter)
3617 void *temp_RcvBlock;
3618 struct list_entry *ple;
3619 struct sxg_rcv_block_hdr *RcvBlockHdr;
3620 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3621 ASSERT((adapter->state == SXG_STATE_INITIALIZING) ||
3622 (adapter->state == SXG_STATE_HALTING));
3623 while(!(IsListEmpty(&adapter->AllRcvBlocks))) {
3625 ple = RemoveHeadList(&adapter->AllRcvBlocks);
3626 RcvBlockHdr = container_of(ple, struct sxg_rcv_block_hdr, AllList);
3628 if(RcvBlockHdr->VirtualAddress) {
3629 temp_RcvBlock = RcvBlockHdr->VirtualAddress;
3631 for(i=0; i< SXG_RCV_DESCRIPTORS_PER_BLOCK;
3632 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3634 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
3635 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3639 pci_free_consistent(adapter->pcidev,
3640 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
3641 RcvBlockHdr->VirtualAddress,
3642 RcvBlockHdr->PhysicalAddress);
3643 adapter->AllRcvBlockCount--;
3645 ASSERT(adapter->AllRcvBlockCount == 0);
3646 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3649 void sxg_free_mcast_addrs(struct adapter_t *adapter)
3651 struct sxg_multicast_address *address;
3652 while(adapter->MulticastAddrs) {
3653 address = adapter->MulticastAddrs;
3654 adapter->MulticastAddrs = address->Next;
3658 adapter->MulticastMask= 0;
3661 void sxg_unmap_resources(struct adapter_t *adapter)
3663 if(adapter->HwRegs) {
3664 iounmap((void *)adapter->HwRegs);
3666 if(adapter->UcodeRegs) {
3667 iounmap((void *)adapter->UcodeRegs);
3670 ASSERT(adapter->AllRcvBlockCount == 0);
3671 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3678 * sxg_free_resources - Free everything allocated in SxgAllocateResources
3681 * adapter - A pointer to our adapter structure
3686 void sxg_free_resources(struct adapter_t *adapter)
3688 u32 RssIds, IsrCount;
3689 RssIds = SXG_RSS_CPU_COUNT(adapter);
3690 IsrCount = adapter->msi_enabled ? RssIds : 1;
3692 if (adapter->BasicAllocations == FALSE) {
3694 * No allocations have been made, including spinlocks,
3695 * or listhead initializations. Return.
3700 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
3701 sxg_free_rcvblocks(adapter);
3703 if (!(IsListEmpty(&adapter->AllSglBuffers))) {
3704 sxg_free_sgl_buffers(adapter);
3707 if (adapter->XmtRingZeroIndex) {
3708 pci_free_consistent(adapter->pcidev,
3710 adapter->XmtRingZeroIndex,
3711 adapter->PXmtRingZeroIndex);
3714 pci_free_consistent(adapter->pcidev,
3715 sizeof(u32) * IsrCount,
3716 adapter->Isr, adapter->PIsr);
3719 if (adapter->EventRings) {
3720 pci_free_consistent(adapter->pcidev,
3721 sizeof(struct sxg_event_ring) * RssIds,
3722 adapter->EventRings, adapter->PEventRings);
3724 if (adapter->RcvRings) {
3725 pci_free_consistent(adapter->pcidev,
3726 sizeof(struct sxg_rcv_ring) * 1,
3728 adapter->PRcvRings);
3729 adapter->RcvRings = NULL;
3732 if(adapter->XmtRings) {
3733 pci_free_consistent(adapter->pcidev,
3734 sizeof(struct sxg_xmt_ring) * 1,
3736 adapter->PXmtRings);
3737 adapter->XmtRings = NULL;
3740 if (adapter->ucode_stats) {
3741 pci_unmap_single(adapter->pcidev,
3742 sizeof(struct sxg_ucode_stats),
3743 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
3744 adapter->ucode_stats = NULL;
3748 /* Unmap register spaces */
3749 sxg_unmap_resources(adapter);
3751 sxg_free_mcast_addrs(adapter);
3753 adapter->BasicAllocations = FALSE;
3758 * sxg_allocate_complete -
3760 * This routine is called when a memory allocation has completed.
3763 * struct adapter_t * - Our adapter structure
3764 * VirtualAddress - Memory virtual address
3765 * PhysicalAddress - Memory physical address
3766 * Length - Length of memory allocated (or 0)
3767 * Context - The type of buffer allocated
3772 static int sxg_allocate_complete(struct adapter_t *adapter,
3773 void *VirtualAddress,
3774 dma_addr_t PhysicalAddress,
3775 u32 Length, enum sxg_buffer_type Context)
3778 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocCmp",
3779 adapter, VirtualAddress, Length, Context);
3780 ASSERT(atomic_read(&adapter->pending_allocations));
3781 atomic_dec(&adapter->pending_allocations);
3785 case SXG_BUFFER_TYPE_RCV:
3786 status = sxg_allocate_rcvblock_complete(adapter,
3788 PhysicalAddress, Length);
3790 case SXG_BUFFER_TYPE_SGL:
3791 sxg_allocate_sgl_buffer_complete(adapter, (struct sxg_scatter_gather *)
3793 PhysicalAddress, Length);
3796 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocCmp",
3797 adapter, VirtualAddress, Length, Context);
3803 * sxg_allocate_buffer_memory - Shared memory allocation routine used for
3804 * synchronous and asynchronous buffer allocations
3807 * adapter - A pointer to our adapter structure
3808 * Size - block size to allocate
3809 * BufferType - Type of buffer to allocate
3814 static int sxg_allocate_buffer_memory(struct adapter_t *adapter,
3815 u32 Size, enum sxg_buffer_type BufferType)
3821 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocMem",
3822 adapter, Size, BufferType, 0);
3824 * Grab the adapter lock and check the state. If we're in anything other
3825 * than INITIALIZING or RUNNING state, fail. This is to prevent
3826 * allocations in an improper driver state
3829 atomic_inc(&adapter->pending_allocations);
3831 if(BufferType != SXG_BUFFER_TYPE_SGL)
3832 Buffer = pci_alloc_consistent(adapter->pcidev, Size, &pBuffer);
3834 Buffer = kzalloc(Size, GFP_ATOMIC);
3835 pBuffer = (dma_addr_t)NULL;
3837 if (Buffer == NULL) {
3839 * Decrement the AllocationsPending count while holding
3840 * the lock. Pause processing relies on this
3842 atomic_dec(&adapter->pending_allocations);
3843 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlcMemF1",
3844 adapter, Size, BufferType, 0);
3845 return (STATUS_RESOURCES);
3847 status = sxg_allocate_complete(adapter, Buffer, pBuffer, Size, BufferType);
3849 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocMem",
3850 adapter, Size, BufferType, status);
3855 * sxg_allocate_rcvblock_complete - Complete a receive descriptor
3859 * adapter - A pointer to our adapter structure
3860 * RcvBlock - receive block virtual address
3861 * PhysicalAddress - Physical address
3862 * Length - Memory length
3866 static int sxg_allocate_rcvblock_complete(struct adapter_t *adapter,
3868 dma_addr_t PhysicalAddress,
3872 u32 BufferSize = adapter->ReceiveBufferSize;
3874 void *temp_RcvBlock;
3875 struct sxg_rcv_block_hdr *RcvBlockHdr;
3876 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3877 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
3878 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
3880 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlRcvBlk",
3881 adapter, RcvBlock, Length, 0);
3882 if (RcvBlock == NULL) {
3885 memset(RcvBlock, 0, Length);
3886 ASSERT((BufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
3887 (BufferSize == SXG_RCV_JUMBO_BUFFER_SIZE));
3888 ASSERT(Length == SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE));
3890 * First, initialize the contained pool of receive data buffers.
3891 * This initialization requires NBL/NB/MDL allocations, if any of them
3892 * fail, free the block and return without queueing the shared memory
3894 //RcvDataBuffer = RcvBlock;
3895 temp_RcvBlock = RcvBlock;
3896 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
3897 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3898 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *)
3900 /* For FREE macro assertion */
3901 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
3902 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
3903 if (RcvDataBufferHdr->SxgDumbRcvPacket == NULL)
3909 * Place this entire block of memory on the AllRcvBlocks queue so it
3913 RcvBlockHdr = (struct sxg_rcv_block_hdr *) ((unsigned char *)RcvBlock +
3914 SXG_RCV_BLOCK_HDR_OFFSET(SXG_RCV_DATA_HDR_SIZE));
3915 RcvBlockHdr->VirtualAddress = RcvBlock;
3916 RcvBlockHdr->PhysicalAddress = PhysicalAddress;
3917 spin_lock(&adapter->RcvQLock);
3918 adapter->AllRcvBlockCount++;
3919 InsertTailList(&adapter->AllRcvBlocks, &RcvBlockHdr->AllList);
3920 spin_unlock(&adapter->RcvQLock);
3922 /* Now free the contained receive data buffers that we
3923 * initialized above */
3924 temp_RcvBlock = RcvBlock;
3925 for (i = 0, Paddr = PhysicalAddress;
3926 i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
3927 i++, Paddr += SXG_RCV_DATA_HDR_SIZE,
3928 temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3930 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
3931 spin_lock(&adapter->RcvQLock);
3932 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
3933 spin_unlock(&adapter->RcvQLock);
3936 /* Locate the descriptor block and put it on a separate free queue */
3937 RcvDescriptorBlock =
3938 (struct sxg_rcv_descriptor_block *) ((unsigned char *)RcvBlock +
3939 SXG_RCV_DESCRIPTOR_BLOCK_OFFSET
3940 (SXG_RCV_DATA_HDR_SIZE));
3941 RcvDescriptorBlockHdr =
3942 (struct sxg_rcv_descriptor_block_hdr *) ((unsigned char *)RcvBlock +
3943 SXG_RCV_DESCRIPTOR_BLOCK_HDR_OFFSET
3944 (SXG_RCV_DATA_HDR_SIZE));
3945 RcvDescriptorBlockHdr->VirtualAddress = RcvDescriptorBlock;
3946 RcvDescriptorBlockHdr->PhysicalAddress = Paddr;
3947 spin_lock(&adapter->RcvQLock);
3948 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter, RcvDescriptorBlockHdr);
3949 spin_unlock(&adapter->RcvQLock);
3950 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlRBlk",
3951 adapter, RcvBlock, Length, 0);
3952 return STATUS_SUCCESS;
3954 /* Free any allocated resources */
3956 temp_RcvBlock = RcvBlock;
3957 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
3958 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3960 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
3961 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3963 pci_free_consistent(adapter->pcidev,
3964 Length, RcvBlock, PhysicalAddress);
3966 DBG_ERROR("%s: OUT OF RESOURCES\n", __func__);
3967 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "RcvAFail",
3968 adapter, adapter->FreeRcvBufferCount,
3969 adapter->FreeRcvBlockCount, adapter->AllRcvBlockCount);
3970 adapter->Stats.NoMem++;
3971 /* As allocation failed, free all previously allocated blocks..*/
3972 //sxg_free_rcvblocks(adapter);
3974 return STATUS_RESOURCES;
3978 * sxg_allocate_sgl_buffer_complete - Complete a SGL buffer allocation
3981 * adapter - A pointer to our adapter structure
3982 * SxgSgl - struct sxg_scatter_gather buffer
3983 * PhysicalAddress - Physical address
3984 * Length - Memory length
3988 static void sxg_allocate_sgl_buffer_complete(struct adapter_t *adapter,
3989 struct sxg_scatter_gather *SxgSgl,
3990 dma_addr_t PhysicalAddress,
3993 unsigned long sgl_flags;
3994 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlSglCmp",
3995 adapter, SxgSgl, Length, 0);
3996 spin_lock_irqsave(&adapter->SglQLock, sgl_flags);
3997 adapter->AllSglBufferCount++;
3998 /* PhysicalAddress; */
3999 SxgSgl->PhysicalAddress = PhysicalAddress;
4000 /* Initialize backpointer once */
4001 SxgSgl->adapter = adapter;
4002 InsertTailList(&adapter->AllSglBuffers, &SxgSgl->AllList);
4003 spin_unlock_irqrestore(&adapter->SglQLock, sgl_flags);
4004 SxgSgl->State = SXG_BUFFER_BUSY;
4005 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL);
4006 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlSgl",
4007 adapter, SxgSgl, Length, 0);
4011 static int sxg_adapter_set_hwaddr(struct adapter_t *adapter)
4014 * DBG_ERROR ("%s ENTER card->config_set[%x] port[%d] physport[%d] \
4015 * funct#[%d]\n", __func__, card->config_set,
4016 * adapter->port, adapter->physport, adapter->functionnumber);
4018 * sxg_dbg_macaddrs(adapter);
4020 /* DBG_ERROR ("%s AFTER copying from config.macinfo into currmacaddr\n",
4024 /* sxg_dbg_macaddrs(adapter); */
4026 struct net_device * dev = adapter->netdev;
4029 printk("sxg: Dev is Null\n");
4032 DBG_ERROR("%s ENTER (%s)\n", __FUNCTION__, adapter->netdev->name);
4034 if (netif_running(dev)) {
4041 if (!(adapter->currmacaddr[0] ||
4042 adapter->currmacaddr[1] ||
4043 adapter->currmacaddr[2] ||
4044 adapter->currmacaddr[3] ||
4045 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
4046 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
4048 if (adapter->netdev) {
4049 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
4050 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
4052 /* DBG_ERROR ("%s EXIT port %d\n", __func__, adapter->port); */
4053 sxg_dbg_macaddrs(adapter);
4059 static int sxg_mac_set_address(struct net_device *dev, void *ptr)
4061 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
4062 struct sockaddr *addr = ptr;
4064 DBG_ERROR("%s ENTER (%s)\n", __func__, adapter->netdev->name);
4066 if (netif_running(dev)) {
4072 DBG_ERROR("sxg: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
4073 __func__, adapter->netdev->name, adapter->currmacaddr[0],
4074 adapter->currmacaddr[1], adapter->currmacaddr[2],
4075 adapter->currmacaddr[3], adapter->currmacaddr[4],
4076 adapter->currmacaddr[5]);
4077 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
4078 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
4079 DBG_ERROR("sxg: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
4080 __func__, adapter->netdev->name, adapter->currmacaddr[0],
4081 adapter->currmacaddr[1], adapter->currmacaddr[2],
4082 adapter->currmacaddr[3], adapter->currmacaddr[4],
4083 adapter->currmacaddr[5]);
4085 sxg_config_set(adapter, TRUE);
4091 * SXG DRIVER FUNCTIONS (below)
4093 * sxg_initialize_adapter - Initialize adapter
4096 * adapter - A pointer to our adapter structure
4100 static int sxg_initialize_adapter(struct adapter_t *adapter)
4102 u32 RssIds, IsrCount;
4105 int sxg_rcv_ring_size = SXG_RCV_RING_SIZE;
4107 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitAdpt",
4110 RssIds = 1; /* XXXTODO SXG_RSS_CPU_COUNT(adapter); */
4111 IsrCount = adapter->msi_enabled ? RssIds : 1;
4114 * Sanity check SXG_UCODE_REGS structure definition to
4115 * make sure the length is correct
4117 ASSERT(sizeof(struct sxg_ucode_regs) == SXG_REGISTER_SIZE_PER_CPU);
4119 /* Disable interrupts */
4120 SXG_DISABLE_ALL_INTERRUPTS(adapter);
4123 ASSERT((adapter->FrameSize == ETHERMAXFRAME) ||
4124 (adapter->FrameSize == JUMBOMAXFRAME));
4125 WRITE_REG(adapter->UcodeRegs[0].LinkMtu, adapter->FrameSize, TRUE);
4127 /* Set event ring base address and size */
4128 WRITE_REG64(adapter,
4129 adapter->UcodeRegs[0].EventBase, adapter->PEventRings, 0);
4130 WRITE_REG(adapter->UcodeRegs[0].EventSize, EVENT_RING_SIZE, TRUE);
4132 /* Per-ISR initialization */
4133 for (i = 0; i < IsrCount; i++) {
4135 /* Set interrupt status pointer */
4136 Addr = adapter->PIsr + (i * sizeof(u32));
4137 WRITE_REG64(adapter, adapter->UcodeRegs[i].Isp, Addr, i);
4140 /* XMT ring zero index */
4141 WRITE_REG64(adapter,
4142 adapter->UcodeRegs[0].SPSendIndex,
4143 adapter->PXmtRingZeroIndex, 0);
4145 /* Per-RSS initialization */
4146 for (i = 0; i < RssIds; i++) {
4147 /* Release all event ring entries to the Microcode */
4148 WRITE_REG(adapter->UcodeRegs[i].EventRelease, EVENT_RING_SIZE,
4152 /* Transmit ring base and size */
4153 WRITE_REG64(adapter,
4154 adapter->UcodeRegs[0].XmtBase, adapter->PXmtRings, 0);
4155 WRITE_REG(adapter->UcodeRegs[0].XmtSize, SXG_XMT_RING_SIZE, TRUE);
4157 /* Receive ring base and size */
4158 WRITE_REG64(adapter,
4159 adapter->UcodeRegs[0].RcvBase, adapter->PRcvRings, 0);
4160 if (adapter->JumboEnabled == TRUE)
4161 sxg_rcv_ring_size = SXG_JUMBO_RCV_RING_SIZE;
4162 WRITE_REG(adapter->UcodeRegs[0].RcvSize, sxg_rcv_ring_size, TRUE);
4164 /* Populate the card with receive buffers */
4165 sxg_stock_rcv_buffers(adapter);
4168 * Initialize checksum offload capabilities. At the moment we always
4169 * enable IP and TCP receive checksums on the card. Depending on the
4170 * checksum configuration specified by the user, we can choose to
4171 * report or ignore the checksum information provided by the card.
4173 WRITE_REG(adapter->UcodeRegs[0].ReceiveChecksum,
4174 SXG_RCV_TCP_CSUM_ENABLED | SXG_RCV_IP_CSUM_ENABLED, TRUE);
4176 adapter->flags |= (SXG_RCV_TCP_CSUM_ENABLED | SXG_RCV_IP_CSUM_ENABLED );
4178 /* Initialize the MAC, XAUI */
4179 DBG_ERROR("sxg: %s ENTER sxg_initialize_link\n", __func__);
4180 status = sxg_initialize_link(adapter);
4181 DBG_ERROR("sxg: %s EXIT sxg_initialize_link status[%x]\n", __func__,
4183 if (status != STATUS_SUCCESS) {
4187 * Initialize Dead to FALSE.
4188 * SlicCheckForHang or SlicDumpThread will take it from here.
4190 adapter->Dead = FALSE;
4191 adapter->PingOutstanding = FALSE;
4192 adapter->XmtFcEnabled = TRUE;
4193 adapter->RcvFcEnabled = TRUE;
4195 adapter->State = SXG_STATE_RUNNING;
4197 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInit",
4199 return (STATUS_SUCCESS);
4203 * sxg_fill_descriptor_block - Populate a descriptor block and give it to
4204 * the card. The caller should hold the RcvQLock
4207 * adapter - A pointer to our adapter structure
4208 * RcvDescriptorBlockHdr - Descriptor block to fill
4213 static int sxg_fill_descriptor_block(struct adapter_t *adapter,
4214 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr)
4217 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4218 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
4219 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
4220 struct sxg_cmd *RingDescriptorCmd;
4221 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
4223 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "FilBlk",
4224 adapter, adapter->RcvBuffersOnCard,
4225 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4227 ASSERT(RcvDescriptorBlockHdr);
4230 * If we don't have the resources to fill the descriptor block,
4233 if ((adapter->FreeRcvBufferCount < SXG_RCV_DESCRIPTORS_PER_BLOCK) ||
4234 SXG_RING_FULL(RcvRingInfo)) {
4235 adapter->Stats.NoMem++;
4236 return (STATUS_FAILURE);
4238 /* Get a ring descriptor command */
4239 SXG_GET_CMD(RingZero,
4240 RcvRingInfo, RingDescriptorCmd, RcvDescriptorBlockHdr);
4241 ASSERT(RingDescriptorCmd);
4242 RcvDescriptorBlockHdr->State = SXG_BUFFER_ONCARD;
4243 RcvDescriptorBlock = (struct sxg_rcv_descriptor_block *)
4244 RcvDescriptorBlockHdr->VirtualAddress;
4246 /* Fill in the descriptor block */
4247 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK; i++) {
4248 SXG_GET_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
4249 ASSERT(RcvDataBufferHdr);
4250 // ASSERT(RcvDataBufferHdr->SxgDumbRcvPacket);
4251 if (!RcvDataBufferHdr->SxgDumbRcvPacket) {
4252 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr,
4253 adapter->ReceiveBufferSize);
4254 if(RcvDataBufferHdr->skb)
4255 RcvDataBufferHdr->SxgDumbRcvPacket =
4256 RcvDataBufferHdr->skb;
4260 SXG_REINIATIALIZE_PACKET(RcvDataBufferHdr->SxgDumbRcvPacket);
4261 RcvDataBufferHdr->State = SXG_BUFFER_ONCARD;
4262 RcvDescriptorBlock->Descriptors[i].VirtualAddress =
4263 (void *)RcvDataBufferHdr;
4265 RcvDescriptorBlock->Descriptors[i].PhysicalAddress =
4266 RcvDataBufferHdr->PhysicalAddress;
4268 /* Add the descriptor block to receive descriptor ring 0 */
4269 RingDescriptorCmd->Sgl = RcvDescriptorBlockHdr->PhysicalAddress;
4272 * RcvBuffersOnCard is not protected via the receive lock (see
4273 * sxg_process_event_queue) We don't want to grap a lock every time a
4274 * buffer is returned to us, so we use atomic interlocked functions
4277 adapter->RcvBuffersOnCard += SXG_RCV_DESCRIPTORS_PER_BLOCK;
4279 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DscBlk",
4280 RcvDescriptorBlockHdr,
4281 RingDescriptorCmd, RcvRingInfo->Head, RcvRingInfo->Tail);
4283 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 1, true);
4284 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlk",
4285 adapter, adapter->RcvBuffersOnCard,
4286 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4287 return (STATUS_SUCCESS);
4289 for (; i >= 0 ; i--) {
4290 if (RcvDescriptorBlock->Descriptors[i].VirtualAddress) {
4291 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *)
4292 RcvDescriptorBlock->Descriptors[i].
4294 RcvDescriptorBlock->Descriptors[i].PhysicalAddress =
4296 RcvDescriptorBlock->Descriptors[i].VirtualAddress=NULL;
4298 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
4300 RcvDescriptorBlockHdr->State = SXG_BUFFER_FREE;
4301 SXG_RETURN_CMD(RingZero, RcvRingInfo, RingDescriptorCmd,
4302 RcvDescriptorBlockHdr);
4308 * sxg_stock_rcv_buffers - Stock the card with receive buffers
4311 * adapter - A pointer to our adapter structure
4316 static void sxg_stock_rcv_buffers(struct adapter_t *adapter)
4318 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
4319 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
4320 int sxg_min_rcv_data_buffers = SXG_MIN_RCV_DATA_BUFFERS;
4322 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "StockBuf",
4323 adapter, adapter->RcvBuffersOnCard,
4324 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4326 * First, see if we've got less than our minimum threshold of
4327 * receive buffers, there isn't an allocation in progress, and
4328 * we haven't exceeded our maximum.. get another block of buffers
4329 * None of this needs to be SMP safe. It's round numbers.
4331 if (adapter->JumboEnabled == TRUE)
4332 sxg_min_rcv_data_buffers = SXG_MIN_JUMBO_RCV_DATA_BUFFERS;
4333 if ((adapter->FreeRcvBufferCount < sxg_min_rcv_data_buffers) &&
4334 (adapter->AllRcvBlockCount < SXG_MAX_RCV_BLOCKS) &&
4335 (atomic_read(&adapter->pending_allocations) == 0)) {
4336 sxg_allocate_buffer_memory(adapter,
4338 (SXG_RCV_DATA_HDR_SIZE),
4339 SXG_BUFFER_TYPE_RCV);
4341 /* Now grab the RcvQLock lock and proceed */
4342 spin_lock(&adapter->RcvQLock);
4343 if (adapter->JumboEnabled)
4344 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
4345 while (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
4346 struct list_entry *_ple;
4348 /* Get a descriptor block */
4349 RcvDescriptorBlockHdr = NULL;
4350 if (adapter->FreeRcvBlockCount) {
4351 _ple = RemoveHeadList(&adapter->FreeRcvBlocks);
4352 RcvDescriptorBlockHdr =
4353 container_of(_ple, struct sxg_rcv_descriptor_block_hdr,
4355 adapter->FreeRcvBlockCount--;
4356 RcvDescriptorBlockHdr->State = SXG_BUFFER_BUSY;
4359 if (RcvDescriptorBlockHdr == NULL) {
4361 adapter->Stats.NoMem++;
4364 /* Fill in the descriptor block and give it to the card */
4365 if (sxg_fill_descriptor_block(adapter, RcvDescriptorBlockHdr) ==
4367 /* Free the descriptor block */
4368 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4369 RcvDescriptorBlockHdr);
4373 spin_unlock(&adapter->RcvQLock);
4374 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlks",
4375 adapter, adapter->RcvBuffersOnCard,
4376 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4380 * sxg_complete_descriptor_blocks - Return descriptor blocks that have been
4381 * completed by the microcode
4384 * adapter - A pointer to our adapter structure
4385 * Index - Where the microcode is up to
4390 static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
4391 unsigned char Index)
4393 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
4394 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4395 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
4396 struct sxg_cmd *RingDescriptorCmd;
4398 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlks",
4399 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4401 /* Now grab the RcvQLock lock and proceed */
4402 spin_lock(&adapter->RcvQLock);
4403 ASSERT(Index != RcvRingInfo->Tail);
4404 while (sxg_ring_get_forward_diff(RcvRingInfo, Index,
4405 RcvRingInfo->Tail) > 3) {
4407 * Locate the current Cmd (ring descriptor entry), and
4408 * associated receive descriptor block, and advance
4411 SXG_RETURN_CMD(RingZero,
4413 RingDescriptorCmd, RcvDescriptorBlockHdr);
4414 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlk",
4415 RcvRingInfo->Head, RcvRingInfo->Tail,
4416 RingDescriptorCmd, RcvDescriptorBlockHdr);
4418 /* Clear the SGL field */
4419 RingDescriptorCmd->Sgl = 0;
4421 * Attempt to refill it and hand it right back to the
4422 * card. If we fail to refill it, free the descriptor block
4423 * header. The card will be restocked later via the
4424 * RcvBuffersOnCard test
4426 if (sxg_fill_descriptor_block(adapter,
4427 RcvDescriptorBlockHdr) == STATUS_FAILURE)
4428 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4429 RcvDescriptorBlockHdr);
4431 spin_unlock(&adapter->RcvQLock);
4432 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XCRBlks",
4433 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4437 * Read the statistics which the card has been maintaining.
4439 void sxg_collect_statistics(struct adapter_t *adapter)
4441 if(adapter->ucode_stats)
4442 WRITE_REG64(adapter, adapter->UcodeRegs[0].GetUcodeStats,
4443 adapter->pucode_stats, 0);
4444 adapter->stats.rx_fifo_errors = adapter->ucode_stats->ERDrops;
4445 adapter->stats.rx_over_errors = adapter->ucode_stats->NBDrops;
4446 adapter->stats.tx_fifo_errors = adapter->ucode_stats->XDrops;
4449 static struct net_device_stats *sxg_get_stats(struct net_device * dev)
4451 struct adapter_t *adapter = netdev_priv(dev);
4453 sxg_collect_statistics(adapter);
4454 return (&adapter->stats);
4457 static void sxg_watchdog(unsigned long data)
4459 struct adapter_t *adapter = (struct adapter_t *) data;
4461 if (adapter->state != ADAPT_DOWN) {
4462 sxg_link_event(adapter);
4463 /* Reset the timer */
4464 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4468 static void sxg_update_link_status (struct work_struct *work)
4470 struct adapter_t *adapter = (struct adapter_t *)container_of
4471 (work, struct adapter_t, update_link_status);
4472 if (likely(adapter->link_status_changed)) {
4473 sxg_link_event(adapter);
4474 adapter->link_status_changed = 0;
4478 static struct pci_driver sxg_driver = {
4479 .name = sxg_driver_name,
4480 .id_table = sxg_pci_tbl,
4481 .probe = sxg_entry_probe,
4482 .remove = sxg_entry_remove,
4483 #if SXG_POWER_MANAGEMENT_ENABLED
4484 .suspend = sxgpm_suspend,
4485 .resume = sxgpm_resume,
4487 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
4490 static int __init sxg_module_init(void)
4497 return pci_register_driver(&sxg_driver);
4500 static void __exit sxg_module_cleanup(void)
4502 pci_unregister_driver(&sxg_driver);
4505 module_init(sxg_module_init);
4506 module_exit(sxg_module_cleanup);