1ec21e2ecSJeff Kirsher /*
2ec21e2ecSJeff Kirsher * Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx.
3ec21e2ecSJeff Kirsher *
4ec21e2ecSJeff Kirsher * Copyright (c) 2003 Intracom S.A.
5ec21e2ecSJeff Kirsher * by Pantelis Antoniou <panto@intracom.gr>
6ec21e2ecSJeff Kirsher *
7ec21e2ecSJeff Kirsher * 2005 (c) MontaVista Software, Inc.
8ec21e2ecSJeff Kirsher * Vitaly Bordug <vbordug@ru.mvista.com>
9ec21e2ecSJeff Kirsher *
10ec21e2ecSJeff Kirsher * This file is licensed under the terms of the GNU General Public License
11ec21e2ecSJeff Kirsher * version 2. This program is licensed "as is" without any warranty of any
12ec21e2ecSJeff Kirsher * kind, whether express or implied.
13ec21e2ecSJeff Kirsher */
14ec21e2ecSJeff Kirsher
15ec21e2ecSJeff Kirsher #include <linux/module.h>
16ec21e2ecSJeff Kirsher #include <linux/kernel.h>
17ec21e2ecSJeff Kirsher #include <linux/types.h>
18ec21e2ecSJeff Kirsher #include <linux/string.h>
19ec21e2ecSJeff Kirsher #include <linux/ptrace.h>
20ec21e2ecSJeff Kirsher #include <linux/errno.h>
21ec21e2ecSJeff Kirsher #include <linux/ioport.h>
22ec21e2ecSJeff Kirsher #include <linux/interrupt.h>
23ec21e2ecSJeff Kirsher #include <linux/delay.h>
24ec21e2ecSJeff Kirsher #include <linux/netdevice.h>
25ec21e2ecSJeff Kirsher #include <linux/etherdevice.h>
26ec21e2ecSJeff Kirsher #include <linux/skbuff.h>
27ec21e2ecSJeff Kirsher #include <linux/spinlock.h>
28ec21e2ecSJeff Kirsher #include <linux/mii.h>
29ec21e2ecSJeff Kirsher #include <linux/ethtool.h>
30ec21e2ecSJeff Kirsher #include <linux/bitops.h>
31ec21e2ecSJeff Kirsher #include <linux/fs.h>
32ec21e2ecSJeff Kirsher #include <linux/platform_device.h>
335af50730SRob Herring #include <linux/of_address.h>
345af50730SRob Herring #include <linux/of_irq.h>
35ec21e2ecSJeff Kirsher
36ec21e2ecSJeff Kirsher #include <asm/irq.h>
377c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
38ec21e2ecSJeff Kirsher
39ec21e2ecSJeff Kirsher #include "fs_enet.h"
40ec21e2ecSJeff Kirsher
41ec21e2ecSJeff Kirsher /*************************************************/
42ec21e2ecSJeff Kirsher #if defined(CONFIG_CPM1)
43ec21e2ecSJeff Kirsher /* for a 8xx __raw_xxx's are sufficient */
44ec21e2ecSJeff Kirsher #define __fs_out32(addr, x) __raw_writel(x, addr)
45ec21e2ecSJeff Kirsher #define __fs_out16(addr, x) __raw_writew(x, addr)
46ec21e2ecSJeff Kirsher #define __fs_out8(addr, x) __raw_writeb(x, addr)
47ec21e2ecSJeff Kirsher #define __fs_in32(addr) __raw_readl(addr)
48ec21e2ecSJeff Kirsher #define __fs_in16(addr) __raw_readw(addr)
49ec21e2ecSJeff Kirsher #define __fs_in8(addr) __raw_readb(addr)
50ec21e2ecSJeff Kirsher #else
51ec21e2ecSJeff Kirsher /* for others play it safe */
52ec21e2ecSJeff Kirsher #define __fs_out32(addr, x) out_be32(addr, x)
53ec21e2ecSJeff Kirsher #define __fs_out16(addr, x) out_be16(addr, x)
54ec21e2ecSJeff Kirsher #define __fs_in32(addr) in_be32(addr)
55ec21e2ecSJeff Kirsher #define __fs_in16(addr) in_be16(addr)
56ec21e2ecSJeff Kirsher #define __fs_out8(addr, x) out_8(addr, x)
57ec21e2ecSJeff Kirsher #define __fs_in8(addr) in_8(addr)
58ec21e2ecSJeff Kirsher #endif
59ec21e2ecSJeff Kirsher
60ec21e2ecSJeff Kirsher /* write, read, set bits, clear bits */
61ec21e2ecSJeff Kirsher #define W32(_p, _m, _v) __fs_out32(&(_p)->_m, (_v))
62ec21e2ecSJeff Kirsher #define R32(_p, _m) __fs_in32(&(_p)->_m)
63ec21e2ecSJeff Kirsher #define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
64ec21e2ecSJeff Kirsher #define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
65ec21e2ecSJeff Kirsher
66ec21e2ecSJeff Kirsher #define W16(_p, _m, _v) __fs_out16(&(_p)->_m, (_v))
67ec21e2ecSJeff Kirsher #define R16(_p, _m) __fs_in16(&(_p)->_m)
68ec21e2ecSJeff Kirsher #define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
69ec21e2ecSJeff Kirsher #define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
70ec21e2ecSJeff Kirsher
71ec21e2ecSJeff Kirsher #define W8(_p, _m, _v) __fs_out8(&(_p)->_m, (_v))
72ec21e2ecSJeff Kirsher #define R8(_p, _m) __fs_in8(&(_p)->_m)
73ec21e2ecSJeff Kirsher #define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
74ec21e2ecSJeff Kirsher #define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
75ec21e2ecSJeff Kirsher
76ec21e2ecSJeff Kirsher #define SCC_MAX_MULTICAST_ADDRS 64
77ec21e2ecSJeff Kirsher
78ec21e2ecSJeff Kirsher /*
79ec21e2ecSJeff Kirsher * Delay to wait for SCC reset command to complete (in us)
80ec21e2ecSJeff Kirsher */
81ec21e2ecSJeff Kirsher #define SCC_RESET_DELAY 50
82ec21e2ecSJeff Kirsher
scc_cr_cmd(struct fs_enet_private * fep,u32 op)83ec21e2ecSJeff Kirsher static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
84ec21e2ecSJeff Kirsher {
85ec21e2ecSJeff Kirsher const struct fs_platform_info *fpi = fep->fpi;
86ec21e2ecSJeff Kirsher
87ec21e2ecSJeff Kirsher return cpm_command(fpi->cp_command, op);
88ec21e2ecSJeff Kirsher }
89ec21e2ecSJeff Kirsher
do_pd_setup(struct fs_enet_private * fep)90ec21e2ecSJeff Kirsher static int do_pd_setup(struct fs_enet_private *fep)
91ec21e2ecSJeff Kirsher {
92ec21e2ecSJeff Kirsher struct platform_device *ofdev = to_platform_device(fep->dev);
93ec21e2ecSJeff Kirsher
94f7578496SThierry Reding fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
9599c1790eSMichael Ellerman if (!fep->interrupt)
96ec21e2ecSJeff Kirsher return -EINVAL;
97ec21e2ecSJeff Kirsher
98ec21e2ecSJeff Kirsher fep->scc.sccp = of_iomap(ofdev->dev.of_node, 0);
99ec21e2ecSJeff Kirsher if (!fep->scc.sccp)
100ec21e2ecSJeff Kirsher return -EINVAL;
101ec21e2ecSJeff Kirsher
102ec21e2ecSJeff Kirsher fep->scc.ep = of_iomap(ofdev->dev.of_node, 1);
103ec21e2ecSJeff Kirsher if (!fep->scc.ep) {
104ec21e2ecSJeff Kirsher iounmap(fep->scc.sccp);
105ec21e2ecSJeff Kirsher return -EINVAL;
106ec21e2ecSJeff Kirsher }
107ec21e2ecSJeff Kirsher
108ec21e2ecSJeff Kirsher return 0;
109ec21e2ecSJeff Kirsher }
110ec21e2ecSJeff Kirsher
1118572763aSChristophe Leroy #define SCC_NAPI_EVENT_MSK (SCCE_ENET_RXF | SCCE_ENET_RXB | SCCE_ENET_TXB)
1128572763aSChristophe Leroy #define SCC_EVENT (SCCE_ENET_RXF | SCCE_ENET_TXB)
113ec21e2ecSJeff Kirsher #define SCC_ERR_EVENT_MSK (SCCE_ENET_TXE | SCCE_ENET_BSY)
114ec21e2ecSJeff Kirsher
setup_data(struct net_device * dev)115ec21e2ecSJeff Kirsher static int setup_data(struct net_device *dev)
116ec21e2ecSJeff Kirsher {
117ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
118ec21e2ecSJeff Kirsher
119ec21e2ecSJeff Kirsher do_pd_setup(fep);
120ec21e2ecSJeff Kirsher
121ec21e2ecSJeff Kirsher fep->scc.hthi = 0;
122ec21e2ecSJeff Kirsher fep->scc.htlo = 0;
123ec21e2ecSJeff Kirsher
1248572763aSChristophe Leroy fep->ev_napi = SCC_NAPI_EVENT_MSK;
1258572763aSChristophe Leroy fep->ev = SCC_EVENT | SCCE_ENET_TXE;
126ec21e2ecSJeff Kirsher fep->ev_err = SCC_ERR_EVENT_MSK;
127ec21e2ecSJeff Kirsher
128ec21e2ecSJeff Kirsher return 0;
129ec21e2ecSJeff Kirsher }
130ec21e2ecSJeff Kirsher
allocate_bd(struct net_device * dev)131ec21e2ecSJeff Kirsher static int allocate_bd(struct net_device *dev)
132ec21e2ecSJeff Kirsher {
133ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
134ec21e2ecSJeff Kirsher const struct fs_platform_info *fpi = fep->fpi;
135ec21e2ecSJeff Kirsher
136*5e6cb39aSChristophe Leroy fep->ring_mem_addr = cpm_muram_alloc((fpi->tx_ring + fpi->rx_ring) *
137ec21e2ecSJeff Kirsher sizeof(cbd_t), 8);
138ec21e2ecSJeff Kirsher if (IS_ERR_VALUE(fep->ring_mem_addr))
139ec21e2ecSJeff Kirsher return -ENOMEM;
140ec21e2ecSJeff Kirsher
141ec21e2ecSJeff Kirsher fep->ring_base = (void __iomem __force*)
142*5e6cb39aSChristophe Leroy cpm_muram_addr(fep->ring_mem_addr);
143ec21e2ecSJeff Kirsher
144ec21e2ecSJeff Kirsher return 0;
145ec21e2ecSJeff Kirsher }
146ec21e2ecSJeff Kirsher
free_bd(struct net_device * dev)147ec21e2ecSJeff Kirsher static void free_bd(struct net_device *dev)
148ec21e2ecSJeff Kirsher {
149ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
150ec21e2ecSJeff Kirsher
151ec21e2ecSJeff Kirsher if (fep->ring_base)
152*5e6cb39aSChristophe Leroy cpm_muram_free(fep->ring_mem_addr);
153ec21e2ecSJeff Kirsher }
154ec21e2ecSJeff Kirsher
cleanup_data(struct net_device * dev)155ec21e2ecSJeff Kirsher static void cleanup_data(struct net_device *dev)
156ec21e2ecSJeff Kirsher {
157ec21e2ecSJeff Kirsher /* nothing */
158ec21e2ecSJeff Kirsher }
159ec21e2ecSJeff Kirsher
set_promiscuous_mode(struct net_device * dev)160ec21e2ecSJeff Kirsher static void set_promiscuous_mode(struct net_device *dev)
161ec21e2ecSJeff Kirsher {
162ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
163ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
164ec21e2ecSJeff Kirsher
165ec21e2ecSJeff Kirsher S16(sccp, scc_psmr, SCC_PSMR_PRO);
166ec21e2ecSJeff Kirsher }
167ec21e2ecSJeff Kirsher
set_multicast_start(struct net_device * dev)168ec21e2ecSJeff Kirsher static void set_multicast_start(struct net_device *dev)
169ec21e2ecSJeff Kirsher {
170ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
171ec21e2ecSJeff Kirsher scc_enet_t __iomem *ep = fep->scc.ep;
172ec21e2ecSJeff Kirsher
173ec21e2ecSJeff Kirsher W16(ep, sen_gaddr1, 0);
174ec21e2ecSJeff Kirsher W16(ep, sen_gaddr2, 0);
175ec21e2ecSJeff Kirsher W16(ep, sen_gaddr3, 0);
176ec21e2ecSJeff Kirsher W16(ep, sen_gaddr4, 0);
177ec21e2ecSJeff Kirsher }
178ec21e2ecSJeff Kirsher
set_multicast_one(struct net_device * dev,const u8 * mac)179ec21e2ecSJeff Kirsher static void set_multicast_one(struct net_device *dev, const u8 * mac)
180ec21e2ecSJeff Kirsher {
181ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
182ec21e2ecSJeff Kirsher scc_enet_t __iomem *ep = fep->scc.ep;
183ec21e2ecSJeff Kirsher u16 taddrh, taddrm, taddrl;
184ec21e2ecSJeff Kirsher
185ec21e2ecSJeff Kirsher taddrh = ((u16) mac[5] << 8) | mac[4];
186ec21e2ecSJeff Kirsher taddrm = ((u16) mac[3] << 8) | mac[2];
187ec21e2ecSJeff Kirsher taddrl = ((u16) mac[1] << 8) | mac[0];
188ec21e2ecSJeff Kirsher
189ec21e2ecSJeff Kirsher W16(ep, sen_taddrh, taddrh);
190ec21e2ecSJeff Kirsher W16(ep, sen_taddrm, taddrm);
191ec21e2ecSJeff Kirsher W16(ep, sen_taddrl, taddrl);
192ec21e2ecSJeff Kirsher scc_cr_cmd(fep, CPM_CR_SET_GADDR);
193ec21e2ecSJeff Kirsher }
194ec21e2ecSJeff Kirsher
set_multicast_finish(struct net_device * dev)195ec21e2ecSJeff Kirsher static void set_multicast_finish(struct net_device *dev)
196ec21e2ecSJeff Kirsher {
197ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
198ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
199ec21e2ecSJeff Kirsher scc_enet_t __iomem *ep = fep->scc.ep;
200ec21e2ecSJeff Kirsher
201ec21e2ecSJeff Kirsher /* clear promiscuous always */
202ec21e2ecSJeff Kirsher C16(sccp, scc_psmr, SCC_PSMR_PRO);
203ec21e2ecSJeff Kirsher
204ec21e2ecSJeff Kirsher /* if all multi or too many multicasts; just enable all */
205ec21e2ecSJeff Kirsher if ((dev->flags & IFF_ALLMULTI) != 0 ||
206ec21e2ecSJeff Kirsher netdev_mc_count(dev) > SCC_MAX_MULTICAST_ADDRS) {
207ec21e2ecSJeff Kirsher
208ec21e2ecSJeff Kirsher W16(ep, sen_gaddr1, 0xffff);
209ec21e2ecSJeff Kirsher W16(ep, sen_gaddr2, 0xffff);
210ec21e2ecSJeff Kirsher W16(ep, sen_gaddr3, 0xffff);
211ec21e2ecSJeff Kirsher W16(ep, sen_gaddr4, 0xffff);
212ec21e2ecSJeff Kirsher }
213ec21e2ecSJeff Kirsher }
214ec21e2ecSJeff Kirsher
set_multicast_list(struct net_device * dev)215ec21e2ecSJeff Kirsher static void set_multicast_list(struct net_device *dev)
216ec21e2ecSJeff Kirsher {
217ec21e2ecSJeff Kirsher struct netdev_hw_addr *ha;
218ec21e2ecSJeff Kirsher
219ec21e2ecSJeff Kirsher if ((dev->flags & IFF_PROMISC) == 0) {
220ec21e2ecSJeff Kirsher set_multicast_start(dev);
221ec21e2ecSJeff Kirsher netdev_for_each_mc_addr(ha, dev)
222ec21e2ecSJeff Kirsher set_multicast_one(dev, ha->addr);
223ec21e2ecSJeff Kirsher set_multicast_finish(dev);
224ec21e2ecSJeff Kirsher } else
225ec21e2ecSJeff Kirsher set_promiscuous_mode(dev);
226ec21e2ecSJeff Kirsher }
227ec21e2ecSJeff Kirsher
228ec21e2ecSJeff Kirsher /*
229ec21e2ecSJeff Kirsher * This function is called to start or restart the FEC during a link
230ec21e2ecSJeff Kirsher * change. This only happens when switching between half and full
231ec21e2ecSJeff Kirsher * duplex.
232ec21e2ecSJeff Kirsher */
restart(struct net_device * dev)233ec21e2ecSJeff Kirsher static void restart(struct net_device *dev)
234ec21e2ecSJeff Kirsher {
235ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
236ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
237ec21e2ecSJeff Kirsher scc_enet_t __iomem *ep = fep->scc.ep;
238ec21e2ecSJeff Kirsher const struct fs_platform_info *fpi = fep->fpi;
239ec21e2ecSJeff Kirsher u16 paddrh, paddrm, paddrl;
240ec21e2ecSJeff Kirsher const unsigned char *mac;
241ec21e2ecSJeff Kirsher int i;
242ec21e2ecSJeff Kirsher
243ec21e2ecSJeff Kirsher C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
244ec21e2ecSJeff Kirsher
245ec21e2ecSJeff Kirsher /* clear everything (slow & steady does it) */
246ec21e2ecSJeff Kirsher for (i = 0; i < sizeof(*ep); i++)
247ec21e2ecSJeff Kirsher __fs_out8((u8 __iomem *)ep + i, 0);
248ec21e2ecSJeff Kirsher
249ec21e2ecSJeff Kirsher /* point to bds */
250ec21e2ecSJeff Kirsher W16(ep, sen_genscc.scc_rbase, fep->ring_mem_addr);
251ec21e2ecSJeff Kirsher W16(ep, sen_genscc.scc_tbase,
252ec21e2ecSJeff Kirsher fep->ring_mem_addr + sizeof(cbd_t) * fpi->rx_ring);
253ec21e2ecSJeff Kirsher
254ec21e2ecSJeff Kirsher /* Initialize function code registers for big-endian.
255ec21e2ecSJeff Kirsher */
256ec21e2ecSJeff Kirsher #ifndef CONFIG_NOT_COHERENT_CACHE
257ec21e2ecSJeff Kirsher W8(ep, sen_genscc.scc_rfcr, SCC_EB | SCC_GBL);
258ec21e2ecSJeff Kirsher W8(ep, sen_genscc.scc_tfcr, SCC_EB | SCC_GBL);
259ec21e2ecSJeff Kirsher #else
260ec21e2ecSJeff Kirsher W8(ep, sen_genscc.scc_rfcr, SCC_EB);
261ec21e2ecSJeff Kirsher W8(ep, sen_genscc.scc_tfcr, SCC_EB);
262ec21e2ecSJeff Kirsher #endif
263ec21e2ecSJeff Kirsher
264ec21e2ecSJeff Kirsher /* Set maximum bytes per receive buffer.
265ec21e2ecSJeff Kirsher * This appears to be an Ethernet frame size, not the buffer
266ec21e2ecSJeff Kirsher * fragment size. It must be a multiple of four.
267ec21e2ecSJeff Kirsher */
268ec21e2ecSJeff Kirsher W16(ep, sen_genscc.scc_mrblr, 0x5f0);
269ec21e2ecSJeff Kirsher
270ec21e2ecSJeff Kirsher /* Set CRC preset and mask.
271ec21e2ecSJeff Kirsher */
272ec21e2ecSJeff Kirsher W32(ep, sen_cpres, 0xffffffff);
273ec21e2ecSJeff Kirsher W32(ep, sen_cmask, 0xdebb20e3);
274ec21e2ecSJeff Kirsher
275ec21e2ecSJeff Kirsher W32(ep, sen_crcec, 0); /* CRC Error counter */
276ec21e2ecSJeff Kirsher W32(ep, sen_alec, 0); /* alignment error counter */
277ec21e2ecSJeff Kirsher W32(ep, sen_disfc, 0); /* discard frame counter */
278ec21e2ecSJeff Kirsher
279ec21e2ecSJeff Kirsher W16(ep, sen_pads, 0x8888); /* Tx short frame pad character */
280ec21e2ecSJeff Kirsher W16(ep, sen_retlim, 15); /* Retry limit threshold */
281ec21e2ecSJeff Kirsher
282ec21e2ecSJeff Kirsher W16(ep, sen_maxflr, 0x5ee); /* maximum frame length register */
283ec21e2ecSJeff Kirsher
284ec21e2ecSJeff Kirsher W16(ep, sen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
285ec21e2ecSJeff Kirsher
286ec21e2ecSJeff Kirsher W16(ep, sen_maxd1, 0x000005f0); /* maximum DMA1 length */
287ec21e2ecSJeff Kirsher W16(ep, sen_maxd2, 0x000005f0); /* maximum DMA2 length */
288ec21e2ecSJeff Kirsher
289ec21e2ecSJeff Kirsher /* Clear hash tables.
290ec21e2ecSJeff Kirsher */
291ec21e2ecSJeff Kirsher W16(ep, sen_gaddr1, 0);
292ec21e2ecSJeff Kirsher W16(ep, sen_gaddr2, 0);
293ec21e2ecSJeff Kirsher W16(ep, sen_gaddr3, 0);
294ec21e2ecSJeff Kirsher W16(ep, sen_gaddr4, 0);
295ec21e2ecSJeff Kirsher W16(ep, sen_iaddr1, 0);
296ec21e2ecSJeff Kirsher W16(ep, sen_iaddr2, 0);
297ec21e2ecSJeff Kirsher W16(ep, sen_iaddr3, 0);
298ec21e2ecSJeff Kirsher W16(ep, sen_iaddr4, 0);
299ec21e2ecSJeff Kirsher
300ec21e2ecSJeff Kirsher /* set address
301ec21e2ecSJeff Kirsher */
302ec21e2ecSJeff Kirsher mac = dev->dev_addr;
303ec21e2ecSJeff Kirsher paddrh = ((u16) mac[5] << 8) | mac[4];
304ec21e2ecSJeff Kirsher paddrm = ((u16) mac[3] << 8) | mac[2];
305ec21e2ecSJeff Kirsher paddrl = ((u16) mac[1] << 8) | mac[0];
306ec21e2ecSJeff Kirsher
307ec21e2ecSJeff Kirsher W16(ep, sen_paddrh, paddrh);
308ec21e2ecSJeff Kirsher W16(ep, sen_paddrm, paddrm);
309ec21e2ecSJeff Kirsher W16(ep, sen_paddrl, paddrl);
310ec21e2ecSJeff Kirsher
311ec21e2ecSJeff Kirsher W16(ep, sen_pper, 0);
312ec21e2ecSJeff Kirsher W16(ep, sen_taddrl, 0);
313ec21e2ecSJeff Kirsher W16(ep, sen_taddrm, 0);
314ec21e2ecSJeff Kirsher W16(ep, sen_taddrh, 0);
315ec21e2ecSJeff Kirsher
316ec21e2ecSJeff Kirsher fs_init_bds(dev);
317ec21e2ecSJeff Kirsher
318ec21e2ecSJeff Kirsher scc_cr_cmd(fep, CPM_CR_INIT_TRX);
319ec21e2ecSJeff Kirsher
320ec21e2ecSJeff Kirsher W16(sccp, scc_scce, 0xffff);
321ec21e2ecSJeff Kirsher
322ec21e2ecSJeff Kirsher /* Enable interrupts we wish to service.
323ec21e2ecSJeff Kirsher */
324ec21e2ecSJeff Kirsher W16(sccp, scc_sccm, SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);
325ec21e2ecSJeff Kirsher
326ec21e2ecSJeff Kirsher /* Set GSMR_H to enable all normal operating modes.
327ec21e2ecSJeff Kirsher * Set GSMR_L to enable Ethernet to MC68160.
328ec21e2ecSJeff Kirsher */
329ec21e2ecSJeff Kirsher W32(sccp, scc_gsmrh, 0);
330ec21e2ecSJeff Kirsher W32(sccp, scc_gsmrl,
331ec21e2ecSJeff Kirsher SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 | SCC_GSMRL_TPP_10 |
332ec21e2ecSJeff Kirsher SCC_GSMRL_MODE_ENET);
333ec21e2ecSJeff Kirsher
334ec21e2ecSJeff Kirsher /* Set sync/delimiters.
335ec21e2ecSJeff Kirsher */
336ec21e2ecSJeff Kirsher W16(sccp, scc_dsr, 0xd555);
337ec21e2ecSJeff Kirsher
338ec21e2ecSJeff Kirsher /* Set processing mode. Use Ethernet CRC, catch broadcast, and
339ec21e2ecSJeff Kirsher * start frame search 22 bit times after RENA.
340ec21e2ecSJeff Kirsher */
341ec21e2ecSJeff Kirsher W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
342ec21e2ecSJeff Kirsher
343ec21e2ecSJeff Kirsher /* Set full duplex mode if needed */
344c1c511a2SPhilippe Reynes if (dev->phydev->duplex)
345ec21e2ecSJeff Kirsher S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
346ec21e2ecSJeff Kirsher
3478751b12cSLEROY Christophe /* Restore multicast and promiscuous settings */
3488751b12cSLEROY Christophe set_multicast_list(dev);
3498751b12cSLEROY Christophe
350ec21e2ecSJeff Kirsher S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
351ec21e2ecSJeff Kirsher }
352ec21e2ecSJeff Kirsher
stop(struct net_device * dev)353ec21e2ecSJeff Kirsher static void stop(struct net_device *dev)
354ec21e2ecSJeff Kirsher {
355ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
356ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
357ec21e2ecSJeff Kirsher int i;
358ec21e2ecSJeff Kirsher
359ec21e2ecSJeff Kirsher for (i = 0; (R16(sccp, scc_sccm) == 0) && i < SCC_RESET_DELAY; i++)
360ec21e2ecSJeff Kirsher udelay(1);
361ec21e2ecSJeff Kirsher
362ec21e2ecSJeff Kirsher if (i == SCC_RESET_DELAY)
363ec21e2ecSJeff Kirsher dev_warn(fep->dev, "SCC timeout on graceful transmit stop\n");
364ec21e2ecSJeff Kirsher
365ec21e2ecSJeff Kirsher W16(sccp, scc_sccm, 0);
366ec21e2ecSJeff Kirsher C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
367ec21e2ecSJeff Kirsher
368ec21e2ecSJeff Kirsher fs_cleanup_bds(dev);
369ec21e2ecSJeff Kirsher }
370ec21e2ecSJeff Kirsher
napi_clear_event_fs(struct net_device * dev)3718572763aSChristophe Leroy static void napi_clear_event_fs(struct net_device *dev)
372ec21e2ecSJeff Kirsher {
373ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
374ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
375ec21e2ecSJeff Kirsher
3768572763aSChristophe Leroy W16(sccp, scc_scce, SCC_NAPI_EVENT_MSK);
377ec21e2ecSJeff Kirsher }
378ec21e2ecSJeff Kirsher
napi_enable_fs(struct net_device * dev)3798572763aSChristophe Leroy static void napi_enable_fs(struct net_device *dev)
380ec21e2ecSJeff Kirsher {
381ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
382ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
383ec21e2ecSJeff Kirsher
3848572763aSChristophe Leroy S16(sccp, scc_sccm, SCC_NAPI_EVENT_MSK);
385ec21e2ecSJeff Kirsher }
386ec21e2ecSJeff Kirsher
napi_disable_fs(struct net_device * dev)3878572763aSChristophe Leroy static void napi_disable_fs(struct net_device *dev)
388ec21e2ecSJeff Kirsher {
389ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
390ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
391ec21e2ecSJeff Kirsher
3928572763aSChristophe Leroy C16(sccp, scc_sccm, SCC_NAPI_EVENT_MSK);
393d43a396aSLEROY Christophe }
394d43a396aSLEROY Christophe
rx_bd_done(struct net_device * dev)395ec21e2ecSJeff Kirsher static void rx_bd_done(struct net_device *dev)
396ec21e2ecSJeff Kirsher {
397ec21e2ecSJeff Kirsher /* nothing */
398ec21e2ecSJeff Kirsher }
399ec21e2ecSJeff Kirsher
tx_kickstart(struct net_device * dev)400ec21e2ecSJeff Kirsher static void tx_kickstart(struct net_device *dev)
401ec21e2ecSJeff Kirsher {
402ec21e2ecSJeff Kirsher /* nothing */
403ec21e2ecSJeff Kirsher }
404ec21e2ecSJeff Kirsher
get_int_events(struct net_device * dev)405ec21e2ecSJeff Kirsher static u32 get_int_events(struct net_device *dev)
406ec21e2ecSJeff Kirsher {
407ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
408ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
409ec21e2ecSJeff Kirsher
410ec21e2ecSJeff Kirsher return (u32) R16(sccp, scc_scce);
411ec21e2ecSJeff Kirsher }
412ec21e2ecSJeff Kirsher
clear_int_events(struct net_device * dev,u32 int_events)413ec21e2ecSJeff Kirsher static void clear_int_events(struct net_device *dev, u32 int_events)
414ec21e2ecSJeff Kirsher {
415ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
416ec21e2ecSJeff Kirsher scc_t __iomem *sccp = fep->scc.sccp;
417ec21e2ecSJeff Kirsher
418ec21e2ecSJeff Kirsher W16(sccp, scc_scce, int_events & 0xffff);
419ec21e2ecSJeff Kirsher }
420ec21e2ecSJeff Kirsher
ev_error(struct net_device * dev,u32 int_events)421ec21e2ecSJeff Kirsher static void ev_error(struct net_device *dev, u32 int_events)
422ec21e2ecSJeff Kirsher {
423ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
424ec21e2ecSJeff Kirsher
425ec21e2ecSJeff Kirsher dev_warn(fep->dev, "SCC ERROR(s) 0x%x\n", int_events);
426ec21e2ecSJeff Kirsher }
427ec21e2ecSJeff Kirsher
get_regs(struct net_device * dev,void * p,int * sizep)428ec21e2ecSJeff Kirsher static int get_regs(struct net_device *dev, void *p, int *sizep)
429ec21e2ecSJeff Kirsher {
430ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
431ec21e2ecSJeff Kirsher
432ec21e2ecSJeff Kirsher if (*sizep < sizeof(scc_t) + sizeof(scc_enet_t __iomem *))
433ec21e2ecSJeff Kirsher return -EINVAL;
434ec21e2ecSJeff Kirsher
435ec21e2ecSJeff Kirsher memcpy_fromio(p, fep->scc.sccp, sizeof(scc_t));
436ec21e2ecSJeff Kirsher p = (char *)p + sizeof(scc_t);
437ec21e2ecSJeff Kirsher
438ec21e2ecSJeff Kirsher memcpy_fromio(p, fep->scc.ep, sizeof(scc_enet_t __iomem *));
439ec21e2ecSJeff Kirsher
440ec21e2ecSJeff Kirsher return 0;
441ec21e2ecSJeff Kirsher }
442ec21e2ecSJeff Kirsher
get_regs_len(struct net_device * dev)443ec21e2ecSJeff Kirsher static int get_regs_len(struct net_device *dev)
444ec21e2ecSJeff Kirsher {
445ec21e2ecSJeff Kirsher return sizeof(scc_t) + sizeof(scc_enet_t __iomem *);
446ec21e2ecSJeff Kirsher }
447ec21e2ecSJeff Kirsher
tx_restart(struct net_device * dev)448ec21e2ecSJeff Kirsher static void tx_restart(struct net_device *dev)
449ec21e2ecSJeff Kirsher {
450ec21e2ecSJeff Kirsher struct fs_enet_private *fep = netdev_priv(dev);
451ec21e2ecSJeff Kirsher
452ec21e2ecSJeff Kirsher scc_cr_cmd(fep, CPM_CR_RESTART_TX);
453ec21e2ecSJeff Kirsher }
454ec21e2ecSJeff Kirsher
455ec21e2ecSJeff Kirsher
456ec21e2ecSJeff Kirsher
457ec21e2ecSJeff Kirsher /*************************************************************************/
458ec21e2ecSJeff Kirsher
459ec21e2ecSJeff Kirsher const struct fs_ops fs_scc_ops = {
460ec21e2ecSJeff Kirsher .setup_data = setup_data,
461ec21e2ecSJeff Kirsher .cleanup_data = cleanup_data,
462ec21e2ecSJeff Kirsher .set_multicast_list = set_multicast_list,
463ec21e2ecSJeff Kirsher .restart = restart,
464ec21e2ecSJeff Kirsher .stop = stop,
4658572763aSChristophe Leroy .napi_clear_event = napi_clear_event_fs,
4668572763aSChristophe Leroy .napi_enable = napi_enable_fs,
4678572763aSChristophe Leroy .napi_disable = napi_disable_fs,
468ec21e2ecSJeff Kirsher .rx_bd_done = rx_bd_done,
469ec21e2ecSJeff Kirsher .tx_kickstart = tx_kickstart,
470ec21e2ecSJeff Kirsher .get_int_events = get_int_events,
471ec21e2ecSJeff Kirsher .clear_int_events = clear_int_events,
472ec21e2ecSJeff Kirsher .ev_error = ev_error,
473ec21e2ecSJeff Kirsher .get_regs = get_regs,
474ec21e2ecSJeff Kirsher .get_regs_len = get_regs_len,
475ec21e2ecSJeff Kirsher .tx_restart = tx_restart,
476ec21e2ecSJeff Kirsher .allocate_bd = allocate_bd,
477ec21e2ecSJeff Kirsher .free_bd = free_bd,
478ec21e2ecSJeff Kirsher };
479