MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / mvme147.c
blob5995658b18fba777778b801d3974d22685355484
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.
6 */
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/dio.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
26 #include <asm/system.h>
27 #include <asm/io.h>
28 #include <asm/pgtable.h>
29 #include <asm/mvme147hw.h>
31 /* We have 16834 bytes of RAM for the init block and buffers. This places
32 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
33 * buffers and 2 Tx buffers.
35 #define LANCE_LOG_TX_BUFFERS 1
36 #define LANCE_LOG_RX_BUFFERS 3
38 #include "7990.h" /* use generic LANCE code */
40 /* Our private data structure */
41 struct m147lance_private {
42 struct lance_private lance;
43 void *base;
44 unsigned long ram;
47 /* function prototypes... This is easy because all the grot is in the
48 * generic LANCE support. All we have to support is probing for boards,
49 * plus board-specific init, open and close actions.
50 * Oh, and we need to tell the generic code how to read and write LANCE registers...
52 static int m147lance_open(struct net_device *dev);
53 static int m147lance_close(struct net_device *dev);
54 static void m147lance_writerap(struct m147lance_private *lp, unsigned short value);
55 static void m147lance_writerdp(struct m147lance_private *lp, unsigned short value);
56 static unsigned short m147lance_readrdp(struct m147lance_private *lp);
58 typedef void (*writerap_t)(void *, unsigned short);
59 typedef void (*writerdp_t)(void *, unsigned short);
60 typedef unsigned short (*readrdp_t)(void *);
62 /* Initialise the one and only on-board 7990 */
63 struct net_device * __init mvme147lance_probe(int unit)
65 struct net_device *dev;
66 static int called;
67 static const char name[] = "MVME147 LANCE";
68 struct m147lance_private *lp;
69 u_long *addr;
70 u_long address;
71 int err;
73 if (!MACH_IS_MVME147 || called)
74 return ERR_PTR(-ENODEV);
75 called++;
77 dev = alloc_etherdev(sizeof(struct m147lance_private));
78 if (!dev)
79 return ERR_PTR(-ENOMEM);
81 if (unit >= 0)
82 sprintf(dev->name, "eth%d", unit);
84 SET_MODULE_OWNER(dev);
86 /* Fill the dev fields */
87 dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
88 dev->open = &m147lance_open;
89 dev->stop = &m147lance_close;
90 dev->hard_start_xmit = &lance_start_xmit;
91 dev->get_stats = &lance_get_stats;
92 dev->set_multicast_list = &lance_set_multicast;
93 dev->tx_timeout = &lance_tx_timeout;
94 dev->dma = 0;
96 addr=(u_long *)ETHERNET_ADDRESS;
97 address = *addr;
98 dev->dev_addr[0]=0x08;
99 dev->dev_addr[1]=0x00;
100 dev->dev_addr[2]=0x3e;
101 address=address>>8;
102 dev->dev_addr[5]=address&0xff;
103 address=address>>8;
104 dev->dev_addr[4]=address&0xff;
105 address=address>>8;
106 dev->dev_addr[3]=address&0xff;
108 printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %02x:%02x:%02x:%02x:%02x:%02x\n",
109 dev->name, dev->base_addr, MVME147_LANCE_IRQ,
110 dev->dev_addr[0],
111 dev->dev_addr[1], dev->dev_addr[2],
112 dev->dev_addr[3], dev->dev_addr[4],
113 dev->dev_addr[5]);
115 lp = (struct m147lance_private *)dev->priv;
116 lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */
117 if (!lp->ram)
119 printk("%s: No memory for LANCE buffers\n", dev->name);
120 free_netdev(dev);
121 return ERR_PTR(-ENOMEM);
124 lp->lance.name = (char*)name; /* discards const, shut up gcc */
125 lp->lance.ll = (struct lance_regs *)(dev->base_addr);
126 lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
127 lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
128 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
129 lp->lance.irq = MVME147_LANCE_IRQ;
130 lp->lance.writerap = (writerap_t)m147lance_writerap;
131 lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
132 lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
133 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
134 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
135 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
136 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
138 err = register_netdev(dev);
139 if (err) {
140 free_pages(lp->ram, 3);
141 free_netdev(dev);
142 return ERR_PTR(err);
145 return dev;
148 static void m147lance_writerap(struct m147lance_private *lp, unsigned short value)
150 lp->lance.ll->rap = value;
153 static void m147lance_writerdp(struct m147lance_private *lp, unsigned short value)
155 lp->lance.ll->rdp = value;
158 static unsigned short m147lance_readrdp(struct m147lance_private *lp)
160 return lp->lance.ll->rdp;
163 static int m147lance_open(struct net_device *dev)
165 int status;
167 status = lance_open(dev); /* call generic lance open code */
168 if (status)
169 return status;
170 /* enable interrupts at board level. */
171 m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
172 m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
174 return 0;
177 static int m147lance_close(struct net_device *dev)
179 /* disable interrupts at boardlevel */
180 m147_pcc->lan_cntrl=0x0; /* disable interrupts */
181 lance_close(dev);
182 return 0;
185 #ifdef MODULE
186 MODULE_LICENSE("GPL");
188 static struct net_device *dev_mvme147_lance;
189 int init_module(void)
191 dev_mvme147_lance = mvme147lance_probe(-1);
192 if (IS_ERR(dev_mvme147_lance))
193 return PTR_ERR(dev_mvme147_lance);
194 return 0;
197 void cleanup_module(void)
199 struct m147lance_private *lp = dev_mvme147_lance->priv;
200 unregister_netdev(dev_mvme147_lance);
201 free_pages(lp->ram, 3);
202 free_netdev(dev_mvme147_lance);
205 #endif /* MODULE */