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