1 // SPDX-License-Identifier: GPL-2.0-only
2 /* stnic.c : A SH7750 specific part of driver for NS DP83902A ST-NIC.
4 * Copyright (C) 1999 kaz Kojima
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/interrupt.h>
11 #include <linux/ioport.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
18 #include <mach-se/mach/se.h>
19 #include <asm/machvec.h>
20 #ifdef CONFIG_SH_STANDARD_BIOS
21 #include <asm/sh_bios.h>
26 #define DRV_NAME "stnic"
28 #define byte unsigned char
29 #define half unsigned short
30 #define word unsigned int
31 #define vbyte volatile unsigned char
32 #define vhalf volatile unsigned short
33 #define vword volatile unsigned int
35 #define STNIC_RUN 0x01 /* 1 == Run, 0 == reset. */
37 #define START_PG 0 /* First page of TX buffer */
38 #define STOP_PG 128 /* Last page +1 of RX ring */
41 #define STNIC_CR E8390_CMD
42 #define PG0_RSAR0 EN0_RSARLO
43 #define PG0_RSAR1 EN0_RSARHI
44 #define PG0_RBCR0 EN0_RCNTLO
45 #define PG0_RBCR1 EN0_RCNTHI
47 #define CR_RRD E8390_RREAD
48 #define CR_RWR E8390_RWRITE
49 #define CR_PG0 E8390_PAGE0
50 #define CR_STA E8390_START
51 #define CR_RDMA E8390_NODMA
53 /* FIXME! YOU MUST SET YOUR OWN ETHER ADDRESS. */
54 static byte stnic_eadr[6] =
55 {0x00, 0xc0, 0x6e, 0x00, 0x00, 0x07};
57 static struct net_device *stnic_dev;
59 static void stnic_reset (struct net_device *dev);
60 static void stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
62 static void stnic_block_input (struct net_device *dev, int count,
63 struct sk_buff *skb , int ring_offset);
64 static void stnic_block_output (struct net_device *dev, int count,
65 const unsigned char *buf, int start_page);
67 static void stnic_init (struct net_device *dev);
69 static u32 stnic_msg_enable;
71 module_param_named(msg_enable, stnic_msg_enable, uint, 0444);
72 MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)");
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 static int __init stnic_probe(void)
103 struct net_device *dev;
104 struct ei_device *ei_local;
107 /* If we are not running on a SolutionEngine, give up now */
111 /* New style probing API */
112 dev = alloc_ei_netdev();
116 #ifdef CONFIG_SH_STANDARD_BIOS
117 sh_bios_get_node_addr (stnic_eadr);
119 eth_hw_addr_set(dev, stnic_eadr);
121 /* Set the base address to point to the NIC, not the "real" base! */
122 dev->base_addr = 0x1000;
123 dev->irq = IRQ_STNIC;
124 dev->netdev_ops = &ei_netdev_ops;
126 /* Snarf the interrupt now. There's no point in waiting since we cannot
127 share and the board will usually be enabled. */
128 err = request_irq (dev->irq, ei_interrupt, 0, DRV_NAME, dev);
130 netdev_emerg(dev, " unable to get IRQ %d.\n", dev->irq);
135 ei_status.name = dev->name;
136 ei_status.word16 = 1;
137 #ifdef __LITTLE_ENDIAN__
138 ei_status.bigendian = 0;
140 ei_status.bigendian = 1;
142 ei_status.tx_start_page = START_PG;
143 ei_status.rx_start_page = START_PG + TX_PAGES;
144 ei_status.stop_page = STOP_PG;
146 ei_status.reset_8390 = &stnic_reset;
147 ei_status.get_8390_hdr = &stnic_get_hdr;
148 ei_status.block_input = &stnic_block_input;
149 ei_status.block_output = &stnic_block_output;
152 ei_local = netdev_priv(dev);
153 ei_local->msg_enable = stnic_msg_enable;
155 err = register_netdev(dev);
157 free_irq(dev->irq, dev);
163 netdev_info(dev, "NS ST-NIC 83902A\n");
169 stnic_reset (struct net_device *dev)
171 struct ei_device *ei_local = netdev_priv(dev);
173 *(vhalf *) PA_83902_RST = 0;
175 netif_warn(ei_local, hw, dev, "8390 reset done (%ld).\n", jiffies);
176 *(vhalf *) PA_83902_RST = ~0;
181 stnic_get_hdr (struct net_device *dev, struct e8390_pkt_hdr *hdr,
184 struct ei_device *ei_local = netdev_priv(dev);
188 STNIC_WRITE (PG0_RSAR0, 0);
189 STNIC_WRITE (PG0_RSAR1, ring_page);
190 STNIC_WRITE (PG0_RBCR0, 4);
191 STNIC_WRITE (PG0_RBCR1, 0);
192 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
194 buf[0] = *(vhalf *) PA_83902_IF;
196 buf[1] = *(vhalf *) PA_83902_IF;
198 hdr->next = buf[0] >> 8;
199 hdr->status = buf[0] & 0xff;
200 #ifdef __LITTLE_ENDIAN__
203 hdr->count = ((buf[1] >> 8) & 0xff) | (buf[1] << 8);
206 netif_dbg(ei_local, probe, dev, "ring %x status %02x next %02x count %04x.\n",
207 ring_page, hdr->status, hdr->next, hdr->count);
209 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
212 /* Block input and output, similar to the Crynwr packet driver. If you are
213 porting to a new ethercard look at the packet driver source for hints.
214 The HP LAN doesn't use shared memory -- we put the packet
215 out through the "remote DMA" dataport. */
218 stnic_block_input (struct net_device *dev, int length, struct sk_buff *skb,
221 char *buf = skb->data;
224 STNIC_WRITE (PG0_RSAR0, offset & 0xff);
225 STNIC_WRITE (PG0_RSAR1, offset >> 8);
226 STNIC_WRITE (PG0_RBCR0, length & 0xff);
227 STNIC_WRITE (PG0_RBCR1, length >> 8);
228 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
235 val = *(vhalf *) PA_83902_IF;
236 #ifdef __LITTLE_ENDIAN__
244 length -= sizeof (half);
247 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
251 stnic_block_output (struct net_device *dev, int length,
252 const unsigned char *buf, int output_page)
254 STNIC_WRITE (PG0_RBCR0, 1); /* Write non-zero value */
255 STNIC_WRITE (STNIC_CR, CR_RRD | CR_PG0 | CR_STA);
258 STNIC_WRITE (PG0_RBCR0, length & 0xff);
259 STNIC_WRITE (PG0_RBCR1, length >> 8);
260 STNIC_WRITE (PG0_RSAR0, 0);
261 STNIC_WRITE (PG0_RSAR1, output_page);
262 STNIC_WRITE (STNIC_CR, CR_RWR | CR_PG0 | CR_STA);
269 #ifdef __LITTLE_ENDIAN__
270 *(vhalf *) PA_83902_IF = ((half) buf[1] << 8) | buf[0];
272 *(vhalf *) PA_83902_IF = ((half) buf[0] << 8) | buf[1];
275 buf += sizeof (half);
276 length -= sizeof (half);
279 STNIC_WRITE (STNIC_CR, CR_RDMA | CR_PG0 | CR_STA);
282 /* This function resets the STNIC if something screws up. */
284 stnic_init (struct net_device *dev)
287 NS8390_init (dev, 0);
290 static void __exit stnic_cleanup(void)
292 unregister_netdev(stnic_dev);
293 free_irq(stnic_dev->irq, stnic_dev);
294 free_netdev(stnic_dev);
297 module_init(stnic_probe);
298 module_exit(stnic_cleanup);
299 MODULE_LICENSE("GPL");