1 |
1275 |
phoenix |
/* hplance.c : the Linux/hp300/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 "hplance.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 hplance_private {
|
47 |
|
|
struct lance_private lance;
|
48 |
|
|
unsigned int scode;
|
49 |
|
|
void *base;
|
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 hplance_probe(struct net_device *dev);
|
58 |
|
|
static int hplance_init(struct net_device *dev, int scode);
|
59 |
|
|
static int hplance_open(struct net_device *dev);
|
60 |
|
|
static int hplance_close(struct net_device *dev);
|
61 |
|
|
static void hplance_writerap(void *priv, unsigned short value);
|
62 |
|
|
static void hplance_writerdp(void *priv, unsigned short value);
|
63 |
|
|
static unsigned short hplance_readrdp(void *priv);
|
64 |
|
|
|
65 |
|
|
#ifdef MODULE
|
66 |
|
|
static struct hplance_private *root_hplance_dev;
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
/* Find all the HP Lance boards and initialise them... */
|
70 |
|
|
int __init hplance_probe(struct net_device *dev)
|
71 |
|
|
{
|
72 |
|
|
int cards = 0, called = 0;
|
73 |
|
|
|
74 |
|
|
if (!MACH_IS_HP300 || called)
|
75 |
|
|
return(ENODEV);
|
76 |
|
|
called++;
|
77 |
|
|
|
78 |
|
|
/* Isn't DIO nice? */
|
79 |
|
|
for(;;)
|
80 |
|
|
{
|
81 |
|
|
int v, scode = dio_find(DIO_ID_LAN);
|
82 |
|
|
|
83 |
|
|
if (!scode)
|
84 |
|
|
break;
|
85 |
|
|
|
86 |
|
|
if(cards)
|
87 |
|
|
dev = NULL; /* don't trash previous device, make a new one */
|
88 |
|
|
cards++;
|
89 |
|
|
|
90 |
|
|
v = hplance_init(dev, scode);
|
91 |
|
|
if (v) /* error, abort immediately */
|
92 |
|
|
return v;
|
93 |
|
|
}
|
94 |
|
|
/* OK, return success, or ENODEV if we didn't find any cards */
|
95 |
|
|
if (!cards)
|
96 |
|
|
return -ENODEV;
|
97 |
|
|
return 0;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
/* Initialise a single lance board at the given select code */
|
101 |
|
|
static int __init hplance_init(struct net_device *dev, int scode)
|
102 |
|
|
{
|
103 |
|
|
const char *name = dio_scodetoname(scode);
|
104 |
|
|
void *va = dio_scodetoviraddr(scode);
|
105 |
|
|
struct hplance_private *lp;
|
106 |
|
|
int i;
|
107 |
|
|
|
108 |
|
|
#ifdef MODULE
|
109 |
|
|
dev = init_etherdev(0, sizeof(struct hplance_private));
|
110 |
|
|
if (!dev)
|
111 |
|
|
return -ENOMEM;
|
112 |
|
|
#else
|
113 |
|
|
dev->priv = kmalloc(sizeof(struct hplance_private), GFP_KERNEL);
|
114 |
|
|
if (dev->priv == NULL)
|
115 |
|
|
return -ENOMEM;
|
116 |
|
|
memset(dev->priv, 0, sizeof(struct hplance_private));
|
117 |
|
|
#endif
|
118 |
|
|
SET_MODULE_OWNER(dev);
|
119 |
|
|
|
120 |
|
|
printk("%s: %s; select code %d, addr", dev->name, name, scode);
|
121 |
|
|
|
122 |
|
|
/* reset the board */
|
123 |
|
|
out_8(va+DIO_IDOFF, 0xff);
|
124 |
|
|
udelay(100); /* ariba! ariba! udelay! udelay! */
|
125 |
|
|
|
126 |
|
|
/* Fill the dev fields */
|
127 |
|
|
dev->base_addr = (unsigned long)va;
|
128 |
|
|
dev->open = &hplance_open;
|
129 |
|
|
dev->stop = &hplance_close;
|
130 |
|
|
dev->hard_start_xmit = &lance_start_xmit;
|
131 |
|
|
dev->get_stats = &lance_get_stats;
|
132 |
|
|
dev->set_multicast_list = &lance_set_multicast;
|
133 |
|
|
dev->dma = 0;
|
134 |
|
|
|
135 |
|
|
for (i=0; i<6; i++)
|
136 |
|
|
{
|
137 |
|
|
/* The NVRAM holds our ethernet address, one nibble per byte,
|
138 |
|
|
* at bytes NVRAMOFF+1,3,5,7,9...
|
139 |
|
|
*/
|
140 |
|
|
dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
|
141 |
|
|
| (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
|
142 |
|
|
printk("%c%2.2x", i == 0 ? ' ' : ':', dev->dev_addr[i]);
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
lp = (struct hplance_private *)dev->priv;
|
146 |
|
|
lp->lance.name = (char*)name; /* discards const, shut up gcc */
|
147 |
|
|
lp->lance.ll = (struct lance_regs *)(va + HPLANCE_REGOFF);
|
148 |
|
|
lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
|
149 |
|
|
lp->lance.lance_init_block = 0; /* LANCE addr of same RAM */
|
150 |
|
|
lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
|
151 |
|
|
lp->lance.irq = dio_scodetoipl(scode);
|
152 |
|
|
lp->lance.writerap = hplance_writerap;
|
153 |
|
|
lp->lance.writerdp = hplance_writerdp;
|
154 |
|
|
lp->lance.readrdp = hplance_readrdp;
|
155 |
|
|
lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
|
156 |
|
|
lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
|
157 |
|
|
lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
|
158 |
|
|
lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
|
159 |
|
|
lp->scode = scode;
|
160 |
|
|
lp->base = va;
|
161 |
|
|
ether_setup(dev);
|
162 |
|
|
printk(", irq %d\n", lp->lance.irq);
|
163 |
|
|
|
164 |
|
|
#ifdef MODULE
|
165 |
|
|
dev->ifindex = dev_new_index();
|
166 |
|
|
lp->next_module = root_hplance_dev;
|
167 |
|
|
root_hplance_dev = lp;
|
168 |
|
|
#endif /* MODULE */
|
169 |
|
|
|
170 |
|
|
dio_config_board(scode); /* tell bus scanning code this one's taken */
|
171 |
|
|
return 0;
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
/* This is disgusting. We have to check the DIO status register for ack every
|
175 |
|
|
* time we read or write the LANCE registers.
|
176 |
|
|
*/
|
177 |
|
|
static void hplance_writerap(void *priv, unsigned short value)
|
178 |
|
|
{
|
179 |
|
|
struct hplance_private *lp = (struct hplance_private *)priv;
|
180 |
|
|
struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
|
181 |
|
|
do {
|
182 |
|
|
lp->lance.ll->rap = value;
|
183 |
|
|
} while ((hpregs->status & LE_ACK) == 0);
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
static void hplance_writerdp(void *priv, unsigned short value)
|
187 |
|
|
{
|
188 |
|
|
struct hplance_private *lp = (struct hplance_private *)priv;
|
189 |
|
|
struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
|
190 |
|
|
do {
|
191 |
|
|
lp->lance.ll->rdp = value;
|
192 |
|
|
} while ((hpregs->status & LE_ACK) == 0);
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
static unsigned short hplance_readrdp(void *priv)
|
196 |
|
|
{
|
197 |
|
|
unsigned short val;
|
198 |
|
|
struct hplance_private *lp = (struct hplance_private *)priv;
|
199 |
|
|
struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
|
200 |
|
|
do {
|
201 |
|
|
val = lp->lance.ll->rdp;
|
202 |
|
|
} while ((hpregs->status & LE_ACK) == 0);
|
203 |
|
|
return val;
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
static int hplance_open(struct net_device *dev)
|
207 |
|
|
{
|
208 |
|
|
int status;
|
209 |
|
|
struct hplance_private *lp = (struct hplance_private *)dev->priv;
|
210 |
|
|
struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
|
211 |
|
|
|
212 |
|
|
status = lance_open(dev); /* call generic lance open code */
|
213 |
|
|
if (status)
|
214 |
|
|
return status;
|
215 |
|
|
/* enable interrupts at board level. */
|
216 |
|
|
out_8(&(hpregs->status), LE_IE);
|
217 |
|
|
|
218 |
|
|
return 0;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
static int hplance_close(struct net_device *dev)
|
222 |
|
|
{
|
223 |
|
|
struct hplance_private *lp = (struct hplance_private *)dev->priv;
|
224 |
|
|
struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
|
225 |
|
|
out_8(&(hpregs->status), 8); /* disable interrupts at boardlevel */
|
226 |
|
|
lance_close(dev);
|
227 |
|
|
return 0;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
#ifdef MODULE
|
231 |
|
|
MODULE_LICENSE("GPL");
|
232 |
|
|
int init_module(void)
|
233 |
|
|
{
|
234 |
|
|
root_lance_dev = NULL;
|
235 |
|
|
return hplance_probe(NULL);
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
void cleanup_module(void)
|
239 |
|
|
{
|
240 |
|
|
/* Walk the chain of devices, unregistering them */
|
241 |
|
|
struct hplance_private *lp;
|
242 |
|
|
while (root_hplance_dev) {
|
243 |
|
|
lp = root_hplance_dev->next_module;
|
244 |
|
|
dio_unconfig_board(lp->scode);
|
245 |
|
|
unregister_netdev(root_lance_dev->dev);
|
246 |
|
|
kfree(root_lance_dev->dev);
|
247 |
|
|
root_lance_dev = lp;
|
248 |
|
|
}
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
#endif /* MODULE */
|