1 // SPDX-License-Identifier: GPL-2.0-only
2 /* mvme147.c : the Linux/mvme147/lance ethernet driver
4 * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
5 * Based on the Sun Lance driver and the NetBSD HP Lance driver
6 * Uses the generic 7990.c LANCE code.
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/interrupt.h>
13 #include <linux/ioport.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/gfp.h>
19 #include <linux/pgtable.h>
20 /* Used for the temporal inet entries and routing */
21 #include <linux/socket.h>
22 #include <linux/route.h>
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/skbuff.h>
28 #include <asm/mvme147hw.h>
30 /* We have 32K of RAM for the init block and buffers. This places
31 * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
32 * buffers and 2 Tx buffers, it takes (8 + 2) * 1544 bytes.
34 #define LANCE_LOG_TX_BUFFERS 1
35 #define LANCE_LOG_RX_BUFFERS 3
37 #include "7990.h" /* use generic LANCE code */
39 /* Our private data structure */
40 struct m147lance_private
{
41 struct lance_private lance
;
45 /* function prototypes... This is easy because all the grot is in the
46 * generic LANCE support. All we have to support is probing for boards,
47 * plus board-specific init, open and close actions.
48 * Oh, and we need to tell the generic code how to read and write LANCE registers...
50 static int m147lance_open(struct net_device
*dev
);
51 static int m147lance_close(struct net_device
*dev
);
52 static void m147lance_writerap(struct lance_private
*lp
, unsigned short value
);
53 static void m147lance_writerdp(struct lance_private
*lp
, unsigned short value
);
54 static unsigned short m147lance_readrdp(struct lance_private
*lp
);
56 typedef void (*writerap_t
)(void *, unsigned short);
57 typedef void (*writerdp_t
)(void *, unsigned short);
58 typedef unsigned short (*readrdp_t
)(void *);
60 static const struct net_device_ops lance_netdev_ops
= {
61 .ndo_open
= m147lance_open
,
62 .ndo_stop
= m147lance_close
,
63 .ndo_start_xmit
= lance_start_xmit
,
64 .ndo_set_rx_mode
= lance_set_multicast
,
65 .ndo_tx_timeout
= lance_tx_timeout
,
66 .ndo_validate_addr
= eth_validate_addr
,
67 .ndo_set_mac_address
= eth_mac_addr
,
70 /* Initialise the one and only on-board 7990 */
71 static struct net_device
* __init
mvme147lance_probe(void)
73 struct net_device
*dev
;
75 static const char name
[] = "MVME147 LANCE";
76 struct m147lance_private
*lp
;
82 if (!MACH_IS_MVME147
|| called
)
83 return ERR_PTR(-ENODEV
);
86 dev
= alloc_etherdev(sizeof(struct m147lance_private
));
88 return ERR_PTR(-ENOMEM
);
90 /* Fill the dev fields */
91 dev
->base_addr
= (unsigned long)MVME147_LANCE_BASE
;
92 dev
->netdev_ops
= &lance_netdev_ops
;
95 addr
= (u_long
*)ETHERNET_ADDRESS
;
100 address
= address
>> 8;
101 macaddr
[5] = address
&0xff;
102 address
= address
>> 8;
103 macaddr
[4] = address
&0xff;
104 address
= address
>> 8;
105 macaddr
[3] = address
&0xff;
106 eth_hw_addr_set(dev
, macaddr
);
108 lp
= netdev_priv(dev
);
109 lp
->ram
= __get_dma_pages(GFP_ATOMIC
, 3); /* 32K */
111 printk("%s: No memory for LANCE buffers\n", dev
->name
);
113 return ERR_PTR(-ENOMEM
);
116 lp
->lance
.name
= name
;
117 lp
->lance
.base
= dev
->base_addr
;
118 lp
->lance
.init_block
= (struct lance_init_block
*)(lp
->ram
); /* CPU addr */
119 lp
->lance
.lance_init_block
= (struct lance_init_block
*)(lp
->ram
); /* LANCE addr of same RAM */
120 lp
->lance
.busmaster_regval
= LE_C3_BSWP
; /* we're bigendian */
121 lp
->lance
.irq
= MVME147_LANCE_IRQ
;
122 lp
->lance
.writerap
= (writerap_t
)m147lance_writerap
;
123 lp
->lance
.writerdp
= (writerdp_t
)m147lance_writerdp
;
124 lp
->lance
.readrdp
= (readrdp_t
)m147lance_readrdp
;
125 lp
->lance
.lance_log_rx_bufs
= LANCE_LOG_RX_BUFFERS
;
126 lp
->lance
.lance_log_tx_bufs
= LANCE_LOG_TX_BUFFERS
;
127 lp
->lance
.rx_ring_mod_mask
= RX_RING_MOD_MASK
;
128 lp
->lance
.tx_ring_mod_mask
= TX_RING_MOD_MASK
;
130 err
= register_netdev(dev
);
132 free_pages(lp
->ram
, 3);
137 netdev_info(dev
, "MVME147 at 0x%08lx, irq %d, Hardware Address %pM\n",
138 dev
->base_addr
, MVME147_LANCE_IRQ
, dev
->dev_addr
);
143 static void m147lance_writerap(struct lance_private
*lp
, unsigned short value
)
145 out_be16(lp
->base
+ LANCE_RAP
, value
);
148 static void m147lance_writerdp(struct lance_private
*lp
, unsigned short value
)
150 out_be16(lp
->base
+ LANCE_RDP
, value
);
153 static unsigned short m147lance_readrdp(struct lance_private
*lp
)
155 return in_be16(lp
->base
+ LANCE_RDP
);
158 static int m147lance_open(struct net_device
*dev
)
162 status
= lance_open(dev
); /* call generic lance open code */
165 /* enable interrupts at board level. */
166 m147_pcc
->lan_cntrl
= 0; /* clear the interrupts (if any) */
167 m147_pcc
->lan_cntrl
= 0x08 | 0x04; /* Enable irq 4 */
172 static int m147lance_close(struct net_device
*dev
)
174 /* disable interrupts at boardlevel */
175 m147_pcc
->lan_cntrl
= 0x0; /* disable interrupts */
180 MODULE_DESCRIPTION("MVME147 LANCE Ethernet driver");
181 MODULE_LICENSE("GPL");
183 static struct net_device
*dev_mvme147_lance
;
184 static int __init
m147lance_init(void)
186 dev_mvme147_lance
= mvme147lance_probe();
187 return PTR_ERR_OR_ZERO(dev_mvme147_lance
);
189 module_init(m147lance_init
);
191 static void __exit
m147lance_exit(void)
193 struct m147lance_private
*lp
= netdev_priv(dev_mvme147_lance
);
194 unregister_netdev(dev_mvme147_lance
);
195 free_pages(lp
->ram
, 3);
196 free_netdev(dev_mvme147_lance
);
198 module_exit(m147lance_exit
);