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> | |
5a0e3ad6 | 25 | #include <linux/gfp.h> |
1da177e4 LT |
26 | #include <linux/interrupt.h> |
27 | #include <linux/init.h> | |
28 | #include <linux/ioport.h> | |
29 | #include <linux/in.h> | |
1da177e4 LT |
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> |
5a0e3ad6 | 38 | #include <linux/slab.h> |
1da177e4 LT |
39 | |
40 | #include <asm/bootinfo.h> | |
41 | #include <asm/system.h> | |
42 | #include <asm/pgtable.h> | |
43 | #include <asm/io.h> | |
44 | #include <asm/dma.h> | |
45 | #include <asm/jazz.h> | |
46 | #include <asm/jazzdma.h> | |
47 | ||
48 | static char jazz_sonic_string[] = "jazzsonic"; | |
1da177e4 LT |
49 | |
50 | #define SONIC_MEM_SIZE 0x100 | |
51 | ||
1da177e4 LT |
52 | #include "sonic.h" |
53 | ||
54 | /* | |
55 | * Macros to access SONIC registers | |
56 | */ | |
efcce839 | 57 | #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg)) |
1da177e4 LT |
58 | |
59 | #define SONIC_WRITE(reg,val) \ | |
60 | do { \ | |
efcce839 | 61 | *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \ |
1da177e4 LT |
62 | } while (0) |
63 | ||
64 | ||
efcce839 | 65 | /* use 0 for production, 1 for verification, >1 for debug */ |
1da177e4 LT |
66 | #ifdef SONIC_DEBUG |
67 | static unsigned int sonic_debug = SONIC_DEBUG; | |
6aa20a22 | 68 | #else |
1da177e4 LT |
69 | static unsigned int sonic_debug = 1; |
70 | #endif | |
71 | ||
1da177e4 LT |
72 | /* |
73 | * We cannot use station (ethernet) address prefixes to detect the | |
74 | * sonic controller since these are board manufacturer depended. | |
6aa20a22 | 75 | * So we check for known Silicon Revision IDs instead. |
1da177e4 LT |
76 | */ |
77 | static unsigned short known_revisions[] = | |
78 | { | |
79 | 0x04, /* Mips Magnum 4000 */ | |
80 | 0xffff /* end of list */ | |
81 | }; | |
82 | ||
f4d86754 FT |
83 | static int jazzsonic_open(struct net_device* dev) |
84 | { | |
a0607fd3 | 85 | if (request_irq(dev->irq, sonic_interrupt, IRQF_DISABLED, "sonic", dev)) { |
f4d86754 FT |
86 | printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq); |
87 | return -EAGAIN; | |
88 | } | |
89 | return sonic_open(dev); | |
90 | } | |
91 | ||
92 | static int jazzsonic_close(struct net_device* dev) | |
93 | { | |
94 | int err; | |
95 | err = sonic_close(dev); | |
96 | free_irq(dev->irq, dev); | |
97 | return err; | |
98 | } | |
99 | ||
502a326f AB |
100 | static const struct net_device_ops sonic_netdev_ops = { |
101 | .ndo_open = jazzsonic_open, | |
102 | .ndo_stop = jazzsonic_close, | |
103 | .ndo_start_xmit = sonic_send_packet, | |
104 | .ndo_get_stats = sonic_get_stats, | |
105 | .ndo_set_multicast_list = sonic_multicast_list, | |
106 | .ndo_tx_timeout = sonic_tx_timeout, | |
107 | .ndo_change_mtu = eth_change_mtu, | |
108 | .ndo_validate_addr = eth_validate_addr, | |
109 | .ndo_set_mac_address = eth_mac_addr, | |
110 | }; | |
111 | ||
2e76baea | 112 | static int __devinit sonic_probe1(struct net_device *dev) |
1da177e4 LT |
113 | { |
114 | static unsigned version_printed; | |
115 | unsigned int silicon_revision; | |
116 | unsigned int val; | |
efcce839 | 117 | struct sonic_local *lp = netdev_priv(dev); |
1da177e4 LT |
118 | int err = -ENODEV; |
119 | int i; | |
120 | ||
efcce839 | 121 | if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string)) |
1da177e4 | 122 | return -EBUSY; |
efcce839 | 123 | |
1da177e4 LT |
124 | /* |
125 | * get the Silicon Revision ID. If this is one of the known | |
126 | * one assume that we found a SONIC ethernet controller at | |
127 | * the expected location. | |
128 | */ | |
129 | silicon_revision = SONIC_READ(SONIC_SR); | |
130 | if (sonic_debug > 1) | |
131 | printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision); | |
132 | ||
133 | i = 0; | |
8e95a202 JP |
134 | while (known_revisions[i] != 0xffff && |
135 | known_revisions[i] != silicon_revision) | |
1da177e4 LT |
136 | i++; |
137 | ||
138 | if (known_revisions[i] == 0xffff) { | |
139 | printk("SONIC ethernet controller not found (0x%4x)\n", | |
140 | silicon_revision); | |
141 | goto out; | |
142 | } | |
6aa20a22 | 143 | |
1da177e4 LT |
144 | if (sonic_debug && version_printed++ == 0) |
145 | printk(version); | |
146 | ||
c2313557 KS |
147 | printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", |
148 | dev_name(lp->device), dev->base_addr); | |
1da177e4 LT |
149 | |
150 | /* | |
151 | * Put the sonic into software reset, then | |
152 | * retrieve and print the ethernet address. | |
153 | */ | |
154 | SONIC_WRITE(SONIC_CMD,SONIC_CR_RST); | |
155 | SONIC_WRITE(SONIC_CEP,0); | |
156 | for (i=0; i<3; i++) { | |
157 | val = SONIC_READ(SONIC_CAP0-i); | |
158 | dev->dev_addr[i*2] = val; | |
159 | dev->dev_addr[i*2+1] = val >> 8; | |
160 | } | |
161 | ||
1da177e4 | 162 | err = -ENOMEM; |
6aa20a22 | 163 | |
1da177e4 | 164 | /* Initialize the device structure. */ |
1da177e4 | 165 | |
efcce839 | 166 | lp->dma_bitmode = SONIC_BITMODE32; |
1da177e4 | 167 | |
efcce839 FT |
168 | /* Allocate the entire chunk of memory for the descriptors. |
169 | Note that this cannot cross a 64K boundary. */ | |
170 | if ((lp->descriptors = dma_alloc_coherent(lp->device, | |
171 | SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), | |
172 | &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { | |
c2313557 KS |
173 | printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", |
174 | dev_name(lp->device)); | |
efcce839 | 175 | goto out; |
1da177e4 LT |
176 | } |
177 | ||
efcce839 FT |
178 | /* Now set up the pointers to point to the appropriate places */ |
179 | lp->cda = lp->descriptors; | |
180 | lp->tda = lp->cda + (SIZEOF_SONIC_CDA | |
181 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
182 | lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS | |
183 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
184 | lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS | |
185 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
186 | ||
187 | lp->cda_laddr = lp->descriptors_laddr; | |
188 | lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA | |
189 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
190 | lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS | |
191 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
192 | lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS | |
193 | * SONIC_BUS_SCALE(lp->dma_bitmode)); | |
194 | ||
502a326f | 195 | dev->netdev_ops = &sonic_netdev_ops; |
1da177e4 LT |
196 | dev->watchdog_timeo = TX_TIMEOUT; |
197 | ||
198 | /* | |
199 | * clear tally counter | |
200 | */ | |
201 | SONIC_WRITE(SONIC_CRCT,0xffff); | |
202 | SONIC_WRITE(SONIC_FAET,0xffff); | |
203 | SONIC_WRITE(SONIC_MPT,0xffff); | |
204 | ||
205 | return 0; | |
1da177e4 | 206 | out: |
c9145a2d | 207 | release_mem_region(dev->base_addr, SONIC_MEM_SIZE); |
1da177e4 LT |
208 | return err; |
209 | } | |
210 | ||
211 | /* | |
212 | * Probe for a SONIC ethernet controller on a Mips Jazz board. | |
213 | * Actually probing is superfluous but we're paranoid. | |
214 | */ | |
2e76baea | 215 | static int __devinit jazz_sonic_probe(struct platform_device *pdev) |
1da177e4 LT |
216 | { |
217 | struct net_device *dev; | |
218 | struct sonic_local *lp; | |
ed9f0e0b | 219 | struct resource *res; |
1da177e4 | 220 | int err = 0; |
1da177e4 | 221 | |
ed9f0e0b TB |
222 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
223 | if (!res) | |
1da177e4 LT |
224 | return -ENODEV; |
225 | ||
efcce839 | 226 | dev = alloc_etherdev(sizeof(struct sonic_local)); |
1da177e4 LT |
227 | if (!dev) |
228 | return -ENOMEM; | |
229 | ||
efcce839 | 230 | lp = netdev_priv(dev); |
3ae5eaec RK |
231 | lp->device = &pdev->dev; |
232 | SET_NETDEV_DEV(dev, &pdev->dev); | |
4564cba7 | 233 | platform_set_drvdata(pdev, dev); |
efcce839 | 234 | |
1da177e4 | 235 | netdev_boot_setup_check(dev); |
1da177e4 | 236 | |
ed9f0e0b TB |
237 | dev->base_addr = res->start; |
238 | dev->irq = platform_get_irq(pdev, 0); | |
239 | err = sonic_probe1(dev); | |
1da177e4 LT |
240 | if (err) |
241 | goto out; | |
242 | err = register_netdev(dev); | |
243 | if (err) | |
244 | goto out1; | |
245 | ||
e174961c | 246 | printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq); |
efcce839 | 247 | |
1da177e4 LT |
248 | return 0; |
249 | ||
250 | out1: | |
c9145a2d | 251 | release_mem_region(dev->base_addr, SONIC_MEM_SIZE); |
1da177e4 LT |
252 | out: |
253 | free_netdev(dev); | |
254 | ||
255 | return err; | |
256 | } | |
257 | ||
efcce839 FT |
258 | MODULE_DESCRIPTION("Jazz SONIC ethernet driver"); |
259 | module_param(sonic_debug, int, 0); | |
260 | MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)"); | |
72abb461 | 261 | MODULE_ALIAS("platform:jazzsonic"); |
1da177e4 | 262 | |
1da177e4 LT |
263 | #include "sonic.c" |
264 | ||
3ae5eaec | 265 | static int __devexit jazz_sonic_device_remove (struct platform_device *pdev) |
1da177e4 | 266 | { |
3ae5eaec | 267 | struct net_device *dev = platform_get_drvdata(pdev); |
efcce839 | 268 | struct sonic_local* lp = netdev_priv(dev); |
1da177e4 | 269 | |
d74472f0 | 270 | unregister_netdev(dev); |
efcce839 FT |
271 | dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), |
272 | lp->descriptors, lp->descriptors_laddr); | |
c9145a2d | 273 | release_mem_region(dev->base_addr, SONIC_MEM_SIZE); |
d74472f0 | 274 | free_netdev(dev); |
1da177e4 LT |
275 | |
276 | return 0; | |
277 | } | |
278 | ||
3ae5eaec | 279 | static struct platform_driver jazz_sonic_driver = { |
1da177e4 LT |
280 | .probe = jazz_sonic_probe, |
281 | .remove = __devexit_p(jazz_sonic_device_remove), | |
3ae5eaec RK |
282 | .driver = { |
283 | .name = jazz_sonic_string, | |
72abb461 | 284 | .owner = THIS_MODULE, |
3ae5eaec | 285 | }, |
1da177e4 | 286 | }; |
efcce839 | 287 | |
1da177e4 LT |
288 | static int __init jazz_sonic_init_module(void) |
289 | { | |
ed9f0e0b | 290 | return platform_driver_register(&jazz_sonic_driver); |
1da177e4 LT |
291 | } |
292 | ||
293 | static void __exit jazz_sonic_cleanup_module(void) | |
294 | { | |
3ae5eaec | 295 | platform_driver_unregister(&jazz_sonic_driver); |
1da177e4 LT |
296 | } |
297 | ||
298 | module_init(jazz_sonic_init_module); | |
299 | module_exit(jazz_sonic_cleanup_module); |