blob: 6094cbf542a2c9e325c2a7869ff03634bfda7c45 [file] [log] [blame]
Pantelis Antoniou48257c42005-10-28 16:25:58 -04001/*
2 * FCC driver for Motorola MPC82xx (PQ2).
3 *
Vitaly Bordug9b8ee8e2007-09-18 20:05:35 +04004 * Copyright (c) 2003 Intracom S.A.
Pantelis Antoniou48257c42005-10-28 16:25:58 -04005 * by Pantelis Antoniou <panto@intracom.gr>
6 *
Vitaly Bordug9b8ee8e2007-09-18 20:05:35 +04007 * 2005 (c) MontaVista Software, Inc.
Pantelis Antoniou48257c42005-10-28 16:25:58 -04008 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
Vitaly Bordug9b8ee8e2007-09-18 20:05:35 +040010 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
Pantelis Antoniou48257c42005-10-28 16:25:58 -040012 * kind, whether express or implied.
13 */
14
Pantelis Antoniou48257c42005-10-28 16:25:58 -040015#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/types.h>
Pantelis Antoniou48257c42005-10-28 16:25:58 -040018#include <linux/string.h>
19#include <linux/ptrace.h>
20#include <linux/errno.h>
21#include <linux/ioport.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
Pantelis Antoniou48257c42005-10-28 16:25:58 -040024#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <linux/skbuff.h>
29#include <linux/spinlock.h>
30#include <linux/mii.h>
31#include <linux/ethtool.h>
32#include <linux/bitops.h>
33#include <linux/fs.h>
Marcelo Tosattif7b99962005-11-09 11:00:16 -020034#include <linux/platform_device.h>
Vitaly Bordug5b4b8452006-08-14 23:00:30 -070035#include <linux/phy.h>
Pantelis Antoniou48257c42005-10-28 16:25:58 -040036
37#include <asm/immap_cpm2.h>
38#include <asm/mpc8260.h>
39#include <asm/cpm2.h>
40
41#include <asm/pgtable.h>
42#include <asm/irq.h>
43#include <asm/uaccess.h>
44
Scott Wood976de6a2007-10-02 10:55:58 -050045#ifdef CONFIG_PPC_CPM_NEW_BINDING
46#include <asm/of_device.h>
47#endif
48
Pantelis Antoniou48257c42005-10-28 16:25:58 -040049#include "fs_enet.h"
50
51/*************************************************/
52
53/* FCC access macros */
54
Pantelis Antoniou48257c42005-10-28 16:25:58 -040055/* write, read, set bits, clear bits */
Scott Woodc6565332007-10-01 14:20:50 -050056#define W32(_p, _m, _v) out_be32(&(_p)->_m, (_v))
57#define R32(_p, _m) in_be32(&(_p)->_m)
Pantelis Antoniou48257c42005-10-28 16:25:58 -040058#define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
59#define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
60
Scott Woodc6565332007-10-01 14:20:50 -050061#define W16(_p, _m, _v) out_be16(&(_p)->_m, (_v))
62#define R16(_p, _m) in_be16(&(_p)->_m)
Pantelis Antoniou48257c42005-10-28 16:25:58 -040063#define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
64#define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
65
Scott Woodc6565332007-10-01 14:20:50 -050066#define W8(_p, _m, _v) out_8(&(_p)->_m, (_v))
67#define R8(_p, _m) in_8(&(_p)->_m)
Pantelis Antoniou48257c42005-10-28 16:25:58 -040068#define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
69#define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
70
71/*************************************************/
72
73#define FCC_MAX_MULTICAST_ADDRS 64
74
75#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
76#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
77#define mk_mii_end 0
78
79#define MAX_CR_CMD_LOOPS 10000
80
Scott Wood976de6a2007-10-02 10:55:58 -050081static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
Pantelis Antoniou48257c42005-10-28 16:25:58 -040082{
83 const struct fs_platform_info *fpi = fep->fpi;
Pantelis Antoniou48257c42005-10-28 16:25:58 -040084 cpm2_map_t *immap = fs_enet_immap;
85 cpm_cpm2_t *cpmp = &immap->im_cpm;
Pantelis Antoniou48257c42005-10-28 16:25:58 -040086 int i;
87
Scott Wood976de6a2007-10-02 10:55:58 -050088 W32(cpmp, cp_cpcr, fpi->cp_command | op | CPM_CR_FLG);
Pantelis Antoniou48257c42005-10-28 16:25:58 -040089 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
90 if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
Scott Wood976de6a2007-10-02 10:55:58 -050091 return 0;
Pantelis Antoniou48257c42005-10-28 16:25:58 -040092
Scott Wood976de6a2007-10-02 10:55:58 -050093 printk(KERN_ERR "%s(): Not able to issue CPM command\n",
94 __FUNCTION__);
95 return 1;
Pantelis Antoniou48257c42005-10-28 16:25:58 -040096}
97
98static int do_pd_setup(struct fs_enet_private *fep)
99{
Scott Wood976de6a2007-10-02 10:55:58 -0500100#ifdef CONFIG_PPC_CPM_NEW_BINDING
101 struct of_device *ofdev = to_of_device(fep->dev);
102 struct fs_platform_info *fpi = fep->fpi;
103 int ret = -EINVAL;
104
105 fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL);
106 if (fep->interrupt == NO_IRQ)
107 goto out;
108
109 fep->fcc.fccp = of_iomap(ofdev->node, 0);
110 if (!fep->fcc.fccp)
111 goto out;
112
113 fep->fcc.ep = of_iomap(ofdev->node, 1);
114 if (!fep->fcc.ep)
115 goto out_fccp;
116
117 fep->fcc.fcccp = of_iomap(ofdev->node, 2);
118 if (!fep->fcc.fcccp)
119 goto out_ep;
120
121 fep->fcc.mem = (void *)cpm_dpalloc(128, 8);
122 fpi->dpram_offset = (u32)cpm2_immr;
123 if (IS_ERR_VALUE(fpi->dpram_offset)) {
124 ret = fpi->dpram_offset;
125 goto out_fcccp;
126 }
127
128 return 0;
129
130out_fcccp:
131 iounmap(fep->fcc.fcccp);
132out_ep:
133 iounmap(fep->fcc.ep);
134out_fccp:
135 iounmap(fep->fcc.fccp);
136out:
137 return ret;
138#else
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400139 struct platform_device *pdev = to_platform_device(fep->dev);
140 struct resource *r;
141
142 /* Fill out IRQ field */
143 fep->interrupt = platform_get_irq(pdev, 0);
David Vrabel48944732006-01-19 17:56:29 +0000144 if (fep->interrupt < 0)
145 return -EINVAL;
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400146
147 /* Attach the memory for the FCC Parameter RAM */
148 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700149 fep->fcc.ep = (void *)ioremap(r->start, r->end - r->start + 1);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400150 if (fep->fcc.ep == NULL)
151 return -EINVAL;
152
153 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700154 fep->fcc.fccp = (void *)ioremap(r->start, r->end - r->start + 1);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400155 if (fep->fcc.fccp == NULL)
156 return -EINVAL;
157
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700158 if (fep->fpi->fcc_regs_c) {
159
160 fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
161 } else {
162 r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
163 "fcc_regs_c");
164 fep->fcc.fcccp = (void *)ioremap(r->start,
165 r->end - r->start + 1);
166 }
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400167
168 if (fep->fcc.fcccp == NULL)
169 return -EINVAL;
170
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700171 fep->fcc.mem = (void *)fep->fpi->mem_offset;
172 if (fep->fcc.mem == NULL)
173 return -EINVAL;
174
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400175 return 0;
Scott Wood976de6a2007-10-02 10:55:58 -0500176#endif
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400177}
178
179#define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
180#define FCC_RX_EVENT (FCC_ENET_RXF)
181#define FCC_TX_EVENT (FCC_ENET_TXB)
182#define FCC_ERR_EVENT_MSK (FCC_ENET_TXE | FCC_ENET_BSY)
183
184static int setup_data(struct net_device *dev)
185{
186 struct fs_enet_private *fep = netdev_priv(dev);
Scott Wood976de6a2007-10-02 10:55:58 -0500187#ifndef CONFIG_PPC_CPM_NEW_BINDING
188 struct fs_platform_info *fpi = fep->fpi;
189
190 fpi->cp_command = (fpi->cp_page << 26) |
191 (fpi->cp_block << 21) |
192 (12 << 6);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400193
194 fep->fcc.idx = fs_get_fcc_index(fpi->fs_no);
195 if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */
196 return -EINVAL;
Scott Wood976de6a2007-10-02 10:55:58 -0500197#endif
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400198
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400199 if (do_pd_setup(fep) != 0)
200 return -EINVAL;
201
202 fep->ev_napi_rx = FCC_NAPI_RX_EVENT_MSK;
203 fep->ev_rx = FCC_RX_EVENT;
204 fep->ev_tx = FCC_TX_EVENT;
205 fep->ev_err = FCC_ERR_EVENT_MSK;
206
207 return 0;
208}
209
210static int allocate_bd(struct net_device *dev)
211{
212 struct fs_enet_private *fep = netdev_priv(dev);
213 const struct fs_platform_info *fpi = fep->fpi;
214
215 fep->ring_base = dma_alloc_coherent(fep->dev,
216 (fpi->tx_ring + fpi->rx_ring) *
217 sizeof(cbd_t), &fep->ring_mem_addr,
218 GFP_KERNEL);
219 if (fep->ring_base == NULL)
220 return -ENOMEM;
221
222 return 0;
223}
224
225static void free_bd(struct net_device *dev)
226{
227 struct fs_enet_private *fep = netdev_priv(dev);
228 const struct fs_platform_info *fpi = fep->fpi;
229
230 if (fep->ring_base)
231 dma_free_coherent(fep->dev,
232 (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
233 fep->ring_base, fep->ring_mem_addr);
234}
235
236static void cleanup_data(struct net_device *dev)
237{
238 /* nothing */
239}
240
241static void set_promiscuous_mode(struct net_device *dev)
242{
243 struct fs_enet_private *fep = netdev_priv(dev);
244 fcc_t *fccp = fep->fcc.fccp;
245
246 S32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
247}
248
249static void set_multicast_start(struct net_device *dev)
250{
251 struct fs_enet_private *fep = netdev_priv(dev);
252 fcc_enet_t *ep = fep->fcc.ep;
253
254 W32(ep, fen_gaddrh, 0);
255 W32(ep, fen_gaddrl, 0);
256}
257
258static void set_multicast_one(struct net_device *dev, const u8 *mac)
259{
260 struct fs_enet_private *fep = netdev_priv(dev);
261 fcc_enet_t *ep = fep->fcc.ep;
262 u16 taddrh, taddrm, taddrl;
263
264 taddrh = ((u16)mac[5] << 8) | mac[4];
265 taddrm = ((u16)mac[3] << 8) | mac[2];
266 taddrl = ((u16)mac[1] << 8) | mac[0];
267
268 W16(ep, fen_taddrh, taddrh);
269 W16(ep, fen_taddrm, taddrm);
270 W16(ep, fen_taddrl, taddrl);
Scott Wood976de6a2007-10-02 10:55:58 -0500271 fcc_cr_cmd(fep, CPM_CR_SET_GADDR);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400272}
273
274static void set_multicast_finish(struct net_device *dev)
275{
276 struct fs_enet_private *fep = netdev_priv(dev);
277 fcc_t *fccp = fep->fcc.fccp;
278 fcc_enet_t *ep = fep->fcc.ep;
279
280 /* clear promiscuous always */
281 C32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
282
283 /* if all multi or too many multicasts; just enable all */
284 if ((dev->flags & IFF_ALLMULTI) != 0 ||
285 dev->mc_count > FCC_MAX_MULTICAST_ADDRS) {
286
287 W32(ep, fen_gaddrh, 0xffffffff);
288 W32(ep, fen_gaddrl, 0xffffffff);
289 }
290
291 /* read back */
292 fep->fcc.gaddrh = R32(ep, fen_gaddrh);
293 fep->fcc.gaddrl = R32(ep, fen_gaddrl);
294}
295
296static void set_multicast_list(struct net_device *dev)
297{
298 struct dev_mc_list *pmc;
299
300 if ((dev->flags & IFF_PROMISC) == 0) {
301 set_multicast_start(dev);
302 for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
303 set_multicast_one(dev, pmc->dmi_addr);
304 set_multicast_finish(dev);
305 } else
306 set_promiscuous_mode(dev);
307}
308
309static void restart(struct net_device *dev)
310{
311 struct fs_enet_private *fep = netdev_priv(dev);
312 const struct fs_platform_info *fpi = fep->fpi;
313 fcc_t *fccp = fep->fcc.fccp;
314 fcc_c_t *fcccp = fep->fcc.fcccp;
315 fcc_enet_t *ep = fep->fcc.ep;
316 dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
317 u16 paddrh, paddrm, paddrl;
318 u16 mem_addr;
319 const unsigned char *mac;
320 int i;
321
322 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
323
324 /* clear everything (slow & steady does it) */
325 for (i = 0; i < sizeof(*ep); i++)
Scott Wood976de6a2007-10-02 10:55:58 -0500326 out_8((u8 __iomem *)ep + i, 0);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400327
328 /* get physical address */
329 rx_bd_base_phys = fep->ring_mem_addr;
330 tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
331
332 /* point to bds */
333 W32(ep, fen_genfcc.fcc_rbase, rx_bd_base_phys);
334 W32(ep, fen_genfcc.fcc_tbase, tx_bd_base_phys);
335
336 /* Set maximum bytes per receive buffer.
337 * It must be a multiple of 32.
338 */
339 W16(ep, fen_genfcc.fcc_mrblr, PKT_MAXBLR_SIZE);
340
341 W32(ep, fen_genfcc.fcc_rstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
342 W32(ep, fen_genfcc.fcc_tstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
343
344 /* Allocate space in the reserved FCC area of DPRAM for the
345 * internal buffers. No one uses this space (yet), so we
346 * can do this. Later, we will add resource management for
347 * this area.
348 */
349
350 mem_addr = (u32) fep->fcc.mem; /* de-fixup dpram offset */
351
352 W16(ep, fen_genfcc.fcc_riptr, (mem_addr & 0xffff));
353 W16(ep, fen_genfcc.fcc_tiptr, ((mem_addr + 32) & 0xffff));
354 W16(ep, fen_padptr, mem_addr + 64);
355
356 /* fill with special symbol... */
357 memset(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32);
358
359 W32(ep, fen_genfcc.fcc_rbptr, 0);
360 W32(ep, fen_genfcc.fcc_tbptr, 0);
361 W32(ep, fen_genfcc.fcc_rcrc, 0);
362 W32(ep, fen_genfcc.fcc_tcrc, 0);
363 W16(ep, fen_genfcc.fcc_res1, 0);
364 W32(ep, fen_genfcc.fcc_res2, 0);
365
366 /* no CAM */
367 W32(ep, fen_camptr, 0);
368
369 /* Set CRC preset and mask */
370 W32(ep, fen_cmask, 0xdebb20e3);
371 W32(ep, fen_cpres, 0xffffffff);
372
373 W32(ep, fen_crcec, 0); /* CRC Error counter */
374 W32(ep, fen_alec, 0); /* alignment error counter */
375 W32(ep, fen_disfc, 0); /* discard frame counter */
376 W16(ep, fen_retlim, 15); /* Retry limit threshold */
377 W16(ep, fen_pper, 0); /* Normal persistence */
378
379 /* set group address */
380 W32(ep, fen_gaddrh, fep->fcc.gaddrh);
381 W32(ep, fen_gaddrl, fep->fcc.gaddrh);
382
383 /* Clear hash filter tables */
384 W32(ep, fen_iaddrh, 0);
385 W32(ep, fen_iaddrl, 0);
386
387 /* Clear the Out-of-sequence TxBD */
388 W16(ep, fen_tfcstat, 0);
389 W16(ep, fen_tfclen, 0);
390 W32(ep, fen_tfcptr, 0);
391
392 W16(ep, fen_mflr, PKT_MAXBUF_SIZE); /* maximum frame length register */
393 W16(ep, fen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
394
395 /* set address */
396 mac = dev->dev_addr;
397 paddrh = ((u16)mac[5] << 8) | mac[4];
398 paddrm = ((u16)mac[3] << 8) | mac[2];
399 paddrl = ((u16)mac[1] << 8) | mac[0];
400
401 W16(ep, fen_paddrh, paddrh);
402 W16(ep, fen_paddrm, paddrm);
403 W16(ep, fen_paddrl, paddrl);
404
405 W16(ep, fen_taddrh, 0);
406 W16(ep, fen_taddrm, 0);
407 W16(ep, fen_taddrl, 0);
408
409 W16(ep, fen_maxd1, 1520); /* maximum DMA1 length */
410 W16(ep, fen_maxd2, 1520); /* maximum DMA2 length */
411
412 /* Clear stat counters, in case we ever enable RMON */
413 W32(ep, fen_octc, 0);
414 W32(ep, fen_colc, 0);
415 W32(ep, fen_broc, 0);
416 W32(ep, fen_mulc, 0);
417 W32(ep, fen_uspc, 0);
418 W32(ep, fen_frgc, 0);
419 W32(ep, fen_ospc, 0);
420 W32(ep, fen_jbrc, 0);
421 W32(ep, fen_p64c, 0);
422 W32(ep, fen_p65c, 0);
423 W32(ep, fen_p128c, 0);
424 W32(ep, fen_p256c, 0);
425 W32(ep, fen_p512c, 0);
426 W32(ep, fen_p1024c, 0);
427
428 W16(ep, fen_rfthr, 0); /* Suggested by manual */
429 W16(ep, fen_rfcnt, 0);
430 W16(ep, fen_cftype, 0);
431
432 fs_init_bds(dev);
433
434 /* adjust to speed (for RMII mode) */
435 if (fpi->use_rmii) {
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700436 if (fep->phydev->speed == 100)
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400437 C8(fcccp, fcc_gfemr, 0x20);
438 else
439 S8(fcccp, fcc_gfemr, 0x20);
440 }
441
Scott Wood976de6a2007-10-02 10:55:58 -0500442 fcc_cr_cmd(fep, CPM_CR_INIT_TRX);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400443
444 /* clear events */
445 W16(fccp, fcc_fcce, 0xffff);
446
447 /* Enable interrupts we wish to service */
448 W16(fccp, fcc_fccm, FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
449
450 /* Set GFMR to enable Ethernet operating mode */
451 W32(fccp, fcc_gfmr, FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
452
453 /* set sync/delimiters */
454 W16(fccp, fcc_fdsr, 0xd555);
455
456 W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
457
458 if (fpi->use_rmii)
459 S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
460
461 /* adjust to duplex mode */
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700462 if (fep->phydev->duplex)
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400463 S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
464 else
465 C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
466
467 S32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
468}
469
470static void stop(struct net_device *dev)
471{
472 struct fs_enet_private *fep = netdev_priv(dev);
473 fcc_t *fccp = fep->fcc.fccp;
474
475 /* stop ethernet */
476 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
477
478 /* clear events */
479 W16(fccp, fcc_fcce, 0xffff);
480
481 /* clear interrupt mask */
482 W16(fccp, fcc_fccm, 0);
483
484 fs_cleanup_bds(dev);
485}
486
487static void pre_request_irq(struct net_device *dev, int irq)
488{
489 /* nothing */
490}
491
492static void post_free_irq(struct net_device *dev, int irq)
493{
494 /* nothing */
495}
496
497static void napi_clear_rx_event(struct net_device *dev)
498{
499 struct fs_enet_private *fep = netdev_priv(dev);
500 fcc_t *fccp = fep->fcc.fccp;
501
502 W16(fccp, fcc_fcce, FCC_NAPI_RX_EVENT_MSK);
503}
504
505static void napi_enable_rx(struct net_device *dev)
506{
507 struct fs_enet_private *fep = netdev_priv(dev);
508 fcc_t *fccp = fep->fcc.fccp;
509
510 S16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
511}
512
513static void napi_disable_rx(struct net_device *dev)
514{
515 struct fs_enet_private *fep = netdev_priv(dev);
516 fcc_t *fccp = fep->fcc.fccp;
517
518 C16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
519}
520
521static void rx_bd_done(struct net_device *dev)
522{
523 /* nothing */
524}
525
526static void tx_kickstart(struct net_device *dev)
527{
Vitaly Bordug5b4b8452006-08-14 23:00:30 -0700528 struct fs_enet_private *fep = netdev_priv(dev);
529 fcc_t *fccp = fep->fcc.fccp;
530
Scott Woodc6565332007-10-01 14:20:50 -0500531 S16(fccp, fcc_ftodr, 0x8000);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400532}
533
534static u32 get_int_events(struct net_device *dev)
535{
536 struct fs_enet_private *fep = netdev_priv(dev);
537 fcc_t *fccp = fep->fcc.fccp;
538
539 return (u32)R16(fccp, fcc_fcce);
540}
541
542static void clear_int_events(struct net_device *dev, u32 int_events)
543{
544 struct fs_enet_private *fep = netdev_priv(dev);
545 fcc_t *fccp = fep->fcc.fccp;
546
547 W16(fccp, fcc_fcce, int_events & 0xffff);
548}
549
550static void ev_error(struct net_device *dev, u32 int_events)
551{
552 printk(KERN_WARNING DRV_MODULE_NAME
553 ": %s FS_ENET ERROR(s) 0x%x\n", dev->name, int_events);
554}
555
556int get_regs(struct net_device *dev, void *p, int *sizep)
557{
558 struct fs_enet_private *fep = netdev_priv(dev);
559
Scott Wood976de6a2007-10-02 10:55:58 -0500560 if (*sizep < sizeof(fcc_t) + sizeof(fcc_enet_t) + 1)
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400561 return -EINVAL;
562
563 memcpy_fromio(p, fep->fcc.fccp, sizeof(fcc_t));
564 p = (char *)p + sizeof(fcc_t);
565
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400566 memcpy_fromio(p, fep->fcc.ep, sizeof(fcc_enet_t));
Scott Wood976de6a2007-10-02 10:55:58 -0500567 p = (char *)p + sizeof(fcc_enet_t);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400568
Scott Wood976de6a2007-10-02 10:55:58 -0500569 memcpy_fromio(p, fep->fcc.fcccp, 1);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400570 return 0;
571}
572
573int get_regs_len(struct net_device *dev)
574{
Scott Wood976de6a2007-10-02 10:55:58 -0500575 return sizeof(fcc_t) + sizeof(fcc_enet_t) + 1;
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400576}
577
578/* Some transmit errors cause the transmitter to shut
579 * down. We now issue a restart transmit. Since the
580 * errors close the BD and update the pointers, the restart
581 * _should_ pick up without having to reset any of our
Vitaly Bordug9b8ee8e2007-09-18 20:05:35 +0400582 * pointers either. Also, To workaround 8260 device erratum
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400583 * CPM37, we must disable and then re-enable the transmitter
584 * following a Late Collision, Underrun, or Retry Limit error.
585 */
586void tx_restart(struct net_device *dev)
587{
588 struct fs_enet_private *fep = netdev_priv(dev);
589 fcc_t *fccp = fep->fcc.fccp;
590
591 C32(fccp, fcc_gfmr, FCC_GFMR_ENT);
592 udelay(10);
593 S32(fccp, fcc_gfmr, FCC_GFMR_ENT);
594
Scott Wood976de6a2007-10-02 10:55:58 -0500595 fcc_cr_cmd(fep, CPM_CR_RESTART_TX);
Pantelis Antoniou48257c42005-10-28 16:25:58 -0400596}
597
598/*************************************************************************/
599
600const struct fs_ops fs_fcc_ops = {
601 .setup_data = setup_data,
602 .cleanup_data = cleanup_data,
603 .set_multicast_list = set_multicast_list,
604 .restart = restart,
605 .stop = stop,
606 .pre_request_irq = pre_request_irq,
607 .post_free_irq = post_free_irq,
608 .napi_clear_rx_event = napi_clear_rx_event,
609 .napi_enable_rx = napi_enable_rx,
610 .napi_disable_rx = napi_disable_rx,
611 .rx_bd_done = rx_bd_done,
612 .tx_kickstart = tx_kickstart,
613 .get_int_events = get_int_events,
614 .clear_int_events = clear_int_events,
615 .ev_error = ev_error,
616 .get_regs = get_regs,
617 .get_regs_len = get_regs_len,
618 .tx_restart = tx_restart,
619 .allocate_bd = allocate_bd,
620 .free_bd = free_bd,
621};