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
7 * Copyright (C) 1999 kaz Kojima
10 #include <linux/config.h>
11 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/errno.h>
16 #include <linux/ioport.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <asm/system.h>
23 #include <asm/hitachi_se.h>
24 #include <asm/machvec.h>
25 #ifdef CONFIG_SH_STANDARD_BIOS
26 #include <asm/sh_bios.h>
31 #define byte unsigned char
32 #define half unsigned short
33 #define word unsigned int
34 #define vbyte volatile unsigned char
35 #define vhalf volatile unsigned short
36 #define vword volatile unsigned int
38 #define STNIC_RUN 0x01 /* 1 == Run, 0 == reset. */
40 #define START_PG 0 /* First page of TX buffer */
41 #define STOP_PG 128 /* Last page +1 of RX ring */
44 #define STNIC_CR E8390_CMD
45 #define PG0_RSAR0 EN0_RSARLO
46 #define PG0_RSAR1 EN0_RSARHI
47 #define PG0_RBCR0 EN0_RCNTLO
48 #define PG0_RBCR1 EN0_RCNTHI
50 #define CR_RRD E8390_RREAD
51 #define CR_RWR E8390_RWRITE
52 #define CR_PG0 E8390_PAGE0
53 #define CR_STA E8390_START
54 #define CR_RDMA E8390_NODMA
56 /* FIXME! YOU MUST SET YOUR OWN ETHER ADDRESS. */
57 static byte stnic_eadr[6] =
58 {0x00, 0xc0, 0x6e, 0x00, 0x00, 0x07};
60 static struct net_device *stnic_dev;
62 static int stnic_open (struct net_device *dev);
63 static int stnic_close (struct net_device *dev);
64 static void stnic_reset (struct net_device *dev);
65 static void stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
67 static void stnic_block_input (struct net_device *dev, int count,
68 struct sk_buff *skb , int ring_offset);
69 static void stnic_block_output (struct net_device *dev, int count,
70 const unsigned char *buf, int start_page);
72 static void stnic_init (struct net_device *dev);
74 /* SH7750 specific read/write io. */
79 trash = *(vword *) 0xa0000000;
80 trash = *(vword *) 0xa0000000;
81 trash = *(vword *) 0xa0000000;
89 val = (*(vhalf *) (PA_83902 + ((reg) << 1)) >> 8) & 0xff;
95 STNIC_WRITE (int reg, byte val)
97 *(vhalf *) (PA_83902 + ((reg) << 1)) = ((half) (val) << 8);
101 int __init stnic_probe(void)
103 struct net_device *dev;
106 /* If we are not running on a SolutionEngine, give up now */
110 /* New style probing API */
111 dev = init_etherdev (NULL, 0);
114 SET_MODULE_OWNER(dev);
117 /* Allocate dev->priv and fill in 8390 specific dev fields. */
118 if (ethdev_init (dev))
120 printk (KERN_EMERG "Unable to get memory for dev->priv.\n");
124 #ifdef CONFIG_SH_STANDARD_BIOS
125 sh_bios_get_node_addr (stnic_eadr);
127 for (i = 0; i < ETHER_ADDR_LEN; i++)
128 dev->dev_addr[i] = stnic_eadr[i];
130 /* Set the base address to point to the NIC, not the "real" base! */
131 dev->base_addr = 0x1000;
132 dev->irq = IRQ_STNIC;
133 dev->open = &stnic_open;
134 dev->stop = &stnic_close;
136 /* Snarf the interrupt now. There's no point in waiting since we cannot
137 share and the board will usually be enabled. */
138 i = request_irq (dev->irq, ei_interrupt, 0, dev->name, dev);
140 printk (KERN_EMERG " unable to get IRQ %d.\n", dev->irq);
141 unregister_netdev(dev);
147 ei_status.name = dev->name;
148 ei_status.word16 = 1;
149 #ifdef __LITTLE_ENDIAN__
150 ei_status.bigendian = 0;
152 ei_status.bigendian = 1;
154 ei_status.tx_start_page = START_PG;
155 ei_status.rx_start_page = START_PG + TX_PAGES;
156 ei_status.stop_page = STOP_PG;
158 ei_status.reset_8390 = &stnic_reset;
159 ei_status.get_8390_hdr = &stnic_get_hdr;
160 ei_status.block_input = &stnic_block_input;
161 ei_status.block_output = &stnic_block_output;
165 printk (KERN_INFO "NS ST-NIC 83902A\n");
171 stnic_open (struct net_device *dev)
174 printk (KERN_DEBUG "stnic open\n");
181 stnic_close (struct net_device *dev)
188 stnic_reset (struct net_device *dev)
190 *(vhalf *) PA_83902_RST = 0;
193 printk (KERN_WARNING "8390 reset done (%ld).\n", jiffies);
194 *(vhalf *) PA_83902_RST = ~0;
199 stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
204 STNIC_WRITE (PG0_RSAR0, 0);
205 STNIC_WRITE (PG0_RSAR1, ring_page);
206 STNIC_WRITE (PG0_RBCR0, 4);
207 STNIC_WRITE (PG0_RBCR1, 0);
208 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
210 buf[0] = *(vhalf *) PA_83902_IF;
212 buf[1] = *(vhalf *) PA_83902_IF;
214 hdr->next = buf[0] >> 8;
215 hdr->status = buf[0] & 0xff;
216 #ifdef __LITTLE_ENDIAN__
219 hdr->count = ((buf[1] >> 8) & 0xff) | (buf[1] << 8);
223 printk (KERN_DEBUG "ring %x status %02x next %02x count %04x.\n",
224 ring_page, hdr->status, hdr->next, hdr->count);
226 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
229 /* Block input and output, similar to the Crynwr packet driver. If you are
230 porting to a new ethercard look at the packet driver source for hints.
231 The HP LAN doesn't use shared memory -- we put the packet
232 out through the "remote DMA" dataport. */
235 stnic_block_input (struct net_device *dev, int length, struct sk_buff *skb,
238 char *buf = skb->data;
241 STNIC_WRITE (PG0_RSAR0, offset & 0xff);
242 STNIC_WRITE (PG0_RSAR1, offset >> 8);
243 STNIC_WRITE (PG0_RBCR0, length & 0xff);
244 STNIC_WRITE (PG0_RBCR1, length >> 8);
245 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
252 val = *(vhalf *) PA_83902_IF;
253 #ifdef __LITTLE_ENDIAN__
261 length -= sizeof (half);
264 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
268 stnic_block_output (struct net_device *dev, int length,
269 const unsigned char *buf, int output_page)
271 STNIC_WRITE (PG0_RBCR0, 1); /* Write non-zero value */
272 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
275 STNIC_WRITE (PG0_RBCR0, length & 0xff);
276 STNIC_WRITE (PG0_RBCR1, length >> 8);
277 STNIC_WRITE (PG0_RSAR0, 0);
278 STNIC_WRITE (PG0_RSAR1, output_page);
279 STNIC_WRITE (STNIC_CR, CR_RWR | CR_PG0 | CR_STA);
286 #ifdef __LITTLE_ENDIAN__
287 *(vhalf *) PA_83902_IF = ((half) buf[1] << 8) | buf[0];
289 *(vhalf *) PA_83902_IF = ((half) buf[0] << 8) | buf[1];
292 buf += sizeof (half);
293 length -= sizeof (half);
296 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
299 /* This function resets the STNIC if something screws up. */
301 stnic_init (struct net_device *dev)
304 NS8390_init (dev, 0);
308 /* Hardware interrupt handler. */
309 extern void ei_interrupt (int irq, void *dev_id, struct pt_regs *regs);
312 do_stnic_intr (int irq, void *dev_id, struct pt_regs *regs)
314 ei_interrupt (0, stnic_dev, regs);
317 module_init(stnic_probe);
318 /* No cleanup routine. */
319 MODULE_LICENSE("GPL");