[TG3]: Add tagged status support.
[linux-2.6/verdex.git] / drivers / net / stnic.c
blobb6dfdf8f44dac25b83f9c5cd82775cb4bb96853b
1 /* stnic.c : A SH7750 specific part of driver for NS DP83902A ST-NIC.
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
5 * for more details.
7 * Copyright (C) 1999 kaz Kojima
8 */
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/interrupt.h>
15 #include <linux/ioport.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
21 #include <asm/system.h>
22 #include <asm/io.h>
23 #include <asm/se/se.h>
24 #include <asm/machvec.h>
25 #ifdef CONFIG_SH_STANDARD_BIOS
26 #include <asm/sh_bios.h>
27 #endif
29 #include "8390.h"
31 #define DRV_NAME "stnic"
33 #define byte unsigned char
34 #define half unsigned short
35 #define word unsigned int
36 #define vbyte volatile unsigned char
37 #define vhalf volatile unsigned short
38 #define vword volatile unsigned int
40 #define STNIC_RUN 0x01 /* 1 == Run, 0 == reset. */
42 #define START_PG 0 /* First page of TX buffer */
43 #define STOP_PG 128 /* Last page +1 of RX ring */
45 /* Alias */
46 #define STNIC_CR E8390_CMD
47 #define PG0_RSAR0 EN0_RSARLO
48 #define PG0_RSAR1 EN0_RSARHI
49 #define PG0_RBCR0 EN0_RCNTLO
50 #define PG0_RBCR1 EN0_RCNTHI
52 #define CR_RRD E8390_RREAD
53 #define CR_RWR E8390_RWRITE
54 #define CR_PG0 E8390_PAGE0
55 #define CR_STA E8390_START
56 #define CR_RDMA E8390_NODMA
58 /* FIXME! YOU MUST SET YOUR OWN ETHER ADDRESS. */
59 static byte stnic_eadr[6] =
60 {0x00, 0xc0, 0x6e, 0x00, 0x00, 0x07};
62 static struct net_device *stnic_dev;
64 static int stnic_open (struct net_device *dev);
65 static int stnic_close (struct net_device *dev);
66 static void stnic_reset (struct net_device *dev);
67 static void stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
68 int ring_page);
69 static void stnic_block_input (struct net_device *dev, int count,
70 struct sk_buff *skb , int ring_offset);
71 static void stnic_block_output (struct net_device *dev, int count,
72 const unsigned char *buf, int start_page);
74 static void stnic_init (struct net_device *dev);
76 /* SH7750 specific read/write io. */
77 static inline void
78 STNIC_DELAY (void)
80 vword trash;
81 trash = *(vword *) 0xa0000000;
82 trash = *(vword *) 0xa0000000;
83 trash = *(vword *) 0xa0000000;
86 static inline byte
87 STNIC_READ (int reg)
89 byte val;
91 val = (*(vhalf *) (PA_83902 + ((reg) << 1)) >> 8) & 0xff;
92 STNIC_DELAY ();
93 return val;
96 static inline void
97 STNIC_WRITE (int reg, byte val)
99 *(vhalf *) (PA_83902 + ((reg) << 1)) = ((half) (val) << 8);
100 STNIC_DELAY ();
103 static int __init stnic_probe(void)
105 struct net_device *dev;
106 int i, err;
108 /* If we are not running on a SolutionEngine, give up now */
109 if (! MACH_SE)
110 return -ENODEV;
112 /* New style probing API */
113 dev = alloc_ei_netdev();
114 if (!dev)
115 return -ENOMEM;
116 SET_MODULE_OWNER(dev);
118 #ifdef CONFIG_SH_STANDARD_BIOS
119 sh_bios_get_node_addr (stnic_eadr);
120 #endif
121 for (i = 0; i < ETHER_ADDR_LEN; i++)
122 dev->dev_addr[i] = stnic_eadr[i];
124 /* Set the base address to point to the NIC, not the "real" base! */
125 dev->base_addr = 0x1000;
126 dev->irq = IRQ_STNIC;
127 dev->open = &stnic_open;
128 dev->stop = &stnic_close;
129 #ifdef CONFIG_NET_POLL_CONTROLLER
130 dev->poll_controller = ei_poll;
131 #endif
133 /* Snarf the interrupt now. There's no point in waiting since we cannot
134 share and the board will usually be enabled. */
135 err = request_irq (dev->irq, ei_interrupt, 0, DRV_NAME, dev);
136 if (err) {
137 printk (KERN_EMERG " unable to get IRQ %d.\n", dev->irq);
138 free_netdev(dev);
139 return err;
142 ei_status.name = dev->name;
143 ei_status.word16 = 1;
144 #ifdef __LITTLE_ENDIAN__
145 ei_status.bigendian = 0;
146 #else
147 ei_status.bigendian = 1;
148 #endif
149 ei_status.tx_start_page = START_PG;
150 ei_status.rx_start_page = START_PG + TX_PAGES;
151 ei_status.stop_page = STOP_PG;
153 ei_status.reset_8390 = &stnic_reset;
154 ei_status.get_8390_hdr = &stnic_get_hdr;
155 ei_status.block_input = &stnic_block_input;
156 ei_status.block_output = &stnic_block_output;
158 stnic_init (dev);
160 err = register_netdev(dev);
161 if (err) {
162 free_irq(dev->irq, dev);
163 free_netdev(dev);
164 return err;
166 stnic_dev = dev;
168 printk (KERN_INFO "NS ST-NIC 83902A\n");
170 return 0;
173 static int
174 stnic_open (struct net_device *dev)
176 #if 0
177 printk (KERN_DEBUG "stnic open\n");
178 #endif
179 ei_open (dev);
180 return 0;
183 static int
184 stnic_close (struct net_device *dev)
186 ei_close (dev);
187 return 0;
190 static void
191 stnic_reset (struct net_device *dev)
193 *(vhalf *) PA_83902_RST = 0;
194 udelay (5);
195 if (ei_debug > 1)
196 printk (KERN_WARNING "8390 reset done (%ld).\n", jiffies);
197 *(vhalf *) PA_83902_RST = ~0;
198 udelay (5);
201 static void
202 stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
203 int ring_page)
205 half buf[2];
207 STNIC_WRITE (PG0_RSAR0, 0);
208 STNIC_WRITE (PG0_RSAR1, ring_page);
209 STNIC_WRITE (PG0_RBCR0, 4);
210 STNIC_WRITE (PG0_RBCR1, 0);
211 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
213 buf[0] = *(vhalf *) PA_83902_IF;
214 STNIC_DELAY ();
215 buf[1] = *(vhalf *) PA_83902_IF;
216 STNIC_DELAY ();
217 hdr->next = buf[0] >> 8;
218 hdr->status = buf[0] & 0xff;
219 #ifdef __LITTLE_ENDIAN__
220 hdr->count = buf[1];
221 #else
222 hdr->count = ((buf[1] >> 8) & 0xff) | (buf[1] << 8);
223 #endif
225 if (ei_debug > 1)
226 printk (KERN_DEBUG "ring %x status %02x next %02x count %04x.\n",
227 ring_page, hdr->status, hdr->next, hdr->count);
229 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
232 /* Block input and output, similar to the Crynwr packet driver. If you are
233 porting to a new ethercard look at the packet driver source for hints.
234 The HP LAN doesn't use shared memory -- we put the packet
235 out through the "remote DMA" dataport. */
237 static void
238 stnic_block_input (struct net_device *dev, int length, struct sk_buff *skb,
239 int offset)
241 char *buf = skb->data;
242 half val;
244 STNIC_WRITE (PG0_RSAR0, offset & 0xff);
245 STNIC_WRITE (PG0_RSAR1, offset >> 8);
246 STNIC_WRITE (PG0_RBCR0, length & 0xff);
247 STNIC_WRITE (PG0_RBCR1, length >> 8);
248 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
250 if (length & 1)
251 length++;
253 while (length > 0)
255 val = *(vhalf *) PA_83902_IF;
256 #ifdef __LITTLE_ENDIAN__
257 *buf++ = val & 0xff;
258 *buf++ = val >> 8;
259 #else
260 *buf++ = val >> 8;
261 *buf++ = val & 0xff;
262 #endif
263 STNIC_DELAY ();
264 length -= sizeof (half);
267 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
270 static void
271 stnic_block_output (struct net_device *dev, int length,
272 const unsigned char *buf, int output_page)
274 STNIC_WRITE (PG0_RBCR0, 1); /* Write non-zero value */
275 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
276 STNIC_DELAY ();
278 STNIC_WRITE (PG0_RBCR0, length & 0xff);
279 STNIC_WRITE (PG0_RBCR1, length >> 8);
280 STNIC_WRITE (PG0_RSAR0, 0);
281 STNIC_WRITE (PG0_RSAR1, output_page);
282 STNIC_WRITE (STNIC_CR, CR_RWR | CR_PG0 | CR_STA);
284 if (length & 1)
285 length++;
287 while (length > 0)
289 #ifdef __LITTLE_ENDIAN__
290 *(vhalf *) PA_83902_IF = ((half) buf[1] << 8) | buf[0];
291 #else
292 *(vhalf *) PA_83902_IF = ((half) buf[0] << 8) | buf[1];
293 #endif
294 STNIC_DELAY ();
295 buf += sizeof (half);
296 length -= sizeof (half);
299 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
302 /* This function resets the STNIC if something screws up. */
303 static void
304 stnic_init (struct net_device *dev)
306 stnic_reset (dev);
307 NS8390_init (dev, 0);
308 return;
311 static void __exit stnic_cleanup(void)
313 unregister_netdev(stnic_dev);
314 free_irq(stnic_dev->irq, stnic_dev);
315 free_netdev(stnic_dev);
318 module_init(stnic_probe);
319 module_exit(stnic_cleanup);
320 MODULE_LICENSE("GPL");