Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Xilinx TEMAC Ethernet device |
| 3 | * |
| 4 | * Copyright (c) 2008 Nissin Systems Co., Ltd., Yoshio Kashiwagi |
| 5 | * Copyright (c) 2005-2008 DLA Systems, David H. Lynch Jr. <dhlii@dlasys.net> |
| 6 | * Copyright (c) 2008-2009 Secret Lab Technologies Ltd. |
| 7 | * |
| 8 | * This is a driver for the Xilinx ll_temac ipcore which is often used |
| 9 | * in the Virtex and Spartan series of chips. |
| 10 | * |
| 11 | * Notes: |
| 12 | * - The ll_temac hardware uses indirect access for many of the TEMAC |
| 13 | * registers, include the MDIO bus. However, indirect access to MDIO |
| 14 | * registers take considerably more clock cycles than to TEMAC registers. |
| 15 | * MDIO accesses are long, so threads doing them should probably sleep |
| 16 | * rather than busywait. However, since only one indirect access can be |
| 17 | * in progress at any given time, that means that *all* indirect accesses |
| 18 | * could end up sleeping (to wait for an MDIO access to complete). |
| 19 | * Fortunately none of the indirect accesses are on the 'hot' path for tx |
| 20 | * or rx, so this should be okay. |
| 21 | * |
| 22 | * TODO: |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 23 | * - Factor out locallink DMA code into separate driver |
| 24 | * - Fix multicast assignment. |
| 25 | * - Fix support for hardware checksumming. |
| 26 | * - Testing. Lots and lots of testing. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/mii.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/mutex.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/of.h> |
| 38 | #include <linux/of_device.h> |
Rob Herring | 5c9f303 | 2013-09-07 14:05:10 -0500 | [diff] [blame] | 39 | #include <linux/of_irq.h> |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 40 | #include <linux/of_mdio.h> |
| 41 | #include <linux/of_platform.h> |
Michal Simek | 9f1a1fc | 2010-09-01 08:55:23 -0600 | [diff] [blame] | 42 | #include <linux/of_address.h> |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 43 | #include <linux/skbuff.h> |
| 44 | #include <linux/spinlock.h> |
| 45 | #include <linux/tcp.h> /* needed for sizeof(tcphdr) */ |
| 46 | #include <linux/udp.h> /* needed for sizeof(udphdr) */ |
| 47 | #include <linux/phy.h> |
| 48 | #include <linux/in.h> |
| 49 | #include <linux/io.h> |
| 50 | #include <linux/ip.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 51 | #include <linux/slab.h> |
Stephen Rothwell | ffbc03b | 2011-06-08 15:49:33 +1000 | [diff] [blame] | 52 | #include <linux/interrupt.h> |
Stephen Rothwell | 84cac39 | 2011-06-29 02:55:59 -0700 | [diff] [blame] | 53 | #include <linux/dma-mapping.h> |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 54 | |
| 55 | #include "ll_temac.h" |
| 56 | |
| 57 | #define TX_BD_NUM 64 |
| 58 | #define RX_BD_NUM 128 |
| 59 | |
| 60 | /* --------------------------------------------------------------------- |
| 61 | * Low level register access functions |
| 62 | */ |
| 63 | |
| 64 | u32 temac_ior(struct temac_local *lp, int offset) |
| 65 | { |
| 66 | return in_be32((u32 *)(lp->regs + offset)); |
| 67 | } |
| 68 | |
| 69 | void temac_iow(struct temac_local *lp, int offset, u32 value) |
| 70 | { |
| 71 | out_be32((u32 *) (lp->regs + offset), value); |
| 72 | } |
| 73 | |
| 74 | int temac_indirect_busywait(struct temac_local *lp) |
| 75 | { |
| 76 | long end = jiffies + 2; |
| 77 | |
| 78 | while (!(temac_ior(lp, XTE_RDY0_OFFSET) & XTE_RDY0_HARD_ACS_RDY_MASK)) { |
| 79 | if (end - jiffies <= 0) { |
| 80 | WARN_ON(1); |
| 81 | return -ETIMEDOUT; |
| 82 | } |
| 83 | msleep(1); |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * temac_indirect_in32 |
| 90 | * |
| 91 | * lp->indirect_mutex must be held when calling this function |
| 92 | */ |
| 93 | u32 temac_indirect_in32(struct temac_local *lp, int reg) |
| 94 | { |
| 95 | u32 val; |
| 96 | |
| 97 | if (temac_indirect_busywait(lp)) |
| 98 | return -ETIMEDOUT; |
| 99 | temac_iow(lp, XTE_CTL0_OFFSET, reg); |
| 100 | if (temac_indirect_busywait(lp)) |
| 101 | return -ETIMEDOUT; |
| 102 | val = temac_ior(lp, XTE_LSW0_OFFSET); |
| 103 | |
| 104 | return val; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * temac_indirect_out32 |
| 109 | * |
| 110 | * lp->indirect_mutex must be held when calling this function |
| 111 | */ |
| 112 | void temac_indirect_out32(struct temac_local *lp, int reg, u32 value) |
| 113 | { |
| 114 | if (temac_indirect_busywait(lp)) |
| 115 | return; |
| 116 | temac_iow(lp, XTE_LSW0_OFFSET, value); |
| 117 | temac_iow(lp, XTE_CTL0_OFFSET, CNTLREG_WRITE_ENABLE_MASK | reg); |
Ricardo Ribalda | f79d7e6 | 2011-11-07 23:39:57 +0000 | [diff] [blame] | 118 | temac_indirect_busywait(lp); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 119 | } |
| 120 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 121 | /** |
| 122 | * temac_dma_in32 - Memory mapped DMA read, this function expects a |
| 123 | * register input that is based on DCR word addresses which |
| 124 | * are then converted to memory mapped byte addresses |
| 125 | */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 126 | static u32 temac_dma_in32(struct temac_local *lp, int reg) |
| 127 | { |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 128 | return in_be32((u32 *)(lp->sdma_regs + (reg << 2))); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * temac_dma_out32 - Memory mapped DMA read, this function expects a |
| 133 | * register input that is based on DCR word addresses which |
| 134 | * are then converted to memory mapped byte addresses |
| 135 | */ |
| 136 | static void temac_dma_out32(struct temac_local *lp, int reg, u32 value) |
| 137 | { |
| 138 | out_be32((u32 *)(lp->sdma_regs + (reg << 2)), value); |
| 139 | } |
| 140 | |
| 141 | /* DMA register access functions can be DCR based or memory mapped. |
| 142 | * The PowerPC 440 is DCR based, the PowerPC 405 and MicroBlaze are both |
| 143 | * memory mapped. |
| 144 | */ |
| 145 | #ifdef CONFIG_PPC_DCR |
| 146 | |
| 147 | /** |
| 148 | * temac_dma_dcr_in32 - DCR based DMA read |
| 149 | */ |
| 150 | static u32 temac_dma_dcr_in(struct temac_local *lp, int reg) |
| 151 | { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 152 | return dcr_read(lp->sdma_dcrs, reg); |
| 153 | } |
| 154 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 155 | /** |
| 156 | * temac_dma_dcr_out32 - DCR based DMA write |
| 157 | */ |
| 158 | static void temac_dma_dcr_out(struct temac_local *lp, int reg, u32 value) |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 159 | { |
| 160 | dcr_write(lp->sdma_dcrs, reg, value); |
| 161 | } |
| 162 | |
| 163 | /** |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 164 | * temac_dcr_setup - If the DMA is DCR based, then setup the address and |
| 165 | * I/O functions |
| 166 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 167 | static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op, |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 168 | struct device_node *np) |
| 169 | { |
| 170 | unsigned int dcrs; |
| 171 | |
| 172 | /* setup the dcr address mapping if it's in the device tree */ |
| 173 | |
| 174 | dcrs = dcr_resource_start(np, 0); |
| 175 | if (dcrs != 0) { |
| 176 | lp->sdma_dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0)); |
| 177 | lp->dma_in = temac_dma_dcr_in; |
| 178 | lp->dma_out = temac_dma_dcr_out; |
| 179 | dev_dbg(&op->dev, "DCR base: %x\n", dcrs); |
| 180 | return 0; |
| 181 | } |
| 182 | /* no DCR in the device tree, indicate a failure */ |
| 183 | return -1; |
| 184 | } |
| 185 | |
| 186 | #else |
| 187 | |
| 188 | /* |
| 189 | * temac_dcr_setup - This is a stub for when DCR is not supported, |
| 190 | * such as with MicroBlaze |
| 191 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 192 | static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op, |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 193 | struct device_node *np) |
| 194 | { |
| 195 | return -1; |
| 196 | } |
| 197 | |
| 198 | #endif |
| 199 | |
| 200 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 201 | * temac_dma_bd_release - Release buffer descriptor rings |
Denis Kirjanov | 301e9d9 | 2010-07-08 10:24:51 +0000 | [diff] [blame] | 202 | */ |
| 203 | static void temac_dma_bd_release(struct net_device *ndev) |
| 204 | { |
| 205 | struct temac_local *lp = netdev_priv(ndev); |
| 206 | int i; |
| 207 | |
Ricardo Ribalda | 50ec153 | 2011-11-07 23:31:58 +0000 | [diff] [blame] | 208 | /* Reset Local Link (DMA) */ |
| 209 | lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST); |
| 210 | |
Denis Kirjanov | 301e9d9 | 2010-07-08 10:24:51 +0000 | [diff] [blame] | 211 | for (i = 0; i < RX_BD_NUM; i++) { |
| 212 | if (!lp->rx_skb[i]) |
| 213 | break; |
| 214 | else { |
| 215 | dma_unmap_single(ndev->dev.parent, lp->rx_bd_v[i].phys, |
| 216 | XTE_MAX_JUMBO_FRAME_SIZE, DMA_FROM_DEVICE); |
| 217 | dev_kfree_skb(lp->rx_skb[i]); |
| 218 | } |
| 219 | } |
| 220 | if (lp->rx_bd_v) |
| 221 | dma_free_coherent(ndev->dev.parent, |
| 222 | sizeof(*lp->rx_bd_v) * RX_BD_NUM, |
| 223 | lp->rx_bd_v, lp->rx_bd_p); |
| 224 | if (lp->tx_bd_v) |
| 225 | dma_free_coherent(ndev->dev.parent, |
| 226 | sizeof(*lp->tx_bd_v) * TX_BD_NUM, |
| 227 | lp->tx_bd_v, lp->tx_bd_p); |
| 228 | if (lp->rx_skb) |
| 229 | kfree(lp->rx_skb); |
| 230 | } |
| 231 | |
| 232 | /** |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 233 | * temac_dma_bd_init - Setup buffer descriptor rings |
| 234 | */ |
| 235 | static int temac_dma_bd_init(struct net_device *ndev) |
| 236 | { |
| 237 | struct temac_local *lp = netdev_priv(ndev); |
| 238 | struct sk_buff *skb; |
| 239 | int i; |
| 240 | |
Thomas Meyer | ddf98e6 | 2011-12-02 12:35:43 +0000 | [diff] [blame] | 241 | lp->rx_skb = kcalloc(RX_BD_NUM, sizeof(*lp->rx_skb), GFP_KERNEL); |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 242 | if (!lp->rx_skb) |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 243 | goto out; |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 244 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 245 | /* allocate the tx and rx ring buffer descriptors. */ |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 246 | /* returns a virtual address and a physical address. */ |
Joe Perches | ede23fa8 | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 247 | lp->tx_bd_v = dma_zalloc_coherent(ndev->dev.parent, |
| 248 | sizeof(*lp->tx_bd_v) * TX_BD_NUM, |
| 249 | &lp->tx_bd_p, GFP_KERNEL); |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 250 | if (!lp->tx_bd_v) |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 251 | goto out; |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 252 | |
Joe Perches | ede23fa8 | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 253 | lp->rx_bd_v = dma_zalloc_coherent(ndev->dev.parent, |
| 254 | sizeof(*lp->rx_bd_v) * RX_BD_NUM, |
| 255 | &lp->rx_bd_p, GFP_KERNEL); |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 256 | if (!lp->rx_bd_v) |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 257 | goto out; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 258 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 259 | for (i = 0; i < TX_BD_NUM; i++) { |
| 260 | lp->tx_bd_v[i].next = lp->tx_bd_p + |
| 261 | sizeof(*lp->tx_bd_v) * ((i + 1) % TX_BD_NUM); |
| 262 | } |
| 263 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 264 | for (i = 0; i < RX_BD_NUM; i++) { |
| 265 | lp->rx_bd_v[i].next = lp->rx_bd_p + |
| 266 | sizeof(*lp->rx_bd_v) * ((i + 1) % RX_BD_NUM); |
| 267 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 268 | skb = netdev_alloc_skb_ip_align(ndev, |
| 269 | XTE_MAX_JUMBO_FRAME_SIZE); |
Joe Perches | 720a43e | 2013-03-08 15:03:25 +0000 | [diff] [blame] | 270 | if (!skb) |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 271 | goto out; |
Joe Perches | 720a43e | 2013-03-08 15:03:25 +0000 | [diff] [blame] | 272 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 273 | lp->rx_skb[i] = skb; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 274 | /* returns physical address of skb->data */ |
| 275 | lp->rx_bd_v[i].phys = dma_map_single(ndev->dev.parent, |
| 276 | skb->data, |
| 277 | XTE_MAX_JUMBO_FRAME_SIZE, |
| 278 | DMA_FROM_DEVICE); |
| 279 | lp->rx_bd_v[i].len = XTE_MAX_JUMBO_FRAME_SIZE; |
| 280 | lp->rx_bd_v[i].app0 = STS_CTRL_APP0_IRQONEND; |
| 281 | } |
| 282 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 283 | lp->dma_out(lp, TX_CHNL_CTRL, 0x10220400 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 284 | CHNL_CTRL_IRQ_EN | |
| 285 | CHNL_CTRL_IRQ_DLY_EN | |
| 286 | CHNL_CTRL_IRQ_COAL_EN); |
| 287 | /* 0x10220483 */ |
| 288 | /* 0x00100483 */ |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 289 | lp->dma_out(lp, RX_CHNL_CTRL, 0xff070000 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 290 | CHNL_CTRL_IRQ_EN | |
| 291 | CHNL_CTRL_IRQ_DLY_EN | |
| 292 | CHNL_CTRL_IRQ_COAL_EN | |
| 293 | CHNL_CTRL_IRQ_IOE); |
| 294 | /* 0xff010283 */ |
| 295 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 296 | lp->dma_out(lp, RX_CURDESC_PTR, lp->rx_bd_p); |
| 297 | lp->dma_out(lp, RX_TAILDESC_PTR, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 298 | lp->rx_bd_p + (sizeof(*lp->rx_bd_v) * (RX_BD_NUM - 1))); |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 299 | lp->dma_out(lp, TX_CURDESC_PTR, lp->tx_bd_p); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 300 | |
Ricardo Ribalda | 7167cf0 | 2013-10-01 08:17:10 +0200 | [diff] [blame] | 301 | /* Init descriptor indexes */ |
| 302 | lp->tx_bd_ci = 0; |
| 303 | lp->tx_bd_next = 0; |
| 304 | lp->tx_bd_tail = 0; |
| 305 | lp->rx_bd_ci = 0; |
| 306 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 307 | return 0; |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 308 | |
| 309 | out: |
Denis Kirjanov | 301e9d9 | 2010-07-08 10:24:51 +0000 | [diff] [blame] | 310 | temac_dma_bd_release(ndev); |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 311 | return -ENOMEM; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* --------------------------------------------------------------------- |
| 315 | * net_device_ops |
| 316 | */ |
| 317 | |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 318 | static void temac_do_set_mac_address(struct net_device *ndev) |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 319 | { |
| 320 | struct temac_local *lp = netdev_priv(ndev); |
| 321 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 322 | /* set up unicast MAC address filter set its mac address */ |
| 323 | mutex_lock(&lp->indirect_mutex); |
| 324 | temac_indirect_out32(lp, XTE_UAW0_OFFSET, |
| 325 | (ndev->dev_addr[0]) | |
| 326 | (ndev->dev_addr[1] << 8) | |
| 327 | (ndev->dev_addr[2] << 16) | |
| 328 | (ndev->dev_addr[3] << 24)); |
| 329 | /* There are reserved bits in EUAW1 |
| 330 | * so don't affect them Set MAC bits [47:32] in EUAW1 */ |
| 331 | temac_indirect_out32(lp, XTE_UAW1_OFFSET, |
| 332 | (ndev->dev_addr[4] & 0x000000ff) | |
| 333 | (ndev->dev_addr[5] << 8)); |
| 334 | mutex_unlock(&lp->indirect_mutex); |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 335 | } |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 336 | |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 337 | static int temac_init_mac_address(struct net_device *ndev, void *address) |
| 338 | { |
| 339 | memcpy(ndev->dev_addr, address, ETH_ALEN); |
| 340 | if (!is_valid_ether_addr(ndev->dev_addr)) |
| 341 | eth_hw_addr_random(ndev); |
| 342 | temac_do_set_mac_address(ndev); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 346 | static int temac_set_mac_address(struct net_device *ndev, void *p) |
Steven J. Magnani | 8ea7a37 | 2010-02-17 07:55:07 +0000 | [diff] [blame] | 347 | { |
| 348 | struct sockaddr *addr = p; |
| 349 | |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 350 | if (!is_valid_ether_addr(addr->sa_data)) |
| 351 | return -EADDRNOTAVAIL; |
| 352 | memcpy(ndev->dev_addr, addr->sa_data, ETH_ALEN); |
| 353 | temac_do_set_mac_address(ndev); |
| 354 | return 0; |
Steven J. Magnani | 8ea7a37 | 2010-02-17 07:55:07 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 357 | static void temac_set_multicast_list(struct net_device *ndev) |
| 358 | { |
| 359 | struct temac_local *lp = netdev_priv(ndev); |
| 360 | u32 multi_addr_msw, multi_addr_lsw, val; |
| 361 | int i; |
| 362 | |
| 363 | mutex_lock(&lp->indirect_mutex); |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 364 | if (ndev->flags & (IFF_ALLMULTI | IFF_PROMISC) || |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 365 | netdev_mc_count(ndev) > MULTICAST_CAM_TABLE_NUM) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 366 | /* |
| 367 | * We must make the kernel realise we had to move |
| 368 | * into promisc mode or we start all out war on |
| 369 | * the cable. If it was a promisc request the |
| 370 | * flag is already set. If not we assert it. |
| 371 | */ |
| 372 | ndev->flags |= IFF_PROMISC; |
| 373 | temac_indirect_out32(lp, XTE_AFM_OFFSET, XTE_AFM_EPPRM_MASK); |
| 374 | dev_info(&ndev->dev, "Promiscuous mode enabled.\n"); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 375 | } else if (!netdev_mc_empty(ndev)) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 376 | struct netdev_hw_addr *ha; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 377 | |
Jiri Pirko | f9dcbcc | 2010-02-23 09:19:49 +0000 | [diff] [blame] | 378 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 379 | netdev_for_each_mc_addr(ha, ndev) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 380 | if (i >= MULTICAST_CAM_TABLE_NUM) |
| 381 | break; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 382 | multi_addr_msw = ((ha->addr[3] << 24) | |
| 383 | (ha->addr[2] << 16) | |
| 384 | (ha->addr[1] << 8) | |
| 385 | (ha->addr[0])); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 386 | temac_indirect_out32(lp, XTE_MAW0_OFFSET, |
| 387 | multi_addr_msw); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 388 | multi_addr_lsw = ((ha->addr[5] << 8) | |
| 389 | (ha->addr[4]) | (i << 16)); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 390 | temac_indirect_out32(lp, XTE_MAW1_OFFSET, |
| 391 | multi_addr_lsw); |
Jiri Pirko | f9dcbcc | 2010-02-23 09:19:49 +0000 | [diff] [blame] | 392 | i++; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 393 | } |
| 394 | } else { |
| 395 | val = temac_indirect_in32(lp, XTE_AFM_OFFSET); |
| 396 | temac_indirect_out32(lp, XTE_AFM_OFFSET, |
| 397 | val & ~XTE_AFM_EPPRM_MASK); |
| 398 | temac_indirect_out32(lp, XTE_MAW0_OFFSET, 0); |
| 399 | temac_indirect_out32(lp, XTE_MAW1_OFFSET, 0); |
| 400 | dev_info(&ndev->dev, "Promiscuous mode disabled.\n"); |
| 401 | } |
| 402 | mutex_unlock(&lp->indirect_mutex); |
| 403 | } |
| 404 | |
| 405 | struct temac_option { |
| 406 | int flg; |
| 407 | u32 opt; |
| 408 | u32 reg; |
| 409 | u32 m_or; |
| 410 | u32 m_and; |
| 411 | } temac_options[] = { |
| 412 | /* Turn on jumbo packet support for both Rx and Tx */ |
| 413 | { |
| 414 | .opt = XTE_OPTION_JUMBO, |
| 415 | .reg = XTE_TXC_OFFSET, |
| 416 | .m_or = XTE_TXC_TXJMBO_MASK, |
| 417 | }, |
| 418 | { |
| 419 | .opt = XTE_OPTION_JUMBO, |
| 420 | .reg = XTE_RXC1_OFFSET, |
| 421 | .m_or =XTE_RXC1_RXJMBO_MASK, |
| 422 | }, |
| 423 | /* Turn on VLAN packet support for both Rx and Tx */ |
| 424 | { |
| 425 | .opt = XTE_OPTION_VLAN, |
| 426 | .reg = XTE_TXC_OFFSET, |
| 427 | .m_or =XTE_TXC_TXVLAN_MASK, |
| 428 | }, |
| 429 | { |
| 430 | .opt = XTE_OPTION_VLAN, |
| 431 | .reg = XTE_RXC1_OFFSET, |
| 432 | .m_or =XTE_RXC1_RXVLAN_MASK, |
| 433 | }, |
| 434 | /* Turn on FCS stripping on receive packets */ |
| 435 | { |
| 436 | .opt = XTE_OPTION_FCS_STRIP, |
| 437 | .reg = XTE_RXC1_OFFSET, |
| 438 | .m_or =XTE_RXC1_RXFCS_MASK, |
| 439 | }, |
| 440 | /* Turn on FCS insertion on transmit packets */ |
| 441 | { |
| 442 | .opt = XTE_OPTION_FCS_INSERT, |
| 443 | .reg = XTE_TXC_OFFSET, |
| 444 | .m_or =XTE_TXC_TXFCS_MASK, |
| 445 | }, |
| 446 | /* Turn on length/type field checking on receive packets */ |
| 447 | { |
| 448 | .opt = XTE_OPTION_LENTYPE_ERR, |
| 449 | .reg = XTE_RXC1_OFFSET, |
| 450 | .m_or =XTE_RXC1_RXLT_MASK, |
| 451 | }, |
| 452 | /* Turn on flow control */ |
| 453 | { |
| 454 | .opt = XTE_OPTION_FLOW_CONTROL, |
| 455 | .reg = XTE_FCC_OFFSET, |
| 456 | .m_or =XTE_FCC_RXFLO_MASK, |
| 457 | }, |
| 458 | /* Turn on flow control */ |
| 459 | { |
| 460 | .opt = XTE_OPTION_FLOW_CONTROL, |
| 461 | .reg = XTE_FCC_OFFSET, |
| 462 | .m_or =XTE_FCC_TXFLO_MASK, |
| 463 | }, |
| 464 | /* Turn on promiscuous frame filtering (all frames are received ) */ |
| 465 | { |
| 466 | .opt = XTE_OPTION_PROMISC, |
| 467 | .reg = XTE_AFM_OFFSET, |
| 468 | .m_or =XTE_AFM_EPPRM_MASK, |
| 469 | }, |
| 470 | /* Enable transmitter if not already enabled */ |
| 471 | { |
| 472 | .opt = XTE_OPTION_TXEN, |
| 473 | .reg = XTE_TXC_OFFSET, |
| 474 | .m_or =XTE_TXC_TXEN_MASK, |
| 475 | }, |
| 476 | /* Enable receiver? */ |
| 477 | { |
| 478 | .opt = XTE_OPTION_RXEN, |
| 479 | .reg = XTE_RXC1_OFFSET, |
| 480 | .m_or =XTE_RXC1_RXEN_MASK, |
| 481 | }, |
| 482 | {} |
| 483 | }; |
| 484 | |
| 485 | /** |
| 486 | * temac_setoptions |
| 487 | */ |
| 488 | static u32 temac_setoptions(struct net_device *ndev, u32 options) |
| 489 | { |
| 490 | struct temac_local *lp = netdev_priv(ndev); |
| 491 | struct temac_option *tp = &temac_options[0]; |
| 492 | int reg; |
| 493 | |
| 494 | mutex_lock(&lp->indirect_mutex); |
| 495 | while (tp->opt) { |
| 496 | reg = temac_indirect_in32(lp, tp->reg) & ~tp->m_or; |
| 497 | if (options & tp->opt) |
| 498 | reg |= tp->m_or; |
| 499 | temac_indirect_out32(lp, tp->reg, reg); |
| 500 | tp++; |
| 501 | } |
| 502 | lp->options |= options; |
| 503 | mutex_unlock(&lp->indirect_mutex); |
| 504 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 505 | return 0; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 508 | /* Initialize temac */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 509 | static void temac_device_reset(struct net_device *ndev) |
| 510 | { |
| 511 | struct temac_local *lp = netdev_priv(ndev); |
| 512 | u32 timeout; |
| 513 | u32 val; |
| 514 | |
| 515 | /* Perform a software reset */ |
| 516 | |
| 517 | /* 0x300 host enable bit ? */ |
| 518 | /* reset PHY through control register ?:1 */ |
| 519 | |
| 520 | dev_dbg(&ndev->dev, "%s()\n", __func__); |
| 521 | |
| 522 | mutex_lock(&lp->indirect_mutex); |
| 523 | /* Reset the receiver and wait for it to finish reset */ |
| 524 | temac_indirect_out32(lp, XTE_RXC1_OFFSET, XTE_RXC1_RXRST_MASK); |
| 525 | timeout = 1000; |
| 526 | while (temac_indirect_in32(lp, XTE_RXC1_OFFSET) & XTE_RXC1_RXRST_MASK) { |
| 527 | udelay(1); |
| 528 | if (--timeout == 0) { |
| 529 | dev_err(&ndev->dev, |
| 530 | "temac_device_reset RX reset timeout!!\n"); |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /* Reset the transmitter and wait for it to finish reset */ |
| 536 | temac_indirect_out32(lp, XTE_TXC_OFFSET, XTE_TXC_TXRST_MASK); |
| 537 | timeout = 1000; |
| 538 | while (temac_indirect_in32(lp, XTE_TXC_OFFSET) & XTE_TXC_TXRST_MASK) { |
| 539 | udelay(1); |
| 540 | if (--timeout == 0) { |
| 541 | dev_err(&ndev->dev, |
| 542 | "temac_device_reset TX reset timeout!!\n"); |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /* Disable the receiver */ |
| 548 | val = temac_indirect_in32(lp, XTE_RXC1_OFFSET); |
| 549 | temac_indirect_out32(lp, XTE_RXC1_OFFSET, val & ~XTE_RXC1_RXEN_MASK); |
| 550 | |
| 551 | /* Reset Local Link (DMA) */ |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 552 | lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 553 | timeout = 1000; |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 554 | while (lp->dma_in(lp, DMA_CONTROL_REG) & DMA_CONTROL_RST) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 555 | udelay(1); |
| 556 | if (--timeout == 0) { |
| 557 | dev_err(&ndev->dev, |
| 558 | "temac_device_reset DMA reset timeout!!\n"); |
| 559 | break; |
| 560 | } |
| 561 | } |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 562 | lp->dma_out(lp, DMA_CONTROL_REG, DMA_TAIL_ENABLE); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 563 | |
Denis Kirjanov | fe62c29 | 2010-06-30 23:39:05 +0000 | [diff] [blame] | 564 | if (temac_dma_bd_init(ndev)) { |
| 565 | dev_err(&ndev->dev, |
| 566 | "temac_device_reset descriptor allocation failed\n"); |
| 567 | } |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 568 | |
| 569 | temac_indirect_out32(lp, XTE_RXC0_OFFSET, 0); |
| 570 | temac_indirect_out32(lp, XTE_RXC1_OFFSET, 0); |
| 571 | temac_indirect_out32(lp, XTE_TXC_OFFSET, 0); |
| 572 | temac_indirect_out32(lp, XTE_FCC_OFFSET, XTE_FCC_RXFLO_MASK); |
| 573 | |
| 574 | mutex_unlock(&lp->indirect_mutex); |
| 575 | |
| 576 | /* Sync default options with HW |
| 577 | * but leave receiver and transmitter disabled. */ |
| 578 | temac_setoptions(ndev, |
| 579 | lp->options & ~(XTE_OPTION_TXEN | XTE_OPTION_RXEN)); |
| 580 | |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 581 | temac_do_set_mac_address(ndev); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 582 | |
| 583 | /* Set address filter table */ |
| 584 | temac_set_multicast_list(ndev); |
| 585 | if (temac_setoptions(ndev, lp->options)) |
| 586 | dev_err(&ndev->dev, "Error setting TEMAC options\n"); |
| 587 | |
| 588 | /* Init Driver variable */ |
Eric Dumazet | 1ae5dc3 | 2010-05-10 05:01:31 -0700 | [diff] [blame] | 589 | ndev->trans_start = jiffies; /* prevent tx timeout */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | void temac_adjust_link(struct net_device *ndev) |
| 593 | { |
| 594 | struct temac_local *lp = netdev_priv(ndev); |
| 595 | struct phy_device *phy = lp->phy_dev; |
| 596 | u32 mii_speed; |
| 597 | int link_state; |
| 598 | |
| 599 | /* hash together the state values to decide if something has changed */ |
| 600 | link_state = phy->speed | (phy->duplex << 1) | phy->link; |
| 601 | |
| 602 | mutex_lock(&lp->indirect_mutex); |
| 603 | if (lp->last_link != link_state) { |
| 604 | mii_speed = temac_indirect_in32(lp, XTE_EMCFG_OFFSET); |
| 605 | mii_speed &= ~XTE_EMCFG_LINKSPD_MASK; |
| 606 | |
| 607 | switch (phy->speed) { |
| 608 | case SPEED_1000: mii_speed |= XTE_EMCFG_LINKSPD_1000; break; |
| 609 | case SPEED_100: mii_speed |= XTE_EMCFG_LINKSPD_100; break; |
| 610 | case SPEED_10: mii_speed |= XTE_EMCFG_LINKSPD_10; break; |
| 611 | } |
| 612 | |
| 613 | /* Write new speed setting out to TEMAC */ |
| 614 | temac_indirect_out32(lp, XTE_EMCFG_OFFSET, mii_speed); |
| 615 | lp->last_link = link_state; |
| 616 | phy_print_status(phy); |
| 617 | } |
| 618 | mutex_unlock(&lp->indirect_mutex); |
| 619 | } |
| 620 | |
| 621 | static void temac_start_xmit_done(struct net_device *ndev) |
| 622 | { |
| 623 | struct temac_local *lp = netdev_priv(ndev); |
| 624 | struct cdmac_bd *cur_p; |
| 625 | unsigned int stat = 0; |
| 626 | |
| 627 | cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; |
| 628 | stat = cur_p->app0; |
| 629 | |
| 630 | while (stat & STS_CTRL_APP0_CMPLT) { |
| 631 | dma_unmap_single(ndev->dev.parent, cur_p->phys, cur_p->len, |
| 632 | DMA_TO_DEVICE); |
| 633 | if (cur_p->app4) |
| 634 | dev_kfree_skb_irq((struct sk_buff *)cur_p->app4); |
| 635 | cur_p->app0 = 0; |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 636 | cur_p->app1 = 0; |
| 637 | cur_p->app2 = 0; |
| 638 | cur_p->app3 = 0; |
| 639 | cur_p->app4 = 0; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 640 | |
| 641 | ndev->stats.tx_packets++; |
| 642 | ndev->stats.tx_bytes += cur_p->len; |
| 643 | |
| 644 | lp->tx_bd_ci++; |
| 645 | if (lp->tx_bd_ci >= TX_BD_NUM) |
| 646 | lp->tx_bd_ci = 0; |
| 647 | |
| 648 | cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; |
| 649 | stat = cur_p->app0; |
| 650 | } |
| 651 | |
| 652 | netif_wake_queue(ndev); |
| 653 | } |
| 654 | |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 655 | static inline int temac_check_tx_bd_space(struct temac_local *lp, int num_frag) |
| 656 | { |
| 657 | struct cdmac_bd *cur_p; |
| 658 | int tail; |
| 659 | |
| 660 | tail = lp->tx_bd_tail; |
| 661 | cur_p = &lp->tx_bd_v[tail]; |
| 662 | |
| 663 | do { |
| 664 | if (cur_p->app0) |
| 665 | return NETDEV_TX_BUSY; |
| 666 | |
| 667 | tail++; |
| 668 | if (tail >= TX_BD_NUM) |
| 669 | tail = 0; |
| 670 | |
| 671 | cur_p = &lp->tx_bd_v[tail]; |
| 672 | num_frag--; |
| 673 | } while (num_frag >= 0); |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 678 | static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 679 | { |
| 680 | struct temac_local *lp = netdev_priv(ndev); |
| 681 | struct cdmac_bd *cur_p; |
| 682 | dma_addr_t start_p, tail_p; |
| 683 | int ii; |
| 684 | unsigned long num_frag; |
| 685 | skb_frag_t *frag; |
| 686 | |
| 687 | num_frag = skb_shinfo(skb)->nr_frags; |
| 688 | frag = &skb_shinfo(skb)->frags[0]; |
| 689 | start_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail; |
| 690 | cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; |
| 691 | |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 692 | if (temac_check_tx_bd_space(lp, num_frag)) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 693 | if (!netif_queue_stopped(ndev)) { |
| 694 | netif_stop_queue(ndev); |
| 695 | return NETDEV_TX_BUSY; |
| 696 | } |
| 697 | return NETDEV_TX_BUSY; |
| 698 | } |
| 699 | |
| 700 | cur_p->app0 = 0; |
| 701 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 702 | unsigned int csum_start_off = skb_checksum_start_offset(skb); |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 703 | unsigned int csum_index_off = csum_start_off + skb->csum_offset; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 704 | |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 705 | cur_p->app0 |= 1; /* TX Checksum Enabled */ |
| 706 | cur_p->app1 = (csum_start_off << 16) | csum_index_off; |
| 707 | cur_p->app2 = 0; /* initial checksum seed */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 708 | } |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 709 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 710 | cur_p->app0 |= STS_CTRL_APP0_SOP; |
| 711 | cur_p->len = skb_headlen(skb); |
| 712 | cur_p->phys = dma_map_single(ndev->dev.parent, skb->data, skb->len, |
| 713 | DMA_TO_DEVICE); |
| 714 | cur_p->app4 = (unsigned long)skb; |
| 715 | |
| 716 | for (ii = 0; ii < num_frag; ii++) { |
| 717 | lp->tx_bd_tail++; |
| 718 | if (lp->tx_bd_tail >= TX_BD_NUM) |
| 719 | lp->tx_bd_tail = 0; |
| 720 | |
| 721 | cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; |
| 722 | cur_p->phys = dma_map_single(ndev->dev.parent, |
Ian Campbell | 3ed6f69 | 2011-10-10 01:11:40 +0000 | [diff] [blame] | 723 | skb_frag_address(frag), |
Stephen Rothwell | 2edcd4c | 2011-11-02 01:49:44 -0400 | [diff] [blame] | 724 | skb_frag_size(frag), DMA_TO_DEVICE); |
| 725 | cur_p->len = skb_frag_size(frag); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 726 | cur_p->app0 = 0; |
| 727 | frag++; |
| 728 | } |
| 729 | cur_p->app0 |= STS_CTRL_APP0_EOP; |
| 730 | |
| 731 | tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail; |
| 732 | lp->tx_bd_tail++; |
| 733 | if (lp->tx_bd_tail >= TX_BD_NUM) |
| 734 | lp->tx_bd_tail = 0; |
| 735 | |
Richard Cochran | 93e0ed1 | 2011-06-19 21:51:26 +0000 | [diff] [blame] | 736 | skb_tx_timestamp(skb); |
| 737 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 738 | /* Kick off the transfer */ |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 739 | lp->dma_out(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 740 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 741 | return NETDEV_TX_OK; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | |
| 745 | static void ll_temac_recv(struct net_device *ndev) |
| 746 | { |
| 747 | struct temac_local *lp = netdev_priv(ndev); |
| 748 | struct sk_buff *skb, *new_skb; |
| 749 | unsigned int bdstat; |
| 750 | struct cdmac_bd *cur_p; |
| 751 | dma_addr_t tail_p; |
| 752 | int length; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 753 | unsigned long flags; |
| 754 | |
| 755 | spin_lock_irqsave(&lp->rx_lock, flags); |
| 756 | |
| 757 | tail_p = lp->rx_bd_p + sizeof(*lp->rx_bd_v) * lp->rx_bd_ci; |
| 758 | cur_p = &lp->rx_bd_v[lp->rx_bd_ci]; |
| 759 | |
| 760 | bdstat = cur_p->app0; |
| 761 | while ((bdstat & STS_CTRL_APP0_CMPLT)) { |
| 762 | |
| 763 | skb = lp->rx_skb[lp->rx_bd_ci]; |
Steven J. Magnani | c3b7c12 | 2010-02-17 07:14:20 +0000 | [diff] [blame] | 764 | length = cur_p->app4 & 0x3FFF; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 765 | |
John Linn | 33646d7 | 2010-04-08 07:08:01 +0000 | [diff] [blame] | 766 | dma_unmap_single(ndev->dev.parent, cur_p->phys, length, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 767 | DMA_FROM_DEVICE); |
| 768 | |
| 769 | skb_put(skb, length); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 770 | skb->protocol = eth_type_trans(skb, ndev); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 771 | skb_checksum_none_assert(skb); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 772 | |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 773 | /* if we're doing rx csum offload, set it up */ |
| 774 | if (((lp->temac_features & TEMAC_FEATURE_RX_CSUM) != 0) && |
| 775 | (skb->protocol == __constant_htons(ETH_P_IP)) && |
| 776 | (skb->len > 64)) { |
| 777 | |
| 778 | skb->csum = cur_p->app3 & 0xFFFF; |
| 779 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 780 | } |
| 781 | |
Richard Cochran | 93e0ed1 | 2011-06-19 21:51:26 +0000 | [diff] [blame] | 782 | if (!skb_defer_rx_timestamp(skb)) |
| 783 | netif_rx(skb); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 784 | |
| 785 | ndev->stats.rx_packets++; |
| 786 | ndev->stats.rx_bytes += length; |
| 787 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 788 | new_skb = netdev_alloc_skb_ip_align(ndev, |
| 789 | XTE_MAX_JUMBO_FRAME_SIZE); |
Joe Perches | 720a43e | 2013-03-08 15:03:25 +0000 | [diff] [blame] | 790 | if (!new_skb) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 791 | spin_unlock_irqrestore(&lp->rx_lock, flags); |
| 792 | return; |
| 793 | } |
| 794 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 795 | cur_p->app0 = STS_CTRL_APP0_IRQONEND; |
| 796 | cur_p->phys = dma_map_single(ndev->dev.parent, new_skb->data, |
| 797 | XTE_MAX_JUMBO_FRAME_SIZE, |
| 798 | DMA_FROM_DEVICE); |
| 799 | cur_p->len = XTE_MAX_JUMBO_FRAME_SIZE; |
| 800 | lp->rx_skb[lp->rx_bd_ci] = new_skb; |
| 801 | |
| 802 | lp->rx_bd_ci++; |
| 803 | if (lp->rx_bd_ci >= RX_BD_NUM) |
| 804 | lp->rx_bd_ci = 0; |
| 805 | |
| 806 | cur_p = &lp->rx_bd_v[lp->rx_bd_ci]; |
| 807 | bdstat = cur_p->app0; |
| 808 | } |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 809 | lp->dma_out(lp, RX_TAILDESC_PTR, tail_p); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 810 | |
| 811 | spin_unlock_irqrestore(&lp->rx_lock, flags); |
| 812 | } |
| 813 | |
| 814 | static irqreturn_t ll_temac_tx_irq(int irq, void *_ndev) |
| 815 | { |
| 816 | struct net_device *ndev = _ndev; |
| 817 | struct temac_local *lp = netdev_priv(ndev); |
| 818 | unsigned int status; |
| 819 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 820 | status = lp->dma_in(lp, TX_IRQ_REG); |
| 821 | lp->dma_out(lp, TX_IRQ_REG, status); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 822 | |
| 823 | if (status & (IRQ_COAL | IRQ_DLY)) |
| 824 | temac_start_xmit_done(lp->ndev); |
| 825 | if (status & 0x080) |
| 826 | dev_err(&ndev->dev, "DMA error 0x%x\n", status); |
| 827 | |
| 828 | return IRQ_HANDLED; |
| 829 | } |
| 830 | |
| 831 | static irqreturn_t ll_temac_rx_irq(int irq, void *_ndev) |
| 832 | { |
| 833 | struct net_device *ndev = _ndev; |
| 834 | struct temac_local *lp = netdev_priv(ndev); |
| 835 | unsigned int status; |
| 836 | |
| 837 | /* Read and clear the status registers */ |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 838 | status = lp->dma_in(lp, RX_IRQ_REG); |
| 839 | lp->dma_out(lp, RX_IRQ_REG, status); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 840 | |
| 841 | if (status & (IRQ_COAL | IRQ_DLY)) |
| 842 | ll_temac_recv(lp->ndev); |
| 843 | |
| 844 | return IRQ_HANDLED; |
| 845 | } |
| 846 | |
| 847 | static int temac_open(struct net_device *ndev) |
| 848 | { |
| 849 | struct temac_local *lp = netdev_priv(ndev); |
| 850 | int rc; |
| 851 | |
| 852 | dev_dbg(&ndev->dev, "temac_open()\n"); |
| 853 | |
| 854 | if (lp->phy_node) { |
| 855 | lp->phy_dev = of_phy_connect(lp->ndev, lp->phy_node, |
| 856 | temac_adjust_link, 0, 0); |
| 857 | if (!lp->phy_dev) { |
| 858 | dev_err(lp->dev, "of_phy_connect() failed\n"); |
| 859 | return -ENODEV; |
| 860 | } |
| 861 | |
| 862 | phy_start(lp->phy_dev); |
| 863 | } |
| 864 | |
Ricardo Ribalda | 50ec153 | 2011-11-07 23:31:58 +0000 | [diff] [blame] | 865 | temac_device_reset(ndev); |
| 866 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 867 | rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev); |
| 868 | if (rc) |
| 869 | goto err_tx_irq; |
| 870 | rc = request_irq(lp->rx_irq, ll_temac_rx_irq, 0, ndev->name, ndev); |
| 871 | if (rc) |
| 872 | goto err_rx_irq; |
| 873 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 874 | return 0; |
| 875 | |
| 876 | err_rx_irq: |
| 877 | free_irq(lp->tx_irq, ndev); |
| 878 | err_tx_irq: |
| 879 | if (lp->phy_dev) |
| 880 | phy_disconnect(lp->phy_dev); |
| 881 | lp->phy_dev = NULL; |
| 882 | dev_err(lp->dev, "request_irq() failed\n"); |
| 883 | return rc; |
| 884 | } |
| 885 | |
| 886 | static int temac_stop(struct net_device *ndev) |
| 887 | { |
| 888 | struct temac_local *lp = netdev_priv(ndev); |
| 889 | |
| 890 | dev_dbg(&ndev->dev, "temac_close()\n"); |
| 891 | |
| 892 | free_irq(lp->tx_irq, ndev); |
| 893 | free_irq(lp->rx_irq, ndev); |
| 894 | |
| 895 | if (lp->phy_dev) |
| 896 | phy_disconnect(lp->phy_dev); |
| 897 | lp->phy_dev = NULL; |
| 898 | |
Denis Kirjanov | 301e9d9 | 2010-07-08 10:24:51 +0000 | [diff] [blame] | 899 | temac_dma_bd_release(ndev); |
| 900 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 905 | static void |
| 906 | temac_poll_controller(struct net_device *ndev) |
| 907 | { |
| 908 | struct temac_local *lp = netdev_priv(ndev); |
| 909 | |
| 910 | disable_irq(lp->tx_irq); |
| 911 | disable_irq(lp->rx_irq); |
| 912 | |
Michal Simek | 8539992 | 2010-08-18 00:26:34 +0000 | [diff] [blame] | 913 | ll_temac_rx_irq(lp->tx_irq, ndev); |
| 914 | ll_temac_tx_irq(lp->rx_irq, ndev); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 915 | |
| 916 | enable_irq(lp->tx_irq); |
| 917 | enable_irq(lp->rx_irq); |
| 918 | } |
| 919 | #endif |
| 920 | |
Ricardo Ribalda | 8d8bdfe | 2011-11-07 23:47:45 +0000 | [diff] [blame] | 921 | static int temac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) |
| 922 | { |
| 923 | struct temac_local *lp = netdev_priv(ndev); |
| 924 | |
| 925 | if (!netif_running(ndev)) |
| 926 | return -EINVAL; |
| 927 | |
| 928 | if (!lp->phy_dev) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | return phy_mii_ioctl(lp->phy_dev, rq, cmd); |
| 932 | } |
| 933 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 934 | static const struct net_device_ops temac_netdev_ops = { |
| 935 | .ndo_open = temac_open, |
| 936 | .ndo_stop = temac_stop, |
| 937 | .ndo_start_xmit = temac_start_xmit, |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 938 | .ndo_set_mac_address = temac_set_mac_address, |
Denis Kirjanov | 60eb5fd | 2010-07-10 11:10:44 +0000 | [diff] [blame] | 939 | .ndo_validate_addr = eth_validate_addr, |
Ricardo Ribalda | 8d8bdfe | 2011-11-07 23:47:45 +0000 | [diff] [blame] | 940 | .ndo_do_ioctl = temac_ioctl, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 941 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 942 | .ndo_poll_controller = temac_poll_controller, |
| 943 | #endif |
| 944 | }; |
| 945 | |
| 946 | /* --------------------------------------------------------------------- |
| 947 | * SYSFS device attributes |
| 948 | */ |
| 949 | static ssize_t temac_show_llink_regs(struct device *dev, |
| 950 | struct device_attribute *attr, char *buf) |
| 951 | { |
| 952 | struct net_device *ndev = dev_get_drvdata(dev); |
| 953 | struct temac_local *lp = netdev_priv(ndev); |
| 954 | int i, len = 0; |
| 955 | |
| 956 | for (i = 0; i < 0x11; i++) |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 957 | len += sprintf(buf + len, "%.8x%s", lp->dma_in(lp, i), |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 958 | (i % 8) == 7 ? "\n" : " "); |
| 959 | len += sprintf(buf + len, "\n"); |
| 960 | |
| 961 | return len; |
| 962 | } |
| 963 | |
| 964 | static DEVICE_ATTR(llink_regs, 0440, temac_show_llink_regs, NULL); |
| 965 | |
| 966 | static struct attribute *temac_device_attrs[] = { |
| 967 | &dev_attr_llink_regs.attr, |
| 968 | NULL, |
| 969 | }; |
| 970 | |
| 971 | static const struct attribute_group temac_attr_group = { |
| 972 | .attrs = temac_device_attrs, |
| 973 | }; |
| 974 | |
Ricardo | 9eac2d4 | 2011-10-18 21:35:25 +0000 | [diff] [blame] | 975 | /* ethtool support */ |
| 976 | static int temac_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd) |
| 977 | { |
| 978 | struct temac_local *lp = netdev_priv(ndev); |
| 979 | return phy_ethtool_gset(lp->phy_dev, cmd); |
| 980 | } |
| 981 | |
| 982 | static int temac_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd) |
| 983 | { |
| 984 | struct temac_local *lp = netdev_priv(ndev); |
| 985 | return phy_ethtool_sset(lp->phy_dev, cmd); |
| 986 | } |
| 987 | |
| 988 | static int temac_nway_reset(struct net_device *ndev) |
| 989 | { |
| 990 | struct temac_local *lp = netdev_priv(ndev); |
| 991 | return phy_start_aneg(lp->phy_dev); |
| 992 | } |
| 993 | |
| 994 | static const struct ethtool_ops temac_ethtool_ops = { |
| 995 | .get_settings = temac_get_settings, |
| 996 | .set_settings = temac_set_settings, |
| 997 | .nway_reset = temac_nway_reset, |
| 998 | .get_link = ethtool_op_get_link, |
Richard Cochran | f85e5ea | 2012-04-03 22:59:30 +0000 | [diff] [blame] | 999 | .get_ts_info = ethtool_op_get_ts_info, |
Ricardo | 9eac2d4 | 2011-10-18 21:35:25 +0000 | [diff] [blame] | 1000 | }; |
| 1001 | |
Bill Pemberton | 06b0e68 | 2012-12-03 09:24:08 -0500 | [diff] [blame] | 1002 | static int temac_of_probe(struct platform_device *op) |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1003 | { |
| 1004 | struct device_node *np; |
| 1005 | struct temac_local *lp; |
| 1006 | struct net_device *ndev; |
| 1007 | const void *addr; |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 1008 | __be32 *p; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1009 | int size, rc = 0; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1010 | |
| 1011 | /* Init network device structure */ |
| 1012 | ndev = alloc_etherdev(sizeof(*lp)); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 1013 | if (!ndev) |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1014 | return -ENOMEM; |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 1015 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1016 | ether_setup(ndev); |
Jingoo Han | 8513fbd | 2013-05-23 00:52:31 +0000 | [diff] [blame] | 1017 | platform_set_drvdata(op, ndev); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1018 | SET_NETDEV_DEV(ndev, &op->dev); |
| 1019 | ndev->flags &= ~IFF_MULTICAST; /* clear multicast */ |
Eric Dumazet | 28e24c6 | 2013-12-02 08:51:13 -0800 | [diff] [blame^] | 1020 | ndev->features = NETIF_F_SG; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1021 | ndev->netdev_ops = &temac_netdev_ops; |
Ricardo | 9eac2d4 | 2011-10-18 21:35:25 +0000 | [diff] [blame] | 1022 | ndev->ethtool_ops = &temac_ethtool_ops; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1023 | #if 0 |
| 1024 | ndev->features |= NETIF_F_IP_CSUM; /* Can checksum TCP/UDP over IPv4. */ |
| 1025 | ndev->features |= NETIF_F_HW_CSUM; /* Can checksum all the packets. */ |
| 1026 | ndev->features |= NETIF_F_IPV6_CSUM; /* Can checksum IPV6 TCP/UDP */ |
| 1027 | ndev->features |= NETIF_F_HIGHDMA; /* Can DMA to high memory. */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1028 | ndev->features |= NETIF_F_HW_VLAN_CTAG_TX; /* Transmit VLAN hw accel */ |
| 1029 | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; /* Receive VLAN hw acceleration */ |
| 1030 | ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; /* Receive VLAN filtering */ |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1031 | ndev->features |= NETIF_F_VLAN_CHALLENGED; /* cannot handle VLAN pkts */ |
| 1032 | ndev->features |= NETIF_F_GSO; /* Enable software GSO. */ |
| 1033 | ndev->features |= NETIF_F_MULTI_QUEUE; /* Has multiple TX/RX queues */ |
| 1034 | ndev->features |= NETIF_F_LRO; /* large receive offload */ |
| 1035 | #endif |
| 1036 | |
| 1037 | /* setup temac private info structure */ |
| 1038 | lp = netdev_priv(ndev); |
| 1039 | lp->ndev = ndev; |
| 1040 | lp->dev = &op->dev; |
| 1041 | lp->options = XTE_OPTION_DEFAULTS; |
| 1042 | spin_lock_init(&lp->rx_lock); |
| 1043 | mutex_init(&lp->indirect_mutex); |
| 1044 | |
| 1045 | /* map device registers */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1046 | lp->regs = of_iomap(op->dev.of_node, 0); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1047 | if (!lp->regs) { |
| 1048 | dev_err(&op->dev, "could not map temac regs.\n"); |
| 1049 | goto nodev; |
| 1050 | } |
| 1051 | |
Brian Hill | 23ecc4b | 2010-05-26 20:44:30 -0700 | [diff] [blame] | 1052 | /* Setup checksum offload, but default to off if not specified */ |
| 1053 | lp->temac_features = 0; |
| 1054 | p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,txcsum", NULL); |
| 1055 | if (p && be32_to_cpu(*p)) { |
| 1056 | lp->temac_features |= TEMAC_FEATURE_TX_CSUM; |
| 1057 | /* Can checksum TCP/UDP over IPv4. */ |
| 1058 | ndev->features |= NETIF_F_IP_CSUM; |
| 1059 | } |
| 1060 | p = (__be32 *)of_get_property(op->dev.of_node, "xlnx,rxcsum", NULL); |
| 1061 | if (p && be32_to_cpu(*p)) |
| 1062 | lp->temac_features |= TEMAC_FEATURE_RX_CSUM; |
| 1063 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1064 | /* Find the DMA node, map the DMA registers, and decode the DMA IRQs */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1065 | np = of_parse_phandle(op->dev.of_node, "llink-connected", 0); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1066 | if (!np) { |
| 1067 | dev_err(&op->dev, "could not find DMA node\n"); |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1068 | goto err_iounmap; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 1071 | /* Setup the DMA register accesses, could be DCR or memory mapped */ |
| 1072 | if (temac_dcr_setup(lp, op, np)) { |
| 1073 | |
| 1074 | /* no DCR in the device tree, try non-DCR */ |
| 1075 | lp->sdma_regs = of_iomap(np, 0); |
| 1076 | if (lp->sdma_regs) { |
| 1077 | lp->dma_in = temac_dma_in32; |
| 1078 | lp->dma_out = temac_dma_out32; |
| 1079 | dev_dbg(&op->dev, "MEM base: %p\n", lp->sdma_regs); |
| 1080 | } else { |
| 1081 | dev_err(&op->dev, "unable to map DMA registers\n"); |
Kulikov Vasiliy | 7cc36f6 | 2010-07-08 23:43:20 -0700 | [diff] [blame] | 1082 | of_node_put(np); |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1083 | goto err_iounmap; |
John Linn | e44171f | 2010-04-08 07:08:02 +0000 | [diff] [blame] | 1084 | } |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1085 | } |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1086 | |
| 1087 | lp->rx_irq = irq_of_parse_and_map(np, 0); |
| 1088 | lp->tx_irq = irq_of_parse_and_map(np, 1); |
Kulikov Vasiliy | 7cc36f6 | 2010-07-08 23:43:20 -0700 | [diff] [blame] | 1089 | |
| 1090 | of_node_put(np); /* Finished with the DMA node; drop the reference */ |
| 1091 | |
Michal Simek | 4e68ea2 | 2011-12-21 15:42:50 -0500 | [diff] [blame] | 1092 | if (!lp->rx_irq || !lp->tx_irq) { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1093 | dev_err(&op->dev, "could not determine irqs\n"); |
| 1094 | rc = -ENOMEM; |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1095 | goto err_iounmap_2; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1098 | |
| 1099 | /* Retrieve the MAC address */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1100 | addr = of_get_property(op->dev.of_node, "local-mac-address", &size); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1101 | if ((!addr) || (size != 6)) { |
| 1102 | dev_err(&op->dev, "could not find MAC address\n"); |
| 1103 | rc = -ENODEV; |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1104 | goto err_iounmap_2; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1105 | } |
Jiri Pirko | 04e406d | 2013-01-01 03:30:19 +0000 | [diff] [blame] | 1106 | temac_init_mac_address(ndev, (void *)addr); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1107 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1108 | rc = temac_mdio_setup(lp, op->dev.of_node); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1109 | if (rc) |
| 1110 | dev_warn(&op->dev, "error registering MDIO bus\n"); |
| 1111 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1112 | lp->phy_node = of_parse_phandle(op->dev.of_node, "phy-handle", 0); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1113 | if (lp->phy_node) |
| 1114 | dev_dbg(lp->dev, "using PHY node %s (%p)\n", np->full_name, np); |
| 1115 | |
| 1116 | /* Add the device attributes */ |
| 1117 | rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group); |
| 1118 | if (rc) { |
| 1119 | dev_err(lp->dev, "Error creating sysfs files\n"); |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1120 | goto err_iounmap_2; |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | rc = register_netdev(lp->ndev); |
| 1124 | if (rc) { |
| 1125 | dev_err(lp->dev, "register_netdev() error (%i)\n", rc); |
| 1126 | goto err_register_ndev; |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | |
| 1131 | err_register_ndev: |
| 1132 | sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1133 | err_iounmap_2: |
| 1134 | if (lp->sdma_regs) |
| 1135 | iounmap(lp->sdma_regs); |
| 1136 | err_iounmap: |
| 1137 | iounmap(lp->regs); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1138 | nodev: |
| 1139 | free_netdev(ndev); |
| 1140 | ndev = NULL; |
| 1141 | return rc; |
| 1142 | } |
| 1143 | |
Bill Pemberton | 06b0e68 | 2012-12-03 09:24:08 -0500 | [diff] [blame] | 1144 | static int temac_of_remove(struct platform_device *op) |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1145 | { |
Jingoo Han | 8513fbd | 2013-05-23 00:52:31 +0000 | [diff] [blame] | 1146 | struct net_device *ndev = platform_get_drvdata(op); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1147 | struct temac_local *lp = netdev_priv(ndev); |
| 1148 | |
| 1149 | temac_mdio_teardown(lp); |
| 1150 | unregister_netdev(ndev); |
| 1151 | sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); |
| 1152 | if (lp->phy_node) |
| 1153 | of_node_put(lp->phy_node); |
| 1154 | lp->phy_node = NULL; |
Denis Kirjanov | dfe1e8e | 2010-07-05 21:44:20 +0000 | [diff] [blame] | 1155 | iounmap(lp->regs); |
| 1156 | if (lp->sdma_regs) |
| 1157 | iounmap(lp->sdma_regs); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1158 | free_netdev(ndev); |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
Bill Pemberton | 06b0e68 | 2012-12-03 09:24:08 -0500 | [diff] [blame] | 1162 | static struct of_device_id temac_of_match[] = { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1163 | { .compatible = "xlnx,xps-ll-temac-1.01.b", }, |
Steven J. Magnani | c3b7c12 | 2010-02-17 07:14:20 +0000 | [diff] [blame] | 1164 | { .compatible = "xlnx,xps-ll-temac-2.00.a", }, |
| 1165 | { .compatible = "xlnx,xps-ll-temac-2.02.a", }, |
| 1166 | { .compatible = "xlnx,xps-ll-temac-2.03.a", }, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1167 | {}, |
| 1168 | }; |
| 1169 | MODULE_DEVICE_TABLE(of, temac_of_match); |
| 1170 | |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 1171 | static struct platform_driver temac_of_driver = { |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1172 | .probe = temac_of_probe, |
Bill Pemberton | 06b0e68 | 2012-12-03 09:24:08 -0500 | [diff] [blame] | 1173 | .remove = temac_of_remove, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1174 | .driver = { |
| 1175 | .owner = THIS_MODULE, |
| 1176 | .name = "xilinx_temac", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1177 | .of_match_table = temac_of_match, |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1178 | }, |
| 1179 | }; |
| 1180 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 1181 | module_platform_driver(temac_of_driver); |
Grant Likely | 9274498 | 2009-04-25 12:53:39 +0000 | [diff] [blame] | 1182 | |
| 1183 | MODULE_DESCRIPTION("Xilinx LL_TEMAC Ethernet driver"); |
| 1184 | MODULE_AUTHOR("Yoshio Kashiwagi"); |
| 1185 | MODULE_LICENSE("GPL"); |