1 /* mvme147.c : the Linux/mvme147/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>
34 #include <asm/mvme147hw.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 m147lance_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 mvme147lance_probe(struct net_device
*dev
);
58 static int m147lance_open(struct net_device
*dev
);
59 static int m147lance_close(struct net_device
*dev
);
60 static void m147lance_writerap(struct m147lance_private
*lp
, unsigned short value
);
61 static void m147lance_writerdp(struct m147lance_private
*lp
, unsigned short value
);
62 static unsigned short m147lance_readrdp(struct m147lance_private
*lp
);
64 typedef void (*writerap_t
)(void *, unsigned short);
65 typedef void (*writerdp_t
)(void *, unsigned short);
66 typedef void (*readrdp_t
)(void *);
69 static struct m147lance_private
*root_m147lance_dev
= NULL
;
72 /* Initialise the one and only on-board 7990 */
73 int __init
mvme147lance_probe(struct net_device
*dev
)
75 static int called
= 0;
76 static const char name
[] = "MVME147 LANCE";
77 struct m147lance_private
*lp
;
81 if (!MACH_IS_MVME147
|| called
)
85 dev
->priv
= kmalloc(sizeof(struct m147lance_private
), GFP_KERNEL
);
86 if (dev
->priv
== NULL
)
88 memset(dev
->priv
, 0, sizeof(struct m147lance_private
));
90 /* Fill the dev fields */
91 dev
->base_addr
= (unsigned long)MVME147_LANCE_BASE
;
92 dev
->open
= &m147lance_open
;
93 dev
->stop
= &m147lance_close
;
94 dev
->hard_start_xmit
= &lance_start_xmit
;
95 dev
->get_stats
= &lance_get_stats
;
96 dev
->set_multicast_list
= &lance_set_multicast
;
99 addr
=(u_long
*)ETHERNET_ADDRESS
;
101 dev
->dev_addr
[0]=0x08;
102 dev
->dev_addr
[1]=0x00;
103 dev
->dev_addr
[2]=0x3e;
105 dev
->dev_addr
[5]=address
&0xff;
107 dev
->dev_addr
[4]=address
&0xff;
109 dev
->dev_addr
[3]=address
&0xff;
111 printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %02x:%02x:%02x:%02x:%02x:%02x\n",
112 dev
->name
, dev
->base_addr
, MVME147_LANCE_IRQ
,
114 dev
->dev_addr
[1], dev
->dev_addr
[2],
115 dev
->dev_addr
[3], dev
->dev_addr
[4],
118 lp
= (struct m147lance_private
*)dev
->priv
;
119 lp
->ram
= (void *)__get_dma_pages(GFP_ATOMIC
, 3); /* 16K */
122 printk("%s: No memory for LANCE buffers\n", dev
->name
);
126 lp
->lance
.name
= (char*)name
; /* discards const, shut up gcc */
127 lp
->lance
.ll
= (struct lance_regs
*)(dev
->base_addr
);
128 lp
->lance
.init_block
= (struct lance_init_block
*)(lp
->ram
); /* CPU addr */
129 lp
->lance
.lance_init_block
= (struct lance_init_block
*)(lp
->ram
); /* LANCE addr of same RAM */
130 lp
->lance
.busmaster_regval
= LE_C3_BSWP
; /* we're bigendian */
131 lp
->lance
.irq
= MVME147_LANCE_IRQ
;
132 lp
->lance
.writerap
= (writerap_t
)m147lance_writerap
;
133 lp
->lance
.writerdp
= (writerdp_t
)m147lance_writerdp
;
134 lp
->lance
.readrdp
= (readrdp_t
)m147lance_readrdp
;
135 lp
->lance
.lance_log_rx_bufs
= LANCE_LOG_RX_BUFFERS
;
136 lp
->lance
.lance_log_tx_bufs
= LANCE_LOG_TX_BUFFERS
;
137 lp
->lance
.rx_ring_mod_mask
= RX_RING_MOD_MASK
;
138 lp
->lance
.tx_ring_mod_mask
= TX_RING_MOD_MASK
;
142 dev
->ifindex
= dev_new_index();
143 lp
->next_module
= root_m147lance_dev
;
144 root_m147lance_dev
= lp
;
150 static void m147lance_writerap(struct m147lance_private
*lp
, unsigned short value
)
152 lp
->lance
.ll
->rap
= value
;
155 static void m147lance_writerdp(struct m147lance_private
*lp
, unsigned short value
)
157 lp
->lance
.ll
->rdp
= value
;
160 static unsigned short m147lance_readrdp(struct m147lance_private
*lp
)
162 return lp
->lance
.ll
->rdp
;
165 static int m147lance_open(struct net_device
*dev
)
169 status
= lance_open(dev
); /* call generic lance open code */
172 /* enable interrupts at board level. */
173 m147_pcc
->lan_cntrl
=0; /* clear the interrupts (if any) */
174 m147_pcc
->lan_cntrl
=0x08 | 0x04; /* Enable irq 4 */
180 static int m147lance_close(struct net_device
*dev
)
182 /* disable interrupts at boardlevel */
183 m147_pcc
->lan_cntrl
=0x0; /* disable interrupts */
190 int init_module(void)
192 root_lance_dev
= NULL
;
193 return mvme147lance_probe(NULL
);
196 void cleanup_module(void)
198 /* Walk the chain of devices, unregistering them */
199 struct m147lance_private
*lp
;
200 while (root_m147lance_dev
) {
201 lp
= root_m147lance_dev
->next_module
;
202 unregister_netdev(root_lance_dev
->dev
);
203 free_pages(lp
->ram
, 3);
204 kfree(root_lance_dev
->dev
);