Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1 | /* |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 2 | * Cadence MACB/GEM Ethernet Controller driver |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004-2006 Atmel Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 12 | #include <linux/clk.h> |
Claudiu Beznea | 653e92a | 2018-08-07 12:25:14 +0300 | [diff] [blame] | 13 | #include <linux/crc32.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/types.h> |
Nicolas Ferre | 909a858 | 2012-11-19 06:00:21 +0000 | [diff] [blame] | 18 | #include <linux/circ_buf.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/init.h> |
Soren Brinkmann | 60fe716 | 2013-12-10 16:07:21 -0800 | [diff] [blame] | 21 | #include <linux/io.h> |
Joachim Eastwood | 2dbfdbb9 | 2012-11-11 13:56:27 +0000 | [diff] [blame] | 22 | #include <linux/gpio.h> |
Gregory CLEMENT | 270c499 | 2015-12-17 10:51:04 +0100 | [diff] [blame] | 23 | #include <linux/gpio/consumer.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 25 | #include <linux/netdevice.h> |
| 26 | #include <linux/etherdevice.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 27 | #include <linux/dma-mapping.h> |
Jamie Iles | 84e0cdb | 2011-03-08 20:17:06 +0000 | [diff] [blame] | 28 | #include <linux/platform_data/macb.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 30 | #include <linux/phy.h> |
Olof Johansson | b17471f | 2011-12-20 13:13:07 -0800 | [diff] [blame] | 31 | #include <linux/of.h> |
Jean-Christophe PLAGNIOL-VILLARD | fb97a84 | 2011-11-18 15:29:25 +0100 | [diff] [blame] | 32 | #include <linux/of_device.h> |
Gregory CLEMENT | 270c499 | 2015-12-17 10:51:04 +0100 | [diff] [blame] | 33 | #include <linux/of_gpio.h> |
Boris BREZILLON | 148cbb5 | 2013-08-22 17:57:28 +0200 | [diff] [blame] | 34 | #include <linux/of_mdio.h> |
Jean-Christophe PLAGNIOL-VILLARD | fb97a84 | 2011-11-18 15:29:25 +0100 | [diff] [blame] | 35 | #include <linux/of_net.h> |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 36 | #include <linux/ip.h> |
| 37 | #include <linux/udp.h> |
| 38 | #include <linux/tcp.h> |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 39 | #include "macb.h" |
| 40 | |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 41 | #define MACB_RX_BUFFER_SIZE 128 |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 42 | #define RX_BUFFER_MULTIPLE 64 /* bytes */ |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 43 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 44 | #define DEFAULT_RX_RING_SIZE 512 /* must be power of 2 */ |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 45 | #define MIN_RX_RING_SIZE 64 |
| 46 | #define MAX_RX_RING_SIZE 8192 |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 47 | #define RX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \ |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 48 | * (bp)->rx_ring_size) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 49 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 50 | #define DEFAULT_TX_RING_SIZE 512 /* must be power of 2 */ |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 51 | #define MIN_TX_RING_SIZE 64 |
| 52 | #define MAX_TX_RING_SIZE 4096 |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 53 | #define TX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \ |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 54 | * (bp)->tx_ring_size) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 55 | |
Nicolas Ferre | 909a858 | 2012-11-19 06:00:21 +0000 | [diff] [blame] | 56 | /* level of occupied TX descriptors under which we wake up TX process */ |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 57 | #define MACB_TX_WAKEUP_THRESH(bp) (3 * (bp)->tx_ring_size / 4) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 58 | |
| 59 | #define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(RXUBR) \ |
| 60 | | MACB_BIT(ISR_ROVR)) |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 61 | #define MACB_TX_ERR_FLAGS (MACB_BIT(ISR_TUND) \ |
| 62 | | MACB_BIT(ISR_RLE) \ |
| 63 | | MACB_BIT(TXERR)) |
Claudiu Beznea | 4298388 | 2018-12-17 10:02:42 +0000 | [diff] [blame] | 64 | #define MACB_TX_INT_FLAGS (MACB_TX_ERR_FLAGS | MACB_BIT(TCOMP) \ |
| 65 | | MACB_BIT(TXUBR)) |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 66 | |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 67 | /* Max length of transmit frame must be a multiple of 8 bytes */ |
| 68 | #define MACB_TX_LEN_ALIGN 8 |
| 69 | #define MACB_MAX_TX_LEN ((unsigned int)((1 << MACB_TX_FRMLEN_SIZE) - 1) & ~((unsigned int)(MACB_TX_LEN_ALIGN - 1))) |
| 70 | #define GEM_MAX_TX_LEN ((unsigned int)((1 << GEM_TX_FRMLEN_SIZE) - 1) & ~((unsigned int)(MACB_TX_LEN_ALIGN - 1))) |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 71 | |
Jarod Wilson | 44770e1 | 2016-10-17 15:54:17 -0400 | [diff] [blame] | 72 | #define GEM_MTU_MIN_SIZE ETH_MIN_MTU |
David S. Miller | f9c45ae | 2017-07-03 06:31:05 -0700 | [diff] [blame] | 73 | #define MACB_NETIF_LSO NETIF_F_TSO |
Harini Katakam | a5898ea | 2015-05-06 22:27:18 +0530 | [diff] [blame] | 74 | |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 75 | #define MACB_WOL_HAS_MAGIC_PACKET (0x1 << 0) |
| 76 | #define MACB_WOL_ENABLED (0x1 << 1) |
| 77 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 78 | /* Graceful stop timeouts in us. We should allow up to |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 79 | * 1 frame time (10 Mbits/s, full-duplex, ignoring collisions) |
| 80 | */ |
| 81 | #define MACB_HALT_TIMEOUT 1230 |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 82 | |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 83 | /* DMA buffer descriptor might be different size |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 84 | * depends on hardware configuration: |
| 85 | * |
| 86 | * 1. dma address width 32 bits: |
| 87 | * word 1: 32 bit address of Data Buffer |
| 88 | * word 2: control |
| 89 | * |
| 90 | * 2. dma address width 64 bits: |
| 91 | * word 1: 32 bit address of Data Buffer |
| 92 | * word 2: control |
| 93 | * word 3: upper 32 bit address of Data Buffer |
| 94 | * word 4: unused |
| 95 | * |
| 96 | * 3. dma address width 32 bits with hardware timestamping: |
| 97 | * word 1: 32 bit address of Data Buffer |
| 98 | * word 2: control |
| 99 | * word 3: timestamp word 1 |
| 100 | * word 4: timestamp word 2 |
| 101 | * |
| 102 | * 4. dma address width 64 bits with hardware timestamping: |
| 103 | * word 1: 32 bit address of Data Buffer |
| 104 | * word 2: control |
| 105 | * word 3: upper 32 bit address of Data Buffer |
| 106 | * word 4: unused |
| 107 | * word 5: timestamp word 1 |
| 108 | * word 6: timestamp word 2 |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 109 | */ |
| 110 | static unsigned int macb_dma_desc_get_size(struct macb *bp) |
| 111 | { |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 112 | #ifdef MACB_EXT_DESC |
| 113 | unsigned int desc_size; |
| 114 | |
| 115 | switch (bp->hw_dma_cap) { |
| 116 | case HW_DMA_CAP_64B: |
| 117 | desc_size = sizeof(struct macb_dma_desc) |
| 118 | + sizeof(struct macb_dma_desc_64); |
| 119 | break; |
| 120 | case HW_DMA_CAP_PTP: |
| 121 | desc_size = sizeof(struct macb_dma_desc) |
| 122 | + sizeof(struct macb_dma_desc_ptp); |
| 123 | break; |
| 124 | case HW_DMA_CAP_64B_PTP: |
| 125 | desc_size = sizeof(struct macb_dma_desc) |
| 126 | + sizeof(struct macb_dma_desc_64) |
| 127 | + sizeof(struct macb_dma_desc_ptp); |
| 128 | break; |
| 129 | default: |
| 130 | desc_size = sizeof(struct macb_dma_desc); |
| 131 | } |
| 132 | return desc_size; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 133 | #endif |
| 134 | return sizeof(struct macb_dma_desc); |
| 135 | } |
| 136 | |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 137 | static unsigned int macb_adj_dma_desc_idx(struct macb *bp, unsigned int desc_idx) |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 138 | { |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 139 | #ifdef MACB_EXT_DESC |
| 140 | switch (bp->hw_dma_cap) { |
| 141 | case HW_DMA_CAP_64B: |
| 142 | case HW_DMA_CAP_PTP: |
| 143 | desc_idx <<= 1; |
| 144 | break; |
| 145 | case HW_DMA_CAP_64B_PTP: |
| 146 | desc_idx *= 3; |
| 147 | break; |
| 148 | default: |
| 149 | break; |
| 150 | } |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 151 | #endif |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 152 | return desc_idx; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 156 | static struct macb_dma_desc_64 *macb_64b_desc(struct macb *bp, struct macb_dma_desc *desc) |
| 157 | { |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 158 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
| 159 | return (struct macb_dma_desc_64 *)((void *)desc + sizeof(struct macb_dma_desc)); |
| 160 | return NULL; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 161 | } |
| 162 | #endif |
| 163 | |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 164 | /* Ring buffer accessors */ |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 165 | static unsigned int macb_tx_ring_wrap(struct macb *bp, unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 166 | { |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 167 | return index & (bp->tx_ring_size - 1); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 170 | static struct macb_dma_desc *macb_tx_desc(struct macb_queue *queue, |
| 171 | unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 172 | { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 173 | index = macb_tx_ring_wrap(queue->bp, index); |
| 174 | index = macb_adj_dma_desc_idx(queue->bp, index); |
| 175 | return &queue->tx_ring[index]; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 178 | static struct macb_tx_skb *macb_tx_skb(struct macb_queue *queue, |
| 179 | unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 180 | { |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 181 | return &queue->tx_skb[macb_tx_ring_wrap(queue->bp, index)]; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 184 | static dma_addr_t macb_tx_dma(struct macb_queue *queue, unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 185 | { |
| 186 | dma_addr_t offset; |
| 187 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 188 | offset = macb_tx_ring_wrap(queue->bp, index) * |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 189 | macb_dma_desc_get_size(queue->bp); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 190 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 191 | return queue->tx_ring_dma + offset; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 194 | static unsigned int macb_rx_ring_wrap(struct macb *bp, unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 195 | { |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 196 | return index & (bp->rx_ring_size - 1); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 199 | static struct macb_dma_desc *macb_rx_desc(struct macb_queue *queue, unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 200 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 201 | index = macb_rx_ring_wrap(queue->bp, index); |
| 202 | index = macb_adj_dma_desc_idx(queue->bp, index); |
| 203 | return &queue->rx_ring[index]; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 206 | static void *macb_rx_buffer(struct macb_queue *queue, unsigned int index) |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 207 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 208 | return queue->rx_buffers + queue->bp->rx_buffer_size * |
| 209 | macb_rx_ring_wrap(queue->bp, index); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 212 | /* I/O accessors */ |
| 213 | static u32 hw_readl_native(struct macb *bp, int offset) |
| 214 | { |
| 215 | return __raw_readl(bp->regs + offset); |
| 216 | } |
| 217 | |
| 218 | static void hw_writel_native(struct macb *bp, int offset, u32 value) |
| 219 | { |
| 220 | __raw_writel(value, bp->regs + offset); |
| 221 | } |
| 222 | |
| 223 | static u32 hw_readl(struct macb *bp, int offset) |
| 224 | { |
| 225 | return readl_relaxed(bp->regs + offset); |
| 226 | } |
| 227 | |
| 228 | static void hw_writel(struct macb *bp, int offset, u32 value) |
| 229 | { |
| 230 | writel_relaxed(value, bp->regs + offset); |
| 231 | } |
| 232 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 233 | /* Find the CPU endianness by using the loopback bit of NCR register. When the |
Moritz Fischer | 88023be | 2016-03-29 19:11:15 -0700 | [diff] [blame] | 234 | * CPU is in big endian we need to program swapped mode for management |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 235 | * descriptor access. |
| 236 | */ |
| 237 | static bool hw_is_native_io(void __iomem *addr) |
| 238 | { |
| 239 | u32 value = MACB_BIT(LLB); |
| 240 | |
| 241 | __raw_writel(value, addr + MACB_NCR); |
| 242 | value = __raw_readl(addr + MACB_NCR); |
| 243 | |
| 244 | /* Write 0 back to disable everything */ |
| 245 | __raw_writel(0, addr + MACB_NCR); |
| 246 | |
| 247 | return value == MACB_BIT(LLB); |
| 248 | } |
| 249 | |
| 250 | static bool hw_is_gem(void __iomem *addr, bool native_io) |
| 251 | { |
| 252 | u32 id; |
| 253 | |
| 254 | if (native_io) |
| 255 | id = __raw_readl(addr + MACB_MID); |
| 256 | else |
| 257 | id = readl_relaxed(addr + MACB_MID); |
| 258 | |
| 259 | return MACB_BFEXT(IDNUM, id) >= 0x2; |
| 260 | } |
| 261 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 262 | static void macb_set_hwaddr(struct macb *bp) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 263 | { |
| 264 | u32 bottom; |
| 265 | u16 top; |
| 266 | |
| 267 | bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr)); |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 268 | macb_or_gem_writel(bp, SA1B, bottom); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 269 | top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4))); |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 270 | macb_or_gem_writel(bp, SA1T, top); |
Joachim Eastwood | 3629a6c | 2012-11-11 13:56:28 +0000 | [diff] [blame] | 271 | |
| 272 | /* Clear unused address register sets */ |
| 273 | macb_or_gem_writel(bp, SA2B, 0); |
| 274 | macb_or_gem_writel(bp, SA2T, 0); |
| 275 | macb_or_gem_writel(bp, SA3B, 0); |
| 276 | macb_or_gem_writel(bp, SA3T, 0); |
| 277 | macb_or_gem_writel(bp, SA4B, 0); |
| 278 | macb_or_gem_writel(bp, SA4T, 0); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 281 | static void macb_get_hwaddr(struct macb *bp) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 282 | { |
Joachim Eastwood | d25e78a | 2012-11-07 08:14:51 +0000 | [diff] [blame] | 283 | struct macb_platform_data *pdata; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 284 | u32 bottom; |
| 285 | u16 top; |
| 286 | u8 addr[6]; |
Joachim Eastwood | 17b8bb3 | 2012-11-07 08:14:50 +0000 | [diff] [blame] | 287 | int i; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 288 | |
Jingoo Han | c607a0d | 2013-08-30 14:12:21 +0900 | [diff] [blame] | 289 | pdata = dev_get_platdata(&bp->pdev->dev); |
Joachim Eastwood | d25e78a | 2012-11-07 08:14:51 +0000 | [diff] [blame] | 290 | |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 291 | /* Check all 4 address register for valid address */ |
Joachim Eastwood | 17b8bb3 | 2012-11-07 08:14:50 +0000 | [diff] [blame] | 292 | for (i = 0; i < 4; i++) { |
| 293 | bottom = macb_or_gem_readl(bp, SA1B + i * 8); |
| 294 | top = macb_or_gem_readl(bp, SA1T + i * 8); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 295 | |
Joachim Eastwood | d25e78a | 2012-11-07 08:14:51 +0000 | [diff] [blame] | 296 | if (pdata && pdata->rev_eth_addr) { |
| 297 | addr[5] = bottom & 0xff; |
| 298 | addr[4] = (bottom >> 8) & 0xff; |
| 299 | addr[3] = (bottom >> 16) & 0xff; |
| 300 | addr[2] = (bottom >> 24) & 0xff; |
| 301 | addr[1] = top & 0xff; |
| 302 | addr[0] = (top & 0xff00) >> 8; |
| 303 | } else { |
| 304 | addr[0] = bottom & 0xff; |
| 305 | addr[1] = (bottom >> 8) & 0xff; |
| 306 | addr[2] = (bottom >> 16) & 0xff; |
| 307 | addr[3] = (bottom >> 24) & 0xff; |
| 308 | addr[4] = top & 0xff; |
| 309 | addr[5] = (top >> 8) & 0xff; |
| 310 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 311 | |
Joachim Eastwood | 17b8bb3 | 2012-11-07 08:14:50 +0000 | [diff] [blame] | 312 | if (is_valid_ether_addr(addr)) { |
| 313 | memcpy(bp->dev->dev_addr, addr, sizeof(addr)); |
| 314 | return; |
| 315 | } |
Sven Schnelle | d1d5741 | 2008-06-09 16:33:57 -0700 | [diff] [blame] | 316 | } |
Joachim Eastwood | 17b8bb3 | 2012-11-07 08:14:50 +0000 | [diff] [blame] | 317 | |
Andy Shevchenko | a35919e | 2015-07-24 21:24:01 +0300 | [diff] [blame] | 318 | dev_info(&bp->pdev->dev, "invalid hw address, using random\n"); |
Joachim Eastwood | 17b8bb3 | 2012-11-07 08:14:50 +0000 | [diff] [blame] | 319 | eth_hw_addr_random(bp->dev); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 320 | } |
| 321 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 322 | static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 323 | { |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 324 | struct macb *bp = bus->priv; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 325 | int value; |
| 326 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 327 | macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF) |
| 328 | | MACB_BF(RW, MACB_MAN_READ) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 329 | | MACB_BF(PHYA, mii_id) |
| 330 | | MACB_BF(REGA, regnum) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 331 | | MACB_BF(CODE, MACB_MAN_CODE))); |
| 332 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 333 | /* wait for end of transfer */ |
| 334 | while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR))) |
| 335 | cpu_relax(); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 336 | |
| 337 | value = MACB_BFEXT(DATA, macb_readl(bp, MAN)); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 338 | |
| 339 | return value; |
| 340 | } |
| 341 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 342 | static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum, |
| 343 | u16 value) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 344 | { |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 345 | struct macb *bp = bus->priv; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 346 | |
| 347 | macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF) |
| 348 | | MACB_BF(RW, MACB_MAN_WRITE) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 349 | | MACB_BF(PHYA, mii_id) |
| 350 | | MACB_BF(REGA, regnum) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 351 | | MACB_BF(CODE, MACB_MAN_CODE) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 352 | | MACB_BF(DATA, value))); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 353 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 354 | /* wait for end of transfer */ |
| 355 | while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR))) |
| 356 | cpu_relax(); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 357 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 361 | /** |
| 362 | * macb_set_tx_clk() - Set a clock to a new frequency |
| 363 | * @clk Pointer to the clock to change |
| 364 | * @rate New frequency in Hz |
| 365 | * @dev Pointer to the struct net_device |
| 366 | */ |
| 367 | static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev) |
| 368 | { |
| 369 | long ferr, rate, rate_rounded; |
| 370 | |
Cyrille Pitchen | 93b31f4 | 2015-03-07 07:23:31 +0100 | [diff] [blame] | 371 | if (!clk) |
| 372 | return; |
| 373 | |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 374 | switch (speed) { |
| 375 | case SPEED_10: |
| 376 | rate = 2500000; |
| 377 | break; |
| 378 | case SPEED_100: |
| 379 | rate = 25000000; |
| 380 | break; |
| 381 | case SPEED_1000: |
| 382 | rate = 125000000; |
| 383 | break; |
| 384 | default: |
Soren Brinkmann | 9319e47 | 2013-12-10 20:57:57 -0800 | [diff] [blame] | 385 | return; |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | rate_rounded = clk_round_rate(clk, rate); |
| 389 | if (rate_rounded < 0) |
| 390 | return; |
| 391 | |
| 392 | /* RGMII allows 50 ppm frequency error. Test and warn if this limit |
| 393 | * is not satisfied. |
| 394 | */ |
| 395 | ferr = abs(rate_rounded - rate); |
| 396 | ferr = DIV_ROUND_UP(ferr, rate / 100000); |
| 397 | if (ferr > 5) |
| 398 | netdev_warn(dev, "unable to generate target frequency: %ld Hz\n", |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 399 | rate); |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 400 | |
| 401 | if (clk_set_rate(clk, rate_rounded)) |
| 402 | netdev_err(dev, "adjusting tx_clk failed.\n"); |
| 403 | } |
| 404 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 405 | static void macb_handle_link_change(struct net_device *dev) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 406 | { |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 407 | struct macb *bp = netdev_priv(dev); |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 408 | struct phy_device *phydev = dev->phydev; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 409 | unsigned long flags; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 410 | int status_change = 0; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 411 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 412 | spin_lock_irqsave(&bp->lock, flags); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 413 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 414 | if (phydev->link) { |
| 415 | if ((bp->speed != phydev->speed) || |
| 416 | (bp->duplex != phydev->duplex)) { |
| 417 | u32 reg; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 418 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 419 | reg = macb_readl(bp, NCFGR); |
| 420 | reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD)); |
Patrice Vilchez | 140b755 | 2012-10-31 06:04:50 +0000 | [diff] [blame] | 421 | if (macb_is_gem(bp)) |
| 422 | reg &= ~GEM_BIT(GBE); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 423 | |
| 424 | if (phydev->duplex) |
| 425 | reg |= MACB_BIT(FD); |
Atsushi Nemoto | 179956f | 2008-02-21 22:50:54 +0900 | [diff] [blame] | 426 | if (phydev->speed == SPEED_100) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 427 | reg |= MACB_BIT(SPD); |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 428 | if (phydev->speed == SPEED_1000 && |
| 429 | bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE) |
Patrice Vilchez | 140b755 | 2012-10-31 06:04:50 +0000 | [diff] [blame] | 430 | reg |= GEM_BIT(GBE); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 431 | |
Patrice Vilchez | 140b755 | 2012-10-31 06:04:50 +0000 | [diff] [blame] | 432 | macb_or_gem_writel(bp, NCFGR, reg); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 433 | |
| 434 | bp->speed = phydev->speed; |
| 435 | bp->duplex = phydev->duplex; |
| 436 | status_change = 1; |
| 437 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 438 | } |
| 439 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 440 | if (phydev->link != bp->link) { |
Anton Vorontsov | c8f1568 | 2008-07-22 15:41:24 -0700 | [diff] [blame] | 441 | if (!phydev->link) { |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 442 | bp->speed = 0; |
| 443 | bp->duplex = -1; |
| 444 | } |
| 445 | bp->link = phydev->link; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 446 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 447 | status_change = 1; |
| 448 | } |
| 449 | |
| 450 | spin_unlock_irqrestore(&bp->lock, flags); |
| 451 | |
| 452 | if (status_change) { |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 453 | if (phydev->link) { |
Jaeden Amero | 2c29b23 | 2015-03-12 18:07:54 -0500 | [diff] [blame] | 454 | /* Update the TX clock rate if and only if the link is |
| 455 | * up and there has been a link change. |
| 456 | */ |
| 457 | macb_set_tx_clk(bp->tx_clk, phydev->speed, dev); |
| 458 | |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 459 | netif_carrier_on(dev); |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 460 | netdev_info(dev, "link up (%d/%s)\n", |
| 461 | phydev->speed, |
| 462 | phydev->duplex == DUPLEX_FULL ? |
| 463 | "Full" : "Half"); |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 464 | } else { |
| 465 | netif_carrier_off(dev); |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 466 | netdev_info(dev, "link down\n"); |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 467 | } |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
| 471 | /* based on au1000_eth. c*/ |
| 472 | static int macb_mii_probe(struct net_device *dev) |
| 473 | { |
| 474 | struct macb *bp = netdev_priv(dev); |
Joachim Eastwood | 2dbfdbb9 | 2012-11-11 13:56:27 +0000 | [diff] [blame] | 475 | struct macb_platform_data *pdata; |
Jiri Pirko | 7455a76 | 2010-02-08 05:12:08 +0000 | [diff] [blame] | 476 | struct phy_device *phydev; |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 477 | struct device_node *np; |
| 478 | int phy_irq, ret, i; |
| 479 | |
| 480 | pdata = dev_get_platdata(&bp->pdev->dev); |
| 481 | np = bp->pdev->dev.of_node; |
| 482 | ret = 0; |
| 483 | |
| 484 | if (np) { |
| 485 | if (of_phy_is_fixed_link(np)) { |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 486 | bp->phy_node = of_node_get(np); |
| 487 | } else { |
Brad Mouring | 2105a5d | 2018-03-13 16:32:15 -0500 | [diff] [blame] | 488 | bp->phy_node = of_parse_phandle(np, "phy-handle", 0); |
| 489 | /* fallback to standard phy registration if no |
| 490 | * phy-handle was found nor any phy found during |
| 491 | * dt phy registration |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 492 | */ |
Brad Mouring | 2105a5d | 2018-03-13 16:32:15 -0500 | [diff] [blame] | 493 | if (!bp->phy_node && !phy_find_first(bp->mii_bus)) { |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 494 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
| 495 | struct phy_device *phydev; |
| 496 | |
| 497 | phydev = mdiobus_scan(bp->mii_bus, i); |
| 498 | if (IS_ERR(phydev) && |
| 499 | PTR_ERR(phydev) != -ENODEV) { |
| 500 | ret = PTR_ERR(phydev); |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if (ret) |
| 506 | return -ENODEV; |
| 507 | } |
| 508 | } |
| 509 | } |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 510 | |
Michael Grzeschik | dacdbb4 | 2017-06-23 16:54:10 +0200 | [diff] [blame] | 511 | if (bp->phy_node) { |
| 512 | phydev = of_phy_connect(dev, bp->phy_node, |
| 513 | &macb_handle_link_change, 0, |
| 514 | bp->phy_interface); |
| 515 | if (!phydev) |
| 516 | return -ENODEV; |
| 517 | } else { |
| 518 | phydev = phy_find_first(bp->mii_bus); |
| 519 | if (!phydev) { |
| 520 | netdev_err(dev, "no PHY found\n"); |
| 521 | return -ENXIO; |
Joachim Eastwood | 2dbfdbb9 | 2012-11-11 13:56:27 +0000 | [diff] [blame] | 522 | } |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 523 | |
Michael Grzeschik | dacdbb4 | 2017-06-23 16:54:10 +0200 | [diff] [blame] | 524 | if (pdata) { |
| 525 | if (gpio_is_valid(pdata->phy_irq_pin)) { |
| 526 | ret = devm_gpio_request(&bp->pdev->dev, |
| 527 | pdata->phy_irq_pin, "phy int"); |
| 528 | if (!ret) { |
| 529 | phy_irq = gpio_to_irq(pdata->phy_irq_pin); |
| 530 | phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq; |
| 531 | } |
| 532 | } else { |
| 533 | phydev->irq = PHY_POLL; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* attach the mac to the phy */ |
| 538 | ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, |
| 539 | bp->phy_interface); |
| 540 | if (ret) { |
| 541 | netdev_err(dev, "Could not attach to PHY\n"); |
| 542 | return ret; |
| 543 | } |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 544 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 545 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 546 | /* mask with MAC supported features */ |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 547 | if (macb_is_gem(bp) && bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE) |
Andrew Lunn | 58056c1 | 2018-09-12 01:53:11 +0200 | [diff] [blame] | 548 | phy_set_max_speed(phydev, SPEED_1000); |
Patrice Vilchez | 140b755 | 2012-10-31 06:04:50 +0000 | [diff] [blame] | 549 | else |
Andrew Lunn | 58056c1 | 2018-09-12 01:53:11 +0200 | [diff] [blame] | 550 | phy_set_max_speed(phydev, SPEED_100); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 551 | |
Nathan Sullivan | 222ca8e | 2015-05-22 09:22:10 -0500 | [diff] [blame] | 552 | if (bp->caps & MACB_CAPS_NO_GIGABIT_HALF) |
Andrew Lunn | 41124fa | 2018-09-12 01:53:14 +0200 | [diff] [blame] | 553 | phy_remove_link_mode(phydev, |
| 554 | ETHTOOL_LINK_MODE_1000baseT_Half_BIT); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 555 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 556 | bp->link = 0; |
| 557 | bp->speed = 0; |
| 558 | bp->duplex = -1; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 563 | static int macb_mii_init(struct macb *bp) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 564 | { |
Jamie Iles | 84e0cdb | 2011-03-08 20:17:06 +0000 | [diff] [blame] | 565 | struct macb_platform_data *pdata; |
Boris BREZILLON | 148cbb5 | 2013-08-22 17:57:28 +0200 | [diff] [blame] | 566 | struct device_node *np; |
Ahmad Fatoum | ab5f110 | 2018-08-21 17:35:48 +0200 | [diff] [blame] | 567 | int err = -ENXIO; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 568 | |
Uwe Kleine-Koenig | 3dbda77 | 2009-07-23 08:31:31 +0200 | [diff] [blame] | 569 | /* Enable management port */ |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 570 | macb_writel(bp, NCR, MACB_BIT(MPE)); |
| 571 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 572 | bp->mii_bus = mdiobus_alloc(); |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 573 | if (!bp->mii_bus) { |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 574 | err = -ENOMEM; |
| 575 | goto err_out; |
| 576 | } |
| 577 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 578 | bp->mii_bus->name = "MACB_mii_bus"; |
| 579 | bp->mii_bus->read = &macb_mdio_read; |
| 580 | bp->mii_bus->write = &macb_mdio_write; |
Florian Fainelli | 98d5e57 | 2012-01-09 23:59:11 +0000 | [diff] [blame] | 581 | snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 582 | bp->pdev->name, bp->pdev->id); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 583 | bp->mii_bus->priv = bp; |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 584 | bp->mii_bus->parent = &bp->pdev->dev; |
Jingoo Han | c607a0d | 2013-08-30 14:12:21 +0900 | [diff] [blame] | 585 | pdata = dev_get_platdata(&bp->pdev->dev); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 586 | |
Jamie Iles | 9152394 | 2011-02-28 04:05:25 +0000 | [diff] [blame] | 587 | dev_set_drvdata(&bp->dev->dev, bp->mii_bus); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 588 | |
Boris BREZILLON | 148cbb5 | 2013-08-22 17:57:28 +0200 | [diff] [blame] | 589 | np = bp->pdev->dev.of_node; |
Ahmad Fatoum | ab5f110 | 2018-08-21 17:35:48 +0200 | [diff] [blame] | 590 | if (np && of_phy_is_fixed_link(np)) { |
| 591 | if (of_phy_register_fixed_link(np) < 0) { |
| 592 | dev_err(&bp->pdev->dev, |
| 593 | "broken fixed-link specification %pOF\n", np); |
| 594 | goto err_out_free_mdiobus; |
| 595 | } |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 596 | |
Ahmad Fatoum | ab5f110 | 2018-08-21 17:35:48 +0200 | [diff] [blame] | 597 | err = mdiobus_register(bp->mii_bus); |
| 598 | } else { |
| 599 | if (pdata) |
| 600 | bp->mii_bus->phy_mask = pdata->phy_mask; |
| 601 | |
| 602 | err = of_mdiobus_register(bp->mii_bus, np); |
| 603 | } |
| 604 | |
Boris BREZILLON | 148cbb5 | 2013-08-22 17:57:28 +0200 | [diff] [blame] | 605 | if (err) |
Ahmad Fatoum | ab5f110 | 2018-08-21 17:35:48 +0200 | [diff] [blame] | 606 | goto err_out_free_fixed_link; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 607 | |
Boris BREZILLON | 7daa78e | 2013-08-27 14:36:14 +0200 | [diff] [blame] | 608 | err = macb_mii_probe(bp->dev); |
| 609 | if (err) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 610 | goto err_out_unregister_bus; |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 611 | |
| 612 | return 0; |
| 613 | |
| 614 | err_out_unregister_bus: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 615 | mdiobus_unregister(bp->mii_bus); |
Ahmad Fatoum | ab5f110 | 2018-08-21 17:35:48 +0200 | [diff] [blame] | 616 | err_out_free_fixed_link: |
Michael Grzeschik | 9ce9814 | 2017-11-08 09:56:34 +0100 | [diff] [blame] | 617 | if (np && of_phy_is_fixed_link(np)) |
| 618 | of_phy_deregister_fixed_link(np); |
Brad Mouring | 739de9a | 2018-03-13 16:32:13 -0500 | [diff] [blame] | 619 | err_out_free_mdiobus: |
| 620 | of_node_put(bp->phy_node); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 621 | mdiobus_free(bp->mii_bus); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 622 | err_out: |
| 623 | return err; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static void macb_update_stats(struct macb *bp) |
| 627 | { |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 628 | u32 *p = &bp->hw_stats.macb.rx_pause_frames; |
| 629 | u32 *end = &bp->hw_stats.macb.tx_pause_frames + 1; |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 630 | int offset = MACB_PFR; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 631 | |
| 632 | WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4); |
| 633 | |
Moritz Fischer | 96ec631 | 2016-03-29 19:11:11 -0700 | [diff] [blame] | 634 | for (; p < end; p++, offset += 4) |
David S. Miller | 7a6e070 | 2015-07-27 14:24:48 -0700 | [diff] [blame] | 635 | *p += bp->macb_reg_readl(bp, offset); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 638 | static int macb_halt_tx(struct macb *bp) |
| 639 | { |
| 640 | unsigned long halt_time, timeout; |
| 641 | u32 status; |
| 642 | |
| 643 | macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(THALT)); |
| 644 | |
| 645 | timeout = jiffies + usecs_to_jiffies(MACB_HALT_TIMEOUT); |
| 646 | do { |
| 647 | halt_time = jiffies; |
| 648 | status = macb_readl(bp, TSR); |
| 649 | if (!(status & MACB_BIT(TGO))) |
| 650 | return 0; |
| 651 | |
Jia-Ju Bai | 16fe10c | 2018-09-01 20:11:05 +0800 | [diff] [blame] | 652 | udelay(250); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 653 | } while (time_before(halt_time, timeout)); |
| 654 | |
| 655 | return -ETIMEDOUT; |
| 656 | } |
| 657 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 658 | static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb) |
| 659 | { |
| 660 | if (tx_skb->mapping) { |
| 661 | if (tx_skb->mapped_as_page) |
| 662 | dma_unmap_page(&bp->pdev->dev, tx_skb->mapping, |
| 663 | tx_skb->size, DMA_TO_DEVICE); |
| 664 | else |
| 665 | dma_unmap_single(&bp->pdev->dev, tx_skb->mapping, |
| 666 | tx_skb->size, DMA_TO_DEVICE); |
| 667 | tx_skb->mapping = 0; |
| 668 | } |
| 669 | |
| 670 | if (tx_skb->skb) { |
| 671 | dev_kfree_skb_any(tx_skb->skb); |
| 672 | tx_skb->skb = NULL; |
| 673 | } |
| 674 | } |
| 675 | |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 676 | static void macb_set_addr(struct macb *bp, struct macb_dma_desc *desc, dma_addr_t addr) |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 677 | { |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 678 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 679 | struct macb_dma_desc_64 *desc_64; |
| 680 | |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 681 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 682 | desc_64 = macb_64b_desc(bp, desc); |
| 683 | desc_64->addrh = upper_32_bits(addr); |
Anssi Hannula | e100a89 | 2018-12-17 15:05:39 +0200 | [diff] [blame^] | 684 | /* The low bits of RX address contain the RX_USED bit, clearing |
| 685 | * of which allows packet RX. Make sure the high bits are also |
| 686 | * visible to HW at that point. |
| 687 | */ |
| 688 | dma_wmb(); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 689 | } |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 690 | #endif |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 691 | desc->addr = lower_32_bits(addr); |
| 692 | } |
| 693 | |
| 694 | static dma_addr_t macb_get_addr(struct macb *bp, struct macb_dma_desc *desc) |
| 695 | { |
| 696 | dma_addr_t addr = 0; |
| 697 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 698 | struct macb_dma_desc_64 *desc_64; |
| 699 | |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 700 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 701 | desc_64 = macb_64b_desc(bp, desc); |
| 702 | addr = ((u64)(desc_64->addrh) << 32); |
| 703 | } |
| 704 | #endif |
| 705 | addr |= MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr)); |
| 706 | return addr; |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 707 | } |
| 708 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 709 | static void macb_tx_error_task(struct work_struct *work) |
| 710 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 711 | struct macb_queue *queue = container_of(work, struct macb_queue, |
| 712 | tx_error_task); |
| 713 | struct macb *bp = queue->bp; |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 714 | struct macb_tx_skb *tx_skb; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 715 | struct macb_dma_desc *desc; |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 716 | struct sk_buff *skb; |
| 717 | unsigned int tail; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 718 | unsigned long flags; |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 719 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 720 | netdev_vdbg(bp->dev, "macb_tx_error_task: q = %u, t = %u, h = %u\n", |
| 721 | (unsigned int)(queue - bp->queues), |
| 722 | queue->tx_tail, queue->tx_head); |
| 723 | |
| 724 | /* Prevent the queue IRQ handlers from running: each of them may call |
| 725 | * macb_tx_interrupt(), which in turn may call netif_wake_subqueue(). |
| 726 | * As explained below, we have to halt the transmission before updating |
| 727 | * TBQP registers so we call netif_tx_stop_all_queues() to notify the |
| 728 | * network engine about the macb/gem being halted. |
| 729 | */ |
| 730 | spin_lock_irqsave(&bp->lock, flags); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 731 | |
| 732 | /* Make sure nobody is trying to queue up new packets */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 733 | netif_tx_stop_all_queues(bp->dev); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 734 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 735 | /* Stop transmission now |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 736 | * (in case we have just queued new packets) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 737 | * macb/gem must be halted to write TBQP register |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 738 | */ |
| 739 | if (macb_halt_tx(bp)) |
| 740 | /* Just complain for now, reinitializing TX path can be good */ |
| 741 | netdev_err(bp->dev, "BUG: halt tx timed out\n"); |
| 742 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 743 | /* Treat frames in TX queue including the ones that caused the error. |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 744 | * Free transmit buffers in upper layer. |
| 745 | */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 746 | for (tail = queue->tx_tail; tail != queue->tx_head; tail++) { |
| 747 | u32 ctrl; |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 748 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 749 | desc = macb_tx_desc(queue, tail); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 750 | ctrl = desc->ctrl; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 751 | tx_skb = macb_tx_skb(queue, tail); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 752 | skb = tx_skb->skb; |
| 753 | |
| 754 | if (ctrl & MACB_BIT(TX_USED)) { |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 755 | /* skb is set for the last buffer of the frame */ |
| 756 | while (!skb) { |
| 757 | macb_tx_unmap(bp, tx_skb); |
| 758 | tail++; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 759 | tx_skb = macb_tx_skb(queue, tail); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 760 | skb = tx_skb->skb; |
| 761 | } |
| 762 | |
| 763 | /* ctrl still refers to the first buffer descriptor |
| 764 | * since it's the only one written back by the hardware |
| 765 | */ |
| 766 | if (!(ctrl & MACB_BIT(TX_BUF_EXHAUSTED))) { |
| 767 | netdev_vdbg(bp->dev, "txerr skb %u (data %p) TX complete\n", |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 768 | macb_tx_ring_wrap(bp, tail), |
| 769 | skb->data); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 770 | bp->dev->stats.tx_packets++; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 771 | queue->stats.tx_packets++; |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 772 | bp->dev->stats.tx_bytes += skb->len; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 773 | queue->stats.tx_bytes += skb->len; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 774 | } |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 775 | } else { |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 776 | /* "Buffers exhausted mid-frame" errors may only happen |
| 777 | * if the driver is buggy, so complain loudly about |
| 778 | * those. Statistics are updated by hardware. |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 779 | */ |
| 780 | if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED)) |
| 781 | netdev_err(bp->dev, |
| 782 | "BUG: TX buffers exhausted mid-frame\n"); |
| 783 | |
| 784 | desc->ctrl = ctrl | MACB_BIT(TX_USED); |
| 785 | } |
| 786 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 787 | macb_tx_unmap(bp, tx_skb); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 790 | /* Set end of TX queue */ |
| 791 | desc = macb_tx_desc(queue, 0); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 792 | macb_set_addr(bp, desc, 0); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 793 | desc->ctrl = MACB_BIT(TX_USED); |
| 794 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 795 | /* Make descriptor updates visible to hardware */ |
| 796 | wmb(); |
| 797 | |
| 798 | /* Reinitialize the TX desc queue */ |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 799 | queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 800 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 801 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 802 | queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma)); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 803 | #endif |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 804 | /* Make TX ring reflect state of hardware */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 805 | queue->tx_head = 0; |
| 806 | queue->tx_tail = 0; |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 807 | |
| 808 | /* Housework before enabling TX IRQ */ |
| 809 | macb_writel(bp, TSR, macb_readl(bp, TSR)); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 810 | queue_writel(queue, IER, MACB_TX_INT_FLAGS); |
| 811 | |
| 812 | /* Now we are ready to start transmission again */ |
| 813 | netif_tx_start_all_queues(bp->dev); |
| 814 | macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); |
| 815 | |
| 816 | spin_unlock_irqrestore(&bp->lock, flags); |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 819 | static void macb_tx_interrupt(struct macb_queue *queue) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 820 | { |
| 821 | unsigned int tail; |
| 822 | unsigned int head; |
| 823 | u32 status; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 824 | struct macb *bp = queue->bp; |
| 825 | u16 queue_index = queue - bp->queues; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 826 | |
| 827 | status = macb_readl(bp, TSR); |
| 828 | macb_writel(bp, TSR, status); |
| 829 | |
Nicolas Ferre | 581df9e | 2013-05-14 03:00:16 +0000 | [diff] [blame] | 830 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 831 | queue_writel(queue, ISR, MACB_BIT(TCOMP)); |
Steffen Trumtrar | 749a2b6 | 2013-03-27 23:07:05 +0000 | [diff] [blame] | 832 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 833 | netdev_vdbg(bp->dev, "macb_tx_interrupt status = 0x%03lx\n", |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 834 | (unsigned long)status); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 835 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 836 | head = queue->tx_head; |
| 837 | for (tail = queue->tx_tail; tail != head; tail++) { |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 838 | struct macb_tx_skb *tx_skb; |
| 839 | struct sk_buff *skb; |
| 840 | struct macb_dma_desc *desc; |
| 841 | u32 ctrl; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 842 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 843 | desc = macb_tx_desc(queue, tail); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 844 | |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 845 | /* Make hw descriptor updates visible to CPU */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 846 | rmb(); |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 847 | |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 848 | ctrl = desc->ctrl; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 849 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 850 | /* TX_USED bit is only set by hardware on the very first buffer |
| 851 | * descriptor of the transmitted frame. |
| 852 | */ |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 853 | if (!(ctrl & MACB_BIT(TX_USED))) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 854 | break; |
| 855 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 856 | /* Process all buffers of the current transmitted frame */ |
| 857 | for (;; tail++) { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 858 | tx_skb = macb_tx_skb(queue, tail); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 859 | skb = tx_skb->skb; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 860 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 861 | /* First, update TX stats if needed */ |
| 862 | if (skb) { |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 863 | if (gem_ptp_do_txstamp(queue, skb, desc) == 0) { |
| 864 | /* skb now belongs to timestamp buffer |
| 865 | * and will be removed later |
| 866 | */ |
| 867 | tx_skb->skb = NULL; |
| 868 | } |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 869 | netdev_vdbg(bp->dev, "skb %u (data %p) TX complete\n", |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 870 | macb_tx_ring_wrap(bp, tail), |
| 871 | skb->data); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 872 | bp->dev->stats.tx_packets++; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 873 | queue->stats.tx_packets++; |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 874 | bp->dev->stats.tx_bytes += skb->len; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 875 | queue->stats.tx_bytes += skb->len; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | /* Now we can safely release resources */ |
| 879 | macb_tx_unmap(bp, tx_skb); |
| 880 | |
| 881 | /* skb is set only for the last buffer of the frame. |
| 882 | * WARNING: at this point skb has been freed by |
| 883 | * macb_tx_unmap(). |
| 884 | */ |
| 885 | if (skb) |
| 886 | break; |
| 887 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 888 | } |
| 889 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 890 | queue->tx_tail = tail; |
| 891 | if (__netif_subqueue_stopped(bp->dev, queue_index) && |
| 892 | CIRC_CNT(queue->tx_head, queue->tx_tail, |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 893 | bp->tx_ring_size) <= MACB_TX_WAKEUP_THRESH(bp)) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 894 | netif_wake_subqueue(bp->dev, queue_index); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 897 | static void gem_rx_refill(struct macb_queue *queue) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 898 | { |
| 899 | unsigned int entry; |
| 900 | struct sk_buff *skb; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 901 | dma_addr_t paddr; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 902 | struct macb *bp = queue->bp; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 903 | struct macb_dma_desc *desc; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 904 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 905 | while (CIRC_SPACE(queue->rx_prepared_head, queue->rx_tail, |
| 906 | bp->rx_ring_size) > 0) { |
| 907 | entry = macb_rx_ring_wrap(bp, queue->rx_prepared_head); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 908 | |
| 909 | /* Make hw descriptor updates visible to CPU */ |
| 910 | rmb(); |
| 911 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 912 | queue->rx_prepared_head++; |
| 913 | desc = macb_rx_desc(queue, entry); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 914 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 915 | if (!queue->rx_skbuff[entry]) { |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 916 | /* allocate sk_buff for this free entry in ring */ |
| 917 | skb = netdev_alloc_skb(bp->dev, bp->rx_buffer_size); |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 918 | if (unlikely(!skb)) { |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 919 | netdev_err(bp->dev, |
| 920 | "Unable to allocate sk_buff\n"); |
| 921 | break; |
| 922 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 923 | |
| 924 | /* now fill corresponding descriptor entry */ |
| 925 | paddr = dma_map_single(&bp->pdev->dev, skb->data, |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 926 | bp->rx_buffer_size, |
| 927 | DMA_FROM_DEVICE); |
Soren Brinkmann | 9203090 | 2014-03-04 08:46:39 -0800 | [diff] [blame] | 928 | if (dma_mapping_error(&bp->pdev->dev, paddr)) { |
| 929 | dev_kfree_skb(skb); |
| 930 | break; |
| 931 | } |
| 932 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 933 | queue->rx_skbuff[entry] = skb; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 934 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 935 | if (entry == bp->rx_ring_size - 1) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 936 | paddr |= MACB_BIT(RX_WRAP); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 937 | macb_set_addr(bp, desc, paddr); |
| 938 | desc->ctrl = 0; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 939 | |
| 940 | /* properly align Ethernet header */ |
| 941 | skb_reserve(skb, NET_IP_ALIGN); |
Punnaiah Choudary Kalluri | d4c216c | 2015-04-29 08:34:46 +0530 | [diff] [blame] | 942 | } else { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 943 | desc->addr &= ~MACB_BIT(RX_USED); |
| 944 | desc->ctrl = 0; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | /* Make descriptor updates visible to hardware */ |
| 949 | wmb(); |
| 950 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 951 | netdev_vdbg(bp->dev, "rx ring: queue: %p, prepared head %d, tail %d\n", |
| 952 | queue, queue->rx_prepared_head, queue->rx_tail); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /* Mark DMA descriptors from begin up to and not including end as unused */ |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 956 | static void discard_partial_frame(struct macb_queue *queue, unsigned int begin, |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 957 | unsigned int end) |
| 958 | { |
| 959 | unsigned int frag; |
| 960 | |
| 961 | for (frag = begin; frag != end; frag++) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 962 | struct macb_dma_desc *desc = macb_rx_desc(queue, frag); |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 963 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 964 | desc->addr &= ~MACB_BIT(RX_USED); |
| 965 | } |
| 966 | |
| 967 | /* Make descriptor updates visible to hardware */ |
| 968 | wmb(); |
| 969 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 970 | /* When this happens, the hardware stats registers for |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 971 | * whatever caused this is updated, so we don't have to record |
| 972 | * anything. |
| 973 | */ |
| 974 | } |
| 975 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 976 | static int gem_rx(struct macb_queue *queue, int budget) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 977 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 978 | struct macb *bp = queue->bp; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 979 | unsigned int len; |
| 980 | unsigned int entry; |
| 981 | struct sk_buff *skb; |
| 982 | struct macb_dma_desc *desc; |
| 983 | int count = 0; |
| 984 | |
| 985 | while (count < budget) { |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 986 | u32 ctrl; |
| 987 | dma_addr_t addr; |
| 988 | bool rxused; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 989 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 990 | entry = macb_rx_ring_wrap(bp, queue->rx_tail); |
| 991 | desc = macb_rx_desc(queue, entry); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 992 | |
| 993 | /* Make hw descriptor updates visible to CPU */ |
| 994 | rmb(); |
| 995 | |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 996 | rxused = (desc->addr & MACB_BIT(RX_USED)) ? true : false; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 997 | addr = macb_get_addr(bp, desc); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 998 | ctrl = desc->ctrl; |
| 999 | |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 1000 | if (!rxused) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1003 | queue->rx_tail++; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1004 | count++; |
| 1005 | |
| 1006 | if (!(ctrl & MACB_BIT(RX_SOF) && ctrl & MACB_BIT(RX_EOF))) { |
| 1007 | netdev_err(bp->dev, |
| 1008 | "not whole frame pointed by descriptor\n"); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1009 | bp->dev->stats.rx_dropped++; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 1010 | queue->stats.rx_dropped++; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1011 | break; |
| 1012 | } |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1013 | skb = queue->rx_skbuff[entry]; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1014 | if (unlikely(!skb)) { |
| 1015 | netdev_err(bp->dev, |
| 1016 | "inconsistent Rx descriptor chain\n"); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1017 | bp->dev->stats.rx_dropped++; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 1018 | queue->stats.rx_dropped++; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | /* now everything is ready for receiving packet */ |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1022 | queue->rx_skbuff[entry] = NULL; |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 1023 | len = ctrl & bp->rx_frm_len_mask; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1024 | |
| 1025 | netdev_vdbg(bp->dev, "gem_rx %u (len %u)\n", entry, len); |
| 1026 | |
| 1027 | skb_put(skb, len); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1028 | dma_unmap_single(&bp->pdev->dev, addr, |
Soren Brinkmann | 48330e08 | 2014-03-04 08:46:40 -0800 | [diff] [blame] | 1029 | bp->rx_buffer_size, DMA_FROM_DEVICE); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1030 | |
| 1031 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1032 | skb_checksum_none_assert(skb); |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 1033 | if (bp->dev->features & NETIF_F_RXCSUM && |
| 1034 | !(bp->dev->flags & IFF_PROMISC) && |
| 1035 | GEM_BFEXT(RX_CSUM, ctrl) & GEM_RX_CSUM_CHECKED_MASK) |
| 1036 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1037 | |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1038 | bp->dev->stats.rx_packets++; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 1039 | queue->stats.rx_packets++; |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1040 | bp->dev->stats.rx_bytes += skb->len; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 1041 | queue->stats.rx_bytes += skb->len; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1042 | |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 1043 | gem_ptp_do_rxstamp(bp, skb, desc); |
| 1044 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1045 | #if defined(DEBUG) && defined(VERBOSE_DEBUG) |
| 1046 | netdev_vdbg(bp->dev, "received skb of length %u, csum: %08x\n", |
| 1047 | skb->len, skb->csum); |
| 1048 | print_hex_dump(KERN_DEBUG, " mac: ", DUMP_PREFIX_ADDRESS, 16, 1, |
Cyrille Pitchen | 51f8301 | 2014-12-11 11:15:54 +0100 | [diff] [blame] | 1049 | skb_mac_header(skb), 16, true); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1050 | print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_ADDRESS, 16, 1, |
| 1051 | skb->data, 32, true); |
| 1052 | #endif |
| 1053 | |
| 1054 | netif_receive_skb(skb); |
| 1055 | } |
| 1056 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1057 | gem_rx_refill(queue); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1058 | |
| 1059 | return count; |
| 1060 | } |
| 1061 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1062 | static int macb_rx_frame(struct macb_queue *queue, unsigned int first_frag, |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1063 | unsigned int last_frag) |
| 1064 | { |
| 1065 | unsigned int len; |
| 1066 | unsigned int frag; |
Havard Skinnemoen | 29bc2e1 | 2012-10-31 06:04:58 +0000 | [diff] [blame] | 1067 | unsigned int offset; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1068 | struct sk_buff *skb; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1069 | struct macb_dma_desc *desc; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1070 | struct macb *bp = queue->bp; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1071 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1072 | desc = macb_rx_desc(queue, last_frag); |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 1073 | len = desc->ctrl & bp->rx_frm_len_mask; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1074 | |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1075 | netdev_vdbg(bp->dev, "macb_rx_frame frags %u - %u (len %u)\n", |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1076 | macb_rx_ring_wrap(bp, first_frag), |
| 1077 | macb_rx_ring_wrap(bp, last_frag), len); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1078 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 1079 | /* The ethernet header starts NET_IP_ALIGN bytes into the |
Havard Skinnemoen | 29bc2e1 | 2012-10-31 06:04:58 +0000 | [diff] [blame] | 1080 | * first buffer. Since the header is 14 bytes, this makes the |
| 1081 | * payload word-aligned. |
| 1082 | * |
| 1083 | * Instead of calling skb_reserve(NET_IP_ALIGN), we just copy |
| 1084 | * the two padding bytes into the skb so that we avoid hitting |
| 1085 | * the slowpath in memcpy(), and pull them off afterwards. |
| 1086 | */ |
| 1087 | skb = netdev_alloc_skb(bp->dev, len + NET_IP_ALIGN); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1088 | if (!skb) { |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1089 | bp->dev->stats.rx_dropped++; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1090 | for (frag = first_frag; ; frag++) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1091 | desc = macb_rx_desc(queue, frag); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1092 | desc->addr &= ~MACB_BIT(RX_USED); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1093 | if (frag == last_frag) |
| 1094 | break; |
| 1095 | } |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1096 | |
| 1097 | /* Make descriptor updates visible to hardware */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1098 | wmb(); |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1099 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1100 | return 1; |
| 1101 | } |
| 1102 | |
Havard Skinnemoen | 29bc2e1 | 2012-10-31 06:04:58 +0000 | [diff] [blame] | 1103 | offset = 0; |
| 1104 | len += NET_IP_ALIGN; |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1105 | skb_checksum_none_assert(skb); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1106 | skb_put(skb, len); |
| 1107 | |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1108 | for (frag = first_frag; ; frag++) { |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1109 | unsigned int frag_len = bp->rx_buffer_size; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1110 | |
| 1111 | if (offset + frag_len > len) { |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1112 | if (unlikely(frag != last_frag)) { |
| 1113 | dev_kfree_skb_any(skb); |
| 1114 | return -1; |
| 1115 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1116 | frag_len = len - offset; |
| 1117 | } |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1118 | skb_copy_to_linear_data_offset(skb, offset, |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1119 | macb_rx_buffer(queue, frag), |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1120 | frag_len); |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1121 | offset += bp->rx_buffer_size; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1122 | desc = macb_rx_desc(queue, frag); |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1123 | desc->addr &= ~MACB_BIT(RX_USED); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1124 | |
| 1125 | if (frag == last_frag) |
| 1126 | break; |
| 1127 | } |
| 1128 | |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1129 | /* Make descriptor updates visible to hardware */ |
| 1130 | wmb(); |
| 1131 | |
Havard Skinnemoen | 29bc2e1 | 2012-10-31 06:04:58 +0000 | [diff] [blame] | 1132 | __skb_pull(skb, NET_IP_ALIGN); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1133 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1134 | |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 1135 | bp->dev->stats.rx_packets++; |
| 1136 | bp->dev->stats.rx_bytes += skb->len; |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1137 | netdev_vdbg(bp->dev, "received skb of length %u, csum: %08x\n", |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1138 | skb->len, skb->csum); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1139 | netif_receive_skb(skb); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1144 | static inline void macb_init_rx_ring(struct macb_queue *queue) |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1145 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1146 | struct macb *bp = queue->bp; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1147 | dma_addr_t addr; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1148 | struct macb_dma_desc *desc = NULL; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1149 | int i; |
| 1150 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1151 | addr = queue->rx_buffers_dma; |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1152 | for (i = 0; i < bp->rx_ring_size; i++) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1153 | desc = macb_rx_desc(queue, i); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1154 | macb_set_addr(bp, desc, addr); |
| 1155 | desc->ctrl = 0; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1156 | addr += bp->rx_buffer_size; |
| 1157 | } |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1158 | desc->addr |= MACB_BIT(RX_WRAP); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1159 | queue->rx_tail = 0; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1162 | static int macb_rx(struct macb_queue *queue, int budget) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1163 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1164 | struct macb *bp = queue->bp; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1165 | bool reset_rx_queue = false; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1166 | int received = 0; |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1167 | unsigned int tail; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1168 | int first_frag = -1; |
| 1169 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1170 | for (tail = queue->rx_tail; budget > 0; tail++) { |
| 1171 | struct macb_dma_desc *desc = macb_rx_desc(queue, tail); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1172 | u32 ctrl; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1173 | |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1174 | /* Make hw descriptor updates visible to CPU */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1175 | rmb(); |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1176 | |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1177 | ctrl = desc->ctrl; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1178 | |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1179 | if (!(desc->addr & MACB_BIT(RX_USED))) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1180 | break; |
| 1181 | |
| 1182 | if (ctrl & MACB_BIT(RX_SOF)) { |
| 1183 | if (first_frag != -1) |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1184 | discard_partial_frame(queue, first_frag, tail); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1185 | first_frag = tail; |
| 1186 | } |
| 1187 | |
| 1188 | if (ctrl & MACB_BIT(RX_EOF)) { |
| 1189 | int dropped; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1190 | |
| 1191 | if (unlikely(first_frag == -1)) { |
| 1192 | reset_rx_queue = true; |
| 1193 | continue; |
| 1194 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1195 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1196 | dropped = macb_rx_frame(queue, first_frag, tail); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1197 | first_frag = -1; |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1198 | if (unlikely(dropped < 0)) { |
| 1199 | reset_rx_queue = true; |
| 1200 | continue; |
| 1201 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1202 | if (!dropped) { |
| 1203 | received++; |
| 1204 | budget--; |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1209 | if (unlikely(reset_rx_queue)) { |
| 1210 | unsigned long flags; |
| 1211 | u32 ctrl; |
| 1212 | |
| 1213 | netdev_err(bp->dev, "RX queue corruption: reset it\n"); |
| 1214 | |
| 1215 | spin_lock_irqsave(&bp->lock, flags); |
| 1216 | |
| 1217 | ctrl = macb_readl(bp, NCR); |
| 1218 | macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE)); |
| 1219 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1220 | macb_init_rx_ring(queue); |
| 1221 | queue_writel(queue, RBQP, queue->rx_ring_dma); |
Cyrille Pitchen | 9ba723b | 2016-03-25 10:37:34 +0100 | [diff] [blame] | 1222 | |
| 1223 | macb_writel(bp, NCR, ctrl | MACB_BIT(RE)); |
| 1224 | |
| 1225 | spin_unlock_irqrestore(&bp->lock, flags); |
| 1226 | return received; |
| 1227 | } |
| 1228 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1229 | if (first_frag != -1) |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1230 | queue->rx_tail = first_frag; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1231 | else |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1232 | queue->rx_tail = tail; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1233 | |
| 1234 | return received; |
| 1235 | } |
| 1236 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1237 | static int macb_poll(struct napi_struct *napi, int budget) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1238 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1239 | struct macb_queue *queue = container_of(napi, struct macb_queue, napi); |
| 1240 | struct macb *bp = queue->bp; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1241 | int work_done; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1242 | u32 status; |
| 1243 | |
| 1244 | status = macb_readl(bp, RSR); |
| 1245 | macb_writel(bp, RSR, status); |
| 1246 | |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1247 | netdev_vdbg(bp->dev, "poll: status = %08lx, budget = %d\n", |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1248 | (unsigned long)status, budget); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1249 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1250 | work_done = bp->macbgem_ops.mog_rx(queue, budget); |
Joshua Hoke | b336369 | 2010-10-25 01:44:22 +0000 | [diff] [blame] | 1251 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 1252 | napi_complete_done(napi, work_done); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1253 | |
Nicolas Ferre | 8770e91 | 2013-02-12 11:08:48 +0100 | [diff] [blame] | 1254 | /* Packets received while interrupts were disabled */ |
| 1255 | status = macb_readl(bp, RSR); |
Soren Brinkmann | 504ad98 | 2014-05-04 15:43:01 -0700 | [diff] [blame] | 1256 | if (status) { |
Soren Brinkmann | 02f7a34 | 2014-05-04 15:43:00 -0700 | [diff] [blame] | 1257 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1258 | queue_writel(queue, ISR, MACB_BIT(RCOMP)); |
Nicolas Ferre | 8770e91 | 2013-02-12 11:08:48 +0100 | [diff] [blame] | 1259 | napi_reschedule(napi); |
Soren Brinkmann | 02f7a34 | 2014-05-04 15:43:00 -0700 | [diff] [blame] | 1260 | } else { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1261 | queue_writel(queue, IER, MACB_RX_INT_FLAGS); |
Soren Brinkmann | 02f7a34 | 2014-05-04 15:43:00 -0700 | [diff] [blame] | 1262 | } |
Joshua Hoke | b336369 | 2010-10-25 01:44:22 +0000 | [diff] [blame] | 1263 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1264 | |
| 1265 | /* TODO: Handle errors */ |
| 1266 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1267 | return work_done; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Harini Katakam | 032dc41 | 2018-01-27 12:09:01 +0530 | [diff] [blame] | 1270 | static void macb_hresp_error_task(unsigned long data) |
| 1271 | { |
| 1272 | struct macb *bp = (struct macb *)data; |
| 1273 | struct net_device *dev = bp->dev; |
| 1274 | struct macb_queue *queue = bp->queues; |
| 1275 | unsigned int q; |
| 1276 | u32 ctrl; |
| 1277 | |
| 1278 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 1279 | queue_writel(queue, IDR, MACB_RX_INT_FLAGS | |
| 1280 | MACB_TX_INT_FLAGS | |
| 1281 | MACB_BIT(HRESP)); |
| 1282 | } |
| 1283 | ctrl = macb_readl(bp, NCR); |
| 1284 | ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE)); |
| 1285 | macb_writel(bp, NCR, ctrl); |
| 1286 | |
| 1287 | netif_tx_stop_all_queues(dev); |
| 1288 | netif_carrier_off(dev); |
| 1289 | |
| 1290 | bp->macbgem_ops.mog_init_rings(bp); |
| 1291 | |
| 1292 | /* Initialize TX and RX buffers */ |
| 1293 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 1294 | queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma)); |
| 1295 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 1296 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
| 1297 | queue_writel(queue, RBQPH, |
| 1298 | upper_32_bits(queue->rx_ring_dma)); |
| 1299 | #endif |
| 1300 | queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); |
| 1301 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 1302 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
| 1303 | queue_writel(queue, TBQPH, |
| 1304 | upper_32_bits(queue->tx_ring_dma)); |
| 1305 | #endif |
| 1306 | |
| 1307 | /* Enable interrupts */ |
| 1308 | queue_writel(queue, IER, |
| 1309 | MACB_RX_INT_FLAGS | |
| 1310 | MACB_TX_INT_FLAGS | |
| 1311 | MACB_BIT(HRESP)); |
| 1312 | } |
| 1313 | |
| 1314 | ctrl |= MACB_BIT(RE) | MACB_BIT(TE); |
| 1315 | macb_writel(bp, NCR, ctrl); |
| 1316 | |
| 1317 | netif_carrier_on(dev); |
| 1318 | netif_tx_start_all_queues(dev); |
| 1319 | } |
| 1320 | |
Claudiu Beznea | 4298388 | 2018-12-17 10:02:42 +0000 | [diff] [blame] | 1321 | static void macb_tx_restart(struct macb_queue *queue) |
| 1322 | { |
| 1323 | unsigned int head = queue->tx_head; |
| 1324 | unsigned int tail = queue->tx_tail; |
| 1325 | struct macb *bp = queue->bp; |
| 1326 | |
| 1327 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
| 1328 | queue_writel(queue, ISR, MACB_BIT(TXUBR)); |
| 1329 | |
| 1330 | if (head == tail) |
| 1331 | return; |
| 1332 | |
| 1333 | macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); |
| 1334 | } |
| 1335 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1336 | static irqreturn_t macb_interrupt(int irq, void *dev_id) |
| 1337 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1338 | struct macb_queue *queue = dev_id; |
| 1339 | struct macb *bp = queue->bp; |
| 1340 | struct net_device *dev = bp->dev; |
Nathan Sullivan | bfbb92c | 2015-05-05 15:00:25 -0500 | [diff] [blame] | 1341 | u32 status, ctrl; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1342 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1343 | status = queue_readl(queue, ISR); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1344 | |
| 1345 | if (unlikely(!status)) |
| 1346 | return IRQ_NONE; |
| 1347 | |
| 1348 | spin_lock(&bp->lock); |
| 1349 | |
| 1350 | while (status) { |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1351 | /* close possible race with dev_close */ |
| 1352 | if (unlikely(!netif_running(dev))) { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1353 | queue_writel(queue, IDR, -1); |
Nathan Sullivan | 2446837 | 2016-01-14 13:27:27 -0600 | [diff] [blame] | 1354 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
| 1355 | queue_writel(queue, ISR, -1); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1356 | break; |
| 1357 | } |
| 1358 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1359 | netdev_vdbg(bp->dev, "queue = %u, isr = 0x%08lx\n", |
| 1360 | (unsigned int)(queue - bp->queues), |
| 1361 | (unsigned long)status); |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1362 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1363 | if (status & MACB_RX_INT_FLAGS) { |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 1364 | /* There's no point taking any more interrupts |
Joshua Hoke | b336369 | 2010-10-25 01:44:22 +0000 | [diff] [blame] | 1365 | * until we have processed the buffers. The |
| 1366 | * scheduling call may fail if the poll routine |
| 1367 | * is already scheduled, so disable interrupts |
| 1368 | * now. |
| 1369 | */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1370 | queue_writel(queue, IDR, MACB_RX_INT_FLAGS); |
Nicolas Ferre | 581df9e | 2013-05-14 03:00:16 +0000 | [diff] [blame] | 1371 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1372 | queue_writel(queue, ISR, MACB_BIT(RCOMP)); |
Joshua Hoke | b336369 | 2010-10-25 01:44:22 +0000 | [diff] [blame] | 1373 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1374 | if (napi_schedule_prep(&queue->napi)) { |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1375 | netdev_vdbg(bp->dev, "scheduling RX softirq\n"); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1376 | __napi_schedule(&queue->napi); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 1380 | if (unlikely(status & (MACB_TX_ERR_FLAGS))) { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1381 | queue_writel(queue, IDR, MACB_TX_INT_FLAGS); |
| 1382 | schedule_work(&queue->tx_error_task); |
Soren Brinkmann | 6a027b7 | 2014-05-04 15:42:59 -0700 | [diff] [blame] | 1383 | |
| 1384 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1385 | queue_writel(queue, ISR, MACB_TX_ERR_FLAGS); |
Soren Brinkmann | 6a027b7 | 2014-05-04 15:42:59 -0700 | [diff] [blame] | 1386 | |
Nicolas Ferre | e86cd53 | 2012-10-31 06:04:57 +0000 | [diff] [blame] | 1387 | break; |
| 1388 | } |
| 1389 | |
| 1390 | if (status & MACB_BIT(TCOMP)) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1391 | macb_tx_interrupt(queue); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1392 | |
Claudiu Beznea | 4298388 | 2018-12-17 10:02:42 +0000 | [diff] [blame] | 1393 | if (status & MACB_BIT(TXUBR)) |
| 1394 | macb_tx_restart(queue); |
| 1395 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 1396 | /* Link change detection isn't possible with RMII, so we'll |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1397 | * add that if/when we get our hands on a full-blown MII PHY. |
| 1398 | */ |
| 1399 | |
Nathan Sullivan | 86b5e7d | 2015-05-13 17:01:36 -0500 | [diff] [blame] | 1400 | /* There is a hardware issue under heavy load where DMA can |
| 1401 | * stop, this causes endless "used buffer descriptor read" |
| 1402 | * interrupts but it can be cleared by re-enabling RX. See |
| 1403 | * the at91 manual, section 41.3.1 or the Zynq manual |
| 1404 | * section 16.7.4 for details. |
| 1405 | */ |
Nathan Sullivan | bfbb92c | 2015-05-05 15:00:25 -0500 | [diff] [blame] | 1406 | if (status & MACB_BIT(RXUBR)) { |
| 1407 | ctrl = macb_readl(bp, NCR); |
| 1408 | macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE)); |
Zumeng Chen | ffac0e9 | 2016-11-28 21:55:00 +0800 | [diff] [blame] | 1409 | wmb(); |
Nathan Sullivan | bfbb92c | 2015-05-05 15:00:25 -0500 | [diff] [blame] | 1410 | macb_writel(bp, NCR, ctrl | MACB_BIT(RE)); |
| 1411 | |
| 1412 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | ba50499 | 2016-03-24 15:40:04 +0100 | [diff] [blame] | 1413 | queue_writel(queue, ISR, MACB_BIT(RXUBR)); |
Nathan Sullivan | bfbb92c | 2015-05-05 15:00:25 -0500 | [diff] [blame] | 1414 | } |
| 1415 | |
Alexander Stein | b19f7f7 | 2011-04-13 05:03:24 +0000 | [diff] [blame] | 1416 | if (status & MACB_BIT(ISR_ROVR)) { |
| 1417 | /* We missed at least one packet */ |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 1418 | if (macb_is_gem(bp)) |
| 1419 | bp->hw_stats.gem.rx_overruns++; |
| 1420 | else |
| 1421 | bp->hw_stats.macb.rx_overruns++; |
Soren Brinkmann | 6a027b7 | 2014-05-04 15:42:59 -0700 | [diff] [blame] | 1422 | |
| 1423 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1424 | queue_writel(queue, ISR, MACB_BIT(ISR_ROVR)); |
Alexander Stein | b19f7f7 | 2011-04-13 05:03:24 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1427 | if (status & MACB_BIT(HRESP)) { |
Harini Katakam | 032dc41 | 2018-01-27 12:09:01 +0530 | [diff] [blame] | 1428 | tasklet_schedule(&bp->hresp_err_tasklet); |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 1429 | netdev_err(dev, "DMA bus error: HRESP not OK\n"); |
Soren Brinkmann | 6a027b7 | 2014-05-04 15:42:59 -0700 | [diff] [blame] | 1430 | |
| 1431 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1432 | queue_writel(queue, ISR, MACB_BIT(HRESP)); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1433 | } |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1434 | status = queue_readl(queue, ISR); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | spin_unlock(&bp->lock); |
| 1438 | |
| 1439 | return IRQ_HANDLED; |
| 1440 | } |
| 1441 | |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 1442 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 1443 | /* Polling receive - used by netconsole and other diagnostic tools |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 1444 | * to allow network i/o with interrupts disabled. |
| 1445 | */ |
| 1446 | static void macb_poll_controller(struct net_device *dev) |
| 1447 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1448 | struct macb *bp = netdev_priv(dev); |
| 1449 | struct macb_queue *queue; |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 1450 | unsigned long flags; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1451 | unsigned int q; |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 1452 | |
| 1453 | local_irq_save(flags); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1454 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) |
| 1455 | macb_interrupt(dev->irq, queue); |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 1456 | local_irq_restore(flags); |
| 1457 | } |
| 1458 | #endif |
| 1459 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1460 | static unsigned int macb_tx_map(struct macb *bp, |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1461 | struct macb_queue *queue, |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1462 | struct sk_buff *skb, |
| 1463 | unsigned int hdrlen) |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1464 | { |
| 1465 | dma_addr_t mapping; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1466 | unsigned int len, entry, i, tx_head = queue->tx_head; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1467 | struct macb_tx_skb *tx_skb = NULL; |
| 1468 | struct macb_dma_desc *desc; |
| 1469 | unsigned int offset, size, count = 0; |
| 1470 | unsigned int f, nr_frags = skb_shinfo(skb)->nr_frags; |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1471 | unsigned int eof = 1, mss_mfs = 0; |
| 1472 | u32 ctrl, lso_ctrl = 0, seq_ctrl = 0; |
| 1473 | |
| 1474 | /* LSO */ |
| 1475 | if (skb_shinfo(skb)->gso_size != 0) { |
| 1476 | if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 1477 | /* UDP - UFO */ |
| 1478 | lso_ctrl = MACB_LSO_UFO_ENABLE; |
| 1479 | else |
| 1480 | /* TCP - TSO */ |
| 1481 | lso_ctrl = MACB_LSO_TSO_ENABLE; |
| 1482 | } |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1483 | |
| 1484 | /* First, map non-paged data */ |
| 1485 | len = skb_headlen(skb); |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1486 | |
| 1487 | /* first buffer length */ |
| 1488 | size = hdrlen; |
| 1489 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1490 | offset = 0; |
| 1491 | while (len) { |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1492 | entry = macb_tx_ring_wrap(bp, tx_head); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1493 | tx_skb = &queue->tx_skb[entry]; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1494 | |
| 1495 | mapping = dma_map_single(&bp->pdev->dev, |
| 1496 | skb->data + offset, |
| 1497 | size, DMA_TO_DEVICE); |
| 1498 | if (dma_mapping_error(&bp->pdev->dev, mapping)) |
| 1499 | goto dma_error; |
| 1500 | |
| 1501 | /* Save info to properly release resources */ |
| 1502 | tx_skb->skb = NULL; |
| 1503 | tx_skb->mapping = mapping; |
| 1504 | tx_skb->size = size; |
| 1505 | tx_skb->mapped_as_page = false; |
| 1506 | |
| 1507 | len -= size; |
| 1508 | offset += size; |
| 1509 | count++; |
| 1510 | tx_head++; |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1511 | |
| 1512 | size = min(len, bp->max_tx_length); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /* Then, map paged data from fragments */ |
| 1516 | for (f = 0; f < nr_frags; f++) { |
| 1517 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
| 1518 | |
| 1519 | len = skb_frag_size(frag); |
| 1520 | offset = 0; |
| 1521 | while (len) { |
| 1522 | size = min(len, bp->max_tx_length); |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1523 | entry = macb_tx_ring_wrap(bp, tx_head); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1524 | tx_skb = &queue->tx_skb[entry]; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1525 | |
| 1526 | mapping = skb_frag_dma_map(&bp->pdev->dev, frag, |
| 1527 | offset, size, DMA_TO_DEVICE); |
| 1528 | if (dma_mapping_error(&bp->pdev->dev, mapping)) |
| 1529 | goto dma_error; |
| 1530 | |
| 1531 | /* Save info to properly release resources */ |
| 1532 | tx_skb->skb = NULL; |
| 1533 | tx_skb->mapping = mapping; |
| 1534 | tx_skb->size = size; |
| 1535 | tx_skb->mapped_as_page = true; |
| 1536 | |
| 1537 | len -= size; |
| 1538 | offset += size; |
| 1539 | count++; |
| 1540 | tx_head++; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | /* Should never happen */ |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1545 | if (unlikely(!tx_skb)) { |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1546 | netdev_err(bp->dev, "BUG! empty skb!\n"); |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | /* This is the last buffer of the frame: save socket buffer */ |
| 1551 | tx_skb->skb = skb; |
| 1552 | |
| 1553 | /* Update TX ring: update buffer descriptors in reverse order |
| 1554 | * to avoid race condition |
| 1555 | */ |
| 1556 | |
| 1557 | /* Set 'TX_USED' bit in buffer descriptor at tx_head position |
| 1558 | * to set the end of TX queue |
| 1559 | */ |
| 1560 | i = tx_head; |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1561 | entry = macb_tx_ring_wrap(bp, i); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1562 | ctrl = MACB_BIT(TX_USED); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1563 | desc = macb_tx_desc(queue, entry); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1564 | desc->ctrl = ctrl; |
| 1565 | |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1566 | if (lso_ctrl) { |
| 1567 | if (lso_ctrl == MACB_LSO_UFO_ENABLE) |
| 1568 | /* include header and FCS in value given to h/w */ |
| 1569 | mss_mfs = skb_shinfo(skb)->gso_size + |
| 1570 | skb_transport_offset(skb) + |
| 1571 | ETH_FCS_LEN; |
| 1572 | else /* TSO */ { |
| 1573 | mss_mfs = skb_shinfo(skb)->gso_size; |
| 1574 | /* TCP Sequence Number Source Select |
| 1575 | * can be set only for TSO |
| 1576 | */ |
| 1577 | seq_ctrl = 0; |
| 1578 | } |
| 1579 | } |
| 1580 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1581 | do { |
| 1582 | i--; |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1583 | entry = macb_tx_ring_wrap(bp, i); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1584 | tx_skb = &queue->tx_skb[entry]; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1585 | desc = macb_tx_desc(queue, entry); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1586 | |
| 1587 | ctrl = (u32)tx_skb->size; |
| 1588 | if (eof) { |
| 1589 | ctrl |= MACB_BIT(TX_LAST); |
| 1590 | eof = 0; |
| 1591 | } |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1592 | if (unlikely(entry == (bp->tx_ring_size - 1))) |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1593 | ctrl |= MACB_BIT(TX_WRAP); |
| 1594 | |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1595 | /* First descriptor is header descriptor */ |
| 1596 | if (i == queue->tx_head) { |
| 1597 | ctrl |= MACB_BF(TX_LSO, lso_ctrl); |
| 1598 | ctrl |= MACB_BF(TX_TCP_SEQ_SRC, seq_ctrl); |
Claudiu Beznea | 653e92a | 2018-08-07 12:25:14 +0300 | [diff] [blame] | 1599 | if ((bp->dev->features & NETIF_F_HW_CSUM) && |
| 1600 | skb->ip_summed != CHECKSUM_PARTIAL && !lso_ctrl) |
| 1601 | ctrl |= MACB_BIT(TX_NOCRC); |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1602 | } else |
| 1603 | /* Only set MSS/MFS on payload descriptors |
| 1604 | * (second or later descriptor) |
| 1605 | */ |
| 1606 | ctrl |= MACB_BF(MSS_MFS, mss_mfs); |
| 1607 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1608 | /* Set TX buffer descriptor */ |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1609 | macb_set_addr(bp, desc, tx_skb->mapping); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1610 | /* desc->addr must be visible to hardware before clearing |
| 1611 | * 'TX_USED' bit in desc->ctrl. |
| 1612 | */ |
| 1613 | wmb(); |
| 1614 | desc->ctrl = ctrl; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1615 | } while (i != queue->tx_head); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1616 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1617 | queue->tx_head = tx_head; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1618 | |
| 1619 | return count; |
| 1620 | |
| 1621 | dma_error: |
| 1622 | netdev_err(bp->dev, "TX DMA map failed\n"); |
| 1623 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1624 | for (i = queue->tx_head; i != tx_head; i++) { |
| 1625 | tx_skb = macb_tx_skb(queue, i); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1626 | |
| 1627 | macb_tx_unmap(bp, tx_skb); |
| 1628 | } |
| 1629 | |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1633 | static netdev_features_t macb_features_check(struct sk_buff *skb, |
| 1634 | struct net_device *dev, |
| 1635 | netdev_features_t features) |
| 1636 | { |
| 1637 | unsigned int nr_frags, f; |
| 1638 | unsigned int hdrlen; |
| 1639 | |
| 1640 | /* Validate LSO compatibility */ |
| 1641 | |
| 1642 | /* there is only one buffer */ |
| 1643 | if (!skb_is_nonlinear(skb)) |
| 1644 | return features; |
| 1645 | |
| 1646 | /* length of header */ |
| 1647 | hdrlen = skb_transport_offset(skb); |
| 1648 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 1649 | hdrlen += tcp_hdrlen(skb); |
| 1650 | |
| 1651 | /* For LSO: |
| 1652 | * When software supplies two or more payload buffers all payload buffers |
| 1653 | * apart from the last must be a multiple of 8 bytes in size. |
| 1654 | */ |
| 1655 | if (!IS_ALIGNED(skb_headlen(skb) - hdrlen, MACB_TX_LEN_ALIGN)) |
| 1656 | return features & ~MACB_NETIF_LSO; |
| 1657 | |
| 1658 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1659 | /* No need to check last fragment */ |
| 1660 | nr_frags--; |
| 1661 | for (f = 0; f < nr_frags; f++) { |
| 1662 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
| 1663 | |
| 1664 | if (!IS_ALIGNED(skb_frag_size(frag), MACB_TX_LEN_ALIGN)) |
| 1665 | return features & ~MACB_NETIF_LSO; |
| 1666 | } |
| 1667 | return features; |
| 1668 | } |
| 1669 | |
Helmut Buchsbaum | 007e4ba | 2016-09-04 18:09:47 +0200 | [diff] [blame] | 1670 | static inline int macb_clear_csum(struct sk_buff *skb) |
| 1671 | { |
| 1672 | /* no change for packets without checksum offloading */ |
| 1673 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1674 | return 0; |
| 1675 | |
| 1676 | /* make sure we can modify the header */ |
| 1677 | if (unlikely(skb_cow_head(skb, 0))) |
| 1678 | return -1; |
| 1679 | |
| 1680 | /* initialize checksum field |
| 1681 | * This is required - at least for Zynq, which otherwise calculates |
| 1682 | * wrong UDP header checksums for UDP packets with UDP data len <=2 |
| 1683 | */ |
| 1684 | *(__sum16 *)(skb_checksum_start(skb) + skb->csum_offset) = 0; |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Claudiu Beznea | 653e92a | 2018-08-07 12:25:14 +0300 | [diff] [blame] | 1688 | static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev) |
| 1689 | { |
| 1690 | bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb); |
| 1691 | int padlen = ETH_ZLEN - (*skb)->len; |
| 1692 | int headroom = skb_headroom(*skb); |
| 1693 | int tailroom = skb_tailroom(*skb); |
| 1694 | struct sk_buff *nskb; |
| 1695 | u32 fcs; |
| 1696 | |
| 1697 | if (!(ndev->features & NETIF_F_HW_CSUM) || |
| 1698 | !((*skb)->ip_summed != CHECKSUM_PARTIAL) || |
| 1699 | skb_shinfo(*skb)->gso_size) /* Not available for GSO */ |
| 1700 | return 0; |
| 1701 | |
| 1702 | if (padlen <= 0) { |
| 1703 | /* FCS could be appeded to tailroom. */ |
| 1704 | if (tailroom >= ETH_FCS_LEN) |
| 1705 | goto add_fcs; |
| 1706 | /* FCS could be appeded by moving data to headroom. */ |
| 1707 | else if (!cloned && headroom + tailroom >= ETH_FCS_LEN) |
| 1708 | padlen = 0; |
| 1709 | /* No room for FCS, need to reallocate skb. */ |
| 1710 | else |
Tristram Ha | 899ecae | 2018-10-24 14:51:23 -0700 | [diff] [blame] | 1711 | padlen = ETH_FCS_LEN; |
Claudiu Beznea | 653e92a | 2018-08-07 12:25:14 +0300 | [diff] [blame] | 1712 | } else { |
| 1713 | /* Add room for FCS. */ |
| 1714 | padlen += ETH_FCS_LEN; |
| 1715 | } |
| 1716 | |
| 1717 | if (!cloned && headroom + tailroom >= padlen) { |
| 1718 | (*skb)->data = memmove((*skb)->head, (*skb)->data, (*skb)->len); |
| 1719 | skb_set_tail_pointer(*skb, (*skb)->len); |
| 1720 | } else { |
| 1721 | nskb = skb_copy_expand(*skb, 0, padlen, GFP_ATOMIC); |
| 1722 | if (!nskb) |
| 1723 | return -ENOMEM; |
| 1724 | |
| 1725 | dev_kfree_skb_any(*skb); |
| 1726 | *skb = nskb; |
| 1727 | } |
| 1728 | |
| 1729 | if (padlen) { |
| 1730 | if (padlen >= ETH_FCS_LEN) |
| 1731 | skb_put_zero(*skb, padlen - ETH_FCS_LEN); |
| 1732 | else |
| 1733 | skb_trim(*skb, ETH_FCS_LEN - padlen); |
| 1734 | } |
| 1735 | |
| 1736 | add_fcs: |
| 1737 | /* set FCS to packet */ |
| 1738 | fcs = crc32_le(~0, (*skb)->data, (*skb)->len); |
| 1739 | fcs = ~fcs; |
| 1740 | |
| 1741 | skb_put_u8(*skb, fcs & 0xff); |
| 1742 | skb_put_u8(*skb, (fcs >> 8) & 0xff); |
| 1743 | skb_put_u8(*skb, (fcs >> 16) & 0xff); |
| 1744 | skb_put_u8(*skb, (fcs >> 24) & 0xff); |
| 1745 | |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
Claudiu Beznea | d1c3895 | 2018-08-07 12:25:12 +0300 | [diff] [blame] | 1749 | static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1750 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1751 | u16 queue_index = skb_get_queue_mapping(skb); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1752 | struct macb *bp = netdev_priv(dev); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1753 | struct macb_queue *queue = &bp->queues[queue_index]; |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 1754 | unsigned long flags; |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1755 | unsigned int desc_cnt, nr_frags, frag_size, f; |
| 1756 | unsigned int hdrlen; |
| 1757 | bool is_lso, is_udp = 0; |
Claudiu Beznea | d1c3895 | 2018-08-07 12:25:12 +0300 | [diff] [blame] | 1758 | netdev_tx_t ret = NETDEV_TX_OK; |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1759 | |
Claudiu Beznea | 33729f2 | 2018-08-07 12:25:13 +0300 | [diff] [blame] | 1760 | if (macb_clear_csum(skb)) { |
| 1761 | dev_kfree_skb_any(skb); |
| 1762 | return ret; |
| 1763 | } |
| 1764 | |
Claudiu Beznea | 653e92a | 2018-08-07 12:25:14 +0300 | [diff] [blame] | 1765 | if (macb_pad_and_fcs(&skb, dev)) { |
| 1766 | dev_kfree_skb_any(skb); |
| 1767 | return ret; |
| 1768 | } |
| 1769 | |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1770 | is_lso = (skb_shinfo(skb)->gso_size != 0); |
| 1771 | |
| 1772 | if (is_lso) { |
| 1773 | is_udp = !!(ip_hdr(skb)->protocol == IPPROTO_UDP); |
| 1774 | |
| 1775 | /* length of headers */ |
| 1776 | if (is_udp) |
| 1777 | /* only queue eth + ip headers separately for UDP */ |
| 1778 | hdrlen = skb_transport_offset(skb); |
| 1779 | else |
| 1780 | hdrlen = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1781 | if (skb_headlen(skb) < hdrlen) { |
| 1782 | netdev_err(bp->dev, "Error - LSO headers fragmented!!!\n"); |
| 1783 | /* if this is required, would need to copy to single buffer */ |
| 1784 | return NETDEV_TX_BUSY; |
| 1785 | } |
| 1786 | } else |
| 1787 | hdrlen = min(skb_headlen(skb), bp->max_tx_length); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1788 | |
Havard Skinnemoen | a268adb | 2012-10-31 06:04:52 +0000 | [diff] [blame] | 1789 | #if defined(DEBUG) && defined(VERBOSE_DEBUG) |
| 1790 | netdev_vdbg(bp->dev, |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1791 | "start_xmit: queue %hu len %u head %p data %p tail %p end %p\n", |
| 1792 | queue_index, skb->len, skb->head, skb->data, |
| 1793 | skb_tail_pointer(skb), skb_end_pointer(skb)); |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 1794 | print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 1795 | skb->data, 16, true); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1796 | #endif |
| 1797 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1798 | /* Count how many TX buffer descriptors are needed to send this |
| 1799 | * socket buffer: skb fragments of jumbo frames may need to be |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1800 | * split into many buffer descriptors. |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1801 | */ |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1802 | if (is_lso && (skb_headlen(skb) > hdrlen)) |
| 1803 | /* extra header descriptor if also payload in first buffer */ |
| 1804 | desc_cnt = DIV_ROUND_UP((skb_headlen(skb) - hdrlen), bp->max_tx_length) + 1; |
| 1805 | else |
| 1806 | desc_cnt = DIV_ROUND_UP(skb_headlen(skb), bp->max_tx_length); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1807 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1808 | for (f = 0; f < nr_frags; f++) { |
| 1809 | frag_size = skb_frag_size(&skb_shinfo(skb)->frags[f]); |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1810 | desc_cnt += DIV_ROUND_UP(frag_size, bp->max_tx_length); |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 1813 | spin_lock_irqsave(&bp->lock, flags); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1814 | |
| 1815 | /* This is a hard error, log it. */ |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1816 | if (CIRC_SPACE(queue->tx_head, queue->tx_tail, |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1817 | bp->tx_ring_size) < desc_cnt) { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1818 | netif_stop_subqueue(dev, queue_index); |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 1819 | spin_unlock_irqrestore(&bp->lock, flags); |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 1820 | netdev_dbg(bp->dev, "tx_head = %u, tx_tail = %u\n", |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1821 | queue->tx_head, queue->tx_tail); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1822 | return NETDEV_TX_BUSY; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1823 | } |
| 1824 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 1825 | /* Map socket buffer for DMA transfer */ |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 1826 | if (!macb_tx_map(bp, queue, skb, hdrlen)) { |
Eric W. Biederman | c88b5b6 | 2014-03-15 16:08:27 -0700 | [diff] [blame] | 1827 | dev_kfree_skb_any(skb); |
Soren Brinkmann | 9203090 | 2014-03-04 08:46:39 -0800 | [diff] [blame] | 1828 | goto unlock; |
| 1829 | } |
Havard Skinnemoen | 55054a1 | 2012-10-31 06:04:55 +0000 | [diff] [blame] | 1830 | |
Havard Skinnemoen | 03dbe05 | 2012-10-31 06:04:51 +0000 | [diff] [blame] | 1831 | /* Make newly initialized descriptor visible to hardware */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1832 | wmb(); |
Richard Cochran | e072092 | 2011-06-19 21:51:28 +0000 | [diff] [blame] | 1833 | skb_tx_timestamp(skb); |
| 1834 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1835 | macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); |
| 1836 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1837 | if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1838 | netif_stop_subqueue(dev, queue_index); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1839 | |
Soren Brinkmann | 9203090 | 2014-03-04 08:46:39 -0800 | [diff] [blame] | 1840 | unlock: |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 1841 | spin_unlock_irqrestore(&bp->lock, flags); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1842 | |
Claudiu Beznea | d1c3895 | 2018-08-07 12:25:12 +0300 | [diff] [blame] | 1843 | return ret; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1846 | static void macb_init_rx_buffer_size(struct macb *bp, size_t size) |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1847 | { |
| 1848 | if (!macb_is_gem(bp)) { |
| 1849 | bp->rx_buffer_size = MACB_RX_BUFFER_SIZE; |
| 1850 | } else { |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1851 | bp->rx_buffer_size = size; |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1852 | |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1853 | if (bp->rx_buffer_size % RX_BUFFER_MULTIPLE) { |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1854 | netdev_dbg(bp->dev, |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 1855 | "RX buffer must be multiple of %d bytes, expanding\n", |
| 1856 | RX_BUFFER_MULTIPLE); |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1857 | bp->rx_buffer_size = |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1858 | roundup(bp->rx_buffer_size, RX_BUFFER_MULTIPLE); |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1859 | } |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1860 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1861 | |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 1862 | netdev_dbg(bp->dev, "mtu [%u] rx_buffer_size [%zu]\n", |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1863 | bp->dev->mtu, bp->rx_buffer_size); |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1866 | static void gem_free_rx_buffers(struct macb *bp) |
| 1867 | { |
| 1868 | struct sk_buff *skb; |
| 1869 | struct macb_dma_desc *desc; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1870 | struct macb_queue *queue; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1871 | dma_addr_t addr; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1872 | unsigned int q; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1873 | int i; |
| 1874 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1875 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 1876 | if (!queue->rx_skbuff) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1877 | continue; |
| 1878 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1879 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 1880 | skb = queue->rx_skbuff[i]; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 1881 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1882 | if (!skb) |
| 1883 | continue; |
| 1884 | |
| 1885 | desc = macb_rx_desc(queue, i); |
| 1886 | addr = macb_get_addr(bp, desc); |
| 1887 | |
| 1888 | dma_unmap_single(&bp->pdev->dev, addr, bp->rx_buffer_size, |
| 1889 | DMA_FROM_DEVICE); |
| 1890 | dev_kfree_skb_any(skb); |
| 1891 | skb = NULL; |
| 1892 | } |
| 1893 | |
| 1894 | kfree(queue->rx_skbuff); |
| 1895 | queue->rx_skbuff = NULL; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1896 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | static void macb_free_rx_buffers(struct macb *bp) |
| 1900 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1901 | struct macb_queue *queue = &bp->queues[0]; |
| 1902 | |
| 1903 | if (queue->rx_buffers) { |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1904 | dma_free_coherent(&bp->pdev->dev, |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1905 | bp->rx_ring_size * bp->rx_buffer_size, |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1906 | queue->rx_buffers, queue->rx_buffers_dma); |
| 1907 | queue->rx_buffers = NULL; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1908 | } |
| 1909 | } |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 1910 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1911 | static void macb_free_consistent(struct macb *bp) |
| 1912 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1913 | struct macb_queue *queue; |
| 1914 | unsigned int q; |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 1915 | int size; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1916 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1917 | bp->macbgem_ops.mog_free_rx_buffers(bp); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1918 | |
| 1919 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 1920 | kfree(queue->tx_skb); |
| 1921 | queue->tx_skb = NULL; |
| 1922 | if (queue->tx_ring) { |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 1923 | size = TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch; |
| 1924 | dma_free_coherent(&bp->pdev->dev, size, |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1925 | queue->tx_ring, queue->tx_ring_dma); |
| 1926 | queue->tx_ring = NULL; |
| 1927 | } |
Harini Katakam | e50b770 | 2018-07-06 12:18:57 +0530 | [diff] [blame] | 1928 | if (queue->rx_ring) { |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 1929 | size = RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch; |
| 1930 | dma_free_coherent(&bp->pdev->dev, size, |
Harini Katakam | e50b770 | 2018-07-06 12:18:57 +0530 | [diff] [blame] | 1931 | queue->rx_ring, queue->rx_ring_dma); |
| 1932 | queue->rx_ring = NULL; |
| 1933 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1934 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | static int gem_alloc_rx_buffers(struct macb *bp) |
| 1938 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1939 | struct macb_queue *queue; |
| 1940 | unsigned int q; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1941 | int size; |
| 1942 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1943 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 1944 | size = bp->rx_ring_size * sizeof(struct sk_buff *); |
| 1945 | queue->rx_skbuff = kzalloc(size, GFP_KERNEL); |
| 1946 | if (!queue->rx_skbuff) |
| 1947 | return -ENOMEM; |
| 1948 | else |
| 1949 | netdev_dbg(bp->dev, |
| 1950 | "Allocated %d RX struct sk_buff entries at %p\n", |
| 1951 | bp->rx_ring_size, queue->rx_skbuff); |
| 1952 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1953 | return 0; |
| 1954 | } |
| 1955 | |
| 1956 | static int macb_alloc_rx_buffers(struct macb *bp) |
| 1957 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1958 | struct macb_queue *queue = &bp->queues[0]; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1959 | int size; |
| 1960 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1961 | size = bp->rx_ring_size * bp->rx_buffer_size; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1962 | queue->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size, |
| 1963 | &queue->rx_buffers_dma, GFP_KERNEL); |
| 1964 | if (!queue->rx_buffers) |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1965 | return -ENOMEM; |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 1966 | |
| 1967 | netdev_dbg(bp->dev, |
| 1968 | "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n", |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1969 | size, (unsigned long)queue->rx_buffers_dma, queue->rx_buffers); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 1970 | return 0; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static int macb_alloc_consistent(struct macb *bp) |
| 1974 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1975 | struct macb_queue *queue; |
| 1976 | unsigned int q; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 1977 | int size; |
| 1978 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1979 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 1980 | size = TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1981 | queue->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size, |
| 1982 | &queue->tx_ring_dma, |
| 1983 | GFP_KERNEL); |
| 1984 | if (!queue->tx_ring) |
| 1985 | goto out_err; |
| 1986 | netdev_dbg(bp->dev, |
| 1987 | "Allocated TX ring for queue %u of %d bytes at %08lx (mapped %p)\n", |
| 1988 | q, size, (unsigned long)queue->tx_ring_dma, |
| 1989 | queue->tx_ring); |
| 1990 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 1991 | size = bp->tx_ring_size * sizeof(struct macb_tx_skb); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 1992 | queue->tx_skb = kmalloc(size, GFP_KERNEL); |
| 1993 | if (!queue->tx_skb) |
| 1994 | goto out_err; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1995 | |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 1996 | size = RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 1997 | queue->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size, |
| 1998 | &queue->rx_ring_dma, GFP_KERNEL); |
| 1999 | if (!queue->rx_ring) |
| 2000 | goto out_err; |
| 2001 | netdev_dbg(bp->dev, |
| 2002 | "Allocated RX ring of %d bytes at %08lx (mapped %p)\n", |
| 2003 | size, (unsigned long)queue->rx_ring_dma, queue->rx_ring); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2004 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2005 | if (bp->macbgem_ops.mog_alloc_rx_buffers(bp)) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2006 | goto out_err; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2007 | |
| 2008 | return 0; |
| 2009 | |
| 2010 | out_err: |
| 2011 | macb_free_consistent(bp); |
| 2012 | return -ENOMEM; |
| 2013 | } |
| 2014 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2015 | static void gem_init_rings(struct macb *bp) |
| 2016 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2017 | struct macb_queue *queue; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2018 | struct macb_dma_desc *desc = NULL; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2019 | unsigned int q; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2020 | int i; |
| 2021 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2022 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 2023 | for (i = 0; i < bp->tx_ring_size; i++) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2024 | desc = macb_tx_desc(queue, i); |
| 2025 | macb_set_addr(bp, desc, 0); |
| 2026 | desc->ctrl = MACB_BIT(TX_USED); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2027 | } |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2028 | desc->ctrl |= MACB_BIT(TX_WRAP); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2029 | queue->tx_head = 0; |
| 2030 | queue->tx_tail = 0; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2031 | |
| 2032 | queue->rx_tail = 0; |
| 2033 | queue->rx_prepared_head = 0; |
| 2034 | |
| 2035 | gem_rx_refill(queue); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2036 | } |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2037 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2040 | static void macb_init_rings(struct macb *bp) |
| 2041 | { |
| 2042 | int i; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2043 | struct macb_dma_desc *desc = NULL; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2044 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2045 | macb_init_rx_ring(&bp->queues[0]); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2046 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 2047 | for (i = 0; i < bp->tx_ring_size; i++) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2048 | desc = macb_tx_desc(&bp->queues[0], i); |
| 2049 | macb_set_addr(bp, desc, 0); |
| 2050 | desc->ctrl = MACB_BIT(TX_USED); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2051 | } |
Ben Shelton | 21d3515 | 2015-04-22 17:28:54 -0500 | [diff] [blame] | 2052 | bp->queues[0].tx_head = 0; |
| 2053 | bp->queues[0].tx_tail = 0; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2054 | desc->ctrl |= MACB_BIT(TX_WRAP); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | static void macb_reset_hw(struct macb *bp) |
| 2058 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2059 | struct macb_queue *queue; |
| 2060 | unsigned int q; |
Anssi Hannula | 0da70f8 | 2018-08-23 10:45:22 +0300 | [diff] [blame] | 2061 | u32 ctrl = macb_readl(bp, NCR); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2062 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2063 | /* Disable RX and TX (XXX: Should we halt the transmission |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2064 | * more gracefully?) |
| 2065 | */ |
Anssi Hannula | 0da70f8 | 2018-08-23 10:45:22 +0300 | [diff] [blame] | 2066 | ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE)); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2067 | |
| 2068 | /* Clear the stats registers (XXX: Update stats first?) */ |
Anssi Hannula | 0da70f8 | 2018-08-23 10:45:22 +0300 | [diff] [blame] | 2069 | ctrl |= MACB_BIT(CLRSTAT); |
| 2070 | |
| 2071 | macb_writel(bp, NCR, ctrl); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2072 | |
| 2073 | /* Clear all status flags */ |
Joachim Eastwood | 95ebcea | 2012-10-22 08:45:31 +0000 | [diff] [blame] | 2074 | macb_writel(bp, TSR, -1); |
| 2075 | macb_writel(bp, RSR, -1); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2076 | |
| 2077 | /* Disable all interrupts */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2078 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 2079 | queue_writel(queue, IDR, -1); |
| 2080 | queue_readl(queue, ISR); |
Nathan Sullivan | 2446837 | 2016-01-14 13:27:27 -0600 | [diff] [blame] | 2081 | if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) |
| 2082 | queue_writel(queue, ISR, -1); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2083 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2084 | } |
| 2085 | |
Jamie Iles | 70c9f3d | 2011-03-09 16:22:54 +0000 | [diff] [blame] | 2086 | static u32 gem_mdc_clk_div(struct macb *bp) |
| 2087 | { |
| 2088 | u32 config; |
| 2089 | unsigned long pclk_hz = clk_get_rate(bp->pclk); |
| 2090 | |
| 2091 | if (pclk_hz <= 20000000) |
| 2092 | config = GEM_BF(CLK, GEM_CLK_DIV8); |
| 2093 | else if (pclk_hz <= 40000000) |
| 2094 | config = GEM_BF(CLK, GEM_CLK_DIV16); |
| 2095 | else if (pclk_hz <= 80000000) |
| 2096 | config = GEM_BF(CLK, GEM_CLK_DIV32); |
| 2097 | else if (pclk_hz <= 120000000) |
| 2098 | config = GEM_BF(CLK, GEM_CLK_DIV48); |
| 2099 | else if (pclk_hz <= 160000000) |
| 2100 | config = GEM_BF(CLK, GEM_CLK_DIV64); |
| 2101 | else |
| 2102 | config = GEM_BF(CLK, GEM_CLK_DIV96); |
| 2103 | |
| 2104 | return config; |
| 2105 | } |
| 2106 | |
| 2107 | static u32 macb_mdc_clk_div(struct macb *bp) |
| 2108 | { |
| 2109 | u32 config; |
| 2110 | unsigned long pclk_hz; |
| 2111 | |
| 2112 | if (macb_is_gem(bp)) |
| 2113 | return gem_mdc_clk_div(bp); |
| 2114 | |
| 2115 | pclk_hz = clk_get_rate(bp->pclk); |
| 2116 | if (pclk_hz <= 20000000) |
| 2117 | config = MACB_BF(CLK, MACB_CLK_DIV8); |
| 2118 | else if (pclk_hz <= 40000000) |
| 2119 | config = MACB_BF(CLK, MACB_CLK_DIV16); |
| 2120 | else if (pclk_hz <= 80000000) |
| 2121 | config = MACB_BF(CLK, MACB_CLK_DIV32); |
| 2122 | else |
| 2123 | config = MACB_BF(CLK, MACB_CLK_DIV64); |
| 2124 | |
| 2125 | return config; |
| 2126 | } |
| 2127 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2128 | /* Get the DMA bus width field of the network configuration register that we |
Jamie Iles | 757a03c | 2011-03-09 16:29:59 +0000 | [diff] [blame] | 2129 | * should program. We find the width from decoding the design configuration |
| 2130 | * register to find the maximum supported data bus width. |
| 2131 | */ |
| 2132 | static u32 macb_dbw(struct macb *bp) |
| 2133 | { |
| 2134 | if (!macb_is_gem(bp)) |
| 2135 | return 0; |
| 2136 | |
| 2137 | switch (GEM_BFEXT(DBWDEF, gem_readl(bp, DCFG1))) { |
| 2138 | case 4: |
| 2139 | return GEM_BF(DBW, GEM_DBW128); |
| 2140 | case 2: |
| 2141 | return GEM_BF(DBW, GEM_DBW64); |
| 2142 | case 1: |
| 2143 | default: |
| 2144 | return GEM_BF(DBW, GEM_DBW32); |
| 2145 | } |
| 2146 | } |
| 2147 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2148 | /* Configure the receive DMA engine |
Nicolas Ferre | b3e3bd71 | 2012-11-23 03:49:01 +0000 | [diff] [blame] | 2149 | * - use the correct receive buffer size |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 2150 | * - set best burst length for DMA operations |
Nicolas Ferre | b3e3bd71 | 2012-11-23 03:49:01 +0000 | [diff] [blame] | 2151 | * (if not supported by FIFO, it will fallback to default) |
| 2152 | * - set both rx/tx packet buffers to full memory size |
| 2153 | * These are configurable parameters for GEM. |
Jamie Iles | 0116da4 | 2011-03-14 17:38:30 +0000 | [diff] [blame] | 2154 | */ |
| 2155 | static void macb_configure_dma(struct macb *bp) |
| 2156 | { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2157 | struct macb_queue *queue; |
| 2158 | u32 buffer_size; |
| 2159 | unsigned int q; |
Jamie Iles | 0116da4 | 2011-03-14 17:38:30 +0000 | [diff] [blame] | 2160 | u32 dmacfg; |
| 2161 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2162 | buffer_size = bp->rx_buffer_size / RX_BUFFER_MULTIPLE; |
Jamie Iles | 0116da4 | 2011-03-14 17:38:30 +0000 | [diff] [blame] | 2163 | if (macb_is_gem(bp)) { |
| 2164 | dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2165 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 2166 | if (q) |
| 2167 | queue_writel(queue, RBQS, buffer_size); |
| 2168 | else |
| 2169 | dmacfg |= GEM_BF(RXBS, buffer_size); |
| 2170 | } |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 2171 | if (bp->dma_burst_length) |
| 2172 | dmacfg = GEM_BFINS(FBLDO, bp->dma_burst_length, dmacfg); |
Nicolas Ferre | b3e3bd71 | 2012-11-23 03:49:01 +0000 | [diff] [blame] | 2173 | dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L); |
Arun Chandran | a50dad3 | 2015-02-18 16:59:35 +0530 | [diff] [blame] | 2174 | dmacfg &= ~GEM_BIT(ENDIA_PKT); |
Arun Chandran | 62f6924 | 2015-03-01 11:38:02 +0530 | [diff] [blame] | 2175 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 2176 | if (bp->native_io) |
Arun Chandran | 62f6924 | 2015-03-01 11:38:02 +0530 | [diff] [blame] | 2177 | dmacfg &= ~GEM_BIT(ENDIA_DESC); |
| 2178 | else |
| 2179 | dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */ |
| 2180 | |
Cyrille Pitchen | 85ff3d8 | 2014-07-24 13:51:00 +0200 | [diff] [blame] | 2181 | if (bp->dev->features & NETIF_F_HW_CSUM) |
| 2182 | dmacfg |= GEM_BIT(TXCOEN); |
| 2183 | else |
| 2184 | dmacfg &= ~GEM_BIT(TXCOEN); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 2185 | |
Michal Simek | bd62072 | 2018-09-25 08:32:50 +0200 | [diff] [blame] | 2186 | dmacfg &= ~GEM_BIT(ADDR64); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 2187 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 2188 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2189 | dmacfg |= GEM_BIT(ADDR64); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 2190 | #endif |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 2191 | #ifdef CONFIG_MACB_USE_HWSTAMP |
| 2192 | if (bp->hw_dma_cap & HW_DMA_CAP_PTP) |
| 2193 | dmacfg |= GEM_BIT(RXEXT) | GEM_BIT(TXEXT); |
| 2194 | #endif |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 2195 | netdev_dbg(bp->dev, "Cadence configure DMA with 0x%08x\n", |
| 2196 | dmacfg); |
Jamie Iles | 0116da4 | 2011-03-14 17:38:30 +0000 | [diff] [blame] | 2197 | gem_writel(bp, DMACFG, dmacfg); |
| 2198 | } |
| 2199 | } |
| 2200 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2201 | static void macb_init_hw(struct macb *bp) |
| 2202 | { |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2203 | struct macb_queue *queue; |
| 2204 | unsigned int q; |
| 2205 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2206 | u32 config; |
| 2207 | |
| 2208 | macb_reset_hw(bp); |
Joachim Eastwood | 314bccc | 2012-11-07 08:14:52 +0000 | [diff] [blame] | 2209 | macb_set_hwaddr(bp); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2210 | |
Jamie Iles | 70c9f3d | 2011-03-09 16:22:54 +0000 | [diff] [blame] | 2211 | config = macb_mdc_clk_div(bp); |
Punnaiah Choudary Kalluri | 022be25 | 2015-11-18 09:03:50 +0530 | [diff] [blame] | 2212 | if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) |
| 2213 | config |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL); |
Havard Skinnemoen | 29bc2e1 | 2012-10-31 06:04:58 +0000 | [diff] [blame] | 2214 | config |= MACB_BF(RBOF, NET_IP_ALIGN); /* Make eth data aligned */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2215 | config |= MACB_BIT(PAE); /* PAuse Enable */ |
| 2216 | config |= MACB_BIT(DRFCS); /* Discard Rx FCS */ |
Dan Carpenter | a104a6b | 2015-05-12 21:15:24 +0300 | [diff] [blame] | 2217 | if (bp->caps & MACB_CAPS_JUMBO) |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 2218 | config |= MACB_BIT(JFRAME); /* Enable jumbo frames */ |
| 2219 | else |
| 2220 | config |= MACB_BIT(BIG); /* Receive oversized frames */ |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2221 | if (bp->dev->flags & IFF_PROMISC) |
| 2222 | config |= MACB_BIT(CAF); /* Copy All Frames */ |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 2223 | else if (macb_is_gem(bp) && bp->dev->features & NETIF_F_RXCSUM) |
| 2224 | config |= GEM_BIT(RXCOEN); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2225 | if (!(bp->dev->flags & IFF_BROADCAST)) |
| 2226 | config |= MACB_BIT(NBC); /* No BroadCast */ |
Jamie Iles | 757a03c | 2011-03-09 16:29:59 +0000 | [diff] [blame] | 2227 | config |= macb_dbw(bp); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2228 | macb_writel(bp, NCFGR, config); |
Dan Carpenter | a104a6b | 2015-05-12 21:15:24 +0300 | [diff] [blame] | 2229 | if ((bp->caps & MACB_CAPS_JUMBO) && bp->jumbo_max_len) |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 2230 | gem_writel(bp, JML, bp->jumbo_max_len); |
Vitalii Demianets | 26cdfb4 | 2012-11-02 07:09:24 +0000 | [diff] [blame] | 2231 | bp->speed = SPEED_10; |
| 2232 | bp->duplex = DUPLEX_HALF; |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 2233 | bp->rx_frm_len_mask = MACB_RX_FRMLEN_MASK; |
Dan Carpenter | a104a6b | 2015-05-12 21:15:24 +0300 | [diff] [blame] | 2234 | if (bp->caps & MACB_CAPS_JUMBO) |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 2235 | bp->rx_frm_len_mask = MACB_RX_JFRMLEN_MASK; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2236 | |
Jamie Iles | 0116da4 | 2011-03-14 17:38:30 +0000 | [diff] [blame] | 2237 | macb_configure_dma(bp); |
| 2238 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2239 | /* Initialize TX and RX buffers */ |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2240 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2241 | queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma)); |
| 2242 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 2243 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
| 2244 | queue_writel(queue, RBQPH, upper_32_bits(queue->rx_ring_dma)); |
| 2245 | #endif |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2246 | queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 2247 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 2248 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 2249 | queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma)); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 2250 | #endif |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2251 | |
| 2252 | /* Enable interrupts */ |
| 2253 | queue_writel(queue, IER, |
| 2254 | MACB_RX_INT_FLAGS | |
| 2255 | MACB_TX_INT_FLAGS | |
| 2256 | MACB_BIT(HRESP)); |
| 2257 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2258 | |
| 2259 | /* Enable TX and RX */ |
Anssi Hannula | 0da70f8 | 2018-08-23 10:45:22 +0300 | [diff] [blame] | 2260 | macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(RE) | MACB_BIT(TE)); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2261 | } |
| 2262 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2263 | /* The hash address register is 64 bits long and takes up two |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2264 | * locations in the memory map. The least significant bits are stored |
| 2265 | * in EMAC_HSL and the most significant bits in EMAC_HSH. |
| 2266 | * |
| 2267 | * The unicast hash enable and the multicast hash enable bits in the |
| 2268 | * network configuration register enable the reception of hash matched |
| 2269 | * frames. The destination address is reduced to a 6 bit index into |
| 2270 | * the 64 bit hash register using the following hash function. The |
| 2271 | * hash function is an exclusive or of every sixth bit of the |
| 2272 | * destination address. |
| 2273 | * |
| 2274 | * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47] |
| 2275 | * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46] |
| 2276 | * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45] |
| 2277 | * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44] |
| 2278 | * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43] |
| 2279 | * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42] |
| 2280 | * |
| 2281 | * da[0] represents the least significant bit of the first byte |
| 2282 | * received, that is, the multicast/unicast indicator, and da[47] |
| 2283 | * represents the most significant bit of the last byte received. If |
| 2284 | * the hash index, hi[n], points to a bit that is set in the hash |
| 2285 | * register then the frame will be matched according to whether the |
| 2286 | * frame is multicast or unicast. A multicast match will be signalled |
| 2287 | * if the multicast hash enable bit is set, da[0] is 1 and the hash |
| 2288 | * index points to a bit set in the hash register. A unicast match |
| 2289 | * will be signalled if the unicast hash enable bit is set, da[0] is 0 |
| 2290 | * and the hash index points to a bit set in the hash register. To |
| 2291 | * receive all multicast frames, the hash register should be set with |
| 2292 | * all ones and the multicast hash enable bit should be set in the |
| 2293 | * network configuration register. |
| 2294 | */ |
| 2295 | |
| 2296 | static inline int hash_bit_value(int bitnr, __u8 *addr) |
| 2297 | { |
| 2298 | if (addr[bitnr / 8] & (1 << (bitnr % 8))) |
| 2299 | return 1; |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2303 | /* Return the hash index value for the specified address. */ |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2304 | static int hash_get_index(__u8 *addr) |
| 2305 | { |
| 2306 | int i, j, bitval; |
| 2307 | int hash_index = 0; |
| 2308 | |
| 2309 | for (j = 0; j < 6; j++) { |
| 2310 | for (i = 0, bitval = 0; i < 8; i++) |
Xander Huff | 2fa45e2 | 2015-01-15 15:55:19 -0600 | [diff] [blame] | 2311 | bitval ^= hash_bit_value(i * 6 + j, addr); |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2312 | |
| 2313 | hash_index |= (bitval << j); |
| 2314 | } |
| 2315 | |
| 2316 | return hash_index; |
| 2317 | } |
| 2318 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2319 | /* Add multicast addresses to the internal multicast-hash table. */ |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2320 | static void macb_sethashtable(struct net_device *dev) |
| 2321 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2322 | struct netdev_hw_addr *ha; |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2323 | unsigned long mc_filter[2]; |
Jiri Pirko | f9dcbcc | 2010-02-23 09:19:49 +0000 | [diff] [blame] | 2324 | unsigned int bitnr; |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2325 | struct macb *bp = netdev_priv(dev); |
| 2326 | |
Moritz Fischer | aa50b55 | 2016-03-29 19:11:13 -0700 | [diff] [blame] | 2327 | mc_filter[0] = 0; |
| 2328 | mc_filter[1] = 0; |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2329 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2330 | netdev_for_each_mc_addr(ha, dev) { |
| 2331 | bitnr = hash_get_index(ha->addr); |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2332 | mc_filter[bitnr >> 5] |= 1 << (bitnr & 31); |
| 2333 | } |
| 2334 | |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 2335 | macb_or_gem_writel(bp, HRB, mc_filter[0]); |
| 2336 | macb_or_gem_writel(bp, HRT, mc_filter[1]); |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2337 | } |
| 2338 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2339 | /* Enable/Disable promiscuous and multicast modes. */ |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 2340 | static void macb_set_rx_mode(struct net_device *dev) |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2341 | { |
| 2342 | unsigned long cfg; |
| 2343 | struct macb *bp = netdev_priv(dev); |
| 2344 | |
| 2345 | cfg = macb_readl(bp, NCFGR); |
| 2346 | |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 2347 | if (dev->flags & IFF_PROMISC) { |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2348 | /* Enable promiscuous mode */ |
| 2349 | cfg |= MACB_BIT(CAF); |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 2350 | |
| 2351 | /* Disable RX checksum offload */ |
| 2352 | if (macb_is_gem(bp)) |
| 2353 | cfg &= ~GEM_BIT(RXCOEN); |
| 2354 | } else { |
| 2355 | /* Disable promiscuous mode */ |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2356 | cfg &= ~MACB_BIT(CAF); |
| 2357 | |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 2358 | /* Enable RX checksum offload only if requested */ |
| 2359 | if (macb_is_gem(bp) && dev->features & NETIF_F_RXCSUM) |
| 2360 | cfg |= GEM_BIT(RXCOEN); |
| 2361 | } |
| 2362 | |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2363 | if (dev->flags & IFF_ALLMULTI) { |
| 2364 | /* Enable all multicast mode */ |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 2365 | macb_or_gem_writel(bp, HRB, -1); |
| 2366 | macb_or_gem_writel(bp, HRT, -1); |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2367 | cfg |= MACB_BIT(NCFGR_MTI); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 2368 | } else if (!netdev_mc_empty(dev)) { |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2369 | /* Enable specific multicasts */ |
| 2370 | macb_sethashtable(dev); |
| 2371 | cfg |= MACB_BIT(NCFGR_MTI); |
| 2372 | } else if (dev->flags & (~IFF_ALLMULTI)) { |
| 2373 | /* Disable all multicast mode */ |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 2374 | macb_or_gem_writel(bp, HRB, 0); |
| 2375 | macb_or_gem_writel(bp, HRT, 0); |
Patrice Vilchez | 446ebd0 | 2007-07-12 19:07:25 +0200 | [diff] [blame] | 2376 | cfg &= ~MACB_BIT(NCFGR_MTI); |
| 2377 | } |
| 2378 | |
| 2379 | macb_writel(bp, NCFGR, cfg); |
| 2380 | } |
| 2381 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2382 | static int macb_open(struct net_device *dev) |
| 2383 | { |
| 2384 | struct macb *bp = netdev_priv(dev); |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2385 | size_t bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2386 | struct macb_queue *queue; |
| 2387 | unsigned int q; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2388 | int err; |
| 2389 | |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 2390 | netdev_dbg(bp->dev, "open\n"); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2391 | |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 2392 | /* carrier starts down */ |
| 2393 | netif_carrier_off(dev); |
| 2394 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2395 | /* if the phy is not yet register, retry later*/ |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 2396 | if (!dev->phydev) |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2397 | return -EAGAIN; |
| 2398 | |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 2399 | /* RX buffers initialization */ |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2400 | macb_init_rx_buffer_size(bp, bufsz); |
Nicolas Ferre | 1b44791 | 2013-06-04 21:57:11 +0000 | [diff] [blame] | 2401 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2402 | err = macb_alloc_consistent(bp); |
| 2403 | if (err) { |
Jamie Iles | c220f8c | 2011-03-08 20:27:08 +0000 | [diff] [blame] | 2404 | netdev_err(dev, "Unable to allocate DMA memory (error %d)\n", |
| 2405 | err); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2406 | return err; |
| 2407 | } |
| 2408 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 2409 | bp->macbgem_ops.mog_init_rings(bp); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2410 | macb_init_hw(bp); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2411 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2412 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) |
| 2413 | napi_enable(&queue->napi); |
| 2414 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2415 | /* schedule a link state check */ |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 2416 | phy_start(dev->phydev); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2417 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2418 | netif_tx_start_all_queues(dev); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2419 | |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 2420 | if (bp->ptp_info) |
| 2421 | bp->ptp_info->ptp_init(dev); |
| 2422 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2423 | return 0; |
| 2424 | } |
| 2425 | |
| 2426 | static int macb_close(struct net_device *dev) |
| 2427 | { |
| 2428 | struct macb *bp = netdev_priv(dev); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2429 | struct macb_queue *queue; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2430 | unsigned long flags; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2431 | unsigned int q; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2432 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2433 | netif_tx_stop_all_queues(dev); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 2434 | |
| 2435 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) |
| 2436 | napi_disable(&queue->napi); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2437 | |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 2438 | if (dev->phydev) |
| 2439 | phy_stop(dev->phydev); |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2440 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2441 | spin_lock_irqsave(&bp->lock, flags); |
| 2442 | macb_reset_hw(bp); |
| 2443 | netif_carrier_off(dev); |
| 2444 | spin_unlock_irqrestore(&bp->lock, flags); |
| 2445 | |
| 2446 | macb_free_consistent(bp); |
| 2447 | |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 2448 | if (bp->ptp_info) |
| 2449 | bp->ptp_info->ptp_remove(dev); |
| 2450 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2451 | return 0; |
| 2452 | } |
| 2453 | |
Harini Katakam | a5898ea | 2015-05-06 22:27:18 +0530 | [diff] [blame] | 2454 | static int macb_change_mtu(struct net_device *dev, int new_mtu) |
| 2455 | { |
Harini Katakam | a5898ea | 2015-05-06 22:27:18 +0530 | [diff] [blame] | 2456 | if (netif_running(dev)) |
| 2457 | return -EBUSY; |
| 2458 | |
Harini Katakam | a5898ea | 2015-05-06 22:27:18 +0530 | [diff] [blame] | 2459 | dev->mtu = new_mtu; |
| 2460 | |
| 2461 | return 0; |
| 2462 | } |
| 2463 | |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2464 | static void gem_update_stats(struct macb *bp) |
| 2465 | { |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2466 | struct macb_queue *queue; |
| 2467 | unsigned int i, q, idx; |
| 2468 | unsigned long *stat; |
| 2469 | |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2470 | u32 *p = &bp->hw_stats.gem.tx_octets_31_0; |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2471 | |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2472 | for (i = 0; i < GEM_STATS_LEN; ++i, ++p) { |
| 2473 | u32 offset = gem_statistics[i].offset; |
David S. Miller | 7a6e070 | 2015-07-27 14:24:48 -0700 | [diff] [blame] | 2474 | u64 val = bp->macb_reg_readl(bp, offset); |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2475 | |
| 2476 | bp->ethtool_stats[i] += val; |
| 2477 | *p += val; |
| 2478 | |
| 2479 | if (offset == GEM_OCTTXL || offset == GEM_OCTRXL) { |
| 2480 | /* Add GEM_OCTTXH, GEM_OCTRXH */ |
David S. Miller | 7a6e070 | 2015-07-27 14:24:48 -0700 | [diff] [blame] | 2481 | val = bp->macb_reg_readl(bp, offset + 4); |
Xander Huff | 2fa45e2 | 2015-01-15 15:55:19 -0600 | [diff] [blame] | 2482 | bp->ethtool_stats[i] += ((u64)val) << 32; |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2483 | *(++p) += val; |
| 2484 | } |
| 2485 | } |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2486 | |
| 2487 | idx = GEM_STATS_LEN; |
| 2488 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) |
| 2489 | for (i = 0, stat = &queue->stats.first; i < QUEUE_STATS_LEN; ++i, ++stat) |
| 2490 | bp->ethtool_stats[idx++] = *stat; |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | static struct net_device_stats *gem_get_stats(struct macb *bp) |
| 2494 | { |
| 2495 | struct gem_stats *hwstat = &bp->hw_stats.gem; |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 2496 | struct net_device_stats *nstat = &bp->dev->stats; |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2497 | |
| 2498 | gem_update_stats(bp); |
| 2499 | |
| 2500 | nstat->rx_errors = (hwstat->rx_frame_check_sequence_errors + |
| 2501 | hwstat->rx_alignment_errors + |
| 2502 | hwstat->rx_resource_errors + |
| 2503 | hwstat->rx_overruns + |
| 2504 | hwstat->rx_oversize_frames + |
| 2505 | hwstat->rx_jabbers + |
| 2506 | hwstat->rx_undersized_frames + |
| 2507 | hwstat->rx_length_field_frame_errors); |
| 2508 | nstat->tx_errors = (hwstat->tx_late_collisions + |
| 2509 | hwstat->tx_excessive_collisions + |
| 2510 | hwstat->tx_underrun + |
| 2511 | hwstat->tx_carrier_sense_errors); |
| 2512 | nstat->multicast = hwstat->rx_multicast_frames; |
| 2513 | nstat->collisions = (hwstat->tx_single_collision_frames + |
| 2514 | hwstat->tx_multiple_collision_frames + |
| 2515 | hwstat->tx_excessive_collisions); |
| 2516 | nstat->rx_length_errors = (hwstat->rx_oversize_frames + |
| 2517 | hwstat->rx_jabbers + |
| 2518 | hwstat->rx_undersized_frames + |
| 2519 | hwstat->rx_length_field_frame_errors); |
| 2520 | nstat->rx_over_errors = hwstat->rx_resource_errors; |
| 2521 | nstat->rx_crc_errors = hwstat->rx_frame_check_sequence_errors; |
| 2522 | nstat->rx_frame_errors = hwstat->rx_alignment_errors; |
| 2523 | nstat->rx_fifo_errors = hwstat->rx_overruns; |
| 2524 | nstat->tx_aborted_errors = hwstat->tx_excessive_collisions; |
| 2525 | nstat->tx_carrier_errors = hwstat->tx_carrier_sense_errors; |
| 2526 | nstat->tx_fifo_errors = hwstat->tx_underrun; |
| 2527 | |
| 2528 | return nstat; |
| 2529 | } |
| 2530 | |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2531 | static void gem_get_ethtool_stats(struct net_device *dev, |
| 2532 | struct ethtool_stats *stats, u64 *data) |
| 2533 | { |
| 2534 | struct macb *bp; |
| 2535 | |
| 2536 | bp = netdev_priv(dev); |
| 2537 | gem_update_stats(bp); |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2538 | memcpy(data, &bp->ethtool_stats, sizeof(u64) |
| 2539 | * (GEM_STATS_LEN + QUEUE_STATS_LEN * MACB_MAX_QUEUES)); |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | static int gem_get_sset_count(struct net_device *dev, int sset) |
| 2543 | { |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2544 | struct macb *bp = netdev_priv(dev); |
| 2545 | |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2546 | switch (sset) { |
| 2547 | case ETH_SS_STATS: |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2548 | return GEM_STATS_LEN + bp->num_queues * QUEUE_STATS_LEN; |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2549 | default: |
| 2550 | return -EOPNOTSUPP; |
| 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | static void gem_get_ethtool_strings(struct net_device *dev, u32 sset, u8 *p) |
| 2555 | { |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2556 | char stat_string[ETH_GSTRING_LEN]; |
| 2557 | struct macb *bp = netdev_priv(dev); |
| 2558 | struct macb_queue *queue; |
Andy Shevchenko | 8bcbf82 | 2015-07-24 21:24:02 +0300 | [diff] [blame] | 2559 | unsigned int i; |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2560 | unsigned int q; |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2561 | |
| 2562 | switch (sset) { |
| 2563 | case ETH_SS_STATS: |
| 2564 | for (i = 0; i < GEM_STATS_LEN; i++, p += ETH_GSTRING_LEN) |
| 2565 | memcpy(p, gem_statistics[i].stat_string, |
| 2566 | ETH_GSTRING_LEN); |
Rafal Ozieblo | 512286b | 2017-11-30 18:19:56 +0000 | [diff] [blame] | 2567 | |
| 2568 | for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { |
| 2569 | for (i = 0; i < QUEUE_STATS_LEN; i++, p += ETH_GSTRING_LEN) { |
| 2570 | snprintf(stat_string, ETH_GSTRING_LEN, "q%d_%s", |
| 2571 | q, queue_statistics[i].stat_string); |
| 2572 | memcpy(p, stat_string, ETH_GSTRING_LEN); |
| 2573 | } |
| 2574 | } |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 2575 | break; |
| 2576 | } |
| 2577 | } |
| 2578 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 2579 | static struct net_device_stats *macb_get_stats(struct net_device *dev) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2580 | { |
| 2581 | struct macb *bp = netdev_priv(dev); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 2582 | struct net_device_stats *nstat = &bp->dev->stats; |
Jamie Iles | a494ed8 | 2011-03-09 16:26:35 +0000 | [diff] [blame] | 2583 | struct macb_stats *hwstat = &bp->hw_stats.macb; |
| 2584 | |
| 2585 | if (macb_is_gem(bp)) |
| 2586 | return gem_get_stats(bp); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2587 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 2588 | /* read stats from hardware */ |
| 2589 | macb_update_stats(bp); |
| 2590 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2591 | /* Convert HW stats into netdevice stats */ |
| 2592 | nstat->rx_errors = (hwstat->rx_fcs_errors + |
| 2593 | hwstat->rx_align_errors + |
| 2594 | hwstat->rx_resource_errors + |
| 2595 | hwstat->rx_overruns + |
| 2596 | hwstat->rx_oversize_pkts + |
| 2597 | hwstat->rx_jabbers + |
| 2598 | hwstat->rx_undersize_pkts + |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2599 | hwstat->rx_length_mismatch); |
| 2600 | nstat->tx_errors = (hwstat->tx_late_cols + |
| 2601 | hwstat->tx_excessive_cols + |
| 2602 | hwstat->tx_underruns + |
Wolfgang Steinwender | 716723c | 2015-04-10 11:42:56 +0200 | [diff] [blame] | 2603 | hwstat->tx_carrier_errors + |
| 2604 | hwstat->sqe_test_errors); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2605 | nstat->collisions = (hwstat->tx_single_cols + |
| 2606 | hwstat->tx_multiple_cols + |
| 2607 | hwstat->tx_excessive_cols); |
| 2608 | nstat->rx_length_errors = (hwstat->rx_oversize_pkts + |
| 2609 | hwstat->rx_jabbers + |
| 2610 | hwstat->rx_undersize_pkts + |
| 2611 | hwstat->rx_length_mismatch); |
Alexander Stein | b19f7f7 | 2011-04-13 05:03:24 +0000 | [diff] [blame] | 2612 | nstat->rx_over_errors = hwstat->rx_resource_errors + |
| 2613 | hwstat->rx_overruns; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 2614 | nstat->rx_crc_errors = hwstat->rx_fcs_errors; |
| 2615 | nstat->rx_frame_errors = hwstat->rx_align_errors; |
| 2616 | nstat->rx_fifo_errors = hwstat->rx_overruns; |
| 2617 | /* XXX: What does "missed" mean? */ |
| 2618 | nstat->tx_aborted_errors = hwstat->tx_excessive_cols; |
| 2619 | nstat->tx_carrier_errors = hwstat->tx_carrier_errors; |
| 2620 | nstat->tx_fifo_errors = hwstat->tx_underruns; |
| 2621 | /* Don't know about heartbeat or window errors... */ |
| 2622 | |
| 2623 | return nstat; |
| 2624 | } |
| 2625 | |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 2626 | static int macb_get_regs_len(struct net_device *netdev) |
| 2627 | { |
| 2628 | return MACB_GREGS_NBR * sizeof(u32); |
| 2629 | } |
| 2630 | |
| 2631 | static void macb_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2632 | void *p) |
| 2633 | { |
| 2634 | struct macb *bp = netdev_priv(dev); |
| 2635 | unsigned int tail, head; |
| 2636 | u32 *regs_buff = p; |
| 2637 | |
| 2638 | regs->version = (macb_readl(bp, MID) & ((1 << MACB_REV_SIZE) - 1)) |
| 2639 | | MACB_GREGS_VERSION; |
| 2640 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 2641 | tail = macb_tx_ring_wrap(bp, bp->queues[0].tx_tail); |
| 2642 | head = macb_tx_ring_wrap(bp, bp->queues[0].tx_head); |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 2643 | |
| 2644 | regs_buff[0] = macb_readl(bp, NCR); |
| 2645 | regs_buff[1] = macb_or_gem_readl(bp, NCFGR); |
| 2646 | regs_buff[2] = macb_readl(bp, NSR); |
| 2647 | regs_buff[3] = macb_readl(bp, TSR); |
| 2648 | regs_buff[4] = macb_readl(bp, RBQP); |
| 2649 | regs_buff[5] = macb_readl(bp, TBQP); |
| 2650 | regs_buff[6] = macb_readl(bp, RSR); |
| 2651 | regs_buff[7] = macb_readl(bp, IMR); |
| 2652 | |
| 2653 | regs_buff[8] = tail; |
| 2654 | regs_buff[9] = head; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 2655 | regs_buff[10] = macb_tx_dma(&bp->queues[0], tail); |
| 2656 | regs_buff[11] = macb_tx_dma(&bp->queues[0], head); |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 2657 | |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 2658 | if (!(bp->caps & MACB_CAPS_USRIO_DISABLED)) |
| 2659 | regs_buff[12] = macb_or_gem_readl(bp, USRIO); |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 2660 | if (macb_is_gem(bp)) |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 2661 | regs_buff[13] = gem_readl(bp, DMACFG); |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 2664 | static void macb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 2665 | { |
| 2666 | struct macb *bp = netdev_priv(netdev); |
| 2667 | |
| 2668 | wol->supported = 0; |
| 2669 | wol->wolopts = 0; |
| 2670 | |
| 2671 | if (bp->wol & MACB_WOL_HAS_MAGIC_PACKET) { |
| 2672 | wol->supported = WAKE_MAGIC; |
| 2673 | |
| 2674 | if (bp->wol & MACB_WOL_ENABLED) |
| 2675 | wol->wolopts |= WAKE_MAGIC; |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 2680 | { |
| 2681 | struct macb *bp = netdev_priv(netdev); |
| 2682 | |
| 2683 | if (!(bp->wol & MACB_WOL_HAS_MAGIC_PACKET) || |
| 2684 | (wol->wolopts & ~WAKE_MAGIC)) |
| 2685 | return -EOPNOTSUPP; |
| 2686 | |
| 2687 | if (wol->wolopts & WAKE_MAGIC) |
| 2688 | bp->wol |= MACB_WOL_ENABLED; |
| 2689 | else |
| 2690 | bp->wol &= ~MACB_WOL_ENABLED; |
| 2691 | |
| 2692 | device_set_wakeup_enable(&bp->pdev->dev, bp->wol & MACB_WOL_ENABLED); |
| 2693 | |
| 2694 | return 0; |
| 2695 | } |
| 2696 | |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 2697 | static void macb_get_ringparam(struct net_device *netdev, |
| 2698 | struct ethtool_ringparam *ring) |
| 2699 | { |
| 2700 | struct macb *bp = netdev_priv(netdev); |
| 2701 | |
| 2702 | ring->rx_max_pending = MAX_RX_RING_SIZE; |
| 2703 | ring->tx_max_pending = MAX_TX_RING_SIZE; |
| 2704 | |
| 2705 | ring->rx_pending = bp->rx_ring_size; |
| 2706 | ring->tx_pending = bp->tx_ring_size; |
| 2707 | } |
| 2708 | |
| 2709 | static int macb_set_ringparam(struct net_device *netdev, |
| 2710 | struct ethtool_ringparam *ring) |
| 2711 | { |
| 2712 | struct macb *bp = netdev_priv(netdev); |
| 2713 | u32 new_rx_size, new_tx_size; |
| 2714 | unsigned int reset = 0; |
| 2715 | |
| 2716 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 2717 | return -EINVAL; |
| 2718 | |
| 2719 | new_rx_size = clamp_t(u32, ring->rx_pending, |
| 2720 | MIN_RX_RING_SIZE, MAX_RX_RING_SIZE); |
| 2721 | new_rx_size = roundup_pow_of_two(new_rx_size); |
| 2722 | |
| 2723 | new_tx_size = clamp_t(u32, ring->tx_pending, |
| 2724 | MIN_TX_RING_SIZE, MAX_TX_RING_SIZE); |
| 2725 | new_tx_size = roundup_pow_of_two(new_tx_size); |
| 2726 | |
| 2727 | if ((new_tx_size == bp->tx_ring_size) && |
| 2728 | (new_rx_size == bp->rx_ring_size)) { |
| 2729 | /* nothing to do */ |
| 2730 | return 0; |
| 2731 | } |
| 2732 | |
| 2733 | if (netif_running(bp->dev)) { |
| 2734 | reset = 1; |
| 2735 | macb_close(bp->dev); |
| 2736 | } |
| 2737 | |
| 2738 | bp->rx_ring_size = new_rx_size; |
| 2739 | bp->tx_ring_size = new_tx_size; |
| 2740 | |
| 2741 | if (reset) |
| 2742 | macb_open(bp->dev); |
| 2743 | |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 2747 | #ifdef CONFIG_MACB_USE_HWSTAMP |
| 2748 | static unsigned int gem_get_tsu_rate(struct macb *bp) |
| 2749 | { |
| 2750 | struct clk *tsu_clk; |
| 2751 | unsigned int tsu_rate; |
| 2752 | |
| 2753 | tsu_clk = devm_clk_get(&bp->pdev->dev, "tsu_clk"); |
| 2754 | if (!IS_ERR(tsu_clk)) |
| 2755 | tsu_rate = clk_get_rate(tsu_clk); |
| 2756 | /* try pclk instead */ |
| 2757 | else if (!IS_ERR(bp->pclk)) { |
| 2758 | tsu_clk = bp->pclk; |
| 2759 | tsu_rate = clk_get_rate(tsu_clk); |
| 2760 | } else |
| 2761 | return -ENOTSUPP; |
| 2762 | return tsu_rate; |
| 2763 | } |
| 2764 | |
| 2765 | static s32 gem_get_ptp_max_adj(void) |
| 2766 | { |
| 2767 | return 64000000; |
| 2768 | } |
| 2769 | |
| 2770 | static int gem_get_ts_info(struct net_device *dev, |
| 2771 | struct ethtool_ts_info *info) |
| 2772 | { |
| 2773 | struct macb *bp = netdev_priv(dev); |
| 2774 | |
| 2775 | if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0) { |
| 2776 | ethtool_op_get_ts_info(dev, info); |
| 2777 | return 0; |
| 2778 | } |
| 2779 | |
| 2780 | info->so_timestamping = |
| 2781 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 2782 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 2783 | SOF_TIMESTAMPING_SOFTWARE | |
| 2784 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 2785 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 2786 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 2787 | info->tx_types = |
| 2788 | (1 << HWTSTAMP_TX_ONESTEP_SYNC) | |
| 2789 | (1 << HWTSTAMP_TX_OFF) | |
| 2790 | (1 << HWTSTAMP_TX_ON); |
| 2791 | info->rx_filters = |
| 2792 | (1 << HWTSTAMP_FILTER_NONE) | |
| 2793 | (1 << HWTSTAMP_FILTER_ALL); |
| 2794 | |
| 2795 | info->phc_index = bp->ptp_clock ? ptp_clock_index(bp->ptp_clock) : -1; |
| 2796 | |
| 2797 | return 0; |
| 2798 | } |
| 2799 | |
| 2800 | static struct macb_ptp_info gem_ptp_info = { |
| 2801 | .ptp_init = gem_ptp_init, |
| 2802 | .ptp_remove = gem_ptp_remove, |
| 2803 | .get_ptp_max_adj = gem_get_ptp_max_adj, |
| 2804 | .get_tsu_rate = gem_get_tsu_rate, |
| 2805 | .get_ts_info = gem_get_ts_info, |
| 2806 | .get_hwtst = gem_get_hwtst, |
| 2807 | .set_hwtst = gem_set_hwtst, |
| 2808 | }; |
| 2809 | #endif |
| 2810 | |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 2811 | static int macb_get_ts_info(struct net_device *netdev, |
| 2812 | struct ethtool_ts_info *info) |
| 2813 | { |
| 2814 | struct macb *bp = netdev_priv(netdev); |
| 2815 | |
| 2816 | if (bp->ptp_info) |
| 2817 | return bp->ptp_info->get_ts_info(netdev, info); |
| 2818 | |
| 2819 | return ethtool_op_get_ts_info(netdev, info); |
| 2820 | } |
| 2821 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2822 | static void gem_enable_flow_filters(struct macb *bp, bool enable) |
| 2823 | { |
| 2824 | struct ethtool_rx_fs_item *item; |
| 2825 | u32 t2_scr; |
| 2826 | int num_t2_scr; |
| 2827 | |
| 2828 | num_t2_scr = GEM_BFEXT(T2SCR, gem_readl(bp, DCFG8)); |
| 2829 | |
| 2830 | list_for_each_entry(item, &bp->rx_fs_list.list, list) { |
| 2831 | struct ethtool_rx_flow_spec *fs = &item->fs; |
| 2832 | struct ethtool_tcpip4_spec *tp4sp_m; |
| 2833 | |
| 2834 | if (fs->location >= num_t2_scr) |
| 2835 | continue; |
| 2836 | |
| 2837 | t2_scr = gem_readl_n(bp, SCRT2, fs->location); |
| 2838 | |
| 2839 | /* enable/disable screener regs for the flow entry */ |
| 2840 | t2_scr = GEM_BFINS(ETHTEN, enable, t2_scr); |
| 2841 | |
| 2842 | /* only enable fields with no masking */ |
| 2843 | tp4sp_m = &(fs->m_u.tcp_ip4_spec); |
| 2844 | |
| 2845 | if (enable && (tp4sp_m->ip4src == 0xFFFFFFFF)) |
| 2846 | t2_scr = GEM_BFINS(CMPAEN, 1, t2_scr); |
| 2847 | else |
| 2848 | t2_scr = GEM_BFINS(CMPAEN, 0, t2_scr); |
| 2849 | |
| 2850 | if (enable && (tp4sp_m->ip4dst == 0xFFFFFFFF)) |
| 2851 | t2_scr = GEM_BFINS(CMPBEN, 1, t2_scr); |
| 2852 | else |
| 2853 | t2_scr = GEM_BFINS(CMPBEN, 0, t2_scr); |
| 2854 | |
| 2855 | if (enable && ((tp4sp_m->psrc == 0xFFFF) || (tp4sp_m->pdst == 0xFFFF))) |
| 2856 | t2_scr = GEM_BFINS(CMPCEN, 1, t2_scr); |
| 2857 | else |
| 2858 | t2_scr = GEM_BFINS(CMPCEN, 0, t2_scr); |
| 2859 | |
| 2860 | gem_writel_n(bp, SCRT2, fs->location, t2_scr); |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | static void gem_prog_cmp_regs(struct macb *bp, struct ethtool_rx_flow_spec *fs) |
| 2865 | { |
| 2866 | struct ethtool_tcpip4_spec *tp4sp_v, *tp4sp_m; |
| 2867 | uint16_t index = fs->location; |
| 2868 | u32 w0, w1, t2_scr; |
| 2869 | bool cmp_a = false; |
| 2870 | bool cmp_b = false; |
| 2871 | bool cmp_c = false; |
| 2872 | |
| 2873 | tp4sp_v = &(fs->h_u.tcp_ip4_spec); |
| 2874 | tp4sp_m = &(fs->m_u.tcp_ip4_spec); |
| 2875 | |
| 2876 | /* ignore field if any masking set */ |
| 2877 | if (tp4sp_m->ip4src == 0xFFFFFFFF) { |
| 2878 | /* 1st compare reg - IP source address */ |
| 2879 | w0 = 0; |
| 2880 | w1 = 0; |
| 2881 | w0 = tp4sp_v->ip4src; |
| 2882 | w1 = GEM_BFINS(T2DISMSK, 1, w1); /* 32-bit compare */ |
| 2883 | w1 = GEM_BFINS(T2CMPOFST, GEM_T2COMPOFST_ETYPE, w1); |
| 2884 | w1 = GEM_BFINS(T2OFST, ETYPE_SRCIP_OFFSET, w1); |
| 2885 | gem_writel_n(bp, T2CMPW0, T2CMP_OFST(GEM_IP4SRC_CMP(index)), w0); |
| 2886 | gem_writel_n(bp, T2CMPW1, T2CMP_OFST(GEM_IP4SRC_CMP(index)), w1); |
| 2887 | cmp_a = true; |
| 2888 | } |
| 2889 | |
| 2890 | /* ignore field if any masking set */ |
| 2891 | if (tp4sp_m->ip4dst == 0xFFFFFFFF) { |
| 2892 | /* 2nd compare reg - IP destination address */ |
| 2893 | w0 = 0; |
| 2894 | w1 = 0; |
| 2895 | w0 = tp4sp_v->ip4dst; |
| 2896 | w1 = GEM_BFINS(T2DISMSK, 1, w1); /* 32-bit compare */ |
| 2897 | w1 = GEM_BFINS(T2CMPOFST, GEM_T2COMPOFST_ETYPE, w1); |
| 2898 | w1 = GEM_BFINS(T2OFST, ETYPE_DSTIP_OFFSET, w1); |
| 2899 | gem_writel_n(bp, T2CMPW0, T2CMP_OFST(GEM_IP4DST_CMP(index)), w0); |
| 2900 | gem_writel_n(bp, T2CMPW1, T2CMP_OFST(GEM_IP4DST_CMP(index)), w1); |
| 2901 | cmp_b = true; |
| 2902 | } |
| 2903 | |
| 2904 | /* ignore both port fields if masking set in both */ |
| 2905 | if ((tp4sp_m->psrc == 0xFFFF) || (tp4sp_m->pdst == 0xFFFF)) { |
| 2906 | /* 3rd compare reg - source port, destination port */ |
| 2907 | w0 = 0; |
| 2908 | w1 = 0; |
| 2909 | w1 = GEM_BFINS(T2CMPOFST, GEM_T2COMPOFST_IPHDR, w1); |
| 2910 | if (tp4sp_m->psrc == tp4sp_m->pdst) { |
| 2911 | w0 = GEM_BFINS(T2MASK, tp4sp_v->psrc, w0); |
| 2912 | w0 = GEM_BFINS(T2CMP, tp4sp_v->pdst, w0); |
| 2913 | w1 = GEM_BFINS(T2DISMSK, 1, w1); /* 32-bit compare */ |
| 2914 | w1 = GEM_BFINS(T2OFST, IPHDR_SRCPORT_OFFSET, w1); |
| 2915 | } else { |
| 2916 | /* only one port definition */ |
| 2917 | w1 = GEM_BFINS(T2DISMSK, 0, w1); /* 16-bit compare */ |
| 2918 | w0 = GEM_BFINS(T2MASK, 0xFFFF, w0); |
| 2919 | if (tp4sp_m->psrc == 0xFFFF) { /* src port */ |
| 2920 | w0 = GEM_BFINS(T2CMP, tp4sp_v->psrc, w0); |
| 2921 | w1 = GEM_BFINS(T2OFST, IPHDR_SRCPORT_OFFSET, w1); |
| 2922 | } else { /* dst port */ |
| 2923 | w0 = GEM_BFINS(T2CMP, tp4sp_v->pdst, w0); |
| 2924 | w1 = GEM_BFINS(T2OFST, IPHDR_DSTPORT_OFFSET, w1); |
| 2925 | } |
| 2926 | } |
| 2927 | gem_writel_n(bp, T2CMPW0, T2CMP_OFST(GEM_PORT_CMP(index)), w0); |
| 2928 | gem_writel_n(bp, T2CMPW1, T2CMP_OFST(GEM_PORT_CMP(index)), w1); |
| 2929 | cmp_c = true; |
| 2930 | } |
| 2931 | |
| 2932 | t2_scr = 0; |
| 2933 | t2_scr = GEM_BFINS(QUEUE, (fs->ring_cookie) & 0xFF, t2_scr); |
| 2934 | t2_scr = GEM_BFINS(ETHT2IDX, SCRT2_ETHT, t2_scr); |
| 2935 | if (cmp_a) |
| 2936 | t2_scr = GEM_BFINS(CMPA, GEM_IP4SRC_CMP(index), t2_scr); |
| 2937 | if (cmp_b) |
| 2938 | t2_scr = GEM_BFINS(CMPB, GEM_IP4DST_CMP(index), t2_scr); |
| 2939 | if (cmp_c) |
| 2940 | t2_scr = GEM_BFINS(CMPC, GEM_PORT_CMP(index), t2_scr); |
| 2941 | gem_writel_n(bp, SCRT2, index, t2_scr); |
| 2942 | } |
| 2943 | |
| 2944 | static int gem_add_flow_filter(struct net_device *netdev, |
| 2945 | struct ethtool_rxnfc *cmd) |
| 2946 | { |
| 2947 | struct macb *bp = netdev_priv(netdev); |
| 2948 | struct ethtool_rx_flow_spec *fs = &cmd->fs; |
| 2949 | struct ethtool_rx_fs_item *item, *newfs; |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 2950 | unsigned long flags; |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2951 | int ret = -EINVAL; |
| 2952 | bool added = false; |
| 2953 | |
Julia Cartwright | cc1674e | 2017-12-05 18:02:50 -0600 | [diff] [blame] | 2954 | newfs = kmalloc(sizeof(*newfs), GFP_KERNEL); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2955 | if (newfs == NULL) |
| 2956 | return -ENOMEM; |
| 2957 | memcpy(&newfs->fs, fs, sizeof(newfs->fs)); |
| 2958 | |
| 2959 | netdev_dbg(netdev, |
| 2960 | "Adding flow filter entry,type=%u,queue=%u,loc=%u,src=%08X,dst=%08X,ps=%u,pd=%u\n", |
| 2961 | fs->flow_type, (int)fs->ring_cookie, fs->location, |
| 2962 | htonl(fs->h_u.tcp_ip4_spec.ip4src), |
| 2963 | htonl(fs->h_u.tcp_ip4_spec.ip4dst), |
| 2964 | htons(fs->h_u.tcp_ip4_spec.psrc), htons(fs->h_u.tcp_ip4_spec.pdst)); |
| 2965 | |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 2966 | spin_lock_irqsave(&bp->rx_fs_lock, flags); |
| 2967 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2968 | /* find correct place to add in list */ |
Julia Cartwright | a3da8ad | 2017-12-05 18:02:48 -0600 | [diff] [blame] | 2969 | list_for_each_entry(item, &bp->rx_fs_list.list, list) { |
| 2970 | if (item->fs.location > newfs->fs.location) { |
| 2971 | list_add_tail(&newfs->list, &item->list); |
| 2972 | added = true; |
| 2973 | break; |
| 2974 | } else if (item->fs.location == fs->location) { |
| 2975 | netdev_err(netdev, "Rule not added: location %d not free!\n", |
| 2976 | fs->location); |
| 2977 | ret = -EBUSY; |
| 2978 | goto err; |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2979 | } |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2980 | } |
Julia Cartwright | a3da8ad | 2017-12-05 18:02:48 -0600 | [diff] [blame] | 2981 | if (!added) |
| 2982 | list_add_tail(&newfs->list, &bp->rx_fs_list.list); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2983 | |
| 2984 | gem_prog_cmp_regs(bp, fs); |
| 2985 | bp->rx_fs_list.count++; |
| 2986 | /* enable filtering if NTUPLE on */ |
| 2987 | if (netdev->features & NETIF_F_NTUPLE) |
| 2988 | gem_enable_flow_filters(bp, 1); |
| 2989 | |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 2990 | spin_unlock_irqrestore(&bp->rx_fs_lock, flags); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2991 | return 0; |
| 2992 | |
| 2993 | err: |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 2994 | spin_unlock_irqrestore(&bp->rx_fs_lock, flags); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 2995 | kfree(newfs); |
| 2996 | return ret; |
| 2997 | } |
| 2998 | |
| 2999 | static int gem_del_flow_filter(struct net_device *netdev, |
| 3000 | struct ethtool_rxnfc *cmd) |
| 3001 | { |
| 3002 | struct macb *bp = netdev_priv(netdev); |
| 3003 | struct ethtool_rx_fs_item *item; |
| 3004 | struct ethtool_rx_flow_spec *fs; |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 3005 | unsigned long flags; |
| 3006 | |
| 3007 | spin_lock_irqsave(&bp->rx_fs_lock, flags); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3008 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3009 | list_for_each_entry(item, &bp->rx_fs_list.list, list) { |
| 3010 | if (item->fs.location == cmd->fs.location) { |
| 3011 | /* disable screener regs for the flow entry */ |
| 3012 | fs = &(item->fs); |
| 3013 | netdev_dbg(netdev, |
| 3014 | "Deleting flow filter entry,type=%u,queue=%u,loc=%u,src=%08X,dst=%08X,ps=%u,pd=%u\n", |
| 3015 | fs->flow_type, (int)fs->ring_cookie, fs->location, |
| 3016 | htonl(fs->h_u.tcp_ip4_spec.ip4src), |
| 3017 | htonl(fs->h_u.tcp_ip4_spec.ip4dst), |
| 3018 | htons(fs->h_u.tcp_ip4_spec.psrc), |
| 3019 | htons(fs->h_u.tcp_ip4_spec.pdst)); |
| 3020 | |
| 3021 | gem_writel_n(bp, SCRT2, fs->location, 0); |
| 3022 | |
| 3023 | list_del(&item->list); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3024 | bp->rx_fs_list.count--; |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 3025 | spin_unlock_irqrestore(&bp->rx_fs_lock, flags); |
| 3026 | kfree(item); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3027 | return 0; |
| 3028 | } |
| 3029 | } |
| 3030 | |
Julia Cartwright | 7038cdb | 2017-12-05 18:02:49 -0600 | [diff] [blame] | 3031 | spin_unlock_irqrestore(&bp->rx_fs_lock, flags); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3032 | return -EINVAL; |
| 3033 | } |
| 3034 | |
| 3035 | static int gem_get_flow_entry(struct net_device *netdev, |
| 3036 | struct ethtool_rxnfc *cmd) |
| 3037 | { |
| 3038 | struct macb *bp = netdev_priv(netdev); |
| 3039 | struct ethtool_rx_fs_item *item; |
| 3040 | |
| 3041 | list_for_each_entry(item, &bp->rx_fs_list.list, list) { |
| 3042 | if (item->fs.location == cmd->fs.location) { |
| 3043 | memcpy(&cmd->fs, &item->fs, sizeof(cmd->fs)); |
| 3044 | return 0; |
| 3045 | } |
| 3046 | } |
| 3047 | return -EINVAL; |
| 3048 | } |
| 3049 | |
| 3050 | static int gem_get_all_flow_entries(struct net_device *netdev, |
| 3051 | struct ethtool_rxnfc *cmd, u32 *rule_locs) |
| 3052 | { |
| 3053 | struct macb *bp = netdev_priv(netdev); |
| 3054 | struct ethtool_rx_fs_item *item; |
| 3055 | uint32_t cnt = 0; |
| 3056 | |
| 3057 | list_for_each_entry(item, &bp->rx_fs_list.list, list) { |
| 3058 | if (cnt == cmd->rule_cnt) |
| 3059 | return -EMSGSIZE; |
| 3060 | rule_locs[cnt] = item->fs.location; |
| 3061 | cnt++; |
| 3062 | } |
| 3063 | cmd->data = bp->max_tuples; |
| 3064 | cmd->rule_cnt = cnt; |
| 3065 | |
| 3066 | return 0; |
| 3067 | } |
| 3068 | |
| 3069 | static int gem_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 3070 | u32 *rule_locs) |
| 3071 | { |
| 3072 | struct macb *bp = netdev_priv(netdev); |
| 3073 | int ret = 0; |
| 3074 | |
| 3075 | switch (cmd->cmd) { |
| 3076 | case ETHTOOL_GRXRINGS: |
| 3077 | cmd->data = bp->num_queues; |
| 3078 | break; |
| 3079 | case ETHTOOL_GRXCLSRLCNT: |
| 3080 | cmd->rule_cnt = bp->rx_fs_list.count; |
| 3081 | break; |
| 3082 | case ETHTOOL_GRXCLSRULE: |
| 3083 | ret = gem_get_flow_entry(netdev, cmd); |
| 3084 | break; |
| 3085 | case ETHTOOL_GRXCLSRLALL: |
| 3086 | ret = gem_get_all_flow_entries(netdev, cmd, rule_locs); |
| 3087 | break; |
| 3088 | default: |
| 3089 | netdev_err(netdev, |
| 3090 | "Command parameter %d is not supported\n", cmd->cmd); |
| 3091 | ret = -EOPNOTSUPP; |
| 3092 | } |
| 3093 | |
| 3094 | return ret; |
| 3095 | } |
| 3096 | |
| 3097 | static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 3098 | { |
| 3099 | struct macb *bp = netdev_priv(netdev); |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3100 | int ret; |
| 3101 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3102 | switch (cmd->cmd) { |
| 3103 | case ETHTOOL_SRXCLSRLINS: |
| 3104 | if ((cmd->fs.location >= bp->max_tuples) |
| 3105 | || (cmd->fs.ring_cookie >= bp->num_queues)) { |
| 3106 | ret = -EINVAL; |
| 3107 | break; |
| 3108 | } |
| 3109 | ret = gem_add_flow_filter(netdev, cmd); |
| 3110 | break; |
| 3111 | case ETHTOOL_SRXCLSRLDEL: |
| 3112 | ret = gem_del_flow_filter(netdev, cmd); |
| 3113 | break; |
| 3114 | default: |
| 3115 | netdev_err(netdev, |
| 3116 | "Command parameter %d is not supported\n", cmd->cmd); |
| 3117 | ret = -EOPNOTSUPP; |
| 3118 | } |
| 3119 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3120 | return ret; |
| 3121 | } |
| 3122 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3123 | static const struct ethtool_ops macb_ethtool_ops = { |
Nicolas Ferre | d1d1b53 | 2012-10-31 06:04:56 +0000 | [diff] [blame] | 3124 | .get_regs_len = macb_get_regs_len, |
| 3125 | .get_regs = macb_get_regs, |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3126 | .get_link = ethtool_op_get_link, |
Richard Cochran | 17f393e | 2012-04-03 22:59:31 +0000 | [diff] [blame] | 3127 | .get_ts_info = ethtool_op_get_ts_info, |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 3128 | .get_wol = macb_get_wol, |
| 3129 | .set_wol = macb_set_wol, |
Philippe Reynes | 176275a | 2016-06-22 00:32:36 +0200 | [diff] [blame] | 3130 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 3131 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 3132 | .get_ringparam = macb_get_ringparam, |
| 3133 | .set_ringparam = macb_set_ringparam, |
Xander Huff | 8cd5a56 | 2015-01-15 15:55:20 -0600 | [diff] [blame] | 3134 | }; |
Xander Huff | 8cd5a56 | 2015-01-15 15:55:20 -0600 | [diff] [blame] | 3135 | |
Lad, Prabhakar | 8093b1c | 2015-02-05 16:21:07 +0000 | [diff] [blame] | 3136 | static const struct ethtool_ops gem_ethtool_ops = { |
Xander Huff | 8cd5a56 | 2015-01-15 15:55:20 -0600 | [diff] [blame] | 3137 | .get_regs_len = macb_get_regs_len, |
| 3138 | .get_regs = macb_get_regs, |
| 3139 | .get_link = ethtool_op_get_link, |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 3140 | .get_ts_info = macb_get_ts_info, |
Xander Huff | 3ff13f1 | 2015-01-13 16:15:51 -0600 | [diff] [blame] | 3141 | .get_ethtool_stats = gem_get_ethtool_stats, |
| 3142 | .get_strings = gem_get_ethtool_strings, |
| 3143 | .get_sset_count = gem_get_sset_count, |
Philippe Reynes | 176275a | 2016-06-22 00:32:36 +0200 | [diff] [blame] | 3144 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 3145 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Zach Brown | 8441bb3 | 2016-10-19 09:56:58 -0500 | [diff] [blame] | 3146 | .get_ringparam = macb_get_ringparam, |
| 3147 | .set_ringparam = macb_set_ringparam, |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3148 | .get_rxnfc = gem_get_rxnfc, |
| 3149 | .set_rxnfc = gem_set_rxnfc, |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3150 | }; |
| 3151 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3152 | static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3153 | { |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 3154 | struct phy_device *phydev = dev->phydev; |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 3155 | struct macb *bp = netdev_priv(dev); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3156 | |
| 3157 | if (!netif_running(dev)) |
| 3158 | return -EINVAL; |
| 3159 | |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 3160 | if (!phydev) |
| 3161 | return -ENODEV; |
| 3162 | |
Andrei.Pistirica@microchip.com | c2594d8 | 2017-01-19 17:56:15 +0200 | [diff] [blame] | 3163 | if (!bp->ptp_info) |
| 3164 | return phy_mii_ioctl(phydev, rq, cmd); |
| 3165 | |
| 3166 | switch (cmd) { |
| 3167 | case SIOCSHWTSTAMP: |
| 3168 | return bp->ptp_info->set_hwtst(dev, rq, cmd); |
| 3169 | case SIOCGHWTSTAMP: |
| 3170 | return bp->ptp_info->get_hwtst(dev, rq); |
| 3171 | default: |
| 3172 | return phy_mii_ioctl(phydev, rq, cmd); |
| 3173 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3174 | } |
| 3175 | |
Cyrille Pitchen | 85ff3d8 | 2014-07-24 13:51:00 +0200 | [diff] [blame] | 3176 | static int macb_set_features(struct net_device *netdev, |
| 3177 | netdev_features_t features) |
| 3178 | { |
| 3179 | struct macb *bp = netdev_priv(netdev); |
| 3180 | netdev_features_t changed = features ^ netdev->features; |
| 3181 | |
| 3182 | /* TX checksum offload */ |
| 3183 | if ((changed & NETIF_F_HW_CSUM) && macb_is_gem(bp)) { |
| 3184 | u32 dmacfg; |
| 3185 | |
| 3186 | dmacfg = gem_readl(bp, DMACFG); |
| 3187 | if (features & NETIF_F_HW_CSUM) |
| 3188 | dmacfg |= GEM_BIT(TXCOEN); |
| 3189 | else |
| 3190 | dmacfg &= ~GEM_BIT(TXCOEN); |
| 3191 | gem_writel(bp, DMACFG, dmacfg); |
| 3192 | } |
| 3193 | |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 3194 | /* RX checksum offload */ |
| 3195 | if ((changed & NETIF_F_RXCSUM) && macb_is_gem(bp)) { |
| 3196 | u32 netcfg; |
| 3197 | |
| 3198 | netcfg = gem_readl(bp, NCFGR); |
| 3199 | if (features & NETIF_F_RXCSUM && |
| 3200 | !(netdev->flags & IFF_PROMISC)) |
| 3201 | netcfg |= GEM_BIT(RXCOEN); |
| 3202 | else |
| 3203 | netcfg &= ~GEM_BIT(RXCOEN); |
| 3204 | gem_writel(bp, NCFGR, netcfg); |
| 3205 | } |
| 3206 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3207 | /* RX Flow Filters */ |
| 3208 | if ((changed & NETIF_F_NTUPLE) && macb_is_gem(bp)) { |
| 3209 | bool turn_on = features & NETIF_F_NTUPLE; |
| 3210 | |
| 3211 | gem_enable_flow_filters(bp, turn_on); |
| 3212 | } |
Cyrille Pitchen | 85ff3d8 | 2014-07-24 13:51:00 +0200 | [diff] [blame] | 3213 | return 0; |
| 3214 | } |
| 3215 | |
Alexander Beregalov | 5f1fa99 | 2009-04-11 07:42:26 +0000 | [diff] [blame] | 3216 | static const struct net_device_ops macb_netdev_ops = { |
| 3217 | .ndo_open = macb_open, |
| 3218 | .ndo_stop = macb_close, |
| 3219 | .ndo_start_xmit = macb_start_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 3220 | .ndo_set_rx_mode = macb_set_rx_mode, |
Alexander Beregalov | 5f1fa99 | 2009-04-11 07:42:26 +0000 | [diff] [blame] | 3221 | .ndo_get_stats = macb_get_stats, |
| 3222 | .ndo_do_ioctl = macb_ioctl, |
| 3223 | .ndo_validate_addr = eth_validate_addr, |
Harini Katakam | a5898ea | 2015-05-06 22:27:18 +0530 | [diff] [blame] | 3224 | .ndo_change_mtu = macb_change_mtu, |
Alexander Beregalov | 5f1fa99 | 2009-04-11 07:42:26 +0000 | [diff] [blame] | 3225 | .ndo_set_mac_address = eth_mac_addr, |
Thomas Petazzoni | 6e8cf5c | 2009-05-04 11:08:41 -0700 | [diff] [blame] | 3226 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3227 | .ndo_poll_controller = macb_poll_controller, |
| 3228 | #endif |
Cyrille Pitchen | 85ff3d8 | 2014-07-24 13:51:00 +0200 | [diff] [blame] | 3229 | .ndo_set_features = macb_set_features, |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 3230 | .ndo_features_check = macb_features_check, |
Alexander Beregalov | 5f1fa99 | 2009-04-11 07:42:26 +0000 | [diff] [blame] | 3231 | }; |
| 3232 | |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 3233 | /* Configure peripheral capabilities according to device tree |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3234 | * and integration options used |
| 3235 | */ |
Moritz Fischer | 64ec42f | 2016-03-29 19:11:12 -0700 | [diff] [blame] | 3236 | static void macb_configure_caps(struct macb *bp, |
| 3237 | const struct macb_config *dt_conf) |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3238 | { |
| 3239 | u32 dcfg; |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3240 | |
Nicolas Ferre | f697050 | 2015-03-31 15:02:01 +0200 | [diff] [blame] | 3241 | if (dt_conf) |
| 3242 | bp->caps = dt_conf->caps; |
| 3243 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3244 | if (hw_is_gem(bp->regs, bp->native_io)) { |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3245 | bp->caps |= MACB_CAPS_MACB_IS_GEM; |
| 3246 | |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3247 | dcfg = gem_readl(bp, DCFG1); |
| 3248 | if (GEM_BFEXT(IRQCOR, dcfg) == 0) |
| 3249 | bp->caps |= MACB_CAPS_ISR_CLEAR_ON_WRITE; |
| 3250 | dcfg = gem_readl(bp, DCFG2); |
| 3251 | if ((dcfg & (GEM_BIT(RX_PKT_BUFF) | GEM_BIT(TX_PKT_BUFF))) == 0) |
| 3252 | bp->caps |= MACB_CAPS_FIFO_MODE; |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3253 | #ifdef CONFIG_MACB_USE_HWSTAMP |
| 3254 | if (gem_has_ptp(bp)) { |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 3255 | if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5))) |
| 3256 | pr_err("GEM doesn't support hardware ptp.\n"); |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3257 | else { |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 3258 | bp->hw_dma_cap |= HW_DMA_CAP_PTP; |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3259 | bp->ptp_info = &gem_ptp_info; |
| 3260 | } |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 3261 | } |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3262 | #endif |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3263 | } |
| 3264 | |
Andy Shevchenko | a35919e | 2015-07-24 21:24:01 +0300 | [diff] [blame] | 3265 | dev_dbg(&bp->pdev->dev, "Cadence caps 0x%08x\n", bp->caps); |
Nicolas Ferre | e175587 | 2014-07-24 13:50:58 +0200 | [diff] [blame] | 3266 | } |
| 3267 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3268 | static void macb_probe_queues(void __iomem *mem, |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3269 | bool native_io, |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3270 | unsigned int *queue_mask, |
| 3271 | unsigned int *num_queues) |
| 3272 | { |
| 3273 | unsigned int hw_q; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3274 | |
| 3275 | *queue_mask = 0x1; |
| 3276 | *num_queues = 1; |
| 3277 | |
Nicolas Ferre | da12011 | 2015-03-31 15:02:00 +0200 | [diff] [blame] | 3278 | /* is it macb or gem ? |
| 3279 | * |
| 3280 | * We need to read directly from the hardware here because |
| 3281 | * we are early in the probe process and don't have the |
| 3282 | * MACB_CAPS_MACB_IS_GEM flag positioned |
| 3283 | */ |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3284 | if (!hw_is_gem(mem, native_io)) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3285 | return; |
| 3286 | |
| 3287 | /* bit 0 is never set but queue 0 always exists */ |
Arun Chandran | a50dad3 | 2015-02-18 16:59:35 +0530 | [diff] [blame] | 3288 | *queue_mask = readl_relaxed(mem + GEM_DCFG6) & 0xff; |
| 3289 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3290 | *queue_mask |= 0x1; |
| 3291 | |
| 3292 | for (hw_q = 1; hw_q < MACB_MAX_QUEUES; ++hw_q) |
| 3293 | if (*queue_mask & (1 << hw_q)) |
| 3294 | (*num_queues)++; |
| 3295 | } |
| 3296 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3297 | static int macb_clk_init(struct platform_device *pdev, struct clk **pclk, |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3298 | struct clk **hclk, struct clk **tx_clk, |
| 3299 | struct clk **rx_clk) |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3300 | { |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3301 | struct macb_platform_data *pdata; |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3302 | int err; |
| 3303 | |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3304 | pdata = dev_get_platdata(&pdev->dev); |
| 3305 | if (pdata) { |
| 3306 | *pclk = pdata->pclk; |
| 3307 | *hclk = pdata->hclk; |
| 3308 | } else { |
| 3309 | *pclk = devm_clk_get(&pdev->dev, "pclk"); |
| 3310 | *hclk = devm_clk_get(&pdev->dev, "hclk"); |
| 3311 | } |
| 3312 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3313 | if (IS_ERR(*pclk)) { |
| 3314 | err = PTR_ERR(*pclk); |
| 3315 | dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err); |
| 3316 | return err; |
| 3317 | } |
| 3318 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3319 | if (IS_ERR(*hclk)) { |
| 3320 | err = PTR_ERR(*hclk); |
| 3321 | dev_err(&pdev->dev, "failed to get hclk (%u)\n", err); |
| 3322 | return err; |
| 3323 | } |
| 3324 | |
| 3325 | *tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); |
| 3326 | if (IS_ERR(*tx_clk)) |
| 3327 | *tx_clk = NULL; |
| 3328 | |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3329 | *rx_clk = devm_clk_get(&pdev->dev, "rx_clk"); |
| 3330 | if (IS_ERR(*rx_clk)) |
| 3331 | *rx_clk = NULL; |
| 3332 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3333 | err = clk_prepare_enable(*pclk); |
| 3334 | if (err) { |
| 3335 | dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); |
| 3336 | return err; |
| 3337 | } |
| 3338 | |
| 3339 | err = clk_prepare_enable(*hclk); |
| 3340 | if (err) { |
| 3341 | dev_err(&pdev->dev, "failed to enable hclk (%u)\n", err); |
| 3342 | goto err_disable_pclk; |
| 3343 | } |
| 3344 | |
| 3345 | err = clk_prepare_enable(*tx_clk); |
| 3346 | if (err) { |
| 3347 | dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); |
| 3348 | goto err_disable_hclk; |
| 3349 | } |
| 3350 | |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3351 | err = clk_prepare_enable(*rx_clk); |
| 3352 | if (err) { |
| 3353 | dev_err(&pdev->dev, "failed to enable rx_clk (%u)\n", err); |
| 3354 | goto err_disable_txclk; |
| 3355 | } |
| 3356 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3357 | return 0; |
| 3358 | |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3359 | err_disable_txclk: |
| 3360 | clk_disable_unprepare(*tx_clk); |
| 3361 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3362 | err_disable_hclk: |
| 3363 | clk_disable_unprepare(*hclk); |
| 3364 | |
| 3365 | err_disable_pclk: |
| 3366 | clk_disable_unprepare(*pclk); |
| 3367 | |
| 3368 | return err; |
| 3369 | } |
| 3370 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3371 | static int macb_init(struct platform_device *pdev) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3372 | { |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3373 | struct net_device *dev = platform_get_drvdata(pdev); |
Nicolas Ferre | bfa0914 | 2015-03-31 15:01:59 +0200 | [diff] [blame] | 3374 | unsigned int hw_q, q; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3375 | struct macb *bp = netdev_priv(dev); |
| 3376 | struct macb_queue *queue; |
| 3377 | int err; |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3378 | u32 val, reg; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3379 | |
Zach Brown | b410d13 | 2016-10-19 09:56:57 -0500 | [diff] [blame] | 3380 | bp->tx_ring_size = DEFAULT_TX_RING_SIZE; |
| 3381 | bp->rx_ring_size = DEFAULT_RX_RING_SIZE; |
| 3382 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3383 | /* set the queue register mapping once for all: queue0 has a special |
| 3384 | * register mapping but we don't want to test the queue index then |
| 3385 | * compute the corresponding register offset at run time. |
| 3386 | */ |
Cyrille Pitchen | cf250de | 2014-12-15 15:13:32 +0100 | [diff] [blame] | 3387 | for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) { |
Nicolas Ferre | bfa0914 | 2015-03-31 15:01:59 +0200 | [diff] [blame] | 3388 | if (!(bp->queue_mask & (1 << hw_q))) |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3389 | continue; |
Jamie Iles | 461845d | 2011-03-08 20:19:23 +0000 | [diff] [blame] | 3390 | |
Cyrille Pitchen | cf250de | 2014-12-15 15:13:32 +0100 | [diff] [blame] | 3391 | queue = &bp->queues[q]; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3392 | queue->bp = bp; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3393 | netif_napi_add(dev, &queue->napi, macb_poll, 64); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3394 | if (hw_q) { |
| 3395 | queue->ISR = GEM_ISR(hw_q - 1); |
| 3396 | queue->IER = GEM_IER(hw_q - 1); |
| 3397 | queue->IDR = GEM_IDR(hw_q - 1); |
| 3398 | queue->IMR = GEM_IMR(hw_q - 1); |
| 3399 | queue->TBQP = GEM_TBQP(hw_q - 1); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3400 | queue->RBQP = GEM_RBQP(hw_q - 1); |
| 3401 | queue->RBQS = GEM_RBQS(hw_q - 1); |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 3402 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3403 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3404 | queue->TBQPH = GEM_TBQPH(hw_q - 1); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3405 | queue->RBQPH = GEM_RBQPH(hw_q - 1); |
| 3406 | } |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 3407 | #endif |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3408 | } else { |
| 3409 | /* queue0 uses legacy registers */ |
| 3410 | queue->ISR = MACB_ISR; |
| 3411 | queue->IER = MACB_IER; |
| 3412 | queue->IDR = MACB_IDR; |
| 3413 | queue->IMR = MACB_IMR; |
| 3414 | queue->TBQP = MACB_TBQP; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3415 | queue->RBQP = MACB_RBQP; |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 3416 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3417 | if (bp->hw_dma_cap & HW_DMA_CAP_64B) { |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3418 | queue->TBQPH = MACB_TBQPH; |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3419 | queue->RBQPH = MACB_RBQPH; |
| 3420 | } |
Harini Katakam | fff8019 | 2016-08-09 13:15:53 +0530 | [diff] [blame] | 3421 | #endif |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 3422 | } |
Soren Brinkmann | e1824df | 2013-12-10 16:07:23 -0800 | [diff] [blame] | 3423 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3424 | /* get irq: here we use the linux queue index, not the hardware |
| 3425 | * queue index. the queue irq definitions in the device tree |
| 3426 | * must remove the optional gaps that could exist in the |
| 3427 | * hardware queue mask. |
| 3428 | */ |
Cyrille Pitchen | cf250de | 2014-12-15 15:13:32 +0100 | [diff] [blame] | 3429 | queue->irq = platform_get_irq(pdev, q); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3430 | err = devm_request_irq(&pdev->dev, queue->irq, macb_interrupt, |
Punnaiah Choudary Kalluri | 2048823 | 2015-03-06 18:29:12 +0100 | [diff] [blame] | 3431 | IRQF_SHARED, dev->name, queue); |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3432 | if (err) { |
| 3433 | dev_err(&pdev->dev, |
| 3434 | "Unable to request IRQ %d (error %d)\n", |
| 3435 | queue->irq, err); |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3436 | return err; |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3437 | } |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3438 | |
Cyrille Pitchen | 02c958d | 2014-12-12 13:26:44 +0100 | [diff] [blame] | 3439 | INIT_WORK(&queue->tx_error_task, macb_tx_error_task); |
Cyrille Pitchen | cf250de | 2014-12-15 15:13:32 +0100 | [diff] [blame] | 3440 | q++; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3441 | } |
| 3442 | |
Alexander Beregalov | 5f1fa99 | 2009-04-11 07:42:26 +0000 | [diff] [blame] | 3443 | dev->netdev_ops = &macb_netdev_ops; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3444 | |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 3445 | /* setup appropriated routines according to adapter type */ |
| 3446 | if (macb_is_gem(bp)) { |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 3447 | bp->max_tx_length = GEM_MAX_TX_LEN; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 3448 | bp->macbgem_ops.mog_alloc_rx_buffers = gem_alloc_rx_buffers; |
| 3449 | bp->macbgem_ops.mog_free_rx_buffers = gem_free_rx_buffers; |
| 3450 | bp->macbgem_ops.mog_init_rings = gem_init_rings; |
| 3451 | bp->macbgem_ops.mog_rx = gem_rx; |
Xander Huff | 8cd5a56 | 2015-01-15 15:55:20 -0600 | [diff] [blame] | 3452 | dev->ethtool_ops = &gem_ethtool_ops; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 3453 | } else { |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 3454 | bp->max_tx_length = MACB_MAX_TX_LEN; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 3455 | bp->macbgem_ops.mog_alloc_rx_buffers = macb_alloc_rx_buffers; |
| 3456 | bp->macbgem_ops.mog_free_rx_buffers = macb_free_rx_buffers; |
| 3457 | bp->macbgem_ops.mog_init_rings = macb_init_rings; |
| 3458 | bp->macbgem_ops.mog_rx = macb_rx; |
Xander Huff | 8cd5a56 | 2015-01-15 15:55:20 -0600 | [diff] [blame] | 3459 | dev->ethtool_ops = &macb_ethtool_ops; |
Nicolas Ferre | 4df9513 | 2013-06-04 21:57:12 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 3462 | /* Set features */ |
| 3463 | dev->hw_features = NETIF_F_SG; |
Rafal Ozieblo | 1629dd4 | 2016-11-16 10:02:34 +0000 | [diff] [blame] | 3464 | |
| 3465 | /* Check LSO capability */ |
| 3466 | if (GEM_BFEXT(PBUF_LSO, gem_readl(bp, DCFG6))) |
| 3467 | dev->hw_features |= MACB_NETIF_LSO; |
| 3468 | |
Cyrille Pitchen | 85ff3d8 | 2014-07-24 13:51:00 +0200 | [diff] [blame] | 3469 | /* Checksum offload is only available on gem with packet buffer */ |
| 3470 | if (macb_is_gem(bp) && !(bp->caps & MACB_CAPS_FIFO_MODE)) |
Cyrille Pitchen | 924ec53 | 2014-07-24 13:51:01 +0200 | [diff] [blame] | 3471 | dev->hw_features |= NETIF_F_HW_CSUM | NETIF_F_RXCSUM; |
Cyrille Pitchen | a4c35ed3 | 2014-07-24 13:50:59 +0200 | [diff] [blame] | 3472 | if (bp->caps & MACB_CAPS_SG_DISABLED) |
| 3473 | dev->hw_features &= ~NETIF_F_SG; |
| 3474 | dev->features = dev->hw_features; |
| 3475 | |
Rafal Ozieblo | ae8223de | 2017-11-30 18:20:44 +0000 | [diff] [blame] | 3476 | /* Check RX Flow Filters support. |
| 3477 | * Max Rx flows set by availability of screeners & compare regs: |
| 3478 | * each 4-tuple define requires 1 T2 screener reg + 3 compare regs |
| 3479 | */ |
| 3480 | reg = gem_readl(bp, DCFG8); |
| 3481 | bp->max_tuples = min((GEM_BFEXT(SCR2CMP, reg) / 3), |
| 3482 | GEM_BFEXT(T2SCR, reg)); |
| 3483 | if (bp->max_tuples > 0) { |
| 3484 | /* also needs one ethtype match to check IPv4 */ |
| 3485 | if (GEM_BFEXT(SCR2ETH, reg) > 0) { |
| 3486 | /* program this reg now */ |
| 3487 | reg = 0; |
| 3488 | reg = GEM_BFINS(ETHTCMP, (uint16_t)ETH_P_IP, reg); |
| 3489 | gem_writel_n(bp, ETHT, SCRT2_ETHT, reg); |
| 3490 | /* Filtering is supported in hw but don't enable it in kernel now */ |
| 3491 | dev->hw_features |= NETIF_F_NTUPLE; |
| 3492 | /* init Rx flow definitions */ |
| 3493 | INIT_LIST_HEAD(&bp->rx_fs_list.list); |
| 3494 | bp->rx_fs_list.count = 0; |
| 3495 | spin_lock_init(&bp->rx_fs_lock); |
| 3496 | } else |
| 3497 | bp->max_tuples = 0; |
| 3498 | } |
| 3499 | |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 3500 | if (!(bp->caps & MACB_CAPS_USRIO_DISABLED)) { |
| 3501 | val = 0; |
| 3502 | if (bp->phy_interface == PHY_INTERFACE_MODE_RGMII) |
| 3503 | val = GEM_BIT(RGMII); |
| 3504 | else if (bp->phy_interface == PHY_INTERFACE_MODE_RMII && |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3505 | (bp->caps & MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII)) |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 3506 | val = MACB_BIT(RMII); |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3507 | else if (!(bp->caps & MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII)) |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 3508 | val = MACB_BIT(MII); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 3509 | |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 3510 | if (bp->caps & MACB_CAPS_USRIO_HAS_CLKEN) |
| 3511 | val |= MACB_BIT(CLKEN); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3512 | |
Neil Armstrong | ce721a7 | 2016-01-05 14:39:16 +0100 | [diff] [blame] | 3513 | macb_or_gem_writel(bp, USRIO, val); |
| 3514 | } |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3515 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3516 | /* Set MII management clock divider */ |
| 3517 | val = macb_mdc_clk_div(bp); |
| 3518 | val |= macb_dbw(bp); |
Punnaiah Choudary Kalluri | 022be25 | 2015-11-18 09:03:50 +0530 | [diff] [blame] | 3519 | if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) |
| 3520 | val |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3521 | macb_writel(bp, NCFGR, val); |
| 3522 | |
| 3523 | return 0; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | #if defined(CONFIG_OF) |
| 3527 | /* 1518 rounded up */ |
| 3528 | #define AT91ETHER_MAX_RBUFF_SZ 0x600 |
| 3529 | /* max number of receive buffers */ |
| 3530 | #define AT91ETHER_MAX_RX_DESCR 9 |
| 3531 | |
| 3532 | /* Initialize and start the Receiver and Transmit subsystems */ |
| 3533 | static int at91ether_start(struct net_device *dev) |
| 3534 | { |
| 3535 | struct macb *lp = netdev_priv(dev); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3536 | struct macb_queue *q = &lp->queues[0]; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3537 | struct macb_dma_desc *desc; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3538 | dma_addr_t addr; |
| 3539 | u32 ctl; |
| 3540 | int i; |
| 3541 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3542 | q->rx_ring = dma_alloc_coherent(&lp->pdev->dev, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3543 | (AT91ETHER_MAX_RX_DESCR * |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3544 | macb_dma_desc_get_size(lp)), |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3545 | &q->rx_ring_dma, GFP_KERNEL); |
| 3546 | if (!q->rx_ring) |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3547 | return -ENOMEM; |
| 3548 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3549 | q->rx_buffers = dma_alloc_coherent(&lp->pdev->dev, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3550 | AT91ETHER_MAX_RX_DESCR * |
| 3551 | AT91ETHER_MAX_RBUFF_SZ, |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3552 | &q->rx_buffers_dma, GFP_KERNEL); |
| 3553 | if (!q->rx_buffers) { |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3554 | dma_free_coherent(&lp->pdev->dev, |
| 3555 | AT91ETHER_MAX_RX_DESCR * |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3556 | macb_dma_desc_get_size(lp), |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3557 | q->rx_ring, q->rx_ring_dma); |
| 3558 | q->rx_ring = NULL; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3559 | return -ENOMEM; |
| 3560 | } |
| 3561 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3562 | addr = q->rx_buffers_dma; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3563 | for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3564 | desc = macb_rx_desc(q, i); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3565 | macb_set_addr(lp, desc, addr); |
| 3566 | desc->ctrl = 0; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3567 | addr += AT91ETHER_MAX_RBUFF_SZ; |
| 3568 | } |
| 3569 | |
| 3570 | /* Set the Wrap bit on the last descriptor */ |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3571 | desc->addr |= MACB_BIT(RX_WRAP); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3572 | |
| 3573 | /* Reset buffer index */ |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3574 | q->rx_tail = 0; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3575 | |
| 3576 | /* Program address of descriptor list in Rx Buffer Queue register */ |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3577 | macb_writel(lp, RBQP, q->rx_ring_dma); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3578 | |
| 3579 | /* Enable Receive and Transmit */ |
| 3580 | ctl = macb_readl(lp, NCR); |
| 3581 | macb_writel(lp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE)); |
| 3582 | |
| 3583 | return 0; |
| 3584 | } |
| 3585 | |
| 3586 | /* Open the ethernet interface */ |
| 3587 | static int at91ether_open(struct net_device *dev) |
| 3588 | { |
| 3589 | struct macb *lp = netdev_priv(dev); |
| 3590 | u32 ctl; |
| 3591 | int ret; |
| 3592 | |
| 3593 | /* Clear internal statistics */ |
| 3594 | ctl = macb_readl(lp, NCR); |
| 3595 | macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT)); |
| 3596 | |
| 3597 | macb_set_hwaddr(lp); |
| 3598 | |
| 3599 | ret = at91ether_start(dev); |
| 3600 | if (ret) |
| 3601 | return ret; |
| 3602 | |
| 3603 | /* Enable MAC interrupts */ |
| 3604 | macb_writel(lp, IER, MACB_BIT(RCOMP) | |
| 3605 | MACB_BIT(RXUBR) | |
| 3606 | MACB_BIT(ISR_TUND) | |
| 3607 | MACB_BIT(ISR_RLE) | |
| 3608 | MACB_BIT(TCOMP) | |
| 3609 | MACB_BIT(ISR_ROVR) | |
| 3610 | MACB_BIT(HRESP)); |
| 3611 | |
| 3612 | /* schedule a link state check */ |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 3613 | phy_start(dev->phydev); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3614 | |
| 3615 | netif_start_queue(dev); |
| 3616 | |
| 3617 | return 0; |
| 3618 | } |
| 3619 | |
| 3620 | /* Close the interface */ |
| 3621 | static int at91ether_close(struct net_device *dev) |
| 3622 | { |
| 3623 | struct macb *lp = netdev_priv(dev); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3624 | struct macb_queue *q = &lp->queues[0]; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3625 | u32 ctl; |
| 3626 | |
| 3627 | /* Disable Receiver and Transmitter */ |
| 3628 | ctl = macb_readl(lp, NCR); |
| 3629 | macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE))); |
| 3630 | |
| 3631 | /* Disable MAC interrupts */ |
| 3632 | macb_writel(lp, IDR, MACB_BIT(RCOMP) | |
| 3633 | MACB_BIT(RXUBR) | |
| 3634 | MACB_BIT(ISR_TUND) | |
| 3635 | MACB_BIT(ISR_RLE) | |
| 3636 | MACB_BIT(TCOMP) | |
| 3637 | MACB_BIT(ISR_ROVR) | |
| 3638 | MACB_BIT(HRESP)); |
| 3639 | |
| 3640 | netif_stop_queue(dev); |
| 3641 | |
| 3642 | dma_free_coherent(&lp->pdev->dev, |
| 3643 | AT91ETHER_MAX_RX_DESCR * |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3644 | macb_dma_desc_get_size(lp), |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3645 | q->rx_ring, q->rx_ring_dma); |
| 3646 | q->rx_ring = NULL; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3647 | |
| 3648 | dma_free_coherent(&lp->pdev->dev, |
| 3649 | AT91ETHER_MAX_RX_DESCR * AT91ETHER_MAX_RBUFF_SZ, |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3650 | q->rx_buffers, q->rx_buffers_dma); |
| 3651 | q->rx_buffers = NULL; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3652 | |
| 3653 | return 0; |
| 3654 | } |
| 3655 | |
| 3656 | /* Transmit packet */ |
Claudiu Beznea | d1c3895 | 2018-08-07 12:25:12 +0300 | [diff] [blame] | 3657 | static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb, |
| 3658 | struct net_device *dev) |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3659 | { |
| 3660 | struct macb *lp = netdev_priv(dev); |
| 3661 | |
| 3662 | if (macb_readl(lp, TSR) & MACB_BIT(RM9200_BNQ)) { |
| 3663 | netif_stop_queue(dev); |
| 3664 | |
| 3665 | /* Store packet information (to free when Tx completed) */ |
| 3666 | lp->skb = skb; |
| 3667 | lp->skb_length = skb->len; |
| 3668 | lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, |
| 3669 | DMA_TO_DEVICE); |
Alexey Khoroshilov | 178c7ae | 2016-11-19 01:40:10 +0300 | [diff] [blame] | 3670 | if (dma_mapping_error(NULL, lp->skb_physaddr)) { |
| 3671 | dev_kfree_skb_any(skb); |
| 3672 | dev->stats.tx_dropped++; |
| 3673 | netdev_err(dev, "%s: DMA mapping error\n", __func__); |
| 3674 | return NETDEV_TX_OK; |
| 3675 | } |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3676 | |
| 3677 | /* Set address of the data in the Transmit Address register */ |
| 3678 | macb_writel(lp, TAR, lp->skb_physaddr); |
| 3679 | /* Set length of the packet in the Transmit Control register */ |
| 3680 | macb_writel(lp, TCR, skb->len); |
| 3681 | |
| 3682 | } else { |
| 3683 | netdev_err(dev, "%s called, but device is busy!\n", __func__); |
| 3684 | return NETDEV_TX_BUSY; |
| 3685 | } |
| 3686 | |
| 3687 | return NETDEV_TX_OK; |
| 3688 | } |
| 3689 | |
| 3690 | /* Extract received frame from buffer descriptors and sent to upper layers. |
| 3691 | * (Called from interrupt context) |
| 3692 | */ |
| 3693 | static void at91ether_rx(struct net_device *dev) |
| 3694 | { |
| 3695 | struct macb *lp = netdev_priv(dev); |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3696 | struct macb_queue *q = &lp->queues[0]; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3697 | struct macb_dma_desc *desc; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3698 | unsigned char *p_recv; |
| 3699 | struct sk_buff *skb; |
| 3700 | unsigned int pktlen; |
| 3701 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3702 | desc = macb_rx_desc(q, q->rx_tail); |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3703 | while (desc->addr & MACB_BIT(RX_USED)) { |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3704 | p_recv = q->rx_buffers + q->rx_tail * AT91ETHER_MAX_RBUFF_SZ; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3705 | pktlen = MACB_BF(RX_FRMLEN, desc->ctrl); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3706 | skb = netdev_alloc_skb(dev, pktlen + 2); |
| 3707 | if (skb) { |
| 3708 | skb_reserve(skb, 2); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 3709 | skb_put_data(skb, p_recv, pktlen); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3710 | |
| 3711 | skb->protocol = eth_type_trans(skb, dev); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 3712 | dev->stats.rx_packets++; |
| 3713 | dev->stats.rx_bytes += pktlen; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3714 | netif_rx(skb); |
| 3715 | } else { |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 3716 | dev->stats.rx_dropped++; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3717 | } |
| 3718 | |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3719 | if (desc->ctrl & MACB_BIT(RX_MHASH_MATCH)) |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 3720 | dev->stats.multicast++; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3721 | |
| 3722 | /* reset ownership bit */ |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3723 | desc->addr &= ~MACB_BIT(RX_USED); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3724 | |
| 3725 | /* wrap after last buffer */ |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3726 | if (q->rx_tail == AT91ETHER_MAX_RX_DESCR - 1) |
| 3727 | q->rx_tail = 0; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3728 | else |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3729 | q->rx_tail++; |
Rafal Ozieblo | dc97a89 | 2017-01-27 15:08:20 +0000 | [diff] [blame] | 3730 | |
Rafal Ozieblo | ae1f2a5 | 2017-11-30 18:19:15 +0000 | [diff] [blame] | 3731 | desc = macb_rx_desc(q, q->rx_tail); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | /* MAC interrupt handler */ |
| 3736 | static irqreturn_t at91ether_interrupt(int irq, void *dev_id) |
| 3737 | { |
| 3738 | struct net_device *dev = dev_id; |
| 3739 | struct macb *lp = netdev_priv(dev); |
| 3740 | u32 intstatus, ctl; |
| 3741 | |
| 3742 | /* MAC Interrupt Status register indicates what interrupts are pending. |
| 3743 | * It is automatically cleared once read. |
| 3744 | */ |
| 3745 | intstatus = macb_readl(lp, ISR); |
| 3746 | |
| 3747 | /* Receive complete */ |
| 3748 | if (intstatus & MACB_BIT(RCOMP)) |
| 3749 | at91ether_rx(dev); |
| 3750 | |
| 3751 | /* Transmit complete */ |
| 3752 | if (intstatus & MACB_BIT(TCOMP)) { |
| 3753 | /* The TCOM bit is set even if the transmission failed */ |
| 3754 | if (intstatus & (MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE))) |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 3755 | dev->stats.tx_errors++; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3756 | |
| 3757 | if (lp->skb) { |
| 3758 | dev_kfree_skb_irq(lp->skb); |
| 3759 | lp->skb = NULL; |
| 3760 | dma_unmap_single(NULL, lp->skb_physaddr, |
| 3761 | lp->skb_length, DMA_TO_DEVICE); |
Tobias Klauser | 5f1d3a5 | 2017-04-07 10:17:30 +0200 | [diff] [blame] | 3762 | dev->stats.tx_packets++; |
| 3763 | dev->stats.tx_bytes += lp->skb_length; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3764 | } |
| 3765 | netif_wake_queue(dev); |
| 3766 | } |
| 3767 | |
| 3768 | /* Work-around for EMAC Errata section 41.3.1 */ |
| 3769 | if (intstatus & MACB_BIT(RXUBR)) { |
| 3770 | ctl = macb_readl(lp, NCR); |
| 3771 | macb_writel(lp, NCR, ctl & ~MACB_BIT(RE)); |
Zumeng Chen | ffac0e9 | 2016-11-28 21:55:00 +0800 | [diff] [blame] | 3772 | wmb(); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3773 | macb_writel(lp, NCR, ctl | MACB_BIT(RE)); |
| 3774 | } |
| 3775 | |
| 3776 | if (intstatus & MACB_BIT(ISR_ROVR)) |
| 3777 | netdev_err(dev, "ROVR error\n"); |
| 3778 | |
| 3779 | return IRQ_HANDLED; |
| 3780 | } |
| 3781 | |
| 3782 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3783 | static void at91ether_poll_controller(struct net_device *dev) |
| 3784 | { |
| 3785 | unsigned long flags; |
| 3786 | |
| 3787 | local_irq_save(flags); |
| 3788 | at91ether_interrupt(dev->irq, dev); |
| 3789 | local_irq_restore(flags); |
| 3790 | } |
| 3791 | #endif |
| 3792 | |
| 3793 | static const struct net_device_ops at91ether_netdev_ops = { |
| 3794 | .ndo_open = at91ether_open, |
| 3795 | .ndo_stop = at91ether_close, |
| 3796 | .ndo_start_xmit = at91ether_start_xmit, |
| 3797 | .ndo_get_stats = macb_get_stats, |
| 3798 | .ndo_set_rx_mode = macb_set_rx_mode, |
| 3799 | .ndo_set_mac_address = eth_mac_addr, |
| 3800 | .ndo_do_ioctl = macb_ioctl, |
| 3801 | .ndo_validate_addr = eth_validate_addr, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3802 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3803 | .ndo_poll_controller = at91ether_poll_controller, |
| 3804 | #endif |
| 3805 | }; |
| 3806 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3807 | static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk, |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3808 | struct clk **hclk, struct clk **tx_clk, |
| 3809 | struct clk **rx_clk) |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3810 | { |
| 3811 | int err; |
| 3812 | |
| 3813 | *hclk = NULL; |
| 3814 | *tx_clk = NULL; |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3815 | *rx_clk = NULL; |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3816 | |
| 3817 | *pclk = devm_clk_get(&pdev->dev, "ether_clk"); |
| 3818 | if (IS_ERR(*pclk)) |
| 3819 | return PTR_ERR(*pclk); |
| 3820 | |
| 3821 | err = clk_prepare_enable(*pclk); |
| 3822 | if (err) { |
| 3823 | dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); |
| 3824 | return err; |
| 3825 | } |
| 3826 | |
| 3827 | return 0; |
| 3828 | } |
| 3829 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3830 | static int at91ether_init(struct platform_device *pdev) |
| 3831 | { |
| 3832 | struct net_device *dev = platform_get_drvdata(pdev); |
| 3833 | struct macb *bp = netdev_priv(dev); |
| 3834 | int err; |
| 3835 | u32 reg; |
| 3836 | |
Alexandre Belloni | fec9d3b | 2018-06-26 10:44:01 +0200 | [diff] [blame] | 3837 | bp->queues[0].bp = bp; |
| 3838 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3839 | dev->netdev_ops = &at91ether_netdev_ops; |
| 3840 | dev->ethtool_ops = &macb_ethtool_ops; |
| 3841 | |
| 3842 | err = devm_request_irq(&pdev->dev, dev->irq, at91ether_interrupt, |
| 3843 | 0, dev->name, dev); |
| 3844 | if (err) |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3845 | return err; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3846 | |
| 3847 | macb_writel(bp, NCR, 0); |
| 3848 | |
| 3849 | reg = MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG); |
| 3850 | if (bp->phy_interface == PHY_INTERFACE_MODE_RMII) |
| 3851 | reg |= MACB_BIT(RM9200_RMII); |
| 3852 | |
| 3853 | macb_writel(bp, NCFGR, reg); |
| 3854 | |
| 3855 | return 0; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3856 | } |
| 3857 | |
David S. Miller | 3cef5c5 | 2015-03-09 23:38:02 -0400 | [diff] [blame] | 3858 | static const struct macb_config at91sam9260_config = { |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3859 | .caps = MACB_CAPS_USRIO_HAS_CLKEN | MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII, |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3860 | .clk_init = macb_clk_init, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3861 | .init = macb_init, |
| 3862 | }; |
| 3863 | |
Nicolas Ferre | eb4ed8e | 2018-09-14 17:48:10 +0200 | [diff] [blame] | 3864 | static const struct macb_config sama5d3macb_config = { |
| 3865 | .caps = MACB_CAPS_SG_DISABLED |
| 3866 | | MACB_CAPS_USRIO_HAS_CLKEN | MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII, |
| 3867 | .clk_init = macb_clk_init, |
| 3868 | .init = macb_init, |
| 3869 | }; |
| 3870 | |
David S. Miller | 3cef5c5 | 2015-03-09 23:38:02 -0400 | [diff] [blame] | 3871 | static const struct macb_config pc302gem_config = { |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3872 | .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE, |
| 3873 | .dma_burst_length = 16, |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3874 | .clk_init = macb_clk_init, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3875 | .init = macb_init, |
| 3876 | }; |
| 3877 | |
Cyrille Pitchen | 5c8fe71 | 2015-06-18 16:27:23 +0200 | [diff] [blame] | 3878 | static const struct macb_config sama5d2_config = { |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3879 | .caps = MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII, |
Cyrille Pitchen | 5c8fe71 | 2015-06-18 16:27:23 +0200 | [diff] [blame] | 3880 | .dma_burst_length = 16, |
| 3881 | .clk_init = macb_clk_init, |
| 3882 | .init = macb_init, |
| 3883 | }; |
| 3884 | |
David S. Miller | 3cef5c5 | 2015-03-09 23:38:02 -0400 | [diff] [blame] | 3885 | static const struct macb_config sama5d3_config = { |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3886 | .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE |
vishnuvardhan | 233a158 | 2017-07-05 17:36:16 +0200 | [diff] [blame] | 3887 | | MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII | MACB_CAPS_JUMBO, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3888 | .dma_burst_length = 16, |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3889 | .clk_init = macb_clk_init, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3890 | .init = macb_init, |
vishnuvardhan | 233a158 | 2017-07-05 17:36:16 +0200 | [diff] [blame] | 3891 | .jumbo_max_len = 10240, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3892 | }; |
| 3893 | |
David S. Miller | 3cef5c5 | 2015-03-09 23:38:02 -0400 | [diff] [blame] | 3894 | static const struct macb_config sama5d4_config = { |
Nicolas Ferre | 6bdaa5e | 2016-03-10 16:44:32 +0100 | [diff] [blame] | 3895 | .caps = MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3896 | .dma_burst_length = 4, |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3897 | .clk_init = macb_clk_init, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3898 | .init = macb_init, |
| 3899 | }; |
| 3900 | |
David S. Miller | 3cef5c5 | 2015-03-09 23:38:02 -0400 | [diff] [blame] | 3901 | static const struct macb_config emac_config = { |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3902 | .clk_init = at91ether_clk_init, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3903 | .init = at91ether_init, |
| 3904 | }; |
| 3905 | |
Neil Armstrong | e611b5b | 2016-01-05 14:39:17 +0100 | [diff] [blame] | 3906 | static const struct macb_config np4_config = { |
| 3907 | .caps = MACB_CAPS_USRIO_DISABLED, |
| 3908 | .clk_init = macb_clk_init, |
| 3909 | .init = macb_init, |
| 3910 | }; |
David S. Miller | 36583eb | 2015-05-23 01:22:35 -0400 | [diff] [blame] | 3911 | |
Harini Katakam | 7b61f9c | 2015-05-06 22:27:16 +0530 | [diff] [blame] | 3912 | static const struct macb_config zynqmp_config = { |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3913 | .caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | |
| 3914 | MACB_CAPS_JUMBO | |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 3915 | MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_BD_RD_PREFETCH, |
Harini Katakam | 7b61f9c | 2015-05-06 22:27:16 +0530 | [diff] [blame] | 3916 | .dma_burst_length = 16, |
| 3917 | .clk_init = macb_clk_init, |
| 3918 | .init = macb_init, |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 3919 | .jumbo_max_len = 10240, |
Harini Katakam | 7b61f9c | 2015-05-06 22:27:16 +0530 | [diff] [blame] | 3920 | }; |
| 3921 | |
Nathan Sullivan | 222ca8e | 2015-05-22 09:22:10 -0500 | [diff] [blame] | 3922 | static const struct macb_config zynq_config = { |
Punnaiah Choudary Kalluri | 7baaa90 | 2015-07-06 10:02:53 +0530 | [diff] [blame] | 3923 | .caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_NO_GIGABIT_HALF, |
Nathan Sullivan | 222ca8e | 2015-05-22 09:22:10 -0500 | [diff] [blame] | 3924 | .dma_burst_length = 16, |
| 3925 | .clk_init = macb_clk_init, |
| 3926 | .init = macb_init, |
| 3927 | }; |
| 3928 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3929 | static const struct of_device_id macb_dt_ids[] = { |
| 3930 | { .compatible = "cdns,at32ap7000-macb" }, |
| 3931 | { .compatible = "cdns,at91sam9260-macb", .data = &at91sam9260_config }, |
| 3932 | { .compatible = "cdns,macb" }, |
Neil Armstrong | e611b5b | 2016-01-05 14:39:17 +0100 | [diff] [blame] | 3933 | { .compatible = "cdns,np4-macb", .data = &np4_config }, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3934 | { .compatible = "cdns,pc302-gem", .data = &pc302gem_config }, |
| 3935 | { .compatible = "cdns,gem", .data = &pc302gem_config }, |
Cyrille Pitchen | 5c8fe71 | 2015-06-18 16:27:23 +0200 | [diff] [blame] | 3936 | { .compatible = "atmel,sama5d2-gem", .data = &sama5d2_config }, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3937 | { .compatible = "atmel,sama5d3-gem", .data = &sama5d3_config }, |
Nicolas Ferre | eb4ed8e | 2018-09-14 17:48:10 +0200 | [diff] [blame] | 3938 | { .compatible = "atmel,sama5d3-macb", .data = &sama5d3macb_config }, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3939 | { .compatible = "atmel,sama5d4-gem", .data = &sama5d4_config }, |
| 3940 | { .compatible = "cdns,at91rm9200-emac", .data = &emac_config }, |
| 3941 | { .compatible = "cdns,emac", .data = &emac_config }, |
Harini Katakam | 7b61f9c | 2015-05-06 22:27:16 +0530 | [diff] [blame] | 3942 | { .compatible = "cdns,zynqmp-gem", .data = &zynqmp_config}, |
Nathan Sullivan | 222ca8e | 2015-05-22 09:22:10 -0500 | [diff] [blame] | 3943 | { .compatible = "cdns,zynq-gem", .data = &zynq_config }, |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3944 | { /* sentinel */ } |
| 3945 | }; |
| 3946 | MODULE_DEVICE_TABLE(of, macb_dt_ids); |
| 3947 | #endif /* CONFIG_OF */ |
| 3948 | |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3949 | static const struct macb_config default_gem_config = { |
Rafal Ozieblo | ab91f0a | 2017-06-29 07:14:16 +0100 | [diff] [blame] | 3950 | .caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | |
| 3951 | MACB_CAPS_JUMBO | |
| 3952 | MACB_CAPS_GEM_HAS_PTP, |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3953 | .dma_burst_length = 16, |
| 3954 | .clk_init = macb_clk_init, |
| 3955 | .init = macb_init, |
| 3956 | .jumbo_max_len = 10240, |
| 3957 | }; |
| 3958 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3959 | static int macb_probe(struct platform_device *pdev) |
| 3960 | { |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3961 | const struct macb_config *macb_config = &default_gem_config; |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3962 | int (*clk_init)(struct platform_device *, struct clk **, |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3963 | struct clk **, struct clk **, struct clk **) |
Bartosz Folta | 83a77e9 | 2016-12-14 06:39:15 +0000 | [diff] [blame] | 3964 | = macb_config->clk_init; |
| 3965 | int (*init)(struct platform_device *) = macb_config->init; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3966 | struct device_node *np = pdev->dev.of_node; |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3967 | struct clk *pclk, *hclk = NULL, *tx_clk = NULL, *rx_clk = NULL; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3968 | unsigned int queue_mask, num_queues; |
| 3969 | struct macb_platform_data *pdata; |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3970 | bool native_io; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3971 | struct phy_device *phydev; |
| 3972 | struct net_device *dev; |
| 3973 | struct resource *regs; |
| 3974 | void __iomem *mem; |
| 3975 | const char *mac; |
| 3976 | struct macb *bp; |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 3977 | int err, val; |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 3978 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3979 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 3980 | mem = devm_ioremap_resource(&pdev->dev, regs); |
| 3981 | if (IS_ERR(mem)) |
| 3982 | return PTR_ERR(mem); |
| 3983 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3984 | if (np) { |
| 3985 | const struct of_device_id *match; |
| 3986 | |
| 3987 | match = of_match_node(macb_dt_ids, np); |
| 3988 | if (match && match->data) { |
| 3989 | macb_config = match->data; |
| 3990 | clk_init = macb_config->clk_init; |
| 3991 | init = macb_config->init; |
| 3992 | } |
| 3993 | } |
| 3994 | |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 3995 | err = clk_init(pdev, &pclk, &hclk, &tx_clk, &rx_clk); |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 3996 | if (err) |
| 3997 | return err; |
| 3998 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 3999 | native_io = hw_is_native_io(mem); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4000 | |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 4001 | macb_probe_queues(mem, native_io, &queue_mask, &num_queues); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4002 | dev = alloc_etherdev_mq(sizeof(*bp), num_queues); |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4003 | if (!dev) { |
| 4004 | err = -ENOMEM; |
| 4005 | goto err_disable_clocks; |
| 4006 | } |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4007 | |
| 4008 | dev->base_addr = regs->start; |
| 4009 | |
| 4010 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 4011 | |
| 4012 | bp = netdev_priv(dev); |
| 4013 | bp->pdev = pdev; |
| 4014 | bp->dev = dev; |
| 4015 | bp->regs = mem; |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 4016 | bp->native_io = native_io; |
| 4017 | if (native_io) { |
David S. Miller | 7a6e070 | 2015-07-27 14:24:48 -0700 | [diff] [blame] | 4018 | bp->macb_reg_readl = hw_readl_native; |
| 4019 | bp->macb_reg_writel = hw_writel_native; |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 4020 | } else { |
David S. Miller | 7a6e070 | 2015-07-27 14:24:48 -0700 | [diff] [blame] | 4021 | bp->macb_reg_readl = hw_readl; |
| 4022 | bp->macb_reg_writel = hw_writel; |
Andy Shevchenko | f2ce8a9e | 2015-07-24 21:23:59 +0300 | [diff] [blame] | 4023 | } |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4024 | bp->num_queues = num_queues; |
Nicolas Ferre | bfa0914 | 2015-03-31 15:01:59 +0200 | [diff] [blame] | 4025 | bp->queue_mask = queue_mask; |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4026 | if (macb_config) |
| 4027 | bp->dma_burst_length = macb_config->dma_burst_length; |
| 4028 | bp->pclk = pclk; |
| 4029 | bp->hclk = hclk; |
| 4030 | bp->tx_clk = tx_clk; |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 4031 | bp->rx_clk = rx_clk; |
Andy Shevchenko | f36dbe6 | 2015-07-24 21:24:00 +0300 | [diff] [blame] | 4032 | if (macb_config) |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 4033 | bp->jumbo_max_len = macb_config->jumbo_max_len; |
Harini Katakam | 98b5a0f4 | 2015-05-06 22:27:17 +0530 | [diff] [blame] | 4034 | |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4035 | bp->wol = 0; |
Sergio Prado | 7c4a1d0 | 2016-02-16 21:10:45 -0200 | [diff] [blame] | 4036 | if (of_get_property(np, "magic-packet", NULL)) |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4037 | bp->wol |= MACB_WOL_HAS_MAGIC_PACKET; |
| 4038 | device_init_wakeup(&pdev->dev, bp->wol & MACB_WOL_HAS_MAGIC_PACKET); |
| 4039 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4040 | spin_lock_init(&bp->lock); |
| 4041 | |
Nicolas Ferre | ad78347 | 2015-03-31 15:02:02 +0200 | [diff] [blame] | 4042 | /* setup capabilities */ |
Nicolas Ferre | f697050 | 2015-03-31 15:02:01 +0200 | [diff] [blame] | 4043 | macb_configure_caps(bp, macb_config); |
| 4044 | |
Rafal Ozieblo | 7b42961 | 2017-06-29 07:12:51 +0100 | [diff] [blame] | 4045 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
| 4046 | if (GEM_BFEXT(DAW64, gem_readl(bp, DCFG6))) { |
| 4047 | dma_set_mask(&pdev->dev, DMA_BIT_MASK(44)); |
| 4048 | bp->hw_dma_cap |= HW_DMA_CAP_64B; |
| 4049 | } |
| 4050 | #endif |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4051 | platform_set_drvdata(pdev, dev); |
| 4052 | |
| 4053 | dev->irq = platform_get_irq(pdev, 0); |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4054 | if (dev->irq < 0) { |
| 4055 | err = dev->irq; |
Wei Yongjun | b22ae0b | 2016-08-12 15:43:54 +0000 | [diff] [blame] | 4056 | goto err_out_free_netdev; |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4057 | } |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4058 | |
Jarod Wilson | 44770e1 | 2016-10-17 15:54:17 -0400 | [diff] [blame] | 4059 | /* MTU range: 68 - 1500 or 10240 */ |
| 4060 | dev->min_mtu = GEM_MTU_MIN_SIZE; |
| 4061 | if (bp->caps & MACB_CAPS_JUMBO) |
| 4062 | dev->max_mtu = gem_readl(bp, JML) - ETH_HLEN - ETH_FCS_LEN; |
| 4063 | else |
| 4064 | dev->max_mtu = ETH_DATA_LEN; |
| 4065 | |
Harini Katakam | 404cd08 | 2018-07-06 12:18:58 +0530 | [diff] [blame] | 4066 | if (bp->caps & MACB_CAPS_BD_RD_PREFETCH) { |
| 4067 | val = GEM_BFEXT(RXBD_RDBUFF, gem_readl(bp, DCFG10)); |
| 4068 | if (val) |
| 4069 | bp->rx_bd_rd_prefetch = (2 << (val - 1)) * |
| 4070 | macb_dma_desc_get_size(bp); |
| 4071 | |
| 4072 | val = GEM_BFEXT(TXBD_RDBUFF, gem_readl(bp, DCFG10)); |
| 4073 | if (val) |
| 4074 | bp->tx_bd_rd_prefetch = (2 << (val - 1)) * |
| 4075 | macb_dma_desc_get_size(bp); |
| 4076 | } |
| 4077 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4078 | mac = of_get_mac_address(np); |
Mike Looijmans | aa076e3 | 2018-03-29 07:29:49 +0200 | [diff] [blame] | 4079 | if (mac) { |
Moritz Fischer | eefb52d | 2016-03-29 19:11:14 -0700 | [diff] [blame] | 4080 | ether_addr_copy(bp->dev->dev_addr, mac); |
Mike Looijmans | aa076e3 | 2018-03-29 07:29:49 +0200 | [diff] [blame] | 4081 | } else { |
| 4082 | err = of_get_nvmem_mac_address(np, bp->dev->dev_addr); |
| 4083 | if (err) { |
| 4084 | if (err == -EPROBE_DEFER) |
| 4085 | goto err_out_free_netdev; |
| 4086 | macb_get_hwaddr(bp); |
| 4087 | } |
| 4088 | } |
frederic RODO | 6c36a70 | 2007-07-12 19:07:24 +0200 | [diff] [blame] | 4089 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4090 | err = of_get_phy_mode(np); |
Jean-Christophe PLAGNIOL-VILLARD | fb97a84 | 2011-11-18 15:29:25 +0100 | [diff] [blame] | 4091 | if (err < 0) { |
Jingoo Han | c607a0d | 2013-08-30 14:12:21 +0900 | [diff] [blame] | 4092 | pdata = dev_get_platdata(&pdev->dev); |
Jean-Christophe PLAGNIOL-VILLARD | fb97a84 | 2011-11-18 15:29:25 +0100 | [diff] [blame] | 4093 | if (pdata && pdata->is_rmii) |
| 4094 | bp->phy_interface = PHY_INTERFACE_MODE_RMII; |
| 4095 | else |
| 4096 | bp->phy_interface = PHY_INTERFACE_MODE_MII; |
| 4097 | } else { |
| 4098 | bp->phy_interface = err; |
| 4099 | } |
| 4100 | |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4101 | /* IP specific init */ |
| 4102 | err = init(pdev); |
| 4103 | if (err) |
| 4104 | goto err_out_free_netdev; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4105 | |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4106 | err = macb_mii_init(bp); |
| 4107 | if (err) |
| 4108 | goto err_out_free_netdev; |
| 4109 | |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 4110 | phydev = dev->phydev; |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4111 | |
| 4112 | netif_carrier_off(dev); |
| 4113 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4114 | err = register_netdev(dev); |
| 4115 | if (err) { |
| 4116 | dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4117 | goto err_out_unregister_mdio; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
Harini Katakam | 032dc41 | 2018-01-27 12:09:01 +0530 | [diff] [blame] | 4120 | tasklet_init(&bp->hresp_err_tasklet, macb_hresp_error_task, |
| 4121 | (unsigned long)bp); |
| 4122 | |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4123 | phy_attached_info(phydev); |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 4124 | |
Bo Shen | 5879823 | 2014-09-13 01:57:49 +0200 | [diff] [blame] | 4125 | netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n", |
| 4126 | macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID), |
| 4127 | dev->base_addr, dev->irq, dev->dev_addr); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4128 | |
| 4129 | return 0; |
| 4130 | |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4131 | err_out_unregister_mdio: |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 4132 | phy_disconnect(dev->phydev); |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4133 | mdiobus_unregister(bp->mii_bus); |
Michael Grzeschik | 66ee6a0 | 2017-11-08 09:56:35 +0100 | [diff] [blame] | 4134 | of_node_put(bp->phy_node); |
Michael Grzeschik | 9ce9814 | 2017-11-08 09:56:34 +0100 | [diff] [blame] | 4135 | if (np && of_phy_is_fixed_link(np)) |
| 4136 | of_phy_deregister_fixed_link(np); |
Florian Fainelli | cf66966 | 2016-05-02 18:38:45 -0700 | [diff] [blame] | 4137 | mdiobus_free(bp->mii_bus); |
| 4138 | |
Cyrille Pitchen | cf250de | 2014-12-15 15:13:32 +0100 | [diff] [blame] | 4139 | err_out_free_netdev: |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4140 | free_netdev(dev); |
Cyrille Pitchen | 421d9df | 2015-03-07 07:23:32 +0100 | [diff] [blame] | 4141 | |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4142 | err_disable_clocks: |
| 4143 | clk_disable_unprepare(tx_clk); |
| 4144 | clk_disable_unprepare(hclk); |
| 4145 | clk_disable_unprepare(pclk); |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 4146 | clk_disable_unprepare(rx_clk); |
Nicolas Ferre | c69618b | 2015-03-31 15:02:03 +0200 | [diff] [blame] | 4147 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4148 | return err; |
| 4149 | } |
| 4150 | |
Nicolae Rosia | 9e86d766 | 2015-01-22 17:31:05 +0000 | [diff] [blame] | 4151 | static int macb_remove(struct platform_device *pdev) |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4152 | { |
| 4153 | struct net_device *dev; |
| 4154 | struct macb *bp; |
Michael Grzeschik | 9ce9814 | 2017-11-08 09:56:34 +0100 | [diff] [blame] | 4155 | struct device_node *np = pdev->dev.of_node; |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4156 | |
| 4157 | dev = platform_get_drvdata(pdev); |
| 4158 | |
| 4159 | if (dev) { |
| 4160 | bp = netdev_priv(dev); |
Philippe Reynes | 0a91281 | 2016-06-22 00:32:35 +0200 | [diff] [blame] | 4161 | if (dev->phydev) |
| 4162 | phy_disconnect(dev->phydev); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 4163 | mdiobus_unregister(bp->mii_bus); |
Michael Grzeschik | 9ce9814 | 2017-11-08 09:56:34 +0100 | [diff] [blame] | 4164 | if (np && of_phy_is_fixed_link(np)) |
| 4165 | of_phy_deregister_fixed_link(np); |
Nathan Sullivan | fa6114d | 2016-10-07 10:13:22 -0500 | [diff] [blame] | 4166 | dev->phydev = NULL; |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 4167 | mdiobus_free(bp->mii_bus); |
Gregory CLEMENT | 5833e05 | 2015-12-11 11:34:53 +0100 | [diff] [blame] | 4168 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4169 | unregister_netdev(dev); |
Cyrille Pitchen | 93b31f4 | 2015-03-07 07:23:31 +0100 | [diff] [blame] | 4170 | clk_disable_unprepare(bp->tx_clk); |
Steffen Trumtrar | ace5801 | 2013-03-27 23:07:07 +0000 | [diff] [blame] | 4171 | clk_disable_unprepare(bp->hclk); |
Steffen Trumtrar | ace5801 | 2013-03-27 23:07:07 +0000 | [diff] [blame] | 4172 | clk_disable_unprepare(bp->pclk); |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 4173 | clk_disable_unprepare(bp->rx_clk); |
Michael Grzeschik | dacdbb4 | 2017-06-23 16:54:10 +0200 | [diff] [blame] | 4174 | of_node_put(bp->phy_node); |
Cyrille Pitchen | e965be7 | 2014-12-15 15:13:31 +0100 | [diff] [blame] | 4175 | free_netdev(dev); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | return 0; |
| 4179 | } |
| 4180 | |
Michal Simek | d23823d | 2015-01-23 09:36:03 +0100 | [diff] [blame] | 4181 | static int __maybe_unused macb_suspend(struct device *dev) |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4182 | { |
Wolfram Sang | ce886a4 | 2018-10-21 22:00:14 +0200 | [diff] [blame] | 4183 | struct net_device *netdev = dev_get_drvdata(dev); |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4184 | struct macb *bp = netdev_priv(netdev); |
| 4185 | |
Nicolas Ferre | 03fc472 | 2012-07-03 23:14:13 +0000 | [diff] [blame] | 4186 | netif_carrier_off(netdev); |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4187 | netif_device_detach(netdev); |
| 4188 | |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4189 | if (bp->wol & MACB_WOL_ENABLED) { |
| 4190 | macb_writel(bp, IER, MACB_BIT(WOL)); |
| 4191 | macb_writel(bp, WOL, MACB_BIT(MAG)); |
| 4192 | enable_irq_wake(bp->queues[0].irq); |
| 4193 | } else { |
| 4194 | clk_disable_unprepare(bp->tx_clk); |
| 4195 | clk_disable_unprepare(bp->hclk); |
| 4196 | clk_disable_unprepare(bp->pclk); |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 4197 | clk_disable_unprepare(bp->rx_clk); |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4198 | } |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4199 | |
| 4200 | return 0; |
| 4201 | } |
| 4202 | |
Michal Simek | d23823d | 2015-01-23 09:36:03 +0100 | [diff] [blame] | 4203 | static int __maybe_unused macb_resume(struct device *dev) |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4204 | { |
Wolfram Sang | ce886a4 | 2018-10-21 22:00:14 +0200 | [diff] [blame] | 4205 | struct net_device *netdev = dev_get_drvdata(dev); |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4206 | struct macb *bp = netdev_priv(netdev); |
| 4207 | |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4208 | if (bp->wol & MACB_WOL_ENABLED) { |
| 4209 | macb_writel(bp, IDR, MACB_BIT(WOL)); |
| 4210 | macb_writel(bp, WOL, 0); |
| 4211 | disable_irq_wake(bp->queues[0].irq); |
| 4212 | } else { |
| 4213 | clk_prepare_enable(bp->pclk); |
| 4214 | clk_prepare_enable(bp->hclk); |
| 4215 | clk_prepare_enable(bp->tx_clk); |
shubhrajyoti.datta@xilinx.com | aead88b | 2016-08-16 10:14:50 +0530 | [diff] [blame] | 4216 | clk_prepare_enable(bp->rx_clk); |
Sergio Prado | 3e2a5e1 | 2016-02-09 12:07:16 -0200 | [diff] [blame] | 4217 | } |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4218 | |
| 4219 | netif_device_attach(netdev); |
| 4220 | |
| 4221 | return 0; |
| 4222 | } |
Haavard Skinnemoen | c1f598f | 2008-03-04 13:39:29 +0100 | [diff] [blame] | 4223 | |
Soren Brinkmann | 0dfc3e1 | 2013-12-10 16:07:19 -0800 | [diff] [blame] | 4224 | static SIMPLE_DEV_PM_OPS(macb_pm_ops, macb_suspend, macb_resume); |
| 4225 | |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4226 | static struct platform_driver macb_driver = { |
Nicolae Rosia | 9e86d766 | 2015-01-22 17:31:05 +0000 | [diff] [blame] | 4227 | .probe = macb_probe, |
| 4228 | .remove = macb_remove, |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4229 | .driver = { |
| 4230 | .name = "macb", |
Jean-Christophe PLAGNIOL-VILLARD | fb97a84 | 2011-11-18 15:29:25 +0100 | [diff] [blame] | 4231 | .of_match_table = of_match_ptr(macb_dt_ids), |
Soren Brinkmann | 0dfc3e1 | 2013-12-10 16:07:19 -0800 | [diff] [blame] | 4232 | .pm = &macb_pm_ops, |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4233 | }, |
| 4234 | }; |
| 4235 | |
Nicolae Rosia | 9e86d766 | 2015-01-22 17:31:05 +0000 | [diff] [blame] | 4236 | module_platform_driver(macb_driver); |
Haavard Skinnemoen | 89e5785 | 2006-11-09 14:51:17 +0100 | [diff] [blame] | 4237 | |
| 4238 | MODULE_LICENSE("GPL"); |
Jamie Iles | f75ba50 | 2011-11-08 10:12:32 +0000 | [diff] [blame] | 4239 | MODULE_DESCRIPTION("Cadence MACB/GEM Ethernet driver"); |
Jean Delvare | e05503e | 2011-05-18 16:49:24 +0200 | [diff] [blame] | 4240 | MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 4241 | MODULE_ALIAS("platform:macb"); |