Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the MPC5200 Fast Ethernet Controller |
| 3 | * |
| 4 | * Originally written by Dale Farnsworth <dfarnsworth@mvista.com> and |
| 5 | * now maintained by Sylvain Munaut <tnt@246tNt.com> |
| 6 | * |
| 7 | * Copyright (C) 2007 Domen Puncer, Telargo, Inc. |
| 8 | * Copyright (C) 2007 Sylvain Munaut <tnt@246tNt.com> |
| 9 | * Copyright (C) 2003-2004 MontaVista, Software, Inc. |
| 10 | * |
| 11 | * This file is licensed under the terms of the GNU General Public License |
| 12 | * version 2. This program is licensed "as is" without any warranty of any |
| 13 | * kind, whether express or implied. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 23 | #include <linux/errno.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/crc32.h> |
| 26 | #include <linux/hardirq.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/of_device.h> |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 29 | #include <linux/of_mdio.h> |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 30 | #include <linux/of_platform.h> |
| 31 | |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/etherdevice.h> |
| 34 | #include <linux/ethtool.h> |
| 35 | #include <linux/skbuff.h> |
| 36 | |
| 37 | #include <asm/io.h> |
| 38 | #include <asm/delay.h> |
| 39 | #include <asm/mpc52xx.h> |
| 40 | |
| 41 | #include <sysdev/bestcomm/bestcomm.h> |
| 42 | #include <sysdev/bestcomm/fec.h> |
| 43 | |
| 44 | #include "fec_mpc52xx.h" |
| 45 | |
| 46 | #define DRIVER_NAME "mpc52xx-fec" |
| 47 | |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 48 | /* Private driver data structure */ |
| 49 | struct mpc52xx_fec_priv { |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 50 | struct net_device *ndev; |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 51 | int duplex; |
| 52 | int speed; |
| 53 | int r_irq; |
| 54 | int t_irq; |
| 55 | struct mpc52xx_fec __iomem *fec; |
| 56 | struct bcom_task *rx_dmatsk; |
| 57 | struct bcom_task *tx_dmatsk; |
| 58 | spinlock_t lock; |
| 59 | int msg_enable; |
| 60 | |
| 61 | /* MDIO link details */ |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 62 | unsigned int mdio_speed; |
| 63 | struct device_node *phy_node; |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 64 | struct phy_device *phydev; |
| 65 | enum phy_state link; |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 66 | int seven_wire_mode; |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 70 | static irqreturn_t mpc52xx_fec_interrupt(int, void *); |
| 71 | static irqreturn_t mpc52xx_fec_rx_interrupt(int, void *); |
| 72 | static irqreturn_t mpc52xx_fec_tx_interrupt(int, void *); |
| 73 | static void mpc52xx_fec_stop(struct net_device *dev); |
| 74 | static void mpc52xx_fec_start(struct net_device *dev); |
| 75 | static void mpc52xx_fec_reset(struct net_device *dev); |
| 76 | |
| 77 | static u8 mpc52xx_fec_mac_addr[6]; |
| 78 | module_param_array_named(mac, mpc52xx_fec_mac_addr, byte, NULL, 0); |
| 79 | MODULE_PARM_DESC(mac, "six hex digits, ie. 0x1,0x2,0xc0,0x01,0xba,0xbe"); |
| 80 | |
| 81 | #define MPC52xx_MESSAGES_DEFAULT ( NETIF_MSG_DRV | NETIF_MSG_PROBE | \ |
Roel Kluin | 8b98351 | 2008-06-09 16:33:51 -0700 | [diff] [blame] | 82 | NETIF_MSG_LINK | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 83 | static int debug = -1; /* the above default */ |
| 84 | module_param(debug, int, 0); |
| 85 | MODULE_PARM_DESC(debug, "debugging messages level"); |
| 86 | |
| 87 | static void mpc52xx_fec_tx_timeout(struct net_device *dev) |
| 88 | { |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 89 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 90 | unsigned long flags; |
| 91 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 92 | dev_warn(&dev->dev, "transmit timed out\n"); |
| 93 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 94 | spin_lock_irqsave(&priv->lock, flags); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 95 | mpc52xx_fec_reset(dev); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 96 | dev->stats.tx_errors++; |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 97 | spin_unlock_irqrestore(&priv->lock, flags); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 98 | |
| 99 | netif_wake_queue(dev); |
| 100 | } |
| 101 | |
| 102 | static void mpc52xx_fec_set_paddr(struct net_device *dev, u8 *mac) |
| 103 | { |
| 104 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 105 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 106 | |
| 107 | out_be32(&fec->paddr1, *(u32 *)(&mac[0])); |
| 108 | out_be32(&fec->paddr2, (*(u16 *)(&mac[4]) << 16) | FEC_PADDR2_TYPE); |
| 109 | } |
| 110 | |
| 111 | static void mpc52xx_fec_get_paddr(struct net_device *dev, u8 *mac) |
| 112 | { |
| 113 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 114 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 115 | |
| 116 | *(u32 *)(&mac[0]) = in_be32(&fec->paddr1); |
| 117 | *(u16 *)(&mac[4]) = in_be32(&fec->paddr2) >> 16; |
| 118 | } |
| 119 | |
| 120 | static int mpc52xx_fec_set_mac_address(struct net_device *dev, void *addr) |
| 121 | { |
| 122 | struct sockaddr *sock = addr; |
| 123 | |
| 124 | memcpy(dev->dev_addr, sock->sa_data, dev->addr_len); |
| 125 | |
| 126 | mpc52xx_fec_set_paddr(dev, sock->sa_data); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void mpc52xx_fec_free_rx_buffers(struct net_device *dev, struct bcom_task *s) |
| 131 | { |
| 132 | while (!bcom_queue_empty(s)) { |
| 133 | struct bcom_fec_bd *bd; |
| 134 | struct sk_buff *skb; |
| 135 | |
| 136 | skb = bcom_retrieve_buffer(s, NULL, (struct bcom_bd **)&bd); |
Grant Likely | 461cadb | 2009-03-31 20:16:52 +0000 | [diff] [blame] | 137 | dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len, |
| 138 | DMA_FROM_DEVICE); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 139 | kfree_skb(skb); |
| 140 | } |
| 141 | } |
| 142 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 143 | static void |
| 144 | mpc52xx_fec_rx_submit(struct net_device *dev, struct sk_buff *rskb) |
| 145 | { |
| 146 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 147 | struct bcom_fec_bd *bd; |
| 148 | |
| 149 | bd = (struct bcom_fec_bd *) bcom_prepare_next_buffer(priv->rx_dmatsk); |
| 150 | bd->status = FEC_RX_BUFFER_SIZE; |
| 151 | bd->skb_pa = dma_map_single(dev->dev.parent, rskb->data, |
| 152 | FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE); |
| 153 | bcom_submit_next_buffer(priv->rx_dmatsk, rskb); |
| 154 | } |
| 155 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 156 | static int mpc52xx_fec_alloc_rx_buffers(struct net_device *dev, struct bcom_task *rxtsk) |
| 157 | { |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 158 | struct sk_buff *skb; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 159 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 160 | while (!bcom_queue_full(rxtsk)) { |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 161 | skb = dev_alloc_skb(FEC_RX_BUFFER_SIZE); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 162 | if (!skb) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 163 | return -EAGAIN; |
| 164 | |
| 165 | /* zero out the initial receive buffers to aid debugging */ |
| 166 | memset(skb->data, 0, FEC_RX_BUFFER_SIZE); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 167 | mpc52xx_fec_rx_submit(dev, skb); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 168 | } |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | /* based on generic_adjust_link from fs_enet-main.c */ |
| 173 | static void mpc52xx_fec_adjust_link(struct net_device *dev) |
| 174 | { |
| 175 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 176 | struct phy_device *phydev = priv->phydev; |
| 177 | int new_state = 0; |
| 178 | |
| 179 | if (phydev->link != PHY_DOWN) { |
| 180 | if (phydev->duplex != priv->duplex) { |
| 181 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 182 | u32 rcntrl; |
| 183 | u32 tcntrl; |
| 184 | |
| 185 | new_state = 1; |
| 186 | priv->duplex = phydev->duplex; |
| 187 | |
| 188 | rcntrl = in_be32(&fec->r_cntrl); |
| 189 | tcntrl = in_be32(&fec->x_cntrl); |
| 190 | |
| 191 | rcntrl &= ~FEC_RCNTRL_DRT; |
| 192 | tcntrl &= ~FEC_TCNTRL_FDEN; |
| 193 | if (phydev->duplex == DUPLEX_FULL) |
| 194 | tcntrl |= FEC_TCNTRL_FDEN; /* FD enable */ |
| 195 | else |
| 196 | rcntrl |= FEC_RCNTRL_DRT; /* disable Rx on Tx (HD) */ |
| 197 | |
| 198 | out_be32(&fec->r_cntrl, rcntrl); |
| 199 | out_be32(&fec->x_cntrl, tcntrl); |
| 200 | } |
| 201 | |
| 202 | if (phydev->speed != priv->speed) { |
| 203 | new_state = 1; |
| 204 | priv->speed = phydev->speed; |
| 205 | } |
| 206 | |
| 207 | if (priv->link == PHY_DOWN) { |
| 208 | new_state = 1; |
| 209 | priv->link = phydev->link; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | } else if (priv->link) { |
| 213 | new_state = 1; |
| 214 | priv->link = PHY_DOWN; |
| 215 | priv->speed = 0; |
| 216 | priv->duplex = -1; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | if (new_state && netif_msg_link(priv)) |
| 220 | phy_print_status(phydev); |
| 221 | } |
| 222 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 223 | static int mpc52xx_fec_open(struct net_device *dev) |
| 224 | { |
| 225 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 226 | int err = -EBUSY; |
| 227 | |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 228 | if (priv->phy_node) { |
| 229 | priv->phydev = of_phy_connect(priv->ndev, priv->phy_node, |
| 230 | mpc52xx_fec_adjust_link, 0, 0); |
| 231 | if (!priv->phydev) { |
| 232 | dev_err(&dev->dev, "of_phy_connect failed\n"); |
| 233 | return -ENODEV; |
| 234 | } |
| 235 | phy_start(priv->phydev); |
| 236 | } |
| 237 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 238 | if (request_irq(dev->irq, mpc52xx_fec_interrupt, IRQF_SHARED, |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 239 | DRIVER_NAME "_ctrl", dev)) { |
| 240 | dev_err(&dev->dev, "ctrl interrupt request failed\n"); |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 241 | goto free_phy; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 242 | } |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 243 | if (request_irq(priv->r_irq, mpc52xx_fec_rx_interrupt, 0, |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 244 | DRIVER_NAME "_rx", dev)) { |
| 245 | dev_err(&dev->dev, "rx interrupt request failed\n"); |
| 246 | goto free_ctrl_irq; |
| 247 | } |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 248 | if (request_irq(priv->t_irq, mpc52xx_fec_tx_interrupt, 0, |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 249 | DRIVER_NAME "_tx", dev)) { |
| 250 | dev_err(&dev->dev, "tx interrupt request failed\n"); |
| 251 | goto free_2irqs; |
| 252 | } |
| 253 | |
| 254 | bcom_fec_rx_reset(priv->rx_dmatsk); |
| 255 | bcom_fec_tx_reset(priv->tx_dmatsk); |
| 256 | |
| 257 | err = mpc52xx_fec_alloc_rx_buffers(dev, priv->rx_dmatsk); |
| 258 | if (err) { |
| 259 | dev_err(&dev->dev, "mpc52xx_fec_alloc_rx_buffers failed\n"); |
| 260 | goto free_irqs; |
| 261 | } |
| 262 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 263 | bcom_enable(priv->rx_dmatsk); |
| 264 | bcom_enable(priv->tx_dmatsk); |
| 265 | |
| 266 | mpc52xx_fec_start(dev); |
| 267 | |
| 268 | netif_start_queue(dev); |
| 269 | |
| 270 | return 0; |
| 271 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 272 | free_irqs: |
| 273 | free_irq(priv->t_irq, dev); |
| 274 | free_2irqs: |
| 275 | free_irq(priv->r_irq, dev); |
| 276 | free_ctrl_irq: |
| 277 | free_irq(dev->irq, dev); |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 278 | free_phy: |
| 279 | if (priv->phydev) { |
| 280 | phy_stop(priv->phydev); |
| 281 | phy_disconnect(priv->phydev); |
| 282 | priv->phydev = NULL; |
| 283 | } |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 284 | |
| 285 | return err; |
| 286 | } |
| 287 | |
| 288 | static int mpc52xx_fec_close(struct net_device *dev) |
| 289 | { |
| 290 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 291 | |
| 292 | netif_stop_queue(dev); |
| 293 | |
| 294 | mpc52xx_fec_stop(dev); |
| 295 | |
| 296 | mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk); |
| 297 | |
| 298 | free_irq(dev->irq, dev); |
| 299 | free_irq(priv->r_irq, dev); |
| 300 | free_irq(priv->t_irq, dev); |
| 301 | |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 302 | if (priv->phydev) { |
| 303 | /* power down phy */ |
| 304 | phy_stop(priv->phydev); |
| 305 | phy_disconnect(priv->phydev); |
| 306 | priv->phydev = NULL; |
| 307 | } |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /* This will only be invoked if your driver is _not_ in XOFF state. |
| 313 | * What this means is that you need not check it, and that this |
| 314 | * invariant will hold if you make sure that the netif_*_queue() |
| 315 | * calls are done at the proper times. |
| 316 | */ |
Henk Stegeman | d360009 | 2009-03-31 20:16:57 +0000 | [diff] [blame] | 317 | static int mpc52xx_fec_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 318 | { |
| 319 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 320 | struct bcom_fec_bd *bd; |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 321 | unsigned long flags; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 322 | |
| 323 | if (bcom_queue_full(priv->tx_dmatsk)) { |
| 324 | if (net_ratelimit()) |
| 325 | dev_err(&dev->dev, "transmit queue overrun\n"); |
Henk Stegeman | d360009 | 2009-03-31 20:16:57 +0000 | [diff] [blame] | 326 | return NETDEV_TX_BUSY; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 329 | spin_lock_irqsave(&priv->lock, flags); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 330 | |
| 331 | bd = (struct bcom_fec_bd *) |
| 332 | bcom_prepare_next_buffer(priv->tx_dmatsk); |
| 333 | |
| 334 | bd->status = skb->len | BCOM_FEC_TX_BD_TFD | BCOM_FEC_TX_BD_TC; |
Grant Likely | 461cadb | 2009-03-31 20:16:52 +0000 | [diff] [blame] | 335 | bd->skb_pa = dma_map_single(dev->dev.parent, skb->data, skb->len, |
| 336 | DMA_TO_DEVICE); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 337 | |
| 338 | bcom_submit_next_buffer(priv->tx_dmatsk, skb); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 339 | spin_unlock_irqrestore(&priv->lock, flags); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 340 | |
| 341 | if (bcom_queue_full(priv->tx_dmatsk)) { |
| 342 | netif_stop_queue(dev); |
| 343 | } |
| 344 | |
Henk Stegeman | d360009 | 2009-03-31 20:16:57 +0000 | [diff] [blame] | 345 | return NETDEV_TX_OK; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Jon Smirl | bd28bdb | 2008-10-18 11:40:59 +0000 | [diff] [blame] | 348 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 349 | static void mpc52xx_fec_poll_controller(struct net_device *dev) |
| 350 | { |
| 351 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 352 | |
| 353 | disable_irq(priv->t_irq); |
| 354 | mpc52xx_fec_tx_interrupt(priv->t_irq, dev); |
| 355 | enable_irq(priv->t_irq); |
| 356 | disable_irq(priv->r_irq); |
| 357 | mpc52xx_fec_rx_interrupt(priv->r_irq, dev); |
| 358 | enable_irq(priv->r_irq); |
| 359 | } |
| 360 | #endif |
| 361 | |
| 362 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 363 | /* This handles BestComm transmit task interrupts |
| 364 | */ |
| 365 | static irqreturn_t mpc52xx_fec_tx_interrupt(int irq, void *dev_id) |
| 366 | { |
| 367 | struct net_device *dev = dev_id; |
| 368 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 369 | |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 370 | spin_lock(&priv->lock); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 371 | while (bcom_buffer_done(priv->tx_dmatsk)) { |
| 372 | struct sk_buff *skb; |
| 373 | struct bcom_fec_bd *bd; |
| 374 | skb = bcom_retrieve_buffer(priv->tx_dmatsk, NULL, |
| 375 | (struct bcom_bd **)&bd); |
Grant Likely | 461cadb | 2009-03-31 20:16:52 +0000 | [diff] [blame] | 376 | dma_unmap_single(dev->dev.parent, bd->skb_pa, skb->len, |
| 377 | DMA_TO_DEVICE); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 378 | |
| 379 | dev_kfree_skb_irq(skb); |
| 380 | } |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 381 | spin_unlock(&priv->lock); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 382 | |
| 383 | netif_wake_queue(dev); |
| 384 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 385 | return IRQ_HANDLED; |
| 386 | } |
| 387 | |
| 388 | static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id) |
| 389 | { |
| 390 | struct net_device *dev = dev_id; |
| 391 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 392 | struct sk_buff *rskb; /* received sk_buff */ |
| 393 | struct sk_buff *skb; /* new sk_buff to enqueue in its place */ |
| 394 | struct bcom_fec_bd *bd; |
| 395 | u32 status, physaddr; |
| 396 | int length; |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 397 | |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 398 | spin_lock(&priv->lock); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 399 | |
| 400 | while (bcom_buffer_done(priv->rx_dmatsk)) { |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 401 | |
| 402 | rskb = bcom_retrieve_buffer(priv->rx_dmatsk, &status, |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 403 | (struct bcom_bd **)&bd); |
| 404 | physaddr = bd->skb_pa; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 405 | |
| 406 | /* Test for errors in received frame */ |
| 407 | if (status & BCOM_FEC_RX_BD_ERRORS) { |
| 408 | /* Drop packet and reuse the buffer */ |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 409 | mpc52xx_fec_rx_submit(dev, rskb); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 410 | dev->stats.rx_dropped++; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 411 | continue; |
| 412 | } |
| 413 | |
| 414 | /* skbs are allocated on open, so now we allocate a new one, |
| 415 | * and remove the old (with the packet) */ |
| 416 | skb = dev_alloc_skb(FEC_RX_BUFFER_SIZE); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 417 | if (!skb) { |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 418 | /* Can't get a new one : reuse the same & drop pkt */ |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 419 | dev_notice(&dev->dev, "Low memory - dropped packet.\n"); |
| 420 | mpc52xx_fec_rx_submit(dev, rskb); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 421 | dev->stats.rx_dropped++; |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 422 | continue; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 423 | } |
| 424 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 425 | /* Enqueue the new sk_buff back on the hardware */ |
| 426 | mpc52xx_fec_rx_submit(dev, skb); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 427 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 428 | /* Process the received skb - Drop the spin lock while |
| 429 | * calling into the network stack */ |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 430 | spin_unlock(&priv->lock); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 431 | |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 432 | dma_unmap_single(dev->dev.parent, physaddr, rskb->len, |
| 433 | DMA_FROM_DEVICE); |
| 434 | length = status & BCOM_FEC_RX_BD_LEN_MASK; |
| 435 | skb_put(rskb, length - 4); /* length without CRC32 */ |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 436 | rskb->protocol = eth_type_trans(rskb, dev); |
| 437 | netif_rx(rskb); |
| 438 | |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 439 | spin_lock(&priv->lock); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 440 | } |
| 441 | |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 442 | spin_unlock(&priv->lock); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 443 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 444 | return IRQ_HANDLED; |
| 445 | } |
| 446 | |
| 447 | static irqreturn_t mpc52xx_fec_interrupt(int irq, void *dev_id) |
| 448 | { |
| 449 | struct net_device *dev = dev_id; |
| 450 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 451 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 452 | u32 ievent; |
| 453 | |
| 454 | ievent = in_be32(&fec->ievent); |
| 455 | |
| 456 | ievent &= ~FEC_IEVENT_MII; /* mii is handled separately */ |
| 457 | if (!ievent) |
| 458 | return IRQ_NONE; |
| 459 | |
| 460 | out_be32(&fec->ievent, ievent); /* clear pending events */ |
| 461 | |
Sascha Hauer | 8f3ba2d | 2008-04-16 01:44:39 +1000 | [diff] [blame] | 462 | /* on fifo error, soft-reset fec */ |
| 463 | if (ievent & (FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) { |
| 464 | |
| 465 | if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR)) |
| 466 | dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n"); |
| 467 | if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR)) |
| 468 | dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n"); |
| 469 | |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 470 | spin_lock(&priv->lock); |
Sascha Hauer | 8f3ba2d | 2008-04-16 01:44:39 +1000 | [diff] [blame] | 471 | mpc52xx_fec_reset(dev); |
Eric Dumazet | 9d1e5e4 | 2010-11-03 05:56:38 +0000 | [diff] [blame] | 472 | spin_unlock(&priv->lock); |
Sascha Hauer | 8f3ba2d | 2008-04-16 01:44:39 +1000 | [diff] [blame] | 473 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 474 | return IRQ_HANDLED; |
| 475 | } |
| 476 | |
Sascha Hauer | 8f3ba2d | 2008-04-16 01:44:39 +1000 | [diff] [blame] | 477 | if (ievent & ~FEC_IEVENT_TFINT) |
| 478 | dev_dbg(&dev->dev, "ievent: %08x\n", ievent); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 479 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 480 | return IRQ_HANDLED; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * Get the current statistics. |
| 485 | * This may be called with the card open or closed. |
| 486 | */ |
| 487 | static struct net_device_stats *mpc52xx_fec_get_stats(struct net_device *dev) |
| 488 | { |
| 489 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 490 | struct net_device_stats *stats = &dev->stats; |
| 491 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 492 | |
| 493 | stats->rx_bytes = in_be32(&fec->rmon_r_octets); |
| 494 | stats->rx_packets = in_be32(&fec->rmon_r_packets); |
| 495 | stats->rx_errors = in_be32(&fec->rmon_r_crc_align) + |
| 496 | in_be32(&fec->rmon_r_undersize) + |
| 497 | in_be32(&fec->rmon_r_oversize) + |
| 498 | in_be32(&fec->rmon_r_frag) + |
| 499 | in_be32(&fec->rmon_r_jab); |
| 500 | |
| 501 | stats->tx_bytes = in_be32(&fec->rmon_t_octets); |
| 502 | stats->tx_packets = in_be32(&fec->rmon_t_packets); |
| 503 | stats->tx_errors = in_be32(&fec->rmon_t_crc_align) + |
| 504 | in_be32(&fec->rmon_t_undersize) + |
| 505 | in_be32(&fec->rmon_t_oversize) + |
| 506 | in_be32(&fec->rmon_t_frag) + |
| 507 | in_be32(&fec->rmon_t_jab); |
| 508 | |
| 509 | stats->multicast = in_be32(&fec->rmon_r_mc_pkt); |
| 510 | stats->collisions = in_be32(&fec->rmon_t_col); |
| 511 | |
| 512 | /* detailed rx_errors: */ |
| 513 | stats->rx_length_errors = in_be32(&fec->rmon_r_undersize) |
| 514 | + in_be32(&fec->rmon_r_oversize) |
| 515 | + in_be32(&fec->rmon_r_frag) |
| 516 | + in_be32(&fec->rmon_r_jab); |
| 517 | stats->rx_over_errors = in_be32(&fec->r_macerr); |
| 518 | stats->rx_crc_errors = in_be32(&fec->ieee_r_crc); |
| 519 | stats->rx_frame_errors = in_be32(&fec->ieee_r_align); |
| 520 | stats->rx_fifo_errors = in_be32(&fec->rmon_r_drop); |
| 521 | stats->rx_missed_errors = in_be32(&fec->rmon_r_drop); |
| 522 | |
| 523 | /* detailed tx_errors: */ |
| 524 | stats->tx_aborted_errors = 0; |
| 525 | stats->tx_carrier_errors = in_be32(&fec->ieee_t_cserr); |
| 526 | stats->tx_fifo_errors = in_be32(&fec->rmon_t_drop); |
| 527 | stats->tx_heartbeat_errors = in_be32(&fec->ieee_t_sqe); |
| 528 | stats->tx_window_errors = in_be32(&fec->ieee_t_lcol); |
| 529 | |
| 530 | return stats; |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * Read MIB counters in order to reset them, |
| 535 | * then zero all the stats fields in memory |
| 536 | */ |
| 537 | static void mpc52xx_fec_reset_stats(struct net_device *dev) |
| 538 | { |
| 539 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 540 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 541 | |
| 542 | out_be32(&fec->mib_control, FEC_MIB_DISABLE); |
Al Viro | cc154ac | 2007-12-22 18:56:53 +0000 | [diff] [blame] | 543 | memset_io(&fec->rmon_t_drop, 0, |
| 544 | offsetof(struct mpc52xx_fec, reserved10) - |
| 545 | offsetof(struct mpc52xx_fec, rmon_t_drop)); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 546 | out_be32(&fec->mib_control, 0); |
| 547 | |
| 548 | memset(&dev->stats, 0, sizeof(dev->stats)); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Set or clear the multicast filter for this adaptor. |
| 553 | */ |
| 554 | static void mpc52xx_fec_set_multicast_list(struct net_device *dev) |
| 555 | { |
| 556 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 557 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 558 | u32 rx_control; |
| 559 | |
| 560 | rx_control = in_be32(&fec->r_cntrl); |
| 561 | |
| 562 | if (dev->flags & IFF_PROMISC) { |
| 563 | rx_control |= FEC_RCNTRL_PROM; |
| 564 | out_be32(&fec->r_cntrl, rx_control); |
| 565 | } else { |
| 566 | rx_control &= ~FEC_RCNTRL_PROM; |
| 567 | out_be32(&fec->r_cntrl, rx_control); |
| 568 | |
| 569 | if (dev->flags & IFF_ALLMULTI) { |
| 570 | out_be32(&fec->gaddr1, 0xffffffff); |
| 571 | out_be32(&fec->gaddr2, 0xffffffff); |
| 572 | } else { |
| 573 | u32 crc; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 574 | struct netdev_hw_addr *ha; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 575 | u32 gaddr1 = 0x00000000; |
| 576 | u32 gaddr2 = 0x00000000; |
| 577 | |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 578 | netdev_for_each_mc_addr(ha, dev) { |
| 579 | crc = ether_crc_le(6, ha->addr) >> 26; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 580 | if (crc >= 32) |
| 581 | gaddr1 |= 1 << (crc-32); |
| 582 | else |
| 583 | gaddr2 |= 1 << crc; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 584 | } |
| 585 | out_be32(&fec->gaddr1, gaddr1); |
| 586 | out_be32(&fec->gaddr2, gaddr2); |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * mpc52xx_fec_hw_init |
| 593 | * @dev: network device |
| 594 | * |
| 595 | * Setup various hardware setting, only needed once on start |
| 596 | */ |
| 597 | static void mpc52xx_fec_hw_init(struct net_device *dev) |
| 598 | { |
| 599 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 600 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 601 | int i; |
| 602 | |
| 603 | /* Whack a reset. We should wait for this. */ |
| 604 | out_be32(&fec->ecntrl, FEC_ECNTRL_RESET); |
| 605 | for (i = 0; i < FEC_RESET_DELAY; ++i) { |
| 606 | if ((in_be32(&fec->ecntrl) & FEC_ECNTRL_RESET) == 0) |
| 607 | break; |
| 608 | udelay(1); |
| 609 | } |
| 610 | if (i == FEC_RESET_DELAY) |
| 611 | dev_err(&dev->dev, "FEC Reset timeout!\n"); |
| 612 | |
| 613 | /* set pause to 0x20 frames */ |
| 614 | out_be32(&fec->op_pause, FEC_OP_PAUSE_OPCODE | 0x20); |
| 615 | |
| 616 | /* high service request will be deasserted when there's < 7 bytes in fifo |
| 617 | * low service request will be deasserted when there's < 4*7 bytes in fifo |
| 618 | */ |
| 619 | out_be32(&fec->rfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7); |
| 620 | out_be32(&fec->tfifo_cntrl, FEC_FIFO_CNTRL_FRAME | FEC_FIFO_CNTRL_LTG_7); |
| 621 | |
| 622 | /* alarm when <= x bytes in FIFO */ |
| 623 | out_be32(&fec->rfifo_alarm, 0x0000030c); |
| 624 | out_be32(&fec->tfifo_alarm, 0x00000100); |
| 625 | |
| 626 | /* begin transmittion when 256 bytes are in FIFO (or EOF or FIFO full) */ |
| 627 | out_be32(&fec->x_wmrk, FEC_FIFO_WMRK_256B); |
| 628 | |
| 629 | /* enable crc generation */ |
| 630 | out_be32(&fec->xmit_fsm, FEC_XMIT_FSM_APPEND_CRC | FEC_XMIT_FSM_ENABLE_CRC); |
| 631 | out_be32(&fec->iaddr1, 0x00000000); /* No individual filter */ |
| 632 | out_be32(&fec->iaddr2, 0x00000000); /* No individual filter */ |
| 633 | |
| 634 | /* set phy speed. |
| 635 | * this can't be done in phy driver, since it needs to be called |
| 636 | * before fec stuff (even on resume) */ |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 637 | out_be32(&fec->mii_speed, priv->mdio_speed); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
| 641 | * mpc52xx_fec_start |
| 642 | * @dev: network device |
| 643 | * |
| 644 | * This function is called to start or restart the FEC during a link |
| 645 | * change. This happens on fifo errors or when switching between half |
| 646 | * and full duplex. |
| 647 | */ |
| 648 | static void mpc52xx_fec_start(struct net_device *dev) |
| 649 | { |
| 650 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 651 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 652 | u32 rcntrl; |
| 653 | u32 tcntrl; |
| 654 | u32 tmp; |
| 655 | |
| 656 | /* clear sticky error bits */ |
| 657 | tmp = FEC_FIFO_STATUS_ERR | FEC_FIFO_STATUS_UF | FEC_FIFO_STATUS_OF; |
| 658 | out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status) & tmp); |
| 659 | out_be32(&fec->tfifo_status, in_be32(&fec->tfifo_status) & tmp); |
| 660 | |
| 661 | /* FIFOs will reset on mpc52xx_fec_enable */ |
| 662 | out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_ENABLE_IS_RESET); |
| 663 | |
| 664 | /* Set station address. */ |
| 665 | mpc52xx_fec_set_paddr(dev, dev->dev_addr); |
| 666 | |
| 667 | mpc52xx_fec_set_multicast_list(dev); |
| 668 | |
| 669 | /* set max frame len, enable flow control, select mii mode */ |
| 670 | rcntrl = FEC_RX_BUFFER_SIZE << 16; /* max frame length */ |
| 671 | rcntrl |= FEC_RCNTRL_FCE; |
| 672 | |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 673 | if (!priv->seven_wire_mode) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 674 | rcntrl |= FEC_RCNTRL_MII_MODE; |
| 675 | |
| 676 | if (priv->duplex == DUPLEX_FULL) |
| 677 | tcntrl = FEC_TCNTRL_FDEN; /* FD enable */ |
| 678 | else { |
| 679 | rcntrl |= FEC_RCNTRL_DRT; /* disable Rx on Tx (HD) */ |
| 680 | tcntrl = 0; |
| 681 | } |
| 682 | out_be32(&fec->r_cntrl, rcntrl); |
| 683 | out_be32(&fec->x_cntrl, tcntrl); |
| 684 | |
| 685 | /* Clear any outstanding interrupt. */ |
| 686 | out_be32(&fec->ievent, 0xffffffff); |
| 687 | |
| 688 | /* Enable interrupts we wish to service. */ |
| 689 | out_be32(&fec->imask, FEC_IMASK_ENABLE); |
| 690 | |
| 691 | /* And last, enable the transmit and receive processing. */ |
| 692 | out_be32(&fec->ecntrl, FEC_ECNTRL_ETHER_EN); |
| 693 | out_be32(&fec->r_des_active, 0x01000000); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * mpc52xx_fec_stop |
| 698 | * @dev: network device |
| 699 | * |
| 700 | * stop all activity on fec and empty dma buffers |
| 701 | */ |
| 702 | static void mpc52xx_fec_stop(struct net_device *dev) |
| 703 | { |
| 704 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 705 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 706 | unsigned long timeout; |
| 707 | |
| 708 | /* disable all interrupts */ |
| 709 | out_be32(&fec->imask, 0); |
| 710 | |
| 711 | /* Disable the rx task. */ |
| 712 | bcom_disable(priv->rx_dmatsk); |
| 713 | |
| 714 | /* Wait for tx queue to drain, but only if we're in process context */ |
| 715 | if (!in_interrupt()) { |
| 716 | timeout = jiffies + msecs_to_jiffies(2000); |
| 717 | while (time_before(jiffies, timeout) && |
| 718 | !bcom_queue_empty(priv->tx_dmatsk)) |
| 719 | msleep(100); |
| 720 | |
| 721 | if (time_after_eq(jiffies, timeout)) |
| 722 | dev_err(&dev->dev, "queues didn't drain\n"); |
| 723 | #if 1 |
| 724 | if (time_after_eq(jiffies, timeout)) { |
| 725 | dev_err(&dev->dev, " tx: index: %i, outdex: %i\n", |
| 726 | priv->tx_dmatsk->index, |
| 727 | priv->tx_dmatsk->outdex); |
| 728 | dev_err(&dev->dev, " rx: index: %i, outdex: %i\n", |
| 729 | priv->rx_dmatsk->index, |
| 730 | priv->rx_dmatsk->outdex); |
| 731 | } |
| 732 | #endif |
| 733 | } |
| 734 | |
| 735 | bcom_disable(priv->tx_dmatsk); |
| 736 | |
| 737 | /* Stop FEC */ |
| 738 | out_be32(&fec->ecntrl, in_be32(&fec->ecntrl) & ~FEC_ECNTRL_ETHER_EN); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* reset fec and bestcomm tasks */ |
| 742 | static void mpc52xx_fec_reset(struct net_device *dev) |
| 743 | { |
| 744 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 745 | struct mpc52xx_fec __iomem *fec = priv->fec; |
| 746 | |
| 747 | mpc52xx_fec_stop(dev); |
| 748 | |
| 749 | out_be32(&fec->rfifo_status, in_be32(&fec->rfifo_status)); |
| 750 | out_be32(&fec->reset_cntrl, FEC_RESET_CNTRL_RESET_FIFO); |
| 751 | |
| 752 | mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk); |
| 753 | |
| 754 | mpc52xx_fec_hw_init(dev); |
| 755 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 756 | bcom_fec_rx_reset(priv->rx_dmatsk); |
| 757 | bcom_fec_tx_reset(priv->tx_dmatsk); |
| 758 | |
| 759 | mpc52xx_fec_alloc_rx_buffers(dev, priv->rx_dmatsk); |
| 760 | |
| 761 | bcom_enable(priv->rx_dmatsk); |
| 762 | bcom_enable(priv->tx_dmatsk); |
| 763 | |
| 764 | mpc52xx_fec_start(dev); |
Asier Llano | 1e4e076 | 2009-12-08 20:29:10 -0800 | [diff] [blame] | 765 | |
| 766 | netif_wake_queue(dev); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | |
| 770 | /* ethtool interface */ |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 771 | |
| 772 | static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 773 | { |
| 774 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
Grant Likely | 9404c82 | 2009-03-31 20:17:03 +0000 | [diff] [blame] | 775 | |
| 776 | if (!priv->phydev) |
| 777 | return -ENODEV; |
| 778 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 779 | return phy_ethtool_gset(priv->phydev, cmd); |
| 780 | } |
| 781 | |
| 782 | static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 783 | { |
| 784 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
Grant Likely | 9404c82 | 2009-03-31 20:17:03 +0000 | [diff] [blame] | 785 | |
| 786 | if (!priv->phydev) |
| 787 | return -ENODEV; |
| 788 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 789 | return phy_ethtool_sset(priv->phydev, cmd); |
| 790 | } |
| 791 | |
| 792 | static u32 mpc52xx_fec_get_msglevel(struct net_device *dev) |
| 793 | { |
| 794 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 795 | return priv->msg_enable; |
| 796 | } |
| 797 | |
| 798 | static void mpc52xx_fec_set_msglevel(struct net_device *dev, u32 level) |
| 799 | { |
| 800 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 801 | priv->msg_enable = level; |
| 802 | } |
| 803 | |
| 804 | static const struct ethtool_ops mpc52xx_fec_ethtool_ops = { |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 805 | .get_settings = mpc52xx_fec_get_settings, |
| 806 | .set_settings = mpc52xx_fec_set_settings, |
| 807 | .get_link = ethtool_op_get_link, |
| 808 | .get_msglevel = mpc52xx_fec_get_msglevel, |
| 809 | .set_msglevel = mpc52xx_fec_set_msglevel, |
| 810 | }; |
| 811 | |
| 812 | |
| 813 | static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 814 | { |
| 815 | struct mpc52xx_fec_priv *priv = netdev_priv(dev); |
| 816 | |
Grant Likely | 9404c82 | 2009-03-31 20:17:03 +0000 | [diff] [blame] | 817 | if (!priv->phydev) |
| 818 | return -ENOTSUPP; |
| 819 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 820 | return phy_mii_ioctl(priv->phydev, rq, cmd); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 821 | } |
| 822 | |
Henk Stegeman | d360009 | 2009-03-31 20:16:57 +0000 | [diff] [blame] | 823 | static const struct net_device_ops mpc52xx_fec_netdev_ops = { |
| 824 | .ndo_open = mpc52xx_fec_open, |
| 825 | .ndo_stop = mpc52xx_fec_close, |
| 826 | .ndo_start_xmit = mpc52xx_fec_start_xmit, |
| 827 | .ndo_set_multicast_list = mpc52xx_fec_set_multicast_list, |
| 828 | .ndo_set_mac_address = mpc52xx_fec_set_mac_address, |
| 829 | .ndo_validate_addr = eth_validate_addr, |
| 830 | .ndo_do_ioctl = mpc52xx_fec_ioctl, |
| 831 | .ndo_change_mtu = eth_change_mtu, |
| 832 | .ndo_tx_timeout = mpc52xx_fec_tx_timeout, |
| 833 | .ndo_get_stats = mpc52xx_fec_get_stats, |
| 834 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 835 | .ndo_poll_controller = mpc52xx_fec_poll_controller, |
| 836 | #endif |
| 837 | }; |
| 838 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 839 | /* ======================================================================== */ |
| 840 | /* OF Driver */ |
| 841 | /* ======================================================================== */ |
| 842 | |
| 843 | static int __devinit |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 844 | mpc52xx_fec_probe(struct platform_device *op, const struct of_device_id *match) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 845 | { |
| 846 | int rv; |
| 847 | struct net_device *ndev; |
| 848 | struct mpc52xx_fec_priv *priv = NULL; |
| 849 | struct resource mem; |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 850 | const u32 *prop; |
| 851 | int prop_size; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 852 | |
| 853 | phys_addr_t rx_fifo; |
| 854 | phys_addr_t tx_fifo; |
| 855 | |
| 856 | /* Get the ether ndev & it's private zone */ |
| 857 | ndev = alloc_etherdev(sizeof(struct mpc52xx_fec_priv)); |
| 858 | if (!ndev) |
| 859 | return -ENOMEM; |
| 860 | |
| 861 | priv = netdev_priv(ndev); |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 862 | priv->ndev = ndev; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 863 | |
| 864 | /* Reserve FEC control zone */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 865 | rv = of_address_to_resource(op->dev.of_node, 0, &mem); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 866 | if (rv) { |
| 867 | printk(KERN_ERR DRIVER_NAME ": " |
| 868 | "Error while parsing device node resource\n" ); |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 869 | goto err_netdev; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 870 | } |
Grant Likely | 48d5845 | 2007-11-01 08:22:35 -0600 | [diff] [blame] | 871 | if ((mem.end - mem.start + 1) < sizeof(struct mpc52xx_fec)) { |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 872 | printk(KERN_ERR DRIVER_NAME |
Grant Likely | 48d5845 | 2007-11-01 08:22:35 -0600 | [diff] [blame] | 873 | " - invalid resource size (%lx < %x), check mpc52xx_devices.c\n", |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 874 | (unsigned long)(mem.end - mem.start + 1), sizeof(struct mpc52xx_fec)); |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 875 | rv = -EINVAL; |
| 876 | goto err_netdev; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 877 | } |
| 878 | |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 879 | if (!request_mem_region(mem.start, sizeof(struct mpc52xx_fec), |
| 880 | DRIVER_NAME)) { |
| 881 | rv = -EBUSY; |
| 882 | goto err_netdev; |
| 883 | } |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 884 | |
| 885 | /* Init ether ndev with what we have */ |
Henk Stegeman | d360009 | 2009-03-31 20:16:57 +0000 | [diff] [blame] | 886 | ndev->netdev_ops = &mpc52xx_fec_netdev_ops; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 887 | ndev->ethtool_ops = &mpc52xx_fec_ethtool_ops; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 888 | ndev->watchdog_timeo = FEC_WATCHDOG_TIMEOUT; |
| 889 | ndev->base_addr = mem.start; |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 890 | SET_NETDEV_DEV(ndev, &op->dev); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 891 | |
| 892 | spin_lock_init(&priv->lock); |
| 893 | |
| 894 | /* ioremap the zones */ |
| 895 | priv->fec = ioremap(mem.start, sizeof(struct mpc52xx_fec)); |
| 896 | |
| 897 | if (!priv->fec) { |
| 898 | rv = -ENOMEM; |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 899 | goto err_mem_region; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* Bestcomm init */ |
| 903 | rx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, rfifo_data); |
| 904 | tx_fifo = ndev->base_addr + offsetof(struct mpc52xx_fec, tfifo_data); |
| 905 | |
| 906 | priv->rx_dmatsk = bcom_fec_rx_init(FEC_RX_NUM_BD, rx_fifo, FEC_RX_BUFFER_SIZE); |
| 907 | priv->tx_dmatsk = bcom_fec_tx_init(FEC_TX_NUM_BD, tx_fifo); |
| 908 | |
| 909 | if (!priv->rx_dmatsk || !priv->tx_dmatsk) { |
| 910 | printk(KERN_ERR DRIVER_NAME ": Can not init SDMA tasks\n" ); |
| 911 | rv = -ENOMEM; |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 912 | goto err_rx_tx_dmatsk; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* Get the IRQ we need one by one */ |
| 916 | /* Control */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 917 | ndev->irq = irq_of_parse_and_map(op->dev.of_node, 0); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 918 | |
| 919 | /* RX */ |
| 920 | priv->r_irq = bcom_get_task_irq(priv->rx_dmatsk); |
| 921 | |
| 922 | /* TX */ |
| 923 | priv->t_irq = bcom_get_task_irq(priv->tx_dmatsk); |
| 924 | |
| 925 | /* MAC address init */ |
| 926 | if (!is_zero_ether_addr(mpc52xx_fec_mac_addr)) |
| 927 | memcpy(ndev->dev_addr, mpc52xx_fec_mac_addr, 6); |
| 928 | else |
| 929 | mpc52xx_fec_get_paddr(ndev, ndev->dev_addr); |
| 930 | |
| 931 | priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 932 | |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 933 | /* |
| 934 | * Link mode configuration |
| 935 | */ |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 936 | |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 937 | /* Start with safe defaults for link connection */ |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 938 | priv->speed = 100; |
| 939 | priv->duplex = DUPLEX_HALF; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 940 | priv->mdio_speed = ((mpc5xxx_get_bus_frequency(op->dev.of_node) >> 20) / 5) << 1; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 941 | |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 942 | /* The current speed preconfigures the speed of the MII link */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 943 | prop = of_get_property(op->dev.of_node, "current-speed", &prop_size); |
Grant Likely | 80791be | 2008-05-01 11:05:58 -0600 | [diff] [blame] | 944 | if (prop && (prop_size >= sizeof(u32) * 2)) { |
| 945 | priv->speed = prop[0]; |
| 946 | priv->duplex = prop[1] ? DUPLEX_FULL : DUPLEX_HALF; |
| 947 | } |
| 948 | |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 949 | /* If there is a phy handle, then get the PHY node */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 950 | priv->phy_node = of_parse_phandle(op->dev.of_node, "phy-handle", 0); |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 951 | |
| 952 | /* the 7-wire property means don't use MII mode */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 953 | if (of_find_property(op->dev.of_node, "fsl,7-wire-mode", NULL)) { |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 954 | priv->seven_wire_mode = 1; |
| 955 | dev_info(&ndev->dev, "using 7-wire PHY mode\n"); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | /* Hardware init */ |
| 959 | mpc52xx_fec_hw_init(ndev); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 960 | mpc52xx_fec_reset_stats(ndev); |
| 961 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 962 | rv = register_netdev(ndev); |
| 963 | if (rv < 0) |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 964 | goto err_node; |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 965 | |
| 966 | /* We're done ! */ |
| 967 | dev_set_drvdata(&op->dev, ndev); |
| 968 | |
| 969 | return 0; |
| 970 | |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 971 | err_node: |
| 972 | of_node_put(priv->phy_node); |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 973 | irq_dispose_mapping(ndev->irq); |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 974 | err_rx_tx_dmatsk: |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 975 | if (priv->rx_dmatsk) |
| 976 | bcom_fec_rx_release(priv->rx_dmatsk); |
| 977 | if (priv->tx_dmatsk) |
| 978 | bcom_fec_tx_release(priv->tx_dmatsk); |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 979 | iounmap(priv->fec); |
| 980 | err_mem_region: |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 981 | release_mem_region(mem.start, sizeof(struct mpc52xx_fec)); |
Kulikov Vasiliy | fabc51a | 2010-07-08 23:44:26 -0700 | [diff] [blame] | 982 | err_netdev: |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 983 | free_netdev(ndev); |
| 984 | |
| 985 | return rv; |
| 986 | } |
| 987 | |
| 988 | static int |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 989 | mpc52xx_fec_remove(struct platform_device *op) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 990 | { |
| 991 | struct net_device *ndev; |
| 992 | struct mpc52xx_fec_priv *priv; |
| 993 | |
| 994 | ndev = dev_get_drvdata(&op->dev); |
| 995 | priv = netdev_priv(ndev); |
| 996 | |
| 997 | unregister_netdev(ndev); |
| 998 | |
Grant Likely | ca816d9 | 2009-04-25 12:53:02 +0000 | [diff] [blame] | 999 | if (priv->phy_node) |
| 1000 | of_node_put(priv->phy_node); |
| 1001 | priv->phy_node = NULL; |
| 1002 | |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1003 | irq_dispose_mapping(ndev->irq); |
| 1004 | |
| 1005 | bcom_fec_rx_release(priv->rx_dmatsk); |
| 1006 | bcom_fec_tx_release(priv->tx_dmatsk); |
| 1007 | |
| 1008 | iounmap(priv->fec); |
| 1009 | |
| 1010 | release_mem_region(ndev->base_addr, sizeof(struct mpc52xx_fec)); |
| 1011 | |
| 1012 | free_netdev(ndev); |
| 1013 | |
| 1014 | dev_set_drvdata(&op->dev, NULL); |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
| 1018 | #ifdef CONFIG_PM |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1019 | static int mpc52xx_fec_of_suspend(struct platform_device *op, pm_message_t state) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1020 | { |
| 1021 | struct net_device *dev = dev_get_drvdata(&op->dev); |
| 1022 | |
| 1023 | if (netif_running(dev)) |
| 1024 | mpc52xx_fec_close(dev); |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1029 | static int mpc52xx_fec_of_resume(struct platform_device *op) |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1030 | { |
| 1031 | struct net_device *dev = dev_get_drvdata(&op->dev); |
| 1032 | |
| 1033 | mpc52xx_fec_hw_init(dev); |
| 1034 | mpc52xx_fec_reset_stats(dev); |
| 1035 | |
| 1036 | if (netif_running(dev)) |
| 1037 | mpc52xx_fec_open(dev); |
| 1038 | |
| 1039 | return 0; |
| 1040 | } |
| 1041 | #endif |
| 1042 | |
| 1043 | static struct of_device_id mpc52xx_fec_match[] = { |
Grant Likely | 3b5ebf8 | 2009-02-03 12:30:25 -0700 | [diff] [blame] | 1044 | { .compatible = "fsl,mpc5200b-fec", }, |
| 1045 | { .compatible = "fsl,mpc5200-fec", }, |
| 1046 | { .compatible = "mpc5200-fec", }, |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1047 | { } |
| 1048 | }; |
| 1049 | |
| 1050 | MODULE_DEVICE_TABLE(of, mpc52xx_fec_match); |
| 1051 | |
| 1052 | static struct of_platform_driver mpc52xx_fec_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1053 | .driver = { |
| 1054 | .name = DRIVER_NAME, |
| 1055 | .owner = THIS_MODULE, |
| 1056 | .of_match_table = mpc52xx_fec_match, |
| 1057 | }, |
Domen Puncer | 5d031e9 | 2007-10-26 18:07:49 +0200 | [diff] [blame] | 1058 | .probe = mpc52xx_fec_probe, |
| 1059 | .remove = mpc52xx_fec_remove, |
| 1060 | #ifdef CONFIG_PM |
| 1061 | .suspend = mpc52xx_fec_of_suspend, |
| 1062 | .resume = mpc52xx_fec_of_resume, |
| 1063 | #endif |
| 1064 | }; |
| 1065 | |
| 1066 | |
| 1067 | /* ======================================================================== */ |
| 1068 | /* Module */ |
| 1069 | /* ======================================================================== */ |
| 1070 | |
| 1071 | static int __init |
| 1072 | mpc52xx_fec_init(void) |
| 1073 | { |
| 1074 | #ifdef CONFIG_FEC_MPC52xx_MDIO |
| 1075 | int ret; |
| 1076 | ret = of_register_platform_driver(&mpc52xx_fec_mdio_driver); |
| 1077 | if (ret) { |
| 1078 | printk(KERN_ERR DRIVER_NAME ": failed to register mdio driver\n"); |
| 1079 | return ret; |
| 1080 | } |
| 1081 | #endif |
| 1082 | return of_register_platform_driver(&mpc52xx_fec_driver); |
| 1083 | } |
| 1084 | |
| 1085 | static void __exit |
| 1086 | mpc52xx_fec_exit(void) |
| 1087 | { |
| 1088 | of_unregister_platform_driver(&mpc52xx_fec_driver); |
| 1089 | #ifdef CONFIG_FEC_MPC52xx_MDIO |
| 1090 | of_unregister_platform_driver(&mpc52xx_fec_mdio_driver); |
| 1091 | #endif |
| 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | module_init(mpc52xx_fec_init); |
| 1096 | module_exit(mpc52xx_fec_exit); |
| 1097 | |
| 1098 | MODULE_LICENSE("GPL"); |
| 1099 | MODULE_AUTHOR("Dale Farnsworth"); |
| 1100 | MODULE_DESCRIPTION("Ethernet driver for the Freescale MPC52xx FEC"); |