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