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>
35 #include <linux/pci.h>
36 #include <linux/kernel.h>
37 #include <linux/netdevice.h>
43 #include <linux/slab.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))
70 .ndo_do_ioctl = rr_ioctl,
71 .ndo_start_xmit = rr_start_xmit,
95 static int version_disp;
112 rrpriv = netdev_priv(dev);
120 pci_set_drvdata(pdev, dev);
137 if (pci_latency <= 0x58){
145 "at 0x%llx, irq %i, PCI latency %i\n", dev->
name,
147 pdev->
irq, pci_latency);
152 rrpriv->
regs = pci_iomap(pdev, 0, 0x1000);
155 "RoadRunner will be disabled.\n", dev->
name);
192 &rrpriv->
regs->HostCtrl);
216 pci_set_drvdata(pdev,
NULL);
226 struct net_device *dev = pci_get_drvdata(pdev);
245 pci_set_drvdata(pdev,
NULL);
265 printk(
"issuing command for halted NIC, code 0x%x, "
268 printk(
"error codes Fail1 %02x, Fail2 %02x\n",
272 idx = rrpriv->
info->cmd_ctrl.pi;
278 rrpriv->
info->cmd_ctrl.pi =
idx;
297 rrpriv = netdev_priv(dev);
300 rr_load_firmware(dev);
322 #if (BITS_PER_LONG == 64) && defined __LITTLE_ENDIAN
324 #elif (BITS_PER_LONG == 64)
369 rrpriv->
info->evt_ctrl.pi = 0;
380 start_pc = rr_read_eeprom_word(rrpriv,
384 printk(
"%s: Executing firmware at address 0x%06x\n",
385 dev->
name, start_pc);
388 writel(start_pc + 0x800, ®s->
Pc);
402 static unsigned int rr_read_eeprom(
struct rr_private *rrpriv,
418 for (i = 0; i <
length; i++){
442 if ((rr_read_eeprom(rrpriv, offset,
443 (
unsigned char *)&word, 4) == 4))
454 static unsigned int write_eeprom(
struct rr_private *rrpriv,
455 unsigned long offset,
457 unsigned long length)
468 for (i = 0; i <
length; i++){
488 printk(
"data mismatch: %08x, "
489 "WinData %08x\n", data,
512 rrpriv = netdev_priv(dev);
517 if (rev > 0x00020024)
518 printk(
" Firmware revision: %i.%i.%i\n", (rev >> 16),
519 ((rev >> 8) & 0xff), (rev & 0xff));
520 else if (rev >= 0x00020000) {
521 printk(
" Firmware revision: %i.%i.%i (2.0.37 or "
522 "later is recommended)\n", (rev >> 16),
523 ((rev >> 8) & 0xff), (rev & 0xff));
525 printk(
" Firmware revision too old: %i.%i.%i, please "
526 "upgrade to 2.0.37 or later.\n",
527 (rev >> 16), ((rev >> 8) & 0xff), (rev & 0xff));
550 sram_size = rr_read_eeprom_word(rrpriv, 8);
551 printk(
" SRAM size 0x%06x\n", sram_size);
561 unsigned long myjif,
flags;
567 rrpriv = netdev_priv(dev);
577 printk(
"%s: Parity error halting NIC - this is serious!\n",
579 spin_unlock_irqrestore(&rrpriv->
lock, flags);
585 set_infoaddr(regs, rrpriv->
info_dma);
587 rrpriv->
info->evt_ctrl.entry_size =
sizeof(
struct event);
589 rrpriv->
info->evt_ctrl.mode = 0;
590 rrpriv->
info->evt_ctrl.pi = 0;
593 rrpriv->
info->cmd_ctrl.entry_size =
sizeof(
struct cmd);
595 rrpriv->
info->cmd_ctrl.mode = 0;
596 rrpriv->
info->cmd_ctrl.pi = 15;
604 set_rraddr(&rrpriv->
tx_ring[i].addr, 0);
607 rrpriv->
info->tx_ctrl.entry_size =
sizeof(
struct tx_desc);
609 rrpriv->
info->tx_ctrl.mode = 0;
610 rrpriv->
info->tx_ctrl.pi = 0;
642 spin_unlock_irqrestore(&rrpriv->
lock, flags);
652 "for receive ring - halting NIC\n", dev->
name);
663 if ((((
unsigned long)skb->
data) & 0xfff) > ~65320)
664 printk(
"skb alloc error\n");
666 set_rraddr(&rrpriv->
rx_ring[i].addr, addr);
686 rr_issue_cmd(rrpriv, &cmd);
695 netif_start_queue(dev);
708 pci_unmap_single(rrpriv->
pci_dev,
709 rrpriv->
rx_ring[i].addr.addrlo,
713 set_rraddr(&rrpriv->
rx_ring[i].addr, 0);
733 rrpriv = netdev_priv(dev);
736 while (prodidx != eidx){
737 switch (rrpriv->
evt_ring[eidx].code){
741 "up and running\n", dev->
name,
742 (tmp >> 16), ((tmp >> 8) & 0xff), (tmp & 0xff));
781 dev->
stats.tx_aborted_errors++;
790 dev->
stats.tx_aborted_errors++;
806 dev->
stats.tx_aborted_errors++;
849 "error\n", dev->
name);
857 "error\n", dev->
name);
861 " error\n", dev->
name);
877 "packet\n", dev->
name);
881 "address\n", dev->
name);
888 "address\n", dev->
name);
911 index = (index + (RX_RING_ENTRIES - 1)) %
924 rrpriv->
info->evt_ctrl.pi = eidx;
940 pkt_len = desc->
size;
942 printk(
"index %i, rxlimit %i\n", index, rxlimit);
943 printk(
"len %x, mode %x\n", pkt_len, desc->
mode);
946 dev->
stats.rx_dropped++;
959 dev->
stats.rx_dropped++;
962 pci_dma_sync_single_for_cpu(rrpriv->
pci_dev,
968 rx_skb->
data, pkt_len);
970 pci_dma_sync_single_for_device(rrpriv->
pci_dev,
983 pci_unmap_single(rrpriv->
pci_dev,
989 addr = pci_map_single(rrpriv->
pci_dev,
993 set_rraddr(&desc->
addr, addr);
995 printk(
"%s: Out of memory, deferring "
996 "packet\n", dev->
name);
997 dev->
stats.rx_dropped++;
1005 dev->
stats.rx_packets++;
1012 if ((index & 7) == 7)
1015 index = (index + 1) % RX_RING_ENTRIES;
1016 }
while(index != rxlimit);
1028 u32 prodidx, rxindex, eidx, txcsmr, rxlimit, txcon;
1030 rrpriv = netdev_priv(dev);
1031 regs = rrpriv->
regs;
1036 spin_lock(&rrpriv->
lock);
1039 txcsmr = (prodidx >> 8) & 0xff;
1040 rxlimit = (prodidx >> 16) & 0xff;
1044 printk(
"%s: interrupt, prodidx = %i, eidx = %i\n", dev->
name,
1045 prodidx, rrpriv->
info->evt_ctrl.pi);
1053 eidx = rrpriv->
info->evt_ctrl.pi;
1054 if (prodidx != eidx)
1055 eidx = rr_handle_event(dev, prodidx, eidx);
1057 rxindex = rrpriv->
cur_rx;
1058 if (rxindex != rxlimit)
1059 rx_int(dev, rxlimit, rxindex);
1062 if (txcsmr != txcon) {
1071 desc = &(rrpriv->
tx_ring[txcon]);
1074 dev->
stats.tx_packets++;
1077 pci_unmap_single(rrpriv->
pci_dev,
1084 set_rraddr(&rrpriv->
tx_ring[txcon].addr, 0);
1087 txcon = (txcon + 1) % TX_RING_ENTRIES;
1088 }
while (txcsmr != txcon);
1093 (((rrpriv->
info->tx_ctrl.pi + 1) % TX_RING_ENTRIES)
1096 netif_wake_queue(dev);
1100 eidx |= ((txcsmr << 8) | (rxlimit << 16));
1104 spin_unlock(&rrpriv->
lock);
1108 static inline void rr_raz_tx(
struct rr_private *rrpriv,
1119 pci_unmap_single(rrpriv->
pci_dev, desc->
addr.addrlo,
1122 set_rraddr(&desc->
addr, 0);
1130 static inline void rr_raz_rx(
struct rr_private *rrpriv,
1141 pci_unmap_single(rrpriv->
pci_dev, desc->
addr.addrlo,
1144 set_rraddr(&desc->
addr, 0);
1151 static void rr_timer(
unsigned long data)
1154 struct rr_private *rrpriv = netdev_priv(dev);
1156 unsigned long flags;
1164 rr_raz_tx(rrpriv, dev);
1165 rr_raz_rx(rrpriv, dev);
1167 if (rr_init1(dev)) {
1171 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1181 struct rr_private *rrpriv = netdev_priv(dev);
1185 unsigned long flags;
1188 regs = rrpriv->
regs;
1190 if (rrpriv->
fw_rev < 0x00020000) {
1192 "obsolete firmware\n", dev->
name);
1209 if (!rrpriv->
info) {
1220 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1229 if ((ecode = rr_init1(dev)))
1236 rrpriv->
timer.data = (
unsigned long)dev;
1237 rrpriv->
timer.function = rr_timer;
1240 netif_start_queue(dev);
1247 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1260 netif_stop_queue(dev);
1274 rrpriv = netdev_priv(dev);
1275 regs = rrpriv->
regs;
1277 printk(
"%s: dumping NIC TX rings\n", dev->
name);
1279 printk(
"RxPrd %08x, TxPrd %02x, EvtPrd %08x, TxPi %02x, TxCtrlPi %02x\n",
1282 rrpriv->
info->tx_ctrl.pi);
1286 index = (((
readl(®s->
EvtPrd) >> 8) & 0xff) - 1) % TX_RING_ENTRIES;
1288 printk(
"TX ring index %i, TX consumer %i\n",
1293 printk(
"skbuff for index %i is valid - dumping data (0x%x bytes - DMA len 0x%x)\n", index, len, rrpriv->
tx_ring[index].size);
1294 for (i = 0; i < len; i++){
1304 printk(
"skbuff for cons %i is valid - dumping data (0x%x bytes - skbuff len 0x%x)\n", cons, len, rrpriv->
tx_skbuff[cons]->len);
1305 printk(
"mode 0x%x, size 0x%x,\n phys %08Lx, skbuff-addr %08lx, truesize 0x%x\n",
1308 (
unsigned long long) rrpriv->
tx_ring[cons].addr.addrlo,
1309 (
unsigned long)rrpriv->
tx_skbuff[cons]->data,
1310 (
unsigned int)rrpriv->
tx_skbuff[cons]->truesize);
1311 for (i = 0; i < len; i++){
1319 printk(
"dumping TX ring info:\n");
1321 printk(
"mode 0x%x, size 0x%x, phys-addr %08Lx\n",
1324 (
unsigned long long) rrpriv->
tx_ring[i].addr.addrlo);
1331 struct rr_private *rrpriv = netdev_priv(dev);
1334 unsigned long flags;
1338 netif_stop_queue(dev);
1349 printk(
"%s: NIC already halted\n", dev->
name);
1370 rrpriv->
info->tx_ctrl.entries = 0;
1371 rrpriv->
info->cmd_ctrl.pi = 0;
1372 rrpriv->
info->evt_ctrl.pi = 0;
1373 rrpriv->
rx_ctrl[4].entries = 0;
1375 rr_raz_tx(rrpriv, dev);
1376 rr_raz_rx(rrpriv, dev);
1387 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1396 struct rr_private *rrpriv = netdev_priv(dev);
1398 struct hippi_cb *hcb = (
struct hippi_cb *) skb->cb;
1400 unsigned long flags;
1401 u32 index, len = skb->
len;
1406 printk(
"error codes Fail1 %02x, Fail2 %02x\n",
1413 if (skb_headroom(skb) < 8){
1414 printk(
"incoming skb too small - reallocating\n");
1415 if (!(new_skb = dev_alloc_skb(len + 8))) {
1417 netif_wake_queue(dev);
1420 skb_reserve(new_skb, 8);
1422 skb_copy_from_linear_data(skb, new_skb->
data, len);
1430 ifield[1] = hcb->ifield;
1438 txctrl = &rrpriv->
info->tx_ctrl;
1443 set_rraddr(&rrpriv->
tx_ring[index].addr, pci_map_single(
1447 txctrl->pi = (index + 1) % TX_RING_ENTRIES;
1451 if (txctrl->pi == rrpriv->
dirty_tx){
1453 netif_stop_queue(dev);
1456 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1469 static int rr_load_firmware(
struct net_device *dev)
1473 size_t eptr, segptr;
1475 u32 localctrl, sptr, len,
tmp;
1478 rrpriv = netdev_priv(dev);
1479 regs = rrpriv->
regs;
1485 printk(
"%s: Trying to load firmware to a running NIC.\n",
1504 sram_size = rr_read_eeprom_word(rrpriv, 8);
1506 for (i = 200; i < sram_size / 4; i++){
1515 eptr = rr_read_eeprom_word(rrpriv,
1517 eptr = ((eptr & 0x1fffff) >> 3);
1519 p2len = rr_read_eeprom_word(rrpriv, 0x83*4);
1520 p2len = (p2len << 2);
1521 p2size = rr_read_eeprom_word(rrpriv, 0x84*4);
1522 p2size = ((p2size & 0x1fffff) >> 3);
1524 if ((eptr < p2size) || (eptr > (p2size + p2len))){
1529 revision = rr_read_eeprom_word(rrpriv,
1533 printk(
"%s: invalid firmware format (%i)\n",
1534 dev->
name, revision);
1538 nr_seg = rr_read_eeprom_word(rrpriv, eptr);
1541 printk(
"%s: nr_seg %i\n", dev->
name, nr_seg);
1544 for (i = 0; i < nr_seg; i++){
1545 sptr = rr_read_eeprom_word(rrpriv, eptr);
1547 len = rr_read_eeprom_word(rrpriv, eptr);
1549 segptr = rr_read_eeprom_word(rrpriv, eptr);
1550 segptr = ((segptr & 0x1fffff) >> 3);
1553 printk(
"%s: segment %i, sram address %06x, length %04x, segptr %06x\n",
1554 dev->
name, i, sptr, len, segptr);
1556 for (j = 0; j < len; j++){
1557 tmp = rr_read_eeprom_word(rrpriv, segptr);
1577 unsigned char *
image, *oldimage;
1578 unsigned long flags;
1582 rrpriv = netdev_priv(dev);
1595 printk(
"%s: Firmware already running\n", dev->
name);
1602 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1623 if (!image || !oldimage) {
1635 printk(
"%s: Firmware already running\n", dev->
name);
1640 printk(
"%s: Updating EEPROM firmware\n", dev->
name);
1649 spin_unlock_irqrestore(&rrpriv->
lock, flags);
1653 "image\n", dev->
name);
1667 return put_user(0x52523032, (
int __user *)rq->ifr_data);
1682 .id_table = rr_pci_tbl,
1683 .probe = rr_init_one,
1687 static int __init rr_init_module(
void)
1689 return pci_register_driver(&rr_driver);
1692 static void __exit rr_cleanup_module(
void)