1 |
1275 |
phoenix |
/* 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/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>
|
21 |
|
|
#include <asm/io.h>
|
22 |
|
|
#include <asm/pgtable.h>
|
23 |
|
|
|
24 |
|
|
/* Used for the temporal inet entries and routing */
|
25 |
|
|
#include <linux/socket.h>
|
26 |
|
|
#include <linux/route.h>
|
27 |
|
|
|
28 |
|
|
#include <linux/dio.h>
|
29 |
|
|
|
30 |
|
|
#include <linux/netdevice.h>
|
31 |
|
|
#include <linux/etherdevice.h>
|
32 |
|
|
#include <linux/skbuff.h>
|
33 |
|
|
|
34 |
|
|
#include <asm/mvme147hw.h>
|
35 |
|
|
|
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.
|
39 |
|
|
*/
|
40 |
|
|
#define LANCE_LOG_TX_BUFFERS 1
|
41 |
|
|
#define LANCE_LOG_RX_BUFFERS 3
|
42 |
|
|
|
43 |
|
|
#include "7990.h" /* use generic LANCE code */
|
44 |
|
|
|
45 |
|
|
/* Our private data structure */
|
46 |
|
|
struct m147lance_private {
|
47 |
|
|
struct lance_private lance;
|
48 |
|
|
void *base;
|
49 |
|
|
void *ram;
|
50 |
|
|
};
|
51 |
|
|
|
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...
|
56 |
|
|
*/
|
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);
|
63 |
|
|
|
64 |
|
|
typedef void (*writerap_t)(void *, unsigned short);
|
65 |
|
|
typedef void (*writerdp_t)(void *, unsigned short);
|
66 |
|
|
typedef unsigned short (*readrdp_t)(void *);
|
67 |
|
|
|
68 |
|
|
#ifdef MODULE
|
69 |
|
|
static struct m147lance_private *root_m147lance_dev;
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
/* Initialise the one and only on-board 7990 */
|
73 |
|
|
int __init mvme147lance_probe(struct net_device *dev)
|
74 |
|
|
{
|
75 |
|
|
static int called;
|
76 |
|
|
static const char name[] = "MVME147 LANCE";
|
77 |
|
|
struct m147lance_private *lp;
|
78 |
|
|
u_long *addr;
|
79 |
|
|
u_long address;
|
80 |
|
|
|
81 |
|
|
if (!MACH_IS_MVME147 || called)
|
82 |
|
|
return -ENODEV;
|
83 |
|
|
called++;
|
84 |
|
|
|
85 |
|
|
SET_MODULE_OWNER(dev);
|
86 |
|
|
|
87 |
|
|
dev->priv = kmalloc(sizeof(struct m147lance_private), GFP_KERNEL);
|
88 |
|
|
if (dev->priv == NULL)
|
89 |
|
|
return -ENOMEM;
|
90 |
|
|
memset(dev->priv, 0, sizeof(struct m147lance_private));
|
91 |
|
|
|
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;
|
100 |
|
|
dev->dma = 0;
|
101 |
|
|
|
102 |
|
|
addr=(u_long *)ETHERNET_ADDRESS;
|
103 |
|
|
address = *addr;
|
104 |
|
|
dev->dev_addr[0]=0x08;
|
105 |
|
|
dev->dev_addr[1]=0x00;
|
106 |
|
|
dev->dev_addr[2]=0x3e;
|
107 |
|
|
address=address>>8;
|
108 |
|
|
dev->dev_addr[5]=address&0xff;
|
109 |
|
|
address=address>>8;
|
110 |
|
|
dev->dev_addr[4]=address&0xff;
|
111 |
|
|
address=address>>8;
|
112 |
|
|
dev->dev_addr[3]=address&0xff;
|
113 |
|
|
|
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,
|
116 |
|
|
dev->dev_addr[0],
|
117 |
|
|
dev->dev_addr[1], dev->dev_addr[2],
|
118 |
|
|
dev->dev_addr[3], dev->dev_addr[4],
|
119 |
|
|
dev->dev_addr[5]);
|
120 |
|
|
|
121 |
|
|
lp = (struct m147lance_private *)dev->priv;
|
122 |
|
|
lp->ram = (void *)__get_dma_pages(GFP_ATOMIC, 3); /* 16K */
|
123 |
|
|
if (!lp->ram)
|
124 |
|
|
{
|
125 |
|
|
printk("%s: No memory for LANCE buffers\n", dev->name);
|
126 |
|
|
return -ENODEV;
|
127 |
|
|
}
|
128 |
|
|
|
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;
|
142 |
|
|
ether_setup(dev);
|
143 |
|
|
|
144 |
|
|
#ifdef MODULE
|
145 |
|
|
dev->ifindex = dev_new_index();
|
146 |
|
|
lp->next_module = root_m147lance_dev;
|
147 |
|
|
root_m147lance_dev = lp;
|
148 |
|
|
#endif /* MODULE */
|
149 |
|
|
|
150 |
|
|
return 0;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
static void m147lance_writerap(struct m147lance_private *lp, unsigned short value)
|
154 |
|
|
{
|
155 |
|
|
lp->lance.ll->rap = value;
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
static void m147lance_writerdp(struct m147lance_private *lp, unsigned short value)
|
159 |
|
|
{
|
160 |
|
|
lp->lance.ll->rdp = value;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
static unsigned short m147lance_readrdp(struct m147lance_private *lp)
|
164 |
|
|
{
|
165 |
|
|
return lp->lance.ll->rdp;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
static int m147lance_open(struct net_device *dev)
|
169 |
|
|
{
|
170 |
|
|
int status;
|
171 |
|
|
|
172 |
|
|
status = lance_open(dev); /* call generic lance open code */
|
173 |
|
|
if (status)
|
174 |
|
|
return status;
|
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 */
|
178 |
|
|
|
179 |
|
|
return 0;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
static int m147lance_close(struct net_device *dev)
|
183 |
|
|
{
|
184 |
|
|
/* disable interrupts at boardlevel */
|
185 |
|
|
m147_pcc->lan_cntrl=0x0; /* disable interrupts */
|
186 |
|
|
lance_close(dev);
|
187 |
|
|
return 0;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
#ifdef MODULE
|
191 |
|
|
MODULE_LICENSE("GPL");
|
192 |
|
|
|
193 |
|
|
int init_module(void)
|
194 |
|
|
{
|
195 |
|
|
root_lance_dev = NULL;
|
196 |
|
|
return mvme147lance_probe(NULL);
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
void cleanup_module(void)
|
200 |
|
|
{
|
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);
|
208 |
|
|
root_lance_dev = lp;
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
#endif /* MODULE */
|