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/delay.h>
42 #include <linux/slab.h>
45 #include <asm/cache.h>
46 #include <asm/byteorder.h>
49 #include <linux/uaccess.h>
51 #define rr_if_busy(dev) netif_queue_stopped(dev)
52 #define rr_if_running(dev) netif_running(dev)
56 #define RUN_AT(x) (jiffies + (x))
59 MODULE_AUTHOR("Jes Sorensen <jes@wildopensource.com>");
60 MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
61 MODULE_LICENSE("GPL");
63 static const char version
[] =
64 "rrunner.c: v0.50 11/11/2002 Jes Sorensen (jes@wildopensource.com)\n";
67 static const struct net_device_ops rr_netdev_ops
= {
70 .ndo_do_ioctl
= rr_ioctl
,
71 .ndo_start_xmit
= rr_start_xmit
,
72 .ndo_set_mac_address
= hippi_mac_addr
,
76 * Implementation notes:
78 * The DMA engine only allows for DMA within physical 64KB chunks of
79 * memory. The current approach of the driver (and stack) is to use
80 * linear blocks of memory for the skbuffs. However, as the data block
81 * is always the first part of the skb and skbs are 2^n aligned so we
82 * are guarantted to get the whole block within one 64KB align 64KB
85 * On the long term, relying on being able to allocate 64KB linear
86 * chunks of memory is not feasible and the skb handling code and the
87 * stack will need to know about I/O vectors or something similar.
90 static int rr_init_one(struct pci_dev
*pdev
, 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 ret
= pci_request_regions(pdev
, "rrunner");
118 pci_set_drvdata(pdev
, dev
);
120 rrpriv
->pci_dev
= pdev
;
122 spin_lock_init(&rrpriv
->lock
);
124 dev
->netdev_ops
= &rr_netdev_ops
;
126 /* display version info if adapter is found */
128 /* set display flag to TRUE so that */
129 /* we only display this string ONCE */
134 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &pci_latency
);
135 if (pci_latency
<= 0x58){
137 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, pci_latency
);
140 pci_set_master(pdev
);
142 printk(KERN_INFO
"%s: Essential RoadRunner serial HIPPI "
143 "at 0x%llx, irq %i, PCI latency %i\n", dev
->name
,
144 (unsigned long long)pci_resource_start(pdev
, 0),
145 pdev
->irq
, pci_latency
);
148 * Remap the MMIO regs into kernel space.
150 rrpriv
->regs
= pci_iomap(pdev
, 0, 0x1000);
152 printk(KERN_ERR
"%s: Unable to map I/O register, "
153 "RoadRunner will be disabled.\n", dev
->name
);
158 tmpptr
= pci_alloc_consistent(pdev
, TX_TOTAL_SIZE
, &ring_dma
);
159 rrpriv
->tx_ring
= tmpptr
;
160 rrpriv
->tx_ring_dma
= ring_dma
;
167 tmpptr
= pci_alloc_consistent(pdev
, RX_TOTAL_SIZE
, &ring_dma
);
168 rrpriv
->rx_ring
= tmpptr
;
169 rrpriv
->rx_ring_dma
= ring_dma
;
176 tmpptr
= pci_alloc_consistent(pdev
, EVT_RING_SIZE
, &ring_dma
);
177 rrpriv
->evt_ring
= tmpptr
;
178 rrpriv
->evt_ring_dma
= ring_dma
;
186 * Don't access any register before this point!
189 writel(readl(&rrpriv
->regs
->HostCtrl
) | NO_SWAP
,
190 &rrpriv
->regs
->HostCtrl
);
193 * Need to add a case for little-endian 64-bit hosts here.
198 ret
= register_netdev(dev
);
204 if (rrpriv
->evt_ring
)
205 pci_free_consistent(pdev
, EVT_RING_SIZE
, rrpriv
->evt_ring
,
206 rrpriv
->evt_ring_dma
);
208 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rrpriv
->rx_ring
,
209 rrpriv
->rx_ring_dma
);
211 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rrpriv
->tx_ring
,
212 rrpriv
->tx_ring_dma
);
214 pci_iounmap(pdev
, rrpriv
->regs
);
216 pci_release_regions(pdev
);
223 static void rr_remove_one(struct pci_dev
*pdev
)
225 struct net_device
*dev
= pci_get_drvdata(pdev
);
226 struct rr_private
*rr
= netdev_priv(dev
);
228 if (!(readl(&rr
->regs
->HostCtrl
) & NIC_HALTED
)) {
229 printk(KERN_ERR
"%s: trying to unload running NIC\n",
231 writel(HALT_NIC
, &rr
->regs
->HostCtrl
);
234 unregister_netdev(dev
);
235 pci_free_consistent(pdev
, EVT_RING_SIZE
, rr
->evt_ring
,
237 pci_free_consistent(pdev
, RX_TOTAL_SIZE
, rr
->rx_ring
,
239 pci_free_consistent(pdev
, TX_TOTAL_SIZE
, rr
->tx_ring
,
241 pci_iounmap(pdev
, rr
->regs
);
242 pci_release_regions(pdev
);
243 pci_disable_device(pdev
);
249 * Commands are considered to be slow, thus there is no reason to
252 static void rr_issue_cmd(struct rr_private
*rrpriv
, struct cmd
*cmd
)
254 struct rr_regs __iomem
*regs
;
259 * This is temporary - it will go away in the final version.
260 * We probably also want to make this function inline.
262 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
263 printk("issuing command for halted NIC, code 0x%x, "
264 "HostCtrl %08x\n", cmd
->code
, readl(®s
->HostCtrl
));
265 if (readl(®s
->Mode
) & FATAL_ERR
)
266 printk("error codes Fail1 %02x, Fail2 %02x\n",
267 readl(®s
->Fail1
), readl(®s
->Fail2
));
270 idx
= rrpriv
->info
->cmd_ctrl
.pi
;
272 writel(*(u32
*)(cmd
), ®s
->CmdRing
[idx
]);
275 idx
= (idx
- 1) % CMD_RING_ENTRIES
;
276 rrpriv
->info
->cmd_ctrl
.pi
= idx
;
279 if (readl(®s
->Mode
) & FATAL_ERR
)
280 printk("error code %02x\n", readl(®s
->Fail1
));
285 * Reset the board in a sensible manner. The NIC is already halted
286 * when we get here and a spin-lock is held.
288 static int rr_reset(struct net_device
*dev
)
290 struct rr_private
*rrpriv
;
291 struct rr_regs __iomem
*regs
;
295 rrpriv
= netdev_priv(dev
);
298 rr_load_firmware(dev
);
300 writel(0x01000000, ®s
->TX_state
);
301 writel(0xff800000, ®s
->RX_state
);
302 writel(0, ®s
->AssistState
);
303 writel(CLEAR_INTA
, ®s
->LocalCtrl
);
304 writel(0x01, ®s
->BrkPt
);
305 writel(0, ®s
->Timer
);
306 writel(0, ®s
->TimerRef
);
307 writel(RESET_DMA
, ®s
->DmaReadState
);
308 writel(RESET_DMA
, ®s
->DmaWriteState
);
309 writel(0, ®s
->DmaWriteHostHi
);
310 writel(0, ®s
->DmaWriteHostLo
);
311 writel(0, ®s
->DmaReadHostHi
);
312 writel(0, ®s
->DmaReadHostLo
);
313 writel(0, ®s
->DmaReadLen
);
314 writel(0, ®s
->DmaWriteLen
);
315 writel(0, ®s
->DmaWriteLcl
);
316 writel(0, ®s
->DmaWriteIPchecksum
);
317 writel(0, ®s
->DmaReadLcl
);
318 writel(0, ®s
->DmaReadIPchecksum
);
319 writel(0, ®s
->PciState
);
320 #if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
321 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_SWAP
, ®s
->Mode
);
322 #elif (BITS_PER_LONG == 64)
323 writel(SWAP_DATA
| PTR64BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
325 writel(SWAP_DATA
| PTR32BIT
| PTR_WD_NOSWAP
, ®s
->Mode
);
330 * Don't worry, this is just black magic.
332 writel(0xdf000, ®s
->RxBase
);
333 writel(0xdf000, ®s
->RxPrd
);
334 writel(0xdf000, ®s
->RxCon
);
335 writel(0xce000, ®s
->TxBase
);
336 writel(0xce000, ®s
->TxPrd
);
337 writel(0xce000, ®s
->TxCon
);
338 writel(0, ®s
->RxIndPro
);
339 writel(0, ®s
->RxIndCon
);
340 writel(0, ®s
->RxIndRef
);
341 writel(0, ®s
->TxIndPro
);
342 writel(0, ®s
->TxIndCon
);
343 writel(0, ®s
->TxIndRef
);
344 writel(0xcc000, ®s
->pad10
[0]);
345 writel(0, ®s
->DrCmndPro
);
346 writel(0, ®s
->DrCmndCon
);
347 writel(0, ®s
->DwCmndPro
);
348 writel(0, ®s
->DwCmndCon
);
349 writel(0, ®s
->DwCmndRef
);
350 writel(0, ®s
->DrDataPro
);
351 writel(0, ®s
->DrDataCon
);
352 writel(0, ®s
->DrDataRef
);
353 writel(0, ®s
->DwDataPro
);
354 writel(0, ®s
->DwDataCon
);
355 writel(0, ®s
->DwDataRef
);
358 writel(0xffffffff, ®s
->MbEvent
);
359 writel(0, ®s
->Event
);
361 writel(0, ®s
->TxPi
);
362 writel(0, ®s
->IpRxPi
);
364 writel(0, ®s
->EvtCon
);
365 writel(0, ®s
->EvtPrd
);
367 rrpriv
->info
->evt_ctrl
.pi
= 0;
369 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
370 writel(0, ®s
->CmdRing
[i
]);
373 * Why 32 ? is this not cache line size dependent?
375 writel(RBURST_64
|WBURST_64
, ®s
->PciState
);
378 start_pc
= rr_read_eeprom_word(rrpriv
,
379 offsetof(struct eeprom
, rncd_info
.FwStart
));
382 printk("%s: Executing firmware at address 0x%06x\n",
383 dev
->name
, start_pc
);
386 writel(start_pc
+ 0x800, ®s
->Pc
);
390 writel(start_pc
, ®s
->Pc
);
398 * Read a string from the EEPROM.
400 static unsigned int rr_read_eeprom(struct rr_private
*rrpriv
,
401 unsigned long offset
,
403 unsigned long length
)
405 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
406 u32 misc
, io
, host
, i
;
408 io
= readl(®s
->ExtIo
);
409 writel(0, ®s
->ExtIo
);
410 misc
= readl(®s
->LocalCtrl
);
411 writel(0, ®s
->LocalCtrl
);
412 host
= readl(®s
->HostCtrl
);
413 writel(host
| HALT_NIC
, ®s
->HostCtrl
);
416 for (i
= 0; i
< length
; i
++){
417 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
419 buf
[i
] = (readl(®s
->WinData
) >> 24) & 0xff;
423 writel(host
, ®s
->HostCtrl
);
424 writel(misc
, ®s
->LocalCtrl
);
425 writel(io
, ®s
->ExtIo
);
432 * Shortcut to read one word (4 bytes) out of the EEPROM and convert
433 * it to our CPU byte-order.
435 static u32
rr_read_eeprom_word(struct rr_private
*rrpriv
,
440 if ((rr_read_eeprom(rrpriv
, offset
,
441 (unsigned char *)&word
, 4) == 4))
442 return be32_to_cpu(word
);
448 * Write a string to the EEPROM.
450 * This is only called when the firmware is not running.
452 static unsigned int write_eeprom(struct rr_private
*rrpriv
,
453 unsigned long offset
,
455 unsigned long length
)
457 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
458 u32 misc
, io
, data
, i
, j
, ready
, error
= 0;
460 io
= readl(®s
->ExtIo
);
461 writel(0, ®s
->ExtIo
);
462 misc
= readl(®s
->LocalCtrl
);
463 writel(ENABLE_EEPROM_WRITE
, ®s
->LocalCtrl
);
466 for (i
= 0; i
< length
; i
++){
467 writel((EEPROM_BASE
+ ((offset
+i
) << 3)), ®s
->WinBase
);
471 * Only try to write the data if it is not the same
474 if ((readl(®s
->WinData
) & 0xff000000) != data
){
475 writel(data
, ®s
->WinData
);
481 if ((readl(®s
->WinData
) & 0xff000000) ==
486 printk("data mismatch: %08x, "
487 "WinData %08x\n", data
,
488 readl(®s
->WinData
));
496 writel(misc
, ®s
->LocalCtrl
);
497 writel(io
, ®s
->ExtIo
);
504 static int rr_init(struct net_device
*dev
)
506 struct rr_private
*rrpriv
;
507 struct rr_regs __iomem
*regs
;
510 rrpriv
= netdev_priv(dev
);
513 rev
= readl(®s
->FwRev
);
514 rrpriv
->fw_rev
= rev
;
515 if (rev
> 0x00020024)
516 printk(" Firmware revision: %i.%i.%i\n", (rev
>> 16),
517 ((rev
>> 8) & 0xff), (rev
& 0xff));
518 else if (rev
>= 0x00020000) {
519 printk(" Firmware revision: %i.%i.%i (2.0.37 or "
520 "later is recommended)\n", (rev
>> 16),
521 ((rev
>> 8) & 0xff), (rev
& 0xff));
523 printk(" Firmware revision too old: %i.%i.%i, please "
524 "upgrade to 2.0.37 or later.\n",
525 (rev
>> 16), ((rev
>> 8) & 0xff), (rev
& 0xff));
529 printk(" Maximum receive rings %i\n", readl(®s
->MaxRxRng
));
533 * Read the hardware address from the eeprom. The HW address
534 * is not really necessary for HIPPI but awfully convenient.
535 * The pointer arithmetic to put it in dev_addr is ugly, but
536 * Donald Becker does it this way for the GigE version of this
537 * card and it's shorter and more portable than any
538 * other method I've seen. -VAL
541 *(__be16
*)(dev
->dev_addr
) =
542 htons(rr_read_eeprom_word(rrpriv
, offsetof(struct eeprom
, manf
.BoardULA
)));
543 *(__be32
*)(dev
->dev_addr
+2) =
544 htonl(rr_read_eeprom_word(rrpriv
, offsetof(struct eeprom
, manf
.BoardULA
[4])));
546 printk(" MAC: %pM\n", dev
->dev_addr
);
548 sram_size
= rr_read_eeprom_word(rrpriv
, 8);
549 printk(" SRAM size 0x%06x\n", sram_size
);
555 static int rr_init1(struct net_device
*dev
)
557 struct rr_private
*rrpriv
;
558 struct rr_regs __iomem
*regs
;
559 unsigned long myjif
, flags
;
565 rrpriv
= netdev_priv(dev
);
568 spin_lock_irqsave(&rrpriv
->lock
, flags
);
570 hostctrl
= readl(®s
->HostCtrl
);
571 writel(hostctrl
| HALT_NIC
| RR_CLEAR_INT
, ®s
->HostCtrl
);
574 if (hostctrl
& PARITY_ERR
){
575 printk("%s: Parity error halting NIC - this is serious!\n",
577 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
582 set_rxaddr(regs
, rrpriv
->rx_ctrl_dma
);
583 set_infoaddr(regs
, rrpriv
->info_dma
);
585 rrpriv
->info
->evt_ctrl
.entry_size
= sizeof(struct event
);
586 rrpriv
->info
->evt_ctrl
.entries
= EVT_RING_ENTRIES
;
587 rrpriv
->info
->evt_ctrl
.mode
= 0;
588 rrpriv
->info
->evt_ctrl
.pi
= 0;
589 set_rraddr(&rrpriv
->info
->evt_ctrl
.rngptr
, rrpriv
->evt_ring_dma
);
591 rrpriv
->info
->cmd_ctrl
.entry_size
= sizeof(struct cmd
);
592 rrpriv
->info
->cmd_ctrl
.entries
= CMD_RING_ENTRIES
;
593 rrpriv
->info
->cmd_ctrl
.mode
= 0;
594 rrpriv
->info
->cmd_ctrl
.pi
= 15;
596 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++) {
597 writel(0, ®s
->CmdRing
[i
]);
600 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
601 rrpriv
->tx_ring
[i
].size
= 0;
602 set_rraddr(&rrpriv
->tx_ring
[i
].addr
, 0);
603 rrpriv
->tx_skbuff
[i
] = NULL
;
605 rrpriv
->info
->tx_ctrl
.entry_size
= sizeof(struct tx_desc
);
606 rrpriv
->info
->tx_ctrl
.entries
= TX_RING_ENTRIES
;
607 rrpriv
->info
->tx_ctrl
.mode
= 0;
608 rrpriv
->info
->tx_ctrl
.pi
= 0;
609 set_rraddr(&rrpriv
->info
->tx_ctrl
.rngptr
, rrpriv
->tx_ring_dma
);
612 * Set dirty_tx before we start receiving interrupts, otherwise
613 * the interrupt handler might think it is supposed to process
614 * tx ints before we are up and running, which may cause a null
615 * pointer access in the int handler.
619 rrpriv
->dirty_rx
= rrpriv
->dirty_tx
= 0;
624 writel(0x5000, ®s
->ConRetry
);
625 writel(0x100, ®s
->ConRetryTmr
);
626 writel(0x500000, ®s
->ConTmout
);
627 writel(0x60, ®s
->IntrTmr
);
628 writel(0x500000, ®s
->TxDataMvTimeout
);
629 writel(0x200000, ®s
->RxDataMvTimeout
);
630 writel(0x80, ®s
->WriteDmaThresh
);
631 writel(0x80, ®s
->ReadDmaThresh
);
633 rrpriv
->fw_running
= 0;
636 hostctrl
&= ~(HALT_NIC
| INVALID_INST_B
| PARITY_ERR
);
637 writel(hostctrl
, ®s
->HostCtrl
);
640 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
642 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
646 rrpriv
->rx_ring
[i
].mode
= 0;
647 skb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
, GFP_ATOMIC
);
649 printk(KERN_WARNING
"%s: Unable to allocate memory "
650 "for receive ring - halting NIC\n", dev
->name
);
654 rrpriv
->rx_skbuff
[i
] = skb
;
655 addr
= pci_map_single(rrpriv
->pci_dev
, skb
->data
,
656 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
658 * Sanity test to see if we conflict with the DMA
659 * limitations of the Roadrunner.
661 if ((((unsigned long)skb
->data
) & 0xfff) > ~65320)
662 printk("skb alloc error\n");
664 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, addr
);
665 rrpriv
->rx_ring
[i
].size
= dev
->mtu
+ HIPPI_HLEN
;
668 rrpriv
->rx_ctrl
[4].entry_size
= sizeof(struct rx_desc
);
669 rrpriv
->rx_ctrl
[4].entries
= RX_RING_ENTRIES
;
670 rrpriv
->rx_ctrl
[4].mode
= 8;
671 rrpriv
->rx_ctrl
[4].pi
= 0;
673 set_rraddr(&rrpriv
->rx_ctrl
[4].rngptr
, rrpriv
->rx_ring_dma
);
678 * Now start the FirmWare.
680 cmd
.code
= C_START_FW
;
684 rr_issue_cmd(rrpriv
, &cmd
);
687 * Give the FirmWare time to chew on the `get running' command.
689 myjif
= jiffies
+ 5 * HZ
;
690 while (time_before(jiffies
, myjif
) && !rrpriv
->fw_running
)
693 netif_start_queue(dev
);
699 * We might have gotten here because we are out of memory,
700 * make sure we release everything we allocated before failing
702 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
703 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
706 pci_unmap_single(rrpriv
->pci_dev
,
707 rrpriv
->rx_ring
[i
].addr
.addrlo
,
708 dev
->mtu
+ HIPPI_HLEN
,
710 rrpriv
->rx_ring
[i
].size
= 0;
711 set_rraddr(&rrpriv
->rx_ring
[i
].addr
, 0);
713 rrpriv
->rx_skbuff
[i
] = NULL
;
721 * All events are considered to be slow (RX/TX ints do not generate
722 * events) and are handled here, outside the main interrupt handler,
723 * to reduce the size of the handler.
725 static u32
rr_handle_event(struct net_device
*dev
, u32 prodidx
, u32 eidx
)
727 struct rr_private
*rrpriv
;
728 struct rr_regs __iomem
*regs
;
731 rrpriv
= netdev_priv(dev
);
734 while (prodidx
!= eidx
){
735 switch (rrpriv
->evt_ring
[eidx
].code
){
737 tmp
= readl(®s
->FwRev
);
738 printk(KERN_INFO
"%s: Firmware revision %i.%i.%i "
739 "up and running\n", dev
->name
,
740 (tmp
>> 16), ((tmp
>> 8) & 0xff), (tmp
& 0xff));
741 rrpriv
->fw_running
= 1;
742 writel(RX_RING_ENTRIES
- 1, ®s
->IpRxPi
);
746 printk(KERN_INFO
"%s: Optical link ON\n", dev
->name
);
749 printk(KERN_INFO
"%s: Optical link OFF\n", dev
->name
);
752 printk(KERN_WARNING
"%s: RX data not moving\n",
756 printk(KERN_INFO
"%s: The watchdog is here to see "
760 printk(KERN_ERR
"%s: HIPPI Internal NIC error\n",
762 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
767 printk(KERN_ERR
"%s: Host software error\n",
769 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
777 printk(KERN_WARNING
"%s: Connection rejected\n",
779 dev
->stats
.tx_aborted_errors
++;
782 printk(KERN_WARNING
"%s: Connection timeout\n",
786 printk(KERN_WARNING
"%s: HIPPI disconnect error\n",
788 dev
->stats
.tx_aborted_errors
++;
791 printk(KERN_ERR
"%s: HIPPI Internal Parity error\n",
793 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
798 printk(KERN_WARNING
"%s: Transmitter idle\n",
802 printk(KERN_WARNING
"%s: Link lost during transmit\n",
804 dev
->stats
.tx_aborted_errors
++;
805 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
810 printk(KERN_ERR
"%s: Invalid send ring block\n",
812 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
817 printk(KERN_ERR
"%s: Invalid send buffer address\n",
819 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
824 printk(KERN_ERR
"%s: Invalid descriptor address\n",
826 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
834 printk(KERN_INFO
"%s: Receive ring full\n", dev
->name
);
838 printk(KERN_WARNING
"%s: Receive parity error\n",
842 printk(KERN_WARNING
"%s: Receive LLRC error\n",
846 printk(KERN_WARNING
"%s: Receive packet length "
847 "error\n", dev
->name
);
850 printk(KERN_WARNING
"%s: Data checksum error\n",
854 printk(KERN_WARNING
"%s: Unexpected short burst "
855 "error\n", dev
->name
);
858 printk(KERN_WARNING
"%s: Recv. state transition"
859 " error\n", dev
->name
);
862 printk(KERN_WARNING
"%s: Unexpected data error\n",
866 printk(KERN_WARNING
"%s: Link lost error\n",
870 printk(KERN_WARNING
"%s: Framing Error\n",
874 printk(KERN_WARNING
"%s: Flag sync. lost during "
875 "packet\n", dev
->name
);
878 printk(KERN_ERR
"%s: Invalid receive buffer "
879 "address\n", dev
->name
);
880 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
885 printk(KERN_ERR
"%s: Invalid receive descriptor "
886 "address\n", dev
->name
);
887 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
892 printk(KERN_ERR
"%s: Invalid ring block\n",
894 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
899 /* Label packet to be dropped.
900 * Actual dropping occurs in rx
903 * The index of packet we get to drop is
904 * the index of the packet following
905 * the bad packet. -kbf
908 u16 index
= rrpriv
->evt_ring
[eidx
].index
;
909 index
= (index
+ (RX_RING_ENTRIES
- 1)) %
911 rrpriv
->rx_ring
[index
].mode
|=
912 (PACKET_BAD
| PACKET_END
);
916 printk(KERN_WARNING
"%s: Unhandled event 0x%02x\n",
917 dev
->name
, rrpriv
->evt_ring
[eidx
].code
);
919 eidx
= (eidx
+ 1) % EVT_RING_ENTRIES
;
922 rrpriv
->info
->evt_ctrl
.pi
= eidx
;
928 static void rx_int(struct net_device
*dev
, u32 rxlimit
, u32 index
)
930 struct rr_private
*rrpriv
= netdev_priv(dev
);
931 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
934 struct rx_desc
*desc
;
937 desc
= &(rrpriv
->rx_ring
[index
]);
938 pkt_len
= desc
->size
;
940 printk("index %i, rxlimit %i\n", index
, rxlimit
);
941 printk("len %x, mode %x\n", pkt_len
, desc
->mode
);
943 if ( (rrpriv
->rx_ring
[index
].mode
& PACKET_BAD
) == PACKET_BAD
){
944 dev
->stats
.rx_dropped
++;
949 struct sk_buff
*skb
, *rx_skb
;
951 rx_skb
= rrpriv
->rx_skbuff
[index
];
953 if (pkt_len
< PKT_COPY_THRESHOLD
) {
954 skb
= alloc_skb(pkt_len
, GFP_ATOMIC
);
956 printk(KERN_WARNING
"%s: Unable to allocate skb (%i bytes), deferring packet\n", dev
->name
, pkt_len
);
957 dev
->stats
.rx_dropped
++;
960 pci_dma_sync_single_for_cpu(rrpriv
->pci_dev
,
965 skb_put_data(skb
, rx_skb
->data
,
968 pci_dma_sync_single_for_device(rrpriv
->pci_dev
,
974 struct sk_buff
*newskb
;
976 newskb
= alloc_skb(dev
->mtu
+ HIPPI_HLEN
,
981 pci_unmap_single(rrpriv
->pci_dev
,
982 desc
->addr
.addrlo
, dev
->mtu
+
983 HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
985 skb_put(skb
, pkt_len
);
986 rrpriv
->rx_skbuff
[index
] = newskb
;
987 addr
= pci_map_single(rrpriv
->pci_dev
,
989 dev
->mtu
+ HIPPI_HLEN
,
991 set_rraddr(&desc
->addr
, addr
);
993 printk("%s: Out of memory, deferring "
994 "packet\n", dev
->name
);
995 dev
->stats
.rx_dropped
++;
999 skb
->protocol
= hippi_type_trans(skb
, dev
);
1001 netif_rx(skb
); /* send it up */
1003 dev
->stats
.rx_packets
++;
1004 dev
->stats
.rx_bytes
+= pkt_len
;
1008 desc
->size
= dev
->mtu
+ HIPPI_HLEN
;
1010 if ((index
& 7) == 7)
1011 writel(index
, ®s
->IpRxPi
);
1013 index
= (index
+ 1) % RX_RING_ENTRIES
;
1014 } while(index
!= rxlimit
);
1016 rrpriv
->cur_rx
= index
;
1021 static irqreturn_t
rr_interrupt(int irq
, void *dev_id
)
1023 struct rr_private
*rrpriv
;
1024 struct rr_regs __iomem
*regs
;
1025 struct net_device
*dev
= (struct net_device
*)dev_id
;
1026 u32 prodidx
, rxindex
, eidx
, txcsmr
, rxlimit
, txcon
;
1028 rrpriv
= netdev_priv(dev
);
1029 regs
= rrpriv
->regs
;
1031 if (!(readl(®s
->HostCtrl
) & RR_INT
))
1034 spin_lock(&rrpriv
->lock
);
1036 prodidx
= readl(®s
->EvtPrd
);
1037 txcsmr
= (prodidx
>> 8) & 0xff;
1038 rxlimit
= (prodidx
>> 16) & 0xff;
1042 printk("%s: interrupt, prodidx = %i, eidx = %i\n", dev
->name
,
1043 prodidx
, rrpriv
->info
->evt_ctrl
.pi
);
1046 * Order here is important. We must handle events
1047 * before doing anything else in order to catch
1048 * such things as LLRC errors, etc -kbf
1051 eidx
= rrpriv
->info
->evt_ctrl
.pi
;
1052 if (prodidx
!= eidx
)
1053 eidx
= rr_handle_event(dev
, prodidx
, eidx
);
1055 rxindex
= rrpriv
->cur_rx
;
1056 if (rxindex
!= rxlimit
)
1057 rx_int(dev
, rxlimit
, rxindex
);
1059 txcon
= rrpriv
->dirty_tx
;
1060 if (txcsmr
!= txcon
) {
1062 /* Due to occational firmware TX producer/consumer out
1063 * of sync. error need to check entry in ring -kbf
1065 if(rrpriv
->tx_skbuff
[txcon
]){
1066 struct tx_desc
*desc
;
1067 struct sk_buff
*skb
;
1069 desc
= &(rrpriv
->tx_ring
[txcon
]);
1070 skb
= rrpriv
->tx_skbuff
[txcon
];
1072 dev
->stats
.tx_packets
++;
1073 dev
->stats
.tx_bytes
+= skb
->len
;
1075 pci_unmap_single(rrpriv
->pci_dev
,
1076 desc
->addr
.addrlo
, skb
->len
,
1078 dev_kfree_skb_irq(skb
);
1080 rrpriv
->tx_skbuff
[txcon
] = NULL
;
1082 set_rraddr(&rrpriv
->tx_ring
[txcon
].addr
, 0);
1085 txcon
= (txcon
+ 1) % TX_RING_ENTRIES
;
1086 } while (txcsmr
!= txcon
);
1089 rrpriv
->dirty_tx
= txcon
;
1090 if (rrpriv
->tx_full
&& rr_if_busy(dev
) &&
1091 (((rrpriv
->info
->tx_ctrl
.pi
+ 1) % TX_RING_ENTRIES
)
1092 != rrpriv
->dirty_tx
)){
1093 rrpriv
->tx_full
= 0;
1094 netif_wake_queue(dev
);
1098 eidx
|= ((txcsmr
<< 8) | (rxlimit
<< 16));
1099 writel(eidx
, ®s
->EvtCon
);
1102 spin_unlock(&rrpriv
->lock
);
1106 static inline void rr_raz_tx(struct rr_private
*rrpriv
,
1107 struct net_device
*dev
)
1111 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
1112 struct sk_buff
*skb
= rrpriv
->tx_skbuff
[i
];
1115 struct tx_desc
*desc
= &(rrpriv
->tx_ring
[i
]);
1117 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1118 skb
->len
, PCI_DMA_TODEVICE
);
1120 set_rraddr(&desc
->addr
, 0);
1122 rrpriv
->tx_skbuff
[i
] = NULL
;
1128 static inline void rr_raz_rx(struct rr_private
*rrpriv
,
1129 struct net_device
*dev
)
1133 for (i
= 0; i
< RX_RING_ENTRIES
; i
++) {
1134 struct sk_buff
*skb
= rrpriv
->rx_skbuff
[i
];
1137 struct rx_desc
*desc
= &(rrpriv
->rx_ring
[i
]);
1139 pci_unmap_single(rrpriv
->pci_dev
, desc
->addr
.addrlo
,
1140 dev
->mtu
+ HIPPI_HLEN
, PCI_DMA_FROMDEVICE
);
1142 set_rraddr(&desc
->addr
, 0);
1144 rrpriv
->rx_skbuff
[i
] = NULL
;
1149 static void rr_timer(struct timer_list
*t
)
1151 struct rr_private
*rrpriv
= from_timer(rrpriv
, t
, timer
);
1152 struct net_device
*dev
= pci_get_drvdata(rrpriv
->pci_dev
);
1153 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1154 unsigned long flags
;
1156 if (readl(®s
->HostCtrl
) & NIC_HALTED
){
1157 printk("%s: Restarting nic\n", dev
->name
);
1158 memset(rrpriv
->rx_ctrl
, 0, 256 * sizeof(struct ring_ctrl
));
1159 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1162 rr_raz_tx(rrpriv
, dev
);
1163 rr_raz_rx(rrpriv
, dev
);
1165 if (rr_init1(dev
)) {
1166 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1167 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
,
1169 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1172 rrpriv
->timer
.expires
= RUN_AT(5*HZ
);
1173 add_timer(&rrpriv
->timer
);
1177 static int rr_open(struct net_device
*dev
)
1179 struct rr_private
*rrpriv
= netdev_priv(dev
);
1180 struct pci_dev
*pdev
= rrpriv
->pci_dev
;
1181 struct rr_regs __iomem
*regs
;
1183 unsigned long flags
;
1184 dma_addr_t dma_addr
;
1186 regs
= rrpriv
->regs
;
1188 if (rrpriv
->fw_rev
< 0x00020000) {
1189 printk(KERN_WARNING
"%s: trying to configure device with "
1190 "obsolete firmware\n", dev
->name
);
1195 rrpriv
->rx_ctrl
= pci_alloc_consistent(pdev
,
1196 256 * sizeof(struct ring_ctrl
),
1198 if (!rrpriv
->rx_ctrl
) {
1202 rrpriv
->rx_ctrl_dma
= dma_addr
;
1203 memset(rrpriv
->rx_ctrl
, 0, 256*sizeof(struct ring_ctrl
));
1205 rrpriv
->info
= pci_alloc_consistent(pdev
, sizeof(struct rr_info
),
1207 if (!rrpriv
->info
) {
1211 rrpriv
->info_dma
= dma_addr
;
1212 memset(rrpriv
->info
, 0, sizeof(struct rr_info
));
1215 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1216 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1217 readl(®s
->HostCtrl
);
1218 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1220 if (request_irq(pdev
->irq
, rr_interrupt
, IRQF_SHARED
, dev
->name
, dev
)) {
1221 printk(KERN_WARNING
"%s: Requested IRQ %d is busy\n",
1222 dev
->name
, pdev
->irq
);
1227 if ((ecode
= rr_init1(dev
)))
1230 /* Set the timer to switch to check for link beat and perhaps switch
1231 to an alternate media type. */
1232 timer_setup(&rrpriv
->timer
, rr_timer
, 0);
1233 rrpriv
->timer
.expires
= RUN_AT(5*HZ
); /* 5 sec. watchdog */
1234 add_timer(&rrpriv
->timer
);
1236 netif_start_queue(dev
);
1241 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1242 writel(readl(®s
->HostCtrl
)|HALT_NIC
|RR_CLEAR_INT
, ®s
->HostCtrl
);
1243 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1246 pci_free_consistent(pdev
, sizeof(struct rr_info
), rrpriv
->info
,
1248 rrpriv
->info
= NULL
;
1250 if (rrpriv
->rx_ctrl
) {
1251 pci_free_consistent(pdev
, sizeof(struct ring_ctrl
),
1252 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1253 rrpriv
->rx_ctrl
= NULL
;
1256 netif_stop_queue(dev
);
1262 static void rr_dump(struct net_device
*dev
)
1264 struct rr_private
*rrpriv
;
1265 struct rr_regs __iomem
*regs
;
1270 rrpriv
= netdev_priv(dev
);
1271 regs
= rrpriv
->regs
;
1273 printk("%s: dumping NIC TX rings\n", dev
->name
);
1275 printk("RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1276 readl(®s
->RxPrd
), readl(®s
->TxPrd
),
1277 readl(®s
->EvtPrd
), readl(®s
->TxPi
),
1278 rrpriv
->info
->tx_ctrl
.pi
);
1280 printk("Error code 0x%x\n", readl(®s
->Fail1
));
1282 index
= (((readl(®s
->EvtPrd
) >> 8) & 0xff) - 1) % TX_RING_ENTRIES
;
1283 cons
= rrpriv
->dirty_tx
;
1284 printk("TX ring index %i, TX consumer %i\n",
1287 if (rrpriv
->tx_skbuff
[index
]){
1288 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[index
]->len
);
1289 printk("skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index
, len
, rrpriv
->tx_ring
[index
].size
);
1290 for (i
= 0; i
< len
; i
++){
1293 printk("%02x ", (unsigned char) rrpriv
->tx_skbuff
[index
]->data
[i
]);
1298 if (rrpriv
->tx_skbuff
[cons
]){
1299 len
= min_t(int, 0x80, rrpriv
->tx_skbuff
[cons
]->len
);
1300 printk("skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons
, len
, rrpriv
->tx_skbuff
[cons
]->len
);
1301 printk("mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %08lx, truesize 0x%x\n",
1302 rrpriv
->tx_ring
[cons
].mode
,
1303 rrpriv
->tx_ring
[cons
].size
,
1304 (unsigned long long) rrpriv
->tx_ring
[cons
].addr
.addrlo
,
1305 (unsigned long)rrpriv
->tx_skbuff
[cons
]->data
,
1306 (unsigned int)rrpriv
->tx_skbuff
[cons
]->truesize
);
1307 for (i
= 0; i
< len
; i
++){
1310 printk("%02x ", (unsigned char)rrpriv
->tx_ring
[cons
].size
);
1315 printk("dumping TX ring info:\n");
1316 for (i
= 0; i
< TX_RING_ENTRIES
; i
++)
1317 printk("mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1318 rrpriv
->tx_ring
[i
].mode
,
1319 rrpriv
->tx_ring
[i
].size
,
1320 (unsigned long long) rrpriv
->tx_ring
[i
].addr
.addrlo
);
1325 static int rr_close(struct net_device
*dev
)
1327 struct rr_private
*rrpriv
= netdev_priv(dev
);
1328 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1329 struct pci_dev
*pdev
= rrpriv
->pci_dev
;
1330 unsigned long flags
;
1334 netif_stop_queue(dev
);
1338 * Lock to make sure we are not cleaning up while another CPU
1339 * is handling interrupts.
1341 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1343 tmp
= readl(®s
->HostCtrl
);
1344 if (tmp
& NIC_HALTED
){
1345 printk("%s: NIC already halted\n", dev
->name
);
1348 tmp
|= HALT_NIC
| RR_CLEAR_INT
;
1349 writel(tmp
, ®s
->HostCtrl
);
1350 readl(®s
->HostCtrl
);
1353 rrpriv
->fw_running
= 0;
1355 del_timer_sync(&rrpriv
->timer
);
1357 writel(0, ®s
->TxPi
);
1358 writel(0, ®s
->IpRxPi
);
1360 writel(0, ®s
->EvtCon
);
1361 writel(0, ®s
->EvtPrd
);
1363 for (i
= 0; i
< CMD_RING_ENTRIES
; i
++)
1364 writel(0, ®s
->CmdRing
[i
]);
1366 rrpriv
->info
->tx_ctrl
.entries
= 0;
1367 rrpriv
->info
->cmd_ctrl
.pi
= 0;
1368 rrpriv
->info
->evt_ctrl
.pi
= 0;
1369 rrpriv
->rx_ctrl
[4].entries
= 0;
1371 rr_raz_tx(rrpriv
, dev
);
1372 rr_raz_rx(rrpriv
, dev
);
1374 pci_free_consistent(pdev
, 256 * sizeof(struct ring_ctrl
),
1375 rrpriv
->rx_ctrl
, rrpriv
->rx_ctrl_dma
);
1376 rrpriv
->rx_ctrl
= NULL
;
1378 pci_free_consistent(pdev
, sizeof(struct rr_info
), rrpriv
->info
,
1380 rrpriv
->info
= NULL
;
1382 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1383 free_irq(pdev
->irq
, dev
);
1389 static netdev_tx_t
rr_start_xmit(struct sk_buff
*skb
,
1390 struct net_device
*dev
)
1392 struct rr_private
*rrpriv
= netdev_priv(dev
);
1393 struct rr_regs __iomem
*regs
= rrpriv
->regs
;
1394 struct hippi_cb
*hcb
= (struct hippi_cb
*) skb
->cb
;
1395 struct ring_ctrl
*txctrl
;
1396 unsigned long flags
;
1397 u32 index
, len
= skb
->len
;
1399 struct sk_buff
*new_skb
;
1401 if (readl(®s
->Mode
) & FATAL_ERR
)
1402 printk("error codes Fail1 %02x, Fail2 %02x\n",
1403 readl(®s
->Fail1
), readl(®s
->Fail2
));
1406 * We probably need to deal with tbusy here to prevent overruns.
1409 if (skb_headroom(skb
) < 8){
1410 printk("incoming skb too small - reallocating\n");
1411 if (!(new_skb
= dev_alloc_skb(len
+ 8))) {
1413 netif_wake_queue(dev
);
1414 return NETDEV_TX_OK
;
1416 skb_reserve(new_skb
, 8);
1417 skb_put(new_skb
, len
);
1418 skb_copy_from_linear_data(skb
, new_skb
->data
, len
);
1423 ifield
= skb_push(skb
, 8);
1426 ifield
[1] = hcb
->ifield
;
1429 * We don't need the lock before we are actually going to start
1430 * fiddling with the control blocks.
1432 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1434 txctrl
= &rrpriv
->info
->tx_ctrl
;
1438 rrpriv
->tx_skbuff
[index
] = skb
;
1439 set_rraddr(&rrpriv
->tx_ring
[index
].addr
, pci_map_single(
1440 rrpriv
->pci_dev
, skb
->data
, len
+ 8, PCI_DMA_TODEVICE
));
1441 rrpriv
->tx_ring
[index
].size
= len
+ 8; /* include IFIELD */
1442 rrpriv
->tx_ring
[index
].mode
= PACKET_START
| PACKET_END
;
1443 txctrl
->pi
= (index
+ 1) % TX_RING_ENTRIES
;
1445 writel(txctrl
->pi
, ®s
->TxPi
);
1447 if (txctrl
->pi
== rrpriv
->dirty_tx
){
1448 rrpriv
->tx_full
= 1;
1449 netif_stop_queue(dev
);
1452 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1454 return NETDEV_TX_OK
;
1459 * Read the firmware out of the EEPROM and put it into the SRAM
1460 * (or from user space - later)
1462 * This operation requires the NIC to be halted and is performed with
1463 * interrupts disabled and with the spinlock hold.
1465 static int rr_load_firmware(struct net_device
*dev
)
1467 struct rr_private
*rrpriv
;
1468 struct rr_regs __iomem
*regs
;
1469 size_t eptr
, segptr
;
1471 u32 localctrl
, sptr
, len
, tmp
;
1472 u32 p2len
, p2size
, nr_seg
, revision
, io
, sram_size
;
1474 rrpriv
= netdev_priv(dev
);
1475 regs
= rrpriv
->regs
;
1477 if (dev
->flags
& IFF_UP
)
1480 if (!(readl(®s
->HostCtrl
) & NIC_HALTED
)){
1481 printk("%s: Trying to load firmware to a running NIC.\n",
1486 localctrl
= readl(®s
->LocalCtrl
);
1487 writel(0, ®s
->LocalCtrl
);
1489 writel(0, ®s
->EvtPrd
);
1490 writel(0, ®s
->RxPrd
);
1491 writel(0, ®s
->TxPrd
);
1494 * First wipe the entire SRAM, otherwise we might run into all
1495 * kinds of trouble ... sigh, this took almost all afternoon
1498 io
= readl(®s
->ExtIo
);
1499 writel(0, ®s
->ExtIo
);
1500 sram_size
= rr_read_eeprom_word(rrpriv
, 8);
1502 for (i
= 200; i
< sram_size
/ 4; i
++){
1503 writel(i
* 4, ®s
->WinBase
);
1505 writel(0, ®s
->WinData
);
1508 writel(io
, ®s
->ExtIo
);
1511 eptr
= rr_read_eeprom_word(rrpriv
,
1512 offsetof(struct eeprom
, rncd_info
.AddrRunCodeSegs
));
1513 eptr
= ((eptr
& 0x1fffff) >> 3);
1515 p2len
= rr_read_eeprom_word(rrpriv
, 0x83*4);
1516 p2len
= (p2len
<< 2);
1517 p2size
= rr_read_eeprom_word(rrpriv
, 0x84*4);
1518 p2size
= ((p2size
& 0x1fffff) >> 3);
1520 if ((eptr
< p2size
) || (eptr
> (p2size
+ p2len
))){
1521 printk("%s: eptr is invalid\n", dev
->name
);
1525 revision
= rr_read_eeprom_word(rrpriv
,
1526 offsetof(struct eeprom
, manf
.HeaderFmt
));
1529 printk("%s: invalid firmware format (%i)\n",
1530 dev
->name
, revision
);
1534 nr_seg
= rr_read_eeprom_word(rrpriv
, eptr
);
1537 printk("%s: nr_seg %i\n", dev
->name
, nr_seg
);
1540 for (i
= 0; i
< nr_seg
; i
++){
1541 sptr
= rr_read_eeprom_word(rrpriv
, eptr
);
1543 len
= rr_read_eeprom_word(rrpriv
, eptr
);
1545 segptr
= rr_read_eeprom_word(rrpriv
, eptr
);
1546 segptr
= ((segptr
& 0x1fffff) >> 3);
1549 printk("%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1550 dev
->name
, i
, sptr
, len
, segptr
);
1552 for (j
= 0; j
< len
; j
++){
1553 tmp
= rr_read_eeprom_word(rrpriv
, segptr
);
1554 writel(sptr
, ®s
->WinBase
);
1556 writel(tmp
, ®s
->WinData
);
1564 writel(localctrl
, ®s
->LocalCtrl
);
1570 static int rr_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1572 struct rr_private
*rrpriv
;
1573 unsigned char *image
, *oldimage
;
1574 unsigned long flags
;
1576 int error
= -EOPNOTSUPP
;
1578 rrpriv
= netdev_priv(dev
);
1582 if (!capable(CAP_SYS_RAWIO
)){
1586 image
= kmalloc_array(EEPROM_WORDS
, sizeof(u32
), GFP_KERNEL
);
1590 if (rrpriv
->fw_running
){
1591 printk("%s: Firmware already running\n", dev
->name
);
1596 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1597 i
= rr_read_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1598 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1599 if (i
!= EEPROM_BYTES
){
1600 printk(KERN_ERR
"%s: Error reading EEPROM\n",
1605 error
= copy_to_user(rq
->ifr_data
, image
, EEPROM_BYTES
);
1613 if (!capable(CAP_SYS_RAWIO
)){
1617 image
= memdup_user(rq
->ifr_data
, EEPROM_BYTES
);
1619 return PTR_ERR(image
);
1621 oldimage
= kmalloc(EEPROM_BYTES
, GFP_KERNEL
);
1627 if (rrpriv
->fw_running
){
1628 printk("%s: Firmware already running\n", dev
->name
);
1633 printk("%s: Updating EEPROM firmware\n", dev
->name
);
1635 spin_lock_irqsave(&rrpriv
->lock
, flags
);
1636 error
= write_eeprom(rrpriv
, 0, image
, EEPROM_BYTES
);
1638 printk(KERN_ERR
"%s: Error writing EEPROM\n",
1641 i
= rr_read_eeprom(rrpriv
, 0, oldimage
, EEPROM_BYTES
);
1642 spin_unlock_irqrestore(&rrpriv
->lock
, flags
);
1644 if (i
!= EEPROM_BYTES
)
1645 printk(KERN_ERR
"%s: Error reading back EEPROM "
1646 "image\n", dev
->name
);
1648 error
= memcmp(image
, oldimage
, EEPROM_BYTES
);
1650 printk(KERN_ERR
"%s: Error verifying EEPROM image\n",
1660 return put_user(0x52523032, (int __user
*)rq
->ifr_data
);
1666 static const struct pci_device_id rr_pci_tbl
[] = {
1667 { PCI_VENDOR_ID_ESSENTIAL
, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER
,
1668 PCI_ANY_ID
, PCI_ANY_ID
, },
1671 MODULE_DEVICE_TABLE(pci
, rr_pci_tbl
);
1673 static struct pci_driver rr_driver
= {
1675 .id_table
= rr_pci_tbl
,
1676 .probe
= rr_init_one
,
1677 .remove
= rr_remove_one
,
1680 module_pci_driver(rr_driver
);