2 * rrunner.c: Linux driver for the Essential RoadRunner HIPPI board.
4 * Copyright (C) 1998-2002 by Jes Sorensen, <jes@wildopensource.com>.
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.
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.
17 * Thanks to Jayaram Bhat from ODS/Essential for fixing some of the
18 * stupid bugs in my code.
20 * Softnet support and various other patches from Val Henson of
23 * PCI DMA mapping code partly based on work by Francois Romieu.
28 #define RX_DMA_SKBUFF 1
29 #define PKT_COPY_THRESHOLD 512
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>
45 #include <asm/system.h>
46 #include <asm/cache.h>
47 #include <asm/byteorder.h>
50 #include <asm/uaccess.h>
52 #define rr_if_busy(dev) netif_queue_stopped(dev)
53 #define rr_if_running(dev) netif_running(dev)
57 #define RUN_AT(x) (jiffies + (x))
60 MODULE_AUTHOR("Jes Sorensen <jes@wildopensource.com>");
61 MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
62 MODULE_LICENSE("GPL");
64 static char version
[] __devinitdata
= "rrunner.c: v0.50 11/11/2002 Jes Sorensen (jes@wildopensource.com)\n";
67 * Implementation notes:
69 * The DMA engine only allows for DMA within physical 64KB chunks of
70 * memory. The current approach of the driver (and stack) is to use
71 * linear blocks of memory for the skbuffs. However, as the data block
72 * is always the first part of the skb and skbs are 2^n aligned so we
73 * are guarantted to get the whole block within one 64KB align 64KB
76 * On the long term, relying on being able to allocate 64KB linear
77 * chunks of memory is not feasible and the skb handling code and the
78 * stack will need to know about I/O vectors or something similar.
82 * These are checked at init time to see if they are at least 256KB
83 * and increased to 256KB if they are not. This is done to avoid ending
84 * up with socket buffers smaller than the MTU size,
86 extern __u32 sysctl_wmem_max
;
87 extern __u32 sysctl_rmem_max
;
89 static int __devinit
rr_init_one(struct pci_dev
*pdev
,
90 const struct pci_device_id
*ent
)
92 struct net_device
*dev
;
93 static int version_disp
;
95 struct rr_private
*rrpriv
;
100 dev
= alloc_hippi_dev(sizeof(struct rr_private
));
104 ret
= pci_enable_device(pdev
);
110 rrpriv
= netdev_priv(dev
);
112 SET_MODULE_OWNER(dev
);
113 SET_NETDEV_DEV(dev
, &pdev
->dev
);
115 if (pci_request_regions(pdev
, "rrunner")) {
120 pci_set_drvdata(pdev
, dev
);
122 rrpriv
->pci_dev
= pdev
;
124 spin_lock_init(&rrpriv
->lock
);
126 dev
->irq
= pdev
->irq
;
127 dev
->open
= &rr_open
;
128 dev
->hard_start_xmit
= &rr_start_xmit
;
129 dev
->stop
= &rr_close
;
130 dev
->get_stats
= &rr_get_stats
;
131 dev
->do_ioctl
= &rr_ioctl
;
133 dev
->base_addr
= pci_resource_start(pdev
, 0);
135 /* display version info if adapter is found */
137 /* set display flag to TRUE so that */
138 /* we only display this string ONCE */
143 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &pci_latency
);
144 if (pci_latency
<= 0x58){
146 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, pci_latency
);
149 pci_set_master(pdev
);
151 printk(KERN_INFO
"%s: Essential RoadRunner serial HIPPI "
152 "at 0x%08lx, irq %i, PCI latency %i\n", dev
->name
,
153 dev
->base_addr
, dev
->irq
, pci_latency
);
156 * Remap the regs into kernel space.
159 rrpriv
->regs
= ioremap(dev
->base_addr
, 0x1000);
162 printk(KERN_ERR
"%s: Unable to map I/O register, "
163 "RoadRunner will be disabled.\n", dev
->name
);
168 tmpptr
= pci_alloc_consistent(pdev
, TX_TOTAL_SIZE
, &ring_dma
);
169 rrpriv
->tx_ring
= tmpptr
;
170 rrpriv
->tx_ring_dma
= ring_dma
;
177 tmpptr
= pci_alloc_consistent(pdev
, RX_TOTAL_SIZE
, &ring_dma
);
178 rrpriv
->rx_ring
= tmpptr
;
179 rrpriv
->rx_ring_dma
= ring_dma
;
186 tmpptr
= pci_alloc_consistent(pdev
, EVT_RING_SIZE
, &ring_dma
);
187 rrpriv
->evt_ring
= tmpptr
;
188 rrpriv
->evt_ring_dma
= ring_dma
;
196 * Don't access any register before this point!
199 writel(readl(&rrpriv
->regs
->HostCtrl
) | NO_SWAP
,
200 &rrpriv
->regs
->HostCtrl
);
203 * Need to add a case for little-endian 64-bit hosts here.
210 ret
= register_netdev(dev
);
217 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rrpriv
->rx_ring
,
218 rrpriv
->rx_ring_dma
);
220 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rrpriv
->tx_ring
,
221 rrpriv
->tx_ring_dma
);
223 iounmap(rrpriv
->regs
);
225 pci_release_regions(pdev
);
226 pci_set_drvdata(pdev
, NULL
);
234 static void __devexit
rr_remove_one (struct pci_dev
*pdev
)
236 struct net_device
*dev
= pci_get_drvdata(pdev
);
239 struct rr_private
*rr
= netdev_priv(dev
);
241 if (!(readl(&rr
->regs
->HostCtrl
) & NIC_HALTED
)){
242 printk(KERN_ERR
"%s: trying to unload running NIC\n",
244 writel(HALT_NIC
, &rr
->regs
->HostCtrl
);
247 pci_free_consistent(pdev
, EVT_RING_SIZE
, rr
->evt_ring
,
249 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rr
->rx_ring
,
251 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rr
->tx_ring
,
253 unregister_netdev(dev
);
256 pci_release_regions(pdev
);
257 pci_disable_device(pdev
);
258 pci_set_drvdata(pdev
, NULL
);
264 * Commands are considered to be slow, thus there is no reason to
267 static void rr_issue_cmd(struct rr_private
*rrpriv
, struct cmd
*cmd
)
269 struct rr_regs __iomem
*regs
;
274 * This is temporary - it will go away in the final version.
275 * We probably also want to make this function inline.
277 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
278 printk("issuing command for halted NIC, code 0x%x, "
279 "HostCtrl %08x\n", cmd
->code
, readl(®s
->HostCtrl
));
280 if (readl(®s
->Mode
) & FATAL_ERR
)
281 printk("error codes Fail1 %02x, Fail2 %02x\n",
282 readl(®s
->Fail1
), readl(®s
->Fail2
));
285 idx
= rrpriv
->info
->cmd_ctrl
.pi
;
287 writel(*(u32
*)(cmd
), ®s
->CmdRing
[idx
]);
290 idx
= (idx
- 1) % CMD_RING_ENTRIES
;
291 rrpriv
->info
->cmd_ctrl
.pi
= idx
;
294 if (readl(®s
->Mode
) & FATAL_ERR
)
295 printk("error code %02x\n", readl(®s
->Fail1
));
300 * Reset the board in a sensible manner. The NIC is already halted
301 * when we get here and a spin-lock is held.
303 static int rr_reset(struct net_device
*dev
)
305 struct rr_private
*rrpriv
;
306 struct rr_regs __iomem
*regs
;
307 struct eeprom
*hw
= NULL
;
311 rrpriv
= netdev_priv(dev
);
314 rr_load_firmware(dev
);
316 writel(0x01000000, ®s
->TX_state
);
317 writel(0xff800000, ®s
->RX_state
);
318 writel(0, ®s
->AssistState
);
319 writel(CLEAR_INTA
, ®s
->LocalCtrl
);
320 writel(0x01, ®s
->BrkPt
);
321 writel(0, ®s
->Timer
);
322 writel(0, ®s
->TimerRef
);
323 writel(RESET_DMA
, ®s
->DmaReadState
);
324 writel(RESET_DMA
, ®s
->DmaWriteState
);
325 writel(0, ®s
->DmaWriteHostHi
);
326 writel(0, ®s
->DmaWriteHostLo
);
327 writel(0, ®s
->DmaReadHostHi
);
328 writel(0, ®s
->DmaReadHostLo
);
329 writel(0, ®s
->DmaReadLen
);
330 writel(0, ®s
->DmaWriteLen
);
331 writel(0, ®s
->DmaWriteLcl
);
332 writel(0, ®s
->DmaWriteIPchecksum
);
333 writel(0, ®s
->DmaReadLcl
);
334 writel(0, ®s
->DmaReadIPchecksum
);
335 writel(0, ®s
->PciState
);
336 #if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
337 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_SWAP
, ®s
->Mode
);
338 #elif (BITS_PER_LONG == 64)
339 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
341 writel(SWAP_DATA
| PTR32BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
346 * Don't worry, this is just black magic.
348 writel(0xdf000, ®s
->RxBase
);
349 writel(0xdf000, ®s
->RxPrd
);
350 writel(0xdf000, ®s
->RxCon
);
351 writel(0xce000, ®s
->TxBase
);
352 writel(0xce000, ®s
->TxPrd
);
353 writel(0xce000, ®s
->TxCon
);
354 writel(0, ®s
->RxIndPro
);
355 writel(0, ®s
->RxIndCon
);
356 writel(0, ®s
->RxIndRef
);
357 writel(0, ®s
->TxIndPro
);
358 writel(0, ®s
->TxIndCon
);
359 writel(0, ®s
->TxIndRef
);
360 writel(0xcc000, ®s
->pad10
[0]);
361 writel(0, ®s
->DrCmndPro
);
362 writel(0, ®s
->DrCmndCon
);
363 writel(0, ®s
->DwCmndPro
);
364 writel(0, ®s
->DwCmndCon
);
365 writel(0, ®s
->DwCmndRef
);
366 writel(0, ®s
->DrDataPro
);
367 writel(0, ®s
->DrDataCon
);
368 writel(0, ®s
->DrDataRef
);
369 writel(0, ®s
->DwDataPro
);
370 writel(0, ®s
->DwDataCon
);
371 writel(0, ®s
->DwDataRef
);
374 writel(0xffffffff, ®s
->MbEvent
);
375 writel(0, ®s
->Event
);
377 writel(0, ®s
->TxPi
);
378 writel(0, ®s
->IpRxPi
);
380 writel(0, ®s
->EvtCon
);
381 writel(0, ®s
->EvtPrd
);
383 rrpriv
->info
->evt_ctrl
.pi
= 0;
385 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
386 writel(0, ®s
->CmdRing
[i
]);
389 * Why 32 ? is this not cache line size dependent?
391 writel(RBURST_64
|WBURST_64
, ®s
->PciState
);
394 start_pc
= rr_read_eeprom_word(rrpriv
, &hw
->rncd_info
.FwStart
);
397 printk("%s: Executing firmware at address 0x%06x\n",
398 dev
->name
, start_pc
);
401 writel(start_pc
+ 0x800, ®s
->Pc
);
405 writel(start_pc
, ®s
->Pc
);
413 * Read a string from the EEPROM.
415 static unsigned int rr_read_eeprom(struct rr_private
*rrpriv
,
416 unsigned long offset
,
418 unsigned long length
)
420 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
421 u32 misc
, io
, host
, i
;
423 io
= readl(®s
->ExtIo
);
424 writel(0, ®s
->ExtIo
);
425 misc
= readl(®s
->LocalCtrl
);
426 writel(0, ®s
->LocalCtrl
);
427 host
= readl(®s
->HostCtrl
);
428 writel(host
| HALT_NIC
, ®s
->HostCtrl
);
431 for (i
= 0; i
< length
; i
++){
432 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
434 buf
[i
] = (readl(®s
->WinData
) >> 24) & 0xff;
438 writel(host
, ®s
->HostCtrl
);
439 writel(misc
, ®s
->LocalCtrl
);
440 writel(io
, ®s
->ExtIo
);
447 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
448 * it to our CPU byte-order.
450 static u32
rr_read_eeprom_word(struct rr_private
*rrpriv
,
455 if ((rr_read_eeprom(rrpriv
, (unsigned long)offset
,
456 (char *)&word
, 4) == 4))
457 return be32_to_cpu(word
);
463 * Write a string to the EEPROM.
465 * This is only called when the firmware is not running.
467 static unsigned int write_eeprom(struct rr_private
*rrpriv
,
468 unsigned long offset
,
470 unsigned long length
)
472 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
473 u32 misc
, io
, data
, i
, j
, ready
, error
= 0;
475 io
= readl(®s
->ExtIo
);
476 writel(0, ®s
->ExtIo
);
477 misc
= readl(®s
->LocalCtrl
);
478 writel(ENABLE_EEPROM_WRITE
, ®s
->LocalCtrl
);
481 for (i
= 0; i
< length
; i
++){
482 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
486 * Only try to write the data if it is not the same
489 if ((readl(®s
->WinData
) & 0xff000000) != data
){
490 writel(data
, ®s
->WinData
);
496 if ((readl(®s
->WinData
) & 0xff000000) ==
501 printk("data mismatch: %08x, "
502 "WinData %08x\n", data
,
503 readl(®s
->WinData
));
511 writel(misc
, ®s
->LocalCtrl
);
512 writel(io
, ®s
->ExtIo
);
519 static int __devinit
rr_init(struct net_device
*dev
)
521 struct rr_private
*rrpriv
;
522 struct rr_regs __iomem
*regs
;
523 struct eeprom
*hw
= NULL
;
527 rrpriv
= netdev_priv(dev
);
530 rev
= readl(®s
->FwRev
);
531 rrpriv
->fw_rev
= rev
;
532 if (rev
> 0x00020024)
533 printk(" Firmware revision: %i.%i.%i\n", (rev
>> 16),
534 ((rev
>> 8) & 0xff), (rev
& 0xff));
535 else if (rev
>= 0x00020000) {
536 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
537 "later is recommended)\n", (rev
>> 16),
538 ((rev
>> 8) & 0xff), (rev
& 0xff));
540 printk(" Firmware revision too old: %i.%i.%i, please "
541 "upgrade to 2.0.37 or later.\n",
542 (rev
>> 16), ((rev
>> 8) & 0xff), (rev
& 0xff));
546 printk(" Maximum receive rings %i\n", readl(®s
->MaxRxRng
));
550 * Read the hardware address from the eeprom. The HW address
551 * is not really necessary for HIPPI but awfully convenient.
552 * The pointer arithmetic to put it in dev_addr is ugly, but
553 * Donald Becker does it this way for the GigE version of this
554 * card and it's shorter and more portable than any
555 * other method I've seen. -VAL
558 *(u16
*)(dev
->dev_addr
) =
559 htons(rr_read_eeprom_word(rrpriv
, &hw
->manf
.BoardULA
));
560 *(u32
*)(dev
->dev_addr
+2) =
561 htonl(rr_read_eeprom_word(rrpriv
, &hw
->manf
.BoardULA
[4]));
565 for (i
= 0; i
< 5; i
++)
566 printk("%2.2x:", dev
->dev_addr
[i
]);
567 printk("%2.2x\n", dev
->dev_addr
[i
]);
569 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
570 printk(" SRAM size 0x%06x\n", sram_size
);
572 if (sysctl_rmem_max
< 262144){
573 printk(" Receive socket buffer limit too low (%i), "
574 "setting to 262144\n", sysctl_rmem_max
);
575 sysctl_rmem_max
= 262144;
578 if (sysctl_wmem_max
< 262144){
579 printk(" Transmit socket buffer limit too low (%i), "
580 "setting to 262144\n", sysctl_wmem_max
);
581 sysctl_wmem_max
= 262144;
588 static int rr_init1(struct net_device
*dev
)
590 struct rr_private
*rrpriv
;
591 struct rr_regs __iomem
*regs
;
592 unsigned long myjif
, flags
;
598 rrpriv
= netdev_priv(dev
);
601 spin_lock_irqsave(&rrpriv
->lock
, flags
);
603 hostctrl
= readl(®s
->HostCtrl
);
604 writel(hostctrl
| HALT_NIC
| RR_CLEAR_INT
, ®s
->HostCtrl
);
607 if (hostctrl
& PARITY_ERR
){
608 printk("%s: Parity error halting NIC - this is serious!\n",
610 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
615 set_rxaddr(regs
, rrpriv
->rx_ctrl_dma
);
616 set_infoaddr(regs
, rrpriv
->info_dma
);
618 rrpriv
->info
->evt_ctrl
.entry_size
= sizeof(struct event
);
619 rrpriv
->info
->evt_ctrl
.entries
= EVT_RING_ENTRIES
;
620 rrpriv
->info
->evt_ctrl
.mode
= 0;
621 rrpriv
->info
->evt_ctrl
.pi
= 0;
622 set_rraddr(&rrpriv
->info
->evt_ctrl
.rngptr
, rrpriv
->evt_ring_dma
);
624 rrpriv
->info
->cmd_ctrl
.entry_size
= sizeof(struct cmd
);
625 rrpriv
->info
->cmd_ctrl
.entries
= CMD_RING_ENTRIES
;
626 rrpriv
->info
->cmd_ctrl
.mode
= 0;
627 rrpriv
->info
->cmd_ctrl
.pi
= 15;
629 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++) {
630 writel(0, ®s
->CmdRing
[i
]);
633 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
634 rrpriv
->tx_ring
[i
].size
= 0;
635 set_rraddr(&rrpriv
->tx_ring
[i
].addr
, 0);
636 rrpriv
->tx_skbuff
[i
] = NULL
;
638 rrpriv
->info
->tx_ctrl
.entry_size
= sizeof(struct tx_desc
);
639 rrpriv
->info
->tx_ctrl
.entries
= TX_RING_ENTRIES
;
640 rrpriv
->info
->tx_ctrl
.mode
= 0;
641 rrpriv
->info
->tx_ctrl
.pi
= 0;
642 set_rraddr(&rrpriv
->info
->tx_ctrl
.rngptr
, rrpriv
->tx_ring_dma
);
645 * Set dirty_tx before we start receiving interrupts, otherwise
646 * the interrupt handler might think it is supposed to process
647 * tx ints before we are up and running, which may cause a null
648 * pointer access in the int handler.
652 rrpriv
->dirty_rx
= rrpriv
->dirty_tx
= 0;
657 writel(0x5000, ®s
->ConRetry
);
658 writel(0x100, ®s
->ConRetryTmr
);
659 writel(0x500000, ®s
->ConTmout
);
660 writel(0x60, ®s
->IntrTmr
);
661 writel(0x500000, ®s
->TxDataMvTimeout
);
662 writel(0x200000, ®s
->RxDataMvTimeout
);
663 writel(0x80, ®s
->WriteDmaThresh
);
664 writel(0x80, ®s
->ReadDmaThresh
);
666 rrpriv
->fw_running
= 0;
669 hostctrl
&= ~(HALT_NIC
| INVALID_INST_B
| PARITY_ERR
);
670 writel(hostctrl
, ®s
->HostCtrl
);
673 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
675 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
679 rrpriv
->rx_ring
[i
].mode
= 0;
680 skb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
, GFP_ATOMIC
);
682 printk(KERN_WARNING
"%s: Unable to allocate memory "
683 "for receive ring - halting NIC\n", dev
->name
);
687 rrpriv
->rx_skbuff
[i
] = skb
;
688 addr
= pci_map_single(rrpriv
->pci_dev
, skb
->data
,
689 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
691 * Sanity test to see if we conflict with the DMA
692 * limitations of the Roadrunner.
694 if ((((unsigned long)skb
->data
) & 0xfff) > ~65320)
695 printk("skb alloc error\n");
697 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, addr
);
698 rrpriv
->rx_ring
[i
].size
= dev
->mtu
+ HIPPI_HLEN
;
701 rrpriv
->rx_ctrl
[4].entry_size
= sizeof(struct rx_desc
);
702 rrpriv
->rx_ctrl
[4].entries
= RX_RING_ENTRIES
;
703 rrpriv
->rx_ctrl
[4].mode
= 8;
704 rrpriv
->rx_ctrl
[4].pi
= 0;
706 set_rraddr(&rrpriv
->rx_ctrl
[4].rngptr
, rrpriv
->rx_ring_dma
);
711 * Now start the FirmWare.
713 cmd
.code
= C_START_FW
;
717 rr_issue_cmd(rrpriv
, &cmd
);
720 * Give the FirmWare time to chew on the `get running' command.
722 myjif
= jiffies
+ 5 * HZ
;
723 while (time_before(jiffies
, myjif
) && !rrpriv
->fw_running
)
726 netif_start_queue(dev
);
732 * We might have gotten here because we are out of memory,
733 * make sure we release everything we allocated before failing
735 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
736 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
739 pci_unmap_single(rrpriv
->pci_dev
,
740 rrpriv
->rx_ring
[i
].addr
.addrlo
,
741 dev
->mtu
+ HIPPI_HLEN
,
743 rrpriv
->rx_ring
[i
].size
= 0;
744 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, 0);
746 rrpriv
->rx_skbuff
[i
] = NULL
;
754 * All events are considered to be slow (RX/TX ints do not generate
755 * events) and are handled here, outside the main interrupt handler,
756 * to reduce the size of the handler.
758 static u32
rr_handle_event(struct net_device
*dev
, u32 prodidx
, u32 eidx
)
760 struct rr_private
*rrpriv
;
761 struct rr_regs __iomem
*regs
;
764 rrpriv
= netdev_priv(dev
);
767 while (prodidx
!= eidx
){
768 switch (rrpriv
->evt_ring
[eidx
].code
){
770 tmp
= readl(®s
->FwRev
);
771 printk(KERN_INFO
"%s: Firmware revision %i.%i.%i "
772 "up and running\n", dev
->name
,
773 (tmp
>> 16), ((tmp
>> 8) & 0xff), (tmp
& 0xff));
774 rrpriv
->fw_running
= 1;
775 writel(RX_RING_ENTRIES
- 1, ®s
->IpRxPi
);
779 printk(KERN_INFO
"%s: Optical link ON\n", dev
->name
);
782 printk(KERN_INFO
"%s: Optical link OFF\n", dev
->name
);
785 printk(KERN_WARNING
"%s: RX data not moving\n",
789 printk(KERN_INFO
"%s: The watchdog is here to see "
793 printk(KERN_ERR
"%s: HIPPI Internal NIC error\n",
795 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
800 printk(KERN_ERR
"%s: Host software error\n",
802 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
810 printk(KERN_WARNING
"%s: Connection rejected\n",
812 rrpriv
->stats
.tx_aborted_errors
++;
815 printk(KERN_WARNING
"%s: Connection timeout\n",
819 printk(KERN_WARNING
"%s: HIPPI disconnect error\n",
821 rrpriv
->stats
.tx_aborted_errors
++;
824 printk(KERN_ERR
"%s: HIPPI Internal Parity error\n",
826 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
831 printk(KERN_WARNING
"%s: Transmitter idle\n",
835 printk(KERN_WARNING
"%s: Link lost during transmit\n",
837 rrpriv
->stats
.tx_aborted_errors
++;
838 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
843 printk(KERN_ERR
"%s: Invalid send ring block\n",
845 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
850 printk(KERN_ERR
"%s: Invalid send buffer address\n",
852 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
857 printk(KERN_ERR
"%s: Invalid descriptor address\n",
859 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
867 printk(KERN_INFO
"%s: Receive ring full\n", dev
->name
);
871 printk(KERN_WARNING
"%s: Receive parity error\n",
875 printk(KERN_WARNING
"%s: Receive LLRC error\n",
879 printk(KERN_WARNING
"%s: Receive packet length "
880 "error\n", dev
->name
);
883 printk(KERN_WARNING
"%s: Data checksum error\n",
887 printk(KERN_WARNING
"%s: Unexpected short burst "
888 "error\n", dev
->name
);
891 printk(KERN_WARNING
"%s: Recv. state transition"
892 " error\n", dev
->name
);
895 printk(KERN_WARNING
"%s: Unexpected data error\n",
899 printk(KERN_WARNING
"%s: Link lost error\n",
903 printk(KERN_WARNING
"%s: Framming Error\n",
907 printk(KERN_WARNING
"%s: Flag sync. lost during"
908 "packet\n", dev
->name
);
911 printk(KERN_ERR
"%s: Invalid receive buffer "
912 "address\n", dev
->name
);
913 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
918 printk(KERN_ERR
"%s: Invalid receive descriptor "
919 "address\n", dev
->name
);
920 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
925 printk(KERN_ERR
"%s: Invalid ring block\n",
927 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
932 /* Label packet to be dropped.
933 * Actual dropping occurs in rx
936 * The index of packet we get to drop is
937 * the index of the packet following
938 * the bad packet. -kbf
941 u16 index
= rrpriv
->evt_ring
[eidx
].index
;
942 index
= (index
+ (RX_RING_ENTRIES
- 1)) %
944 rrpriv
->rx_ring
[index
].mode
|=
945 (PACKET_BAD
| PACKET_END
);
949 printk(KERN_WARNING
"%s: Unhandled event 0x%02x\n",
950 dev
->name
, rrpriv
->evt_ring
[eidx
].code
);
952 eidx
= (eidx
+ 1) % EVT_RING_ENTRIES
;
955 rrpriv
->info
->evt_ctrl
.pi
= eidx
;
961 static void rx_int(struct net_device
*dev
, u32 rxlimit
, u32 index
)
963 struct rr_private
*rrpriv
= netdev_priv(dev
);
964 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
967 struct rx_desc
*desc
;
970 desc
= &(rrpriv
->rx_ring
[index
]);
971 pkt_len
= desc
->size
;
973 printk("index %i, rxlimit %i\n", index
, rxlimit
);
974 printk("len %x, mode %x\n", pkt_len
, desc
->mode
);
976 if ( (rrpriv
->rx_ring
[index
].mode
& PACKET_BAD
) == PACKET_BAD
){
977 rrpriv
->stats
.rx_dropped
++;
982 struct sk_buff
*skb
, *rx_skb
;
984 rx_skb
= rrpriv
->rx_skbuff
[index
];
986 if (pkt_len
< PKT_COPY_THRESHOLD
) {
987 skb
= alloc_skb(pkt_len
, GFP_ATOMIC
);
989 printk(KERN_WARNING
"%s: Unable to allocate skb (%i bytes), deferring packet\n", dev
->name
, pkt_len
);
990 rrpriv
->stats
.rx_dropped
++;
993 pci_dma_sync_single_for_cpu(rrpriv
->pci_dev
,
998 memcpy(skb_put(skb
, pkt_len
),
999 rx_skb
->data
, pkt_len
);
1001 pci_dma_sync_single_for_device(rrpriv
->pci_dev
,
1004 PCI_DMA_FROMDEVICE
);
1007 struct sk_buff
*newskb
;
1009 newskb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
,
1014 pci_unmap_single(rrpriv
->pci_dev
,
1015 desc
->addr
.addrlo
, dev
->mtu
+
1016 HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
1018 skb_put(skb
, pkt_len
);
1019 rrpriv
->rx_skbuff
[index
] = newskb
;
1020 addr
= pci_map_single(rrpriv
->pci_dev
,
1022 dev
->mtu
+ HIPPI_HLEN
,
1023 PCI_DMA_FROMDEVICE
);
1024 set_rraddr(&desc
->addr
, addr
);
1026 printk("%s: Out of memory, deferring "
1027 "packet\n", dev
->name
);
1028 rrpriv
->stats
.rx_dropped
++;
1032 skb
->protocol
= hippi_type_trans(skb
, dev
);
1034 netif_rx(skb
); /* send it up */
1036 dev
->last_rx
= jiffies
;
1037 rrpriv
->stats
.rx_packets
++;
1038 rrpriv
->stats
.rx_bytes
+= pkt_len
;
1042 desc
->size
= dev
->mtu
+ HIPPI_HLEN
;
1044 if ((index
& 7) == 7)
1045 writel(index
, ®s
->IpRxPi
);
1047 index
= (index
+ 1) % RX_RING_ENTRIES
;
1048 } while(index
!= rxlimit
);
1050 rrpriv
->cur_rx
= index
;
1055 static irqreturn_t
rr_interrupt(int irq
, void *dev_id
)
1057 struct rr_private
*rrpriv
;
1058 struct rr_regs __iomem
*regs
;
1059 struct net_device
*dev
= (struct net_device
*)dev_id
;
1060 u32 prodidx
, rxindex
, eidx
, txcsmr
, rxlimit
, txcon
;
1062 rrpriv
= netdev_priv(dev
);
1063 regs
= rrpriv
->regs
;
1065 if (!(readl(®s
->HostCtrl
) & RR_INT
))
1068 spin_lock(&rrpriv
->lock
);
1070 prodidx
= readl(®s
->EvtPrd
);
1071 txcsmr
= (prodidx
>> 8) & 0xff;
1072 rxlimit
= (prodidx
>> 16) & 0xff;
1076 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev
->name
,
1077 prodidx
, rrpriv
->info
->evt_ctrl
.pi
);
1080 * Order here is important. We must handle events
1081 * before doing anything else in order to catch
1082 * such things as LLRC errors, etc -kbf
1085 eidx
= rrpriv
->info
->evt_ctrl
.pi
;
1086 if (prodidx
!= eidx
)
1087 eidx
= rr_handle_event(dev
, prodidx
, eidx
);
1089 rxindex
= rrpriv
->cur_rx
;
1090 if (rxindex
!= rxlimit
)
1091 rx_int(dev
, rxlimit
, rxindex
);
1093 txcon
= rrpriv
->dirty_tx
;
1094 if (txcsmr
!= txcon
) {
1096 /* Due to occational firmware TX producer/consumer out
1097 * of sync. error need to check entry in ring -kbf
1099 if(rrpriv
->tx_skbuff
[txcon
]){
1100 struct tx_desc
*desc
;
1101 struct sk_buff
*skb
;
1103 desc
= &(rrpriv
->tx_ring
[txcon
]);
1104 skb
= rrpriv
->tx_skbuff
[txcon
];
1106 rrpriv
->stats
.tx_packets
++;
1107 rrpriv
->stats
.tx_bytes
+= skb
->len
;
1109 pci_unmap_single(rrpriv
->pci_dev
,
1110 desc
->addr
.addrlo
, skb
->len
,
1112 dev_kfree_skb_irq(skb
);
1114 rrpriv
->tx_skbuff
[txcon
] = NULL
;
1116 set_rraddr(&rrpriv
->tx_ring
[txcon
].addr
, 0);
1119 txcon
= (txcon
+ 1) % TX_RING_ENTRIES
;
1120 } while (txcsmr
!= txcon
);
1123 rrpriv
->dirty_tx
= txcon
;
1124 if (rrpriv
->tx_full
&& rr_if_busy(dev
) &&
1125 (((rrpriv
->info
->tx_ctrl
.pi
+ 1) % TX_RING_ENTRIES
)
1126 != rrpriv
->dirty_tx
)){
1127 rrpriv
->tx_full
= 0;
1128 netif_wake_queue(dev
);
1132 eidx
|= ((txcsmr
<< 8) | (rxlimit
<< 16));
1133 writel(eidx
, ®s
->EvtCon
);
1136 spin_unlock(&rrpriv
->lock
);
1140 static inline void rr_raz_tx(struct rr_private
*rrpriv
,
1141 struct net_device
*dev
)
1145 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
1146 struct sk_buff
*skb
= rrpriv
->tx_skbuff
[i
];
1149 struct tx_desc
*desc
= &(rrpriv
->tx_ring
[i
]);
1151 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1152 skb
->len
, PCI_DMA_TODEVICE
);
1154 set_rraddr(&desc
->addr
, 0);
1156 rrpriv
->tx_skbuff
[i
] = NULL
;
1162 static inline void rr_raz_rx(struct rr_private
*rrpriv
,
1163 struct net_device
*dev
)
1167 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
1168 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
1171 struct rx_desc
*desc
= &(rrpriv
->rx_ring
[i
]);
1173 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1174 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
1176 set_rraddr(&desc
->addr
, 0);
1178 rrpriv
->rx_skbuff
[i
] = NULL
;
1183 static void rr_timer(unsigned long data
)
1185 struct net_device
*dev
= (struct net_device
*)data
;
1186 struct rr_private
*rrpriv
= netdev_priv(dev
);
1187 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1188 unsigned long flags
;
1190 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
1191 printk("%s: Restarting nic\n", dev
->name
);
1192 memset(rrpriv
->rx_ctrl
, 0, 256 * sizeof(struct ring_ctrl
));
1193 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1196 rr_raz_tx(rrpriv
, dev
);
1197 rr_raz_rx(rrpriv
, dev
);
1199 if (rr_init1(dev
)) {
1200 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1201 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
1203 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1206 rrpriv
->timer
.expires
= RUN_AT(5*HZ
);
1207 add_timer(&rrpriv
->timer
);
1211 static int rr_open(struct net_device
*dev
)
1213 struct rr_private
*rrpriv
= netdev_priv(dev
);
1214 struct pci_dev
*pdev
= rrpriv
->pci_dev
;
1215 struct rr_regs __iomem
*regs
;
1217 unsigned long flags
;
1218 dma_addr_t dma_addr
;
1220 regs
= rrpriv
->regs
;
1222 if (rrpriv
->fw_rev
< 0x00020000) {
1223 printk(KERN_WARNING
"%s: trying to configure device with "
1224 "obsolete firmware\n", dev
->name
);
1229 rrpriv
->rx_ctrl
= pci_alloc_consistent(pdev
,
1230 256 * sizeof(struct ring_ctrl
),
1232 if (!rrpriv
->rx_ctrl
) {
1236 rrpriv
->rx_ctrl_dma
= dma_addr
;
1237 memset(rrpriv
->rx_ctrl
, 0, 256*sizeof(struct ring_ctrl
));
1239 rrpriv
->info
= pci_alloc_consistent(pdev
, sizeof(struct rr_info
),
1241 if (!rrpriv
->info
) {
1245 rrpriv
->info_dma
= dma_addr
;
1246 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1249 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1250 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1251 readl(®s
->HostCtrl
);
1252 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1254 if (request_irq(dev
->irq
, rr_interrupt
, IRQF_SHARED
, dev
->name
, dev
)) {
1255 printk(KERN_WARNING
"%s: Requested IRQ %d is busy\n",
1256 dev
->name
, dev
->irq
);
1261 if ((ecode
= rr_init1(dev
)))
1264 /* Set the timer to switch to check for link beat and perhaps switch
1265 to an alternate media type. */
1266 init_timer(&rrpriv
->timer
);
1267 rrpriv
->timer
.expires
= RUN_AT(5*HZ
); /* 5 sec. watchdog */
1268 rrpriv
->timer
.data
= (unsigned long)dev
;
1269 rrpriv
->timer
.function
= &rr_timer
; /* timer handler */
1270 add_timer(&rrpriv
->timer
);
1272 netif_start_queue(dev
);
1277 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1278 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1279 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1282 pci_free_consistent(pdev
, sizeof(struct rr_info
), rrpriv
->info
,
1284 rrpriv
->info
= NULL
;
1286 if (rrpriv
->rx_ctrl
) {
1287 pci_free_consistent(pdev
, sizeof(struct ring_ctrl
),
1288 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1289 rrpriv
->rx_ctrl
= NULL
;
1292 netif_stop_queue(dev
);
1298 static void rr_dump(struct net_device
*dev
)
1300 struct rr_private
*rrpriv
;
1301 struct rr_regs __iomem
*regs
;
1306 rrpriv
= netdev_priv(dev
);
1307 regs
= rrpriv
->regs
;
1309 printk("%s: dumping NIC TX rings\n", dev
->name
);
1311 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1312 readl(®s
->RxPrd
), readl(®s
->TxPrd
),
1313 readl(®s
->EvtPrd
), readl(®s
->TxPi
),
1314 rrpriv
->info
->tx_ctrl
.pi
);
1316 printk("Error code 0x%x\n", readl(®s
->Fail1
));
1318 index
= (((readl(®s
->EvtPrd
) >> 8) & 0xff ) - 1) % EVT_RING_ENTRIES
;
1319 cons
= rrpriv
->dirty_tx
;
1320 printk("TX ring index %i, TX consumer %i\n",
1323 if (rrpriv
->tx_skbuff
[index
]){
1324 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[index
]->len
);
1325 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index
, len
, rrpriv
->tx_ring
[index
].size
);
1326 for (i
= 0; i
< len
; i
++){
1329 printk("%02x ", (unsigned char) rrpriv
->tx_skbuff
[index
]->data
[i
]);
1334 if (rrpriv
->tx_skbuff
[cons
]){
1335 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[cons
]->len
);
1336 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons
, len
, rrpriv
->tx_skbuff
[cons
]->len
);
1337 printk("mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %08lx, truesize 0x%x\n",
1338 rrpriv
->tx_ring
[cons
].mode
,
1339 rrpriv
->tx_ring
[cons
].size
,
1340 (unsigned long long) rrpriv
->tx_ring
[cons
].addr
.addrlo
,
1341 (unsigned long)rrpriv
->tx_skbuff
[cons
]->data
,
1342 (unsigned int)rrpriv
->tx_skbuff
[cons
]->truesize
);
1343 for (i
= 0; i
< len
; i
++){
1346 printk("%02x ", (unsigned char)rrpriv
->tx_ring
[cons
].size
);
1351 printk("dumping TX ring info:\n");
1352 for (i
= 0; i
< TX_RING_ENTRIES
; i
++)
1353 printk("mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1354 rrpriv
->tx_ring
[i
].mode
,
1355 rrpriv
->tx_ring
[i
].size
,
1356 (unsigned long long) rrpriv
->tx_ring
[i
].addr
.addrlo
);
1361 static int rr_close(struct net_device
*dev
)
1363 struct rr_private
*rrpriv
;
1364 struct rr_regs __iomem
*regs
;
1365 unsigned long flags
;
1369 netif_stop_queue(dev
);
1371 rrpriv
= netdev_priv(dev
);
1372 regs
= rrpriv
->regs
;
1375 * Lock to make sure we are not cleaning up while another CPU
1376 * is handling interrupts.
1378 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1380 tmp
= readl(®s
->HostCtrl
);
1381 if (tmp
& NIC_HALTED
){
1382 printk("%s: NIC already halted\n", dev
->name
);
1385 tmp
|= HALT_NIC
| RR_CLEAR_INT
;
1386 writel(tmp
, ®s
->HostCtrl
);
1387 readl(®s
->HostCtrl
);
1390 rrpriv
->fw_running
= 0;
1392 del_timer_sync(&rrpriv
->timer
);
1394 writel(0, ®s
->TxPi
);
1395 writel(0, ®s
->IpRxPi
);
1397 writel(0, ®s
->EvtCon
);
1398 writel(0, ®s
->EvtPrd
);
1400 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
1401 writel(0, ®s
->CmdRing
[i
]);
1403 rrpriv
->info
->tx_ctrl
.entries
= 0;
1404 rrpriv
->info
->cmd_ctrl
.pi
= 0;
1405 rrpriv
->info
->evt_ctrl
.pi
= 0;
1406 rrpriv
->rx_ctrl
[4].entries
= 0;
1408 rr_raz_tx(rrpriv
, dev
);
1409 rr_raz_rx(rrpriv
, dev
);
1411 pci_free_consistent(rrpriv
->pci_dev
, 256 * sizeof(struct ring_ctrl
),
1412 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1413 rrpriv
->rx_ctrl
= NULL
;
1415 pci_free_consistent(rrpriv
->pci_dev
, sizeof(struct rr_info
),
1416 rrpriv
->info
, rrpriv
->info_dma
);
1417 rrpriv
->info
= NULL
;
1419 free_irq(dev
->irq
, dev
);
1420 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1426 static int rr_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1428 struct rr_private
*rrpriv
= netdev_priv(dev
);
1429 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1430 struct hippi_cb
*hcb
= (struct hippi_cb
*) skb
->cb
;
1431 struct ring_ctrl
*txctrl
;
1432 unsigned long flags
;
1433 u32 index
, len
= skb
->len
;
1435 struct sk_buff
*new_skb
;
1437 if (readl(®s
->Mode
) & FATAL_ERR
)
1438 printk("error codes Fail1 %02x, Fail2 %02x\n",
1439 readl(®s
->Fail1
), readl(®s
->Fail2
));
1442 * We probably need to deal with tbusy here to prevent overruns.
1445 if (skb_headroom(skb
) < 8){
1446 printk("incoming skb too small - reallocating\n");
1447 if (!(new_skb
= dev_alloc_skb(len
+ 8))) {
1449 netif_wake_queue(dev
);
1452 skb_reserve(new_skb
, 8);
1453 skb_put(new_skb
, len
);
1454 skb_copy_from_linear_data(skb
, new_skb
->data
, len
);
1459 ifield
= (u32
*)skb_push(skb
, 8);
1462 ifield
[1] = hcb
->ifield
;
1465 * We don't need the lock before we are actually going to start
1466 * fiddling with the control blocks.
1468 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1470 txctrl
= &rrpriv
->info
->tx_ctrl
;
1474 rrpriv
->tx_skbuff
[index
] = skb
;
1475 set_rraddr(&rrpriv
->tx_ring
[index
].addr
, pci_map_single(
1476 rrpriv
->pci_dev
, skb
->data
, len
+ 8, PCI_DMA_TODEVICE
));
1477 rrpriv
->tx_ring
[index
].size
= len
+ 8; /* include IFIELD */
1478 rrpriv
->tx_ring
[index
].mode
= PACKET_START
| PACKET_END
;
1479 txctrl
->pi
= (index
+ 1) % TX_RING_ENTRIES
;
1481 writel(txctrl
->pi
, ®s
->TxPi
);
1483 if (txctrl
->pi
== rrpriv
->dirty_tx
){
1484 rrpriv
->tx_full
= 1;
1485 netif_stop_queue(dev
);
1488 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1490 dev
->trans_start
= jiffies
;
1495 static struct net_device_stats
*rr_get_stats(struct net_device
*dev
)
1497 struct rr_private
*rrpriv
;
1499 rrpriv
= netdev_priv(dev
);
1501 return(&rrpriv
->stats
);
1506 * Read the firmware out of the EEPROM and put it into the SRAM
1507 * (or from user space - later)
1509 * This operation requires the NIC to be halted and is performed with
1510 * interrupts disabled and with the spinlock hold.
1512 static int rr_load_firmware(struct net_device
*dev
)
1514 struct rr_private
*rrpriv
;
1515 struct rr_regs __iomem
*regs
;
1516 unsigned long eptr
, segptr
;
1518 u32 localctrl
, sptr
, len
, tmp
;
1519 u32 p2len
, p2size
, nr_seg
, revision
, io
, sram_size
;
1520 struct eeprom
*hw
= NULL
;
1522 rrpriv
= netdev_priv(dev
);
1523 regs
= rrpriv
->regs
;
1525 if (dev
->flags
& IFF_UP
)
1528 if (!(readl(®s
->HostCtrl
) & NIC_HALTED
)){
1529 printk("%s: Trying to load firmware to a running NIC.\n",
1534 localctrl
= readl(®s
->LocalCtrl
);
1535 writel(0, ®s
->LocalCtrl
);
1537 writel(0, ®s
->EvtPrd
);
1538 writel(0, ®s
->RxPrd
);
1539 writel(0, ®s
->TxPrd
);
1542 * First wipe the entire SRAM, otherwise we might run into all
1543 * kinds of trouble ... sigh, this took almost all afternoon
1546 io
= readl(®s
->ExtIo
);
1547 writel(0, ®s
->ExtIo
);
1548 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
1550 for (i
= 200; i
< sram_size
/ 4; i
++){
1551 writel(i
* 4, ®s
->WinBase
);
1553 writel(0, ®s
->WinData
);
1556 writel(io
, ®s
->ExtIo
);
1559 eptr
= (unsigned long)rr_read_eeprom_word(rrpriv
,
1560 &hw
->rncd_info
.AddrRunCodeSegs
);
1561 eptr
= ((eptr
& 0x1fffff) >> 3);
1563 p2len
= rr_read_eeprom_word(rrpriv
, (void *)(0x83*4));
1564 p2len
= (p2len
<< 2);
1565 p2size
= rr_read_eeprom_word(rrpriv
, (void *)(0x84*4));
1566 p2size
= ((p2size
& 0x1fffff) >> 3);
1568 if ((eptr
< p2size
) || (eptr
> (p2size
+ p2len
))){
1569 printk("%s: eptr is invalid\n", dev
->name
);
1573 revision
= rr_read_eeprom_word(rrpriv
, &hw
->manf
.HeaderFmt
);
1576 printk("%s: invalid firmware format (%i)\n",
1577 dev
->name
, revision
);
1581 nr_seg
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1584 printk("%s: nr_seg %i\n", dev
->name
, nr_seg
);
1587 for (i
= 0; i
< nr_seg
; i
++){
1588 sptr
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1590 len
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1592 segptr
= (unsigned long)rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1593 segptr
= ((segptr
& 0x1fffff) >> 3);
1596 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1597 dev
->name
, i
, sptr
, len
, segptr
);
1599 for (j
= 0; j
< len
; j
++){
1600 tmp
= rr_read_eeprom_word(rrpriv
, (void *)segptr
);
1601 writel(sptr
, ®s
->WinBase
);
1603 writel(tmp
, ®s
->WinData
);
1611 writel(localctrl
, ®s
->LocalCtrl
);
1617 static int rr_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1619 struct rr_private
*rrpriv
;
1620 unsigned char *image
, *oldimage
;
1621 unsigned long flags
;
1623 int error
= -EOPNOTSUPP
;
1625 rrpriv
= netdev_priv(dev
);
1629 if (!capable(CAP_SYS_RAWIO
)){
1633 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1635 printk(KERN_ERR
"%s: Unable to allocate memory "
1636 "for EEPROM image\n", dev
->name
);
1641 if (rrpriv
->fw_running
){
1642 printk("%s: Firmware already running\n", dev
->name
);
1647 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1648 i
= rr_read_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1649 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1650 if (i
!= EEPROM_BYTES
){
1651 printk(KERN_ERR
"%s: Error reading EEPROM\n",
1656 error
= copy_to_user(rq
->ifr_data
, image
, EEPROM_BYTES
);
1664 if (!capable(CAP_SYS_RAWIO
)){
1668 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1669 oldimage
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1670 if (!image
|| !oldimage
) {
1671 printk(KERN_ERR
"%s: Unable to allocate memory "
1672 "for EEPROM image\n", dev
->name
);
1677 error
= copy_from_user(image
, rq
->ifr_data
, EEPROM_BYTES
);
1683 if (rrpriv
->fw_running
){
1684 printk("%s: Firmware already running\n", dev
->name
);
1689 printk("%s: Updating EEPROM firmware\n", dev
->name
);
1691 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1692 error
= write_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1694 printk(KERN_ERR
"%s: Error writing EEPROM\n",
1697 i
= rr_read_eeprom(rrpriv
, 0, oldimage
, EEPROM_BYTES
);
1698 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1700 if (i
!= EEPROM_BYTES
)
1701 printk(KERN_ERR
"%s: Error reading back EEPROM "
1702 "image\n", dev
->name
);
1704 error
= memcmp(image
, oldimage
, EEPROM_BYTES
);
1706 printk(KERN_ERR
"%s: Error verifying EEPROM image\n",
1716 return put_user(0x52523032, (int __user
*)rq
->ifr_data
);
1722 static struct pci_device_id rr_pci_tbl
[] = {
1723 { PCI_VENDOR_ID_ESSENTIAL
, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER
,
1724 PCI_ANY_ID
, PCI_ANY_ID
, },
1727 MODULE_DEVICE_TABLE(pci
, rr_pci_tbl
);
1729 static struct pci_driver rr_driver
= {
1731 .id_table
= rr_pci_tbl
,
1732 .probe
= rr_init_one
,
1733 .remove
= __devexit_p(rr_remove_one
),
1736 static int __init
rr_init_module(void)
1738 return pci_register_driver(&rr_driver
);
1741 static void __exit
rr_cleanup_module(void)
1743 pci_unregister_driver(&rr_driver
);
1746 module_init(rr_init_module
);
1747 module_exit(rr_cleanup_module
);
1751 * compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -pipe -fomit-frame-pointer -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -c rrunner.c"