More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / hplance.c
blob29aa6abced63ae9c24c1c4587463b270dd0eba79
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/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>
30 #include "hplance.h"
32 /* We have 16834 bytes of RAM for the init block and buffers. This places
33 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
34 * buffers and 2 Tx buffers.
36 #define LANCE_LOG_TX_BUFFERS 1
37 #define LANCE_LOG_RX_BUFFERS 3
39 #include "7990.h" /* use generic LANCE code */
41 /* Our private data structure */
42 struct hplance_private {
43 struct lance_private lance;
44 unsigned int scode;
45 void *base;
48 /* function prototypes... This is easy because all the grot is in the
49 * generic LANCE support. All we have to support is probing for boards,
50 * plus board-specific init, open and close actions.
51 * Oh, and we need to tell the generic code how to read and write LANCE registers...
53 int hplance_probe(struct net_device *dev);
54 static int hplance_init(struct net_device *dev, int scode);
55 static int hplance_open(struct net_device *dev);
56 static int hplance_close(struct net_device *dev);
57 static void hplance_writerap(void *priv, unsigned short value);
58 static void hplance_writerdp(void *priv, unsigned short value);
59 static unsigned short hplance_readrdp(void *priv);
61 #ifdef MODULE
62 static struct hplance_private *root_hplance_dev;
63 #endif
65 /* Find all the HP Lance boards and initialise them... */
66 int __init hplance_probe(struct net_device *dev)
68 int cards = 0, called = 0;
70 if (!MACH_IS_HP300 || called)
71 return(ENODEV);
72 called++;
74 /* Isn't DIO nice? */
75 for(;;)
77 int v, scode = dio_find(DIO_ID_LAN);
79 if (!scode)
80 break;
82 if(cards)
83 dev = NULL; /* don't trash previous device, make a new one */
84 cards++;
86 v = hplance_init(dev, scode);
87 if (v) /* error, abort immediately */
88 return v;
90 /* OK, return success, or ENODEV if we didn't find any cards */
91 if (!cards)
92 return -ENODEV;
93 return 0;
96 /* Initialise a single lance board at the given select code */
97 static int __init hplance_init(struct net_device *dev, int scode)
99 const char *name = dio_scodetoname(scode);
100 void *va = dio_scodetoviraddr(scode);
101 struct hplance_private *lp;
102 int i;
104 #ifdef MODULE
105 dev = init_etherdev(0, sizeof(struct hplance_private));
106 if (!dev)
107 return -ENOMEM;
108 #else
109 dev->priv = kmalloc(sizeof(struct hplance_private), GFP_KERNEL);
110 if (dev->priv == NULL)
111 return -ENOMEM;
112 memset(dev->priv, 0, sizeof(struct hplance_private));
113 #endif
114 SET_MODULE_OWNER(dev);
116 printk("%s: %s; select code %d, addr", dev->name, name, scode);
118 /* reset the board */
119 out_8(va+DIO_IDOFF, 0xff);
120 udelay(100); /* ariba! ariba! udelay! udelay! */
122 /* Fill the dev fields */
123 dev->base_addr = (unsigned long)va;
124 dev->open = &hplance_open;
125 dev->stop = &hplance_close;
126 dev->hard_start_xmit = &lance_start_xmit;
127 dev->get_stats = &lance_get_stats;
128 dev->set_multicast_list = &lance_set_multicast;
129 dev->dma = 0;
131 for (i=0; i<6; i++)
133 /* The NVRAM holds our ethernet address, one nibble per byte,
134 * at bytes NVRAMOFF+1,3,5,7,9...
136 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
137 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
138 printk("%c%2.2x", i == 0 ? ' ' : ':', dev->dev_addr[i]);
141 lp = (struct hplance_private *)dev->priv;
142 lp->lance.name = (char*)name; /* discards const, shut up gcc */
143 lp->lance.ll = (struct lance_regs *)(va + HPLANCE_REGOFF);
144 lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
145 lp->lance.lance_init_block = 0; /* LANCE addr of same RAM */
146 lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
147 lp->lance.irq = dio_scodetoipl(scode);
148 lp->lance.writerap = hplance_writerap;
149 lp->lance.writerdp = hplance_writerdp;
150 lp->lance.readrdp = hplance_readrdp;
151 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
152 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
153 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
154 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
155 lp->scode = scode;
156 lp->base = va;
157 ether_setup(dev);
158 printk(", irq %d\n", lp->lance.irq);
160 #ifdef MODULE
161 dev->ifindex = dev_new_index();
162 lp->next_module = root_hplance_dev;
163 root_hplance_dev = lp;
164 #endif /* MODULE */
166 dio_config_board(scode); /* tell bus scanning code this one's taken */
167 return 0;
170 /* This is disgusting. We have to check the DIO status register for ack every
171 * time we read or write the LANCE registers.
173 static void hplance_writerap(void *priv, unsigned short value)
175 struct hplance_private *lp = (struct hplance_private *)priv;
176 struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
177 do {
178 lp->lance.ll->rap = value;
179 } while ((hpregs->status & LE_ACK) == 0);
182 static void hplance_writerdp(void *priv, unsigned short value)
184 struct hplance_private *lp = (struct hplance_private *)priv;
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(void *priv)
193 unsigned short val;
194 struct hplance_private *lp = (struct hplance_private *)priv;
195 struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
196 do {
197 val = lp->lance.ll->rdp;
198 } while ((hpregs->status & LE_ACK) == 0);
199 return val;
202 static int hplance_open(struct net_device *dev)
204 int status;
205 struct hplance_private *lp = (struct hplance_private *)dev->priv;
206 struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
208 status = lance_open(dev); /* call generic lance open code */
209 if (status)
210 return status;
211 /* enable interrupts at board level. */
212 out_8(&(hpregs->status), LE_IE);
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 out_8(&(hpregs->status), 8); /* disable interrupts at boardlevel */
222 lance_close(dev);
223 return 0;
226 #ifdef MODULE
227 MODULE_LICENSE("GPL");
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 */