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.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/types.h>
12 #include <linux/interrupt.h>
13 #include <linux/ptrace.h>
14 #include <linux/ioport.h>
15 #include <linux/malloc.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/errno.h>
20 #include <asm/system.h>
22 #include <asm/pgtable.h>
24 /* Used for the temporal inet entries and routing */
25 #include <linux/socket.h>
26 #include <linux/route.h>
28 #include <linux/dio.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
36 /* We have 16834 bytes of RAM for the init block and buffers. This places
37 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
38 * buffers and 2 Tx buffers.
40 #define LANCE_LOG_TX_BUFFERS 1
41 #define LANCE_LOG_RX_BUFFERS 3
43 #include "7990.h" /* use generic LANCE code */
45 /* Our private data structure */
46 struct hplance_private
{
47 struct lance_private lance
;
52 /* function prototypes... This is easy because all the grot is in the
53 * generic LANCE support. All we have to support is probing for boards,
54 * plus board-specific init, open and close actions.
55 * Oh, and we need to tell the generic code how to read and write LANCE registers...
57 int hplance_probe(struct net_device
*dev
);
58 static int hplance_init(struct net_device
*dev
, int scode
);
59 static int hplance_open(struct net_device
*dev
);
60 static int hplance_close(struct net_device
*dev
);
61 static void hplance_writerap(struct hplance_private
*lp
, unsigned short value
);
62 static void hplance_writerdp(struct hplance_private
*lp
, unsigned short value
);
63 static unsigned short hplance_readrdp(struct hplance_private
*lp
);
66 static struct hplance_private
*root_hplance_dev
= NULL
;
69 /* Find all the HP Lance boards and initialise them... */
70 int __init
hplance_probe(struct net_device
*dev
)
72 int cards
= 0, called
= 0;
74 if (!MACH_IS_HP300
|| called
)
81 int v
, scode
= dio_find(DIO_ID_LAN
);
87 dev
= NULL
; /* don't trash previous device, make a new one */
90 v
= hplance_init(dev
, scode
);
91 if (v
) /* error, abort immediately */
94 /* OK, return success, or ENODEV if we didn't find any cards */
100 /* Initialise a single lance board at the given select code */
101 static int __init
hplance_init(struct net_device
*dev
, int scode
)
103 /* const char *name = dio_scodetoname(scode); */
104 static const char name
[] = "HP LANCE";
105 void *va
= dio_scodetoviraddr(scode
);
106 struct hplance_private
*lp
;
110 dev
= init_etherdev(0, sizeof(struct hplance_private
));
113 dev
->priv
= kmalloc(sizeof(struct hplance_private
), GFP_KERNEL
);
114 if (dev
->priv
== NULL
)
116 memset(dev
->priv
, 0, sizeof(struct hplance_private
));
118 printk("%s: HP LANCE; select code %d, addr", dev
->name
, scode
);
120 /* reset the board */
121 writeb(0xff,va
+DIO_IDOFF
);
122 udelay(100); /* ariba! ariba! udelay! udelay! */
124 /* Fill the dev fields */
125 dev
->base_addr
= (unsigned long)va
;
126 dev
->open
= &hplance_open
;
127 dev
->stop
= &hplance_close
;
128 dev
->hard_start_xmit
= &lance_start_xmit
;
129 dev
->get_stats
= &lance_get_stats
;
130 dev
->set_multicast_list
= &lance_set_multicast
;
135 /* The NVRAM holds our ethernet address, one nibble per byte,
136 * at bytes NVRAMOFF+1,3,5,7,9...
138 dev
->dev_addr
[i
] = ((readb(va
+ HPLANCE_NVRAMOFF
+ i
*4 + 1) & 0xF) << 4)
139 | (readb(va
+ HPLANCE_NVRAMOFF
+ i
*4 + 3) & 0xF);
140 printk("%c%2.2x", i
== 0 ? ' ' : ':', dev
->dev_addr
[i
]);
143 lp
= (struct hplance_private
*)dev
->priv
;
144 lp
->lance
.name
= (char*)name
; /* discards const, shut up gcc */
145 lp
->lance
.ll
= (struct lance_regs
*)(va
+ HPLANCE_REGOFF
);
146 lp
->lance
.init_block
= (struct lance_init_block
*)(va
+ HPLANCE_MEMOFF
); /* CPU addr */
147 lp
->lance
.lance_init_block
= 0; /* LANCE addr of same RAM */
148 lp
->lance
.busmaster_regval
= LE_C3_BSWP
; /* we're bigendian */
149 lp
->lance
.irq
= dio_scodetoipl(scode
);
150 lp
->lance
.writerap
= hplance_writerap
;
151 lp
->lance
.writerdp
= hplance_writerdp
;
152 lp
->lance
.readrdp
= hplance_readrdp
;
153 lp
->lance
.lance_log_rx_bufs
= LANCE_LOG_RX_BUFFERS
;
154 lp
->lance
.lance_log_tx_bufs
= LANCE_LOG_TX_BUFFERS
;
155 lp
->lance
.rx_ring_mod_mask
= RX_RING_MOD_MASK
;
156 lp
->lance
.tx_ring_mod_mask
= TX_RING_MOD_MASK
;
160 printk(", irq %d\n", lp
->lance
.irq
);
163 dev
->ifindex
= dev_new_index();
164 lp
->next_module
= root_hplance_dev
;
165 root_hplance_dev
= lp
;
168 dio_config_board(scode
); /* tell bus scanning code this one's taken */
172 /* This is disgusting. We have to check the DIO status register for ack every
173 * time we read or write the LANCE registers.
175 static void hplance_writerap(struct hplance_private
*lp
, unsigned short value
)
177 struct hplance_reg
*hpregs
= (struct hplance_reg
*)lp
->base
;
179 lp
->lance
.ll
->rap
= value
;
180 } while ((hpregs
->status
& LE_ACK
) == 0);
183 static void hplance_writerdp(struct hplance_private
*lp
, unsigned short value
)
185 struct hplance_reg
*hpregs
= (struct hplance_reg
*)lp
->base
;
187 lp
->lance
.ll
->rdp
= value
;
188 } while ((hpregs
->status
& LE_ACK
) == 0);
191 static unsigned short hplance_readrdp(struct hplance_private
*lp
)
194 struct hplance_reg
*hpregs
= (struct hplance_reg
*)lp
->base
;
196 val
= lp
->lance
.ll
->rdp
;
197 } while ((hpregs
->status
& LE_ACK
) == 0);
201 static int hplance_open(struct net_device
*dev
)
204 struct hplance_private
*lp
= (struct hplance_private
*)dev
->priv
;
205 struct hplance_reg
*hpregs
= (struct hplance_reg
*)lp
->base
;
207 status
= lance_open(dev
); /* call generic lance open code */
210 /* enable interrupts at board level. */
211 writeb(LE_IE
, &(hpregs
->status
));
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 writeb(0,&(hpregs
->status
)); /* disable interrupts at boardlevel */
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
);