1 // SPDX-License-Identifier: GPL-2.0
7 * Converted to DMA API, and (from the mac68k project) introduced
8 * dhd's support for 16-bit cards.
10 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
12 * This driver is based on work from Andreas Busse, but most of
13 * the code is rewritten.
15 * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
17 * A driver for the onboard Sonic ethernet controller on Mips Jazz
18 * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and
19 * perhaps others, too)
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/fcntl.h>
26 #include <linux/gfp.h>
27 #include <linux/interrupt.h>
28 #include <linux/ioport.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>
36 #include <linux/platform_device.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/slab.h>
39 #include <linux/pgtable.h>
41 #include <asm/bootinfo.h>
45 #include <asm/jazzdma.h>
47 static char jazz_sonic_string
[] = "jazzsonic";
49 #define SONIC_MEM_SIZE 0x100
54 * Macros to access SONIC registers
56 #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
58 #define SONIC_WRITE(reg,val) \
60 *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
64 * We cannot use station (ethernet) address prefixes to detect the
65 * sonic controller since these are board manufacturer depended.
66 * So we check for known Silicon Revision IDs instead.
68 static unsigned short known_revisions
[] =
70 0x04, /* Mips Magnum 4000 */
71 0xffff /* end of list */
74 static int jazzsonic_open(struct net_device
* dev
)
78 retval
= request_irq(dev
->irq
, sonic_interrupt
, 0, "sonic", dev
);
80 printk(KERN_ERR
"%s: unable to get IRQ %d.\n",
85 retval
= sonic_open(dev
);
87 free_irq(dev
->irq
, dev
);
91 static int jazzsonic_close(struct net_device
* dev
)
94 err
= sonic_close(dev
);
95 free_irq(dev
->irq
, dev
);
99 static 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_rx_mode
= sonic_multicast_list
,
105 .ndo_tx_timeout
= sonic_tx_timeout
,
106 .ndo_validate_addr
= eth_validate_addr
,
107 .ndo_set_mac_address
= eth_mac_addr
,
110 static int sonic_probe1(struct net_device
*dev
)
112 unsigned int silicon_revision
;
114 struct sonic_local
*lp
= netdev_priv(dev
);
117 unsigned char addr
[ETH_ALEN
];
119 if (!request_mem_region(dev
->base_addr
, SONIC_MEM_SIZE
, jazz_sonic_string
))
123 * get the Silicon Revision ID. If this is one of the known
124 * one assume that we found a SONIC ethernet controller at
125 * the expected location.
127 silicon_revision
= SONIC_READ(SONIC_SR
);
129 while (known_revisions
[i
] != 0xffff &&
130 known_revisions
[i
] != silicon_revision
)
133 if (known_revisions
[i
] == 0xffff) {
134 pr_info("SONIC ethernet controller not found (0x%4x)\n",
140 * Put the sonic into software reset, then
141 * retrieve and print the ethernet address.
143 SONIC_WRITE(SONIC_CMD
,SONIC_CR_RST
);
144 SONIC_WRITE(SONIC_CEP
,0);
145 for (i
=0; i
<3; i
++) {
146 val
= SONIC_READ(SONIC_CAP0
-i
);
148 addr
[i
*2+1] = val
>> 8;
150 eth_hw_addr_set(dev
, addr
);
152 lp
->dma_bitmode
= SONIC_BITMODE32
;
154 err
= sonic_alloc_descriptors(dev
);
158 dev
->netdev_ops
= &sonic_netdev_ops
;
159 dev
->watchdog_timeo
= TX_TIMEOUT
;
162 * clear tally counter
164 SONIC_WRITE(SONIC_CRCT
,0xffff);
165 SONIC_WRITE(SONIC_FAET
,0xffff);
166 SONIC_WRITE(SONIC_MPT
,0xffff);
170 release_mem_region(dev
->base_addr
, SONIC_MEM_SIZE
);
175 * Probe for a SONIC ethernet controller on a Mips Jazz board.
176 * Actually probing is superfluous but we're paranoid.
178 static int jazz_sonic_probe(struct platform_device
*pdev
)
180 struct net_device
*dev
;
181 struct sonic_local
*lp
;
182 struct resource
*res
;
185 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
189 dev
= alloc_etherdev(sizeof(struct sonic_local
));
193 lp
= netdev_priv(dev
);
194 lp
->device
= &pdev
->dev
;
195 SET_NETDEV_DEV(dev
, &pdev
->dev
);
196 platform_set_drvdata(pdev
, dev
);
198 dev
->base_addr
= res
->start
;
199 dev
->irq
= platform_get_irq(pdev
, 0);
200 err
= sonic_probe1(dev
);
204 pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
205 dev
->base_addr
, dev
->dev_addr
, dev
->irq
);
209 err
= register_netdev(dev
);
216 dma_free_coherent(lp
->device
, SIZEOF_SONIC_DESC
* SONIC_BUS_SCALE(lp
->dma_bitmode
),
217 lp
->descriptors
, lp
->descriptors_laddr
);
218 release_mem_region(dev
->base_addr
, SONIC_MEM_SIZE
);
225 MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
226 MODULE_ALIAS("platform:jazzsonic");
230 static void jazz_sonic_device_remove(struct platform_device
*pdev
)
232 struct net_device
*dev
= platform_get_drvdata(pdev
);
233 struct sonic_local
* lp
= netdev_priv(dev
);
235 unregister_netdev(dev
);
236 dma_free_coherent(lp
->device
, SIZEOF_SONIC_DESC
* SONIC_BUS_SCALE(lp
->dma_bitmode
),
237 lp
->descriptors
, lp
->descriptors_laddr
);
238 release_mem_region(dev
->base_addr
, SONIC_MEM_SIZE
);
242 static struct platform_driver jazz_sonic_driver
= {
243 .probe
= jazz_sonic_probe
,
244 .remove_new
= jazz_sonic_device_remove
,
246 .name
= jazz_sonic_string
,
250 module_platform_driver(jazz_sonic_driver
);