Merge git://git.infradead.org/mtd-2.6
[linux-2.6/zen-sources.git] / drivers / net / sh_eth.c
blob59f242a6771497619e36f51cc424ef9a61e2036d
1 /*
2 * SuperH Ethernet device driver
4 * Copyright (C) 2006-2008 Nobuhiro Iwamatsu
5 * Copyright (C) 2008 Renesas Solutions Corp.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
23 #include <linux/init.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/etherdevice.h>
26 #include <linux/delay.h>
27 #include <linux/platform_device.h>
28 #include <linux/mdio-bitbang.h>
29 #include <linux/netdevice.h>
30 #include <linux/phy.h>
31 #include <linux/cache.h>
32 #include <linux/io.h>
34 #include "sh_eth.h"
36 /* CPU <-> EDMAC endian convert */
37 static inline __u32 cpu_to_edmac(struct sh_eth_private *mdp, u32 x)
39 switch (mdp->edmac_endian) {
40 case EDMAC_LITTLE_ENDIAN:
41 return cpu_to_le32(x);
42 case EDMAC_BIG_ENDIAN:
43 return cpu_to_be32(x);
45 return x;
48 static inline __u32 edmac_to_cpu(struct sh_eth_private *mdp, u32 x)
50 switch (mdp->edmac_endian) {
51 case EDMAC_LITTLE_ENDIAN:
52 return le32_to_cpu(x);
53 case EDMAC_BIG_ENDIAN:
54 return be32_to_cpu(x);
56 return x;
60 * Program the hardware MAC address from dev->dev_addr.
62 static void update_mac_address(struct net_device *ndev)
64 u32 ioaddr = ndev->base_addr;
66 ctrl_outl((ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
67 (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]),
68 ioaddr + MAHR);
69 ctrl_outl((ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]),
70 ioaddr + MALR);
74 * Get MAC address from SuperH MAC address register
76 * SuperH's Ethernet device doesn't have 'ROM' to MAC address.
77 * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g).
78 * When you want use this device, you must set MAC address in bootloader.
81 static void read_mac_address(struct net_device *ndev)
83 u32 ioaddr = ndev->base_addr;
85 ndev->dev_addr[0] = (ctrl_inl(ioaddr + MAHR) >> 24);
86 ndev->dev_addr[1] = (ctrl_inl(ioaddr + MAHR) >> 16) & 0xFF;
87 ndev->dev_addr[2] = (ctrl_inl(ioaddr + MAHR) >> 8) & 0xFF;
88 ndev->dev_addr[3] = (ctrl_inl(ioaddr + MAHR) & 0xFF);
89 ndev->dev_addr[4] = (ctrl_inl(ioaddr + MALR) >> 8) & 0xFF;
90 ndev->dev_addr[5] = (ctrl_inl(ioaddr + MALR) & 0xFF);
93 struct bb_info {
94 struct mdiobb_ctrl ctrl;
95 u32 addr;
96 u32 mmd_msk;/* MMD */
97 u32 mdo_msk;
98 u32 mdi_msk;
99 u32 mdc_msk;
102 /* PHY bit set */
103 static void bb_set(u32 addr, u32 msk)
105 ctrl_outl(ctrl_inl(addr) | msk, addr);
108 /* PHY bit clear */
109 static void bb_clr(u32 addr, u32 msk)
111 ctrl_outl((ctrl_inl(addr) & ~msk), addr);
114 /* PHY bit read */
115 static int bb_read(u32 addr, u32 msk)
117 return (ctrl_inl(addr) & msk) != 0;
120 /* Data I/O pin control */
121 static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit)
123 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
124 if (bit)
125 bb_set(bitbang->addr, bitbang->mmd_msk);
126 else
127 bb_clr(bitbang->addr, bitbang->mmd_msk);
130 /* Set bit data*/
131 static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit)
133 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
135 if (bit)
136 bb_set(bitbang->addr, bitbang->mdo_msk);
137 else
138 bb_clr(bitbang->addr, bitbang->mdo_msk);
141 /* Get bit data*/
142 static int sh_get_mdio(struct mdiobb_ctrl *ctrl)
144 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
145 return bb_read(bitbang->addr, bitbang->mdi_msk);
148 /* MDC pin control */
149 static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
151 struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
153 if (bit)
154 bb_set(bitbang->addr, bitbang->mdc_msk);
155 else
156 bb_clr(bitbang->addr, bitbang->mdc_msk);
159 /* mdio bus control struct */
160 static struct mdiobb_ops bb_ops = {
161 .owner = THIS_MODULE,
162 .set_mdc = sh_mdc_ctrl,
163 .set_mdio_dir = sh_mmd_ctrl,
164 .set_mdio_data = sh_set_mdio,
165 .get_mdio_data = sh_get_mdio,
168 /* Chip Reset */
169 static void sh_eth_reset(struct net_device *ndev)
171 u32 ioaddr = ndev->base_addr;
173 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
174 int cnt = 100;
176 ctrl_outl(EDSR_ENALL, ioaddr + EDSR);
177 ctrl_outl(ctrl_inl(ioaddr + EDMR) | EDMR_SRST, ioaddr + EDMR);
178 while (cnt > 0) {
179 if (!(ctrl_inl(ioaddr + EDMR) & 0x3))
180 break;
181 mdelay(1);
182 cnt--;
184 if (cnt < 0)
185 printk(KERN_ERR "Device reset fail\n");
187 /* Table Init */
188 ctrl_outl(0x0, ioaddr + TDLAR);
189 ctrl_outl(0x0, ioaddr + TDFAR);
190 ctrl_outl(0x0, ioaddr + TDFXR);
191 ctrl_outl(0x0, ioaddr + TDFFR);
192 ctrl_outl(0x0, ioaddr + RDLAR);
193 ctrl_outl(0x0, ioaddr + RDFAR);
194 ctrl_outl(0x0, ioaddr + RDFXR);
195 ctrl_outl(0x0, ioaddr + RDFFR);
196 #else
197 ctrl_outl(ctrl_inl(ioaddr + EDMR) | EDMR_SRST, ioaddr + EDMR);
198 mdelay(3);
199 ctrl_outl(ctrl_inl(ioaddr + EDMR) & ~EDMR_SRST, ioaddr + EDMR);
200 #endif
203 /* free skb and descriptor buffer */
204 static void sh_eth_ring_free(struct net_device *ndev)
206 struct sh_eth_private *mdp = netdev_priv(ndev);
207 int i;
209 /* Free Rx skb ringbuffer */
210 if (mdp->rx_skbuff) {
211 for (i = 0; i < RX_RING_SIZE; i++) {
212 if (mdp->rx_skbuff[i])
213 dev_kfree_skb(mdp->rx_skbuff[i]);
216 kfree(mdp->rx_skbuff);
218 /* Free Tx skb ringbuffer */
219 if (mdp->tx_skbuff) {
220 for (i = 0; i < TX_RING_SIZE; i++) {
221 if (mdp->tx_skbuff[i])
222 dev_kfree_skb(mdp->tx_skbuff[i]);
225 kfree(mdp->tx_skbuff);
228 /* format skb and descriptor buffer */
229 static void sh_eth_ring_format(struct net_device *ndev)
231 u32 ioaddr = ndev->base_addr, reserve = 0;
232 struct sh_eth_private *mdp = netdev_priv(ndev);
233 int i;
234 struct sk_buff *skb;
235 struct sh_eth_rxdesc *rxdesc = NULL;
236 struct sh_eth_txdesc *txdesc = NULL;
237 int rx_ringsize = sizeof(*rxdesc) * RX_RING_SIZE;
238 int tx_ringsize = sizeof(*txdesc) * TX_RING_SIZE;
240 mdp->cur_rx = mdp->cur_tx = 0;
241 mdp->dirty_rx = mdp->dirty_tx = 0;
243 memset(mdp->rx_ring, 0, rx_ringsize);
245 /* build Rx ring buffer */
246 for (i = 0; i < RX_RING_SIZE; i++) {
247 /* skb */
248 mdp->rx_skbuff[i] = NULL;
249 skb = dev_alloc_skb(mdp->rx_buf_sz);
250 mdp->rx_skbuff[i] = skb;
251 if (skb == NULL)
252 break;
253 skb->dev = ndev; /* Mark as being used by this device. */
254 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
255 reserve = SH7763_SKB_ALIGN
256 - ((uint32_t)skb->data & (SH7763_SKB_ALIGN-1));
257 if (reserve)
258 skb_reserve(skb, reserve);
259 #else
260 skb_reserve(skb, RX_OFFSET);
261 #endif
262 /* RX descriptor */
263 rxdesc = &mdp->rx_ring[i];
264 rxdesc->addr = (u32)skb->data & ~0x3UL;
265 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP);
267 /* The size of the buffer is 16 byte boundary. */
268 rxdesc->buffer_length = (mdp->rx_buf_sz + 16) & ~0x0F;
269 /* Rx descriptor address set */
270 if (i == 0) {
271 ctrl_outl((u32)rxdesc, ioaddr + RDLAR);
272 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
273 ctrl_outl((u32)rxdesc, ioaddr + RDFAR);
274 #endif
278 /* Rx descriptor address set */
279 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
280 ctrl_outl((u32)rxdesc, ioaddr + RDFXR);
281 ctrl_outl(0x1, ioaddr + RDFFR);
282 #endif
284 mdp->dirty_rx = (u32) (i - RX_RING_SIZE);
286 /* Mark the last entry as wrapping the ring. */
287 rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL);
289 memset(mdp->tx_ring, 0, tx_ringsize);
291 /* build Tx ring buffer */
292 for (i = 0; i < TX_RING_SIZE; i++) {
293 mdp->tx_skbuff[i] = NULL;
294 txdesc = &mdp->tx_ring[i];
295 txdesc->status = cpu_to_edmac(mdp, TD_TFP);
296 txdesc->buffer_length = 0;
297 if (i == 0) {
298 /* Tx descriptor address set */
299 ctrl_outl((u32)txdesc, ioaddr + TDLAR);
300 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
301 ctrl_outl((u32)txdesc, ioaddr + TDFAR);
302 #endif
306 /* Tx descriptor address set */
307 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
308 ctrl_outl((u32)txdesc, ioaddr + TDFXR);
309 ctrl_outl(0x1, ioaddr + TDFFR);
310 #endif
312 txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
315 /* Get skb and descriptor buffer */
316 static int sh_eth_ring_init(struct net_device *ndev)
318 struct sh_eth_private *mdp = netdev_priv(ndev);
319 int rx_ringsize, tx_ringsize, ret = 0;
322 * +26 gets the maximum ethernet encapsulation, +7 & ~7 because the
323 * card needs room to do 8 byte alignment, +2 so we can reserve
324 * the first 2 bytes, and +16 gets room for the status word from the
325 * card.
327 mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ :
328 (((ndev->mtu + 26 + 7) & ~7) + 2 + 16));
330 /* Allocate RX and TX skb rings */
331 mdp->rx_skbuff = kmalloc(sizeof(*mdp->rx_skbuff) * RX_RING_SIZE,
332 GFP_KERNEL);
333 if (!mdp->rx_skbuff) {
334 printk(KERN_ERR "%s: Cannot allocate Rx skb\n", ndev->name);
335 ret = -ENOMEM;
336 return ret;
339 mdp->tx_skbuff = kmalloc(sizeof(*mdp->tx_skbuff) * TX_RING_SIZE,
340 GFP_KERNEL);
341 if (!mdp->tx_skbuff) {
342 printk(KERN_ERR "%s: Cannot allocate Tx skb\n", ndev->name);
343 ret = -ENOMEM;
344 goto skb_ring_free;
347 /* Allocate all Rx descriptors. */
348 rx_ringsize = sizeof(struct sh_eth_rxdesc) * RX_RING_SIZE;
349 mdp->rx_ring = dma_alloc_coherent(NULL, rx_ringsize, &mdp->rx_desc_dma,
350 GFP_KERNEL);
352 if (!mdp->rx_ring) {
353 printk(KERN_ERR "%s: Cannot allocate Rx Ring (size %d bytes)\n",
354 ndev->name, rx_ringsize);
355 ret = -ENOMEM;
356 goto desc_ring_free;
359 mdp->dirty_rx = 0;
361 /* Allocate all Tx descriptors. */
362 tx_ringsize = sizeof(struct sh_eth_txdesc) * TX_RING_SIZE;
363 mdp->tx_ring = dma_alloc_coherent(NULL, tx_ringsize, &mdp->tx_desc_dma,
364 GFP_KERNEL);
365 if (!mdp->tx_ring) {
366 printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n",
367 ndev->name, tx_ringsize);
368 ret = -ENOMEM;
369 goto desc_ring_free;
371 return ret;
373 desc_ring_free:
374 /* free DMA buffer */
375 dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma);
377 skb_ring_free:
378 /* Free Rx and Tx skb ring buffer */
379 sh_eth_ring_free(ndev);
381 return ret;
384 static int sh_eth_dev_init(struct net_device *ndev)
386 int ret = 0;
387 struct sh_eth_private *mdp = netdev_priv(ndev);
388 u32 ioaddr = ndev->base_addr;
389 u_int32_t rx_int_var, tx_int_var;
390 u32 val;
392 /* Soft Reset */
393 sh_eth_reset(ndev);
395 /* Descriptor format */
396 sh_eth_ring_format(ndev);
397 ctrl_outl(RPADIR_INIT, ioaddr + RPADIR);
399 /* all sh_eth int mask */
400 ctrl_outl(0, ioaddr + EESIPR);
402 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
403 ctrl_outl(EDMR_EL, ioaddr + EDMR);
404 #else
405 ctrl_outl(0, ioaddr + EDMR); /* Endian change */
406 #endif
408 /* FIFO size set */
409 ctrl_outl((FIFO_SIZE_T | FIFO_SIZE_R), ioaddr + FDR);
410 ctrl_outl(0, ioaddr + TFTR);
412 /* Frame recv control */
413 ctrl_outl(0, ioaddr + RMCR);
415 rx_int_var = mdp->rx_int_var = DESC_I_RINT8 | DESC_I_RINT5;
416 tx_int_var = mdp->tx_int_var = DESC_I_TINT2;
417 ctrl_outl(rx_int_var | tx_int_var, ioaddr + TRSCER);
419 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
420 /* Burst sycle set */
421 ctrl_outl(0x800, ioaddr + BCULR);
422 #endif
424 ctrl_outl((FIFO_F_D_RFF | FIFO_F_D_RFD), ioaddr + FCFTR);
426 #if !defined(CONFIG_CPU_SUBTYPE_SH7763)
427 ctrl_outl(0, ioaddr + TRIMD);
428 #endif
430 /* Recv frame limit set register */
431 ctrl_outl(RFLR_VALUE, ioaddr + RFLR);
433 ctrl_outl(ctrl_inl(ioaddr + EESR), ioaddr + EESR);
434 ctrl_outl((DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff), ioaddr + EESIPR);
436 /* PAUSE Prohibition */
437 val = (ctrl_inl(ioaddr + ECMR) & ECMR_DM) |
438 ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
440 ctrl_outl(val, ioaddr + ECMR);
442 /* E-MAC Status Register clear */
443 ctrl_outl(ECSR_INIT, ioaddr + ECSR);
445 /* E-MAC Interrupt Enable register */
446 ctrl_outl(ECSIPR_INIT, ioaddr + ECSIPR);
448 /* Set MAC address */
449 update_mac_address(ndev);
451 /* mask reset */
452 #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7763)
453 ctrl_outl(APR_AP, ioaddr + APR);
454 ctrl_outl(MPR_MP, ioaddr + MPR);
455 ctrl_outl(TPAUSER_UNLIMITED, ioaddr + TPAUSER);
456 #endif
457 #if defined(CONFIG_CPU_SUBTYPE_SH7710)
458 ctrl_outl(BCFR_UNLIMITED, ioaddr + BCFR);
459 #endif
461 /* Setting the Rx mode will start the Rx process. */
462 ctrl_outl(EDRRR_R, ioaddr + EDRRR);
464 netif_start_queue(ndev);
466 return ret;
469 /* free Tx skb function */
470 static int sh_eth_txfree(struct net_device *ndev)
472 struct sh_eth_private *mdp = netdev_priv(ndev);
473 struct sh_eth_txdesc *txdesc;
474 int freeNum = 0;
475 int entry = 0;
477 for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
478 entry = mdp->dirty_tx % TX_RING_SIZE;
479 txdesc = &mdp->tx_ring[entry];
480 if (txdesc->status & cpu_to_edmac(mdp, TD_TACT))
481 break;
482 /* Free the original skb. */
483 if (mdp->tx_skbuff[entry]) {
484 dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
485 mdp->tx_skbuff[entry] = NULL;
486 freeNum++;
488 txdesc->status = cpu_to_edmac(mdp, TD_TFP);
489 if (entry >= TX_RING_SIZE - 1)
490 txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
492 mdp->stats.tx_packets++;
493 mdp->stats.tx_bytes += txdesc->buffer_length;
495 return freeNum;
498 /* Packet receive function */
499 static int sh_eth_rx(struct net_device *ndev)
501 struct sh_eth_private *mdp = netdev_priv(ndev);
502 struct sh_eth_rxdesc *rxdesc;
504 int entry = mdp->cur_rx % RX_RING_SIZE;
505 int boguscnt = (mdp->dirty_rx + RX_RING_SIZE) - mdp->cur_rx;
506 struct sk_buff *skb;
507 u16 pkt_len = 0;
508 u32 desc_status, reserve = 0;
510 rxdesc = &mdp->rx_ring[entry];
511 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) {
512 desc_status = edmac_to_cpu(mdp, rxdesc->status);
513 pkt_len = rxdesc->frame_length;
515 if (--boguscnt < 0)
516 break;
518 if (!(desc_status & RDFEND))
519 mdp->stats.rx_length_errors++;
521 if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 |
522 RD_RFS5 | RD_RFS6 | RD_RFS10)) {
523 mdp->stats.rx_errors++;
524 if (desc_status & RD_RFS1)
525 mdp->stats.rx_crc_errors++;
526 if (desc_status & RD_RFS2)
527 mdp->stats.rx_frame_errors++;
528 if (desc_status & RD_RFS3)
529 mdp->stats.rx_length_errors++;
530 if (desc_status & RD_RFS4)
531 mdp->stats.rx_length_errors++;
532 if (desc_status & RD_RFS6)
533 mdp->stats.rx_missed_errors++;
534 if (desc_status & RD_RFS10)
535 mdp->stats.rx_over_errors++;
536 } else {
537 swaps((char *)(rxdesc->addr & ~0x3), pkt_len + 2);
538 skb = mdp->rx_skbuff[entry];
539 mdp->rx_skbuff[entry] = NULL;
540 skb_put(skb, pkt_len);
541 skb->protocol = eth_type_trans(skb, ndev);
542 netif_rx(skb);
543 ndev->last_rx = jiffies;
544 mdp->stats.rx_packets++;
545 mdp->stats.rx_bytes += pkt_len;
547 rxdesc->status |= cpu_to_edmac(mdp, RD_RACT);
548 entry = (++mdp->cur_rx) % RX_RING_SIZE;
551 /* Refill the Rx ring buffers. */
552 for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) {
553 entry = mdp->dirty_rx % RX_RING_SIZE;
554 rxdesc = &mdp->rx_ring[entry];
555 /* The size of the buffer is 16 byte boundary. */
556 rxdesc->buffer_length = (mdp->rx_buf_sz + 16) & ~0x0F;
558 if (mdp->rx_skbuff[entry] == NULL) {
559 skb = dev_alloc_skb(mdp->rx_buf_sz);
560 mdp->rx_skbuff[entry] = skb;
561 if (skb == NULL)
562 break; /* Better luck next round. */
563 skb->dev = ndev;
564 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
565 reserve = SH7763_SKB_ALIGN
566 - ((uint32_t)skb->data & (SH7763_SKB_ALIGN-1));
567 if (reserve)
568 skb_reserve(skb, reserve);
569 #else
570 skb_reserve(skb, RX_OFFSET);
571 #endif
572 skb->ip_summed = CHECKSUM_NONE;
573 rxdesc->addr = (u32)skb->data & ~0x3UL;
575 if (entry >= RX_RING_SIZE - 1)
576 rxdesc->status |=
577 cpu_to_edmac(mdp, RD_RACT | RD_RFP | RD_RDEL);
578 else
579 rxdesc->status |=
580 cpu_to_edmac(mdp, RD_RACT | RD_RFP);
583 /* Restart Rx engine if stopped. */
584 /* If we don't need to check status, don't. -KDU */
585 if (!(ctrl_inl(ndev->base_addr + EDRRR) & EDRRR_R))
586 ctrl_outl(EDRRR_R, ndev->base_addr + EDRRR);
588 return 0;
591 /* error control function */
592 static void sh_eth_error(struct net_device *ndev, int intr_status)
594 struct sh_eth_private *mdp = netdev_priv(ndev);
595 u32 ioaddr = ndev->base_addr;
596 u32 felic_stat;
598 if (intr_status & EESR_ECI) {
599 felic_stat = ctrl_inl(ioaddr + ECSR);
600 ctrl_outl(felic_stat, ioaddr + ECSR); /* clear int */
601 if (felic_stat & ECSR_ICD)
602 mdp->stats.tx_carrier_errors++;
603 if (felic_stat & ECSR_LCHNG) {
604 /* Link Changed */
605 u32 link_stat = (ctrl_inl(ioaddr + PSR));
606 if (!(link_stat & PHY_ST_LINK)) {
607 /* Link Down : disable tx and rx */
608 ctrl_outl(ctrl_inl(ioaddr + ECMR) &
609 ~(ECMR_RE | ECMR_TE), ioaddr + ECMR);
610 } else {
611 /* Link Up */
612 ctrl_outl(ctrl_inl(ioaddr + EESIPR) &
613 ~DMAC_M_ECI, ioaddr + EESIPR);
614 /*clear int */
615 ctrl_outl(ctrl_inl(ioaddr + ECSR),
616 ioaddr + ECSR);
617 ctrl_outl(ctrl_inl(ioaddr + EESIPR) |
618 DMAC_M_ECI, ioaddr + EESIPR);
619 /* enable tx and rx */
620 ctrl_outl(ctrl_inl(ioaddr + ECMR) |
621 (ECMR_RE | ECMR_TE), ioaddr + ECMR);
626 if (intr_status & EESR_TWB) {
627 /* Write buck end. unused write back interrupt */
628 if (intr_status & EESR_TABT) /* Transmit Abort int */
629 mdp->stats.tx_aborted_errors++;
632 if (intr_status & EESR_RABT) {
633 /* Receive Abort int */
634 if (intr_status & EESR_RFRMER) {
635 /* Receive Frame Overflow int */
636 mdp->stats.rx_frame_errors++;
637 printk(KERN_ERR "Receive Frame Overflow\n");
640 #if !defined(CONFIG_CPU_SUBTYPE_SH7763)
641 if (intr_status & EESR_ADE) {
642 if (intr_status & EESR_TDE) {
643 if (intr_status & EESR_TFE)
644 mdp->stats.tx_fifo_errors++;
647 #endif
649 if (intr_status & EESR_RDE) {
650 /* Receive Descriptor Empty int */
651 mdp->stats.rx_over_errors++;
653 if (ctrl_inl(ioaddr + EDRRR) ^ EDRRR_R)
654 ctrl_outl(EDRRR_R, ioaddr + EDRRR);
655 printk(KERN_ERR "Receive Descriptor Empty\n");
657 if (intr_status & EESR_RFE) {
658 /* Receive FIFO Overflow int */
659 mdp->stats.rx_fifo_errors++;
660 printk(KERN_ERR "Receive FIFO Overflow\n");
662 if (intr_status & (EESR_TWB | EESR_TABT |
663 #if !defined(CONFIG_CPU_SUBTYPE_SH7763)
664 EESR_ADE |
665 #endif
666 EESR_TDE | EESR_TFE)) {
667 /* Tx error */
668 u32 edtrr = ctrl_inl(ndev->base_addr + EDTRR);
669 /* dmesg */
670 printk(KERN_ERR "%s:TX error. status=%8.8x cur_tx=%8.8x ",
671 ndev->name, intr_status, mdp->cur_tx);
672 printk(KERN_ERR "dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n",
673 mdp->dirty_tx, (u32) ndev->state, edtrr);
674 /* dirty buffer free */
675 sh_eth_txfree(ndev);
677 /* SH7712 BUG */
678 if (edtrr ^ EDTRR_TRNS) {
679 /* tx dma start */
680 ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR);
682 /* wakeup */
683 netif_wake_queue(ndev);
687 static irqreturn_t sh_eth_interrupt(int irq, void *netdev)
689 struct net_device *ndev = netdev;
690 struct sh_eth_private *mdp = netdev_priv(ndev);
691 u32 ioaddr, boguscnt = RX_RING_SIZE;
692 u32 intr_status = 0;
694 ioaddr = ndev->base_addr;
695 spin_lock(&mdp->lock);
697 /* Get interrpt stat */
698 intr_status = ctrl_inl(ioaddr + EESR);
699 /* Clear interrupt */
700 ctrl_outl(intr_status, ioaddr + EESR);
702 if (intr_status & (EESR_FRC | /* Frame recv*/
703 EESR_RMAF | /* Multi cast address recv*/
704 EESR_RRF | /* Bit frame recv */
705 EESR_RTLF | /* Long frame recv*/
706 EESR_RTSF | /* short frame recv */
707 EESR_PRE | /* PHY-LSI recv error */
708 EESR_CERF)){ /* recv frame CRC error */
709 sh_eth_rx(ndev);
712 /* Tx Check */
713 if (intr_status & TX_CHECK) {
714 sh_eth_txfree(ndev);
715 netif_wake_queue(ndev);
718 if (intr_status & EESR_ERR_CHECK)
719 sh_eth_error(ndev, intr_status);
721 if (--boguscnt < 0) {
722 printk(KERN_WARNING
723 "%s: Too much work at interrupt, status=0x%4.4x.\n",
724 ndev->name, intr_status);
727 spin_unlock(&mdp->lock);
729 return IRQ_HANDLED;
732 static void sh_eth_timer(unsigned long data)
734 struct net_device *ndev = (struct net_device *)data;
735 struct sh_eth_private *mdp = netdev_priv(ndev);
737 mod_timer(&mdp->timer, jiffies + (10 * HZ));
740 /* PHY state control function */
741 static void sh_eth_adjust_link(struct net_device *ndev)
743 struct sh_eth_private *mdp = netdev_priv(ndev);
744 struct phy_device *phydev = mdp->phydev;
745 u32 ioaddr = ndev->base_addr;
746 int new_state = 0;
748 if (phydev->link != PHY_DOWN) {
749 if (phydev->duplex != mdp->duplex) {
750 new_state = 1;
751 mdp->duplex = phydev->duplex;
752 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
753 if (mdp->duplex) { /* FULL */
754 ctrl_outl(ctrl_inl(ioaddr + ECMR) | ECMR_DM,
755 ioaddr + ECMR);
756 } else { /* Half */
757 ctrl_outl(ctrl_inl(ioaddr + ECMR) & ~ECMR_DM,
758 ioaddr + ECMR);
760 #endif
763 if (phydev->speed != mdp->speed) {
764 new_state = 1;
765 mdp->speed = phydev->speed;
766 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
767 switch (mdp->speed) {
768 case 10: /* 10BASE */
769 ctrl_outl(GECMR_10, ioaddr + GECMR); break;
770 case 100:/* 100BASE */
771 ctrl_outl(GECMR_100, ioaddr + GECMR); break;
772 case 1000: /* 1000BASE */
773 ctrl_outl(GECMR_1000, ioaddr + GECMR); break;
774 default:
775 break;
777 #endif
779 if (mdp->link == PHY_DOWN) {
780 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_TXF)
781 | ECMR_DM, ioaddr + ECMR);
782 new_state = 1;
783 mdp->link = phydev->link;
785 } else if (mdp->link) {
786 new_state = 1;
787 mdp->link = PHY_DOWN;
788 mdp->speed = 0;
789 mdp->duplex = -1;
792 if (new_state)
793 phy_print_status(phydev);
796 /* PHY init function */
797 static int sh_eth_phy_init(struct net_device *ndev)
799 struct sh_eth_private *mdp = netdev_priv(ndev);
800 char phy_id[BUS_ID_SIZE];
801 struct phy_device *phydev = NULL;
803 snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT,
804 mdp->mii_bus->id , mdp->phy_id);
806 mdp->link = PHY_DOWN;
807 mdp->speed = 0;
808 mdp->duplex = -1;
810 /* Try connect to PHY */
811 phydev = phy_connect(ndev, phy_id, &sh_eth_adjust_link,
812 0, PHY_INTERFACE_MODE_MII);
813 if (IS_ERR(phydev)) {
814 dev_err(&ndev->dev, "phy_connect failed\n");
815 return PTR_ERR(phydev);
817 dev_info(&ndev->dev, "attached phy %i to driver %s\n",
818 phydev->addr, phydev->drv->name);
820 mdp->phydev = phydev;
822 return 0;
825 /* PHY control start function */
826 static int sh_eth_phy_start(struct net_device *ndev)
828 struct sh_eth_private *mdp = netdev_priv(ndev);
829 int ret;
831 ret = sh_eth_phy_init(ndev);
832 if (ret)
833 return ret;
835 /* reset phy - this also wakes it from PDOWN */
836 phy_write(mdp->phydev, MII_BMCR, BMCR_RESET);
837 phy_start(mdp->phydev);
839 return 0;
842 /* network device open function */
843 static int sh_eth_open(struct net_device *ndev)
845 int ret = 0;
846 struct sh_eth_private *mdp = netdev_priv(ndev);
848 ret = request_irq(ndev->irq, &sh_eth_interrupt, 0, ndev->name, ndev);
849 if (ret) {
850 printk(KERN_ERR "Can not assign IRQ number to %s\n", CARDNAME);
851 return ret;
854 /* Descriptor set */
855 ret = sh_eth_ring_init(ndev);
856 if (ret)
857 goto out_free_irq;
859 /* device init */
860 ret = sh_eth_dev_init(ndev);
861 if (ret)
862 goto out_free_irq;
864 /* PHY control start*/
865 ret = sh_eth_phy_start(ndev);
866 if (ret)
867 goto out_free_irq;
869 /* Set the timer to check for link beat. */
870 init_timer(&mdp->timer);
871 mdp->timer.expires = (jiffies + (24 * HZ)) / 10;/* 2.4 sec. */
872 setup_timer(&mdp->timer, sh_eth_timer, (unsigned long)ndev);
874 return ret;
876 out_free_irq:
877 free_irq(ndev->irq, ndev);
878 return ret;
881 /* Timeout function */
882 static void sh_eth_tx_timeout(struct net_device *ndev)
884 struct sh_eth_private *mdp = netdev_priv(ndev);
885 u32 ioaddr = ndev->base_addr;
886 struct sh_eth_rxdesc *rxdesc;
887 int i;
889 netif_stop_queue(ndev);
891 /* worning message out. */
892 printk(KERN_WARNING "%s: transmit timed out, status %8.8x,"
893 " resetting...\n", ndev->name, (int)ctrl_inl(ioaddr + EESR));
895 /* tx_errors count up */
896 mdp->stats.tx_errors++;
898 /* timer off */
899 del_timer_sync(&mdp->timer);
901 /* Free all the skbuffs in the Rx queue. */
902 for (i = 0; i < RX_RING_SIZE; i++) {
903 rxdesc = &mdp->rx_ring[i];
904 rxdesc->status = 0;
905 rxdesc->addr = 0xBADF00D0;
906 if (mdp->rx_skbuff[i])
907 dev_kfree_skb(mdp->rx_skbuff[i]);
908 mdp->rx_skbuff[i] = NULL;
910 for (i = 0; i < TX_RING_SIZE; i++) {
911 if (mdp->tx_skbuff[i])
912 dev_kfree_skb(mdp->tx_skbuff[i]);
913 mdp->tx_skbuff[i] = NULL;
916 /* device init */
917 sh_eth_dev_init(ndev);
919 /* timer on */
920 mdp->timer.expires = (jiffies + (24 * HZ)) / 10;/* 2.4 sec. */
921 add_timer(&mdp->timer);
924 /* Packet transmit function */
925 static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
927 struct sh_eth_private *mdp = netdev_priv(ndev);
928 struct sh_eth_txdesc *txdesc;
929 u32 entry;
930 unsigned long flags;
932 spin_lock_irqsave(&mdp->lock, flags);
933 if ((mdp->cur_tx - mdp->dirty_tx) >= (TX_RING_SIZE - 4)) {
934 if (!sh_eth_txfree(ndev)) {
935 netif_stop_queue(ndev);
936 spin_unlock_irqrestore(&mdp->lock, flags);
937 return 1;
940 spin_unlock_irqrestore(&mdp->lock, flags);
942 entry = mdp->cur_tx % TX_RING_SIZE;
943 mdp->tx_skbuff[entry] = skb;
944 txdesc = &mdp->tx_ring[entry];
945 txdesc->addr = (u32)(skb->data);
946 /* soft swap. */
947 swaps((char *)(txdesc->addr & ~0x3), skb->len + 2);
948 /* write back */
949 __flush_purge_region(skb->data, skb->len);
950 if (skb->len < ETHERSMALL)
951 txdesc->buffer_length = ETHERSMALL;
952 else
953 txdesc->buffer_length = skb->len;
955 if (entry >= TX_RING_SIZE - 1)
956 txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE);
957 else
958 txdesc->status |= cpu_to_edmac(mdp, TD_TACT);
960 mdp->cur_tx++;
962 if (!(ctrl_inl(ndev->base_addr + EDTRR) & EDTRR_TRNS))
963 ctrl_outl(EDTRR_TRNS, ndev->base_addr + EDTRR);
965 ndev->trans_start = jiffies;
967 return 0;
970 /* device close function */
971 static int sh_eth_close(struct net_device *ndev)
973 struct sh_eth_private *mdp = netdev_priv(ndev);
974 u32 ioaddr = ndev->base_addr;
975 int ringsize;
977 netif_stop_queue(ndev);
979 /* Disable interrupts by clearing the interrupt mask. */
980 ctrl_outl(0x0000, ioaddr + EESIPR);
982 /* Stop the chip's Tx and Rx processes. */
983 ctrl_outl(0, ioaddr + EDTRR);
984 ctrl_outl(0, ioaddr + EDRRR);
986 /* PHY Disconnect */
987 if (mdp->phydev) {
988 phy_stop(mdp->phydev);
989 phy_disconnect(mdp->phydev);
992 free_irq(ndev->irq, ndev);
994 del_timer_sync(&mdp->timer);
996 /* Free all the skbuffs in the Rx queue. */
997 sh_eth_ring_free(ndev);
999 /* free DMA buffer */
1000 ringsize = sizeof(struct sh_eth_rxdesc) * RX_RING_SIZE;
1001 dma_free_coherent(NULL, ringsize, mdp->rx_ring, mdp->rx_desc_dma);
1003 /* free DMA buffer */
1004 ringsize = sizeof(struct sh_eth_txdesc) * TX_RING_SIZE;
1005 dma_free_coherent(NULL, ringsize, mdp->tx_ring, mdp->tx_desc_dma);
1007 return 0;
1010 static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
1012 struct sh_eth_private *mdp = netdev_priv(ndev);
1013 u32 ioaddr = ndev->base_addr;
1015 mdp->stats.tx_dropped += ctrl_inl(ioaddr + TROCR);
1016 ctrl_outl(0, ioaddr + TROCR); /* (write clear) */
1017 mdp->stats.collisions += ctrl_inl(ioaddr + CDCR);
1018 ctrl_outl(0, ioaddr + CDCR); /* (write clear) */
1019 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + LCCR);
1020 ctrl_outl(0, ioaddr + LCCR); /* (write clear) */
1021 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
1022 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CERCR);/* CERCR */
1023 ctrl_outl(0, ioaddr + CERCR); /* (write clear) */
1024 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CEECR);/* CEECR */
1025 ctrl_outl(0, ioaddr + CEECR); /* (write clear) */
1026 #else
1027 mdp->stats.tx_carrier_errors += ctrl_inl(ioaddr + CNDCR);
1028 ctrl_outl(0, ioaddr + CNDCR); /* (write clear) */
1029 #endif
1030 return &mdp->stats;
1033 /* ioctl to device funciotn*/
1034 static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq,
1035 int cmd)
1037 struct sh_eth_private *mdp = netdev_priv(ndev);
1038 struct phy_device *phydev = mdp->phydev;
1040 if (!netif_running(ndev))
1041 return -EINVAL;
1043 if (!phydev)
1044 return -ENODEV;
1046 return phy_mii_ioctl(phydev, if_mii(rq), cmd);
1050 /* Multicast reception directions set */
1051 static void sh_eth_set_multicast_list(struct net_device *ndev)
1053 u32 ioaddr = ndev->base_addr;
1055 if (ndev->flags & IFF_PROMISC) {
1056 /* Set promiscuous. */
1057 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_MCT) | ECMR_PRM,
1058 ioaddr + ECMR);
1059 } else {
1060 /* Normal, unicast/broadcast-only mode. */
1061 ctrl_outl((ctrl_inl(ioaddr + ECMR) & ~ECMR_PRM) | ECMR_MCT,
1062 ioaddr + ECMR);
1066 /* SuperH's TSU register init function */
1067 static void sh_eth_tsu_init(u32 ioaddr)
1069 ctrl_outl(0, ioaddr + TSU_FWEN0); /* Disable forward(0->1) */
1070 ctrl_outl(0, ioaddr + TSU_FWEN1); /* Disable forward(1->0) */
1071 ctrl_outl(0, ioaddr + TSU_FCM); /* forward fifo 3k-3k */
1072 ctrl_outl(0xc, ioaddr + TSU_BSYSL0);
1073 ctrl_outl(0xc, ioaddr + TSU_BSYSL1);
1074 ctrl_outl(0, ioaddr + TSU_PRISL0);
1075 ctrl_outl(0, ioaddr + TSU_PRISL1);
1076 ctrl_outl(0, ioaddr + TSU_FWSL0);
1077 ctrl_outl(0, ioaddr + TSU_FWSL1);
1078 ctrl_outl(TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, ioaddr + TSU_FWSLC);
1079 #if defined(CONFIG_CPU_SUBTYPE_SH7763)
1080 ctrl_outl(0, ioaddr + TSU_QTAG0); /* Disable QTAG(0->1) */
1081 ctrl_outl(0, ioaddr + TSU_QTAG1); /* Disable QTAG(1->0) */
1082 #else
1083 ctrl_outl(0, ioaddr + TSU_QTAGM0); /* Disable QTAG(0->1) */
1084 ctrl_outl(0, ioaddr + TSU_QTAGM1); /* Disable QTAG(1->0) */
1085 #endif
1086 ctrl_outl(0, ioaddr + TSU_FWSR); /* all interrupt status clear */
1087 ctrl_outl(0, ioaddr + TSU_FWINMK); /* Disable all interrupt */
1088 ctrl_outl(0, ioaddr + TSU_TEN); /* Disable all CAM entry */
1089 ctrl_outl(0, ioaddr + TSU_POST1); /* Disable CAM entry [ 0- 7] */
1090 ctrl_outl(0, ioaddr + TSU_POST2); /* Disable CAM entry [ 8-15] */
1091 ctrl_outl(0, ioaddr + TSU_POST3); /* Disable CAM entry [16-23] */
1092 ctrl_outl(0, ioaddr + TSU_POST4); /* Disable CAM entry [24-31] */
1095 /* MDIO bus release function */
1096 static int sh_mdio_release(struct net_device *ndev)
1098 struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
1100 /* unregister mdio bus */
1101 mdiobus_unregister(bus);
1103 /* remove mdio bus info from net_device */
1104 dev_set_drvdata(&ndev->dev, NULL);
1106 /* free bitbang info */
1107 free_mdio_bitbang(bus);
1109 return 0;
1112 /* MDIO bus init function */
1113 static int sh_mdio_init(struct net_device *ndev, int id)
1115 int ret, i;
1116 struct bb_info *bitbang;
1117 struct sh_eth_private *mdp = netdev_priv(ndev);
1119 /* create bit control struct for PHY */
1120 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
1121 if (!bitbang) {
1122 ret = -ENOMEM;
1123 goto out;
1126 /* bitbang init */
1127 bitbang->addr = ndev->base_addr + PIR;
1128 bitbang->mdi_msk = 0x08;
1129 bitbang->mdo_msk = 0x04;
1130 bitbang->mmd_msk = 0x02;/* MMD */
1131 bitbang->mdc_msk = 0x01;
1132 bitbang->ctrl.ops = &bb_ops;
1134 /* MII contorller setting */
1135 mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
1136 if (!mdp->mii_bus) {
1137 ret = -ENOMEM;
1138 goto out_free_bitbang;
1141 /* Hook up MII support for ethtool */
1142 mdp->mii_bus->name = "sh_mii";
1143 mdp->mii_bus->parent = &ndev->dev;
1144 snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%x", id);
1146 /* PHY IRQ */
1147 mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1148 if (!mdp->mii_bus->irq) {
1149 ret = -ENOMEM;
1150 goto out_free_bus;
1153 for (i = 0; i < PHY_MAX_ADDR; i++)
1154 mdp->mii_bus->irq[i] = PHY_POLL;
1156 /* regist mdio bus */
1157 ret = mdiobus_register(mdp->mii_bus);
1158 if (ret)
1159 goto out_free_irq;
1161 dev_set_drvdata(&ndev->dev, mdp->mii_bus);
1163 return 0;
1165 out_free_irq:
1166 kfree(mdp->mii_bus->irq);
1168 out_free_bus:
1169 free_mdio_bitbang(mdp->mii_bus);
1171 out_free_bitbang:
1172 kfree(bitbang);
1174 out:
1175 return ret;
1178 static int sh_eth_drv_probe(struct platform_device *pdev)
1180 int ret, i, devno = 0;
1181 struct resource *res;
1182 struct net_device *ndev = NULL;
1183 struct sh_eth_private *mdp;
1184 struct sh_eth_plat_data *pd;
1186 /* get base addr */
1187 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1188 if (unlikely(res == NULL)) {
1189 dev_err(&pdev->dev, "invalid resource\n");
1190 ret = -EINVAL;
1191 goto out;
1194 ndev = alloc_etherdev(sizeof(struct sh_eth_private));
1195 if (!ndev) {
1196 printk(KERN_ERR "%s: could not allocate device.\n", CARDNAME);
1197 ret = -ENOMEM;
1198 goto out;
1201 /* The sh Ether-specific entries in the device structure. */
1202 ndev->base_addr = res->start;
1203 devno = pdev->id;
1204 if (devno < 0)
1205 devno = 0;
1207 ndev->dma = -1;
1208 ret = platform_get_irq(pdev, 0);
1209 if (ret < 0) {
1210 ret = -ENODEV;
1211 goto out_release;
1213 ndev->irq = ret;
1215 SET_NETDEV_DEV(ndev, &pdev->dev);
1217 /* Fill in the fields of the device structure with ethernet values. */
1218 ether_setup(ndev);
1220 mdp = netdev_priv(ndev);
1221 spin_lock_init(&mdp->lock);
1223 pd = (struct sh_eth_plat_data *)(pdev->dev.platform_data);
1224 /* get PHY ID */
1225 mdp->phy_id = pd->phy;
1226 /* EDMAC endian */
1227 mdp->edmac_endian = pd->edmac_endian;
1229 /* set function */
1230 ndev->open = sh_eth_open;
1231 ndev->hard_start_xmit = sh_eth_start_xmit;
1232 ndev->stop = sh_eth_close;
1233 ndev->get_stats = sh_eth_get_stats;
1234 ndev->set_multicast_list = sh_eth_set_multicast_list;
1235 ndev->do_ioctl = sh_eth_do_ioctl;
1236 ndev->tx_timeout = sh_eth_tx_timeout;
1237 ndev->watchdog_timeo = TX_TIMEOUT;
1239 mdp->post_rx = POST_RX >> (devno << 1);
1240 mdp->post_fw = POST_FW >> (devno << 1);
1242 /* read and set MAC address */
1243 read_mac_address(ndev);
1245 /* First device only init */
1246 if (!devno) {
1247 #if defined(ARSTR)
1248 /* reset device */
1249 ctrl_outl(ARSTR_ARSTR, ARSTR);
1250 mdelay(1);
1251 #endif
1253 #if defined(SH_TSU_ADDR)
1254 /* TSU init (Init only)*/
1255 sh_eth_tsu_init(SH_TSU_ADDR);
1256 #endif
1259 /* network device register */
1260 ret = register_netdev(ndev);
1261 if (ret)
1262 goto out_release;
1264 /* mdio bus init */
1265 ret = sh_mdio_init(ndev, pdev->id);
1266 if (ret)
1267 goto out_unregister;
1269 /* pritnt device infomation */
1270 printk(KERN_INFO "%s: %s at 0x%x, ",
1271 ndev->name, CARDNAME, (u32) ndev->base_addr);
1273 for (i = 0; i < 5; i++)
1274 printk("%02X:", ndev->dev_addr[i]);
1275 printk("%02X, IRQ %d.\n", ndev->dev_addr[i], ndev->irq);
1277 platform_set_drvdata(pdev, ndev);
1279 return ret;
1281 out_unregister:
1282 unregister_netdev(ndev);
1284 out_release:
1285 /* net_dev free */
1286 if (ndev)
1287 free_netdev(ndev);
1289 out:
1290 return ret;
1293 static int sh_eth_drv_remove(struct platform_device *pdev)
1295 struct net_device *ndev = platform_get_drvdata(pdev);
1297 sh_mdio_release(ndev);
1298 unregister_netdev(ndev);
1299 flush_scheduled_work();
1301 free_netdev(ndev);
1302 platform_set_drvdata(pdev, NULL);
1304 return 0;
1307 static struct platform_driver sh_eth_driver = {
1308 .probe = sh_eth_drv_probe,
1309 .remove = sh_eth_drv_remove,
1310 .driver = {
1311 .name = CARDNAME,
1315 static int __init sh_eth_init(void)
1317 return platform_driver_register(&sh_eth_driver);
1320 static void __exit sh_eth_cleanup(void)
1322 platform_driver_unregister(&sh_eth_driver);
1325 module_init(sh_eth_init);
1326 module_exit(sh_eth_cleanup);
1328 MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda");
1329 MODULE_DESCRIPTION("Renesas SuperH Ethernet driver");
1330 MODULE_LICENSE("GPL v2");