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