2 * rrunner.c: Linux driver for the Essential RoadRunner HIPPI board.
4 * Written 1998 by Jes Sorensen, <Jes.Sorensen@cern.ch>.
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.
19 #define RX_DMA_SKBUFF 1
20 #define PKT_COPY_THRESHOLD 512
22 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/pci.h>
28 #include <linux/kernel.h>
29 #include <linux/netdevice.h>
30 #include <linux/hippidevice.h>
31 #include <linux/skbuff.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
37 #include <asm/system.h>
38 #include <asm/cache.h>
39 #include <asm/byteorder.h>
42 #include <asm/uaccess.h>
48 * Implementation notes:
50 * The DMA engine only allows for DMA within physical 64KB chunks of
51 * memory. The current approach of the driver (and stack) is to use
52 * linear blocks of memory for the skbuffs. However, as the data block
53 * is always the first part of the skb and skbs are 2^n aligned so we
54 * are guarantted to get the whole block within one 64KB align 64KB
57 * On the long term, relying on being able to allocate 64KB linear
58 * chunks of memory is not feasible and the skb handling code and the
59 * stack will need to know about I/O vectors or something similar.
62 static const char __initdata
*version
= "rrunner.c: v0.17 03/09/99 Jes Sorensen (Jes.Sorensen@cern.ch)\n";
66 * These are checked at init time to see if they are at least 256KB
67 * and increased to 256KB if they are not. This is done to avoid ending
68 * up with socket buffers smaller than the MTU size,
70 extern __u32 sysctl_wmem_max
;
71 extern __u32 sysctl_rmem_max
;
73 static int probed __initdata
= 0;
75 int __init
rr_hippi_probe (struct net_device
*dev
)
78 int version_disp
; /* was version info already displayed? */
79 struct pci_dev
*pdev
= NULL
;
80 struct pci_dev
*opdev
= NULL
;
82 struct rr_private
*rrpriv
;
88 if (!pci_present()) /* is PCI BIOS even present? */
93 while((pdev
= pci_find_device(PCI_VENDOR_ID_ESSENTIAL
,
94 PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER
,
101 * So we found our HIPPI ... time to tell the system.
104 dev
= init_hippi_dev(dev
, sizeof(struct rr_private
));
110 dev
->priv
= kmalloc(sizeof(*rrpriv
), GFP_KERNEL
);
115 rrpriv
= (struct rr_private
*)dev
->priv
;
116 memset(rrpriv
, 0, sizeof(*rrpriv
));
119 spin_lock_init(&rrpriv
->lock
);
121 sprintf(rrpriv
->name
, "RoadRunner serial HIPPI");
123 dev
->irq
= pdev
->irq
;
124 dev
->open
= &rr_open
;
125 dev
->hard_start_xmit
= &rr_start_xmit
;
126 dev
->stop
= &rr_close
;
127 dev
->get_stats
= &rr_get_stats
;
128 dev
->do_ioctl
= &rr_ioctl
;
135 /* display version info if adapter is found */
138 /* set display flag to TRUE so that */
139 /* we only display this string ONCE */
144 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &pci_latency
);
145 if (pci_latency
<= 0x58){
147 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
,
151 pci_set_master(pdev
);
153 printk(KERN_INFO
"%s: Essential RoadRunner serial HIPPI "
154 "at 0x%08lx, irq %i, PCI latency %i\n", dev
->name
,
155 pdev
->resource
[0].start
, dev
->irq
, pci_latency
);
158 * Remap the regs into kernel space.
161 rrpriv
->regs
= (struct rr_regs
*)
162 ioremap(pdev
->resource
[0].start
, 0x1000);
165 printk(KERN_ERR
"%s: Unable to map I/O register, "
166 "RoadRunner %i will be disabled.\n",
167 dev
->name
, boards_found
);
172 * Don't access any registes before this point!
175 writel(readl(®s
->HostCtrl
) | NO_SWAP
, ®s
->HostCtrl
);
178 * Need to add a case for little-endian 64-bit hosts here.
190 * If we're at this point we're going through rr_hippi_probe()
191 * for the first time. Return success (0) if we've initialized
192 * 1 or more boards. Otherwise, return failure (-ENODEV).
198 if (boards_found
> 0)
205 static struct net_device
*root_dev
= NULL
;
208 #if LINUX_VERSION_CODE > 0x20118
209 MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@cern.ch>");
210 MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
214 int init_module(void)
220 cards
= rr_hippi_probe(NULL
);
221 return cards
? 0 : -ENODEV
;
224 void cleanup_module(void)
226 struct rr_private
*rr
;
227 struct net_device
*next
;
230 next
= ((struct rr_private
*)root_dev
->priv
)->next
;
231 rr
= (struct rr_private
*)root_dev
->priv
;
233 if (!(readl(&rr
->regs
->HostCtrl
) & NIC_HALTED
)){
234 printk(KERN_ERR
"%s: trying to unload running NIC\n",
236 writel(HALT_NIC
, &rr
->regs
->HostCtrl
);
240 unregister_hipdev(root_dev
);
250 * Commands are considered to be slow, thus there is no reason to
253 static void rr_issue_cmd(struct rr_private
*rrpriv
, struct cmd
*cmd
)
255 struct rr_regs
*regs
;
260 * This is temporary - it will go away in the final version.
261 * We probably also want to make this function inline.
263 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
264 printk("issuing command for halted NIC, code 0x%x, "
265 "HostCtrl %08x\n", cmd
->code
, readl(®s
->HostCtrl
));
266 if (readl(®s
->Mode
) & FATAL_ERR
)
267 printk("error codes Fail1 %02x, Fail2 %02x\n",
268 readl(®s
->Fail1
), readl(®s
->Fail2
));
271 idx
= rrpriv
->info
->cmd_ctrl
.pi
;
273 writel(*(u32
*)(cmd
), ®s
->CmdRing
[idx
]);
276 idx
= (idx
- 1) % CMD_RING_ENTRIES
;
277 rrpriv
->info
->cmd_ctrl
.pi
= idx
;
280 if (readl(®s
->Mode
) & FATAL_ERR
)
281 printk("error code %02x\n", readl(®s
->Fail1
));
286 * Reset the board in a sensible manner. The NIC is already halted
287 * when we get here and a spin-lock is held.
289 static int rr_reset(struct net_device
*dev
)
291 struct rr_private
*rrpriv
;
292 struct rr_regs
*regs
;
293 struct eeprom
*hw
= NULL
;
297 rrpriv
= (struct rr_private
*)dev
->priv
;
300 rr_load_firmware(dev
);
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
);
327 writel(SWAP_DATA
| PTR32BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
332 * Don't worry, this is just black magic.
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
);
360 writel(0xffffffff, ®s
->MbEvent
);
361 writel(0, ®s
->Event
);
363 writel(0, ®s
->TxPi
);
364 writel(0, ®s
->IpRxPi
);
366 writel(0, ®s
->EvtCon
);
367 writel(0, ®s
->EvtPrd
);
369 rrpriv
->info
->evt_ctrl
.pi
= 0;
371 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
372 writel(0, ®s
->CmdRing
[i
]);
375 * Why 32 ? is this not cache line size dependant?
377 writel(WBURST_32
, ®s
->PciState
);
380 start_pc
= rr_read_eeprom_word(rrpriv
, &hw
->rncd_info
.FwStart
);
383 printk("%s: Executing firmware at address 0x%06x\n",
384 dev
->name
, start_pc
);
387 writel(start_pc
+ 0x800, ®s
->Pc
);
391 writel(start_pc
, ®s
->Pc
);
399 * Read a string from the EEPROM.
401 static unsigned int rr_read_eeprom(struct rr_private
*rrpriv
,
402 unsigned long offset
,
404 unsigned long length
)
406 struct rr_regs
*regs
= rrpriv
->regs
;
407 u32 misc
, io
, host
, i
;
409 io
= readl(®s
->ExtIo
);
410 writel(0, ®s
->ExtIo
);
411 misc
= readl(®s
->LocalCtrl
);
412 writel(0, ®s
->LocalCtrl
);
413 host
= readl(®s
->HostCtrl
);
414 writel(host
| HALT_NIC
, ®s
->HostCtrl
);
417 for (i
= 0; i
< length
; i
++){
418 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
420 buf
[i
] = (readl(®s
->WinData
) >> 24) & 0xff;
424 writel(host
, ®s
->HostCtrl
);
425 writel(misc
, ®s
->LocalCtrl
);
426 writel(io
, ®s
->ExtIo
);
433 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
434 * it to our CPU byte-order.
436 static u32
rr_read_eeprom_word(struct rr_private
*rrpriv
,
441 if ((rr_read_eeprom(rrpriv
, (unsigned long)offset
,
442 (char *)&word
, 4) == 4))
443 return be32_to_cpu(word
);
449 * Write a string to the EEPROM.
451 * This is only called when the firmware is not running.
453 static unsigned int write_eeprom(struct rr_private
*rrpriv
,
454 unsigned long offset
,
456 unsigned long length
)
458 struct rr_regs
*regs
= rrpriv
->regs
;
459 u32 misc
, io
, data
, i
, j
, ready
, error
= 0;
461 io
= readl(®s
->ExtIo
);
462 writel(0, ®s
->ExtIo
);
463 misc
= readl(®s
->LocalCtrl
);
464 writel(ENABLE_EEPROM_WRITE
, ®s
->LocalCtrl
);
467 for (i
= 0; i
< length
; i
++){
468 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
472 * Only try to write the data if it is not the same
475 if ((readl(®s
->WinData
) & 0xff000000) != data
){
476 writel(data
, ®s
->WinData
);
482 if ((readl(®s
->WinData
) & 0xff000000) ==
487 printk("data mismatch: %08x, "
488 "WinData %08x\n", data
,
489 readl(®s
->WinData
));
497 writel(misc
, ®s
->LocalCtrl
);
498 writel(io
, ®s
->ExtIo
);
505 static int __init
rr_init(struct net_device
*dev
)
507 struct rr_private
*rrpriv
;
508 struct rr_regs
*regs
;
511 rrpriv
= (struct rr_private
*)dev
->priv
;
514 rev
= readl(®s
->FwRev
);
515 rrpriv
->fw_rev
= rev
;
516 if (rev
> 0x00020024)
517 printk(" Firmware revision: %i.%i.%i\n", (rev
>> 16),
518 ((rev
>> 8) & 0xff), (rev
& 0xff));
519 else if (rev
>= 0x00020000) {
520 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
521 "later is recommended)\n", (rev
>> 16),
522 ((rev
>> 8) & 0xff), (rev
& 0xff));
524 printk(" Firmware revision too old: %i.%i.%i, please "
525 "upgrade to 2.0.37 or later.\n",
526 (rev
>> 16), ((rev
>> 8) & 0xff), (rev
& 0xff));
530 printk(" Maximum receive rings %i\n", readl(®s
->MaxRxRng
));
533 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
534 printk(" SRAM size 0x%06x\n", sram_size
);
536 if (sysctl_rmem_max
< 262144){
537 printk(" Receive socket buffer limit too low (%i), "
538 "setting to 262144\n", sysctl_rmem_max
);
539 sysctl_rmem_max
= 262144;
542 if (sysctl_wmem_max
< 262144){
543 printk(" Transmit socket buffer limit too low (%i), "
544 "setting to 262144\n", sysctl_wmem_max
);
545 sysctl_wmem_max
= 262144;
548 rrpriv
->next
= root_dev
;
555 static int rr_init1(struct net_device
*dev
)
557 struct rr_private
*rrpriv
;
558 struct rr_regs
*regs
;
560 unsigned long myjif
, flags
;
564 rrpriv
= (struct rr_private
*)dev
->priv
;
567 spin_lock_irqsave(&rrpriv
->lock
, flags
);
569 hostctrl
= readl(®s
->HostCtrl
);
570 writel(hostctrl
| HALT_NIC
| RR_CLEAR_INT
, ®s
->HostCtrl
);
573 if (hostctrl
& PARITY_ERR
){
574 printk("%s: Parity error halting NIC - this is serious!\n",
576 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
580 set_rxaddr(regs
, rrpriv
->rx_ctrl
);
581 set_infoaddr(regs
, rrpriv
->info
);
583 rrpriv
->info
->evt_ctrl
.entry_size
= sizeof(struct event
);
584 rrpriv
->info
->evt_ctrl
.entries
= EVT_RING_ENTRIES
;
585 rrpriv
->info
->evt_ctrl
.mode
= 0;
586 rrpriv
->info
->evt_ctrl
.pi
= 0;
587 set_rraddr(&rrpriv
->info
->evt_ctrl
.rngptr
, rrpriv
->evt_ring
);
589 rrpriv
->info
->cmd_ctrl
.entry_size
= sizeof(struct cmd
);
590 rrpriv
->info
->cmd_ctrl
.entries
= CMD_RING_ENTRIES
;
591 rrpriv
->info
->cmd_ctrl
.mode
= 0;
592 rrpriv
->info
->cmd_ctrl
.pi
= 15;
594 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++) {
595 writel(0, ®s
->CmdRing
[i
]);
598 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
599 rrpriv
->tx_ring
[i
].size
= 0;
600 set_rraddr(&rrpriv
->tx_ring
[i
].addr
, 0);
601 rrpriv
->tx_skbuff
[i
] = 0;
603 rrpriv
->info
->tx_ctrl
.entry_size
= sizeof(struct tx_desc
);
604 rrpriv
->info
->tx_ctrl
.entries
= TX_RING_ENTRIES
;
605 rrpriv
->info
->tx_ctrl
.mode
= 0;
606 rrpriv
->info
->tx_ctrl
.pi
= 0;
607 set_rraddr(&rrpriv
->info
->tx_ctrl
.rngptr
, rrpriv
->tx_ring
);
610 * Set dirty_tx before we start receiving interrupts, otherwise
611 * the interrupt handler might think it is supposed to process
612 * tx ints before we are up and running, which may cause a null
613 * pointer access in the int handler.
617 rrpriv
->dirty_rx
= rrpriv
->dirty_tx
= 0;
621 writel(0x60, ®s
->IntrTmr
);
623 * These seem to have no real effect as the Firmware sets
624 * it's own default values
626 writel(0x10, ®s
->WriteDmaThresh
);
627 writel(0x20, ®s
->ReadDmaThresh
);
629 rrpriv
->fw_running
= 0;
632 hostctrl
&= ~(HALT_NIC
| INVALID_INST_B
| PARITY_ERR
);
633 writel(hostctrl
, ®s
->HostCtrl
);
636 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
641 * Now start the FirmWare.
643 cmd
.code
= C_START_FW
;
647 rr_issue_cmd(rrpriv
, &cmd
);
650 * Give the FirmWare time to chew on the `get running' command.
652 myjif
= jiffies
+ 5 * HZ
;
653 while ((jiffies
< myjif
) && !rrpriv
->fw_running
);
655 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
658 rrpriv
->rx_ring
[i
].mode
= 0;
659 skb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
, GFP_ATOMIC
);
660 rrpriv
->rx_skbuff
[i
] = skb
;
662 * Sanity test to see if we conflict with the DMA
663 * limitations of the Roadrunner.
665 if ((((unsigned long)skb
->data
) & 0xfff) > ~65320)
666 printk("skb alloc error\n");
668 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, skb
->data
);
669 rrpriv
->rx_ring
[i
].size
= dev
->mtu
+ HIPPI_HLEN
;
672 rrpriv
->rx_ctrl
[4].entry_size
= sizeof(struct rx_desc
);
673 rrpriv
->rx_ctrl
[4].entries
= RX_RING_ENTRIES
;
674 rrpriv
->rx_ctrl
[4].mode
= 8;
675 rrpriv
->rx_ctrl
[4].pi
= 0;
677 set_rraddr(&rrpriv
->rx_ctrl
[4].rngptr
, rrpriv
->rx_ring
);
679 cmd
.code
= C_NEW_RNG
;
682 rr_issue_cmd(rrpriv
, &cmd
);
687 tmp
= readl(®s
->ExtIo
);
688 writel(0x80, ®s
->ExtIo
);
690 i
= jiffies
+ 1 * HZ
;
692 writel(tmp
, ®s
->ExtIo
);
702 * All events are considered to be slow (RX/TX ints do not generate
703 * events) and are handled here, outside the main interrupt handler,
704 * to reduce the size of the handler.
706 static u32
rr_handle_event(struct net_device
*dev
, u32 prodidx
, u32 eidx
)
708 struct rr_private
*rrpriv
;
709 struct rr_regs
*regs
;
712 rrpriv
= (struct rr_private
*)dev
->priv
;
715 while (prodidx
!= eidx
){
716 switch (rrpriv
->evt_ring
[eidx
].code
){
718 tmp
= readl(®s
->FwRev
);
719 printk("%s: Firmware revision %i.%i.%i up and running\n",
720 dev
->name
, (tmp
>> 16), ((tmp
>> 8) & 0xff),
722 rrpriv
->fw_running
= 1;
726 printk("%s: Optical link ON\n", dev
->name
);
729 printk("%s: Optical link OFF\n", dev
->name
);
732 printk("%s: RX data not moving\n", dev
->name
);
735 printk("%s: The watchdog is here to see us\n",
742 printk("%s: Connection rejected\n", dev
->name
);
743 rrpriv
->stats
.tx_aborted_errors
++;
746 printk("%s: Connection timeout\n", dev
->name
);
749 printk("%s: HIPPI disconnect error\n", dev
->name
);
750 rrpriv
->stats
.tx_aborted_errors
++;
753 printk("%s: Transmitter idle\n", dev
->name
);
756 printk("%s: Link lost during transmit\n", dev
->name
);
757 rrpriv
->stats
.tx_aborted_errors
++;
762 case E_VAL_RNG
: /* Should be ignored */
764 printk("%s: RX ring valid event\n", dev
->name
);
766 writel(RX_RING_ENTRIES
- 1, ®s
->IpRxPi
);
769 printk("%s: RX ring invalid event\n", dev
->name
);
772 printk("%s: Receive ring full\n", dev
->name
);
776 printk("%s: Receive parity error.\n", dev
->name
);
779 printk("%s: Receive LLRC error.\n", dev
->name
);
782 printk("%s: Receive packet length error.\n",
786 printk("%s: Unhandled event 0x%02x\n",
787 dev
->name
, rrpriv
->evt_ring
[eidx
].code
);
789 eidx
= (eidx
+ 1) % EVT_RING_ENTRIES
;
792 rrpriv
->info
->evt_ctrl
.pi
= eidx
;
798 static void rx_int(struct net_device
*dev
, u32 rxlimit
, u32 index
)
800 struct rr_private
*rrpriv
= (struct rr_private
*)dev
->priv
;
802 struct rr_regs
*regs
= rrpriv
->regs
;
805 pkt_len
= rrpriv
->rx_ring
[index
].size
;
807 printk("index %i, rxlimit %i\n", index
, rxlimit
);
808 printk("len %x, mode %x\n", pkt_len
,
809 rrpriv
->rx_ring
[index
].mode
);
814 if (pkt_len
< PKT_COPY_THRESHOLD
) {
815 skb
= alloc_skb(pkt_len
, GFP_ATOMIC
);
817 printk("%s: Out of memory deferring "
818 "packet\n", dev
->name
);
819 rrpriv
->stats
.rx_dropped
++;
822 memcpy(skb_put(skb
, pkt_len
),
823 rrpriv
->rx_skbuff
[index
]->data
,
826 struct sk_buff
*newskb
;
828 newskb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
,
831 skb
= rrpriv
->rx_skbuff
[index
];
832 skb_put(skb
, pkt_len
);
833 rrpriv
->rx_skbuff
[index
] = newskb
;
834 set_rraddr(&rrpriv
->rx_ring
[index
].addr
, newskb
->data
);
836 printk("%s: Out of memory, deferring "
837 "packet\n", dev
->name
);
838 rrpriv
->stats
.rx_dropped
++;
843 skb
->protocol
= hippi_type_trans(skb
, dev
);
845 netif_rx(skb
); /* send it up */
847 rrpriv
->stats
.rx_packets
++;
848 rrpriv
->stats
.rx_bytes
+= skb
->len
;
851 rrpriv
->rx_ring
[index
].mode
= 0;
852 rrpriv
->rx_ring
[index
].size
= dev
->mtu
+ HIPPI_HLEN
;
854 if ((index
& 7) == 7)
855 writel(index
, ®s
->IpRxPi
);
857 index
= (index
+ 1) % RX_RING_ENTRIES
;
858 } while(index
!= rxlimit
);
860 rrpriv
->cur_rx
= index
;
865 static void rr_interrupt(int irq
, void *dev_id
, struct pt_regs
*ptregs
)
867 struct rr_private
*rrpriv
;
868 struct rr_regs
*regs
;
869 struct net_device
*dev
= (struct net_device
*)dev_id
;
870 u32 prodidx
, rxindex
, eidx
, txcsmr
, rxlimit
, txcon
;
873 rrpriv
= (struct rr_private
*)dev
->priv
;
876 if (!(readl(®s
->HostCtrl
) & RR_INT
))
879 spin_lock_irqsave(&rrpriv
->lock
, flags
);
881 prodidx
= readl(®s
->EvtPrd
);
882 txcsmr
= (prodidx
>> 8) & 0xff;
883 rxlimit
= (prodidx
>> 16) & 0xff;
887 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev
->name
,
888 prodidx
, rrpriv
->info
->evt_ctrl
.pi
);
891 rxindex
= rrpriv
->cur_rx
;
892 if (rxindex
!= rxlimit
)
893 rx_int(dev
, rxlimit
, rxindex
);
895 txcon
= rrpriv
->dirty_tx
;
896 if (txcsmr
!= txcon
) {
898 rrpriv
->stats
.tx_packets
++;
899 rrpriv
->stats
.tx_bytes
+=rrpriv
->tx_skbuff
[txcon
]->len
;
900 dev_kfree_skb(rrpriv
->tx_skbuff
[txcon
]);
902 rrpriv
->tx_skbuff
[txcon
] = NULL
;
903 rrpriv
->tx_ring
[txcon
].size
= 0;
904 set_rraddr(&rrpriv
->tx_ring
[txcon
].addr
, 0);
905 rrpriv
->tx_ring
[txcon
].mode
= 0;
907 txcon
= (txcon
+ 1) % TX_RING_ENTRIES
;
908 } while (txcsmr
!= txcon
);
911 rrpriv
->dirty_tx
= txcon
;
912 if (rrpriv
->tx_full
&& dev
->tbusy
&&
913 (((rrpriv
->info
->tx_ctrl
.pi
+ 1) % TX_RING_ENTRIES
)
914 != rrpriv
->dirty_tx
)){
921 eidx
= rrpriv
->info
->evt_ctrl
.pi
;
923 eidx
= rr_handle_event(dev
, prodidx
, eidx
);
925 eidx
|= ((txcsmr
<< 8) | (rxlimit
<< 16));
926 writel(eidx
, ®s
->EvtCon
);
929 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
933 static int rr_open(struct net_device
*dev
)
935 struct rr_private
*rrpriv
;
936 struct rr_regs
*regs
;
940 rrpriv
= (struct rr_private
*)dev
->priv
;
943 if (rrpriv
->fw_rev
< 0x00020000) {
944 printk(KERN_WARNING
"%s: trying to configure device with "
945 "obsolete firmware\n", dev
->name
);
950 rrpriv
->rx_ctrl
= kmalloc(256*sizeof(struct ring_ctrl
),
951 GFP_KERNEL
| GFP_DMA
);
952 if (!rrpriv
->rx_ctrl
) {
957 rrpriv
->info
= kmalloc(sizeof(struct rr_info
), GFP_KERNEL
| GFP_DMA
);
959 kfree(rrpriv
->rx_ctrl
);
963 memset(rrpriv
->rx_ctrl
, 0, 256 * sizeof(struct ring_ctrl
));
964 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
967 spin_lock_irqsave(&rrpriv
->lock
, flags
);
968 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
969 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
971 if (request_irq(dev
->irq
, rr_interrupt
, SA_SHIRQ
, rrpriv
->name
, dev
))
973 printk(KERN_WARNING
"%s: Requested IRQ %d is busy\n",
974 dev
->name
, dev
->irq
);
988 spin_lock_irqsave(&rrpriv
->lock
, flags
);
989 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
990 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
998 static void rr_dump(struct net_device
*dev
)
1000 struct rr_private
*rrpriv
;
1001 struct rr_regs
*regs
;
1006 rrpriv
= (struct rr_private
*)dev
->priv
;
1007 regs
= rrpriv
->regs
;
1009 printk("%s: dumping NIC TX rings\n", dev
->name
);
1011 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1012 readl(®s
->RxPrd
), readl(®s
->TxPrd
),
1013 readl(®s
->EvtPrd
), readl(®s
->TxPi
),
1014 rrpriv
->info
->tx_ctrl
.pi
);
1016 printk("Error code 0x%x\n", readl(®s
->Fail1
));
1018 index
= (((readl(®s
->EvtPrd
) >> 8) & 0xff ) - 1) % EVT_RING_ENTRIES
;
1019 cons
= rrpriv
->dirty_tx
;
1020 printk("TX ring index %i, TX consumer %i\n",
1023 if (rrpriv
->tx_skbuff
[index
]){
1024 len
= min(0x80, rrpriv
->tx_skbuff
[index
]->len
);
1025 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index
, len
, rrpriv
->tx_ring
[index
].size
);
1026 for (i
= 0; i
< len
; i
++){
1029 printk("%02x ", (unsigned char) rrpriv
->tx_skbuff
[index
]->data
[i
]);
1034 if (rrpriv
->tx_skbuff
[cons
]){
1035 len
= min(0x80, rrpriv
->tx_skbuff
[cons
]->len
);
1036 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons
, len
, rrpriv
->tx_skbuff
[cons
]->len
);
1037 printk("mode 0x%x, size 0x%x,\n phys %08x (virt %08lx), skbuff-addr %08lx, truesize 0x%x\n",
1038 rrpriv
->tx_ring
[cons
].mode
,
1039 rrpriv
->tx_ring
[cons
].size
,
1040 rrpriv
->tx_ring
[cons
].addr
.addrlo
,
1041 (unsigned long)bus_to_virt(rrpriv
->tx_ring
[cons
].addr
.addrlo
),
1042 (unsigned long)rrpriv
->tx_skbuff
[cons
]->data
,
1043 (unsigned int)rrpriv
->tx_skbuff
[cons
]->truesize
);
1044 for (i
= 0; i
< len
; i
++){
1047 printk("%02x ", (unsigned char)rrpriv
->tx_ring
[cons
].size
);
1052 printk("dumping TX ring info:\n");
1053 for (i
= 0; i
< TX_RING_ENTRIES
; i
++)
1054 printk("mode 0x%x, size 0x%x, phys-addr %08x\n",
1055 rrpriv
->tx_ring
[i
].mode
,
1056 rrpriv
->tx_ring
[i
].size
,
1057 rrpriv
->tx_ring
[i
].addr
.addrlo
);
1062 static int rr_close(struct net_device
*dev
)
1064 struct rr_private
*rrpriv
;
1065 struct rr_regs
*regs
;
1070 set_bit(0, (void*)&dev
->tbusy
);
1072 rrpriv
= (struct rr_private
*)dev
->priv
;
1073 regs
= rrpriv
->regs
;
1076 * Lock to make sure we are not cleaning up while another CPU
1077 * handling interrupts.
1079 spin_lock(&rrpriv
->lock
);
1081 tmp
= readl(®s
->HostCtrl
);
1082 if (tmp
& NIC_HALTED
){
1083 printk("%s: NIC already halted\n", dev
->name
);
1086 tmp
|= HALT_NIC
| RR_CLEAR_INT
;
1087 writel(tmp
, ®s
->HostCtrl
);
1091 rrpriv
->fw_running
= 0;
1093 writel(0, ®s
->TxPi
);
1094 writel(0, ®s
->IpRxPi
);
1096 writel(0, ®s
->EvtCon
);
1097 writel(0, ®s
->EvtPrd
);
1099 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
1100 writel(0, ®s
->CmdRing
[i
]);
1102 rrpriv
->info
->tx_ctrl
.entries
= 0;
1103 rrpriv
->info
->cmd_ctrl
.pi
= 0;
1104 rrpriv
->info
->evt_ctrl
.pi
= 0;
1105 rrpriv
->rx_ctrl
[4].entries
= 0;
1107 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
1108 if (rrpriv
->tx_skbuff
[i
]) {
1109 rrpriv
->tx_ring
[i
].size
= 0;
1110 set_rraddr(&rrpriv
->tx_ring
[i
].addr
, 0);
1111 dev_kfree_skb(rrpriv
->tx_skbuff
[i
]);
1115 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
1116 if (rrpriv
->rx_skbuff
[i
]) {
1117 rrpriv
->rx_ring
[i
].size
= 0;
1118 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, 0);
1119 dev_kfree_skb(rrpriv
->rx_skbuff
[i
]);
1123 kfree(rrpriv
->rx_ctrl
);
1124 kfree(rrpriv
->info
);
1126 free_irq(dev
->irq
, dev
);
1127 spin_unlock(&rrpriv
->lock
);
1134 static int rr_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1136 struct rr_private
*rrpriv
= (struct rr_private
*)dev
->priv
;
1137 struct rr_regs
*regs
= rrpriv
->regs
;
1138 struct ring_ctrl
*txctrl
;
1139 unsigned long flags
;
1140 u32 index
, len
= skb
->len
;
1142 struct sk_buff
*new_skb
;
1144 if (readl(®s
->Mode
) & FATAL_ERR
)
1145 printk("error codes Fail1 %02x, Fail2 %02x\n",
1146 readl(®s
->Fail1
), readl(®s
->Fail2
));
1149 * We probably need to deal with tbusy here to prevent overruns.
1152 if (skb_headroom(skb
) < 8){
1153 printk("incoming skb too small - reallocating\n");
1154 if (!(new_skb
= dev_alloc_skb(len
+ 8))) {
1159 skb_reserve(new_skb
, 8);
1160 skb_put(new_skb
, len
);
1161 memcpy(new_skb
->data
, skb
->data
, len
);
1166 ifield
= (u32
*)skb_push(skb
, 8);
1169 ifield
[1] = skb
->private.ifield
;
1172 * We don't need the lock before we are actually going to start
1173 * fiddling with the control blocks.
1175 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1177 txctrl
= &rrpriv
->info
->tx_ctrl
;
1181 rrpriv
->tx_skbuff
[index
] = skb
;
1182 set_rraddr(&rrpriv
->tx_ring
[index
].addr
, skb
->data
);
1183 rrpriv
->tx_ring
[index
].size
= len
+ 8; /* include IFIELD */
1184 rrpriv
->tx_ring
[index
].mode
= PACKET_START
| PACKET_END
;
1185 txctrl
->pi
= (index
+ 1) % TX_RING_ENTRIES
;
1186 writel(txctrl
->pi
, ®s
->TxPi
);
1188 if (txctrl
->pi
== rrpriv
->dirty_tx
){
1189 rrpriv
->tx_full
= 1;
1190 set_bit(0, (void*)&dev
->tbusy
);
1193 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1195 dev
->trans_start
= jiffies
;
1200 static struct net_device_stats
*rr_get_stats(struct net_device
*dev
)
1202 struct rr_private
*rrpriv
;
1204 rrpriv
= (struct rr_private
*)dev
->priv
;
1206 return(&rrpriv
->stats
);
1211 * Read the firmware out of the EEPROM and put it into the SRAM
1212 * (or from user space - later)
1214 * This operation requires the NIC to be halted and is performed with
1215 * interrupts disabled and with the spinlock hold.
1217 static int rr_load_firmware(struct net_device
*dev
)
1219 struct rr_private
*rrpriv
;
1220 struct rr_regs
*regs
;
1221 unsigned long eptr
, segptr
;
1223 u32 localctrl
, sptr
, len
, tmp
;
1224 u32 p2len
, p2size
, nr_seg
, revision
, io
, sram_size
;
1225 struct eeprom
*hw
= NULL
;
1227 rrpriv
= (struct rr_private
*)dev
->priv
;
1228 regs
= rrpriv
->regs
;
1230 if (dev
->flags
& IFF_UP
)
1233 if (!(readl(®s
->HostCtrl
) & NIC_HALTED
)){
1234 printk("%s: Trying to load firmware to a running NIC.\n",
1239 localctrl
= readl(®s
->LocalCtrl
);
1240 writel(0, ®s
->LocalCtrl
);
1242 writel(0, ®s
->EvtPrd
);
1243 writel(0, ®s
->RxPrd
);
1244 writel(0, ®s
->TxPrd
);
1247 * First wipe the entire SRAM, otherwise we might run into all
1248 * kinds of trouble ... sigh, this took almost all afternoon
1251 io
= readl(®s
->ExtIo
);
1252 writel(0, ®s
->ExtIo
);
1253 sram_size
= rr_read_eeprom_word(rrpriv
, (void *)8);
1255 for (i
= 200; i
< sram_size
/ 4; i
++){
1256 writel(i
* 4, ®s
->WinBase
);
1258 writel(0, ®s
->WinData
);
1261 writel(io
, ®s
->ExtIo
);
1264 eptr
= (unsigned long)rr_read_eeprom_word(rrpriv
,
1265 &hw
->rncd_info
.AddrRunCodeSegs
);
1266 eptr
= ((eptr
& 0x1fffff) >> 3);
1268 p2len
= rr_read_eeprom_word(rrpriv
, (void *)(0x83*4));
1269 p2len
= (p2len
<< 2);
1270 p2size
= rr_read_eeprom_word(rrpriv
, (void *)(0x84*4));
1271 p2size
= ((p2size
& 0x1fffff) >> 3);
1273 if ((eptr
< p2size
) || (eptr
> (p2size
+ p2len
))){
1274 printk("%s: eptr is invalid\n", dev
->name
);
1278 revision
= rr_read_eeprom_word(rrpriv
, &hw
->manf
.HeaderFmt
);
1281 printk("%s: invalid firmware format (%i)\n",
1282 dev
->name
, revision
);
1286 nr_seg
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1289 printk("%s: nr_seg %i\n", dev
->name
, nr_seg
);
1292 for (i
= 0; i
< nr_seg
; i
++){
1293 sptr
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1295 len
= rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1297 segptr
= (unsigned long)rr_read_eeprom_word(rrpriv
, (void *)eptr
);
1298 segptr
= ((segptr
& 0x1fffff) >> 3);
1301 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1302 dev
->name
, i
, sptr
, len
, segptr
);
1304 for (j
= 0; j
< len
; j
++){
1305 tmp
= rr_read_eeprom_word(rrpriv
, (void *)segptr
);
1306 writel(sptr
, ®s
->WinBase
);
1308 writel(tmp
, ®s
->WinData
);
1316 writel(localctrl
, ®s
->LocalCtrl
);
1322 static int rr_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1324 struct rr_private
*rrpriv
;
1325 unsigned char *image
, *oldimage
;
1327 int error
= -EOPNOTSUPP
;
1329 rrpriv
= (struct rr_private
*)dev
->priv
;
1331 spin_lock(&rrpriv
->lock
);
1340 if (rrpriv
->fw_running
){
1341 printk("%s: Firmware already running\n", dev
->name
);
1346 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1348 printk(KERN_ERR
"%s: Unable to allocate memory "
1349 "for EEPROM image\n", dev
->name
);
1353 i
= rr_read_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1354 if (i
!= EEPROM_BYTES
){
1356 printk(KERN_ERR
"%s: Error reading EEPROM\n",
1361 error
= copy_to_user(rq
->ifr_data
, image
, EEPROM_BYTES
);
1372 if (rrpriv
->fw_running
){
1373 printk("%s: Firmware already running\n", dev
->name
);
1378 image
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1380 printk(KERN_ERR
"%s: Unable to allocate memory "
1381 "for EEPROM image\n", dev
->name
);
1386 oldimage
= kmalloc(EEPROM_WORDS
* sizeof(u32
), GFP_KERNEL
);
1388 printk(KERN_ERR
"%s: Unable to allocate memory "
1389 "for old EEPROM image\n", dev
->name
);
1394 error
= copy_from_user(image
, rq
->ifr_data
, EEPROM_BYTES
);
1398 printk("%s: Updating EEPROM firmware\n", dev
->name
);
1400 error
= write_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1402 printk(KERN_ERR
"%s: Error writing EEPROM\n",
1405 i
= rr_read_eeprom(rrpriv
, 0, oldimage
, EEPROM_BYTES
);
1406 if (i
!= EEPROM_BYTES
)
1407 printk(KERN_ERR
"%s: Error reading back EEPROM "
1408 "image\n", dev
->name
);
1410 error
= memcmp(image
, oldimage
, EEPROM_BYTES
);
1412 printk(KERN_ERR
"%s: Error verifying EEPROM image\n",
1420 error
= put_user(0x52523032, (int *)(&rq
->ifr_data
[0]));
1428 spin_unlock(&rrpriv
->lock
);
1435 * compile-command: "gcc -D__SMP__ -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 -DCPU=686 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -c rrunner.c"