blob: 951904320d9e615fc921e24b86cc5883b4e7ff99 [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 Thukrald9d578b2009-01-19 20:23:22 +0530122static void sxg_complete_slow_send(struct adapter_t *adapter, int irq_context);
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 Thukrald0128aa2009-01-05 21:18:04 +0530135
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -0700136#define XXXTODO 0
137
Greg Kroah-Hartman96e70882009-01-21 08:17:45 -0800138#if XXXTODO
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530139static int sxg_mac_set_address(struct net_device *dev, void *ptr);
Greg Kroah-Hartman96e70882009-01-21 08:17:45 -0800140#endif
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530141static void sxg_mcast_set_list(struct net_device *dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700142
Mithlesh Thukral54aed112009-01-19 20:27:17 +0530143static int sxg_adapter_set_hwaddr(struct adapter_t *adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700144
J.R. Mauro73b07062008-10-28 18:42:02 -0400145static int sxg_initialize_adapter(struct adapter_t *adapter);
146static void sxg_stock_rcv_buffers(struct adapter_t *adapter);
147static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400148 unsigned char Index);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +0530149int sxg_change_mtu (struct net_device *netdev, int new_mtu);
J.R. Mauro73b07062008-10-28 18:42:02 -0400150static int sxg_initialize_link(struct adapter_t *adapter);
151static int sxg_phy_init(struct adapter_t *adapter);
152static void sxg_link_event(struct adapter_t *adapter);
153static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530154static void sxg_link_state(struct adapter_t *adapter,
155 enum SXG_LINK_STATE LinkState);
J.R. Mauro73b07062008-10-28 18:42:02 -0400156static int sxg_write_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400157 u32 DevAddr, u32 RegAddr, u32 Value);
J.R. Mauro73b07062008-10-28 18:42:02 -0400158static int sxg_read_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400159 u32 DevAddr, u32 RegAddr, u32 *pValue);
Mithlesh Thukralb040b072009-01-28 07:08:11 +0530160static void sxg_set_mcast_addr(struct adapter_t *adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700161
162static unsigned int sxg_first_init = 1;
163static char *sxg_banner =
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530164 "Alacritech SLIC Technology(tm) Server and Storage \
165 10Gbe Accelerator (Non-Accelerated)\n";
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700166
167static int sxg_debug = 1;
168static int debug = -1;
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530169static struct net_device *head_netdevice = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700170
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530171static struct sxgbase_driver sxg_global = {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700172 .dynamic_intagg = 1,
173};
174static int intagg_delay = 100;
175static u32 dynamic_intagg = 0;
176
Mithlesh Thukral54aed112009-01-19 20:27:17 +0530177char sxg_driver_name[] = "sxg_nic";
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700178#define DRV_AUTHOR "Alacritech, Inc. Engineering"
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530179#define DRV_DESCRIPTION \
180 "Alacritech SLIC Techonology(tm) Non-Accelerated 10Gbe Driver"
181#define DRV_COPYRIGHT \
182 "Copyright 2000-2008 Alacritech, Inc. All rights reserved."
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700183
184MODULE_AUTHOR(DRV_AUTHOR);
185MODULE_DESCRIPTION(DRV_DESCRIPTION);
186MODULE_LICENSE("GPL");
187
188module_param(dynamic_intagg, int, 0);
189MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
190module_param(intagg_delay, int, 0);
191MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
192
193static struct pci_device_id sxg_pci_tbl[] __devinitdata = {
194 {PCI_DEVICE(SXG_VENDOR_ID, SXG_DEVICE_ID)},
195 {0,}
196};
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400197
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700198MODULE_DEVICE_TABLE(pci, sxg_pci_tbl);
199
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700200static inline void sxg_reg32_write(void __iomem *reg, u32 value, bool flush)
201{
202 writel(value, reg);
203 if (flush)
204 mb();
205}
206
J.R. Mauro73b07062008-10-28 18:42:02 -0400207static inline void sxg_reg64_write(struct adapter_t *adapter, void __iomem *reg,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700208 u64 value, u32 cpu)
209{
210 u32 value_high = (u32) (value >> 32);
211 u32 value_low = (u32) (value & 0x00000000FFFFFFFF);
212 unsigned long flags;
213
214 spin_lock_irqsave(&adapter->Bit64RegLock, flags);
215 writel(value_high, (void __iomem *)(&adapter->UcodeRegs[cpu].Upper));
216 writel(value_low, reg);
217 spin_unlock_irqrestore(&adapter->Bit64RegLock, flags);
218}
219
220static void sxg_init_driver(void)
221{
222 if (sxg_first_init) {
223 DBG_ERROR("sxg: %s sxg_first_init set jiffies[%lx]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700224 __func__, jiffies);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700225 sxg_first_init = 0;
226 spin_lock_init(&sxg_global.driver_lock);
227 }
228}
229
J.R. Mauro73b07062008-10-28 18:42:02 -0400230static void sxg_dbg_macaddrs(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700231{
232 DBG_ERROR(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
233 adapter->netdev->name, adapter->currmacaddr[0],
234 adapter->currmacaddr[1], adapter->currmacaddr[2],
235 adapter->currmacaddr[3], adapter->currmacaddr[4],
236 adapter->currmacaddr[5]);
237 DBG_ERROR(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
238 adapter->netdev->name, adapter->macaddr[0],
239 adapter->macaddr[1], adapter->macaddr[2],
240 adapter->macaddr[3], adapter->macaddr[4],
241 adapter->macaddr[5]);
242 return;
243}
244
J.R. Maurob243c4a2008-10-20 19:28:58 -0400245/* SXG Globals */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530246static struct sxg_driver SxgDriver;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700247
248#ifdef ATKDBG
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530249static struct sxg_trace_buffer LSxgTraceBuffer;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700250#endif /* ATKDBG */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530251static struct sxg_trace_buffer *SxgTraceBuffer = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700252
253/*
254 * sxg_download_microcode
255 *
256 * Download Microcode to Sahara adapter
257 *
258 * Arguments -
259 * adapter - A pointer to our adapter structure
260 * UcodeSel - microcode file selection
261 *
262 * Return
263 * int
264 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530265static bool sxg_download_microcode(struct adapter_t *adapter,
266 enum SXG_UCODE_SEL UcodeSel)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700267{
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530268 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700269 u32 Section;
270 u32 ThisSectionSize;
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400271 u32 *Instruction = NULL;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700272 u32 BaseAddress, AddressOffset, Address;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530273 /* u32 Failure; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700274 u32 ValueRead;
275 u32 i;
276 u32 numSections = 0;
277 u32 sectionSize[16];
278 u32 sectionStart[16];
279
280 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DnldUcod",
281 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700282 DBG_ERROR("sxg: %s ENTER\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700283
284 switch (UcodeSel) {
J.R. Maurob243c4a2008-10-20 19:28:58 -0400285 case SXG_UCODE_SAHARA: /* Sahara operational ucode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700286 numSections = SNumSections;
287 for (i = 0; i < numSections; i++) {
288 sectionSize[i] = SSectionSize[i];
289 sectionStart[i] = SSectionStart[i];
290 }
291 break;
292 default:
293 printk(KERN_ERR KBUILD_MODNAME
294 ": Woah, big error with the microcode!\n");
295 break;
296 }
297
298 DBG_ERROR("sxg: RESET THE CARD\n");
J.R. Maurob243c4a2008-10-20 19:28:58 -0400299 /* First, reset the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700300 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
301
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530302 /*
303 * Download each section of the microcode as specified in
304 * its download file. The *download.c file is generated using
305 * the saharaobjtoc facility which converts the metastep .obj
306 * file to a .c file which contains a two dimentional array.
307 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700308 for (Section = 0; Section < numSections; Section++) {
309 DBG_ERROR("sxg: SECTION # %d\n", Section);
310 switch (UcodeSel) {
311 case SXG_UCODE_SAHARA:
312 Instruction = (u32 *) & SaharaUCode[Section][0];
313 break;
314 default:
315 ASSERT(0);
316 break;
317 }
318 BaseAddress = sectionStart[Section];
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530319 /* Size in instructions */
320 ThisSectionSize = sectionSize[Section] / 12;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700321 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
322 AddressOffset++) {
323 Address = BaseAddress + AddressOffset;
324 ASSERT((Address & ~MICROCODE_ADDRESS_MASK) == 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400325 /* Write instruction bits 31 - 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700326 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400327 /* Write instruction bits 63-32 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700328 WRITE_REG(HwRegs->UcodeDataMiddle, *(Instruction + 1),
329 FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400330 /* Write instruction bits 95-64 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700331 WRITE_REG(HwRegs->UcodeDataHigh, *(Instruction + 2),
332 FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400333 /* Write instruction address with the WRITE bit set */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700334 WRITE_REG(HwRegs->UcodeAddr,
335 (Address | MICROCODE_ADDRESS_WRITE), FLUSH);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530336 /*
337 * Sahara bug in the ucode download logic - the write to DataLow
338 * for the next instruction could get corrupted. To avoid this,
339 * write to DataLow again for this instruction (which may get
340 * corrupted, but it doesn't matter), then increment the address
341 * and write the data for the next instruction to DataLow. That
342 * write should succeed.
343 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700344 WRITE_REG(HwRegs->UcodeDataLow, *Instruction, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400345 /* Advance 3 u32S to start of next instruction */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700346 Instruction += 3;
347 }
348 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530349 /*
350 * Now repeat the entire operation reading the instruction back and
351 * checking for parity errors
352 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700353 for (Section = 0; Section < numSections; Section++) {
354 DBG_ERROR("sxg: check SECTION # %d\n", Section);
355 switch (UcodeSel) {
356 case SXG_UCODE_SAHARA:
357 Instruction = (u32 *) & SaharaUCode[Section][0];
358 break;
359 default:
360 ASSERT(0);
361 break;
362 }
363 BaseAddress = sectionStart[Section];
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530364 /* Size in instructions */
365 ThisSectionSize = sectionSize[Section] / 12;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700366 for (AddressOffset = 0; AddressOffset < ThisSectionSize;
367 AddressOffset++) {
368 Address = BaseAddress + AddressOffset;
J.R. Maurob243c4a2008-10-20 19:28:58 -0400369 /* Write the address with the READ bit set */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700370 WRITE_REG(HwRegs->UcodeAddr,
371 (Address | MICROCODE_ADDRESS_READ), FLUSH);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400372 /* Read it back and check parity bit. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700373 READ_REG(HwRegs->UcodeAddr, ValueRead);
374 if (ValueRead & MICROCODE_ADDRESS_PARITY) {
375 DBG_ERROR("sxg: %s PARITY ERROR\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700376 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700377
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530378 return FALSE; /* Parity error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700379 }
380 ASSERT((ValueRead & MICROCODE_ADDRESS_MASK) == Address);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400381 /* Read the instruction back and compare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700382 READ_REG(HwRegs->UcodeDataLow, ValueRead);
383 if (ValueRead != *Instruction) {
384 DBG_ERROR("sxg: %s MISCOMPARE LOW\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700385 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530386 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700387 }
388 READ_REG(HwRegs->UcodeDataMiddle, ValueRead);
389 if (ValueRead != *(Instruction + 1)) {
390 DBG_ERROR("sxg: %s MISCOMPARE MIDDLE\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700391 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530392 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700393 }
394 READ_REG(HwRegs->UcodeDataHigh, ValueRead);
395 if (ValueRead != *(Instruction + 2)) {
396 DBG_ERROR("sxg: %s MISCOMPARE HIGH\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700397 __func__);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530398 return FALSE; /* Miscompare */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700399 }
J.R. Maurob243c4a2008-10-20 19:28:58 -0400400 /* Advance 3 u32S to start of next instruction */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700401 Instruction += 3;
402 }
403 }
404
J.R. Maurob243c4a2008-10-20 19:28:58 -0400405 /* Everything OK, Go. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700406 WRITE_REG(HwRegs->UcodeAddr, MICROCODE_ADDRESS_GO, FLUSH);
407
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530408 /*
409 * Poll the CardUp register to wait for microcode to initialize
410 * Give up after 10,000 attemps (500ms).
411 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700412 for (i = 0; i < 10000; i++) {
413 udelay(50);
414 READ_REG(adapter->UcodeRegs[0].CardUp, ValueRead);
415 if (ValueRead == 0xCAFE) {
Harvey Harrisone88bd232008-10-17 14:46:10 -0700416 DBG_ERROR("sxg: %s BOO YA 0xCAFE\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700417 break;
418 }
419 }
420 if (i == 10000) {
Harvey Harrisone88bd232008-10-17 14:46:10 -0700421 DBG_ERROR("sxg: %s TIMEOUT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700422
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530423 return FALSE; /* Timeout */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700424 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530425 /*
426 * Now write the LoadSync register. This is used to
427 * synchronize with the card so it can scribble on the memory
428 * that contained 0xCAFE from the "CardUp" step above
429 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700430 if (UcodeSel == SXG_UCODE_SAHARA) {
431 WRITE_REG(adapter->UcodeRegs[0].LoadSync, 0, FLUSH);
432 }
433
434 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDnldUcd",
435 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700436 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700437
438 return (TRUE);
439}
440
441/*
442 * sxg_allocate_resources - Allocate memory and locks
443 *
444 * Arguments -
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530445 * adapter - A pointer to our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700446 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530447 * Return - int
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700448 */
J.R. Mauro73b07062008-10-28 18:42:02 -0400449static int sxg_allocate_resources(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700450{
451 int status;
452 u32 i;
453 u32 RssIds, IsrCount;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530454 /* struct sxg_xmt_ring *XmtRing; */
455 /* struct sxg_rcv_ring *RcvRing; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700456
Harvey Harrisone88bd232008-10-17 14:46:10 -0700457 DBG_ERROR("%s ENTER\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700458
459 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocRes",
460 adapter, 0, 0, 0);
461
J.R. Maurob243c4a2008-10-20 19:28:58 -0400462 /* Windows tells us how many CPUs it plans to use for */
463 /* RSS */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700464 RssIds = SXG_RSS_CPU_COUNT(adapter);
465 IsrCount = adapter->MsiEnabled ? RssIds : 1;
466
Harvey Harrisone88bd232008-10-17 14:46:10 -0700467 DBG_ERROR("%s Setup the spinlocks\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700468
J.R. Maurob243c4a2008-10-20 19:28:58 -0400469 /* Allocate spinlocks and initialize listheads first. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700470 spin_lock_init(&adapter->RcvQLock);
471 spin_lock_init(&adapter->SglQLock);
472 spin_lock_init(&adapter->XmtZeroLock);
473 spin_lock_init(&adapter->Bit64RegLock);
474 spin_lock_init(&adapter->AdapterLock);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +0530475 atomic_set(&adapter->pending_allocations, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700476
Harvey Harrisone88bd232008-10-17 14:46:10 -0700477 DBG_ERROR("%s Setup the lists\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700478
479 InitializeListHead(&adapter->FreeRcvBuffers);
480 InitializeListHead(&adapter->FreeRcvBlocks);
481 InitializeListHead(&adapter->AllRcvBlocks);
482 InitializeListHead(&adapter->FreeSglBuffers);
483 InitializeListHead(&adapter->AllSglBuffers);
484
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530485 /*
486 * Mark these basic allocations done. This flags essentially
487 * tells the SxgFreeResources routine that it can grab spinlocks
488 * and reference listheads.
489 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700490 adapter->BasicAllocations = TRUE;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530491 /*
492 * Main allocation loop. Start with the maximum supported by
493 * the microcode and back off if memory allocation
494 * fails. If we hit a minimum, fail.
495 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700496
497 for (;;) {
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700498 DBG_ERROR("%s Allocate XmtRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530499 (unsigned int)(sizeof(struct sxg_xmt_ring) * 1));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700500
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530501 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530502 * Start with big items first - receive and transmit rings.
503 * At the moment I'm going to keep the ring size fixed and
504 * adjust the TCBs if we fail. Later we might
505 * consider reducing the ring size as well..
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530506 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700507 adapter->XmtRings = pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530508 sizeof(struct sxg_xmt_ring) *
509 1,
510 &adapter->PXmtRings);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700511 DBG_ERROR("%s XmtRings[%p]\n", __func__, adapter->XmtRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700512
513 if (!adapter->XmtRings) {
514 goto per_tcb_allocation_failed;
515 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530516 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700517
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700518 DBG_ERROR("%s Allocate RcvRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530519 (unsigned int)(sizeof(struct sxg_rcv_ring) * 1));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700520 adapter->RcvRings =
521 pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530522 sizeof(struct sxg_rcv_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700523 &adapter->PRcvRings);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700524 DBG_ERROR("%s RcvRings[%p]\n", __func__, adapter->RcvRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700525 if (!adapter->RcvRings) {
526 goto per_tcb_allocation_failed;
527 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530528 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530529 adapter->ucode_stats = kzalloc(sizeof(struct sxg_ucode_stats), GFP_ATOMIC);
530 adapter->pucode_stats = pci_map_single(adapter->pcidev,
531 adapter->ucode_stats,
532 sizeof(struct sxg_ucode_stats),
533 PCI_DMA_FROMDEVICE);
534// memset(adapter->ucode_stats, 0, sizeof(struct sxg_ucode_stats));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700535 break;
536
537 per_tcb_allocation_failed:
J.R. Maurob243c4a2008-10-20 19:28:58 -0400538 /* an allocation failed. Free any successful allocations. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700539 if (adapter->XmtRings) {
540 pci_free_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530541 sizeof(struct sxg_xmt_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700542 adapter->XmtRings,
543 adapter->PXmtRings);
544 adapter->XmtRings = NULL;
545 }
546 if (adapter->RcvRings) {
547 pci_free_consistent(adapter->pcidev,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530548 sizeof(struct sxg_rcv_ring) * 1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700549 adapter->RcvRings,
550 adapter->PRcvRings);
551 adapter->RcvRings = NULL;
552 }
J.R. Maurob243c4a2008-10-20 19:28:58 -0400553 /* Loop around and try again.... */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +0530554 if (adapter->ucode_stats) {
555 pci_unmap_single(adapter->pcidev,
556 sizeof(struct sxg_ucode_stats),
557 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
558 adapter->ucode_stats = NULL;
559 }
560
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700561 }
562
Harvey Harrisone88bd232008-10-17 14:46:10 -0700563 DBG_ERROR("%s Initialize RCV ZERO and XMT ZERO rings\n", __func__);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400564 /* Initialize rcv zero and xmt zero rings */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700565 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
566 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
567
J.R. Maurob243c4a2008-10-20 19:28:58 -0400568 /* Sanity check receive data structure format */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530569 /* ASSERT((adapter->ReceiveBufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
570 (adapter->ReceiveBufferSize == SXG_RCV_JUMBO_BUFFER_SIZE)); */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530571 ASSERT(sizeof(struct sxg_rcv_descriptor_block) ==
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700572 SXG_RCV_DESCRIPTOR_BLOCK_SIZE);
573
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530574 /*
575 * Allocate receive data buffers. We allocate a block of buffers and
576 * a corresponding descriptor block at once. See sxghw.h:SXG_RCV_BLOCK
577 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700578 for (i = 0; i < SXG_INITIAL_RCV_DATA_BUFFERS;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530579 i += SXG_RCV_DESCRIPTORS_PER_BLOCK) {
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530580 status = sxg_allocate_buffer_memory(adapter,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530581 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700582 SXG_BUFFER_TYPE_RCV);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530583 if (status != STATUS_SUCCESS)
584 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700585 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530586 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530587 * NBL resource allocation can fail in the 'AllocateComplete' routine,
588 * which doesn't return status. Make sure we got the number of buffers
589 * we requested
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530590 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700591 if (adapter->FreeRcvBufferCount < SXG_INITIAL_RCV_DATA_BUFFERS) {
592 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF6",
593 adapter, adapter->FreeRcvBufferCount, SXG_MAX_ENTRIES,
594 0);
595 return (STATUS_RESOURCES);
596 }
597
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700598 DBG_ERROR("%s Allocate EventRings size[%x]\n", __func__,
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530599 (unsigned int)(sizeof(struct sxg_event_ring) * RssIds));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700600
J.R. Maurob243c4a2008-10-20 19:28:58 -0400601 /* Allocate event queues. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700602 adapter->EventRings = pci_alloc_consistent(adapter->pcidev,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530603 sizeof(struct sxg_event_ring) *
604 RssIds,
605 &adapter->PEventRings);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700606
607 if (!adapter->EventRings) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530608 /* Caller will call SxgFreeAdapter to clean up above
609 * allocations */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700610 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF8",
611 adapter, SXG_MAX_ENTRIES, 0, 0);
612 status = STATUS_RESOURCES;
613 goto per_tcb_allocation_failed;
614 }
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530615 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700616
Harvey Harrisone88bd232008-10-17 14:46:10 -0700617 DBG_ERROR("%s Allocate ISR size[%x]\n", __func__, IsrCount);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400618 /* Allocate ISR */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700619 adapter->Isr = pci_alloc_consistent(adapter->pcidev,
620 IsrCount, &adapter->PIsr);
621 if (!adapter->Isr) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530622 /* Caller will call SxgFreeAdapter to clean up above
623 * allocations */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700624 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF9",
625 adapter, SXG_MAX_ENTRIES, 0, 0);
626 status = STATUS_RESOURCES;
627 goto per_tcb_allocation_failed;
628 }
629 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
630
Greg Kroah-Hartmand78404c2008-10-21 10:41:45 -0700631 DBG_ERROR("%s Allocate shared XMT ring zero index location size[%x]\n",
632 __func__, (unsigned int)sizeof(u32));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700633
J.R. Maurob243c4a2008-10-20 19:28:58 -0400634 /* Allocate shared XMT ring zero index location */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700635 adapter->XmtRingZeroIndex = pci_alloc_consistent(adapter->pcidev,
636 sizeof(u32),
637 &adapter->
638 PXmtRingZeroIndex);
639 if (!adapter->XmtRingZeroIndex) {
640 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF10",
641 adapter, SXG_MAX_ENTRIES, 0, 0);
642 status = STATUS_RESOURCES;
643 goto per_tcb_allocation_failed;
644 }
645 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
646
647 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlcResS",
648 adapter, SXG_MAX_ENTRIES, 0, 0);
649
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530650 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700651}
652
653/*
654 * sxg_config_pci -
655 *
656 * Set up PCI Configuration space
657 *
658 * Arguments -
659 * pcidev - A pointer to our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700660 */
661static void sxg_config_pci(struct pci_dev *pcidev)
662{
663 u16 pci_command;
664 u16 new_command;
665
666 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700667 DBG_ERROR("sxg: %s PCI command[%4.4x]\n", __func__, pci_command);
J.R. Maurob243c4a2008-10-20 19:28:58 -0400668 /* Set the command register */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530669 new_command = pci_command | (
670 /* Memory Space Enable */
671 PCI_COMMAND_MEMORY |
672 /* Bus master enable */
673 PCI_COMMAND_MASTER |
674 /* Memory write and invalidate */
675 PCI_COMMAND_INVALIDATE |
676 /* Parity error response */
677 PCI_COMMAND_PARITY |
678 /* System ERR */
679 PCI_COMMAND_SERR |
680 /* Fast back-to-back */
681 PCI_COMMAND_FAST_BACK);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700682 if (pci_command != new_command) {
683 DBG_ERROR("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700684 __func__, pci_command, new_command);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700685 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
686 }
687}
688
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530689/*
690 * sxg_read_config
691 * @adapter : Pointer to the adapter structure for the card
692 * This function will read the configuration data from EEPROM/FLASH
693 */
694static inline int sxg_read_config(struct adapter_t *adapter)
695{
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530696 /* struct sxg_config data; */
Mithlesh Thukral942798b2009-01-05 21:14:34 +0530697 struct sw_cfg_data *data;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530698 dma_addr_t p_addr;
699 unsigned long status;
700 unsigned long i;
701
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530702 data = pci_alloc_consistent(adapter->pcidev,
703 sizeof(struct sw_cfg_data), &p_addr);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530704 if(!data) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530705 /*
706 * We cant get even this much memory. Raise a hell
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530707 * Get out of here
708 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530709 printk(KERN_ERR"%s : Could not allocate memory for reading \
710 EEPROM\n", __FUNCTION__);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530711 return -ENOMEM;
712 }
713
714 WRITE_REG(adapter->UcodeRegs[0].ConfigStat, SXG_CFG_TIMEOUT, TRUE);
715
716 WRITE_REG64(adapter, adapter->UcodeRegs[0].Config, p_addr, 0);
717 for(i=0; i<1000; i++) {
718 READ_REG(adapter->UcodeRegs[0].ConfigStat, status);
719 if (status != SXG_CFG_TIMEOUT)
720 break;
721 mdelay(1); /* Do we really need this */
722 }
723
724 switch(status) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530725 /* Config read from EEPROM succeeded */
726 case SXG_CFG_LOAD_EEPROM:
727 /* Config read from Flash succeeded */
728 case SXG_CFG_LOAD_FLASH:
729 /* Copy the MAC address to adapter structure */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530730 /* TODO: We are not doing the remaining part : FRU,
731 * etc
732 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +0530733 memcpy(adapter->macaddr, data->MacAddr[0].MacAddr,
734 sizeof(struct sxg_config_mac));
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530735 break;
736 case SXG_CFG_TIMEOUT:
737 case SXG_CFG_LOAD_INVALID:
738 case SXG_CFG_LOAD_ERROR:
739 default: /* Fix default handler later */
740 printk(KERN_WARNING"%s : We could not read the config \
741 word. Status = %ld\n", __FUNCTION__, status);
742 break;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530743 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530744 pci_free_consistent(adapter->pcidev, sizeof(struct sw_cfg_data), data,
745 p_addr);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530746 if (adapter->netdev) {
747 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
748 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
749 }
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530750 sxg_dbg_macaddrs(adapter);
751
752 return status;
753}
754
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700755static int sxg_entry_probe(struct pci_dev *pcidev,
756 const struct pci_device_id *pci_tbl_entry)
757{
758 static int did_version = 0;
759 int err;
760 struct net_device *netdev;
J.R. Mauro73b07062008-10-28 18:42:02 -0400761 struct adapter_t *adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700762 void __iomem *memmapped_ioaddr;
763 u32 status = 0;
764 ulong mmio_start = 0;
765 ulong mmio_len = 0;
766
767 DBG_ERROR("sxg: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700768 __func__, jiffies, smp_processor_id());
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700769
J.R. Maurob243c4a2008-10-20 19:28:58 -0400770 /* Initialize trace buffer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700771#ifdef ATKDBG
772 SxgTraceBuffer = &LSxgTraceBuffer;
773 SXG_TRACE_INIT(SxgTraceBuffer, TRACE_NOISY);
774#endif
775
776 sxg_global.dynamic_intagg = dynamic_intagg;
777
778 err = pci_enable_device(pcidev);
779
780 DBG_ERROR("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
781 if (err) {
782 return err;
783 }
784
785 if (sxg_debug > 0 && did_version++ == 0) {
786 printk(KERN_INFO "%s\n", sxg_banner);
Mithlesh Thukral371d7a92009-01-19 20:22:34 +0530787 printk(KERN_INFO "%s\n", SXG_DRV_VERSION);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700788 }
789
790 if (!(err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK))) {
791 DBG_ERROR("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
792 } else {
793 if ((err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK))) {
794 DBG_ERROR
795 ("No usable DMA configuration, aborting err[%x]\n",
796 err);
797 return err;
798 }
799 DBG_ERROR("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
800 }
801
802 DBG_ERROR("Call pci_request_regions\n");
803
Mithlesh Thukral371d7a92009-01-19 20:22:34 +0530804 err = pci_request_regions(pcidev, sxg_driver_name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700805 if (err) {
806 DBG_ERROR("pci_request_regions FAILED err[%x]\n", err);
807 return err;
808 }
809
810 DBG_ERROR("call pci_set_master\n");
811 pci_set_master(pcidev);
812
813 DBG_ERROR("call alloc_etherdev\n");
J.R. Mauro73b07062008-10-28 18:42:02 -0400814 netdev = alloc_etherdev(sizeof(struct adapter_t));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700815 if (!netdev) {
816 err = -ENOMEM;
817 goto err_out_exit_sxg_probe;
818 }
819 DBG_ERROR("alloc_etherdev for slic netdev[%p]\n", netdev);
820
821 SET_NETDEV_DEV(netdev, &pcidev->dev);
822
823 pci_set_drvdata(pcidev, netdev);
824 adapter = netdev_priv(netdev);
825 adapter->netdev = netdev;
826 adapter->pcidev = pcidev;
827
828 mmio_start = pci_resource_start(pcidev, 0);
829 mmio_len = pci_resource_len(pcidev, 0);
830
831 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
832 mmio_start, mmio_len);
833
834 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700835 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400836 memmapped_ioaddr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700837 if (!memmapped_ioaddr) {
838 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700839 __func__, mmio_len, mmio_start);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530840 goto err_out_free_mmio_region_0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700841 }
842
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530843 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, start[%lx] \
844 len[%lx], IRQ %d.\n", __func__, memmapped_ioaddr, mmio_start,
845 mmio_len, pcidev->irq);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700846
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400847 adapter->HwRegs = (void *)memmapped_ioaddr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700848 adapter->base_addr = memmapped_ioaddr;
849
850 mmio_start = pci_resource_start(pcidev, 2);
851 mmio_len = pci_resource_len(pcidev, 2);
852
853 DBG_ERROR("sxg: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
854 mmio_start, mmio_len);
855
856 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
J.R. Mauro5c7514e2008-10-05 20:38:52 -0400857 DBG_ERROR("sxg: %s MEMMAPPED_IOADDR [%p]\n", __func__,
858 memmapped_ioaddr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700859 if (!memmapped_ioaddr) {
860 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700861 __func__, mmio_len, mmio_start);
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530862 goto err_out_free_mmio_region_2;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700863 }
864
865 DBG_ERROR("sxg: %s found Alacritech SXG PCI, MMIO at %p, "
866 "start[%lx] len[%lx], IRQ %d.\n", __func__,
867 memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
868
869 adapter->UcodeRegs = (void *)memmapped_ioaddr;
870
871 adapter->State = SXG_STATE_INITIALIZING;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +0530872 /*
873 * Maintain a list of all adapters anchored by
874 * the global SxgDriver structure.
875 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700876 adapter->Next = SxgDriver.Adapters;
877 SxgDriver.Adapters = adapter;
878 adapter->AdapterID = ++SxgDriver.AdapterID;
879
J.R. Maurob243c4a2008-10-20 19:28:58 -0400880 /* Initialize CRC table used to determine multicast hash */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700881 sxg_mcast_init_crc32();
882
883 adapter->JumboEnabled = FALSE;
884 adapter->RssEnabled = FALSE;
885 if (adapter->JumboEnabled) {
886 adapter->FrameSize = JUMBOMAXFRAME;
887 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
888 } else {
889 adapter->FrameSize = ETHERMAXFRAME;
890 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
891 }
892
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530893 /*
894 * status = SXG_READ_EEPROM(adapter);
895 * if (!status) {
896 * goto sxg_init_bad;
897 * }
898 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700899
Harvey Harrisone88bd232008-10-17 14:46:10 -0700900 DBG_ERROR("sxg: %s ENTER sxg_config_pci\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700901 sxg_config_pci(pcidev);
Harvey Harrisone88bd232008-10-17 14:46:10 -0700902 DBG_ERROR("sxg: %s EXIT sxg_config_pci\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700903
Harvey Harrisone88bd232008-10-17 14:46:10 -0700904 DBG_ERROR("sxg: %s ENTER sxg_init_driver\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700905 sxg_init_driver();
Harvey Harrisone88bd232008-10-17 14:46:10 -0700906 DBG_ERROR("sxg: %s EXIT sxg_init_driver\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700907
908 adapter->vendid = pci_tbl_entry->vendor;
909 adapter->devid = pci_tbl_entry->device;
910 adapter->subsysid = pci_tbl_entry->subdevice;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700911 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
912 adapter->functionnumber = (pcidev->devfn & 0x7);
913 adapter->memorylength = pci_resource_len(pcidev, 0);
914 adapter->irq = pcidev->irq;
915 adapter->next_netdevice = head_netdevice;
916 head_netdevice = netdev;
J.R. Maurob243c4a2008-10-20 19:28:58 -0400917 adapter->port = 0; /*adapter->functionnumber; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700918
J.R. Maurob243c4a2008-10-20 19:28:58 -0400919 /* Allocate memory and other resources */
Harvey Harrisone88bd232008-10-17 14:46:10 -0700920 DBG_ERROR("sxg: %s ENTER sxg_allocate_resources\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700921 status = sxg_allocate_resources(adapter);
922 DBG_ERROR("sxg: %s EXIT sxg_allocate_resources status %x\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700923 __func__, status);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700924 if (status != STATUS_SUCCESS) {
925 goto err_out_unmap;
926 }
927
Harvey Harrisone88bd232008-10-17 14:46:10 -0700928 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700929 if (sxg_download_microcode(adapter, SXG_UCODE_SAHARA)) {
930 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -0700931 __func__);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530932 sxg_read_config(adapter);
Mithlesh Thukral54aed112009-01-19 20:27:17 +0530933 status = sxg_adapter_set_hwaddr(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700934 } else {
935 adapter->state = ADAPT_FAIL;
936 adapter->linkstate = LINK_DOWN;
937 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n", status);
938 }
939
940 netdev->base_addr = (unsigned long)adapter->base_addr;
941 netdev->irq = adapter->irq;
942 netdev->open = sxg_entry_open;
943 netdev->stop = sxg_entry_halt;
944 netdev->hard_start_xmit = sxg_send_packets;
945 netdev->do_ioctl = sxg_ioctl;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +0530946 netdev->change_mtu = sxg_change_mtu;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700947#if XXXTODO
948 netdev->set_mac_address = sxg_mac_set_address;
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +0530949#endif
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700950 netdev->get_stats = sxg_get_stats;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +0530951 netdev->set_multicast_list = sxg_mcast_set_list;
Mithlesh Thukral371d7a92009-01-19 20:22:34 +0530952 SET_ETHTOOL_OPS(netdev, &sxg_nic_ethtool_ops);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700953
954 strcpy(netdev->name, "eth%d");
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530955 /* strcpy(netdev->name, pci_name(pcidev)); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700956 if ((err = register_netdev(netdev))) {
957 DBG_ERROR("Cannot register net device, aborting. %s\n",
958 netdev->name);
959 goto err_out_unmap;
960 }
961
Mithlesh Thukralb62a2942009-01-30 20:19:03 +0530962 netif_napi_add(netdev, &adapter->napi,
963 sxg_poll, SXG_NETDEV_WEIGHT);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700964 DBG_ERROR
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530965 ("sxg: %s addr 0x%lx, irq %d, MAC addr \
966 %02X:%02X:%02X:%02X:%02X:%02X\n",
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700967 netdev->name, netdev->base_addr, pcidev->irq, netdev->dev_addr[0],
968 netdev->dev_addr[1], netdev->dev_addr[2], netdev->dev_addr[3],
969 netdev->dev_addr[4], netdev->dev_addr[5]);
970
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530971 /* sxg_init_bad: */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700972 ASSERT(status == FALSE);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +0530973 /* sxg_free_adapter(adapter); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700974
Harvey Harrisone88bd232008-10-17 14:46:10 -0700975 DBG_ERROR("sxg: %s EXIT status[%x] jiffies[%lx] cpu %d\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700976 status, jiffies, smp_processor_id());
977 return status;
978
979 err_out_unmap:
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530980 sxg_free_resources(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700981
Mithlesh Thukral0d414722009-01-19 20:29:59 +0530982 err_out_free_mmio_region_2:
983
984 mmio_start = pci_resource_start(pcidev, 2);
985 mmio_len = pci_resource_len(pcidev, 2);
986 release_mem_region(mmio_start, mmio_len);
987
988 err_out_free_mmio_region_0:
989
990 mmio_start = pci_resource_start(pcidev, 0);
991 mmio_len = pci_resource_len(pcidev, 0);
992
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700993 release_mem_region(mmio_start, mmio_len);
994
995 err_out_exit_sxg_probe:
996
Harvey Harrisone88bd232008-10-17 14:46:10 -0700997 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -0700998 smp_processor_id());
999
Mithlesh Thukral0d414722009-01-19 20:29:59 +05301000 pci_disable_device(pcidev);
1001 DBG_ERROR("sxg: %s deallocate device\n", __FUNCTION__);
1002 kfree(netdev);
1003 printk("Exit %s, Sxg driver loading failed..\n", __FUNCTION__);
1004
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001005 return -ENODEV;
1006}
1007
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001008/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301009 * LINE BASE Interrupt routines..
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001010 *
1011 * sxg_disable_interrupt
1012 *
1013 * DisableInterrupt Handler
1014 *
1015 * Arguments:
1016 *
1017 * adapter: Our adapter structure
1018 *
1019 * Return Value:
1020 * None.
1021 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001022static void sxg_disable_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001023{
1024 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DisIntr",
1025 adapter, adapter->InterruptsEnabled, 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001026 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001027 ASSERT(adapter->RssEnabled == FALSE);
1028 ASSERT(adapter->MsiEnabled == FALSE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001029 /* Turn off interrupts by writing to the icr register. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001030 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_DISABLE), TRUE);
1031
1032 adapter->InterruptsEnabled = 0;
1033
1034 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDisIntr",
1035 adapter, adapter->InterruptsEnabled, 0, 0);
1036}
1037
1038/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001039 * sxg_enable_interrupt
1040 *
1041 * EnableInterrupt Handler
1042 *
1043 * Arguments:
1044 *
1045 * adapter: Our adapter structure
1046 *
1047 * Return Value:
1048 * None.
1049 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001050static void sxg_enable_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001051{
1052 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "EnIntr",
1053 adapter, adapter->InterruptsEnabled, 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001054 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001055 ASSERT(adapter->RssEnabled == FALSE);
1056 ASSERT(adapter->MsiEnabled == FALSE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001057 /* Turn on interrupts by writing to the icr register. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001058 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_ENABLE), TRUE);
1059
1060 adapter->InterruptsEnabled = 1;
1061
1062 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XEnIntr",
1063 adapter, 0, 0, 0);
1064}
1065
1066/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001067 * sxg_isr - Process an line-based interrupt
1068 *
1069 * Arguments:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301070 * Context - Our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001071 * QueueDefault - Output parameter to queue to default CPU
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301072 * TargetCpus - Output bitmap to schedule DPC's
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001073 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301074 * Return Value: TRUE if our interrupt
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001075 */
1076static irqreturn_t sxg_isr(int irq, void *dev_id)
1077{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301078 struct net_device *dev = (struct net_device *) dev_id;
J.R. Mauro73b07062008-10-28 18:42:02 -04001079 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001080
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05301081 if(adapter->state != ADAPT_UP)
1082 return IRQ_NONE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001083 adapter->Stats.NumInts++;
1084 if (adapter->Isr[0] == 0) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301085 /*
1086 * The SLIC driver used to experience a number of spurious
1087 * interrupts due to the delay associated with the masking of
1088 * the interrupt (we'd bounce back in here). If we see that
1089 * again with Sahara,add a READ_REG of the Icr register after
1090 * the WRITE_REG below.
1091 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001092 adapter->Stats.FalseInts++;
1093 return IRQ_NONE;
1094 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301095 /*
1096 * Move the Isr contents and clear the value in
1097 * shared memory, and mask interrupts
1098 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301099 /* ASSERT(adapter->IsrDpcsPending == 0); */
J.R. Maurob243c4a2008-10-20 19:28:58 -04001100#if XXXTODO /* RSS Stuff */
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301101 /*
1102 * If RSS is enabled and the ISR specifies SXG_ISR_EVENT, then
1103 * schedule DPC's based on event queues.
1104 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001105 if (adapter->RssEnabled && (adapter->IsrCopy[0] & SXG_ISR_EVENT)) {
1106 for (i = 0;
1107 i < adapter->RssSystemInfo->ProcessorInfo.RssCpuCount;
1108 i++) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301109 struct sxg_event_ring *EventRing =
1110 &adapter->EventRings[i];
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301111 struct sxg_event *Event =
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001112 &EventRing->Ring[adapter->NextEvent[i]];
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001113 unsigned char Cpu =
1114 adapter->RssSystemInfo->RssIdToCpu[i];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001115 if (Event->Status & EVENT_STATUS_VALID) {
1116 adapter->IsrDpcsPending++;
1117 CpuMask |= (1 << Cpu);
1118 }
1119 }
1120 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301121 /*
1122 * Now, either schedule the CPUs specified by the CpuMask,
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301123 * or queue default
1124 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001125 if (CpuMask) {
1126 *QueueDefault = FALSE;
1127 } else {
1128 adapter->IsrDpcsPending = 1;
1129 *QueueDefault = TRUE;
1130 }
1131 *TargetCpus = CpuMask;
1132#endif
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301133 sxg_interrupt(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001134
1135 return IRQ_HANDLED;
1136}
1137
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301138static void sxg_interrupt(struct adapter_t *adapter)
1139{
1140 WRITE_REG(adapter->UcodeRegs[0].Icr, SXG_ICR(0, SXG_ICR_MASK), TRUE);
1141
1142 if (netif_rx_schedule_prep(&adapter->napi)) {
1143 __netif_rx_schedule(&adapter->napi);
1144 }
1145}
1146
1147static void sxg_handle_interrupt(struct adapter_t *adapter, int *work_done,
1148 int budget)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001149{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301150 /* unsigned char RssId = 0; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001151 u32 NewIsr;
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301152 int sxg_napi_continue = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001153 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "HndlIntr",
1154 adapter, adapter->IsrCopy[0], 0, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001155 /* For now, RSS is disabled with line based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001156 ASSERT(adapter->RssEnabled == FALSE);
1157 ASSERT(adapter->MsiEnabled == FALSE);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301158
1159 adapter->IsrCopy[0] = adapter->Isr[0];
1160 adapter->Isr[0] = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001161
J.R. Maurob243c4a2008-10-20 19:28:58 -04001162 /* Always process the event queue. */
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301163 while (sxg_napi_continue)
1164 {
1165 sxg_process_event_queue(adapter,
1166 (adapter->RssEnabled ? /*RssId */ 0 : 0),
1167 &sxg_napi_continue, work_done, budget);
1168 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001169
J.R. Maurob243c4a2008-10-20 19:28:58 -04001170#if XXXTODO /* RSS stuff */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001171 if (--adapter->IsrDpcsPending) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001172 /* We're done. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001173 ASSERT(adapter->RssEnabled);
1174 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DPCsPend",
1175 adapter, 0, 0, 0);
1176 return;
1177 }
1178#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001179 /* Last (or only) DPC processes the ISR and clears the interrupt. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001180 NewIsr = sxg_process_isr(adapter, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001181 /* Reenable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001182 adapter->IsrCopy[0] = 0;
1183 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ClearIsr",
1184 adapter, NewIsr, 0, 0);
1185
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001186 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XHndlInt",
1187 adapter, 0, 0, 0);
1188}
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301189static int sxg_poll(struct napi_struct *napi, int budget)
1190{
1191 struct adapter_t *adapter = container_of(napi, struct adapter_t, napi);
1192 int work_done = 0;
1193
1194 sxg_handle_interrupt(adapter, &work_done, budget);
1195
1196 if (work_done < budget) {
1197 netif_rx_complete(napi);
1198 WRITE_REG(adapter->UcodeRegs[0].Isr, 0, TRUE);
1199 }
1200
1201 return work_done;
1202}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001203
1204/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001205 * sxg_process_isr - Process an interrupt. Called from the line-based and
1206 * message based interrupt DPC routines
1207 *
1208 * Arguments:
1209 * adapter - Our adapter structure
1210 * Queue - The ISR that needs processing
1211 *
1212 * Return Value:
1213 * None
1214 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001215static int sxg_process_isr(struct adapter_t *adapter, u32 MessageId)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001216{
1217 u32 Isr = adapter->IsrCopy[MessageId];
1218 u32 NewIsr = 0;
1219
1220 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "ProcIsr",
1221 adapter, Isr, 0, 0);
1222
J.R. Maurob243c4a2008-10-20 19:28:58 -04001223 /* Error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001224 if (Isr & SXG_ISR_ERR) {
1225 if (Isr & SXG_ISR_PDQF) {
1226 adapter->Stats.PdqFull++;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001227 DBG_ERROR("%s: SXG_ISR_ERR PDQF!!\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001228 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001229 /* No host buffer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001230 if (Isr & SXG_ISR_RMISS) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301231 /*
1232 * There is a bunch of code in the SLIC driver which
1233 * attempts to process more receive events per DPC
1234 * if we start to fall behind. We'll probablyd
1235 * need to do something similar here, but hold
1236 * off for now. I don't want to make the code more
1237 * complicated than strictly needed.
1238 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05301239 adapter->stats.rx_missed_errors++;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301240 if (adapter->stats.rx_missed_errors< 5) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001241 DBG_ERROR("%s: SXG_ISR_ERR RMISS!!\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001242 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001243 }
1244 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001245 /* Card crash */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001246 if (Isr & SXG_ISR_DEAD) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301247 /*
1248 * Set aside the crash info and set the adapter state
1249 * to RESET
1250 */
1251 adapter->CrashCpu = (unsigned char)
1252 ((Isr & SXG_ISR_CPU) >> SXG_ISR_CPU_SHIFT);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001253 adapter->CrashLocation = (ushort) (Isr & SXG_ISR_CRASH);
1254 adapter->Dead = TRUE;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001255 DBG_ERROR("%s: ISR_DEAD %x, CPU: %d\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001256 adapter->CrashLocation, adapter->CrashCpu);
1257 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001258 /* Event ring full */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001259 if (Isr & SXG_ISR_ERFULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301260 /*
1261 * Same issue as RMISS, really. This means the
1262 * host is falling behind the card. Need to increase
1263 * event ring size, process more events per interrupt,
1264 * and/or reduce/remove interrupt aggregation.
1265 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001266 adapter->Stats.EventRingFull++;
1267 DBG_ERROR("%s: SXG_ISR_ERR EVENT RING FULL!!\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001268 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001269 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001270 /* Transmit drop - no DRAM buffers or XMT error */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001271 if (Isr & SXG_ISR_XDROP) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07001272 DBG_ERROR("%s: SXG_ISR_ERR XDROP!!\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001273 }
1274 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001275 /* Slowpath send completions */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001276 if (Isr & SXG_ISR_SPSEND) {
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301277 sxg_complete_slow_send(adapter, 1);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001278 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001279 /* Dump */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001280 if (Isr & SXG_ISR_UPC) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301281 /* Maybe change when debug is added.. */
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301282// ASSERT(adapter->DumpCmdRunning);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001283 adapter->DumpCmdRunning = FALSE;
1284 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001285 /* Link event */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001286 if (Isr & SXG_ISR_LINK) {
1287 sxg_link_event(adapter);
1288 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001289 /* Debug - breakpoint hit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001290 if (Isr & SXG_ISR_BREAK) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301291 /*
1292 * At the moment AGDB isn't written to support interactive
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301293 * debug sessions. When it is, this interrupt will be used to
1294 * signal AGDB that it has hit a breakpoint. For now, ASSERT.
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301295 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001296 ASSERT(0);
1297 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001298 /* Heartbeat response */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001299 if (Isr & SXG_ISR_PING) {
1300 adapter->PingOutstanding = FALSE;
1301 }
1302 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XProcIsr",
1303 adapter, Isr, NewIsr, 0);
1304
1305 return (NewIsr);
1306}
1307
1308/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001309 * sxg_process_event_queue - Process our event queue
1310 *
1311 * Arguments:
1312 * - adapter - Adapter structure
1313 * - RssId - The event queue requiring processing
1314 *
1315 * Return Value:
1316 * None.
1317 */
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301318static u32 sxg_process_event_queue(struct adapter_t *adapter, u32 RssId,
1319 int *sxg_napi_continue, int *work_done, int budget)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001320{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301321 struct sxg_event_ring *EventRing = &adapter->EventRings[RssId];
1322 struct sxg_event *Event = &EventRing->Ring[adapter->NextEvent[RssId]];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001323 u32 EventsProcessed = 0, Batches = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001324 struct sk_buff *skb;
1325#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
1326 struct sk_buff *prev_skb = NULL;
1327 struct sk_buff *IndicationList[SXG_RCV_ARRAYSIZE];
1328 u32 Index;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301329 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001330#endif
1331 u32 ReturnStatus = 0;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301332 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001333
1334 ASSERT((adapter->State == SXG_STATE_RUNNING) ||
1335 (adapter->State == SXG_STATE_PAUSING) ||
1336 (adapter->State == SXG_STATE_PAUSED) ||
1337 (adapter->State == SXG_STATE_HALTING));
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301338 /*
1339 * We may still have unprocessed events on the queue if
1340 * the card crashed. Don't process them.
1341 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001342 if (adapter->Dead) {
1343 return (0);
1344 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301345 /*
1346 * In theory there should only be a single processor that
1347 * accesses this queue, and only at interrupt-DPC time. So/
1348 * we shouldn't need a lock for any of this.
1349 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001350 while (Event->Status & EVENT_STATUS_VALID) {
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301351 (*sxg_napi_continue) = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001352 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "Event",
1353 Event, Event->Code, Event->Status,
1354 adapter->NextEvent);
1355 switch (Event->Code) {
1356 case EVENT_CODE_BUFFERS:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301357 /* struct sxg_ring_info Head & Tail == unsigned char */
1358 ASSERT(!(Event->CommandIndex & 0xFF00));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001359 sxg_complete_descriptor_blocks(adapter,
1360 Event->CommandIndex);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001361 break;
1362 case EVENT_CODE_SLOWRCV:
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301363 (*work_done)++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001364 --adapter->RcvBuffersOnCard;
1365 if ((skb = sxg_slow_receive(adapter, Event))) {
1366 u32 rx_bytes;
1367#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
J.R. Maurob243c4a2008-10-20 19:28:58 -04001368 /* Add it to our indication list */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001369 SXG_ADD_RCV_PACKET(adapter, skb, prev_skb,
1370 IndicationList, num_skbs);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301371 /*
1372 * Linux, we just pass up each skb to the
1373 * protocol above at this point, there is no
1374 * capability of an indication list.
1375 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001376#else
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301377 /* CHECK skb_pull(skb, INIC_RCVBUF_HEADSIZE); */
1378 /* (rcvbuf->length & IRHDDR_FLEN_MSK); */
1379 rx_bytes = Event->Length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001380 adapter->stats.rx_packets++;
1381 adapter->stats.rx_bytes += rx_bytes;
1382#if SXG_OFFLOAD_IP_CHECKSUM
1383 skb->ip_summed = CHECKSUM_UNNECESSARY;
1384#endif
1385 skb->dev = adapter->netdev;
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301386 netif_receive_skb(skb);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001387#endif
1388 }
1389 break;
1390 default:
1391 DBG_ERROR("%s: ERROR Invalid EventCode %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001392 __func__, Event->Code);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301393 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001394 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301395 /*
1396 * See if we need to restock card receive buffers.
1397 * There are two things to note here:
1398 * First - This test is not SMP safe. The
1399 * adapter->BuffersOnCard field is protected via atomic
1400 * interlocked calls, but we do not protect it with respect
1401 * to these tests. The only way to do that is with a lock,
1402 * and I don't want to grab a lock every time we adjust the
1403 * BuffersOnCard count. Instead, we allow the buffer
1404 * replenishment to be off once in a while. The worst that
1405 * can happen is the card is given on more-or-less descriptor
1406 * block than the arbitrary value we've chosen. No big deal
1407 * In short DO NOT ADD A LOCK HERE, OR WHERE RcvBuffersOnCard
1408 * is adjusted.
1409 * Second - We expect this test to rarely
1410 * evaluate to true. We attempt to refill descriptor blocks
1411 * as they are returned to us (sxg_complete_descriptor_blocks)
1412 * so The only time this should evaluate to true is when
1413 * sxg_complete_descriptor_blocks failed to allocate
1414 * receive buffers.
1415 */
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301416 if (adapter->JumboEnabled)
1417 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
1418
1419 if (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001420 sxg_stock_rcv_buffers(adapter);
1421 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301422 /*
1423 * It's more efficient to just set this to zero.
1424 * But clearing the top bit saves potential debug info...
1425 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001426 Event->Status &= ~EVENT_STATUS_VALID;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301427 /* Advance to the next event */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001428 SXG_ADVANCE_INDEX(adapter->NextEvent[RssId], EVENT_RING_SIZE);
1429 Event = &EventRing->Ring[adapter->NextEvent[RssId]];
1430 EventsProcessed++;
1431 if (EventsProcessed == EVENT_RING_BATCH) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001432 /* Release a batch of events back to the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001433 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1434 EVENT_RING_BATCH, FALSE);
1435 EventsProcessed = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301436 /*
1437 * If we've processed our batch limit, break out of the
1438 * loop and return SXG_ISR_EVENT to arrange for us to
1439 * be called again
1440 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001441 if (Batches++ == EVENT_BATCH_LIMIT) {
1442 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1443 TRACE_NOISY, "EvtLimit", Batches,
1444 adapter->NextEvent, 0, 0);
1445 ReturnStatus = SXG_ISR_EVENT;
1446 break;
1447 }
1448 }
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301449 if (*work_done >= budget) {
1450 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1451 EventsProcessed, FALSE);
1452 EventsProcessed = 0;
1453 (*sxg_napi_continue) = 0;
1454 break;
1455 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001456 }
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301457 if (!(Event->Status & EVENT_STATUS_VALID))
1458 (*sxg_napi_continue) = 0;
1459
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001460#ifdef LINUX_HANDLES_RCV_INDICATION_LISTS
J.R. Maurob243c4a2008-10-20 19:28:58 -04001461 /* Indicate any received dumb-nic frames */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001462 SXG_INDICATE_PACKETS(adapter, IndicationList, num_skbs);
1463#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001464 /* Release events back to the card. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001465 if (EventsProcessed) {
1466 WRITE_REG(adapter->UcodeRegs[RssId].EventRelease,
1467 EventsProcessed, FALSE);
1468 }
1469 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XPrcEvnt",
1470 Batches, EventsProcessed, adapter->NextEvent, num_skbs);
1471
1472 return (ReturnStatus);
1473}
1474
1475/*
1476 * sxg_complete_slow_send - Complete slowpath or dumb-nic sends
1477 *
1478 * Arguments -
1479 * adapter - A pointer to our adapter structure
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301480 * irq_context - An integer to denote if we are in interrupt context
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001481 * Return
1482 * None
1483 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301484static void sxg_complete_slow_send(struct adapter_t *adapter, int irq_context)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001485{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301486 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
1487 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001488 u32 *ContextType;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301489 struct sxg_cmd *XmtCmd;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301490 unsigned long flags = 0;
1491 unsigned long sgl_flags = 0;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301492 unsigned int processed_count = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001493
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301494 /*
1495 * NOTE - This lock is dropped and regrabbed in this loop.
1496 * This means two different processors can both be running/
1497 * through this loop. Be *very* careful.
1498 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301499 if(irq_context) {
1500 if(!spin_trylock(&adapter->XmtZeroLock))
1501 goto lock_busy;
1502 }
1503 else
1504 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
1505
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001506 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnds",
1507 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1508
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301509 while ((XmtRingInfo->Tail != *adapter->XmtRingZeroIndex)
1510 && processed_count++ < SXG_COMPLETE_SLOW_SEND_LIMIT) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301511 /*
1512 * Locate the current Cmd (ring descriptor entry), and
1513 * associated SGL, and advance the tail
1514 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001515 SXG_RETURN_CMD(XmtRing, XmtRingInfo, XmtCmd, ContextType);
1516 ASSERT(ContextType);
1517 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1518 XmtRingInfo->Head, XmtRingInfo->Tail, XmtCmd, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001519 /* Clear the SGL field. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001520 XmtCmd->Sgl = 0;
1521
1522 switch (*ContextType) {
1523 case SXG_SGL_DUMB:
1524 {
1525 struct sk_buff *skb;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301526 struct sxg_scatter_gather *SxgSgl =
1527 (struct sxg_scatter_gather *)ContextType;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301528 dma64_addr_t FirstSgeAddress;
1529 u32 FirstSgeLength;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301530
J.R. Maurob243c4a2008-10-20 19:28:58 -04001531 /* Dumb-nic send. Command context is the dumb-nic SGL */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001532 skb = (struct sk_buff *)ContextType;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301533 skb = SxgSgl->DumbPacket;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301534 FirstSgeAddress = XmtCmd->Buffer.FirstSgeAddress;
1535 FirstSgeLength = XmtCmd->Buffer.FirstSgeLength;
J.R. Maurob243c4a2008-10-20 19:28:58 -04001536 /* Complete the send */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001537 SXG_TRACE(TRACE_SXG, SxgTraceBuffer,
1538 TRACE_IMPORTANT, "DmSndCmp", skb, 0,
1539 0, 0);
1540 ASSERT(adapter->Stats.XmtQLen);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301541 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301542 * Now drop the lock and complete the send
1543 * back to Microsoft. We need to drop the lock
1544 * because Microsoft can come back with a
1545 * chimney send, which results in a double trip
1546 * in SxgTcpOuput
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301547 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301548 if(irq_context)
1549 spin_unlock(&adapter->XmtZeroLock);
1550 else
1551 spin_unlock_irqrestore(
1552 &adapter->XmtZeroLock, flags);
1553
1554 SxgSgl->DumbPacket = NULL;
1555 SXG_COMPLETE_DUMB_SEND(adapter, skb,
1556 FirstSgeAddress,
1557 FirstSgeLength);
1558 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL,
1559 irq_context);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001560 /* and reacquire.. */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301561 if(irq_context) {
1562 if(!spin_trylock(&adapter->XmtZeroLock))
1563 goto lock_busy;
1564 }
1565 else
1566 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001567 }
1568 break;
1569 default:
1570 ASSERT(0);
1571 }
1572 }
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301573 if(irq_context)
1574 spin_unlock(&adapter->XmtZeroLock);
1575 else
1576 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
1577lock_busy:
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001578 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpSnd",
1579 adapter, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
1580}
1581
1582/*
1583 * sxg_slow_receive
1584 *
1585 * Arguments -
1586 * adapter - A pointer to our adapter structure
1587 * Event - Receive event
1588 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301589 * Return - skb
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001590 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301591static struct sk_buff *sxg_slow_receive(struct adapter_t *adapter,
1592 struct sxg_event *Event)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001593{
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301594 u32 BufferSize = adapter->ReceiveBufferSize;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301595 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001596 struct sk_buff *Packet;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301597 static int read_counter = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001598
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301599 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *) Event->HostHandle;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301600 if(read_counter++ & 0x100)
1601 {
1602 sxg_collect_statistics(adapter);
1603 read_counter = 0;
1604 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001605 ASSERT(RcvDataBufferHdr);
1606 ASSERT(RcvDataBufferHdr->State == SXG_BUFFER_ONCARD);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001607 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "SlowRcv", Event,
1608 RcvDataBufferHdr, RcvDataBufferHdr->State,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301609 /*RcvDataBufferHdr->VirtualAddress*/ 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001610 /* Drop rcv frames in non-running state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001611 switch (adapter->State) {
1612 case SXG_STATE_RUNNING:
1613 break;
1614 case SXG_STATE_PAUSING:
1615 case SXG_STATE_PAUSED:
1616 case SXG_STATE_HALTING:
1617 goto drop;
1618 default:
1619 ASSERT(0);
1620 goto drop;
1621 }
1622
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301623 /*
1624 * memcpy(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1625 * RcvDataBufferHdr->VirtualAddress, Event->Length);
1626 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301627
J.R. Maurob243c4a2008-10-20 19:28:58 -04001628 /* Change buffer state to UPSTREAM */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001629 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
1630 if (Event->Status & EVENT_STATUS_RCVERR) {
1631 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvError",
1632 Event, Event->Status, Event->HostHandle, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001633 /* XXXTODO - Remove this print later */
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001634 DBG_ERROR("SXG: Receive error %x\n", *(u32 *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001635 SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr));
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001636 sxg_process_rcv_error(adapter, *(u32 *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001637 SXG_RECEIVE_DATA_LOCATION
1638 (RcvDataBufferHdr));
1639 goto drop;
1640 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04001641#if XXXTODO /* VLAN stuff */
1642 /* If there's a VLAN tag, extract it and validate it */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301643 if (((struct ether_header *)
1644 (SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)))->EtherType
1645 == ETHERTYPE_VLAN) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001646 if (SxgExtractVlanHeader(adapter, RcvDataBufferHdr, Event) !=
1647 STATUS_SUCCESS) {
1648 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY,
1649 "BadVlan", Event,
1650 SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1651 Event->Length, 0);
1652 goto drop;
1653 }
1654 }
1655#endif
J.R. Maurob243c4a2008-10-20 19:28:58 -04001656 /* Dumb-nic frame. See if it passes our mac filter and update stats */
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301657
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301658 if (!sxg_mac_filter(adapter,
1659 (struct ether_header *)(SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr)),
1660 Event->Length)) {
1661 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RcvFiltr",
1662 Event, SXG_RECEIVE_DATA_LOCATION(RcvDataBufferHdr),
1663 Event->Length, 0);
1664 goto drop;
1665 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001666
1667 Packet = RcvDataBufferHdr->SxgDumbRcvPacket;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301668 SXG_ADJUST_RCV_PACKET(Packet, RcvDataBufferHdr, Event);
1669 Packet->protocol = eth_type_trans(Packet, adapter->netdev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001670
1671 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumbRcv",
1672 RcvDataBufferHdr, Packet, Event->Length, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04001673 /* Lastly adjust the receive packet length. */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301674 RcvDataBufferHdr->SxgDumbRcvPacket = NULL;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301675 RcvDataBufferHdr->PhysicalAddress = (dma_addr_t)NULL;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301676 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
1677 if (RcvDataBufferHdr->skb)
1678 {
1679 spin_lock(&adapter->RcvQLock);
1680 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05301681 // adapter->RcvBuffersOnCard ++;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05301682 spin_unlock(&adapter->RcvQLock);
1683 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001684 return (Packet);
1685
1686 drop:
1687 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DropRcv",
1688 RcvDataBufferHdr, Event->Length, 0, 0);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301689 adapter->stats.rx_dropped++;
1690// adapter->Stats.RcvDiscards++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001691 spin_lock(&adapter->RcvQLock);
1692 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
1693 spin_unlock(&adapter->RcvQLock);
1694 return (NULL);
1695}
1696
1697/*
1698 * sxg_process_rcv_error - process receive error and update
1699 * stats
1700 *
1701 * Arguments:
1702 * adapter - Adapter structure
1703 * ErrorStatus - 4-byte receive error status
1704 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301705 * Return Value : None
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001706 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001707static void sxg_process_rcv_error(struct adapter_t *adapter, u32 ErrorStatus)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001708{
1709 u32 Error;
1710
Mithlesh Thukral54aed112009-01-19 20:27:17 +05301711 adapter->stats.rx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001712
1713 if (ErrorStatus & SXG_RCV_STATUS_TRANSPORT_ERROR) {
1714 Error = ErrorStatus & SXG_RCV_STATUS_TRANSPORT_MASK;
1715 switch (Error) {
1716 case SXG_RCV_STATUS_TRANSPORT_CSUM:
1717 adapter->Stats.TransportCsum++;
1718 break;
1719 case SXG_RCV_STATUS_TRANSPORT_UFLOW:
1720 adapter->Stats.TransportUflow++;
1721 break;
1722 case SXG_RCV_STATUS_TRANSPORT_HDRLEN:
1723 adapter->Stats.TransportHdrLen++;
1724 break;
1725 }
1726 }
1727 if (ErrorStatus & SXG_RCV_STATUS_NETWORK_ERROR) {
1728 Error = ErrorStatus & SXG_RCV_STATUS_NETWORK_MASK;
1729 switch (Error) {
1730 case SXG_RCV_STATUS_NETWORK_CSUM:
1731 adapter->Stats.NetworkCsum++;
1732 break;
1733 case SXG_RCV_STATUS_NETWORK_UFLOW:
1734 adapter->Stats.NetworkUflow++;
1735 break;
1736 case SXG_RCV_STATUS_NETWORK_HDRLEN:
1737 adapter->Stats.NetworkHdrLen++;
1738 break;
1739 }
1740 }
1741 if (ErrorStatus & SXG_RCV_STATUS_PARITY) {
1742 adapter->Stats.Parity++;
1743 }
1744 if (ErrorStatus & SXG_RCV_STATUS_LINK_ERROR) {
1745 Error = ErrorStatus & SXG_RCV_STATUS_LINK_MASK;
1746 switch (Error) {
1747 case SXG_RCV_STATUS_LINK_PARITY:
1748 adapter->Stats.LinkParity++;
1749 break;
1750 case SXG_RCV_STATUS_LINK_EARLY:
1751 adapter->Stats.LinkEarly++;
1752 break;
1753 case SXG_RCV_STATUS_LINK_BUFOFLOW:
1754 adapter->Stats.LinkBufOflow++;
1755 break;
1756 case SXG_RCV_STATUS_LINK_CODE:
1757 adapter->Stats.LinkCode++;
1758 break;
1759 case SXG_RCV_STATUS_LINK_DRIBBLE:
1760 adapter->Stats.LinkDribble++;
1761 break;
1762 case SXG_RCV_STATUS_LINK_CRC:
1763 adapter->Stats.LinkCrc++;
1764 break;
1765 case SXG_RCV_STATUS_LINK_OFLOW:
1766 adapter->Stats.LinkOflow++;
1767 break;
1768 case SXG_RCV_STATUS_LINK_UFLOW:
1769 adapter->Stats.LinkUflow++;
1770 break;
1771 }
1772 }
1773}
1774
1775/*
1776 * sxg_mac_filter
1777 *
1778 * Arguments:
1779 * adapter - Adapter structure
1780 * pether - Ethernet header
1781 * length - Frame length
1782 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301783 * Return Value : TRUE if the frame is to be allowed
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001784 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05301785static bool sxg_mac_filter(struct adapter_t *adapter,
1786 struct ether_header *EtherHdr, ushort length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001787{
1788 bool EqualAddr;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301789 struct net_device *dev = adapter->netdev;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001790
1791 if (SXG_MULTICAST_PACKET(EtherHdr)) {
1792 if (SXG_BROADCAST_PACKET(EtherHdr)) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001793 /* broadcast */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001794 if (adapter->MacFilter & MAC_BCAST) {
1795 adapter->Stats.DumbRcvBcastPkts++;
1796 adapter->Stats.DumbRcvBcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001797 return (TRUE);
1798 }
1799 } else {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001800 /* multicast */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001801 if (adapter->MacFilter & MAC_ALLMCAST) {
1802 adapter->Stats.DumbRcvMcastPkts++;
1803 adapter->Stats.DumbRcvMcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001804 return (TRUE);
1805 }
1806 if (adapter->MacFilter & MAC_MCAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301807 struct dev_mc_list *mclist = dev->mc_list;
1808 while (mclist) {
1809 ETHER_EQ_ADDR(mclist->da_addr,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001810 EtherHdr->ether_dhost,
1811 EqualAddr);
1812 if (EqualAddr) {
1813 adapter->Stats.
1814 DumbRcvMcastPkts++;
1815 adapter->Stats.
1816 DumbRcvMcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001817 return (TRUE);
1818 }
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301819 mclist = mclist->next;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001820 }
1821 }
1822 }
1823 } else if (adapter->MacFilter & MAC_DIRECTED) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301824 /*
1825 * Not broadcast or multicast. Must be directed at us or
1826 * the card is in promiscuous mode. Either way, consider it
1827 * ours if MAC_DIRECTED is set
1828 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001829 adapter->Stats.DumbRcvUcastPkts++;
1830 adapter->Stats.DumbRcvUcastBytes += length;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001831 return (TRUE);
1832 }
1833 if (adapter->MacFilter & MAC_PROMISC) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04001834 /* Whatever it is, keep it. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001835 return (TRUE);
1836 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001837 return (FALSE);
1838}
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301839
J.R. Mauro73b07062008-10-28 18:42:02 -04001840static int sxg_register_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001841{
1842 if (!adapter->intrregistered) {
1843 int retval;
1844
1845 DBG_ERROR
1846 ("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x] %x\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001847 __func__, adapter, adapter->netdev->irq, NR_IRQS);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001848
J.R. Mauro5c7514e2008-10-05 20:38:52 -04001849 spin_unlock_irqrestore(&sxg_global.driver_lock,
1850 sxg_global.flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001851
1852 retval = request_irq(adapter->netdev->irq,
1853 &sxg_isr,
1854 IRQF_SHARED,
1855 adapter->netdev->name, adapter->netdev);
1856
1857 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
1858
1859 if (retval) {
1860 DBG_ERROR("sxg: request_irq (%s) FAILED [%x]\n",
1861 adapter->netdev->name, retval);
1862 return (retval);
1863 }
1864 adapter->intrregistered = 1;
1865 adapter->IntRegistered = TRUE;
J.R. Maurob243c4a2008-10-20 19:28:58 -04001866 /* Disable RSS with line-based interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001867 adapter->MsiEnabled = FALSE;
1868 adapter->RssEnabled = FALSE;
1869 DBG_ERROR("sxg: %s AllocAdaptRsrcs adapter[%p] dev->irq[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001870 __func__, adapter, adapter->netdev->irq);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001871 }
1872 return (STATUS_SUCCESS);
1873}
1874
J.R. Mauro73b07062008-10-28 18:42:02 -04001875static void sxg_deregister_interrupt(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001876{
Harvey Harrisone88bd232008-10-17 14:46:10 -07001877 DBG_ERROR("sxg: %s ENTER adapter[%p]\n", __func__, adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001878#if XXXTODO
1879 slic_init_cleanup(adapter);
1880#endif
1881 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1882 adapter->error_interrupts = 0;
1883 adapter->rcv_interrupts = 0;
1884 adapter->xmit_interrupts = 0;
1885 adapter->linkevent_interrupts = 0;
1886 adapter->upr_interrupts = 0;
1887 adapter->num_isrs = 0;
1888 adapter->xmit_completes = 0;
1889 adapter->rcv_broadcasts = 0;
1890 adapter->rcv_multicasts = 0;
1891 adapter->rcv_unicasts = 0;
Harvey Harrisone88bd232008-10-17 14:46:10 -07001892 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001893}
1894
1895/*
1896 * sxg_if_init
1897 *
1898 * Perform initialization of our slic interface.
1899 *
1900 */
J.R. Mauro73b07062008-10-28 18:42:02 -04001901static int sxg_if_init(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001902{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301903 struct net_device *dev = adapter->netdev;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001904 int status = 0;
1905
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301906 DBG_ERROR("sxg: %s (%s) ENTER states[%d:%d] flags[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07001907 __func__, adapter->netdev->name,
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05301908 adapter->state,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001909 adapter->linkstate, dev->flags);
1910
1911 /* adapter should be down at this point */
1912 if (adapter->state != ADAPT_DOWN) {
1913 DBG_ERROR("sxg_if_init adapter->state != ADAPT_DOWN\n");
1914 return (-EIO);
1915 }
1916 ASSERT(adapter->linkstate == LINK_DOWN);
1917
1918 adapter->devflags_prev = dev->flags;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301919 adapter->MacFilter = MAC_DIRECTED;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001920 if (dev->flags) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07001921 DBG_ERROR("sxg: %s (%s) Set MAC options: ", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001922 adapter->netdev->name);
1923 if (dev->flags & IFF_BROADCAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301924 adapter->MacFilter |= MAC_BCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001925 DBG_ERROR("BCAST ");
1926 }
1927 if (dev->flags & IFF_PROMISC) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301928 adapter->MacFilter |= MAC_PROMISC;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001929 DBG_ERROR("PROMISC ");
1930 }
1931 if (dev->flags & IFF_ALLMULTI) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301932 adapter->MacFilter |= MAC_ALLMCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001933 DBG_ERROR("ALL_MCAST ");
1934 }
1935 if (dev->flags & IFF_MULTICAST) {
Mithlesh Thukralb040b072009-01-28 07:08:11 +05301936 adapter->MacFilter |= MAC_MCAST;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001937 DBG_ERROR("MCAST ");
1938 }
1939 DBG_ERROR("\n");
1940 }
1941 status = sxg_register_interrupt(adapter);
1942 if (status != STATUS_SUCCESS) {
1943 DBG_ERROR("sxg_if_init: sxg_register_interrupt FAILED %x\n",
1944 status);
1945 sxg_deregister_interrupt(adapter);
1946 return (status);
1947 }
1948
1949 adapter->state = ADAPT_UP;
1950
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05301951 /* clear any pending events, then enable interrupts */
Harvey Harrisone88bd232008-10-17 14:46:10 -07001952 DBG_ERROR("sxg: %s ENABLE interrupts(slic)\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001953
1954 return (STATUS_SUCCESS);
1955}
1956
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05301957void sxg_set_interrupt_aggregation(struct adapter_t *adapter)
1958{
1959 /*
1960 * Top bit disables aggregation on xmt (SXG_AGG_XMT_DISABLE).
1961 * Make sure Max is less than 0x8000.
1962 */
1963 adapter->max_aggregation = SXG_MAX_AGG_DEFAULT;
1964 adapter->min_aggregation = SXG_MIN_AGG_DEFAULT;
1965 WRITE_REG(adapter->UcodeRegs[0].Aggregation,
1966 ((adapter->max_aggregation << SXG_MAX_AGG_SHIFT) |
1967 adapter->min_aggregation),
1968 TRUE);
1969}
1970
Mithlesh Thukral942798b2009-01-05 21:14:34 +05301971static int sxg_entry_open(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001972{
J.R. Mauro73b07062008-10-28 18:42:02 -04001973 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07001974 int status;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05301975 static int turn;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05301976 int sxg_initial_rcv_data_buffers = SXG_INITIAL_RCV_DATA_BUFFERS;
1977 int i;
1978
1979 if (adapter->JumboEnabled == TRUE) {
1980 sxg_initial_rcv_data_buffers =
1981 SXG_INITIAL_JUMBO_RCV_DATA_BUFFERS;
1982 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo,
1983 SXG_JUMBO_RCV_RING_SIZE);
1984 }
1985
1986 /*
1987 * Allocate receive data buffers. We allocate a block of buffers and
1988 * a corresponding descriptor block at once. See sxghw.h:SXG_RCV_BLOCK
1989 */
1990
1991 for (i = 0; i < sxg_initial_rcv_data_buffers;
1992 i += SXG_RCV_DESCRIPTORS_PER_BLOCK)
1993 {
1994 status = sxg_allocate_buffer_memory(adapter,
1995 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
1996 SXG_BUFFER_TYPE_RCV);
1997 if (status != STATUS_SUCCESS)
1998 return status;
1999 }
2000 /*
2001 * NBL resource allocation can fail in the 'AllocateComplete' routine,
2002 * which doesn't return status. Make sure we got the number of buffers
2003 * we requested
2004 */
2005
2006 if (adapter->FreeRcvBufferCount < sxg_initial_rcv_data_buffers) {
2007 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAResF6",
2008 adapter, adapter->FreeRcvBufferCount, SXG_MAX_ENTRIES,
2009 0);
2010 return (STATUS_RESOURCES);
2011 }
2012 /*
2013 * The microcode expects it to be downloaded on every open.
2014 */
2015 DBG_ERROR("sxg: %s ENTER sxg_download_microcode\n", __FUNCTION__);
2016 if (sxg_download_microcode(adapter, SXG_UCODE_SAHARA)) {
2017 DBG_ERROR("sxg: %s ENTER sxg_adapter_set_hwaddr\n",
2018 __FUNCTION__);
2019 sxg_read_config(adapter);
2020 } else {
2021 adapter->state = ADAPT_FAIL;
2022 adapter->linkstate = LINK_DOWN;
2023 DBG_ERROR("sxg_download_microcode FAILED status[%x]\n",
2024 status);
2025 }
2026 msleep(5);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302027
2028 if (turn) {
2029 sxg_second_open(adapter->netdev);
2030
2031 return STATUS_SUCCESS;
2032 }
2033
2034 turn++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002035
2036 ASSERT(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002037 DBG_ERROR("sxg: %s adapter->activated[%d]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002038 adapter->activated);
2039 DBG_ERROR
2040 ("sxg: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] port[%d]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002041 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002042 adapter->netdev, adapter, adapter->port);
2043
2044 netif_stop_queue(adapter->netdev);
2045
2046 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2047 if (!adapter->activated) {
2048 sxg_global.num_sxg_ports_active++;
2049 adapter->activated = 1;
2050 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002051 /* Initialize the adapter */
Harvey Harrisone88bd232008-10-17 14:46:10 -07002052 DBG_ERROR("sxg: %s ENTER sxg_initialize_adapter\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002053 status = sxg_initialize_adapter(adapter);
2054 DBG_ERROR("sxg: %s EXIT sxg_initialize_adapter status[%x]\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002055 __func__, status);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002056
2057 if (status == STATUS_SUCCESS) {
Harvey Harrisone88bd232008-10-17 14:46:10 -07002058 DBG_ERROR("sxg: %s ENTER sxg_if_init\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002059 status = sxg_if_init(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002060 DBG_ERROR("sxg: %s EXIT sxg_if_init status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002061 status);
2062 }
2063
2064 if (status != STATUS_SUCCESS) {
2065 if (adapter->activated) {
2066 sxg_global.num_sxg_ports_active--;
2067 adapter->activated = 0;
2068 }
2069 spin_unlock_irqrestore(&sxg_global.driver_lock,
2070 sxg_global.flags);
2071 return (status);
2072 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002073 DBG_ERROR("sxg: %s ENABLE ALL INTERRUPTS\n", __func__);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302074 sxg_set_interrupt_aggregation(adapter);
2075 napi_enable(&adapter->napi);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002076
J.R. Maurob243c4a2008-10-20 19:28:58 -04002077 /* Enable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002078 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2079
Harvey Harrisone88bd232008-10-17 14:46:10 -07002080 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002081
2082 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2083 return STATUS_SUCCESS;
2084}
2085
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302086int sxg_second_open(struct net_device * dev)
2087{
2088 struct adapter_t *adapter = (struct adapter_t*) netdev_priv(dev);
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302089 int status = 0;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302090
2091 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
2092 netif_start_queue(adapter->netdev);
2093 adapter->state = ADAPT_UP;
2094 adapter->linkstate = LINK_UP;
2095
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302096 status = sxg_initialize_adapter(adapter);
2097 sxg_set_interrupt_aggregation(adapter);
2098 napi_enable(&adapter->napi);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302099 /* Re-enable interrupts */
2100 SXG_ENABLE_ALL_INTERRUPTS(adapter);
2101
2102 netif_carrier_on(dev);
2103 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
2104 sxg_register_interrupt(adapter);
2105 return (STATUS_SUCCESS);
2106
2107}
2108
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002109static void __devexit sxg_entry_remove(struct pci_dev *pcidev)
2110{
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302111 u32 mmio_start = 0;
2112 u32 mmio_len = 0;
2113
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302114 struct net_device *dev = pci_get_drvdata(pcidev);
J.R. Mauro73b07062008-10-28 18:42:02 -04002115 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302116
2117 flush_scheduled_work();
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302118
2119 /* Deallocate Resources */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302120 unregister_netdev(dev);
2121 sxg_free_resources(adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302122
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002123 ASSERT(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002124
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302125 mmio_start = pci_resource_start(pcidev, 0);
2126 mmio_len = pci_resource_len(pcidev, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002127
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302128 DBG_ERROR("sxg: %s rel_region(0) start[%x] len[%x]\n", __FUNCTION__,
2129 mmio_start, mmio_len);
2130 release_mem_region(mmio_start, mmio_len);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002131
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302132 mmio_start = pci_resource_start(pcidev, 2);
2133 mmio_len = pci_resource_len(pcidev, 2);
2134
2135 DBG_ERROR("sxg: %s rel_region(2) start[%x] len[%x]\n", __FUNCTION__,
2136 mmio_start, mmio_len);
2137 release_mem_region(mmio_start, mmio_len);
2138
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302139 pci_disable_device(pcidev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002140
Harvey Harrisone88bd232008-10-17 14:46:10 -07002141 DBG_ERROR("sxg: %s deallocate device\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002142 kfree(dev);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002143 DBG_ERROR("sxg: %s EXIT\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002144}
2145
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302146static int sxg_entry_halt(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002147{
J.R. Mauro73b07062008-10-28 18:42:02 -04002148 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302149 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
2150 int i;
2151 u32 RssIds, IsrCount;
2152 unsigned long flags;
2153
2154 RssIds = SXG_RSS_CPU_COUNT(adapter);
2155 IsrCount = adapter->MsiEnabled ? RssIds : 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002156
Mithlesh Thukralb62a2942009-01-30 20:19:03 +05302157 napi_disable(&adapter->napi);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002158 spin_lock_irqsave(&sxg_global.driver_lock, sxg_global.flags);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002159 DBG_ERROR("sxg: %s (%s) ENTER\n", __func__, dev->name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002160
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302161 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 0, true);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002162 netif_stop_queue(adapter->netdev);
2163 adapter->state = ADAPT_DOWN;
2164 adapter->linkstate = LINK_DOWN;
2165 adapter->devflags_prev = 0;
2166 DBG_ERROR("sxg: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002167 __func__, dev->name, adapter, adapter->state);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002168
Harvey Harrisone88bd232008-10-17 14:46:10 -07002169 DBG_ERROR("sxg: %s (%s) EXIT\n", __func__, dev->name);
2170 DBG_ERROR("sxg: %s EXIT\n", __func__);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302171
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302172 /* Disable interrupts */
2173 SXG_DISABLE_ALL_INTERRUPTS(adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302174
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302175 netif_carrier_off(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002176 spin_unlock_irqrestore(&sxg_global.driver_lock, sxg_global.flags);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302177
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302178 sxg_deregister_interrupt(adapter);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302179 WRITE_REG(HwRegs->Reset, 0xDEAD, FLUSH);
2180 mdelay(5000);
2181 spin_lock(&adapter->RcvQLock);
2182 /* Free all the blocks and the buffers, moved from remove() routine */
2183 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
2184 sxg_free_rcvblocks(adapter);
2185 }
2186
2187
2188 InitializeListHead(&adapter->FreeRcvBuffers);
2189 InitializeListHead(&adapter->FreeRcvBlocks);
2190 InitializeListHead(&adapter->AllRcvBlocks);
2191 InitializeListHead(&adapter->FreeSglBuffers);
2192 InitializeListHead(&adapter->AllSglBuffers);
2193
2194 adapter->FreeRcvBufferCount = 0;
2195 adapter->FreeRcvBlockCount = 0;
2196 adapter->AllRcvBlockCount = 0;
2197 adapter->RcvBuffersOnCard = 0;
2198 adapter->PendingRcvCount = 0;
2199
2200 memset(adapter->RcvRings, 0, sizeof(struct sxg_rcv_ring) * 1);
2201 memset(adapter->EventRings, 0, sizeof(struct sxg_event_ring) * RssIds);
2202 memset(adapter->Isr, 0, sizeof(u32) * IsrCount);
2203 for (i = 0; i < SXG_MAX_RING_SIZE; i++)
2204 adapter->RcvRingZeroInfo.Context[i] = NULL;
2205 SXG_INITIALIZE_RING(adapter->RcvRingZeroInfo, SXG_RCV_RING_SIZE);
2206 SXG_INITIALIZE_RING(adapter->XmtRingZeroInfo, SXG_XMT_RING_SIZE);
2207
2208 spin_unlock(&adapter->RcvQLock);
2209
2210 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
2211 adapter->AllSglBufferCount = 0;
2212 adapter->FreeSglBufferCount = 0;
2213 adapter->PendingXmtCount = 0;
2214 memset(adapter->XmtRings, 0, sizeof(struct sxg_xmt_ring) * 1);
2215 memset(adapter->XmtRingZeroIndex, 0, sizeof(u32));
2216 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2217
2218
2219 for (i = 0; i < SXG_MAX_RSS; i++) {
2220 adapter->NextEvent[i] = 0;
2221 }
2222 atomic_set(&adapter->pending_allocations, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002223 return (STATUS_SUCCESS);
2224}
2225
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302226static int sxg_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002227{
2228 ASSERT(rq);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302229/* DBG_ERROR("sxg: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);*/
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002230 switch (cmd) {
2231 case SIOCSLICSETINTAGG:
2232 {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302233 /* struct adapter_t *adapter = (struct adapter_t *)
2234 * netdev_priv(dev);
2235 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002236 u32 data[7];
2237 u32 intagg;
2238
2239 if (copy_from_user(data, rq->ifr_data, 28)) {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302240 DBG_ERROR("copy_from_user FAILED getting \
2241 initial params\n");
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002242 return -EFAULT;
2243 }
2244 intagg = data[0];
2245 printk(KERN_EMERG
2246 "%s: set interrupt aggregation to %d\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002247 __func__, intagg);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002248 return 0;
2249 }
2250
2251 default:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302252 /* DBG_ERROR("sxg: %s UNSUPPORTED[%x]\n", __func__, cmd); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002253 return -EOPNOTSUPP;
2254 }
2255 return 0;
2256}
2257
2258#define NORMAL_ETHFRAME 0
2259
2260/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002261 * sxg_send_packets - Send a skb packet
2262 *
2263 * Arguments:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302264 * skb - The packet to send
2265 * dev - Our linux net device that refs our adapter
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002266 *
2267 * Return:
2268 * 0 regardless of outcome XXXTODO refer to e1000 driver
2269 */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302270static int sxg_send_packets(struct sk_buff *skb, struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002271{
J.R. Mauro73b07062008-10-28 18:42:02 -04002272 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002273 u32 status = STATUS_SUCCESS;
2274
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302275 /*
2276 * DBG_ERROR("sxg: %s ENTER sxg_send_packets skb[%p]\n", __FUNCTION__,
2277 * skb);
2278 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302279
J.R. Maurob243c4a2008-10-20 19:28:58 -04002280 /* Check the adapter state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002281 switch (adapter->State) {
2282 case SXG_STATE_INITIALIZING:
2283 case SXG_STATE_HALTED:
2284 case SXG_STATE_SHUTDOWN:
J.R. Maurob243c4a2008-10-20 19:28:58 -04002285 ASSERT(0); /* unexpected */
2286 /* fall through */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002287 case SXG_STATE_RESETTING:
2288 case SXG_STATE_SLEEP:
2289 case SXG_STATE_BOOTDIAG:
2290 case SXG_STATE_DIAG:
2291 case SXG_STATE_HALTING:
2292 status = STATUS_FAILURE;
2293 break;
2294 case SXG_STATE_RUNNING:
2295 if (adapter->LinkState != SXG_LINK_UP) {
2296 status = STATUS_FAILURE;
2297 }
2298 break;
2299 default:
2300 ASSERT(0);
2301 status = STATUS_FAILURE;
2302 }
2303 if (status != STATUS_SUCCESS) {
2304 goto xmit_fail;
2305 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002306 /* send a packet */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002307 status = sxg_transmit_packet(adapter, skb);
2308 if (status == STATUS_SUCCESS) {
2309 goto xmit_done;
2310 }
2311
2312 xmit_fail:
J.R. Maurob243c4a2008-10-20 19:28:58 -04002313 /* reject & complete all the packets if they cant be sent */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002314 if (status != STATUS_SUCCESS) {
2315#if XXXTODO
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302316 /* sxg_send_packets_fail(adapter, skb, status); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002317#else
2318 SXG_DROP_DUMB_SEND(adapter, skb);
2319 adapter->stats.tx_dropped++;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302320 return NETDEV_TX_BUSY;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002321#endif
2322 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002323 DBG_ERROR("sxg: %s EXIT sxg_send_packets status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002324 status);
2325
2326 xmit_done:
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302327 return NETDEV_TX_OK;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002328}
2329
2330/*
2331 * sxg_transmit_packet
2332 *
2333 * This function transmits a single packet.
2334 *
2335 * Arguments -
2336 * adapter - Pointer to our adapter structure
2337 * skb - The packet to be sent
2338 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302339 * Return - STATUS of send
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002340 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002341static int sxg_transmit_packet(struct adapter_t *adapter, struct sk_buff *skb)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002342{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302343 struct sxg_x64_sgl *pSgl;
2344 struct sxg_scatter_gather *SxgSgl;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302345 unsigned long sgl_flags;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302346 /* void *SglBuffer; */
2347 /* u32 SglBufferLength; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002348
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302349 /*
2350 * The vast majority of work is done in the shared
2351 * sxg_dumb_sgl routine.
2352 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002353 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSend",
2354 adapter, skb, 0, 0);
2355
J.R. Maurob243c4a2008-10-20 19:28:58 -04002356 /* Allocate a SGL buffer */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302357 SXG_GET_SGL_BUFFER(adapter, SxgSgl, 0);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002358 if (!SxgSgl) {
2359 adapter->Stats.NoSglBuf++;
Mithlesh Thukral54aed112009-01-19 20:27:17 +05302360 adapter->stats.tx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002361 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "SndPktF1",
2362 adapter, skb, 0, 0);
2363 return (STATUS_RESOURCES);
2364 }
2365 ASSERT(SxgSgl->adapter == adapter);
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05302366 /*SglBuffer = SXG_SGL_BUFFER(SxgSgl);
2367 SglBufferLength = SXG_SGL_BUF_SIZE; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002368 SxgSgl->VlanTag.VlanTci = 0;
2369 SxgSgl->VlanTag.VlanTpid = 0;
2370 SxgSgl->Type = SXG_SGL_DUMB;
2371 SxgSgl->DumbPacket = skb;
2372 pSgl = NULL;
2373
J.R. Maurob243c4a2008-10-20 19:28:58 -04002374 /* Call the common sxg_dumb_sgl routine to complete the send. */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302375 return (sxg_dumb_sgl(pSgl, SxgSgl));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002376}
2377
2378/*
2379 * sxg_dumb_sgl
2380 *
2381 * Arguments:
2382 * pSgl -
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302383 * SxgSgl - struct sxg_scatter_gather
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002384 *
2385 * Return Value:
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302386 * Status of send operation.
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002387 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302388static int sxg_dumb_sgl(struct sxg_x64_sgl *pSgl,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302389 struct sxg_scatter_gather *SxgSgl)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002390{
J.R. Mauro73b07062008-10-28 18:42:02 -04002391 struct adapter_t *adapter = SxgSgl->adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002392 struct sk_buff *skb = SxgSgl->DumbPacket;
J.R. Maurob243c4a2008-10-20 19:28:58 -04002393 /* For now, all dumb-nic sends go on RSS queue zero */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302394 struct sxg_xmt_ring *XmtRing = &adapter->XmtRings[0];
2395 struct sxg_ring_info *XmtRingInfo = &adapter->XmtRingZeroInfo;
2396 struct sxg_cmd *XmtCmd = NULL;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302397 /* u32 Index = 0; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002398 u32 DataLength = skb->len;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302399 /* unsigned int BufLen; */
2400 /* u32 SglOffset; */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002401 u64 phys_addr;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302402 unsigned long flags;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302403 unsigned long queue_id=0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002404
2405 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbSgl",
2406 pSgl, SxgSgl, 0, 0);
2407
J.R. Maurob243c4a2008-10-20 19:28:58 -04002408 /* Set aside a pointer to the sgl */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002409 SxgSgl->pSgl = pSgl;
2410
J.R. Maurob243c4a2008-10-20 19:28:58 -04002411 /* Sanity check that our SGL format is as we expect. */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302412 ASSERT(sizeof(struct sxg_x64_sge) == sizeof(struct sxg_x64_sge));
J.R. Maurob243c4a2008-10-20 19:28:58 -04002413 /* Shouldn't be a vlan tag on this frame */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002414 ASSERT(SxgSgl->VlanTag.VlanTci == 0);
2415 ASSERT(SxgSgl->VlanTag.VlanTpid == 0);
2416
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302417 /*
2418 * From here below we work with the SGL placed in our
2419 * buffer.
2420 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002421
2422 SxgSgl->Sgl.NumberOfElements = 1;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302423 /*
2424 * Set ucode Queue ID based on bottom bits of destination TCP port.
2425 * This Queue ID splits slowpath/dumb-nic packet processing across
2426 * multiple threads on the card to improve performance. It is split
2427 * using the TCP port to avoid out-of-order packets that can result
2428 * from multithreaded processing. We use the destination port because
2429 * we expect to be run on a server, so in nearly all cases the local
2430 * port is likely to be constant (well-known server port) and the
2431 * remote port is likely to be random. The exception to this is iSCSI,
2432 * in which case we use the sport instead. Note
2433 * that original attempt at XOR'ing source and dest port resulted in
2434 * poor balance on NTTTCP/iometer applications since they tend to
2435 * line up (even-even, odd-odd..).
2436 */
2437
2438 if (skb->protocol == htons(ETH_P_IP)) {
2439 struct iphdr *ip;
2440
2441 ip = ip_hdr(skb);
2442 if ((ip->protocol == IPPROTO_TCP)&&(DataLength >= sizeof(
2443 struct tcphdr))){
2444 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2445 (ntohs (tcp_hdr(skb)->source) &
2446 SXG_LARGE_SEND_QUEUE_MASK):
2447 (ntohs(tcp_hdr(skb)->dest) &
2448 SXG_LARGE_SEND_QUEUE_MASK));
2449 }
2450 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2451 if ( (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) && (DataLength >=
2452 sizeof(struct tcphdr)) ) {
2453 queue_id = ((ntohs(tcp_hdr(skb)->dest) == ISCSI_PORT) ?
2454 (ntohs (tcp_hdr(skb)->source) &
2455 SXG_LARGE_SEND_QUEUE_MASK):
2456 (ntohs(tcp_hdr(skb)->dest) &
2457 SXG_LARGE_SEND_QUEUE_MASK));
2458 }
2459 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002460
J.R. Maurob243c4a2008-10-20 19:28:58 -04002461 /* Grab the spinlock and acquire a command */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302462 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002463 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2464 if (XmtCmd == NULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302465 /*
2466 * Call sxg_complete_slow_send to see if we can
2467 * free up any XmtRingZero entries and then try again
2468 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302469
2470 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2471 sxg_complete_slow_send(adapter, 0);
2472 spin_lock_irqsave(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002473 SXG_GET_CMD(XmtRing, XmtRingInfo, XmtCmd, SxgSgl);
2474 if (XmtCmd == NULL) {
2475 adapter->Stats.XmtZeroFull++;
2476 goto abortcmd;
2477 }
2478 }
2479 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbCmd",
2480 XmtCmd, XmtRingInfo->Head, XmtRingInfo->Tail, 0);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002481 /* Update stats */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302482 adapter->stats.tx_packets++;
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302483 adapter->stats.tx_bytes += DataLength;
J.R. Maurob243c4a2008-10-20 19:28:58 -04002484#if XXXTODO /* Stats stuff */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002485 if (SXG_MULTICAST_PACKET(EtherHdr)) {
2486 if (SXG_BROADCAST_PACKET(EtherHdr)) {
2487 adapter->Stats.DumbXmtBcastPkts++;
2488 adapter->Stats.DumbXmtBcastBytes += DataLength;
2489 } else {
2490 adapter->Stats.DumbXmtMcastPkts++;
2491 adapter->Stats.DumbXmtMcastBytes += DataLength;
2492 }
2493 } else {
2494 adapter->Stats.DumbXmtUcastPkts++;
2495 adapter->Stats.DumbXmtUcastBytes += DataLength;
2496 }
2497#endif
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302498 /*
2499 * Fill in the command
2500 * Copy out the first SGE to the command and adjust for offset
2501 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302502 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04002503 PCI_DMA_TODEVICE);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302504
2505 /*
2506 * SAHARA SGL WORKAROUND
2507 * See if the SGL straddles a 64k boundary. If so, skip to
2508 * the start of the next 64k boundary and continue
2509 */
2510
2511 if (SXG_INVALID_SGL(phys_addr,skb->data_len))
2512 {
2513 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
2514 /* Silently drop this packet */
2515 printk(KERN_EMERG"Dropped a packet for 64k boundary problem\n");
2516 return STATUS_SUCCESS;
2517 }
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302518 memset(XmtCmd, '\0', sizeof(*XmtCmd));
2519 XmtCmd->Buffer.FirstSgeAddress = phys_addr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002520 XmtCmd->Buffer.FirstSgeLength = DataLength;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002521 XmtCmd->Buffer.SgeOffset = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002522 XmtCmd->Buffer.TotalLength = DataLength;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302523 XmtCmd->SgEntries = 1;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002524 XmtCmd->Flags = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302525 /*
2526 * Advance transmit cmd descripter by 1.
2527 * NOTE - See comments in SxgTcpOutput where we write
2528 * to the XmtCmd register regarding CPU ID values and/or
2529 * multiple commands.
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302530 * Top 16 bits specify queue_id. See comments about queue_id above
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302531 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302532 /* Four queues at the moment */
2533 ASSERT((queue_id & ~SXG_LARGE_SEND_QUEUE_MASK) == 0);
2534 WRITE_REG(adapter->UcodeRegs[0].XmtCmd, ((queue_id << 16) | 1), TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002535 adapter->Stats.XmtQLen++; /* Stats within lock */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302536 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002537 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XDumSgl2",
2538 XmtCmd, pSgl, SxgSgl, 0);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302539 return STATUS_SUCCESS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002540
2541 abortcmd:
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302542 /*
2543 * NOTE - Only jump to this label AFTER grabbing the
2544 * XmtZeroLock, and DO NOT DROP IT between the
2545 * command allocation and the following abort.
2546 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002547 if (XmtCmd) {
2548 SXG_ABORT_CMD(XmtRingInfo);
2549 }
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302550 spin_unlock_irqrestore(&adapter->XmtZeroLock, flags);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002551
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302552/*
2553 * failsgl:
2554 * Jump to this label if failure occurs before the
2555 * XmtZeroLock is grabbed
2556 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05302557 adapter->stats.tx_errors++;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002558 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "DumSGFal",
2559 pSgl, SxgSgl, XmtRingInfo->Head, XmtRingInfo->Tail);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302560 /* SxgSgl->DumbPacket is the skb */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05302561 // SXG_COMPLETE_DUMB_SEND(adapter, SxgSgl->DumbPacket);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05302562
2563 return STATUS_FAILURE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002564}
2565
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002566/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302567 * Link management functions
2568 *
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002569 * sxg_initialize_link - Initialize the link stuff
2570 *
2571 * Arguments -
2572 * adapter - A pointer to our adapter structure
2573 *
2574 * Return
2575 * status
2576 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002577static int sxg_initialize_link(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002578{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302579 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002580 u32 Value;
2581 u32 ConfigData;
2582 u32 MaxFrame;
2583 int status;
2584
2585 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitLink",
2586 adapter, 0, 0, 0);
2587
J.R. Maurob243c4a2008-10-20 19:28:58 -04002588 /* Reset PHY and XGXS module */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002589 WRITE_REG(HwRegs->LinkStatus, LS_SERDES_POWER_DOWN, TRUE);
2590
J.R. Maurob243c4a2008-10-20 19:28:58 -04002591 /* Reset transmit configuration register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002592 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_RESET, TRUE);
2593
J.R. Maurob243c4a2008-10-20 19:28:58 -04002594 /* Reset receive configuration register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002595 WRITE_REG(HwRegs->RcvConfig, RCV_CONFIG_RESET, TRUE);
2596
J.R. Maurob243c4a2008-10-20 19:28:58 -04002597 /* Reset all MAC modules */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002598 WRITE_REG(HwRegs->MacConfig0, AXGMAC_CFG0_SUB_RESET, TRUE);
2599
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302600 /*
2601 * Link address 0
2602 * XXXTODO - This assumes the MAC address (0a:0b:0c:0d:0e:0f)
2603 * is stored with the first nibble (0a) in the byte 0
2604 * of the Mac address. Possibly reverse?
2605 */
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302606 Value = *(u32 *) adapter->macaddr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002607 WRITE_REG(HwRegs->LinkAddress0Low, Value, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002608 /* also write the MAC address to the MAC. Endian is reversed. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002609 WRITE_REG(HwRegs->MacAddressLow, ntohl(Value), TRUE);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05302610 Value = (*(u16 *) & adapter->macaddr[4] & 0x0000FFFF);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002611 WRITE_REG(HwRegs->LinkAddress0High, Value | LINK_ADDRESS_ENABLE, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002612 /* endian swap for the MAC (put high bytes in bits [31:16], swapped) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002613 Value = ntohl(Value);
2614 WRITE_REG(HwRegs->MacAddressHigh, Value, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002615 /* Link address 1 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002616 WRITE_REG(HwRegs->LinkAddress1Low, 0, TRUE);
2617 WRITE_REG(HwRegs->LinkAddress1High, 0, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002618 /* Link address 2 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002619 WRITE_REG(HwRegs->LinkAddress2Low, 0, TRUE);
2620 WRITE_REG(HwRegs->LinkAddress2High, 0, TRUE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002621 /* Link address 3 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002622 WRITE_REG(HwRegs->LinkAddress3Low, 0, TRUE);
2623 WRITE_REG(HwRegs->LinkAddress3High, 0, TRUE);
2624
J.R. Maurob243c4a2008-10-20 19:28:58 -04002625 /* Enable MAC modules */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002626 WRITE_REG(HwRegs->MacConfig0, 0, TRUE);
2627
J.R. Maurob243c4a2008-10-20 19:28:58 -04002628 /* Configure MAC */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302629 WRITE_REG(HwRegs->MacConfig1, (
2630 /* Allow sending of pause */
2631 AXGMAC_CFG1_XMT_PAUSE |
2632 /* Enable XMT */
2633 AXGMAC_CFG1_XMT_EN |
2634 /* Enable detection of pause */
2635 AXGMAC_CFG1_RCV_PAUSE |
2636 /* Enable receive */
2637 AXGMAC_CFG1_RCV_EN |
2638 /* short frame detection */
2639 AXGMAC_CFG1_SHORT_ASSERT |
2640 /* Verify frame length */
2641 AXGMAC_CFG1_CHECK_LEN |
2642 /* Generate FCS */
2643 AXGMAC_CFG1_GEN_FCS |
2644 /* Pad frames to 64 bytes */
2645 AXGMAC_CFG1_PAD_64),
2646 TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002647
J.R. Maurob243c4a2008-10-20 19:28:58 -04002648 /* Set AXGMAC max frame length if jumbo. Not needed for standard MTU */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002649 if (adapter->JumboEnabled) {
2650 WRITE_REG(HwRegs->MacMaxFrameLen, AXGMAC_MAXFRAME_JUMBO, TRUE);
2651 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302652 /*
2653 * AMIIM Configuration Register -
2654 * The value placed in the AXGMAC_AMIIM_CFG_HALF_CLOCK portion
2655 * (bottom bits) of this register is used to determine the MDC frequency
2656 * as specified in the A-XGMAC Design Document. This value must not be
2657 * zero. The following value (62 or 0x3E) is based on our MAC transmit
2658 * clock frequency (MTCLK) of 312.5 MHz. Given a maximum MDIO clock
2659 * frequency of 2.5 MHz (see the PHY spec), we get:
2660 * 312.5/(2*(X+1)) < 2.5 ==> X = 62.
2661 * This value happens to be the default value for this register, so we
2662 * really don't have to do this.
2663 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002664 WRITE_REG(HwRegs->MacAmiimConfig, 0x0000003E, TRUE);
2665
J.R. Maurob243c4a2008-10-20 19:28:58 -04002666 /* Power up and enable PHY and XAUI/XGXS/Serdes logic */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002667 WRITE_REG(HwRegs->LinkStatus,
2668 (LS_PHY_CLR_RESET |
2669 LS_XGXS_ENABLE |
2670 LS_XGXS_CTL | LS_PHY_CLK_EN | LS_ATTN_ALARM), TRUE);
2671 DBG_ERROR("After Power Up and enable PHY in sxg_initialize_link\n");
2672
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302673 /*
2674 * Per information given by Aeluros, wait 100 ms after removing reset.
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302675 * It's not enough to wait for the self-clearing reset bit in reg 0 to
2676 * clear.
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302677 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002678 mdelay(100);
2679
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302680 /* Verify the PHY has come up by checking that the Reset bit has
2681 * cleared.
2682 */
2683 status = sxg_read_mdio_reg(adapter,
2684 MIIM_DEV_PHY_PMA, /* PHY PMA/PMD module */
2685 PHY_PMA_CONTROL1, /* PMA/PMD control register */
2686 &Value);
2687 DBG_ERROR("After sxg_read_mdio_reg Value[%x] fail=%x\n", Value,
2688 (Value & PMA_CONTROL1_RESET));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002689 if (status != STATUS_SUCCESS)
2690 return (STATUS_FAILURE);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002691 if (Value & PMA_CONTROL1_RESET) /* reset complete if bit is 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002692 return (STATUS_FAILURE);
2693
J.R. Maurob243c4a2008-10-20 19:28:58 -04002694 /* The SERDES should be initialized by now - confirm */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002695 READ_REG(HwRegs->LinkStatus, Value);
J.R. Maurob243c4a2008-10-20 19:28:58 -04002696 if (Value & LS_SERDES_DOWN) /* verify SERDES is initialized */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002697 return (STATUS_FAILURE);
2698
J.R. Maurob243c4a2008-10-20 19:28:58 -04002699 /* The XAUI link should also be up - confirm */
2700 if (!(Value & LS_XAUI_LINK_UP)) /* verify XAUI link is up */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002701 return (STATUS_FAILURE);
2702
J.R. Maurob243c4a2008-10-20 19:28:58 -04002703 /* Initialize the PHY */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002704 status = sxg_phy_init(adapter);
2705 if (status != STATUS_SUCCESS)
2706 return (STATUS_FAILURE);
2707
J.R. Maurob243c4a2008-10-20 19:28:58 -04002708 /* Enable the Link Alarm */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302709
2710 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2711 * LASI_CONTROL - LASI control register
2712 * LASI_CTL_LS_ALARM_ENABLE - enable link alarm bit
2713 */
2714 status = sxg_write_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2715 LASI_CONTROL,
2716 LASI_CTL_LS_ALARM_ENABLE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002717 if (status != STATUS_SUCCESS)
2718 return (STATUS_FAILURE);
2719
J.R. Maurob243c4a2008-10-20 19:28:58 -04002720 /* XXXTODO - temporary - verify bit is set */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302721
2722 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2723 * LASI_CONTROL - LASI control register
2724 */
2725 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2726 LASI_CONTROL,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002727 &Value);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302728
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002729 if (status != STATUS_SUCCESS)
2730 return (STATUS_FAILURE);
2731 if (!(Value & LASI_CTL_LS_ALARM_ENABLE)) {
2732 DBG_ERROR("Error! LASI Control Alarm Enable bit not set!\n");
2733 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04002734 /* Enable receive */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002735 MaxFrame = adapter->JumboEnabled ? JUMBOMAXFRAME : ETHERMAXFRAME;
2736 ConfigData = (RCV_CONFIG_ENABLE |
2737 RCV_CONFIG_ENPARSE |
2738 RCV_CONFIG_RCVBAD |
2739 RCV_CONFIG_RCVPAUSE |
2740 RCV_CONFIG_TZIPV6 |
2741 RCV_CONFIG_TZIPV4 |
2742 RCV_CONFIG_HASH_16 |
2743 RCV_CONFIG_SOCKET | RCV_CONFIG_BUFSIZE(MaxFrame));
2744 WRITE_REG(HwRegs->RcvConfig, ConfigData, TRUE);
2745
2746 WRITE_REG(HwRegs->XmtConfig, XMT_CONFIG_ENABLE, TRUE);
2747
J.R. Maurob243c4a2008-10-20 19:28:58 -04002748 /* Mark the link as down. We'll get a link event when it comes up. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002749 sxg_link_state(adapter, SXG_LINK_DOWN);
2750
2751 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInitLnk",
2752 adapter, 0, 0, 0);
2753 return (STATUS_SUCCESS);
2754}
2755
2756/*
2757 * sxg_phy_init - Initialize the PHY
2758 *
2759 * Arguments -
2760 * adapter - A pointer to our adapter structure
2761 *
2762 * Return
2763 * status
2764 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002765static int sxg_phy_init(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002766{
2767 u32 Value;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302768 struct phy_ucode *p;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002769 int status;
2770
Harvey Harrisone88bd232008-10-17 14:46:10 -07002771 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002772
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302773 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module
2774 * 0xC205 - PHY ID register (?)
2775 * &Value - XXXTODO - add def
2776 */
2777 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2778 0xC205,
2779 &Value);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002780 if (status != STATUS_SUCCESS)
2781 return (STATUS_FAILURE);
2782
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302783 if (Value == 0x0012) {
2784 /* 0x0012 == AEL2005C PHY(?) - XXXTODO - add def */
2785 DBG_ERROR("AEL2005C PHY detected. Downloading PHY \
2786 microcode.\n");
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002787
J.R. Maurob243c4a2008-10-20 19:28:58 -04002788 /* Initialize AEL2005C PHY and download PHY microcode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002789 for (p = PhyUcode; p->Addr != 0xFFFF; p++) {
2790 if (p->Addr == 0) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04002791 /* if address == 0, data == sleep time in ms */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002792 mdelay(p->Data);
2793 } else {
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302794 /* write the given data to the specified address */
2795 status = sxg_write_mdio_reg(adapter,
2796 MIIM_DEV_PHY_PMA,
2797 /* PHY address */
2798 p->Addr,
2799 /* PHY data */
2800 p->Data);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002801 if (status != STATUS_SUCCESS)
2802 return (STATUS_FAILURE);
2803 }
2804 }
2805 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002806 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002807
2808 return (STATUS_SUCCESS);
2809}
2810
2811/*
2812 * sxg_link_event - Process a link event notification from the card
2813 *
2814 * Arguments -
2815 * adapter - A pointer to our adapter structure
2816 *
2817 * Return
2818 * None
2819 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002820static void sxg_link_event(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002821{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05302822 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302823 struct net_device *netdev = adapter->netdev;
J.R. Mauro73b07062008-10-28 18:42:02 -04002824 enum SXG_LINK_STATE LinkState;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002825 int status;
2826 u32 Value;
2827
2828 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "LinkEvnt",
2829 adapter, 0, 0, 0);
Harvey Harrisone88bd232008-10-17 14:46:10 -07002830 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002831
J.R. Maurob243c4a2008-10-20 19:28:58 -04002832 /* Check the Link Status register. We should have a Link Alarm. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002833 READ_REG(HwRegs->LinkStatus, Value);
2834 if (Value & LS_LINK_ALARM) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302835 /*
2836 * We got a Link Status alarm. First, pause to let the
2837 * link state settle (it can bounce a number of times)
2838 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002839 mdelay(10);
2840
J.R. Maurob243c4a2008-10-20 19:28:58 -04002841 /* Now clear the alarm by reading the LASI status register. */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302842 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
2843 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2844 /* LASI status register */
2845 LASI_STATUS,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002846 &Value);
2847 if (status != STATUS_SUCCESS) {
2848 DBG_ERROR("Error reading LASI Status MDIO register!\n");
2849 sxg_link_state(adapter, SXG_LINK_DOWN);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302850 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002851 }
2852 ASSERT(Value & LASI_STATUS_LS_ALARM);
2853
J.R. Maurob243c4a2008-10-20 19:28:58 -04002854 /* Now get and set the link state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002855 LinkState = sxg_get_link_state(adapter);
2856 sxg_link_state(adapter, LinkState);
2857 DBG_ERROR("SXG: Link Alarm occurred. Link is %s\n",
2858 ((LinkState == SXG_LINK_UP) ? "UP" : "DOWN"));
Mithlesh Thukral0d414722009-01-19 20:29:59 +05302859 if (LinkState == SXG_LINK_UP)
2860 netif_carrier_on(netdev);
2861 else
2862 netif_carrier_off(netdev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002863 } else {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302864 /*
2865 * XXXTODO - Assuming Link Attention is only being generated
2866 * for the Link Alarm pin (and not for a XAUI Link Status change)
2867 * , then it's impossible to get here. Yet we've gotten here
2868 * twice (under extreme conditions - bouncing the link up and
2869 * down many times a second). Needs further investigation.
2870 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002871 DBG_ERROR("SXG: sxg_link_event: Can't get here!\n");
2872 DBG_ERROR("SXG: Link Status == 0x%08X.\n", Value);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302873 /* ASSERT(0); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002874 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07002875 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002876
2877}
2878
2879/*
2880 * sxg_get_link_state - Determine if the link is up or down
2881 *
2882 * Arguments -
2883 * adapter - A pointer to our adapter structure
2884 *
2885 * Return
2886 * Link State
2887 */
J.R. Mauro73b07062008-10-28 18:42:02 -04002888static enum SXG_LINK_STATE sxg_get_link_state(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002889{
2890 int status;
2891 u32 Value;
2892
Harvey Harrisone88bd232008-10-17 14:46:10 -07002893 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002894
2895 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "GetLink",
2896 adapter, 0, 0, 0);
2897
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05302898 /*
2899 * Per the Xenpak spec (and the IEEE 10Gb spec?), the link is up if
2900 * the following 3 bits (from 3 different MDIO registers) are all true.
2901 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302902
2903 /* MIIM_DEV_PHY_PMA - PHY PMA/PMD module */
2904 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PMA,
2905 /* PMA/PMD Receive Signal Detect register */
2906 PHY_PMA_RCV_DET,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002907 &Value);
2908 if (status != STATUS_SUCCESS)
2909 goto bad;
2910
J.R. Maurob243c4a2008-10-20 19:28:58 -04002911 /* If PMA/PMD receive signal detect is 0, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002912 if (!(Value & PMA_RCV_DETECT))
2913 return (SXG_LINK_DOWN);
2914
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302915 /* MIIM_DEV_PHY_PCS - PHY PCS module */
2916 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_PCS,
2917 /* PCS 10GBASE-R Status 1 register */
2918 PHY_PCS_10G_STATUS1,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002919 &Value);
2920 if (status != STATUS_SUCCESS)
2921 goto bad;
2922
J.R. Maurob243c4a2008-10-20 19:28:58 -04002923 /* If PCS is not locked to receive blocks, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002924 if (!(Value & PCS_10B_BLOCK_LOCK))
2925 return (SXG_LINK_DOWN);
2926
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302927 status = sxg_read_mdio_reg(adapter, MIIM_DEV_PHY_XS,/* PHY XS module */
2928 /* XS Lane Status register */
2929 PHY_XS_LANE_STATUS,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002930 &Value);
2931 if (status != STATUS_SUCCESS)
2932 goto bad;
2933
J.R. Maurob243c4a2008-10-20 19:28:58 -04002934 /* If XS transmit lanes are not aligned, then the link is down */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002935 if (!(Value & XS_LANE_ALIGN))
2936 return (SXG_LINK_DOWN);
2937
J.R. Maurob243c4a2008-10-20 19:28:58 -04002938 /* All 3 bits are true, so the link is up */
Harvey Harrisone88bd232008-10-17 14:46:10 -07002939 DBG_ERROR("EXIT %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002940
2941 return (SXG_LINK_UP);
2942
2943 bad:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05302944 /* An error occurred reading an MDIO register. This shouldn't happen. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002945 DBG_ERROR("Error reading an MDIO register!\n");
2946 ASSERT(0);
2947 return (SXG_LINK_DOWN);
2948}
2949
J.R. Mauro73b07062008-10-28 18:42:02 -04002950static void sxg_indicate_link_state(struct adapter_t *adapter,
2951 enum SXG_LINK_STATE LinkState)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002952{
2953 if (adapter->LinkState == SXG_LINK_UP) {
2954 DBG_ERROR("%s: LINK now UP, call netif_start_queue\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002955 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002956 netif_start_queue(adapter->netdev);
2957 } else {
2958 DBG_ERROR("%s: LINK now DOWN, call netif_stop_queue\n",
Harvey Harrisone88bd232008-10-17 14:46:10 -07002959 __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002960 netif_stop_queue(adapter->netdev);
2961 }
2962}
2963
2964/*
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05302965 * sxg_change_mtu - Change the Maximum Transfer Unit
2966 * * @returns 0 on success, negative on failure
2967 */
2968int sxg_change_mtu (struct net_device *netdev, int new_mtu)
2969{
2970 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(netdev);
2971
2972 if (!((new_mtu == SXG_DEFAULT_MTU) || (new_mtu == SXG_JUMBO_MTU)))
2973 return -EINVAL;
2974
2975 if(new_mtu == netdev->mtu)
2976 return 0;
2977
2978 netdev->mtu = new_mtu;
2979
2980 if (new_mtu == SXG_JUMBO_MTU) {
2981 adapter->JumboEnabled = TRUE;
2982 adapter->FrameSize = JUMBOMAXFRAME;
2983 adapter->ReceiveBufferSize = SXG_RCV_JUMBO_BUFFER_SIZE;
2984 } else {
2985 adapter->JumboEnabled = FALSE;
2986 adapter->FrameSize = ETHERMAXFRAME;
2987 adapter->ReceiveBufferSize = SXG_RCV_DATA_BUFFER_SIZE;
2988 }
2989
2990 sxg_entry_halt(netdev);
2991 sxg_entry_open(netdev);
2992 return 0;
2993}
2994
2995/*
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07002996 * sxg_link_state - Set the link state and if necessary, indicate.
2997 * This routine the central point of processing for all link state changes.
2998 * Nothing else in the driver should alter the link state or perform
2999 * link state indications
3000 *
3001 * Arguments -
3002 * adapter - A pointer to our adapter structure
3003 * LinkState - The link state
3004 *
3005 * Return
3006 * None
3007 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303008static void sxg_link_state(struct adapter_t *adapter,
3009 enum SXG_LINK_STATE LinkState)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003010{
3011 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "LnkINDCT",
3012 adapter, LinkState, adapter->LinkState, adapter->State);
3013
Harvey Harrisone88bd232008-10-17 14:46:10 -07003014 DBG_ERROR("ENTER %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003015
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303016 /*
3017 * Hold the adapter lock during this routine. Maybe move
3018 * the lock to the caller.
3019 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303020 /* IMP TODO : Check if we can survive without taking this lock */
3021// spin_lock(&adapter->AdapterLock);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003022 if (LinkState == adapter->LinkState) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003023 /* Nothing changed.. */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303024// spin_unlock(&adapter->AdapterLock);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303025 DBG_ERROR("EXIT #0 %s. Link status = %d\n",
3026 __func__, LinkState);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003027 return;
3028 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04003029 /* Save the adapter state */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003030 adapter->LinkState = LinkState;
3031
J.R. Maurob243c4a2008-10-20 19:28:58 -04003032 /* Drop the lock and indicate link state */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303033// spin_unlock(&adapter->AdapterLock);
Harvey Harrisone88bd232008-10-17 14:46:10 -07003034 DBG_ERROR("EXIT #1 %s\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003035
3036 sxg_indicate_link_state(adapter, LinkState);
3037}
3038
3039/*
3040 * sxg_write_mdio_reg - Write to a register on the MDIO bus
3041 *
3042 * Arguments -
3043 * adapter - A pointer to our adapter structure
3044 * DevAddr - MDIO device number being addressed
3045 * RegAddr - register address for the specified MDIO device
3046 * Value - value to write to the MDIO register
3047 *
3048 * Return
3049 * status
3050 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003051static int sxg_write_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003052 u32 DevAddr, u32 RegAddr, u32 Value)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003053{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303054 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303055 /* Address operation (written to MIIM field reg) */
3056 u32 AddrOp;
3057 /* Write operation (written to MIIM field reg) */
3058 u32 WriteOp;
3059 u32 Cmd;/* Command (written to MIIM command reg) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003060 u32 ValueRead;
3061 u32 Timeout;
3062
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303063 /* DBG_ERROR("ENTER %s\n", __func__); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003064
3065 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3066 adapter, 0, 0, 0);
3067
J.R. Maurob243c4a2008-10-20 19:28:58 -04003068 /* Ensure values don't exceed field width */
3069 DevAddr &= 0x001F; /* 5-bit field */
3070 RegAddr &= 0xFFFF; /* 16-bit field */
3071 Value &= 0xFFFF; /* 16-bit field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003072
J.R. Maurob243c4a2008-10-20 19:28:58 -04003073 /* Set MIIM field register bits for an MIIM address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003074 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3075 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3076 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3077 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3078
J.R. Maurob243c4a2008-10-20 19:28:58 -04003079 /* Set MIIM field register bits for an MIIM write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003080 WriteOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3081 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3082 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3083 (MIIM_OP_WRITE << AXGMAC_AMIIM_FIELD_OP_SHIFT) | Value;
3084
J.R. Maurob243c4a2008-10-20 19:28:58 -04003085 /* Set MIIM command register bits to execute an MIIM command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003086 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3087
J.R. Maurob243c4a2008-10-20 19:28:58 -04003088 /* Reset the command register command bit (in case it's not 0) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003089 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3090
J.R. Maurob243c4a2008-10-20 19:28:58 -04003091 /* MIIM write to set the address of the specified MDIO register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003092 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3093
J.R. Maurob243c4a2008-10-20 19:28:58 -04003094 /* Write to MIIM Command Register to execute to address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003095 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3096
J.R. Maurob243c4a2008-10-20 19:28:58 -04003097 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003098 Timeout = SXG_LINK_TIMEOUT;
3099 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003100 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003101 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3102 if (--Timeout == 0) {
3103 return (STATUS_FAILURE);
3104 }
3105 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3106
J.R. Maurob243c4a2008-10-20 19:28:58 -04003107 /* Reset the command register command bit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003108 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3109
J.R. Maurob243c4a2008-10-20 19:28:58 -04003110 /* MIIM write to set up an MDIO write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003111 WRITE_REG(HwRegs->MacAmiimField, WriteOp, TRUE);
3112
J.R. Maurob243c4a2008-10-20 19:28:58 -04003113 /* Write to MIIM Command Register to execute the write operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003114 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3115
J.R. Maurob243c4a2008-10-20 19:28:58 -04003116 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003117 Timeout = SXG_LINK_TIMEOUT;
3118 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003119 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003120 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3121 if (--Timeout == 0) {
3122 return (STATUS_FAILURE);
3123 }
3124 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3125
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303126 /* DBG_ERROR("EXIT %s\n", __func__); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003127
3128 return (STATUS_SUCCESS);
3129}
3130
3131/*
3132 * sxg_read_mdio_reg - Read a register on the MDIO bus
3133 *
3134 * Arguments -
3135 * adapter - A pointer to our adapter structure
3136 * DevAddr - MDIO device number being addressed
3137 * RegAddr - register address for the specified MDIO device
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303138 * pValue - pointer to where to put data read from the MDIO register
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003139 *
3140 * Return
3141 * status
3142 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003143static int sxg_read_mdio_reg(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003144 u32 DevAddr, u32 RegAddr, u32 *pValue)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003145{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303146 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303147 u32 AddrOp; /* Address operation (written to MIIM field reg) */
3148 u32 ReadOp; /* Read operation (written to MIIM field reg) */
3149 u32 Cmd; /* Command (written to MIIM command reg) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003150 u32 ValueRead;
3151 u32 Timeout;
3152
3153 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "WrtMDIO",
3154 adapter, 0, 0, 0);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303155 DBG_ERROR("ENTER %s\n", __FUNCTION__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003156
J.R. Maurob243c4a2008-10-20 19:28:58 -04003157 /* Ensure values don't exceed field width */
3158 DevAddr &= 0x001F; /* 5-bit field */
3159 RegAddr &= 0xFFFF; /* 16-bit field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003160
J.R. Maurob243c4a2008-10-20 19:28:58 -04003161 /* Set MIIM field register bits for an MIIM address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003162 AddrOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3163 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3164 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3165 (MIIM_OP_ADDR << AXGMAC_AMIIM_FIELD_OP_SHIFT) | RegAddr;
3166
J.R. Maurob243c4a2008-10-20 19:28:58 -04003167 /* Set MIIM field register bits for an MIIM read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003168 ReadOp = (MIIM_PORT_NUM << AXGMAC_AMIIM_FIELD_PORT_SHIFT) |
3169 (DevAddr << AXGMAC_AMIIM_FIELD_DEV_SHIFT) |
3170 (MIIM_TA_10GB << AXGMAC_AMIIM_FIELD_TA_SHIFT) |
3171 (MIIM_OP_READ << AXGMAC_AMIIM_FIELD_OP_SHIFT);
3172
J.R. Maurob243c4a2008-10-20 19:28:58 -04003173 /* Set MIIM command register bits to execute an MIIM command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003174 Cmd = AXGMAC_AMIIM_CMD_START | AXGMAC_AMIIM_CMD_10G_OPERATION;
3175
J.R. Maurob243c4a2008-10-20 19:28:58 -04003176 /* Reset the command register command bit (in case it's not 0) */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003177 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3178
J.R. Maurob243c4a2008-10-20 19:28:58 -04003179 /* MIIM write to set the address of the specified MDIO register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003180 WRITE_REG(HwRegs->MacAmiimField, AddrOp, TRUE);
3181
J.R. Maurob243c4a2008-10-20 19:28:58 -04003182 /* Write to MIIM Command Register to execute to address operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003183 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3184
J.R. Maurob243c4a2008-10-20 19:28:58 -04003185 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003186 Timeout = SXG_LINK_TIMEOUT;
3187 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003188 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003189 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3190 if (--Timeout == 0) {
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303191 DBG_ERROR("EXIT %s with STATUS_FAILURE 1\n", __FUNCTION__);
3192
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003193 return (STATUS_FAILURE);
3194 }
3195 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3196
J.R. Maurob243c4a2008-10-20 19:28:58 -04003197 /* Reset the command register command bit */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003198 WRITE_REG(HwRegs->MacAmiimCmd, 0, TRUE);
3199
J.R. Maurob243c4a2008-10-20 19:28:58 -04003200 /* MIIM write to set up an MDIO register read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003201 WRITE_REG(HwRegs->MacAmiimField, ReadOp, TRUE);
3202
J.R. Maurob243c4a2008-10-20 19:28:58 -04003203 /* Write to MIIM Command Register to execute the read operation */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003204 WRITE_REG(HwRegs->MacAmiimCmd, Cmd, TRUE);
3205
J.R. Maurob243c4a2008-10-20 19:28:58 -04003206 /* Poll AMIIM Indicator register to wait for completion */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003207 Timeout = SXG_LINK_TIMEOUT;
3208 do {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003209 udelay(100); /* Timeout in 100us units */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003210 READ_REG(HwRegs->MacAmiimIndicator, ValueRead);
3211 if (--Timeout == 0) {
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303212 DBG_ERROR("EXIT %s with STATUS_FAILURE 2\n", __FUNCTION__);
3213
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003214 return (STATUS_FAILURE);
3215 }
3216 } while (ValueRead & AXGMAC_AMIIM_INDC_BUSY);
3217
J.R. Maurob243c4a2008-10-20 19:28:58 -04003218 /* Read the MDIO register data back from the field register */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003219 READ_REG(HwRegs->MacAmiimField, *pValue);
J.R. Maurob243c4a2008-10-20 19:28:58 -04003220 *pValue &= 0xFFFF; /* data is in the lower 16 bits */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003221
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303222 DBG_ERROR("EXIT %s\n", __FUNCTION__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003223
3224 return (STATUS_SUCCESS);
3225}
3226
3227/*
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003228 * Functions to obtain the CRC corresponding to the destination mac address.
3229 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
3230 * the polynomial:
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303231 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5
3232 * + x^4 + x^2 + x^1.
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003233 *
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303234 * After the CRC for the 6 bytes is generated (but before the value is
3235 * complemented), we must then transpose the value and return bits 30-23.
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003236 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303237static u32 sxg_crc_table[256];/* Table of CRC's for all possible byte values */
3238static u32 sxg_crc_init; /* Is table initialized */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003239
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303240/* Contruct the CRC32 table */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003241static void sxg_mcast_init_crc32(void)
3242{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303243 u32 c; /* CRC shit reg */
3244 u32 e = 0; /* Poly X-or pattern */
3245 int i; /* counter */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003246 int k; /* byte being shifted into crc */
3247
3248 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
3249
3250 for (i = 0; i < sizeof(p) / sizeof(int); i++) {
3251 e |= 1L << (31 - p[i]);
3252 }
3253
3254 for (i = 1; i < 256; i++) {
3255 c = i;
3256 for (k = 8; k; k--) {
3257 c = c & 1 ? (c >> 1) ^ e : c >> 1;
3258 }
3259 sxg_crc_table[i] = c;
3260 }
3261}
3262
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003263/*
3264 * Return the MAC hast as described above.
3265 */
3266static unsigned char sxg_mcast_get_mac_hash(char *macaddr)
3267{
3268 u32 crc;
3269 char *p;
3270 int i;
3271 unsigned char machash = 0;
3272
3273 if (!sxg_crc_init) {
3274 sxg_mcast_init_crc32();
3275 sxg_crc_init = 1;
3276 }
3277
3278 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
3279 for (i = 0, p = macaddr; i < 6; ++p, ++i) {
3280 crc = (crc >> 8) ^ sxg_crc_table[(crc ^ *p) & 0xFF];
3281 }
3282
3283 /* Return bits 1-8, transposed */
3284 for (i = 1; i < 9; i++) {
3285 machash |= (((crc >> i) & 1) << (8 - i));
3286 }
3287
3288 return (machash);
3289}
3290
J.R. Mauro73b07062008-10-28 18:42:02 -04003291static void sxg_mcast_set_mask(struct adapter_t *adapter)
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003292{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303293 struct sxg_ucode_regs *sxg_regs = adapter->UcodeRegs;
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003294
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303295 DBG_ERROR("%s ENTER (%s) MacFilter[%x] mask[%llx]\n", __FUNCTION__,
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003296 adapter->netdev->name, (unsigned int)adapter->MacFilter,
3297 adapter->MulticastMask);
3298
3299 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_PROMISC)) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303300 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303301 * Turn on all multicast addresses. We have to do this for
3302 * promiscuous mode as well as ALLMCAST mode. It saves the
3303 * Microcode from having keep state about the MAC configuration
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003304 */
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303305 /* DBG_ERROR("sxg: %s MacFilter = MAC_ALLMCAST | MAC_PROMISC\n \
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303306 * SLUT MODE!!!\n",__func__);
3307 */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003308 WRITE_REG(sxg_regs->McastLow, 0xFFFFFFFF, FLUSH);
3309 WRITE_REG(sxg_regs->McastHigh, 0xFFFFFFFF, FLUSH);
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303310 /* DBG_ERROR("%s (%s) WRITE to slic_regs slic_mcastlow&high \
3311 * 0xFFFFFFFF\n",__func__, adapter->netdev->name);
3312 */
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003313
3314 } else {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303315 /*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303316 * Commit our multicast mast to the SLIC by writing to the
3317 * multicast address mask registers
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003318 */
3319 DBG_ERROR("%s (%s) WRITE mcastlow[%lx] mcasthigh[%lx]\n",
3320 __func__, adapter->netdev->name,
3321 ((ulong) (adapter->MulticastMask & 0xFFFFFFFF)),
3322 ((ulong)
3323 ((adapter->MulticastMask >> 32) & 0xFFFFFFFF)));
3324
3325 WRITE_REG(sxg_regs->McastLow,
3326 (u32) (adapter->MulticastMask & 0xFFFFFFFF), FLUSH);
3327 WRITE_REG(sxg_regs->McastHigh,
3328 (u32) ((adapter->
3329 MulticastMask >> 32) & 0xFFFFFFFF), FLUSH);
3330 }
3331}
3332
J.R. Mauro73b07062008-10-28 18:42:02 -04003333static void sxg_mcast_set_bit(struct adapter_t *adapter, char *address)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003334{
3335 unsigned char crcpoly;
3336
3337 /* Get the CRC polynomial for the mac address */
3338 crcpoly = sxg_mcast_get_mac_hash(address);
3339
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303340 /*
3341 * We only have space on the SLIC for 64 entries. Lop
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003342 * off the top two bits. (2^6 = 64)
3343 */
3344 crcpoly &= 0x3F;
3345
3346 /* OR in the new bit into our 64 bit mask. */
3347 adapter->MulticastMask |= (u64) 1 << crcpoly;
3348}
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303349
3350/*
3351 * Function takes MAC addresses from dev_mc_list and generates the Mask
3352 */
3353
3354static void sxg_set_mcast_addr(struct adapter_t *adapter)
3355{
3356 struct dev_mc_list *mclist;
3357 struct net_device *dev = adapter->netdev;
3358 int i;
3359
3360 if (adapter->MacFilter & (MAC_ALLMCAST | MAC_MCAST)) {
3361 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
3362 i++, mclist = mclist->next) {
3363 sxg_mcast_set_bit(adapter,mclist->da_addr);
3364 }
3365 }
3366 sxg_mcast_set_mask(adapter);
3367}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003368
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303369static void sxg_mcast_set_list(struct net_device *dev)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003370{
J.R. Mauro73b07062008-10-28 18:42:02 -04003371 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003372
3373 ASSERT(adapter);
Mithlesh Thukral559990c2009-01-30 20:20:19 +05303374 if (dev->flags & IFF_PROMISC)
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303375 adapter->MacFilter |= MAC_PROMISC;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303376 if (dev->flags & IFF_MULTICAST)
3377 adapter->MacFilter |= MAC_MCAST;
Mithlesh Thukral559990c2009-01-30 20:20:19 +05303378 if (dev->flags & IFF_ALLMULTI)
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303379 adapter->MacFilter |= MAC_ALLMCAST;
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303380
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303381 //XXX handle other flags as well
Mithlesh Thukralb040b072009-01-28 07:08:11 +05303382 sxg_set_mcast_addr(adapter);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303383}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003384
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303385void sxg_free_sgl_buffers(struct adapter_t *adapter)
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303386{
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303387 struct list_entry *ple;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303388 struct sxg_scatter_gather *Sgl;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003389
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303390 while(!(IsListEmpty(&adapter->AllSglBuffers))) {
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303391 ple = RemoveHeadList(&adapter->AllSglBuffers);
3392 Sgl = container_of(ple, struct sxg_scatter_gather, AllList);
3393 kfree(Sgl);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303394 adapter->AllSglBufferCount--;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303395 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303396}
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303397
3398void sxg_free_rcvblocks(struct adapter_t *adapter)
3399{
3400 u32 i;
3401 void *temp_RcvBlock;
3402 struct list_entry *ple;
3403 struct sxg_rcv_block_hdr *RcvBlockHdr;
3404 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3405 ASSERT((adapter->state == SXG_STATE_INITIALIZING) ||
3406 (adapter->state == SXG_STATE_HALTING));
3407 while(!(IsListEmpty(&adapter->AllRcvBlocks))) {
3408
3409 ple = RemoveHeadList(&adapter->AllRcvBlocks);
3410 RcvBlockHdr = container_of(ple, struct sxg_rcv_block_hdr, AllList);
3411
3412 if(RcvBlockHdr->VirtualAddress) {
3413 temp_RcvBlock = RcvBlockHdr->VirtualAddress;
3414
3415 for(i=0; i< SXG_RCV_DESCRIPTORS_PER_BLOCK;
3416 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3417 RcvDataBufferHdr =
3418 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
3419 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3420 }
3421 }
3422
3423 pci_free_consistent(adapter->pcidev,
3424 SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE),
3425 RcvBlockHdr->VirtualAddress,
3426 RcvBlockHdr->PhysicalAddress);
3427 adapter->AllRcvBlockCount--;
3428 }
3429 ASSERT(adapter->AllRcvBlockCount == 0);
3430 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3431 adapter, 0, 0, 0);
3432}
3433void sxg_free_mcast_addrs(struct adapter_t *adapter)
3434{
3435 struct sxg_multicast_address *address;
3436 while(adapter->MulticastAddrs) {
3437 address = adapter->MulticastAddrs;
3438 adapter->MulticastAddrs = address->Next;
3439 kfree(address);
3440 }
3441
3442 adapter->MulticastMask= 0;
3443}
3444
3445void sxg_unmap_resources(struct adapter_t *adapter)
3446{
3447 if(adapter->HwRegs) {
3448 iounmap((void *)adapter->HwRegs);
3449 }
3450 if(adapter->UcodeRegs) {
3451 iounmap((void *)adapter->UcodeRegs);
3452 }
3453
3454 ASSERT(adapter->AllRcvBlockCount == 0);
3455 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFrRBlk",
3456 adapter, 0, 0, 0);
3457}
3458
3459
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303460
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003461/*
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303462 * sxg_free_resources - Free everything allocated in SxgAllocateResources
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003463 *
3464 * Arguments -
3465 * adapter - A pointer to our adapter structure
3466 *
3467 * Return
3468 * none
3469 */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303470void sxg_free_resources(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003471{
3472 u32 RssIds, IsrCount;
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303473 struct net_device *netdev = adapter->netdev;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003474 RssIds = SXG_RSS_CPU_COUNT(adapter);
3475 IsrCount = adapter->MsiEnabled ? RssIds : 1;
3476
3477 if (adapter->BasicAllocations == FALSE) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303478 /*
3479 * No allocations have been made, including spinlocks,
3480 * or listhead initializations. Return.
3481 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003482 return;
3483 }
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303484
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303485 /* Free Irq */
3486 free_irq(adapter->netdev->irq, netdev);
3487
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003488 if (!(IsListEmpty(&adapter->AllRcvBlocks))) {
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303489 sxg_free_rcvblocks(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003490 }
3491 if (!(IsListEmpty(&adapter->AllSglBuffers))) {
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303492 sxg_free_sgl_buffers(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003493 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303494
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003495 if (adapter->XmtRingZeroIndex) {
3496 pci_free_consistent(adapter->pcidev,
3497 sizeof(u32),
3498 adapter->XmtRingZeroIndex,
3499 adapter->PXmtRingZeroIndex);
3500 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303501 if (adapter->Isr) {
3502 pci_free_consistent(adapter->pcidev,
3503 sizeof(u32) * IsrCount,
3504 adapter->Isr, adapter->PIsr);
3505 }
3506
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303507 if (adapter->EventRings) {
3508 pci_free_consistent(adapter->pcidev,
3509 sizeof(struct sxg_event_ring) * RssIds,
3510 adapter->EventRings, adapter->PEventRings);
3511 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303512 if (adapter->RcvRings) {
3513 pci_free_consistent(adapter->pcidev,
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303514 sizeof(struct sxg_rcv_ring) * 1,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303515 adapter->RcvRings,
3516 adapter->PRcvRings);
3517 adapter->RcvRings = NULL;
3518 }
3519
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303520 if(adapter->XmtRings) {
3521 pci_free_consistent(adapter->pcidev,
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303522 sizeof(struct sxg_xmt_ring) * 1,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303523 adapter->XmtRings,
3524 adapter->PXmtRings);
3525 adapter->XmtRings = NULL;
3526 }
3527
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303528 if (adapter->ucode_stats) {
3529 pci_unmap_single(adapter->pcidev,
3530 sizeof(struct sxg_ucode_stats),
3531 adapter->pucode_stats, PCI_DMA_FROMDEVICE);
3532 adapter->ucode_stats = NULL;
3533 }
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303534
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003535
J.R. Maurob243c4a2008-10-20 19:28:58 -04003536 /* Unmap register spaces */
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303537 sxg_unmap_resources(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003538
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303539 sxg_free_mcast_addrs(adapter);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003540
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003541 adapter->BasicAllocations = FALSE;
3542
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003543}
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003544
3545/*
3546 * sxg_allocate_complete -
3547 *
3548 * This routine is called when a memory allocation has completed.
3549 *
3550 * Arguments -
J.R. Mauro73b07062008-10-28 18:42:02 -04003551 * struct adapter_t * - Our adapter structure
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003552 * VirtualAddress - Memory virtual address
3553 * PhysicalAddress - Memory physical address
3554 * Length - Length of memory allocated (or 0)
3555 * Context - The type of buffer allocated
3556 *
3557 * Return
3558 * None.
3559 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303560static int sxg_allocate_complete(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003561 void *VirtualAddress,
3562 dma_addr_t PhysicalAddress,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303563 u32 Length, enum sxg_buffer_type Context)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003564{
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303565 int status = 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003566 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocCmp",
3567 adapter, VirtualAddress, Length, Context);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303568 ASSERT(atomic_read(&adapter->pending_allocations));
3569 atomic_dec(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003570
3571 switch (Context) {
3572
3573 case SXG_BUFFER_TYPE_RCV:
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303574 status = sxg_allocate_rcvblock_complete(adapter,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003575 VirtualAddress,
3576 PhysicalAddress, Length);
3577 break;
3578 case SXG_BUFFER_TYPE_SGL:
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303579 sxg_allocate_sgl_buffer_complete(adapter, (struct sxg_scatter_gather *)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003580 VirtualAddress,
3581 PhysicalAddress, Length);
3582 break;
3583 }
3584 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocCmp",
3585 adapter, VirtualAddress, Length, Context);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303586
3587 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003588}
3589
3590/*
3591 * sxg_allocate_buffer_memory - Shared memory allocation routine used for
3592 * synchronous and asynchronous buffer allocations
3593 *
3594 * Arguments -
3595 * adapter - A pointer to our adapter structure
3596 * Size - block size to allocate
3597 * BufferType - Type of buffer to allocate
3598 *
3599 * Return
3600 * int
3601 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003602static int sxg_allocate_buffer_memory(struct adapter_t *adapter,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303603 u32 Size, enum sxg_buffer_type BufferType)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003604{
3605 int status;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003606 void *Buffer;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003607 dma_addr_t pBuffer;
3608
3609 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AllocMem",
3610 adapter, Size, BufferType, 0);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303611 /*
3612 * Grab the adapter lock and check the state. If we're in anything other
3613 * than INITIALIZING or RUNNING state, fail. This is to prevent
3614 * allocations in an improper driver state
3615 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003616
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303617 atomic_inc(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003618
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303619 if(BufferType != SXG_BUFFER_TYPE_SGL)
3620 Buffer = pci_alloc_consistent(adapter->pcidev, Size, &pBuffer);
3621 else {
3622 Buffer = kzalloc(Size, GFP_ATOMIC);
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303623 pBuffer = (dma_addr_t)NULL;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303624 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003625 if (Buffer == NULL) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303626 /*
3627 * Decrement the AllocationsPending count while holding
3628 * the lock. Pause processing relies on this
3629 */
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303630 atomic_dec(&adapter->pending_allocations);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003631 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlcMemF1",
3632 adapter, Size, BufferType, 0);
3633 return (STATUS_RESOURCES);
3634 }
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303635 status = sxg_allocate_complete(adapter, Buffer, pBuffer, Size, BufferType);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003636
3637 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlocMem",
3638 adapter, Size, BufferType, status);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303639 return status;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003640}
3641
3642/*
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303643 * sxg_allocate_rcvblock_complete - Complete a receive descriptor
3644 * block allocation
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003645 *
3646 * Arguments -
3647 * adapter - A pointer to our adapter structure
3648 * RcvBlock - receive block virtual address
3649 * PhysicalAddress - Physical address
3650 * Length - Memory length
3651 *
3652 * Return
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003653 */
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303654static int sxg_allocate_rcvblock_complete(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003655 void *RcvBlock,
3656 dma_addr_t PhysicalAddress,
3657 u32 Length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003658{
3659 u32 i;
3660 u32 BufferSize = adapter->ReceiveBufferSize;
3661 u64 Paddr;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303662 void *temp_RcvBlock;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303663 struct sxg_rcv_block_hdr *RcvBlockHdr;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303664 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
3665 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
3666 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003667
3668 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlRcvBlk",
3669 adapter, RcvBlock, Length, 0);
3670 if (RcvBlock == NULL) {
3671 goto fail;
3672 }
3673 memset(RcvBlock, 0, Length);
3674 ASSERT((BufferSize == SXG_RCV_DATA_BUFFER_SIZE) ||
3675 (BufferSize == SXG_RCV_JUMBO_BUFFER_SIZE));
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303676 ASSERT(Length == SXG_RCV_BLOCK_SIZE(SXG_RCV_DATA_HDR_SIZE));
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303677 /*
3678 * First, initialize the contained pool of receive data buffers.
3679 * This initialization requires NBL/NB/MDL allocations, if any of them
3680 * fail, free the block and return without queueing the shared memory
3681 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303682 //RcvDataBuffer = RcvBlock;
3683 temp_RcvBlock = RcvBlock;
3684 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
3685 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3686 RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *)
3687 temp_RcvBlock;
3688 /* For FREE macro assertion */
3689 RcvDataBufferHdr->State = SXG_BUFFER_UPSTREAM;
3690 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr, BufferSize);
3691 if (RcvDataBufferHdr->SxgDumbRcvPacket == NULL)
3692 goto fail;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303693
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303694 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003695
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303696 /*
3697 * Place this entire block of memory on the AllRcvBlocks queue so it
3698 * can be free later
3699 */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303700
3701 RcvBlockHdr = (struct sxg_rcv_block_hdr *) ((unsigned char *)RcvBlock +
3702 SXG_RCV_BLOCK_HDR_OFFSET(SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003703 RcvBlockHdr->VirtualAddress = RcvBlock;
3704 RcvBlockHdr->PhysicalAddress = PhysicalAddress;
3705 spin_lock(&adapter->RcvQLock);
3706 adapter->AllRcvBlockCount++;
3707 InsertTailList(&adapter->AllRcvBlocks, &RcvBlockHdr->AllList);
3708 spin_unlock(&adapter->RcvQLock);
3709
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303710 /* Now free the contained receive data buffers that we
3711 * initialized above */
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303712 temp_RcvBlock = RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003713 for (i = 0, Paddr = PhysicalAddress;
3714 i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303715 i++, Paddr += SXG_RCV_DATA_HDR_SIZE,
3716 temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
3717 RcvDataBufferHdr =
3718 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003719 spin_lock(&adapter->RcvQLock);
3720 SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
3721 spin_unlock(&adapter->RcvQLock);
3722 }
3723
J.R. Maurob243c4a2008-10-20 19:28:58 -04003724 /* Locate the descriptor block and put it on a separate free queue */
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003725 RcvDescriptorBlock =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303726 (struct sxg_rcv_descriptor_block *) ((unsigned char *)RcvBlock +
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003727 SXG_RCV_DESCRIPTOR_BLOCK_OFFSET
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303728 (SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003729 RcvDescriptorBlockHdr =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303730 (struct sxg_rcv_descriptor_block_hdr *) ((unsigned char *)RcvBlock +
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003731 SXG_RCV_DESCRIPTOR_BLOCK_HDR_OFFSET
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303732 (SXG_RCV_DATA_HDR_SIZE));
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003733 RcvDescriptorBlockHdr->VirtualAddress = RcvDescriptorBlock;
3734 RcvDescriptorBlockHdr->PhysicalAddress = Paddr;
3735 spin_lock(&adapter->RcvQLock);
3736 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter, RcvDescriptorBlockHdr);
3737 spin_unlock(&adapter->RcvQLock);
3738 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlRBlk",
3739 adapter, RcvBlock, Length, 0);
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303740 return STATUS_SUCCESS;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303741fail:
J.R. Maurob243c4a2008-10-20 19:28:58 -04003742 /* Free any allocated resources */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003743 if (RcvBlock) {
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303744 temp_RcvBlock = RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003745 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK;
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303746 i++, temp_RcvBlock += SXG_RCV_DATA_HDR_SIZE) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003747 RcvDataBufferHdr =
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05303748 (struct sxg_rcv_data_buffer_hdr *)temp_RcvBlock;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003749 SXG_FREE_RCV_PACKET(RcvDataBufferHdr);
3750 }
3751 pci_free_consistent(adapter->pcidev,
3752 Length, RcvBlock, PhysicalAddress);
3753 }
Harvey Harrisone88bd232008-10-17 14:46:10 -07003754 DBG_ERROR("%s: OUT OF RESOURCES\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003755 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_IMPORTANT, "RcvAFail",
3756 adapter, adapter->FreeRcvBufferCount,
3757 adapter->FreeRcvBlockCount, adapter->AllRcvBlockCount);
3758 adapter->Stats.NoMem++;
Mithlesh Thukral0d414722009-01-19 20:29:59 +05303759 /* As allocation failed, free all previously allocated blocks..*/
3760 //sxg_free_rcvblocks(adapter);
3761
3762 return STATUS_RESOURCES;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003763}
3764
3765/*
3766 * sxg_allocate_sgl_buffer_complete - Complete a SGL buffer allocation
3767 *
3768 * Arguments -
3769 * adapter - A pointer to our adapter structure
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303770 * SxgSgl - struct sxg_scatter_gather buffer
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003771 * PhysicalAddress - Physical address
3772 * Length - Memory length
3773 *
3774 * Return
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003775 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003776static void sxg_allocate_sgl_buffer_complete(struct adapter_t *adapter,
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303777 struct sxg_scatter_gather *SxgSgl,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04003778 dma_addr_t PhysicalAddress,
3779 u32 Length)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003780{
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303781 unsigned long sgl_flags;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003782 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "AlSglCmp",
3783 adapter, SxgSgl, Length, 0);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303784 if(!in_irq())
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303785 spin_lock_irqsave(&adapter->SglQLock, sgl_flags);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303786 else
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303787 spin_lock(&adapter->SglQLock);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003788 adapter->AllSglBufferCount++;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303789 /* PhysicalAddress; */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303790 SxgSgl->PhysicalAddress = PhysicalAddress;
3791 /* Initialize backpointer once */
3792 SxgSgl->adapter = adapter;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003793 InsertTailList(&adapter->AllSglBuffers, &SxgSgl->AllList);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303794 if(!in_irq())
3795 spin_unlock_irqrestore(&adapter->SglQLock, sgl_flags);
3796 else
3797 spin_unlock(&adapter->SglQLock);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003798 SxgSgl->State = SXG_BUFFER_BUSY;
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05303799 SXG_FREE_SGL_BUFFER(adapter, SxgSgl, NULL, in_irq());
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003800 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XAlSgl",
3801 adapter, SxgSgl, Length, 0);
3802}
3803
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003804
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303805static int sxg_adapter_set_hwaddr(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003806{
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303807 /*
3808 * DBG_ERROR ("%s ENTER card->config_set[%x] port[%d] physport[%d] \
3809 * funct#[%d]\n", __func__, card->config_set,
3810 * adapter->port, adapter->physport, adapter->functionnumber);
3811 *
3812 * sxg_dbg_macaddrs(adapter);
3813 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303814 /* DBG_ERROR ("%s AFTER copying from config.macinfo into currmacaddr\n",
3815 * __FUNCTION__);
3816 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003817
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303818 /* sxg_dbg_macaddrs(adapter); */
3819
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05303820 struct net_device * dev = adapter->netdev;
3821 if(!dev)
3822 {
3823 printk("sxg: Dev is Null\n");
3824 }
3825
3826 DBG_ERROR("%s ENTER (%s)\n", __FUNCTION__, adapter->netdev->name);
3827
3828 if (netif_running(dev)) {
3829 return -EBUSY;
3830 }
3831 if (!adapter) {
3832 return -EBUSY;
3833 }
3834
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003835 if (!(adapter->currmacaddr[0] ||
3836 adapter->currmacaddr[1] ||
3837 adapter->currmacaddr[2] ||
3838 adapter->currmacaddr[3] ||
3839 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
3840 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
3841 }
3842 if (adapter->netdev) {
3843 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr, 6);
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303844 memcpy(adapter->netdev->perm_addr, adapter->currmacaddr, 6);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003845 }
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05303846 /* DBG_ERROR ("%s EXIT port %d\n", __func__, adapter->port); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003847 sxg_dbg_macaddrs(adapter);
3848
Mithlesh Thukral54aed112009-01-19 20:27:17 +05303849 return 0;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003850}
3851
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003852#if XXXTODO
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303853static int sxg_mac_set_address(struct net_device *dev, void *ptr)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003854{
J.R. Mauro73b07062008-10-28 18:42:02 -04003855 struct adapter_t *adapter = (struct adapter_t *) netdev_priv(dev);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003856 struct sockaddr *addr = ptr;
3857
Harvey Harrisone88bd232008-10-17 14:46:10 -07003858 DBG_ERROR("%s ENTER (%s)\n", __func__, adapter->netdev->name);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003859
3860 if (netif_running(dev)) {
3861 return -EBUSY;
3862 }
3863 if (!adapter) {
3864 return -EBUSY;
3865 }
3866 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 -07003867 __func__, adapter->netdev->name, adapter->currmacaddr[0],
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003868 adapter->currmacaddr[1], adapter->currmacaddr[2],
3869 adapter->currmacaddr[3], adapter->currmacaddr[4],
3870 adapter->currmacaddr[5]);
3871 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3872 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3873 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 -07003874 __func__, adapter->netdev->name, adapter->currmacaddr[0],
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003875 adapter->currmacaddr[1], adapter->currmacaddr[2],
3876 adapter->currmacaddr[3], adapter->currmacaddr[4],
3877 adapter->currmacaddr[5]);
3878
3879 sxg_config_set(adapter, TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003880 return 0;
3881}
Greg Kroah-Hartmanc6c25ed2008-10-21 10:41:45 -07003882#endif
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003883
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003884/*
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303885 * SXG DRIVER FUNCTIONS (below)
3886 *
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003887 * sxg_initialize_adapter - Initialize adapter
3888 *
3889 * Arguments -
3890 * adapter - A pointer to our adapter structure
3891 *
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303892 * Return - int
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003893 */
J.R. Mauro73b07062008-10-28 18:42:02 -04003894static int sxg_initialize_adapter(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003895{
3896 u32 RssIds, IsrCount;
3897 u32 i;
3898 int status;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05303899 int sxg_rcv_ring_size = SXG_RCV_RING_SIZE;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003900
3901 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "InitAdpt",
3902 adapter, 0, 0, 0);
3903
J.R. Maurob243c4a2008-10-20 19:28:58 -04003904 RssIds = 1; /* XXXTODO SXG_RSS_CPU_COUNT(adapter); */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003905 IsrCount = adapter->MsiEnabled ? RssIds : 1;
3906
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303907 /*
3908 * Sanity check SXG_UCODE_REGS structure definition to
3909 * make sure the length is correct
3910 */
Mithlesh Thukral942798b2009-01-05 21:14:34 +05303911 ASSERT(sizeof(struct sxg_ucode_regs) == SXG_REGISTER_SIZE_PER_CPU);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003912
J.R. Maurob243c4a2008-10-20 19:28:58 -04003913 /* Disable interrupts */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003914 SXG_DISABLE_ALL_INTERRUPTS(adapter);
3915
J.R. Maurob243c4a2008-10-20 19:28:58 -04003916 /* Set MTU */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003917 ASSERT((adapter->FrameSize == ETHERMAXFRAME) ||
3918 (adapter->FrameSize == JUMBOMAXFRAME));
3919 WRITE_REG(adapter->UcodeRegs[0].LinkMtu, adapter->FrameSize, TRUE);
3920
J.R. Maurob243c4a2008-10-20 19:28:58 -04003921 /* Set event ring base address and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003922 WRITE_REG64(adapter,
3923 adapter->UcodeRegs[0].EventBase, adapter->PEventRings, 0);
3924 WRITE_REG(adapter->UcodeRegs[0].EventSize, EVENT_RING_SIZE, TRUE);
3925
J.R. Maurob243c4a2008-10-20 19:28:58 -04003926 /* Per-ISR initialization */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003927 for (i = 0; i < IsrCount; i++) {
3928 u64 Addr;
J.R. Maurob243c4a2008-10-20 19:28:58 -04003929 /* Set interrupt status pointer */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003930 Addr = adapter->PIsr + (i * sizeof(u32));
3931 WRITE_REG64(adapter, adapter->UcodeRegs[i].Isp, Addr, i);
3932 }
3933
J.R. Maurob243c4a2008-10-20 19:28:58 -04003934 /* XMT ring zero index */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003935 WRITE_REG64(adapter,
3936 adapter->UcodeRegs[0].SPSendIndex,
3937 adapter->PXmtRingZeroIndex, 0);
3938
J.R. Maurob243c4a2008-10-20 19:28:58 -04003939 /* Per-RSS initialization */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003940 for (i = 0; i < RssIds; i++) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04003941 /* Release all event ring entries to the Microcode */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003942 WRITE_REG(adapter->UcodeRegs[i].EventRelease, EVENT_RING_SIZE,
3943 TRUE);
3944 }
3945
J.R. Maurob243c4a2008-10-20 19:28:58 -04003946 /* Transmit ring base and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003947 WRITE_REG64(adapter,
3948 adapter->UcodeRegs[0].XmtBase, adapter->PXmtRings, 0);
3949 WRITE_REG(adapter->UcodeRegs[0].XmtSize, SXG_XMT_RING_SIZE, TRUE);
3950
J.R. Maurob243c4a2008-10-20 19:28:58 -04003951 /* Receive ring base and size */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003952 WRITE_REG64(adapter,
3953 adapter->UcodeRegs[0].RcvBase, adapter->PRcvRings, 0);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05303954 if (adapter->JumboEnabled == TRUE)
3955 sxg_rcv_ring_size = SXG_JUMBO_RCV_RING_SIZE;
3956 WRITE_REG(adapter->UcodeRegs[0].RcvSize, sxg_rcv_ring_size, TRUE);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003957
J.R. Maurob243c4a2008-10-20 19:28:58 -04003958 /* Populate the card with receive buffers */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003959 sxg_stock_rcv_buffers(adapter);
3960
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303961 /*
3962 * Initialize checksum offload capabilities. At the moment we always
3963 * enable IP and TCP receive checksums on the card. Depending on the
3964 * checksum configuration specified by the user, we can choose to
3965 * report or ignore the checksum information provided by the card.
3966 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003967 WRITE_REG(adapter->UcodeRegs[0].ReceiveChecksum,
3968 SXG_RCV_TCP_CSUM_ENABLED | SXG_RCV_IP_CSUM_ENABLED, TRUE);
3969
J.R. Maurob243c4a2008-10-20 19:28:58 -04003970 /* Initialize the MAC, XAUI */
Harvey Harrisone88bd232008-10-17 14:46:10 -07003971 DBG_ERROR("sxg: %s ENTER sxg_initialize_link\n", __func__);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003972 status = sxg_initialize_link(adapter);
Harvey Harrisone88bd232008-10-17 14:46:10 -07003973 DBG_ERROR("sxg: %s EXIT sxg_initialize_link status[%x]\n", __func__,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003974 status);
3975 if (status != STATUS_SUCCESS) {
3976 return (status);
3977 }
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05303978 /*
3979 * Initialize Dead to FALSE.
3980 * SlicCheckForHang or SlicDumpThread will take it from here.
3981 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003982 adapter->Dead = FALSE;
3983 adapter->PingOutstanding = FALSE;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05303984 adapter->State = SXG_STATE_RUNNING;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07003985
3986 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XInit",
3987 adapter, 0, 0, 0);
3988 return (STATUS_SUCCESS);
3989}
3990
3991/*
3992 * sxg_fill_descriptor_block - Populate a descriptor block and give it to
3993 * the card. The caller should hold the RcvQLock
3994 *
3995 * Arguments -
3996 * adapter - A pointer to our adapter structure
3997 * RcvDescriptorBlockHdr - Descriptor block to fill
3998 *
3999 * Return
4000 * status
4001 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004002static int sxg_fill_descriptor_block(struct adapter_t *adapter,
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304003 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004004{
4005 u32 i;
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304006 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4007 struct sxg_rcv_data_buffer_hdr *RcvDataBufferHdr;
4008 struct sxg_rcv_descriptor_block *RcvDescriptorBlock;
4009 struct sxg_cmd *RingDescriptorCmd;
4010 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004011
4012 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "FilBlk",
4013 adapter, adapter->RcvBuffersOnCard,
4014 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4015
4016 ASSERT(RcvDescriptorBlockHdr);
4017
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304018 /*
4019 * If we don't have the resources to fill the descriptor block,
4020 * return failure
4021 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004022 if ((adapter->FreeRcvBufferCount < SXG_RCV_DESCRIPTORS_PER_BLOCK) ||
4023 SXG_RING_FULL(RcvRingInfo)) {
4024 adapter->Stats.NoMem++;
4025 return (STATUS_FAILURE);
4026 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004027 /* Get a ring descriptor command */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004028 SXG_GET_CMD(RingZero,
4029 RcvRingInfo, RingDescriptorCmd, RcvDescriptorBlockHdr);
4030 ASSERT(RingDescriptorCmd);
4031 RcvDescriptorBlockHdr->State = SXG_BUFFER_ONCARD;
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304032 RcvDescriptorBlock = (struct sxg_rcv_descriptor_block *)
4033 RcvDescriptorBlockHdr->VirtualAddress;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004034
J.R. Maurob243c4a2008-10-20 19:28:58 -04004035 /* Fill in the descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004036 for (i = 0; i < SXG_RCV_DESCRIPTORS_PER_BLOCK; i++) {
4037 SXG_GET_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
4038 ASSERT(RcvDataBufferHdr);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304039// ASSERT(RcvDataBufferHdr->SxgDumbRcvPacket);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304040 if (!RcvDataBufferHdr->SxgDumbRcvPacket) {
4041 SXG_ALLOCATE_RCV_PACKET(adapter, RcvDataBufferHdr,
4042 adapter->ReceiveBufferSize);
4043 if(RcvDataBufferHdr->skb)
4044 RcvDataBufferHdr->SxgDumbRcvPacket =
4045 RcvDataBufferHdr->skb;
4046 else
4047 goto no_memory;
4048 }
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004049 SXG_REINIATIALIZE_PACKET(RcvDataBufferHdr->SxgDumbRcvPacket);
4050 RcvDataBufferHdr->State = SXG_BUFFER_ONCARD;
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004051 RcvDescriptorBlock->Descriptors[i].VirtualAddress =
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304052 (void *)RcvDataBufferHdr;
Mithlesh Thukral1323e5f2009-01-05 21:13:23 +05304053
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004054 RcvDescriptorBlock->Descriptors[i].PhysicalAddress =
4055 RcvDataBufferHdr->PhysicalAddress;
4056 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004057 /* Add the descriptor block to receive descriptor ring 0 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004058 RingDescriptorCmd->Sgl = RcvDescriptorBlockHdr->PhysicalAddress;
4059
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304060 /*
4061 * RcvBuffersOnCard is not protected via the receive lock (see
4062 * sxg_process_event_queue) We don't want to grap a lock every time a
4063 * buffer is returned to us, so we use atomic interlocked functions
4064 * instead.
4065 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004066 adapter->RcvBuffersOnCard += SXG_RCV_DESCRIPTORS_PER_BLOCK;
4067
4068 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DscBlk",
4069 RcvDescriptorBlockHdr,
4070 RingDescriptorCmd, RcvRingInfo->Head, RcvRingInfo->Tail);
4071
4072 WRITE_REG(adapter->UcodeRegs[0].RcvCmd, 1, true);
4073 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlk",
4074 adapter, adapter->RcvBuffersOnCard,
4075 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4076 return (STATUS_SUCCESS);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304077no_memory:
4078 return (-ENOMEM);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004079}
4080
4081/*
4082 * sxg_stock_rcv_buffers - Stock the card with receive buffers
4083 *
4084 * Arguments -
4085 * adapter - A pointer to our adapter structure
4086 *
4087 * Return
4088 * None
4089 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004090static void sxg_stock_rcv_buffers(struct adapter_t *adapter)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004091{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304092 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304093 int sxg_rcv_data_buffers = SXG_RCV_DATA_BUFFERS;
4094 int sxg_min_rcv_data_buffers = SXG_MIN_RCV_DATA_BUFFERS;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004095
4096 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "StockBuf",
4097 adapter, adapter->RcvBuffersOnCard,
4098 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304099 /*
4100 * First, see if we've got less than our minimum threshold of
4101 * receive buffers, there isn't an allocation in progress, and
4102 * we haven't exceeded our maximum.. get another block of buffers
4103 * None of this needs to be SMP safe. It's round numbers.
4104 */
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304105 if (adapter->JumboEnabled == TRUE)
4106 sxg_min_rcv_data_buffers = SXG_MIN_JUMBO_RCV_DATA_BUFFERS;
4107 if ((adapter->FreeRcvBufferCount < sxg_min_rcv_data_buffers) &&
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004108 (adapter->AllRcvBlockCount < SXG_MAX_RCV_BLOCKS) &&
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304109 (atomic_read(&adapter->pending_allocations) == 0)) {
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004110 sxg_allocate_buffer_memory(adapter,
Mithlesh Thukrald0128aa2009-01-05 21:18:04 +05304111 SXG_RCV_BLOCK_SIZE
4112 (SXG_RCV_DATA_HDR_SIZE),
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004113 SXG_BUFFER_TYPE_RCV);
4114 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004115 /* Now grab the RcvQLock lock and proceed */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004116 spin_lock(&adapter->RcvQLock);
Mithlesh Thukral7c66b142009-02-06 19:30:40 +05304117 if (adapter->JumboEnabled)
4118 sxg_rcv_data_buffers = SXG_JUMBO_RCV_DATA_BUFFERS;
4119 while (adapter->RcvBuffersOnCard < sxg_rcv_data_buffers) {
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304120 struct list_entry *_ple;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004121
J.R. Maurob243c4a2008-10-20 19:28:58 -04004122 /* Get a descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004123 RcvDescriptorBlockHdr = NULL;
4124 if (adapter->FreeRcvBlockCount) {
4125 _ple = RemoveHeadList(&adapter->FreeRcvBlocks);
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004126 RcvDescriptorBlockHdr =
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304127 container_of(_ple, struct sxg_rcv_descriptor_block_hdr,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004128 FreeList);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004129 adapter->FreeRcvBlockCount--;
4130 RcvDescriptorBlockHdr->State = SXG_BUFFER_BUSY;
4131 }
4132
4133 if (RcvDescriptorBlockHdr == NULL) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04004134 /* Bail out.. */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004135 adapter->Stats.NoMem++;
4136 break;
4137 }
J.R. Maurob243c4a2008-10-20 19:28:58 -04004138 /* Fill in the descriptor block and give it to the card */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004139 if (sxg_fill_descriptor_block(adapter, RcvDescriptorBlockHdr) ==
4140 STATUS_FAILURE) {
J.R. Maurob243c4a2008-10-20 19:28:58 -04004141 /* Free the descriptor block */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004142 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4143 RcvDescriptorBlockHdr);
4144 break;
4145 }
4146 }
4147 spin_unlock(&adapter->RcvQLock);
4148 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XFilBlks",
4149 adapter, adapter->RcvBuffersOnCard,
4150 adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
4151}
4152
4153/*
4154 * sxg_complete_descriptor_blocks - Return descriptor blocks that have been
4155 * completed by the microcode
4156 *
4157 * Arguments -
4158 * adapter - A pointer to our adapter structure
4159 * Index - Where the microcode is up to
4160 *
4161 * Return
4162 * None
4163 */
J.R. Mauro73b07062008-10-28 18:42:02 -04004164static void sxg_complete_descriptor_blocks(struct adapter_t *adapter,
J.R. Mauro5c7514e2008-10-05 20:38:52 -04004165 unsigned char Index)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004166{
Mithlesh Thukral942798b2009-01-05 21:14:34 +05304167 struct sxg_rcv_ring *RingZero = &adapter->RcvRings[0];
4168 struct sxg_ring_info *RcvRingInfo = &adapter->RcvRingZeroInfo;
4169 struct sxg_rcv_descriptor_block_hdr *RcvDescriptorBlockHdr;
4170 struct sxg_cmd *RingDescriptorCmd;
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004171
4172 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlks",
4173 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4174
J.R. Maurob243c4a2008-10-20 19:28:58 -04004175 /* Now grab the RcvQLock lock and proceed */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004176 spin_lock(&adapter->RcvQLock);
4177 ASSERT(Index != RcvRingInfo->Tail);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304178 while (sxg_ring_get_forward_diff(RcvRingInfo, Index,
4179 RcvRingInfo->Tail) > 3) {
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304180 /*
4181 * Locate the current Cmd (ring descriptor entry), and
4182 * associated receive descriptor block, and advance
4183 * the tail
4184 */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004185 SXG_RETURN_CMD(RingZero,
4186 RcvRingInfo,
4187 RingDescriptorCmd, RcvDescriptorBlockHdr);
4188 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "CmpRBlk",
4189 RcvRingInfo->Head, RcvRingInfo->Tail,
4190 RingDescriptorCmd, RcvDescriptorBlockHdr);
4191
J.R. Maurob243c4a2008-10-20 19:28:58 -04004192 /* Clear the SGL field */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004193 RingDescriptorCmd->Sgl = 0;
Mithlesh Thukralddd6f0a2009-01-05 21:15:29 +05304194 /*
4195 * Attempt to refill it and hand it right back to the
4196 * card. If we fail to refill it, free the descriptor block
4197 * header. The card will be restocked later via the
4198 * RcvBuffersOnCard test
4199 */
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304200 if (sxg_fill_descriptor_block(adapter,
4201 RcvDescriptorBlockHdr) == STATUS_FAILURE)
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004202 SXG_FREE_RCV_DESCRIPTOR_BLOCK(adapter,
4203 RcvDescriptorBlockHdr);
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004204 }
4205 spin_unlock(&adapter->RcvQLock);
4206 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "XCRBlks",
4207 adapter, Index, RcvRingInfo->Head, RcvRingInfo->Tail);
4208}
4209
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304210/*
4211 * Read the statistics which the card has been maintaining.
4212 */
4213void sxg_collect_statistics(struct adapter_t *adapter)
4214{
4215 if(adapter->ucode_stats)
Mithlesh Thukral54aed112009-01-19 20:27:17 +05304216 WRITE_REG64(adapter, adapter->UcodeRegs[0].GetUcodeStats,
4217 adapter->pucode_stats, 0);
Mithlesh Thukral6a2946b2009-01-19 20:24:30 +05304218 adapter->stats.rx_fifo_errors = adapter->ucode_stats->ERDrops;
4219 adapter->stats.rx_over_errors = adapter->ucode_stats->NBDrops;
4220 adapter->stats.tx_fifo_errors = adapter->ucode_stats->XDrops;
4221}
4222
4223static struct net_device_stats *sxg_get_stats(struct net_device * dev)
4224{
4225 struct adapter_t *adapter = netdev_priv(dev);
4226
4227 sxg_collect_statistics(adapter);
4228 return (&adapter->stats);
Mithlesh Thukrald9d578b2009-01-19 20:23:22 +05304229}
4230
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004231static struct pci_driver sxg_driver = {
Mithlesh Thukral371d7a92009-01-19 20:22:34 +05304232 .name = sxg_driver_name,
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004233 .id_table = sxg_pci_tbl,
4234 .probe = sxg_entry_probe,
4235 .remove = sxg_entry_remove,
4236#if SXG_POWER_MANAGEMENT_ENABLED
4237 .suspend = sxgpm_suspend,
4238 .resume = sxgpm_resume,
4239#endif
Mithlesh Thukralcb636fe2009-01-05 21:16:56 +05304240 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
Greg Kroah-Hartman5db6b772008-08-21 14:04:55 -07004241};
4242
4243static int __init sxg_module_init(void)
4244{
4245 sxg_init_driver();
4246
4247 if (debug >= 0)
4248 sxg_debug = debug;
4249
4250 return pci_register_driver(&sxg_driver);
4251}
4252
4253static void __exit sxg_module_cleanup(void)
4254{
4255 pci_unregister_driver(&sxg_driver);
4256}
4257
4258module_init(sxg_module_init);
4259module_exit(sxg_module_cleanup);