1 /**************************************************************************
3 * Copyright 2000-2006 Alacritech, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * 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.
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
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.
37 **************************************************************************/
42 * The SLICOSS driver for Alacritech's IS-NIC products.
44 * This driver is supposed to support:
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
50 * The driver was acutally tested on Oasis and Kalahari cards.
53 * NOTE: This is the standard, non-accelerated version of Alacritech's
58 #define KLUDGE_FOR_4GB_BOUNDARY 1
59 #define DEBUG_MICROCODE 1
61 #define SLIC_ASSERT_ENABLED 1
62 #define SLIC_PING_TIMER_ENABLED 1
63 #define SLIC_POWER_MANAGEMENT_ENABLED 0
64 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
65 #define LINUX_FREES_ADAPTER_RESOURCES 1
66 #define SLIC_OFFLOAD_IP_CHECKSUM 1
67 #define STATS_TIMER_INTERVAL 2
68 #define PING_TIMER_INTERVAL 1
70 #include <linux/kernel.h>
71 #include <linux/string.h>
72 #include <linux/errno.h>
73 #include <linux/ioport.h>
74 #include <linux/slab.h>
75 #include <linux/interrupt.h>
76 #include <linux/timer.h>
77 #include <linux/pci.h>
78 #include <linux/spinlock.h>
79 #include <linux/init.h>
80 #include <linux/bitops.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/skbuff.h>
85 #include <linux/delay.h>
86 #include <linux/debugfs.h>
87 #include <linux/seq_file.h>
88 #include <linux/kthread.h>
89 #include <linux/module.h>
90 #include <linux/moduleparam.h>
92 #include <linux/firmware.h>
93 #include <linux/types.h>
94 #include <linux/dma-mapping.h>
95 #include <linux/mii.h>
96 #include <linux/if_vlan.h>
97 #include <asm/unaligned.h>
99 #include <linux/ethtool.h>
100 #define SLIC_ETHTOOL_SUPPORT 1
102 #include <linux/uaccess.h>
107 static struct net_device_stats *slic_get_stats(struct net_device *dev);
108 static int slic_entry_open(struct net_device *dev);
109 static int slic_entry_halt(struct net_device *dev);
110 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
111 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev);
112 static void slic_xmit_fail(struct adapter *adapter, struct sk_buff *skb,
113 void *cmd, u32 skbtype, u32 status);
114 static void slic_config_pci(struct pci_dev *pcidev);
115 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter);
116 static int slic_mac_set_address(struct net_device *dev, void *ptr);
117 static void slic_link_event_handler(struct adapter *adapter);
118 static void slic_upr_request_complete(struct adapter *adapter, u32 isr);
119 static int slic_rspqueue_init(struct adapter *adapter);
120 static int slic_rspqueue_reset(struct adapter *adapter);
121 static void slic_rspqueue_free(struct adapter *adapter);
122 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter);
123 static int slic_cmdq_init(struct adapter *adapter);
124 static void slic_cmdq_free(struct adapter *adapter);
125 static void slic_cmdq_reset(struct adapter *adapter);
126 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page);
127 static void slic_cmdq_getdone(struct adapter *adapter);
128 static void slic_cmdq_putdone_irq(struct adapter *adapter,
129 struct slic_hostcmd *cmd);
130 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter);
131 static int slic_rcvqueue_init(struct adapter *adapter);
132 static int slic_rcvqueue_reset(struct adapter *adapter);
133 static int slic_rcvqueue_fill(struct adapter *adapter);
134 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb);
135 static void slic_rcvqueue_free(struct adapter *adapter);
136 static void slic_adapter_set_hwaddr(struct adapter *adapter);
137 static int slic_card_init(struct sliccard *card, struct adapter *adapter);
138 static void slic_intagg_set(struct adapter *adapter, u32 value);
139 static int slic_card_download(struct adapter *adapter);
140 static u32 slic_card_locate(struct adapter *adapter);
141 static int slic_if_init(struct adapter *adapter);
142 static int slic_adapter_allocresources(struct adapter *adapter);
143 static void slic_adapter_freeresources(struct adapter *adapter);
144 static void slic_link_config(struct adapter *adapter, u32 linkspeed,
146 static void slic_unmap_mmio_space(struct adapter *adapter);
147 static void slic_card_cleanup(struct sliccard *card);
148 static void slic_soft_reset(struct adapter *adapter);
149 static bool slic_mac_filter(struct adapter *adapter,
150 struct ether_header *ether_frame);
151 static void slic_mac_address_config(struct adapter *adapter);
152 static void slic_mac_config(struct adapter *adapter);
153 static void slic_mcast_set_mask(struct adapter *adapter);
154 static void slic_config_set(struct adapter *adapter, bool linkchange);
155 static void slic_config_clear(struct adapter *adapter);
156 static void slic_config_get(struct adapter *adapter, u32 config,
158 static void slic_timer_load_check(ulong context);
159 static void slic_assert_fail(void);
160 static ushort slic_eeprom_cksum(char *m, int len);
161 static void slic_upr_start(struct adapter *adapter);
162 static void slic_link_upr_complete(struct adapter *adapter, u32 Isr);
163 static int slic_upr_request(struct adapter *adapter, u32 upr_request,
164 u32 upr_data, u32 upr_data_h, u32 upr_buffer,
166 static void slic_mcast_set_list(struct net_device *dev);
169 #define SLIC_POWER_MANAGEMENT 0
171 static uint slic_first_init = 1;
172 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
173 "and Storage Accelerator (Non-Accelerated)\n";
175 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
176 static char *slic_product_name = "SLIC Technology(tm) Server "\
177 "and Storage Accelerator (Non-Accelerated)";
178 static char *slic_vendor = "Alacritech, Inc.";
180 static int slic_debug = 1;
181 static int debug = -1;
182 static struct net_device *head_netdevice;
184 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
185 static int intagg_delay = 100;
186 static u32 dynamic_intagg;
187 static unsigned int rcv_count;
188 static struct dentry *slic_debugfs;
190 #define DRV_NAME "slicoss"
191 #define DRV_VERSION "2.0.1"
192 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
193 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
194 "Non-Accelerated Driver"
195 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
196 "All rights reserved."
197 #define PFX DRV_NAME " "
199 MODULE_AUTHOR(DRV_AUTHOR);
200 MODULE_DESCRIPTION(DRV_DESCRIPTION);
201 MODULE_LICENSE("Dual BSD/GPL");
203 module_param(dynamic_intagg, int, 0);
204 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
205 module_param(intagg_delay, int, 0);
206 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
208 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
209 {PCI_VENDOR_ID_ALACRITECH,
211 PCI_ANY_ID, PCI_ANY_ID,},
212 {PCI_VENDOR_ID_ALACRITECH,
214 PCI_ANY_ID, PCI_ANY_ID,},
218 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
220 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
222 spin_lock_irqsave(&_adapter->handle_lock.lock, \
223 _adapter->handle_lock.flags); \
224 _pslic_handle = _adapter->pfree_slic_handles; \
225 if (_pslic_handle) { \
226 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
227 _adapter->pfree_slic_handles = _pslic_handle->next; \
229 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
230 _adapter->handle_lock.flags); \
233 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
235 _pslic_handle->type = SLIC_HANDLE_FREE; \
236 spin_lock_irqsave(&_adapter->handle_lock.lock, \
237 _adapter->handle_lock.flags); \
238 _pslic_handle->next = _adapter->pfree_slic_handles; \
239 _adapter->pfree_slic_handles = _pslic_handle; \
240 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
241 _adapter->handle_lock.flags); \
244 static void slic_debug_init(void);
245 static void slic_debug_cleanup(void);
246 static void slic_debug_adapter_create(struct adapter *adapter);
247 static void slic_debug_adapter_destroy(struct adapter *adapter);
248 static void slic_debug_card_create(struct sliccard *card);
249 static void slic_debug_card_destroy(struct sliccard *card);
251 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
258 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
259 u32 value, void __iomem *regh, u32 paddrh,
262 spin_lock_irqsave(&adapter->bit64reglock.lock,
263 adapter->bit64reglock.flags);
264 if (paddrh != adapter->curaddrupper) {
265 adapter->curaddrupper = paddrh;
266 writel(paddrh, regh);
271 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
272 adapter->bit64reglock.flags);
275 static void slic_init_driver(void)
277 if (slic_first_init) {
278 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
281 spin_lock_init(&slic_global.driver_lock.lock);
286 static void slic_dbg_macaddrs(struct adapter *adapter)
288 DBG_MSG(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
289 adapter->netdev->name, adapter->currmacaddr[0],
290 adapter->currmacaddr[1], adapter->currmacaddr[2],
291 adapter->currmacaddr[3], adapter->currmacaddr[4],
292 adapter->currmacaddr[5]);
293 DBG_MSG(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
294 adapter->netdev->name, adapter->macaddr[0],
295 adapter->macaddr[1], adapter->macaddr[2],
296 adapter->macaddr[3], adapter->macaddr[4], adapter->macaddr[5]);
300 static void slic_init_adapter(struct net_device *netdev,
301 struct pci_dev *pcidev,
302 const struct pci_device_id *pci_tbl_entry,
303 void __iomem *memaddr, int chip_idx)
306 struct slic_handle *pslic_handle;
307 struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
309 DBG_MSG("slicoss: %s (%s)\n netdev [%p]\n adapter[%p]\n "
310 "pcidev [%p]\n", __func__, netdev->name, netdev, adapter, pcidev);*/
311 /* adapter->pcidev = pcidev;*/
312 adapter->vendid = pci_tbl_entry->vendor;
313 adapter->devid = pci_tbl_entry->device;
314 adapter->subsysid = pci_tbl_entry->subdevice;
315 adapter->busnumber = pcidev->bus->number;
316 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
317 adapter->functionnumber = (pcidev->devfn & 0x7);
318 adapter->memorylength = pci_resource_len(pcidev, 0);
319 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
320 adapter->irq = pcidev->irq;
321 /* adapter->netdev = netdev;*/
322 adapter->next_netdevice = head_netdevice;
323 head_netdevice = netdev;
324 adapter->chipid = chip_idx;
325 adapter->port = 0; /*adapter->functionnumber;*/
326 adapter->cardindex = adapter->port;
327 adapter->memorybase = memaddr;
328 spin_lock_init(&adapter->upr_lock.lock);
329 spin_lock_init(&adapter->bit64reglock.lock);
330 spin_lock_init(&adapter->adapter_lock.lock);
331 spin_lock_init(&adapter->reset_lock.lock);
332 spin_lock_init(&adapter->handle_lock.lock);
334 adapter->card_size = 1;
336 Initialize slic_handle array
338 ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
340 Start with 1. 0 is an invalid host handle.
342 for (index = 1, pslic_handle = &adapter->slic_handles[1];
343 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
345 pslic_handle->token.handle_index = index;
346 pslic_handle->type = SLIC_HANDLE_FREE;
347 pslic_handle->next = adapter->pfree_slic_handles;
348 adapter->pfree_slic_handles = pslic_handle;
351 DBG_MSG(".........\nix[%d] phandle[%p] pfree[%p] next[%p]\n",
352 index, pslic_handle, adapter->pfree_slic_handles, pslic_handle->next);*/
353 adapter->pshmem = (struct slic_shmem *)
354 pci_alloc_consistent(adapter->pcidev,
355 sizeof(struct slic_shmem),
359 DBG_MSG("slicoss: %s (%s)\n pshmem [%p]\n phys_shmem[%p]\n"\
360 "slic_regs [%p]\n", __func__, netdev->name, adapter->pshmem,
361 (void *)adapter->phys_shmem, adapter->slic_regs);
363 ASSERT(adapter->pshmem);
365 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
370 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
371 const struct pci_device_id *pci_tbl_entry)
373 static int cards_found;
374 static int did_version;
376 struct net_device *netdev;
377 struct adapter *adapter;
378 void __iomem *memmapped_ioaddr = NULL;
380 ulong mmio_start = 0;
382 struct sliccard *card = NULL;
384 DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
385 __func__, jiffies, smp_processor_id());
387 slic_global.dynamic_intagg = dynamic_intagg;
389 err = pci_enable_device(pcidev);
391 DBG_MSG("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
395 if (slic_debug > 0 && did_version++ == 0) {
397 printk(slic_proc_version);
400 err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
402 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
404 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
407 ("No usable DMA configuration, aborting err[%x]\n",
409 goto err_out_disable_pci;
411 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
414 DBG_MSG("Call pci_request_regions\n");
416 err = pci_request_regions(pcidev, DRV_NAME);
418 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
419 goto err_out_disable_pci;
422 DBG_MSG("call pci_set_master\n");
423 pci_set_master(pcidev);
425 DBG_MSG("call alloc_etherdev\n");
426 netdev = alloc_etherdev(sizeof(struct adapter));
429 goto err_out_exit_slic_probe;
431 DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
433 SET_NETDEV_DEV(netdev, &pcidev->dev);
435 pci_set_drvdata(pcidev, netdev);
436 adapter = netdev_priv(netdev);
437 adapter->netdev = netdev;
438 adapter->pcidev = pcidev;
440 mmio_start = pci_resource_start(pcidev, 0);
441 mmio_len = pci_resource_len(pcidev, 0);
443 DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
444 mmio_start, mmio_len);
446 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
447 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
448 DBG_MSG("slicoss: %s MEMMAPPED_IOADDR [%p]\n", __func__,
450 if (!memmapped_ioaddr) {
451 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
452 __func__, mmio_len, mmio_start);
453 goto err_out_free_netdev;
457 ("slicoss: %s found Alacritech SLICOSS PCI, MMIO at %p, "\
458 "start[%lx] len[%lx], IRQ %d.\n",
459 __func__, memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
461 slic_config_pci(pcidev);
465 slic_init_adapter(netdev,
466 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
468 status = slic_card_locate(adapter);
470 DBG_ERROR("%s cannot locate card\n", __func__);
471 goto err_out_free_mmio_region;
474 card = adapter->card;
476 if (!adapter->allocated) {
477 card->adapters_allocated++;
478 adapter->allocated = 1;
481 DBG_MSG("slicoss: %s card: %p\n", __func__,
483 DBG_MSG("slicoss: %s card->adapter[%d] == [%p]\n", __func__,
484 (uint) adapter->port, adapter);
485 DBG_MSG("slicoss: %s card->adapters_allocated [%d]\n", __func__,
486 card->adapters_allocated);
487 DBG_MSG("slicoss: %s card->adapters_activated [%d]\n", __func__,
488 card->adapters_activated);
490 status = slic_card_init(card, adapter);
492 if (status != STATUS_SUCCESS) {
493 card->state = CARD_FAIL;
494 adapter->state = ADAPT_FAIL;
495 adapter->linkstate = LINK_DOWN;
496 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
498 slic_adapter_set_hwaddr(adapter);
501 netdev->base_addr = (unsigned long)adapter->memorybase;
502 netdev->irq = adapter->irq;
503 netdev->open = slic_entry_open;
504 netdev->stop = slic_entry_halt;
505 netdev->hard_start_xmit = slic_xmit_start;
506 netdev->do_ioctl = slic_ioctl;
507 netdev->set_mac_address = slic_mac_set_address;
508 netdev->get_stats = slic_get_stats;
509 netdev->set_multicast_list = slic_mcast_set_list;
511 slic_debug_adapter_create(adapter);
513 strcpy(netdev->name, "eth%d");
514 err = register_netdev(netdev);
516 DBG_ERROR("Cannot register net device, aborting.\n");
521 ("slicoss: addr 0x%lx, irq %d, MAC addr "\
522 "%02X:%02X:%02X:%02X:%02X:%02X\n",
523 mmio_start, /*pci_resource_start(pcidev, 0), */ pcidev->irq,
524 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
525 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
528 DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
529 __func__, status, jiffies, smp_processor_id());
534 iounmap(memmapped_ioaddr);
535 err_out_free_mmio_region:
536 release_mem_region(mmio_start, mmio_len);
539 err_out_exit_slic_probe:
540 pci_release_regions(pcidev);
541 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
544 pci_disable_device(pcidev);
548 static int slic_entry_open(struct net_device *dev)
550 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
551 struct sliccard *card = adapter->card;
558 ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
559 "allocd[%x]\n", __func__, adapter->activated,
560 card->adapters_activated,
561 card->adapters_allocated);
563 ("slicoss: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] "\
564 "port[%d] card[%p]\n",
565 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
566 adapter->netdev, adapter, adapter->port, card);
568 netif_stop_queue(adapter->netdev);
570 spin_lock_irqsave(&slic_global.driver_lock.lock,
571 slic_global.driver_lock.flags);
573 if (!adapter->activated) {
574 card->adapters_activated++;
575 slic_global.num_slic_ports_active++;
576 adapter->activated = 1;
578 status = slic_if_init(adapter);
580 if (status != STATUS_SUCCESS) {
581 if (adapter->activated) {
582 card->adapters_activated--;
583 slic_global.num_slic_ports_active--;
584 adapter->activated = 0;
587 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
588 slic_global.driver_lock.flags);
593 DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
594 card->master, adapter);
596 card->master = adapter;
599 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
600 slic_global.driver_lock.flags);
604 return STATUS_SUCCESS;
607 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
609 struct net_device *dev = pci_get_drvdata(pcidev);
612 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
613 struct sliccard *card;
614 struct mcast_address *mcaddr, *mlist;
617 DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
619 slic_adapter_freeresources(adapter);
620 slic_unmap_mmio_space(adapter);
621 DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
622 unregister_netdev(dev);
624 mmio_start = pci_resource_start(pcidev, 0);
625 mmio_len = pci_resource_len(pcidev, 0);
627 DBG_MSG("slicoss: %s rel_region(0) start[%x] len[%x]\n", __func__,
628 mmio_start, mmio_len);
629 release_mem_region(mmio_start, mmio_len);
631 DBG_MSG("slicoss: %s iounmap dev->base_addr[%x]\n", __func__,
632 (uint) dev->base_addr);
633 iounmap((void __iomem *)dev->base_addr);
634 /* free multicast addresses */
635 mlist = adapter->mcastaddrs;
641 ASSERT(adapter->card);
642 card = adapter->card;
643 ASSERT(card->adapters_allocated);
644 card->adapters_allocated--;
645 adapter->allocated = 0;
647 ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
648 __func__, card->adapters_activated, card->adapters_allocated,
650 if (!card->adapters_allocated) {
651 struct sliccard *curr_card = slic_global.slic_card;
652 if (curr_card == card) {
653 slic_global.slic_card = card->next;
655 while (curr_card->next != card)
656 curr_card = curr_card->next;
658 curr_card->next = card->next;
660 ASSERT(slic_global.num_slic_cards);
661 slic_global.num_slic_cards--;
662 slic_card_cleanup(card);
664 DBG_MSG("slicoss: %s deallocate device\n", __func__);
666 pci_release_regions(pcidev);
667 DBG_MSG("slicoss: %s EXIT\n", __func__);
670 static int slic_entry_halt(struct net_device *dev)
672 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
673 struct sliccard *card = adapter->card;
674 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
676 spin_lock_irqsave(&slic_global.driver_lock.lock,
677 slic_global.driver_lock.flags);
679 DBG_MSG("slicoss: %s (%s) ENTER\n", __func__, dev->name);
680 DBG_MSG("slicoss: %s (%s) actvtd[%d] alloc[%d] state[%x] adapt[%p]\n",
681 __func__, dev->name, card->adapters_activated,
682 card->adapters_allocated, card->state, adapter);
683 netif_stop_queue(adapter->netdev);
684 adapter->state = ADAPT_DOWN;
685 adapter->linkstate = LINK_DOWN;
686 adapter->upr_list = NULL;
687 adapter->upr_busy = 0;
688 adapter->devflags_prev = 0;
689 DBG_MSG("slicoss: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
690 __func__, dev->name, adapter, adapter->state);
691 ASSERT(card->adapter[adapter->cardindex] == adapter);
692 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
693 adapter->all_reg_writes++;
694 adapter->icr_reg_writes++;
695 slic_config_clear(adapter);
696 DBG_MSG("slicoss: %s (%s) dev[%p] adapt[%p] card[%p]\n",
697 __func__, dev->name, dev, adapter, card);
698 if (adapter->activated) {
699 card->adapters_activated--;
700 slic_global.num_slic_ports_active--;
701 adapter->activated = 0;
703 #ifdef AUTOMATIC_RESET
704 slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
707 * Reset the adapter's rsp, cmd, and rcv queues
709 slic_cmdq_reset(adapter);
710 slic_rspqueue_reset(adapter);
711 slic_rcvqueue_reset(adapter);
713 #ifdef AUTOMATIC_RESET
714 if (!card->adapters_activated) {
715 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
718 slic_card_init(card, adapter);
722 DBG_MSG("slicoss: %s (%s) EXIT\n", __func__, dev->name);
723 DBG_MSG("slicoss: %s EXIT\n", __func__);
724 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
725 slic_global.driver_lock.flags);
726 return STATUS_SUCCESS;
729 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
733 DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
736 case SIOCSLICSETINTAGG:
738 struct adapter *adapter = (struct adapter *)
743 if (copy_from_user(data, rq->ifr_data, 28)) {
745 ("copy_from_user FAILED getting initial \
751 "%s: set interrupt aggregation to %d\n",
753 slic_intagg_set(adapter, intagg);
757 #ifdef SLIC_TRACE_DUMP_ENABLED
758 case SIOCSLICTRACEDUMP:
763 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
765 if (copy_from_user(data, rq->ifr_data, 28)) {
767 ("slic: copy_from_user FAILED getting \
768 initial simba param\n");
773 if (tracemon_request == SLIC_DUMP_DONE) {
775 ("ATK Diagnostic Trace Dump Requested\n");
776 tracemon_request = SLIC_DUMP_REQUESTED;
777 tracemon_request_type = value;
778 tracemon_timestamp = jiffies;
779 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
781 SLIC_DUMP_IN_PROGRESS)) {
783 ("ATK Diagnostic Trace Dump Requested but \
784 already in progress... ignore\n");
787 ("ATK Diagnostic Trace Dump Requested\n");
788 tracemon_request = SLIC_DUMP_REQUESTED;
789 tracemon_request_type = value;
790 tracemon_timestamp = jiffies;
795 #if SLIC_ETHTOOL_SUPPORT
798 struct adapter *adapter = (struct adapter *)
800 struct ethtool_cmd data;
801 struct ethtool_cmd ecmd;
804 /* DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
805 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
808 if (ecmd.cmd == ETHTOOL_GSET) {
810 (SUPPORTED_10baseT_Half |
811 SUPPORTED_10baseT_Full |
812 SUPPORTED_100baseT_Half |
813 SUPPORTED_100baseT_Full |
814 SUPPORTED_Autoneg | SUPPORTED_MII);
815 data.port = PORT_MII;
816 data.transceiver = XCVR_INTERNAL;
817 data.phy_address = 0;
818 if (adapter->linkspeed == LINK_100MB)
819 data.speed = SPEED_100;
820 else if (adapter->linkspeed == LINK_10MB)
821 data.speed = SPEED_10;
825 if (adapter->linkduplex == LINK_FULLD)
826 data.duplex = DUPLEX_FULL;
828 data.duplex = DUPLEX_HALF;
830 data.autoneg = AUTONEG_ENABLE;
834 (rq->ifr_data, &data, sizeof(data)))
837 } else if (ecmd.cmd == ETHTOOL_SSET) {
838 if (!capable(CAP_NET_ADMIN))
841 if (adapter->linkspeed == LINK_100MB)
842 data.speed = SPEED_100;
843 else if (adapter->linkspeed == LINK_10MB)
844 data.speed = SPEED_10;
848 if (adapter->linkduplex == LINK_FULLD)
849 data.duplex = DUPLEX_FULL;
851 data.duplex = DUPLEX_HALF;
853 data.autoneg = AUTONEG_ENABLE;
856 if ((ecmd.speed != data.speed) ||
857 (ecmd.duplex != data.duplex)) {
861 if (ecmd.speed == SPEED_10) {
864 ("%s: slic ETHTOOL set \
868 speed = PCR_SPEED_100;
870 ("%s: slic ETHTOOL set \
874 if (ecmd.duplex == DUPLEX_FULL) {
875 duplex = PCR_DUPLEX_FULL;
877 (": duplex==FULL\n");
881 (": duplex==HALF\n");
883 slic_link_config(adapter,
885 slic_link_event_handler(adapter);
892 /* DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
897 #define XMIT_FAIL_LINK_STATE 1
898 #define XMIT_FAIL_ZERO_LENGTH 2
899 #define XMIT_FAIL_HOSTCMD_FAIL 3
901 static void slic_xmit_build_request(struct adapter *adapter,
902 struct slic_hostcmd *hcmd, struct sk_buff *skb)
904 struct slic_host64_cmd *ihcmd;
907 ihcmd = &hcmd->cmd64;
909 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
910 ihcmd->command = IHCMD_XMT_REQ;
911 ihcmd->u.slic_buffers.totlen = skb->len;
912 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
914 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
915 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
916 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
917 #if defined(CONFIG_X86_64)
918 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
919 (u64) hcmd) + 31) >> 5);
920 #elif defined(CONFIG_X86)
921 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
922 (u32) hcmd) + 31) >> 5);
928 #define NORMAL_ETHFRAME 0
930 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
932 struct sliccard *card;
933 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
934 struct slic_hostcmd *hcmd = NULL;
936 u32 skbtype = NORMAL_ETHFRAME;
937 void *offloadcmd = NULL;
939 card = adapter->card;
942 DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
943 adapter->netdev->name, skb, skb->len, adapter->linkstate,
946 if ((adapter->linkstate != LINK_UP) ||
947 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
948 status = XMIT_FAIL_LINK_STATE;
951 } else if (skb->len == 0) {
952 status = XMIT_FAIL_ZERO_LENGTH;
956 if (skbtype == NORMAL_ETHFRAME) {
957 hcmd = slic_cmdq_getfree(adapter);
959 adapter->xmitq_full = 1;
960 status = XMIT_FAIL_HOSTCMD_FAIL;
963 ASSERT(hcmd->pslic_handle);
964 ASSERT(hcmd->cmd64.hosthandle ==
965 hcmd->pslic_handle->token.handle_token);
968 hcmd->type = SLIC_CMD_DUMB;
969 if (skbtype == NORMAL_ETHFRAME)
970 slic_xmit_build_request(adapter, hcmd, skb);
972 adapter->stats.tx_packets++;
973 adapter->stats.tx_bytes += skb->len;
976 if (adapter->kill_card) {
977 struct slic_host64_cmd ihcmd;
979 ihcmd = &hcmd->cmd64;
981 ihcmd->flags |= 0x40;
982 adapter->kill_card = 0; /* only do this once */
985 if (hcmd->paddrh == 0) {
986 slic_reg32_write(&adapter->slic_regs->slic_cbar,
987 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
989 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
990 (hcmd->paddrl | hcmd->cmdsize),
991 &adapter->slic_regs->slic_addr_upper,
992 hcmd->paddrh, DONT_FLUSH);
997 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
1001 static void slic_xmit_fail(struct adapter *adapter,
1002 struct sk_buff *skb,
1003 void *cmd, u32 skbtype, u32 status)
1005 if (adapter->xmitq_full)
1006 netif_stop_queue(adapter->netdev);
1007 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1009 case XMIT_FAIL_LINK_STATE:
1011 ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
1012 adapter[%s:%d] card[%s:%d]\n",
1013 adapter->netdev->name, skb, skb->pkt_type,
1014 SLIC_LINKSTATE(adapter->linkstate),
1015 SLIC_ADAPTER_STATE(adapter->state), adapter->state,
1016 SLIC_CARD_STATE(adapter->card->state),
1017 adapter->card->state);
1019 case XMIT_FAIL_ZERO_LENGTH:
1021 ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1022 skb, skb->pkt_type);
1024 case XMIT_FAIL_HOSTCMD_FAIL:
1026 ("xmit_start skb[%p] type[%x] No host commands \
1028 skb, skb->pkt_type);
1035 adapter->stats.tx_dropped++;
1038 static void slic_rcv_handle_error(struct adapter *adapter,
1039 struct slic_rcvbuf *rcvbuf)
1041 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1043 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1044 if (hdr->frame_status14 & VRHSTAT_802OE)
1045 adapter->if_events.oflow802++;
1046 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1047 adapter->if_events.Tprtoflow++;
1048 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1049 adapter->if_events.uflow802++;
1050 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1051 adapter->if_events.rcvearly++;
1052 adapter->stats.rx_fifo_errors++;
1054 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1055 adapter->if_events.Bufov++;
1056 adapter->stats.rx_over_errors++;
1058 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1059 adapter->if_events.Carre++;
1060 adapter->stats.tx_carrier_errors++;
1062 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1063 adapter->if_events.Longe++;
1064 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1065 adapter->if_events.Invp++;
1066 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1067 adapter->if_events.Crc++;
1068 adapter->stats.rx_crc_errors++;
1070 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1071 adapter->if_events.Drbl++;
1072 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1073 adapter->if_events.Code++;
1074 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1075 adapter->if_events.TpCsum++;
1076 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1077 adapter->if_events.TpHlen++;
1078 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1079 adapter->if_events.IpCsum++;
1080 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1081 adapter->if_events.IpLen++;
1082 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1083 adapter->if_events.IpHlen++;
1085 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1086 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1088 if (xerr == VGBSTAT_XCSERR)
1089 adapter->if_events.TpCsum++;
1090 if (xerr == VGBSTAT_XUFLOW)
1091 adapter->if_events.Tprtoflow++;
1092 if (xerr == VGBSTAT_XHLEN)
1093 adapter->if_events.TpHlen++;
1095 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1098 frame_statusGB >> VGBSTAT_NERRSHFT) &
1100 if (nerr == VGBSTAT_NCSERR)
1101 adapter->if_events.IpCsum++;
1102 if (nerr == VGBSTAT_NUFLOW)
1103 adapter->if_events.IpLen++;
1104 if (nerr == VGBSTAT_NHLEN)
1105 adapter->if_events.IpHlen++;
1107 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1108 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1110 if (lerr == VGBSTAT_LDEARLY)
1111 adapter->if_events.rcvearly++;
1112 if (lerr == VGBSTAT_LBOFLO)
1113 adapter->if_events.Bufov++;
1114 if (lerr == VGBSTAT_LCODERR)
1115 adapter->if_events.Code++;
1116 if (lerr == VGBSTAT_LDBLNBL)
1117 adapter->if_events.Drbl++;
1118 if (lerr == VGBSTAT_LCRCERR)
1119 adapter->if_events.Crc++;
1120 if (lerr == VGBSTAT_LOFLO)
1121 adapter->if_events.oflow802++;
1122 if (lerr == VGBSTAT_LUFLO)
1123 adapter->if_events.uflow802++;
1129 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
1130 #define M_FAST_PATH 0x0040
1132 static void slic_rcv_handler(struct adapter *adapter)
1134 struct sk_buff *skb;
1135 struct slic_rcvbuf *rcvbuf;
1138 while ((skb = slic_rcvqueue_getnext(adapter))) {
1142 rcvbuf = (struct slic_rcvbuf *)skb->head;
1143 adapter->card->events++;
1144 if (rcvbuf->status & IRHDDR_ERR) {
1145 adapter->rx_errors++;
1146 slic_rcv_handle_error(adapter, rcvbuf);
1147 slic_rcvqueue_reinsert(adapter, skb);
1151 if (!slic_mac_filter(adapter, (struct ether_header *)
1155 ("slicoss: %s (%s) drop frame due to mac filter\n",
1156 __func__, adapter->netdev->name);
1158 slic_rcvqueue_reinsert(adapter, skb);
1161 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1162 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1163 skb_put(skb, rx_bytes);
1164 adapter->stats.rx_packets++;
1165 adapter->stats.rx_bytes += rx_bytes;
1166 #if SLIC_OFFLOAD_IP_CHECKSUM
1167 skb->ip_summed = CHECKSUM_UNNECESSARY;
1170 skb->dev = adapter->netdev;
1171 skb->protocol = eth_type_trans(skb, skb->dev);
1175 #if SLIC_INTERRUPT_PROCESS_LIMIT
1176 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1177 adapter->rcv_interrupt_yields++;
1182 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1185 static void slic_xmit_complete(struct adapter *adapter)
1187 struct slic_hostcmd *hcmd;
1188 struct slic_rspbuf *rspbuf;
1190 struct slic_handle_word slic_handle_word;
1193 rspbuf = slic_rspqueue_getnext(adapter);
1196 adapter->xmit_completes++;
1197 adapter->card->events++;
1199 Get the complete host command buffer
1201 slic_handle_word.handle_token = rspbuf->hosthandle;
1202 ASSERT(slic_handle_word.handle_index);
1203 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1205 (struct slic_hostcmd *)
1206 adapter->slic_handles[slic_handle_word.handle_index].
1208 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1210 ASSERT(hcmd->pslic_handle ==
1211 &adapter->slic_handles[slic_handle_word.handle_index]);
1213 DBG_ERROR("xmit_complete (%s) hcmd[%p] hosthandle[%x]\n",
1214 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1215 DBG_ERROR(" skb[%p] len %d hcmdtype[%x]\n", hcmd->skb,
1216 hcmd->skb->len, hcmd->type);
1218 if (hcmd->type == SLIC_CMD_DUMB) {
1220 dev_kfree_skb_irq(hcmd->skb);
1221 slic_cmdq_putdone_irq(adapter, hcmd);
1224 rspbuf->hosthandle = 0;
1227 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1230 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1232 struct net_device *dev = (struct net_device *)dev_id;
1233 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1236 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1237 slic_reg32_write(&adapter->slic_regs->slic_icr,
1238 ICR_INT_MASK, FLUSH);
1239 isr = adapter->isrcopy = adapter->pshmem->isr;
1240 adapter->pshmem->isr = 0;
1241 adapter->num_isrs++;
1242 switch (adapter->card->state) {
1244 if (isr & ~ISR_IO) {
1245 if (isr & ISR_ERR) {
1246 adapter->error_interrupts++;
1247 if (isr & ISR_RMISS) {
1252 struct slic_rcvqueue *rcvq =
1256 error_rmiss_interrupts++;
1258 rcv_count = rcvq->count;
1259 pre_count = rcvq->count;
1260 errors = rcvq->errors;
1262 while (rcvq->count <
1263 SLIC_RCVQ_FILLTHRESH) {
1271 ("(%s): [%x] ISR_RMISS \
1272 initial[%x] pre[%x] \
1275 adapter->netdev->name,
1276 isr, rcv_count, pre_count,
1277 errors, rcvq->count);
1278 } else if (isr & ISR_XDROP) {
1280 ("isr & ISR_ERR [%x] \
1285 ("isr & ISR_ERR [%x]\n",
1290 if (isr & ISR_LEVENT) {
1291 /*DBG_MSG("%s (%s) ISR_LEVENT \n",
1292 __func__, adapter->netdev->name);*/
1293 adapter->linkevent_interrupts++;
1294 slic_link_event_handler(adapter);
1297 if ((isr & ISR_UPC) ||
1298 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1299 adapter->upr_interrupts++;
1300 slic_upr_request_complete(adapter, isr);
1304 if (isr & ISR_RCV) {
1305 adapter->rcv_interrupts++;
1306 slic_rcv_handler(adapter);
1309 if (isr & ISR_CMD) {
1310 adapter->xmit_interrupts++;
1311 slic_xmit_complete(adapter);
1316 if ((isr & ISR_UPC) ||
1317 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1318 adapter->upr_interrupts++;
1319 slic_upr_request_complete(adapter, isr);
1327 adapter->isrcopy = 0;
1328 adapter->all_reg_writes += 2;
1329 adapter->isr_reg_writes++;
1330 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
1332 adapter->false_interrupts++;
1338 * slic_link_event_handler -
1340 * Initiate a link configuration sequence. The link configuration begins
1341 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1342 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
1343 * routine will follow it up witha UP configuration write command, which
1344 * will also complete asynchronously.
1347 static void slic_link_event_handler(struct adapter *adapter)
1350 struct slic_shmem *pshmem;
1352 if (adapter->state != ADAPT_UP) {
1353 /* Adapter is not operational. Ignore. */
1357 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1359 #if defined(CONFIG_X86_64)
1361 DBG_MSG("slic_event_handler pshmem->linkstatus[%x] pshmem[%p]\n \
1362 &linkstatus[%p] &isr[%p]\n", adapter->pshmem->linkstatus, pshmem,
1363 &pshmem->linkstatus, &pshmem->isr);
1365 status = slic_upr_request(adapter,
1367 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1368 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1370 #elif defined(CONFIG_X86)
1371 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1372 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
1377 ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1380 static void slic_init_cleanup(struct adapter *adapter)
1382 DBG_MSG("slicoss: %s ENTER adapter[%p] ", __func__, adapter);
1383 if (adapter->intrregistered) {
1384 DBG_MSG("FREE_IRQ ");
1385 adapter->intrregistered = 0;
1386 free_irq(adapter->netdev->irq, adapter->netdev);
1389 if (adapter->pshmem) {
1390 DBG_MSG("FREE_SHMEM ");
1391 DBG_MSG("adapter[%p] port %d pshmem[%p] FreeShmem ",
1392 adapter, adapter->port, (void *) adapter->pshmem);
1393 pci_free_consistent(adapter->pcidev,
1394 sizeof(struct slic_shmem),
1395 adapter->pshmem, adapter->phys_shmem);
1396 adapter->pshmem = NULL;
1397 adapter->phys_shmem = (dma_addr_t) NULL;
1399 #if SLIC_PING_TIMER_ENABLED
1400 if (adapter->pingtimerset) {
1401 DBG_MSG("pingtimer ");
1402 adapter->pingtimerset = 0;
1403 del_timer(&adapter->pingtimer);
1406 slic_rspqueue_free(adapter);
1407 slic_cmdq_free(adapter);
1408 slic_rcvqueue_free(adapter);
1413 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1415 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1416 struct net_device_stats *stats;
1419 stats = &adapter->stats;
1420 stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1421 stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1422 stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1423 stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1424 stats->tx_heartbeat_errors = 0;
1425 stats->tx_aborted_errors = 0;
1426 stats->tx_window_errors = 0;
1427 stats->tx_fifo_errors = 0;
1428 stats->rx_frame_errors = 0;
1429 stats->rx_length_errors = 0;
1430 return &adapter->stats;
1434 * Allocate a mcast_address structure to hold the multicast address.
1437 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1439 struct mcast_address *mcaddr, *mlist;
1442 /* Check to see if it already exists */
1443 mlist = adapter->mcastaddrs;
1445 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1447 return STATUS_SUCCESS;
1448 mlist = mlist->next;
1451 /* Doesn't already exist. Allocate a structure to hold it */
1452 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1456 memcpy(mcaddr->address, address, 6);
1458 mcaddr->next = adapter->mcastaddrs;
1459 adapter->mcastaddrs = mcaddr;
1461 return STATUS_SUCCESS;
1465 * Functions to obtain the CRC corresponding to the destination mac address.
1466 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1468 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1471 * After the CRC for the 6 bytes is generated (but before the value is
1473 * we must then transpose the value and return bits 30-23.
1476 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1477 static u32 slic_crc_init; /* Is table initialized */
1480 * Contruct the CRC32 table
1482 static void slic_mcast_init_crc32(void)
1484 u32 c; /* CRC shit reg */
1485 u32 e = 0; /* Poly X-or pattern */
1486 int i; /* counter */
1487 int k; /* byte being shifted into crc */
1489 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1491 for (i = 0; i < sizeof(p) / sizeof(int); i++)
1492 e |= 1L << (31 - p[i]);
1494 for (i = 1; i < 256; i++) {
1497 c = c & 1 ? (c >> 1) ^ e : c >> 1;
1498 slic_crc_table[i] = c;
1503 * Return the MAC hast as described above.
1505 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1510 unsigned char machash = 0;
1512 if (!slic_crc_init) {
1513 slic_mcast_init_crc32();
1517 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
1518 for (i = 0, p = macaddr; i < 6; ++p, ++i)
1519 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1521 /* Return bits 1-8, transposed */
1522 for (i = 1; i < 9; i++)
1523 machash |= (((crc >> i) & 1) << (8 - i));
1528 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1530 unsigned char crcpoly;
1532 /* Get the CRC polynomial for the mac address */
1533 crcpoly = slic_mcast_get_mac_hash(address);
1535 /* We only have space on the SLIC for 64 entries. Lop
1536 * off the top two bits. (2^6 = 64)
1540 /* OR in the new bit into our 64 bit mask. */
1541 adapter->mcastmask |= (u64) 1 << crcpoly;
1544 static void slic_mcast_set_list(struct net_device *dev)
1546 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1547 int status = STATUS_SUCCESS;
1550 struct dev_mc_list *mc_list = dev->mc_list;
1551 int mc_count = dev->mc_count;
1555 for (i = 1; i <= mc_count; i++) {
1556 addresses = (char *) &mc_list->dmi_addr;
1557 if (mc_list->dmi_addrlen == 6) {
1558 status = slic_mcast_add_list(adapter, addresses);
1559 if (status != STATUS_SUCCESS)
1565 slic_mcast_set_bit(adapter, addresses);
1566 mc_list = mc_list->next;
1569 DBG_MSG("%s a->devflags_prev[%x] dev->flags[%x] status[%x]\n",
1570 __func__, adapter->devflags_prev, dev->flags, status);
1571 if (adapter->devflags_prev != dev->flags) {
1572 adapter->macopts = MAC_DIRECTED;
1574 if (dev->flags & IFF_BROADCAST)
1575 adapter->macopts |= MAC_BCAST;
1576 if (dev->flags & IFF_PROMISC)
1577 adapter->macopts |= MAC_PROMISC;
1578 if (dev->flags & IFF_ALLMULTI)
1579 adapter->macopts |= MAC_ALLMCAST;
1580 if (dev->flags & IFF_MULTICAST)
1581 adapter->macopts |= MAC_MCAST;
1583 adapter->devflags_prev = dev->flags;
1584 DBG_MSG("%s call slic_config_set adapter->macopts[%x]\n",
1585 __func__, adapter->macopts);
1586 slic_config_set(adapter, true);
1588 if (status == STATUS_SUCCESS)
1589 slic_mcast_set_mask(adapter);
1594 static void slic_mcast_set_mask(struct adapter *adapter)
1596 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1598 DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1599 adapter->netdev->name, (uint) adapter->macopts,
1600 adapter->mcastmask);
1602 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1603 /* Turn on all multicast addresses. We have to do this for
1604 * promiscuous mode as well as ALLMCAST mode. It saves the
1605 * Microcode from having to keep state about the MAC
1608 /* DBG_MSG("slicoss: %s macopts = MAC_ALLMCAST | MAC_PROMISC\n\
1609 SLUT MODE!!!\n",__func__); */
1610 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1611 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
1613 /* DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1614 _func__, adapter->netdev->name); */
1616 /* Commit our multicast mast to the SLIC by writing to the
1617 * multicast address mask registers
1619 DBG_MSG("%s (%s) WRITE mcastlow[%x] mcasthigh[%x]\n",
1620 __func__, adapter->netdev->name,
1621 ((ulong) (adapter->mcastmask & 0xFFFFFFFF)),
1622 ((ulong) ((adapter->mcastmask >> 32) & 0xFFFFFFFF)));
1624 slic_reg32_write(&slic_regs->slic_mcastlow,
1625 (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1626 slic_reg32_write(&slic_regs->slic_mcasthigh,
1627 (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
1631 static void slic_timer_ping(ulong dev)
1633 struct adapter *adapter;
1634 struct sliccard *card;
1637 adapter = netdev_priv((struct net_device *)dev);
1639 card = adapter->card;
1642 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1643 add_timer(&adapter->pingtimer);
1649 * Perform initialization of our slic interface.
1652 static int slic_if_init(struct adapter *adapter)
1654 struct sliccard *card = adapter->card;
1655 struct net_device *dev = adapter->netdev;
1656 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1657 struct slic_shmem *pshmem;
1661 DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1662 __func__, adapter->netdev->name,
1663 adapter->queues_initialized, adapter->state, adapter->linkstate,
1664 card->state, dev->flags);
1666 /* adapter should be down at this point */
1667 if (adapter->state != ADAPT_DOWN) {
1668 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1671 ASSERT(adapter->linkstate == LINK_DOWN);
1673 adapter->devflags_prev = dev->flags;
1674 adapter->macopts = MAC_DIRECTED;
1676 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1677 adapter->netdev->name);
1678 if (dev->flags & IFF_BROADCAST) {
1679 adapter->macopts |= MAC_BCAST;
1682 if (dev->flags & IFF_PROMISC) {
1683 adapter->macopts |= MAC_PROMISC;
1684 DBG_MSG("PROMISC ");
1686 if (dev->flags & IFF_ALLMULTI) {
1687 adapter->macopts |= MAC_ALLMCAST;
1688 DBG_MSG("ALL_MCAST ");
1690 if (dev->flags & IFF_MULTICAST) {
1691 adapter->macopts |= MAC_MCAST;
1696 status = slic_adapter_allocresources(adapter);
1697 if (status != STATUS_SUCCESS) {
1699 ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1701 slic_adapter_freeresources(adapter);
1705 if (!adapter->queues_initialized) {
1706 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1707 if (slic_rspqueue_init(adapter))
1710 ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1711 __func__, adapter, adapter->port);
1712 if (slic_cmdq_init(adapter))
1715 ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1716 port %d \n", __func__, adapter, adapter->port);
1717 if (slic_rcvqueue_init(adapter))
1719 adapter->queues_initialized = 1;
1721 DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1723 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1726 if (!adapter->isp_initialized) {
1727 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1729 spin_lock_irqsave(&adapter->bit64reglock.lock,
1730 adapter->bit64reglock.flags);
1732 #if defined(CONFIG_X86_64)
1733 slic_reg32_write(&slic_regs->slic_addr_upper,
1734 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1735 slic_reg32_write(&slic_regs->slic_isp,
1736 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1737 #elif defined(CONFIG_X86)
1738 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1739 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
1743 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1744 adapter->bit64reglock.flags);
1745 adapter->isp_initialized = 1;
1748 adapter->state = ADAPT_UP;
1749 if (!card->loadtimerset) {
1750 init_timer(&card->loadtimer);
1751 card->loadtimer.expires =
1752 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1753 card->loadtimer.data = (ulong) card;
1754 card->loadtimer.function = &slic_timer_load_check;
1755 add_timer(&card->loadtimer);
1757 card->loadtimerset = 1;
1759 #if SLIC_PING_TIMER_ENABLED
1760 if (!adapter->pingtimerset) {
1761 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1763 init_timer(&adapter->pingtimer);
1764 adapter->pingtimer.expires =
1765 jiffies + (PING_TIMER_INTERVAL * HZ);
1766 adapter->pingtimer.data = (ulong) dev;
1767 adapter->pingtimer.function = &slic_timer_ping;
1768 add_timer(&adapter->pingtimer);
1769 adapter->pingtimerset = 1;
1770 adapter->card->pingstatus = ISR_PINGMASK;
1775 * clear any pending events, then enable interrupts
1777 DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1778 adapter->isrcopy = 0;
1779 adapter->pshmem->isr = 0;
1780 slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
1781 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1783 DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1784 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1785 slic_link_event_handler(adapter);
1787 DBG_MSG("slicoss: %s EXIT\n", __func__);
1788 return STATUS_SUCCESS;
1791 static void slic_unmap_mmio_space(struct adapter *adapter)
1793 #if LINUX_FREES_ADAPTER_RESOURCES
1794 if (adapter->slic_regs)
1795 iounmap(adapter->slic_regs);
1796 adapter->slic_regs = NULL;
1800 static int slic_adapter_allocresources(struct adapter *adapter)
1802 if (!adapter->intrregistered) {
1806 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1807 phys_shmem[%p] dev->irq[%x] %x\n",
1808 __func__, adapter, adapter->pshmem,
1809 (void *)adapter->phys_shmem, adapter->netdev->irq,
1812 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1813 slic_global.driver_lock.flags);
1815 retval = request_irq(adapter->netdev->irq,
1818 adapter->netdev->name, adapter->netdev);
1820 spin_lock_irqsave(&slic_global.driver_lock.lock,
1821 slic_global.driver_lock.flags);
1824 DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1825 adapter->netdev->name, retval);
1828 adapter->intrregistered = 1;
1830 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1831 pshmem[%p] dev->irq[%x]\n",
1832 __func__, adapter, adapter->pshmem,
1833 (void *)adapter->pshmem, adapter->netdev->irq);
1835 return STATUS_SUCCESS;
1838 static void slic_config_pci(struct pci_dev *pcidev)
1843 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1844 DBG_MSG("slicoss: %s PCI command[%4.4x]\n", __func__, pci_command);
1846 new_command = pci_command | PCI_COMMAND_MASTER
1847 | PCI_COMMAND_MEMORY
1848 | PCI_COMMAND_INVALIDATE
1849 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1850 if (pci_command != new_command) {
1851 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1852 __func__, pci_command, new_command);
1853 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1857 static void slic_adapter_freeresources(struct adapter *adapter)
1859 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1860 slic_init_cleanup(adapter);
1861 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1862 adapter->error_interrupts = 0;
1863 adapter->rcv_interrupts = 0;
1864 adapter->xmit_interrupts = 0;
1865 adapter->linkevent_interrupts = 0;
1866 adapter->upr_interrupts = 0;
1867 adapter->num_isrs = 0;
1868 adapter->xmit_completes = 0;
1869 adapter->rcv_broadcasts = 0;
1870 adapter->rcv_multicasts = 0;
1871 adapter->rcv_unicasts = 0;
1872 DBG_MSG("slicoss: %s EXIT\n", __func__);
1878 * Write phy control to configure link duplex/speed
1881 static void slic_link_config(struct adapter *adapter,
1882 u32 linkspeed, u32 linkduplex)
1891 if (adapter->state != ADAPT_UP) {
1893 ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1894 __func__, adapter->netdev->name, linkspeed,
1898 DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1899 __func__, adapter->netdev->name, linkspeed, linkduplex);
1901 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1902 || (adapter->devid == SLIC_2GB_DEVICE_ID));
1904 if (linkspeed > LINK_1000MB)
1905 linkspeed = LINK_AUTOSPEED;
1906 if (linkduplex > LINK_AUTOD)
1907 linkduplex = LINK_AUTOD;
1909 wphy = &adapter->slic_regs->slic_wphy;
1911 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
1912 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
1913 /* We've got a fiber gigabit interface, and register
1914 * 4 is different in fiber mode than in copper mode
1917 /* advertise FD only @1000 Mb */
1918 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
1919 /* enable PAUSE frames */
1920 phy_advreg |= PAR_ASYMPAUSE_FIBER;
1921 slic_reg32_write(wphy, phy_advreg, FLUSH);
1923 if (linkspeed == LINK_AUTOSPEED) {
1924 /* reset phy, enable auto-neg */
1927 (PCR_RESET | PCR_AUTONEG |
1929 slic_reg32_write(wphy, phy_config, FLUSH);
1930 } else { /* forced 1000 Mb FD*/
1931 /* power down phy to break link
1932 this may not work) */
1933 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
1934 slic_reg32_write(wphy, phy_config, FLUSH);
1935 /* wait, Marvell says 1 sec,
1936 try to get away with 10 ms */
1939 /* disable auto-neg, set speed/duplex,
1940 soft reset phy, powerup */
1943 (PCR_RESET | PCR_SPEED_1000 |
1945 slic_reg32_write(wphy, phy_config, FLUSH);
1947 } else { /* copper gigabit */
1949 /* Auto-Negotiate or 1000 Mb must be auto negotiated
1950 * We've got a copper gigabit interface, and
1951 * register 4 is different in copper mode than
1954 if (linkspeed == LINK_AUTOSPEED) {
1955 /* advertise 10/100 Mb modes */
1958 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
1961 /* linkspeed == LINK_1000MB -
1962 don't advertise 10/100 Mb modes */
1963 phy_advreg = MIICR_REG_4;
1965 /* enable PAUSE frames */
1966 phy_advreg |= PAR_ASYMPAUSE;
1967 /* required by the Cicada PHY */
1968 phy_advreg |= PAR_802_3;
1969 slic_reg32_write(wphy, phy_advreg, FLUSH);
1970 /* advertise FD only @1000 Mb */
1971 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
1972 slic_reg32_write(wphy, phy_gctlreg, FLUSH);
1974 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1976 enable auto crossover */
1978 (MIICR_REG_16 | (MRV_REG16_XOVERON));
1979 slic_reg32_write(wphy, phy_config, FLUSH);
1981 /* reset phy, enable auto-neg */
1984 (PCR_RESET | PCR_AUTONEG |
1986 slic_reg32_write(wphy, phy_config, FLUSH);
1987 } else { /* it's a Cicada PHY */
1988 /* enable and restart auto-neg (don't reset) */
1991 (PCR_AUTONEG | PCR_AUTONEG_RST));
1992 slic_reg32_write(wphy, phy_config, FLUSH);
1997 if (linkspeed == LINK_10MB)
2000 speed = PCR_SPEED_100;
2001 if (linkduplex == LINK_HALFD)
2004 duplex = PCR_DUPLEX_FULL;
2006 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2008 disable auto crossover */
2009 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2010 slic_reg32_write(wphy, phy_config, FLUSH);
2013 /* power down phy to break link (this may not work) */
2014 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2015 slic_reg32_write(wphy, phy_config, FLUSH);
2017 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2020 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2022 disable auto-neg, set speed,
2023 soft reset phy, powerup */
2025 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2026 slic_reg32_write(wphy, phy_config, FLUSH);
2027 } else { /* it's a Cicada PHY */
2028 /* disable auto-neg, set speed, powerup */
2029 phy_config = (MIICR_REG_PCR | (speed | duplex));
2030 slic_reg32_write(wphy, phy_config, FLUSH);
2035 ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2036 phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2040 static void slic_card_cleanup(struct sliccard *card)
2042 DBG_MSG("slicoss: %s ENTER\n", __func__);
2044 if (card->loadtimerset) {
2045 card->loadtimerset = 0;
2046 del_timer(&card->loadtimer);
2049 slic_debug_card_destroy(card);
2052 DBG_MSG("slicoss: %s EXIT\n", __func__);
2055 static int slic_card_download_gbrcv(struct adapter *adapter)
2057 const struct firmware *fw;
2058 const char *file = "";
2060 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2064 u32 rcvucodelen = 0;
2066 switch (adapter->devid) {
2067 case SLIC_2GB_DEVICE_ID:
2068 file = "slicoss/oasisrcvucode.sys";
2070 case SLIC_1GB_DEVICE_ID:
2071 file = "slicoss/gbrcvucode.sys";
2078 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2080 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2084 rcvucodelen = *(u32 *)(fw->data + index);
2086 switch (adapter->devid) {
2087 case SLIC_2GB_DEVICE_ID:
2088 if (rcvucodelen != OasisRcvUCodeLen)
2091 case SLIC_1GB_DEVICE_ID:
2092 if (rcvucodelen != GBRcvUCodeLen)
2099 /* start download */
2100 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2101 /* download the rcv sequencer ucode */
2102 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2103 /* write out instruction address */
2104 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2106 instruction = *(u32 *)(fw->data + index);
2108 /* write out the instruction data low addr */
2109 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
2111 instruction = *(u8 *)(fw->data + index);
2113 /* write out the instruction data high addr */
2114 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
2118 /* download finished */
2119 release_firmware(fw);
2120 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2124 static int slic_card_download(struct adapter *adapter)
2126 const struct firmware *fw;
2127 const char *file = "";
2130 int thissectionsize;
2132 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2140 int ucode_start, index = 0;
2142 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2143 jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2144 adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2146 switch (adapter->devid) {
2147 case SLIC_2GB_DEVICE_ID:
2148 file = "slicoss/oasisdownload.sys";
2150 case SLIC_1GB_DEVICE_ID:
2151 file = "slicoss/gbdownload.sys";
2157 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2159 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2162 numsects = *(u32 *)(fw->data + index);
2164 ASSERT(numsects <= 3);
2165 for (i = 0; i < numsects; i++) {
2166 sectsize[i] = *(u32 *)(fw->data + index);
2169 for (i = 0; i < numsects; i++) {
2170 sectstart[i] = *(u32 *)(fw->data + index);
2173 ucode_start = index;
2174 instruction = *(u32 *)(fw->data + index);
2176 for (section = 0; section < numsects; section++) {
2177 baseaddress = sectstart[section];
2178 thissectionsize = sectsize[section] >> 3;
2180 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2181 /* Write out instruction address */
2182 slic_reg32_write(&slic_regs->slic_wcs,
2183 baseaddress + codeaddr, FLUSH);
2184 /* Write out instruction to low addr */
2185 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2186 instruction = *(u32 *)(fw->data + index);
2189 /* Write out instruction to high addr */
2190 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2191 instruction = *(u32 *)(fw->data + index);
2195 index = ucode_start;
2196 for (section = 0; section < numsects; section++) {
2197 instruction = *(u32 *)(fw->data + index);
2198 baseaddress = sectstart[section];
2199 if (baseaddress < 0x8000)
2201 thissectionsize = sectsize[section] >> 3;
2203 /* DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2204 (uint)section,baseaddress,thissectionsize);*/
2205 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2206 /* Write out instruction address */
2207 slic_reg32_write(&slic_regs->slic_wcs,
2208 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2210 /* Write out instruction to low addr */
2211 slic_reg32_write(&slic_regs->slic_wcs, instruction,
2213 instruction = *(u32 *)(fw->data + index);
2215 /* Write out instruction to high addr */
2216 slic_reg32_write(&slic_regs->slic_wcs, instruction,
2218 instruction = *(u32 *)(fw->data + index);
2221 /* Check SRAM location zero. If it is non-zero. Abort.*/
2222 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2225 ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2226 "thissectionsize[%x] failure[%x]\n",
2227 __func__, codeaddr, thissectionsize,
2229 release_firmware(fw);
2234 /* DBG_MSG ("slicoss: Compare done\n");*/
2235 release_firmware(fw);
2236 /* Everything OK, kick off the card */
2238 slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2240 /* stall for 20 ms, long enough for ucode to init card
2241 and reach mainloop */
2244 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2245 __func__, adapter->netdev->name, adapter, adapter->card);
2247 return STATUS_SUCCESS;
2250 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2252 struct sliccard *card = adapter->card;
2254 /* DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2255 __func__, card->config_set, adapter->port, adapter->physport,
2256 adapter->functionnumber);
2258 slic_dbg_macaddrs(adapter); */
2260 if ((adapter->card) && (card->config_set)) {
2261 memcpy(adapter->macaddr,
2262 card->config.MacInfo[adapter->functionnumber].macaddrA,
2263 sizeof(struct slic_config_mac));
2264 /* DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2266 slic_dbg_macaddrs(adapter);*/
2267 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2268 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2269 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2270 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2272 if (adapter->netdev) {
2273 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2277 /* DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2278 slic_dbg_macaddrs(adapter); */
2281 static void slic_intagg_set(struct adapter *adapter, u32 value)
2283 slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
2284 adapter->card->loadlevel_current = value;
2287 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2289 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2290 struct slic_eeprom *peeprom;
2291 struct oslic_eeprom *pOeeprom;
2292 dma_addr_t phys_config;
2296 struct slic_shmem *pshmem;
2298 uint macaddrs = card->card_size;
2303 struct slic_config_mac *pmac;
2304 unsigned char fruformat;
2305 unsigned char oemfruformat;
2306 struct atk_fru *patkfru;
2307 union oemfru *poemfru;
2310 ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2311 size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2313 /* Reset everything except PCI configuration space */
2314 slic_soft_reset(adapter);
2316 /* Download the microcode */
2317 status = slic_card_download(adapter);
2319 if (status != STATUS_SUCCESS) {
2320 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2321 (uint) adapter->busnumber,
2322 (uint) adapter->slotnumber);
2326 if (!card->config_set) {
2327 peeprom = pci_alloc_consistent(adapter->pcidev,
2328 sizeof(struct slic_eeprom),
2331 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2332 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2334 DBG_MSG("slicoss: %s Eeprom info adapter [%p]\n "
2335 "size [%x]\n peeprom [%p]\n "
2336 "phys_config [%p]\n phys_configl[%x]\n "
2337 "phys_configh[%x]\n",
2339 (u32)sizeof(struct slic_eeprom),
2340 peeprom, (void *) phys_config, phys_configl,
2344 ("SLIC eeprom read failed to get memory bus %d \
2346 (uint) adapter->busnumber,
2347 (uint) adapter->slotnumber);
2350 memset(peeprom, 0, sizeof(struct slic_eeprom));
2352 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2354 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2356 spin_lock_irqsave(&adapter->bit64reglock.lock,
2357 adapter->bit64reglock.flags);
2358 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2359 slic_reg32_write(&slic_regs->slic_isp,
2360 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2361 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2362 adapter->bit64reglock.flags);
2364 slic_config_get(adapter, phys_configl, phys_configh);
2367 if (adapter->pshmem->isr) {
2368 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2369 __func__, adapter->pshmem,
2370 adapter->pshmem->isr);
2372 if (adapter->pshmem->isr & ISR_UPC) {
2373 adapter->pshmem->isr = 0;
2374 slic_reg64_write(adapter,
2375 &slic_regs->slic_isp, 0,
2376 &slic_regs->slic_addr_upper,
2378 slic_reg32_write(&slic_regs->slic_isr,
2381 slic_upr_request_complete(adapter, 0);
2384 adapter->pshmem->isr = 0;
2385 slic_reg32_write(&slic_regs->slic_isr,
2393 ("SLIC: %d config data fetch timed "
2394 "out!\n", adapter->port);
2395 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2396 __func__, adapter->pshmem,
2397 adapter->pshmem->isr);
2398 slic_reg64_write(adapter,
2399 &slic_regs->slic_isp, 0,
2400 &slic_regs->slic_addr_upper,
2407 switch (adapter->devid) {
2409 case SLIC_2GB_DEVICE_ID:
2410 /* extract EEPROM data and pointers to EEPROM data */
2411 pOeeprom = (struct oslic_eeprom *) peeprom;
2412 eecodesize = pOeeprom->EecodeSize;
2413 dramsize = pOeeprom->DramSize;
2414 pmac = pOeeprom->MacInfo;
2415 fruformat = pOeeprom->FruFormat;
2416 patkfru = &pOeeprom->AtkFru;
2417 oemfruformat = pOeeprom->OemFruFormat;
2418 poemfru = &pOeeprom->OemFru;
2420 /* Minor kludge for Oasis card
2421 get 2 MAC addresses from the
2422 EEPROM to ensure that function 1
2423 gets the Port 1 MAC address */
2426 /* extract EEPROM data and pointers to EEPROM data */
2427 eecodesize = peeprom->EecodeSize;
2428 dramsize = peeprom->DramSize;
2429 pmac = peeprom->u2.mac.MacInfo;
2430 fruformat = peeprom->FruFormat;
2431 patkfru = &peeprom->AtkFru;
2432 oemfruformat = peeprom->OemFruFormat;
2433 poemfru = &peeprom->OemFru;
2437 card->config.EepromValid = false;
2439 /* see if the EEPROM is valid by checking it's checksum */
2440 if ((eecodesize <= MAX_EECODE_SIZE) &&
2441 (eecodesize >= MIN_EECODE_SIZE)) {
2444 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2446 calculate the EEPROM checksum
2449 ~slic_eeprom_cksum((char *) peeprom,
2452 if the ucdoe chksum flag bit worked,
2453 we wouldn't need this shit
2455 if (ee_chksum == calc_chksum)
2456 card->config.EepromValid = true;
2458 /* copy in the DRAM size */
2459 card->config.DramSize = dramsize;
2461 /* copy in the MAC address(es) */
2462 for (i = 0; i < macaddrs; i++) {
2463 memcpy(&card->config.MacInfo[i],
2464 &pmac[i], sizeof(struct slic_config_mac));
2466 /* DBG_MSG ("%s EEPROM Checksum Good? %d MacAddress\n",__func__,
2467 card->config.EepromValid); */
2469 /* copy the Alacritech FRU information */
2470 card->config.FruFormat = fruformat;
2471 memcpy(&card->config.AtkFru, patkfru,
2472 sizeof(struct atk_fru));
2474 pci_free_consistent(adapter->pcidev,
2475 sizeof(struct slic_eeprom),
2476 peeprom, phys_config);
2478 ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2480 __func__, adapter->port, adapter,
2481 (u32) sizeof(struct slic_eeprom), peeprom,
2482 (void *) phys_config);
2484 if ((!card->config.EepromValid) &&
2485 (adapter->reg_params.fail_on_bad_eeprom)) {
2486 slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2487 &slic_regs->slic_addr_upper,
2490 ("unsupported CONFIGURATION EEPROM invalid\n");
2494 card->config_set = 1;
2497 if (slic_card_download_gbrcv(adapter)) {
2498 DBG_ERROR("%s unable to download GB receive microcode\n",
2503 if (slic_global.dynamic_intagg) {
2505 ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2506 SET intagg to %d\n",
2508 slic_intagg_set(adapter, 0);
2510 slic_intagg_set(adapter, intagg_delay);
2512 ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2513 SET intagg to %d\n",
2514 card->cardnum, intagg_delay);
2518 * Initialize ping status to "ok"
2520 card->pingstatus = ISR_PINGMASK;
2523 * Lastly, mark our card state as up and return success
2525 card->state = CARD_UP;
2526 card->reset_in_progress = 0;
2527 DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2528 __func__, card, adapter, card->state);
2530 return STATUS_SUCCESS;
2533 static u32 slic_card_locate(struct adapter *adapter)
2535 struct sliccard *card = slic_global.slic_card;
2536 struct physcard *physcard = slic_global.phys_card;
2538 u16 __iomem *hostid_reg;
2540 uint rdhostid_offset = 0;
2542 DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2543 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2546 switch (adapter->devid) {
2547 case SLIC_2GB_DEVICE_ID:
2548 rdhostid_offset = SLIC_RDHOSTID_2GB;
2550 case SLIC_1GB_DEVICE_ID:
2551 rdhostid_offset = SLIC_RDHOSTID_1GB;
2559 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2561 DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2563 /* read the 16 bit hostid from SRAM */
2564 card_hostid = (ushort) readw(hostid_reg);
2565 DBG_MSG(" card_hostid[%x]\n", card_hostid);
2567 /* Initialize a new card structure if need be */
2568 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2569 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2573 card->next = slic_global.slic_card;
2574 slic_global.slic_card = card;
2576 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2578 ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2579 "and Storage Accelerator\n");
2582 ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2583 "and Storage Accelerator\n");
2586 card->busnumber = adapter->busnumber;
2587 card->slotnumber = adapter->slotnumber;
2589 /* Find an available cardnum */
2590 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2591 if (slic_global.cardnuminuse[i] == 0) {
2592 slic_global.cardnuminuse[i] = 1;
2597 slic_global.num_slic_cards++;
2598 DBG_MSG("\nCARDNUM == %d Total %d Card[%p]\n\n",
2599 card->cardnum, slic_global.num_slic_cards, card);
2601 slic_debug_card_create(card);
2604 ("slicoss: %s CARD already allocated, find the \
2605 correct card\n", __func__);
2606 /* Card exists, find the card this adapter belongs to */
2609 ("slicoss: %s card[%p] slot[%x] bus[%x] \
2610 adaptport[%p] hostid[%x] cardnum[%x]\n",
2611 __func__, card, card->slotnumber,
2612 card->busnumber, card->adapter[adapter->port],
2613 card_hostid, card->cardnum);
2615 if (card->cardnum == card_hostid)
2623 return STATUS_FAILURE;
2624 /* Put the adapter in the card's adapter list */
2625 ASSERT(card->adapter[adapter->port] == NULL);
2626 if (!card->adapter[adapter->port]) {
2627 card->adapter[adapter->port] = adapter;
2628 adapter->card = card;
2631 card->card_size = 1; /* one port per *logical* card */
2634 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2635 if (!physcard->adapter[i])
2640 ASSERT(i != SLIC_MAX_PORTS);
2641 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2643 physcard = physcard->next;
2646 /* no structure allocated for this physical card yet */
2647 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2651 ("\n%s Allocate a PHYSICALcard:\n PHYSICAL_Card[%p]\n"
2652 " LogicalCard [%p]\n adapter [%p]\n",
2653 __func__, physcard, card, adapter);
2655 physcard->next = slic_global.phys_card;
2656 slic_global.phys_card = physcard;
2657 physcard->adapters_allocd = 1;
2659 physcard->adapters_allocd++;
2661 /* Note - this is ZERO relative */
2662 adapter->physport = physcard->adapters_allocd - 1;
2664 ASSERT(physcard->adapter[adapter->physport] == NULL);
2665 physcard->adapter[adapter->physport] = adapter;
2666 adapter->physcard = physcard;
2667 DBG_MSG(" PHYSICAL_Port %d Logical_Port %d\n", adapter->physport,
2673 static void slic_soft_reset(struct adapter *adapter)
2675 if (adapter->card->state == CARD_UP) {
2676 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2677 __func__, adapter, adapter->card, adapter->devid);
2678 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
2681 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2682 __func__, adapter->netdev->name, adapter, adapter->card,
2685 slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2690 static void slic_config_set(struct adapter *adapter, bool linkchange)
2694 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2696 DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2697 __func__, adapter->netdev->name, adapter,
2698 adapter->cardindex);
2702 slic_mac_config(adapter);
2703 RcrReset = GRCR_RESET;
2705 slic_mac_address_config(adapter);
2709 if (adapter->linkduplex == LINK_FULLD) {
2711 value = (GXCR_RESET | /* Always reset */
2712 GXCR_XMTEN | /* Enable transmit */
2713 GXCR_PAUSEEN); /* Enable pause */
2715 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2717 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2719 /* Setup rcvcfg last */
2720 value = (RcrReset | /* Reset, if linkchange */
2721 GRCR_CTLEN | /* Enable CTL frames */
2722 GRCR_ADDRAEN | /* Address A enable */
2723 GRCR_RCVBAD | /* Rcv bad frames */
2724 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2727 value = (GXCR_RESET | /* Always reset */
2728 GXCR_XMTEN); /* Enable transmit */
2730 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2732 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2734 /* Setup rcvcfg last */
2735 value = (RcrReset | /* Reset, if linkchange */
2736 GRCR_ADDRAEN | /* Address A enable */
2737 GRCR_RCVBAD | /* Rcv bad frames */
2738 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2741 if (adapter->state != ADAPT_DOWN) {
2742 /* Only enable receive if we are restarting or running */
2743 value |= GRCR_RCVEN;
2746 if (adapter->macopts & MAC_PROMISC)
2747 value |= GRCR_RCVALL;
2749 DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2750 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2754 * Turn off RCV and XMT, power down PHY
2756 static void slic_config_clear(struct adapter *adapter)
2760 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2763 value = (GXCR_RESET | /* Always reset */
2764 GXCR_PAUSEEN); /* Enable pause */
2766 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2768 value = (GRCR_RESET | /* Always reset */
2769 GRCR_CTLEN | /* Enable CTL frames */
2770 GRCR_ADDRAEN | /* Address A enable */
2771 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2773 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2775 /* power down phy */
2776 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2777 slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2780 static void slic_config_get(struct adapter *adapter, u32 config,
2785 status = slic_upr_request(adapter,
2787 (u32) config, (u32) config_h, 0, 0);
2788 ASSERT(status == 0);
2791 static void slic_mac_address_config(struct adapter *adapter)
2795 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2797 value = *(u32 *) &adapter->currmacaddr[2];
2798 value = ntohl(value);
2799 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
2800 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
2802 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2803 adapter->currmacaddr[1]) & 0xFFFF);
2805 slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2806 slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2808 DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2809 __func__, value, value2);
2810 slic_dbg_macaddrs(adapter);
2812 /* Write our multicast mask out to the card. This is done */
2813 /* here in addition to the slic_mcast_addr_set routine */
2814 /* because ALL_MCAST may have been enabled or disabled */
2815 slic_mcast_set_mask(adapter);
2818 static void slic_mac_config(struct adapter *adapter)
2821 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2823 /* Setup GMAC gaps */
2824 if (adapter->linkspeed == LINK_1000MB) {
2825 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2826 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2827 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2829 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2830 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2831 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2835 if (adapter->linkspeed == LINK_1000MB)
2838 /* enable fullduplex */
2839 if ((adapter->linkduplex == LINK_FULLD)
2840 || (adapter->macopts & MAC_LOOPBACK)) {
2841 value |= GMCR_FULLD;
2844 /* write mac config */
2845 slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2847 /* setup mac addresses */
2848 slic_mac_address_config(adapter);
2851 static bool slic_mac_filter(struct adapter *adapter,
2852 struct ether_header *ether_frame)
2854 u32 opts = adapter->macopts;
2855 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
2856 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
2859 if (opts & MAC_PROMISC) {
2860 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
2861 __func__, adapter->netdev->name);
2865 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
2866 if (opts & MAC_BCAST) {
2867 adapter->rcv_broadcasts++;
2874 if (ether_frame->ether_dhost[0] & 0x01) {
2875 if (opts & MAC_ALLMCAST) {
2876 adapter->rcv_multicasts++;
2877 adapter->stats.multicast++;
2880 if (opts & MAC_MCAST) {
2881 struct mcast_address *mcaddr = adapter->mcastaddrs;
2884 ETHER_EQ_ADDR(mcaddr->address,
2885 ether_frame->ether_dhost,
2888 adapter->rcv_multicasts++;
2889 adapter->stats.multicast++;
2892 mcaddr = mcaddr->next;
2899 if (opts & MAC_DIRECTED) {
2900 adapter->rcv_unicasts++;
2907 static int slic_mac_set_address(struct net_device *dev, void *ptr)
2909 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
2910 struct sockaddr *addr = ptr;
2912 DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
2914 if (netif_running(dev))
2918 DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2919 __func__, adapter->netdev->name, adapter->currmacaddr[0],
2920 adapter->currmacaddr[1], adapter->currmacaddr[2],
2921 adapter->currmacaddr[3], adapter->currmacaddr[4],
2922 adapter->currmacaddr[5]);
2923 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2924 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
2925 DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2926 __func__, adapter->netdev->name, adapter->currmacaddr[0],
2927 adapter->currmacaddr[1], adapter->currmacaddr[2],
2928 adapter->currmacaddr[3], adapter->currmacaddr[4],
2929 adapter->currmacaddr[5]);
2931 slic_config_set(adapter, true);
2935 static void slic_timer_load_check(ulong cardaddr)
2937 struct sliccard *card = (struct sliccard *)cardaddr;
2938 struct adapter *adapter = card->master;
2939 u32 __iomem *intagg;
2940 u32 load = card->events;
2943 intagg = &adapter->slic_regs->slic_intagg;
2945 if ((adapter) && (adapter->state == ADAPT_UP) &&
2946 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
2947 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
2948 if (adapter->linkspeed == LINK_1000MB)
2951 if (load > SLIC_LOAD_5)
2952 level = SLIC_INTAGG_5;
2953 else if (load > SLIC_LOAD_4)
2954 level = SLIC_INTAGG_4;
2955 else if (load > SLIC_LOAD_3)
2956 level = SLIC_INTAGG_3;
2957 else if (load > SLIC_LOAD_2)
2958 level = SLIC_INTAGG_2;
2959 else if (load > SLIC_LOAD_1)
2960 level = SLIC_INTAGG_1;
2962 level = SLIC_INTAGG_0;
2964 if (card->loadlevel_current != level) {
2965 card->loadlevel_current = level;
2966 slic_reg32_write(intagg, level, FLUSH);
2969 if (load > SLIC_LOAD_5)
2970 level = SLIC_INTAGG_5;
2971 else if (load > SLIC_LOAD_4)
2972 level = SLIC_INTAGG_4;
2973 else if (load > SLIC_LOAD_3)
2974 level = SLIC_INTAGG_3;
2975 else if (load > SLIC_LOAD_2)
2976 level = SLIC_INTAGG_2;
2977 else if (load > SLIC_LOAD_1)
2978 level = SLIC_INTAGG_1;
2980 level = SLIC_INTAGG_0;
2981 if (card->loadlevel_current != level) {
2982 card->loadlevel_current = level;
2983 slic_reg32_write(intagg, level, FLUSH);
2988 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2989 add_timer(&card->loadtimer);
2992 static void slic_assert_fail(void)
2996 cpuid = smp_processor_id();
2997 curr_pid = current->pid;
2999 DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3002 static int slic_upr_queue_request(struct adapter *adapter,
3006 u32 upr_buffer, u32 upr_buffer_h)
3008 struct slic_upr *upr;
3009 struct slic_upr *uprqueue;
3011 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3013 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3017 upr->adapter = adapter->port;
3018 upr->upr_request = upr_request;
3019 upr->upr_data = upr_data;
3020 upr->upr_buffer = upr_buffer;
3021 upr->upr_data_h = upr_data_h;
3022 upr->upr_buffer_h = upr_buffer_h;
3024 if (adapter->upr_list) {
3025 uprqueue = adapter->upr_list;
3027 while (uprqueue->next)
3028 uprqueue = uprqueue->next;
3029 uprqueue->next = upr;
3031 adapter->upr_list = upr;
3033 return STATUS_SUCCESS;
3036 static int slic_upr_request(struct adapter *adapter,
3040 u32 upr_buffer, u32 upr_buffer_h)
3044 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3045 status = slic_upr_queue_request(adapter,
3048 upr_data_h, upr_buffer, upr_buffer_h);
3049 if (status != STATUS_SUCCESS) {
3050 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3051 adapter->upr_lock.flags);
3054 slic_upr_start(adapter);
3055 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3056 adapter->upr_lock.flags);
3057 return STATUS_PENDING;
3060 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3062 struct sliccard *card = adapter->card;
3063 struct slic_upr *upr;
3065 /* if (card->dump_requested) {
3066 DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3069 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3070 upr = adapter->upr_list;
3073 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3074 adapter->upr_lock.flags);
3077 adapter->upr_list = upr->next;
3079 adapter->upr_busy = 0;
3080 ASSERT(adapter->port == upr->adapter);
3081 switch (upr->upr_request) {
3082 case SLIC_UPR_STATS:
3084 struct slic_stats *slicstats =
3085 (struct slic_stats *) &adapter->pshmem->inicstats;
3086 struct slic_stats *newstats = slicstats;
3087 struct slic_stats *old = &adapter->inicstats_prev;
3088 struct slicnet_stats *stst = &adapter->slic_stats;
3090 if (isr & ISR_UPCERR) {
3092 ("SLIC_UPR_STATS command failed isr[%x]\n",
3097 /* DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3098 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3100 slicstats->rcv_unicasts100,
3101 slicstats->rcv_bytes100,
3102 slicstats->rcv_bytes100,
3103 slicstats->rcv_tcp_bytes100,
3104 slicstats->rcv_tcp_segs100,
3105 slicstats->rcv_other_error100,
3106 slicstats->rcv_drops100,
3107 slicstats->xmit_unicasts100,
3108 slicstats->xmit_bytes100,
3109 slicstats->xmit_bytes100,
3110 slicstats->xmit_tcp_bytes100,
3111 slicstats->xmit_tcp_segs100,
3112 slicstats->xmit_other_error100,
3113 slicstats->xmit_collisions100);*/
3114 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3115 newstats->xmit_tcp_segs_gb,
3116 old->xmit_tcp_segs_gb);
3118 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3119 newstats->xmit_tcp_bytes_gb,
3120 old->xmit_tcp_bytes_gb);
3122 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3123 newstats->rcv_tcp_segs_gb,
3124 old->rcv_tcp_segs_gb);
3126 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3127 newstats->rcv_tcp_bytes_gb,
3128 old->rcv_tcp_bytes_gb);
3130 UPDATE_STATS_GB(stst->iface.xmt_bytes,
3131 newstats->xmit_bytes_gb,
3132 old->xmit_bytes_gb);
3134 UPDATE_STATS_GB(stst->iface.xmt_ucast,
3135 newstats->xmit_unicasts_gb,
3136 old->xmit_unicasts_gb);
3138 UPDATE_STATS_GB(stst->iface.rcv_bytes,
3139 newstats->rcv_bytes_gb,
3142 UPDATE_STATS_GB(stst->iface.rcv_ucast,
3143 newstats->rcv_unicasts_gb,
3144 old->rcv_unicasts_gb);
3146 UPDATE_STATS_GB(stst->iface.xmt_errors,
3147 newstats->xmit_collisions_gb,
3148 old->xmit_collisions_gb);
3150 UPDATE_STATS_GB(stst->iface.xmt_errors,
3151 newstats->xmit_excess_collisions_gb,
3152 old->xmit_excess_collisions_gb);
3154 UPDATE_STATS_GB(stst->iface.xmt_errors,
3155 newstats->xmit_other_error_gb,
3156 old->xmit_other_error_gb);
3158 UPDATE_STATS_GB(stst->iface.rcv_errors,
3159 newstats->rcv_other_error_gb,
3160 old->rcv_other_error_gb);
3162 UPDATE_STATS_GB(stst->iface.rcv_discards,
3163 newstats->rcv_drops_gb,
3166 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3167 adapter->rcv_drops +=
3168 (newstats->rcv_drops_gb -
3171 memcpy(old, newstats, sizeof(struct slic_stats));
3175 slic_link_upr_complete(adapter, isr);
3177 case SLIC_UPR_RCONFIG:
3192 card->pingstatus |= (isr & ISR_PINGDSMASK);
3198 slic_upr_start(adapter);
3199 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3200 adapter->upr_lock.flags);
3203 static void slic_upr_start(struct adapter *adapter)
3205 struct slic_upr *upr;
3206 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3212 upr = adapter->upr_list;
3215 if (adapter->upr_busy)
3217 adapter->upr_busy = 1;
3219 switch (upr->upr_request) {
3220 case SLIC_UPR_STATS:
3221 if (upr->upr_data_h == 0) {
3222 slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
3225 slic_reg64_write(adapter, &slic_regs->slic_stats64,
3227 &slic_regs->slic_addr_upper,
3228 upr->upr_data_h, FLUSH);
3233 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
3234 &slic_regs->slic_addr_upper, upr->upr_data_h,
3238 case SLIC_UPR_RCONFIG:
3239 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3240 DBG_MSG("slic_reg64_write adapter[%p]\n"
3241 " a->slic_regs[%p] slic_regs[%p]\n"
3242 " &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3244 " uprdata[%x] uprdatah[%x]\n",
3245 adapter, adapter->slic_regs, slic_regs,
3246 &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3247 upr, upr->upr_data, upr->upr_data_h);
3248 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
3249 upr->upr_data, &slic_regs->slic_addr_upper,
3250 upr->upr_data_h, FLUSH);
3253 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
3260 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3262 u32 linkstatus = adapter->pshmem->linkstatus;
3264 unsigned char linkspeed;
3265 unsigned char linkduplex;
3267 DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n adapter[%p](%d)\n",
3268 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3269 adapter->cardindex);
3271 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3272 struct slic_shmem *pshmem;
3274 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3275 #if defined(CONFIG_X86_64)
3276 slic_upr_queue_request(adapter,
3278 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3279 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3281 #elif defined(CONFIG_X86)
3282 slic_upr_queue_request(adapter,
3284 (u32) &pshmem->linkstatus,
3285 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3291 if (adapter->state != ADAPT_UP)
3294 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3295 || (adapter->devid == SLIC_2GB_DEVICE_ID));
3297 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3298 if (linkstatus & GIG_SPEED_1000) {
3299 linkspeed = LINK_1000MB;
3300 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB ",
3301 __func__, adapter->netdev->name);
3302 } else if (linkstatus & GIG_SPEED_100) {
3303 linkspeed = LINK_100MB;
3304 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB ", __func__,
3305 adapter->netdev->name);
3307 linkspeed = LINK_10MB;
3308 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB ", __func__,
3309 adapter->netdev->name);
3311 if (linkstatus & GIG_FULLDUPLEX) {
3312 linkduplex = LINK_FULLD;
3313 DBG_MSG(" Duplex == FULL\n");
3315 linkduplex = LINK_HALFD;
3316 DBG_MSG(" Duplex == HALF\n");
3319 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3320 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3321 __func__, adapter->netdev->name, adapter->physport);
3325 /* link up event, but nothing has changed */
3326 if ((adapter->linkstate == LINK_UP) &&
3327 (linkup == LINK_UP) &&
3328 (adapter->linkspeed == linkspeed) &&
3329 (adapter->linkduplex == linkduplex)) {
3330 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3331 __func__, adapter->netdev->name, adapter->physport);
3335 /* link has changed at this point */
3337 /* link has gone from up to down */
3338 if (linkup == LINK_DOWN) {
3339 adapter->linkstate = LINK_DOWN;
3340 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3345 /* link has gone from down to up */
3346 adapter->linkspeed = linkspeed;
3347 adapter->linkduplex = linkduplex;
3349 if (adapter->linkstate != LINK_UP) {
3351 DBG_MSG("%s call slic_config_set\n", __func__);
3352 slic_config_set(adapter, true);
3353 adapter->linkstate = LINK_UP;
3354 DBG_MSG("\n(%s) Link UP: CALL netif_start_queue",
3355 adapter->netdev->name);
3356 netif_start_queue(adapter->netdev);
3359 switch (linkspeed) {
3362 ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB duplex[%x]\n",
3363 adapter->netdev->name, adapter->linkduplex);
3366 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB duplex[%x]\n",
3367 adapter->netdev->name, adapter->linkduplex);
3370 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB duplex[%x]\n",
3371 adapter->netdev->name, adapter->linkduplex);
3378 * this is here to checksum the eeprom, there is some ucode bug
3379 * which prevens us from using the ucode result.
3380 * remove this once ucode is fixed.
3382 static ushort slic_eeprom_cksum(char *m, int len)
3384 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
3385 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3390 u32 byte_swapped = 0;
3407 #ifdef CONFIG_X86_64
3408 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3412 if ((1 & w_int) && (len > 0)) {
3415 s_util.c[0] = *(unsigned char *)w;
3416 w = (u16 *)((char *)w + 1);
3421 /* Unroll the loop to make overhead from branches &c small. */
3422 while ((len -= 32) >= 0) {
3439 w = (u16 *)((ulong) w + 16); /* verify */
3442 while ((len -= 8) >= 0) {
3447 w = (u16 *)((ulong) w + 4); /* verify */
3450 if (len != 0 || byte_swapped != 0) {
3452 while ((len -= 2) >= 0)
3453 sum += *w++; /* verify */
3459 s_util.c[1] = *(char *) w;
3466 } else if (len == -1) {
3467 s_util.c[0] = *(char *) w;
3476 return (ushort) sum;
3479 static int slic_rspqueue_init(struct adapter *adapter)
3482 struct slic_rspqueue *rspq = &adapter->rspqueue;
3483 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3486 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3487 adapter->netdev->name, adapter);
3488 ASSERT(adapter->state == ADAPT_DOWN);
3489 memset(rspq, 0, sizeof(struct slic_rspqueue));
3491 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3493 for (i = 0; i < rspq->num_pages; i++) {
3495 pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3497 if (!rspq->vaddr[i]) {
3499 ("rspqueue_init_failed pci_alloc_consistent\n");
3500 slic_rspqueue_free(adapter);
3501 return STATUS_FAILURE;
3503 #ifndef CONFIG_X86_64
3504 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3505 (u32) rspq->vaddr[i]);
3506 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3507 (u32) rspq->paddr[i]);
3509 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3510 /* DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3512 __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3515 slic_reg32_write(&slic_regs->slic_rbar,
3516 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3519 slic_reg64_write(adapter, &slic_regs->slic_rbar64,
3520 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3521 &slic_regs->slic_addr_upper,
3522 paddrh, DONT_FLUSH);
3526 rspq->pageindex = 0;
3527 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3528 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3529 adapter->netdev->name, adapter);
3530 return STATUS_SUCCESS;
3533 static int slic_rspqueue_reset(struct adapter *adapter)
3535 struct slic_rspqueue *rspq = &adapter->rspqueue;
3537 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3538 adapter->netdev->name, adapter);
3539 ASSERT(adapter->state == ADAPT_DOWN);
3542 DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3546 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3548 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3549 adapter->netdev->name, adapter);
3550 return STATUS_SUCCESS;
3553 static void slic_rspqueue_free(struct adapter *adapter)
3556 struct slic_rspqueue *rspq = &adapter->rspqueue;
3558 DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3559 __func__, adapter, adapter->physport, rspq);
3560 for (i = 0; i < rspq->num_pages; i++) {
3561 if (rspq->vaddr[i]) {
3563 ("slicoss: pci_free_consistent rspq->vaddr[%p] \
3565 rspq->vaddr[i], (void *) rspq->paddr[i]);
3566 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3567 rspq->vaddr[i], rspq->paddr[i]);
3569 rspq->vaddr[i] = NULL;
3573 rspq->pageindex = 0;
3574 rspq->rspbuf = NULL;
3577 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3579 struct slic_rspqueue *rspq = &adapter->rspqueue;
3580 struct slic_rspbuf *buf;
3582 if (!(rspq->rspbuf->status))
3586 #ifndef CONFIG_X86_64
3587 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3589 ASSERT(buf->hosthandle);
3590 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3592 #ifndef CONFIG_X86_64
3593 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3594 (u32) rspq->rspbuf);
3597 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3598 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
3599 (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3600 &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3601 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3603 rspq->rspbuf = (struct slic_rspbuf *)
3604 rspq->vaddr[rspq->pageindex];
3605 #ifndef CONFIG_X86_64
3606 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3607 (u32) rspq->rspbuf);
3610 #ifndef CONFIG_X86_64
3611 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3616 static void slic_cmdqmem_init(struct adapter *adapter)
3618 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3620 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3623 static void slic_cmdqmem_free(struct adapter *adapter)
3625 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3628 DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3629 __func__, adapter, adapter->physport, cmdqmem);
3630 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3631 if (cmdqmem->pages[i]) {
3632 DBG_MSG("slicoss: %s Deallocate page CmdQPage[%p]\n",
3633 __func__, (void *) cmdqmem->pages[i]);
3634 pci_free_consistent(adapter->pcidev,
3636 (void *) cmdqmem->pages[i],
3637 cmdqmem->dma_pages[i]);
3640 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3643 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3645 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3648 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3650 pageaddr = pci_alloc_consistent(adapter->pcidev,
3652 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3655 #ifndef CONFIG_X86_64
3656 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3658 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3663 static int slic_cmdq_init(struct adapter *adapter)
3668 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3669 ASSERT(adapter->state == ADAPT_DOWN);
3670 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3671 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3672 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3673 spin_lock_init(&adapter->cmdq_all.lock.lock);
3674 spin_lock_init(&adapter->cmdq_free.lock.lock);
3675 spin_lock_init(&adapter->cmdq_done.lock.lock);
3676 slic_cmdqmem_init(adapter);
3677 adapter->slic_handle_ix = 1;
3678 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3679 pageaddr = slic_cmdqmem_addpage(adapter);
3680 #ifndef CONFIG_X86_64
3681 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3684 slic_cmdq_free(adapter);
3685 return STATUS_FAILURE;
3687 slic_cmdq_addcmdpage(adapter, pageaddr);
3689 adapter->slic_handle_ix = 1;
3690 DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3692 return STATUS_SUCCESS;
3695 static void slic_cmdq_free(struct adapter *adapter)
3697 struct slic_hostcmd *cmd;
3699 DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3700 __func__, adapter, adapter->physport);
3701 cmd = adapter->cmdq_all.head;
3704 struct sk_buff *tempskb;
3709 dev_kfree_skb_irq(tempskb);
3712 cmd = cmd->next_all;
3714 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3715 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3716 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3717 slic_cmdqmem_free(adapter);
3720 static void slic_cmdq_reset(struct adapter *adapter)
3722 struct slic_hostcmd *hcmd;
3723 struct sk_buff *skb;
3726 DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3727 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3728 adapter->cmdq_free.lock.flags);
3729 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3730 adapter->cmdq_done.lock.flags);
3731 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3732 outstanding -= adapter->cmdq_free.count;
3733 hcmd = adapter->cmdq_all.head;
3738 DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3742 DBG_MSG(" Free SKB\n");
3743 dev_kfree_skb_irq(skb);
3745 hcmd = hcmd->next_all;
3747 adapter->cmdq_free.count = 0;
3748 adapter->cmdq_free.head = NULL;
3749 adapter->cmdq_free.tail = NULL;
3750 adapter->cmdq_done.count = 0;
3751 adapter->cmdq_done.head = NULL;
3752 adapter->cmdq_done.tail = NULL;
3753 adapter->cmdq_free.head = adapter->cmdq_all.head;
3754 hcmd = adapter->cmdq_all.head;
3756 adapter->cmdq_free.count++;
3757 hcmd->next = hcmd->next_all;
3758 hcmd = hcmd->next_all;
3760 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
3761 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
3762 adapter->cmdq_free.count, adapter->cmdq_all.count);
3764 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
3765 adapter->cmdq_done.lock.flags);
3766 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
3767 adapter->cmdq_free.lock.flags);
3768 DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
3771 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3773 struct slic_hostcmd *cmd;
3774 struct slic_hostcmd *prev;
3775 struct slic_hostcmd *tail;
3776 struct slic_cmdqueue *cmdq;
3782 struct slic_handle *pslic_handle;
3785 cmd = (struct slic_hostcmd *)cmdaddr;
3786 /* DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
3787 adapter->pfree_slic_handles); */
3790 phys_addr = virt_to_bus((void *)page);
3791 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
3792 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
3796 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
3797 (adapter->slic_handle_ix < 256)) {
3798 /* Allocate and initialize a SLIC_HANDLE for this command */
3799 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
3800 if (pslic_handle == NULL)
3802 ASSERT(pslic_handle ==
3803 &adapter->slic_handles[pslic_handle->token.
3805 pslic_handle->type = SLIC_HANDLE_CMD;
3806 pslic_handle->address = (void *) cmd;
3807 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
3808 pslic_handle->other_handle = NULL;
3809 pslic_handle->next = NULL;
3811 cmd->pslic_handle = pslic_handle;
3812 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
3814 cmd->paddrl = phys_addrl;
3815 cmd->paddrh = phys_addrh;
3816 cmd->next_all = prev;
3819 phys_addrl += SLIC_HOSTCMD_SIZE;
3820 cmdaddr += SLIC_HOSTCMD_SIZE;
3822 cmd = (struct slic_hostcmd *)cmdaddr;
3826 cmdq = &adapter->cmdq_all;
3827 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3828 tail->next_all = cmdq->head;
3829 ASSERT(VALID_ADDRESS(prev));
3831 cmdq = &adapter->cmdq_free;
3832 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3833 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3834 tail->next = cmdq->head;
3835 ASSERT(VALID_ADDRESS(prev));
3837 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3840 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
3842 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
3843 struct slic_hostcmd *cmd = NULL;
3846 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3850 cmdq->head = cmd->next;
3852 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3854 slic_cmdq_getdone(adapter);
3861 spin_unlock_irqrestore(&cmdq->lock.lock,
3863 pageaddr = slic_cmdqmem_addpage(adapter);
3865 slic_cmdq_addcmdpage(adapter, pageaddr);
3866 goto lock_and_retry;
3873 static void slic_cmdq_getdone(struct adapter *adapter)
3875 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
3876 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
3878 ASSERT(free_cmdq->head == NULL);
3879 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3880 ASSERT(VALID_ADDRESS(done_cmdq->head));
3882 free_cmdq->head = done_cmdq->head;
3883 free_cmdq->count = done_cmdq->count;
3884 done_cmdq->head = NULL;
3885 done_cmdq->tail = NULL;
3886 done_cmdq->count = 0;
3887 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3890 static void slic_cmdq_putdone_irq(struct adapter *adapter,
3891 struct slic_hostcmd *cmd)
3893 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
3895 spin_lock(&cmdq->lock.lock);
3897 ASSERT(VALID_ADDRESS(cmdq->head));
3898 cmd->next = cmdq->head;
3899 ASSERT(VALID_ADDRESS(cmd));
3902 if ((adapter->xmitq_full) && (cmdq->count > 10))
3903 netif_wake_queue(adapter->netdev);
3904 spin_unlock(&cmdq->lock.lock);
3907 static int slic_rcvqueue_init(struct adapter *adapter)
3910 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3912 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3913 ASSERT(adapter->state == ADAPT_DOWN);
3916 rcvq->size = SLIC_RCVQ_ENTRIES;
3919 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
3922 count += slic_rcvqueue_fill(adapter);
3925 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
3926 slic_rcvqueue_free(adapter);
3927 return STATUS_FAILURE;
3929 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
3930 return STATUS_SUCCESS;
3933 static int slic_rcvqueue_reset(struct adapter *adapter)
3935 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3937 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3938 ASSERT(adapter->state == ADAPT_DOWN);
3941 DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
3945 rcvq, rcvq->count, rcvq->head, rcvq->tail);
3947 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
3948 return STATUS_SUCCESS;
3951 static void slic_rcvqueue_free(struct adapter *adapter)
3953 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3954 struct sk_buff *skb;
3956 while (rcvq->head) {
3958 rcvq->head = rcvq->head->next;
3966 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
3968 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3969 struct sk_buff *skb;
3970 struct slic_rcvbuf *rcvbuf;
3975 rcvbuf = (struct slic_rcvbuf *)skb->head;
3978 if (rcvbuf->status & IRHDDR_SVALID) {
3979 rcvq->head = rcvq->head->next;
3986 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
3987 adapter, rcvq, rcvq->count);
3990 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
3991 count = slic_rcvqueue_fill(adapter);
4000 static int slic_rcvqueue_fill(struct adapter *adapter)
4005 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4008 while (i < SLIC_RCVQ_FILLENTRIES) {
4009 struct slic_rcvbuf *rcvbuf;
4010 struct sk_buff *skb;
4011 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4014 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4016 paddr = (void *)pci_map_single(adapter->pcidev,
4018 SLIC_RCVQ_RCVBUFSIZE,
4019 PCI_DMA_FROMDEVICE);
4020 paddrl = SLIC_GET_ADDR_LOW(paddr);
4021 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4023 skb->len = SLIC_RCVBUF_HEADSIZE;
4024 rcvbuf = (struct slic_rcvbuf *)skb->head;
4027 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4030 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4036 " paddrh[%x]\n", __func__, skb,
4037 skb->data, skb->len, paddr, paddrl,
4039 DBG_ERROR(" rcvq->head[%p]\n"
4041 " rcvq->count[%x]\n",
4042 rcvq->head, rcvq->tail, rcvq->count);
4043 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4044 goto retry_rcvqfill;
4049 ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4050 "skb[%p] GIVE TO CARD ANYWAY\n"
4054 " paddrh[%x]\n", __func__, skb,
4055 skb->data, paddr, paddrl, paddrh);
4059 slic_reg32_write(&adapter->slic_regs->slic_hbar,
4060 (u32)paddrl, DONT_FLUSH);
4062 slic_reg64_write(adapter,
4063 &adapter->slic_regs->slic_hbar64,
4065 &adapter->slic_regs->slic_addr_upper,
4066 paddrh, DONT_FLUSH);
4069 rcvq->tail->next = skb;
4077 ("%s slic_rcvqueue_fill could only get [%d] "
4079 adapter->netdev->name, i);
4086 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4088 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4092 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4094 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4096 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4097 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4101 paddrl = SLIC_GET_ADDR_LOW(paddr);
4102 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4106 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p] PROBLEM\n"
4107 " skbdata[%p]\n" " skblen[%x]\n"
4108 " paddr[%p]\n" " paddrl[%x]\n"
4109 " paddrh[%x]\n", __func__, skb, skb->data,
4110 skb->len, paddr, paddrl, paddrh);
4111 DBG_ERROR(" rcvq->head[%p]\n"
4113 " rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4117 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
4120 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
4121 paddrl, &adapter->slic_regs->slic_addr_upper,
4122 paddrh, DONT_FLUSH);
4125 rcvq->tail->next = skb;
4133 static int slic_debug_card_show(struct seq_file *seq, void *v)
4137 struct sliccard *card = seq->private;
4138 struct slic_config *config = &card->config;
4139 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4140 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4143 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
4144 seq_printf(seq, "Microcode versions: \n");
4145 seq_printf(seq, " Gigabit (gb) : %s %s\n",
4146 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4147 seq_printf(seq, " Gigabit Receiver : %s %s\n",
4148 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4149 seq_printf(seq, "Vendor : %s\n", slic_vendor);
4150 seq_printf(seq, "Product Name : %s\n", slic_product_name);
4152 seq_printf(seq, "VendorId : %4.4X\n",
4154 seq_printf(seq, "DeviceId : %4.4X\n",
4156 seq_printf(seq, "RevisionId : %2.2x\n",
4157 config->RevisionId);
4158 seq_printf(seq, "Bus # : %d\n", card->busnumber);
4159 seq_printf(seq, "Device # : %d\n", card->slotnumber);
4160 seq_printf(seq, "Interfaces : %d\n", card->card_size);
4161 seq_printf(seq, " Initialized : %d\n",
4162 card->adapters_activated);
4163 seq_printf(seq, " Allocated : %d\n",
4164 card->adapters_allocated);
4165 ASSERT(card->card_size <= SLIC_NBR_MACS);
4166 for (i = 0; i < card->card_size; i++) {
4168 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4169 i, config->macinfo[i].macaddrA[0],
4170 config->macinfo[i].macaddrA[1],
4171 config->macinfo[i].macaddrA[2],
4172 config->macinfo[i].macaddrA[3],
4173 config->macinfo[i].macaddrA[4],
4174 config->macinfo[i].macaddrA[5]);
4176 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
4177 seq_printf(seq, " -------------------------------\n");
4178 for (i = 0; i < card->adapters_allocated; i++) {
4179 struct adapter *adapter;
4181 adapter = card->adapter[i];
4184 " %d %d %s %s %s 0x%X\n",
4185 adapter->physport, adapter->state,
4186 SLIC_LINKSTATE(adapter->linkstate),
4187 SLIC_DUPLEX(adapter->linkduplex),
4188 SLIC_SPEED(adapter->linkspeed),
4189 (uint) adapter->irq);
4192 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
4193 seq_printf(seq, "RcvQ max entries : %4.4X\n",
4195 seq_printf(seq, "Ping Status : %8.8X\n",
4197 seq_printf(seq, "Minimum grant : %2.2x\n",
4199 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
4200 seq_printf(seq, "PciStatus : %4.4x\n",
4202 seq_printf(seq, "Debug Device Id : %4.4x\n",
4204 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
4206 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
4207 config->NetIntPin1);
4208 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
4209 config->NetIntPin1);
4210 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
4211 config->NetIntPin1);
4212 seq_printf(seq, "PM capabilities : %4.4X\n",
4214 seq_printf(seq, "Network Clock Controls : %4.4X\n",
4215 config->NwClkCtrls);
4217 switch (config->FruFormat) {
4218 case ATK_FRU_FORMAT:
4221 "Vendor : Alacritech, Inc.\n");
4223 "Assembly # : %c%c%c%c%c%c\n",
4224 fru[0], fru[1], fru[2], fru[3], fru[4],
4227 "Revision # : %c%c\n",
4230 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4233 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4234 fru[8], fru[9], fru[10],
4235 fru[11], fru[12], fru[13],
4236 fru[16], fru[17], fru[18],
4237 fru[19], fru[20], fru[21]);
4241 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4242 fru[8], fru[9], fru[10],
4243 fru[11], fru[12], fru[13],
4244 fru[14], fru[15], fru[16],
4245 fru[17], fru[18], fru[19],
4254 "Vendor : Alacritech, Inc.\n");
4256 "Serial # : Empty FRU\n");
4261 switch (config->OEMFruFormat) {
4262 case VENDOR1_FRU_FORMAT:
4264 seq_printf(seq, "FRU Information:\n");
4265 seq_printf(seq, " Commodity # : %c\n",
4268 " Assembly # : %c%c%c%c\n",
4269 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4271 " Revision # : %c%c\n",
4272 oemfru[5], oemfru[6]);
4274 " Supplier # : %c%c\n",
4275 oemfru[7], oemfru[8]);
4278 oemfru[9], oemfru[10]);
4280 " Sequence # : %c%c%c\n",
4281 oemfru[11], oemfru[12], oemfru[13]);
4285 case VENDOR2_FRU_FORMAT:
4287 seq_printf(seq, "FRU Information:\n");
4290 "%c%c%c%c%c%c%c%c\n",
4291 oemfru[0], oemfru[1], oemfru[2],
4292 oemfru[3], oemfru[4], oemfru[5],
4293 oemfru[6], oemfru[7]);
4295 " Supplier # : %c%c%c%c%c\n",
4296 oemfru[8], oemfru[9], oemfru[10],
4297 oemfru[11], oemfru[12]);
4300 oemfru[13], oemfru[14], oemfru[15]);
4302 " Sequence # : %c%c%c%c\n",
4303 oemfru[16], oemfru[17], oemfru[18],
4308 case VENDOR3_FRU_FORMAT:
4310 seq_printf(seq, "FRU Information:\n");
4313 case VENDOR4_FRU_FORMAT:
4315 seq_printf(seq, "FRU Information:\n");
4318 "%c%c%c%c%c%c%c%c\n",
4319 oemfru[0], oemfru[1], oemfru[2],
4320 oemfru[3], oemfru[4], oemfru[5],
4321 oemfru[6], oemfru[7]);
4324 "%c%c%c%c%c%c%c%c\n",
4325 oemfru[8], oemfru[9], oemfru[10],
4326 oemfru[11], oemfru[12], oemfru[13],
4327 oemfru[14], oemfru[15]);
4330 "%c%c%c%c%c%c%c%c\n",
4331 oemfru[16], oemfru[17], oemfru[18],
4332 oemfru[19], oemfru[20], oemfru[21],
4333 oemfru[22], oemfru[23]);
4345 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4347 struct adapter *adapter = seq->private;
4349 if ((adapter->netdev) && (adapter->netdev->name)) {
4350 seq_printf(seq, "info: interface : %s\n",
4351 adapter->netdev->name);
4353 seq_printf(seq, "info: status : %s\n",
4354 SLIC_LINKSTATE(adapter->linkstate));
4355 seq_printf(seq, "info: port : %d\n",
4357 seq_printf(seq, "info: speed : %s\n",
4358 SLIC_SPEED(adapter->linkspeed));
4359 seq_printf(seq, "info: duplex : %s\n",
4360 SLIC_DUPLEX(adapter->linkduplex));
4361 seq_printf(seq, "info: irq : 0x%X\n",
4362 (uint) adapter->irq);
4363 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4364 adapter->card->loadlevel_current);
4365 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
4367 seq_printf(seq, "info: RcvQ current : %4.4X\n",
4368 adapter->rcvqueue.count);
4369 seq_printf(seq, "rx stats: packets : %8.8lX\n",
4370 adapter->stats.rx_packets);
4371 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
4372 adapter->stats.rx_bytes);
4373 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
4374 adapter->rcv_broadcasts);
4375 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
4376 adapter->rcv_multicasts);
4377 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
4378 adapter->rcv_unicasts);
4379 seq_printf(seq, "rx stats: errors : %8.8X\n",
4380 (u32) adapter->slic_stats.iface.rcv_errors);
4381 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
4382 (u32) adapter->slic_stats.iface.rcv_discards);
4383 seq_printf(seq, "rx stats: drops : %8.8X\n",
4384 (u32) adapter->rcv_drops);
4385 seq_printf(seq, "tx stats: packets : %8.8lX\n",
4386 adapter->stats.tx_packets);
4387 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
4388 adapter->stats.tx_bytes);
4389 seq_printf(seq, "tx stats: errors : %8.8X\n",
4390 (u32) adapter->slic_stats.iface.xmt_errors);
4391 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
4392 adapter->stats.multicast);
4393 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
4394 (u32) adapter->slic_stats.iface.xmit_collisions);
4395 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
4396 adapter->max_isr_rcvs);
4397 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
4398 adapter->rcv_interrupt_yields);
4399 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
4400 adapter->max_isr_xmits);
4401 seq_printf(seq, "perf: error interrupts : %8.8X\n",
4402 adapter->error_interrupts);
4403 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
4404 adapter->error_rmiss_interrupts);
4405 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
4406 adapter->rcv_interrupts);
4407 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
4408 adapter->xmit_interrupts);
4409 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
4410 adapter->linkevent_interrupts);
4411 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
4412 adapter->upr_interrupts);
4413 seq_printf(seq, "perf: interrupt count : %8.8X\n",
4415 seq_printf(seq, "perf: false interrupts : %8.8X\n",
4416 adapter->false_interrupts);
4417 seq_printf(seq, "perf: All register writes : %8.8X\n",
4418 adapter->all_reg_writes);
4419 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
4420 adapter->icr_reg_writes);
4421 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
4422 adapter->isr_reg_writes);
4423 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
4424 adapter->if_events.oflow802);
4425 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4426 adapter->if_events.Tprtoflow);
4427 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
4428 adapter->if_events.uflow802);
4429 seq_printf(seq, "ifevents: receive early : %8.8X\n",
4430 adapter->if_events.rcvearly);
4431 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
4432 adapter->if_events.Bufov);
4433 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
4434 adapter->if_events.Carre);
4435 seq_printf(seq, "ifevents: Long : %8.8X\n",
4436 adapter->if_events.Longe);
4437 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
4438 adapter->if_events.Invp);
4439 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
4440 adapter->if_events.Crc);
4441 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
4442 adapter->if_events.Drbl);
4443 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
4444 adapter->if_events.Code);
4445 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
4446 adapter->if_events.TpCsum);
4447 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
4448 adapter->if_events.TpHlen);
4449 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
4450 adapter->if_events.IpCsum);
4451 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
4452 adapter->if_events.IpLen);
4453 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
4454 adapter->if_events.IpHlen);
4458 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4460 return single_open(file, slic_debug_adapter_show, inode->i_private);
4463 static int slic_debug_card_open(struct inode *inode, struct file *file)
4465 return single_open(file, slic_debug_card_show, inode->i_private);
4468 static const struct file_operations slic_debug_adapter_fops = {
4469 .owner = THIS_MODULE,
4470 .open = slic_debug_adapter_open,
4472 .llseek = seq_lseek,
4473 .release = single_release,
4476 static const struct file_operations slic_debug_card_fops = {
4477 .owner = THIS_MODULE,
4478 .open = slic_debug_card_open,
4480 .llseek = seq_lseek,
4481 .release = single_release,
4484 static void slic_debug_adapter_create(struct adapter *adapter)
4488 struct sliccard *card = adapter->card;
4490 if (!card->debugfs_dir)
4493 sprintf(name, "port%d", adapter->port);
4494 d = debugfs_create_file(name, S_IRUGO,
4495 card->debugfs_dir, adapter,
4496 &slic_debug_adapter_fops);
4497 if (!d || IS_ERR(d))
4498 pr_info(PFX "%s: debugfs create failed\n", name);
4500 adapter->debugfs_entry = d;
4503 static void slic_debug_adapter_destroy(struct adapter *adapter)
4505 if (adapter->debugfs_entry) {
4506 debugfs_remove(adapter->debugfs_entry);
4507 adapter->debugfs_entry = NULL;
4511 static void slic_debug_card_create(struct sliccard *card)
4514 char name[IFNAMSIZ];
4516 snprintf(name, sizeof(name), "slic%d", card->cardnum);
4517 d = debugfs_create_dir(name, slic_debugfs);
4518 if (!d || IS_ERR(d))
4519 pr_info(PFX "%s: debugfs create dir failed\n",
4522 card->debugfs_dir = d;
4523 d = debugfs_create_file("cardinfo", S_IRUGO,
4525 &slic_debug_card_fops);
4526 if (!d || IS_ERR(d))
4527 pr_info(PFX "%s: debugfs create failed\n",
4530 card->debugfs_cardinfo = d;
4534 static void slic_debug_card_destroy(struct sliccard *card)
4538 for (i = 0; i < card->card_size; i++) {
4539 struct adapter *adapter;
4541 adapter = card->adapter[i];
4543 slic_debug_adapter_destroy(adapter);
4545 if (card->debugfs_cardinfo) {
4546 debugfs_remove(card->debugfs_cardinfo);
4547 card->debugfs_cardinfo = NULL;
4549 if (card->debugfs_dir) {
4550 debugfs_remove(card->debugfs_dir);
4551 card->debugfs_dir = NULL;
4555 static void slic_debug_init(void)
4559 ent = debugfs_create_dir("slic", NULL);
4560 if (!ent || IS_ERR(ent)) {
4561 pr_info(PFX "debugfs create directory failed\n");
4568 static void slic_debug_cleanup(void)
4571 debugfs_remove(slic_debugfs);
4572 slic_debugfs = NULL;
4576 /******************************************************************************/
4577 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
4578 /******************************************************************************/
4580 static struct pci_driver slic_driver = {
4582 .id_table = slic_pci_tbl,
4583 .probe = slic_entry_probe,
4584 .remove = slic_entry_remove,
4585 #if SLIC_POWER_MANAGEMENT_ENABLED
4586 .suspend = slicpm_suspend,
4587 .resume = slicpm_resume,
4589 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
4592 static int __init slic_module_init(void)
4594 struct pci_device_id *pcidev;
4597 /* DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
4601 if (debug >= 0 && slic_debug != debug)
4602 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
4606 pcidev = (struct pci_device_id *)slic_driver.id_table;
4607 /* DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
4608 __func__, jiffies, smp_processor_id()); */
4610 ret = pci_register_driver(&slic_driver);
4612 /* DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
4613 "cpu #%d status[%x]\n",__func__, jiffies,
4614 smp_processor_id(), ret); */
4619 static void __exit slic_module_cleanup(void)
4621 /* DBG_MSG("slicoss: %s ENTER\n", __func__); */
4622 pci_unregister_driver(&slic_driver);
4623 slic_debug_cleanup();
4624 /* DBG_MSG("slicoss: %s EXIT\n", __func__); */
4627 module_init(slic_module_init);
4628 module_exit(slic_module_cleanup);