Staging: slicoss: remove SLIC_GET_STATS_ENABLED
[linux-2.6] / drivers / staging / slicoss / slicoss.c
1 /**************************************************************************
2  *
3  * Copyright  2000-2006 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  * Alternatively, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") version 2 as published by the Free
18  * Software Foundation.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
21  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ALACRITECH, INC. OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * The views and conclusions contained in the software and documentation
34  * are those of the authors and should not be interpreted as representing
35  * official policies, either expressed or implied, of Alacritech, Inc.
36  *
37  **************************************************************************/
38
39 /*
40  * FILENAME: slicoss.c
41  *
42  * The SLICOSS driver for Alacritech's IS-NIC products.
43  *
44  * This driver is supposed to support:
45  *
46  *      Mojave cards (single port PCI Gigabit) both copper and fiber
47  *      Oasis cards (single and dual port PCI-x Gigabit) copper and fiber
48  *      Kalahari cards (dual and quad port PCI-e Gigabit) copper and fiber
49  *
50  * The driver was acutally tested on Oasis and Kalahari cards.
51  *
52  *
53  * NOTE: This is the standard, non-accelerated version of Alacritech's
54  *       IS-NIC driver.
55  */
56
57
58 #define KLUDGE_FOR_4GB_BOUNDARY         1
59 #define DEBUG_MICROCODE                 1
60 #define DBG                             1
61 #define SLIC_ASSERT_ENABLED                     1
62 #define SLIC_PING_TIMER_ENABLED             1
63 #define SLIC_POWER_MANAGEMENT_ENABLED   0
64 #define SLIC_INTERRUPT_PROCESS_LIMIT    1
65 #define LINUX_FREES_ADAPTER_RESOURCES   1
66 #define SLIC_OFFLOAD_IP_CHECKSUM                1
67 #define STATS_TIMER_INTERVAL                    2
68 #define PING_TIMER_INTERVAL                         1
69
70 #include <linux/kernel.h>
71 #include <linux/string.h>
72 #include <linux/errno.h>
73 #include <linux/ioport.h>
74 #include <linux/slab.h>
75 #include <linux/interrupt.h>
76 #include <linux/timer.h>
77 #include <linux/pci.h>
78 #include <linux/spinlock.h>
79 #include <linux/init.h>
80 #include <linux/bitops.h>
81 #include <linux/io.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/skbuff.h>
85 #include <linux/delay.h>
86 #include <linux/debugfs.h>
87 #include <linux/seq_file.h>
88 #include <linux/kthread.h>
89 #include <linux/module.h>
90 #include <linux/moduleparam.h>
91
92 #include <linux/firmware.h>
93 #include <linux/types.h>
94 #include <linux/dma-mapping.h>
95 #include <linux/mii.h>
96 #include <linux/if_vlan.h>
97 #include <asm/unaligned.h>
98
99 #include <linux/ethtool.h>
100 #define SLIC_ETHTOOL_SUPPORT     1
101
102 #include <linux/uaccess.h>
103 #include "slicdbg.h"
104 #include "slichw.h"
105 #include "slic.h"
106
107 static struct net_device_stats *slic_get_stats(struct net_device *dev);
108 static int slic_entry_open(struct net_device *dev);
109 static int slic_entry_halt(struct net_device *dev);
110 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
111 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev);
112 static void slic_xmit_fail(struct adapter *adapter, struct sk_buff *skb,
113                            void *cmd, u32 skbtype, u32 status);
114 static void slic_config_pci(struct pci_dev *pcidev);
115 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter);
116 static int slic_mac_set_address(struct net_device *dev, void *ptr);
117 static void slic_link_event_handler(struct adapter *adapter);
118 static void slic_upr_request_complete(struct adapter *adapter, u32 isr);
119 static int slic_rspqueue_init(struct adapter *adapter);
120 static int slic_rspqueue_reset(struct adapter *adapter);
121 static void slic_rspqueue_free(struct adapter *adapter);
122 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter);
123 static int slic_cmdq_init(struct adapter *adapter);
124 static void slic_cmdq_free(struct adapter *adapter);
125 static void slic_cmdq_reset(struct adapter *adapter);
126 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page);
127 static void slic_cmdq_getdone(struct adapter *adapter);
128 static void slic_cmdq_putdone_irq(struct adapter *adapter,
129                                   struct slic_hostcmd *cmd);
130 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter);
131 static int slic_rcvqueue_init(struct adapter *adapter);
132 static int slic_rcvqueue_reset(struct adapter *adapter);
133 static int slic_rcvqueue_fill(struct adapter *adapter);
134 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb);
135 static void slic_rcvqueue_free(struct adapter *adapter);
136 static void slic_adapter_set_hwaddr(struct adapter *adapter);
137 static int slic_card_init(struct sliccard *card, struct adapter *adapter);
138 static void slic_intagg_set(struct adapter *adapter, u32 value);
139 static int slic_card_download(struct adapter *adapter);
140 static u32 slic_card_locate(struct adapter *adapter);
141 static int slic_if_init(struct adapter *adapter);
142 static int slic_adapter_allocresources(struct adapter *adapter);
143 static void slic_adapter_freeresources(struct adapter *adapter);
144 static void slic_link_config(struct adapter *adapter, u32 linkspeed,
145                              u32 linkduplex);
146 static void slic_unmap_mmio_space(struct adapter *adapter);
147 static void slic_card_cleanup(struct sliccard *card);
148 static void slic_soft_reset(struct adapter *adapter);
149 static bool slic_mac_filter(struct adapter *adapter,
150                             struct ether_header *ether_frame);
151 static void slic_mac_address_config(struct adapter *adapter);
152 static void slic_mac_config(struct adapter *adapter);
153 static void slic_mcast_set_mask(struct adapter *adapter);
154 static void slic_config_set(struct adapter *adapter, bool linkchange);
155 static void slic_config_clear(struct adapter *adapter);
156 static void slic_config_get(struct adapter *adapter, u32 config,
157                             u32 configh);
158 static void slic_timer_load_check(ulong context);
159 static void slic_assert_fail(void);
160 static ushort slic_eeprom_cksum(char *m, int len);
161 static void slic_upr_start(struct adapter *adapter);
162 static void slic_link_upr_complete(struct adapter *adapter, u32 Isr);
163 static int  slic_upr_request(struct adapter *adapter, u32 upr_request,
164                              u32 upr_data, u32 upr_data_h, u32 upr_buffer,
165                              u32 upr_buffer_h);
166 static void slic_mcast_set_list(struct net_device *dev);
167
168
169 #define SLIC_POWER_MANAGEMENT  0
170
171 static uint slic_first_init = 1;
172 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
173                 "and Storage Accelerator (Non-Accelerated)\n";
174
175 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
176 static char *slic_product_name = "SLIC Technology(tm) Server "\
177                 "and Storage Accelerator (Non-Accelerated)";
178 static char *slic_vendor = "Alacritech, Inc.";
179
180 static int slic_debug = 1;
181 static int debug = -1;
182 static struct net_device *head_netdevice;
183
184 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
185 static int intagg_delay = 100;
186 static u32 dynamic_intagg;
187 static unsigned int rcv_count;
188 static struct dentry *slic_debugfs;
189
190 #define DRV_NAME          "slicoss"
191 #define DRV_VERSION       "2.0.1"
192 #define DRV_AUTHOR        "Alacritech, Inc. Engineering"
193 #define DRV_DESCRIPTION   "Alacritech SLIC Techonology(tm) "\
194                 "Non-Accelerated Driver"
195 #define DRV_COPYRIGHT     "Copyright  2000-2006 Alacritech, Inc. "\
196                 "All rights reserved."
197 #define PFX                DRV_NAME " "
198
199 MODULE_AUTHOR(DRV_AUTHOR);
200 MODULE_DESCRIPTION(DRV_DESCRIPTION);
201 MODULE_LICENSE("Dual BSD/GPL");
202
203 module_param(dynamic_intagg, int, 0);
204 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
205 module_param(intagg_delay, int, 0);
206 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
207
208 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
209         {PCI_VENDOR_ID_ALACRITECH,
210          SLIC_1GB_DEVICE_ID,
211          PCI_ANY_ID, PCI_ANY_ID,},
212         {PCI_VENDOR_ID_ALACRITECH,
213          SLIC_2GB_DEVICE_ID,
214          PCI_ANY_ID, PCI_ANY_ID,},
215         {0,}
216 };
217
218 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
219
220 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle)                   \
221 {                                                                       \
222     spin_lock_irqsave(&_adapter->handle_lock.lock,                      \
223                         _adapter->handle_lock.flags);                   \
224     _pslic_handle  =  _adapter->pfree_slic_handles;                     \
225     if (_pslic_handle) {                                                \
226         ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE);                \
227         _adapter->pfree_slic_handles = _pslic_handle->next;             \
228     }                                                                   \
229     spin_unlock_irqrestore(&_adapter->handle_lock.lock,                 \
230                         _adapter->handle_lock.flags);                   \
231 }
232
233 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle)                  \
234 {                                                                       \
235     _pslic_handle->type = SLIC_HANDLE_FREE;                             \
236     spin_lock_irqsave(&_adapter->handle_lock.lock,                      \
237                         _adapter->handle_lock.flags);                   \
238     _pslic_handle->next = _adapter->pfree_slic_handles;                 \
239     _adapter->pfree_slic_handles = _pslic_handle;                       \
240     spin_unlock_irqrestore(&_adapter->handle_lock.lock,                 \
241                         _adapter->handle_lock.flags);                   \
242 }
243
244 static void slic_debug_init(void);
245 static void slic_debug_cleanup(void);
246 static void slic_debug_adapter_create(struct adapter *adapter);
247 static void slic_debug_adapter_destroy(struct adapter *adapter);
248 static void slic_debug_card_create(struct sliccard *card);
249 static void slic_debug_card_destroy(struct sliccard *card);
250
251 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
252 {
253         writel(value, reg);
254         if (flush)
255                 mb();
256 }
257
258 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
259                                     u32 value, void __iomem *regh, u32 paddrh,
260                                     bool flush)
261 {
262         spin_lock_irqsave(&adapter->bit64reglock.lock,
263                                 adapter->bit64reglock.flags);
264         if (paddrh != adapter->curaddrupper) {
265                 adapter->curaddrupper = paddrh;
266                 writel(paddrh, regh);
267         }
268         writel(value, reg);
269         if (flush)
270                 mb();
271         spin_unlock_irqrestore(&adapter->bit64reglock.lock,
272                                 adapter->bit64reglock.flags);
273 }
274
275 static void slic_init_driver(void)
276 {
277         if (slic_first_init) {
278                 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
279                         __func__, jiffies);
280                 slic_first_init = 0;
281                 spin_lock_init(&slic_global.driver_lock.lock);
282                 slic_debug_init();
283         }
284 }
285
286 static void slic_dbg_macaddrs(struct adapter *adapter)
287 {
288         DBG_MSG("  (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
289                 adapter->netdev->name, adapter->currmacaddr[0],
290                 adapter->currmacaddr[1], adapter->currmacaddr[2],
291                 adapter->currmacaddr[3], adapter->currmacaddr[4],
292                 adapter->currmacaddr[5]);
293         DBG_MSG("  (%s) mac  %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
294                 adapter->netdev->name, adapter->macaddr[0],
295                 adapter->macaddr[1], adapter->macaddr[2],
296                 adapter->macaddr[3], adapter->macaddr[4], adapter->macaddr[5]);
297         return;
298 }
299
300 static void slic_init_adapter(struct net_device *netdev,
301                               struct pci_dev *pcidev,
302                               const struct pci_device_id *pci_tbl_entry,
303                               void __iomem *memaddr, int chip_idx)
304 {
305         ushort index;
306         struct slic_handle *pslic_handle;
307         struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
308 /*
309     DBG_MSG("slicoss: %s (%s)\n    netdev [%p]\n    adapter[%p]\n    "
310             "pcidev [%p]\n", __func__, netdev->name, netdev, adapter, pcidev);*/
311 /*      adapter->pcidev = pcidev;*/
312         adapter->vendid = pci_tbl_entry->vendor;
313         adapter->devid = pci_tbl_entry->device;
314         adapter->subsysid = pci_tbl_entry->subdevice;
315         adapter->busnumber = pcidev->bus->number;
316         adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
317         adapter->functionnumber = (pcidev->devfn & 0x7);
318         adapter->memorylength = pci_resource_len(pcidev, 0);
319         adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
320         adapter->irq = pcidev->irq;
321 /*      adapter->netdev = netdev;*/
322         adapter->next_netdevice = head_netdevice;
323         head_netdevice = netdev;
324         adapter->chipid = chip_idx;
325         adapter->port = 0;      /*adapter->functionnumber;*/
326         adapter->cardindex = adapter->port;
327         adapter->memorybase = memaddr;
328         spin_lock_init(&adapter->upr_lock.lock);
329         spin_lock_init(&adapter->bit64reglock.lock);
330         spin_lock_init(&adapter->adapter_lock.lock);
331         spin_lock_init(&adapter->reset_lock.lock);
332         spin_lock_init(&adapter->handle_lock.lock);
333
334         adapter->card_size = 1;
335         /*
336           Initialize slic_handle array
337         */
338         ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
339         /*
340          Start with 1.  0 is an invalid host handle.
341         */
342         for (index = 1, pslic_handle = &adapter->slic_handles[1];
343              index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
344
345                 pslic_handle->token.handle_index = index;
346                 pslic_handle->type = SLIC_HANDLE_FREE;
347                 pslic_handle->next = adapter->pfree_slic_handles;
348                 adapter->pfree_slic_handles = pslic_handle;
349         }
350 /*
351     DBG_MSG(".........\nix[%d] phandle[%p] pfree[%p] next[%p]\n",
352         index, pslic_handle, adapter->pfree_slic_handles, pslic_handle->next);*/
353         adapter->pshmem = (struct slic_shmem *)
354                                         pci_alloc_consistent(adapter->pcidev,
355                                         sizeof(struct slic_shmem),
356                                         &adapter->
357                                         phys_shmem);
358 /*
359       DBG_MSG("slicoss: %s (%s)\n   pshmem    [%p]\n   phys_shmem[%p]\n"\
360                 "slic_regs [%p]\n", __func__, netdev->name, adapter->pshmem,
361                 (void *)adapter->phys_shmem, adapter->slic_regs);
362 */
363         ASSERT(adapter->pshmem);
364
365         memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
366
367         return;
368 }
369
370 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
371                                const struct pci_device_id *pci_tbl_entry)
372 {
373         static int cards_found;
374         static int did_version;
375         int err = -ENODEV;
376         struct net_device *netdev;
377         struct adapter *adapter;
378         void __iomem *memmapped_ioaddr = NULL;
379         u32 status = 0;
380         ulong mmio_start = 0;
381         ulong mmio_len = 0;
382         struct sliccard *card = NULL;
383
384         DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
385                 __func__, jiffies, smp_processor_id());
386
387         slic_global.dynamic_intagg = dynamic_intagg;
388
389         err = pci_enable_device(pcidev);
390
391         DBG_MSG("Call pci_enable_device(%p)  status[%x]\n", pcidev, err);
392         if (err)
393                 return err;
394
395         if (slic_debug > 0 && did_version++ == 0) {
396                 printk(slic_banner);
397                 printk(slic_proc_version);
398         }
399
400         err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
401         if (!err) {
402                 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
403         } else {
404                 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
405                 if (err) {
406                         DBG_MSG
407                             ("No usable DMA configuration, aborting  err[%x]\n",
408                              err);
409                         goto err_out_disable_pci;
410                 }
411                 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
412         }
413
414         DBG_MSG("Call pci_request_regions\n");
415
416         err = pci_request_regions(pcidev, DRV_NAME);
417         if (err) {
418                 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
419                 goto err_out_disable_pci;
420         }
421
422         DBG_MSG("call pci_set_master\n");
423         pci_set_master(pcidev);
424
425         DBG_MSG("call alloc_etherdev\n");
426         netdev = alloc_etherdev(sizeof(struct adapter));
427         if (!netdev) {
428                 err = -ENOMEM;
429                 goto err_out_exit_slic_probe;
430         }
431         DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
432
433         SET_NETDEV_DEV(netdev, &pcidev->dev);
434
435         pci_set_drvdata(pcidev, netdev);
436         adapter = netdev_priv(netdev);
437         adapter->netdev = netdev;
438         adapter->pcidev = pcidev;
439
440         mmio_start = pci_resource_start(pcidev, 0);
441         mmio_len = pci_resource_len(pcidev, 0);
442
443         DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
444                 mmio_start, mmio_len);
445
446 /*  memmapped_ioaddr =  (u32)ioremap_nocache(mmio_start, mmio_len);*/
447         memmapped_ioaddr = ioremap(mmio_start, mmio_len);
448         DBG_MSG("slicoss: %s MEMMAPPED_IOADDR [%p]\n", __func__,
449                 memmapped_ioaddr);
450         if (!memmapped_ioaddr) {
451                 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
452                           __func__, mmio_len, mmio_start);
453                 goto err_out_free_netdev;
454         }
455
456         DBG_MSG
457             ("slicoss: %s found Alacritech SLICOSS PCI, MMIO at %p, "\
458             "start[%lx] len[%lx], IRQ %d.\n",
459              __func__, memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
460
461         slic_config_pci(pcidev);
462
463         slic_init_driver();
464
465         slic_init_adapter(netdev,
466                           pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
467
468         status = slic_card_locate(adapter);
469         if (status) {
470                 DBG_ERROR("%s cannot locate card\n", __func__);
471                 goto err_out_free_mmio_region;
472         }
473
474         card = adapter->card;
475
476         if (!adapter->allocated) {
477                 card->adapters_allocated++;
478                 adapter->allocated = 1;
479         }
480
481         DBG_MSG("slicoss: %s    card:             %p\n", __func__,
482                 adapter->card);
483         DBG_MSG("slicoss: %s    card->adapter[%d] == [%p]\n", __func__,
484                 (uint) adapter->port, adapter);
485         DBG_MSG("slicoss: %s    card->adapters_allocated [%d]\n", __func__,
486                 card->adapters_allocated);
487         DBG_MSG("slicoss: %s    card->adapters_activated [%d]\n", __func__,
488                 card->adapters_activated);
489
490         status = slic_card_init(card, adapter);
491
492         if (status != STATUS_SUCCESS) {
493                 card->state = CARD_FAIL;
494                 adapter->state = ADAPT_FAIL;
495                 adapter->linkstate = LINK_DOWN;
496                 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
497         } else {
498                 slic_adapter_set_hwaddr(adapter);
499         }
500
501         netdev->base_addr = (unsigned long)adapter->memorybase;
502         netdev->irq = adapter->irq;
503         netdev->open = slic_entry_open;
504         netdev->stop = slic_entry_halt;
505         netdev->hard_start_xmit = slic_xmit_start;
506         netdev->do_ioctl = slic_ioctl;
507         netdev->set_mac_address = slic_mac_set_address;
508         netdev->get_stats = slic_get_stats;
509         netdev->set_multicast_list = slic_mcast_set_list;
510
511         slic_debug_adapter_create(adapter);
512
513         strcpy(netdev->name, "eth%d");
514         err = register_netdev(netdev);
515         if (err) {
516                 DBG_ERROR("Cannot register net device, aborting.\n");
517                 goto err_out_unmap;
518         }
519
520         DBG_MSG
521             ("slicoss: addr 0x%lx, irq %d, MAC addr "\
522              "%02X:%02X:%02X:%02X:%02X:%02X\n",
523              mmio_start, /*pci_resource_start(pcidev, 0), */ pcidev->irq,
524              netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
525              netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
526
527         cards_found++;
528         DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
529                 __func__, status, jiffies, smp_processor_id());
530
531         return status;
532
533 err_out_unmap:
534         iounmap(memmapped_ioaddr);
535 err_out_free_mmio_region:
536         release_mem_region(mmio_start, mmio_len);
537 err_out_free_netdev:
538         free_netdev(netdev);
539 err_out_exit_slic_probe:
540         pci_release_regions(pcidev);
541         DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
542                   smp_processor_id());
543 err_out_disable_pci:
544         pci_disable_device(pcidev);
545         return err;
546 }
547
548 static int slic_entry_open(struct net_device *dev)
549 {
550         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
551         struct sliccard *card = adapter->card;
552         u32 locked = 0;
553         int status;
554
555         ASSERT(adapter);
556         ASSERT(card);
557         DBG_MSG
558             ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
559              "allocd[%x]\n", __func__, adapter->activated,
560              card->adapters_activated,
561              card->adapters_allocated);
562         DBG_MSG
563             ("slicoss: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] "\
564              "port[%d] card[%p]\n",
565              __func__, adapter->netdev->name, jiffies, smp_processor_id(),
566              adapter->netdev, adapter, adapter->port, card);
567
568         netif_stop_queue(adapter->netdev);
569
570         spin_lock_irqsave(&slic_global.driver_lock.lock,
571                                 slic_global.driver_lock.flags);
572         locked = 1;
573         if (!adapter->activated) {
574                 card->adapters_activated++;
575                 slic_global.num_slic_ports_active++;
576                 adapter->activated = 1;
577         }
578         status = slic_if_init(adapter);
579
580         if (status != STATUS_SUCCESS) {
581                 if (adapter->activated) {
582                         card->adapters_activated--;
583                         slic_global.num_slic_ports_active--;
584                         adapter->activated = 0;
585                 }
586                 if (locked) {
587                         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
588                                                 slic_global.driver_lock.flags);
589                         locked = 0;
590                 }
591                 return status;
592         }
593         DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
594                 card->master, adapter);
595         if (!card->master)
596                 card->master = adapter;
597
598         if (locked) {
599                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
600                                         slic_global.driver_lock.flags);
601                 locked = 0;
602         }
603
604         return STATUS_SUCCESS;
605 }
606
607 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
608 {
609         struct net_device *dev = pci_get_drvdata(pcidev);
610         u32 mmio_start = 0;
611         uint mmio_len = 0;
612         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
613         struct sliccard *card;
614         struct mcast_address *mcaddr, *mlist;
615
616         ASSERT(adapter);
617         DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
618                 adapter);
619         slic_adapter_freeresources(adapter);
620         slic_unmap_mmio_space(adapter);
621         DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
622         unregister_netdev(dev);
623
624         mmio_start = pci_resource_start(pcidev, 0);
625         mmio_len = pci_resource_len(pcidev, 0);
626
627         DBG_MSG("slicoss: %s rel_region(0) start[%x] len[%x]\n", __func__,
628                 mmio_start, mmio_len);
629         release_mem_region(mmio_start, mmio_len);
630
631         DBG_MSG("slicoss: %s iounmap dev->base_addr[%x]\n", __func__,
632                 (uint) dev->base_addr);
633         iounmap((void __iomem *)dev->base_addr);
634         /* free multicast addresses */
635         mlist = adapter->mcastaddrs;
636         while (mlist) {
637                 mcaddr = mlist;
638                 mlist = mlist->next;
639                 kfree(mcaddr);
640         }
641         ASSERT(adapter->card);
642         card = adapter->card;
643         ASSERT(card->adapters_allocated);
644         card->adapters_allocated--;
645         adapter->allocated = 0;
646         DBG_MSG
647             ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
648              __func__, card->adapters_activated, card->adapters_allocated,
649              card, adapter);
650         if (!card->adapters_allocated) {
651                 struct sliccard *curr_card = slic_global.slic_card;
652                 if (curr_card == card) {
653                         slic_global.slic_card = card->next;
654                 } else {
655                         while (curr_card->next != card)
656                                 curr_card = curr_card->next;
657                         ASSERT(curr_card);
658                         curr_card->next = card->next;
659                 }
660                 ASSERT(slic_global.num_slic_cards);
661                 slic_global.num_slic_cards--;
662                 slic_card_cleanup(card);
663         }
664         DBG_MSG("slicoss: %s deallocate device\n", __func__);
665         kfree(dev);
666         pci_release_regions(pcidev);
667         DBG_MSG("slicoss: %s EXIT\n", __func__);
668 }
669
670 static int slic_entry_halt(struct net_device *dev)
671 {
672         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
673         struct sliccard *card = adapter->card;
674         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
675
676         spin_lock_irqsave(&slic_global.driver_lock.lock,
677                                 slic_global.driver_lock.flags);
678         ASSERT(card);
679         DBG_MSG("slicoss: %s (%s) ENTER\n", __func__, dev->name);
680         DBG_MSG("slicoss: %s (%s) actvtd[%d] alloc[%d] state[%x] adapt[%p]\n",
681                 __func__, dev->name, card->adapters_activated,
682                 card->adapters_allocated, card->state, adapter);
683         netif_stop_queue(adapter->netdev);
684         adapter->state = ADAPT_DOWN;
685         adapter->linkstate = LINK_DOWN;
686         adapter->upr_list = NULL;
687         adapter->upr_busy = 0;
688         adapter->devflags_prev = 0;
689         DBG_MSG("slicoss: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
690                 __func__, dev->name, adapter, adapter->state);
691         ASSERT(card->adapter[adapter->cardindex] == adapter);
692         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
693         adapter->all_reg_writes++;
694         adapter->icr_reg_writes++;
695         slic_config_clear(adapter);
696         DBG_MSG("slicoss: %s (%s) dev[%p] adapt[%p] card[%p]\n",
697                 __func__, dev->name, dev, adapter, card);
698         if (adapter->activated) {
699                 card->adapters_activated--;
700                 slic_global.num_slic_ports_active--;
701                 adapter->activated = 0;
702         }
703 #ifdef AUTOMATIC_RESET
704         slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
705 #endif
706         /*
707          *  Reset the adapter's rsp, cmd, and rcv queues
708          */
709         slic_cmdq_reset(adapter);
710         slic_rspqueue_reset(adapter);
711         slic_rcvqueue_reset(adapter);
712
713 #ifdef AUTOMATIC_RESET
714         if (!card->adapters_activated) {
715                 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
716                         dev->name);
717
718                 slic_card_init(card, adapter);
719         }
720 #endif
721
722         DBG_MSG("slicoss: %s (%s) EXIT\n", __func__, dev->name);
723         DBG_MSG("slicoss: %s EXIT\n", __func__);
724         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
725                                 slic_global.driver_lock.flags);
726         return STATUS_SUCCESS;
727 }
728
729 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
730 {
731         ASSERT(rq);
732 /*
733       DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
734 */
735         switch (cmd) {
736         case SIOCSLICSETINTAGG:
737                 {
738                         struct adapter *adapter = (struct adapter *)
739                                                         netdev_priv(dev);
740                         u32 data[7];
741                         u32 intagg;
742
743                         if (copy_from_user(data, rq->ifr_data, 28)) {
744                                 DBG_ERROR
745                                     ("copy_from_user FAILED getting initial \
746                                      params\n");
747                                 return -EFAULT;
748                         }
749                         intagg = data[0];
750                         printk(KERN_EMERG
751                                "%s: set interrupt aggregation to %d\n",
752                                __func__, intagg);
753                         slic_intagg_set(adapter, intagg);
754                         return 0;
755                 }
756
757 #ifdef SLIC_TRACE_DUMP_ENABLED
758         case SIOCSLICTRACEDUMP:
759                 {
760                         ulong data[7];
761                         ulong value;
762
763                         DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
764
765                         if (copy_from_user(data, rq->ifr_data, 28)) {
766                                 PRINT_ERROR
767                                     ("slic: copy_from_user FAILED getting \
768                                      initial simba param\n");
769                                 return -EFAULT;
770                         }
771
772                         value = data[0];
773                         if (tracemon_request == SLIC_DUMP_DONE) {
774                                 PRINT_ERROR
775                                     ("ATK Diagnostic Trace Dump Requested\n");
776                                 tracemon_request = SLIC_DUMP_REQUESTED;
777                                 tracemon_request_type = value;
778                                 tracemon_timestamp = jiffies;
779                         } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
780                                    (tracemon_request ==
781                                     SLIC_DUMP_IN_PROGRESS)) {
782                                 PRINT_ERROR
783                                     ("ATK Diagnostic Trace Dump Requested but \
784                                      already in progress... ignore\n");
785                         } else {
786                                 PRINT_ERROR
787                                     ("ATK Diagnostic Trace Dump Requested\n");
788                                 tracemon_request = SLIC_DUMP_REQUESTED;
789                                 tracemon_request_type = value;
790                                 tracemon_timestamp = jiffies;
791                         }
792                         return 0;
793                 }
794 #endif
795 #if SLIC_ETHTOOL_SUPPORT
796         case SIOCETHTOOL:
797                 {
798                         struct adapter *adapter = (struct adapter *)
799                                                         netdev_priv(dev);
800                         struct ethtool_cmd data;
801                         struct ethtool_cmd ecmd;
802
803                         ASSERT(adapter);
804 /*                      DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
805                         if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
806                                 return -EFAULT;
807
808                         if (ecmd.cmd == ETHTOOL_GSET) {
809                                 data.supported =
810                                     (SUPPORTED_10baseT_Half |
811                                      SUPPORTED_10baseT_Full |
812                                      SUPPORTED_100baseT_Half |
813                                      SUPPORTED_100baseT_Full |
814                                      SUPPORTED_Autoneg | SUPPORTED_MII);
815                                 data.port = PORT_MII;
816                                 data.transceiver = XCVR_INTERNAL;
817                                 data.phy_address = 0;
818                                 if (adapter->linkspeed == LINK_100MB)
819                                         data.speed = SPEED_100;
820                                 else if (adapter->linkspeed == LINK_10MB)
821                                         data.speed = SPEED_10;
822                                 else
823                                         data.speed = 0;
824
825                                 if (adapter->linkduplex == LINK_FULLD)
826                                         data.duplex = DUPLEX_FULL;
827                                 else
828                                         data.duplex = DUPLEX_HALF;
829
830                                 data.autoneg = AUTONEG_ENABLE;
831                                 data.maxtxpkt = 1;
832                                 data.maxrxpkt = 1;
833                                 if (copy_to_user
834                                     (rq->ifr_data, &data, sizeof(data)))
835                                         return -EFAULT;
836
837                         } else if (ecmd.cmd == ETHTOOL_SSET) {
838                                 if (!capable(CAP_NET_ADMIN))
839                                         return -EPERM;
840
841                                 if (adapter->linkspeed == LINK_100MB)
842                                         data.speed = SPEED_100;
843                                 else if (adapter->linkspeed == LINK_10MB)
844                                         data.speed = SPEED_10;
845                                 else
846                                         data.speed = 0;
847
848                                 if (adapter->linkduplex == LINK_FULLD)
849                                         data.duplex = DUPLEX_FULL;
850                                 else
851                                         data.duplex = DUPLEX_HALF;
852
853                                 data.autoneg = AUTONEG_ENABLE;
854                                 data.maxtxpkt = 1;
855                                 data.maxrxpkt = 1;
856                                 if ((ecmd.speed != data.speed) ||
857                                     (ecmd.duplex != data.duplex)) {
858                                         u32 speed;
859                                         u32 duplex;
860
861                                         if (ecmd.speed == SPEED_10) {
862                                                 speed = 0;
863                                                 SLIC_DISPLAY
864                                                     ("%s: slic ETHTOOL set \
865                                                      link speed==10MB",
866                                                      dev->name);
867                                         } else {
868                                                 speed = PCR_SPEED_100;
869                                                 SLIC_DISPLAY
870                                                     ("%s: slic ETHTOOL set \
871                                                     link speed==100MB",
872                                                      dev->name);
873                                         }
874                                         if (ecmd.duplex == DUPLEX_FULL) {
875                                                 duplex = PCR_DUPLEX_FULL;
876                                                 SLIC_DISPLAY
877                                                     (": duplex==FULL\n");
878                                         } else {
879                                                 duplex = 0;
880                                                 SLIC_DISPLAY
881                                                     (": duplex==HALF\n");
882                                         }
883                                         slic_link_config(adapter,
884                                                          speed, duplex);
885                                         slic_link_event_handler(adapter);
886                                 }
887                         }
888                         return 0;
889                 }
890 #endif
891         default:
892 /*              DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
893                 return -EOPNOTSUPP;
894         }
895 }
896
897 #define  XMIT_FAIL_LINK_STATE               1
898 #define  XMIT_FAIL_ZERO_LENGTH              2
899 #define  XMIT_FAIL_HOSTCMD_FAIL             3
900
901 static void slic_xmit_build_request(struct adapter *adapter,
902                              struct slic_hostcmd *hcmd, struct sk_buff *skb)
903 {
904         struct slic_host64_cmd *ihcmd;
905         ulong phys_addr;
906
907         ihcmd = &hcmd->cmd64;
908
909         ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
910         ihcmd->command = IHCMD_XMT_REQ;
911         ihcmd->u.slic_buffers.totlen = skb->len;
912         phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
913                         PCI_DMA_TODEVICE);
914         ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
915         ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
916         ihcmd->u.slic_buffers.bufs[0].length = skb->len;
917 #if defined(CONFIG_X86_64)
918         hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
919                                      (u64) hcmd) + 31) >> 5);
920 #elif defined(CONFIG_X86)
921         hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
922                            (u32) hcmd) + 31) >> 5);
923 #else
924         Stop Compilation;
925 #endif
926 }
927
928 #define NORMAL_ETHFRAME     0
929
930 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
931 {
932         struct sliccard *card;
933         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
934         struct slic_hostcmd *hcmd = NULL;
935         u32 status = 0;
936         u32 skbtype = NORMAL_ETHFRAME;
937         void *offloadcmd = NULL;
938
939         card = adapter->card;
940         ASSERT(card);
941 /*
942     DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
943         adapter->netdev->name, skb, skb->len, adapter->linkstate,
944          adapter->state);
945 */
946         if ((adapter->linkstate != LINK_UP) ||
947             (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
948                 status = XMIT_FAIL_LINK_STATE;
949                 goto xmit_fail;
950
951         } else if (skb->len == 0) {
952                 status = XMIT_FAIL_ZERO_LENGTH;
953                 goto xmit_fail;
954         }
955
956         if (skbtype == NORMAL_ETHFRAME) {
957                 hcmd = slic_cmdq_getfree(adapter);
958                 if (!hcmd) {
959                         adapter->xmitq_full = 1;
960                         status = XMIT_FAIL_HOSTCMD_FAIL;
961                         goto xmit_fail;
962                 }
963                 ASSERT(hcmd->pslic_handle);
964                 ASSERT(hcmd->cmd64.hosthandle ==
965                        hcmd->pslic_handle->token.handle_token);
966                 hcmd->skb = skb;
967                 hcmd->busy = 1;
968                 hcmd->type = SLIC_CMD_DUMB;
969                 if (skbtype == NORMAL_ETHFRAME)
970                         slic_xmit_build_request(adapter, hcmd, skb);
971         }
972         adapter->stats.tx_packets++;
973         adapter->stats.tx_bytes += skb->len;
974
975 #ifdef DEBUG_DUMP
976         if (adapter->kill_card) {
977                 struct slic_host64_cmd ihcmd;
978
979                 ihcmd = &hcmd->cmd64;
980
981                 ihcmd->flags |= 0x40;
982                 adapter->kill_card = 0; /* only do this once */
983         }
984 #endif
985         if (hcmd->paddrh == 0) {
986                 slic_reg32_write(&adapter->slic_regs->slic_cbar,
987                                  (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
988         } else {
989                 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
990                                  (hcmd->paddrl | hcmd->cmdsize),
991                                  &adapter->slic_regs->slic_addr_upper,
992                                  hcmd->paddrh, DONT_FLUSH);
993         }
994 xmit_done:
995         return 0;
996 xmit_fail:
997         slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
998         goto xmit_done;
999 }
1000
1001 static void slic_xmit_fail(struct adapter *adapter,
1002                     struct sk_buff *skb,
1003                     void *cmd, u32 skbtype, u32 status)
1004 {
1005         if (adapter->xmitq_full)
1006                 netif_stop_queue(adapter->netdev);
1007         if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1008                 switch (status) {
1009                 case XMIT_FAIL_LINK_STATE:
1010                         DBG_ERROR
1011                             ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
1012                              adapter[%s:%d] card[%s:%d]\n",
1013                              adapter->netdev->name, skb, skb->pkt_type,
1014                              SLIC_LINKSTATE(adapter->linkstate),
1015                              SLIC_ADAPTER_STATE(adapter->state), adapter->state,
1016                              SLIC_CARD_STATE(adapter->card->state),
1017                              adapter->card->state);
1018                         break;
1019                 case XMIT_FAIL_ZERO_LENGTH:
1020                         DBG_ERROR
1021                             ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1022                              skb, skb->pkt_type);
1023                         break;
1024                 case XMIT_FAIL_HOSTCMD_FAIL:
1025                         DBG_ERROR
1026                             ("xmit_start skb[%p] type[%x] No host commands \
1027                              available !!!! \n",
1028                              skb, skb->pkt_type);
1029                         break;
1030                 default:
1031                         ASSERT(0);
1032                 }
1033         }
1034         dev_kfree_skb(skb);
1035         adapter->stats.tx_dropped++;
1036 }
1037
1038 static void slic_rcv_handle_error(struct adapter *adapter,
1039                                         struct slic_rcvbuf *rcvbuf)
1040 {
1041         struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1042
1043         if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1044                 if (hdr->frame_status14 & VRHSTAT_802OE)
1045                         adapter->if_events.oflow802++;
1046                 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1047                         adapter->if_events.Tprtoflow++;
1048                 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1049                         adapter->if_events.uflow802++;
1050                 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1051                         adapter->if_events.rcvearly++;
1052                         adapter->stats.rx_fifo_errors++;
1053                 }
1054                 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1055                         adapter->if_events.Bufov++;
1056                         adapter->stats.rx_over_errors++;
1057                 }
1058                 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1059                         adapter->if_events.Carre++;
1060                         adapter->stats.tx_carrier_errors++;
1061                 }
1062                 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1063                         adapter->if_events.Longe++;
1064                 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1065                         adapter->if_events.Invp++;
1066                 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1067                         adapter->if_events.Crc++;
1068                         adapter->stats.rx_crc_errors++;
1069                 }
1070                 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1071                         adapter->if_events.Drbl++;
1072                 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1073                         adapter->if_events.Code++;
1074                 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1075                         adapter->if_events.TpCsum++;
1076                 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1077                         adapter->if_events.TpHlen++;
1078                 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1079                         adapter->if_events.IpCsum++;
1080                 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1081                         adapter->if_events.IpLen++;
1082                 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1083                         adapter->if_events.IpHlen++;
1084         } else {
1085                 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1086                         u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1087
1088                         if (xerr == VGBSTAT_XCSERR)
1089                                 adapter->if_events.TpCsum++;
1090                         if (xerr == VGBSTAT_XUFLOW)
1091                                 adapter->if_events.Tprtoflow++;
1092                         if (xerr == VGBSTAT_XHLEN)
1093                                 adapter->if_events.TpHlen++;
1094                 }
1095                 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1096                         u32 nerr =
1097                             (hdr->
1098                              frame_statusGB >> VGBSTAT_NERRSHFT) &
1099                             VGBSTAT_NERRMSK;
1100                         if (nerr == VGBSTAT_NCSERR)
1101                                 adapter->if_events.IpCsum++;
1102                         if (nerr == VGBSTAT_NUFLOW)
1103                                 adapter->if_events.IpLen++;
1104                         if (nerr == VGBSTAT_NHLEN)
1105                                 adapter->if_events.IpHlen++;
1106                 }
1107                 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1108                         u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1109
1110                         if (lerr == VGBSTAT_LDEARLY)
1111                                 adapter->if_events.rcvearly++;
1112                         if (lerr == VGBSTAT_LBOFLO)
1113                                 adapter->if_events.Bufov++;
1114                         if (lerr == VGBSTAT_LCODERR)
1115                                 adapter->if_events.Code++;
1116                         if (lerr == VGBSTAT_LDBLNBL)
1117                                 adapter->if_events.Drbl++;
1118                         if (lerr == VGBSTAT_LCRCERR)
1119                                 adapter->if_events.Crc++;
1120                         if (lerr == VGBSTAT_LOFLO)
1121                                 adapter->if_events.oflow802++;
1122                         if (lerr == VGBSTAT_LUFLO)
1123                                 adapter->if_events.uflow802++;
1124                 }
1125         }
1126         return;
1127 }
1128
1129 #define TCP_OFFLOAD_FRAME_PUSHFLAG  0x10000000
1130 #define M_FAST_PATH                 0x0040
1131
1132 static void slic_rcv_handler(struct adapter *adapter)
1133 {
1134         struct sk_buff *skb;
1135         struct slic_rcvbuf *rcvbuf;
1136         u32 frames = 0;
1137
1138         while ((skb = slic_rcvqueue_getnext(adapter))) {
1139                 u32 rx_bytes;
1140
1141                 ASSERT(skb->head);
1142                 rcvbuf = (struct slic_rcvbuf *)skb->head;
1143                 adapter->card->events++;
1144                 if (rcvbuf->status & IRHDDR_ERR) {
1145                         adapter->rx_errors++;
1146                         slic_rcv_handle_error(adapter, rcvbuf);
1147                         slic_rcvqueue_reinsert(adapter, skb);
1148                         continue;
1149                 }
1150
1151                 if (!slic_mac_filter(adapter, (struct ether_header *)
1152                                         rcvbuf->data)) {
1153 #if 0
1154                         DBG_MSG
1155                             ("slicoss: %s (%s) drop frame due to mac filter\n",
1156                              __func__, adapter->netdev->name);
1157 #endif
1158                         slic_rcvqueue_reinsert(adapter, skb);
1159                         continue;
1160                 }
1161                 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1162                 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1163                 skb_put(skb, rx_bytes);
1164                 adapter->stats.rx_packets++;
1165                 adapter->stats.rx_bytes += rx_bytes;
1166 #if SLIC_OFFLOAD_IP_CHECKSUM
1167                 skb->ip_summed = CHECKSUM_UNNECESSARY;
1168 #endif
1169
1170                 skb->dev = adapter->netdev;
1171                 skb->protocol = eth_type_trans(skb, skb->dev);
1172                 netif_rx(skb);
1173
1174                 ++frames;
1175 #if SLIC_INTERRUPT_PROCESS_LIMIT
1176                 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1177                         adapter->rcv_interrupt_yields++;
1178                         break;
1179                 }
1180 #endif
1181         }
1182         adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1183 }
1184
1185 static void slic_xmit_complete(struct adapter *adapter)
1186 {
1187         struct slic_hostcmd *hcmd;
1188         struct slic_rspbuf *rspbuf;
1189         u32 frames = 0;
1190         struct slic_handle_word slic_handle_word;
1191
1192         do {
1193                 rspbuf = slic_rspqueue_getnext(adapter);
1194                 if (!rspbuf)
1195                         break;
1196                 adapter->xmit_completes++;
1197                 adapter->card->events++;
1198                 /*
1199                  Get the complete host command buffer
1200                 */
1201                 slic_handle_word.handle_token = rspbuf->hosthandle;
1202                 ASSERT(slic_handle_word.handle_index);
1203                 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1204                 hcmd =
1205                     (struct slic_hostcmd *)
1206                         adapter->slic_handles[slic_handle_word.handle_index].
1207                                                                         address;
1208 /*      hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1209                 ASSERT(hcmd);
1210                 ASSERT(hcmd->pslic_handle ==
1211                        &adapter->slic_handles[slic_handle_word.handle_index]);
1212 /*
1213       DBG_ERROR("xmit_complete (%s)   hcmd[%p]  hosthandle[%x]\n",
1214                 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1215       DBG_ERROR("    skb[%p] len %d  hcmdtype[%x]\n", hcmd->skb,
1216                 hcmd->skb->len, hcmd->type);
1217 */
1218                 if (hcmd->type == SLIC_CMD_DUMB) {
1219                         if (hcmd->skb)
1220                                 dev_kfree_skb_irq(hcmd->skb);
1221                         slic_cmdq_putdone_irq(adapter, hcmd);
1222                 }
1223                 rspbuf->status = 0;
1224                 rspbuf->hosthandle = 0;
1225                 frames++;
1226         } while (1);
1227         adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1228 }
1229
1230 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1231 {
1232         struct net_device *dev = (struct net_device *)dev_id;
1233         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1234         u32 isr;
1235
1236         if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1237                 slic_reg32_write(&adapter->slic_regs->slic_icr,
1238                                  ICR_INT_MASK, FLUSH);
1239                 isr = adapter->isrcopy = adapter->pshmem->isr;
1240                 adapter->pshmem->isr = 0;
1241                 adapter->num_isrs++;
1242                 switch (adapter->card->state) {
1243                 case CARD_UP:
1244                         if (isr & ~ISR_IO) {
1245                                 if (isr & ISR_ERR) {
1246                                         adapter->error_interrupts++;
1247                                         if (isr & ISR_RMISS) {
1248                                                 int count;
1249                                                 int pre_count;
1250                                                 int errors;
1251
1252                                                 struct slic_rcvqueue *rcvq =
1253                                                     &adapter->rcvqueue;
1254
1255                                                 adapter->
1256                                                     error_rmiss_interrupts++;
1257                                                 if (!rcvq->errors)
1258                                                         rcv_count = rcvq->count;
1259                                                 pre_count = rcvq->count;
1260                                                 errors = rcvq->errors;
1261
1262                                                 while (rcvq->count <
1263                                                        SLIC_RCVQ_FILLTHRESH) {
1264                                                         count =
1265                                                             slic_rcvqueue_fill
1266                                                             (adapter);
1267                                                         if (!count)
1268                                                                 break;
1269                                                 }
1270                                                 DBG_MSG
1271                                                     ("(%s): [%x] ISR_RMISS \
1272                                                      initial[%x] pre[%x] \
1273                                                      errors[%x] \
1274                                                      post_count[%x]\n",
1275                                                      adapter->netdev->name,
1276                                                      isr, rcv_count, pre_count,
1277                                                      errors, rcvq->count);
1278                                         } else if (isr & ISR_XDROP) {
1279                                                 DBG_ERROR
1280                                                     ("isr & ISR_ERR [%x] \
1281                                                      ISR_XDROP \n",
1282                                                      isr);
1283                                         } else {
1284                                                 DBG_ERROR
1285                                                     ("isr & ISR_ERR [%x]\n",
1286                                                      isr);
1287                                         }
1288                                 }
1289
1290                                 if (isr & ISR_LEVENT) {
1291                                         /*DBG_MSG("%s (%s)  ISR_LEVENT \n",
1292                                            __func__, adapter->netdev->name);*/
1293                                         adapter->linkevent_interrupts++;
1294                                         slic_link_event_handler(adapter);
1295                                 }
1296
1297                                 if ((isr & ISR_UPC) ||
1298                                     (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1299                                         adapter->upr_interrupts++;
1300                                         slic_upr_request_complete(adapter, isr);
1301                                 }
1302                         }
1303
1304                         if (isr & ISR_RCV) {
1305                                 adapter->rcv_interrupts++;
1306                                 slic_rcv_handler(adapter);
1307                         }
1308
1309                         if (isr & ISR_CMD) {
1310                                 adapter->xmit_interrupts++;
1311                                 slic_xmit_complete(adapter);
1312                         }
1313                         break;
1314
1315                 case CARD_DOWN:
1316                         if ((isr & ISR_UPC) ||
1317                             (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1318                                 adapter->upr_interrupts++;
1319                                 slic_upr_request_complete(adapter, isr);
1320                         }
1321                         break;
1322
1323                 default:
1324                         break;
1325                 }
1326
1327                 adapter->isrcopy = 0;
1328                 adapter->all_reg_writes += 2;
1329                 adapter->isr_reg_writes++;
1330                 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
1331         } else {
1332                 adapter->false_interrupts++;
1333         }
1334         return IRQ_HANDLED;
1335 }
1336
1337 /*
1338  * slic_link_event_handler -
1339  *
1340  * Initiate a link configuration sequence.  The link configuration begins
1341  * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1342  * SLIC.  Since the command finishes asynchronously, the slic_upr_comlete
1343  * routine will follow it up witha UP configuration write command, which
1344  * will also complete asynchronously.
1345  *
1346  */
1347 static void slic_link_event_handler(struct adapter *adapter)
1348 {
1349         int status;
1350         struct slic_shmem *pshmem;
1351
1352         if (adapter->state != ADAPT_UP) {
1353                 /* Adapter is not operational.  Ignore.  */
1354                 return;
1355         }
1356
1357         pshmem = (struct slic_shmem *)adapter->phys_shmem;
1358
1359 #if defined(CONFIG_X86_64)
1360 /*
1361     DBG_MSG("slic_event_handler  pshmem->linkstatus[%x]  pshmem[%p]\n   \
1362         &linkstatus[%p] &isr[%p]\n", adapter->pshmem->linkstatus, pshmem,
1363         &pshmem->linkstatus, &pshmem->isr);
1364 */
1365         status = slic_upr_request(adapter,
1366                                   SLIC_UPR_RLSR,
1367                                   SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1368                                   SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1369                                   0, 0);
1370 #elif defined(CONFIG_X86)
1371         status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1372                 (u32) &pshmem->linkstatus,      /* no 4GB wrap guaranteed */
1373                                   0, 0, 0);
1374 #else
1375         Stop compilation;
1376 #endif
1377         ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1378 }
1379
1380 static void slic_init_cleanup(struct adapter *adapter)
1381 {
1382         DBG_MSG("slicoss: %s ENTER adapter[%p] ", __func__, adapter);
1383         if (adapter->intrregistered) {
1384                 DBG_MSG("FREE_IRQ ");
1385                 adapter->intrregistered = 0;
1386                 free_irq(adapter->netdev->irq, adapter->netdev);
1387
1388         }
1389         if (adapter->pshmem) {
1390                 DBG_MSG("FREE_SHMEM ");
1391                 DBG_MSG("adapter[%p] port %d pshmem[%p] FreeShmem ",
1392                         adapter, adapter->port, (void *) adapter->pshmem);
1393                 pci_free_consistent(adapter->pcidev,
1394                                     sizeof(struct slic_shmem),
1395                                     adapter->pshmem, adapter->phys_shmem);
1396                 adapter->pshmem = NULL;
1397                 adapter->phys_shmem = (dma_addr_t) NULL;
1398         }
1399 #if SLIC_PING_TIMER_ENABLED
1400         if (adapter->pingtimerset) {
1401                 DBG_MSG("pingtimer ");
1402                 adapter->pingtimerset = 0;
1403                 del_timer(&adapter->pingtimer);
1404         }
1405 #endif
1406         slic_rspqueue_free(adapter);
1407         slic_cmdq_free(adapter);
1408         slic_rcvqueue_free(adapter);
1409
1410         DBG_MSG("\n");
1411 }
1412
1413 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1414 {
1415         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1416         struct net_device_stats *stats;
1417
1418         ASSERT(adapter);
1419         stats = &adapter->stats;
1420         stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1421         stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1422         stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1423         stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1424         stats->tx_heartbeat_errors = 0;
1425         stats->tx_aborted_errors = 0;
1426         stats->tx_window_errors = 0;
1427         stats->tx_fifo_errors = 0;
1428         stats->rx_frame_errors = 0;
1429         stats->rx_length_errors = 0;
1430         return &adapter->stats;
1431 }
1432
1433 /*
1434  *  Allocate a mcast_address structure to hold the multicast address.
1435  *  Link it in.
1436  */
1437 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1438 {
1439         struct mcast_address *mcaddr, *mlist;
1440         bool equaladdr;
1441
1442         /* Check to see if it already exists */
1443         mlist = adapter->mcastaddrs;
1444         while (mlist) {
1445                 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1446                 if (equaladdr)
1447                         return STATUS_SUCCESS;
1448                 mlist = mlist->next;
1449         }
1450
1451         /* Doesn't already exist.  Allocate a structure to hold it */
1452         mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1453         if (mcaddr == NULL)
1454                 return 1;
1455
1456         memcpy(mcaddr->address, address, 6);
1457
1458         mcaddr->next = adapter->mcastaddrs;
1459         adapter->mcastaddrs = mcaddr;
1460
1461         return STATUS_SUCCESS;
1462 }
1463
1464 /*
1465  * Functions to obtain the CRC corresponding to the destination mac address.
1466  * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1467  * the polynomial:
1468  *   x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1469  *   x^4 + x^2 + x^1.
1470  *
1471  * After the CRC for the 6 bytes is generated (but before the value is
1472  * complemented),
1473  * we must then transpose the value and return bits 30-23.
1474  *
1475  */
1476 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1477 static u32 slic_crc_init;       /* Is table initialized */
1478
1479 /*
1480  *  Contruct the CRC32 table
1481  */
1482 static void slic_mcast_init_crc32(void)
1483 {
1484         u32 c;          /*  CRC shit reg                 */
1485         u32 e = 0;              /*  Poly X-or pattern            */
1486         int i;                  /*  counter                      */
1487         int k;                  /*  byte being shifted into crc  */
1488
1489         static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1490
1491         for (i = 0; i < sizeof(p) / sizeof(int); i++)
1492                 e |= 1L << (31 - p[i]);
1493
1494         for (i = 1; i < 256; i++) {
1495                 c = i;
1496                 for (k = 8; k; k--)
1497                         c = c & 1 ? (c >> 1) ^ e : c >> 1;
1498                 slic_crc_table[i] = c;
1499         }
1500 }
1501
1502 /*
1503  *  Return the MAC hast as described above.
1504  */
1505 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1506 {
1507         u32 crc;
1508         char *p;
1509         int i;
1510         unsigned char machash = 0;
1511
1512         if (!slic_crc_init) {
1513                 slic_mcast_init_crc32();
1514                 slic_crc_init = 1;
1515         }
1516
1517         crc = 0xFFFFFFFF;       /* Preload shift register, per crc-32 spec */
1518         for (i = 0, p = macaddr; i < 6; ++p, ++i)
1519                 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1520
1521         /* Return bits 1-8, transposed */
1522         for (i = 1; i < 9; i++)
1523                 machash |= (((crc >> i) & 1) << (8 - i));
1524
1525         return machash;
1526 }
1527
1528 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1529 {
1530         unsigned char crcpoly;
1531
1532         /* Get the CRC polynomial for the mac address */
1533         crcpoly = slic_mcast_get_mac_hash(address);
1534
1535         /* We only have space on the SLIC for 64 entries.  Lop
1536          * off the top two bits. (2^6 = 64)
1537          */
1538         crcpoly &= 0x3F;
1539
1540         /* OR in the new bit into our 64 bit mask. */
1541         adapter->mcastmask |= (u64) 1 << crcpoly;
1542 }
1543
1544 static void slic_mcast_set_list(struct net_device *dev)
1545 {
1546         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1547         int status = STATUS_SUCCESS;
1548         int i;
1549         char *addresses;
1550         struct dev_mc_list *mc_list = dev->mc_list;
1551         int mc_count = dev->mc_count;
1552
1553         ASSERT(adapter);
1554
1555         for (i = 1; i <= mc_count; i++) {
1556                 addresses = (char *) &mc_list->dmi_addr;
1557                 if (mc_list->dmi_addrlen == 6) {
1558                         status = slic_mcast_add_list(adapter, addresses);
1559                         if (status != STATUS_SUCCESS)
1560                                 break;
1561                 } else {
1562                         status = -EINVAL;
1563                         break;
1564                 }
1565                 slic_mcast_set_bit(adapter, addresses);
1566                 mc_list = mc_list->next;
1567         }
1568
1569         DBG_MSG("%s a->devflags_prev[%x] dev->flags[%x] status[%x]\n",
1570                 __func__, adapter->devflags_prev, dev->flags, status);
1571         if (adapter->devflags_prev != dev->flags) {
1572                 adapter->macopts = MAC_DIRECTED;
1573                 if (dev->flags) {
1574                         if (dev->flags & IFF_BROADCAST)
1575                                 adapter->macopts |= MAC_BCAST;
1576                         if (dev->flags & IFF_PROMISC)
1577                                 adapter->macopts |= MAC_PROMISC;
1578                         if (dev->flags & IFF_ALLMULTI)
1579                                 adapter->macopts |= MAC_ALLMCAST;
1580                         if (dev->flags & IFF_MULTICAST)
1581                                 adapter->macopts |= MAC_MCAST;
1582                 }
1583                 adapter->devflags_prev = dev->flags;
1584                 DBG_MSG("%s call slic_config_set adapter->macopts[%x]\n",
1585                         __func__, adapter->macopts);
1586                 slic_config_set(adapter, true);
1587         } else {
1588                 if (status == STATUS_SUCCESS)
1589                         slic_mcast_set_mask(adapter);
1590         }
1591         return;
1592 }
1593
1594 static void slic_mcast_set_mask(struct adapter *adapter)
1595 {
1596         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1597
1598         DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1599                 adapter->netdev->name, (uint) adapter->macopts,
1600                 adapter->mcastmask);
1601
1602         if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1603                 /* Turn on all multicast addresses. We have to do this for
1604                  * promiscuous mode as well as ALLMCAST mode.  It saves the
1605                  * Microcode from having to keep state about the MAC
1606                  * configuration.
1607                  */
1608 /*              DBG_MSG("slicoss: %s macopts = MAC_ALLMCAST | MAC_PROMISC\n\
1609                 SLUT MODE!!!\n",__func__); */
1610                 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1611                 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
1612                                  FLUSH);
1613 /*        DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1614                 _func__, adapter->netdev->name); */
1615         } else {
1616                 /* Commit our multicast mast to the SLIC by writing to the
1617                  * multicast address mask registers
1618                  */
1619                 DBG_MSG("%s (%s) WRITE mcastlow[%x] mcasthigh[%x]\n",
1620                         __func__, adapter->netdev->name,
1621                         ((ulong) (adapter->mcastmask & 0xFFFFFFFF)),
1622                         ((ulong) ((adapter->mcastmask >> 32) & 0xFFFFFFFF)));
1623
1624                 slic_reg32_write(&slic_regs->slic_mcastlow,
1625                         (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1626                 slic_reg32_write(&slic_regs->slic_mcasthigh,
1627                         (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
1628         }
1629 }
1630
1631 static void slic_timer_ping(ulong dev)
1632 {
1633         struct adapter *adapter;
1634         struct sliccard *card;
1635
1636         ASSERT(dev);
1637         adapter = netdev_priv((struct net_device *)dev);
1638         ASSERT(adapter);
1639         card = adapter->card;
1640         ASSERT(card);
1641
1642         adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1643         add_timer(&adapter->pingtimer);
1644 }
1645
1646 /*
1647  *  slic_if_init
1648  *
1649  *  Perform initialization of our slic interface.
1650  *
1651  */
1652 static int slic_if_init(struct adapter *adapter)
1653 {
1654         struct sliccard *card = adapter->card;
1655         struct net_device *dev = adapter->netdev;
1656         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1657         struct slic_shmem *pshmem;
1658         int status = 0;
1659
1660         ASSERT(card);
1661         DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1662                 __func__, adapter->netdev->name,
1663                 adapter->queues_initialized, adapter->state, adapter->linkstate,
1664                 card->state, dev->flags);
1665
1666         /* adapter should be down at this point */
1667         if (adapter->state != ADAPT_DOWN) {
1668                 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1669                 return -EIO;
1670         }
1671         ASSERT(adapter->linkstate == LINK_DOWN);
1672
1673         adapter->devflags_prev = dev->flags;
1674         adapter->macopts = MAC_DIRECTED;
1675         if (dev->flags) {
1676                 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1677                         adapter->netdev->name);
1678                 if (dev->flags & IFF_BROADCAST) {
1679                         adapter->macopts |= MAC_BCAST;
1680                         DBG_MSG("BCAST ");
1681                 }
1682                 if (dev->flags & IFF_PROMISC) {
1683                         adapter->macopts |= MAC_PROMISC;
1684                         DBG_MSG("PROMISC ");
1685                 }
1686                 if (dev->flags & IFF_ALLMULTI) {
1687                         adapter->macopts |= MAC_ALLMCAST;
1688                         DBG_MSG("ALL_MCAST ");
1689                 }
1690                 if (dev->flags & IFF_MULTICAST) {
1691                         adapter->macopts |= MAC_MCAST;
1692                         DBG_MSG("MCAST ");
1693                 }
1694                 DBG_MSG("\n");
1695         }
1696         status = slic_adapter_allocresources(adapter);
1697         if (status != STATUS_SUCCESS) {
1698                 DBG_ERROR
1699                     ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1700                      status);
1701                 slic_adapter_freeresources(adapter);
1702                 return status;
1703         }
1704
1705         if (!adapter->queues_initialized) {
1706                 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1707                 if (slic_rspqueue_init(adapter))
1708                         return -ENOMEM;
1709                 DBG_MSG
1710                     ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1711                      __func__, adapter, adapter->port);
1712                 if (slic_cmdq_init(adapter))
1713                         return -ENOMEM;
1714                 DBG_MSG
1715                     ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1716                      port %d \n", __func__, adapter, adapter->port);
1717                 if (slic_rcvqueue_init(adapter))
1718                         return -ENOMEM;
1719                 adapter->queues_initialized = 1;
1720         }
1721         DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1722
1723         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1724         mdelay(1);
1725
1726         if (!adapter->isp_initialized) {
1727                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1728
1729                 spin_lock_irqsave(&adapter->bit64reglock.lock,
1730                                         adapter->bit64reglock.flags);
1731
1732 #if defined(CONFIG_X86_64)
1733                 slic_reg32_write(&slic_regs->slic_addr_upper,
1734                                  SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1735                 slic_reg32_write(&slic_regs->slic_isp,
1736                                  SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1737 #elif defined(CONFIG_X86)
1738                 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1739                 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
1740 #else
1741                 Stop Compilations
1742 #endif
1743                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1744                                         adapter->bit64reglock.flags);
1745                 adapter->isp_initialized = 1;
1746         }
1747
1748         adapter->state = ADAPT_UP;
1749         if (!card->loadtimerset) {
1750                 init_timer(&card->loadtimer);
1751                 card->loadtimer.expires =
1752                     jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1753                 card->loadtimer.data = (ulong) card;
1754                 card->loadtimer.function = &slic_timer_load_check;
1755                 add_timer(&card->loadtimer);
1756
1757                 card->loadtimerset = 1;
1758         }
1759 #if SLIC_PING_TIMER_ENABLED
1760         if (!adapter->pingtimerset) {
1761                 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1762                         __func__);
1763                 init_timer(&adapter->pingtimer);
1764                 adapter->pingtimer.expires =
1765                     jiffies + (PING_TIMER_INTERVAL * HZ);
1766                 adapter->pingtimer.data = (ulong) dev;
1767                 adapter->pingtimer.function = &slic_timer_ping;
1768                 add_timer(&adapter->pingtimer);
1769                 adapter->pingtimerset = 1;
1770                 adapter->card->pingstatus = ISR_PINGMASK;
1771         }
1772 #endif
1773
1774         /*
1775          *    clear any pending events, then enable interrupts
1776          */
1777         DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1778         adapter->isrcopy = 0;
1779         adapter->pshmem->isr = 0;
1780         slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
1781         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1782
1783         DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1784         slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1785         slic_link_event_handler(adapter);
1786
1787         DBG_MSG("slicoss: %s EXIT\n", __func__);
1788         return STATUS_SUCCESS;
1789 }
1790
1791 static void slic_unmap_mmio_space(struct adapter *adapter)
1792 {
1793 #if LINUX_FREES_ADAPTER_RESOURCES
1794         if (adapter->slic_regs)
1795                 iounmap(adapter->slic_regs);
1796         adapter->slic_regs = NULL;
1797 #endif
1798 }
1799
1800 static int slic_adapter_allocresources(struct adapter *adapter)
1801 {
1802         if (!adapter->intrregistered) {
1803                 int retval;
1804
1805                 DBG_MSG
1806                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1807                      phys_shmem[%p] dev->irq[%x] %x\n",
1808                      __func__, adapter, adapter->pshmem,
1809                      (void *)adapter->phys_shmem, adapter->netdev->irq,
1810                      NR_IRQS);
1811
1812                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1813                                         slic_global.driver_lock.flags);
1814
1815                 retval = request_irq(adapter->netdev->irq,
1816                                      &slic_interrupt,
1817                                      IRQF_SHARED,
1818                                      adapter->netdev->name, adapter->netdev);
1819
1820                 spin_lock_irqsave(&slic_global.driver_lock.lock,
1821                                         slic_global.driver_lock.flags);
1822
1823                 if (retval) {
1824                         DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1825                                   adapter->netdev->name, retval);
1826                         return retval;
1827                 }
1828                 adapter->intrregistered = 1;
1829                 DBG_MSG
1830                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1831                      pshmem[%p] dev->irq[%x]\n",
1832                      __func__, adapter, adapter->pshmem,
1833                      (void *)adapter->pshmem, adapter->netdev->irq);
1834         }
1835         return STATUS_SUCCESS;
1836 }
1837
1838 static void slic_config_pci(struct pci_dev *pcidev)
1839 {
1840         u16 pci_command;
1841         u16 new_command;
1842
1843         pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1844         DBG_MSG("slicoss: %s  PCI command[%4.4x]\n", __func__, pci_command);
1845
1846         new_command = pci_command | PCI_COMMAND_MASTER
1847             | PCI_COMMAND_MEMORY
1848             | PCI_COMMAND_INVALIDATE
1849             | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1850         if (pci_command != new_command) {
1851                 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1852                         __func__, pci_command, new_command);
1853                 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1854         }
1855 }
1856
1857 static void slic_adapter_freeresources(struct adapter *adapter)
1858 {
1859         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1860         slic_init_cleanup(adapter);
1861         memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1862         adapter->error_interrupts = 0;
1863         adapter->rcv_interrupts = 0;
1864         adapter->xmit_interrupts = 0;
1865         adapter->linkevent_interrupts = 0;
1866         adapter->upr_interrupts = 0;
1867         adapter->num_isrs = 0;
1868         adapter->xmit_completes = 0;
1869         adapter->rcv_broadcasts = 0;
1870         adapter->rcv_multicasts = 0;
1871         adapter->rcv_unicasts = 0;
1872         DBG_MSG("slicoss: %s EXIT\n", __func__);
1873 }
1874
1875 /*
1876  *  slic_link_config
1877  *
1878  *  Write phy control to configure link duplex/speed
1879  *
1880  */
1881 static void slic_link_config(struct adapter *adapter,
1882                       u32 linkspeed, u32 linkduplex)
1883 {
1884         u32 __iomem *wphy;
1885         u32 speed;
1886         u32 duplex;
1887         u32 phy_config;
1888         u32 phy_advreg;
1889         u32 phy_gctlreg;
1890
1891         if (adapter->state != ADAPT_UP) {
1892                 DBG_MSG
1893                     ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1894                      __func__, adapter->netdev->name, linkspeed,
1895                      linkduplex);
1896                 return;
1897         }
1898         DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1899                 __func__, adapter->netdev->name, linkspeed, linkduplex);
1900
1901         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1902                || (adapter->devid == SLIC_2GB_DEVICE_ID));
1903
1904         if (linkspeed > LINK_1000MB)
1905                 linkspeed = LINK_AUTOSPEED;
1906         if (linkduplex > LINK_AUTOD)
1907                 linkduplex = LINK_AUTOD;
1908
1909         wphy = &adapter->slic_regs->slic_wphy;
1910
1911         if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
1912                 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
1913                         /*  We've got a fiber gigabit interface, and register
1914                          *  4 is different in fiber mode than in copper mode
1915                          */
1916
1917                         /* advertise FD only @1000 Mb */
1918                         phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
1919                         /* enable PAUSE frames        */
1920                         phy_advreg |= PAR_ASYMPAUSE_FIBER;
1921                         slic_reg32_write(wphy, phy_advreg, FLUSH);
1922
1923                         if (linkspeed == LINK_AUTOSPEED) {
1924                                 /* reset phy, enable auto-neg  */
1925                                 phy_config =
1926                                     (MIICR_REG_PCR |
1927                                      (PCR_RESET | PCR_AUTONEG |
1928                                       PCR_AUTONEG_RST));
1929                                 slic_reg32_write(wphy, phy_config, FLUSH);
1930                         } else {        /* forced 1000 Mb FD*/
1931                                 /* power down phy to break link
1932                                    this may not work) */
1933                                 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
1934                                 slic_reg32_write(wphy, phy_config, FLUSH);
1935                                 /* wait, Marvell says 1 sec,
1936                                    try to get away with 10 ms  */
1937                                 mdelay(10);
1938
1939                                 /* disable auto-neg, set speed/duplex,
1940                                    soft reset phy, powerup */
1941                                 phy_config =
1942                                     (MIICR_REG_PCR |
1943                                      (PCR_RESET | PCR_SPEED_1000 |
1944                                       PCR_DUPLEX_FULL));
1945                                 slic_reg32_write(wphy, phy_config, FLUSH);
1946                         }
1947                 } else {        /* copper gigabit */
1948
1949                         /* Auto-Negotiate or 1000 Mb must be auto negotiated
1950                          * We've got a copper gigabit interface, and
1951                          * register 4 is different in copper mode than
1952                          * in fiber mode
1953                          */
1954                         if (linkspeed == LINK_AUTOSPEED) {
1955                                 /* advertise 10/100 Mb modes   */
1956                                 phy_advreg =
1957                                     (MIICR_REG_4 |
1958                                      (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
1959                                       | PAR_ADV10HD));
1960                         } else {
1961                         /* linkspeed == LINK_1000MB -
1962                            don't advertise 10/100 Mb modes  */
1963                                 phy_advreg = MIICR_REG_4;
1964                         }
1965                         /* enable PAUSE frames  */
1966                         phy_advreg |= PAR_ASYMPAUSE;
1967                         /* required by the Cicada PHY  */
1968                         phy_advreg |= PAR_802_3;
1969                         slic_reg32_write(wphy, phy_advreg, FLUSH);
1970                         /* advertise FD only @1000 Mb  */
1971                         phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
1972                         slic_reg32_write(wphy, phy_gctlreg, FLUSH);
1973
1974                         if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1975                                 /* if a Marvell PHY
1976                                    enable auto crossover */
1977                                 phy_config =
1978                                     (MIICR_REG_16 | (MRV_REG16_XOVERON));
1979                                 slic_reg32_write(wphy, phy_config, FLUSH);
1980
1981                                 /* reset phy, enable auto-neg  */
1982                                 phy_config =
1983                                     (MIICR_REG_PCR |
1984                                      (PCR_RESET | PCR_AUTONEG |
1985                                       PCR_AUTONEG_RST));
1986                                 slic_reg32_write(wphy, phy_config, FLUSH);
1987                         } else {        /* it's a Cicada PHY  */
1988                                 /* enable and restart auto-neg (don't reset)  */
1989                                 phy_config =
1990                                     (MIICR_REG_PCR |
1991                                      (PCR_AUTONEG | PCR_AUTONEG_RST));
1992                                 slic_reg32_write(wphy, phy_config, FLUSH);
1993                         }
1994                 }
1995         } else {
1996                 /* Forced 10/100  */
1997                 if (linkspeed == LINK_10MB)
1998                         speed = 0;
1999                 else
2000                         speed = PCR_SPEED_100;
2001                 if (linkduplex == LINK_HALFD)
2002                         duplex = 0;
2003                 else
2004                         duplex = PCR_DUPLEX_FULL;
2005
2006                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2007                         /* if a Marvell PHY
2008                            disable auto crossover  */
2009                         phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2010                         slic_reg32_write(wphy, phy_config, FLUSH);
2011                 }
2012
2013                 /* power down phy to break link (this may not work)  */
2014                 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2015                 slic_reg32_write(wphy, phy_config, FLUSH);
2016
2017                 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2018                 mdelay(10);
2019
2020                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2021                         /* if a Marvell PHY
2022                            disable auto-neg, set speed,
2023                            soft reset phy, powerup */
2024                         phy_config =
2025                             (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2026                         slic_reg32_write(wphy, phy_config, FLUSH);
2027                 } else {        /* it's a Cicada PHY  */
2028                         /* disable auto-neg, set speed, powerup  */
2029                         phy_config = (MIICR_REG_PCR | (speed | duplex));
2030                         slic_reg32_write(wphy, phy_config, FLUSH);
2031                 }
2032         }
2033
2034         DBG_MSG
2035             ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2036             phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2037             phy_config);
2038 }
2039
2040 static void slic_card_cleanup(struct sliccard *card)
2041 {
2042         DBG_MSG("slicoss: %s ENTER\n", __func__);
2043
2044         if (card->loadtimerset) {
2045                 card->loadtimerset = 0;
2046                 del_timer(&card->loadtimer);
2047         }
2048
2049         slic_debug_card_destroy(card);
2050
2051         kfree(card);
2052         DBG_MSG("slicoss: %s EXIT\n", __func__);
2053 }
2054
2055 static int slic_card_download_gbrcv(struct adapter *adapter)
2056 {
2057         const struct firmware *fw;
2058         const char *file = "";
2059         int ret;
2060         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2061         u32 codeaddr;
2062         u32 instruction;
2063         int index = 0;
2064         u32 rcvucodelen = 0;
2065
2066         switch (adapter->devid) {
2067         case SLIC_2GB_DEVICE_ID:
2068                 file = "slicoss/oasisrcvucode.sys";
2069                 break;
2070         case SLIC_1GB_DEVICE_ID:
2071                 file = "slicoss/gbrcvucode.sys";
2072                 break;
2073         default:
2074                 ASSERT(0);
2075                 break;
2076         }
2077
2078         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2079         if (ret) {
2080                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2081                 return ret;
2082         }
2083
2084         rcvucodelen = *(u32 *)(fw->data + index);
2085         index += 4;
2086         switch (adapter->devid) {
2087         case SLIC_2GB_DEVICE_ID:
2088                 if (rcvucodelen != OasisRcvUCodeLen)
2089                         return -EINVAL;
2090                 break;
2091         case SLIC_1GB_DEVICE_ID:
2092                 if (rcvucodelen != GBRcvUCodeLen)
2093                         return -EINVAL;
2094                 break;
2095         default:
2096                 ASSERT(0);
2097                 break;
2098         }
2099         /* start download */
2100         slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2101         /* download the rcv sequencer ucode */
2102         for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2103                 /* write out instruction address */
2104                 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2105
2106                 instruction = *(u32 *)(fw->data + index);
2107                 index += 4;
2108                 /* write out the instruction data low addr */
2109                 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
2110
2111                 instruction = *(u8 *)(fw->data + index);
2112                 index++;
2113                 /* write out the instruction data high addr */
2114                 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
2115                                  FLUSH);
2116         }
2117
2118         /* download finished */
2119         release_firmware(fw);
2120         slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2121         return 0;
2122 }
2123
2124 static int slic_card_download(struct adapter *adapter)
2125 {
2126         const struct firmware *fw;
2127         const char *file = "";
2128         int ret;
2129         u32 section;
2130         int thissectionsize;
2131         int codeaddr;
2132         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2133         u32 instruction;
2134         u32 baseaddress;
2135         u32 failure;
2136         u32 i;
2137         u32 numsects = 0;
2138         u32 sectsize[3];
2139         u32 sectstart[3];
2140         int ucode_start, index = 0;
2141
2142 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2143         jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2144             adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2145
2146         switch (adapter->devid) {
2147         case SLIC_2GB_DEVICE_ID:
2148                 file = "slicoss/oasisdownload.sys";
2149                 break;
2150         case SLIC_1GB_DEVICE_ID:
2151                 file = "slicoss/gbdownload.sys";
2152                 break;
2153         default:
2154                 ASSERT(0);
2155                 break;
2156         }
2157         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2158         if (ret) {
2159                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2160                 return ret;
2161         }
2162         numsects = *(u32 *)(fw->data + index);
2163         index += 4;
2164         ASSERT(numsects <= 3);
2165         for (i = 0; i < numsects; i++) {
2166                 sectsize[i] = *(u32 *)(fw->data + index);
2167                 index += 4;
2168         }
2169         for (i = 0; i < numsects; i++) {
2170                 sectstart[i] = *(u32 *)(fw->data + index);
2171                 index += 4;
2172         }
2173         ucode_start = index;
2174         instruction = *(u32 *)(fw->data + index);
2175         index += 4;
2176         for (section = 0; section < numsects; section++) {
2177                 baseaddress = sectstart[section];
2178                 thissectionsize = sectsize[section] >> 3;
2179
2180                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2181                         /* Write out instruction address */
2182                         slic_reg32_write(&slic_regs->slic_wcs,
2183                                          baseaddress + codeaddr, FLUSH);
2184                         /* Write out instruction to low addr */
2185                         slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2186                         instruction = *(u32 *)(fw->data + index);
2187                         index += 4;
2188
2189                         /* Write out instruction to high addr */
2190                         slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2191                         instruction = *(u32 *)(fw->data + index);
2192                         index += 4;
2193                 }
2194         }
2195         index = ucode_start;
2196         for (section = 0; section < numsects; section++) {
2197                 instruction = *(u32 *)(fw->data + index);
2198                 baseaddress = sectstart[section];
2199                 if (baseaddress < 0x8000)
2200                         continue;
2201                 thissectionsize = sectsize[section] >> 3;
2202
2203 /*        DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2204                 (uint)section,baseaddress,thissectionsize);*/
2205                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2206                         /* Write out instruction address */
2207                         slic_reg32_write(&slic_regs->slic_wcs,
2208                                 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2209                                 FLUSH);
2210                         /* Write out instruction to low addr */
2211                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
2212                                          FLUSH);
2213                         instruction = *(u32 *)(fw->data + index);
2214                         index += 4;
2215                         /* Write out instruction to high addr */
2216                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
2217                                          FLUSH);
2218                         instruction = *(u32 *)(fw->data + index);
2219                         index += 4;
2220
2221                         /* Check SRAM location zero. If it is non-zero. Abort.*/
2222 /*                      failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2223                         if (failure) {
2224                                 DBG_MSG
2225                                     ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2226                                     "thissectionsize[%x] failure[%x]\n",
2227                                      __func__, codeaddr, thissectionsize,
2228                                      failure);
2229                                 release_firmware(fw);
2230                                 return -EIO;
2231                         }*/
2232                 }
2233         }
2234 /*    DBG_MSG ("slicoss: Compare done\n");*/
2235         release_firmware(fw);
2236         /* Everything OK, kick off the card */
2237         mdelay(10);
2238         slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2239
2240         /* stall for 20 ms, long enough for ucode to init card
2241            and reach mainloop */
2242         mdelay(20);
2243
2244         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2245                 __func__, adapter->netdev->name, adapter, adapter->card);
2246
2247         return STATUS_SUCCESS;
2248 }
2249
2250 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2251 {
2252         struct sliccard *card = adapter->card;
2253
2254 /*  DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2255     __func__, card->config_set, adapter->port, adapter->physport,
2256     adapter->functionnumber);
2257
2258     slic_dbg_macaddrs(adapter); */
2259
2260         if ((adapter->card) && (card->config_set)) {
2261                 memcpy(adapter->macaddr,
2262                        card->config.MacInfo[adapter->functionnumber].macaddrA,
2263                        sizeof(struct slic_config_mac));
2264 /*      DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2265         __func__);
2266         slic_dbg_macaddrs(adapter);*/
2267                 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2268                       adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2269                       adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2270                         memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2271                 }
2272                 if (adapter->netdev) {
2273                         memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2274                                6);
2275                 }
2276         }
2277 /*  DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2278     slic_dbg_macaddrs(adapter); */
2279 }
2280
2281 static void slic_intagg_set(struct adapter *adapter, u32 value)
2282 {
2283         slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
2284         adapter->card->loadlevel_current = value;
2285 }
2286
2287 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2288 {
2289         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2290         struct slic_eeprom *peeprom;
2291         struct oslic_eeprom *pOeeprom;
2292         dma_addr_t phys_config;
2293         u32 phys_configh;
2294         u32 phys_configl;
2295         u32 i = 0;
2296         struct slic_shmem *pshmem;
2297         int status;
2298         uint macaddrs = card->card_size;
2299         ushort eecodesize;
2300         ushort dramsize;
2301         ushort ee_chksum;
2302         ushort calc_chksum;
2303         struct slic_config_mac *pmac;
2304         unsigned char fruformat;
2305         unsigned char oemfruformat;
2306         struct atk_fru *patkfru;
2307         union oemfru *poemfru;
2308
2309         DBG_MSG
2310             ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2311             size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2312
2313         /* Reset everything except PCI configuration space */
2314         slic_soft_reset(adapter);
2315
2316         /* Download the microcode */
2317         status = slic_card_download(adapter);
2318
2319         if (status != STATUS_SUCCESS) {
2320                 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2321                           (uint) adapter->busnumber,
2322                           (uint) adapter->slotnumber);
2323                 return status;
2324         }
2325
2326         if (!card->config_set) {
2327                 peeprom = pci_alloc_consistent(adapter->pcidev,
2328                                                sizeof(struct slic_eeprom),
2329                                                &phys_config);
2330
2331                 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2332                 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2333
2334                 DBG_MSG("slicoss: %s Eeprom info  adapter [%p]\n    "
2335                         "size        [%x]\n    peeprom     [%p]\n    "
2336                         "phys_config [%p]\n    phys_configl[%x]\n    "
2337                         "phys_configh[%x]\n",
2338                         __func__, adapter,
2339                         (u32)sizeof(struct slic_eeprom),
2340                         peeprom, (void *) phys_config, phys_configl,
2341                         phys_configh);
2342                 if (!peeprom) {
2343                         DBG_ERROR
2344                             ("SLIC eeprom read failed to get memory bus %d \
2345                             slot %d\n",
2346                              (uint) adapter->busnumber,
2347                              (uint) adapter->slotnumber);
2348                         return -ENOMEM;
2349                 } else {
2350                         memset(peeprom, 0, sizeof(struct slic_eeprom));
2351                 }
2352                 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2353                 mdelay(1);
2354                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2355
2356                 spin_lock_irqsave(&adapter->bit64reglock.lock,
2357                                         adapter->bit64reglock.flags);
2358                 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2359                 slic_reg32_write(&slic_regs->slic_isp,
2360                                  SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2361                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2362                                         adapter->bit64reglock.flags);
2363
2364                 slic_config_get(adapter, phys_configl, phys_configh);
2365
2366                 for (;;) {
2367                         if (adapter->pshmem->isr) {
2368                                 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2369                                         __func__, adapter->pshmem,
2370                                         adapter->pshmem->isr);
2371
2372                                 if (adapter->pshmem->isr & ISR_UPC) {
2373                                         adapter->pshmem->isr = 0;
2374                                         slic_reg64_write(adapter,
2375                                                 &slic_regs->slic_isp, 0,
2376                                                 &slic_regs->slic_addr_upper,
2377                                                 0, FLUSH);
2378                                         slic_reg32_write(&slic_regs->slic_isr,
2379                                                          0, FLUSH);
2380
2381                                         slic_upr_request_complete(adapter, 0);
2382                                         break;
2383                                 } else {
2384                                         adapter->pshmem->isr = 0;
2385                                         slic_reg32_write(&slic_regs->slic_isr,
2386                                                          0, FLUSH);
2387                                 }
2388                         } else {
2389                                 mdelay(1);
2390                                 i++;
2391                                 if (i > 5000) {
2392                                         DBG_ERROR
2393                                             ("SLIC: %d config data fetch timed "
2394                                               "out!\n", adapter->port);
2395                                         DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2396                                                 __func__, adapter->pshmem,
2397                                                 adapter->pshmem->isr);
2398                                         slic_reg64_write(adapter,
2399                                                 &slic_regs->slic_isp, 0,
2400                                                 &slic_regs->slic_addr_upper,
2401                                                 0, FLUSH);
2402                                         return -EINVAL;
2403                                 }
2404                         }
2405                 }
2406
2407                 switch (adapter->devid) {
2408                 /* Oasis card */
2409                 case SLIC_2GB_DEVICE_ID:
2410                         /* extract EEPROM data and pointers to EEPROM data */
2411                         pOeeprom = (struct oslic_eeprom *) peeprom;
2412                         eecodesize = pOeeprom->EecodeSize;
2413                         dramsize = pOeeprom->DramSize;
2414                         pmac = pOeeprom->MacInfo;
2415                         fruformat = pOeeprom->FruFormat;
2416                         patkfru = &pOeeprom->AtkFru;
2417                         oemfruformat = pOeeprom->OemFruFormat;
2418                         poemfru = &pOeeprom->OemFru;
2419                         macaddrs = 2;
2420                         /* Minor kludge for Oasis card
2421                              get 2 MAC addresses from the
2422                              EEPROM to ensure that function 1
2423                              gets the Port 1 MAC address */
2424                         break;
2425                 default:
2426                         /* extract EEPROM data and pointers to EEPROM data */
2427                         eecodesize = peeprom->EecodeSize;
2428                         dramsize = peeprom->DramSize;
2429                         pmac = peeprom->u2.mac.MacInfo;
2430                         fruformat = peeprom->FruFormat;
2431                         patkfru = &peeprom->AtkFru;
2432                         oemfruformat = peeprom->OemFruFormat;
2433                         poemfru = &peeprom->OemFru;
2434                         break;
2435                 }
2436
2437                 card->config.EepromValid = false;
2438
2439                 /*  see if the EEPROM is valid by checking it's checksum */
2440                 if ((eecodesize <= MAX_EECODE_SIZE) &&
2441                     (eecodesize >= MIN_EECODE_SIZE)) {
2442
2443                         ee_chksum =
2444                             *(u16 *) ((char *) peeprom + (eecodesize - 2));
2445                         /*
2446                             calculate the EEPROM checksum
2447                         */
2448                         calc_chksum =
2449                             ~slic_eeprom_cksum((char *) peeprom,
2450                                                (eecodesize - 2));
2451                         /*
2452                             if the ucdoe chksum flag bit worked,
2453                             we wouldn't need this shit
2454                         */
2455                         if (ee_chksum == calc_chksum)
2456                                 card->config.EepromValid = true;
2457                 }
2458                 /*  copy in the DRAM size */
2459                 card->config.DramSize = dramsize;
2460
2461                 /*  copy in the MAC address(es) */
2462                 for (i = 0; i < macaddrs; i++) {
2463                         memcpy(&card->config.MacInfo[i],
2464                                &pmac[i], sizeof(struct slic_config_mac));
2465                 }
2466 /*      DBG_MSG ("%s EEPROM Checksum Good? %d  MacAddress\n",__func__,
2467                 card->config.EepromValid); */
2468
2469                 /*  copy the Alacritech FRU information */
2470                 card->config.FruFormat = fruformat;
2471                 memcpy(&card->config.AtkFru, patkfru,
2472                                                 sizeof(struct atk_fru));
2473
2474                 pci_free_consistent(adapter->pcidev,
2475                                     sizeof(struct slic_eeprom),
2476                                     peeprom, phys_config);
2477                 DBG_MSG
2478                     ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2479                      phys_config[%p]\n",
2480                      __func__, adapter->port, adapter,
2481                      (u32) sizeof(struct slic_eeprom), peeprom,
2482                      (void *) phys_config);
2483
2484                 if ((!card->config.EepromValid) &&
2485                     (adapter->reg_params.fail_on_bad_eeprom)) {
2486                         slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2487                                          &slic_regs->slic_addr_upper,
2488                                          0, FLUSH);
2489                         DBG_ERROR
2490                             ("unsupported CONFIGURATION  EEPROM invalid\n");
2491                         return -EINVAL;
2492                 }
2493
2494                 card->config_set = 1;
2495         }
2496
2497         if (slic_card_download_gbrcv(adapter)) {
2498                 DBG_ERROR("%s unable to download GB receive microcode\n",
2499                           __func__);
2500                 return -EINVAL;
2501         }
2502
2503         if (slic_global.dynamic_intagg) {
2504                 DBG_MSG
2505                     ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2506                      SET intagg to %d\n",
2507                      card->cardnum, 0);
2508                 slic_intagg_set(adapter, 0);
2509         } else {
2510                 slic_intagg_set(adapter, intagg_delay);
2511                 DBG_MSG
2512                     ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2513                      SET intagg to %d\n",
2514                      card->cardnum, intagg_delay);
2515         }
2516
2517         /*
2518          *  Initialize ping status to "ok"
2519          */
2520         card->pingstatus = ISR_PINGMASK;
2521
2522         /*
2523          * Lastly, mark our card state as up and return success
2524          */
2525         card->state = CARD_UP;
2526         card->reset_in_progress = 0;
2527         DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2528                 __func__, card, adapter, card->state);
2529
2530         return STATUS_SUCCESS;
2531 }
2532
2533 static u32 slic_card_locate(struct adapter *adapter)
2534 {
2535         struct sliccard *card = slic_global.slic_card;
2536         struct physcard *physcard = slic_global.phys_card;
2537         ushort card_hostid;
2538         u16 __iomem *hostid_reg;
2539         uint i;
2540         uint rdhostid_offset = 0;
2541
2542         DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2543                 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2544                 adapter->port);
2545
2546         switch (adapter->devid) {
2547         case SLIC_2GB_DEVICE_ID:
2548                 rdhostid_offset = SLIC_RDHOSTID_2GB;
2549                 break;
2550         case SLIC_1GB_DEVICE_ID:
2551                 rdhostid_offset = SLIC_RDHOSTID_1GB;
2552                 break;
2553         default:
2554                 ASSERT(0);
2555                 break;
2556         }
2557
2558         hostid_reg =
2559             (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2560             rdhostid_offset);
2561         DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2562
2563         /* read the 16 bit hostid from SRAM */
2564         card_hostid = (ushort) readw(hostid_reg);
2565         DBG_MSG(" card_hostid[%x]\n", card_hostid);
2566
2567         /* Initialize a new card structure if need be */
2568         if (card_hostid == SLIC_HOSTID_DEFAULT) {
2569                 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2570                 if (card == NULL)
2571                         return -ENOMEM;
2572
2573                 card->next = slic_global.slic_card;
2574                 slic_global.slic_card = card;
2575 #if DBG
2576                 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2577                         DBG_MSG
2578                             ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2579                              "and Storage Accelerator\n");
2580                 } else {
2581                         DBG_MSG
2582                             ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2583                              "and Storage Accelerator\n");
2584                 }
2585 #endif
2586                 card->busnumber = adapter->busnumber;
2587                 card->slotnumber = adapter->slotnumber;
2588
2589                 /* Find an available cardnum */
2590                 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2591                         if (slic_global.cardnuminuse[i] == 0) {
2592                                 slic_global.cardnuminuse[i] = 1;
2593                                 card->cardnum = i;
2594                                 break;
2595                         }
2596                 }
2597                 slic_global.num_slic_cards++;
2598                 DBG_MSG("\nCARDNUM == %d  Total %d  Card[%p]\n\n",
2599                         card->cardnum, slic_global.num_slic_cards, card);
2600
2601                 slic_debug_card_create(card);
2602         } else {
2603                 DBG_MSG
2604                     ("slicoss: %s CARD already allocated, find the \
2605                      correct card\n", __func__);
2606                 /* Card exists, find the card this adapter belongs to */
2607                 while (card) {
2608                         DBG_MSG
2609                             ("slicoss: %s card[%p] slot[%x] bus[%x] \
2610                               adaptport[%p] hostid[%x] cardnum[%x]\n",
2611                              __func__, card, card->slotnumber,
2612                              card->busnumber, card->adapter[adapter->port],
2613                              card_hostid, card->cardnum);
2614
2615                         if (card->cardnum == card_hostid)
2616                                 break;
2617                         card = card->next;
2618                 }
2619         }
2620
2621         ASSERT(card);
2622         if (!card)
2623                 return STATUS_FAILURE;
2624         /* Put the adapter in the card's adapter list */
2625         ASSERT(card->adapter[adapter->port] == NULL);
2626         if (!card->adapter[adapter->port]) {
2627                 card->adapter[adapter->port] = adapter;
2628                 adapter->card = card;
2629         }
2630
2631         card->card_size = 1;    /* one port per *logical* card */
2632
2633         while (physcard) {
2634                 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2635                         if (!physcard->adapter[i])
2636                                 continue;
2637                         else
2638                                 break;
2639                 }
2640                 ASSERT(i != SLIC_MAX_PORTS);
2641                 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2642                         break;
2643                 physcard = physcard->next;
2644         }
2645         if (!physcard) {
2646                 /* no structure allocated for this physical card yet */
2647                 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2648                 ASSERT(physcard);
2649
2650                 DBG_MSG
2651                     ("\n%s Allocate a PHYSICALcard:\n    PHYSICAL_Card[%p]\n"
2652                      "    LogicalCard  [%p]\n    adapter      [%p]\n",
2653                      __func__, physcard, card, adapter);
2654
2655                 physcard->next = slic_global.phys_card;
2656                 slic_global.phys_card = physcard;
2657                 physcard->adapters_allocd = 1;
2658         } else {
2659                 physcard->adapters_allocd++;
2660         }
2661         /* Note - this is ZERO relative */
2662         adapter->physport = physcard->adapters_allocd - 1;
2663
2664         ASSERT(physcard->adapter[adapter->physport] == NULL);
2665         physcard->adapter[adapter->physport] = adapter;
2666         adapter->physcard = physcard;
2667         DBG_MSG("    PHYSICAL_Port %d    Logical_Port  %d\n", adapter->physport,
2668                 adapter->port);
2669
2670         return 0;
2671 }
2672
2673 static void slic_soft_reset(struct adapter *adapter)
2674 {
2675         if (adapter->card->state == CARD_UP) {
2676                 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2677                         __func__, adapter, adapter->card, adapter->devid);
2678                 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
2679                 mdelay(1);
2680         }
2681 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2682         __func__, adapter->netdev->name, adapter, adapter->card,
2683            adapter->devid); */
2684
2685         slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2686                          FLUSH);
2687         mdelay(1);
2688 }
2689
2690 static void slic_config_set(struct adapter *adapter, bool linkchange)
2691 {
2692         u32 value;
2693         u32 RcrReset;
2694         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2695
2696         DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2697                 __func__, adapter->netdev->name, adapter,
2698                 adapter->cardindex);
2699
2700         if (linkchange) {
2701                 /* Setup MAC */
2702                 slic_mac_config(adapter);
2703                 RcrReset = GRCR_RESET;
2704         } else {
2705                 slic_mac_address_config(adapter);
2706                 RcrReset = 0;
2707         }
2708
2709         if (adapter->linkduplex == LINK_FULLD) {
2710                 /* setup xmtcfg */
2711                 value = (GXCR_RESET |   /* Always reset     */
2712                          GXCR_XMTEN |   /* Enable transmit  */
2713                          GXCR_PAUSEEN); /* Enable pause     */
2714
2715                 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2716                         value);
2717                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2718
2719                 /* Setup rcvcfg last */
2720                 value = (RcrReset |     /* Reset, if linkchange */
2721                          GRCR_CTLEN |   /* Enable CTL frames    */
2722                          GRCR_ADDRAEN | /* Address A enable     */
2723                          GRCR_RCVBAD |  /* Rcv bad frames       */
2724                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2725         } else {
2726                 /* setup xmtcfg */
2727                 value = (GXCR_RESET |   /* Always reset     */
2728                          GXCR_XMTEN);   /* Enable transmit  */
2729
2730                 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2731                         value);
2732                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2733
2734                 /* Setup rcvcfg last */
2735                 value = (RcrReset |     /* Reset, if linkchange */
2736                          GRCR_ADDRAEN | /* Address A enable     */
2737                          GRCR_RCVBAD |  /* Rcv bad frames       */
2738                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2739         }
2740
2741         if (adapter->state != ADAPT_DOWN) {
2742                 /* Only enable receive if we are restarting or running */
2743                 value |= GRCR_RCVEN;
2744         }
2745
2746         if (adapter->macopts & MAC_PROMISC)
2747                 value |= GRCR_RCVALL;
2748
2749         DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2750         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2751 }
2752
2753 /*
2754  *  Turn off RCV and XMT, power down PHY
2755  */
2756 static void slic_config_clear(struct adapter *adapter)
2757 {
2758         u32 value;
2759         u32 phy_config;
2760         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2761
2762         /* Setup xmtcfg */
2763         value = (GXCR_RESET |   /* Always reset */
2764                  GXCR_PAUSEEN); /* Enable pause */
2765
2766         slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2767
2768         value = (GRCR_RESET |   /* Always reset      */
2769                  GRCR_CTLEN |   /* Enable CTL frames */
2770                  GRCR_ADDRAEN | /* Address A enable  */
2771                  (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2772
2773         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2774
2775         /* power down phy */
2776         phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2777         slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2778 }
2779
2780 static void slic_config_get(struct adapter *adapter, u32 config,
2781                                                         u32 config_h)
2782 {
2783         int status;
2784
2785         status = slic_upr_request(adapter,
2786                                   SLIC_UPR_RCONFIG,
2787                                   (u32) config, (u32) config_h, 0, 0);
2788         ASSERT(status == 0);
2789 }
2790
2791 static void slic_mac_address_config(struct adapter *adapter)
2792 {
2793         u32 value;
2794         u32 value2;
2795         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2796
2797         value = *(u32 *) &adapter->currmacaddr[2];
2798         value = ntohl(value);
2799         slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
2800         slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
2801
2802         value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2803                              adapter->currmacaddr[1]) & 0xFFFF);
2804
2805         slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2806         slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2807
2808         DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2809                 __func__, value, value2);
2810         slic_dbg_macaddrs(adapter);
2811
2812         /* Write our multicast mask out to the card.  This is done */
2813         /* here in addition to the slic_mcast_addr_set routine     */
2814         /* because ALL_MCAST may have been enabled or disabled     */
2815         slic_mcast_set_mask(adapter);
2816 }
2817
2818 static void slic_mac_config(struct adapter *adapter)
2819 {
2820         u32 value;
2821         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2822
2823         /* Setup GMAC gaps */
2824         if (adapter->linkspeed == LINK_1000MB) {
2825                 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2826                          (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2827                          (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2828         } else {
2829                 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2830                          (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2831                          (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2832         }
2833
2834         /* enable GMII */
2835         if (adapter->linkspeed == LINK_1000MB)
2836                 value |= GMCR_GBIT;
2837
2838         /* enable fullduplex */
2839         if ((adapter->linkduplex == LINK_FULLD)
2840             || (adapter->macopts & MAC_LOOPBACK)) {
2841                 value |= GMCR_FULLD;
2842         }
2843
2844         /* write mac config */
2845         slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2846
2847         /* setup mac addresses */
2848         slic_mac_address_config(adapter);
2849 }
2850
2851 static bool slic_mac_filter(struct adapter *adapter,
2852                         struct ether_header *ether_frame)
2853 {
2854         u32 opts = adapter->macopts;
2855         u32 *dhost4 = (u32 *)&ether_frame->ether_dhost[0];
2856         u16 *dhost2 = (u16 *)&ether_frame->ether_dhost[4];
2857         bool equaladdr;
2858
2859         if (opts & MAC_PROMISC) {
2860                 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
2861                         __func__, adapter->netdev->name);
2862                 return true;
2863         }
2864
2865         if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
2866                 if (opts & MAC_BCAST) {
2867                         adapter->rcv_broadcasts++;
2868                         return true;
2869                 } else {
2870                         return false;
2871                 }
2872         }
2873
2874         if (ether_frame->ether_dhost[0] & 0x01) {
2875                 if (opts & MAC_ALLMCAST) {
2876                         adapter->rcv_multicasts++;
2877                         adapter->stats.multicast++;
2878                         return true;
2879                 }
2880                 if (opts & MAC_MCAST) {
2881                         struct mcast_address *mcaddr = adapter->mcastaddrs;
2882
2883                         while (mcaddr) {
2884                                 ETHER_EQ_ADDR(mcaddr->address,
2885                                               ether_frame->ether_dhost,
2886                                               equaladdr);
2887                                 if (equaladdr) {
2888                                         adapter->rcv_multicasts++;
2889                                         adapter->stats.multicast++;
2890                                         return true;
2891                                 }
2892                                 mcaddr = mcaddr->next;
2893                         }
2894                         return false;
2895                 } else {
2896                         return false;
2897                 }
2898         }
2899         if (opts & MAC_DIRECTED) {
2900                 adapter->rcv_unicasts++;
2901                 return true;
2902         }
2903         return false;
2904
2905 }
2906
2907 static int slic_mac_set_address(struct net_device *dev, void *ptr)
2908 {
2909         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
2910         struct sockaddr *addr = ptr;
2911
2912         DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
2913
2914         if (netif_running(dev))
2915                 return -EBUSY;
2916         if (!adapter)
2917                 return -EBUSY;
2918         DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2919                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
2920                 adapter->currmacaddr[1], adapter->currmacaddr[2],
2921                 adapter->currmacaddr[3], adapter->currmacaddr[4],
2922                 adapter->currmacaddr[5]);
2923         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2924         memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
2925         DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2926                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
2927                 adapter->currmacaddr[1], adapter->currmacaddr[2],
2928                 adapter->currmacaddr[3], adapter->currmacaddr[4],
2929                 adapter->currmacaddr[5]);
2930
2931         slic_config_set(adapter, true);
2932         return 0;
2933 }
2934
2935 static void slic_timer_load_check(ulong cardaddr)
2936 {
2937         struct sliccard *card = (struct sliccard *)cardaddr;
2938         struct adapter *adapter = card->master;
2939         u32 __iomem *intagg;
2940         u32 load = card->events;
2941         u32 level = 0;
2942
2943         intagg = &adapter->slic_regs->slic_intagg;
2944
2945         if ((adapter) && (adapter->state == ADAPT_UP) &&
2946             (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
2947                 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
2948                         if (adapter->linkspeed == LINK_1000MB)
2949                                 level = 100;
2950                         else {
2951                                 if (load > SLIC_LOAD_5)
2952                                         level = SLIC_INTAGG_5;
2953                                 else if (load > SLIC_LOAD_4)
2954                                         level = SLIC_INTAGG_4;
2955                                 else if (load > SLIC_LOAD_3)
2956                                         level = SLIC_INTAGG_3;
2957                                 else if (load > SLIC_LOAD_2)
2958                                         level = SLIC_INTAGG_2;
2959                                 else if (load > SLIC_LOAD_1)
2960                                         level = SLIC_INTAGG_1;
2961                                 else
2962                                         level = SLIC_INTAGG_0;
2963                         }
2964                         if (card->loadlevel_current != level) {
2965                                 card->loadlevel_current = level;
2966                                 slic_reg32_write(intagg, level, FLUSH);
2967                         }
2968                 } else {
2969                         if (load > SLIC_LOAD_5)
2970                                 level = SLIC_INTAGG_5;
2971                         else if (load > SLIC_LOAD_4)
2972                                 level = SLIC_INTAGG_4;
2973                         else if (load > SLIC_LOAD_3)
2974                                 level = SLIC_INTAGG_3;
2975                         else if (load > SLIC_LOAD_2)
2976                                 level = SLIC_INTAGG_2;
2977                         else if (load > SLIC_LOAD_1)
2978                                 level = SLIC_INTAGG_1;
2979                         else
2980                                 level = SLIC_INTAGG_0;
2981                         if (card->loadlevel_current != level) {
2982                                 card->loadlevel_current = level;
2983                                 slic_reg32_write(intagg, level, FLUSH);
2984                         }
2985                 }
2986         }
2987         card->events = 0;
2988         card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2989         add_timer(&card->loadtimer);
2990 }
2991
2992 static void slic_assert_fail(void)
2993 {
2994         u32 cpuid;
2995         u32 curr_pid;
2996         cpuid = smp_processor_id();
2997         curr_pid = current->pid;
2998
2999         DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3000 }
3001
3002 static int slic_upr_queue_request(struct adapter *adapter,
3003                            u32 upr_request,
3004                            u32 upr_data,
3005                            u32 upr_data_h,
3006                            u32 upr_buffer, u32 upr_buffer_h)
3007 {
3008         struct slic_upr *upr;
3009         struct slic_upr *uprqueue;
3010
3011         upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3012         if (!upr) {
3013                 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3014
3015                 return -ENOMEM;
3016         }
3017         upr->adapter = adapter->port;
3018         upr->upr_request = upr_request;
3019         upr->upr_data = upr_data;
3020         upr->upr_buffer = upr_buffer;
3021         upr->upr_data_h = upr_data_h;
3022         upr->upr_buffer_h = upr_buffer_h;
3023         upr->next = NULL;
3024         if (adapter->upr_list) {
3025                 uprqueue = adapter->upr_list;
3026
3027                 while (uprqueue->next)
3028                         uprqueue = uprqueue->next;
3029                 uprqueue->next = upr;
3030         } else {
3031                 adapter->upr_list = upr;
3032         }
3033         return STATUS_SUCCESS;
3034 }
3035
3036 static int slic_upr_request(struct adapter *adapter,
3037                      u32 upr_request,
3038                      u32 upr_data,
3039                      u32 upr_data_h,
3040                      u32 upr_buffer, u32 upr_buffer_h)
3041 {
3042         int status;
3043
3044         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3045         status = slic_upr_queue_request(adapter,
3046                                         upr_request,
3047                                         upr_data,
3048                                         upr_data_h, upr_buffer, upr_buffer_h);
3049         if (status != STATUS_SUCCESS) {
3050                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3051                                         adapter->upr_lock.flags);
3052                 return status;
3053         }
3054         slic_upr_start(adapter);
3055         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3056                                 adapter->upr_lock.flags);
3057         return STATUS_PENDING;
3058 }
3059
3060 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3061 {
3062         struct sliccard *card = adapter->card;
3063         struct slic_upr *upr;
3064
3065 /*    if (card->dump_requested) {
3066         DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3067                 isr);
3068       } */
3069         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3070         upr = adapter->upr_list;
3071         if (!upr) {
3072                 ASSERT(0);
3073                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3074                                         adapter->upr_lock.flags);
3075                 return;
3076         }
3077         adapter->upr_list = upr->next;
3078         upr->next = NULL;
3079         adapter->upr_busy = 0;
3080         ASSERT(adapter->port == upr->adapter);
3081         switch (upr->upr_request) {
3082         case SLIC_UPR_STATS:
3083                 {
3084                         struct slic_stats *slicstats =
3085                             (struct slic_stats *) &adapter->pshmem->inicstats;
3086                         struct slic_stats *newstats = slicstats;
3087                         struct slic_stats  *old = &adapter->inicstats_prev;
3088                         struct slicnet_stats *stst = &adapter->slic_stats;
3089
3090                         if (isr & ISR_UPCERR) {
3091                                 DBG_ERROR
3092                                     ("SLIC_UPR_STATS command failed isr[%x]\n",
3093                                      isr);
3094
3095                                 break;
3096                         }
3097 /*                      DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3098                                 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3099                                  __func__,
3100                              slicstats->rcv_unicasts100,
3101                              slicstats->rcv_bytes100,
3102                              slicstats->rcv_bytes100,
3103                              slicstats->rcv_tcp_bytes100,
3104                              slicstats->rcv_tcp_segs100,
3105                              slicstats->rcv_other_error100,
3106                              slicstats->rcv_drops100,
3107                              slicstats->xmit_unicasts100,
3108                              slicstats->xmit_bytes100,
3109                              slicstats->xmit_bytes100,
3110                              slicstats->xmit_tcp_bytes100,
3111                              slicstats->xmit_tcp_segs100,
3112                              slicstats->xmit_other_error100,
3113                              slicstats->xmit_collisions100);*/
3114                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3115                                         newstats->xmit_tcp_segs_gb,
3116                                         old->xmit_tcp_segs_gb);
3117
3118                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3119                                         newstats->xmit_tcp_bytes_gb,
3120                                         old->xmit_tcp_bytes_gb);
3121
3122                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3123                                         newstats->rcv_tcp_segs_gb,
3124                                         old->rcv_tcp_segs_gb);
3125
3126                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3127                                         newstats->rcv_tcp_bytes_gb,
3128                                         old->rcv_tcp_bytes_gb);
3129
3130                         UPDATE_STATS_GB(stst->iface.xmt_bytes,
3131                                         newstats->xmit_bytes_gb,
3132                                         old->xmit_bytes_gb);
3133
3134                         UPDATE_STATS_GB(stst->iface.xmt_ucast,
3135                                         newstats->xmit_unicasts_gb,
3136                                         old->xmit_unicasts_gb);
3137
3138                         UPDATE_STATS_GB(stst->iface.rcv_bytes,
3139                                         newstats->rcv_bytes_gb,
3140                                         old->rcv_bytes_gb);
3141
3142                         UPDATE_STATS_GB(stst->iface.rcv_ucast,
3143                                         newstats->rcv_unicasts_gb,
3144                                         old->rcv_unicasts_gb);
3145
3146                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3147                                         newstats->xmit_collisions_gb,
3148                                         old->xmit_collisions_gb);
3149
3150                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3151                                         newstats->xmit_excess_collisions_gb,
3152                                         old->xmit_excess_collisions_gb);
3153
3154                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3155                                         newstats->xmit_other_error_gb,
3156                                         old->xmit_other_error_gb);
3157
3158                         UPDATE_STATS_GB(stst->iface.rcv_errors,
3159                                         newstats->rcv_other_error_gb,
3160                                         old->rcv_other_error_gb);
3161
3162                         UPDATE_STATS_GB(stst->iface.rcv_discards,
3163                                         newstats->rcv_drops_gb,
3164                                         old->rcv_drops_gb);
3165
3166                         if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3167                                 adapter->rcv_drops +=
3168                                     (newstats->rcv_drops_gb -
3169                                      old->rcv_drops_gb);
3170                         }
3171                         memcpy(old, newstats, sizeof(struct slic_stats));
3172                         break;
3173                 }
3174         case SLIC_UPR_RLSR:
3175                 slic_link_upr_complete(adapter, isr);
3176                 break;
3177         case SLIC_UPR_RCONFIG:
3178                 break;
3179         case SLIC_UPR_RPHY:
3180                 ASSERT(0);
3181                 break;
3182         case SLIC_UPR_ENLB:
3183                 ASSERT(0);
3184                 break;
3185         case SLIC_UPR_ENCT:
3186                 ASSERT(0);
3187                 break;
3188         case SLIC_UPR_PDWN:
3189                 ASSERT(0);
3190                 break;
3191         case SLIC_UPR_PING:
3192                 card->pingstatus |= (isr & ISR_PINGDSMASK);
3193                 break;
3194         default:
3195                 ASSERT(0);
3196         }
3197         kfree(upr);
3198         slic_upr_start(adapter);
3199         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3200                                 adapter->upr_lock.flags);
3201 }
3202
3203 static void slic_upr_start(struct adapter *adapter)
3204 {
3205         struct slic_upr *upr;
3206         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3207 /*
3208     char * ptr1;
3209     char * ptr2;
3210     uint cmdoffset;
3211 */
3212         upr = adapter->upr_list;
3213         if (!upr)
3214                 return;
3215         if (adapter->upr_busy)
3216                 return;
3217         adapter->upr_busy = 1;
3218
3219         switch (upr->upr_request) {
3220         case SLIC_UPR_STATS:
3221                 if (upr->upr_data_h == 0) {
3222                         slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
3223                                          FLUSH);
3224                 } else {
3225                         slic_reg64_write(adapter, &slic_regs->slic_stats64,
3226                                          upr->upr_data,
3227                                          &slic_regs->slic_addr_upper,
3228                                          upr->upr_data_h, FLUSH);
3229                 }
3230                 break;
3231
3232         case SLIC_UPR_RLSR:
3233                 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
3234                                  &slic_regs->slic_addr_upper, upr->upr_data_h,
3235                                  FLUSH);
3236                 break;
3237
3238         case SLIC_UPR_RCONFIG:
3239                 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3240                 DBG_MSG("slic_reg64_write adapter[%p]\n"
3241                         "    a->slic_regs[%p] slic_regs[%p]\n"
3242                         "    &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3243                         "    upr[%p]\n"
3244                         "    uprdata[%x] uprdatah[%x]\n",
3245                         adapter, adapter->slic_regs, slic_regs,
3246                         &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3247                         upr, upr->upr_data, upr->upr_data_h);
3248                 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
3249                                  upr->upr_data, &slic_regs->slic_addr_upper,
3250                                  upr->upr_data_h, FLUSH);
3251                 break;
3252         case SLIC_UPR_PING:
3253                 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
3254                 break;
3255         default:
3256                 ASSERT(0);
3257         }
3258 }
3259
3260 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3261 {
3262         u32 linkstatus = adapter->pshmem->linkstatus;
3263         uint linkup;
3264         unsigned char linkspeed;
3265         unsigned char linkduplex;
3266
3267         DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n   adapter[%p](%d)\n",
3268                 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3269                 adapter->cardindex);
3270
3271         if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3272                 struct slic_shmem *pshmem;
3273
3274                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3275 #if defined(CONFIG_X86_64)
3276                 slic_upr_queue_request(adapter,
3277                                        SLIC_UPR_RLSR,
3278                                        SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3279                                        SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3280                                        0, 0);
3281 #elif defined(CONFIG_X86)
3282                 slic_upr_queue_request(adapter,
3283                                        SLIC_UPR_RLSR,
3284                                        (u32) &pshmem->linkstatus,
3285                                        SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3286 #else
3287                 Stop Compilation;
3288 #endif
3289                 return;
3290         }
3291         if (adapter->state != ADAPT_UP)
3292                 return;
3293
3294         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3295                || (adapter->devid == SLIC_2GB_DEVICE_ID));
3296
3297         linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3298         if (linkstatus & GIG_SPEED_1000) {
3299                 linkspeed = LINK_1000MB;
3300                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB  ",
3301                         __func__, adapter->netdev->name);
3302         } else if (linkstatus & GIG_SPEED_100) {
3303                 linkspeed = LINK_100MB;
3304                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB  ", __func__,
3305                         adapter->netdev->name);
3306         } else {
3307                 linkspeed = LINK_10MB;
3308                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB  ", __func__,
3309                         adapter->netdev->name);
3310         }
3311         if (linkstatus & GIG_FULLDUPLEX) {
3312                 linkduplex = LINK_FULLD;
3313                 DBG_MSG(" Duplex == FULL\n");
3314         } else {
3315                 linkduplex = LINK_HALFD;
3316                 DBG_MSG(" Duplex == HALF\n");
3317         }
3318
3319         if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3320                 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3321                         __func__, adapter->netdev->name, adapter->physport);
3322                 return;
3323         }
3324
3325         /* link up event, but nothing has changed */
3326         if ((adapter->linkstate == LINK_UP) &&
3327             (linkup == LINK_UP) &&
3328             (adapter->linkspeed == linkspeed) &&
3329             (adapter->linkduplex == linkduplex)) {
3330                 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3331                         __func__, adapter->netdev->name, adapter->physport);
3332                 return;
3333         }
3334
3335         /* link has changed at this point */
3336
3337         /* link has gone from up to down */
3338         if (linkup == LINK_DOWN) {
3339                 adapter->linkstate = LINK_DOWN;
3340                 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3341                         adapter->physport);
3342                 return;
3343         }
3344
3345         /* link has gone from down to up */
3346         adapter->linkspeed = linkspeed;
3347         adapter->linkduplex = linkduplex;
3348
3349         if (adapter->linkstate != LINK_UP) {
3350                 /* setup the mac */
3351                 DBG_MSG("%s call slic_config_set\n", __func__);
3352                 slic_config_set(adapter, true);
3353                 adapter->linkstate = LINK_UP;
3354                 DBG_MSG("\n(%s) Link UP: CALL netif_start_queue",
3355                         adapter->netdev->name);
3356                 netif_start_queue(adapter->netdev);
3357         }
3358 #if 1
3359         switch (linkspeed) {
3360         case LINK_1000MB:
3361                 DBG_MSG
3362                     ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB  duplex[%x]\n",
3363                      adapter->netdev->name, adapter->linkduplex);
3364                 break;
3365         case LINK_100MB:
3366                 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB  duplex[%x]\n",
3367                         adapter->netdev->name, adapter->linkduplex);
3368                 break;
3369         default:
3370                 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB  duplex[%x]\n",
3371                         adapter->netdev->name, adapter->linkduplex);
3372                 break;
3373         }
3374 #endif
3375 }
3376
3377 /*
3378  *  this is here to checksum the eeprom, there is some ucode bug
3379  *  which prevens us from using the ucode result.
3380  *  remove this once ucode is fixed.
3381  */
3382 static ushort slic_eeprom_cksum(char *m, int len)
3383 {
3384 #define ADDCARRY(x)  (x > 65535 ? x -= 65535 : x)
3385 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3386                 }
3387
3388         u16 *w;
3389         u32 sum = 0;
3390         u32 byte_swapped = 0;
3391         u32 w_int;
3392
3393         union {
3394                 char c[2];
3395                 ushort s;
3396         } s_util;
3397
3398         union {
3399                 ushort s[2];
3400                 int l;
3401         } l_util;
3402
3403         l_util.l = 0;
3404         s_util.s = 0;
3405
3406         w = (u16 *)m;
3407 #ifdef CONFIG_X86_64
3408         w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3409 #else
3410         w_int = (u32) (w);
3411 #endif
3412         if ((1 & w_int) && (len > 0)) {
3413                 REDUCE;
3414                 sum <<= 8;
3415                 s_util.c[0] = *(unsigned char *)w;
3416                 w = (u16 *)((char *)w + 1);
3417                 len--;
3418                 byte_swapped = 1;
3419         }
3420
3421         /* Unroll the loop to make overhead from branches &c small. */
3422         while ((len -= 32) >= 0) {
3423                 sum += w[0];
3424                 sum += w[1];
3425                 sum += w[2];
3426                 sum += w[3];
3427                 sum += w[4];
3428                 sum += w[5];
3429                 sum += w[6];
3430                 sum += w[7];
3431                 sum += w[8];
3432                 sum += w[9];
3433                 sum += w[10];
3434                 sum += w[11];
3435                 sum += w[12];
3436                 sum += w[13];
3437                 sum += w[14];
3438                 sum += w[15];
3439                 w = (u16 *)((ulong) w + 16);    /* verify */
3440         }
3441         len += 32;
3442         while ((len -= 8) >= 0) {
3443                 sum += w[0];
3444                 sum += w[1];
3445                 sum += w[2];
3446                 sum += w[3];
3447                 w = (u16 *)((ulong) w + 4);     /* verify */
3448         }
3449         len += 8;
3450         if (len != 0 || byte_swapped != 0) {
3451                 REDUCE;
3452                 while ((len -= 2) >= 0)
3453                         sum += *w++;    /* verify */
3454                 if (byte_swapped) {
3455                         REDUCE;
3456                         sum <<= 8;
3457                         byte_swapped = 0;
3458                         if (len == -1) {
3459                                 s_util.c[1] = *(char *) w;
3460                                 sum += s_util.s;
3461                                 len = 0;
3462                         } else {
3463                                 len = -1;
3464                         }
3465
3466                 } else if (len == -1) {
3467                         s_util.c[0] = *(char *) w;
3468                 }
3469
3470                 if (len == -1) {
3471                         s_util.c[1] = 0;
3472                         sum += s_util.s;
3473                 }
3474         }
3475         REDUCE;
3476         return (ushort) sum;
3477 }
3478
3479 static int slic_rspqueue_init(struct adapter *adapter)
3480 {
3481         int i;
3482         struct slic_rspqueue *rspq = &adapter->rspqueue;
3483         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3484         u32 paddrh = 0;
3485
3486         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3487                 adapter->netdev->name, adapter);
3488         ASSERT(adapter->state == ADAPT_DOWN);
3489         memset(rspq, 0, sizeof(struct slic_rspqueue));
3490
3491         rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3492
3493         for (i = 0; i < rspq->num_pages; i++) {
3494                 rspq->vaddr[i] =
3495                     pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3496                                          &rspq->paddr[i]);
3497                 if (!rspq->vaddr[i]) {
3498                         DBG_ERROR
3499                             ("rspqueue_init_failed  pci_alloc_consistent\n");
3500                         slic_rspqueue_free(adapter);
3501                         return STATUS_FAILURE;
3502                 }
3503 #ifndef CONFIG_X86_64
3504                 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3505                        (u32) rspq->vaddr[i]);
3506                 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3507                        (u32) rspq->paddr[i]);
3508 #endif
3509                 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3510 /*              DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3511                         "vaddr[%p]\n",
3512                         __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3513
3514                 if (paddrh == 0) {
3515                         slic_reg32_write(&slic_regs->slic_rbar,
3516                                 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3517                                 DONT_FLUSH);
3518                 } else {
3519                         slic_reg64_write(adapter, &slic_regs->slic_rbar64,
3520                                 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3521                                 &slic_regs->slic_addr_upper,
3522                                 paddrh, DONT_FLUSH);
3523                 }
3524         }
3525         rspq->offset = 0;
3526         rspq->pageindex = 0;
3527         rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3528         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3529                 adapter->netdev->name, adapter);
3530         return STATUS_SUCCESS;
3531 }
3532
3533 static int slic_rspqueue_reset(struct adapter *adapter)
3534 {
3535         struct slic_rspqueue *rspq = &adapter->rspqueue;
3536
3537         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3538                 adapter->netdev->name, adapter);
3539         ASSERT(adapter->state == ADAPT_DOWN);
3540         ASSERT(rspq);
3541
3542         DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3543                 "                             offset[%x]\n"
3544                 "                             pageix[%x]\n"
3545                 "                             rspbuf[%p]\n",
3546                 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3547
3548         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3549                 adapter->netdev->name, adapter);
3550         return STATUS_SUCCESS;
3551 }
3552
3553 static void slic_rspqueue_free(struct adapter *adapter)
3554 {
3555         int i;
3556         struct slic_rspqueue *rspq = &adapter->rspqueue;
3557
3558         DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3559                 __func__, adapter, adapter->physport, rspq);
3560         for (i = 0; i < rspq->num_pages; i++) {
3561                 if (rspq->vaddr[i]) {
3562                         DBG_MSG
3563                             ("slicoss:  pci_free_consistent rspq->vaddr[%p] \
3564                             paddr[%p]\n",
3565                              rspq->vaddr[i], (void *) rspq->paddr[i]);
3566                         pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3567                                             rspq->vaddr[i], rspq->paddr[i]);
3568                 }
3569                 rspq->vaddr[i] = NULL;
3570                 rspq->paddr[i] = 0;
3571         }
3572         rspq->offset = 0;
3573         rspq->pageindex = 0;
3574         rspq->rspbuf = NULL;
3575 }
3576
3577 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3578 {
3579         struct slic_rspqueue *rspq = &adapter->rspqueue;
3580         struct slic_rspbuf *buf;
3581
3582         if (!(rspq->rspbuf->status))
3583                 return NULL;
3584
3585         buf = rspq->rspbuf;
3586 #ifndef CONFIG_X86_64
3587         ASSERT((buf->status & 0xFFFFFFE0) == 0);
3588 #endif
3589         ASSERT(buf->hosthandle);
3590         if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3591                 rspq->rspbuf++;
3592 #ifndef CONFIG_X86_64
3593                 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3594                        (u32) rspq->rspbuf);
3595 #endif
3596         } else {
3597                 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3598                 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
3599                         (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3600                         &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3601                 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3602                 rspq->offset = 0;
3603                 rspq->rspbuf = (struct slic_rspbuf *)
3604                                                 rspq->vaddr[rspq->pageindex];
3605 #ifndef CONFIG_X86_64
3606                 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3607                        (u32) rspq->rspbuf);
3608 #endif
3609         }
3610 #ifndef CONFIG_X86_64
3611         ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3612 #endif
3613         return buf;
3614 }
3615
3616 static void slic_cmdqmem_init(struct adapter *adapter)
3617 {
3618         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3619
3620         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3621 }
3622
3623 static void slic_cmdqmem_free(struct adapter *adapter)
3624 {
3625         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3626         int i;
3627
3628         DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3629                 __func__, adapter, adapter->physport, cmdqmem);
3630         for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3631                 if (cmdqmem->pages[i]) {
3632                         DBG_MSG("slicoss: %s Deallocate page  CmdQPage[%p]\n",
3633                                 __func__, (void *) cmdqmem->pages[i]);
3634                         pci_free_consistent(adapter->pcidev,
3635                                             PAGE_SIZE,
3636                                             (void *) cmdqmem->pages[i],
3637                                             cmdqmem->dma_pages[i]);
3638                 }
3639         }
3640         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3641 }
3642
3643 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3644 {
3645         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3646         u32 *pageaddr;
3647
3648         if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3649                 return NULL;
3650         pageaddr = pci_alloc_consistent(adapter->pcidev,
3651                                         PAGE_SIZE,
3652                                         &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3653         if (!pageaddr)
3654                 return NULL;
3655 #ifndef CONFIG_X86_64
3656         ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3657 #endif
3658         cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3659         cmdqmem->pagecnt++;
3660         return pageaddr;
3661 }
3662
3663 static int slic_cmdq_init(struct adapter *adapter)
3664 {
3665         int i;
3666         u32 *pageaddr;
3667
3668         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3669         ASSERT(adapter->state == ADAPT_DOWN);
3670         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3671         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3672         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3673         spin_lock_init(&adapter->cmdq_all.lock.lock);
3674         spin_lock_init(&adapter->cmdq_free.lock.lock);
3675         spin_lock_init(&adapter->cmdq_done.lock.lock);
3676         slic_cmdqmem_init(adapter);
3677         adapter->slic_handle_ix = 1;
3678         for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3679                 pageaddr = slic_cmdqmem_addpage(adapter);
3680 #ifndef CONFIG_X86_64
3681                 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3682 #endif
3683                 if (!pageaddr) {
3684                         slic_cmdq_free(adapter);
3685                         return STATUS_FAILURE;
3686                 }
3687                 slic_cmdq_addcmdpage(adapter, pageaddr);
3688         }
3689         adapter->slic_handle_ix = 1;
3690         DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3691
3692         return STATUS_SUCCESS;
3693 }
3694
3695 static void slic_cmdq_free(struct adapter *adapter)
3696 {
3697         struct slic_hostcmd *cmd;
3698
3699         DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3700                 __func__, adapter, adapter->physport);
3701         cmd = adapter->cmdq_all.head;
3702         while (cmd) {
3703                 if (cmd->busy) {
3704                         struct sk_buff *tempskb;
3705
3706                         tempskb = cmd->skb;
3707                         if (tempskb) {
3708                                 cmd->skb = NULL;
3709                                 dev_kfree_skb_irq(tempskb);
3710                         }
3711                 }
3712                 cmd = cmd->next_all;
3713         }
3714         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3715         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3716         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3717         slic_cmdqmem_free(adapter);
3718 }
3719
3720 static void slic_cmdq_reset(struct adapter *adapter)
3721 {
3722         struct slic_hostcmd *hcmd;
3723         struct sk_buff *skb;
3724         u32 outstanding;
3725
3726         DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3727         spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3728                         adapter->cmdq_free.lock.flags);
3729         spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3730                         adapter->cmdq_done.lock.flags);
3731         outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3732         outstanding -= adapter->cmdq_free.count;
3733         hcmd = adapter->cmdq_all.head;
3734         while (hcmd) {
3735                 if (hcmd->busy) {
3736                         skb = hcmd->skb;
3737                         ASSERT(skb);
3738                         DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3739                                 hcmd, skb);
3740                         hcmd->busy = 0;
3741                         hcmd->skb = NULL;
3742                         DBG_MSG(" Free SKB\n");
3743                         dev_kfree_skb_irq(skb);
3744                 }
3745                 hcmd = hcmd->next_all;
3746         }
3747         adapter->cmdq_free.count = 0;
3748         adapter->cmdq_free.head = NULL;
3749         adapter->cmdq_free.tail = NULL;
3750         adapter->cmdq_done.count = 0;
3751         adapter->cmdq_done.head = NULL;
3752         adapter->cmdq_done.tail = NULL;
3753         adapter->cmdq_free.head = adapter->cmdq_all.head;
3754         hcmd = adapter->cmdq_all.head;
3755         while (hcmd) {
3756                 adapter->cmdq_free.count++;
3757                 hcmd->next = hcmd->next_all;
3758                 hcmd = hcmd->next_all;
3759         }
3760         if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
3761                 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
3762                           adapter->cmdq_free.count, adapter->cmdq_all.count);
3763         }
3764         spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
3765                                 adapter->cmdq_done.lock.flags);
3766         spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
3767                                 adapter->cmdq_free.lock.flags);
3768         DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
3769 }
3770
3771 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3772 {
3773         struct slic_hostcmd *cmd;
3774         struct slic_hostcmd *prev;
3775         struct slic_hostcmd *tail;
3776         struct slic_cmdqueue *cmdq;
3777         int cmdcnt;
3778         void *cmdaddr;
3779         ulong phys_addr;
3780         u32 phys_addrl;
3781         u32 phys_addrh;
3782         struct slic_handle *pslic_handle;
3783
3784         cmdaddr = page;
3785         cmd = (struct slic_hostcmd *)cmdaddr;
3786 /*  DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
3787     adapter->pfree_slic_handles); */
3788         cmdcnt = 0;
3789
3790         phys_addr = virt_to_bus((void *)page);
3791         phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
3792         phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
3793
3794         prev = NULL;
3795         tail = cmd;
3796         while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
3797                (adapter->slic_handle_ix < 256)) {
3798                 /* Allocate and initialize a SLIC_HANDLE for this command */
3799                 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
3800                 if (pslic_handle == NULL)
3801                         ASSERT(0);
3802                 ASSERT(pslic_handle ==
3803                        &adapter->slic_handles[pslic_handle->token.
3804                                               handle_index]);
3805                 pslic_handle->type = SLIC_HANDLE_CMD;
3806                 pslic_handle->address = (void *) cmd;
3807                 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
3808                 pslic_handle->other_handle = NULL;
3809                 pslic_handle->next = NULL;
3810
3811                 cmd->pslic_handle = pslic_handle;
3812                 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
3813                 cmd->busy = false;
3814                 cmd->paddrl = phys_addrl;
3815                 cmd->paddrh = phys_addrh;
3816                 cmd->next_all = prev;
3817                 cmd->next = prev;
3818                 prev = cmd;
3819                 phys_addrl += SLIC_HOSTCMD_SIZE;
3820                 cmdaddr += SLIC_HOSTCMD_SIZE;
3821
3822                 cmd = (struct slic_hostcmd *)cmdaddr;
3823                 cmdcnt++;
3824         }
3825
3826         cmdq = &adapter->cmdq_all;
3827         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
3828         tail->next_all = cmdq->head;
3829         ASSERT(VALID_ADDRESS(prev));
3830         cmdq->head = prev;
3831         cmdq = &adapter->cmdq_free;
3832         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3833         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
3834         tail->next = cmdq->head;
3835         ASSERT(VALID_ADDRESS(prev));
3836         cmdq->head = prev;
3837         spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3838 }
3839
3840 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
3841 {
3842         struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
3843         struct slic_hostcmd *cmd = NULL;
3844
3845 lock_and_retry:
3846         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3847 retry:
3848         cmd = cmdq->head;
3849         if (cmd) {
3850                 cmdq->head = cmd->next;
3851                 cmdq->count--;
3852                 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3853         } else {
3854                 slic_cmdq_getdone(adapter);
3855                 cmd = cmdq->head;
3856                 if (cmd) {
3857                         goto retry;
3858                 } else {
3859                         u32 *pageaddr;
3860
3861                         spin_unlock_irqrestore(&cmdq->lock.lock,
3862                                                 cmdq->lock.flags);
3863                         pageaddr = slic_cmdqmem_addpage(adapter);
3864                         if (pageaddr) {
3865                                 slic_cmdq_addcmdpage(adapter, pageaddr);
3866                                 goto lock_and_retry;
3867                         }
3868                 }
3869         }
3870         return cmd;
3871 }
3872
3873 static void slic_cmdq_getdone(struct adapter *adapter)
3874 {
3875         struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
3876         struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
3877
3878         ASSERT(free_cmdq->head == NULL);
3879         spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3880         ASSERT(VALID_ADDRESS(done_cmdq->head));
3881
3882         free_cmdq->head = done_cmdq->head;
3883         free_cmdq->count = done_cmdq->count;
3884         done_cmdq->head = NULL;
3885         done_cmdq->tail = NULL;
3886         done_cmdq->count = 0;
3887         spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3888 }
3889
3890 static void slic_cmdq_putdone_irq(struct adapter *adapter,
3891                                 struct slic_hostcmd *cmd)
3892 {
3893         struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
3894
3895         spin_lock(&cmdq->lock.lock);
3896         cmd->busy = 0;
3897         ASSERT(VALID_ADDRESS(cmdq->head));
3898         cmd->next = cmdq->head;
3899         ASSERT(VALID_ADDRESS(cmd));
3900         cmdq->head = cmd;
3901         cmdq->count++;
3902         if ((adapter->xmitq_full) && (cmdq->count > 10))
3903                 netif_wake_queue(adapter->netdev);
3904         spin_unlock(&cmdq->lock.lock);
3905 }
3906
3907 static int slic_rcvqueue_init(struct adapter *adapter)
3908 {
3909         int i, count;
3910         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3911
3912         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3913         ASSERT(adapter->state == ADAPT_DOWN);
3914         rcvq->tail = NULL;
3915         rcvq->head = NULL;
3916         rcvq->size = SLIC_RCVQ_ENTRIES;
3917         rcvq->errors = 0;
3918         rcvq->count = 0;
3919         i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
3920         count = 0;
3921         while (i) {
3922                 count += slic_rcvqueue_fill(adapter);
3923                 i--;
3924         }
3925         if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
3926                 slic_rcvqueue_free(adapter);
3927                 return STATUS_FAILURE;
3928         }
3929         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
3930         return STATUS_SUCCESS;
3931 }
3932
3933 static int slic_rcvqueue_reset(struct adapter *adapter)
3934 {
3935         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3936
3937         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3938         ASSERT(adapter->state == ADAPT_DOWN);
3939         ASSERT(rcvq);
3940
3941         DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
3942                 "                             count[%x]\n"
3943                 "                             head[%p]\n"
3944                 "                             tail[%p]\n",
3945                 rcvq, rcvq->count, rcvq->head, rcvq->tail);
3946
3947         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
3948         return STATUS_SUCCESS;
3949 }
3950
3951 static void slic_rcvqueue_free(struct adapter *adapter)
3952 {
3953         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3954         struct sk_buff *skb;
3955
3956         while (rcvq->head) {
3957                 skb = rcvq->head;
3958                 rcvq->head = rcvq->head->next;
3959                 dev_kfree_skb(skb);
3960         }
3961         rcvq->tail = NULL;
3962         rcvq->head = NULL;
3963         rcvq->count = 0;
3964 }
3965
3966 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
3967 {
3968         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3969         struct sk_buff *skb;
3970         struct slic_rcvbuf *rcvbuf;
3971         int count;
3972
3973         if (rcvq->count) {
3974                 skb = rcvq->head;
3975                 rcvbuf = (struct slic_rcvbuf *)skb->head;
3976                 ASSERT(rcvbuf);
3977
3978                 if (rcvbuf->status & IRHDDR_SVALID) {
3979                         rcvq->head = rcvq->head->next;
3980                         skb->next = NULL;
3981                         rcvq->count--;
3982                 } else {
3983                         skb = NULL;
3984                 }
3985         } else {
3986                 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
3987                           adapter, rcvq, rcvq->count);
3988                 skb = NULL;
3989         }
3990         while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
3991                 count = slic_rcvqueue_fill(adapter);
3992                 if (!count)
3993                         break;
3994         }
3995         if (skb)
3996                 rcvq->errors = 0;
3997         return skb;
3998 }
3999
4000 static int slic_rcvqueue_fill(struct adapter *adapter)
4001 {
4002         void *paddr;
4003         u32 paddrl;
4004         u32 paddrh;
4005         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4006         int i = 0;
4007
4008         while (i < SLIC_RCVQ_FILLENTRIES) {
4009                 struct slic_rcvbuf *rcvbuf;
4010                 struct sk_buff *skb;
4011 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4012 retry_rcvqfill:
4013 #endif
4014                 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4015                 if (skb) {
4016                         paddr = (void *)pci_map_single(adapter->pcidev,
4017                                                           skb->data,
4018                                                           SLIC_RCVQ_RCVBUFSIZE,
4019                                                           PCI_DMA_FROMDEVICE);
4020                         paddrl = SLIC_GET_ADDR_LOW(paddr);
4021                         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4022
4023                         skb->len = SLIC_RCVBUF_HEADSIZE;
4024                         rcvbuf = (struct slic_rcvbuf *)skb->head;
4025                         rcvbuf->status = 0;
4026                         skb->next = NULL;
4027 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4028                         if (paddrl == 0) {
4029                                 DBG_ERROR
4030                                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4031                                      "skb[%p]   PROBLEM\n"
4032                                      "         skbdata[%p]\n"
4033                                      "         skblen[%x]\n"
4034                                      "         paddr[%p]\n"
4035                                      "         paddrl[%x]\n"
4036                                      "         paddrh[%x]\n", __func__, skb,
4037                                      skb->data, skb->len, paddr, paddrl,
4038                                      paddrh);
4039                                 DBG_ERROR("         rcvq->head[%p]\n"
4040                                           "         rcvq->tail[%p]\n"
4041                                           "         rcvq->count[%x]\n",
4042                                           rcvq->head, rcvq->tail, rcvq->count);
4043                                 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4044                                 goto retry_rcvqfill;
4045                         }
4046 #else
4047                         if (paddrl == 0) {
4048                                 DBG_ERROR
4049                                     ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4050                                      "skb[%p]  GIVE TO CARD ANYWAY\n"
4051                                      "         skbdata[%p]\n"
4052                                      "         paddr[%p]\n"
4053                                      "         paddrl[%x]\n"
4054                                      "         paddrh[%x]\n", __func__, skb,
4055                                      skb->data, paddr, paddrl, paddrh);
4056                         }
4057 #endif
4058                         if (paddrh == 0) {
4059                                 slic_reg32_write(&adapter->slic_regs->slic_hbar,
4060                                                  (u32)paddrl, DONT_FLUSH);
4061                         } else {
4062                                 slic_reg64_write(adapter,
4063                                         &adapter->slic_regs->slic_hbar64,
4064                                         paddrl,
4065                                         &adapter->slic_regs->slic_addr_upper,
4066                                         paddrh, DONT_FLUSH);
4067                         }
4068                         if (rcvq->head)
4069                                 rcvq->tail->next = skb;
4070                         else
4071                                 rcvq->head = skb;
4072                         rcvq->tail = skb;
4073                         rcvq->count++;
4074                         i++;
4075                 } else {
4076                         DBG_ERROR
4077                             ("%s slic_rcvqueue_fill could only get [%d] "
4078                              "skbuffs\n",
4079                              adapter->netdev->name, i);
4080                         break;
4081                 }
4082         }
4083         return i;
4084 }
4085
4086 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4087 {
4088         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4089         void *paddr;
4090         u32 paddrl;
4091         u32 paddrh;
4092         struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4093
4094         ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4095
4096         paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4097                                   SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4098         rcvbuf->status = 0;
4099         skb->next = NULL;
4100
4101         paddrl = SLIC_GET_ADDR_LOW(paddr);
4102         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4103
4104         if (paddrl == 0) {
4105                 DBG_ERROR
4106                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p]   PROBLEM\n"
4107                      "         skbdata[%p]\n" "         skblen[%x]\n"
4108                      "         paddr[%p]\n" "         paddrl[%x]\n"
4109                      "         paddrh[%x]\n", __func__, skb, skb->data,
4110                      skb->len, paddr, paddrl, paddrh);
4111                 DBG_ERROR("         rcvq->head[%p]\n"
4112                           "         rcvq->tail[%p]\n"
4113                           "         rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4114                           rcvq->count);
4115         }
4116         if (paddrh == 0) {
4117                 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
4118                                  DONT_FLUSH);
4119         } else {
4120                 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
4121                                  paddrl, &adapter->slic_regs->slic_addr_upper,
4122                                  paddrh, DONT_FLUSH);
4123         }
4124         if (rcvq->head)
4125                 rcvq->tail->next = skb;
4126         else
4127                 rcvq->head = skb;
4128         rcvq->tail = skb;
4129         rcvq->count++;
4130         return rcvq->count;
4131 }
4132
4133 static int slic_debug_card_show(struct seq_file *seq, void *v)
4134 {
4135 #ifdef MOOKTODO
4136         int i;
4137         struct sliccard *card = seq->private;
4138         struct slic_config *config = &card->config;
4139         unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4140         unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4141 #endif
4142
4143         seq_printf(seq, "driver_version           : %s\n", slic_proc_version);
4144         seq_printf(seq, "Microcode versions:           \n");
4145         seq_printf(seq, "    Gigabit (gb)         : %s %s\n",
4146                     MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4147         seq_printf(seq, "    Gigabit Receiver     : %s %s\n",
4148                     GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4149         seq_printf(seq, "Vendor                   : %s\n", slic_vendor);
4150         seq_printf(seq, "Product Name             : %s\n", slic_product_name);
4151 #ifdef MOOKTODO
4152         seq_printf(seq, "VendorId                 : %4.4X\n",
4153                     config->VendorId);
4154         seq_printf(seq, "DeviceId                 : %4.4X\n",
4155                     config->DeviceId);
4156         seq_printf(seq, "RevisionId               : %2.2x\n",
4157                     config->RevisionId);
4158         seq_printf(seq, "Bus    #                 : %d\n", card->busnumber);
4159         seq_printf(seq, "Device #                 : %d\n", card->slotnumber);
4160         seq_printf(seq, "Interfaces               : %d\n", card->card_size);
4161         seq_printf(seq, "     Initialized         : %d\n",
4162                     card->adapters_activated);
4163         seq_printf(seq, "     Allocated           : %d\n",
4164                     card->adapters_allocated);
4165         ASSERT(card->card_size <= SLIC_NBR_MACS);
4166         for (i = 0; i < card->card_size; i++) {
4167                 seq_printf(seq,
4168                            "     MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4169                            i, config->macinfo[i].macaddrA[0],
4170                            config->macinfo[i].macaddrA[1],
4171                            config->macinfo[i].macaddrA[2],
4172                            config->macinfo[i].macaddrA[3],
4173                            config->macinfo[i].macaddrA[4],
4174                            config->macinfo[i].macaddrA[5]);
4175         }
4176         seq_printf(seq, "     IF  Init State Duplex/Speed irq\n");
4177         seq_printf(seq, "     -------------------------------\n");
4178         for (i = 0; i < card->adapters_allocated; i++) {
4179                 struct adapter *adapter;
4180
4181                 adapter = card->adapter[i];
4182                 if (adapter) {
4183                         seq_printf(seq,
4184                                     "     %d   %d   %s  %s  %s    0x%X\n",
4185                                     adapter->physport, adapter->state,
4186                                     SLIC_LINKSTATE(adapter->linkstate),
4187                                     SLIC_DUPLEX(adapter->linkduplex),
4188                                     SLIC_SPEED(adapter->linkspeed),
4189                                     (uint) adapter->irq);
4190                 }
4191         }
4192         seq_printf(seq, "Generation #             : %4.4X\n", card->gennumber);
4193         seq_printf(seq, "RcvQ max entries         : %4.4X\n",
4194                     SLIC_RCVQ_ENTRIES);
4195         seq_printf(seq, "Ping Status              : %8.8X\n",
4196                     card->pingstatus);
4197         seq_printf(seq, "Minimum grant            : %2.2x\n",
4198                     config->MinGrant);
4199         seq_printf(seq, "Maximum Latency          : %2.2x\n", config->MaxLat);
4200         seq_printf(seq, "PciStatus                : %4.4x\n",
4201                     config->Pcistatus);
4202         seq_printf(seq, "Debug Device Id          : %4.4x\n",
4203                     config->DbgDevId);
4204         seq_printf(seq, "DRAM ROM Function        : %4.4x\n",
4205                     config->DramRomFn);
4206         seq_printf(seq, "Network interface Pin 1  : %2.2x\n",
4207                     config->NetIntPin1);
4208         seq_printf(seq, "Network interface Pin 2  : %2.2x\n",
4209                     config->NetIntPin1);
4210         seq_printf(seq, "Network interface Pin 3  : %2.2x\n",
4211                     config->NetIntPin1);
4212         seq_printf(seq, "PM capabilities          : %4.4X\n",
4213                     config->PMECapab);
4214         seq_printf(seq, "Network Clock Controls   : %4.4X\n",
4215                     config->NwClkCtrls);
4216
4217         switch (config->FruFormat) {
4218         case ATK_FRU_FORMAT:
4219                 {
4220                         seq_printf(seq,
4221                             "Vendor                   : Alacritech, Inc.\n");
4222                         seq_printf(seq,
4223                             "Assembly #               : %c%c%c%c%c%c\n",
4224                                     fru[0], fru[1], fru[2], fru[3], fru[4],
4225                                     fru[5]);
4226                         seq_printf(seq,
4227                                     "Revision #               : %c%c\n",
4228                                     fru[6], fru[7]);
4229
4230                         if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4231                                 seq_printf(seq,
4232                                             "Serial   #               : "
4233                                             "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4234                                             fru[8], fru[9], fru[10],
4235                                             fru[11], fru[12], fru[13],
4236                                             fru[16], fru[17], fru[18],
4237                                             fru[19], fru[20], fru[21]);
4238                         } else {
4239                                 seq_printf(seq,
4240                                             "Serial   #               : "
4241                                             "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4242                                             fru[8], fru[9], fru[10],
4243                                             fru[11], fru[12], fru[13],
4244                                             fru[14], fru[15], fru[16],
4245                                             fru[17], fru[18], fru[19],
4246                                             fru[20], fru[21]);
4247                         }
4248                         break;
4249                 }
4250
4251         default:
4252                 {
4253                         seq_printf(seq,
4254                             "Vendor                   : Alacritech, Inc.\n");
4255                         seq_printf(seq,
4256                             "Serial   #               : Empty FRU\n");
4257                         break;
4258                 }
4259         }
4260
4261         switch (config->OEMFruFormat) {
4262         case VENDOR1_FRU_FORMAT:
4263                 {
4264                         seq_printf(seq, "FRU Information:\n");
4265                         seq_printf(seq, "    Commodity #          : %c\n",
4266                                     oemfru[0]);
4267                         seq_printf(seq,
4268                                     "    Assembly #           : %c%c%c%c\n",
4269                                     oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4270                         seq_printf(seq,
4271                                     "    Revision #           : %c%c\n",
4272                                     oemfru[5], oemfru[6]);
4273                         seq_printf(seq,
4274                                     "    Supplier #           : %c%c\n",
4275                                     oemfru[7], oemfru[8]);
4276                         seq_printf(seq,
4277                                     "    Date                 : %c%c\n",
4278                                     oemfru[9], oemfru[10]);
4279                         seq_sprintf(seq,
4280                                     "    Sequence #           : %c%c%c\n",
4281                                     oemfru[11], oemfru[12], oemfru[13]);
4282                         break;
4283                 }
4284
4285         case VENDOR2_FRU_FORMAT:
4286                 {
4287                         seq_printf(seq, "FRU Information:\n");
4288                         seq_printf(seq,
4289                                     "    Part     #           : "
4290                                     "%c%c%c%c%c%c%c%c\n",
4291                                     oemfru[0], oemfru[1], oemfru[2],
4292                                     oemfru[3], oemfru[4], oemfru[5],
4293                                     oemfru[6], oemfru[7]);
4294                         seq_printf(seq,
4295                                     "    Supplier #           : %c%c%c%c%c\n",
4296                                     oemfru[8], oemfru[9], oemfru[10],
4297                                     oemfru[11], oemfru[12]);
4298                         seq_printf(seq,
4299                                     "    Date                 : %c%c%c\n",
4300                                     oemfru[13], oemfru[14], oemfru[15]);
4301                         seq_sprintf(seq,
4302                                     "    Sequence #           : %c%c%c%c\n",
4303                                     oemfru[16], oemfru[17], oemfru[18],
4304                                     oemfru[19]);
4305                         break;
4306                 }
4307
4308         case VENDOR3_FRU_FORMAT:
4309                 {
4310                         seq_printf(seq, "FRU Information:\n");
4311                 }
4312
4313         case VENDOR4_FRU_FORMAT:
4314                 {
4315                         seq_printf(seq, "FRU Information:\n");
4316                         seq_printf(seq,
4317                                     "    FRU Number           : "
4318                                     "%c%c%c%c%c%c%c%c\n",
4319                                     oemfru[0], oemfru[1], oemfru[2],
4320                                     oemfru[3], oemfru[4], oemfru[5],
4321                                     oemfru[6], oemfru[7]);
4322                         seq_sprintf(seq,
4323                                     "    Part Number          : "
4324                                     "%c%c%c%c%c%c%c%c\n",
4325                                     oemfru[8], oemfru[9], oemfru[10],
4326                                     oemfru[11], oemfru[12], oemfru[13],
4327                                     oemfru[14], oemfru[15]);
4328                         seq_printf(seq,
4329                                     "    EC Level             : "
4330                                     "%c%c%c%c%c%c%c%c\n",
4331                                     oemfru[16], oemfru[17], oemfru[18],
4332                                     oemfru[19], oemfru[20], oemfru[21],
4333                                     oemfru[22], oemfru[23]);
4334                         break;
4335                 }
4336
4337         default:
4338                 break;
4339         }
4340 #endif
4341
4342         return 0;
4343 }
4344
4345 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4346 {
4347         struct adapter *adapter = seq->private;
4348
4349         if ((adapter->netdev) && (adapter->netdev->name)) {
4350                 seq_printf(seq, "info: interface          : %s\n",
4351                             adapter->netdev->name);
4352         }
4353         seq_printf(seq, "info: status             : %s\n",
4354                 SLIC_LINKSTATE(adapter->linkstate));
4355         seq_printf(seq, "info: port               : %d\n",
4356                 adapter->physport);
4357         seq_printf(seq, "info: speed              : %s\n",
4358                 SLIC_SPEED(adapter->linkspeed));
4359         seq_printf(seq, "info: duplex             : %s\n",
4360                 SLIC_DUPLEX(adapter->linkduplex));
4361         seq_printf(seq, "info: irq                : 0x%X\n",
4362                 (uint) adapter->irq);
4363         seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4364                 adapter->card->loadlevel_current);
4365         seq_printf(seq, "info: RcvQ max entries   : %4.4X\n",
4366                 SLIC_RCVQ_ENTRIES);
4367         seq_printf(seq, "info: RcvQ current       : %4.4X\n",
4368                     adapter->rcvqueue.count);
4369         seq_printf(seq, "rx stats: packets                  : %8.8lX\n",
4370                     adapter->stats.rx_packets);
4371         seq_printf(seq, "rx stats: bytes                    : %8.8lX\n",
4372                     adapter->stats.rx_bytes);
4373         seq_printf(seq, "rx stats: broadcasts               : %8.8X\n",
4374                     adapter->rcv_broadcasts);
4375         seq_printf(seq, "rx stats: multicasts               : %8.8X\n",
4376                     adapter->rcv_multicasts);
4377         seq_printf(seq, "rx stats: unicasts                 : %8.8X\n",
4378                     adapter->rcv_unicasts);
4379         seq_printf(seq, "rx stats: errors                   : %8.8X\n",
4380                     (u32) adapter->slic_stats.iface.rcv_errors);
4381         seq_printf(seq, "rx stats: Missed errors            : %8.8X\n",
4382                     (u32) adapter->slic_stats.iface.rcv_discards);
4383         seq_printf(seq, "rx stats: drops                    : %8.8X\n",
4384                         (u32) adapter->rcv_drops);
4385         seq_printf(seq, "tx stats: packets                  : %8.8lX\n",
4386                         adapter->stats.tx_packets);
4387         seq_printf(seq, "tx stats: bytes                    : %8.8lX\n",
4388                         adapter->stats.tx_bytes);
4389         seq_printf(seq, "tx stats: errors                   : %8.8X\n",
4390                         (u32) adapter->slic_stats.iface.xmt_errors);
4391         seq_printf(seq, "rx stats: multicasts               : %8.8lX\n",
4392                         adapter->stats.multicast);
4393         seq_printf(seq, "tx stats: collision errors         : %8.8X\n",
4394                         (u32) adapter->slic_stats.iface.xmit_collisions);
4395         seq_printf(seq, "perf: Max rcv frames/isr           : %8.8X\n",
4396                         adapter->max_isr_rcvs);
4397         seq_printf(seq, "perf: Rcv interrupt yields         : %8.8X\n",
4398                         adapter->rcv_interrupt_yields);
4399         seq_printf(seq, "perf: Max xmit complete/isr        : %8.8X\n",
4400                         adapter->max_isr_xmits);
4401         seq_printf(seq, "perf: error interrupts             : %8.8X\n",
4402                         adapter->error_interrupts);
4403         seq_printf(seq, "perf: error rmiss interrupts       : %8.8X\n",
4404                         adapter->error_rmiss_interrupts);
4405         seq_printf(seq, "perf: rcv interrupts               : %8.8X\n",
4406                         adapter->rcv_interrupts);
4407         seq_printf(seq, "perf: xmit interrupts              : %8.8X\n",
4408                         adapter->xmit_interrupts);
4409         seq_printf(seq, "perf: link event interrupts        : %8.8X\n",
4410                         adapter->linkevent_interrupts);
4411         seq_printf(seq, "perf: UPR interrupts               : %8.8X\n",
4412                         adapter->upr_interrupts);
4413         seq_printf(seq, "perf: interrupt count              : %8.8X\n",
4414                         adapter->num_isrs);
4415         seq_printf(seq, "perf: false interrupts             : %8.8X\n",
4416                         adapter->false_interrupts);
4417         seq_printf(seq, "perf: All register writes          : %8.8X\n",
4418                         adapter->all_reg_writes);
4419         seq_printf(seq, "perf: ICR register writes          : %8.8X\n",
4420                         adapter->icr_reg_writes);
4421         seq_printf(seq, "perf: ISR register writes          : %8.8X\n",
4422                         adapter->isr_reg_writes);
4423         seq_printf(seq, "ifevents: overflow 802 errors      : %8.8X\n",
4424                         adapter->if_events.oflow802);
4425         seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4426                         adapter->if_events.Tprtoflow);
4427         seq_printf(seq, "ifevents: underflow errors         : %8.8X\n",
4428                         adapter->if_events.uflow802);
4429         seq_printf(seq, "ifevents: receive early            : %8.8X\n",
4430                         adapter->if_events.rcvearly);
4431         seq_printf(seq, "ifevents: buffer overflows         : %8.8X\n",
4432                         adapter->if_events.Bufov);
4433         seq_printf(seq, "ifevents: carrier errors           : %8.8X\n",
4434                         adapter->if_events.Carre);
4435         seq_printf(seq, "ifevents: Long                     : %8.8X\n",
4436                         adapter->if_events.Longe);
4437         seq_printf(seq, "ifevents: invalid preambles        : %8.8X\n",
4438                         adapter->if_events.Invp);
4439         seq_printf(seq, "ifevents: CRC errors               : %8.8X\n",
4440                         adapter->if_events.Crc);
4441         seq_printf(seq, "ifevents: dribble nibbles          : %8.8X\n",
4442                         adapter->if_events.Drbl);
4443         seq_printf(seq, "ifevents: Code violations          : %8.8X\n",
4444                         adapter->if_events.Code);
4445         seq_printf(seq, "ifevents: TCP checksum errors      : %8.8X\n",
4446                         adapter->if_events.TpCsum);
4447         seq_printf(seq, "ifevents: TCP header short errors  : %8.8X\n",
4448                         adapter->if_events.TpHlen);
4449         seq_printf(seq, "ifevents: IP checksum errors       : %8.8X\n",
4450                         adapter->if_events.IpCsum);
4451         seq_printf(seq, "ifevents: IP frame incompletes     : %8.8X\n",
4452                         adapter->if_events.IpLen);
4453         seq_printf(seq, "ifevents: IP headers shorts        : %8.8X\n",
4454                         adapter->if_events.IpHlen);
4455
4456         return 0;
4457 }
4458 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4459 {
4460         return single_open(file, slic_debug_adapter_show, inode->i_private);
4461 }
4462
4463 static int slic_debug_card_open(struct inode *inode, struct file *file)
4464 {
4465         return single_open(file, slic_debug_card_show, inode->i_private);
4466 }
4467
4468 static const struct file_operations slic_debug_adapter_fops = {
4469         .owner          = THIS_MODULE,
4470         .open           = slic_debug_adapter_open,
4471         .read           = seq_read,
4472         .llseek         = seq_lseek,
4473         .release        = single_release,
4474 };
4475
4476 static const struct file_operations slic_debug_card_fops = {
4477         .owner          = THIS_MODULE,
4478         .open           = slic_debug_card_open,
4479         .read           = seq_read,
4480         .llseek         = seq_lseek,
4481         .release        = single_release,
4482 };
4483
4484 static void slic_debug_adapter_create(struct adapter *adapter)
4485 {
4486         struct dentry *d;
4487         char    name[7];
4488         struct sliccard *card = adapter->card;
4489
4490         if (!card->debugfs_dir)
4491                 return;
4492
4493         sprintf(name, "port%d", adapter->port);
4494         d = debugfs_create_file(name, S_IRUGO,
4495                                 card->debugfs_dir, adapter,
4496                                 &slic_debug_adapter_fops);
4497         if (!d || IS_ERR(d))
4498                 pr_info(PFX "%s: debugfs create failed\n", name);
4499         else
4500                 adapter->debugfs_entry = d;
4501 }
4502
4503 static void slic_debug_adapter_destroy(struct adapter *adapter)
4504 {
4505         if (adapter->debugfs_entry) {
4506                 debugfs_remove(adapter->debugfs_entry);
4507                 adapter->debugfs_entry = NULL;
4508         }
4509 }
4510
4511 static void slic_debug_card_create(struct sliccard *card)
4512 {
4513         struct dentry *d;
4514         char    name[IFNAMSIZ];
4515
4516         snprintf(name, sizeof(name), "slic%d", card->cardnum);
4517         d = debugfs_create_dir(name, slic_debugfs);
4518         if (!d || IS_ERR(d))
4519                 pr_info(PFX "%s: debugfs create dir failed\n",
4520                                 name);
4521         else {
4522                 card->debugfs_dir = d;
4523                 d = debugfs_create_file("cardinfo", S_IRUGO,
4524                                 slic_debugfs, card,
4525                                 &slic_debug_card_fops);
4526                 if (!d || IS_ERR(d))
4527                         pr_info(PFX "%s: debugfs create failed\n",
4528                                         name);
4529                 else
4530                         card->debugfs_cardinfo = d;
4531         }
4532 }
4533
4534 static void slic_debug_card_destroy(struct sliccard *card)
4535 {
4536         int i;
4537
4538         for (i = 0; i < card->card_size; i++) {
4539                 struct adapter *adapter;
4540
4541                 adapter = card->adapter[i];
4542                 if (adapter)
4543                         slic_debug_adapter_destroy(adapter);
4544         }
4545         if (card->debugfs_cardinfo) {
4546                 debugfs_remove(card->debugfs_cardinfo);
4547                 card->debugfs_cardinfo = NULL;
4548         }
4549         if (card->debugfs_dir) {
4550                 debugfs_remove(card->debugfs_dir);
4551                 card->debugfs_dir = NULL;
4552         }
4553 }
4554
4555 static void slic_debug_init(void)
4556 {
4557         struct dentry *ent;
4558
4559         ent = debugfs_create_dir("slic", NULL);
4560         if (!ent || IS_ERR(ent)) {
4561                 pr_info(PFX "debugfs create directory failed\n");
4562                 return;
4563         }
4564
4565         slic_debugfs = ent;
4566 }
4567
4568 static void slic_debug_cleanup(void)
4569 {
4570         if (slic_debugfs) {
4571                 debugfs_remove(slic_debugfs);
4572                 slic_debugfs = NULL;
4573         }
4574 }
4575
4576 /******************************************************************************/
4577 /****************   MODULE INITIATION / TERMINATION FUNCTIONS   ***************/
4578 /******************************************************************************/
4579
4580 static struct pci_driver slic_driver = {
4581         .name = DRV_NAME,
4582         .id_table = slic_pci_tbl,
4583         .probe = slic_entry_probe,
4584         .remove = slic_entry_remove,
4585 #if SLIC_POWER_MANAGEMENT_ENABLED
4586         .suspend = slicpm_suspend,
4587         .resume = slicpm_resume,
4588 #endif
4589 /*    .shutdown   =     slic_shutdown,  MOOK_INVESTIGATE */
4590 };
4591
4592 static int __init slic_module_init(void)
4593 {
4594         struct pci_device_id *pcidev;
4595         int ret;
4596
4597 /*      DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
4598
4599         slic_init_driver();
4600
4601         if (debug >= 0 && slic_debug != debug)
4602                 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
4603         if (debug >= 0)
4604                 slic_debug = debug;
4605
4606         pcidev = (struct pci_device_id *)slic_driver.id_table;
4607 /*      DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
4608         __func__, jiffies, smp_processor_id()); */
4609
4610         ret = pci_register_driver(&slic_driver);
4611
4612 /*  DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
4613             "cpu #%d status[%x]\n",__func__, jiffies,
4614             smp_processor_id(), ret); */
4615
4616         return ret;
4617 }
4618
4619 static void __exit slic_module_cleanup(void)
4620 {
4621 /*      DBG_MSG("slicoss: %s ENTER\n", __func__); */
4622         pci_unregister_driver(&slic_driver);
4623         slic_debug_cleanup();
4624 /*      DBG_MSG("slicoss: %s EXIT\n", __func__); */
4625 }
4626
4627 module_init(slic_module_init);
4628 module_exit(slic_module_cleanup);