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/module.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/errno.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>
20 #include <asm/system.h>
22 #include <asm/hitachi_se.h>
23 #include <asm/machvec.h>
27 #define byte unsigned char
28 #define half unsigned short
29 #define word unsigned int
30 #define vbyte volatile unsigned char
31 #define vhalf volatile unsigned short
32 #define vword volatile unsigned int
34 #define STNIC_RUN 0x01 /* 1 == Run, 0 == reset. */
36 #define START_PG 0 /* First page of TX buffer */
37 #define STOP_PG 128 /* Last page +1 of RX ring */
40 #define STNIC_CR E8390_CMD
41 #define PG0_RSAR0 EN0_RSARLO
42 #define PG0_RSAR1 EN0_RSARHI
43 #define PG0_RBCR0 EN0_RCNTLO
44 #define PG0_RBCR1 EN0_RCNTHI
46 #define CR_RRD E8390_RREAD
47 #define CR_RWR E8390_RWRITE
48 #define CR_PG0 E8390_PAGE0
49 #define CR_STA E8390_START
50 #define CR_RDMA E8390_NODMA
52 /* FIXME! YOU MUST SET YOUR OWN ETHER ADDRESS. */
53 static byte stnic_eadr
[6] =
54 {0x00, 0xc0, 0x6e, 0x00, 0x00, 0x07};
56 static struct net_device
*stnic_dev
;
58 static int stnic_open (struct net_device
*dev
);
59 static int stnic_close (struct net_device
*dev
);
60 static void stnic_reset (struct net_device
*dev
);
61 static void stnic_get_hdr (struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
63 static void stnic_block_input (struct net_device
*dev
, int count
,
64 struct sk_buff
*skb
, int ring_offset
);
65 static void stnic_block_output (struct net_device
*dev
, int count
,
66 const unsigned char *buf
, int start_page
);
68 static void stnic_init (struct net_device
*dev
);
70 /* SH7750 specific read/write io. */
75 trash
= *(vword
*) 0xa0000000;
76 trash
= *(vword
*) 0xa0000000;
84 val
= (*(vhalf
*) (PA_83902
+ ((reg
) << 1)) >> 8) & 0xff;
90 STNIC_WRITE (int reg
, byte val
)
92 *(vhalf
*) (PA_83902
+ ((reg
) << 1)) = ((half
) (val
) << 8);
96 int __init
stnic_probe(void)
98 struct net_device
*dev
;
101 /* If we are not running on a SolutionEngine, give up now */
105 /* New style probing API */
106 dev
= init_etherdev (NULL
, 0);
109 SET_MODULE_OWNER(dev
);
112 /* Allocate dev->priv and fill in 8390 specific dev fields. */
113 if (ethdev_init (dev
))
115 printk ("Unable to get memory for dev->priv.\n");
119 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++)
120 dev
->dev_addr
[i
] = stnic_eadr
[i
];
122 /* Set the base address to point to the NIC, not the "real" base! */
123 dev
->base_addr
= 0x1000;
124 dev
->irq
= IRQ_STNIC
;
125 dev
->open
= &stnic_open
;
126 dev
->stop
= &stnic_close
;
128 /* Snarf the interrupt now. There's no point in waiting since we cannot
129 share and the board will usually be enabled. */
130 i
= request_irq (dev
->irq
, ei_interrupt
, 0, dev
->name
, dev
);
132 printk (" unable to get IRQ %d.\n", dev
->irq
);
133 unregister_netdev(dev
);
139 ei_status
.name
= dev
->name
;
140 ei_status
.word16
= 1;
141 ei_status
.tx_start_page
= START_PG
;
142 ei_status
.rx_start_page
= START_PG
+ TX_PAGES
;
143 ei_status
.stop_page
= STOP_PG
;
145 ei_status
.reset_8390
= &stnic_reset
;
146 ei_status
.get_8390_hdr
= &stnic_get_hdr
;
147 ei_status
.block_input
= &stnic_block_input
;
148 ei_status
.block_output
= &stnic_block_output
;
151 printk (KERN_INFO
"NS ST-NIC 83902A\n");
157 stnic_open (struct net_device
*dev
)
160 printk ("stnic open\n");
167 stnic_close (struct net_device
*dev
)
174 stnic_reset (struct net_device
*dev
)
176 *(vhalf
*) PA_83902_RST
= 0;
179 printk("8390 reset done (%ld).\n", jiffies
);
180 *(vhalf
*) PA_83902_RST
= ~0;
185 stnic_get_hdr (struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
190 STNIC_WRITE (PG0_RSAR0
, 0);
191 STNIC_WRITE (PG0_RSAR1
, ring_page
);
192 STNIC_WRITE (PG0_RBCR0
, 4);
193 STNIC_WRITE (PG0_RBCR1
, 0);
194 STNIC_WRITE (STNIC_CR
, CR_RRD
| CR_PG0
| CR_STA
);
196 buf
[0] = *(vhalf
*) PA_83902_IF
;
198 buf
[1] = *(vhalf
*) PA_83902_IF
;
200 hdr
->next
= buf
[0] >> 8;
201 hdr
->status
= buf
[0] & 0xff;
202 #ifdef __LITTLE_ENDIAN__
205 hdr
->count
= ((buf
[1] >> 8) & 0xff) | (buf
[1] << 8);
209 printk ("ring %x status %02x next %02x count %04x.\n",
210 ring_page
, hdr
->status
, hdr
->next
, hdr
->count
);
212 STNIC_WRITE (STNIC_CR
, CR_RDMA
| CR_PG0
| CR_STA
);
215 /* Block input and output, similar to the Crynwr packet driver. If you are
216 porting to a new ethercard look at the packet driver source for hints.
217 The HP LAN doesn't use shared memory -- we put the packet
218 out through the "remote DMA" dataport. */
221 stnic_block_input (struct net_device
*dev
, int length
, struct sk_buff
*skb
,
224 char *buf
= skb
->data
;
227 STNIC_WRITE (PG0_RSAR0
, offset
& 0xff);
228 STNIC_WRITE (PG0_RSAR1
, offset
>> 8);
229 STNIC_WRITE (PG0_RBCR0
, length
& 0xff);
230 STNIC_WRITE (PG0_RBCR1
, length
>> 8);
231 STNIC_WRITE (STNIC_CR
, CR_RRD
| CR_PG0
| CR_STA
);
238 val
= *(vhalf
*) PA_83902_IF
;
239 #ifdef __LITTLE_ENDIAN__
247 length
-= sizeof (half
);
250 STNIC_WRITE (STNIC_CR
, CR_RDMA
| CR_PG0
| CR_STA
);
254 stnic_block_output (struct net_device
*dev
, int length
,
255 const unsigned char *buf
, int output_page
)
258 STNIC_WRITE (PG0_RBCR0
, 1);
259 STNIC_WRITE (STNIC_CR
, CR_RRD
| CR_PG0
| CR_STA
);
260 #else /* XXX: I don't know why but this works. -- gniibe */
261 STNIC_WRITE (PG0_RBCR0
, 0x42);
262 STNIC_WRITE (PG0_RBCR1
, 0x00);
263 STNIC_WRITE (PG0_RBCR0
, 0x42);
264 STNIC_WRITE (PG0_RBCR1
, 0x00);
265 STNIC_WRITE (STNIC_CR
, CR_RRD
| CR_PG0
| CR_STA
);
269 STNIC_WRITE (PG0_RSAR0
, 0);
270 STNIC_WRITE (PG0_RSAR1
, output_page
);
271 STNIC_WRITE (PG0_RBCR0
, length
& 0xff);
272 STNIC_WRITE (PG0_RBCR1
, length
>> 8);
273 STNIC_WRITE (STNIC_CR
, CR_RWR
| CR_PG0
| CR_STA
);
280 #ifdef __LITTLE_ENDIAN__
281 *(vhalf
*) PA_83902_IF
= ((half
) buf
[1] << 8) | buf
[0];
283 *(vhalf
*) PA_83902_IF
= ((half
) buf
[0] << 8) | buf
[1];
286 buf
+= sizeof (half
);
287 length
-= sizeof (half
);
290 STNIC_WRITE (STNIC_CR
, CR_RDMA
| CR_PG0
| CR_STA
);
293 /* This function resets the STNIC if something screws up. */
295 stnic_init (struct net_device
*dev
)
298 NS8390_init (dev
, 0);
302 /* Hardware interrupt handler. */
303 extern void ei_interrupt (int irq
, void *dev_id
, struct pt_regs
*regs
);
306 do_stnic_intr (int irq
, void *dev_id
, struct pt_regs
*regs
)
308 ei_interrupt (0, stnic_dev
, regs
);
311 module_init(stnic_probe
);
312 /* No cleanup routine. */