Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 2 | /* |
Paul Gortmaker | 3396c78 | 2012-01-27 13:36:01 +0000 | [diff] [blame] | 3 | * linux/drivers/net/ethernet/ethoc.c |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2007-2008 Avionic Design Development GmbH |
| 6 | * Copyright (C) 2008-2009 Avionic Design GmbH |
| 7 | * |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 8 | * Written by Thierry Reding <thierry.reding@avionic-design.de> |
| 9 | */ |
| 10 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 11 | #include <linux/dma-mapping.h> |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 12 | #include <linux/etherdevice.h> |
Max Filippov | a13aff0 | 2014-02-04 03:33:10 +0400 | [diff] [blame] | 13 | #include <linux/clk.h> |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 14 | #include <linux/crc32.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 16 | #include <linux/io.h> |
| 17 | #include <linux/mii.h> |
| 18 | #include <linux/phy.h> |
| 19 | #include <linux/platform_device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 20 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Jonas Bonn | e0f4258 | 2010-11-25 02:30:25 +0000 | [diff] [blame] | 22 | #include <linux/of.h> |
Florian Fainelli | b34296a | 2016-12-04 12:40:29 -0800 | [diff] [blame] | 23 | #include <linux/of_net.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 25 | #include <net/ethoc.h> |
| 26 | |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 27 | static int buffer_size = 0x8000; /* 32 KBytes */ |
| 28 | module_param(buffer_size, int, 0); |
| 29 | MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size"); |
| 30 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 31 | /* register offsets */ |
| 32 | #define MODER 0x00 |
| 33 | #define INT_SOURCE 0x04 |
| 34 | #define INT_MASK 0x08 |
| 35 | #define IPGT 0x0c |
| 36 | #define IPGR1 0x10 |
| 37 | #define IPGR2 0x14 |
| 38 | #define PACKETLEN 0x18 |
| 39 | #define COLLCONF 0x1c |
| 40 | #define TX_BD_NUM 0x20 |
| 41 | #define CTRLMODER 0x24 |
| 42 | #define MIIMODER 0x28 |
| 43 | #define MIICOMMAND 0x2c |
| 44 | #define MIIADDRESS 0x30 |
| 45 | #define MIITX_DATA 0x34 |
| 46 | #define MIIRX_DATA 0x38 |
| 47 | #define MIISTATUS 0x3c |
| 48 | #define MAC_ADDR0 0x40 |
| 49 | #define MAC_ADDR1 0x44 |
| 50 | #define ETH_HASH0 0x48 |
| 51 | #define ETH_HASH1 0x4c |
| 52 | #define ETH_TXCTRL 0x50 |
Max Filippov | 1112909 | 2014-01-31 09:41:06 +0400 | [diff] [blame] | 53 | #define ETH_END 0x54 |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 54 | |
| 55 | /* mode register */ |
| 56 | #define MODER_RXEN (1 << 0) /* receive enable */ |
| 57 | #define MODER_TXEN (1 << 1) /* transmit enable */ |
| 58 | #define MODER_NOPRE (1 << 2) /* no preamble */ |
| 59 | #define MODER_BRO (1 << 3) /* broadcast address */ |
| 60 | #define MODER_IAM (1 << 4) /* individual address mode */ |
| 61 | #define MODER_PRO (1 << 5) /* promiscuous mode */ |
| 62 | #define MODER_IFG (1 << 6) /* interframe gap for incoming frames */ |
| 63 | #define MODER_LOOP (1 << 7) /* loopback */ |
| 64 | #define MODER_NBO (1 << 8) /* no back-off */ |
| 65 | #define MODER_EDE (1 << 9) /* excess defer enable */ |
| 66 | #define MODER_FULLD (1 << 10) /* full duplex */ |
| 67 | #define MODER_RESET (1 << 11) /* FIXME: reset (undocumented) */ |
| 68 | #define MODER_DCRC (1 << 12) /* delayed CRC enable */ |
| 69 | #define MODER_CRC (1 << 13) /* CRC enable */ |
| 70 | #define MODER_HUGE (1 << 14) /* huge packets enable */ |
| 71 | #define MODER_PAD (1 << 15) /* padding enabled */ |
| 72 | #define MODER_RSM (1 << 16) /* receive small packets */ |
| 73 | |
| 74 | /* interrupt source and mask registers */ |
| 75 | #define INT_MASK_TXF (1 << 0) /* transmit frame */ |
| 76 | #define INT_MASK_TXE (1 << 1) /* transmit error */ |
| 77 | #define INT_MASK_RXF (1 << 2) /* receive frame */ |
| 78 | #define INT_MASK_RXE (1 << 3) /* receive error */ |
| 79 | #define INT_MASK_BUSY (1 << 4) |
| 80 | #define INT_MASK_TXC (1 << 5) /* transmit control frame */ |
| 81 | #define INT_MASK_RXC (1 << 6) /* receive control frame */ |
| 82 | |
| 83 | #define INT_MASK_TX (INT_MASK_TXF | INT_MASK_TXE) |
| 84 | #define INT_MASK_RX (INT_MASK_RXF | INT_MASK_RXE) |
| 85 | |
| 86 | #define INT_MASK_ALL ( \ |
| 87 | INT_MASK_TXF | INT_MASK_TXE | \ |
| 88 | INT_MASK_RXF | INT_MASK_RXE | \ |
| 89 | INT_MASK_TXC | INT_MASK_RXC | \ |
| 90 | INT_MASK_BUSY \ |
| 91 | ) |
| 92 | |
| 93 | /* packet length register */ |
| 94 | #define PACKETLEN_MIN(min) (((min) & 0xffff) << 16) |
| 95 | #define PACKETLEN_MAX(max) (((max) & 0xffff) << 0) |
| 96 | #define PACKETLEN_MIN_MAX(min, max) (PACKETLEN_MIN(min) | \ |
| 97 | PACKETLEN_MAX(max)) |
| 98 | |
| 99 | /* transmit buffer number register */ |
| 100 | #define TX_BD_NUM_VAL(x) (((x) <= 0x80) ? (x) : 0x80) |
| 101 | |
| 102 | /* control module mode register */ |
| 103 | #define CTRLMODER_PASSALL (1 << 0) /* pass all receive frames */ |
| 104 | #define CTRLMODER_RXFLOW (1 << 1) /* receive control flow */ |
| 105 | #define CTRLMODER_TXFLOW (1 << 2) /* transmit control flow */ |
| 106 | |
| 107 | /* MII mode register */ |
| 108 | #define MIIMODER_CLKDIV(x) ((x) & 0xfe) /* needs to be an even number */ |
| 109 | #define MIIMODER_NOPRE (1 << 8) /* no preamble */ |
| 110 | |
| 111 | /* MII command register */ |
| 112 | #define MIICOMMAND_SCAN (1 << 0) /* scan status */ |
| 113 | #define MIICOMMAND_READ (1 << 1) /* read status */ |
| 114 | #define MIICOMMAND_WRITE (1 << 2) /* write control data */ |
| 115 | |
| 116 | /* MII address register */ |
| 117 | #define MIIADDRESS_FIAD(x) (((x) & 0x1f) << 0) |
| 118 | #define MIIADDRESS_RGAD(x) (((x) & 0x1f) << 8) |
| 119 | #define MIIADDRESS_ADDR(phy, reg) (MIIADDRESS_FIAD(phy) | \ |
| 120 | MIIADDRESS_RGAD(reg)) |
| 121 | |
| 122 | /* MII transmit data register */ |
| 123 | #define MIITX_DATA_VAL(x) ((x) & 0xffff) |
| 124 | |
| 125 | /* MII receive data register */ |
| 126 | #define MIIRX_DATA_VAL(x) ((x) & 0xffff) |
| 127 | |
| 128 | /* MII status register */ |
| 129 | #define MIISTATUS_LINKFAIL (1 << 0) |
| 130 | #define MIISTATUS_BUSY (1 << 1) |
| 131 | #define MIISTATUS_INVALID (1 << 2) |
| 132 | |
| 133 | /* TX buffer descriptor */ |
| 134 | #define TX_BD_CS (1 << 0) /* carrier sense lost */ |
| 135 | #define TX_BD_DF (1 << 1) /* defer indication */ |
| 136 | #define TX_BD_LC (1 << 2) /* late collision */ |
| 137 | #define TX_BD_RL (1 << 3) /* retransmission limit */ |
| 138 | #define TX_BD_RETRY_MASK (0x00f0) |
| 139 | #define TX_BD_RETRY(x) (((x) & 0x00f0) >> 4) |
| 140 | #define TX_BD_UR (1 << 8) /* transmitter underrun */ |
| 141 | #define TX_BD_CRC (1 << 11) /* TX CRC enable */ |
| 142 | #define TX_BD_PAD (1 << 12) /* pad enable for short packets */ |
| 143 | #define TX_BD_WRAP (1 << 13) |
| 144 | #define TX_BD_IRQ (1 << 14) /* interrupt request enable */ |
| 145 | #define TX_BD_READY (1 << 15) /* TX buffer ready */ |
| 146 | #define TX_BD_LEN(x) (((x) & 0xffff) << 16) |
| 147 | #define TX_BD_LEN_MASK (0xffff << 16) |
| 148 | |
| 149 | #define TX_BD_STATS (TX_BD_CS | TX_BD_DF | TX_BD_LC | \ |
| 150 | TX_BD_RL | TX_BD_RETRY_MASK | TX_BD_UR) |
| 151 | |
| 152 | /* RX buffer descriptor */ |
| 153 | #define RX_BD_LC (1 << 0) /* late collision */ |
| 154 | #define RX_BD_CRC (1 << 1) /* RX CRC error */ |
| 155 | #define RX_BD_SF (1 << 2) /* short frame */ |
| 156 | #define RX_BD_TL (1 << 3) /* too long */ |
| 157 | #define RX_BD_DN (1 << 4) /* dribble nibble */ |
| 158 | #define RX_BD_IS (1 << 5) /* invalid symbol */ |
| 159 | #define RX_BD_OR (1 << 6) /* receiver overrun */ |
| 160 | #define RX_BD_MISS (1 << 7) |
| 161 | #define RX_BD_CF (1 << 8) /* control frame */ |
| 162 | #define RX_BD_WRAP (1 << 13) |
| 163 | #define RX_BD_IRQ (1 << 14) /* interrupt request enable */ |
| 164 | #define RX_BD_EMPTY (1 << 15) |
| 165 | #define RX_BD_LEN(x) (((x) & 0xffff) << 16) |
| 166 | |
| 167 | #define RX_BD_STATS (RX_BD_LC | RX_BD_CRC | RX_BD_SF | RX_BD_TL | \ |
| 168 | RX_BD_DN | RX_BD_IS | RX_BD_OR | RX_BD_MISS) |
| 169 | |
| 170 | #define ETHOC_BUFSIZ 1536 |
| 171 | #define ETHOC_ZLEN 64 |
| 172 | #define ETHOC_BD_BASE 0x400 |
| 173 | #define ETHOC_TIMEOUT (HZ / 2) |
| 174 | #define ETHOC_MII_TIMEOUT (1 + (HZ / 5)) |
| 175 | |
| 176 | /** |
| 177 | * struct ethoc - driver-private device structure |
| 178 | * @iobase: pointer to I/O memory region |
| 179 | * @membase: pointer to buffer memory region |
Jesse Brandeburg | d0ea5cb | 2020-09-25 15:24:45 -0700 | [diff] [blame] | 180 | * @big_endian: just big or little (endian) |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 181 | * @num_bd: number of buffer descriptors |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 182 | * @num_tx: number of send buffers |
| 183 | * @cur_tx: last send buffer written |
| 184 | * @dty_tx: last buffer actually sent |
| 185 | * @num_rx: number of receive buffers |
| 186 | * @cur_rx: current receive buffer |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 187 | * @vma: pointer to array of virtual memory addresses for buffers |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 188 | * @netdev: pointer to network device structure |
| 189 | * @napi: NAPI structure |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 190 | * @msg_enable: device state flags |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 191 | * @lock: device lock |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 192 | * @mdio: MDIO bus for PHY access |
Jesse Brandeburg | d0ea5cb | 2020-09-25 15:24:45 -0700 | [diff] [blame] | 193 | * @clk: clock |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 194 | * @phy_id: address of attached PHY |
Jesse Brandeburg | d0ea5cb | 2020-09-25 15:24:45 -0700 | [diff] [blame] | 195 | * @old_link: previous link info |
| 196 | * @old_duplex: previous duplex info |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 197 | */ |
| 198 | struct ethoc { |
| 199 | void __iomem *iobase; |
| 200 | void __iomem *membase; |
Max Filippov | 06e60e59 | 2015-09-22 14:27:16 +0300 | [diff] [blame] | 201 | bool big_endian; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 202 | |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 203 | unsigned int num_bd; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 204 | unsigned int num_tx; |
| 205 | unsigned int cur_tx; |
| 206 | unsigned int dty_tx; |
| 207 | |
| 208 | unsigned int num_rx; |
| 209 | unsigned int cur_rx; |
| 210 | |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 211 | void **vma; |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 212 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 213 | struct net_device *netdev; |
| 214 | struct napi_struct napi; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 215 | u32 msg_enable; |
| 216 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 217 | spinlock_t lock; |
| 218 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 219 | struct mii_bus *mdio; |
Max Filippov | a13aff0 | 2014-02-04 03:33:10 +0400 | [diff] [blame] | 220 | struct clk *clk; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 221 | s8 phy_id; |
Florian Fainelli | abf7e53 | 2016-12-04 12:40:28 -0800 | [diff] [blame] | 222 | |
| 223 | int old_link; |
| 224 | int old_duplex; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | /** |
| 228 | * struct ethoc_bd - buffer descriptor |
| 229 | * @stat: buffer statistics |
| 230 | * @addr: physical memory address |
| 231 | */ |
| 232 | struct ethoc_bd { |
| 233 | u32 stat; |
| 234 | u32 addr; |
| 235 | }; |
| 236 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 237 | static inline u32 ethoc_read(struct ethoc *dev, loff_t offset) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 238 | { |
Max Filippov | 06e60e59 | 2015-09-22 14:27:16 +0300 | [diff] [blame] | 239 | if (dev->big_endian) |
| 240 | return ioread32be(dev->iobase + offset); |
| 241 | else |
| 242 | return ioread32(dev->iobase + offset); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 245 | static inline void ethoc_write(struct ethoc *dev, loff_t offset, u32 data) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 246 | { |
Max Filippov | 06e60e59 | 2015-09-22 14:27:16 +0300 | [diff] [blame] | 247 | if (dev->big_endian) |
| 248 | iowrite32be(data, dev->iobase + offset); |
| 249 | else |
| 250 | iowrite32(data, dev->iobase + offset); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 253 | static inline void ethoc_read_bd(struct ethoc *dev, int index, |
| 254 | struct ethoc_bd *bd) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 255 | { |
| 256 | loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); |
| 257 | bd->stat = ethoc_read(dev, offset + 0); |
| 258 | bd->addr = ethoc_read(dev, offset + 4); |
| 259 | } |
| 260 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 261 | static inline void ethoc_write_bd(struct ethoc *dev, int index, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 262 | const struct ethoc_bd *bd) |
| 263 | { |
| 264 | loff_t offset = ETHOC_BD_BASE + (index * sizeof(struct ethoc_bd)); |
| 265 | ethoc_write(dev, offset + 0, bd->stat); |
| 266 | ethoc_write(dev, offset + 4, bd->addr); |
| 267 | } |
| 268 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 269 | static inline void ethoc_enable_irq(struct ethoc *dev, u32 mask) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 270 | { |
| 271 | u32 imask = ethoc_read(dev, INT_MASK); |
| 272 | imask |= mask; |
| 273 | ethoc_write(dev, INT_MASK, imask); |
| 274 | } |
| 275 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 276 | static inline void ethoc_disable_irq(struct ethoc *dev, u32 mask) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 277 | { |
| 278 | u32 imask = ethoc_read(dev, INT_MASK); |
| 279 | imask &= ~mask; |
| 280 | ethoc_write(dev, INT_MASK, imask); |
| 281 | } |
| 282 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 283 | static inline void ethoc_ack_irq(struct ethoc *dev, u32 mask) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 284 | { |
| 285 | ethoc_write(dev, INT_SOURCE, mask); |
| 286 | } |
| 287 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 288 | static inline void ethoc_enable_rx_and_tx(struct ethoc *dev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 289 | { |
| 290 | u32 mode = ethoc_read(dev, MODER); |
| 291 | mode |= MODER_RXEN | MODER_TXEN; |
| 292 | ethoc_write(dev, MODER, mode); |
| 293 | } |
| 294 | |
Thomas Chou | 16dd18b | 2009-10-07 14:16:42 +0000 | [diff] [blame] | 295 | static inline void ethoc_disable_rx_and_tx(struct ethoc *dev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 296 | { |
| 297 | u32 mode = ethoc_read(dev, MODER); |
| 298 | mode &= ~(MODER_RXEN | MODER_TXEN); |
| 299 | ethoc_write(dev, MODER, mode); |
| 300 | } |
| 301 | |
David S. Miller | 5cf3e03 | 2010-07-07 18:23:19 -0700 | [diff] [blame] | 302 | static int ethoc_init_ring(struct ethoc *dev, unsigned long mem_start) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 303 | { |
| 304 | struct ethoc_bd bd; |
| 305 | int i; |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 306 | void *vma; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 307 | |
| 308 | dev->cur_tx = 0; |
| 309 | dev->dty_tx = 0; |
| 310 | dev->cur_rx = 0; |
| 311 | |
Jonas Bonn | ee4f56b | 2010-06-11 02:47:36 +0000 | [diff] [blame] | 312 | ethoc_write(dev, TX_BD_NUM, dev->num_tx); |
| 313 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 314 | /* setup transmission buffers */ |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 315 | bd.addr = mem_start; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 316 | bd.stat = TX_BD_IRQ | TX_BD_CRC; |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 317 | vma = dev->membase; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 318 | |
| 319 | for (i = 0; i < dev->num_tx; i++) { |
| 320 | if (i == dev->num_tx - 1) |
| 321 | bd.stat |= TX_BD_WRAP; |
| 322 | |
| 323 | ethoc_write_bd(dev, i, &bd); |
| 324 | bd.addr += ETHOC_BUFSIZ; |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 325 | |
| 326 | dev->vma[i] = vma; |
| 327 | vma += ETHOC_BUFSIZ; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 330 | bd.stat = RX_BD_EMPTY | RX_BD_IRQ; |
| 331 | |
| 332 | for (i = 0; i < dev->num_rx; i++) { |
| 333 | if (i == dev->num_rx - 1) |
| 334 | bd.stat |= RX_BD_WRAP; |
| 335 | |
| 336 | ethoc_write_bd(dev, dev->num_tx + i, &bd); |
| 337 | bd.addr += ETHOC_BUFSIZ; |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 338 | |
| 339 | dev->vma[dev->num_tx + i] = vma; |
| 340 | vma += ETHOC_BUFSIZ; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int ethoc_reset(struct ethoc *dev) |
| 347 | { |
| 348 | u32 mode; |
| 349 | |
| 350 | /* TODO: reset controller? */ |
| 351 | |
| 352 | ethoc_disable_rx_and_tx(dev); |
| 353 | |
| 354 | /* TODO: setup registers */ |
| 355 | |
| 356 | /* enable FCS generation and automatic padding */ |
| 357 | mode = ethoc_read(dev, MODER); |
| 358 | mode |= MODER_CRC | MODER_PAD; |
| 359 | ethoc_write(dev, MODER, mode); |
| 360 | |
| 361 | /* set full-duplex mode */ |
| 362 | mode = ethoc_read(dev, MODER); |
| 363 | mode |= MODER_FULLD; |
| 364 | ethoc_write(dev, MODER, mode); |
| 365 | ethoc_write(dev, IPGT, 0x15); |
| 366 | |
| 367 | ethoc_ack_irq(dev, INT_MASK_ALL); |
| 368 | ethoc_enable_irq(dev, INT_MASK_ALL); |
| 369 | ethoc_enable_rx_and_tx(dev); |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static unsigned int ethoc_update_rx_stats(struct ethoc *dev, |
| 374 | struct ethoc_bd *bd) |
| 375 | { |
| 376 | struct net_device *netdev = dev->netdev; |
| 377 | unsigned int ret = 0; |
| 378 | |
| 379 | if (bd->stat & RX_BD_TL) { |
| 380 | dev_err(&netdev->dev, "RX: frame too long\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 381 | netdev->stats.rx_length_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 382 | ret++; |
| 383 | } |
| 384 | |
| 385 | if (bd->stat & RX_BD_SF) { |
| 386 | dev_err(&netdev->dev, "RX: frame too short\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 387 | netdev->stats.rx_length_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 388 | ret++; |
| 389 | } |
| 390 | |
| 391 | if (bd->stat & RX_BD_DN) { |
| 392 | dev_err(&netdev->dev, "RX: dribble nibble\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 393 | netdev->stats.rx_frame_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | if (bd->stat & RX_BD_CRC) { |
| 397 | dev_err(&netdev->dev, "RX: wrong CRC\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 398 | netdev->stats.rx_crc_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 399 | ret++; |
| 400 | } |
| 401 | |
| 402 | if (bd->stat & RX_BD_OR) { |
| 403 | dev_err(&netdev->dev, "RX: overrun\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 404 | netdev->stats.rx_over_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 405 | ret++; |
| 406 | } |
| 407 | |
| 408 | if (bd->stat & RX_BD_MISS) |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 409 | netdev->stats.rx_missed_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 410 | |
| 411 | if (bd->stat & RX_BD_LC) { |
| 412 | dev_err(&netdev->dev, "RX: late collision\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 413 | netdev->stats.collisions++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 414 | ret++; |
| 415 | } |
| 416 | |
| 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | static int ethoc_rx(struct net_device *dev, int limit) |
| 421 | { |
| 422 | struct ethoc *priv = netdev_priv(dev); |
| 423 | int count; |
| 424 | |
| 425 | for (count = 0; count < limit; ++count) { |
| 426 | unsigned int entry; |
| 427 | struct ethoc_bd bd; |
| 428 | |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 429 | entry = priv->num_tx + priv->cur_rx; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 430 | ethoc_read_bd(priv, entry, &bd); |
Jonas Bonn | 20f70dd | 2010-11-25 02:30:28 +0000 | [diff] [blame] | 431 | if (bd.stat & RX_BD_EMPTY) { |
| 432 | ethoc_ack_irq(priv, INT_MASK_RX); |
| 433 | /* If packet (interrupt) came in between checking |
| 434 | * BD_EMTPY and clearing the interrupt source, then we |
| 435 | * risk missing the packet as the RX interrupt won't |
| 436 | * trigger right away when we reenable it; hence, check |
| 437 | * BD_EMTPY here again to make sure there isn't such a |
| 438 | * packet waiting for us... |
| 439 | */ |
| 440 | ethoc_read_bd(priv, entry, &bd); |
| 441 | if (bd.stat & RX_BD_EMPTY) |
| 442 | break; |
| 443 | } |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 444 | |
| 445 | if (ethoc_update_rx_stats(priv, &bd) == 0) { |
| 446 | int size = bd.stat >> 16; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 447 | struct sk_buff *skb; |
Thomas Chou | 050f91d | 2009-10-04 23:33:19 +0000 | [diff] [blame] | 448 | |
| 449 | size -= 4; /* strip the CRC */ |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 450 | skb = netdev_alloc_skb_ip_align(dev, size); |
Thomas Chou | 050f91d | 2009-10-04 23:33:19 +0000 | [diff] [blame] | 451 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 452 | if (likely(skb)) { |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 453 | void *src = priv->vma[entry]; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 454 | memcpy_fromio(skb_put(skb, size), src, size); |
| 455 | skb->protocol = eth_type_trans(skb, dev); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 456 | dev->stats.rx_packets++; |
| 457 | dev->stats.rx_bytes += size; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 458 | netif_receive_skb(skb); |
| 459 | } else { |
| 460 | if (net_ratelimit()) |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 461 | dev_warn(&dev->dev, |
| 462 | "low on memory - packet dropped\n"); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 463 | |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 464 | dev->stats.rx_dropped++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 465 | break; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /* clear the buffer descriptor so it can be reused */ |
| 470 | bd.stat &= ~RX_BD_STATS; |
| 471 | bd.stat |= RX_BD_EMPTY; |
| 472 | ethoc_write_bd(priv, entry, &bd); |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 473 | if (++priv->cur_rx == priv->num_rx) |
| 474 | priv->cur_rx = 0; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | return count; |
| 478 | } |
| 479 | |
Jonas Bonn | 4f64bcb | 2010-11-25 02:30:31 +0000 | [diff] [blame] | 480 | static void ethoc_update_tx_stats(struct ethoc *dev, struct ethoc_bd *bd) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 481 | { |
| 482 | struct net_device *netdev = dev->netdev; |
| 483 | |
| 484 | if (bd->stat & TX_BD_LC) { |
| 485 | dev_err(&netdev->dev, "TX: late collision\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 486 | netdev->stats.tx_window_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (bd->stat & TX_BD_RL) { |
| 490 | dev_err(&netdev->dev, "TX: retransmit limit\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 491 | netdev->stats.tx_aborted_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (bd->stat & TX_BD_UR) { |
| 495 | dev_err(&netdev->dev, "TX: underrun\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 496 | netdev->stats.tx_fifo_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (bd->stat & TX_BD_CS) { |
| 500 | dev_err(&netdev->dev, "TX: carrier sense lost\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 501 | netdev->stats.tx_carrier_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if (bd->stat & TX_BD_STATS) |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 505 | netdev->stats.tx_errors++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 506 | |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 507 | netdev->stats.collisions += (bd->stat >> 4) & 0xf; |
| 508 | netdev->stats.tx_bytes += bd->stat >> 16; |
| 509 | netdev->stats.tx_packets++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 512 | static int ethoc_tx(struct net_device *dev, int limit) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 513 | { |
| 514 | struct ethoc *priv = netdev_priv(dev); |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 515 | int count; |
| 516 | struct ethoc_bd bd; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 517 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 518 | for (count = 0; count < limit; ++count) { |
| 519 | unsigned int entry; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 520 | |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 521 | entry = priv->dty_tx & (priv->num_tx-1); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 522 | |
| 523 | ethoc_read_bd(priv, entry, &bd); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 524 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 525 | if (bd.stat & TX_BD_READY || (priv->dty_tx == priv->cur_tx)) { |
| 526 | ethoc_ack_irq(priv, INT_MASK_TX); |
| 527 | /* If interrupt came in between reading in the BD |
| 528 | * and clearing the interrupt source, then we risk |
| 529 | * missing the event as the TX interrupt won't trigger |
| 530 | * right away when we reenable it; hence, check |
| 531 | * BD_EMPTY here again to make sure there isn't such an |
| 532 | * event pending... |
| 533 | */ |
| 534 | ethoc_read_bd(priv, entry, &bd); |
| 535 | if (bd.stat & TX_BD_READY || |
| 536 | (priv->dty_tx == priv->cur_tx)) |
| 537 | break; |
| 538 | } |
| 539 | |
Jonas Bonn | 4f64bcb | 2010-11-25 02:30:31 +0000 | [diff] [blame] | 540 | ethoc_update_tx_stats(priv, &bd); |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 541 | priv->dty_tx++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if ((priv->cur_tx - priv->dty_tx) <= (priv->num_tx / 2)) |
| 545 | netif_wake_queue(dev); |
| 546 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 547 | return count; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static irqreturn_t ethoc_interrupt(int irq, void *dev_id) |
| 551 | { |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 552 | struct net_device *dev = dev_id; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 553 | struct ethoc *priv = netdev_priv(dev); |
| 554 | u32 pending; |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 555 | u32 mask; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 556 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 557 | /* Figure out what triggered the interrupt... |
| 558 | * The tricky bit here is that the interrupt source bits get |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 559 | * set in INT_SOURCE for an event regardless of whether that |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 560 | * event is masked or not. Thus, in order to figure out what |
| 561 | * triggered the interrupt, we need to remove the sources |
| 562 | * for all events that are currently masked. This behaviour |
| 563 | * is not particularly well documented but reasonable... |
| 564 | */ |
| 565 | mask = ethoc_read(priv, INT_MASK); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 566 | pending = ethoc_read(priv, INT_SOURCE); |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 567 | pending &= mask; |
| 568 | |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 569 | if (unlikely(pending == 0)) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 570 | return IRQ_NONE; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 571 | |
Thomas Chou | 50c54a5 | 2009-10-07 14:16:43 +0000 | [diff] [blame] | 572 | ethoc_ack_irq(priv, pending); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 573 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 574 | /* We always handle the dropped packet interrupt */ |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 575 | if (pending & INT_MASK_BUSY) { |
Florian Fainelli | 38b4bc2 | 2016-12-04 12:40:30 -0800 | [diff] [blame] | 576 | dev_dbg(&dev->dev, "packet dropped\n"); |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 577 | dev->stats.rx_dropped++; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 580 | /* Handle receive/transmit event by switching to polling */ |
| 581 | if (pending & (INT_MASK_TX | INT_MASK_RX)) { |
| 582 | ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX); |
| 583 | napi_schedule(&priv->napi); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 586 | return IRQ_HANDLED; |
| 587 | } |
| 588 | |
| 589 | static int ethoc_get_mac_address(struct net_device *dev, void *addr) |
| 590 | { |
| 591 | struct ethoc *priv = netdev_priv(dev); |
| 592 | u8 *mac = (u8 *)addr; |
| 593 | u32 reg; |
| 594 | |
| 595 | reg = ethoc_read(priv, MAC_ADDR0); |
| 596 | mac[2] = (reg >> 24) & 0xff; |
| 597 | mac[3] = (reg >> 16) & 0xff; |
| 598 | mac[4] = (reg >> 8) & 0xff; |
| 599 | mac[5] = (reg >> 0) & 0xff; |
| 600 | |
| 601 | reg = ethoc_read(priv, MAC_ADDR1); |
| 602 | mac[0] = (reg >> 8) & 0xff; |
| 603 | mac[1] = (reg >> 0) & 0xff; |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static int ethoc_poll(struct napi_struct *napi, int budget) |
| 609 | { |
| 610 | struct ethoc *priv = container_of(napi, struct ethoc, napi); |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 611 | int rx_work_done = 0; |
| 612 | int tx_work_done = 0; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 613 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 614 | rx_work_done = ethoc_rx(priv->netdev, budget); |
| 615 | tx_work_done = ethoc_tx(priv->netdev, budget); |
| 616 | |
| 617 | if (rx_work_done < budget && tx_work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 618 | napi_complete_done(napi, rx_work_done); |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 619 | ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Jonas Bonn | fa98eb0 | 2010-11-25 02:30:29 +0000 | [diff] [blame] | 622 | return rx_work_done; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg) |
| 626 | { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 627 | struct ethoc *priv = bus->priv; |
Jonas Bonn | 8dac428 | 2010-11-25 02:30:30 +0000 | [diff] [blame] | 628 | int i; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 629 | |
| 630 | ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); |
| 631 | ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ); |
| 632 | |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 633 | for (i = 0; i < 5; i++) { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 634 | u32 status = ethoc_read(priv, MIISTATUS); |
| 635 | if (!(status & MIISTATUS_BUSY)) { |
| 636 | u32 data = ethoc_read(priv, MIIRX_DATA); |
| 637 | /* reset MII command register */ |
| 638 | ethoc_write(priv, MIICOMMAND, 0); |
| 639 | return data; |
| 640 | } |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 641 | usleep_range(100, 200); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | return -EBUSY; |
| 645 | } |
| 646 | |
| 647 | static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) |
| 648 | { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 649 | struct ethoc *priv = bus->priv; |
Jonas Bonn | 8dac428 | 2010-11-25 02:30:30 +0000 | [diff] [blame] | 650 | int i; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 651 | |
| 652 | ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); |
| 653 | ethoc_write(priv, MIITX_DATA, val); |
| 654 | ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE); |
| 655 | |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 656 | for (i = 0; i < 5; i++) { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 657 | u32 stat = ethoc_read(priv, MIISTATUS); |
Jonas Bonn | b46773d | 2010-06-11 02:47:39 +0000 | [diff] [blame] | 658 | if (!(stat & MIISTATUS_BUSY)) { |
| 659 | /* reset MII command register */ |
| 660 | ethoc_write(priv, MIICOMMAND, 0); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 661 | return 0; |
Jonas Bonn | b46773d | 2010-06-11 02:47:39 +0000 | [diff] [blame] | 662 | } |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 663 | usleep_range(100, 200); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | return -EBUSY; |
| 667 | } |
| 668 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 669 | static void ethoc_mdio_poll(struct net_device *dev) |
| 670 | { |
Florian Fainelli | abf7e53 | 2016-12-04 12:40:28 -0800 | [diff] [blame] | 671 | struct ethoc *priv = netdev_priv(dev); |
| 672 | struct phy_device *phydev = dev->phydev; |
| 673 | bool changed = false; |
| 674 | u32 mode; |
| 675 | |
| 676 | if (priv->old_link != phydev->link) { |
| 677 | changed = true; |
| 678 | priv->old_link = phydev->link; |
| 679 | } |
| 680 | |
| 681 | if (priv->old_duplex != phydev->duplex) { |
| 682 | changed = true; |
| 683 | priv->old_duplex = phydev->duplex; |
| 684 | } |
| 685 | |
| 686 | if (!changed) |
| 687 | return; |
| 688 | |
| 689 | mode = ethoc_read(priv, MODER); |
| 690 | if (phydev->duplex == DUPLEX_FULL) |
| 691 | mode |= MODER_FULLD; |
| 692 | else |
| 693 | mode &= ~MODER_FULLD; |
| 694 | ethoc_write(priv, MODER, mode); |
| 695 | |
| 696 | phy_print_status(phydev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Bill Pemberton | a0a4efe | 2012-12-03 09:24:09 -0500 | [diff] [blame] | 699 | static int ethoc_mdio_probe(struct net_device *dev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 700 | { |
| 701 | struct ethoc *priv = netdev_priv(dev); |
| 702 | struct phy_device *phy; |
Jonas Bonn | 637f33b8 | 2010-06-11 02:47:37 +0000 | [diff] [blame] | 703 | int err; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 704 | |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 705 | if (priv->phy_id != -1) |
Andrew Lunn | 7f85442 | 2016-01-06 20:11:18 +0100 | [diff] [blame] | 706 | phy = mdiobus_get_phy(priv->mdio, priv->phy_id); |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 707 | else |
Jonas Bonn | 637f33b8 | 2010-06-11 02:47:37 +0000 | [diff] [blame] | 708 | phy = phy_find_first(priv->mdio); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 709 | |
Cai Huoqing | 015a22f | 2021-09-15 22:58:27 +0800 | [diff] [blame] | 710 | if (!phy) |
| 711 | return dev_err_probe(&dev->dev, -ENXIO, "no PHY found\n"); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 712 | |
Florian Fainelli | abf7e53 | 2016-12-04 12:40:28 -0800 | [diff] [blame] | 713 | priv->old_duplex = -1; |
| 714 | priv->old_link = -1; |
| 715 | |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 716 | err = phy_connect_direct(dev, phy, ethoc_mdio_poll, |
| 717 | PHY_INTERFACE_MODE_GMII); |
Cai Huoqing | 015a22f | 2021-09-15 22:58:27 +0800 | [diff] [blame] | 718 | if (err) |
| 719 | return dev_err_probe(&dev->dev, err, "could not attach to PHY\n"); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 720 | |
Andrew Lunn | 58056c1 | 2018-09-12 01:53:11 +0200 | [diff] [blame] | 721 | phy_set_max_speed(phy, SPEED_100); |
Max Filippov | 445a48c | 2014-02-04 03:33:09 +0400 | [diff] [blame] | 722 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int ethoc_open(struct net_device *dev) |
| 727 | { |
| 728 | struct ethoc *priv = netdev_priv(dev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 729 | int ret; |
| 730 | |
| 731 | ret = request_irq(dev->irq, ethoc_interrupt, IRQF_SHARED, |
| 732 | dev->name, dev); |
| 733 | if (ret) |
| 734 | return ret; |
| 735 | |
Max Filippov | d220b94 | 2017-06-05 18:31:16 -0700 | [diff] [blame] | 736 | napi_enable(&priv->napi); |
| 737 | |
David S. Miller | 5cf3e03 | 2010-07-07 18:23:19 -0700 | [diff] [blame] | 738 | ethoc_init_ring(priv, dev->mem_start); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 739 | ethoc_reset(priv); |
| 740 | |
| 741 | if (netif_queue_stopped(dev)) { |
| 742 | dev_dbg(&dev->dev, " resuming queue\n"); |
| 743 | netif_wake_queue(dev); |
| 744 | } else { |
| 745 | dev_dbg(&dev->dev, " starting queue\n"); |
| 746 | netif_start_queue(dev); |
| 747 | } |
| 748 | |
Florian Fainelli | abf7e53 | 2016-12-04 12:40:28 -0800 | [diff] [blame] | 749 | priv->old_link = -1; |
| 750 | priv->old_duplex = -1; |
| 751 | |
Philippe Reynes | 11331fc | 2016-07-15 09:59:11 +0200 | [diff] [blame] | 752 | phy_start(dev->phydev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 753 | |
| 754 | if (netif_msg_ifup(priv)) { |
| 755 | dev_info(&dev->dev, "I/O: %08lx Memory: %08lx-%08lx\n", |
| 756 | dev->base_addr, dev->mem_start, dev->mem_end); |
| 757 | } |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static int ethoc_stop(struct net_device *dev) |
| 763 | { |
| 764 | struct ethoc *priv = netdev_priv(dev); |
| 765 | |
| 766 | napi_disable(&priv->napi); |
| 767 | |
Philippe Reynes | 11331fc | 2016-07-15 09:59:11 +0200 | [diff] [blame] | 768 | if (dev->phydev) |
| 769 | phy_stop(dev->phydev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 770 | |
| 771 | ethoc_disable_rx_and_tx(priv); |
| 772 | free_irq(dev->irq, dev); |
| 773 | |
| 774 | if (!netif_queue_stopped(dev)) |
| 775 | netif_stop_queue(dev); |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | static int ethoc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 781 | { |
| 782 | struct ethoc *priv = netdev_priv(dev); |
| 783 | struct mii_ioctl_data *mdio = if_mii(ifr); |
| 784 | struct phy_device *phy = NULL; |
| 785 | |
| 786 | if (!netif_running(dev)) |
| 787 | return -EINVAL; |
| 788 | |
| 789 | if (cmd != SIOCGMIIPHY) { |
| 790 | if (mdio->phy_id >= PHY_MAX_ADDR) |
| 791 | return -ERANGE; |
| 792 | |
Andrew Lunn | 7f85442 | 2016-01-06 20:11:18 +0100 | [diff] [blame] | 793 | phy = mdiobus_get_phy(priv->mdio, mdio->phy_id); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 794 | if (!phy) |
| 795 | return -ENODEV; |
| 796 | } else { |
Philippe Reynes | 11331fc | 2016-07-15 09:59:11 +0200 | [diff] [blame] | 797 | phy = dev->phydev; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 800 | return phy_mii_ioctl(phy, ifr, cmd); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 803 | static void ethoc_do_set_mac_address(struct net_device *dev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 804 | { |
Jakub Kicinski | 7666075 | 2021-10-14 07:24:31 -0700 | [diff] [blame] | 805 | const unsigned char *mac = dev->dev_addr; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 806 | struct ethoc *priv = netdev_priv(dev); |
Danny Kukawka | 939d225 | 2012-02-17 05:43:29 +0000 | [diff] [blame] | 807 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 808 | ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | |
| 809 | (mac[4] << 8) | (mac[5] << 0)); |
| 810 | ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 811 | } |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 812 | |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 813 | static int ethoc_set_mac_address(struct net_device *dev, void *p) |
| 814 | { |
| 815 | const struct sockaddr *addr = p; |
Danny Kukawka | 939d225 | 2012-02-17 05:43:29 +0000 | [diff] [blame] | 816 | |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 817 | if (!is_valid_ether_addr(addr->sa_data)) |
| 818 | return -EADDRNOTAVAIL; |
Jakub Kicinski | a96d317 | 2021-10-01 14:32:20 -0700 | [diff] [blame] | 819 | eth_hw_addr_set(dev, addr->sa_data); |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 820 | ethoc_do_set_mac_address(dev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static void ethoc_set_multicast_list(struct net_device *dev) |
| 825 | { |
| 826 | struct ethoc *priv = netdev_priv(dev); |
| 827 | u32 mode = ethoc_read(priv, MODER); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 828 | struct netdev_hw_addr *ha; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 829 | u32 hash[2] = { 0, 0 }; |
| 830 | |
| 831 | /* set loopback mode if requested */ |
| 832 | if (dev->flags & IFF_LOOPBACK) |
| 833 | mode |= MODER_LOOP; |
| 834 | else |
| 835 | mode &= ~MODER_LOOP; |
| 836 | |
| 837 | /* receive broadcast frames if requested */ |
| 838 | if (dev->flags & IFF_BROADCAST) |
| 839 | mode &= ~MODER_BRO; |
| 840 | else |
| 841 | mode |= MODER_BRO; |
| 842 | |
| 843 | /* enable promiscuous mode if requested */ |
| 844 | if (dev->flags & IFF_PROMISC) |
| 845 | mode |= MODER_PRO; |
| 846 | else |
| 847 | mode &= ~MODER_PRO; |
| 848 | |
| 849 | ethoc_write(priv, MODER, mode); |
| 850 | |
| 851 | /* receive multicast frames */ |
| 852 | if (dev->flags & IFF_ALLMULTI) { |
| 853 | hash[0] = 0xffffffff; |
| 854 | hash[1] = 0xffffffff; |
| 855 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 856 | netdev_for_each_mc_addr(ha, dev) { |
| 857 | u32 crc = ether_crc(ETH_ALEN, ha->addr); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 858 | int bit = (crc >> 26) & 0x3f; |
| 859 | hash[bit >> 5] |= 1 << (bit & 0x1f); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | ethoc_write(priv, ETH_HASH0, hash[0]); |
| 864 | ethoc_write(priv, ETH_HASH1, hash[1]); |
| 865 | } |
| 866 | |
| 867 | static int ethoc_change_mtu(struct net_device *dev, int new_mtu) |
| 868 | { |
| 869 | return -ENOSYS; |
| 870 | } |
| 871 | |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 872 | static void ethoc_tx_timeout(struct net_device *dev, unsigned int txqueue) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 873 | { |
| 874 | struct ethoc *priv = netdev_priv(dev); |
| 875 | u32 pending = ethoc_read(priv, INT_SOURCE); |
| 876 | if (likely(pending)) |
| 877 | ethoc_interrupt(dev->irq, dev); |
| 878 | } |
| 879 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 880 | static netdev_tx_t ethoc_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 881 | { |
| 882 | struct ethoc *priv = netdev_priv(dev); |
| 883 | struct ethoc_bd bd; |
| 884 | unsigned int entry; |
| 885 | void *dest; |
| 886 | |
Florian Fainelli | ee6c21b | 2016-07-12 16:04:36 -0700 | [diff] [blame] | 887 | if (skb_put_padto(skb, ETHOC_ZLEN)) { |
| 888 | dev->stats.tx_errors++; |
| 889 | goto out_no_free; |
| 890 | } |
| 891 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 892 | if (unlikely(skb->len > ETHOC_BUFSIZ)) { |
Kulikov Vasiliy | 57616ee | 2010-07-05 02:13:31 +0000 | [diff] [blame] | 893 | dev->stats.tx_errors++; |
Patrick McHardy | 3790c8c | 2009-06-12 03:00:35 +0000 | [diff] [blame] | 894 | goto out; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | entry = priv->cur_tx % priv->num_tx; |
| 898 | spin_lock_irq(&priv->lock); |
| 899 | priv->cur_tx++; |
| 900 | |
| 901 | ethoc_read_bd(priv, entry, &bd); |
| 902 | if (unlikely(skb->len < ETHOC_ZLEN)) |
| 903 | bd.stat |= TX_BD_PAD; |
| 904 | else |
| 905 | bd.stat &= ~TX_BD_PAD; |
| 906 | |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 907 | dest = priv->vma[entry]; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 908 | memcpy_toio(dest, skb->data, skb->len); |
| 909 | |
| 910 | bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK); |
| 911 | bd.stat |= TX_BD_LEN(skb->len); |
| 912 | ethoc_write_bd(priv, entry, &bd); |
| 913 | |
| 914 | bd.stat |= TX_BD_READY; |
| 915 | ethoc_write_bd(priv, entry, &bd); |
| 916 | |
| 917 | if (priv->cur_tx == (priv->dty_tx + priv->num_tx)) { |
| 918 | dev_dbg(&dev->dev, "stopping queue\n"); |
| 919 | netif_stop_queue(dev); |
| 920 | } |
| 921 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 922 | spin_unlock_irq(&priv->lock); |
Richard Cochran | 68f5139 | 2011-06-12 02:19:04 +0000 | [diff] [blame] | 923 | skb_tx_timestamp(skb); |
Patrick McHardy | 3790c8c | 2009-06-12 03:00:35 +0000 | [diff] [blame] | 924 | out: |
| 925 | dev_kfree_skb(skb); |
Florian Fainelli | ee6c21b | 2016-07-12 16:04:36 -0700 | [diff] [blame] | 926 | out_no_free: |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 927 | return NETDEV_TX_OK; |
| 928 | } |
| 929 | |
Max Filippov | 1112909 | 2014-01-31 09:41:06 +0400 | [diff] [blame] | 930 | static int ethoc_get_regs_len(struct net_device *netdev) |
| 931 | { |
| 932 | return ETH_END; |
| 933 | } |
| 934 | |
| 935 | static void ethoc_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 936 | void *p) |
| 937 | { |
| 938 | struct ethoc *priv = netdev_priv(dev); |
| 939 | u32 *regs_buff = p; |
| 940 | unsigned i; |
| 941 | |
| 942 | regs->version = 0; |
| 943 | for (i = 0; i < ETH_END / sizeof(u32); ++i) |
| 944 | regs_buff[i] = ethoc_read(priv, i * sizeof(u32)); |
| 945 | } |
| 946 | |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 947 | static void ethoc_get_ringparam(struct net_device *dev, |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 948 | struct ethtool_ringparam *ring, |
| 949 | struct kernel_ethtool_ringparam *kernel_ring, |
| 950 | struct netlink_ext_ack *extack) |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 951 | { |
| 952 | struct ethoc *priv = netdev_priv(dev); |
| 953 | |
| 954 | ring->rx_max_pending = priv->num_bd - 1; |
| 955 | ring->rx_mini_max_pending = 0; |
| 956 | ring->rx_jumbo_max_pending = 0; |
| 957 | ring->tx_max_pending = priv->num_bd - 1; |
| 958 | |
| 959 | ring->rx_pending = priv->num_rx; |
| 960 | ring->rx_mini_pending = 0; |
| 961 | ring->rx_jumbo_pending = 0; |
| 962 | ring->tx_pending = priv->num_tx; |
| 963 | } |
| 964 | |
| 965 | static int ethoc_set_ringparam(struct net_device *dev, |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 966 | struct ethtool_ringparam *ring, |
| 967 | struct kernel_ethtool_ringparam *kernel_ring, |
| 968 | struct netlink_ext_ack *extack) |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 969 | { |
| 970 | struct ethoc *priv = netdev_priv(dev); |
| 971 | |
| 972 | if (ring->tx_pending < 1 || ring->rx_pending < 1 || |
| 973 | ring->tx_pending + ring->rx_pending > priv->num_bd) |
| 974 | return -EINVAL; |
| 975 | if (ring->rx_mini_pending || ring->rx_jumbo_pending) |
| 976 | return -EINVAL; |
| 977 | |
| 978 | if (netif_running(dev)) { |
| 979 | netif_tx_disable(dev); |
| 980 | ethoc_disable_rx_and_tx(priv); |
| 981 | ethoc_disable_irq(priv, INT_MASK_TX | INT_MASK_RX); |
| 982 | synchronize_irq(dev->irq); |
| 983 | } |
| 984 | |
| 985 | priv->num_tx = rounddown_pow_of_two(ring->tx_pending); |
| 986 | priv->num_rx = ring->rx_pending; |
| 987 | ethoc_init_ring(priv, dev->mem_start); |
| 988 | |
| 989 | if (netif_running(dev)) { |
| 990 | ethoc_enable_irq(priv, INT_MASK_TX | INT_MASK_RX); |
| 991 | ethoc_enable_rx_and_tx(priv); |
| 992 | netif_wake_queue(dev); |
| 993 | } |
| 994 | return 0; |
| 995 | } |
| 996 | |
Tobias Klauser | a870a97 | 2017-01-17 15:01:08 +0100 | [diff] [blame] | 997 | static const struct ethtool_ops ethoc_ethtool_ops = { |
Max Filippov | 1112909 | 2014-01-31 09:41:06 +0400 | [diff] [blame] | 998 | .get_regs_len = ethoc_get_regs_len, |
| 999 | .get_regs = ethoc_get_regs, |
Florian Fainelli | 3d3ba56 | 2016-11-15 11:19:46 -0800 | [diff] [blame] | 1000 | .nway_reset = phy_ethtool_nway_reset, |
Max Filippov | fba9110 | 2014-01-31 09:41:04 +0400 | [diff] [blame] | 1001 | .get_link = ethtool_op_get_link, |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 1002 | .get_ringparam = ethoc_get_ringparam, |
| 1003 | .set_ringparam = ethoc_set_ringparam, |
Max Filippov | fba9110 | 2014-01-31 09:41:04 +0400 | [diff] [blame] | 1004 | .get_ts_info = ethtool_op_get_ts_info, |
Philippe Reynes | 87e544b | 2016-07-15 09:59:12 +0200 | [diff] [blame] | 1005 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 1006 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Max Filippov | fba9110 | 2014-01-31 09:41:04 +0400 | [diff] [blame] | 1007 | }; |
| 1008 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1009 | static const struct net_device_ops ethoc_netdev_ops = { |
| 1010 | .ndo_open = ethoc_open, |
| 1011 | .ndo_stop = ethoc_stop, |
Arnd Bergmann | a760537 | 2021-07-27 15:45:13 +0200 | [diff] [blame] | 1012 | .ndo_eth_ioctl = ethoc_ioctl, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1013 | .ndo_set_mac_address = ethoc_set_mac_address, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1014 | .ndo_set_rx_mode = ethoc_set_multicast_list, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1015 | .ndo_change_mtu = ethoc_change_mtu, |
| 1016 | .ndo_tx_timeout = ethoc_tx_timeout, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1017 | .ndo_start_xmit = ethoc_start_xmit, |
| 1018 | }; |
| 1019 | |
| 1020 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 1021 | * ethoc_probe - initialize OpenCores ethernet MAC |
Jesse Brandeburg | d0ea5cb | 2020-09-25 15:24:45 -0700 | [diff] [blame] | 1022 | * @pdev: platform device |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1023 | */ |
Bill Pemberton | a0a4efe | 2012-12-03 09:24:09 -0500 | [diff] [blame] | 1024 | static int ethoc_probe(struct platform_device *pdev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1025 | { |
| 1026 | struct net_device *netdev = NULL; |
| 1027 | struct resource *res = NULL; |
| 1028 | struct resource *mmio = NULL; |
| 1029 | struct resource *mem = NULL; |
| 1030 | struct ethoc *priv = NULL; |
Jonas Bonn | c527f81 | 2010-06-11 02:47:34 +0000 | [diff] [blame] | 1031 | int num_bd; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1032 | int ret = 0; |
Max Filippov | a13aff0 | 2014-02-04 03:33:10 +0400 | [diff] [blame] | 1033 | struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
| 1034 | u32 eth_clkfreq = pdata ? pdata->eth_clkfreq : 0; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1035 | |
| 1036 | /* allocate networking device */ |
| 1037 | netdev = alloc_etherdev(sizeof(struct ethoc)); |
| 1038 | if (!netdev) { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1039 | ret = -ENOMEM; |
| 1040 | goto out; |
| 1041 | } |
| 1042 | |
| 1043 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1044 | platform_set_drvdata(pdev, netdev); |
| 1045 | |
| 1046 | /* obtain I/O memory space */ |
| 1047 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1048 | if (!res) { |
| 1049 | dev_err(&pdev->dev, "cannot obtain I/O memory space\n"); |
| 1050 | ret = -ENXIO; |
| 1051 | goto free; |
| 1052 | } |
| 1053 | |
| 1054 | mmio = devm_request_mem_region(&pdev->dev, res->start, |
Tobias Klauser | d864584 | 2010-01-15 01:48:22 -0800 | [diff] [blame] | 1055 | resource_size(res), res->name); |
Julia Lawall | 463889e | 2009-07-27 06:13:30 +0000 | [diff] [blame] | 1056 | if (!mmio) { |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1057 | dev_err(&pdev->dev, "cannot request I/O memory space\n"); |
| 1058 | ret = -ENXIO; |
| 1059 | goto free; |
| 1060 | } |
| 1061 | |
| 1062 | netdev->base_addr = mmio->start; |
| 1063 | |
| 1064 | /* obtain buffer memory space */ |
| 1065 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1066 | if (res) { |
| 1067 | mem = devm_request_mem_region(&pdev->dev, res->start, |
Tobias Klauser | d864584 | 2010-01-15 01:48:22 -0800 | [diff] [blame] | 1068 | resource_size(res), res->name); |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1069 | if (!mem) { |
| 1070 | dev_err(&pdev->dev, "cannot request memory space\n"); |
| 1071 | ret = -ENXIO; |
| 1072 | goto free; |
| 1073 | } |
| 1074 | |
| 1075 | netdev->mem_start = mem->start; |
| 1076 | netdev->mem_end = mem->end; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1079 | |
| 1080 | /* obtain device IRQ number */ |
Lad Prabhakar | 6c119fbd | 2021-12-24 19:26:22 +0000 | [diff] [blame] | 1081 | ret = platform_get_irq(pdev, 0); |
| 1082 | if (ret < 0) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1083 | goto free; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1084 | |
Lad Prabhakar | 6c119fbd | 2021-12-24 19:26:22 +0000 | [diff] [blame] | 1085 | netdev->irq = ret; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1086 | |
| 1087 | /* setup driver-private data */ |
| 1088 | priv = netdev_priv(netdev); |
| 1089 | priv->netdev = netdev; |
| 1090 | |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 1091 | priv->iobase = devm_ioremap(&pdev->dev, netdev->base_addr, |
Tobias Klauser | d864584 | 2010-01-15 01:48:22 -0800 | [diff] [blame] | 1092 | resource_size(mmio)); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1093 | if (!priv->iobase) { |
| 1094 | dev_err(&pdev->dev, "cannot remap I/O memory space\n"); |
| 1095 | ret = -ENXIO; |
Florian Fainelli | 386512d | 2016-07-12 16:04:35 -0700 | [diff] [blame] | 1096 | goto free; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1099 | if (netdev->mem_end) { |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 1100 | priv->membase = devm_ioremap(&pdev->dev, |
Tobias Klauser | d864584 | 2010-01-15 01:48:22 -0800 | [diff] [blame] | 1101 | netdev->mem_start, resource_size(mem)); |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1102 | if (!priv->membase) { |
| 1103 | dev_err(&pdev->dev, "cannot remap memory space\n"); |
| 1104 | ret = -ENXIO; |
Florian Fainelli | 386512d | 2016-07-12 16:04:35 -0700 | [diff] [blame] | 1105 | goto free; |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } else { |
| 1108 | /* Allocate buffer memory */ |
Jonas Bonn | a71fba9 | 2010-06-11 02:47:40 +0000 | [diff] [blame] | 1109 | priv->membase = dmam_alloc_coherent(&pdev->dev, |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1110 | buffer_size, (void *)&netdev->mem_start, |
| 1111 | GFP_KERNEL); |
| 1112 | if (!priv->membase) { |
| 1113 | dev_err(&pdev->dev, "cannot allocate %dB buffer\n", |
| 1114 | buffer_size); |
| 1115 | ret = -ENOMEM; |
Florian Fainelli | 386512d | 2016-07-12 16:04:35 -0700 | [diff] [blame] | 1116 | goto free; |
Thomas Chou | 0baa080 | 2009-10-04 23:33:20 +0000 | [diff] [blame] | 1117 | } |
| 1118 | netdev->mem_end = netdev->mem_start + buffer_size; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Max Filippov | 06e60e59 | 2015-09-22 14:27:16 +0300 | [diff] [blame] | 1121 | priv->big_endian = pdata ? pdata->big_endian : |
| 1122 | of_device_is_big_endian(pdev->dev.of_node); |
| 1123 | |
Jonas Bonn | c527f81 | 2010-06-11 02:47:34 +0000 | [diff] [blame] | 1124 | /* calculate the number of TX/RX buffers, maximum 128 supported */ |
| 1125 | num_bd = min_t(unsigned int, |
| 1126 | 128, (netdev->mem_end - netdev->mem_start + 1) / ETHOC_BUFSIZ); |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 1127 | if (num_bd < 4) { |
| 1128 | ret = -ENODEV; |
Florian Fainelli | 386512d | 2016-07-12 16:04:35 -0700 | [diff] [blame] | 1129 | goto free; |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 1130 | } |
Max Filippov | bee7bac | 2014-01-31 09:41:07 +0400 | [diff] [blame] | 1131 | priv->num_bd = num_bd; |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 1132 | /* num_tx must be a power of two */ |
| 1133 | priv->num_tx = rounddown_pow_of_two(num_bd >> 1); |
Jonas Bonn | c527f81 | 2010-06-11 02:47:34 +0000 | [diff] [blame] | 1134 | priv->num_rx = num_bd - priv->num_tx; |
| 1135 | |
Jonas Bonn | 6a63262 | 2010-11-25 02:30:32 +0000 | [diff] [blame] | 1136 | dev_dbg(&pdev->dev, "ethoc: num_tx: %d num_rx: %d\n", |
| 1137 | priv->num_tx, priv->num_rx); |
| 1138 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1139 | priv->vma = devm_kcalloc(&pdev->dev, num_bd, sizeof(void *), |
| 1140 | GFP_KERNEL); |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 1141 | if (!priv->vma) { |
| 1142 | ret = -ENOMEM; |
Florian Fainelli | 386512d | 2016-07-12 16:04:35 -0700 | [diff] [blame] | 1143 | goto free; |
Jonas Bonn | f8555ad0 | 2010-06-11 02:47:35 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1146 | /* Allow the platform setup code to pass in a MAC address. */ |
Max Filippov | a13aff0 | 2014-02-04 03:33:10 +0400 | [diff] [blame] | 1147 | if (pdata) { |
Jakub Kicinski | f3956eb | 2021-10-01 14:32:23 -0700 | [diff] [blame] | 1148 | eth_hw_addr_set(netdev, pdata->hwaddr); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1149 | priv->phy_id = pdata->phy_id; |
Jonas Bonn | e0f4258 | 2010-11-25 02:30:25 +0000 | [diff] [blame] | 1150 | } else { |
Jakub Kicinski | 9ca01b2 | 2021-10-06 18:06:56 -0700 | [diff] [blame] | 1151 | of_get_ethdev_address(pdev->dev.of_node, netdev); |
Tobias Klauser | 444c5f9 | 2015-09-09 11:24:29 +0200 | [diff] [blame] | 1152 | priv->phy_id = -1; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /* Check that the given MAC address is valid. If it isn't, read the |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 1156 | * current MAC from the controller. |
| 1157 | */ |
Jakub Kicinski | 4abd7cf | 2021-10-15 14:53:04 -0700 | [diff] [blame] | 1158 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
| 1159 | u8 addr[ETH_ALEN]; |
| 1160 | |
| 1161 | ethoc_get_mac_address(netdev, addr); |
| 1162 | eth_hw_addr_set(netdev, addr); |
| 1163 | } |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* Check the MAC again for validity, if it still isn't choose and |
Barry Grussling | 72aa8e1 | 2013-01-27 18:44:36 +0000 | [diff] [blame] | 1166 | * program a random one. |
| 1167 | */ |
Tobias Klauser | 6d6a505 | 2017-02-16 13:54:32 +0100 | [diff] [blame] | 1168 | if (!is_valid_ether_addr(netdev->dev_addr)) |
| 1169 | eth_hw_addr_random(netdev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1170 | |
Jiri Pirko | efc61a3 | 2013-01-06 03:25:45 +0000 | [diff] [blame] | 1171 | ethoc_do_set_mac_address(netdev); |
Danny Kukawka | 939d225 | 2012-02-17 05:43:29 +0000 | [diff] [blame] | 1172 | |
Max Filippov | a13aff0 | 2014-02-04 03:33:10 +0400 | [diff] [blame] | 1173 | /* Allow the platform setup code to adjust MII management bus clock. */ |
| 1174 | if (!eth_clkfreq) { |
| 1175 | struct clk *clk = devm_clk_get(&pdev->dev, NULL); |
| 1176 | |
| 1177 | if (!IS_ERR(clk)) { |
| 1178 | priv->clk = clk; |
| 1179 | clk_prepare_enable(clk); |
| 1180 | eth_clkfreq = clk_get_rate(clk); |
| 1181 | } |
| 1182 | } |
| 1183 | if (eth_clkfreq) { |
| 1184 | u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1); |
| 1185 | |
| 1186 | if (!clkdiv) |
| 1187 | clkdiv = 2; |
| 1188 | dev_dbg(&pdev->dev, "setting MII clkdiv to %u\n", clkdiv); |
| 1189 | ethoc_write(priv, MIIMODER, |
| 1190 | (ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE) | |
| 1191 | clkdiv); |
| 1192 | } |
| 1193 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1194 | /* register MII bus */ |
| 1195 | priv->mdio = mdiobus_alloc(); |
| 1196 | if (!priv->mdio) { |
| 1197 | ret = -ENOMEM; |
Colin Ian King | bfa49cf | 2016-06-01 14:16:50 +0100 | [diff] [blame] | 1198 | goto free2; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | priv->mdio->name = "ethoc-mdio"; |
| 1202 | snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "%s-%d", |
| 1203 | priv->mdio->name, pdev->id); |
| 1204 | priv->mdio->read = ethoc_mdio_read; |
| 1205 | priv->mdio->write = ethoc_mdio_write; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1206 | priv->mdio->priv = priv; |
| 1207 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1208 | ret = mdiobus_register(priv->mdio); |
| 1209 | if (ret) { |
| 1210 | dev_err(&netdev->dev, "failed to register MDIO bus\n"); |
Dinghao Liu | 5d41f9b | 2020-12-23 19:06:12 +0800 | [diff] [blame] | 1211 | goto free3; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | ret = ethoc_mdio_probe(netdev); |
| 1215 | if (ret) { |
| 1216 | dev_err(&netdev->dev, "failed to probe MDIO bus\n"); |
| 1217 | goto error; |
| 1218 | } |
| 1219 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1220 | /* setup the net_device structure */ |
| 1221 | netdev->netdev_ops = ðoc_netdev_ops; |
| 1222 | netdev->watchdog_timeo = ETHOC_TIMEOUT; |
| 1223 | netdev->features |= 0; |
Max Filippov | fba9110 | 2014-01-31 09:41:04 +0400 | [diff] [blame] | 1224 | netdev->ethtool_ops = ðoc_ethtool_ops; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1225 | |
| 1226 | /* setup NAPI */ |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1227 | netif_napi_add(netdev, &priv->napi, ethoc_poll, 64); |
| 1228 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1229 | spin_lock_init(&priv->lock); |
| 1230 | |
| 1231 | ret = register_netdev(netdev); |
| 1232 | if (ret < 0) { |
| 1233 | dev_err(&netdev->dev, "failed to register interface\n"); |
Thomas Chou | ee02a4e | 2010-05-23 16:44:02 +0000 | [diff] [blame] | 1234 | goto error2; |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | goto out; |
| 1238 | |
Thomas Chou | ee02a4e | 2010-05-23 16:44:02 +0000 | [diff] [blame] | 1239 | error2: |
| 1240 | netif_napi_del(&priv->napi); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1241 | error: |
| 1242 | mdiobus_unregister(priv->mdio); |
Dinghao Liu | 5d41f9b | 2020-12-23 19:06:12 +0800 | [diff] [blame] | 1243 | free3: |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1244 | mdiobus_free(priv->mdio); |
Colin Ian King | bfa49cf | 2016-06-01 14:16:50 +0100 | [diff] [blame] | 1245 | free2: |
YueHaibing | 76e597e | 2018-05-16 19:18:22 +0800 | [diff] [blame] | 1246 | clk_disable_unprepare(priv->clk); |
Colin Ian King | bfa49cf | 2016-06-01 14:16:50 +0100 | [diff] [blame] | 1247 | free: |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1248 | free_netdev(netdev); |
| 1249 | out: |
| 1250 | return ret; |
| 1251 | } |
| 1252 | |
| 1253 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 1254 | * ethoc_remove - shutdown OpenCores ethernet MAC |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1255 | * @pdev: platform device |
| 1256 | */ |
Bill Pemberton | a0a4efe | 2012-12-03 09:24:09 -0500 | [diff] [blame] | 1257 | static int ethoc_remove(struct platform_device *pdev) |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1258 | { |
| 1259 | struct net_device *netdev = platform_get_drvdata(pdev); |
| 1260 | struct ethoc *priv = netdev_priv(netdev); |
| 1261 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1262 | if (netdev) { |
Thomas Chou | ee02a4e | 2010-05-23 16:44:02 +0000 | [diff] [blame] | 1263 | netif_napi_del(&priv->napi); |
Philippe Reynes | 11331fc | 2016-07-15 09:59:11 +0200 | [diff] [blame] | 1264 | phy_disconnect(netdev->phydev); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1265 | |
| 1266 | if (priv->mdio) { |
| 1267 | mdiobus_unregister(priv->mdio); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1268 | mdiobus_free(priv->mdio); |
| 1269 | } |
YueHaibing | 76e597e | 2018-05-16 19:18:22 +0800 | [diff] [blame] | 1270 | clk_disable_unprepare(priv->clk); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1271 | unregister_netdev(netdev); |
| 1272 | free_netdev(netdev); |
| 1273 | } |
| 1274 | |
| 1275 | return 0; |
| 1276 | } |
| 1277 | |
| 1278 | #ifdef CONFIG_PM |
| 1279 | static int ethoc_suspend(struct platform_device *pdev, pm_message_t state) |
| 1280 | { |
| 1281 | return -ENOSYS; |
| 1282 | } |
| 1283 | |
| 1284 | static int ethoc_resume(struct platform_device *pdev) |
| 1285 | { |
| 1286 | return -ENOSYS; |
| 1287 | } |
| 1288 | #else |
| 1289 | # define ethoc_suspend NULL |
| 1290 | # define ethoc_resume NULL |
| 1291 | #endif |
| 1292 | |
Fabian Frederick | fa2b183 | 2015-03-17 19:37:35 +0100 | [diff] [blame] | 1293 | static const struct of_device_id ethoc_match[] = { |
Grant Likely | c9e358d | 2011-01-21 09:24:48 -0700 | [diff] [blame] | 1294 | { .compatible = "opencores,ethoc", }, |
Jonas Bonn | e0f4258 | 2010-11-25 02:30:25 +0000 | [diff] [blame] | 1295 | {}, |
| 1296 | }; |
| 1297 | MODULE_DEVICE_TABLE(of, ethoc_match); |
Jonas Bonn | e0f4258 | 2010-11-25 02:30:25 +0000 | [diff] [blame] | 1298 | |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1299 | static struct platform_driver ethoc_driver = { |
| 1300 | .probe = ethoc_probe, |
Bill Pemberton | a0a4efe | 2012-12-03 09:24:09 -0500 | [diff] [blame] | 1301 | .remove = ethoc_remove, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1302 | .suspend = ethoc_suspend, |
| 1303 | .resume = ethoc_resume, |
| 1304 | .driver = { |
| 1305 | .name = "ethoc", |
Jonas Bonn | e0f4258 | 2010-11-25 02:30:25 +0000 | [diff] [blame] | 1306 | .of_match_table = ethoc_match, |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1307 | }, |
| 1308 | }; |
| 1309 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 1310 | module_platform_driver(ethoc_driver); |
Thierry Reding | a170285 | 2009-03-27 00:12:24 -0700 | [diff] [blame] | 1311 | |
| 1312 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); |
| 1313 | MODULE_DESCRIPTION("OpenCores Ethernet MAC driver"); |
| 1314 | MODULE_LICENSE("GPL v2"); |
| 1315 | |