blob: 287edb7b86f1876d3988ef67310d7366fbdc3c7f [file] [log] [blame]
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001/**************************************************************************
2 *
3 * Copyright (C) 2000-2008 Alacritech, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
15 *
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
27 * SUCH DAMAGE.
28 *
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.
32 *
Mithlesh Thukral0d414722009-01-19 20:29:59 +053033 * Parts developed by LinSysSoft Sahara team
34 *
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -070035 **************************************************************************/
36
37/*
38 * FILENAME: sxg.c
39 *
40 * The SXG driver for Alacritech's 10Gbe products.
41 *
42 * NOTE: This is the standard, non-accelerated version of Alacritech's
43 * IS-NIC driver.
44 */
45
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>
Mithlesh Thukral0d414722009-01-19 20:29:59 +053066#include <linux/ip.h>
67#include <linux/in.h>
68#include <linux/tcp.h>
69#include <linux/ipv6.h>
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -070070
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -070071#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
75#define VPCI 0
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -070076#define ATK_DEBUG 1
77
78#include "sxg_os.h"
79#include "sxghw.h"
80#include "sxghif.h"
81#include "sxg.h"
82#include "sxgdbg.h"
83
84#include "sxgphycode.h"
Mithlesh Thukrala3915dd2009-01-19 20:28:13 +053085#define SXG_UCODE_DBG 0 /* Turn on for debugging */
86#ifdef SXG_UCODE_DBG
87#include "saharadbgdownload.c"
88#include "saharadbgdownloadB.c"
89#else
90#include "saharadownload.c"
91#include "saharadownloadB.c"
92#endif
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -070093
J.R. Mauro73b07062008-10-28 18:42:02 -040094static int sxg_allocate_buffer_memory(struct adapter_t *adapter, u32 Size,
Mithlesh Thukral942798b2009-01-05 21:14:34 +053095 enum sxg_buffer_type BufferType);
Mithlesh Thukral0d414722009-01-19 20:29:59 +053096static int sxg_allocate_rcvblock_complete(struct adapter_t *adapter,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +053097 void *RcvBlock,
98 dma_addr_t PhysicalAddress,
99 u32 Length);
J.R. Mauro73b07062008-10-28 18:42:02 -0400100static void sxg_allocate_sgl_buffer_complete(struct adapter_t *adapter,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530101 struct sxg_scatter_gather *SxgSgl,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400102 dma_addr_t PhysicalAddress,
103 u32 Length);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700104
105static void sxg_mcast_init_crc32(void);
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530106static int sxg_entry_open(struct net_device *dev);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530107static int sxg_second_open(struct net_device * dev);
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530108static int sxg_entry_halt(struct net_device *dev);
109static int sxg_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
110static int sxg_send_packets(struct sk_buff *skb, struct net_device *dev);
J.R. Mauro73b07062008-10-28 18:42:02 -0400111static int sxg_transmit_packet(struct adapter_t *adapter, struct sk_buff *skb);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530112static int sxg_dumb_sgl(struct sxg_x64_sgl *pSgl,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530113 struct sxg_scatter_gather *SxgSgl);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700114
Mithlesh Thukralb62a2942009-01-30 20:19:03 +0530115static void sxg_handle_interrupt(struct adapter_t *adapter, int *work_done,
116 int budget);
117static void sxg_interrupt(struct adapter_t *adapter);
118static int sxg_poll(struct napi_struct *napi, int budget);
J.R. Mauro73b07062008-10-28 18:42:02 -0400119static int sxg_process_isr(struct adapter_t *adapter, u32 MessageId);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +0530120static u32 sxg_process_event_queue(struct adapter_t *adapter, u32 RssId,
121 int *sxg_napi_continue, int *work_done, int budget);
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +0530122static void sxg_complete_slow_send(struct adapter_t *adapter);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530123static struct sk_buff *sxg_slow_receive(struct adapter_t *adapter,
124 struct sxg_event *Event);
J.R. Mauro73b07062008-10-28 18:42:02 -0400125static void sxg_process_rcv_error(struct adapter_t *adapter, u32 ErrorStatus);
126static bool sxg_mac_filter(struct adapter_t *adapter,
127 struct ether_header *EtherHdr, ushort length);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +0530128static struct net_device_stats *sxg_get_stats(struct net_device * dev);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530129void sxg_free_resources(struct adapter_t *adapter);
130void sxg_free_rcvblocks(struct adapter_t *adapter);
131void sxg_free_sgl_buffers(struct adapter_t *adapter);
132void sxg_unmap_resources(struct adapter_t *adapter);
133void sxg_free_mcast_addrs(struct adapter_t *adapter);
134void sxg_collect_statistics(struct adapter_t *adapter);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +0530135static int sxg_register_interrupt(struct adapter_t *adapter);
136static void sxg_remove_isr(struct adapter_t *adapter);
137static irqreturn_t sxg_isr(int irq, void *dev_id);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530138
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -0700139#define XXXTODO 0
140
Greg Kroah-Hartman96e70882009-01-21 08:17:45 -0800141#if XXXTODO
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530142static int sxg_mac_set_address(struct net_device *dev, void *ptr);
Greg Kroah-Hartman96e70882009-01-21 08:17:45 -0800143#endif
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530144static void sxg_mcast_set_list(struct net_device *dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700145
Mithlesh Thukral54aed112009-01-19 20:27:17 +0530146static int sxg_adapter_set_hwaddr(struct adapter_t *adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700147
J.R. Mauro73b07062008-10-28 18:42:02 -0400148static int sxg_initialize_adapter(struct adapter_t *adapter);
149static void sxg_stock_rcv_buffers(struct adapter_t *adapter);
150static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400151 unsigned char Index);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +0530152int sxg_change_mtu (struct net_device *netdev, int new_mtu);
J.R. Mauro73b07062008-10-28 18:42:02 -0400153static int sxg_initialize_link(struct adapter_t *adapter);
154static int sxg_phy_init(struct adapter_t *adapter);
155static void sxg_link_event(struct adapter_t *adapter);
156static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530157static void sxg_link_state(struct adapter_t *adapter,
158 enum SXG_LINK_STATE LinkState);
J.R. Mauro73b07062008-10-28 18:42:02 -0400159static int sxg_write_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400160 u32 DevAddr, u32 RegAddr, u32 Value);
J.R. Mauro73b07062008-10-28 18:42:02 -0400161static int sxg_read_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400162 u32 DevAddr, u32 RegAddr, u32 *pValue);
Mithlesh Thukralb040b072009-01-28 07:08:11 +0530163static void sxg_set_mcast_addr(struct adapter_t *adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700164
165static unsigned int sxg_first_init = 1;
166static char *sxg_banner =
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530167 "Alacritech SLIC Technology(tm) Server and Storage \
168 10Gbe Accelerator (Non-Accelerated)\n";
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700169
170static int sxg_debug = 1;
171static int debug = -1;
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530172static struct net_device *head_netdevice = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700173
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530174static struct sxgbase_driver sxg_global = {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700175 .dynamic_intagg = 1,
176};
177static int intagg_delay = 100;
178static u32 dynamic_intagg = 0;
179
Mithlesh Thukral54aed112009-01-19 20:27:17 +0530180char sxg_driver_name[] = "sxg_nic";
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700181#define DRV_AUTHOR "Alacritech, Inc. Engineering"
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530182#define DRV_DESCRIPTION \
183 "Alacritech SLIC Techonology(tm) Non-Accelerated 10Gbe Driver"
184#define DRV_COPYRIGHT \
185 "Copyright 2000-2008 Alacritech, Inc. All rights reserved."
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700186
187MODULE_AUTHOR(DRV_AUTHOR);
188MODULE_DESCRIPTION(DRV_DESCRIPTION);
189MODULE_LICENSE("GPL");
190
191module_param(dynamic_intagg, int, 0);
192MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
193module_param(intagg_delay, int, 0);
194MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
195
196static struct pci_device_id sxg_pci_tbl[] __devinitdata = {
197 {PCI_DEVICE(SXG_VENDOR_ID, SXG_DEVICE_ID)},
198 {0,}
199};
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400200
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700201MODULE_DEVICE_TABLE(pci, sxg_pci_tbl);
202
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700203static inline void sxg_reg32_write(void __iomem *reg, u32 value, bool flush)
204{
205 writel(value, reg);
206 if (flush)
207 mb();
208}
209
J.R. Mauro73b07062008-10-28 18:42:02 -0400210static inline void sxg_reg64_write(struct adapter_t *adapter, void __iomem *reg,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700211 u64 value, u32 cpu)
212{
213 u32 value_high = (u32) (value >> 32);
214 u32 value_low = (u32) (value & 0x00000000FFFFFFFF);
215 unsigned long flags;
216
217 spin_lock_irqsave(&adapter->Bit64RegLock, flags);
218 writel(value_high, (void __iomem *)(&adapter->UcodeRegs[cpu].Upper));
219 writel(value_low, reg);
220 spin_unlock_irqrestore(&adapter->Bit64RegLock, flags);
221}
222
223static void sxg_init_driver(void)
224{
225 if (sxg_first_init) {
226 DBG_ERROR("sxg: %s sxg_first_init set jiffies[%lx]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700227 __func__, jiffies);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700228 sxg_first_init = 0;
229 spin_lock_init(&sxg_global.driver_lock);
230 }
231}
232
J.R. Mauro73b07062008-10-28 18:42:02 -0400233static void sxg_dbg_macaddrs(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700234{
235 DBG_ERROR(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
236 adapter->netdev->name, adapter->currmacaddr[0],
237 adapter->currmacaddr[1], adapter->currmacaddr[2],
238 adapter->currmacaddr[3], adapter->currmacaddr[4],
239 adapter->currmacaddr[5]);
240 DBG_ERROR(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
241 adapter->netdev->name, adapter->macaddr[0],
242 adapter->macaddr[1], adapter->macaddr[2],
243 adapter->macaddr[3], adapter->macaddr[4],
244 adapter->macaddr[5]);
245 return;
246}
247
J.R. Maurob243c4a2008-10-20 19:28:58 -0400248/* SXG Globals */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530249static struct sxg_driver SxgDriver;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700250
251#ifdef ATKDBG
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530252static struct sxg_trace_buffer LSxgTraceBuffer;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700253#endif /* ATKDBG */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530254static struct sxg_trace_buffer *SxgTraceBuffer = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700255
256/*
Mithlesh Thukral1782199f2009-02-06 19:32:28 +0530257 * MSI Related API's
258 */
259int sxg_register_intr(struct adapter_t *adapter);
260int sxg_enable_msi_x(struct adapter_t *adapter);
261int sxg_add_msi_isr(struct adapter_t *adapter);
262void sxg_remove_msix_isr(struct adapter_t *adapter);
263int sxg_set_interrupt_capability(struct adapter_t *adapter);
264
265int sxg_set_interrupt_capability(struct adapter_t *adapter)
266{
267 int ret;
268
269 ret = sxg_enable_msi_x(adapter);
270 if (ret != STATUS_SUCCESS) {
271 adapter->msi_enabled = FALSE;
272 DBG_ERROR("sxg_set_interrupt_capability MSI-X Disable\n");
273 } else {
274 adapter->msi_enabled = TRUE;
275 DBG_ERROR("sxg_set_interrupt_capability MSI-X Enable\n");
276 }
277 return ret;
278}
279
280int sxg_register_intr(struct adapter_t *adapter)
281{
282 int ret = 0;
283
284 if (adapter->msi_enabled) {
285 ret = sxg_add_msi_isr(adapter);
286 }
287 else {
288 DBG_ERROR("MSI-X Enable Failed. Using Pin INT\n");
289 ret = sxg_register_interrupt(adapter);
290 if (ret != STATUS_SUCCESS) {
291 DBG_ERROR("sxg_register_interrupt Failed\n");
292 }
293 }
294 return ret;
295}
296
297int sxg_enable_msi_x(struct adapter_t *adapter)
298{
299 int ret;
300
301 adapter->nr_msix_entries = 1;
302 adapter->msi_entries = kmalloc(adapter->nr_msix_entries *
303 sizeof(struct msix_entry),GFP_KERNEL);
304 if (!adapter->msi_entries) {
305 DBG_ERROR("%s:MSI Entries memory allocation Failed\n",__func__);
306 return -ENOMEM;
307 }
308 memset(adapter->msi_entries, 0, adapter->nr_msix_entries *
309 sizeof(struct msix_entry));
310
311 ret = pci_enable_msix(adapter->pcidev, adapter->msi_entries,
312 adapter->nr_msix_entries);
313 if (ret) {
314 DBG_ERROR("Enabling MSI-X with %d vectors failed\n",
315 adapter->nr_msix_entries);
316 /*Should try with less vector returned.*/
317 kfree(adapter->msi_entries);
318 return STATUS_FAILURE; /*MSI-X Enable failed.*/
319 }
320 return (STATUS_SUCCESS);
321}
322
323int sxg_add_msi_isr(struct adapter_t *adapter)
324{
325 int ret,i;
326
327 if (!adapter->intrregistered) {
328 for (i=0; i<adapter->nr_msix_entries; i++) {
329 ret = request_irq (adapter->msi_entries[i].vector,
330 sxg_isr,
331 IRQF_SHARED,
332 adapter->netdev->name,
333 adapter->netdev);
334 if (ret) {
335 DBG_ERROR("sxg: MSI-X request_irq (%s) "
336 "FAILED [%x]\n", adapter->netdev->name,
337 ret);
338 return (ret);
339 }
340 }
341 }
342 adapter->msi_enabled = TRUE;
343 adapter->intrregistered = 1;
344 adapter->IntRegistered = TRUE;
345 return (STATUS_SUCCESS);
346}
347
348void sxg_remove_msix_isr(struct adapter_t *adapter)
349{
350 int i,vector;
351 struct net_device *netdev = adapter->netdev;
352
353 for(i=0; i< adapter->nr_msix_entries;i++)
354 {
355 vector = adapter->msi_entries[i].vector;
356 DBG_ERROR("%s : Freeing IRQ vector#%d\n",__FUNCTION__,vector);
357 free_irq(vector,netdev);
358 }
359}
360
361
362static void sxg_remove_isr(struct adapter_t *adapter)
363{
364 struct net_device *netdev = adapter->netdev;
365 if (adapter->msi_enabled)
366 sxg_remove_msix_isr(adapter);
367 else
368 free_irq(adapter->netdev->irq, netdev);
369}
370
371void sxg_reset_interrupt_capability(struct adapter_t *adapter)
372{
373 if (adapter->msi_enabled) {
374 pci_disable_msix(adapter->pcidev);
375 kfree(adapter->msi_entries);
376 adapter->msi_entries = NULL;
377 }
378 return;
379}
380
381/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700382 * sxg_download_microcode
383 *
384 * Download Microcode to Sahara adapter
385 *
386 * Arguments -
387 * adapter - A pointer to our adapter structure
388 * UcodeSel - microcode file selection
389 *
390 * Return
391 * int
392 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530393static bool sxg_download_microcode(struct adapter_t *adapter,
394 enum SXG_UCODE_SEL UcodeSel)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700395{
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530396 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700397 u32 Section;
398 u32 ThisSectionSize;
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400399 u32 *Instruction = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700400 u32 BaseAddress, AddressOffset, Address;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530401 /* u32 Failure; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700402 u32 ValueRead;
403 u32 i;
404 u32 numSections = 0;
405 u32 sectionSize[16];
406 u32 sectionStart[16];
407
408 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DnldUcod",
409 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700410 DBG_ERROR("sxg: %s ENTER\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700411
412 switch (UcodeSel) {
J.R. Maurob243c4a2008-10-20 19:28:58 -0400413 case SXG_UCODE_SAHARA: /* Sahara operational ucode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700414 numSections = SNumSections;
415 for (i = 0; i < numSections; i++) {
416 sectionSize[i] = SSectionSize[i];
417 sectionStart[i] = SSectionStart[i];
418 }
419 break;
420 default:
421 printk(KERN_ERR KBUILD_MODNAME
422 ": Woah, big error with the microcode!\n");
423 break;
424 }
425
426 DBG_ERROR("sxg: RESET THE CARD\n");
J.R. Maurob243c4a2008-10-20 19:28:58 -0400427 /* First, reset the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700428 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
429
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530430 /*
431 * Download each section of the microcode as specified in
432 * its download file. The *download.c file is generated using
433 * the saharaobjtoc facility which converts the metastep .obj
434 * file to a .c file which contains a two dimentional array.
435 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700436 for (Section = 0; Section < numSections; Section++) {
437 DBG_ERROR("sxg: SECTION # %d\n", Section);
438 switch (UcodeSel) {
439 case SXG_UCODE_SAHARA:
440 Instruction = (u32 *) & SaharaUCode[Section][0];
441 break;
442 default:
443 ASSERT(0);
444 break;
445 }
446 BaseAddress = sectionStart[Section];
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530447 /* Size in instructions */
448 ThisSectionSize = sectionSize[Section] / 12;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700449 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
450 AddressOffset++) {
451 Address = BaseAddress + AddressOffset;
452 ASSERT((Address & ~MICROCODE_ADDRESS_MASK) == 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400453 /* Write instruction bits 31 - 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700454 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400455 /* Write instruction bits 63-32 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700456 WRITE_REG(HwRegs->UcodeDataMiddle, *(Instruction + 1),
457 FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400458 /* Write instruction bits 95-64 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700459 WRITE_REG(HwRegs->UcodeDataHigh, *(Instruction + 2),
460 FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400461 /* Write instruction address with the WRITE bit set */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700462 WRITE_REG(HwRegs->UcodeAddr,
463 (Address | MICROCODE_ADDRESS_WRITE), FLUSH);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530464 /*
465 * Sahara bug in the ucode download logic - the write to DataLow
466 * for the next instruction could get corrupted. To avoid this,
467 * write to DataLow again for this instruction (which may get
468 * corrupted, but it doesn't matter), then increment the address
469 * and write the data for the next instruction to DataLow. That
470 * write should succeed.
471 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700472 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400473 /* Advance 3 u32S to start of next instruction */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700474 Instruction += 3;
475 }
476 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530477 /*
478 * Now repeat the entire operation reading the instruction back and
479 * checking for parity errors
480 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700481 for (Section = 0; Section < numSections; Section++) {
482 DBG_ERROR("sxg: check SECTION # %d\n", Section);
483 switch (UcodeSel) {
484 case SXG_UCODE_SAHARA:
485 Instruction = (u32 *) & SaharaUCode[Section][0];
486 break;
487 default:
488 ASSERT(0);
489 break;
490 }
491 BaseAddress = sectionStart[Section];
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530492 /* Size in instructions */
493 ThisSectionSize = sectionSize[Section] / 12;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700494 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
495 AddressOffset++) {
496 Address = BaseAddress + AddressOffset;
J.R. Maurob243c4a2008-10-20 19:28:58 -0400497 /* Write the address with the READ bit set */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700498 WRITE_REG(HwRegs->UcodeAddr,
499 (Address | MICROCODE_ADDRESS_READ), FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400500 /* Read it back and check parity bit. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700501 READ_REG(HwRegs->UcodeAddr, ValueRead);
502 if (ValueRead & MICROCODE_ADDRESS_PARITY) {
503 DBG_ERROR("sxg: %s PARITY ERROR\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700504 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700505
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530506 return FALSE; /* Parity error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700507 }
508 ASSERT((ValueRead & MICROCODE_ADDRESS_MASK) == Address);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400509 /* Read the instruction back and compare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700510 READ_REG(HwRegs->UcodeDataLow, ValueRead);
511 if (ValueRead != *Instruction) {
512 DBG_ERROR("sxg: %s MISCOMPARE LOW\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700513 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530514 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700515 }
516 READ_REG(HwRegs->UcodeDataMiddle, ValueRead);
517 if (ValueRead != *(Instruction + 1)) {
518 DBG_ERROR("sxg: %s MISCOMPARE MIDDLE\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700519 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530520 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700521 }
522 READ_REG(HwRegs->UcodeDataHigh, ValueRead);
523 if (ValueRead != *(Instruction + 2)) {
524 DBG_ERROR("sxg: %s MISCOMPARE HIGH\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700525 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530526 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700527 }
J.R. Maurob243c4a2008-10-20 19:28:58 -0400528 /* Advance 3 u32S to start of next instruction */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700529 Instruction += 3;
530 }
531 }
532
J.R. Maurob243c4a2008-10-20 19:28:58 -0400533 /* Everything OK, Go. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700534 WRITE_REG(HwRegs->UcodeAddr, MICROCODE_ADDRESS_GO, FLUSH);
535
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530536 /*
537 * Poll the CardUp register to wait for microcode to initialize
538 * Give up after 10,000 attemps (500ms).
539 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700540 for (i = 0; i < 10000; i++) {
541 udelay(50);
542 READ_REG(adapter->UcodeRegs[0].CardUp, ValueRead);
543 if (ValueRead == 0xCAFE) {
Harvey Harrisone88bd232008-10-17 14:46:10 -0700544 DBG_ERROR("sxg: %s BOO YA 0xCAFE\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700545 break;
546 }
547 }
548 if (i == 10000) {
Harvey Harrisone88bd232008-10-17 14:46:10 -0700549 DBG_ERROR("sxg: %s TIMEOUT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700550
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530551 return FALSE; /* Timeout */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700552 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530553 /*
554 * Now write the LoadSync register. This is used to
555 * synchronize with the card so it can scribble on the memory
556 * that contained 0xCAFE from the "CardUp" step above
557 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700558 if (UcodeSel == SXG_UCODE_SAHARA) {
559 WRITE_REG(adapter->UcodeRegs[0].LoadSync, 0, FLUSH);
560 }
561
562 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDnldUcd",
563 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700564 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700565
566 return (TRUE);
567}
568
569/*
570 * sxg_allocate_resources - Allocate memory and locks
571 *
572 * Arguments -
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530573 * adapter - A pointer to our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700574 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530575 * Return - int
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700576 */
J.R. Mauro73b07062008-10-28 18:42:02 -0400577static int sxg_allocate_resources(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700578{
579 int status;
580 u32 i;
581 u32 RssIds, IsrCount;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530582 /* struct sxg_xmt_ring *XmtRing; */
583 /* struct sxg_rcv_ring *RcvRing; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700584
Harvey Harrisone88bd232008-10-17 14:46:10 -0700585 DBG_ERROR("%s ENTER\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700586
587 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocRes",
588 adapter, 0, 0, 0);
589
J.R. Maurob243c4a2008-10-20 19:28:58 -0400590 /* Windows tells us how many CPUs it plans to use for */
591 /* RSS */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700592 RssIds = SXG_RSS_CPU_COUNT(adapter);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +0530593 IsrCount = adapter->msi_enabled ? RssIds : 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700594
Harvey Harrisone88bd232008-10-17 14:46:10 -0700595 DBG_ERROR("%s Setup the spinlocks\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700596
J.R. Maurob243c4a2008-10-20 19:28:58 -0400597 /* Allocate spinlocks and initialize listheads first. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700598 spin_lock_init(&adapter->RcvQLock);
599 spin_lock_init(&adapter->SglQLock);
600 spin_lock_init(&adapter->XmtZeroLock);
601 spin_lock_init(&adapter->Bit64RegLock);
602 spin_lock_init(&adapter->AdapterLock);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +0530603 atomic_set(&adapter->pending_allocations, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700604
Harvey Harrisone88bd232008-10-17 14:46:10 -0700605 DBG_ERROR("%s Setup the lists\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700606
607 InitializeListHead(&adapter->FreeRcvBuffers);
608 InitializeListHead(&adapter->FreeRcvBlocks);
609 InitializeListHead(&adapter->AllRcvBlocks);
610 InitializeListHead(&adapter->FreeSglBuffers);
611 InitializeListHead(&adapter->AllSglBuffers);
612
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530613 /*
614 * Mark these basic allocations done. This flags essentially
615 * tells the SxgFreeResources routine that it can grab spinlocks
616 * and reference listheads.
617 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700618 adapter->BasicAllocations = TRUE;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530619 /*
620 * Main allocation loop. Start with the maximum supported by
621 * the microcode and back off if memory allocation
622 * fails. If we hit a minimum, fail.
623 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700624
625 for (;;) {
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700626 DBG_ERROR("%s Allocate XmtRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530627 (unsigned int)(sizeof(struct sxg_xmt_ring) * 1));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700628
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530629 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530630 * Start with big items first - receive and transmit rings.
631 * At the moment I'm going to keep the ring size fixed and
632 * adjust the TCBs if we fail. Later we might
633 * consider reducing the ring size as well..
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530634 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700635 adapter->XmtRings = pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530636 sizeof(struct sxg_xmt_ring) *
637 1,
638 &adapter->PXmtRings);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700639 DBG_ERROR("%s XmtRings[%p]\n", __func__, adapter->XmtRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700640
641 if (!adapter->XmtRings) {
642 goto per_tcb_allocation_failed;
643 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530644 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700645
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700646 DBG_ERROR("%s Allocate RcvRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530647 (unsigned int)(sizeof(struct sxg_rcv_ring) * 1));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700648 adapter->RcvRings =
649 pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530650 sizeof(struct sxg_rcv_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700651 &adapter->PRcvRings);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700652 DBG_ERROR("%s RcvRings[%p]\n", __func__, adapter->RcvRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700653 if (!adapter->RcvRings) {
654 goto per_tcb_allocation_failed;
655 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530656 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530657 adapter->ucode_stats = kzalloc(sizeof(struct sxg_ucode_stats), GFP_ATOMIC);
658 adapter->pucode_stats = pci_map_single(adapter->pcidev,
659 adapter->ucode_stats,
660 sizeof(struct sxg_ucode_stats),
661 PCI_DMA_FROMDEVICE);
662// memset(adapter->ucode_stats, 0, sizeof(struct sxg_ucode_stats));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700663 break;
664
665 per_tcb_allocation_failed:
J.R. Maurob243c4a2008-10-20 19:28:58 -0400666 /* an allocation failed. Free any successful allocations. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700667 if (adapter->XmtRings) {
668 pci_free_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530669 sizeof(struct sxg_xmt_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700670 adapter->XmtRings,
671 adapter->PXmtRings);
672 adapter->XmtRings = NULL;
673 }
674 if (adapter->RcvRings) {
675 pci_free_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530676 sizeof(struct sxg_rcv_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700677 adapter->RcvRings,
678 adapter->PRcvRings);
679 adapter->RcvRings = NULL;
680 }
J.R. Maurob243c4a2008-10-20 19:28:58 -0400681 /* Loop around and try again.... */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530682 if (adapter->ucode_stats) {
683 pci_unmap_single(adapter->pcidev,
684 sizeof(struct sxg_ucode_stats),
685 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
686 adapter->ucode_stats = NULL;
687 }
688
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700689 }
690
Harvey Harrisone88bd232008-10-17 14:46:10 -0700691 DBG_ERROR("%s Initialize RCV ZERO and XMT ZERO rings\n", __func__);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400692 /* Initialize rcv zero and xmt zero rings */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700693 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
694 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
695
J.R. Maurob243c4a2008-10-20 19:28:58 -0400696 /* Sanity check receive data structure format */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530697 /* ASSERT((adapter->ReceiveBufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
698 (adapter->ReceiveBufferSize == SXG_RCV_JUMBO_BUFFER_SIZE)); */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530699 ASSERT(sizeof(struct sxg_rcv_descriptor_block) ==
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700700 SXG_RCV_DESCRIPTOR_BLOCK_SIZE);
701
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530702 /*
703 * Allocate receive data buffers. We allocate a block of buffers and
704 * a corresponding descriptor block at once. See sxghw.h:SXG_RCV_BLOCK
705 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700706 for (i = 0; i < SXG_INITIAL_RCV_DATA_BUFFERS;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530707 i += SXG_RCV_DESCRIPTORS_PER_BLOCK) {
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530708 status = sxg_allocate_buffer_memory(adapter,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530709 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700710 SXG_BUFFER_TYPE_RCV);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530711 if (status != STATUS_SUCCESS)
712 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700713 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530714 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530715 * NBL resource allocation can fail in the 'AllocateComplete' routine,
716 * which doesn't return status. Make sure we got the number of buffers
717 * we requested
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530718 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700719 if (adapter->FreeRcvBufferCount < SXG_INITIAL_RCV_DATA_BUFFERS) {
720 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF6",
721 adapter, adapter->FreeRcvBufferCount, SXG_MAX_ENTRIES,
722 0);
723 return (STATUS_RESOURCES);
724 }
725
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700726 DBG_ERROR("%s Allocate EventRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530727 (unsigned int)(sizeof(struct sxg_event_ring) * RssIds));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700728
J.R. Maurob243c4a2008-10-20 19:28:58 -0400729 /* Allocate event queues. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700730 adapter->EventRings = pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530731 sizeof(struct sxg_event_ring) *
732 RssIds,
733 &adapter->PEventRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700734
735 if (!adapter->EventRings) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530736 /* Caller will call SxgFreeAdapter to clean up above
737 * allocations */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700738 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF8",
739 adapter, SXG_MAX_ENTRIES, 0, 0);
740 status = STATUS_RESOURCES;
741 goto per_tcb_allocation_failed;
742 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530743 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700744
Harvey Harrisone88bd232008-10-17 14:46:10 -0700745 DBG_ERROR("%s Allocate ISR size[%x]\n", __func__, IsrCount);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400746 /* Allocate ISR */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700747 adapter->Isr = pci_alloc_consistent(adapter->pcidev,
748 IsrCount, &adapter->PIsr);
749 if (!adapter->Isr) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530750 /* Caller will call SxgFreeAdapter to clean up above
751 * allocations */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700752 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF9",
753 adapter, SXG_MAX_ENTRIES, 0, 0);
754 status = STATUS_RESOURCES;
755 goto per_tcb_allocation_failed;
756 }
757 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
758
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700759 DBG_ERROR("%s Allocate shared XMT ring zero index location size[%x]\n",
760 __func__, (unsigned int)sizeof(u32));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700761
J.R. Maurob243c4a2008-10-20 19:28:58 -0400762 /* Allocate shared XMT ring zero index location */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700763 adapter->XmtRingZeroIndex = pci_alloc_consistent(adapter->pcidev,
764 sizeof(u32),
765 &adapter->
766 PXmtRingZeroIndex);
767 if (!adapter->XmtRingZeroIndex) {
768 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF10",
769 adapter, SXG_MAX_ENTRIES, 0, 0);
770 status = STATUS_RESOURCES;
771 goto per_tcb_allocation_failed;
772 }
773 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
774
775 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlcResS",
776 adapter, SXG_MAX_ENTRIES, 0, 0);
777
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530778 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700779}
780
781/*
782 * sxg_config_pci -
783 *
784 * Set up PCI Configuration space
785 *
786 * Arguments -
787 * pcidev - A pointer to our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700788 */
789static void sxg_config_pci(struct pci_dev *pcidev)
790{
791 u16 pci_command;
792 u16 new_command;
793
794 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700795 DBG_ERROR("sxg: %s PCI command[%4.4x]\n", __func__, pci_command);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400796 /* Set the command register */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530797 new_command = pci_command | (
798 /* Memory Space Enable */
799 PCI_COMMAND_MEMORY |
800 /* Bus master enable */
801 PCI_COMMAND_MASTER |
802 /* Memory write and invalidate */
803 PCI_COMMAND_INVALIDATE |
804 /* Parity error response */
805 PCI_COMMAND_PARITY |
806 /* System ERR */
807 PCI_COMMAND_SERR |
808 /* Fast back-to-back */
809 PCI_COMMAND_FAST_BACK);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700810 if (pci_command != new_command) {
811 DBG_ERROR("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700812 __func__, pci_command, new_command);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700813 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
814 }
815}
816
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530817/*
818 * sxg_read_config
819 * @adapter : Pointer to the adapter structure for the card
820 * This function will read the configuration data from EEPROM/FLASH
821 */
822static inline int sxg_read_config(struct adapter_t *adapter)
823{
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530824 /* struct sxg_config data; */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530825 struct sw_cfg_data *data;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530826 dma_addr_t p_addr;
827 unsigned long status;
828 unsigned long i;
829
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530830 data = pci_alloc_consistent(adapter->pcidev,
831 sizeof(struct sw_cfg_data), &p_addr);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530832 if(!data) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530833 /*
834 * We cant get even this much memory. Raise a hell
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530835 * Get out of here
836 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530837 printk(KERN_ERR"%s : Could not allocate memory for reading \
838 EEPROM\n", __FUNCTION__);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530839 return -ENOMEM;
840 }
841
842 WRITE_REG(adapter->UcodeRegs[0].ConfigStat, SXG_CFG_TIMEOUT, TRUE);
843
844 WRITE_REG64(adapter, adapter->UcodeRegs[0].Config, p_addr, 0);
845 for(i=0; i<1000; i++) {
846 READ_REG(adapter->UcodeRegs[0].ConfigStat, status);
847 if (status != SXG_CFG_TIMEOUT)
848 break;
849 mdelay(1); /* Do we really need this */
850 }
851
852 switch(status) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530853 /* Config read from EEPROM succeeded */
854 case SXG_CFG_LOAD_EEPROM:
855 /* Config read from Flash succeeded */
856 case SXG_CFG_LOAD_FLASH:
857 /* Copy the MAC address to adapter structure */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530858 /* TODO: We are not doing the remaining part : FRU,
859 * etc
860 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530861 memcpy(adapter->macaddr, data->MacAddr[0].MacAddr,
862 sizeof(struct sxg_config_mac));
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530863 break;
864 case SXG_CFG_TIMEOUT:
865 case SXG_CFG_LOAD_INVALID:
866 case SXG_CFG_LOAD_ERROR:
867 default: /* Fix default handler later */
868 printk(KERN_WARNING"%s : We could not read the config \
869 word. Status = %ld\n", __FUNCTION__, status);
870 break;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530871 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530872 pci_free_consistent(adapter->pcidev, sizeof(struct sw_cfg_data), data,
873 p_addr);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530874 if (adapter->netdev) {
875 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
876 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
877 }
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530878 sxg_dbg_macaddrs(adapter);
879
880 return status;
881}
882
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700883static int sxg_entry_probe(struct pci_dev *pcidev,
884 const struct pci_device_id *pci_tbl_entry)
885{
886 static int did_version = 0;
887 int err;
888 struct net_device *netdev;
J.R. Mauro73b07062008-10-28 18:42:02 -0400889 struct adapter_t *adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700890 void __iomem *memmapped_ioaddr;
891 u32 status = 0;
892 ulong mmio_start = 0;
893 ulong mmio_len = 0;
894
895 DBG_ERROR("sxg: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700896 __func__, jiffies, smp_processor_id());
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700897
J.R. Maurob243c4a2008-10-20 19:28:58 -0400898 /* Initialize trace buffer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700899#ifdef ATKDBG
900 SxgTraceBuffer = &LSxgTraceBuffer;
901 SXG_TRACE_INIT(SxgTraceBuffer, TRACE_NOISY);
902#endif
903
904 sxg_global.dynamic_intagg = dynamic_intagg;
905
906 err = pci_enable_device(pcidev);
907
908 DBG_ERROR("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
909 if (err) {
910 return err;
911 }
912
913 if (sxg_debug > 0 && did_version++ == 0) {
914 printk(KERN_INFO "%s\n", sxg_banner);
Mithlesh Thukral371d7a92009-01-19 20:22:34 +0530915 printk(KERN_INFO "%s\n", SXG_DRV_VERSION);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700916 }
917
918 if (!(err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK))) {
919 DBG_ERROR("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
920 } else {
921 if ((err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK))) {
922 DBG_ERROR
923 ("No usable DMA configuration, aborting err[%x]\n",
924 err);
925 return err;
926 }
927 DBG_ERROR("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
928 }
929
930 DBG_ERROR("Call pci_request_regions\n");
931
Mithlesh Thukral371d7a92009-01-19 20:22:34 +0530932 err = pci_request_regions(pcidev, sxg_driver_name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700933 if (err) {
934 DBG_ERROR("pci_request_regions FAILED err[%x]\n", err);
935 return err;
936 }
937
938 DBG_ERROR("call pci_set_master\n");
939 pci_set_master(pcidev);
940
941 DBG_ERROR("call alloc_etherdev\n");
J.R. Mauro73b07062008-10-28 18:42:02 -0400942 netdev = alloc_etherdev(sizeof(struct adapter_t));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700943 if (!netdev) {
944 err = -ENOMEM;
945 goto err_out_exit_sxg_probe;
946 }
947 DBG_ERROR("alloc_etherdev for slic netdev[%p]\n", netdev);
948
949 SET_NETDEV_DEV(netdev, &pcidev->dev);
950
951 pci_set_drvdata(pcidev, netdev);
952 adapter = netdev_priv(netdev);
953 adapter->netdev = netdev;
954 adapter->pcidev = pcidev;
955
956 mmio_start = pci_resource_start(pcidev, 0);
957 mmio_len = pci_resource_len(pcidev, 0);
958
959 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
960 mmio_start, mmio_len);
961
962 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700963 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400964 memmapped_ioaddr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700965 if (!memmapped_ioaddr) {
966 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700967 __func__, mmio_len, mmio_start);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530968 goto err_out_free_mmio_region_0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700969 }
970
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530971 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, start[%lx] \
972 len[%lx], IRQ %d.\n", __func__, memmapped_ioaddr, mmio_start,
973 mmio_len, pcidev->irq);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700974
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400975 adapter->HwRegs = (void *)memmapped_ioaddr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700976 adapter->base_addr = memmapped_ioaddr;
977
978 mmio_start = pci_resource_start(pcidev, 2);
979 mmio_len = pci_resource_len(pcidev, 2);
980
981 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
982 mmio_start, mmio_len);
983
984 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400985 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
986 memmapped_ioaddr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700987 if (!memmapped_ioaddr) {
988 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700989 __func__, mmio_len, mmio_start);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530990 goto err_out_free_mmio_region_2;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700991 }
992
993 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, "
994 "start[%lx] len[%lx], IRQ %d.\n", __func__,
995 memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
996
997 adapter->UcodeRegs = (void *)memmapped_ioaddr;
998
999 adapter->State = SXG_STATE_INITIALIZING;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301000 /*
1001 * Maintain a list of all adapters anchored by
1002 * the global SxgDriver structure.
1003 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001004 adapter->Next = SxgDriver.Adapters;
1005 SxgDriver.Adapters = adapter;
1006 adapter->AdapterID = ++SxgDriver.AdapterID;
1007
J.R. Maurob243c4a2008-10-20 19:28:58 -04001008 /* Initialize CRC table used to determine multicast hash */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001009 sxg_mcast_init_crc32();
1010
1011 adapter->JumboEnabled = FALSE;
1012 adapter->RssEnabled = FALSE;
1013 if (adapter->JumboEnabled) {
1014 adapter->FrameSize = JUMBOMAXFRAME;
1015 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
1016 } else {
1017 adapter->FrameSize = ETHERMAXFRAME;
1018 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
1019 }
1020
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301021 /*
1022 * status = SXG_READ_EEPROM(adapter);
1023 * if (!status) {
1024 * goto sxg_init_bad;
1025 * }
1026 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001027
Harvey Harrisone88bd232008-10-17 14:46:10 -07001028 DBG_ERROR("sxg: %s ENTER sxg_config_pci\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001029 sxg_config_pci(pcidev);
Harvey Harrisone88bd232008-10-17 14:46:10 -07001030 DBG_ERROR("sxg: %s EXIT sxg_config_pci\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001031
Harvey Harrisone88bd232008-10-17 14:46:10 -07001032 DBG_ERROR("sxg: %s ENTER sxg_init_driver\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001033 sxg_init_driver();
Harvey Harrisone88bd232008-10-17 14:46:10 -07001034 DBG_ERROR("sxg: %s EXIT sxg_init_driver\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001035
1036 adapter->vendid = pci_tbl_entry->vendor;
1037 adapter->devid = pci_tbl_entry->device;
1038 adapter->subsysid = pci_tbl_entry->subdevice;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001039 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
1040 adapter->functionnumber = (pcidev->devfn & 0x7);
1041 adapter->memorylength = pci_resource_len(pcidev, 0);
1042 adapter->irq = pcidev->irq;
1043 adapter->next_netdevice = head_netdevice;
1044 head_netdevice = netdev;
J.R. Maurob243c4a2008-10-20 19:28:58 -04001045 adapter->port = 0; /*adapter->functionnumber; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001046
J.R. Maurob243c4a2008-10-20 19:28:58 -04001047 /* Allocate memory and other resources */
Harvey Harrisone88bd232008-10-17 14:46:10 -07001048 DBG_ERROR("sxg: %s ENTER sxg_allocate_resources\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001049 status = sxg_allocate_resources(adapter);
1050 DBG_ERROR("sxg: %s EXIT sxg_allocate_resources status %x\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001051 __func__, status);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001052 if (status != STATUS_SUCCESS) {
1053 goto err_out_unmap;
1054 }
1055
Harvey Harrisone88bd232008-10-17 14:46:10 -07001056 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001057 if (sxg_download_microcode(adapter, SXG_UCODE_SAHARA)) {
1058 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001059 __func__);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301060 sxg_read_config(adapter);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301061 status = sxg_adapter_set_hwaddr(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001062 } else {
1063 adapter->state = ADAPT_FAIL;
1064 adapter->linkstate = LINK_DOWN;
1065 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n", status);
1066 }
1067
1068 netdev->base_addr = (unsigned long)adapter->base_addr;
1069 netdev->irq = adapter->irq;
1070 netdev->open = sxg_entry_open;
1071 netdev->stop = sxg_entry_halt;
1072 netdev->hard_start_xmit = sxg_send_packets;
1073 netdev->do_ioctl = sxg_ioctl;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301074 netdev->change_mtu = sxg_change_mtu;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001075#if XXXTODO
1076 netdev->set_mac_address = sxg_mac_set_address;
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05301077#endif
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001078 netdev->get_stats = sxg_get_stats;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301079 netdev->set_multicast_list = sxg_mcast_set_list;
Mithlesh Thukral371d7a92009-01-19 20:22:34 +05301080 SET_ETHTOOL_OPS(netdev, &sxg_nic_ethtool_ops);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05301081 err = sxg_set_interrupt_capability(adapter);
1082 if (err != STATUS_SUCCESS)
1083 DBG_ERROR("Cannot enable MSI-X capability\n");
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001084
1085 strcpy(netdev->name, "eth%d");
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301086 /* strcpy(netdev->name, pci_name(pcidev)); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001087 if ((err = register_netdev(netdev))) {
1088 DBG_ERROR("Cannot register net device, aborting. %s\n",
1089 netdev->name);
1090 goto err_out_unmap;
1091 }
1092
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301093 netif_napi_add(netdev, &adapter->napi,
1094 sxg_poll, SXG_NETDEV_WEIGHT);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001095 DBG_ERROR
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301096 ("sxg: %s addr 0x%lx, irq %d, MAC addr \
1097 %02X:%02X:%02X:%02X:%02X:%02X\n",
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001098 netdev->name, netdev->base_addr, pcidev->irq, netdev->dev_addr[0],
1099 netdev->dev_addr[1], netdev->dev_addr[2], netdev->dev_addr[3],
1100 netdev->dev_addr[4], netdev->dev_addr[5]);
1101
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301102 /* sxg_init_bad: */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001103 ASSERT(status == FALSE);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301104 /* sxg_free_adapter(adapter); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001105
Harvey Harrisone88bd232008-10-17 14:46:10 -07001106 DBG_ERROR("sxg: %s EXIT status[%x] jiffies[%lx] cpu %d\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001107 status, jiffies, smp_processor_id());
1108 return status;
1109
1110 err_out_unmap:
Mithlesh Thukral0d414722009-01-19 20:29:59 +05301111 sxg_free_resources(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001112
Mithlesh Thukral0d414722009-01-19 20:29:59 +05301113 err_out_free_mmio_region_2:
1114
1115 mmio_start = pci_resource_start(pcidev, 2);
1116 mmio_len = pci_resource_len(pcidev, 2);
1117 release_mem_region(mmio_start, mmio_len);
1118
1119 err_out_free_mmio_region_0:
1120
1121 mmio_start = pci_resource_start(pcidev, 0);
1122 mmio_len = pci_resource_len(pcidev, 0);
1123
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001124 release_mem_region(mmio_start, mmio_len);
1125
1126 err_out_exit_sxg_probe:
1127
Harvey Harrisone88bd232008-10-17 14:46:10 -07001128 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001129 smp_processor_id());
1130
Mithlesh Thukral0d414722009-01-19 20:29:59 +05301131 pci_disable_device(pcidev);
1132 DBG_ERROR("sxg: %s deallocate device\n", __FUNCTION__);
1133 kfree(netdev);
1134 printk("Exit %s, Sxg driver loading failed..\n", __FUNCTION__);
1135
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001136 return -ENODEV;
1137}
1138
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001139/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301140 * LINE BASE Interrupt routines..
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001141 *
1142 * sxg_disable_interrupt
1143 *
1144 * DisableInterrupt Handler
1145 *
1146 * Arguments:
1147 *
1148 * adapter: Our adapter structure
1149 *
1150 * Return Value:
1151 * None.
1152 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001153static void sxg_disable_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001154{
1155 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DisIntr",
1156 adapter, adapter->InterruptsEnabled, 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001157 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001158 ASSERT(adapter->RssEnabled == FALSE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001159 /* Turn off interrupts by writing to the icr register. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001160 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_DISABLE), TRUE);
1161
1162 adapter->InterruptsEnabled = 0;
1163
1164 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDisIntr",
1165 adapter, adapter->InterruptsEnabled, 0, 0);
1166}
1167
1168/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001169 * sxg_enable_interrupt
1170 *
1171 * EnableInterrupt Handler
1172 *
1173 * Arguments:
1174 *
1175 * adapter: Our adapter structure
1176 *
1177 * Return Value:
1178 * None.
1179 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001180static void sxg_enable_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001181{
1182 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "EnIntr",
1183 adapter, adapter->InterruptsEnabled, 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001184 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001185 ASSERT(adapter->RssEnabled == FALSE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001186 /* Turn on interrupts by writing to the icr register. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001187 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_ENABLE), TRUE);
1188
1189 adapter->InterruptsEnabled = 1;
1190
1191 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XEnIntr",
1192 adapter, 0, 0, 0);
1193}
1194
1195/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001196 * sxg_isr - Process an line-based interrupt
1197 *
1198 * Arguments:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301199 * Context - Our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001200 * QueueDefault - Output parameter to queue to default CPU
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301201 * TargetCpus - Output bitmap to schedule DPC's
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001202 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301203 * Return Value: TRUE if our interrupt
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001204 */
1205static irqreturn_t sxg_isr(int irq, void *dev_id)
1206{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301207 struct net_device *dev = (struct net_device *) dev_id;
J.R. Mauro73b07062008-10-28 18:42:02 -04001208 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001209
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05301210 if(adapter->state != ADAPT_UP)
1211 return IRQ_NONE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001212 adapter->Stats.NumInts++;
1213 if (adapter->Isr[0] == 0) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301214 /*
1215 * The SLIC driver used to experience a number of spurious
1216 * interrupts due to the delay associated with the masking of
1217 * the interrupt (we'd bounce back in here). If we see that
1218 * again with Sahara,add a READ_REG of the Icr register after
1219 * the WRITE_REG below.
1220 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001221 adapter->Stats.FalseInts++;
1222 return IRQ_NONE;
1223 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301224 /*
1225 * Move the Isr contents and clear the value in
1226 * shared memory, and mask interrupts
1227 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301228 /* ASSERT(adapter->IsrDpcsPending == 0); */
J.R. Maurob243c4a2008-10-20 19:28:58 -04001229#if XXXTODO /* RSS Stuff */
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301230 /*
1231 * If RSS is enabled and the ISR specifies SXG_ISR_EVENT, then
1232 * schedule DPC's based on event queues.
1233 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001234 if (adapter->RssEnabled && (adapter->IsrCopy[0] & SXG_ISR_EVENT)) {
1235 for (i = 0;
1236 i < adapter->RssSystemInfo->ProcessorInfo.RssCpuCount;
1237 i++) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301238 struct sxg_event_ring *EventRing =
1239 &adapter->EventRings[i];
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301240 struct sxg_event *Event =
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001241 &EventRing->Ring[adapter->NextEvent[i]];
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001242 unsigned char Cpu =
1243 adapter->RssSystemInfo->RssIdToCpu[i];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001244 if (Event->Status & EVENT_STATUS_VALID) {
1245 adapter->IsrDpcsPending++;
1246 CpuMask |= (1 << Cpu);
1247 }
1248 }
1249 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301250 /*
1251 * Now, either schedule the CPUs specified by the CpuMask,
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301252 * or queue default
1253 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001254 if (CpuMask) {
1255 *QueueDefault = FALSE;
1256 } else {
1257 adapter->IsrDpcsPending = 1;
1258 *QueueDefault = TRUE;
1259 }
1260 *TargetCpus = CpuMask;
1261#endif
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301262 sxg_interrupt(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001263
1264 return IRQ_HANDLED;
1265}
1266
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301267static void sxg_interrupt(struct adapter_t *adapter)
1268{
1269 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_MASK), TRUE);
1270
1271 if (netif_rx_schedule_prep(&adapter->napi)) {
1272 __netif_rx_schedule(&adapter->napi);
1273 }
1274}
1275
1276static void sxg_handle_interrupt(struct adapter_t *adapter, int *work_done,
1277 int budget)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001278{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301279 /* unsigned char RssId = 0; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001280 u32 NewIsr;
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301281 int sxg_napi_continue = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001282 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "HndlIntr",
1283 adapter, adapter->IsrCopy[0], 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001284 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001285 ASSERT(adapter->RssEnabled == FALSE);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301286
1287 adapter->IsrCopy[0] = adapter->Isr[0];
1288 adapter->Isr[0] = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001289
J.R. Maurob243c4a2008-10-20 19:28:58 -04001290 /* Always process the event queue. */
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301291 while (sxg_napi_continue)
1292 {
1293 sxg_process_event_queue(adapter,
1294 (adapter->RssEnabled ? /*RssId */ 0 : 0),
1295 &sxg_napi_continue, work_done, budget);
1296 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001297
J.R. Maurob243c4a2008-10-20 19:28:58 -04001298#if XXXTODO /* RSS stuff */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001299 if (--adapter->IsrDpcsPending) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001300 /* We're done. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001301 ASSERT(adapter->RssEnabled);
1302 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DPCsPend",
1303 adapter, 0, 0, 0);
1304 return;
1305 }
1306#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001307 /* Last (or only) DPC processes the ISR and clears the interrupt. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001308 NewIsr = sxg_process_isr(adapter, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001309 /* Reenable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001310 adapter->IsrCopy[0] = 0;
1311 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ClearIsr",
1312 adapter, NewIsr, 0, 0);
1313
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001314 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XHndlInt",
1315 adapter, 0, 0, 0);
1316}
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301317static int sxg_poll(struct napi_struct *napi, int budget)
1318{
1319 struct adapter_t *adapter = container_of(napi, struct adapter_t, napi);
1320 int work_done = 0;
1321
1322 sxg_handle_interrupt(adapter, &work_done, budget);
1323
1324 if (work_done < budget) {
1325 netif_rx_complete(napi);
1326 WRITE_REG(adapter->UcodeRegs[0].Isr, 0, TRUE);
1327 }
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301328 return work_done;
1329}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001330
1331/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001332 * sxg_process_isr - Process an interrupt. Called from the line-based and
1333 * message based interrupt DPC routines
1334 *
1335 * Arguments:
1336 * adapter - Our adapter structure
1337 * Queue - The ISR that needs processing
1338 *
1339 * Return Value:
1340 * None
1341 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001342static int sxg_process_isr(struct adapter_t *adapter, u32 MessageId)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001343{
1344 u32 Isr = adapter->IsrCopy[MessageId];
1345 u32 NewIsr = 0;
1346
1347 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ProcIsr",
1348 adapter, Isr, 0, 0);
1349
J.R. Maurob243c4a2008-10-20 19:28:58 -04001350 /* Error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001351 if (Isr & SXG_ISR_ERR) {
1352 if (Isr & SXG_ISR_PDQF) {
1353 adapter->Stats.PdqFull++;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001354 DBG_ERROR("%s: SXG_ISR_ERR PDQF!!\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001355 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001356 /* No host buffer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001357 if (Isr & SXG_ISR_RMISS) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301358 /*
1359 * There is a bunch of code in the SLIC driver which
1360 * attempts to process more receive events per DPC
1361 * if we start to fall behind. We'll probablyd
1362 * need to do something similar here, but hold
1363 * off for now. I don't want to make the code more
1364 * complicated than strictly needed.
1365 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05301366 adapter->stats.rx_missed_errors++;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301367 if (adapter->stats.rx_missed_errors< 5) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001368 DBG_ERROR("%s: SXG_ISR_ERR RMISS!!\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001369 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001370 }
1371 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001372 /* Card crash */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001373 if (Isr & SXG_ISR_DEAD) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301374 /*
1375 * Set aside the crash info and set the adapter state
1376 * to RESET
1377 */
1378 adapter->CrashCpu = (unsigned char)
1379 ((Isr & SXG_ISR_CPU) >> SXG_ISR_CPU_SHIFT);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001380 adapter->CrashLocation = (ushort) (Isr & SXG_ISR_CRASH);
1381 adapter->Dead = TRUE;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001382 DBG_ERROR("%s: ISR_DEAD %x, CPU: %d\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001383 adapter->CrashLocation, adapter->CrashCpu);
1384 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001385 /* Event ring full */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001386 if (Isr & SXG_ISR_ERFULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301387 /*
1388 * Same issue as RMISS, really. This means the
1389 * host is falling behind the card. Need to increase
1390 * event ring size, process more events per interrupt,
1391 * and/or reduce/remove interrupt aggregation.
1392 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001393 adapter->Stats.EventRingFull++;
1394 DBG_ERROR("%s: SXG_ISR_ERR EVENT RING FULL!!\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001395 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001396 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001397 /* Transmit drop - no DRAM buffers or XMT error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001398 if (Isr & SXG_ISR_XDROP) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07001399 DBG_ERROR("%s: SXG_ISR_ERR XDROP!!\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001400 }
1401 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001402 /* Slowpath send completions */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001403 if (Isr & SXG_ISR_SPSEND) {
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301404 sxg_complete_slow_send(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001405 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001406 /* Dump */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001407 if (Isr & SXG_ISR_UPC) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301408 /* Maybe change when debug is added.. */
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301409// ASSERT(adapter->DumpCmdRunning);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001410 adapter->DumpCmdRunning = FALSE;
1411 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001412 /* Link event */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001413 if (Isr & SXG_ISR_LINK) {
1414 sxg_link_event(adapter);
1415 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001416 /* Debug - breakpoint hit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001417 if (Isr & SXG_ISR_BREAK) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301418 /*
1419 * At the moment AGDB isn't written to support interactive
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301420 * debug sessions. When it is, this interrupt will be used to
1421 * signal AGDB that it has hit a breakpoint. For now, ASSERT.
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301422 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001423 ASSERT(0);
1424 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001425 /* Heartbeat response */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001426 if (Isr & SXG_ISR_PING) {
1427 adapter->PingOutstanding = FALSE;
1428 }
1429 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XProcIsr",
1430 adapter, Isr, NewIsr, 0);
1431
1432 return (NewIsr);
1433}
1434
1435/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001436 * sxg_process_event_queue - Process our event queue
1437 *
1438 * Arguments:
1439 * - adapter - Adapter structure
1440 * - RssId - The event queue requiring processing
1441 *
1442 * Return Value:
1443 * None.
1444 */
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301445static u32 sxg_process_event_queue(struct adapter_t *adapter, u32 RssId,
1446 int *sxg_napi_continue, int *work_done, int budget)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001447{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301448 struct sxg_event_ring *EventRing = &adapter->EventRings[RssId];
1449 struct sxg_event *Event = &EventRing->Ring[adapter->NextEvent[RssId]];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001450 u32 EventsProcessed = 0, Batches = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001451 struct sk_buff *skb;
1452#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
1453 struct sk_buff *prev_skb = NULL;
1454 struct sk_buff *IndicationList[SXG_RCV_ARRAYSIZE];
1455 u32 Index;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301456 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001457#endif
1458 u32 ReturnStatus = 0;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301459 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001460
1461 ASSERT((adapter->State == SXG_STATE_RUNNING) ||
1462 (adapter->State == SXG_STATE_PAUSING) ||
1463 (adapter->State == SXG_STATE_PAUSED) ||
1464 (adapter->State == SXG_STATE_HALTING));
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301465 /*
1466 * We may still have unprocessed events on the queue if
1467 * the card crashed. Don't process them.
1468 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001469 if (adapter->Dead) {
1470 return (0);
1471 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301472 /*
1473 * In theory there should only be a single processor that
1474 * accesses this queue, and only at interrupt-DPC time. So/
1475 * we shouldn't need a lock for any of this.
1476 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001477 while (Event->Status & EVENT_STATUS_VALID) {
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301478 (*sxg_napi_continue) = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001479 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "Event",
1480 Event, Event->Code, Event->Status,
1481 adapter->NextEvent);
1482 switch (Event->Code) {
1483 case EVENT_CODE_BUFFERS:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301484 /* struct sxg_ring_info Head & Tail == unsigned char */
1485 ASSERT(!(Event->CommandIndex & 0xFF00));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001486 sxg_complete_descriptor_blocks(adapter,
1487 Event->CommandIndex);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001488 break;
1489 case EVENT_CODE_SLOWRCV:
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301490 (*work_done)++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001491 --adapter->RcvBuffersOnCard;
1492 if ((skb = sxg_slow_receive(adapter, Event))) {
1493 u32 rx_bytes;
1494#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
J.R. Maurob243c4a2008-10-20 19:28:58 -04001495 /* Add it to our indication list */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001496 SXG_ADD_RCV_PACKET(adapter, skb, prev_skb,
1497 IndicationList, num_skbs);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301498 /*
1499 * Linux, we just pass up each skb to the
1500 * protocol above at this point, there is no
1501 * capability of an indication list.
1502 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001503#else
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301504 /* CHECK skb_pull(skb, INIC_RCVBUF_HEADSIZE); */
1505 /* (rcvbuf->length & IRHDDR_FLEN_MSK); */
1506 rx_bytes = Event->Length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001507 adapter->stats.rx_packets++;
1508 adapter->stats.rx_bytes += rx_bytes;
1509#if SXG_OFFLOAD_IP_CHECKSUM
1510 skb->ip_summed = CHECKSUM_UNNECESSARY;
1511#endif
1512 skb->dev = adapter->netdev;
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301513 netif_receive_skb(skb);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001514#endif
1515 }
1516 break;
1517 default:
1518 DBG_ERROR("%s: ERROR Invalid EventCode %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001519 __func__, Event->Code);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301520 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001521 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301522 /*
1523 * See if we need to restock card receive buffers.
1524 * There are two things to note here:
1525 * First - This test is not SMP safe. The
1526 * adapter->BuffersOnCard field is protected via atomic
1527 * interlocked calls, but we do not protect it with respect
1528 * to these tests. The only way to do that is with a lock,
1529 * and I don't want to grab a lock every time we adjust the
1530 * BuffersOnCard count. Instead, we allow the buffer
1531 * replenishment to be off once in a while. The worst that
1532 * can happen is the card is given on more-or-less descriptor
1533 * block than the arbitrary value we've chosen. No big deal
1534 * In short DO NOT ADD A LOCK HERE, OR WHERE RcvBuffersOnCard
1535 * is adjusted.
1536 * Second - We expect this test to rarely
1537 * evaluate to true. We attempt to refill descriptor blocks
1538 * as they are returned to us (sxg_complete_descriptor_blocks)
1539 * so The only time this should evaluate to true is when
1540 * sxg_complete_descriptor_blocks failed to allocate
1541 * receive buffers.
1542 */
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301543 if (adapter->JumboEnabled)
1544 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
1545
1546 if (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001547 sxg_stock_rcv_buffers(adapter);
1548 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301549 /*
1550 * It's more efficient to just set this to zero.
1551 * But clearing the top bit saves potential debug info...
1552 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001553 Event->Status &= ~EVENT_STATUS_VALID;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301554 /* Advance to the next event */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001555 SXG_ADVANCE_INDEX(adapter->NextEvent[RssId], EVENT_RING_SIZE);
1556 Event = &EventRing->Ring[adapter->NextEvent[RssId]];
1557 EventsProcessed++;
1558 if (EventsProcessed == EVENT_RING_BATCH) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001559 /* Release a batch of events back to the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001560 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1561 EVENT_RING_BATCH, FALSE);
1562 EventsProcessed = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301563 /*
1564 * If we've processed our batch limit, break out of the
1565 * loop and return SXG_ISR_EVENT to arrange for us to
1566 * be called again
1567 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001568 if (Batches++ == EVENT_BATCH_LIMIT) {
1569 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1570 TRACE_NOISY, "EvtLimit", Batches,
1571 adapter->NextEvent, 0, 0);
1572 ReturnStatus = SXG_ISR_EVENT;
1573 break;
1574 }
1575 }
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301576 if (*work_done >= budget) {
1577 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1578 EventsProcessed, FALSE);
1579 EventsProcessed = 0;
1580 (*sxg_napi_continue) = 0;
1581 break;
1582 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001583 }
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301584 if (!(Event->Status & EVENT_STATUS_VALID))
1585 (*sxg_napi_continue) = 0;
1586
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001587#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
J.R. Maurob243c4a2008-10-20 19:28:58 -04001588 /* Indicate any received dumb-nic frames */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001589 SXG_INDICATE_PACKETS(adapter, IndicationList, num_skbs);
1590#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001591 /* Release events back to the card. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001592 if (EventsProcessed) {
1593 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1594 EventsProcessed, FALSE);
1595 }
1596 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XPrcEvnt",
1597 Batches, EventsProcessed, adapter->NextEvent, num_skbs);
1598
1599 return (ReturnStatus);
1600}
1601
1602/*
1603 * sxg_complete_slow_send - Complete slowpath or dumb-nic sends
1604 *
1605 * Arguments -
1606 * adapter - A pointer to our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001607 * Return
1608 * None
1609 */
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301610static void sxg_complete_slow_send(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001611{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301612 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
1613 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001614 u32 *ContextType;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301615 struct sxg_cmd *XmtCmd;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301616 unsigned long flags = 0;
1617 unsigned long sgl_flags = 0;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301618 unsigned int processed_count = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001619
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301620 /*
1621 * NOTE - This lock is dropped and regrabbed in this loop.
1622 * This means two different processors can both be running/
1623 * through this loop. Be *very* careful.
1624 */
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301625 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301626
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001627 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnds",
1628 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1629
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301630 while ((XmtRingInfo->Tail != *adapter->XmtRingZeroIndex)
1631 && processed_count++ < SXG_COMPLETE_SLOW_SEND_LIMIT) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301632 /*
1633 * Locate the current Cmd (ring descriptor entry), and
1634 * associated SGL, and advance the tail
1635 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001636 SXG_RETURN_CMD(XmtRing, XmtRingInfo, XmtCmd, ContextType);
1637 ASSERT(ContextType);
1638 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1639 XmtRingInfo->Head, XmtRingInfo->Tail, XmtCmd, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001640 /* Clear the SGL field. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001641 XmtCmd->Sgl = 0;
1642
1643 switch (*ContextType) {
1644 case SXG_SGL_DUMB:
1645 {
1646 struct sk_buff *skb;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301647 struct sxg_scatter_gather *SxgSgl =
1648 (struct sxg_scatter_gather *)ContextType;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301649 dma64_addr_t FirstSgeAddress;
1650 u32 FirstSgeLength;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301651
J.R. Maurob243c4a2008-10-20 19:28:58 -04001652 /* Dumb-nic send. Command context is the dumb-nic SGL */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001653 skb = (struct sk_buff *)ContextType;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301654 skb = SxgSgl->DumbPacket;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301655 FirstSgeAddress = XmtCmd->Buffer.FirstSgeAddress;
1656 FirstSgeLength = XmtCmd->Buffer.FirstSgeLength;
J.R. Maurob243c4a2008-10-20 19:28:58 -04001657 /* Complete the send */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001658 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1659 TRACE_IMPORTANT, "DmSndCmp", skb, 0,
1660 0, 0);
1661 ASSERT(adapter->Stats.XmtQLen);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301662 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301663 * Now drop the lock and complete the send
1664 * back to Microsoft. We need to drop the lock
1665 * because Microsoft can come back with a
1666 * chimney send, which results in a double trip
1667 * in SxgTcpOuput
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301668 */
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301669 spin_unlock_irqrestore(
1670 &adapter->XmtZeroLock, flags);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301671
1672 SxgSgl->DumbPacket = NULL;
1673 SXG_COMPLETE_DUMB_SEND(adapter, skb,
1674 FirstSgeAddress,
1675 FirstSgeLength);
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301676 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001677 /* and reacquire.. */
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301678 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001679 }
1680 break;
1681 default:
1682 ASSERT(0);
1683 }
1684 }
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05301685 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001686 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1687 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1688}
1689
1690/*
1691 * sxg_slow_receive
1692 *
1693 * Arguments -
1694 * adapter - A pointer to our adapter structure
1695 * Event - Receive event
1696 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301697 * Return - skb
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001698 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301699static struct sk_buff *sxg_slow_receive(struct adapter_t *adapter,
1700 struct sxg_event *Event)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001701{
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301702 u32 BufferSize = adapter->ReceiveBufferSize;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301703 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001704 struct sk_buff *Packet;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301705 static int read_counter = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001706
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301707 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *) Event->HostHandle;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301708 if(read_counter++ & 0x100)
1709 {
1710 sxg_collect_statistics(adapter);
1711 read_counter = 0;
1712 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001713 ASSERT(RcvDataBufferHdr);
1714 ASSERT(RcvDataBufferHdr->State == SXG_BUFFER_ONCARD);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001715 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "SlowRcv", Event,
1716 RcvDataBufferHdr, RcvDataBufferHdr->State,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301717 /*RcvDataBufferHdr->VirtualAddress*/ 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001718 /* Drop rcv frames in non-running state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001719 switch (adapter->State) {
1720 case SXG_STATE_RUNNING:
1721 break;
1722 case SXG_STATE_PAUSING:
1723 case SXG_STATE_PAUSED:
1724 case SXG_STATE_HALTING:
1725 goto drop;
1726 default:
1727 ASSERT(0);
1728 goto drop;
1729 }
1730
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301731 /*
1732 * memcpy(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1733 * RcvDataBufferHdr->VirtualAddress, Event->Length);
1734 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301735
J.R. Maurob243c4a2008-10-20 19:28:58 -04001736 /* Change buffer state to UPSTREAM */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001737 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
1738 if (Event->Status & EVENT_STATUS_RCVERR) {
1739 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvError",
1740 Event, Event->Status, Event->HostHandle, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001741 /* XXXTODO - Remove this print later */
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001742 DBG_ERROR("SXG: Receive error %x\n", *(u32 *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001743 SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr));
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001744 sxg_process_rcv_error(adapter, *(u32 *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001745 SXG_RECEIVE_DATA_LOCATION
1746 (RcvDataBufferHdr));
1747 goto drop;
1748 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001749#if XXXTODO /* VLAN stuff */
1750 /* If there's a VLAN tag, extract it and validate it */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301751 if (((struct ether_header *)
1752 (SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)))->EtherType
1753 == ETHERTYPE_VLAN) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001754 if (SxgExtractVlanHeader(adapter, RcvDataBufferHdr, Event) !=
1755 STATUS_SUCCESS) {
1756 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY,
1757 "BadVlan", Event,
1758 SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1759 Event->Length, 0);
1760 goto drop;
1761 }
1762 }
1763#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001764 /* Dumb-nic frame. See if it passes our mac filter and update stats */
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301765
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301766 if (!sxg_mac_filter(adapter,
1767 (struct ether_header *)(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)),
1768 Event->Length)) {
1769 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvFiltr",
1770 Event, SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1771 Event->Length, 0);
1772 goto drop;
1773 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001774
1775 Packet = RcvDataBufferHdr->SxgDumbRcvPacket;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301776 SXG_ADJUST_RCV_PACKET(Packet, RcvDataBufferHdr, Event);
1777 Packet->protocol = eth_type_trans(Packet, adapter->netdev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001778
1779 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumbRcv",
1780 RcvDataBufferHdr, Packet, Event->Length, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001781 /* Lastly adjust the receive packet length. */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301782 RcvDataBufferHdr->SxgDumbRcvPacket = NULL;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301783 RcvDataBufferHdr->PhysicalAddress = (dma_addr_t)NULL;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301784 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
1785 if (RcvDataBufferHdr->skb)
1786 {
1787 spin_lock(&adapter->RcvQLock);
1788 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301789 // adapter->RcvBuffersOnCard ++;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301790 spin_unlock(&adapter->RcvQLock);
1791 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001792 return (Packet);
1793
1794 drop:
1795 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DropRcv",
1796 RcvDataBufferHdr, Event->Length, 0, 0);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301797 adapter->stats.rx_dropped++;
1798// adapter->Stats.RcvDiscards++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001799 spin_lock(&adapter->RcvQLock);
1800 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
1801 spin_unlock(&adapter->RcvQLock);
1802 return (NULL);
1803}
1804
1805/*
1806 * sxg_process_rcv_error - process receive error and update
1807 * stats
1808 *
1809 * Arguments:
1810 * adapter - Adapter structure
1811 * ErrorStatus - 4-byte receive error status
1812 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301813 * Return Value : None
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001814 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001815static void sxg_process_rcv_error(struct adapter_t *adapter, u32 ErrorStatus)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001816{
1817 u32 Error;
1818
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301819 adapter->stats.rx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001820
1821 if (ErrorStatus & SXG_RCV_STATUS_TRANSPORT_ERROR) {
1822 Error = ErrorStatus & SXG_RCV_STATUS_TRANSPORT_MASK;
1823 switch (Error) {
1824 case SXG_RCV_STATUS_TRANSPORT_CSUM:
1825 adapter->Stats.TransportCsum++;
1826 break;
1827 case SXG_RCV_STATUS_TRANSPORT_UFLOW:
1828 adapter->Stats.TransportUflow++;
1829 break;
1830 case SXG_RCV_STATUS_TRANSPORT_HDRLEN:
1831 adapter->Stats.TransportHdrLen++;
1832 break;
1833 }
1834 }
1835 if (ErrorStatus & SXG_RCV_STATUS_NETWORK_ERROR) {
1836 Error = ErrorStatus & SXG_RCV_STATUS_NETWORK_MASK;
1837 switch (Error) {
1838 case SXG_RCV_STATUS_NETWORK_CSUM:
1839 adapter->Stats.NetworkCsum++;
1840 break;
1841 case SXG_RCV_STATUS_NETWORK_UFLOW:
1842 adapter->Stats.NetworkUflow++;
1843 break;
1844 case SXG_RCV_STATUS_NETWORK_HDRLEN:
1845 adapter->Stats.NetworkHdrLen++;
1846 break;
1847 }
1848 }
1849 if (ErrorStatus & SXG_RCV_STATUS_PARITY) {
1850 adapter->Stats.Parity++;
1851 }
1852 if (ErrorStatus & SXG_RCV_STATUS_LINK_ERROR) {
1853 Error = ErrorStatus & SXG_RCV_STATUS_LINK_MASK;
1854 switch (Error) {
1855 case SXG_RCV_STATUS_LINK_PARITY:
1856 adapter->Stats.LinkParity++;
1857 break;
1858 case SXG_RCV_STATUS_LINK_EARLY:
1859 adapter->Stats.LinkEarly++;
1860 break;
1861 case SXG_RCV_STATUS_LINK_BUFOFLOW:
1862 adapter->Stats.LinkBufOflow++;
1863 break;
1864 case SXG_RCV_STATUS_LINK_CODE:
1865 adapter->Stats.LinkCode++;
1866 break;
1867 case SXG_RCV_STATUS_LINK_DRIBBLE:
1868 adapter->Stats.LinkDribble++;
1869 break;
1870 case SXG_RCV_STATUS_LINK_CRC:
1871 adapter->Stats.LinkCrc++;
1872 break;
1873 case SXG_RCV_STATUS_LINK_OFLOW:
1874 adapter->Stats.LinkOflow++;
1875 break;
1876 case SXG_RCV_STATUS_LINK_UFLOW:
1877 adapter->Stats.LinkUflow++;
1878 break;
1879 }
1880 }
1881}
1882
1883/*
1884 * sxg_mac_filter
1885 *
1886 * Arguments:
1887 * adapter - Adapter structure
1888 * pether - Ethernet header
1889 * length - Frame length
1890 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301891 * Return Value : TRUE if the frame is to be allowed
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001892 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301893static bool sxg_mac_filter(struct adapter_t *adapter,
1894 struct ether_header *EtherHdr, ushort length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001895{
1896 bool EqualAddr;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301897 struct net_device *dev = adapter->netdev;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001898
1899 if (SXG_MULTICAST_PACKET(EtherHdr)) {
1900 if (SXG_BROADCAST_PACKET(EtherHdr)) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001901 /* broadcast */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001902 if (adapter->MacFilter & MAC_BCAST) {
1903 adapter->Stats.DumbRcvBcastPkts++;
1904 adapter->Stats.DumbRcvBcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001905 return (TRUE);
1906 }
1907 } else {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001908 /* multicast */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001909 if (adapter->MacFilter & MAC_ALLMCAST) {
1910 adapter->Stats.DumbRcvMcastPkts++;
1911 adapter->Stats.DumbRcvMcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001912 return (TRUE);
1913 }
1914 if (adapter->MacFilter & MAC_MCAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301915 struct dev_mc_list *mclist = dev->mc_list;
1916 while (mclist) {
1917 ETHER_EQ_ADDR(mclist->da_addr,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001918 EtherHdr->ether_dhost,
1919 EqualAddr);
1920 if (EqualAddr) {
1921 adapter->Stats.
1922 DumbRcvMcastPkts++;
1923 adapter->Stats.
1924 DumbRcvMcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001925 return (TRUE);
1926 }
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301927 mclist = mclist->next;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001928 }
1929 }
1930 }
1931 } else if (adapter->MacFilter & MAC_DIRECTED) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301932 /*
1933 * Not broadcast or multicast. Must be directed at us or
1934 * the card is in promiscuous mode. Either way, consider it
1935 * ours if MAC_DIRECTED is set
1936 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001937 adapter->Stats.DumbRcvUcastPkts++;
1938 adapter->Stats.DumbRcvUcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001939 return (TRUE);
1940 }
1941 if (adapter->MacFilter & MAC_PROMISC) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001942 /* Whatever it is, keep it. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001943 return (TRUE);
1944 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001945 return (FALSE);
1946}
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301947
J.R. Mauro73b07062008-10-28 18:42:02 -04001948static int sxg_register_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001949{
1950 if (!adapter->intrregistered) {
1951 int retval;
1952
1953 DBG_ERROR
1954 ("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x] %x\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001955 __func__, adapter, adapter->netdev->irq, NR_IRQS);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001956
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001957 spin_unlock_irqrestore(&sxg_global.driver_lock,
1958 sxg_global.flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001959
1960 retval = request_irq(adapter->netdev->irq,
1961 &sxg_isr,
1962 IRQF_SHARED,
1963 adapter->netdev->name, adapter->netdev);
1964
1965 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
1966
1967 if (retval) {
1968 DBG_ERROR("sxg: request_irq (%s) FAILED [%x]\n",
1969 adapter->netdev->name, retval);
1970 return (retval);
1971 }
1972 adapter->intrregistered = 1;
1973 adapter->IntRegistered = TRUE;
J.R. Maurob243c4a2008-10-20 19:28:58 -04001974 /* Disable RSS with line-based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001975 adapter->RssEnabled = FALSE;
1976 DBG_ERROR("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001977 __func__, adapter, adapter->netdev->irq);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001978 }
1979 return (STATUS_SUCCESS);
1980}
1981
J.R. Mauro73b07062008-10-28 18:42:02 -04001982static void sxg_deregister_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001983{
Harvey Harrisone88bd232008-10-17 14:46:10 -07001984 DBG_ERROR("sxg: %s ENTER adapter[%p]\n", __func__, adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001985#if XXXTODO
1986 slic_init_cleanup(adapter);
1987#endif
1988 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1989 adapter->error_interrupts = 0;
1990 adapter->rcv_interrupts = 0;
1991 adapter->xmit_interrupts = 0;
1992 adapter->linkevent_interrupts = 0;
1993 adapter->upr_interrupts = 0;
1994 adapter->num_isrs = 0;
1995 adapter->xmit_completes = 0;
1996 adapter->rcv_broadcasts = 0;
1997 adapter->rcv_multicasts = 0;
1998 adapter->rcv_unicasts = 0;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001999 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002000}
2001
2002/*
2003 * sxg_if_init
2004 *
2005 * Perform initialization of our slic interface.
2006 *
2007 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002008static int sxg_if_init(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002009{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302010 struct net_device *dev = adapter->netdev;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002011 int status = 0;
2012
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302013 DBG_ERROR("sxg: %s (%s) ENTER states[%d:%d] flags[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002014 __func__, adapter->netdev->name,
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302015 adapter->state,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002016 adapter->linkstate, dev->flags);
2017
2018 /* adapter should be down at this point */
2019 if (adapter->state != ADAPT_DOWN) {
2020 DBG_ERROR("sxg_if_init adapter->state != ADAPT_DOWN\n");
2021 return (-EIO);
2022 }
2023 ASSERT(adapter->linkstate == LINK_DOWN);
2024
2025 adapter->devflags_prev = dev->flags;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05302026 adapter->MacFilter = MAC_DIRECTED;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002027 if (dev->flags) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07002028 DBG_ERROR("sxg: %s (%s) Set MAC options: ", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002029 adapter->netdev->name);
2030 if (dev->flags & IFF_BROADCAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05302031 adapter->MacFilter |= MAC_BCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002032 DBG_ERROR("BCAST ");
2033 }
2034 if (dev->flags & IFF_PROMISC) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05302035 adapter->MacFilter |= MAC_PROMISC;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002036 DBG_ERROR("PROMISC ");
2037 }
2038 if (dev->flags & IFF_ALLMULTI) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05302039 adapter->MacFilter |= MAC_ALLMCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002040 DBG_ERROR("ALL_MCAST ");
2041 }
2042 if (dev->flags & IFF_MULTICAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05302043 adapter->MacFilter |= MAC_MCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002044 DBG_ERROR("MCAST ");
2045 }
2046 DBG_ERROR("\n");
2047 }
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302048 status = sxg_register_intr(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002049 if (status != STATUS_SUCCESS) {
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302050 DBG_ERROR("sxg_if_init: sxg_register_intr FAILED %x\n",
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002051 status);
2052 sxg_deregister_interrupt(adapter);
2053 return (status);
2054 }
2055
2056 adapter->state = ADAPT_UP;
2057
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302058 /* clear any pending events, then enable interrupts */
Harvey Harrisone88bd232008-10-17 14:46:10 -07002059 DBG_ERROR("sxg: %s ENABLE interrupts(slic)\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002060
2061 return (STATUS_SUCCESS);
2062}
2063
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302064void sxg_set_interrupt_aggregation(struct adapter_t *adapter)
2065{
2066 /*
2067 * Top bit disables aggregation on xmt (SXG_AGG_XMT_DISABLE).
2068 * Make sure Max is less than 0x8000.
2069 */
2070 adapter->max_aggregation = SXG_MAX_AGG_DEFAULT;
2071 adapter->min_aggregation = SXG_MIN_AGG_DEFAULT;
2072 WRITE_REG(adapter->UcodeRegs[0].Aggregation,
2073 ((adapter->max_aggregation << SXG_MAX_AGG_SHIFT) |
2074 adapter->min_aggregation),
2075 TRUE);
2076}
2077
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302078static int sxg_entry_open(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002079{
J.R. Mauro73b07062008-10-28 18:42:02 -04002080 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002081 int status;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302082 static int turn;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302083 int sxg_initial_rcv_data_buffers = SXG_INITIAL_RCV_DATA_BUFFERS;
2084 int i;
2085
2086 if (adapter->JumboEnabled == TRUE) {
2087 sxg_initial_rcv_data_buffers =
2088 SXG_INITIAL_JUMBO_RCV_DATA_BUFFERS;
2089 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo,
2090 SXG_JUMBO_RCV_RING_SIZE);
2091 }
2092
2093 /*
2094 * Allocate receive data buffers. We allocate a block of buffers and
2095 * a corresponding descriptor block at once. See sxghw.h:SXG_RCV_BLOCK
2096 */
2097
2098 for (i = 0; i < sxg_initial_rcv_data_buffers;
2099 i += SXG_RCV_DESCRIPTORS_PER_BLOCK)
2100 {
2101 status = sxg_allocate_buffer_memory(adapter,
2102 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
2103 SXG_BUFFER_TYPE_RCV);
2104 if (status != STATUS_SUCCESS)
2105 return status;
2106 }
2107 /*
2108 * NBL resource allocation can fail in the 'AllocateComplete' routine,
2109 * which doesn't return status. Make sure we got the number of buffers
2110 * we requested
2111 */
2112
2113 if (adapter->FreeRcvBufferCount < sxg_initial_rcv_data_buffers) {
2114 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF6",
2115 adapter, adapter->FreeRcvBufferCount, SXG_MAX_ENTRIES,
2116 0);
2117 return (STATUS_RESOURCES);
2118 }
2119 /*
2120 * The microcode expects it to be downloaded on every open.
2121 */
2122 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __FUNCTION__);
2123 if (sxg_download_microcode(adapter, SXG_UCODE_SAHARA)) {
2124 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
2125 __FUNCTION__);
2126 sxg_read_config(adapter);
2127 } else {
2128 adapter->state = ADAPT_FAIL;
2129 adapter->linkstate = LINK_DOWN;
2130 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n",
2131 status);
2132 }
2133 msleep(5);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302134
2135 if (turn) {
2136 sxg_second_open(adapter->netdev);
2137
2138 return STATUS_SUCCESS;
2139 }
2140
2141 turn++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002142
2143 ASSERT(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002144 DBG_ERROR("sxg: %s adapter->activated[%d]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002145 adapter->activated);
2146 DBG_ERROR
2147 ("sxg: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] port[%d]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002148 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002149 adapter->netdev, adapter, adapter->port);
2150
2151 netif_stop_queue(adapter->netdev);
2152
2153 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2154 if (!adapter->activated) {
2155 sxg_global.num_sxg_ports_active++;
2156 adapter->activated = 1;
2157 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002158 /* Initialize the adapter */
Harvey Harrisone88bd232008-10-17 14:46:10 -07002159 DBG_ERROR("sxg: %s ENTER sxg_initialize_adapter\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002160 status = sxg_initialize_adapter(adapter);
2161 DBG_ERROR("sxg: %s EXIT sxg_initialize_adapter status[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002162 __func__, status);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002163
2164 if (status == STATUS_SUCCESS) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07002165 DBG_ERROR("sxg: %s ENTER sxg_if_init\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002166 status = sxg_if_init(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002167 DBG_ERROR("sxg: %s EXIT sxg_if_init status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002168 status);
2169 }
2170
2171 if (status != STATUS_SUCCESS) {
2172 if (adapter->activated) {
2173 sxg_global.num_sxg_ports_active--;
2174 adapter->activated = 0;
2175 }
2176 spin_unlock_irqrestore(&sxg_global.driver_lock,
2177 sxg_global.flags);
2178 return (status);
2179 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002180 DBG_ERROR("sxg: %s ENABLE ALL INTERRUPTS\n", __func__);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302181 sxg_set_interrupt_aggregation(adapter);
2182 napi_enable(&adapter->napi);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002183
J.R. Maurob243c4a2008-10-20 19:28:58 -04002184 /* Enable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002185 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2186
Harvey Harrisone88bd232008-10-17 14:46:10 -07002187 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002188
2189 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2190 return STATUS_SUCCESS;
2191}
2192
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302193int sxg_second_open(struct net_device * dev)
2194{
2195 struct adapter_t *adapter = (struct adapter_t*) netdev_priv(dev);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302196 int status = 0;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302197
2198 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2199 netif_start_queue(adapter->netdev);
2200 adapter->state = ADAPT_UP;
2201 adapter->linkstate = LINK_UP;
2202
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302203 status = sxg_initialize_adapter(adapter);
2204 sxg_set_interrupt_aggregation(adapter);
2205 napi_enable(&adapter->napi);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302206 /* Re-enable interrupts */
2207 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2208
2209 netif_carrier_on(dev);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302210 sxg_register_interrupt(adapter);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302211 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302212 return (STATUS_SUCCESS);
2213
2214}
2215
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002216static void __devexit sxg_entry_remove(struct pci_dev *pcidev)
2217{
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302218 u32 mmio_start = 0;
2219 u32 mmio_len = 0;
2220
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302221 struct net_device *dev = pci_get_drvdata(pcidev);
J.R. Mauro73b07062008-10-28 18:42:02 -04002222 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302223
2224 flush_scheduled_work();
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302225
2226 /* Deallocate Resources */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302227 unregister_netdev(dev);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302228 sxg_reset_interrupt_capability(adapter);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302229 sxg_free_resources(adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302230
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002231 ASSERT(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002232
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302233 mmio_start = pci_resource_start(pcidev, 0);
2234 mmio_len = pci_resource_len(pcidev, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002235
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302236 DBG_ERROR("sxg: %s rel_region(0) start[%x] len[%x]\n", __FUNCTION__,
2237 mmio_start, mmio_len);
2238 release_mem_region(mmio_start, mmio_len);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002239
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302240 mmio_start = pci_resource_start(pcidev, 2);
2241 mmio_len = pci_resource_len(pcidev, 2);
2242
2243 DBG_ERROR("sxg: %s rel_region(2) start[%x] len[%x]\n", __FUNCTION__,
2244 mmio_start, mmio_len);
2245 release_mem_region(mmio_start, mmio_len);
2246
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302247 pci_disable_device(pcidev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002248
Harvey Harrisone88bd232008-10-17 14:46:10 -07002249 DBG_ERROR("sxg: %s deallocate device\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002250 kfree(dev);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002251 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002252}
2253
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302254static int sxg_entry_halt(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002255{
J.R. Mauro73b07062008-10-28 18:42:02 -04002256 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302257 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
2258 int i;
2259 u32 RssIds, IsrCount;
2260 unsigned long flags;
2261
2262 RssIds = SXG_RSS_CPU_COUNT(adapter);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302263 IsrCount = adapter->msi_enabled ? RssIds : 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002264
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302265 napi_disable(&adapter->napi);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002266 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002267 DBG_ERROR("sxg: %s (%s) ENTER\n", __func__, dev->name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002268
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302269 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 0, true);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002270 netif_stop_queue(adapter->netdev);
2271 adapter->state = ADAPT_DOWN;
2272 adapter->linkstate = LINK_DOWN;
2273 adapter->devflags_prev = 0;
2274 DBG_ERROR("sxg: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002275 __func__, dev->name, adapter, adapter->state);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002276
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302277 /* Disable interrupts */
2278 SXG_DISABLE_ALL_INTERRUPTS(adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302279
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302280 netif_carrier_off(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002281 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302282
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302283 sxg_deregister_interrupt(adapter);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302284 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
2285 mdelay(5000);
2286 spin_lock(&adapter->RcvQLock);
2287 /* Free all the blocks and the buffers, moved from remove() routine */
2288 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
2289 sxg_free_rcvblocks(adapter);
2290 }
2291
2292
2293 InitializeListHead(&adapter->FreeRcvBuffers);
2294 InitializeListHead(&adapter->FreeRcvBlocks);
2295 InitializeListHead(&adapter->AllRcvBlocks);
2296 InitializeListHead(&adapter->FreeSglBuffers);
2297 InitializeListHead(&adapter->AllSglBuffers);
2298
2299 adapter->FreeRcvBufferCount = 0;
2300 adapter->FreeRcvBlockCount = 0;
2301 adapter->AllRcvBlockCount = 0;
2302 adapter->RcvBuffersOnCard = 0;
2303 adapter->PendingRcvCount = 0;
2304
2305 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
2306 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
2307 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
2308 for (i = 0; i < SXG_MAX_RING_SIZE; i++)
2309 adapter->RcvRingZeroInfo.Context[i] = NULL;
2310 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
2311 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
2312
2313 spin_unlock(&adapter->RcvQLock);
2314
2315 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
2316 adapter->AllSglBufferCount = 0;
2317 adapter->FreeSglBufferCount = 0;
2318 adapter->PendingXmtCount = 0;
2319 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
2320 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
2321 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2322
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302323 for (i = 0; i < SXG_MAX_RSS; i++) {
2324 adapter->NextEvent[i] = 0;
2325 }
2326 atomic_set(&adapter->pending_allocations, 0);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05302327 adapter->intrregistered = 0;
2328 sxg_remove_isr(adapter);
2329 DBG_ERROR("sxg: %s (%s) EXIT\n", __FUNCTION__, dev->name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002330 return (STATUS_SUCCESS);
2331}
2332
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302333static int sxg_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002334{
2335 ASSERT(rq);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302336/* DBG_ERROR("sxg: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);*/
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002337 switch (cmd) {
2338 case SIOCSLICSETINTAGG:
2339 {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302340 /* struct adapter_t *adapter = (struct adapter_t *)
2341 * netdev_priv(dev);
2342 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002343 u32 data[7];
2344 u32 intagg;
2345
2346 if (copy_from_user(data, rq->ifr_data, 28)) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302347 DBG_ERROR("copy_from_user FAILED getting \
2348 initial params\n");
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002349 return -EFAULT;
2350 }
2351 intagg = data[0];
2352 printk(KERN_EMERG
2353 "%s: set interrupt aggregation to %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002354 __func__, intagg);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002355 return 0;
2356 }
2357
2358 default:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302359 /* DBG_ERROR("sxg: %s UNSUPPORTED[%x]\n", __func__, cmd); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002360 return -EOPNOTSUPP;
2361 }
2362 return 0;
2363}
2364
2365#define NORMAL_ETHFRAME 0
2366
2367/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002368 * sxg_send_packets - Send a skb packet
2369 *
2370 * Arguments:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302371 * skb - The packet to send
2372 * dev - Our linux net device that refs our adapter
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002373 *
2374 * Return:
2375 * 0 regardless of outcome XXXTODO refer to e1000 driver
2376 */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302377static int sxg_send_packets(struct sk_buff *skb, struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002378{
J.R. Mauro73b07062008-10-28 18:42:02 -04002379 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002380 u32 status = STATUS_SUCCESS;
2381
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302382 /*
2383 * DBG_ERROR("sxg: %s ENTER sxg_send_packets skb[%p]\n", __FUNCTION__,
2384 * skb);
2385 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302386
J.R. Maurob243c4a2008-10-20 19:28:58 -04002387 /* Check the adapter state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002388 switch (adapter->State) {
2389 case SXG_STATE_INITIALIZING:
2390 case SXG_STATE_HALTED:
2391 case SXG_STATE_SHUTDOWN:
J.R. Maurob243c4a2008-10-20 19:28:58 -04002392 ASSERT(0); /* unexpected */
2393 /* fall through */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002394 case SXG_STATE_RESETTING:
2395 case SXG_STATE_SLEEP:
2396 case SXG_STATE_BOOTDIAG:
2397 case SXG_STATE_DIAG:
2398 case SXG_STATE_HALTING:
2399 status = STATUS_FAILURE;
2400 break;
2401 case SXG_STATE_RUNNING:
2402 if (adapter->LinkState != SXG_LINK_UP) {
2403 status = STATUS_FAILURE;
2404 }
2405 break;
2406 default:
2407 ASSERT(0);
2408 status = STATUS_FAILURE;
2409 }
2410 if (status != STATUS_SUCCESS) {
2411 goto xmit_fail;
2412 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002413 /* send a packet */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002414 status = sxg_transmit_packet(adapter, skb);
2415 if (status == STATUS_SUCCESS) {
2416 goto xmit_done;
2417 }
2418
2419 xmit_fail:
J.R. Maurob243c4a2008-10-20 19:28:58 -04002420 /* reject & complete all the packets if they cant be sent */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002421 if (status != STATUS_SUCCESS) {
2422#if XXXTODO
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302423 /* sxg_send_packets_fail(adapter, skb, status); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002424#else
2425 SXG_DROP_DUMB_SEND(adapter, skb);
2426 adapter->stats.tx_dropped++;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302427 return NETDEV_TX_BUSY;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002428#endif
2429 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002430 DBG_ERROR("sxg: %s EXIT sxg_send_packets status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002431 status);
2432
2433 xmit_done:
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302434 return NETDEV_TX_OK;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002435}
2436
2437/*
2438 * sxg_transmit_packet
2439 *
2440 * This function transmits a single packet.
2441 *
2442 * Arguments -
2443 * adapter - Pointer to our adapter structure
2444 * skb - The packet to be sent
2445 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302446 * Return - STATUS of send
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002447 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002448static int sxg_transmit_packet(struct adapter_t *adapter, struct sk_buff *skb)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002449{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302450 struct sxg_x64_sgl *pSgl;
2451 struct sxg_scatter_gather *SxgSgl;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302452 unsigned long sgl_flags;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302453 /* void *SglBuffer; */
2454 /* u32 SglBufferLength; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002455
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302456 /*
2457 * The vast majority of work is done in the shared
2458 * sxg_dumb_sgl routine.
2459 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002460 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSend",
2461 adapter, skb, 0, 0);
2462
J.R. Maurob243c4a2008-10-20 19:28:58 -04002463 /* Allocate a SGL buffer */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302464 SXG_GET_SGL_BUFFER(adapter, SxgSgl, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002465 if (!SxgSgl) {
2466 adapter->Stats.NoSglBuf++;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05302467 adapter->stats.tx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002468 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "SndPktF1",
2469 adapter, skb, 0, 0);
2470 return (STATUS_RESOURCES);
2471 }
2472 ASSERT(SxgSgl->adapter == adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302473 /*SglBuffer = SXG_SGL_BUFFER(SxgSgl);
2474 SglBufferLength = SXG_SGL_BUF_SIZE; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002475 SxgSgl->VlanTag.VlanTci = 0;
2476 SxgSgl->VlanTag.VlanTpid = 0;
2477 SxgSgl->Type = SXG_SGL_DUMB;
2478 SxgSgl->DumbPacket = skb;
2479 pSgl = NULL;
2480
J.R. Maurob243c4a2008-10-20 19:28:58 -04002481 /* Call the common sxg_dumb_sgl routine to complete the send. */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302482 return (sxg_dumb_sgl(pSgl, SxgSgl));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002483}
2484
2485/*
2486 * sxg_dumb_sgl
2487 *
2488 * Arguments:
2489 * pSgl -
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302490 * SxgSgl - struct sxg_scatter_gather
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002491 *
2492 * Return Value:
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302493 * Status of send operation.
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002494 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302495static int sxg_dumb_sgl(struct sxg_x64_sgl *pSgl,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302496 struct sxg_scatter_gather *SxgSgl)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002497{
J.R. Mauro73b07062008-10-28 18:42:02 -04002498 struct adapter_t *adapter = SxgSgl->adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002499 struct sk_buff *skb = SxgSgl->DumbPacket;
J.R. Maurob243c4a2008-10-20 19:28:58 -04002500 /* For now, all dumb-nic sends go on RSS queue zero */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302501 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
2502 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
2503 struct sxg_cmd *XmtCmd = NULL;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302504 /* u32 Index = 0; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002505 u32 DataLength = skb->len;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302506 /* unsigned int BufLen; */
2507 /* u32 SglOffset; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002508 u64 phys_addr;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302509 unsigned long flags;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302510 unsigned long queue_id=0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002511
2512 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSgl",
2513 pSgl, SxgSgl, 0, 0);
2514
J.R. Maurob243c4a2008-10-20 19:28:58 -04002515 /* Set aside a pointer to the sgl */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002516 SxgSgl->pSgl = pSgl;
2517
J.R. Maurob243c4a2008-10-20 19:28:58 -04002518 /* Sanity check that our SGL format is as we expect. */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302519 ASSERT(sizeof(struct sxg_x64_sge) == sizeof(struct sxg_x64_sge));
J.R. Maurob243c4a2008-10-20 19:28:58 -04002520 /* Shouldn't be a vlan tag on this frame */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002521 ASSERT(SxgSgl->VlanTag.VlanTci == 0);
2522 ASSERT(SxgSgl->VlanTag.VlanTpid == 0);
2523
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302524 /*
2525 * From here below we work with the SGL placed in our
2526 * buffer.
2527 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002528
2529 SxgSgl->Sgl.NumberOfElements = 1;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302530 /*
2531 * Set ucode Queue ID based on bottom bits of destination TCP port.
2532 * This Queue ID splits slowpath/dumb-nic packet processing across
2533 * multiple threads on the card to improve performance. It is split
2534 * using the TCP port to avoid out-of-order packets that can result
2535 * from multithreaded processing. We use the destination port because
2536 * we expect to be run on a server, so in nearly all cases the local
2537 * port is likely to be constant (well-known server port) and the
2538 * remote port is likely to be random. The exception to this is iSCSI,
2539 * in which case we use the sport instead. Note
2540 * that original attempt at XOR'ing source and dest port resulted in
2541 * poor balance on NTTTCP/iometer applications since they tend to
2542 * line up (even-even, odd-odd..).
2543 */
2544
2545 if (skb->protocol == htons(ETH_P_IP)) {
2546 struct iphdr *ip;
2547
2548 ip = ip_hdr(skb);
2549 if ((ip->protocol == IPPROTO_TCP)&&(DataLength >= sizeof(
2550 struct tcphdr))){
2551 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2552 (ntohs (tcp_hdr(skb)->source) &
2553 SXG_LARGE_SEND_QUEUE_MASK):
2554 (ntohs(tcp_hdr(skb)->dest) &
2555 SXG_LARGE_SEND_QUEUE_MASK));
2556 }
2557 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2558 if ( (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) && (DataLength >=
2559 sizeof(struct tcphdr)) ) {
2560 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2561 (ntohs (tcp_hdr(skb)->source) &
2562 SXG_LARGE_SEND_QUEUE_MASK):
2563 (ntohs(tcp_hdr(skb)->dest) &
2564 SXG_LARGE_SEND_QUEUE_MASK));
2565 }
2566 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002567
J.R. Maurob243c4a2008-10-20 19:28:58 -04002568 /* Grab the spinlock and acquire a command */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302569 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002570 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2571 if (XmtCmd == NULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302572 /*
2573 * Call sxg_complete_slow_send to see if we can
2574 * free up any XmtRingZero entries and then try again
2575 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302576
2577 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05302578 sxg_complete_slow_send(adapter);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302579 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002580 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2581 if (XmtCmd == NULL) {
2582 adapter->Stats.XmtZeroFull++;
2583 goto abortcmd;
2584 }
2585 }
2586 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbCmd",
2587 XmtCmd, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002588 /* Update stats */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302589 adapter->stats.tx_packets++;
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302590 adapter->stats.tx_bytes += DataLength;
J.R. Maurob243c4a2008-10-20 19:28:58 -04002591#if XXXTODO /* Stats stuff */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002592 if (SXG_MULTICAST_PACKET(EtherHdr)) {
2593 if (SXG_BROADCAST_PACKET(EtherHdr)) {
2594 adapter->Stats.DumbXmtBcastPkts++;
2595 adapter->Stats.DumbXmtBcastBytes += DataLength;
2596 } else {
2597 adapter->Stats.DumbXmtMcastPkts++;
2598 adapter->Stats.DumbXmtMcastBytes += DataLength;
2599 }
2600 } else {
2601 adapter->Stats.DumbXmtUcastPkts++;
2602 adapter->Stats.DumbXmtUcastBytes += DataLength;
2603 }
2604#endif
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302605 /*
2606 * Fill in the command
2607 * Copy out the first SGE to the command and adjust for offset
2608 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302609 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04002610 PCI_DMA_TODEVICE);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302611
2612 /*
2613 * SAHARA SGL WORKAROUND
2614 * See if the SGL straddles a 64k boundary. If so, skip to
2615 * the start of the next 64k boundary and continue
2616 */
2617
2618 if (SXG_INVALID_SGL(phys_addr,skb->data_len))
2619 {
2620 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2621 /* Silently drop this packet */
2622 printk(KERN_EMERG"Dropped a packet for 64k boundary problem\n");
2623 return STATUS_SUCCESS;
2624 }
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302625 memset(XmtCmd, '\0', sizeof(*XmtCmd));
2626 XmtCmd->Buffer.FirstSgeAddress = phys_addr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002627 XmtCmd->Buffer.FirstSgeLength = DataLength;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002628 XmtCmd->Buffer.SgeOffset = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002629 XmtCmd->Buffer.TotalLength = DataLength;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302630 XmtCmd->SgEntries = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002631 XmtCmd->Flags = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302632 /*
2633 * Advance transmit cmd descripter by 1.
2634 * NOTE - See comments in SxgTcpOutput where we write
2635 * to the XmtCmd register regarding CPU ID values and/or
2636 * multiple commands.
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302637 * Top 16 bits specify queue_id. See comments about queue_id above
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302638 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302639 /* Four queues at the moment */
2640 ASSERT((queue_id & ~SXG_LARGE_SEND_QUEUE_MASK) == 0);
2641 WRITE_REG(adapter->UcodeRegs[0].XmtCmd, ((queue_id << 16) | 1), TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002642 adapter->Stats.XmtQLen++; /* Stats within lock */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302643 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002644 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDumSgl2",
2645 XmtCmd, pSgl, SxgSgl, 0);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302646 return STATUS_SUCCESS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002647
2648 abortcmd:
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302649 /*
2650 * NOTE - Only jump to this label AFTER grabbing the
2651 * XmtZeroLock, and DO NOT DROP IT between the
2652 * command allocation and the following abort.
2653 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002654 if (XmtCmd) {
2655 SXG_ABORT_CMD(XmtRingInfo);
2656 }
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302657 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002658
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302659/*
2660 * failsgl:
2661 * Jump to this label if failure occurs before the
2662 * XmtZeroLock is grabbed
2663 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302664 adapter->stats.tx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002665 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumSGFal",
2666 pSgl, SxgSgl, XmtRingInfo->Head, XmtRingInfo->Tail);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302667 /* SxgSgl->DumbPacket is the skb */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302668 // SXG_COMPLETE_DUMB_SEND(adapter, SxgSgl->DumbPacket);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05302669
2670 return STATUS_FAILURE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002671}
2672
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002673/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302674 * Link management functions
2675 *
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002676 * sxg_initialize_link - Initialize the link stuff
2677 *
2678 * Arguments -
2679 * adapter - A pointer to our adapter structure
2680 *
2681 * Return
2682 * status
2683 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002684static int sxg_initialize_link(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002685{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302686 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002687 u32 Value;
2688 u32 ConfigData;
2689 u32 MaxFrame;
2690 int status;
2691
2692 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitLink",
2693 adapter, 0, 0, 0);
2694
J.R. Maurob243c4a2008-10-20 19:28:58 -04002695 /* Reset PHY and XGXS module */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002696 WRITE_REG(HwRegs->LinkStatus, LS_SERDES_POWER_DOWN, TRUE);
2697
J.R. Maurob243c4a2008-10-20 19:28:58 -04002698 /* Reset transmit configuration register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002699 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_RESET, TRUE);
2700
J.R. Maurob243c4a2008-10-20 19:28:58 -04002701 /* Reset receive configuration register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002702 WRITE_REG(HwRegs->RcvConfig, RCV_CONFIG_RESET, TRUE);
2703
J.R. Maurob243c4a2008-10-20 19:28:58 -04002704 /* Reset all MAC modules */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002705 WRITE_REG(HwRegs->MacConfig0, AXGMAC_CFG0_SUB_RESET, TRUE);
2706
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302707 /*
2708 * Link address 0
2709 * XXXTODO - This assumes the MAC address (0a:0b:0c:0d:0e:0f)
2710 * is stored with the first nibble (0a) in the byte 0
2711 * of the Mac address. Possibly reverse?
2712 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302713 Value = *(u32 *) adapter->macaddr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002714 WRITE_REG(HwRegs->LinkAddress0Low, Value, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002715 /* also write the MAC address to the MAC. Endian is reversed. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002716 WRITE_REG(HwRegs->MacAddressLow, ntohl(Value), TRUE);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302717 Value = (*(u16 *) & adapter->macaddr[4] & 0x0000FFFF);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002718 WRITE_REG(HwRegs->LinkAddress0High, Value | LINK_ADDRESS_ENABLE, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002719 /* endian swap for the MAC (put high bytes in bits [31:16], swapped) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002720 Value = ntohl(Value);
2721 WRITE_REG(HwRegs->MacAddressHigh, Value, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002722 /* Link address 1 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002723 WRITE_REG(HwRegs->LinkAddress1Low, 0, TRUE);
2724 WRITE_REG(HwRegs->LinkAddress1High, 0, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002725 /* Link address 2 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002726 WRITE_REG(HwRegs->LinkAddress2Low, 0, TRUE);
2727 WRITE_REG(HwRegs->LinkAddress2High, 0, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002728 /* Link address 3 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002729 WRITE_REG(HwRegs->LinkAddress3Low, 0, TRUE);
2730 WRITE_REG(HwRegs->LinkAddress3High, 0, TRUE);
2731
J.R. Maurob243c4a2008-10-20 19:28:58 -04002732 /* Enable MAC modules */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002733 WRITE_REG(HwRegs->MacConfig0, 0, TRUE);
2734
J.R. Maurob243c4a2008-10-20 19:28:58 -04002735 /* Configure MAC */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302736 WRITE_REG(HwRegs->MacConfig1, (
2737 /* Allow sending of pause */
2738 AXGMAC_CFG1_XMT_PAUSE |
2739 /* Enable XMT */
2740 AXGMAC_CFG1_XMT_EN |
2741 /* Enable detection of pause */
2742 AXGMAC_CFG1_RCV_PAUSE |
2743 /* Enable receive */
2744 AXGMAC_CFG1_RCV_EN |
2745 /* short frame detection */
2746 AXGMAC_CFG1_SHORT_ASSERT |
2747 /* Verify frame length */
2748 AXGMAC_CFG1_CHECK_LEN |
2749 /* Generate FCS */
2750 AXGMAC_CFG1_GEN_FCS |
2751 /* Pad frames to 64 bytes */
2752 AXGMAC_CFG1_PAD_64),
2753 TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002754
J.R. Maurob243c4a2008-10-20 19:28:58 -04002755 /* Set AXGMAC max frame length if jumbo. Not needed for standard MTU */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002756 if (adapter->JumboEnabled) {
2757 WRITE_REG(HwRegs->MacMaxFrameLen, AXGMAC_MAXFRAME_JUMBO, TRUE);
2758 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302759 /*
2760 * AMIIM Configuration Register -
2761 * The value placed in the AXGMAC_AMIIM_CFG_HALF_CLOCK portion
2762 * (bottom bits) of this register is used to determine the MDC frequency
2763 * as specified in the A-XGMAC Design Document. This value must not be
2764 * zero. The following value (62 or 0x3E) is based on our MAC transmit
2765 * clock frequency (MTCLK) of 312.5 MHz. Given a maximum MDIO clock
2766 * frequency of 2.5 MHz (see the PHY spec), we get:
2767 * 312.5/(2*(X+1)) < 2.5 ==> X = 62.
2768 * This value happens to be the default value for this register, so we
2769 * really don't have to do this.
2770 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002771 WRITE_REG(HwRegs->MacAmiimConfig, 0x0000003E, TRUE);
2772
J.R. Maurob243c4a2008-10-20 19:28:58 -04002773 /* Power up and enable PHY and XAUI/XGXS/Serdes logic */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002774 WRITE_REG(HwRegs->LinkStatus,
2775 (LS_PHY_CLR_RESET |
2776 LS_XGXS_ENABLE |
2777 LS_XGXS_CTL | LS_PHY_CLK_EN | LS_ATTN_ALARM), TRUE);
2778 DBG_ERROR("After Power Up and enable PHY in sxg_initialize_link\n");
2779
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302780 /*
2781 * Per information given by Aeluros, wait 100 ms after removing reset.
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302782 * It's not enough to wait for the self-clearing reset bit in reg 0 to
2783 * clear.
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302784 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002785 mdelay(100);
2786
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302787 /* Verify the PHY has come up by checking that the Reset bit has
2788 * cleared.
2789 */
2790 status = sxg_read_mdio_reg(adapter,
2791 MIIM_DEV_PHY_PMA, /* PHY PMA/PMD module */
2792 PHY_PMA_CONTROL1, /* PMA/PMD control register */
2793 &Value);
2794 DBG_ERROR("After sxg_read_mdio_reg Value[%x] fail=%x\n", Value,
2795 (Value & PMA_CONTROL1_RESET));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002796 if (status != STATUS_SUCCESS)
2797 return (STATUS_FAILURE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002798 if (Value & PMA_CONTROL1_RESET) /* reset complete if bit is 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002799 return (STATUS_FAILURE);
2800
J.R. Maurob243c4a2008-10-20 19:28:58 -04002801 /* The SERDES should be initialized by now - confirm */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002802 READ_REG(HwRegs->LinkStatus, Value);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002803 if (Value & LS_SERDES_DOWN) /* verify SERDES is initialized */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002804 return (STATUS_FAILURE);
2805
J.R. Maurob243c4a2008-10-20 19:28:58 -04002806 /* The XAUI link should also be up - confirm */
2807 if (!(Value & LS_XAUI_LINK_UP)) /* verify XAUI link is up */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002808 return (STATUS_FAILURE);
2809
J.R. Maurob243c4a2008-10-20 19:28:58 -04002810 /* Initialize the PHY */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002811 status = sxg_phy_init(adapter);
2812 if (status != STATUS_SUCCESS)
2813 return (STATUS_FAILURE);
2814
J.R. Maurob243c4a2008-10-20 19:28:58 -04002815 /* Enable the Link Alarm */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302816
2817 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2818 * LASI_CONTROL - LASI control register
2819 * LASI_CTL_LS_ALARM_ENABLE - enable link alarm bit
2820 */
2821 status = sxg_write_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2822 LASI_CONTROL,
2823 LASI_CTL_LS_ALARM_ENABLE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002824 if (status != STATUS_SUCCESS)
2825 return (STATUS_FAILURE);
2826
J.R. Maurob243c4a2008-10-20 19:28:58 -04002827 /* XXXTODO - temporary - verify bit is set */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302828
2829 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2830 * LASI_CONTROL - LASI control register
2831 */
2832 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2833 LASI_CONTROL,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002834 &Value);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302835
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002836 if (status != STATUS_SUCCESS)
2837 return (STATUS_FAILURE);
2838 if (!(Value & LASI_CTL_LS_ALARM_ENABLE)) {
2839 DBG_ERROR("Error! LASI Control Alarm Enable bit not set!\n");
2840 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002841 /* Enable receive */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002842 MaxFrame = adapter->JumboEnabled ? JUMBOMAXFRAME : ETHERMAXFRAME;
2843 ConfigData = (RCV_CONFIG_ENABLE |
2844 RCV_CONFIG_ENPARSE |
2845 RCV_CONFIG_RCVBAD |
2846 RCV_CONFIG_RCVPAUSE |
2847 RCV_CONFIG_TZIPV6 |
2848 RCV_CONFIG_TZIPV4 |
2849 RCV_CONFIG_HASH_16 |
2850 RCV_CONFIG_SOCKET | RCV_CONFIG_BUFSIZE(MaxFrame));
2851 WRITE_REG(HwRegs->RcvConfig, ConfigData, TRUE);
2852
2853 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_ENABLE, TRUE);
2854
J.R. Maurob243c4a2008-10-20 19:28:58 -04002855 /* Mark the link as down. We'll get a link event when it comes up. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002856 sxg_link_state(adapter, SXG_LINK_DOWN);
2857
2858 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInitLnk",
2859 adapter, 0, 0, 0);
2860 return (STATUS_SUCCESS);
2861}
2862
2863/*
2864 * sxg_phy_init - Initialize the PHY
2865 *
2866 * Arguments -
2867 * adapter - A pointer to our adapter structure
2868 *
2869 * Return
2870 * status
2871 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002872static int sxg_phy_init(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002873{
2874 u32 Value;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302875 struct phy_ucode *p;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002876 int status;
2877
Harvey Harrisone88bd232008-10-17 14:46:10 -07002878 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002879
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302880 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2881 * 0xC205 - PHY ID register (?)
2882 * &Value - XXXTODO - add def
2883 */
2884 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2885 0xC205,
2886 &Value);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002887 if (status != STATUS_SUCCESS)
2888 return (STATUS_FAILURE);
2889
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302890 if (Value == 0x0012) {
2891 /* 0x0012 == AEL2005C PHY(?) - XXXTODO - add def */
2892 DBG_ERROR("AEL2005C PHY detected. Downloading PHY \
2893 microcode.\n");
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002894
J.R. Maurob243c4a2008-10-20 19:28:58 -04002895 /* Initialize AEL2005C PHY and download PHY microcode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002896 for (p = PhyUcode; p->Addr != 0xFFFF; p++) {
2897 if (p->Addr == 0) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04002898 /* if address == 0, data == sleep time in ms */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002899 mdelay(p->Data);
2900 } else {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302901 /* write the given data to the specified address */
2902 status = sxg_write_mdio_reg(adapter,
2903 MIIM_DEV_PHY_PMA,
2904 /* PHY address */
2905 p->Addr,
2906 /* PHY data */
2907 p->Data);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002908 if (status != STATUS_SUCCESS)
2909 return (STATUS_FAILURE);
2910 }
2911 }
2912 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002913 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002914
2915 return (STATUS_SUCCESS);
2916}
2917
2918/*
2919 * sxg_link_event - Process a link event notification from the card
2920 *
2921 * Arguments -
2922 * adapter - A pointer to our adapter structure
2923 *
2924 * Return
2925 * None
2926 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002927static void sxg_link_event(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002928{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302929 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302930 struct net_device *netdev = adapter->netdev;
J.R. Mauro73b07062008-10-28 18:42:02 -04002931 enum SXG_LINK_STATE LinkState;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002932 int status;
2933 u32 Value;
2934
2935 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "LinkEvnt",
2936 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002937 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002938
J.R. Maurob243c4a2008-10-20 19:28:58 -04002939 /* Check the Link Status register. We should have a Link Alarm. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002940 READ_REG(HwRegs->LinkStatus, Value);
2941 if (Value & LS_LINK_ALARM) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302942 /*
2943 * We got a Link Status alarm. First, pause to let the
2944 * link state settle (it can bounce a number of times)
2945 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002946 mdelay(10);
2947
J.R. Maurob243c4a2008-10-20 19:28:58 -04002948 /* Now clear the alarm by reading the LASI status register. */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302949 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
2950 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2951 /* LASI status register */
2952 LASI_STATUS,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002953 &Value);
2954 if (status != STATUS_SUCCESS) {
2955 DBG_ERROR("Error reading LASI Status MDIO register!\n");
2956 sxg_link_state(adapter, SXG_LINK_DOWN);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302957 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002958 }
2959 ASSERT(Value & LASI_STATUS_LS_ALARM);
2960
J.R. Maurob243c4a2008-10-20 19:28:58 -04002961 /* Now get and set the link state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002962 LinkState = sxg_get_link_state(adapter);
2963 sxg_link_state(adapter, LinkState);
2964 DBG_ERROR("SXG: Link Alarm occurred. Link is %s\n",
2965 ((LinkState == SXG_LINK_UP) ? "UP" : "DOWN"));
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302966 if (LinkState == SXG_LINK_UP)
2967 netif_carrier_on(netdev);
2968 else
2969 netif_carrier_off(netdev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002970 } else {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302971 /*
2972 * XXXTODO - Assuming Link Attention is only being generated
2973 * for the Link Alarm pin (and not for a XAUI Link Status change)
2974 * , then it's impossible to get here. Yet we've gotten here
2975 * twice (under extreme conditions - bouncing the link up and
2976 * down many times a second). Needs further investigation.
2977 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002978 DBG_ERROR("SXG: sxg_link_event: Can't get here!\n");
2979 DBG_ERROR("SXG: Link Status == 0x%08X.\n", Value);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302980 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002981 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002982 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002983
2984}
2985
2986/*
2987 * sxg_get_link_state - Determine if the link is up or down
2988 *
2989 * Arguments -
2990 * adapter - A pointer to our adapter structure
2991 *
2992 * Return
2993 * Link State
2994 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002995static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002996{
2997 int status;
2998 u32 Value;
2999
Harvey Harrisone88bd232008-10-17 14:46:10 -07003000 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003001
3002 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "GetLink",
3003 adapter, 0, 0, 0);
3004
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303005 /*
3006 * Per the Xenpak spec (and the IEEE 10Gb spec?), the link is up if
3007 * the following 3 bits (from 3 different MDIO registers) are all true.
3008 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303009
3010 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
3011 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
3012 /* PMA/PMD Receive Signal Detect register */
3013 PHY_PMA_RCV_DET,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003014 &Value);
3015 if (status != STATUS_SUCCESS)
3016 goto bad;
3017
J.R. Maurob243c4a2008-10-20 19:28:58 -04003018 /* If PMA/PMD receive signal detect is 0, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003019 if (!(Value & PMA_RCV_DETECT))
3020 return (SXG_LINK_DOWN);
3021
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303022 /* MIIM_DEV_PHY_PCS - PHY PCS module */
3023 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PCS,
3024 /* PCS 10GBASE-R Status 1 register */
3025 PHY_PCS_10G_STATUS1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003026 &Value);
3027 if (status != STATUS_SUCCESS)
3028 goto bad;
3029
J.R. Maurob243c4a2008-10-20 19:28:58 -04003030 /* If PCS is not locked to receive blocks, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003031 if (!(Value & PCS_10B_BLOCK_LOCK))
3032 return (SXG_LINK_DOWN);
3033
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303034 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_XS,/* PHY XS module */
3035 /* XS Lane Status register */
3036 PHY_XS_LANE_STATUS,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003037 &Value);
3038 if (status != STATUS_SUCCESS)
3039 goto bad;
3040
J.R. Maurob243c4a2008-10-20 19:28:58 -04003041 /* If XS transmit lanes are not aligned, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003042 if (!(Value & XS_LANE_ALIGN))
3043 return (SXG_LINK_DOWN);
3044
J.R. Maurob243c4a2008-10-20 19:28:58 -04003045 /* All 3 bits are true, so the link is up */
Harvey Harrisone88bd232008-10-17 14:46:10 -07003046 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003047
3048 return (SXG_LINK_UP);
3049
3050 bad:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303051 /* An error occurred reading an MDIO register. This shouldn't happen. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003052 DBG_ERROR("Error reading an MDIO register!\n");
3053 ASSERT(0);
3054 return (SXG_LINK_DOWN);
3055}
3056
J.R. Mauro73b07062008-10-28 18:42:02 -04003057static void sxg_indicate_link_state(struct adapter_t *adapter,
3058 enum SXG_LINK_STATE LinkState)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003059{
3060 if (adapter->LinkState == SXG_LINK_UP) {
3061 DBG_ERROR("%s: LINK now UP, call netif_start_queue\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07003062 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003063 netif_start_queue(adapter->netdev);
3064 } else {
3065 DBG_ERROR("%s: LINK now DOWN, call netif_stop_queue\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07003066 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003067 netif_stop_queue(adapter->netdev);
3068 }
3069}
3070
3071/*
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05303072 * sxg_change_mtu - Change the Maximum Transfer Unit
3073 * * @returns 0 on success, negative on failure
3074 */
3075int sxg_change_mtu (struct net_device *netdev, int new_mtu)
3076{
3077 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(netdev);
3078
3079 if (!((new_mtu == SXG_DEFAULT_MTU) || (new_mtu == SXG_JUMBO_MTU)))
3080 return -EINVAL;
3081
3082 if(new_mtu == netdev->mtu)
3083 return 0;
3084
3085 netdev->mtu = new_mtu;
3086
3087 if (new_mtu == SXG_JUMBO_MTU) {
3088 adapter->JumboEnabled = TRUE;
3089 adapter->FrameSize = JUMBOMAXFRAME;
3090 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
3091 } else {
3092 adapter->JumboEnabled = FALSE;
3093 adapter->FrameSize = ETHERMAXFRAME;
3094 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
3095 }
3096
3097 sxg_entry_halt(netdev);
3098 sxg_entry_open(netdev);
3099 return 0;
3100}
3101
3102/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003103 * sxg_link_state - Set the link state and if necessary, indicate.
3104 * This routine the central point of processing for all link state changes.
3105 * Nothing else in the driver should alter the link state or perform
3106 * link state indications
3107 *
3108 * Arguments -
3109 * adapter - A pointer to our adapter structure
3110 * LinkState - The link state
3111 *
3112 * Return
3113 * None
3114 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303115static void sxg_link_state(struct adapter_t *adapter,
3116 enum SXG_LINK_STATE LinkState)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003117{
3118 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "LnkINDCT",
3119 adapter, LinkState, adapter->LinkState, adapter->State);
3120
Harvey Harrisone88bd232008-10-17 14:46:10 -07003121 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003122
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303123 /*
3124 * Hold the adapter lock during this routine. Maybe move
3125 * the lock to the caller.
3126 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303127 /* IMP TODO : Check if we can survive without taking this lock */
3128// spin_lock(&adapter->AdapterLock);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003129 if (LinkState == adapter->LinkState) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003130 /* Nothing changed.. */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303131// spin_unlock(&adapter->AdapterLock);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303132 DBG_ERROR("EXIT #0 %s. Link status = %d\n",
3133 __func__, LinkState);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003134 return;
3135 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04003136 /* Save the adapter state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003137 adapter->LinkState = LinkState;
3138
J.R. Maurob243c4a2008-10-20 19:28:58 -04003139 /* Drop the lock and indicate link state */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303140// spin_unlock(&adapter->AdapterLock);
Harvey Harrisone88bd232008-10-17 14:46:10 -07003141 DBG_ERROR("EXIT #1 %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003142
3143 sxg_indicate_link_state(adapter, LinkState);
3144}
3145
3146/*
3147 * sxg_write_mdio_reg - Write to a register on the MDIO bus
3148 *
3149 * Arguments -
3150 * adapter - A pointer to our adapter structure
3151 * DevAddr - MDIO device number being addressed
3152 * RegAddr - register address for the specified MDIO device
3153 * Value - value to write to the MDIO register
3154 *
3155 * Return
3156 * status
3157 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003158static int sxg_write_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003159 u32 DevAddr, u32 RegAddr, u32 Value)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003160{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303161 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303162 /* Address operation (written to MIIM field reg) */
3163 u32 AddrOp;
3164 /* Write operation (written to MIIM field reg) */
3165 u32 WriteOp;
3166 u32 Cmd;/* Command (written to MIIM command reg) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003167 u32 ValueRead;
3168 u32 Timeout;
3169
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303170 /* DBG_ERROR("ENTER %s\n", __func__); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003171
3172 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3173 adapter, 0, 0, 0);
3174
J.R. Maurob243c4a2008-10-20 19:28:58 -04003175 /* Ensure values don't exceed field width */
3176 DevAddr &= 0x001F; /* 5-bit field */
3177 RegAddr &= 0xFFFF; /* 16-bit field */
3178 Value &= 0xFFFF; /* 16-bit field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003179
J.R. Maurob243c4a2008-10-20 19:28:58 -04003180 /* Set MIIM field register bits for an MIIM address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003181 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3182 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3183 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3184 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3185
J.R. Maurob243c4a2008-10-20 19:28:58 -04003186 /* Set MIIM field register bits for an MIIM write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003187 WriteOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3188 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3189 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3190 (MIIM_OP_WRITE << AXGMAC_AMIIM_FIELD_OP_SHIFT) | Value;
3191
J.R. Maurob243c4a2008-10-20 19:28:58 -04003192 /* Set MIIM command register bits to execute an MIIM command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003193 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3194
J.R. Maurob243c4a2008-10-20 19:28:58 -04003195 /* Reset the command register command bit (in case it's not 0) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003196 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3197
J.R. Maurob243c4a2008-10-20 19:28:58 -04003198 /* MIIM write to set the address of the specified MDIO register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003199 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3200
J.R. Maurob243c4a2008-10-20 19:28:58 -04003201 /* Write to MIIM Command Register to execute to address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003202 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3203
J.R. Maurob243c4a2008-10-20 19:28:58 -04003204 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003205 Timeout = SXG_LINK_TIMEOUT;
3206 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003207 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003208 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3209 if (--Timeout == 0) {
3210 return (STATUS_FAILURE);
3211 }
3212 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3213
J.R. Maurob243c4a2008-10-20 19:28:58 -04003214 /* Reset the command register command bit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003215 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3216
J.R. Maurob243c4a2008-10-20 19:28:58 -04003217 /* MIIM write to set up an MDIO write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003218 WRITE_REG(HwRegs->MacAmiimField, WriteOp, TRUE);
3219
J.R. Maurob243c4a2008-10-20 19:28:58 -04003220 /* Write to MIIM Command Register to execute the write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003221 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3222
J.R. Maurob243c4a2008-10-20 19:28:58 -04003223 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003224 Timeout = SXG_LINK_TIMEOUT;
3225 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003226 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003227 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3228 if (--Timeout == 0) {
3229 return (STATUS_FAILURE);
3230 }
3231 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3232
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303233 /* DBG_ERROR("EXIT %s\n", __func__); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003234
3235 return (STATUS_SUCCESS);
3236}
3237
3238/*
3239 * sxg_read_mdio_reg - Read a register on the MDIO bus
3240 *
3241 * Arguments -
3242 * adapter - A pointer to our adapter structure
3243 * DevAddr - MDIO device number being addressed
3244 * RegAddr - register address for the specified MDIO device
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303245 * pValue - pointer to where to put data read from the MDIO register
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003246 *
3247 * Return
3248 * status
3249 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003250static int sxg_read_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003251 u32 DevAddr, u32 RegAddr, u32 *pValue)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003252{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303253 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303254 u32 AddrOp; /* Address operation (written to MIIM field reg) */
3255 u32 ReadOp; /* Read operation (written to MIIM field reg) */
3256 u32 Cmd; /* Command (written to MIIM command reg) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003257 u32 ValueRead;
3258 u32 Timeout;
3259
3260 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3261 adapter, 0, 0, 0);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303262 DBG_ERROR("ENTER %s\n", __FUNCTION__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003263
J.R. Maurob243c4a2008-10-20 19:28:58 -04003264 /* Ensure values don't exceed field width */
3265 DevAddr &= 0x001F; /* 5-bit field */
3266 RegAddr &= 0xFFFF; /* 16-bit field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003267
J.R. Maurob243c4a2008-10-20 19:28:58 -04003268 /* Set MIIM field register bits for an MIIM address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003269 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3270 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3271 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3272 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3273
J.R. Maurob243c4a2008-10-20 19:28:58 -04003274 /* Set MIIM field register bits for an MIIM read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003275 ReadOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3276 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3277 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3278 (MIIM_OP_READ << AXGMAC_AMIIM_FIELD_OP_SHIFT);
3279
J.R. Maurob243c4a2008-10-20 19:28:58 -04003280 /* Set MIIM command register bits to execute an MIIM command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003281 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3282
J.R. Maurob243c4a2008-10-20 19:28:58 -04003283 /* Reset the command register command bit (in case it's not 0) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003284 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3285
J.R. Maurob243c4a2008-10-20 19:28:58 -04003286 /* MIIM write to set the address of the specified MDIO register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003287 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3288
J.R. Maurob243c4a2008-10-20 19:28:58 -04003289 /* Write to MIIM Command Register to execute to address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003290 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3291
J.R. Maurob243c4a2008-10-20 19:28:58 -04003292 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003293 Timeout = SXG_LINK_TIMEOUT;
3294 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003295 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003296 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3297 if (--Timeout == 0) {
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303298 DBG_ERROR("EXIT %s with STATUS_FAILURE 1\n", __FUNCTION__);
3299
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003300 return (STATUS_FAILURE);
3301 }
3302 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3303
J.R. Maurob243c4a2008-10-20 19:28:58 -04003304 /* Reset the command register command bit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003305 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3306
J.R. Maurob243c4a2008-10-20 19:28:58 -04003307 /* MIIM write to set up an MDIO register read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003308 WRITE_REG(HwRegs->MacAmiimField, ReadOp, TRUE);
3309
J.R. Maurob243c4a2008-10-20 19:28:58 -04003310 /* Write to MIIM Command Register to execute the read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003311 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3312
J.R. Maurob243c4a2008-10-20 19:28:58 -04003313 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003314 Timeout = SXG_LINK_TIMEOUT;
3315 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003316 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003317 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3318 if (--Timeout == 0) {
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303319 DBG_ERROR("EXIT %s with STATUS_FAILURE 2\n", __FUNCTION__);
3320
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003321 return (STATUS_FAILURE);
3322 }
3323 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3324
J.R. Maurob243c4a2008-10-20 19:28:58 -04003325 /* Read the MDIO register data back from the field register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003326 READ_REG(HwRegs->MacAmiimField, *pValue);
J.R. Maurob243c4a2008-10-20 19:28:58 -04003327 *pValue &= 0xFFFF; /* data is in the lower 16 bits */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003328
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303329 DBG_ERROR("EXIT %s\n", __FUNCTION__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003330
3331 return (STATUS_SUCCESS);
3332}
3333
3334/*
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003335 * Functions to obtain the CRC corresponding to the destination mac address.
3336 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
3337 * the polynomial:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303338 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5
3339 * + x^4 + x^2 + x^1.
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003340 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303341 * After the CRC for the 6 bytes is generated (but before the value is
3342 * complemented), we must then transpose the value and return bits 30-23.
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003343 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303344static u32 sxg_crc_table[256];/* Table of CRC's for all possible byte values */
3345static u32 sxg_crc_init; /* Is table initialized */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003346
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303347/* Contruct the CRC32 table */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003348static void sxg_mcast_init_crc32(void)
3349{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303350 u32 c; /* CRC shit reg */
3351 u32 e = 0; /* Poly X-or pattern */
3352 int i; /* counter */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003353 int k; /* byte being shifted into crc */
3354
3355 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
3356
3357 for (i = 0; i < sizeof(p) / sizeof(int); i++) {
3358 e |= 1L << (31 - p[i]);
3359 }
3360
3361 for (i = 1; i < 256; i++) {
3362 c = i;
3363 for (k = 8; k; k--) {
3364 c = c & 1 ? (c >> 1) ^ e : c >> 1;
3365 }
3366 sxg_crc_table[i] = c;
3367 }
3368}
3369
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003370/*
3371 * Return the MAC hast as described above.
3372 */
3373static unsigned char sxg_mcast_get_mac_hash(char *macaddr)
3374{
3375 u32 crc;
3376 char *p;
3377 int i;
3378 unsigned char machash = 0;
3379
3380 if (!sxg_crc_init) {
3381 sxg_mcast_init_crc32();
3382 sxg_crc_init = 1;
3383 }
3384
3385 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
3386 for (i = 0, p = macaddr; i < 6; ++p, ++i) {
3387 crc = (crc >> 8) ^ sxg_crc_table[(crc ^ *p) & 0xFF];
3388 }
3389
3390 /* Return bits 1-8, transposed */
3391 for (i = 1; i < 9; i++) {
3392 machash |= (((crc >> i) & 1) << (8 - i));
3393 }
3394
3395 return (machash);
3396}
3397
J.R. Mauro73b07062008-10-28 18:42:02 -04003398static void sxg_mcast_set_mask(struct adapter_t *adapter)
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003399{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303400 struct sxg_ucode_regs *sxg_regs = adapter->UcodeRegs;
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003401
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303402 DBG_ERROR("%s ENTER (%s) MacFilter[%x] mask[%llx]\n", __FUNCTION__,
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003403 adapter->netdev->name, (unsigned int)adapter->MacFilter,
3404 adapter->MulticastMask);
3405
3406 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_PROMISC)) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303407 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303408 * Turn on all multicast addresses. We have to do this for
3409 * promiscuous mode as well as ALLMCAST mode. It saves the
3410 * Microcode from having keep state about the MAC configuration
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003411 */
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303412 /* DBG_ERROR("sxg: %s MacFilter = MAC_ALLMCAST | MAC_PROMISC\n \
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303413 * SLUT MODE!!!\n",__func__);
3414 */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003415 WRITE_REG(sxg_regs->McastLow, 0xFFFFFFFF, FLUSH);
3416 WRITE_REG(sxg_regs->McastHigh, 0xFFFFFFFF, FLUSH);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303417 /* DBG_ERROR("%s (%s) WRITE to slic_regs slic_mcastlow&high \
3418 * 0xFFFFFFFF\n",__func__, adapter->netdev->name);
3419 */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003420
3421 } else {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303422 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303423 * Commit our multicast mast to the SLIC by writing to the
3424 * multicast address mask registers
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003425 */
3426 DBG_ERROR("%s (%s) WRITE mcastlow[%lx] mcasthigh[%lx]\n",
3427 __func__, adapter->netdev->name,
3428 ((ulong) (adapter->MulticastMask & 0xFFFFFFFF)),
3429 ((ulong)
3430 ((adapter->MulticastMask >> 32) & 0xFFFFFFFF)));
3431
3432 WRITE_REG(sxg_regs->McastLow,
3433 (u32) (adapter->MulticastMask & 0xFFFFFFFF), FLUSH);
3434 WRITE_REG(sxg_regs->McastHigh,
3435 (u32) ((adapter->
3436 MulticastMask >> 32) & 0xFFFFFFFF), FLUSH);
3437 }
3438}
3439
J.R. Mauro73b07062008-10-28 18:42:02 -04003440static void sxg_mcast_set_bit(struct adapter_t *adapter, char *address)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003441{
3442 unsigned char crcpoly;
3443
3444 /* Get the CRC polynomial for the mac address */
3445 crcpoly = sxg_mcast_get_mac_hash(address);
3446
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303447 /*
3448 * We only have space on the SLIC for 64 entries. Lop
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003449 * off the top two bits. (2^6 = 64)
3450 */
3451 crcpoly &= 0x3F;
3452
3453 /* OR in the new bit into our 64 bit mask. */
3454 adapter->MulticastMask |= (u64) 1 << crcpoly;
3455}
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303456
3457/*
3458 * Function takes MAC addresses from dev_mc_list and generates the Mask
3459 */
3460
3461static void sxg_set_mcast_addr(struct adapter_t *adapter)
3462{
3463 struct dev_mc_list *mclist;
3464 struct net_device *dev = adapter->netdev;
3465 int i;
3466
3467 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_MCAST)) {
3468 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
3469 i++, mclist = mclist->next) {
3470 sxg_mcast_set_bit(adapter,mclist->da_addr);
3471 }
3472 }
3473 sxg_mcast_set_mask(adapter);
3474}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003475
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303476static void sxg_mcast_set_list(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003477{
J.R. Mauro73b07062008-10-28 18:42:02 -04003478 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003479
3480 ASSERT(adapter);
Mithlesh Thukral559990c2009-01-30 20:20:19 +05303481 if (dev->flags & IFF_PROMISC)
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303482 adapter->MacFilter |= MAC_PROMISC;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303483 if (dev->flags & IFF_MULTICAST)
3484 adapter->MacFilter |= MAC_MCAST;
Mithlesh Thukral559990c2009-01-30 20:20:19 +05303485 if (dev->flags & IFF_ALLMULTI)
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303486 adapter->MacFilter |= MAC_ALLMCAST;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303487
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303488 //XXX handle other flags as well
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303489 sxg_set_mcast_addr(adapter);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303490}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003491
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303492void sxg_free_sgl_buffers(struct adapter_t *adapter)
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303493{
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303494 struct list_entry *ple;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303495 struct sxg_scatter_gather *Sgl;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003496
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303497 while(!(IsListEmpty(&adapter->AllSglBuffers))) {
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303498 ple = RemoveHeadList(&adapter->AllSglBuffers);
3499 Sgl = container_of(ple, struct sxg_scatter_gather, AllList);
3500 kfree(Sgl);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303501 adapter->AllSglBufferCount--;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303502 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303503}
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303504
3505void sxg_free_rcvblocks(struct adapter_t *adapter)
3506{
3507 u32 i;
3508 void *temp_RcvBlock;
3509 struct list_entry *ple;
3510 struct sxg_rcv_block_hdr *RcvBlockHdr;
3511 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3512 ASSERT((adapter->state == SXG_STATE_INITIALIZING) ||
3513 (adapter->state == SXG_STATE_HALTING));
3514 while(!(IsListEmpty(&adapter->AllRcvBlocks))) {
3515
3516 ple = RemoveHeadList(&adapter->AllRcvBlocks);
3517 RcvBlockHdr = container_of(ple, struct sxg_rcv_block_hdr, AllList);
3518
3519 if(RcvBlockHdr->VirtualAddress) {
3520 temp_RcvBlock = RcvBlockHdr->VirtualAddress;
3521
3522 for(i=0; i< SXG_RCV_DESCRIPTORS_PER_BLOCK;
3523 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3524 RcvDataBufferHdr =
3525 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
3526 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3527 }
3528 }
3529
3530 pci_free_consistent(adapter->pcidev,
3531 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
3532 RcvBlockHdr->VirtualAddress,
3533 RcvBlockHdr->PhysicalAddress);
3534 adapter->AllRcvBlockCount--;
3535 }
3536 ASSERT(adapter->AllRcvBlockCount == 0);
3537 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3538 adapter, 0, 0, 0);
3539}
3540void sxg_free_mcast_addrs(struct adapter_t *adapter)
3541{
3542 struct sxg_multicast_address *address;
3543 while(adapter->MulticastAddrs) {
3544 address = adapter->MulticastAddrs;
3545 adapter->MulticastAddrs = address->Next;
3546 kfree(address);
3547 }
3548
3549 adapter->MulticastMask= 0;
3550}
3551
3552void sxg_unmap_resources(struct adapter_t *adapter)
3553{
3554 if(adapter->HwRegs) {
3555 iounmap((void *)adapter->HwRegs);
3556 }
3557 if(adapter->UcodeRegs) {
3558 iounmap((void *)adapter->UcodeRegs);
3559 }
3560
3561 ASSERT(adapter->AllRcvBlockCount == 0);
3562 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3563 adapter, 0, 0, 0);
3564}
3565
3566
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303567
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003568/*
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303569 * sxg_free_resources - Free everything allocated in SxgAllocateResources
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003570 *
3571 * Arguments -
3572 * adapter - A pointer to our adapter structure
3573 *
3574 * Return
3575 * none
3576 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303577void sxg_free_resources(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003578{
3579 u32 RssIds, IsrCount;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003580 RssIds = SXG_RSS_CPU_COUNT(adapter);
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05303581 IsrCount = adapter->msi_enabled ? RssIds : 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003582
3583 if (adapter->BasicAllocations == FALSE) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303584 /*
3585 * No allocations have been made, including spinlocks,
3586 * or listhead initializations. Return.
3587 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003588 return;
3589 }
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303590
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003591 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303592 sxg_free_rcvblocks(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003593 }
3594 if (!(IsListEmpty(&adapter->AllSglBuffers))) {
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303595 sxg_free_sgl_buffers(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003596 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303597
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003598 if (adapter->XmtRingZeroIndex) {
3599 pci_free_consistent(adapter->pcidev,
3600 sizeof(u32),
3601 adapter->XmtRingZeroIndex,
3602 adapter->PXmtRingZeroIndex);
3603 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303604 if (adapter->Isr) {
3605 pci_free_consistent(adapter->pcidev,
3606 sizeof(u32) * IsrCount,
3607 adapter->Isr, adapter->PIsr);
3608 }
3609
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303610 if (adapter->EventRings) {
3611 pci_free_consistent(adapter->pcidev,
3612 sizeof(struct sxg_event_ring) * RssIds,
3613 adapter->EventRings, adapter->PEventRings);
3614 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303615 if (adapter->RcvRings) {
3616 pci_free_consistent(adapter->pcidev,
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303617 sizeof(struct sxg_rcv_ring) * 1,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303618 adapter->RcvRings,
3619 adapter->PRcvRings);
3620 adapter->RcvRings = NULL;
3621 }
3622
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303623 if(adapter->XmtRings) {
3624 pci_free_consistent(adapter->pcidev,
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303625 sizeof(struct sxg_xmt_ring) * 1,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303626 adapter->XmtRings,
3627 adapter->PXmtRings);
3628 adapter->XmtRings = NULL;
3629 }
3630
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303631 if (adapter->ucode_stats) {
3632 pci_unmap_single(adapter->pcidev,
3633 sizeof(struct sxg_ucode_stats),
3634 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
3635 adapter->ucode_stats = NULL;
3636 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303637
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003638
J.R. Maurob243c4a2008-10-20 19:28:58 -04003639 /* Unmap register spaces */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303640 sxg_unmap_resources(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003641
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303642 sxg_free_mcast_addrs(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003643
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003644 adapter->BasicAllocations = FALSE;
3645
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003646}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003647
3648/*
3649 * sxg_allocate_complete -
3650 *
3651 * This routine is called when a memory allocation has completed.
3652 *
3653 * Arguments -
J.R. Mauro73b07062008-10-28 18:42:02 -04003654 * struct adapter_t * - Our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003655 * VirtualAddress - Memory virtual address
3656 * PhysicalAddress - Memory physical address
3657 * Length - Length of memory allocated (or 0)
3658 * Context - The type of buffer allocated
3659 *
3660 * Return
3661 * None.
3662 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303663static int sxg_allocate_complete(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003664 void *VirtualAddress,
3665 dma_addr_t PhysicalAddress,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303666 u32 Length, enum sxg_buffer_type Context)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003667{
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303668 int status = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003669 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocCmp",
3670 adapter, VirtualAddress, Length, Context);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303671 ASSERT(atomic_read(&adapter->pending_allocations));
3672 atomic_dec(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003673
3674 switch (Context) {
3675
3676 case SXG_BUFFER_TYPE_RCV:
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303677 status = sxg_allocate_rcvblock_complete(adapter,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003678 VirtualAddress,
3679 PhysicalAddress, Length);
3680 break;
3681 case SXG_BUFFER_TYPE_SGL:
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303682 sxg_allocate_sgl_buffer_complete(adapter, (struct sxg_scatter_gather *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003683 VirtualAddress,
3684 PhysicalAddress, Length);
3685 break;
3686 }
3687 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocCmp",
3688 adapter, VirtualAddress, Length, Context);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303689
3690 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003691}
3692
3693/*
3694 * sxg_allocate_buffer_memory - Shared memory allocation routine used for
3695 * synchronous and asynchronous buffer allocations
3696 *
3697 * Arguments -
3698 * adapter - A pointer to our adapter structure
3699 * Size - block size to allocate
3700 * BufferType - Type of buffer to allocate
3701 *
3702 * Return
3703 * int
3704 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003705static int sxg_allocate_buffer_memory(struct adapter_t *adapter,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303706 u32 Size, enum sxg_buffer_type BufferType)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003707{
3708 int status;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003709 void *Buffer;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003710 dma_addr_t pBuffer;
3711
3712 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocMem",
3713 adapter, Size, BufferType, 0);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303714 /*
3715 * Grab the adapter lock and check the state. If we're in anything other
3716 * than INITIALIZING or RUNNING state, fail. This is to prevent
3717 * allocations in an improper driver state
3718 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003719
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303720 atomic_inc(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003721
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303722 if(BufferType != SXG_BUFFER_TYPE_SGL)
3723 Buffer = pci_alloc_consistent(adapter->pcidev, Size, &pBuffer);
3724 else {
3725 Buffer = kzalloc(Size, GFP_ATOMIC);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303726 pBuffer = (dma_addr_t)NULL;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303727 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003728 if (Buffer == NULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303729 /*
3730 * Decrement the AllocationsPending count while holding
3731 * the lock. Pause processing relies on this
3732 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303733 atomic_dec(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003734 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlcMemF1",
3735 adapter, Size, BufferType, 0);
3736 return (STATUS_RESOURCES);
3737 }
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303738 status = sxg_allocate_complete(adapter, Buffer, pBuffer, Size, BufferType);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003739
3740 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocMem",
3741 adapter, Size, BufferType, status);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303742 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003743}
3744
3745/*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303746 * sxg_allocate_rcvblock_complete - Complete a receive descriptor
3747 * block allocation
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003748 *
3749 * Arguments -
3750 * adapter - A pointer to our adapter structure
3751 * RcvBlock - receive block virtual address
3752 * PhysicalAddress - Physical address
3753 * Length - Memory length
3754 *
3755 * Return
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003756 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303757static int sxg_allocate_rcvblock_complete(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003758 void *RcvBlock,
3759 dma_addr_t PhysicalAddress,
3760 u32 Length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003761{
3762 u32 i;
3763 u32 BufferSize = adapter->ReceiveBufferSize;
3764 u64 Paddr;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303765 void *temp_RcvBlock;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303766 struct sxg_rcv_block_hdr *RcvBlockHdr;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303767 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3768 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
3769 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003770
3771 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlRcvBlk",
3772 adapter, RcvBlock, Length, 0);
3773 if (RcvBlock == NULL) {
3774 goto fail;
3775 }
3776 memset(RcvBlock, 0, Length);
3777 ASSERT((BufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
3778 (BufferSize == SXG_RCV_JUMBO_BUFFER_SIZE));
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303779 ASSERT(Length == SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE));
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303780 /*
3781 * First, initialize the contained pool of receive data buffers.
3782 * This initialization requires NBL/NB/MDL allocations, if any of them
3783 * fail, free the block and return without queueing the shared memory
3784 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303785 //RcvDataBuffer = RcvBlock;
3786 temp_RcvBlock = RcvBlock;
3787 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
3788 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3789 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *)
3790 temp_RcvBlock;
3791 /* For FREE macro assertion */
3792 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
3793 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
3794 if (RcvDataBufferHdr->SxgDumbRcvPacket == NULL)
3795 goto fail;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303796
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303797 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003798
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303799 /*
3800 * Place this entire block of memory on the AllRcvBlocks queue so it
3801 * can be free later
3802 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303803
3804 RcvBlockHdr = (struct sxg_rcv_block_hdr *) ((unsigned char *)RcvBlock +
3805 SXG_RCV_BLOCK_HDR_OFFSET(SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003806 RcvBlockHdr->VirtualAddress = RcvBlock;
3807 RcvBlockHdr->PhysicalAddress = PhysicalAddress;
3808 spin_lock(&adapter->RcvQLock);
3809 adapter->AllRcvBlockCount++;
3810 InsertTailList(&adapter->AllRcvBlocks, &RcvBlockHdr->AllList);
3811 spin_unlock(&adapter->RcvQLock);
3812
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303813 /* Now free the contained receive data buffers that we
3814 * initialized above */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303815 temp_RcvBlock = RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003816 for (i = 0, Paddr = PhysicalAddress;
3817 i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303818 i++, Paddr += SXG_RCV_DATA_HDR_SIZE,
3819 temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3820 RcvDataBufferHdr =
3821 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003822 spin_lock(&adapter->RcvQLock);
3823 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
3824 spin_unlock(&adapter->RcvQLock);
3825 }
3826
J.R. Maurob243c4a2008-10-20 19:28:58 -04003827 /* Locate the descriptor block and put it on a separate free queue */
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003828 RcvDescriptorBlock =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303829 (struct sxg_rcv_descriptor_block *) ((unsigned char *)RcvBlock +
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003830 SXG_RCV_DESCRIPTOR_BLOCK_OFFSET
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303831 (SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003832 RcvDescriptorBlockHdr =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303833 (struct sxg_rcv_descriptor_block_hdr *) ((unsigned char *)RcvBlock +
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003834 SXG_RCV_DESCRIPTOR_BLOCK_HDR_OFFSET
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303835 (SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003836 RcvDescriptorBlockHdr->VirtualAddress = RcvDescriptorBlock;
3837 RcvDescriptorBlockHdr->PhysicalAddress = Paddr;
3838 spin_lock(&adapter->RcvQLock);
3839 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter, RcvDescriptorBlockHdr);
3840 spin_unlock(&adapter->RcvQLock);
3841 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlRBlk",
3842 adapter, RcvBlock, Length, 0);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303843 return STATUS_SUCCESS;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303844fail:
J.R. Maurob243c4a2008-10-20 19:28:58 -04003845 /* Free any allocated resources */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003846 if (RcvBlock) {
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303847 temp_RcvBlock = RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003848 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303849 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003850 RcvDataBufferHdr =
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303851 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003852 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3853 }
3854 pci_free_consistent(adapter->pcidev,
3855 Length, RcvBlock, PhysicalAddress);
3856 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07003857 DBG_ERROR("%s: OUT OF RESOURCES\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003858 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "RcvAFail",
3859 adapter, adapter->FreeRcvBufferCount,
3860 adapter->FreeRcvBlockCount, adapter->AllRcvBlockCount);
3861 adapter->Stats.NoMem++;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303862 /* As allocation failed, free all previously allocated blocks..*/
3863 //sxg_free_rcvblocks(adapter);
3864
3865 return STATUS_RESOURCES;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003866}
3867
3868/*
3869 * sxg_allocate_sgl_buffer_complete - Complete a SGL buffer allocation
3870 *
3871 * Arguments -
3872 * adapter - A pointer to our adapter structure
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303873 * SxgSgl - struct sxg_scatter_gather buffer
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003874 * PhysicalAddress - Physical address
3875 * Length - Memory length
3876 *
3877 * Return
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003878 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003879static void sxg_allocate_sgl_buffer_complete(struct adapter_t *adapter,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303880 struct sxg_scatter_gather *SxgSgl,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003881 dma_addr_t PhysicalAddress,
3882 u32 Length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003883{
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303884 unsigned long sgl_flags;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003885 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlSglCmp",
3886 adapter, SxgSgl, Length, 0);
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05303887 spin_lock_irqsave(&adapter->SglQLock, sgl_flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003888 adapter->AllSglBufferCount++;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303889 /* PhysicalAddress; */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303890 SxgSgl->PhysicalAddress = PhysicalAddress;
3891 /* Initialize backpointer once */
3892 SxgSgl->adapter = adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003893 InsertTailList(&adapter->AllSglBuffers, &SxgSgl->AllList);
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05303894 spin_unlock_irqrestore(&adapter->SglQLock, sgl_flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003895 SxgSgl->State = SXG_BUFFER_BUSY;
Mithlesh Thukralc5e5cf52009-02-06 19:31:40 +05303896 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003897 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlSgl",
3898 adapter, SxgSgl, Length, 0);
3899}
3900
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003901
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303902static int sxg_adapter_set_hwaddr(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003903{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303904 /*
3905 * DBG_ERROR ("%s ENTER card->config_set[%x] port[%d] physport[%d] \
3906 * funct#[%d]\n", __func__, card->config_set,
3907 * adapter->port, adapter->physport, adapter->functionnumber);
3908 *
3909 * sxg_dbg_macaddrs(adapter);
3910 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303911 /* DBG_ERROR ("%s AFTER copying from config.macinfo into currmacaddr\n",
3912 * __FUNCTION__);
3913 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003914
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303915 /* sxg_dbg_macaddrs(adapter); */
3916
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303917 struct net_device * dev = adapter->netdev;
3918 if(!dev)
3919 {
3920 printk("sxg: Dev is Null\n");
3921 }
3922
3923 DBG_ERROR("%s ENTER (%s)\n", __FUNCTION__, adapter->netdev->name);
3924
3925 if (netif_running(dev)) {
3926 return -EBUSY;
3927 }
3928 if (!adapter) {
3929 return -EBUSY;
3930 }
3931
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003932 if (!(adapter->currmacaddr[0] ||
3933 adapter->currmacaddr[1] ||
3934 adapter->currmacaddr[2] ||
3935 adapter->currmacaddr[3] ||
3936 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
3937 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
3938 }
3939 if (adapter->netdev) {
3940 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303941 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003942 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303943 /* DBG_ERROR ("%s EXIT port %d\n", __func__, adapter->port); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003944 sxg_dbg_macaddrs(adapter);
3945
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303946 return 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003947}
3948
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003949#if XXXTODO
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303950static int sxg_mac_set_address(struct net_device *dev, void *ptr)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003951{
J.R. Mauro73b07062008-10-28 18:42:02 -04003952 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003953 struct sockaddr *addr = ptr;
3954
Harvey Harrisone88bd232008-10-17 14:46:10 -07003955 DBG_ERROR("%s ENTER (%s)\n", __func__, adapter->netdev->name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003956
3957 if (netif_running(dev)) {
3958 return -EBUSY;
3959 }
3960 if (!adapter) {
3961 return -EBUSY;
3962 }
3963 DBG_ERROR("sxg: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07003964 __func__, adapter->netdev->name, adapter->currmacaddr[0],
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003965 adapter->currmacaddr[1], adapter->currmacaddr[2],
3966 adapter->currmacaddr[3], adapter->currmacaddr[4],
3967 adapter->currmacaddr[5]);
3968 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3969 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3970 DBG_ERROR("sxg: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07003971 __func__, adapter->netdev->name, adapter->currmacaddr[0],
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003972 adapter->currmacaddr[1], adapter->currmacaddr[2],
3973 adapter->currmacaddr[3], adapter->currmacaddr[4],
3974 adapter->currmacaddr[5]);
3975
3976 sxg_config_set(adapter, TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003977 return 0;
3978}
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003979#endif
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003980
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003981/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303982 * SXG DRIVER FUNCTIONS (below)
3983 *
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003984 * sxg_initialize_adapter - Initialize adapter
3985 *
3986 * Arguments -
3987 * adapter - A pointer to our adapter structure
3988 *
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303989 * Return - int
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003990 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003991static int sxg_initialize_adapter(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003992{
3993 u32 RssIds, IsrCount;
3994 u32 i;
3995 int status;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05303996 int sxg_rcv_ring_size = SXG_RCV_RING_SIZE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003997
3998 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitAdpt",
3999 adapter, 0, 0, 0);
4000
J.R. Maurob243c4a2008-10-20 19:28:58 -04004001 RssIds = 1; /* XXXTODO SXG_RSS_CPU_COUNT(adapter); */
Mithlesh Thukral1782199f2009-02-06 19:32:28 +05304002 IsrCount = adapter->msi_enabled ? RssIds : 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004003
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304004 /*
4005 * Sanity check SXG_UCODE_REGS structure definition to
4006 * make sure the length is correct
4007 */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304008 ASSERT(sizeof(struct sxg_ucode_regs) == SXG_REGISTER_SIZE_PER_CPU);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004009
J.R. Maurob243c4a2008-10-20 19:28:58 -04004010 /* Disable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004011 SXG_DISABLE_ALL_INTERRUPTS(adapter);
4012
J.R. Maurob243c4a2008-10-20 19:28:58 -04004013 /* Set MTU */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004014 ASSERT((adapter->FrameSize == ETHERMAXFRAME) ||
4015 (adapter->FrameSize == JUMBOMAXFRAME));
4016 WRITE_REG(adapter->UcodeRegs[0].LinkMtu, adapter->FrameSize, TRUE);
4017
J.R. Maurob243c4a2008-10-20 19:28:58 -04004018 /* Set event ring base address and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004019 WRITE_REG64(adapter,
4020 adapter->UcodeRegs[0].EventBase, adapter->PEventRings, 0);
4021 WRITE_REG(adapter->UcodeRegs[0].EventSize, EVENT_RING_SIZE, TRUE);
4022
J.R. Maurob243c4a2008-10-20 19:28:58 -04004023 /* Per-ISR initialization */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004024 for (i = 0; i < IsrCount; i++) {
4025 u64 Addr;
J.R. Maurob243c4a2008-10-20 19:28:58 -04004026 /* Set interrupt status pointer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004027 Addr = adapter->PIsr + (i * sizeof(u32));
4028 WRITE_REG64(adapter, adapter->UcodeRegs[i].Isp, Addr, i);
4029 }
4030
J.R. Maurob243c4a2008-10-20 19:28:58 -04004031 /* XMT ring zero index */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004032 WRITE_REG64(adapter,
4033 adapter->UcodeRegs[0].SPSendIndex,
4034 adapter->PXmtRingZeroIndex, 0);
4035
J.R. Maurob243c4a2008-10-20 19:28:58 -04004036 /* Per-RSS initialization */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004037 for (i = 0; i < RssIds; i++) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04004038 /* Release all event ring entries to the Microcode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004039 WRITE_REG(adapter->UcodeRegs[i].EventRelease, EVENT_RING_SIZE,
4040 TRUE);
4041 }
4042
J.R. Maurob243c4a2008-10-20 19:28:58 -04004043 /* Transmit ring base and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004044 WRITE_REG64(adapter,
4045 adapter->UcodeRegs[0].XmtBase, adapter->PXmtRings, 0);
4046 WRITE_REG(adapter->UcodeRegs[0].XmtSize, SXG_XMT_RING_SIZE, TRUE);
4047
J.R. Maurob243c4a2008-10-20 19:28:58 -04004048 /* Receive ring base and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004049 WRITE_REG64(adapter,
4050 adapter->UcodeRegs[0].RcvBase, adapter->PRcvRings, 0);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304051 if (adapter->JumboEnabled == TRUE)
4052 sxg_rcv_ring_size = SXG_JUMBO_RCV_RING_SIZE;
4053 WRITE_REG(adapter->UcodeRegs[0].RcvSize, sxg_rcv_ring_size, TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004054
J.R. Maurob243c4a2008-10-20 19:28:58 -04004055 /* Populate the card with receive buffers */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004056 sxg_stock_rcv_buffers(adapter);
4057
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304058 /*
4059 * Initialize checksum offload capabilities. At the moment we always
4060 * enable IP and TCP receive checksums on the card. Depending on the
4061 * checksum configuration specified by the user, we can choose to
4062 * report or ignore the checksum information provided by the card.
4063 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004064 WRITE_REG(adapter->UcodeRegs[0].ReceiveChecksum,
4065 SXG_RCV_TCP_CSUM_ENABLED | SXG_RCV_IP_CSUM_ENABLED, TRUE);
4066
J.R. Maurob243c4a2008-10-20 19:28:58 -04004067 /* Initialize the MAC, XAUI */
Harvey Harrisone88bd232008-10-17 14:46:10 -07004068 DBG_ERROR("sxg: %s ENTER sxg_initialize_link\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004069 status = sxg_initialize_link(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07004070 DBG_ERROR("sxg: %s EXIT sxg_initialize_link status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004071 status);
4072 if (status != STATUS_SUCCESS) {
4073 return (status);
4074 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304075 /*
4076 * Initialize Dead to FALSE.
4077 * SlicCheckForHang or SlicDumpThread will take it from here.
4078 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004079 adapter->Dead = FALSE;
4080 adapter->PingOutstanding = FALSE;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05304081 adapter->State = SXG_STATE_RUNNING;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004082
4083 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInit",
4084 adapter, 0, 0, 0);
4085 return (STATUS_SUCCESS);
4086}
4087
4088/*
4089 * sxg_fill_descriptor_block - Populate a descriptor block and give it to
4090 * the card. The caller should hold the RcvQLock
4091 *
4092 * Arguments -
4093 * adapter - A pointer to our adapter structure
4094 * RcvDescriptorBlockHdr - Descriptor block to fill
4095 *
4096 * Return
4097 * status
4098 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004099static int sxg_fill_descriptor_block(struct adapter_t *adapter,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304100 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004101{
4102 u32 i;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304103 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4104 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
4105 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
4106 struct sxg_cmd *RingDescriptorCmd;
4107 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004108
4109 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "FilBlk",
4110 adapter, adapter->RcvBuffersOnCard,
4111 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4112
4113 ASSERT(RcvDescriptorBlockHdr);
4114
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304115 /*
4116 * If we don't have the resources to fill the descriptor block,
4117 * return failure
4118 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004119 if ((adapter->FreeRcvBufferCount < SXG_RCV_DESCRIPTORS_PER_BLOCK) ||
4120 SXG_RING_FULL(RcvRingInfo)) {
4121 adapter->Stats.NoMem++;
4122 return (STATUS_FAILURE);
4123 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004124 /* Get a ring descriptor command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004125 SXG_GET_CMD(RingZero,
4126 RcvRingInfo, RingDescriptorCmd, RcvDescriptorBlockHdr);
4127 ASSERT(RingDescriptorCmd);
4128 RcvDescriptorBlockHdr->State = SXG_BUFFER_ONCARD;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304129 RcvDescriptorBlock = (struct sxg_rcv_descriptor_block *)
4130 RcvDescriptorBlockHdr->VirtualAddress;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004131
J.R. Maurob243c4a2008-10-20 19:28:58 -04004132 /* Fill in the descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004133 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK; i++) {
4134 SXG_GET_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
4135 ASSERT(RcvDataBufferHdr);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304136// ASSERT(RcvDataBufferHdr->SxgDumbRcvPacket);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304137 if (!RcvDataBufferHdr->SxgDumbRcvPacket) {
4138 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr,
4139 adapter->ReceiveBufferSize);
4140 if(RcvDataBufferHdr->skb)
4141 RcvDataBufferHdr->SxgDumbRcvPacket =
4142 RcvDataBufferHdr->skb;
4143 else
4144 goto no_memory;
4145 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004146 SXG_REINIATIALIZE_PACKET(RcvDataBufferHdr->SxgDumbRcvPacket);
4147 RcvDataBufferHdr->State = SXG_BUFFER_ONCARD;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004148 RcvDescriptorBlock->Descriptors[i].VirtualAddress =
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304149 (void *)RcvDataBufferHdr;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05304150
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004151 RcvDescriptorBlock->Descriptors[i].PhysicalAddress =
4152 RcvDataBufferHdr->PhysicalAddress;
4153 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004154 /* Add the descriptor block to receive descriptor ring 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004155 RingDescriptorCmd->Sgl = RcvDescriptorBlockHdr->PhysicalAddress;
4156
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304157 /*
4158 * RcvBuffersOnCard is not protected via the receive lock (see
4159 * sxg_process_event_queue) We don't want to grap a lock every time a
4160 * buffer is returned to us, so we use atomic interlocked functions
4161 * instead.
4162 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004163 adapter->RcvBuffersOnCard += SXG_RCV_DESCRIPTORS_PER_BLOCK;
4164
4165 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DscBlk",
4166 RcvDescriptorBlockHdr,
4167 RingDescriptorCmd, RcvRingInfo->Head, RcvRingInfo->Tail);
4168
4169 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 1, true);
4170 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlk",
4171 adapter, adapter->RcvBuffersOnCard,
4172 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4173 return (STATUS_SUCCESS);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304174no_memory:
4175 return (-ENOMEM);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004176}
4177
4178/*
4179 * sxg_stock_rcv_buffers - Stock the card with receive buffers
4180 *
4181 * Arguments -
4182 * adapter - A pointer to our adapter structure
4183 *
4184 * Return
4185 * None
4186 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004187static void sxg_stock_rcv_buffers(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004188{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304189 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304190 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
4191 int sxg_min_rcv_data_buffers = SXG_MIN_RCV_DATA_BUFFERS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004192
4193 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "StockBuf",
4194 adapter, adapter->RcvBuffersOnCard,
4195 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304196 /*
4197 * First, see if we've got less than our minimum threshold of
4198 * receive buffers, there isn't an allocation in progress, and
4199 * we haven't exceeded our maximum.. get another block of buffers
4200 * None of this needs to be SMP safe. It's round numbers.
4201 */
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304202 if (adapter->JumboEnabled == TRUE)
4203 sxg_min_rcv_data_buffers = SXG_MIN_JUMBO_RCV_DATA_BUFFERS;
4204 if ((adapter->FreeRcvBufferCount < sxg_min_rcv_data_buffers) &&
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004205 (adapter->AllRcvBlockCount < SXG_MAX_RCV_BLOCKS) &&
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304206 (atomic_read(&adapter->pending_allocations) == 0)) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004207 sxg_allocate_buffer_memory(adapter,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05304208 SXG_RCV_BLOCK_SIZE
4209 (SXG_RCV_DATA_HDR_SIZE),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004210 SXG_BUFFER_TYPE_RCV);
4211 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004212 /* Now grab the RcvQLock lock and proceed */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004213 spin_lock(&adapter->RcvQLock);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304214 if (adapter->JumboEnabled)
4215 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
4216 while (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304217 struct list_entry *_ple;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004218
J.R. Maurob243c4a2008-10-20 19:28:58 -04004219 /* Get a descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004220 RcvDescriptorBlockHdr = NULL;
4221 if (adapter->FreeRcvBlockCount) {
4222 _ple = RemoveHeadList(&adapter->FreeRcvBlocks);
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004223 RcvDescriptorBlockHdr =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304224 container_of(_ple, struct sxg_rcv_descriptor_block_hdr,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004225 FreeList);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004226 adapter->FreeRcvBlockCount--;
4227 RcvDescriptorBlockHdr->State = SXG_BUFFER_BUSY;
4228 }
4229
4230 if (RcvDescriptorBlockHdr == NULL) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04004231 /* Bail out.. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004232 adapter->Stats.NoMem++;
4233 break;
4234 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004235 /* Fill in the descriptor block and give it to the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004236 if (sxg_fill_descriptor_block(adapter, RcvDescriptorBlockHdr) ==
4237 STATUS_FAILURE) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04004238 /* Free the descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004239 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4240 RcvDescriptorBlockHdr);
4241 break;
4242 }
4243 }
4244 spin_unlock(&adapter->RcvQLock);
4245 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlks",
4246 adapter, adapter->RcvBuffersOnCard,
4247 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4248}
4249
4250/*
4251 * sxg_complete_descriptor_blocks - Return descriptor blocks that have been
4252 * completed by the microcode
4253 *
4254 * Arguments -
4255 * adapter - A pointer to our adapter structure
4256 * Index - Where the microcode is up to
4257 *
4258 * Return
4259 * None
4260 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004261static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004262 unsigned char Index)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004263{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304264 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
4265 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4266 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
4267 struct sxg_cmd *RingDescriptorCmd;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004268
4269 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlks",
4270 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4271
J.R. Maurob243c4a2008-10-20 19:28:58 -04004272 /* Now grab the RcvQLock lock and proceed */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004273 spin_lock(&adapter->RcvQLock);
4274 ASSERT(Index != RcvRingInfo->Tail);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304275 while (sxg_ring_get_forward_diff(RcvRingInfo, Index,
4276 RcvRingInfo->Tail) > 3) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304277 /*
4278 * Locate the current Cmd (ring descriptor entry), and
4279 * associated receive descriptor block, and advance
4280 * the tail
4281 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004282 SXG_RETURN_CMD(RingZero,
4283 RcvRingInfo,
4284 RingDescriptorCmd, RcvDescriptorBlockHdr);
4285 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlk",
4286 RcvRingInfo->Head, RcvRingInfo->Tail,
4287 RingDescriptorCmd, RcvDescriptorBlockHdr);
4288
J.R. Maurob243c4a2008-10-20 19:28:58 -04004289 /* Clear the SGL field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004290 RingDescriptorCmd->Sgl = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304291 /*
4292 * Attempt to refill it and hand it right back to the
4293 * card. If we fail to refill it, free the descriptor block
4294 * header. The card will be restocked later via the
4295 * RcvBuffersOnCard test
4296 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304297 if (sxg_fill_descriptor_block(adapter,
4298 RcvDescriptorBlockHdr) == STATUS_FAILURE)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004299 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4300 RcvDescriptorBlockHdr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004301 }
4302 spin_unlock(&adapter->RcvQLock);
4303 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XCRBlks",
4304 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4305}
4306
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304307/*
4308 * Read the statistics which the card has been maintaining.
4309 */
4310void sxg_collect_statistics(struct adapter_t *adapter)
4311{
4312 if(adapter->ucode_stats)
Mithlesh Thukral54aed112009-01-19 20:27:17 +05304313 WRITE_REG64(adapter, adapter->UcodeRegs[0].GetUcodeStats,
4314 adapter->pucode_stats, 0);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304315 adapter->stats.rx_fifo_errors = adapter->ucode_stats->ERDrops;
4316 adapter->stats.rx_over_errors = adapter->ucode_stats->NBDrops;
4317 adapter->stats.tx_fifo_errors = adapter->ucode_stats->XDrops;
4318}
4319
4320static struct net_device_stats *sxg_get_stats(struct net_device * dev)
4321{
4322 struct adapter_t *adapter = netdev_priv(dev);
4323
4324 sxg_collect_statistics(adapter);
4325 return (&adapter->stats);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304326}
4327
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004328static struct pci_driver sxg_driver = {
Mithlesh Thukral371d7a92009-01-19 20:22:34 +05304329 .name = sxg_driver_name,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004330 .id_table = sxg_pci_tbl,
4331 .probe = sxg_entry_probe,
4332 .remove = sxg_entry_remove,
4333#if SXG_POWER_MANAGEMENT_ENABLED
4334 .suspend = sxgpm_suspend,
4335 .resume = sxgpm_resume,
4336#endif
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304337 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004338};
4339
4340static int __init sxg_module_init(void)
4341{
4342 sxg_init_driver();
4343
4344 if (debug >= 0)
4345 sxg_debug = debug;
4346
4347 return pci_register_driver(&sxg_driver);
4348}
4349
4350static void __exit sxg_module_cleanup(void)
4351{
4352 pci_unregister_driver(&sxg_driver);
4353}
4354
4355module_init(sxg_module_init);
4356module_exit(sxg_module_cleanup);