xref: /openbmc/linux/drivers/net/ethernet/amd/mvme147.c (revision f7777dcc)
1 /* mvme147.c  : the  Linux/mvme147/lance ethernet driver
2  *
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.
6  */
7 
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/ioport.h>
13 #include <linux/string.h>
14 #include <linux/delay.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
17 #include <linux/gfp.h>
18 /* Used for the temporal inet entries and routing */
19 #include <linux/socket.h>
20 #include <linux/route.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/skbuff.h>
24 
25 #include <asm/io.h>
26 #include <asm/pgtable.h>
27 #include <asm/mvme147hw.h>
28 
29 /* We have 16834 bytes of RAM for the init block and buffers. This places
30  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
31  * buffers and 2 Tx buffers.
32  */
33 #define LANCE_LOG_TX_BUFFERS 1
34 #define LANCE_LOG_RX_BUFFERS 3
35 
36 #include "7990.h"                                 /* use generic LANCE code */
37 
38 /* Our private data structure */
39 struct m147lance_private {
40 	struct lance_private lance;
41 	unsigned long ram;
42 };
43 
44 /* function prototypes... This is easy because all the grot is in the
45  * generic LANCE support. All we have to support is probing for boards,
46  * plus board-specific init, open and close actions.
47  * Oh, and we need to tell the generic code how to read and write LANCE registers...
48  */
49 static int m147lance_open(struct net_device *dev);
50 static int m147lance_close(struct net_device *dev);
51 static void m147lance_writerap(struct lance_private *lp, unsigned short value);
52 static void m147lance_writerdp(struct lance_private *lp, unsigned short value);
53 static unsigned short m147lance_readrdp(struct lance_private *lp);
54 
55 typedef void (*writerap_t)(void *, unsigned short);
56 typedef void (*writerdp_t)(void *, unsigned short);
57 typedef unsigned short (*readrdp_t)(void *);
58 
59 static const struct net_device_ops lance_netdev_ops = {
60 	.ndo_open		= m147lance_open,
61 	.ndo_stop		= m147lance_close,
62 	.ndo_start_xmit		= lance_start_xmit,
63 	.ndo_set_rx_mode	= lance_set_multicast,
64 	.ndo_tx_timeout		= lance_tx_timeout,
65 	.ndo_change_mtu		= eth_change_mtu,
66 	.ndo_validate_addr	= eth_validate_addr,
67 	.ndo_set_mac_address	= eth_mac_addr,
68 };
69 
70 /* Initialise the one and only on-board 7990 */
71 struct net_device * __init mvme147lance_probe(int unit)
72 {
73 	struct net_device *dev;
74 	static int called;
75 	static const char name[] = "MVME147 LANCE";
76 	struct m147lance_private *lp;
77 	u_long *addr;
78 	u_long address;
79 	int err;
80 
81 	if (!MACH_IS_MVME147 || called)
82 		return ERR_PTR(-ENODEV);
83 	called++;
84 
85 	dev = alloc_etherdev(sizeof(struct m147lance_private));
86 	if (!dev)
87 		return ERR_PTR(-ENOMEM);
88 
89 	if (unit >= 0)
90 		sprintf(dev->name, "eth%d", unit);
91 
92 	/* Fill the dev fields */
93 	dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
94 	dev->netdev_ops = &lance_netdev_ops;
95 	dev->dma = 0;
96 
97 	addr=(u_long *)ETHERNET_ADDRESS;
98 	address = *addr;
99 	dev->dev_addr[0]=0x08;
100 	dev->dev_addr[1]=0x00;
101 	dev->dev_addr[2]=0x3e;
102 	address=address>>8;
103 	dev->dev_addr[5]=address&0xff;
104 	address=address>>8;
105 	dev->dev_addr[4]=address&0xff;
106 	address=address>>8;
107 	dev->dev_addr[3]=address&0xff;
108 
109 	printk("%s: MVME147 at 0x%08lx, irq %d, "
110 	       "Hardware Address %pM\n",
111 	       dev->name, dev->base_addr, MVME147_LANCE_IRQ,
112 	       dev->dev_addr);
113 
114 	lp = netdev_priv(dev);
115 	lp->ram = __get_dma_pages(GFP_ATOMIC, 3);	/* 16K */
116 	if (!lp->ram)
117 	{
118 		printk("%s: No memory for LANCE buffers\n", dev->name);
119 		free_netdev(dev);
120 		return ERR_PTR(-ENOMEM);
121 	}
122 
123 	lp->lance.name = (char*)name;                   /* discards const, shut up gcc */
124 	lp->lance.base = dev->base_addr;
125 	lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
126 	lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram);                 /* LANCE addr of same RAM */
127 	lp->lance.busmaster_regval = LE_C3_BSWP;        /* we're bigendian */
128 	lp->lance.irq = MVME147_LANCE_IRQ;
129 	lp->lance.writerap = (writerap_t)m147lance_writerap;
130 	lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
131 	lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
132 	lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
133 	lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
134 	lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
135 	lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
136 
137 	err = register_netdev(dev);
138 	if (err) {
139 		free_pages(lp->ram, 3);
140 		free_netdev(dev);
141 		return ERR_PTR(err);
142 	}
143 
144 	return dev;
145 }
146 
147 static void m147lance_writerap(struct lance_private *lp, unsigned short value)
148 {
149 	out_be16(lp->base + LANCE_RAP, value);
150 }
151 
152 static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
153 {
154 	out_be16(lp->base + LANCE_RDP, value);
155 }
156 
157 static unsigned short m147lance_readrdp(struct lance_private *lp)
158 {
159 	return in_be16(lp->base + LANCE_RDP);
160 }
161 
162 static int m147lance_open(struct net_device *dev)
163 {
164 	int status;
165 
166 	status = lance_open(dev);                 /* call generic lance open code */
167 	if (status)
168 		return status;
169 	/* enable interrupts at board level. */
170 	m147_pcc->lan_cntrl=0;       /* clear the interrupts (if any) */
171 	m147_pcc->lan_cntrl=0x08 | 0x04;     /* Enable irq 4 */
172 
173 	return 0;
174 }
175 
176 static int m147lance_close(struct net_device *dev)
177 {
178 	/* disable interrupts at boardlevel */
179 	m147_pcc->lan_cntrl=0x0; /* disable interrupts */
180 	lance_close(dev);
181 	return 0;
182 }
183 
184 #ifdef MODULE
185 MODULE_LICENSE("GPL");
186 
187 static struct net_device *dev_mvme147_lance;
188 int __init init_module(void)
189 {
190 	dev_mvme147_lance = mvme147lance_probe(-1);
191 	return PTR_ERR_OR_ZERO(dev_mvme147_lance);
192 }
193 
194 void __exit cleanup_module(void)
195 {
196 	struct m147lance_private *lp = netdev_priv(dev_mvme147_lance);
197 	unregister_netdev(dev_mvme147_lance);
198 	free_pages(lp->ram, 3);
199 	free_netdev(dev_mvme147_lance);
200 }
201 
202 #endif /* MODULE */
203