Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* mvme147.c : the Linux/mvme147/lance ethernet driver |
| 2 | * |
| 3 | * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk> |
| 4 | * Based on the Sun Lance driver and the NetBSD HP Lance driver |
| 5 | * Uses the generic 7990.c LANCE code. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/ioport.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/errno.h> |
| 18 | /* Used for the temporal inet entries and routing */ |
| 19 | #include <linux/socket.h> |
| 20 | #include <linux/route.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/etherdevice.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | |
| 25 | #include <asm/system.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/pgtable.h> |
| 28 | #include <asm/mvme147hw.h> |
| 29 | |
| 30 | /* We have 16834 bytes of RAM for the init block and buffers. This places |
| 31 | * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx |
| 32 | * buffers and 2 Tx buffers. |
| 33 | */ |
| 34 | #define LANCE_LOG_TX_BUFFERS 1 |
| 35 | #define LANCE_LOG_RX_BUFFERS 3 |
| 36 | |
| 37 | #include "7990.h" /* use generic LANCE code */ |
| 38 | |
| 39 | /* Our private data structure */ |
| 40 | struct m147lance_private { |
| 41 | struct lance_private lance; |
| 42 | unsigned long ram; |
| 43 | }; |
| 44 | |
| 45 | /* function prototypes... This is easy because all the grot is in the |
| 46 | * generic LANCE support. All we have to support is probing for boards, |
| 47 | * plus board-specific init, open and close actions. |
| 48 | * Oh, and we need to tell the generic code how to read and write LANCE registers... |
| 49 | */ |
| 50 | static int m147lance_open(struct net_device *dev); |
| 51 | static int m147lance_close(struct net_device *dev); |
| 52 | static void m147lance_writerap(struct lance_private *lp, unsigned short value); |
| 53 | static void m147lance_writerdp(struct lance_private *lp, unsigned short value); |
| 54 | static unsigned short m147lance_readrdp(struct lance_private *lp); |
| 55 | |
| 56 | typedef void (*writerap_t)(void *, unsigned short); |
| 57 | typedef void (*writerdp_t)(void *, unsigned short); |
| 58 | typedef unsigned short (*readrdp_t)(void *); |
| 59 | |
| 60 | /* Initialise the one and only on-board 7990 */ |
| 61 | struct net_device * __init mvme147lance_probe(int unit) |
| 62 | { |
| 63 | struct net_device *dev; |
| 64 | static int called; |
| 65 | static const char name[] = "MVME147 LANCE"; |
| 66 | struct m147lance_private *lp; |
| 67 | u_long *addr; |
| 68 | u_long address; |
| 69 | int err; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 70 | DECLARE_MAC_BUF(mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | if (!MACH_IS_MVME147 || called) |
| 73 | return ERR_PTR(-ENODEV); |
| 74 | called++; |
| 75 | |
| 76 | dev = alloc_etherdev(sizeof(struct m147lance_private)); |
| 77 | if (!dev) |
| 78 | return ERR_PTR(-ENOMEM); |
| 79 | |
| 80 | if (unit >= 0) |
| 81 | sprintf(dev->name, "eth%d", unit); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* Fill the dev fields */ |
| 84 | dev->base_addr = (unsigned long)MVME147_LANCE_BASE; |
| 85 | dev->open = &m147lance_open; |
| 86 | dev->stop = &m147lance_close; |
| 87 | dev->hard_start_xmit = &lance_start_xmit; |
| 88 | dev->get_stats = &lance_get_stats; |
| 89 | dev->set_multicast_list = &lance_set_multicast; |
| 90 | dev->tx_timeout = &lance_tx_timeout; |
| 91 | dev->dma = 0; |
| 92 | |
| 93 | addr=(u_long *)ETHERNET_ADDRESS; |
| 94 | address = *addr; |
| 95 | dev->dev_addr[0]=0x08; |
| 96 | dev->dev_addr[1]=0x00; |
| 97 | dev->dev_addr[2]=0x3e; |
| 98 | address=address>>8; |
| 99 | dev->dev_addr[5]=address&0xff; |
| 100 | address=address>>8; |
| 101 | dev->dev_addr[4]=address&0xff; |
| 102 | address=address>>8; |
| 103 | dev->dev_addr[3]=address&0xff; |
| 104 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 105 | printk("%s: MVME147 at 0x%08lx, irq %d, " |
| 106 | "Hardware Address %s\n", |
| 107 | dev->name, dev->base_addr, MVME147_LANCE_IRQ, |
| 108 | print_mac(mac, dev->dev_addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | lp = (struct m147lance_private *)dev->priv; |
| 111 | lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */ |
| 112 | if (!lp->ram) |
| 113 | { |
| 114 | printk("%s: No memory for LANCE buffers\n", dev->name); |
| 115 | free_netdev(dev); |
| 116 | return ERR_PTR(-ENOMEM); |
| 117 | } |
| 118 | |
| 119 | lp->lance.name = (char*)name; /* discards const, shut up gcc */ |
| 120 | lp->lance.base = dev->base_addr; |
| 121 | lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */ |
| 122 | lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */ |
| 123 | lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */ |
| 124 | lp->lance.irq = MVME147_LANCE_IRQ; |
| 125 | lp->lance.writerap = (writerap_t)m147lance_writerap; |
| 126 | lp->lance.writerdp = (writerdp_t)m147lance_writerdp; |
| 127 | lp->lance.readrdp = (readrdp_t)m147lance_readrdp; |
| 128 | lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; |
| 129 | lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; |
| 130 | lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK; |
| 131 | lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK; |
| 132 | |
| 133 | err = register_netdev(dev); |
| 134 | if (err) { |
| 135 | free_pages(lp->ram, 3); |
| 136 | free_netdev(dev); |
| 137 | return ERR_PTR(err); |
| 138 | } |
| 139 | |
| 140 | return dev; |
| 141 | } |
| 142 | |
| 143 | static void m147lance_writerap(struct lance_private *lp, unsigned short value) |
| 144 | { |
| 145 | out_be16(lp->base + LANCE_RAP, value); |
| 146 | } |
| 147 | |
| 148 | static void m147lance_writerdp(struct lance_private *lp, unsigned short value) |
| 149 | { |
| 150 | out_be16(lp->base + LANCE_RDP, value); |
| 151 | } |
| 152 | |
| 153 | static unsigned short m147lance_readrdp(struct lance_private *lp) |
| 154 | { |
| 155 | return in_be16(lp->base + LANCE_RDP); |
| 156 | } |
| 157 | |
| 158 | static int m147lance_open(struct net_device *dev) |
| 159 | { |
| 160 | int status; |
| 161 | |
| 162 | status = lance_open(dev); /* call generic lance open code */ |
| 163 | if (status) |
| 164 | return status; |
| 165 | /* enable interrupts at board level. */ |
| 166 | m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */ |
| 167 | m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */ |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int m147lance_close(struct net_device *dev) |
| 173 | { |
| 174 | /* disable interrupts at boardlevel */ |
| 175 | m147_pcc->lan_cntrl=0x0; /* disable interrupts */ |
| 176 | lance_close(dev); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | #ifdef MODULE |
| 181 | MODULE_LICENSE("GPL"); |
| 182 | |
| 183 | static struct net_device *dev_mvme147_lance; |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 184 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | dev_mvme147_lance = mvme147lance_probe(-1); |
| 187 | if (IS_ERR(dev_mvme147_lance)) |
| 188 | return PTR_ERR(dev_mvme147_lance); |
| 189 | return 0; |
| 190 | } |
| 191 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 192 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | struct m147lance_private *lp = dev_mvme147_lance->priv; |
| 195 | unregister_netdev(dev_mvme147_lance); |
| 196 | free_pages(lp->ram, 3); |
| 197 | free_netdev(dev_mvme147_lance); |
| 198 | } |
| 199 | |
| 200 | #endif /* MODULE */ |