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_NETDEV_DEV(dev
, &pdev
->dev
);
114 if (pci_request_regions(pdev
, "rrunner")) {
119 pci_set_drvdata(pdev
, dev
);
121 rrpriv
->pci_dev
= pdev
;
123 spin_lock_init(&rrpriv
->lock
);
125 dev
->irq
= pdev
->irq
;
126 dev
->open
= &rr_open
;
127 dev
->hard_start_xmit
= &rr_start_xmit
;
128 dev
->stop
= &rr_close
;
129 dev
->get_stats
= &rr_get_stats
;
130 dev
->do_ioctl
= &rr_ioctl
;
132 dev
->base_addr
= pci_resource_start(pdev
, 0);
134 /* display version info if adapter is found */
136 /* set display flag to TRUE so that */
137 /* we only display this string ONCE */
142 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &pci_latency
);
143 if (pci_latency
<= 0x58){
145 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, pci_latency
);
148 pci_set_master(pdev
);
150 printk(KERN_INFO
"%s: Essential RoadRunner serial HIPPI "
151 "at 0x%08lx, irq %i, PCI latency %i\n", dev
->name
,
152 dev
->base_addr
, dev
->irq
, pci_latency
);
155 * Remap the regs into kernel space.
158 rrpriv
->regs
= ioremap(dev
->base_addr
, 0x1000);
161 printk(KERN_ERR
"%s: Unable to map I/O register, "
162 "RoadRunner will be disabled.\n", dev
->name
);
167 tmpptr
= pci_alloc_consistent(pdev
, TX_TOTAL_SIZE
, &ring_dma
);
168 rrpriv
->tx_ring
= tmpptr
;
169 rrpriv
->tx_ring_dma
= ring_dma
;
176 tmpptr
= pci_alloc_consistent(pdev
, RX_TOTAL_SIZE
, &ring_dma
);
177 rrpriv
->rx_ring
= tmpptr
;
178 rrpriv
->rx_ring_dma
= ring_dma
;
185 tmpptr
= pci_alloc_consistent(pdev
, EVT_RING_SIZE
, &ring_dma
);
186 rrpriv
->evt_ring
= tmpptr
;
187 rrpriv
->evt_ring_dma
= ring_dma
;
195 * Don't access any register before this point!
198 writel(readl(&rrpriv
->regs
->HostCtrl
) | NO_SWAP
,
199 &rrpriv
->regs
->HostCtrl
);
202 * Need to add a case for little-endian 64-bit hosts here.
209 ret
= register_netdev(dev
);
216 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rrpriv
->rx_ring
,
217 rrpriv
->rx_ring_dma
);
219 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rrpriv
->tx_ring
,
220 rrpriv
->tx_ring_dma
);
222 iounmap(rrpriv
->regs
);
224 pci_release_regions(pdev
);
225 pci_set_drvdata(pdev
, NULL
);
233 static void __devexit
rr_remove_one (struct pci_dev
*pdev
)
235 struct net_device
*dev
= pci_get_drvdata(pdev
);
238 struct rr_private
*rr
= netdev_priv(dev
);
240 if (!(readl(&rr
->regs
->HostCtrl
) & NIC_HALTED
)){
241 printk(KERN_ERR
"%s: trying to unload running NIC\n",
243 writel(HALT_NIC
, &rr
->regs
->HostCtrl
);
246 pci_free_consistent(pdev
, EVT_RING_SIZE
, rr
->evt_ring
,
248 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rr
->rx_ring
,
250 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rr
->tx_ring
,
252 unregister_netdev(dev
);
255 pci_release_regions(pdev
);
256 pci_disable_device(pdev
);
257 pci_set_drvdata(pdev
, NULL
);
263 * Commands are considered to be slow, thus there is no reason to
266 static void rr_issue_cmd(struct rr_private
*rrpriv
, struct cmd
*cmd
)
268 struct rr_regs __iomem
*regs
;
273 * This is temporary - it will go away in the final version.
274 * We probably also want to make this function inline.
276 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
277 printk("issuing command for halted NIC, code 0x%x, "
278 "HostCtrl %08x\n", cmd
->code
, readl(®s
->HostCtrl
));
279 if (readl(®s
->Mode
) & FATAL_ERR
)
280 printk("error codes Fail1 %02x, Fail2 %02x\n",
281 readl(®s
->Fail1
), readl(®s
->Fail2
));
284 idx
= rrpriv
->info
->cmd_ctrl
.pi
;
286 writel(*(u32
*)(cmd
), ®s
->CmdRing
[idx
]);
289 idx
= (idx
- 1) % CMD_RING_ENTRIES
;
290 rrpriv
->info
->cmd_ctrl
.pi
= idx
;
293 if (readl(®s
->Mode
) & FATAL_ERR
)
294 printk("error code %02x\n", readl(®s
->Fail1
));
299 * Reset the board in a sensible manner. The NIC is already halted
300 * when we get here and a spin-lock is held.
302 static int rr_reset(struct net_device
*dev
)
304 struct rr_private
*rrpriv
;
305 struct rr_regs __iomem
*regs
;
306 struct eeprom
*hw
= NULL
;
310 rrpriv
= netdev_priv(dev
);
313 rr_load_firmware(dev
);
315 writel(0x01000000, ®s
->TX_state
);
316 writel(0xff800000, ®s
->RX_state
);
317 writel(0, ®s
->AssistState
);
318 writel(CLEAR_INTA
, ®s
->LocalCtrl
);
319 writel(0x01, ®s
->BrkPt
);
320 writel(0, ®s
->Timer
);
321 writel(0, ®s
->TimerRef
);
322 writel(RESET_DMA
, ®s
->DmaReadState
);
323 writel(RESET_DMA
, ®s
->DmaWriteState
);
324 writel(0, ®s
->DmaWriteHostHi
);
325 writel(0, ®s
->DmaWriteHostLo
);
326 writel(0, ®s
->DmaReadHostHi
);
327 writel(0, ®s
->DmaReadHostLo
);
328 writel(0, ®s
->DmaReadLen
);
329 writel(0, ®s
->DmaWriteLen
);
330 writel(0, ®s
->DmaWriteLcl
);
331 writel(0, ®s
->DmaWriteIPchecksum
);
332 writel(0, ®s
->DmaReadLcl
);
333 writel(0, ®s
->DmaReadIPchecksum
);
334 writel(0, ®s
->PciState
);
335 #if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
336 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_SWAP
, ®s
->Mode
);
337 #elif (BITS_PER_LONG == 64)
338 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
340 writel(SWAP_DATA
| PTR32BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
345 * Don't worry, this is just black magic.
347 writel(0xdf000, ®s
->RxBase
);
348 writel(0xdf000, ®s
->RxPrd
);
349 writel(0xdf000, ®s
->RxCon
);
350 writel(0xce000, ®s
->TxBase
);
351 writel(0xce000, ®s
->TxPrd
);
352 writel(0xce000, ®s
->TxCon
);
353 writel(0, ®s
->RxIndPro
);
354 writel(0, ®s
->RxIndCon
);
355 writel(0, ®s
->RxIndRef
);
356 writel(0, ®s
->TxIndPro
);
357 writel(0, ®s
->TxIndCon
);
358 writel(0, ®s
->TxIndRef
);
359 writel(0xcc000, ®s
->pad10
[0]);
360 writel(0, ®s
->DrCmndPro
);
361 writel(0, ®s
->DrCmndCon
);
362 writel(0, ®s
->DwCmndPro
);
363 writel(0, ®s
->DwCmndCon
);
364 writel(0, ®s
->DwCmndRef
);
365 writel(0, ®s
->DrDataPro
);
366 writel(0, ®s
->DrDataCon
);
367 writel(0, ®s
->DrDataRef
);
368 writel(0, ®s
->DwDataPro
);
369 writel(0, ®s
->DwDataCon
);
370 writel(0, ®s
->DwDataRef
);
373 writel(0xffffffff, ®s
->MbEvent
);
374 writel(0, ®s
->Event
);
376 writel(0, ®s
->TxPi
);
377 writel(0, ®s
->IpRxPi
);
379 writel(0, ®s
->EvtCon
);
380 writel(0, ®s
->EvtPrd
);
382 rrpriv
->info
->evt_ctrl
.pi
= 0;
384 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
385 writel(0, ®s
->CmdRing
[i
]);
388 * Why 32 ? is this not cache line size dependent?
390 writel(RBURST_64
|WBURST_64
, ®s
->PciState
);
393 start_pc
= rr_read_eeprom_word(rrpriv
, &hw
->rncd_info
.FwStart
);
396 printk("%s: Executing firmware at address 0x%06x\n",
397 dev
->name
, start_pc
);
400 writel(start_pc
+ 0x800, ®s
->Pc
);
404 writel(start_pc
, ®s
->Pc
);
412 * Read a string from the EEPROM.
414 static unsigned int rr_read_eeprom(struct rr_private
*rrpriv
,
415 unsigned long offset
,
417 unsigned long length
)
419 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
420 u32 misc
, io
, host
, i
;
422 io
= readl(®s
->ExtIo
);
423 writel(0, ®s
->ExtIo
);
424 misc
= readl(®s
->LocalCtrl
);
425 writel(0, ®s
->LocalCtrl
);
426 host
= readl(®s
->HostCtrl
);
427 writel(host
| HALT_NIC
, ®s
->HostCtrl
);
430 for (i
= 0; i
< length
; i
++){
431 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
433 buf
[i
] = (readl(®s
->WinData
) >> 24) & 0xff;
437 writel(host
, ®s
->HostCtrl
);
438 writel(misc
, ®s
->LocalCtrl
);
439 writel(io
, ®s
->ExtIo
);
446 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
447 * it to our CPU byte-order.
449 static u32
rr_read_eeprom_word(struct rr_private
*rrpriv
,
454 if ((rr_read_eeprom(rrpriv
, (unsigned long)offset
,
455 (char *)&word
, 4) == 4))
456 return be32_to_cpu(word
);
462 * Write a string to the EEPROM.
464 * This is only called when the firmware is not running.
466 static unsigned int write_eeprom(struct rr_private
*rrpriv
,
467 unsigned long offset
,
469 unsigned long length
)
471 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
472 u32 misc
, io
, data
, i
, j
, ready
, error
= 0;
474 io
= readl(®s
->ExtIo
);
475 writel(0, ®s
->ExtIo
);
476 misc
= readl(®s
->LocalCtrl
);
477 writel(ENABLE_EEPROM_WRITE
, ®s
->LocalCtrl
);
480 for (i
= 0; i
< length
; i
++){
481 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
485 * Only try to write the data if it is not the same
488 if ((readl(®s
->WinData
) & 0xff000000) != data
){
489 writel(data
, ®s
->WinData
);
495 if ((readl(®s
->WinData
) & 0xff000000) ==
500 printk("data mismatch: %08x, "
501 "WinData %08x\n", data
,
502 readl(®s
->WinData
));
510 writel(misc
, ®s
->LocalCtrl
);
511 writel(io
, ®s
->ExtIo
);
518 static int __devinit
rr_init(struct net_device
*dev
)
520 struct rr_private
*rrpriv
;
521 struct rr_regs __iomem
*regs
;
522 struct eeprom
*hw
= NULL
;
526 rrpriv
= netdev_priv(dev
);
529 rev
= readl(®s
->FwRev
);
530 rrpriv
->fw_rev
= rev
;
531 if (rev
> 0x00020024)
532 printk(" Firmware revision: %i.%i.%i\n", (rev
>> 16),
533 ((rev
>> 8) & 0xff), (rev
& 0xff));
534 else if (rev
>= 0x00020000) {
535 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
536 "later is recommended)\n", (rev
>> 16),
537 ((rev
>> 8) & 0xff), (rev
& 0xff));
539 printk(" Firmware revision too old: %i.%i.%i, please "
540 "upgrade to 2.0.37 or later.\n",
541 (rev
>> 16), ((rev
>> 8) & 0xff), (rev
& 0xff));
545 printk(" Maximum receive rings %i\n", readl(®s
->MaxRxRng
));
549 * Read the hardware address from the eeprom. The HW address
550 * is not really necessary for HIPPI but awfully convenient.
551 * The pointer arithmetic to put it in dev_addr is ugly, but
552 * Donald Becker does it this way for the GigE version of this
553 * card and it's shorter and more portable than any
554 * other method I've seen. -VAL
557 *(u16
*)(dev
->dev_addr
) =
558 htons(rr_read_eeprom_word(rrpriv
, &hw
->manf
.BoardULA
));
559 *(u32
*)(dev
->dev_addr
+2) =
560 htonl(rr_read_eeprom_word(rrpriv
, &hw
->manf
.BoardULA
[4]));
564 for (i
= 0; i
< 5; i
++)
565 printk("%2.2x:", dev
->dev_addr
[i
]);
566 printk("%2.2x\n", dev
->dev_addr
[i
]);
568 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
569 printk(" SRAM size 0x%06x\n", sram_size
);
571 if (sysctl_rmem_max
< 262144){
572 printk(" Receive socket buffer limit too low (%i), "
573 "setting to 262144\n", sysctl_rmem_max
);
574 sysctl_rmem_max
= 262144;
577 if (sysctl_wmem_max
< 262144){
578 printk(" Transmit socket buffer limit too low (%i), "
579 "setting to 262144\n", sysctl_wmem_max
);
580 sysctl_wmem_max
= 262144;
587 static int rr_init1(struct net_device
*dev
)
589 struct rr_private
*rrpriv
;
590 struct rr_regs __iomem
*regs
;
591 unsigned long myjif
, flags
;
597 rrpriv
= netdev_priv(dev
);
600 spin_lock_irqsave(&rrpriv
->lock
, flags
);
602 hostctrl
= readl(®s
->HostCtrl
);
603 writel(hostctrl
| HALT_NIC
| RR_CLEAR_INT
, ®s
->HostCtrl
);
606 if (hostctrl
& PARITY_ERR
){
607 printk("%s: Parity error halting NIC - this is serious!\n",
609 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
614 set_rxaddr(regs
, rrpriv
->rx_ctrl_dma
);
615 set_infoaddr(regs
, rrpriv
->info_dma
);
617 rrpriv
->info
->evt_ctrl
.entry_size
= sizeof(struct event
);
618 rrpriv
->info
->evt_ctrl
.entries
= EVT_RING_ENTRIES
;
619 rrpriv
->info
->evt_ctrl
.mode
= 0;
620 rrpriv
->info
->evt_ctrl
.pi
= 0;
621 set_rraddr(&rrpriv
->info
->evt_ctrl
.rngptr
, rrpriv
->evt_ring_dma
);
623 rrpriv
->info
->cmd_ctrl
.entry_size
= sizeof(struct cmd
);
624 rrpriv
->info
->cmd_ctrl
.entries
= CMD_RING_ENTRIES
;
625 rrpriv
->info
->cmd_ctrl
.mode
= 0;
626 rrpriv
->info
->cmd_ctrl
.pi
= 15;
628 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++) {
629 writel(0, ®s
->CmdRing
[i
]);
632 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
633 rrpriv
->tx_ring
[i
].size
= 0;
634 set_rraddr(&rrpriv
->tx_ring
[i
].addr
, 0);
635 rrpriv
->tx_skbuff
[i
] = NULL
;
637 rrpriv
->info
->tx_ctrl
.entry_size
= sizeof(struct tx_desc
);
638 rrpriv
->info
->tx_ctrl
.entries
= TX_RING_ENTRIES
;
639 rrpriv
->info
->tx_ctrl
.mode
= 0;
640 rrpriv
->info
->tx_ctrl
.pi
= 0;
641 set_rraddr(&rrpriv
->info
->tx_ctrl
.rngptr
, rrpriv
->tx_ring_dma
);
644 * Set dirty_tx before we start receiving interrupts, otherwise
645 * the interrupt handler might think it is supposed to process
646 * tx ints before we are up and running, which may cause a null
647 * pointer access in the int handler.
651 rrpriv
->dirty_rx
= rrpriv
->dirty_tx
= 0;
656 writel(0x5000, ®s
->ConRetry
);
657 writel(0x100, ®s
->ConRetryTmr
);
658 writel(0x500000, ®s
->ConTmout
);
659 writel(0x60, ®s
->IntrTmr
);
660 writel(0x500000, ®s
->TxDataMvTimeout
);
661 writel(0x200000, ®s
->RxDataMvTimeout
);
662 writel(0x80, ®s
->WriteDmaThresh
);
663 writel(0x80, ®s
->ReadDmaThresh
);
665 rrpriv
->fw_running
= 0;
668 hostctrl
&= ~(HALT_NIC
| INVALID_INST_B
| PARITY_ERR
);
669 writel(hostctrl
, ®s
->HostCtrl
);
672 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
674 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
678 rrpriv
->rx_ring
[i
].mode
= 0;
679 skb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
, GFP_ATOMIC
);
681 printk(KERN_WARNING
"%s: Unable to allocate memory "
682 "for receive ring - halting NIC\n", dev
->name
);
686 rrpriv
->rx_skbuff
[i
] = skb
;
687 addr
= pci_map_single(rrpriv
->pci_dev
, skb
->data
,
688 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
690 * Sanity test to see if we conflict with the DMA
691 * limitations of the Roadrunner.
693 if ((((unsigned long)skb
->data
) & 0xfff) > ~65320)
694 printk("skb alloc error\n");
696 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, addr
);
697 rrpriv
->rx_ring
[i
].size
= dev
->mtu
+ HIPPI_HLEN
;
700 rrpriv
->rx_ctrl
[4].entry_size
= sizeof(struct rx_desc
);
701 rrpriv
->rx_ctrl
[4].entries
= RX_RING_ENTRIES
;
702 rrpriv
->rx_ctrl
[4].mode
= 8;
703 rrpriv
->rx_ctrl
[4].pi
= 0;
705 set_rraddr(&rrpriv
->rx_ctrl
[4].rngptr
, rrpriv
->rx_ring_dma
);
710 * Now start the FirmWare.
712 cmd
.code
= C_START_FW
;
716 rr_issue_cmd(rrpriv
, &cmd
);
719 * Give the FirmWare time to chew on the `get running' command.
721 myjif
= jiffies
+ 5 * HZ
;
722 while (time_before(jiffies
, myjif
) && !rrpriv
->fw_running
)
725 netif_start_queue(dev
);
731 * We might have gotten here because we are out of memory,
732 * make sure we release everything we allocated before failing
734 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
735 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
738 pci_unmap_single(rrpriv
->pci_dev
,
739 rrpriv
->rx_ring
[i
].addr
.addrlo
,
740 dev
->mtu
+ HIPPI_HLEN
,
742 rrpriv
->rx_ring
[i
].size
= 0;
743 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, 0);
745 rrpriv
->rx_skbuff
[i
] = NULL
;
753 * All events are considered to be slow (RX/TX ints do not generate
754 * events) and are handled here, outside the main interrupt handler,
755 * to reduce the size of the handler.
757 static u32
rr_handle_event(struct net_device
*dev
, u32 prodidx
, u32 eidx
)
759 struct rr_private
*rrpriv
;
760 struct rr_regs __iomem
*regs
;
763 rrpriv
= netdev_priv(dev
);
766 while (prodidx
!= eidx
){
767 switch (rrpriv
->evt_ring
[eidx
].code
){
769 tmp
= readl(®s
->FwRev
);
770 printk(KERN_INFO
"%s: Firmware revision %i.%i.%i "
771 "up and running\n", dev
->name
,
772 (tmp
>> 16), ((tmp
>> 8) & 0xff), (tmp
& 0xff));
773 rrpriv
->fw_running
= 1;
774 writel(RX_RING_ENTRIES
- 1, ®s
->IpRxPi
);
778 printk(KERN_INFO
"%s: Optical link ON\n", dev
->name
);
781 printk(KERN_INFO
"%s: Optical link OFF\n", dev
->name
);
784 printk(KERN_WARNING
"%s: RX data not moving\n",
788 printk(KERN_INFO
"%s: The watchdog is here to see "
792 printk(KERN_ERR
"%s: HIPPI Internal NIC error\n",
794 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
799 printk(KERN_ERR
"%s: Host software error\n",
801 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
809 printk(KERN_WARNING
"%s: Connection rejected\n",
811 rrpriv
->stats
.tx_aborted_errors
++;
814 printk(KERN_WARNING
"%s: Connection timeout\n",
818 printk(KERN_WARNING
"%s: HIPPI disconnect error\n",
820 rrpriv
->stats
.tx_aborted_errors
++;
823 printk(KERN_ERR
"%s: HIPPI Internal Parity error\n",
825 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
830 printk(KERN_WARNING
"%s: Transmitter idle\n",
834 printk(KERN_WARNING
"%s: Link lost during transmit\n",
836 rrpriv
->stats
.tx_aborted_errors
++;
837 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
842 printk(KERN_ERR
"%s: Invalid send ring block\n",
844 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
849 printk(KERN_ERR
"%s: Invalid send buffer address\n",
851 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
856 printk(KERN_ERR
"%s: Invalid descriptor address\n",
858 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
866 printk(KERN_INFO
"%s: Receive ring full\n", dev
->name
);
870 printk(KERN_WARNING
"%s: Receive parity error\n",
874 printk(KERN_WARNING
"%s: Receive LLRC error\n",
878 printk(KERN_WARNING
"%s: Receive packet length "
879 "error\n", dev
->name
);
882 printk(KERN_WARNING
"%s: Data checksum error\n",
886 printk(KERN_WARNING
"%s: Unexpected short burst "
887 "error\n", dev
->name
);
890 printk(KERN_WARNING
"%s: Recv. state transition"
891 " error\n", dev
->name
);
894 printk(KERN_WARNING
"%s: Unexpected data error\n",
898 printk(KERN_WARNING
"%s: Link lost error\n",
902 printk(KERN_WARNING
"%s: Framming Error\n",
906 printk(KERN_WARNING
"%s: Flag sync. lost during"
907 "packet\n", dev
->name
);
910 printk(KERN_ERR
"%s: Invalid receive buffer "
911 "address\n", dev
->name
);
912 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
917 printk(KERN_ERR
"%s: Invalid receive descriptor "
918 "address\n", dev
->name
);
919 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
924 printk(KERN_ERR
"%s: Invalid ring block\n",
926 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
931 /* Label packet to be dropped.
932 * Actual dropping occurs in rx
935 * The index of packet we get to drop is
936 * the index of the packet following
937 * the bad packet. -kbf
940 u16 index
= rrpriv
->evt_ring
[eidx
].index
;
941 index
= (index
+ (RX_RING_ENTRIES
- 1)) %
943 rrpriv
->rx_ring
[index
].mode
|=
944 (PACKET_BAD
| PACKET_END
);
948 printk(KERN_WARNING
"%s: Unhandled event 0x%02x\n",
949 dev
->name
, rrpriv
->evt_ring
[eidx
].code
);
951 eidx
= (eidx
+ 1) % EVT_RING_ENTRIES
;
954 rrpriv
->info
->evt_ctrl
.pi
= eidx
;
960 static void rx_int(struct net_device
*dev
, u32 rxlimit
, u32 index
)
962 struct rr_private
*rrpriv
= netdev_priv(dev
);
963 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
966 struct rx_desc
*desc
;
969 desc
= &(rrpriv
->rx_ring
[index
]);
970 pkt_len
= desc
->size
;
972 printk("index %i, rxlimit %i\n", index
, rxlimit
);
973 printk("len %x, mode %x\n", pkt_len
, desc
->mode
);
975 if ( (rrpriv
->rx_ring
[index
].mode
& PACKET_BAD
) == PACKET_BAD
){
976 rrpriv
->stats
.rx_dropped
++;
981 struct sk_buff
*skb
, *rx_skb
;
983 rx_skb
= rrpriv
->rx_skbuff
[index
];
985 if (pkt_len
< PKT_COPY_THRESHOLD
) {
986 skb
= alloc_skb(pkt_len
, GFP_ATOMIC
);
988 printk(KERN_WARNING
"%s: Unable to allocate skb (%i bytes), deferring packet\n", dev
->name
, pkt_len
);
989 rrpriv
->stats
.rx_dropped
++;
992 pci_dma_sync_single_for_cpu(rrpriv
->pci_dev
,
997 memcpy(skb_put(skb
, pkt_len
),
998 rx_skb
->data
, pkt_len
);
1000 pci_dma_sync_single_for_device(rrpriv
->pci_dev
,
1003 PCI_DMA_FROMDEVICE
);
1006 struct sk_buff
*newskb
;
1008 newskb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
,
1013 pci_unmap_single(rrpriv
->pci_dev
,
1014 desc
->addr
.addrlo
, dev
->mtu
+
1015 HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
1017 skb_put(skb
, pkt_len
);
1018 rrpriv
->rx_skbuff
[index
] = newskb
;
1019 addr
= pci_map_single(rrpriv
->pci_dev
,
1021 dev
->mtu
+ HIPPI_HLEN
,
1022 PCI_DMA_FROMDEVICE
);
1023 set_rraddr(&desc
->addr
, addr
);
1025 printk("%s: Out of memory, deferring "
1026 "packet\n", dev
->name
);
1027 rrpriv
->stats
.rx_dropped
++;
1031 skb
->protocol
= hippi_type_trans(skb
, dev
);
1033 netif_rx(skb
); /* send it up */
1035 dev
->last_rx
= jiffies
;
1036 rrpriv
->stats
.rx_packets
++;
1037 rrpriv
->stats
.rx_bytes
+= pkt_len
;
1041 desc
->size
= dev
->mtu
+ HIPPI_HLEN
;
1043 if ((index
& 7) == 7)
1044 writel(index
, ®s
->IpRxPi
);
1046 index
= (index
+ 1) % RX_RING_ENTRIES
;
1047 } while(index
!= rxlimit
);
1049 rrpriv
->cur_rx
= index
;
1054 static irqreturn_t
rr_interrupt(int irq
, void *dev_id
)
1056 struct rr_private
*rrpriv
;
1057 struct rr_regs __iomem
*regs
;
1058 struct net_device
*dev
= (struct net_device
*)dev_id
;
1059 u32 prodidx
, rxindex
, eidx
, txcsmr
, rxlimit
, txcon
;
1061 rrpriv
= netdev_priv(dev
);
1062 regs
= rrpriv
->regs
;
1064 if (!(readl(®s
->HostCtrl
) & RR_INT
))
1067 spin_lock(&rrpriv
->lock
);
1069 prodidx
= readl(®s
->EvtPrd
);
1070 txcsmr
= (prodidx
>> 8) & 0xff;
1071 rxlimit
= (prodidx
>> 16) & 0xff;
1075 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev
->name
,
1076 prodidx
, rrpriv
->info
->evt_ctrl
.pi
);
1079 * Order here is important. We must handle events
1080 * before doing anything else in order to catch
1081 * such things as LLRC errors, etc -kbf
1084 eidx
= rrpriv
->info
->evt_ctrl
.pi
;
1085 if (prodidx
!= eidx
)
1086 eidx
= rr_handle_event(dev
, prodidx
, eidx
);
1088 rxindex
= rrpriv
->cur_rx
;
1089 if (rxindex
!= rxlimit
)
1090 rx_int(dev
, rxlimit
, rxindex
);
1092 txcon
= rrpriv
->dirty_tx
;
1093 if (txcsmr
!= txcon
) {
1095 /* Due to occational firmware TX producer/consumer out
1096 * of sync. error need to check entry in ring -kbf
1098 if(rrpriv
->tx_skbuff
[txcon
]){
1099 struct tx_desc
*desc
;
1100 struct sk_buff
*skb
;
1102 desc
= &(rrpriv
->tx_ring
[txcon
]);
1103 skb
= rrpriv
->tx_skbuff
[txcon
];
1105 rrpriv
->stats
.tx_packets
++;
1106 rrpriv
->stats
.tx_bytes
+= skb
->len
;
1108 pci_unmap_single(rrpriv
->pci_dev
,
1109 desc
->addr
.addrlo
, skb
->len
,
1111 dev_kfree_skb_irq(skb
);
1113 rrpriv
->tx_skbuff
[txcon
] = NULL
;
1115 set_rraddr(&rrpriv
->tx_ring
[txcon
].addr
, 0);
1118 txcon
= (txcon
+ 1) % TX_RING_ENTRIES
;
1119 } while (txcsmr
!= txcon
);
1122 rrpriv
->dirty_tx
= txcon
;
1123 if (rrpriv
->tx_full
&& rr_if_busy(dev
) &&
1124 (((rrpriv
->info
->tx_ctrl
.pi
+ 1) % TX_RING_ENTRIES
)
1125 != rrpriv
->dirty_tx
)){
1126 rrpriv
->tx_full
= 0;
1127 netif_wake_queue(dev
);
1131 eidx
|= ((txcsmr
<< 8) | (rxlimit
<< 16));
1132 writel(eidx
, ®s
->EvtCon
);
1135 spin_unlock(&rrpriv
->lock
);
1139 static inline void rr_raz_tx(struct rr_private
*rrpriv
,
1140 struct net_device
*dev
)
1144 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
1145 struct sk_buff
*skb
= rrpriv
->tx_skbuff
[i
];
1148 struct tx_desc
*desc
= &(rrpriv
->tx_ring
[i
]);
1150 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1151 skb
->len
, PCI_DMA_TODEVICE
);
1153 set_rraddr(&desc
->addr
, 0);
1155 rrpriv
->tx_skbuff
[i
] = NULL
;
1161 static inline void rr_raz_rx(struct rr_private
*rrpriv
,
1162 struct net_device
*dev
)
1166 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
1167 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
1170 struct rx_desc
*desc
= &(rrpriv
->rx_ring
[i
]);
1172 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1173 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
1175 set_rraddr(&desc
->addr
, 0);
1177 rrpriv
->rx_skbuff
[i
] = NULL
;
1182 static void rr_timer(unsigned long data
)
1184 struct net_device
*dev
= (struct net_device
*)data
;
1185 struct rr_private
*rrpriv
= netdev_priv(dev
);
1186 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1187 unsigned long flags
;
1189 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
1190 printk("%s: Restarting nic\n", dev
->name
);
1191 memset(rrpriv
->rx_ctrl
, 0, 256 * sizeof(struct ring_ctrl
));
1192 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1195 rr_raz_tx(rrpriv
, dev
);
1196 rr_raz_rx(rrpriv
, dev
);
1198 if (rr_init1(dev
)) {
1199 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1200 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
1202 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1205 rrpriv
->timer
.expires
= RUN_AT(5*HZ
);
1206 add_timer(&rrpriv
->timer
);
1210 static int rr_open(struct net_device
*dev
)
1212 struct rr_private
*rrpriv
= netdev_priv(dev
);
1213 struct pci_dev
*pdev
= rrpriv
->pci_dev
;
1214 struct rr_regs __iomem
*regs
;
1216 unsigned long flags
;
1217 dma_addr_t dma_addr
;
1219 regs
= rrpriv
->regs
;
1221 if (rrpriv
->fw_rev
< 0x00020000) {
1222 printk(KERN_WARNING
"%s: trying to configure device with "
1223 "obsolete firmware\n", dev
->name
);
1228 rrpriv
->rx_ctrl
= pci_alloc_consistent(pdev
,
1229 256 * sizeof(struct ring_ctrl
),
1231 if (!rrpriv
->rx_ctrl
) {
1235 rrpriv
->rx_ctrl_dma
= dma_addr
;
1236 memset(rrpriv
->rx_ctrl
, 0, 256*sizeof(struct ring_ctrl
));
1238 rrpriv
->info
= pci_alloc_consistent(pdev
, sizeof(struct rr_info
),
1240 if (!rrpriv
->info
) {
1244 rrpriv
->info_dma
= dma_addr
;
1245 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1248 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1249 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1250 readl(®s
->HostCtrl
);
1251 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1253 if (request_irq(dev
->irq
, rr_interrupt
, IRQF_SHARED
, dev
->name
, dev
)) {
1254 printk(KERN_WARNING
"%s: Requested IRQ %d is busy\n",
1255 dev
->name
, dev
->irq
);
1260 if ((ecode
= rr_init1(dev
)))
1263 /* Set the timer to switch to check for link beat and perhaps switch
1264 to an alternate media type. */
1265 init_timer(&rrpriv
->timer
);
1266 rrpriv
->timer
.expires
= RUN_AT(5*HZ
); /* 5 sec. watchdog */
1267 rrpriv
->timer
.data
= (unsigned long)dev
;
1268 rrpriv
->timer
.function
= &rr_timer
; /* timer handler */
1269 add_timer(&rrpriv
->timer
);
1271 netif_start_queue(dev
);
1276 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1277 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1278 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1281 pci_free_consistent(pdev
, sizeof(struct rr_info
), rrpriv
->info
,
1283 rrpriv
->info
= NULL
;
1285 if (rrpriv
->rx_ctrl
) {
1286 pci_free_consistent(pdev
, sizeof(struct ring_ctrl
),
1287 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1288 rrpriv
->rx_ctrl
= NULL
;
1291 netif_stop_queue(dev
);
1297 static void rr_dump(struct net_device
*dev
)
1299 struct rr_private
*rrpriv
;
1300 struct rr_regs __iomem
*regs
;
1305 rrpriv
= netdev_priv(dev
);
1306 regs
= rrpriv
->regs
;
1308 printk("%s: dumping NIC TX rings\n", dev
->name
);
1310 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1311 readl(®s
->RxPrd
), readl(®s
->TxPrd
),
1312 readl(®s
->EvtPrd
), readl(®s
->TxPi
),
1313 rrpriv
->info
->tx_ctrl
.pi
);
1315 printk("Error code 0x%x\n", readl(®s
->Fail1
));
1317 index
= (((readl(®s
->EvtPrd
) >> 8) & 0xff ) - 1) % EVT_RING_ENTRIES
;
1318 cons
= rrpriv
->dirty_tx
;
1319 printk("TX ring index %i, TX consumer %i\n",
1322 if (rrpriv
->tx_skbuff
[index
]){
1323 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[index
]->len
);
1324 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index
, len
, rrpriv
->tx_ring
[index
].size
);
1325 for (i
= 0; i
< len
; i
++){
1328 printk("%02x ", (unsigned char) rrpriv
->tx_skbuff
[index
]->data
[i
]);
1333 if (rrpriv
->tx_skbuff
[cons
]){
1334 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[cons
]->len
);
1335 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons
, len
, rrpriv
->tx_skbuff
[cons
]->len
);
1336 printk("mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %08lx, truesize 0x%x\n",
1337 rrpriv
->tx_ring
[cons
].mode
,
1338 rrpriv
->tx_ring
[cons
].size
,
1339 (unsigned long long) rrpriv
->tx_ring
[cons
].addr
.addrlo
,
1340 (unsigned long)rrpriv
->tx_skbuff
[cons
]->data
,
1341 (unsigned int)rrpriv
->tx_skbuff
[cons
]->truesize
);
1342 for (i
= 0; i
< len
; i
++){
1345 printk("%02x ", (unsigned char)rrpriv
->tx_ring
[cons
].size
);
1350 printk("dumping TX ring info:\n");
1351 for (i
= 0; i
< TX_RING_ENTRIES
; i
++)
1352 printk("mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1353 rrpriv
->tx_ring
[i
].mode
,
1354 rrpriv
->tx_ring
[i
].size
,
1355 (unsigned long long) rrpriv
->tx_ring
[i
].addr
.addrlo
);
1360 static int rr_close(struct net_device
*dev
)
1362 struct rr_private
*rrpriv
;
1363 struct rr_regs __iomem
*regs
;
1364 unsigned long flags
;
1368 netif_stop_queue(dev
);
1370 rrpriv
= netdev_priv(dev
);
1371 regs
= rrpriv
->regs
;
1374 * Lock to make sure we are not cleaning up while another CPU
1375 * is handling interrupts.
1377 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1379 tmp
= readl(®s
->HostCtrl
);
1380 if (tmp
& NIC_HALTED
){
1381 printk("%s: NIC already halted\n", dev
->name
);
1384 tmp
|= HALT_NIC
| RR_CLEAR_INT
;
1385 writel(tmp
, ®s
->HostCtrl
);
1386 readl(®s
->HostCtrl
);
1389 rrpriv
->fw_running
= 0;
1391 del_timer_sync(&rrpriv
->timer
);
1393 writel(0, ®s
->TxPi
);
1394 writel(0, ®s
->IpRxPi
);
1396 writel(0, ®s
->EvtCon
);
1397 writel(0, ®s
->EvtPrd
);
1399 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
1400 writel(0, ®s
->CmdRing
[i
]);
1402 rrpriv
->info
->tx_ctrl
.entries
= 0;
1403 rrpriv
->info
->cmd_ctrl
.pi
= 0;
1404 rrpriv
->info
->evt_ctrl
.pi
= 0;
1405 rrpriv
->rx_ctrl
[4].entries
= 0;
1407 rr_raz_tx(rrpriv
, dev
);
1408 rr_raz_rx(rrpriv
, dev
);
1410 pci_free_consistent(rrpriv
->pci_dev
, 256 * sizeof(struct ring_ctrl
),
1411 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1412 rrpriv
->rx_ctrl
= NULL
;
1414 pci_free_consistent(rrpriv
->pci_dev
, sizeof(struct rr_info
),
1415 rrpriv
->info
, rrpriv
->info_dma
);
1416 rrpriv
->info
= NULL
;
1418 free_irq(dev
->irq
, dev
);
1419 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1425 static int rr_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1427 struct rr_private
*rrpriv
= netdev_priv(dev
);
1428 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1429 struct hippi_cb
*hcb
= (struct hippi_cb
*) skb
->cb
;
1430 struct ring_ctrl
*txctrl
;
1431 unsigned long flags
;
1432 u32 index
, len
= skb
->len
;
1434 struct sk_buff
*new_skb
;
1436 if (readl(®s
->Mode
) & FATAL_ERR
)
1437 printk("error codes Fail1 %02x, Fail2 %02x\n",
1438 readl(®s
->Fail1
), readl(®s
->Fail2
));
1441 * We probably need to deal with tbusy here to prevent overruns.
1444 if (skb_headroom(skb
) < 8){
1445 printk("incoming skb too small - reallocating\n");
1446 if (!(new_skb
= dev_alloc_skb(len
+ 8))) {
1448 netif_wake_queue(dev
);
1451 skb_reserve(new_skb
, 8);
1452 skb_put(new_skb
, len
);
1453 skb_copy_from_linear_data(skb
, new_skb
->data
, len
);
1458 ifield
= (u32
*)skb_push(skb
, 8);
1461 ifield
[1] = hcb
->ifield
;
1464 * We don't need the lock before we are actually going to start
1465 * fiddling with the control blocks.
1467 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1469 txctrl
= &rrpriv
->info
->tx_ctrl
;
1473 rrpriv
->tx_skbuff
[index
] = skb
;
1474 set_rraddr(&rrpriv
->tx_ring
[index
].addr
, pci_map_single(
1475 rrpriv
->pci_dev
, skb
->data
, len
+ 8, PCI_DMA_TODEVICE
));
1476 rrpriv
->tx_ring
[index
].size
= len
+ 8; /* include IFIELD */
1477 rrpriv
->tx_ring
[index
].mode
= PACKET_START
| PACKET_END
;
1478 txctrl
->pi
= (index
+ 1) % TX_RING_ENTRIES
;
1480 writel(txctrl
->pi
, ®s
->TxPi
);
1482 if (txctrl
->pi
== rrpriv
->dirty_tx
){
1483 rrpriv
->tx_full
= 1;
1484 netif_stop_queue(dev
);
1487 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1489 dev
->trans_start
= jiffies
;
1494 static struct net_device_stats
*rr_get_stats(struct net_device
*dev
)
1496 struct rr_private
*rrpriv
;
1498 rrpriv
= netdev_priv(dev
);
1500 return(&rrpriv
->stats
);
1505 * Read the firmware out of the EEPROM and put it into the SRAM
1506 * (or from user space - later)
1508 * This operation requires the NIC to be halted and is performed with
1509 * interrupts disabled and with the spinlock hold.
1511 static int rr_load_firmware(struct net_device
*dev
)
1513 struct rr_private
*rrpriv
;
1514 struct rr_regs __iomem
*regs
;
1515 unsigned long eptr
, segptr
;
1517 u32 localctrl
, sptr
, len
, tmp
;
1518 u32 p2len
, p2size
, nr_seg
, revision
, io
, sram_size
;
1519 struct eeprom
*hw
= NULL
;
1521 rrpriv
= netdev_priv(dev
);
1522 regs
= rrpriv
->regs
;
1524 if (dev
->flags
& IFF_UP
)
1527 if (!(readl(®s
->HostCtrl
) & NIC_HALTED
)){
1528 printk("%s: Trying to load firmware to a running NIC.\n",
1533 localctrl
= readl(®s
->LocalCtrl
);
1534 writel(0, ®s
->LocalCtrl
);
1536 writel(0, ®s
->EvtPrd
);
1537 writel(0, ®s
->RxPrd
);
1538 writel(0, ®s
->TxPrd
);
1541 * First wipe the entire SRAM, otherwise we might run into all
1542 * kinds of trouble ... sigh, this took almost all afternoon
1545 io
= readl(®s
->ExtIo
);
1546 writel(0, ®s
->ExtIo
);
1547 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
1549 for (i
= 200; i
< sram_size
/ 4; i
++){
1550 writel(i
* 4, ®s
->WinBase
);
1552 writel(0, ®s
->WinData
);
1555 writel(io
, ®s
->ExtIo
);
1558 eptr
= (unsigned long)rr_read_eeprom_word(rrpriv
,
1559 &hw
->rncd_info
.AddrRunCodeSegs
);
1560 eptr
= ((eptr
& 0x1fffff) >> 3);
1562 p2len
= rr_read_eeprom_word(rrpriv
, (void *)(0x83*4));
1563 p2len
= (p2len
<< 2);
1564 p2size
= rr_read_eeprom_word(rrpriv
, (void *)(0x84*4));
1565 p2size
= ((p2size
& 0x1fffff) >> 3);
1567 if ((eptr
< p2size
) || (eptr
> (p2size
+ p2len
))){
1568 printk("%s: eptr is invalid\n", dev
->name
);
1572 revision
= rr_read_eeprom_word(rrpriv
, &hw
->manf
.HeaderFmt
);
1575 printk("%s: invalid firmware format (%i)\n",
1576 dev
->name
, revision
);
1580 nr_seg
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1583 printk("%s: nr_seg %i\n", dev
->name
, nr_seg
);
1586 for (i
= 0; i
< nr_seg
; i
++){
1587 sptr
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1589 len
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1591 segptr
= (unsigned long)rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1592 segptr
= ((segptr
& 0x1fffff) >> 3);
1595 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1596 dev
->name
, i
, sptr
, len
, segptr
);
1598 for (j
= 0; j
< len
; j
++){
1599 tmp
= rr_read_eeprom_word(rrpriv
, (void *)segptr
);
1600 writel(sptr
, ®s
->WinBase
);
1602 writel(tmp
, ®s
->WinData
);
1610 writel(localctrl
, ®s
->LocalCtrl
);
1616 static int rr_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1618 struct rr_private
*rrpriv
;
1619 unsigned char *image
, *oldimage
;
1620 unsigned long flags
;
1622 int error
= -EOPNOTSUPP
;
1624 rrpriv
= netdev_priv(dev
);
1628 if (!capable(CAP_SYS_RAWIO
)){
1632 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1634 printk(KERN_ERR
"%s: Unable to allocate memory "
1635 "for EEPROM image\n", dev
->name
);
1640 if (rrpriv
->fw_running
){
1641 printk("%s: Firmware already running\n", dev
->name
);
1646 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1647 i
= rr_read_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1648 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1649 if (i
!= EEPROM_BYTES
){
1650 printk(KERN_ERR
"%s: Error reading EEPROM\n",
1655 error
= copy_to_user(rq
->ifr_data
, image
, EEPROM_BYTES
);
1663 if (!capable(CAP_SYS_RAWIO
)){
1667 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1668 oldimage
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1669 if (!image
|| !oldimage
) {
1670 printk(KERN_ERR
"%s: Unable to allocate memory "
1671 "for EEPROM image\n", dev
->name
);
1676 error
= copy_from_user(image
, rq
->ifr_data
, EEPROM_BYTES
);
1682 if (rrpriv
->fw_running
){
1683 printk("%s: Firmware already running\n", dev
->name
);
1688 printk("%s: Updating EEPROM firmware\n", dev
->name
);
1690 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1691 error
= write_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1693 printk(KERN_ERR
"%s: Error writing EEPROM\n",
1696 i
= rr_read_eeprom(rrpriv
, 0, oldimage
, EEPROM_BYTES
);
1697 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1699 if (i
!= EEPROM_BYTES
)
1700 printk(KERN_ERR
"%s: Error reading back EEPROM "
1701 "image\n", dev
->name
);
1703 error
= memcmp(image
, oldimage
, EEPROM_BYTES
);
1705 printk(KERN_ERR
"%s: Error verifying EEPROM image\n",
1715 return put_user(0x52523032, (int __user
*)rq
->ifr_data
);
1721 static struct pci_device_id rr_pci_tbl
[] = {
1722 { PCI_VENDOR_ID_ESSENTIAL
, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER
,
1723 PCI_ANY_ID
, PCI_ANY_ID
, },
1726 MODULE_DEVICE_TABLE(pci
, rr_pci_tbl
);
1728 static struct pci_driver rr_driver
= {
1730 .id_table
= rr_pci_tbl
,
1731 .probe
= rr_init_one
,
1732 .remove
= __devexit_p(rr_remove_one
),
1735 static int __init
rr_init_module(void)
1737 return pci_register_driver(&rr_driver
);
1740 static void __exit
rr_cleanup_module(void)
1742 pci_unregister_driver(&rr_driver
);
1745 module_init(rr_init_module
);
1746 module_exit(rr_cleanup_module
);
1750 * 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"