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