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