1 /* mvme147.c : the Linux/mvme147/lance ethernet driver
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.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/types.h>
12 #include <linux/interrupt.h>
13 #include <linux/ptrace.h>
14 #include <linux/ioport.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/errno.h>
20 #include <asm/system.h>
22 #include <asm/pgtable.h>
24 /* Used for the temporal inet entries and routing */
25 #include <linux/socket.h>
26 #include <linux/route.h>
28 #include <linux/dio.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
34 #include <asm/mvme147hw.h>
36 /* We have 16834 bytes of RAM for the init block and buffers. This places
37 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
38 * buffers and 2 Tx buffers.
40 #define LANCE_LOG_TX_BUFFERS 1
41 #define LANCE_LOG_RX_BUFFERS 3
43 #include "7990.h" /* use generic LANCE code */
45 /* Our private data structure */
46 struct m147lance_private {
47 struct lance_private lance;
52 /* function prototypes... This is easy because all the grot is in the
53 * generic LANCE support. All we have to support is probing for boards,
54 * plus board-specific init, open and close actions.
55 * Oh, and we need to tell the generic code how to read and write LANCE registers...
57 int mvme147lance_probe(struct net_device *dev);
58 static int m147lance_open(struct net_device *dev);
59 static int m147lance_close(struct net_device *dev);
60 static void m147lance_writerap(struct m147lance_private *lp, unsigned short value);
61 static void m147lance_writerdp(struct m147lance_private *lp, unsigned short value);
62 static unsigned short m147lance_readrdp(struct m147lance_private *lp);
64 typedef void (*writerap_t)(void *, unsigned short);
65 typedef void (*writerdp_t)(void *, unsigned short);
66 typedef unsigned short (*readrdp_t)(void *);
69 static struct m147lance_private *root_m147lance_dev;
72 /* Initialise the one and only on-board 7990 */
73 int __init mvme147lance_probe(struct net_device *dev)
76 static const char name[] = "MVME147 LANCE";
77 struct m147lance_private *lp;
81 if (!MACH_IS_MVME147 || called)
85 SET_MODULE_OWNER(dev);
87 dev->priv = kmalloc(sizeof(struct m147lance_private), GFP_KERNEL);
88 if (dev->priv == NULL)
90 memset(dev->priv, 0, sizeof(struct m147lance_private));
92 /* Fill the dev fields */
93 dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
94 dev->open = &m147lance_open;
95 dev->stop = &m147lance_close;
96 dev->hard_start_xmit = &lance_start_xmit;
97 dev->get_stats = &lance_get_stats;
98 dev->set_multicast_list = &lance_set_multicast;
99 dev->tx_timeout = &lance_tx_timeout;
102 addr=(u_long *)ETHERNET_ADDRESS;
104 dev->dev_addr[0]=0x08;
105 dev->dev_addr[1]=0x00;
106 dev->dev_addr[2]=0x3e;
108 dev->dev_addr[5]=address&0xff;
110 dev->dev_addr[4]=address&0xff;
112 dev->dev_addr[3]=address&0xff;
114 printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %02x:%02x:%02x:%02x:%02x:%02x\n",
115 dev->name, dev->base_addr, MVME147_LANCE_IRQ,
117 dev->dev_addr[1], dev->dev_addr[2],
118 dev->dev_addr[3], dev->dev_addr[4],
121 lp = (struct m147lance_private *)dev->priv;
122 lp->ram = (void *)__get_dma_pages(GFP_ATOMIC, 3); /* 16K */
125 printk("%s: No memory for LANCE buffers\n", dev->name);
129 lp->lance.name = (char*)name; /* discards const, shut up gcc */
130 lp->lance.ll = (struct lance_regs *)(dev->base_addr);
131 lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
132 lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
133 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
134 lp->lance.irq = MVME147_LANCE_IRQ;
135 lp->lance.writerap = (writerap_t)m147lance_writerap;
136 lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
137 lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
138 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
139 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
140 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
141 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
145 dev->ifindex = dev_new_index();
146 lp->next_module = root_m147lance_dev;
147 root_m147lance_dev = lp;
153 static void m147lance_writerap(struct m147lance_private *lp, unsigned short value)
155 lp->lance.ll->rap = value;
158 static void m147lance_writerdp(struct m147lance_private *lp, unsigned short value)
160 lp->lance.ll->rdp = value;
163 static unsigned short m147lance_readrdp(struct m147lance_private *lp)
165 return lp->lance.ll->rdp;
168 static int m147lance_open(struct net_device *dev)
172 status = lance_open(dev); /* call generic lance open code */
175 /* enable interrupts at board level. */
176 m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
177 m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
182 static int m147lance_close(struct net_device *dev)
184 /* disable interrupts at boardlevel */
185 m147_pcc->lan_cntrl=0x0; /* disable interrupts */
191 MODULE_LICENSE("GPL");
193 int init_module(void)
195 root_lance_dev = NULL;
196 return mvme147lance_probe(NULL);
199 void cleanup_module(void)
201 /* Walk the chain of devices, unregistering them */
202 struct m147lance_private *lp;
203 while (root_m147lance_dev) {
204 lp = root_m147lance_dev->next_module;
205 unregister_netdev(root_lance_dev->dev);
206 free_pages(lp->ram, 3);
207 kfree(root_lance_dev->dev);