Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * rrunner.c: Linux driver for the Essential RoadRunner HIPPI board.
4 *
5 * Copyright (C) 1998-2002 by Jes Sorensen, <jes@wildopensource.com>.
6 *
7 * Thanks to Essential Communication for providing us with hardware
8 * and very comprehensive documentation without which I would not have
9 * been able to write this driver. A special thank you to John Gibbon
10 * for sorting out the legal issues, with the NDA, allowing the code to
11 * be released under the GPL.
12 *
13 * Thanks to Jayaram Bhat from ODS/Essential for fixing some of the
14 * stupid bugs in my code.
15 *
16 * Softnet support and various other patches from Val Henson of
17 * ODS/Essential.
18 *
19 * PCI DMA mapping code partly based on work by Francois Romieu.
20 */
21
22
23#define DEBUG 1
24#define RX_DMA_SKBUFF 1
25#define PKT_COPY_THRESHOLD 512
26
27#include <linux/module.h>
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/ioport.h>
31#include <linux/pci.h>
32#include <linux/kernel.h>
33#include <linux/netdevice.h>
34#include <linux/hippidevice.h>
35#include <linux/skbuff.h>
36#include <linux/delay.h>
37#include <linux/mm.h>
38#include <linux/slab.h>
39#include <net/sock.h>
40
41#include <asm/cache.h>
42#include <asm/byteorder.h>
43#include <asm/io.h>
44#include <asm/irq.h>
45#include <linux/uaccess.h>
46
47#define rr_if_busy(dev) netif_queue_stopped(dev)
48#define rr_if_running(dev) netif_running(dev)
49
50#include "rrunner.h"
51
52#define RUN_AT(x) (jiffies + (x))
53
54
55MODULE_AUTHOR("Jes Sorensen <jes@wildopensource.com>");
56MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
57MODULE_LICENSE("GPL");
58
59static const char version[] =
60"rrunner.c: v0.50 11/11/2002 Jes Sorensen (jes@wildopensource.com)\n";
61
62
63static const struct net_device_ops rr_netdev_ops = {
64 .ndo_open = rr_open,
65 .ndo_stop = rr_close,
66 .ndo_do_ioctl = rr_ioctl,
67 .ndo_start_xmit = rr_start_xmit,
68 .ndo_set_mac_address = hippi_mac_addr,
69};
70
71/*
72 * Implementation notes:
73 *
74 * The DMA engine only allows for DMA within physical 64KB chunks of
75 * memory. The current approach of the driver (and stack) is to use
76 * linear blocks of memory for the skbuffs. However, as the data block
77 * is always the first part of the skb and skbs are 2^n aligned so we
78 * are guarantted to get the whole block within one 64KB align 64KB
79 * chunk.
80 *
81 * On the long term, relying on being able to allocate 64KB linear
82 * chunks of memory is not feasible and the skb handling code and the
83 * stack will need to know about I/O vectors or something similar.
84 */
85
86static int rr_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
87{
88 struct net_device *dev;
89 static int version_disp;
90 u8 pci_latency;
91 struct rr_private *rrpriv;
92 void *tmpptr;
93 dma_addr_t ring_dma;
94 int ret = -ENOMEM;
95
96 dev = alloc_hippi_dev(sizeof(struct rr_private));
97 if (!dev)
98 goto out3;
99
100 ret = pci_enable_device(pdev);
101 if (ret) {
102 ret = -ENODEV;
103 goto out2;
104 }
105
106 rrpriv = netdev_priv(dev);
107
108 SET_NETDEV_DEV(dev, &pdev->dev);
109
110 ret = pci_request_regions(pdev, "rrunner");
111 if (ret < 0)
112 goto out;
113
114 pci_set_drvdata(pdev, dev);
115
116 rrpriv->pci_dev = pdev;
117
118 spin_lock_init(&rrpriv->lock);
119
120 dev->netdev_ops = &rr_netdev_ops;
121
122 /* display version info if adapter is found */
123 if (!version_disp) {
124 /* set display flag to TRUE so that */
125 /* we only display this string ONCE */
126 version_disp = 1;
127 printk(version);
128 }
129
130 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
131 if (pci_latency <= 0x58){
132 pci_latency = 0x58;
133 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, pci_latency);
134 }
135
136 pci_set_master(pdev);
137
138 printk(KERN_INFO "%s: Essential RoadRunner serial HIPPI "
139 "at 0x%llx, irq %i, PCI latency %i\n", dev->name,
140 (unsigned long long)pci_resource_start(pdev, 0),
141 pdev->irq, pci_latency);
142
143 /*
144 * Remap the MMIO regs into kernel space.
145 */
146 rrpriv->regs = pci_iomap(pdev, 0, 0x1000);
147 if (!rrpriv->regs) {
148 printk(KERN_ERR "%s: Unable to map I/O register, "
149 "RoadRunner will be disabled.\n", dev->name);
150 ret = -EIO;
151 goto out;
152 }
153
154 tmpptr = pci_alloc_consistent(pdev, TX_TOTAL_SIZE, &ring_dma);
155 rrpriv->tx_ring = tmpptr;
156 rrpriv->tx_ring_dma = ring_dma;
157
158 if (!tmpptr) {
159 ret = -ENOMEM;
160 goto out;
161 }
162
163 tmpptr = pci_alloc_consistent(pdev, RX_TOTAL_SIZE, &ring_dma);
164 rrpriv->rx_ring = tmpptr;
165 rrpriv->rx_ring_dma = ring_dma;
166
167 if (!tmpptr) {
168 ret = -ENOMEM;
169 goto out;
170 }
171
172 tmpptr = pci_alloc_consistent(pdev, EVT_RING_SIZE, &ring_dma);
173 rrpriv->evt_ring = tmpptr;
174 rrpriv->evt_ring_dma = ring_dma;
175
176 if (!tmpptr) {
177 ret = -ENOMEM;
178 goto out;
179 }
180
181 /*
182 * Don't access any register before this point!
183 */
184#ifdef __BIG_ENDIAN
185 writel(readl(&rrpriv->regs->HostCtrl) | NO_SWAP,
186 &rrpriv->regs->HostCtrl);
187#endif
188 /*
189 * Need to add a case for little-endian 64-bit hosts here.
190 */
191
192 rr_init(dev);
193
194 ret = register_netdev(dev);
195 if (ret)
196 goto out;
197 return 0;
198
199 out:
200 if (rrpriv->evt_ring)
201 pci_free_consistent(pdev, EVT_RING_SIZE, rrpriv->evt_ring,
202 rrpriv->evt_ring_dma);
203 if (rrpriv->rx_ring)
204 pci_free_consistent(pdev, RX_TOTAL_SIZE, rrpriv->rx_ring,
205 rrpriv->rx_ring_dma);
206 if (rrpriv->tx_ring)
207 pci_free_consistent(pdev, TX_TOTAL_SIZE, rrpriv->tx_ring,
208 rrpriv->tx_ring_dma);
209 if (rrpriv->regs)
210 pci_iounmap(pdev, rrpriv->regs);
211 if (pdev)
212 pci_release_regions(pdev);
213 out2:
214 free_netdev(dev);
215 out3:
216 return ret;
217}
218
219static void rr_remove_one(struct pci_dev *pdev)
220{
221 struct net_device *dev = pci_get_drvdata(pdev);
222 struct rr_private *rr = netdev_priv(dev);
223
224 if (!(readl(&rr->regs->HostCtrl) & NIC_HALTED)) {
225 printk(KERN_ERR "%s: trying to unload running NIC\n",
226 dev->name);
227 writel(HALT_NIC, &rr->regs->HostCtrl);
228 }
229
230 unregister_netdev(dev);
231 pci_free_consistent(pdev, EVT_RING_SIZE, rr->evt_ring,
232 rr->evt_ring_dma);
233 pci_free_consistent(pdev, RX_TOTAL_SIZE, rr->rx_ring,
234 rr->rx_ring_dma);
235 pci_free_consistent(pdev, TX_TOTAL_SIZE, rr->tx_ring,
236 rr->tx_ring_dma);
237 pci_iounmap(pdev, rr->regs);
238 pci_release_regions(pdev);
239 pci_disable_device(pdev);
240 free_netdev(dev);
241}
242
243
244/*
245 * Commands are considered to be slow, thus there is no reason to
246 * inline this.
247 */
248static void rr_issue_cmd(struct rr_private *rrpriv, struct cmd *cmd)
249{
250 struct rr_regs __iomem *regs;
251 u32 idx;
252
253 regs = rrpriv->regs;
254 /*
255 * This is temporary - it will go away in the final version.
256 * We probably also want to make this function inline.
257 */
258 if (readl(®s->HostCtrl) & NIC_HALTED){
259 printk("issuing command for halted NIC, code 0x%x, "
260 "HostCtrl %08x\n", cmd->code, readl(®s->HostCtrl));
261 if (readl(®s->Mode) & FATAL_ERR)
262 printk("error codes Fail1 %02x, Fail2 %02x\n",
263 readl(®s->Fail1), readl(®s->Fail2));
264 }
265
266 idx = rrpriv->info->cmd_ctrl.pi;
267
268 writel(*(u32*)(cmd), ®s->CmdRing[idx]);
269 wmb();
270
271 idx = (idx - 1) % CMD_RING_ENTRIES;
272 rrpriv->info->cmd_ctrl.pi = idx;
273 wmb();
274
275 if (readl(®s->Mode) & FATAL_ERR)
276 printk("error code %02x\n", readl(®s->Fail1));
277}
278
279
280/*
281 * Reset the board in a sensible manner. The NIC is already halted
282 * when we get here and a spin-lock is held.
283 */
284static int rr_reset(struct net_device *dev)
285{
286 struct rr_private *rrpriv;
287 struct rr_regs __iomem *regs;
288 u32 start_pc;
289 int i;
290
291 rrpriv = netdev_priv(dev);
292 regs = rrpriv->regs;
293
294 rr_load_firmware(dev);
295
296 writel(0x01000000, ®s->TX_state);
297 writel(0xff800000, ®s->RX_state);
298 writel(0, ®s->AssistState);
299 writel(CLEAR_INTA, ®s->LocalCtrl);
300 writel(0x01, ®s->BrkPt);
301 writel(0, ®s->Timer);
302 writel(0, ®s->TimerRef);
303 writel(RESET_DMA, ®s->DmaReadState);
304 writel(RESET_DMA, ®s->DmaWriteState);
305 writel(0, ®s->DmaWriteHostHi);
306 writel(0, ®s->DmaWriteHostLo);
307 writel(0, ®s->DmaReadHostHi);
308 writel(0, ®s->DmaReadHostLo);
309 writel(0, ®s->DmaReadLen);
310 writel(0, ®s->DmaWriteLen);
311 writel(0, ®s->DmaWriteLcl);
312 writel(0, ®s->DmaWriteIPchecksum);
313 writel(0, ®s->DmaReadLcl);
314 writel(0, ®s->DmaReadIPchecksum);
315 writel(0, ®s->PciState);
316#if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
317 writel(SWAP_DATA | PTR64BIT | PTR_WD_SWAP, ®s->Mode);
318#elif (BITS_PER_LONG == 64)
319 writel(SWAP_DATA | PTR64BIT | PTR_WD_NOSWAP, ®s->Mode);
320#else
321 writel(SWAP_DATA | PTR32BIT | PTR_WD_NOSWAP, ®s->Mode);
322#endif
323
324#if 0
325 /*
326 * Don't worry, this is just black magic.
327 */
328 writel(0xdf000, ®s->RxBase);
329 writel(0xdf000, ®s->RxPrd);
330 writel(0xdf000, ®s->RxCon);
331 writel(0xce000, ®s->TxBase);
332 writel(0xce000, ®s->TxPrd);
333 writel(0xce000, ®s->TxCon);
334 writel(0, ®s->RxIndPro);
335 writel(0, ®s->RxIndCon);
336 writel(0, ®s->RxIndRef);
337 writel(0, ®s->TxIndPro);
338 writel(0, ®s->TxIndCon);
339 writel(0, ®s->TxIndRef);
340 writel(0xcc000, ®s->pad10[0]);
341 writel(0, ®s->DrCmndPro);
342 writel(0, ®s->DrCmndCon);
343 writel(0, ®s->DwCmndPro);
344 writel(0, ®s->DwCmndCon);
345 writel(0, ®s->DwCmndRef);
346 writel(0, ®s->DrDataPro);
347 writel(0, ®s->DrDataCon);
348 writel(0, ®s->DrDataRef);
349 writel(0, ®s->DwDataPro);
350 writel(0, ®s->DwDataCon);
351 writel(0, ®s->DwDataRef);
352#endif
353
354 writel(0xffffffff, ®s->MbEvent);
355 writel(0, ®s->Event);
356
357 writel(0, ®s->TxPi);
358 writel(0, ®s->IpRxPi);
359
360 writel(0, ®s->EvtCon);
361 writel(0, ®s->EvtPrd);
362
363 rrpriv->info->evt_ctrl.pi = 0;
364
365 for (i = 0; i < CMD_RING_ENTRIES; i++)
366 writel(0, ®s->CmdRing[i]);
367
368/*
369 * Why 32 ? is this not cache line size dependent?
370 */
371 writel(RBURST_64|WBURST_64, ®s->PciState);
372 wmb();
373
374 start_pc = rr_read_eeprom_word(rrpriv,
375 offsetof(struct eeprom, rncd_info.FwStart));
376
377#if (DEBUG > 1)
378 printk("%s: Executing firmware at address 0x%06x\n",
379 dev->name, start_pc);
380#endif
381
382 writel(start_pc + 0x800, ®s->Pc);
383 wmb();
384 udelay(5);
385
386 writel(start_pc, ®s->Pc);
387 wmb();
388
389 return 0;
390}
391
392
393/*
394 * Read a string from the EEPROM.
395 */
396static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
397 unsigned long offset,
398 unsigned char *buf,
399 unsigned long length)
400{
401 struct rr_regs __iomem *regs = rrpriv->regs;
402 u32 misc, io, host, i;
403
404 io = readl(®s->ExtIo);
405 writel(0, ®s->ExtIo);
406 misc = readl(®s->LocalCtrl);
407 writel(0, ®s->LocalCtrl);
408 host = readl(®s->HostCtrl);
409 writel(host | HALT_NIC, ®s->HostCtrl);
410 mb();
411
412 for (i = 0; i < length; i++){
413 writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
414 mb();
415 buf[i] = (readl(®s->WinData) >> 24) & 0xff;
416 mb();
417 }
418
419 writel(host, ®s->HostCtrl);
420 writel(misc, ®s->LocalCtrl);
421 writel(io, ®s->ExtIo);
422 mb();
423 return i;
424}
425
426
427/*
428 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
429 * it to our CPU byte-order.
430 */
431static u32 rr_read_eeprom_word(struct rr_private *rrpriv,
432 size_t offset)
433{
434 __be32 word;
435
436 if ((rr_read_eeprom(rrpriv, offset,
437 (unsigned char *)&word, 4) == 4))
438 return be32_to_cpu(word);
439 return 0;
440}
441
442
443/*
444 * Write a string to the EEPROM.
445 *
446 * This is only called when the firmware is not running.
447 */
448static unsigned int write_eeprom(struct rr_private *rrpriv,
449 unsigned long offset,
450 unsigned char *buf,
451 unsigned long length)
452{
453 struct rr_regs __iomem *regs = rrpriv->regs;
454 u32 misc, io, data, i, j, ready, error = 0;
455
456 io = readl(®s->ExtIo);
457 writel(0, ®s->ExtIo);
458 misc = readl(®s->LocalCtrl);
459 writel(ENABLE_EEPROM_WRITE, ®s->LocalCtrl);
460 mb();
461
462 for (i = 0; i < length; i++){
463 writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
464 mb();
465 data = buf[i] << 24;
466 /*
467 * Only try to write the data if it is not the same
468 * value already.
469 */
470 if ((readl(®s->WinData) & 0xff000000) != data){
471 writel(data, ®s->WinData);
472 ready = 0;
473 j = 0;
474 mb();
475 while(!ready){
476 udelay(20);
477 if ((readl(®s->WinData) & 0xff000000) ==
478 data)
479 ready = 1;
480 mb();
481 if (j++ > 5000){
482 printk("data mismatch: %08x, "
483 "WinData %08x\n", data,
484 readl(®s->WinData));
485 ready = 1;
486 error = 1;
487 }
488 }
489 }
490 }
491
492 writel(misc, ®s->LocalCtrl);
493 writel(io, ®s->ExtIo);
494 mb();
495
496 return error;
497}
498
499
500static int rr_init(struct net_device *dev)
501{
502 struct rr_private *rrpriv;
503 struct rr_regs __iomem *regs;
504 u32 sram_size, rev;
505
506 rrpriv = netdev_priv(dev);
507 regs = rrpriv->regs;
508
509 rev = readl(®s->FwRev);
510 rrpriv->fw_rev = rev;
511 if (rev > 0x00020024)
512 printk(" Firmware revision: %i.%i.%i\n", (rev >> 16),
513 ((rev >> 8) & 0xff), (rev & 0xff));
514 else if (rev >= 0x00020000) {
515 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
516 "later is recommended)\n", (rev >> 16),
517 ((rev >> 8) & 0xff), (rev & 0xff));
518 }else{
519 printk(" Firmware revision too old: %i.%i.%i, please "
520 "upgrade to 2.0.37 or later.\n",
521 (rev >> 16), ((rev >> 8) & 0xff), (rev & 0xff));
522 }
523
524#if (DEBUG > 2)
525 printk(" Maximum receive rings %i\n", readl(®s->MaxRxRng));
526#endif
527
528 /*
529 * Read the hardware address from the eeprom. The HW address
530 * is not really necessary for HIPPI but awfully convenient.
531 * The pointer arithmetic to put it in dev_addr is ugly, but
532 * Donald Becker does it this way for the GigE version of this
533 * card and it's shorter and more portable than any
534 * other method I've seen. -VAL
535 */
536
537 *(__be16 *)(dev->dev_addr) =
538 htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
539 *(__be32 *)(dev->dev_addr+2) =
540 htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
541
542 printk(" MAC: %pM\n", dev->dev_addr);
543
544 sram_size = rr_read_eeprom_word(rrpriv, 8);
545 printk(" SRAM size 0x%06x\n", sram_size);
546
547 return 0;
548}
549
550
551static int rr_init1(struct net_device *dev)
552{
553 struct rr_private *rrpriv;
554 struct rr_regs __iomem *regs;
555 unsigned long myjif, flags;
556 struct cmd cmd;
557 u32 hostctrl;
558 int ecode = 0;
559 short i;
560
561 rrpriv = netdev_priv(dev);
562 regs = rrpriv->regs;
563
564 spin_lock_irqsave(&rrpriv->lock, flags);
565
566 hostctrl = readl(®s->HostCtrl);
567 writel(hostctrl | HALT_NIC | RR_CLEAR_INT, ®s->HostCtrl);
568 wmb();
569
570 if (hostctrl & PARITY_ERR){
571 printk("%s: Parity error halting NIC - this is serious!\n",
572 dev->name);
573 spin_unlock_irqrestore(&rrpriv->lock, flags);
574 ecode = -EFAULT;
575 goto error;
576 }
577
578 set_rxaddr(regs, rrpriv->rx_ctrl_dma);
579 set_infoaddr(regs, rrpriv->info_dma);
580
581 rrpriv->info->evt_ctrl.entry_size = sizeof(struct event);
582 rrpriv->info->evt_ctrl.entries = EVT_RING_ENTRIES;
583 rrpriv->info->evt_ctrl.mode = 0;
584 rrpriv->info->evt_ctrl.pi = 0;
585 set_rraddr(&rrpriv->info->evt_ctrl.rngptr, rrpriv->evt_ring_dma);
586
587 rrpriv->info->cmd_ctrl.entry_size = sizeof(struct cmd);
588 rrpriv->info->cmd_ctrl.entries = CMD_RING_ENTRIES;
589 rrpriv->info->cmd_ctrl.mode = 0;
590 rrpriv->info->cmd_ctrl.pi = 15;
591
592 for (i = 0; i < CMD_RING_ENTRIES; i++) {
593 writel(0, ®s->CmdRing[i]);
594 }
595
596 for (i = 0; i < TX_RING_ENTRIES; i++) {
597 rrpriv->tx_ring[i].size = 0;
598 set_rraddr(&rrpriv->tx_ring[i].addr, 0);
599 rrpriv->tx_skbuff[i] = NULL;
600 }
601 rrpriv->info->tx_ctrl.entry_size = sizeof(struct tx_desc);
602 rrpriv->info->tx_ctrl.entries = TX_RING_ENTRIES;
603 rrpriv->info->tx_ctrl.mode = 0;
604 rrpriv->info->tx_ctrl.pi = 0;
605 set_rraddr(&rrpriv->info->tx_ctrl.rngptr, rrpriv->tx_ring_dma);
606
607 /*
608 * Set dirty_tx before we start receiving interrupts, otherwise
609 * the interrupt handler might think it is supposed to process
610 * tx ints before we are up and running, which may cause a null
611 * pointer access in the int handler.
612 */
613 rrpriv->tx_full = 0;
614 rrpriv->cur_rx = 0;
615 rrpriv->dirty_rx = rrpriv->dirty_tx = 0;
616
617 rr_reset(dev);
618
619 /* Tuning values */
620 writel(0x5000, ®s->ConRetry);
621 writel(0x100, ®s->ConRetryTmr);
622 writel(0x500000, ®s->ConTmout);
623 writel(0x60, ®s->IntrTmr);
624 writel(0x500000, ®s->TxDataMvTimeout);
625 writel(0x200000, ®s->RxDataMvTimeout);
626 writel(0x80, ®s->WriteDmaThresh);
627 writel(0x80, ®s->ReadDmaThresh);
628
629 rrpriv->fw_running = 0;
630 wmb();
631
632 hostctrl &= ~(HALT_NIC | INVALID_INST_B | PARITY_ERR);
633 writel(hostctrl, ®s->HostCtrl);
634 wmb();
635
636 spin_unlock_irqrestore(&rrpriv->lock, flags);
637
638 for (i = 0; i < RX_RING_ENTRIES; i++) {
639 struct sk_buff *skb;
640 dma_addr_t addr;
641
642 rrpriv->rx_ring[i].mode = 0;
643 skb = alloc_skb(dev->mtu + HIPPI_HLEN, GFP_ATOMIC);
644 if (!skb) {
645 printk(KERN_WARNING "%s: Unable to allocate memory "
646 "for receive ring - halting NIC\n", dev->name);
647 ecode = -ENOMEM;
648 goto error;
649 }
650 rrpriv->rx_skbuff[i] = skb;
651 addr = pci_map_single(rrpriv->pci_dev, skb->data,
652 dev->mtu + HIPPI_HLEN, PCI_DMA_FROMDEVICE);
653 /*
654 * Sanity test to see if we conflict with the DMA
655 * limitations of the Roadrunner.
656 */
657 if ((((unsigned long)skb->data) & 0xfff) > ~65320)
658 printk("skb alloc error\n");
659
660 set_rraddr(&rrpriv->rx_ring[i].addr, addr);
661 rrpriv->rx_ring[i].size = dev->mtu + HIPPI_HLEN;
662 }
663
664 rrpriv->rx_ctrl[4].entry_size = sizeof(struct rx_desc);
665 rrpriv->rx_ctrl[4].entries = RX_RING_ENTRIES;
666 rrpriv->rx_ctrl[4].mode = 8;
667 rrpriv->rx_ctrl[4].pi = 0;
668 wmb();
669 set_rraddr(&rrpriv->rx_ctrl[4].rngptr, rrpriv->rx_ring_dma);
670
671 udelay(1000);
672
673 /*
674 * Now start the FirmWare.
675 */
676 cmd.code = C_START_FW;
677 cmd.ring = 0;
678 cmd.index = 0;
679
680 rr_issue_cmd(rrpriv, &cmd);
681
682 /*
683 * Give the FirmWare time to chew on the `get running' command.
684 */
685 myjif = jiffies + 5 * HZ;
686 while (time_before(jiffies, myjif) && !rrpriv->fw_running)
687 cpu_relax();
688
689 netif_start_queue(dev);
690
691 return ecode;
692
693 error:
694 /*
695 * We might have gotten here because we are out of memory,
696 * make sure we release everything we allocated before failing
697 */
698 for (i = 0; i < RX_RING_ENTRIES; i++) {
699 struct sk_buff *skb = rrpriv->rx_skbuff[i];
700
701 if (skb) {
702 pci_unmap_single(rrpriv->pci_dev,
703 rrpriv->rx_ring[i].addr.addrlo,
704 dev->mtu + HIPPI_HLEN,
705 PCI_DMA_FROMDEVICE);
706 rrpriv->rx_ring[i].size = 0;
707 set_rraddr(&rrpriv->rx_ring[i].addr, 0);
708 dev_kfree_skb(skb);
709 rrpriv->rx_skbuff[i] = NULL;
710 }
711 }
712 return ecode;
713}
714
715
716/*
717 * All events are considered to be slow (RX/TX ints do not generate
718 * events) and are handled here, outside the main interrupt handler,
719 * to reduce the size of the handler.
720 */
721static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
722{
723 struct rr_private *rrpriv;
724 struct rr_regs __iomem *regs;
725 u32 tmp;
726
727 rrpriv = netdev_priv(dev);
728 regs = rrpriv->regs;
729
730 while (prodidx != eidx){
731 switch (rrpriv->evt_ring[eidx].code){
732 case E_NIC_UP:
733 tmp = readl(®s->FwRev);
734 printk(KERN_INFO "%s: Firmware revision %i.%i.%i "
735 "up and running\n", dev->name,
736 (tmp >> 16), ((tmp >> 8) & 0xff), (tmp & 0xff));
737 rrpriv->fw_running = 1;
738 writel(RX_RING_ENTRIES - 1, ®s->IpRxPi);
739 wmb();
740 break;
741 case E_LINK_ON:
742 printk(KERN_INFO "%s: Optical link ON\n", dev->name);
743 break;
744 case E_LINK_OFF:
745 printk(KERN_INFO "%s: Optical link OFF\n", dev->name);
746 break;
747 case E_RX_IDLE:
748 printk(KERN_WARNING "%s: RX data not moving\n",
749 dev->name);
750 goto drop;
751 case E_WATCHDOG:
752 printk(KERN_INFO "%s: The watchdog is here to see "
753 "us\n", dev->name);
754 break;
755 case E_INTERN_ERR:
756 printk(KERN_ERR "%s: HIPPI Internal NIC error\n",
757 dev->name);
758 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
759 ®s->HostCtrl);
760 wmb();
761 break;
762 case E_HOST_ERR:
763 printk(KERN_ERR "%s: Host software error\n",
764 dev->name);
765 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
766 ®s->HostCtrl);
767 wmb();
768 break;
769 /*
770 * TX events.
771 */
772 case E_CON_REJ:
773 printk(KERN_WARNING "%s: Connection rejected\n",
774 dev->name);
775 dev->stats.tx_aborted_errors++;
776 break;
777 case E_CON_TMOUT:
778 printk(KERN_WARNING "%s: Connection timeout\n",
779 dev->name);
780 break;
781 case E_DISC_ERR:
782 printk(KERN_WARNING "%s: HIPPI disconnect error\n",
783 dev->name);
784 dev->stats.tx_aborted_errors++;
785 break;
786 case E_INT_PRTY:
787 printk(KERN_ERR "%s: HIPPI Internal Parity error\n",
788 dev->name);
789 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
790 ®s->HostCtrl);
791 wmb();
792 break;
793 case E_TX_IDLE:
794 printk(KERN_WARNING "%s: Transmitter idle\n",
795 dev->name);
796 break;
797 case E_TX_LINK_DROP:
798 printk(KERN_WARNING "%s: Link lost during transmit\n",
799 dev->name);
800 dev->stats.tx_aborted_errors++;
801 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
802 ®s->HostCtrl);
803 wmb();
804 break;
805 case E_TX_INV_RNG:
806 printk(KERN_ERR "%s: Invalid send ring block\n",
807 dev->name);
808 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
809 ®s->HostCtrl);
810 wmb();
811 break;
812 case E_TX_INV_BUF:
813 printk(KERN_ERR "%s: Invalid send buffer address\n",
814 dev->name);
815 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
816 ®s->HostCtrl);
817 wmb();
818 break;
819 case E_TX_INV_DSC:
820 printk(KERN_ERR "%s: Invalid descriptor address\n",
821 dev->name);
822 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
823 ®s->HostCtrl);
824 wmb();
825 break;
826 /*
827 * RX events.
828 */
829 case E_RX_RNG_OUT:
830 printk(KERN_INFO "%s: Receive ring full\n", dev->name);
831 break;
832
833 case E_RX_PAR_ERR:
834 printk(KERN_WARNING "%s: Receive parity error\n",
835 dev->name);
836 goto drop;
837 case E_RX_LLRC_ERR:
838 printk(KERN_WARNING "%s: Receive LLRC error\n",
839 dev->name);
840 goto drop;
841 case E_PKT_LN_ERR:
842 printk(KERN_WARNING "%s: Receive packet length "
843 "error\n", dev->name);
844 goto drop;
845 case E_DTA_CKSM_ERR:
846 printk(KERN_WARNING "%s: Data checksum error\n",
847 dev->name);
848 goto drop;
849 case E_SHT_BST:
850 printk(KERN_WARNING "%s: Unexpected short burst "
851 "error\n", dev->name);
852 goto drop;
853 case E_STATE_ERR:
854 printk(KERN_WARNING "%s: Recv. state transition"
855 " error\n", dev->name);
856 goto drop;
857 case E_UNEXP_DATA:
858 printk(KERN_WARNING "%s: Unexpected data error\n",
859 dev->name);
860 goto drop;
861 case E_LST_LNK_ERR:
862 printk(KERN_WARNING "%s: Link lost error\n",
863 dev->name);
864 goto drop;
865 case E_FRM_ERR:
866 printk(KERN_WARNING "%s: Framing Error\n",
867 dev->name);
868 goto drop;
869 case E_FLG_SYN_ERR:
870 printk(KERN_WARNING "%s: Flag sync. lost during "
871 "packet\n", dev->name);
872 goto drop;
873 case E_RX_INV_BUF:
874 printk(KERN_ERR "%s: Invalid receive buffer "
875 "address\n", dev->name);
876 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
877 ®s->HostCtrl);
878 wmb();
879 break;
880 case E_RX_INV_DSC:
881 printk(KERN_ERR "%s: Invalid receive descriptor "
882 "address\n", dev->name);
883 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
884 ®s->HostCtrl);
885 wmb();
886 break;
887 case E_RNG_BLK:
888 printk(KERN_ERR "%s: Invalid ring block\n",
889 dev->name);
890 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
891 ®s->HostCtrl);
892 wmb();
893 break;
894 drop:
895 /* Label packet to be dropped.
896 * Actual dropping occurs in rx
897 * handling.
898 *
899 * The index of packet we get to drop is
900 * the index of the packet following
901 * the bad packet. -kbf
902 */
903 {
904 u16 index = rrpriv->evt_ring[eidx].index;
905 index = (index + (RX_RING_ENTRIES - 1)) %
906 RX_RING_ENTRIES;
907 rrpriv->rx_ring[index].mode |=
908 (PACKET_BAD | PACKET_END);
909 }
910 break;
911 default:
912 printk(KERN_WARNING "%s: Unhandled event 0x%02x\n",
913 dev->name, rrpriv->evt_ring[eidx].code);
914 }
915 eidx = (eidx + 1) % EVT_RING_ENTRIES;
916 }
917
918 rrpriv->info->evt_ctrl.pi = eidx;
919 wmb();
920 return eidx;
921}
922
923
924static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
925{
926 struct rr_private *rrpriv = netdev_priv(dev);
927 struct rr_regs __iomem *regs = rrpriv->regs;
928
929 do {
930 struct rx_desc *desc;
931 u32 pkt_len;
932
933 desc = &(rrpriv->rx_ring[index]);
934 pkt_len = desc->size;
935#if (DEBUG > 2)
936 printk("index %i, rxlimit %i\n", index, rxlimit);
937 printk("len %x, mode %x\n", pkt_len, desc->mode);
938#endif
939 if ( (rrpriv->rx_ring[index].mode & PACKET_BAD) == PACKET_BAD){
940 dev->stats.rx_dropped++;
941 goto defer;
942 }
943
944 if (pkt_len > 0){
945 struct sk_buff *skb, *rx_skb;
946
947 rx_skb = rrpriv->rx_skbuff[index];
948
949 if (pkt_len < PKT_COPY_THRESHOLD) {
950 skb = alloc_skb(pkt_len, GFP_ATOMIC);
951 if (skb == NULL){
952 printk(KERN_WARNING "%s: Unable to allocate skb (%i bytes), deferring packet\n", dev->name, pkt_len);
953 dev->stats.rx_dropped++;
954 goto defer;
955 } else {
956 pci_dma_sync_single_for_cpu(rrpriv->pci_dev,
957 desc->addr.addrlo,
958 pkt_len,
959 PCI_DMA_FROMDEVICE);
960
961 skb_put_data(skb, rx_skb->data,
962 pkt_len);
963
964 pci_dma_sync_single_for_device(rrpriv->pci_dev,
965 desc->addr.addrlo,
966 pkt_len,
967 PCI_DMA_FROMDEVICE);
968 }
969 }else{
970 struct sk_buff *newskb;
971
972 newskb = alloc_skb(dev->mtu + HIPPI_HLEN,
973 GFP_ATOMIC);
974 if (newskb){
975 dma_addr_t addr;
976
977 pci_unmap_single(rrpriv->pci_dev,
978 desc->addr.addrlo, dev->mtu +
979 HIPPI_HLEN, PCI_DMA_FROMDEVICE);
980 skb = rx_skb;
981 skb_put(skb, pkt_len);
982 rrpriv->rx_skbuff[index] = newskb;
983 addr = pci_map_single(rrpriv->pci_dev,
984 newskb->data,
985 dev->mtu + HIPPI_HLEN,
986 PCI_DMA_FROMDEVICE);
987 set_rraddr(&desc->addr, addr);
988 } else {
989 printk("%s: Out of memory, deferring "
990 "packet\n", dev->name);
991 dev->stats.rx_dropped++;
992 goto defer;
993 }
994 }
995 skb->protocol = hippi_type_trans(skb, dev);
996
997 netif_rx(skb); /* send it up */
998
999 dev->stats.rx_packets++;
1000 dev->stats.rx_bytes += pkt_len;
1001 }
1002 defer:
1003 desc->mode = 0;
1004 desc->size = dev->mtu + HIPPI_HLEN;
1005
1006 if ((index & 7) == 7)
1007 writel(index, ®s->IpRxPi);
1008
1009 index = (index + 1) % RX_RING_ENTRIES;
1010 } while(index != rxlimit);
1011
1012 rrpriv->cur_rx = index;
1013 wmb();
1014}
1015
1016
1017static irqreturn_t rr_interrupt(int irq, void *dev_id)
1018{
1019 struct rr_private *rrpriv;
1020 struct rr_regs __iomem *regs;
1021 struct net_device *dev = (struct net_device *)dev_id;
1022 u32 prodidx, rxindex, eidx, txcsmr, rxlimit, txcon;
1023
1024 rrpriv = netdev_priv(dev);
1025 regs = rrpriv->regs;
1026
1027 if (!(readl(®s->HostCtrl) & RR_INT))
1028 return IRQ_NONE;
1029
1030 spin_lock(&rrpriv->lock);
1031
1032 prodidx = readl(®s->EvtPrd);
1033 txcsmr = (prodidx >> 8) & 0xff;
1034 rxlimit = (prodidx >> 16) & 0xff;
1035 prodidx &= 0xff;
1036
1037#if (DEBUG > 2)
1038 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev->name,
1039 prodidx, rrpriv->info->evt_ctrl.pi);
1040#endif
1041 /*
1042 * Order here is important. We must handle events
1043 * before doing anything else in order to catch
1044 * such things as LLRC errors, etc -kbf
1045 */
1046
1047 eidx = rrpriv->info->evt_ctrl.pi;
1048 if (prodidx != eidx)
1049 eidx = rr_handle_event(dev, prodidx, eidx);
1050
1051 rxindex = rrpriv->cur_rx;
1052 if (rxindex != rxlimit)
1053 rx_int(dev, rxlimit, rxindex);
1054
1055 txcon = rrpriv->dirty_tx;
1056 if (txcsmr != txcon) {
1057 do {
1058 /* Due to occational firmware TX producer/consumer out
1059 * of sync. error need to check entry in ring -kbf
1060 */
1061 if(rrpriv->tx_skbuff[txcon]){
1062 struct tx_desc *desc;
1063 struct sk_buff *skb;
1064
1065 desc = &(rrpriv->tx_ring[txcon]);
1066 skb = rrpriv->tx_skbuff[txcon];
1067
1068 dev->stats.tx_packets++;
1069 dev->stats.tx_bytes += skb->len;
1070
1071 pci_unmap_single(rrpriv->pci_dev,
1072 desc->addr.addrlo, skb->len,
1073 PCI_DMA_TODEVICE);
1074 dev_kfree_skb_irq(skb);
1075
1076 rrpriv->tx_skbuff[txcon] = NULL;
1077 desc->size = 0;
1078 set_rraddr(&rrpriv->tx_ring[txcon].addr, 0);
1079 desc->mode = 0;
1080 }
1081 txcon = (txcon + 1) % TX_RING_ENTRIES;
1082 } while (txcsmr != txcon);
1083 wmb();
1084
1085 rrpriv->dirty_tx = txcon;
1086 if (rrpriv->tx_full && rr_if_busy(dev) &&
1087 (((rrpriv->info->tx_ctrl.pi + 1) % TX_RING_ENTRIES)
1088 != rrpriv->dirty_tx)){
1089 rrpriv->tx_full = 0;
1090 netif_wake_queue(dev);
1091 }
1092 }
1093
1094 eidx |= ((txcsmr << 8) | (rxlimit << 16));
1095 writel(eidx, ®s->EvtCon);
1096 wmb();
1097
1098 spin_unlock(&rrpriv->lock);
1099 return IRQ_HANDLED;
1100}
1101
1102static inline void rr_raz_tx(struct rr_private *rrpriv,
1103 struct net_device *dev)
1104{
1105 int i;
1106
1107 for (i = 0; i < TX_RING_ENTRIES; i++) {
1108 struct sk_buff *skb = rrpriv->tx_skbuff[i];
1109
1110 if (skb) {
1111 struct tx_desc *desc = &(rrpriv->tx_ring[i]);
1112
1113 pci_unmap_single(rrpriv->pci_dev, desc->addr.addrlo,
1114 skb->len, PCI_DMA_TODEVICE);
1115 desc->size = 0;
1116 set_rraddr(&desc->addr, 0);
1117 dev_kfree_skb(skb);
1118 rrpriv->tx_skbuff[i] = NULL;
1119 }
1120 }
1121}
1122
1123
1124static inline void rr_raz_rx(struct rr_private *rrpriv,
1125 struct net_device *dev)
1126{
1127 int i;
1128
1129 for (i = 0; i < RX_RING_ENTRIES; i++) {
1130 struct sk_buff *skb = rrpriv->rx_skbuff[i];
1131
1132 if (skb) {
1133 struct rx_desc *desc = &(rrpriv->rx_ring[i]);
1134
1135 pci_unmap_single(rrpriv->pci_dev, desc->addr.addrlo,
1136 dev->mtu + HIPPI_HLEN, PCI_DMA_FROMDEVICE);
1137 desc->size = 0;
1138 set_rraddr(&desc->addr, 0);
1139 dev_kfree_skb(skb);
1140 rrpriv->rx_skbuff[i] = NULL;
1141 }
1142 }
1143}
1144
1145static void rr_timer(struct timer_list *t)
1146{
1147 struct rr_private *rrpriv = from_timer(rrpriv, t, timer);
1148 struct net_device *dev = pci_get_drvdata(rrpriv->pci_dev);
1149 struct rr_regs __iomem *regs = rrpriv->regs;
1150 unsigned long flags;
1151
1152 if (readl(®s->HostCtrl) & NIC_HALTED){
1153 printk("%s: Restarting nic\n", dev->name);
1154 memset(rrpriv->rx_ctrl, 0, 256 * sizeof(struct ring_ctrl));
1155 memset(rrpriv->info, 0, sizeof(struct rr_info));
1156 wmb();
1157
1158 rr_raz_tx(rrpriv, dev);
1159 rr_raz_rx(rrpriv, dev);
1160
1161 if (rr_init1(dev)) {
1162 spin_lock_irqsave(&rrpriv->lock, flags);
1163 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
1164 ®s->HostCtrl);
1165 spin_unlock_irqrestore(&rrpriv->lock, flags);
1166 }
1167 }
1168 rrpriv->timer.expires = RUN_AT(5*HZ);
1169 add_timer(&rrpriv->timer);
1170}
1171
1172
1173static int rr_open(struct net_device *dev)
1174{
1175 struct rr_private *rrpriv = netdev_priv(dev);
1176 struct pci_dev *pdev = rrpriv->pci_dev;
1177 struct rr_regs __iomem *regs;
1178 int ecode = 0;
1179 unsigned long flags;
1180 dma_addr_t dma_addr;
1181
1182 regs = rrpriv->regs;
1183
1184 if (rrpriv->fw_rev < 0x00020000) {
1185 printk(KERN_WARNING "%s: trying to configure device with "
1186 "obsolete firmware\n", dev->name);
1187 ecode = -EBUSY;
1188 goto error;
1189 }
1190
1191 rrpriv->rx_ctrl = pci_alloc_consistent(pdev,
1192 256 * sizeof(struct ring_ctrl),
1193 &dma_addr);
1194 if (!rrpriv->rx_ctrl) {
1195 ecode = -ENOMEM;
1196 goto error;
1197 }
1198 rrpriv->rx_ctrl_dma = dma_addr;
1199
1200 rrpriv->info = pci_alloc_consistent(pdev, sizeof(struct rr_info),
1201 &dma_addr);
1202 if (!rrpriv->info) {
1203 ecode = -ENOMEM;
1204 goto error;
1205 }
1206 rrpriv->info_dma = dma_addr;
1207 wmb();
1208
1209 spin_lock_irqsave(&rrpriv->lock, flags);
1210 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT, ®s->HostCtrl);
1211 readl(®s->HostCtrl);
1212 spin_unlock_irqrestore(&rrpriv->lock, flags);
1213
1214 if (request_irq(pdev->irq, rr_interrupt, IRQF_SHARED, dev->name, dev)) {
1215 printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
1216 dev->name, pdev->irq);
1217 ecode = -EAGAIN;
1218 goto error;
1219 }
1220
1221 if ((ecode = rr_init1(dev)))
1222 goto error;
1223
1224 /* Set the timer to switch to check for link beat and perhaps switch
1225 to an alternate media type. */
1226 timer_setup(&rrpriv->timer, rr_timer, 0);
1227 rrpriv->timer.expires = RUN_AT(5*HZ); /* 5 sec. watchdog */
1228 add_timer(&rrpriv->timer);
1229
1230 netif_start_queue(dev);
1231
1232 return ecode;
1233
1234 error:
1235 spin_lock_irqsave(&rrpriv->lock, flags);
1236 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT, ®s->HostCtrl);
1237 spin_unlock_irqrestore(&rrpriv->lock, flags);
1238
1239 if (rrpriv->info) {
1240 pci_free_consistent(pdev, sizeof(struct rr_info), rrpriv->info,
1241 rrpriv->info_dma);
1242 rrpriv->info = NULL;
1243 }
1244 if (rrpriv->rx_ctrl) {
1245 pci_free_consistent(pdev, sizeof(struct ring_ctrl),
1246 rrpriv->rx_ctrl, rrpriv->rx_ctrl_dma);
1247 rrpriv->rx_ctrl = NULL;
1248 }
1249
1250 netif_stop_queue(dev);
1251
1252 return ecode;
1253}
1254
1255
1256static void rr_dump(struct net_device *dev)
1257{
1258 struct rr_private *rrpriv;
1259 struct rr_regs __iomem *regs;
1260 u32 index, cons;
1261 short i;
1262 int len;
1263
1264 rrpriv = netdev_priv(dev);
1265 regs = rrpriv->regs;
1266
1267 printk("%s: dumping NIC TX rings\n", dev->name);
1268
1269 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1270 readl(®s->RxPrd), readl(®s->TxPrd),
1271 readl(®s->EvtPrd), readl(®s->TxPi),
1272 rrpriv->info->tx_ctrl.pi);
1273
1274 printk("Error code 0x%x\n", readl(®s->Fail1));
1275
1276 index = (((readl(®s->EvtPrd) >> 8) & 0xff) - 1) % TX_RING_ENTRIES;
1277 cons = rrpriv->dirty_tx;
1278 printk("TX ring index %i, TX consumer %i\n",
1279 index, cons);
1280
1281 if (rrpriv->tx_skbuff[index]){
1282 len = min_t(int, 0x80, rrpriv->tx_skbuff[index]->len);
1283 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index, len, rrpriv->tx_ring[index].size);
1284 for (i = 0; i < len; i++){
1285 if (!(i & 7))
1286 printk("\n");
1287 printk("%02x ", (unsigned char) rrpriv->tx_skbuff[index]->data[i]);
1288 }
1289 printk("\n");
1290 }
1291
1292 if (rrpriv->tx_skbuff[cons]){
1293 len = min_t(int, 0x80, rrpriv->tx_skbuff[cons]->len);
1294 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons, len, rrpriv->tx_skbuff[cons]->len);
1295 printk("mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %p, truesize 0x%x\n",
1296 rrpriv->tx_ring[cons].mode,
1297 rrpriv->tx_ring[cons].size,
1298 (unsigned long long) rrpriv->tx_ring[cons].addr.addrlo,
1299 rrpriv->tx_skbuff[cons]->data,
1300 (unsigned int)rrpriv->tx_skbuff[cons]->truesize);
1301 for (i = 0; i < len; i++){
1302 if (!(i & 7))
1303 printk("\n");
1304 printk("%02x ", (unsigned char)rrpriv->tx_ring[cons].size);
1305 }
1306 printk("\n");
1307 }
1308
1309 printk("dumping TX ring info:\n");
1310 for (i = 0; i < TX_RING_ENTRIES; i++)
1311 printk("mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1312 rrpriv->tx_ring[i].mode,
1313 rrpriv->tx_ring[i].size,
1314 (unsigned long long) rrpriv->tx_ring[i].addr.addrlo);
1315
1316}
1317
1318
1319static int rr_close(struct net_device *dev)
1320{
1321 struct rr_private *rrpriv = netdev_priv(dev);
1322 struct rr_regs __iomem *regs = rrpriv->regs;
1323 struct pci_dev *pdev = rrpriv->pci_dev;
1324 unsigned long flags;
1325 u32 tmp;
1326 short i;
1327
1328 netif_stop_queue(dev);
1329
1330
1331 /*
1332 * Lock to make sure we are not cleaning up while another CPU
1333 * is handling interrupts.
1334 */
1335 spin_lock_irqsave(&rrpriv->lock, flags);
1336
1337 tmp = readl(®s->HostCtrl);
1338 if (tmp & NIC_HALTED){
1339 printk("%s: NIC already halted\n", dev->name);
1340 rr_dump(dev);
1341 }else{
1342 tmp |= HALT_NIC | RR_CLEAR_INT;
1343 writel(tmp, ®s->HostCtrl);
1344 readl(®s->HostCtrl);
1345 }
1346
1347 rrpriv->fw_running = 0;
1348
1349 del_timer_sync(&rrpriv->timer);
1350
1351 writel(0, ®s->TxPi);
1352 writel(0, ®s->IpRxPi);
1353
1354 writel(0, ®s->EvtCon);
1355 writel(0, ®s->EvtPrd);
1356
1357 for (i = 0; i < CMD_RING_ENTRIES; i++)
1358 writel(0, ®s->CmdRing[i]);
1359
1360 rrpriv->info->tx_ctrl.entries = 0;
1361 rrpriv->info->cmd_ctrl.pi = 0;
1362 rrpriv->info->evt_ctrl.pi = 0;
1363 rrpriv->rx_ctrl[4].entries = 0;
1364
1365 rr_raz_tx(rrpriv, dev);
1366 rr_raz_rx(rrpriv, dev);
1367
1368 pci_free_consistent(pdev, 256 * sizeof(struct ring_ctrl),
1369 rrpriv->rx_ctrl, rrpriv->rx_ctrl_dma);
1370 rrpriv->rx_ctrl = NULL;
1371
1372 pci_free_consistent(pdev, sizeof(struct rr_info), rrpriv->info,
1373 rrpriv->info_dma);
1374 rrpriv->info = NULL;
1375
1376 spin_unlock_irqrestore(&rrpriv->lock, flags);
1377 free_irq(pdev->irq, dev);
1378
1379 return 0;
1380}
1381
1382
1383static netdev_tx_t rr_start_xmit(struct sk_buff *skb,
1384 struct net_device *dev)
1385{
1386 struct rr_private *rrpriv = netdev_priv(dev);
1387 struct rr_regs __iomem *regs = rrpriv->regs;
1388 struct hippi_cb *hcb = (struct hippi_cb *) skb->cb;
1389 struct ring_ctrl *txctrl;
1390 unsigned long flags;
1391 u32 index, len = skb->len;
1392 u32 *ifield;
1393 struct sk_buff *new_skb;
1394
1395 if (readl(®s->Mode) & FATAL_ERR)
1396 printk("error codes Fail1 %02x, Fail2 %02x\n",
1397 readl(®s->Fail1), readl(®s->Fail2));
1398
1399 /*
1400 * We probably need to deal with tbusy here to prevent overruns.
1401 */
1402
1403 if (skb_headroom(skb) < 8){
1404 printk("incoming skb too small - reallocating\n");
1405 if (!(new_skb = dev_alloc_skb(len + 8))) {
1406 dev_kfree_skb(skb);
1407 netif_wake_queue(dev);
1408 return NETDEV_TX_OK;
1409 }
1410 skb_reserve(new_skb, 8);
1411 skb_put(new_skb, len);
1412 skb_copy_from_linear_data(skb, new_skb->data, len);
1413 dev_kfree_skb(skb);
1414 skb = new_skb;
1415 }
1416
1417 ifield = skb_push(skb, 8);
1418
1419 ifield[0] = 0;
1420 ifield[1] = hcb->ifield;
1421
1422 /*
1423 * We don't need the lock before we are actually going to start
1424 * fiddling with the control blocks.
1425 */
1426 spin_lock_irqsave(&rrpriv->lock, flags);
1427
1428 txctrl = &rrpriv->info->tx_ctrl;
1429
1430 index = txctrl->pi;
1431
1432 rrpriv->tx_skbuff[index] = skb;
1433 set_rraddr(&rrpriv->tx_ring[index].addr, pci_map_single(
1434 rrpriv->pci_dev, skb->data, len + 8, PCI_DMA_TODEVICE));
1435 rrpriv->tx_ring[index].size = len + 8; /* include IFIELD */
1436 rrpriv->tx_ring[index].mode = PACKET_START | PACKET_END;
1437 txctrl->pi = (index + 1) % TX_RING_ENTRIES;
1438 wmb();
1439 writel(txctrl->pi, ®s->TxPi);
1440
1441 if (txctrl->pi == rrpriv->dirty_tx){
1442 rrpriv->tx_full = 1;
1443 netif_stop_queue(dev);
1444 }
1445
1446 spin_unlock_irqrestore(&rrpriv->lock, flags);
1447
1448 return NETDEV_TX_OK;
1449}
1450
1451
1452/*
1453 * Read the firmware out of the EEPROM and put it into the SRAM
1454 * (or from user space - later)
1455 *
1456 * This operation requires the NIC to be halted and is performed with
1457 * interrupts disabled and with the spinlock hold.
1458 */
1459static int rr_load_firmware(struct net_device *dev)
1460{
1461 struct rr_private *rrpriv;
1462 struct rr_regs __iomem *regs;
1463 size_t eptr, segptr;
1464 int i, j;
1465 u32 localctrl, sptr, len, tmp;
1466 u32 p2len, p2size, nr_seg, revision, io, sram_size;
1467
1468 rrpriv = netdev_priv(dev);
1469 regs = rrpriv->regs;
1470
1471 if (dev->flags & IFF_UP)
1472 return -EBUSY;
1473
1474 if (!(readl(®s->HostCtrl) & NIC_HALTED)){
1475 printk("%s: Trying to load firmware to a running NIC.\n",
1476 dev->name);
1477 return -EBUSY;
1478 }
1479
1480 localctrl = readl(®s->LocalCtrl);
1481 writel(0, ®s->LocalCtrl);
1482
1483 writel(0, ®s->EvtPrd);
1484 writel(0, ®s->RxPrd);
1485 writel(0, ®s->TxPrd);
1486
1487 /*
1488 * First wipe the entire SRAM, otherwise we might run into all
1489 * kinds of trouble ... sigh, this took almost all afternoon
1490 * to track down ;-(
1491 */
1492 io = readl(®s->ExtIo);
1493 writel(0, ®s->ExtIo);
1494 sram_size = rr_read_eeprom_word(rrpriv, 8);
1495
1496 for (i = 200; i < sram_size / 4; i++){
1497 writel(i * 4, ®s->WinBase);
1498 mb();
1499 writel(0, ®s->WinData);
1500 mb();
1501 }
1502 writel(io, ®s->ExtIo);
1503 mb();
1504
1505 eptr = rr_read_eeprom_word(rrpriv,
1506 offsetof(struct eeprom, rncd_info.AddrRunCodeSegs));
1507 eptr = ((eptr & 0x1fffff) >> 3);
1508
1509 p2len = rr_read_eeprom_word(rrpriv, 0x83*4);
1510 p2len = (p2len << 2);
1511 p2size = rr_read_eeprom_word(rrpriv, 0x84*4);
1512 p2size = ((p2size & 0x1fffff) >> 3);
1513
1514 if ((eptr < p2size) || (eptr > (p2size + p2len))){
1515 printk("%s: eptr is invalid\n", dev->name);
1516 goto out;
1517 }
1518
1519 revision = rr_read_eeprom_word(rrpriv,
1520 offsetof(struct eeprom, manf.HeaderFmt));
1521
1522 if (revision != 1){
1523 printk("%s: invalid firmware format (%i)\n",
1524 dev->name, revision);
1525 goto out;
1526 }
1527
1528 nr_seg = rr_read_eeprom_word(rrpriv, eptr);
1529 eptr +=4;
1530#if (DEBUG > 1)
1531 printk("%s: nr_seg %i\n", dev->name, nr_seg);
1532#endif
1533
1534 for (i = 0; i < nr_seg; i++){
1535 sptr = rr_read_eeprom_word(rrpriv, eptr);
1536 eptr += 4;
1537 len = rr_read_eeprom_word(rrpriv, eptr);
1538 eptr += 4;
1539 segptr = rr_read_eeprom_word(rrpriv, eptr);
1540 segptr = ((segptr & 0x1fffff) >> 3);
1541 eptr += 4;
1542#if (DEBUG > 1)
1543 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1544 dev->name, i, sptr, len, segptr);
1545#endif
1546 for (j = 0; j < len; j++){
1547 tmp = rr_read_eeprom_word(rrpriv, segptr);
1548 writel(sptr, ®s->WinBase);
1549 mb();
1550 writel(tmp, ®s->WinData);
1551 mb();
1552 segptr += 4;
1553 sptr += 4;
1554 }
1555 }
1556
1557out:
1558 writel(localctrl, ®s->LocalCtrl);
1559 mb();
1560 return 0;
1561}
1562
1563
1564static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1565{
1566 struct rr_private *rrpriv;
1567 unsigned char *image, *oldimage;
1568 unsigned long flags;
1569 unsigned int i;
1570 int error = -EOPNOTSUPP;
1571
1572 rrpriv = netdev_priv(dev);
1573
1574 switch(cmd){
1575 case SIOCRRGFW:
1576 if (!capable(CAP_SYS_RAWIO)){
1577 return -EPERM;
1578 }
1579
1580 image = kmalloc_array(EEPROM_WORDS, sizeof(u32), GFP_KERNEL);
1581 if (!image)
1582 return -ENOMEM;
1583
1584 if (rrpriv->fw_running){
1585 printk("%s: Firmware already running\n", dev->name);
1586 error = -EPERM;
1587 goto gf_out;
1588 }
1589
1590 spin_lock_irqsave(&rrpriv->lock, flags);
1591 i = rr_read_eeprom(rrpriv, 0, image, EEPROM_BYTES);
1592 spin_unlock_irqrestore(&rrpriv->lock, flags);
1593 if (i != EEPROM_BYTES){
1594 printk(KERN_ERR "%s: Error reading EEPROM\n",
1595 dev->name);
1596 error = -EFAULT;
1597 goto gf_out;
1598 }
1599 error = copy_to_user(rq->ifr_data, image, EEPROM_BYTES);
1600 if (error)
1601 error = -EFAULT;
1602 gf_out:
1603 kfree(image);
1604 return error;
1605
1606 case SIOCRRPFW:
1607 if (!capable(CAP_SYS_RAWIO)){
1608 return -EPERM;
1609 }
1610
1611 image = memdup_user(rq->ifr_data, EEPROM_BYTES);
1612 if (IS_ERR(image))
1613 return PTR_ERR(image);
1614
1615 oldimage = kmalloc(EEPROM_BYTES, GFP_KERNEL);
1616 if (!oldimage) {
1617 kfree(image);
1618 return -ENOMEM;
1619 }
1620
1621 if (rrpriv->fw_running){
1622 printk("%s: Firmware already running\n", dev->name);
1623 error = -EPERM;
1624 goto wf_out;
1625 }
1626
1627 printk("%s: Updating EEPROM firmware\n", dev->name);
1628
1629 spin_lock_irqsave(&rrpriv->lock, flags);
1630 error = write_eeprom(rrpriv, 0, image, EEPROM_BYTES);
1631 if (error)
1632 printk(KERN_ERR "%s: Error writing EEPROM\n",
1633 dev->name);
1634
1635 i = rr_read_eeprom(rrpriv, 0, oldimage, EEPROM_BYTES);
1636 spin_unlock_irqrestore(&rrpriv->lock, flags);
1637
1638 if (i != EEPROM_BYTES)
1639 printk(KERN_ERR "%s: Error reading back EEPROM "
1640 "image\n", dev->name);
1641
1642 error = memcmp(image, oldimage, EEPROM_BYTES);
1643 if (error){
1644 printk(KERN_ERR "%s: Error verifying EEPROM image\n",
1645 dev->name);
1646 error = -EFAULT;
1647 }
1648 wf_out:
1649 kfree(oldimage);
1650 kfree(image);
1651 return error;
1652
1653 case SIOCRRID:
1654 return put_user(0x52523032, (int __user *)rq->ifr_data);
1655 default:
1656 return error;
1657 }
1658}
1659
1660static const struct pci_device_id rr_pci_tbl[] = {
1661 { PCI_VENDOR_ID_ESSENTIAL, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER,
1662 PCI_ANY_ID, PCI_ANY_ID, },
1663 { 0,}
1664};
1665MODULE_DEVICE_TABLE(pci, rr_pci_tbl);
1666
1667static struct pci_driver rr_driver = {
1668 .name = "rrunner",
1669 .id_table = rr_pci_tbl,
1670 .probe = rr_init_one,
1671 .remove = rr_remove_one,
1672};
1673
1674module_pci_driver(rr_driver);
1/*
2 * rrunner.c: Linux driver for the Essential RoadRunner HIPPI board.
3 *
4 * Copyright (C) 1998-2002 by Jes Sorensen, <jes@wildopensource.com>.
5 *
6 * Thanks to Essential Communication for providing us with hardware
7 * and very comprehensive documentation without which I would not have
8 * been able to write this driver. A special thank you to John Gibbon
9 * for sorting out the legal issues, with the NDA, allowing the code to
10 * be released under the GPL.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * Thanks to Jayaram Bhat from ODS/Essential for fixing some of the
18 * stupid bugs in my code.
19 *
20 * Softnet support and various other patches from Val Henson of
21 * ODS/Essential.
22 *
23 * PCI DMA mapping code partly based on work by Francois Romieu.
24 */
25
26
27#define DEBUG 1
28#define RX_DMA_SKBUFF 1
29#define PKT_COPY_THRESHOLD 512
30
31#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/errno.h>
34#include <linux/ioport.h>
35#include <linux/pci.h>
36#include <linux/kernel.h>
37#include <linux/netdevice.h>
38#include <linux/hippidevice.h>
39#include <linux/skbuff.h>
40#include <linux/init.h>
41#include <linux/delay.h>
42#include <linux/mm.h>
43#include <linux/slab.h>
44#include <net/sock.h>
45
46#include <asm/cache.h>
47#include <asm/byteorder.h>
48#include <asm/io.h>
49#include <asm/irq.h>
50#include <asm/uaccess.h>
51
52#define rr_if_busy(dev) netif_queue_stopped(dev)
53#define rr_if_running(dev) netif_running(dev)
54
55#include "rrunner.h"
56
57#define RUN_AT(x) (jiffies + (x))
58
59
60MODULE_AUTHOR("Jes Sorensen <jes@wildopensource.com>");
61MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
62MODULE_LICENSE("GPL");
63
64static char version[] __devinitdata = "rrunner.c: v0.50 11/11/2002 Jes Sorensen (jes@wildopensource.com)\n";
65
66
67static const struct net_device_ops rr_netdev_ops = {
68 .ndo_open = rr_open,
69 .ndo_stop = rr_close,
70 .ndo_do_ioctl = rr_ioctl,
71 .ndo_start_xmit = rr_start_xmit,
72 .ndo_change_mtu = hippi_change_mtu,
73 .ndo_set_mac_address = hippi_mac_addr,
74};
75
76/*
77 * Implementation notes:
78 *
79 * The DMA engine only allows for DMA within physical 64KB chunks of
80 * memory. The current approach of the driver (and stack) is to use
81 * linear blocks of memory for the skbuffs. However, as the data block
82 * is always the first part of the skb and skbs are 2^n aligned so we
83 * are guarantted to get the whole block within one 64KB align 64KB
84 * chunk.
85 *
86 * On the long term, relying on being able to allocate 64KB linear
87 * chunks of memory is not feasible and the skb handling code and the
88 * stack will need to know about I/O vectors or something similar.
89 */
90
91static int __devinit rr_init_one(struct pci_dev *pdev,
92 const struct pci_device_id *ent)
93{
94 struct net_device *dev;
95 static int version_disp;
96 u8 pci_latency;
97 struct rr_private *rrpriv;
98 void *tmpptr;
99 dma_addr_t ring_dma;
100 int ret = -ENOMEM;
101
102 dev = alloc_hippi_dev(sizeof(struct rr_private));
103 if (!dev)
104 goto out3;
105
106 ret = pci_enable_device(pdev);
107 if (ret) {
108 ret = -ENODEV;
109 goto out2;
110 }
111
112 rrpriv = netdev_priv(dev);
113
114 SET_NETDEV_DEV(dev, &pdev->dev);
115
116 ret = pci_request_regions(pdev, "rrunner");
117 if (ret < 0)
118 goto out;
119
120 pci_set_drvdata(pdev, dev);
121
122 rrpriv->pci_dev = pdev;
123
124 spin_lock_init(&rrpriv->lock);
125
126 dev->netdev_ops = &rr_netdev_ops;
127
128 /* display version info if adapter is found */
129 if (!version_disp) {
130 /* set display flag to TRUE so that */
131 /* we only display this string ONCE */
132 version_disp = 1;
133 printk(version);
134 }
135
136 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
137 if (pci_latency <= 0x58){
138 pci_latency = 0x58;
139 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, pci_latency);
140 }
141
142 pci_set_master(pdev);
143
144 printk(KERN_INFO "%s: Essential RoadRunner serial HIPPI "
145 "at 0x%llx, irq %i, PCI latency %i\n", dev->name,
146 (unsigned long long)pci_resource_start(pdev, 0),
147 pdev->irq, pci_latency);
148
149 /*
150 * Remap the MMIO regs into kernel space.
151 */
152 rrpriv->regs = pci_iomap(pdev, 0, 0x1000);
153 if (!rrpriv->regs) {
154 printk(KERN_ERR "%s: Unable to map I/O register, "
155 "RoadRunner will be disabled.\n", dev->name);
156 ret = -EIO;
157 goto out;
158 }
159
160 tmpptr = pci_alloc_consistent(pdev, TX_TOTAL_SIZE, &ring_dma);
161 rrpriv->tx_ring = tmpptr;
162 rrpriv->tx_ring_dma = ring_dma;
163
164 if (!tmpptr) {
165 ret = -ENOMEM;
166 goto out;
167 }
168
169 tmpptr = pci_alloc_consistent(pdev, RX_TOTAL_SIZE, &ring_dma);
170 rrpriv->rx_ring = tmpptr;
171 rrpriv->rx_ring_dma = ring_dma;
172
173 if (!tmpptr) {
174 ret = -ENOMEM;
175 goto out;
176 }
177
178 tmpptr = pci_alloc_consistent(pdev, EVT_RING_SIZE, &ring_dma);
179 rrpriv->evt_ring = tmpptr;
180 rrpriv->evt_ring_dma = ring_dma;
181
182 if (!tmpptr) {
183 ret = -ENOMEM;
184 goto out;
185 }
186
187 /*
188 * Don't access any register before this point!
189 */
190#ifdef __BIG_ENDIAN
191 writel(readl(&rrpriv->regs->HostCtrl) | NO_SWAP,
192 &rrpriv->regs->HostCtrl);
193#endif
194 /*
195 * Need to add a case for little-endian 64-bit hosts here.
196 */
197
198 rr_init(dev);
199
200 ret = register_netdev(dev);
201 if (ret)
202 goto out;
203 return 0;
204
205 out:
206 if (rrpriv->rx_ring)
207 pci_free_consistent(pdev, RX_TOTAL_SIZE, rrpriv->rx_ring,
208 rrpriv->rx_ring_dma);
209 if (rrpriv->tx_ring)
210 pci_free_consistent(pdev, TX_TOTAL_SIZE, rrpriv->tx_ring,
211 rrpriv->tx_ring_dma);
212 if (rrpriv->regs)
213 pci_iounmap(pdev, rrpriv->regs);
214 if (pdev) {
215 pci_release_regions(pdev);
216 pci_set_drvdata(pdev, NULL);
217 }
218 out2:
219 free_netdev(dev);
220 out3:
221 return ret;
222}
223
224static void __devexit rr_remove_one (struct pci_dev *pdev)
225{
226 struct net_device *dev = pci_get_drvdata(pdev);
227 struct rr_private *rr = netdev_priv(dev);
228
229 if (!(readl(&rr->regs->HostCtrl) & NIC_HALTED)) {
230 printk(KERN_ERR "%s: trying to unload running NIC\n",
231 dev->name);
232 writel(HALT_NIC, &rr->regs->HostCtrl);
233 }
234
235 unregister_netdev(dev);
236 pci_free_consistent(pdev, EVT_RING_SIZE, rr->evt_ring,
237 rr->evt_ring_dma);
238 pci_free_consistent(pdev, RX_TOTAL_SIZE, rr->rx_ring,
239 rr->rx_ring_dma);
240 pci_free_consistent(pdev, TX_TOTAL_SIZE, rr->tx_ring,
241 rr->tx_ring_dma);
242 pci_iounmap(pdev, rr->regs);
243 pci_release_regions(pdev);
244 pci_disable_device(pdev);
245 pci_set_drvdata(pdev, NULL);
246 free_netdev(dev);
247}
248
249
250/*
251 * Commands are considered to be slow, thus there is no reason to
252 * inline this.
253 */
254static void rr_issue_cmd(struct rr_private *rrpriv, struct cmd *cmd)
255{
256 struct rr_regs __iomem *regs;
257 u32 idx;
258
259 regs = rrpriv->regs;
260 /*
261 * This is temporary - it will go away in the final version.
262 * We probably also want to make this function inline.
263 */
264 if (readl(®s->HostCtrl) & NIC_HALTED){
265 printk("issuing command for halted NIC, code 0x%x, "
266 "HostCtrl %08x\n", cmd->code, readl(®s->HostCtrl));
267 if (readl(®s->Mode) & FATAL_ERR)
268 printk("error codes Fail1 %02x, Fail2 %02x\n",
269 readl(®s->Fail1), readl(®s->Fail2));
270 }
271
272 idx = rrpriv->info->cmd_ctrl.pi;
273
274 writel(*(u32*)(cmd), ®s->CmdRing[idx]);
275 wmb();
276
277 idx = (idx - 1) % CMD_RING_ENTRIES;
278 rrpriv->info->cmd_ctrl.pi = idx;
279 wmb();
280
281 if (readl(®s->Mode) & FATAL_ERR)
282 printk("error code %02x\n", readl(®s->Fail1));
283}
284
285
286/*
287 * Reset the board in a sensible manner. The NIC is already halted
288 * when we get here and a spin-lock is held.
289 */
290static int rr_reset(struct net_device *dev)
291{
292 struct rr_private *rrpriv;
293 struct rr_regs __iomem *regs;
294 u32 start_pc;
295 int i;
296
297 rrpriv = netdev_priv(dev);
298 regs = rrpriv->regs;
299
300 rr_load_firmware(dev);
301
302 writel(0x01000000, ®s->TX_state);
303 writel(0xff800000, ®s->RX_state);
304 writel(0, ®s->AssistState);
305 writel(CLEAR_INTA, ®s->LocalCtrl);
306 writel(0x01, ®s->BrkPt);
307 writel(0, ®s->Timer);
308 writel(0, ®s->TimerRef);
309 writel(RESET_DMA, ®s->DmaReadState);
310 writel(RESET_DMA, ®s->DmaWriteState);
311 writel(0, ®s->DmaWriteHostHi);
312 writel(0, ®s->DmaWriteHostLo);
313 writel(0, ®s->DmaReadHostHi);
314 writel(0, ®s->DmaReadHostLo);
315 writel(0, ®s->DmaReadLen);
316 writel(0, ®s->DmaWriteLen);
317 writel(0, ®s->DmaWriteLcl);
318 writel(0, ®s->DmaWriteIPchecksum);
319 writel(0, ®s->DmaReadLcl);
320 writel(0, ®s->DmaReadIPchecksum);
321 writel(0, ®s->PciState);
322#if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
323 writel(SWAP_DATA | PTR64BIT | PTR_WD_SWAP, ®s->Mode);
324#elif (BITS_PER_LONG == 64)
325 writel(SWAP_DATA | PTR64BIT | PTR_WD_NOSWAP, ®s->Mode);
326#else
327 writel(SWAP_DATA | PTR32BIT | PTR_WD_NOSWAP, ®s->Mode);
328#endif
329
330#if 0
331 /*
332 * Don't worry, this is just black magic.
333 */
334 writel(0xdf000, ®s->RxBase);
335 writel(0xdf000, ®s->RxPrd);
336 writel(0xdf000, ®s->RxCon);
337 writel(0xce000, ®s->TxBase);
338 writel(0xce000, ®s->TxPrd);
339 writel(0xce000, ®s->TxCon);
340 writel(0, ®s->RxIndPro);
341 writel(0, ®s->RxIndCon);
342 writel(0, ®s->RxIndRef);
343 writel(0, ®s->TxIndPro);
344 writel(0, ®s->TxIndCon);
345 writel(0, ®s->TxIndRef);
346 writel(0xcc000, ®s->pad10[0]);
347 writel(0, ®s->DrCmndPro);
348 writel(0, ®s->DrCmndCon);
349 writel(0, ®s->DwCmndPro);
350 writel(0, ®s->DwCmndCon);
351 writel(0, ®s->DwCmndRef);
352 writel(0, ®s->DrDataPro);
353 writel(0, ®s->DrDataCon);
354 writel(0, ®s->DrDataRef);
355 writel(0, ®s->DwDataPro);
356 writel(0, ®s->DwDataCon);
357 writel(0, ®s->DwDataRef);
358#endif
359
360 writel(0xffffffff, ®s->MbEvent);
361 writel(0, ®s->Event);
362
363 writel(0, ®s->TxPi);
364 writel(0, ®s->IpRxPi);
365
366 writel(0, ®s->EvtCon);
367 writel(0, ®s->EvtPrd);
368
369 rrpriv->info->evt_ctrl.pi = 0;
370
371 for (i = 0; i < CMD_RING_ENTRIES; i++)
372 writel(0, ®s->CmdRing[i]);
373
374/*
375 * Why 32 ? is this not cache line size dependent?
376 */
377 writel(RBURST_64|WBURST_64, ®s->PciState);
378 wmb();
379
380 start_pc = rr_read_eeprom_word(rrpriv,
381 offsetof(struct eeprom, rncd_info.FwStart));
382
383#if (DEBUG > 1)
384 printk("%s: Executing firmware at address 0x%06x\n",
385 dev->name, start_pc);
386#endif
387
388 writel(start_pc + 0x800, ®s->Pc);
389 wmb();
390 udelay(5);
391
392 writel(start_pc, ®s->Pc);
393 wmb();
394
395 return 0;
396}
397
398
399/*
400 * Read a string from the EEPROM.
401 */
402static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
403 unsigned long offset,
404 unsigned char *buf,
405 unsigned long length)
406{
407 struct rr_regs __iomem *regs = rrpriv->regs;
408 u32 misc, io, host, i;
409
410 io = readl(®s->ExtIo);
411 writel(0, ®s->ExtIo);
412 misc = readl(®s->LocalCtrl);
413 writel(0, ®s->LocalCtrl);
414 host = readl(®s->HostCtrl);
415 writel(host | HALT_NIC, ®s->HostCtrl);
416 mb();
417
418 for (i = 0; i < length; i++){
419 writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
420 mb();
421 buf[i] = (readl(®s->WinData) >> 24) & 0xff;
422 mb();
423 }
424
425 writel(host, ®s->HostCtrl);
426 writel(misc, ®s->LocalCtrl);
427 writel(io, ®s->ExtIo);
428 mb();
429 return i;
430}
431
432
433/*
434 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
435 * it to our CPU byte-order.
436 */
437static u32 rr_read_eeprom_word(struct rr_private *rrpriv,
438 size_t offset)
439{
440 __be32 word;
441
442 if ((rr_read_eeprom(rrpriv, offset,
443 (unsigned char *)&word, 4) == 4))
444 return be32_to_cpu(word);
445 return 0;
446}
447
448
449/*
450 * Write a string to the EEPROM.
451 *
452 * This is only called when the firmware is not running.
453 */
454static unsigned int write_eeprom(struct rr_private *rrpriv,
455 unsigned long offset,
456 unsigned char *buf,
457 unsigned long length)
458{
459 struct rr_regs __iomem *regs = rrpriv->regs;
460 u32 misc, io, data, i, j, ready, error = 0;
461
462 io = readl(®s->ExtIo);
463 writel(0, ®s->ExtIo);
464 misc = readl(®s->LocalCtrl);
465 writel(ENABLE_EEPROM_WRITE, ®s->LocalCtrl);
466 mb();
467
468 for (i = 0; i < length; i++){
469 writel((EEPROM_BASE + ((offset+i) << 3)), ®s->WinBase);
470 mb();
471 data = buf[i] << 24;
472 /*
473 * Only try to write the data if it is not the same
474 * value already.
475 */
476 if ((readl(®s->WinData) & 0xff000000) != data){
477 writel(data, ®s->WinData);
478 ready = 0;
479 j = 0;
480 mb();
481 while(!ready){
482 udelay(20);
483 if ((readl(®s->WinData) & 0xff000000) ==
484 data)
485 ready = 1;
486 mb();
487 if (j++ > 5000){
488 printk("data mismatch: %08x, "
489 "WinData %08x\n", data,
490 readl(®s->WinData));
491 ready = 1;
492 error = 1;
493 }
494 }
495 }
496 }
497
498 writel(misc, ®s->LocalCtrl);
499 writel(io, ®s->ExtIo);
500 mb();
501
502 return error;
503}
504
505
506static int __devinit rr_init(struct net_device *dev)
507{
508 struct rr_private *rrpriv;
509 struct rr_regs __iomem *regs;
510 u32 sram_size, rev;
511
512 rrpriv = netdev_priv(dev);
513 regs = rrpriv->regs;
514
515 rev = readl(®s->FwRev);
516 rrpriv->fw_rev = rev;
517 if (rev > 0x00020024)
518 printk(" Firmware revision: %i.%i.%i\n", (rev >> 16),
519 ((rev >> 8) & 0xff), (rev & 0xff));
520 else if (rev >= 0x00020000) {
521 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
522 "later is recommended)\n", (rev >> 16),
523 ((rev >> 8) & 0xff), (rev & 0xff));
524 }else{
525 printk(" Firmware revision too old: %i.%i.%i, please "
526 "upgrade to 2.0.37 or later.\n",
527 (rev >> 16), ((rev >> 8) & 0xff), (rev & 0xff));
528 }
529
530#if (DEBUG > 2)
531 printk(" Maximum receive rings %i\n", readl(®s->MaxRxRng));
532#endif
533
534 /*
535 * Read the hardware address from the eeprom. The HW address
536 * is not really necessary for HIPPI but awfully convenient.
537 * The pointer arithmetic to put it in dev_addr is ugly, but
538 * Donald Becker does it this way for the GigE version of this
539 * card and it's shorter and more portable than any
540 * other method I've seen. -VAL
541 */
542
543 *(__be16 *)(dev->dev_addr) =
544 htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
545 *(__be32 *)(dev->dev_addr+2) =
546 htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
547
548 printk(" MAC: %pM\n", dev->dev_addr);
549
550 sram_size = rr_read_eeprom_word(rrpriv, 8);
551 printk(" SRAM size 0x%06x\n", sram_size);
552
553 return 0;
554}
555
556
557static int rr_init1(struct net_device *dev)
558{
559 struct rr_private *rrpriv;
560 struct rr_regs __iomem *regs;
561 unsigned long myjif, flags;
562 struct cmd cmd;
563 u32 hostctrl;
564 int ecode = 0;
565 short i;
566
567 rrpriv = netdev_priv(dev);
568 regs = rrpriv->regs;
569
570 spin_lock_irqsave(&rrpriv->lock, flags);
571
572 hostctrl = readl(®s->HostCtrl);
573 writel(hostctrl | HALT_NIC | RR_CLEAR_INT, ®s->HostCtrl);
574 wmb();
575
576 if (hostctrl & PARITY_ERR){
577 printk("%s: Parity error halting NIC - this is serious!\n",
578 dev->name);
579 spin_unlock_irqrestore(&rrpriv->lock, flags);
580 ecode = -EFAULT;
581 goto error;
582 }
583
584 set_rxaddr(regs, rrpriv->rx_ctrl_dma);
585 set_infoaddr(regs, rrpriv->info_dma);
586
587 rrpriv->info->evt_ctrl.entry_size = sizeof(struct event);
588 rrpriv->info->evt_ctrl.entries = EVT_RING_ENTRIES;
589 rrpriv->info->evt_ctrl.mode = 0;
590 rrpriv->info->evt_ctrl.pi = 0;
591 set_rraddr(&rrpriv->info->evt_ctrl.rngptr, rrpriv->evt_ring_dma);
592
593 rrpriv->info->cmd_ctrl.entry_size = sizeof(struct cmd);
594 rrpriv->info->cmd_ctrl.entries = CMD_RING_ENTRIES;
595 rrpriv->info->cmd_ctrl.mode = 0;
596 rrpriv->info->cmd_ctrl.pi = 15;
597
598 for (i = 0; i < CMD_RING_ENTRIES; i++) {
599 writel(0, ®s->CmdRing[i]);
600 }
601
602 for (i = 0; i < TX_RING_ENTRIES; i++) {
603 rrpriv->tx_ring[i].size = 0;
604 set_rraddr(&rrpriv->tx_ring[i].addr, 0);
605 rrpriv->tx_skbuff[i] = NULL;
606 }
607 rrpriv->info->tx_ctrl.entry_size = sizeof(struct tx_desc);
608 rrpriv->info->tx_ctrl.entries = TX_RING_ENTRIES;
609 rrpriv->info->tx_ctrl.mode = 0;
610 rrpriv->info->tx_ctrl.pi = 0;
611 set_rraddr(&rrpriv->info->tx_ctrl.rngptr, rrpriv->tx_ring_dma);
612
613 /*
614 * Set dirty_tx before we start receiving interrupts, otherwise
615 * the interrupt handler might think it is supposed to process
616 * tx ints before we are up and running, which may cause a null
617 * pointer access in the int handler.
618 */
619 rrpriv->tx_full = 0;
620 rrpriv->cur_rx = 0;
621 rrpriv->dirty_rx = rrpriv->dirty_tx = 0;
622
623 rr_reset(dev);
624
625 /* Tuning values */
626 writel(0x5000, ®s->ConRetry);
627 writel(0x100, ®s->ConRetryTmr);
628 writel(0x500000, ®s->ConTmout);
629 writel(0x60, ®s->IntrTmr);
630 writel(0x500000, ®s->TxDataMvTimeout);
631 writel(0x200000, ®s->RxDataMvTimeout);
632 writel(0x80, ®s->WriteDmaThresh);
633 writel(0x80, ®s->ReadDmaThresh);
634
635 rrpriv->fw_running = 0;
636 wmb();
637
638 hostctrl &= ~(HALT_NIC | INVALID_INST_B | PARITY_ERR);
639 writel(hostctrl, ®s->HostCtrl);
640 wmb();
641
642 spin_unlock_irqrestore(&rrpriv->lock, flags);
643
644 for (i = 0; i < RX_RING_ENTRIES; i++) {
645 struct sk_buff *skb;
646 dma_addr_t addr;
647
648 rrpriv->rx_ring[i].mode = 0;
649 skb = alloc_skb(dev->mtu + HIPPI_HLEN, GFP_ATOMIC);
650 if (!skb) {
651 printk(KERN_WARNING "%s: Unable to allocate memory "
652 "for receive ring - halting NIC\n", dev->name);
653 ecode = -ENOMEM;
654 goto error;
655 }
656 rrpriv->rx_skbuff[i] = skb;
657 addr = pci_map_single(rrpriv->pci_dev, skb->data,
658 dev->mtu + HIPPI_HLEN, PCI_DMA_FROMDEVICE);
659 /*
660 * Sanity test to see if we conflict with the DMA
661 * limitations of the Roadrunner.
662 */
663 if ((((unsigned long)skb->data) & 0xfff) > ~65320)
664 printk("skb alloc error\n");
665
666 set_rraddr(&rrpriv->rx_ring[i].addr, addr);
667 rrpriv->rx_ring[i].size = dev->mtu + HIPPI_HLEN;
668 }
669
670 rrpriv->rx_ctrl[4].entry_size = sizeof(struct rx_desc);
671 rrpriv->rx_ctrl[4].entries = RX_RING_ENTRIES;
672 rrpriv->rx_ctrl[4].mode = 8;
673 rrpriv->rx_ctrl[4].pi = 0;
674 wmb();
675 set_rraddr(&rrpriv->rx_ctrl[4].rngptr, rrpriv->rx_ring_dma);
676
677 udelay(1000);
678
679 /*
680 * Now start the FirmWare.
681 */
682 cmd.code = C_START_FW;
683 cmd.ring = 0;
684 cmd.index = 0;
685
686 rr_issue_cmd(rrpriv, &cmd);
687
688 /*
689 * Give the FirmWare time to chew on the `get running' command.
690 */
691 myjif = jiffies + 5 * HZ;
692 while (time_before(jiffies, myjif) && !rrpriv->fw_running)
693 cpu_relax();
694
695 netif_start_queue(dev);
696
697 return ecode;
698
699 error:
700 /*
701 * We might have gotten here because we are out of memory,
702 * make sure we release everything we allocated before failing
703 */
704 for (i = 0; i < RX_RING_ENTRIES; i++) {
705 struct sk_buff *skb = rrpriv->rx_skbuff[i];
706
707 if (skb) {
708 pci_unmap_single(rrpriv->pci_dev,
709 rrpriv->rx_ring[i].addr.addrlo,
710 dev->mtu + HIPPI_HLEN,
711 PCI_DMA_FROMDEVICE);
712 rrpriv->rx_ring[i].size = 0;
713 set_rraddr(&rrpriv->rx_ring[i].addr, 0);
714 dev_kfree_skb(skb);
715 rrpriv->rx_skbuff[i] = NULL;
716 }
717 }
718 return ecode;
719}
720
721
722/*
723 * All events are considered to be slow (RX/TX ints do not generate
724 * events) and are handled here, outside the main interrupt handler,
725 * to reduce the size of the handler.
726 */
727static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
728{
729 struct rr_private *rrpriv;
730 struct rr_regs __iomem *regs;
731 u32 tmp;
732
733 rrpriv = netdev_priv(dev);
734 regs = rrpriv->regs;
735
736 while (prodidx != eidx){
737 switch (rrpriv->evt_ring[eidx].code){
738 case E_NIC_UP:
739 tmp = readl(®s->FwRev);
740 printk(KERN_INFO "%s: Firmware revision %i.%i.%i "
741 "up and running\n", dev->name,
742 (tmp >> 16), ((tmp >> 8) & 0xff), (tmp & 0xff));
743 rrpriv->fw_running = 1;
744 writel(RX_RING_ENTRIES - 1, ®s->IpRxPi);
745 wmb();
746 break;
747 case E_LINK_ON:
748 printk(KERN_INFO "%s: Optical link ON\n", dev->name);
749 break;
750 case E_LINK_OFF:
751 printk(KERN_INFO "%s: Optical link OFF\n", dev->name);
752 break;
753 case E_RX_IDLE:
754 printk(KERN_WARNING "%s: RX data not moving\n",
755 dev->name);
756 goto drop;
757 case E_WATCHDOG:
758 printk(KERN_INFO "%s: The watchdog is here to see "
759 "us\n", dev->name);
760 break;
761 case E_INTERN_ERR:
762 printk(KERN_ERR "%s: HIPPI Internal NIC error\n",
763 dev->name);
764 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
765 ®s->HostCtrl);
766 wmb();
767 break;
768 case E_HOST_ERR:
769 printk(KERN_ERR "%s: Host software error\n",
770 dev->name);
771 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
772 ®s->HostCtrl);
773 wmb();
774 break;
775 /*
776 * TX events.
777 */
778 case E_CON_REJ:
779 printk(KERN_WARNING "%s: Connection rejected\n",
780 dev->name);
781 dev->stats.tx_aborted_errors++;
782 break;
783 case E_CON_TMOUT:
784 printk(KERN_WARNING "%s: Connection timeout\n",
785 dev->name);
786 break;
787 case E_DISC_ERR:
788 printk(KERN_WARNING "%s: HIPPI disconnect error\n",
789 dev->name);
790 dev->stats.tx_aborted_errors++;
791 break;
792 case E_INT_PRTY:
793 printk(KERN_ERR "%s: HIPPI Internal Parity error\n",
794 dev->name);
795 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
796 ®s->HostCtrl);
797 wmb();
798 break;
799 case E_TX_IDLE:
800 printk(KERN_WARNING "%s: Transmitter idle\n",
801 dev->name);
802 break;
803 case E_TX_LINK_DROP:
804 printk(KERN_WARNING "%s: Link lost during transmit\n",
805 dev->name);
806 dev->stats.tx_aborted_errors++;
807 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
808 ®s->HostCtrl);
809 wmb();
810 break;
811 case E_TX_INV_RNG:
812 printk(KERN_ERR "%s: Invalid send ring block\n",
813 dev->name);
814 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
815 ®s->HostCtrl);
816 wmb();
817 break;
818 case E_TX_INV_BUF:
819 printk(KERN_ERR "%s: Invalid send buffer address\n",
820 dev->name);
821 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
822 ®s->HostCtrl);
823 wmb();
824 break;
825 case E_TX_INV_DSC:
826 printk(KERN_ERR "%s: Invalid descriptor address\n",
827 dev->name);
828 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
829 ®s->HostCtrl);
830 wmb();
831 break;
832 /*
833 * RX events.
834 */
835 case E_RX_RNG_OUT:
836 printk(KERN_INFO "%s: Receive ring full\n", dev->name);
837 break;
838
839 case E_RX_PAR_ERR:
840 printk(KERN_WARNING "%s: Receive parity error\n",
841 dev->name);
842 goto drop;
843 case E_RX_LLRC_ERR:
844 printk(KERN_WARNING "%s: Receive LLRC error\n",
845 dev->name);
846 goto drop;
847 case E_PKT_LN_ERR:
848 printk(KERN_WARNING "%s: Receive packet length "
849 "error\n", dev->name);
850 goto drop;
851 case E_DTA_CKSM_ERR:
852 printk(KERN_WARNING "%s: Data checksum error\n",
853 dev->name);
854 goto drop;
855 case E_SHT_BST:
856 printk(KERN_WARNING "%s: Unexpected short burst "
857 "error\n", dev->name);
858 goto drop;
859 case E_STATE_ERR:
860 printk(KERN_WARNING "%s: Recv. state transition"
861 " error\n", dev->name);
862 goto drop;
863 case E_UNEXP_DATA:
864 printk(KERN_WARNING "%s: Unexpected data error\n",
865 dev->name);
866 goto drop;
867 case E_LST_LNK_ERR:
868 printk(KERN_WARNING "%s: Link lost error\n",
869 dev->name);
870 goto drop;
871 case E_FRM_ERR:
872 printk(KERN_WARNING "%s: Framming Error\n",
873 dev->name);
874 goto drop;
875 case E_FLG_SYN_ERR:
876 printk(KERN_WARNING "%s: Flag sync. lost during "
877 "packet\n", dev->name);
878 goto drop;
879 case E_RX_INV_BUF:
880 printk(KERN_ERR "%s: Invalid receive buffer "
881 "address\n", dev->name);
882 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
883 ®s->HostCtrl);
884 wmb();
885 break;
886 case E_RX_INV_DSC:
887 printk(KERN_ERR "%s: Invalid receive descriptor "
888 "address\n", dev->name);
889 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
890 ®s->HostCtrl);
891 wmb();
892 break;
893 case E_RNG_BLK:
894 printk(KERN_ERR "%s: Invalid ring block\n",
895 dev->name);
896 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
897 ®s->HostCtrl);
898 wmb();
899 break;
900 drop:
901 /* Label packet to be dropped.
902 * Actual dropping occurs in rx
903 * handling.
904 *
905 * The index of packet we get to drop is
906 * the index of the packet following
907 * the bad packet. -kbf
908 */
909 {
910 u16 index = rrpriv->evt_ring[eidx].index;
911 index = (index + (RX_RING_ENTRIES - 1)) %
912 RX_RING_ENTRIES;
913 rrpriv->rx_ring[index].mode |=
914 (PACKET_BAD | PACKET_END);
915 }
916 break;
917 default:
918 printk(KERN_WARNING "%s: Unhandled event 0x%02x\n",
919 dev->name, rrpriv->evt_ring[eidx].code);
920 }
921 eidx = (eidx + 1) % EVT_RING_ENTRIES;
922 }
923
924 rrpriv->info->evt_ctrl.pi = eidx;
925 wmb();
926 return eidx;
927}
928
929
930static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
931{
932 struct rr_private *rrpriv = netdev_priv(dev);
933 struct rr_regs __iomem *regs = rrpriv->regs;
934
935 do {
936 struct rx_desc *desc;
937 u32 pkt_len;
938
939 desc = &(rrpriv->rx_ring[index]);
940 pkt_len = desc->size;
941#if (DEBUG > 2)
942 printk("index %i, rxlimit %i\n", index, rxlimit);
943 printk("len %x, mode %x\n", pkt_len, desc->mode);
944#endif
945 if ( (rrpriv->rx_ring[index].mode & PACKET_BAD) == PACKET_BAD){
946 dev->stats.rx_dropped++;
947 goto defer;
948 }
949
950 if (pkt_len > 0){
951 struct sk_buff *skb, *rx_skb;
952
953 rx_skb = rrpriv->rx_skbuff[index];
954
955 if (pkt_len < PKT_COPY_THRESHOLD) {
956 skb = alloc_skb(pkt_len, GFP_ATOMIC);
957 if (skb == NULL){
958 printk(KERN_WARNING "%s: Unable to allocate skb (%i bytes), deferring packet\n", dev->name, pkt_len);
959 dev->stats.rx_dropped++;
960 goto defer;
961 } else {
962 pci_dma_sync_single_for_cpu(rrpriv->pci_dev,
963 desc->addr.addrlo,
964 pkt_len,
965 PCI_DMA_FROMDEVICE);
966
967 memcpy(skb_put(skb, pkt_len),
968 rx_skb->data, pkt_len);
969
970 pci_dma_sync_single_for_device(rrpriv->pci_dev,
971 desc->addr.addrlo,
972 pkt_len,
973 PCI_DMA_FROMDEVICE);
974 }
975 }else{
976 struct sk_buff *newskb;
977
978 newskb = alloc_skb(dev->mtu + HIPPI_HLEN,
979 GFP_ATOMIC);
980 if (newskb){
981 dma_addr_t addr;
982
983 pci_unmap_single(rrpriv->pci_dev,
984 desc->addr.addrlo, dev->mtu +
985 HIPPI_HLEN, PCI_DMA_FROMDEVICE);
986 skb = rx_skb;
987 skb_put(skb, pkt_len);
988 rrpriv->rx_skbuff[index] = newskb;
989 addr = pci_map_single(rrpriv->pci_dev,
990 newskb->data,
991 dev->mtu + HIPPI_HLEN,
992 PCI_DMA_FROMDEVICE);
993 set_rraddr(&desc->addr, addr);
994 } else {
995 printk("%s: Out of memory, deferring "
996 "packet\n", dev->name);
997 dev->stats.rx_dropped++;
998 goto defer;
999 }
1000 }
1001 skb->protocol = hippi_type_trans(skb, dev);
1002
1003 netif_rx(skb); /* send it up */
1004
1005 dev->stats.rx_packets++;
1006 dev->stats.rx_bytes += pkt_len;
1007 }
1008 defer:
1009 desc->mode = 0;
1010 desc->size = dev->mtu + HIPPI_HLEN;
1011
1012 if ((index & 7) == 7)
1013 writel(index, ®s->IpRxPi);
1014
1015 index = (index + 1) % RX_RING_ENTRIES;
1016 } while(index != rxlimit);
1017
1018 rrpriv->cur_rx = index;
1019 wmb();
1020}
1021
1022
1023static irqreturn_t rr_interrupt(int irq, void *dev_id)
1024{
1025 struct rr_private *rrpriv;
1026 struct rr_regs __iomem *regs;
1027 struct net_device *dev = (struct net_device *)dev_id;
1028 u32 prodidx, rxindex, eidx, txcsmr, rxlimit, txcon;
1029
1030 rrpriv = netdev_priv(dev);
1031 regs = rrpriv->regs;
1032
1033 if (!(readl(®s->HostCtrl) & RR_INT))
1034 return IRQ_NONE;
1035
1036 spin_lock(&rrpriv->lock);
1037
1038 prodidx = readl(®s->EvtPrd);
1039 txcsmr = (prodidx >> 8) & 0xff;
1040 rxlimit = (prodidx >> 16) & 0xff;
1041 prodidx &= 0xff;
1042
1043#if (DEBUG > 2)
1044 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev->name,
1045 prodidx, rrpriv->info->evt_ctrl.pi);
1046#endif
1047 /*
1048 * Order here is important. We must handle events
1049 * before doing anything else in order to catch
1050 * such things as LLRC errors, etc -kbf
1051 */
1052
1053 eidx = rrpriv->info->evt_ctrl.pi;
1054 if (prodidx != eidx)
1055 eidx = rr_handle_event(dev, prodidx, eidx);
1056
1057 rxindex = rrpriv->cur_rx;
1058 if (rxindex != rxlimit)
1059 rx_int(dev, rxlimit, rxindex);
1060
1061 txcon = rrpriv->dirty_tx;
1062 if (txcsmr != txcon) {
1063 do {
1064 /* Due to occational firmware TX producer/consumer out
1065 * of sync. error need to check entry in ring -kbf
1066 */
1067 if(rrpriv->tx_skbuff[txcon]){
1068 struct tx_desc *desc;
1069 struct sk_buff *skb;
1070
1071 desc = &(rrpriv->tx_ring[txcon]);
1072 skb = rrpriv->tx_skbuff[txcon];
1073
1074 dev->stats.tx_packets++;
1075 dev->stats.tx_bytes += skb->len;
1076
1077 pci_unmap_single(rrpriv->pci_dev,
1078 desc->addr.addrlo, skb->len,
1079 PCI_DMA_TODEVICE);
1080 dev_kfree_skb_irq(skb);
1081
1082 rrpriv->tx_skbuff[txcon] = NULL;
1083 desc->size = 0;
1084 set_rraddr(&rrpriv->tx_ring[txcon].addr, 0);
1085 desc->mode = 0;
1086 }
1087 txcon = (txcon + 1) % TX_RING_ENTRIES;
1088 } while (txcsmr != txcon);
1089 wmb();
1090
1091 rrpriv->dirty_tx = txcon;
1092 if (rrpriv->tx_full && rr_if_busy(dev) &&
1093 (((rrpriv->info->tx_ctrl.pi + 1) % TX_RING_ENTRIES)
1094 != rrpriv->dirty_tx)){
1095 rrpriv->tx_full = 0;
1096 netif_wake_queue(dev);
1097 }
1098 }
1099
1100 eidx |= ((txcsmr << 8) | (rxlimit << 16));
1101 writel(eidx, ®s->EvtCon);
1102 wmb();
1103
1104 spin_unlock(&rrpriv->lock);
1105 return IRQ_HANDLED;
1106}
1107
1108static inline void rr_raz_tx(struct rr_private *rrpriv,
1109 struct net_device *dev)
1110{
1111 int i;
1112
1113 for (i = 0; i < TX_RING_ENTRIES; i++) {
1114 struct sk_buff *skb = rrpriv->tx_skbuff[i];
1115
1116 if (skb) {
1117 struct tx_desc *desc = &(rrpriv->tx_ring[i]);
1118
1119 pci_unmap_single(rrpriv->pci_dev, desc->addr.addrlo,
1120 skb->len, PCI_DMA_TODEVICE);
1121 desc->size = 0;
1122 set_rraddr(&desc->addr, 0);
1123 dev_kfree_skb(skb);
1124 rrpriv->tx_skbuff[i] = NULL;
1125 }
1126 }
1127}
1128
1129
1130static inline void rr_raz_rx(struct rr_private *rrpriv,
1131 struct net_device *dev)
1132{
1133 int i;
1134
1135 for (i = 0; i < RX_RING_ENTRIES; i++) {
1136 struct sk_buff *skb = rrpriv->rx_skbuff[i];
1137
1138 if (skb) {
1139 struct rx_desc *desc = &(rrpriv->rx_ring[i]);
1140
1141 pci_unmap_single(rrpriv->pci_dev, desc->addr.addrlo,
1142 dev->mtu + HIPPI_HLEN, PCI_DMA_FROMDEVICE);
1143 desc->size = 0;
1144 set_rraddr(&desc->addr, 0);
1145 dev_kfree_skb(skb);
1146 rrpriv->rx_skbuff[i] = NULL;
1147 }
1148 }
1149}
1150
1151static void rr_timer(unsigned long data)
1152{
1153 struct net_device *dev = (struct net_device *)data;
1154 struct rr_private *rrpriv = netdev_priv(dev);
1155 struct rr_regs __iomem *regs = rrpriv->regs;
1156 unsigned long flags;
1157
1158 if (readl(®s->HostCtrl) & NIC_HALTED){
1159 printk("%s: Restarting nic\n", dev->name);
1160 memset(rrpriv->rx_ctrl, 0, 256 * sizeof(struct ring_ctrl));
1161 memset(rrpriv->info, 0, sizeof(struct rr_info));
1162 wmb();
1163
1164 rr_raz_tx(rrpriv, dev);
1165 rr_raz_rx(rrpriv, dev);
1166
1167 if (rr_init1(dev)) {
1168 spin_lock_irqsave(&rrpriv->lock, flags);
1169 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
1170 ®s->HostCtrl);
1171 spin_unlock_irqrestore(&rrpriv->lock, flags);
1172 }
1173 }
1174 rrpriv->timer.expires = RUN_AT(5*HZ);
1175 add_timer(&rrpriv->timer);
1176}
1177
1178
1179static int rr_open(struct net_device *dev)
1180{
1181 struct rr_private *rrpriv = netdev_priv(dev);
1182 struct pci_dev *pdev = rrpriv->pci_dev;
1183 struct rr_regs __iomem *regs;
1184 int ecode = 0;
1185 unsigned long flags;
1186 dma_addr_t dma_addr;
1187
1188 regs = rrpriv->regs;
1189
1190 if (rrpriv->fw_rev < 0x00020000) {
1191 printk(KERN_WARNING "%s: trying to configure device with "
1192 "obsolete firmware\n", dev->name);
1193 ecode = -EBUSY;
1194 goto error;
1195 }
1196
1197 rrpriv->rx_ctrl = pci_alloc_consistent(pdev,
1198 256 * sizeof(struct ring_ctrl),
1199 &dma_addr);
1200 if (!rrpriv->rx_ctrl) {
1201 ecode = -ENOMEM;
1202 goto error;
1203 }
1204 rrpriv->rx_ctrl_dma = dma_addr;
1205 memset(rrpriv->rx_ctrl, 0, 256*sizeof(struct ring_ctrl));
1206
1207 rrpriv->info = pci_alloc_consistent(pdev, sizeof(struct rr_info),
1208 &dma_addr);
1209 if (!rrpriv->info) {
1210 ecode = -ENOMEM;
1211 goto error;
1212 }
1213 rrpriv->info_dma = dma_addr;
1214 memset(rrpriv->info, 0, sizeof(struct rr_info));
1215 wmb();
1216
1217 spin_lock_irqsave(&rrpriv->lock, flags);
1218 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT, ®s->HostCtrl);
1219 readl(®s->HostCtrl);
1220 spin_unlock_irqrestore(&rrpriv->lock, flags);
1221
1222 if (request_irq(pdev->irq, rr_interrupt, IRQF_SHARED, dev->name, dev)) {
1223 printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
1224 dev->name, pdev->irq);
1225 ecode = -EAGAIN;
1226 goto error;
1227 }
1228
1229 if ((ecode = rr_init1(dev)))
1230 goto error;
1231
1232 /* Set the timer to switch to check for link beat and perhaps switch
1233 to an alternate media type. */
1234 init_timer(&rrpriv->timer);
1235 rrpriv->timer.expires = RUN_AT(5*HZ); /* 5 sec. watchdog */
1236 rrpriv->timer.data = (unsigned long)dev;
1237 rrpriv->timer.function = rr_timer; /* timer handler */
1238 add_timer(&rrpriv->timer);
1239
1240 netif_start_queue(dev);
1241
1242 return ecode;
1243
1244 error:
1245 spin_lock_irqsave(&rrpriv->lock, flags);
1246 writel(readl(®s->HostCtrl)|HALT_NIC|RR_CLEAR_INT, ®s->HostCtrl);
1247 spin_unlock_irqrestore(&rrpriv->lock, flags);
1248
1249 if (rrpriv->info) {
1250 pci_free_consistent(pdev, sizeof(struct rr_info), rrpriv->info,
1251 rrpriv->info_dma);
1252 rrpriv->info = NULL;
1253 }
1254 if (rrpriv->rx_ctrl) {
1255 pci_free_consistent(pdev, sizeof(struct ring_ctrl),
1256 rrpriv->rx_ctrl, rrpriv->rx_ctrl_dma);
1257 rrpriv->rx_ctrl = NULL;
1258 }
1259
1260 netif_stop_queue(dev);
1261
1262 return ecode;
1263}
1264
1265
1266static void rr_dump(struct net_device *dev)
1267{
1268 struct rr_private *rrpriv;
1269 struct rr_regs __iomem *regs;
1270 u32 index, cons;
1271 short i;
1272 int len;
1273
1274 rrpriv = netdev_priv(dev);
1275 regs = rrpriv->regs;
1276
1277 printk("%s: dumping NIC TX rings\n", dev->name);
1278
1279 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1280 readl(®s->RxPrd), readl(®s->TxPrd),
1281 readl(®s->EvtPrd), readl(®s->TxPi),
1282 rrpriv->info->tx_ctrl.pi);
1283
1284 printk("Error code 0x%x\n", readl(®s->Fail1));
1285
1286 index = (((readl(®s->EvtPrd) >> 8) & 0xff) - 1) % TX_RING_ENTRIES;
1287 cons = rrpriv->dirty_tx;
1288 printk("TX ring index %i, TX consumer %i\n",
1289 index, cons);
1290
1291 if (rrpriv->tx_skbuff[index]){
1292 len = min_t(int, 0x80, rrpriv->tx_skbuff[index]->len);
1293 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index, len, rrpriv->tx_ring[index].size);
1294 for (i = 0; i < len; i++){
1295 if (!(i & 7))
1296 printk("\n");
1297 printk("%02x ", (unsigned char) rrpriv->tx_skbuff[index]->data[i]);
1298 }
1299 printk("\n");
1300 }
1301
1302 if (rrpriv->tx_skbuff[cons]){
1303 len = min_t(int, 0x80, rrpriv->tx_skbuff[cons]->len);
1304 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons, len, rrpriv->tx_skbuff[cons]->len);
1305 printk("mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %08lx, truesize 0x%x\n",
1306 rrpriv->tx_ring[cons].mode,
1307 rrpriv->tx_ring[cons].size,
1308 (unsigned long long) rrpriv->tx_ring[cons].addr.addrlo,
1309 (unsigned long)rrpriv->tx_skbuff[cons]->data,
1310 (unsigned int)rrpriv->tx_skbuff[cons]->truesize);
1311 for (i = 0; i < len; i++){
1312 if (!(i & 7))
1313 printk("\n");
1314 printk("%02x ", (unsigned char)rrpriv->tx_ring[cons].size);
1315 }
1316 printk("\n");
1317 }
1318
1319 printk("dumping TX ring info:\n");
1320 for (i = 0; i < TX_RING_ENTRIES; i++)
1321 printk("mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1322 rrpriv->tx_ring[i].mode,
1323 rrpriv->tx_ring[i].size,
1324 (unsigned long long) rrpriv->tx_ring[i].addr.addrlo);
1325
1326}
1327
1328
1329static int rr_close(struct net_device *dev)
1330{
1331 struct rr_private *rrpriv = netdev_priv(dev);
1332 struct rr_regs __iomem *regs = rrpriv->regs;
1333 struct pci_dev *pdev = rrpriv->pci_dev;
1334 unsigned long flags;
1335 u32 tmp;
1336 short i;
1337
1338 netif_stop_queue(dev);
1339
1340
1341 /*
1342 * Lock to make sure we are not cleaning up while another CPU
1343 * is handling interrupts.
1344 */
1345 spin_lock_irqsave(&rrpriv->lock, flags);
1346
1347 tmp = readl(®s->HostCtrl);
1348 if (tmp & NIC_HALTED){
1349 printk("%s: NIC already halted\n", dev->name);
1350 rr_dump(dev);
1351 }else{
1352 tmp |= HALT_NIC | RR_CLEAR_INT;
1353 writel(tmp, ®s->HostCtrl);
1354 readl(®s->HostCtrl);
1355 }
1356
1357 rrpriv->fw_running = 0;
1358
1359 del_timer_sync(&rrpriv->timer);
1360
1361 writel(0, ®s->TxPi);
1362 writel(0, ®s->IpRxPi);
1363
1364 writel(0, ®s->EvtCon);
1365 writel(0, ®s->EvtPrd);
1366
1367 for (i = 0; i < CMD_RING_ENTRIES; i++)
1368 writel(0, ®s->CmdRing[i]);
1369
1370 rrpriv->info->tx_ctrl.entries = 0;
1371 rrpriv->info->cmd_ctrl.pi = 0;
1372 rrpriv->info->evt_ctrl.pi = 0;
1373 rrpriv->rx_ctrl[4].entries = 0;
1374
1375 rr_raz_tx(rrpriv, dev);
1376 rr_raz_rx(rrpriv, dev);
1377
1378 pci_free_consistent(pdev, 256 * sizeof(struct ring_ctrl),
1379 rrpriv->rx_ctrl, rrpriv->rx_ctrl_dma);
1380 rrpriv->rx_ctrl = NULL;
1381
1382 pci_free_consistent(pdev, sizeof(struct rr_info), rrpriv->info,
1383 rrpriv->info_dma);
1384 rrpriv->info = NULL;
1385
1386 free_irq(pdev->irq, dev);
1387 spin_unlock_irqrestore(&rrpriv->lock, flags);
1388
1389 return 0;
1390}
1391
1392
1393static netdev_tx_t rr_start_xmit(struct sk_buff *skb,
1394 struct net_device *dev)
1395{
1396 struct rr_private *rrpriv = netdev_priv(dev);
1397 struct rr_regs __iomem *regs = rrpriv->regs;
1398 struct hippi_cb *hcb = (struct hippi_cb *) skb->cb;
1399 struct ring_ctrl *txctrl;
1400 unsigned long flags;
1401 u32 index, len = skb->len;
1402 u32 *ifield;
1403 struct sk_buff *new_skb;
1404
1405 if (readl(®s->Mode) & FATAL_ERR)
1406 printk("error codes Fail1 %02x, Fail2 %02x\n",
1407 readl(®s->Fail1), readl(®s->Fail2));
1408
1409 /*
1410 * We probably need to deal with tbusy here to prevent overruns.
1411 */
1412
1413 if (skb_headroom(skb) < 8){
1414 printk("incoming skb too small - reallocating\n");
1415 if (!(new_skb = dev_alloc_skb(len + 8))) {
1416 dev_kfree_skb(skb);
1417 netif_wake_queue(dev);
1418 return NETDEV_TX_OK;
1419 }
1420 skb_reserve(new_skb, 8);
1421 skb_put(new_skb, len);
1422 skb_copy_from_linear_data(skb, new_skb->data, len);
1423 dev_kfree_skb(skb);
1424 skb = new_skb;
1425 }
1426
1427 ifield = (u32 *)skb_push(skb, 8);
1428
1429 ifield[0] = 0;
1430 ifield[1] = hcb->ifield;
1431
1432 /*
1433 * We don't need the lock before we are actually going to start
1434 * fiddling with the control blocks.
1435 */
1436 spin_lock_irqsave(&rrpriv->lock, flags);
1437
1438 txctrl = &rrpriv->info->tx_ctrl;
1439
1440 index = txctrl->pi;
1441
1442 rrpriv->tx_skbuff[index] = skb;
1443 set_rraddr(&rrpriv->tx_ring[index].addr, pci_map_single(
1444 rrpriv->pci_dev, skb->data, len + 8, PCI_DMA_TODEVICE));
1445 rrpriv->tx_ring[index].size = len + 8; /* include IFIELD */
1446 rrpriv->tx_ring[index].mode = PACKET_START | PACKET_END;
1447 txctrl->pi = (index + 1) % TX_RING_ENTRIES;
1448 wmb();
1449 writel(txctrl->pi, ®s->TxPi);
1450
1451 if (txctrl->pi == rrpriv->dirty_tx){
1452 rrpriv->tx_full = 1;
1453 netif_stop_queue(dev);
1454 }
1455
1456 spin_unlock_irqrestore(&rrpriv->lock, flags);
1457
1458 return NETDEV_TX_OK;
1459}
1460
1461
1462/*
1463 * Read the firmware out of the EEPROM and put it into the SRAM
1464 * (or from user space - later)
1465 *
1466 * This operation requires the NIC to be halted and is performed with
1467 * interrupts disabled and with the spinlock hold.
1468 */
1469static int rr_load_firmware(struct net_device *dev)
1470{
1471 struct rr_private *rrpriv;
1472 struct rr_regs __iomem *regs;
1473 size_t eptr, segptr;
1474 int i, j;
1475 u32 localctrl, sptr, len, tmp;
1476 u32 p2len, p2size, nr_seg, revision, io, sram_size;
1477
1478 rrpriv = netdev_priv(dev);
1479 regs = rrpriv->regs;
1480
1481 if (dev->flags & IFF_UP)
1482 return -EBUSY;
1483
1484 if (!(readl(®s->HostCtrl) & NIC_HALTED)){
1485 printk("%s: Trying to load firmware to a running NIC.\n",
1486 dev->name);
1487 return -EBUSY;
1488 }
1489
1490 localctrl = readl(®s->LocalCtrl);
1491 writel(0, ®s->LocalCtrl);
1492
1493 writel(0, ®s->EvtPrd);
1494 writel(0, ®s->RxPrd);
1495 writel(0, ®s->TxPrd);
1496
1497 /*
1498 * First wipe the entire SRAM, otherwise we might run into all
1499 * kinds of trouble ... sigh, this took almost all afternoon
1500 * to track down ;-(
1501 */
1502 io = readl(®s->ExtIo);
1503 writel(0, ®s->ExtIo);
1504 sram_size = rr_read_eeprom_word(rrpriv, 8);
1505
1506 for (i = 200; i < sram_size / 4; i++){
1507 writel(i * 4, ®s->WinBase);
1508 mb();
1509 writel(0, ®s->WinData);
1510 mb();
1511 }
1512 writel(io, ®s->ExtIo);
1513 mb();
1514
1515 eptr = rr_read_eeprom_word(rrpriv,
1516 offsetof(struct eeprom, rncd_info.AddrRunCodeSegs));
1517 eptr = ((eptr & 0x1fffff) >> 3);
1518
1519 p2len = rr_read_eeprom_word(rrpriv, 0x83*4);
1520 p2len = (p2len << 2);
1521 p2size = rr_read_eeprom_word(rrpriv, 0x84*4);
1522 p2size = ((p2size & 0x1fffff) >> 3);
1523
1524 if ((eptr < p2size) || (eptr > (p2size + p2len))){
1525 printk("%s: eptr is invalid\n", dev->name);
1526 goto out;
1527 }
1528
1529 revision = rr_read_eeprom_word(rrpriv,
1530 offsetof(struct eeprom, manf.HeaderFmt));
1531
1532 if (revision != 1){
1533 printk("%s: invalid firmware format (%i)\n",
1534 dev->name, revision);
1535 goto out;
1536 }
1537
1538 nr_seg = rr_read_eeprom_word(rrpriv, eptr);
1539 eptr +=4;
1540#if (DEBUG > 1)
1541 printk("%s: nr_seg %i\n", dev->name, nr_seg);
1542#endif
1543
1544 for (i = 0; i < nr_seg; i++){
1545 sptr = rr_read_eeprom_word(rrpriv, eptr);
1546 eptr += 4;
1547 len = rr_read_eeprom_word(rrpriv, eptr);
1548 eptr += 4;
1549 segptr = rr_read_eeprom_word(rrpriv, eptr);
1550 segptr = ((segptr & 0x1fffff) >> 3);
1551 eptr += 4;
1552#if (DEBUG > 1)
1553 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1554 dev->name, i, sptr, len, segptr);
1555#endif
1556 for (j = 0; j < len; j++){
1557 tmp = rr_read_eeprom_word(rrpriv, segptr);
1558 writel(sptr, ®s->WinBase);
1559 mb();
1560 writel(tmp, ®s->WinData);
1561 mb();
1562 segptr += 4;
1563 sptr += 4;
1564 }
1565 }
1566
1567out:
1568 writel(localctrl, ®s->LocalCtrl);
1569 mb();
1570 return 0;
1571}
1572
1573
1574static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1575{
1576 struct rr_private *rrpriv;
1577 unsigned char *image, *oldimage;
1578 unsigned long flags;
1579 unsigned int i;
1580 int error = -EOPNOTSUPP;
1581
1582 rrpriv = netdev_priv(dev);
1583
1584 switch(cmd){
1585 case SIOCRRGFW:
1586 if (!capable(CAP_SYS_RAWIO)){
1587 return -EPERM;
1588 }
1589
1590 image = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
1591 if (!image)
1592 return -ENOMEM;
1593
1594 if (rrpriv->fw_running){
1595 printk("%s: Firmware already running\n", dev->name);
1596 error = -EPERM;
1597 goto gf_out;
1598 }
1599
1600 spin_lock_irqsave(&rrpriv->lock, flags);
1601 i = rr_read_eeprom(rrpriv, 0, image, EEPROM_BYTES);
1602 spin_unlock_irqrestore(&rrpriv->lock, flags);
1603 if (i != EEPROM_BYTES){
1604 printk(KERN_ERR "%s: Error reading EEPROM\n",
1605 dev->name);
1606 error = -EFAULT;
1607 goto gf_out;
1608 }
1609 error = copy_to_user(rq->ifr_data, image, EEPROM_BYTES);
1610 if (error)
1611 error = -EFAULT;
1612 gf_out:
1613 kfree(image);
1614 return error;
1615
1616 case SIOCRRPFW:
1617 if (!capable(CAP_SYS_RAWIO)){
1618 return -EPERM;
1619 }
1620
1621 image = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
1622 oldimage = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
1623 if (!image || !oldimage) {
1624 error = -ENOMEM;
1625 goto wf_out;
1626 }
1627
1628 error = copy_from_user(image, rq->ifr_data, EEPROM_BYTES);
1629 if (error) {
1630 error = -EFAULT;
1631 goto wf_out;
1632 }
1633
1634 if (rrpriv->fw_running){
1635 printk("%s: Firmware already running\n", dev->name);
1636 error = -EPERM;
1637 goto wf_out;
1638 }
1639
1640 printk("%s: Updating EEPROM firmware\n", dev->name);
1641
1642 spin_lock_irqsave(&rrpriv->lock, flags);
1643 error = write_eeprom(rrpriv, 0, image, EEPROM_BYTES);
1644 if (error)
1645 printk(KERN_ERR "%s: Error writing EEPROM\n",
1646 dev->name);
1647
1648 i = rr_read_eeprom(rrpriv, 0, oldimage, EEPROM_BYTES);
1649 spin_unlock_irqrestore(&rrpriv->lock, flags);
1650
1651 if (i != EEPROM_BYTES)
1652 printk(KERN_ERR "%s: Error reading back EEPROM "
1653 "image\n", dev->name);
1654
1655 error = memcmp(image, oldimage, EEPROM_BYTES);
1656 if (error){
1657 printk(KERN_ERR "%s: Error verifying EEPROM image\n",
1658 dev->name);
1659 error = -EFAULT;
1660 }
1661 wf_out:
1662 kfree(oldimage);
1663 kfree(image);
1664 return error;
1665
1666 case SIOCRRID:
1667 return put_user(0x52523032, (int __user *)rq->ifr_data);
1668 default:
1669 return error;
1670 }
1671}
1672
1673static DEFINE_PCI_DEVICE_TABLE(rr_pci_tbl) = {
1674 { PCI_VENDOR_ID_ESSENTIAL, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER,
1675 PCI_ANY_ID, PCI_ANY_ID, },
1676 { 0,}
1677};
1678MODULE_DEVICE_TABLE(pci, rr_pci_tbl);
1679
1680static struct pci_driver rr_driver = {
1681 .name = "rrunner",
1682 .id_table = rr_pci_tbl,
1683 .probe = rr_init_one,
1684 .remove = __devexit_p(rr_remove_one),
1685};
1686
1687static int __init rr_init_module(void)
1688{
1689 return pci_register_driver(&rr_driver);
1690}
1691
1692static void __exit rr_cleanup_module(void)
1693{
1694 pci_unregister_driver(&rr_driver);
1695}
1696
1697module_init(rr_init_module);
1698module_exit(rr_cleanup_module);