Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
efcce839 FT |
2 | * jazzsonic.c |
3 | * | |
4 | * (C) 2005 Finn Thain | |
5 | * | |
6 | * Converted to DMA API, and (from the mac68k project) introduced | |
7 | * dhd's support for 16-bit cards. | |
1da177e4 LT |
8 | * |
9 | * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de) | |
6aa20a22 | 10 | * |
1da177e4 LT |
11 | * This driver is based on work from Andreas Busse, but most of |
12 | * the code is rewritten. | |
6aa20a22 | 13 | * |
1da177e4 LT |
14 | * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de) |
15 | * | |
16 | * A driver for the onboard Sonic ethernet controller on Mips Jazz | |
17 | * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and | |
18 | * perhaps others, too) | |
19 | */ | |
20 | ||
21 | #include <linux/kernel.h> | |
22 | #include <linux/module.h> | |
23 | #include <linux/types.h> | |
24 | #include <linux/fcntl.h> | |
25 | #include <linux/interrupt.h> | |
26 | #include <linux/init.h> | |
27 | #include <linux/ioport.h> | |
28 | #include <linux/in.h> | |
29 | #include <linux/slab.h> | |
30 | #include <linux/string.h> | |
31 | #include <linux/delay.h> | |
32 | #include <linux/errno.h> | |
33 | #include <linux/netdevice.h> | |
34 | #include <linux/etherdevice.h> | |
35 | #include <linux/skbuff.h> | |
d052d1be | 36 | #include <linux/platform_device.h> |
efcce839 | 37 | #include <linux/dma-mapping.h> |
1da177e4 LT |
38 | |
39 | #include <asm/bootinfo.h> | |
40 | #include <asm/system.h> | |
41 | #include <asm/pgtable.h> | |
42 | #include <asm/io.h> | |
43 | #include <asm/dma.h> | |
44 | #include <asm/jazz.h> | |
45 | #include <asm/jazzdma.h> | |
46 | ||
47 | static char jazz_sonic_string[] = "jazzsonic"; | |
1da177e4 LT |
48 | |
49 | #define SONIC_MEM_SIZE 0x100 | |
50 | ||
1da177e4 LT |
51 | #include "sonic.h" |
52 | ||
53 | /* | |
54 | * Macros to access SONIC registers | |
55 | */ | |
efcce839 | 56 | #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg)) |
1da177e4 LT |
57 | |
58 | #define SONIC_WRITE(reg,val) \ | |
59 | do { \ | |
efcce839 | 60 | *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \ |
1da177e4 LT |
61 | } while (0) |
62 | ||
63 | ||
efcce839 | 64 | /* use 0 for production, 1 for verification, >1 for debug */ |
1da177e4 LT |
65 | #ifdef SONIC_DEBUG |
66 | static unsigned int sonic_debug = SONIC_DEBUG; | |
6aa20a22 | 67 | #else |
1da177e4 LT |
68 | static unsigned int sonic_debug = 1; |
69 | #endif | |
70 | ||
1da177e4 LT |
71 | /* |
72 | * We cannot use station (ethernet) address prefixes to detect the | |
73 | * sonic controller since these are board manufacturer depended. | |
6aa20a22 | 74 | * So we check for known Silicon Revision IDs instead. |
1da177e4 LT |
75 | */ |
76 | static unsigned short known_revisions[] = | |
77 | { | |
78 | 0x04, /* Mips Magnum 4000 */ | |
79 | 0xffff /* end of list */ | |
80 | }; | |
81 | ||
f4d86754 FT |
82 | static int jazzsonic_open(struct net_device* dev) |
83 | { | |
84 | if (request_irq(dev->irq, &sonic_interrupt, IRQF_DISABLED, "sonic", dev)) { | |
85 | printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq); | |
86 | return -EAGAIN; | |
87 | } | |
88 | return sonic_open(dev); | |
89 | } | |
90 | ||
91 | static int jazzsonic_close(struct net_device* dev) | |
92 | { | |
93 | int err; | |
94 | err = sonic_close(dev); | |
95 | free_irq(dev->irq, dev); | |
96 | return err; | |
97 | } | |
98 | ||
efcce839 | 99 | static int __init sonic_probe1(struct net_device *dev) |
1da177e4 LT |
100 | { |
101 | static unsigned version_printed; | |
102 | unsigned int silicon_revision; | |
103 | unsigned int val; | |
efcce839 | 104 | struct sonic_local *lp = netdev_priv(dev); |
1da177e4 LT |
105 | int err = -ENODEV; |
106 | int i; | |
107 | ||
efcce839 | 108 | if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string)) |
1da177e4 | 109 | return -EBUSY; |
efcce839 | 110 | |
1da177e4 LT |
111 | /* |
112 | * get the Silicon Revision ID. If this is one of the known | |
113 | * one assume that we found a SONIC ethernet controller at | |
114 | * the expected location. | |
115 | */ | |
116 | silicon_revision = SONIC_READ(SONIC_SR); | |
117 | if (sonic_debug > 1) | |
118 | printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision); | |
119 | ||
120 | i = 0; | |
121 | while (known_revisions[i] != 0xffff | |
122 | && known_revisions[i] != silicon_revision) | |
123 | i++; | |
124 | ||
125 | if (known_revisions[i] == 0xffff) { | |
126 | printk("SONIC ethernet controller not found (0x%4x)\n", | |
127 | silicon_revision); | |
128 | goto out; | |
129 | } | |
6aa20a22 | 130 | |
1da177e4 LT |
131 | if (sonic_debug && version_printed++ == 0) |
132 | printk(version); | |
133 | ||
efcce839 | 134 | printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr); |
1da177e4 LT |
135 | |
136 | /* | |
137 | * Put the sonic into software reset, then | |
138 | * retrieve and print the ethernet address. | |
139 | */ | |
140 | SONIC_WRITE(SONIC_CMD,SONIC_CR_RST); | |
141 | SONIC_WRITE(SONIC_CEP,0); | |
142 | for (i=0; i<3; i++) { | |
143 | val = SONIC_READ(SONIC_CAP0-i); | |
144 | dev->dev_addr[i*2] = val; | |
145 | dev->dev_addr[i*2+1] = val >> 8; | |
146 | } | |
147 | ||
1da177e4 | 148 | err = -ENOMEM; |
6aa20a22 | 149 | |
1da177e4 | 150 | /* Initialize the device structure. */ |
1da177e4 | 151 | |
efcce839 | 152 | lp->dma_bitmode = SONIC_BITMODE32; |
1da177e4 | 153 | |
efcce839 FT |
154 | /* Allocate the entire chunk of memory for the descriptors. |
155 | Note that this cannot cross a 64K boundary. */ | |
156 | if ((lp->descriptors = dma_alloc_coherent(lp->device, | |
157 | SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), | |
158 | &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { | |
159 | printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); | |
160 | goto out; | |
1da177e4 LT |
161 | } |
162 | ||
efcce839 FT |
163 | /* Now set up the pointers to point to the appropriate places */ |
164 | lp->cda = lp->descriptors; | |
165 | lp->tda = lp->cda + (SIZEOF_SONIC_CDA | |
166 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
167 | lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS | |
168 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
169 | lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS | |
170 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
171 | ||
172 | lp->cda_laddr = lp->descriptors_laddr; | |
173 | lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA | |
174 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
175 | lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS | |
176 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
177 | lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS | |
178 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
179 | ||
f4d86754 FT |
180 | dev->open = jazzsonic_open; |
181 | dev->stop = jazzsonic_close; | |
1da177e4 | 182 | dev->hard_start_xmit = sonic_send_packet; |
efcce839 | 183 | dev->get_stats = sonic_get_stats; |
1da177e4 | 184 | dev->set_multicast_list = &sonic_multicast_list; |
efcce839 | 185 | dev->tx_timeout = sonic_tx_timeout; |
1da177e4 LT |
186 | dev->watchdog_timeo = TX_TIMEOUT; |
187 | ||
188 | /* | |
189 | * clear tally counter | |
190 | */ | |
191 | SONIC_WRITE(SONIC_CRCT,0xffff); | |
192 | SONIC_WRITE(SONIC_FAET,0xffff); | |
193 | SONIC_WRITE(SONIC_MPT,0xffff); | |
194 | ||
195 | return 0; | |
1da177e4 | 196 | out: |
efcce839 | 197 | release_region(dev->base_addr, SONIC_MEM_SIZE); |
1da177e4 LT |
198 | return err; |
199 | } | |
200 | ||
201 | /* | |
202 | * Probe for a SONIC ethernet controller on a Mips Jazz board. | |
203 | * Actually probing is superfluous but we're paranoid. | |
204 | */ | |
3ae5eaec | 205 | static int __init jazz_sonic_probe(struct platform_device *pdev) |
1da177e4 LT |
206 | { |
207 | struct net_device *dev; | |
208 | struct sonic_local *lp; | |
ed9f0e0b | 209 | struct resource *res; |
1da177e4 | 210 | int err = 0; |
0795af57 | 211 | DECLARE_MAC_BUF(mac); |
1da177e4 | 212 | |
ed9f0e0b TB |
213 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
214 | if (!res) | |
1da177e4 LT |
215 | return -ENODEV; |
216 | ||
efcce839 | 217 | dev = alloc_etherdev(sizeof(struct sonic_local)); |
1da177e4 LT |
218 | if (!dev) |
219 | return -ENOMEM; | |
220 | ||
efcce839 | 221 | lp = netdev_priv(dev); |
3ae5eaec RK |
222 | lp->device = &pdev->dev; |
223 | SET_NETDEV_DEV(dev, &pdev->dev); | |
efcce839 | 224 | |
1da177e4 | 225 | netdev_boot_setup_check(dev); |
1da177e4 | 226 | |
ed9f0e0b TB |
227 | dev->base_addr = res->start; |
228 | dev->irq = platform_get_irq(pdev, 0); | |
229 | err = sonic_probe1(dev); | |
1da177e4 LT |
230 | if (err) |
231 | goto out; | |
232 | err = register_netdev(dev); | |
233 | if (err) | |
234 | goto out1; | |
235 | ||
0795af57 JP |
236 | printk("%s: MAC %s IRQ %d\n", |
237 | dev->name, print_mac(mac, dev->dev_addr), dev->irq); | |
efcce839 | 238 | |
1da177e4 LT |
239 | return 0; |
240 | ||
241 | out1: | |
1da177e4 LT |
242 | release_region(dev->base_addr, SONIC_MEM_SIZE); |
243 | out: | |
244 | free_netdev(dev); | |
245 | ||
246 | return err; | |
247 | } | |
248 | ||
efcce839 FT |
249 | MODULE_DESCRIPTION("Jazz SONIC ethernet driver"); |
250 | module_param(sonic_debug, int, 0); | |
251 | MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)"); | |
1da177e4 | 252 | |
1da177e4 LT |
253 | #include "sonic.c" |
254 | ||
3ae5eaec | 255 | static int __devexit jazz_sonic_device_remove (struct platform_device *pdev) |
1da177e4 | 256 | { |
3ae5eaec | 257 | struct net_device *dev = platform_get_drvdata(pdev); |
efcce839 | 258 | struct sonic_local* lp = netdev_priv(dev); |
1da177e4 | 259 | |
d74472f0 | 260 | unregister_netdev(dev); |
efcce839 FT |
261 | dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), |
262 | lp->descriptors, lp->descriptors_laddr); | |
1da177e4 | 263 | release_region (dev->base_addr, SONIC_MEM_SIZE); |
d74472f0 | 264 | free_netdev(dev); |
1da177e4 LT |
265 | |
266 | return 0; | |
267 | } | |
268 | ||
3ae5eaec | 269 | static struct platform_driver jazz_sonic_driver = { |
1da177e4 LT |
270 | .probe = jazz_sonic_probe, |
271 | .remove = __devexit_p(jazz_sonic_device_remove), | |
3ae5eaec RK |
272 | .driver = { |
273 | .name = jazz_sonic_string, | |
274 | }, | |
1da177e4 | 275 | }; |
efcce839 | 276 | |
1da177e4 LT |
277 | static int __init jazz_sonic_init_module(void) |
278 | { | |
ed9f0e0b | 279 | return platform_driver_register(&jazz_sonic_driver); |
1da177e4 LT |
280 | } |
281 | ||
282 | static void __exit jazz_sonic_cleanup_module(void) | |
283 | { | |
3ae5eaec | 284 | platform_driver_unregister(&jazz_sonic_driver); |
1da177e4 LT |
285 | } |
286 | ||
287 | module_init(jazz_sonic_init_module); | |
288 | module_exit(jazz_sonic_cleanup_module); |