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