1
2
3
4
5
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
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
30
31
32
33#define LANCE_LOG_TX_BUFFERS 1
34#define LANCE_LOG_RX_BUFFERS 3
35
36#include "7990.h"
37
38
39struct m147lance_private {
40 struct lance_private lance;
41 unsigned long ram;
42};
43
44
45
46
47
48
49static int m147lance_open(struct net_device *dev);
50static int m147lance_close(struct net_device *dev);
51static void m147lance_writerap(struct lance_private *lp, unsigned short value);
52static void m147lance_writerdp(struct lance_private *lp, unsigned short value);
53static unsigned short m147lance_readrdp(struct lance_private *lp);
54
55typedef void (*writerap_t)(void *, unsigned short);
56typedef void (*writerdp_t)(void *, unsigned short);
57typedef unsigned short (*readrdp_t)(void *);
58
59static 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_validate_addr = eth_validate_addr,
66 .ndo_set_mac_address = eth_mac_addr,
67};
68
69
70struct net_device * __init mvme147lance_probe(int unit)
71{
72 struct net_device *dev;
73 static int called;
74 static const char name[] = "MVME147 LANCE";
75 struct m147lance_private *lp;
76 u_long *addr;
77 u_long address;
78 int err;
79
80 if (!MACH_IS_MVME147 || called)
81 return ERR_PTR(-ENODEV);
82 called++;
83
84 dev = alloc_etherdev(sizeof(struct m147lance_private));
85 if (!dev)
86 return ERR_PTR(-ENOMEM);
87
88 if (unit >= 0)
89 sprintf(dev->name, "eth%d", unit);
90
91
92 dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
93 dev->netdev_ops = &lance_netdev_ops;
94 dev->dma = 0;
95
96 addr = (u_long *)ETHERNET_ADDRESS;
97 address = *addr;
98 dev->dev_addr[0] = 0x08;
99 dev->dev_addr[1] = 0x00;
100 dev->dev_addr[2] = 0x3e;
101 address = address >> 8;
102 dev->dev_addr[5] = address&0xff;
103 address = address >> 8;
104 dev->dev_addr[4] = address&0xff;
105 address = address >> 8;
106 dev->dev_addr[3] = address&0xff;
107
108 printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %pM\n",
109 dev->name, dev->base_addr, MVME147_LANCE_IRQ,
110 dev->dev_addr);
111
112 lp = netdev_priv(dev);
113 lp->ram = __get_dma_pages(GFP_ATOMIC, 3);
114 if (!lp->ram) {
115 printk("%s: No memory for LANCE buffers\n", dev->name);
116 free_netdev(dev);
117 return ERR_PTR(-ENOMEM);
118 }
119
120 lp->lance.name = name;
121 lp->lance.base = dev->base_addr;
122 lp->lance.init_block = (struct lance_init_block *)(lp->ram);
123 lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram);
124 lp->lance.busmaster_regval = LE_C3_BSWP;
125 lp->lance.irq = MVME147_LANCE_IRQ;
126 lp->lance.writerap = (writerap_t)m147lance_writerap;
127 lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
128 lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
129 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
130 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
131 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
132 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
133
134 err = register_netdev(dev);
135 if (err) {
136 free_pages(lp->ram, 3);
137 free_netdev(dev);
138 return ERR_PTR(err);
139 }
140
141 return dev;
142}
143
144static void m147lance_writerap(struct lance_private *lp, unsigned short value)
145{
146 out_be16(lp->base + LANCE_RAP, value);
147}
148
149static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
150{
151 out_be16(lp->base + LANCE_RDP, value);
152}
153
154static unsigned short m147lance_readrdp(struct lance_private *lp)
155{
156 return in_be16(lp->base + LANCE_RDP);
157}
158
159static int m147lance_open(struct net_device *dev)
160{
161 int status;
162
163 status = lance_open(dev);
164 if (status)
165 return status;
166
167 m147_pcc->lan_cntrl = 0;
168 m147_pcc->lan_cntrl = 0x08 | 0x04;
169
170 return 0;
171}
172
173static int m147lance_close(struct net_device *dev)
174{
175
176 m147_pcc->lan_cntrl = 0x0;
177 lance_close(dev);
178 return 0;
179}
180
181#ifdef MODULE
182MODULE_LICENSE("GPL");
183
184static struct net_device *dev_mvme147_lance;
185int __init init_module(void)
186{
187 dev_mvme147_lance = mvme147lance_probe(-1);
188 return PTR_ERR_OR_ZERO(dev_mvme147_lance);
189}
190
191void __exit cleanup_module(void)
192{
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);
197}
198
199#endif
200