Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx. |
| 3 | * Copyright (c) 1997 Dan Malek (dmalek@jlc.net) |
| 4 | * |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 5 | * Right now, I am very wasteful with the buffers. I allocate memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * pages and then divide them into 2K frame buffers. This way I know I |
| 7 | * have buffers large enough to hold one frame within one buffer descriptor. |
| 8 | * Once I get this working, I will use 64 or 128 byte CPM buffers, which |
| 9 | * will be much more memory efficient and will easily handle lots of |
| 10 | * small packets. |
| 11 | * |
| 12 | * Much better multiple PHY support by Magnus Damm. |
| 13 | * Copyright (c) 2000 Ericsson Radio Systems AB. |
| 14 | * |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 15 | * Support for FEC controller of ColdFire processors. |
| 16 | * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 17 | * |
| 18 | * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be) |
Philippe De Muyter | 677177c | 2006-06-27 13:05:33 +1000 | [diff] [blame] | 19 | * Copyright (c) 2004-2006 Macq Electronique SA. |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 20 | * |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 21 | * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/ptrace.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/delay.h> |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/skbuff.h> |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 36 | #include <linux/in.h> |
| 37 | #include <linux/ip.h> |
| 38 | #include <net/ip.h> |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 39 | #include <net/tso.h> |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 40 | #include <linux/tcp.h> |
| 41 | #include <linux/udp.h> |
| 42 | #include <linux/icmp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/spinlock.h> |
| 44 | #include <linux/workqueue.h> |
| 45 | #include <linux/bitops.h> |
Sascha Hauer | 6f501b1 | 2009-01-28 23:03:05 +0000 | [diff] [blame] | 46 | #include <linux/io.h> |
| 47 | #include <linux/irq.h> |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 48 | #include <linux/clk.h> |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 49 | #include <linux/platform_device.h> |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 50 | #include <linux/phy.h> |
Baruch Siach | 5eb32bd | 2010-05-24 00:36:13 -0700 | [diff] [blame] | 51 | #include <linux/fec.h> |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 52 | #include <linux/of.h> |
| 53 | #include <linux/of_device.h> |
| 54 | #include <linux/of_gpio.h> |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 55 | #include <linux/of_mdio.h> |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 56 | #include <linux/of_net.h> |
Shawn Guo | 5fa9c0f | 2012-06-27 03:45:21 +0000 | [diff] [blame] | 57 | #include <linux/regulator/consumer.h> |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 58 | #include <linux/if_vlan.h> |
Fabio Estevam | a68ab98 | 2014-06-02 15:44:30 -0300 | [diff] [blame] | 59 | #include <linux/pinctrl/consumer.h> |
Frank Li | c259c13 | 2014-10-03 14:29:14 -0700 | [diff] [blame] | 60 | #include <linux/prefetch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Greg Ungerer | 080853a | 2007-07-30 16:28:46 +1000 | [diff] [blame] | 62 | #include <asm/cacheflush.h> |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include "fec.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Christoph Müllner | 772e42b | 2013-06-27 21:18:23 +0200 | [diff] [blame] | 66 | static void set_multicast_list(struct net_device *ndev); |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 67 | static void fec_enet_itr_coal_init(struct net_device *ndev); |
Christoph Müllner | 772e42b | 2013-06-27 21:18:23 +0200 | [diff] [blame] | 68 | |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 69 | #define DRIVER_NAME "fec" |
| 70 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 71 | #define FEC_ENET_GET_QUQUE(_x) ((_x == 0) ? 1 : ((_x == 1) ? 2 : 0)) |
| 72 | |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 73 | /* Pause frame feild and FIFO threshold */ |
| 74 | #define FEC_ENET_FCE (1 << 5) |
| 75 | #define FEC_ENET_RSEM_V 0x84 |
| 76 | #define FEC_ENET_RSFL_V 16 |
| 77 | #define FEC_ENET_RAEM_V 0x8 |
| 78 | #define FEC_ENET_RAFL_V 0x8 |
| 79 | #define FEC_ENET_OPD_V 0xFFF0 |
| 80 | |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 81 | static struct platform_device_id fec_devtype[] = { |
| 82 | { |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 83 | /* keep it for coldfire */ |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 84 | .name = DRIVER_NAME, |
| 85 | .driver_data = 0, |
| 86 | }, { |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 87 | .name = "imx25-fec", |
| 88 | .driver_data = FEC_QUIRK_USE_GASKET, |
| 89 | }, { |
| 90 | .name = "imx27-fec", |
| 91 | .driver_data = 0, |
| 92 | }, { |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 93 | .name = "imx28-fec", |
| 94 | .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME, |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 95 | }, { |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 96 | .name = "imx6q-fec", |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 97 | .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT | |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 98 | FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM | |
Frank Li | 0319165 | 2013-07-25 14:05:53 +0800 | [diff] [blame] | 99 | FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR006358, |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 100 | }, { |
Shawn Guo | 3680354 | 2013-05-19 04:38:46 +0000 | [diff] [blame] | 101 | .name = "mvf600-fec", |
Jingchang Lu | ca7c4a4 | 2013-04-11 21:12:45 +0000 | [diff] [blame] | 102 | .driver_data = FEC_QUIRK_ENET_MAC, |
| 103 | }, { |
Fugang Duan | 95a7747 | 2014-09-13 05:00:47 +0800 | [diff] [blame] | 104 | .name = "imx6sx-fec", |
| 105 | .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT | |
| 106 | FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM | |
Nimrod Andy | f88c7ed | 2014-09-23 15:40:56 +0800 | [diff] [blame] | 107 | FEC_QUIRK_HAS_VLAN | FEC_QUIRK_HAS_AVB | |
Nimrod Andy | 28b5f05 | 2014-10-15 17:30:12 +0800 | [diff] [blame] | 108 | FEC_QUIRK_ERR007885 | FEC_QUIRK_BUG_CAPTURE, |
Fugang Duan | 95a7747 | 2014-09-13 05:00:47 +0800 | [diff] [blame] | 109 | }, { |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 110 | /* sentinel */ |
| 111 | } |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 112 | }; |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 113 | MODULE_DEVICE_TABLE(platform, fec_devtype); |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 114 | |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 115 | enum imx_fec_type { |
Lothar Waßmann | a7dd321 | 2011-12-07 21:59:25 +0000 | [diff] [blame] | 116 | IMX25_FEC = 1, /* runs on i.mx25/50/53 */ |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 117 | IMX27_FEC, /* runs on i.mx27/35/51 */ |
| 118 | IMX28_FEC, |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 119 | IMX6Q_FEC, |
Shawn Guo | 3680354 | 2013-05-19 04:38:46 +0000 | [diff] [blame] | 120 | MVF600_FEC, |
Fugang Duan | ba593e0 | 2014-09-13 05:00:53 +0800 | [diff] [blame] | 121 | IMX6SX_FEC, |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | static const struct of_device_id fec_dt_ids[] = { |
| 125 | { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], }, |
| 126 | { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], }, |
| 127 | { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], }, |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 128 | { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], }, |
Shawn Guo | 3680354 | 2013-05-19 04:38:46 +0000 | [diff] [blame] | 129 | { .compatible = "fsl,mvf600-fec", .data = &fec_devtype[MVF600_FEC], }, |
Fugang Duan | ba593e0 | 2014-09-13 05:00:53 +0800 | [diff] [blame] | 130 | { .compatible = "fsl,imx6sx-fec", .data = &fec_devtype[IMX6SX_FEC], }, |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 131 | { /* sentinel */ } |
| 132 | }; |
| 133 | MODULE_DEVICE_TABLE(of, fec_dt_ids); |
| 134 | |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 135 | static unsigned char macaddr[ETH_ALEN]; |
| 136 | module_param_array(macaddr, byte, NULL, 0); |
| 137 | MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); |
| 138 | |
Greg Ungerer | 87f4abb | 2008-06-06 15:55:36 +1000 | [diff] [blame] | 139 | #if defined(CONFIG_M5272) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* |
| 141 | * Some hardware gets it MAC address out of local flash memory. |
| 142 | * if this is non-zero then assume it is the address to get MAC from. |
| 143 | */ |
| 144 | #if defined(CONFIG_NETtel) |
| 145 | #define FEC_FLASHMAC 0xf0006006 |
| 146 | #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES) |
| 147 | #define FEC_FLASHMAC 0xf0006000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #elif defined(CONFIG_CANCam) |
| 149 | #define FEC_FLASHMAC 0xf0020000 |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 150 | #elif defined (CONFIG_M5272C3) |
| 151 | #define FEC_FLASHMAC (0xffe04000 + 4) |
| 152 | #elif defined(CONFIG_MOD5272) |
Lothar Waßmann | a7dd321 | 2011-12-07 21:59:25 +0000 | [diff] [blame] | 153 | #define FEC_FLASHMAC 0xffc0406b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #else |
| 155 | #define FEC_FLASHMAC 0 |
| 156 | #endif |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 157 | #endif /* CONFIG_M5272 */ |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 158 | |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 159 | /* The FEC stores dest/src/type/vlan, data, and checksum for receive packets. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | */ |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 161 | #define PKT_MAXBUF_SIZE 1522 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | #define PKT_MINBUF_SIZE 64 |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 163 | #define PKT_MAXBLR_SIZE 1536 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 165 | /* FEC receive acceleration */ |
| 166 | #define FEC_RACC_IPDIS (1 << 1) |
| 167 | #define FEC_RACC_PRODIS (1 << 2) |
| 168 | #define FEC_RACC_OPTIONS (FEC_RACC_IPDIS | FEC_RACC_PRODIS) |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* |
Matt Waddel | 6b26529 | 2006-06-27 13:10:56 +1000 | [diff] [blame] | 171 | * The 5270/5271/5280/5282/532x RX control register also contains maximum frame |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | * size bits. Other FEC hardware does not, so we need to take that into |
| 173 | * account when setting it. |
| 174 | */ |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 175 | #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ |
Uwe Kleine-König | 085e79e | 2011-01-17 09:52:18 +0100 | [diff] [blame] | 176 | defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) |
| 178 | #else |
| 179 | #define OPT_FRAME_SIZE 0 |
| 180 | #endif |
| 181 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 182 | /* FEC MII MMFR bits definition */ |
| 183 | #define FEC_MMFR_ST (1 << 30) |
| 184 | #define FEC_MMFR_OP_READ (2 << 28) |
| 185 | #define FEC_MMFR_OP_WRITE (1 << 28) |
| 186 | #define FEC_MMFR_PA(v) ((v & 0x1f) << 23) |
| 187 | #define FEC_MMFR_RA(v) ((v & 0x1f) << 18) |
| 188 | #define FEC_MMFR_TA (2 << 16) |
| 189 | #define FEC_MMFR_DATA(v) (v & 0xffff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Rogerio Pimentel | c3b084c | 2011-12-27 14:07:37 -0500 | [diff] [blame] | 191 | #define FEC_MII_TIMEOUT 30000 /* us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 193 | /* Transmitter timeout */ |
| 194 | #define TX_TIMEOUT (2 * HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 196 | #define FEC_PAUSE_FLAG_AUTONEG 0x1 |
| 197 | #define FEC_PAUSE_FLAG_ENABLE 0x2 |
| 198 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 199 | #define COPYBREAK_DEFAULT 256 |
| 200 | |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 201 | #define TSO_HEADER_SIZE 128 |
| 202 | /* Max number of allowed TCP segments for software TSO */ |
| 203 | #define FEC_MAX_TSO_SEGS 100 |
| 204 | #define FEC_MAX_SKB_DESCS (FEC_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS) |
| 205 | |
| 206 | #define IS_TSO_HEADER(txq, addr) \ |
| 207 | ((addr >= txq->tso_hdrs_dma) && \ |
| 208 | (addr < txq->tso_hdrs_dma + txq->tx_ring_size * TSO_HEADER_SIZE)) |
| 209 | |
Lothar Waßmann | e163cc9 | 2011-12-07 21:59:31 +0000 | [diff] [blame] | 210 | static int mii_cnt; |
| 211 | |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 212 | static inline |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 213 | struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp, |
| 214 | struct fec_enet_private *fep, |
| 215 | int queue_id) |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 216 | { |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 217 | struct bufdesc *new_bd = bdp + 1; |
| 218 | struct bufdesc_ex *ex_new_bd = (struct bufdesc_ex *)bdp + 1; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 219 | struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue_id]; |
| 220 | struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue_id]; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 221 | struct bufdesc_ex *ex_base; |
| 222 | struct bufdesc *base; |
| 223 | int ring_size; |
| 224 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 225 | if (bdp >= txq->tx_bd_base) { |
| 226 | base = txq->tx_bd_base; |
| 227 | ring_size = txq->tx_ring_size; |
| 228 | ex_base = (struct bufdesc_ex *)txq->tx_bd_base; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 229 | } else { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 230 | base = rxq->rx_bd_base; |
| 231 | ring_size = rxq->rx_ring_size; |
| 232 | ex_base = (struct bufdesc_ex *)rxq->rx_bd_base; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | if (fep->bufdesc_ex) |
| 236 | return (struct bufdesc *)((ex_new_bd >= (ex_base + ring_size)) ? |
| 237 | ex_base : ex_new_bd); |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 238 | else |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 239 | return (new_bd >= (base + ring_size)) ? |
| 240 | base : new_bd; |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 243 | static inline |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 244 | struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp, |
| 245 | struct fec_enet_private *fep, |
| 246 | int queue_id) |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 247 | { |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 248 | struct bufdesc *new_bd = bdp - 1; |
| 249 | struct bufdesc_ex *ex_new_bd = (struct bufdesc_ex *)bdp - 1; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 250 | struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue_id]; |
| 251 | struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue_id]; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 252 | struct bufdesc_ex *ex_base; |
| 253 | struct bufdesc *base; |
| 254 | int ring_size; |
| 255 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 256 | if (bdp >= txq->tx_bd_base) { |
| 257 | base = txq->tx_bd_base; |
| 258 | ring_size = txq->tx_ring_size; |
| 259 | ex_base = (struct bufdesc_ex *)txq->tx_bd_base; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 260 | } else { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 261 | base = rxq->rx_bd_base; |
| 262 | ring_size = rxq->rx_ring_size; |
| 263 | ex_base = (struct bufdesc_ex *)rxq->rx_bd_base; |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (fep->bufdesc_ex) |
| 267 | return (struct bufdesc *)((ex_new_bd < ex_base) ? |
| 268 | (ex_new_bd + ring_size) : ex_new_bd); |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 269 | else |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 270 | return (new_bd < base) ? (new_bd + ring_size) : new_bd; |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Nimrod Andy | 61a4427 | 2014-06-12 08:16:18 +0800 | [diff] [blame] | 273 | static int fec_enet_get_bd_index(struct bufdesc *base, struct bufdesc *bdp, |
| 274 | struct fec_enet_private *fep) |
| 275 | { |
| 276 | return ((const char *)bdp - (const char *)base) / fep->bufdesc_size; |
| 277 | } |
| 278 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 279 | static int fec_enet_get_free_txdesc_num(struct fec_enet_private *fep, |
| 280 | struct fec_enet_priv_tx_q *txq) |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 281 | { |
| 282 | int entries; |
| 283 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 284 | entries = ((const char *)txq->dirty_tx - |
| 285 | (const char *)txq->cur_tx) / fep->bufdesc_size - 1; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 286 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 287 | return entries > 0 ? entries : entries + txq->tx_ring_size; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 288 | } |
| 289 | |
Lothar Waßmann | c20e599 | 2014-11-17 10:51:24 +0100 | [diff] [blame^] | 290 | static void swap_buffer(void *bufaddr, int len) |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 291 | { |
| 292 | int i; |
| 293 | unsigned int *buf = bufaddr; |
| 294 | |
Lothar Waßmann | 7b487d0 | 2014-11-17 10:51:23 +0100 | [diff] [blame] | 295 | for (i = 0; i < len; i += 4, buf++) |
Lothar Waßmann | e453789 | 2014-11-17 10:51:22 +0100 | [diff] [blame] | 296 | swab32s(buf); |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Lothar Waßmann | 1310b54 | 2014-11-07 10:02:47 +0100 | [diff] [blame] | 299 | static void swap_buffer2(void *dst_buf, void *src_buf, int len) |
| 300 | { |
| 301 | int i; |
| 302 | unsigned int *src = src_buf; |
| 303 | unsigned int *dst = dst_buf; |
| 304 | |
| 305 | for (i = 0; i < len; i += 4, src++, dst++) |
| 306 | *dst = swab32p(src); |
| 307 | } |
| 308 | |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 309 | static void fec_dump(struct net_device *ndev) |
| 310 | { |
| 311 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 312 | struct bufdesc *bdp; |
| 313 | struct fec_enet_priv_tx_q *txq; |
| 314 | int index = 0; |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 315 | |
| 316 | netdev_info(ndev, "TX ring dump\n"); |
| 317 | pr_info("Nr SC addr len SKB\n"); |
| 318 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 319 | txq = fep->tx_queue[0]; |
| 320 | bdp = txq->tx_bd_base; |
| 321 | |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 322 | do { |
| 323 | pr_info("%3u %c%c 0x%04x 0x%08lx %4u %p\n", |
| 324 | index, |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 325 | bdp == txq->cur_tx ? 'S' : ' ', |
| 326 | bdp == txq->dirty_tx ? 'H' : ' ', |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 327 | bdp->cbd_sc, bdp->cbd_bufaddr, bdp->cbd_datlen, |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 328 | txq->tx_skbuff[index]); |
| 329 | bdp = fec_enet_get_nextdesc(bdp, fep, 0); |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 330 | index++; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 331 | } while (bdp != txq->tx_bd_base); |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Fugang Duan | 62a02c9 | 2014-06-18 08:33:52 +0800 | [diff] [blame] | 334 | static inline bool is_ipv4_pkt(struct sk_buff *skb) |
| 335 | { |
| 336 | return skb->protocol == htons(ETH_P_IP) && ip_hdr(skb)->version == 4; |
| 337 | } |
| 338 | |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 339 | static int |
| 340 | fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev) |
| 341 | { |
| 342 | /* Only run for packets requiring a checksum. */ |
| 343 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 344 | return 0; |
| 345 | |
| 346 | if (unlikely(skb_cow_head(skb, 0))) |
| 347 | return -1; |
| 348 | |
Fugang Duan | 62a02c9 | 2014-06-18 08:33:52 +0800 | [diff] [blame] | 349 | if (is_ipv4_pkt(skb)) |
| 350 | ip_hdr(skb)->check = 0; |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 351 | *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0; |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 356 | static int |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 357 | fec_enet_txq_submit_frag_skb(struct fec_enet_priv_tx_q *txq, |
| 358 | struct sk_buff *skb, |
| 359 | struct net_device *ndev) |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 360 | { |
| 361 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 362 | struct bufdesc *bdp = txq->cur_tx; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 363 | struct bufdesc_ex *ebdp; |
| 364 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 365 | unsigned short queue = skb_get_queue_mapping(skb); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 366 | int frag, frag_len; |
| 367 | unsigned short status; |
| 368 | unsigned int estatus = 0; |
| 369 | skb_frag_t *this_frag; |
| 370 | unsigned int index; |
| 371 | void *bufaddr; |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 372 | dma_addr_t addr; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 373 | int i; |
| 374 | |
| 375 | for (frag = 0; frag < nr_frags; frag++) { |
| 376 | this_frag = &skb_shinfo(skb)->frags[frag]; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 377 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 378 | ebdp = (struct bufdesc_ex *)bdp; |
| 379 | |
| 380 | status = bdp->cbd_sc; |
| 381 | status &= ~BD_ENET_TX_STATS; |
| 382 | status |= (BD_ENET_TX_TC | BD_ENET_TX_READY); |
| 383 | frag_len = skb_shinfo(skb)->frags[frag].size; |
| 384 | |
| 385 | /* Handle the last BD specially */ |
| 386 | if (frag == nr_frags - 1) { |
| 387 | status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST); |
| 388 | if (fep->bufdesc_ex) { |
| 389 | estatus |= BD_ENET_TX_INT; |
| 390 | if (unlikely(skb_shinfo(skb)->tx_flags & |
| 391 | SKBTX_HW_TSTAMP && fep->hwts_tx_en)) |
| 392 | estatus |= BD_ENET_TX_TS; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | if (fep->bufdesc_ex) { |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 397 | if (fep->quirks & FEC_QUIRK_HAS_AVB) |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 398 | estatus |= FEC_TX_BD_FTYPE(queue); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 399 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 400 | estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS; |
| 401 | ebdp->cbd_bdu = 0; |
| 402 | ebdp->cbd_esc = estatus; |
| 403 | } |
| 404 | |
| 405 | bufaddr = page_address(this_frag->page.p) + this_frag->page_offset; |
| 406 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 407 | index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep); |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 408 | if (((unsigned long) bufaddr) & fep->tx_align || |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 409 | fep->quirks & FEC_QUIRK_SWAP_FRAME) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 410 | memcpy(txq->tx_bounce[index], bufaddr, frag_len); |
| 411 | bufaddr = txq->tx_bounce[index]; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 412 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 413 | if (fep->quirks & FEC_QUIRK_SWAP_FRAME) |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 414 | swap_buffer(bufaddr, frag_len); |
| 415 | } |
| 416 | |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 417 | addr = dma_map_single(&fep->pdev->dev, bufaddr, frag_len, |
| 418 | DMA_TO_DEVICE); |
| 419 | if (dma_mapping_error(&fep->pdev->dev, addr)) { |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 420 | dev_kfree_skb_any(skb); |
| 421 | if (net_ratelimit()) |
| 422 | netdev_err(ndev, "Tx DMA memory map failed\n"); |
| 423 | goto dma_mapping_error; |
| 424 | } |
| 425 | |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 426 | bdp->cbd_bufaddr = addr; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 427 | bdp->cbd_datlen = frag_len; |
| 428 | bdp->cbd_sc = status; |
| 429 | } |
| 430 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 431 | txq->cur_tx = bdp; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 432 | |
| 433 | return 0; |
| 434 | |
| 435 | dma_mapping_error: |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 436 | bdp = txq->cur_tx; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 437 | for (i = 0; i < frag; i++) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 438 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 439 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
| 440 | bdp->cbd_datlen, DMA_TO_DEVICE); |
| 441 | } |
| 442 | return NETDEV_TX_OK; |
| 443 | } |
| 444 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 445 | static int fec_enet_txq_submit_skb(struct fec_enet_priv_tx_q *txq, |
| 446 | struct sk_buff *skb, struct net_device *ndev) |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 447 | { |
| 448 | struct fec_enet_private *fep = netdev_priv(ndev); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 449 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 450 | struct bufdesc *bdp, *last_bdp; |
| 451 | void *bufaddr; |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 452 | dma_addr_t addr; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 453 | unsigned short status; |
| 454 | unsigned short buflen; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 455 | unsigned short queue; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 456 | unsigned int estatus = 0; |
| 457 | unsigned int index; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 458 | int entries_free; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 459 | int ret; |
| 460 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 461 | entries_free = fec_enet_get_free_txdesc_num(fep, txq); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 462 | if (entries_free < MAX_SKB_FRAGS + 1) { |
| 463 | dev_kfree_skb_any(skb); |
| 464 | if (net_ratelimit()) |
| 465 | netdev_err(ndev, "NOT enough BD for SG!\n"); |
| 466 | return NETDEV_TX_OK; |
| 467 | } |
| 468 | |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 469 | /* Protocol checksum off-load for TCP and UDP. */ |
| 470 | if (fec_enet_clear_csum(skb, ndev)) { |
| 471 | dev_kfree_skb_any(skb); |
| 472 | return NETDEV_TX_OK; |
| 473 | } |
| 474 | |
| 475 | /* Fill in a Tx ring entry */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 476 | bdp = txq->cur_tx; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 477 | status = bdp->cbd_sc; |
| 478 | status &= ~BD_ENET_TX_STATS; |
| 479 | |
| 480 | /* Set buffer length and buffer pointer */ |
| 481 | bufaddr = skb->data; |
| 482 | buflen = skb_headlen(skb); |
| 483 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 484 | queue = skb_get_queue_mapping(skb); |
| 485 | index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep); |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 486 | if (((unsigned long) bufaddr) & fep->tx_align || |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 487 | fep->quirks & FEC_QUIRK_SWAP_FRAME) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 488 | memcpy(txq->tx_bounce[index], skb->data, buflen); |
| 489 | bufaddr = txq->tx_bounce[index]; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 490 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 491 | if (fep->quirks & FEC_QUIRK_SWAP_FRAME) |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 492 | swap_buffer(bufaddr, buflen); |
| 493 | } |
| 494 | |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 495 | /* Push the data cache so the CPM does not get stale memory data. */ |
| 496 | addr = dma_map_single(&fep->pdev->dev, bufaddr, buflen, DMA_TO_DEVICE); |
| 497 | if (dma_mapping_error(&fep->pdev->dev, addr)) { |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 498 | dev_kfree_skb_any(skb); |
| 499 | if (net_ratelimit()) |
| 500 | netdev_err(ndev, "Tx DMA memory map failed\n"); |
| 501 | return NETDEV_TX_OK; |
| 502 | } |
| 503 | |
| 504 | if (nr_frags) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 505 | ret = fec_enet_txq_submit_frag_skb(txq, skb, ndev); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 506 | if (ret) |
| 507 | return ret; |
| 508 | } else { |
| 509 | status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST); |
| 510 | if (fep->bufdesc_ex) { |
| 511 | estatus = BD_ENET_TX_INT; |
| 512 | if (unlikely(skb_shinfo(skb)->tx_flags & |
| 513 | SKBTX_HW_TSTAMP && fep->hwts_tx_en)) |
| 514 | estatus |= BD_ENET_TX_TS; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | if (fep->bufdesc_ex) { |
| 519 | |
| 520 | struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; |
| 521 | |
| 522 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && |
| 523 | fep->hwts_tx_en)) |
| 524 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 525 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 526 | if (fep->quirks & FEC_QUIRK_HAS_AVB) |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 527 | estatus |= FEC_TX_BD_FTYPE(queue); |
| 528 | |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 529 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 530 | estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS; |
| 531 | |
| 532 | ebdp->cbd_bdu = 0; |
| 533 | ebdp->cbd_esc = estatus; |
| 534 | } |
| 535 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 536 | last_bdp = txq->cur_tx; |
| 537 | index = fec_enet_get_bd_index(txq->tx_bd_base, last_bdp, fep); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 538 | /* Save skb pointer */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 539 | txq->tx_skbuff[index] = skb; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 540 | |
| 541 | bdp->cbd_datlen = buflen; |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 542 | bdp->cbd_bufaddr = addr; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 543 | |
| 544 | /* Send it on its way. Tell FEC it's ready, interrupt when done, |
| 545 | * it's the last BD of the frame, and to put the CRC on the end. |
| 546 | */ |
| 547 | status |= (BD_ENET_TX_READY | BD_ENET_TX_TC); |
| 548 | bdp->cbd_sc = status; |
| 549 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 550 | /* If this was the last BD in the ring, start at the beginning again. */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 551 | bdp = fec_enet_get_nextdesc(last_bdp, fep, queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Eric Dumazet | 7a2a845 | 2013-12-19 10:53:02 -0800 | [diff] [blame] | 553 | skb_tx_timestamp(skb); |
| 554 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 555 | txq->cur_tx = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 557 | /* Trigger transmission start */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 558 | writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue)); |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 559 | |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 560 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 563 | static int |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 564 | fec_enet_txq_put_data_tso(struct fec_enet_priv_tx_q *txq, struct sk_buff *skb, |
| 565 | struct net_device *ndev, |
| 566 | struct bufdesc *bdp, int index, char *data, |
| 567 | int size, bool last_tcp, bool is_last) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 568 | { |
| 569 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fabian Frederick | 61cd2eb | 2014-09-13 22:38:26 +0200 | [diff] [blame] | 570 | struct bufdesc_ex *ebdp = container_of(bdp, struct bufdesc_ex, desc); |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 571 | unsigned short queue = skb_get_queue_mapping(skb); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 572 | unsigned short status; |
| 573 | unsigned int estatus = 0; |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 574 | dma_addr_t addr; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 575 | |
| 576 | status = bdp->cbd_sc; |
| 577 | status &= ~BD_ENET_TX_STATS; |
| 578 | |
| 579 | status |= (BD_ENET_TX_TC | BD_ENET_TX_READY); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 580 | |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 581 | if (((unsigned long) data) & fep->tx_align || |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 582 | fep->quirks & FEC_QUIRK_SWAP_FRAME) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 583 | memcpy(txq->tx_bounce[index], data, size); |
| 584 | data = txq->tx_bounce[index]; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 585 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 586 | if (fep->quirks & FEC_QUIRK_SWAP_FRAME) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 587 | swap_buffer(data, size); |
| 588 | } |
| 589 | |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 590 | addr = dma_map_single(&fep->pdev->dev, data, size, DMA_TO_DEVICE); |
| 591 | if (dma_mapping_error(&fep->pdev->dev, addr)) { |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 592 | dev_kfree_skb_any(skb); |
| 593 | if (net_ratelimit()) |
| 594 | netdev_err(ndev, "Tx DMA memory map failed\n"); |
| 595 | return NETDEV_TX_BUSY; |
| 596 | } |
| 597 | |
Russell King | d6bf314 | 2014-07-08 00:23:19 +0100 | [diff] [blame] | 598 | bdp->cbd_datlen = size; |
| 599 | bdp->cbd_bufaddr = addr; |
| 600 | |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 601 | if (fep->bufdesc_ex) { |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 602 | if (fep->quirks & FEC_QUIRK_HAS_AVB) |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 603 | estatus |= FEC_TX_BD_FTYPE(queue); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 604 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 605 | estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS; |
| 606 | ebdp->cbd_bdu = 0; |
| 607 | ebdp->cbd_esc = estatus; |
| 608 | } |
| 609 | |
| 610 | /* Handle the last BD specially */ |
| 611 | if (last_tcp) |
| 612 | status |= (BD_ENET_TX_LAST | BD_ENET_TX_TC); |
| 613 | if (is_last) { |
| 614 | status |= BD_ENET_TX_INTR; |
| 615 | if (fep->bufdesc_ex) |
| 616 | ebdp->cbd_esc |= BD_ENET_TX_INT; |
| 617 | } |
| 618 | |
| 619 | bdp->cbd_sc = status; |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static int |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 625 | fec_enet_txq_put_hdr_tso(struct fec_enet_priv_tx_q *txq, |
| 626 | struct sk_buff *skb, struct net_device *ndev, |
| 627 | struct bufdesc *bdp, int index) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 628 | { |
| 629 | struct fec_enet_private *fep = netdev_priv(ndev); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 630 | int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Fabian Frederick | 61cd2eb | 2014-09-13 22:38:26 +0200 | [diff] [blame] | 631 | struct bufdesc_ex *ebdp = container_of(bdp, struct bufdesc_ex, desc); |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 632 | unsigned short queue = skb_get_queue_mapping(skb); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 633 | void *bufaddr; |
| 634 | unsigned long dmabuf; |
| 635 | unsigned short status; |
| 636 | unsigned int estatus = 0; |
| 637 | |
| 638 | status = bdp->cbd_sc; |
| 639 | status &= ~BD_ENET_TX_STATS; |
| 640 | status |= (BD_ENET_TX_TC | BD_ENET_TX_READY); |
| 641 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 642 | bufaddr = txq->tso_hdrs + index * TSO_HEADER_SIZE; |
| 643 | dmabuf = txq->tso_hdrs_dma + index * TSO_HEADER_SIZE; |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 644 | if (((unsigned long)bufaddr) & fep->tx_align || |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 645 | fep->quirks & FEC_QUIRK_SWAP_FRAME) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 646 | memcpy(txq->tx_bounce[index], skb->data, hdr_len); |
| 647 | bufaddr = txq->tx_bounce[index]; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 648 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 649 | if (fep->quirks & FEC_QUIRK_SWAP_FRAME) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 650 | swap_buffer(bufaddr, hdr_len); |
| 651 | |
| 652 | dmabuf = dma_map_single(&fep->pdev->dev, bufaddr, |
| 653 | hdr_len, DMA_TO_DEVICE); |
| 654 | if (dma_mapping_error(&fep->pdev->dev, dmabuf)) { |
| 655 | dev_kfree_skb_any(skb); |
| 656 | if (net_ratelimit()) |
| 657 | netdev_err(ndev, "Tx DMA memory map failed\n"); |
| 658 | return NETDEV_TX_BUSY; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | bdp->cbd_bufaddr = dmabuf; |
| 663 | bdp->cbd_datlen = hdr_len; |
| 664 | |
| 665 | if (fep->bufdesc_ex) { |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 666 | if (fep->quirks & FEC_QUIRK_HAS_AVB) |
Nimrod Andy | befe821 | 2014-09-23 15:40:55 +0800 | [diff] [blame] | 667 | estatus |= FEC_TX_BD_FTYPE(queue); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 668 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 669 | estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS; |
| 670 | ebdp->cbd_bdu = 0; |
| 671 | ebdp->cbd_esc = estatus; |
| 672 | } |
| 673 | |
| 674 | bdp->cbd_sc = status; |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 679 | static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq, |
| 680 | struct sk_buff *skb, |
| 681 | struct net_device *ndev) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 682 | { |
| 683 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 684 | int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 685 | int total_len, data_left; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 686 | struct bufdesc *bdp = txq->cur_tx; |
| 687 | unsigned short queue = skb_get_queue_mapping(skb); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 688 | struct tso_t tso; |
| 689 | unsigned int index = 0; |
| 690 | int ret; |
| 691 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 692 | if (tso_count_descs(skb) >= fec_enet_get_free_txdesc_num(fep, txq)) { |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 693 | dev_kfree_skb_any(skb); |
| 694 | if (net_ratelimit()) |
| 695 | netdev_err(ndev, "NOT enough BD for TSO!\n"); |
| 696 | return NETDEV_TX_OK; |
| 697 | } |
| 698 | |
| 699 | /* Protocol checksum off-load for TCP and UDP. */ |
| 700 | if (fec_enet_clear_csum(skb, ndev)) { |
| 701 | dev_kfree_skb_any(skb); |
| 702 | return NETDEV_TX_OK; |
| 703 | } |
| 704 | |
| 705 | /* Initialize the TSO handler, and prepare the first payload */ |
| 706 | tso_start(skb, &tso); |
| 707 | |
| 708 | total_len = skb->len - hdr_len; |
| 709 | while (total_len > 0) { |
| 710 | char *hdr; |
| 711 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 712 | index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 713 | data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len); |
| 714 | total_len -= data_left; |
| 715 | |
| 716 | /* prepare packet headers: MAC + IP + TCP */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 717 | hdr = txq->tso_hdrs + index * TSO_HEADER_SIZE; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 718 | tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 719 | ret = fec_enet_txq_put_hdr_tso(txq, skb, ndev, bdp, index); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 720 | if (ret) |
| 721 | goto err_release; |
| 722 | |
| 723 | while (data_left > 0) { |
| 724 | int size; |
| 725 | |
| 726 | size = min_t(int, tso.size, data_left); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 727 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
| 728 | index = fec_enet_get_bd_index(txq->tx_bd_base, |
| 729 | bdp, fep); |
| 730 | ret = fec_enet_txq_put_data_tso(txq, skb, ndev, |
| 731 | bdp, index, |
| 732 | tso.data, size, |
| 733 | size == data_left, |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 734 | total_len == 0); |
| 735 | if (ret) |
| 736 | goto err_release; |
| 737 | |
| 738 | data_left -= size; |
| 739 | tso_build_data(skb, &tso, size); |
| 740 | } |
| 741 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 742 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* Save skb pointer */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 746 | txq->tx_skbuff[index] = skb; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 747 | |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 748 | skb_tx_timestamp(skb); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 749 | txq->cur_tx = bdp; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 750 | |
| 751 | /* Trigger transmission start */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 752 | if (!(fep->quirks & FEC_QUIRK_ERR007885) || |
Fugang Duan | 37d6017 | 2014-09-17 05:18:54 +0800 | [diff] [blame] | 753 | !readl(fep->hwp + FEC_X_DES_ACTIVE(queue)) || |
| 754 | !readl(fep->hwp + FEC_X_DES_ACTIVE(queue)) || |
| 755 | !readl(fep->hwp + FEC_X_DES_ACTIVE(queue)) || |
| 756 | !readl(fep->hwp + FEC_X_DES_ACTIVE(queue))) |
| 757 | writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue)); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 758 | |
| 759 | return 0; |
| 760 | |
| 761 | err_release: |
| 762 | /* TODO: Release all used data descriptors for TSO */ |
| 763 | return ret; |
| 764 | } |
| 765 | |
Nimrod Andy | 61a4427 | 2014-06-12 08:16:18 +0800 | [diff] [blame] | 766 | static netdev_tx_t |
| 767 | fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 768 | { |
| 769 | struct fec_enet_private *fep = netdev_priv(ndev); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 770 | int entries_free; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 771 | unsigned short queue; |
| 772 | struct fec_enet_priv_tx_q *txq; |
| 773 | struct netdev_queue *nq; |
Nimrod Andy | 61a4427 | 2014-06-12 08:16:18 +0800 | [diff] [blame] | 774 | int ret; |
| 775 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 776 | queue = skb_get_queue_mapping(skb); |
| 777 | txq = fep->tx_queue[queue]; |
| 778 | nq = netdev_get_tx_queue(ndev, queue); |
| 779 | |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 780 | if (skb_is_gso(skb)) |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 781 | ret = fec_enet_txq_submit_tso(txq, skb, ndev); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 782 | else |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 783 | ret = fec_enet_txq_submit_skb(txq, skb, ndev); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 784 | if (ret) |
| 785 | return ret; |
Nimrod Andy | 61a4427 | 2014-06-12 08:16:18 +0800 | [diff] [blame] | 786 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 787 | entries_free = fec_enet_get_free_txdesc_num(fep, txq); |
| 788 | if (entries_free <= txq->tx_stop_threshold) |
| 789 | netif_tx_stop_queue(nq); |
Nimrod Andy | 61a4427 | 2014-06-12 08:16:18 +0800 | [diff] [blame] | 790 | |
| 791 | return NETDEV_TX_OK; |
| 792 | } |
| 793 | |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 794 | /* Init RX & TX buffer descriptors |
| 795 | */ |
| 796 | static void fec_enet_bd_init(struct net_device *dev) |
| 797 | { |
| 798 | struct fec_enet_private *fep = netdev_priv(dev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 799 | struct fec_enet_priv_tx_q *txq; |
| 800 | struct fec_enet_priv_rx_q *rxq; |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 801 | struct bufdesc *bdp; |
| 802 | unsigned int i; |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 803 | unsigned int q; |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 804 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 805 | for (q = 0; q < fep->num_rx_queues; q++) { |
| 806 | /* Initialize the receive buffer descriptors. */ |
| 807 | rxq = fep->rx_queue[q]; |
| 808 | bdp = rxq->rx_bd_base; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 809 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 810 | for (i = 0; i < rxq->rx_ring_size; i++) { |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 811 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 812 | /* Initialize the BD for every fragment in the page. */ |
| 813 | if (bdp->cbd_bufaddr) |
| 814 | bdp->cbd_sc = BD_ENET_RX_EMPTY; |
| 815 | else |
| 816 | bdp->cbd_sc = 0; |
| 817 | bdp = fec_enet_get_nextdesc(bdp, fep, q); |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 818 | } |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 819 | |
| 820 | /* Set the last buffer to wrap */ |
| 821 | bdp = fec_enet_get_prevdesc(bdp, fep, q); |
| 822 | bdp->cbd_sc |= BD_SC_WRAP; |
| 823 | |
| 824 | rxq->cur_rx = rxq->rx_bd_base; |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 827 | for (q = 0; q < fep->num_tx_queues; q++) { |
| 828 | /* ...and the same for transmit */ |
| 829 | txq = fep->tx_queue[q]; |
| 830 | bdp = txq->tx_bd_base; |
| 831 | txq->cur_tx = bdp; |
| 832 | |
| 833 | for (i = 0; i < txq->tx_ring_size; i++) { |
| 834 | /* Initialize the BD for every fragment in the page. */ |
| 835 | bdp->cbd_sc = 0; |
| 836 | if (txq->tx_skbuff[i]) { |
| 837 | dev_kfree_skb_any(txq->tx_skbuff[i]); |
| 838 | txq->tx_skbuff[i] = NULL; |
| 839 | } |
| 840 | bdp->cbd_bufaddr = 0; |
| 841 | bdp = fec_enet_get_nextdesc(bdp, fep, q); |
| 842 | } |
| 843 | |
| 844 | /* Set the last buffer to wrap */ |
| 845 | bdp = fec_enet_get_prevdesc(bdp, fep, q); |
| 846 | bdp->cbd_sc |= BD_SC_WRAP; |
| 847 | txq->dirty_tx = bdp; |
| 848 | } |
| 849 | } |
| 850 | |
Frank Li | ce99d0d | 2014-09-13 05:00:52 +0800 | [diff] [blame] | 851 | static void fec_enet_active_rxring(struct net_device *ndev) |
| 852 | { |
| 853 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 854 | int i; |
| 855 | |
| 856 | for (i = 0; i < fep->num_rx_queues; i++) |
| 857 | writel(0, fep->hwp + FEC_R_DES_ACTIVE(i)); |
| 858 | } |
| 859 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 860 | static void fec_enet_enable_ring(struct net_device *ndev) |
| 861 | { |
| 862 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 863 | struct fec_enet_priv_tx_q *txq; |
| 864 | struct fec_enet_priv_rx_q *rxq; |
| 865 | int i; |
| 866 | |
| 867 | for (i = 0; i < fep->num_rx_queues; i++) { |
| 868 | rxq = fep->rx_queue[i]; |
| 869 | writel(rxq->bd_dma, fep->hwp + FEC_R_DES_START(i)); |
| 870 | |
| 871 | /* enable DMA1/2 */ |
| 872 | if (i) |
| 873 | writel(RCMR_MATCHEN | RCMR_CMP(i), |
| 874 | fep->hwp + FEC_RCMR(i)); |
| 875 | } |
| 876 | |
| 877 | for (i = 0; i < fep->num_tx_queues; i++) { |
| 878 | txq = fep->tx_queue[i]; |
| 879 | writel(txq->bd_dma, fep->hwp + FEC_X_DES_START(i)); |
| 880 | |
| 881 | /* enable DMA1/2 */ |
| 882 | if (i) |
| 883 | writel(DMA_CLASS_EN | IDLE_SLOPE(i), |
| 884 | fep->hwp + FEC_DMA_CFG(i)); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | static void fec_enet_reset_skb(struct net_device *ndev) |
| 889 | { |
| 890 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 891 | struct fec_enet_priv_tx_q *txq; |
| 892 | int i, j; |
| 893 | |
| 894 | for (i = 0; i < fep->num_tx_queues; i++) { |
| 895 | txq = fep->tx_queue[i]; |
| 896 | |
| 897 | for (j = 0; j < txq->tx_ring_size; j++) { |
| 898 | if (txq->tx_skbuff[j]) { |
| 899 | dev_kfree_skb_any(txq->tx_skbuff[j]); |
| 900 | txq->tx_skbuff[j] = NULL; |
| 901 | } |
| 902 | } |
| 903 | } |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 906 | /* |
| 907 | * This function is called to start or restart the FEC during a link |
| 908 | * change, transmit timeout, or to reconfigure the FEC. The network |
| 909 | * packet processing for this device must be stopped before this call. |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 910 | */ |
| 911 | static void |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 912 | fec_restart(struct net_device *ndev) |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 913 | { |
| 914 | struct fec_enet_private *fep = netdev_priv(ndev); |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 915 | u32 val; |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 916 | u32 temp_mac[2]; |
| 917 | u32 rcntl = OPT_FRAME_SIZE | 0x04; |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 918 | u32 ecntl = 0x2; /* ETHEREN */ |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 919 | |
Fugang Duan | 106c314 | 2014-09-13 05:00:51 +0800 | [diff] [blame] | 920 | /* Whack a reset. We should wait for this. |
| 921 | * For i.MX6SX SOC, enet use AXI bus, we use disable MAC |
| 922 | * instead of reset MAC itself. |
| 923 | */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 924 | if (fep->quirks & FEC_QUIRK_HAS_AVB) { |
Fugang Duan | 106c314 | 2014-09-13 05:00:51 +0800 | [diff] [blame] | 925 | writel(0, fep->hwp + FEC_ECNTRL); |
| 926 | } else { |
| 927 | writel(1, fep->hwp + FEC_ECNTRL); |
| 928 | udelay(10); |
| 929 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * enet-mac reset will reset mac address registers too, |
| 933 | * so need to reconfigure it. |
| 934 | */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 935 | if (fep->quirks & FEC_QUIRK_ENET_MAC) { |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 936 | memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN); |
| 937 | writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW); |
| 938 | writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH); |
| 939 | } |
| 940 | |
| 941 | /* Clear any outstanding interrupt. */ |
| 942 | writel(0xffc00000, fep->hwp + FEC_IEVENT); |
| 943 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 944 | /* Set maximum receive buffer size. */ |
| 945 | writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); |
| 946 | |
Frank Li | 14109a5 | 2013-03-26 16:12:03 +0000 | [diff] [blame] | 947 | fec_enet_bd_init(ndev); |
| 948 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 949 | fec_enet_enable_ring(ndev); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 950 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 951 | /* Reset tx SKB buffers. */ |
| 952 | fec_enet_reset_skb(ndev); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 953 | |
| 954 | /* Enable MII mode */ |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 955 | if (fep->full_duplex == DUPLEX_FULL) { |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 956 | /* FD enable */ |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 957 | writel(0x04, fep->hwp + FEC_X_CNTRL); |
| 958 | } else { |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 959 | /* No Rcv on Xmit */ |
| 960 | rcntl |= 0x02; |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 961 | writel(0x0, fep->hwp + FEC_X_CNTRL); |
| 962 | } |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 963 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 964 | /* Set MII speed */ |
| 965 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); |
| 966 | |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 967 | #if !defined(CONFIG_M5272) |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 968 | /* set RX checksum */ |
| 969 | val = readl(fep->hwp + FEC_RACC); |
| 970 | if (fep->csum_flags & FLAG_RX_CSUM_ENABLED) |
| 971 | val |= FEC_RACC_OPTIONS; |
| 972 | else |
| 973 | val &= ~FEC_RACC_OPTIONS; |
| 974 | writel(val, fep->hwp + FEC_RACC); |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 975 | #endif |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 976 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 977 | /* |
| 978 | * The phy interface and speed need to get configured |
| 979 | * differently on enet-mac. |
| 980 | */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 981 | if (fep->quirks & FEC_QUIRK_ENET_MAC) { |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 982 | /* Enable flow control and length check */ |
| 983 | rcntl |= 0x40000000 | 0x00000020; |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 984 | |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 985 | /* RGMII, RMII or MII */ |
| 986 | if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII) |
| 987 | rcntl |= (1 << 6); |
| 988 | else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 989 | rcntl |= (1 << 8); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 990 | else |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 991 | rcntl &= ~(1 << 8); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 992 | |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 993 | /* 1G, 100M or 10M */ |
| 994 | if (fep->phy_dev) { |
| 995 | if (fep->phy_dev->speed == SPEED_1000) |
| 996 | ecntl |= (1 << 5); |
| 997 | else if (fep->phy_dev->speed == SPEED_100) |
| 998 | rcntl &= ~(1 << 9); |
| 999 | else |
| 1000 | rcntl |= (1 << 9); |
| 1001 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1002 | } else { |
| 1003 | #ifdef FEC_MIIGSK_ENR |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1004 | if (fep->quirks & FEC_QUIRK_USE_GASKET) { |
Eric Benard | 8d82f21 | 2012-01-12 06:10:28 +0000 | [diff] [blame] | 1005 | u32 cfgr; |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1006 | /* disable the gasket and wait */ |
| 1007 | writel(0, fep->hwp + FEC_MIIGSK_ENR); |
| 1008 | while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4) |
| 1009 | udelay(1); |
| 1010 | |
| 1011 | /* |
| 1012 | * configure the gasket: |
| 1013 | * RMII, 50 MHz, no loopback, no echo |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 1014 | * MII, 25 MHz, no loopback, no echo |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1015 | */ |
Eric Benard | 8d82f21 | 2012-01-12 06:10:28 +0000 | [diff] [blame] | 1016 | cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII) |
| 1017 | ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII; |
| 1018 | if (fep->phy_dev && fep->phy_dev->speed == SPEED_10) |
| 1019 | cfgr |= BM_MIIGSK_CFGR_FRCONT_10M; |
| 1020 | writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1021 | |
| 1022 | /* re-enable the gasket */ |
| 1023 | writel(2, fep->hwp + FEC_MIIGSK_ENR); |
| 1024 | } |
| 1025 | #endif |
| 1026 | } |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1027 | |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 1028 | #if !defined(CONFIG_M5272) |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1029 | /* enable pause frame*/ |
| 1030 | if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) || |
| 1031 | ((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) && |
| 1032 | fep->phy_dev && fep->phy_dev->pause)) { |
| 1033 | rcntl |= FEC_ENET_FCE; |
| 1034 | |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 1035 | /* set FIFO threshold parameter to reduce overrun */ |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1036 | writel(FEC_ENET_RSEM_V, fep->hwp + FEC_R_FIFO_RSEM); |
| 1037 | writel(FEC_ENET_RSFL_V, fep->hwp + FEC_R_FIFO_RSFL); |
| 1038 | writel(FEC_ENET_RAEM_V, fep->hwp + FEC_R_FIFO_RAEM); |
| 1039 | writel(FEC_ENET_RAFL_V, fep->hwp + FEC_R_FIFO_RAFL); |
| 1040 | |
| 1041 | /* OPD */ |
| 1042 | writel(FEC_ENET_OPD_V, fep->hwp + FEC_OPD); |
| 1043 | } else { |
| 1044 | rcntl &= ~FEC_ENET_FCE; |
| 1045 | } |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 1046 | #endif /* !defined(CONFIG_M5272) */ |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1047 | |
Uwe Kleine-König | cd1f402 | 2011-01-25 22:11:25 +0100 | [diff] [blame] | 1048 | writel(rcntl, fep->hwp + FEC_R_CNTRL); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1049 | |
Stefan Wahren | 84fe618 | 2014-03-12 11:28:19 +0100 | [diff] [blame] | 1050 | /* Setup multicast filter. */ |
| 1051 | set_multicast_list(ndev); |
| 1052 | #ifndef CONFIG_M5272 |
| 1053 | writel(0, fep->hwp + FEC_HASH_TABLE_HIGH); |
| 1054 | writel(0, fep->hwp + FEC_HASH_TABLE_LOW); |
| 1055 | #endif |
| 1056 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1057 | if (fep->quirks & FEC_QUIRK_ENET_MAC) { |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1058 | /* enable ENET endian swap */ |
| 1059 | ecntl |= (1 << 8); |
| 1060 | /* enable ENET store and forward mode */ |
| 1061 | writel(1 << 8, fep->hwp + FEC_X_WMRK); |
| 1062 | } |
| 1063 | |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1064 | if (fep->bufdesc_ex) |
| 1065 | ecntl |= (1 << 4); |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 1066 | |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 1067 | #ifndef CONFIG_M5272 |
Jim Baxter | b9eef55 | 2013-07-01 14:57:54 +0100 | [diff] [blame] | 1068 | /* Enable the MIB statistic event counters */ |
| 1069 | writel(0 << 31, fep->hwp + FEC_MIB_CTRLSTAT); |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 1070 | #endif |
| 1071 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1072 | /* And last, enable the transmit and receive processing */ |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1073 | writel(ecntl, fep->hwp + FEC_ECNTRL); |
Frank Li | ce99d0d | 2014-09-13 05:00:52 +0800 | [diff] [blame] | 1074 | fec_enet_active_rxring(ndev); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1075 | |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1076 | if (fep->bufdesc_ex) |
| 1077 | fec_ptp_start_cyclecounter(ndev); |
| 1078 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1079 | /* Enable interrupts we wish to service */ |
| 1080 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 1081 | |
| 1082 | /* Init the interrupt coalescing */ |
| 1083 | fec_enet_itr_coal_init(ndev); |
| 1084 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static void |
| 1088 | fec_stop(struct net_device *ndev) |
| 1089 | { |
| 1090 | struct fec_enet_private *fep = netdev_priv(ndev); |
Lothar Waßmann | 42431dc | 2011-12-07 21:59:30 +0000 | [diff] [blame] | 1091 | u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1092 | |
| 1093 | /* We cannot expect a graceful transmit stop without link !!! */ |
| 1094 | if (fep->link) { |
| 1095 | writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */ |
| 1096 | udelay(10); |
| 1097 | if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA)) |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1098 | netdev_err(ndev, "Graceful transmit stop did not complete!\n"); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
Fugang Duan | 106c314 | 2014-09-13 05:00:51 +0800 | [diff] [blame] | 1101 | /* Whack a reset. We should wait for this. |
| 1102 | * For i.MX6SX SOC, enet use AXI bus, we use disable MAC |
| 1103 | * instead of reset MAC itself. |
| 1104 | */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1105 | if (fep->quirks & FEC_QUIRK_HAS_AVB) { |
Fugang Duan | 106c314 | 2014-09-13 05:00:51 +0800 | [diff] [blame] | 1106 | writel(0, fep->hwp + FEC_ECNTRL); |
| 1107 | } else { |
| 1108 | writel(1, fep->hwp + FEC_ECNTRL); |
| 1109 | udelay(10); |
| 1110 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1111 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); |
| 1112 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1113 | |
| 1114 | /* We have to keep ENET enabled to have MII interrupt stay working */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1115 | if (fep->quirks & FEC_QUIRK_ENET_MAC) { |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1116 | writel(2, fep->hwp + FEC_ECNTRL); |
Lothar Waßmann | 42431dc | 2011-12-07 21:59:30 +0000 | [diff] [blame] | 1117 | writel(rmii_mode, fep->hwp + FEC_R_CNTRL); |
| 1118 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | static void |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1123 | fec_timeout(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1125 | struct fec_enet_private *fep = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Russell King | 344756f | 2014-07-08 13:01:59 +0100 | [diff] [blame] | 1127 | fec_dump(ndev); |
| 1128 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1129 | ndev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 1131 | schedule_work(&fep->tx_timeout_work); |
Frank Li | 54309fa | 2013-05-07 14:08:44 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 1134 | static void fec_enet_timeout_work(struct work_struct *work) |
Frank Li | 54309fa | 2013-05-07 14:08:44 +0000 | [diff] [blame] | 1135 | { |
| 1136 | struct fec_enet_private *fep = |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 1137 | container_of(work, struct fec_enet_private, tx_timeout_work); |
Russell King | 8ce5624 | 2014-07-08 12:40:07 +0100 | [diff] [blame] | 1138 | struct net_device *ndev = fep->netdev; |
Frank Li | 54309fa | 2013-05-07 14:08:44 +0000 | [diff] [blame] | 1139 | |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 1140 | rtnl_lock(); |
| 1141 | if (netif_device_present(ndev) || netif_running(ndev)) { |
| 1142 | napi_disable(&fep->napi); |
| 1143 | netif_tx_lock_bh(ndev); |
| 1144 | fec_restart(ndev); |
| 1145 | netif_wake_queue(ndev); |
| 1146 | netif_tx_unlock_bh(ndev); |
| 1147 | napi_enable(&fep->napi); |
Frank Li | 54309fa | 2013-05-07 14:08:44 +0000 | [diff] [blame] | 1148 | } |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 1149 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | static void |
Russell King | bfd4ecd | 2014-07-08 13:02:09 +0100 | [diff] [blame] | 1153 | fec_enet_hwtstamp(struct fec_enet_private *fep, unsigned ts, |
| 1154 | struct skb_shared_hwtstamps *hwtstamps) |
| 1155 | { |
| 1156 | unsigned long flags; |
| 1157 | u64 ns; |
| 1158 | |
| 1159 | spin_lock_irqsave(&fep->tmreg_lock, flags); |
| 1160 | ns = timecounter_cyc2time(&fep->tc, ts); |
| 1161 | spin_unlock_irqrestore(&fep->tmreg_lock, flags); |
| 1162 | |
| 1163 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 1164 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 1165 | } |
| 1166 | |
| 1167 | static void |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1168 | fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | { |
| 1170 | struct fec_enet_private *fep; |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 1171 | struct bufdesc *bdp; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1172 | unsigned short status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | struct sk_buff *skb; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1174 | struct fec_enet_priv_tx_q *txq; |
| 1175 | struct netdev_queue *nq; |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1176 | int index = 0; |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 1177 | int entries_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1179 | fep = netdev_priv(ndev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1180 | |
| 1181 | queue_id = FEC_ENET_GET_QUQUE(queue_id); |
| 1182 | |
| 1183 | txq = fep->tx_queue[queue_id]; |
| 1184 | /* get next bdp of dirty_tx */ |
| 1185 | nq = netdev_get_tx_queue(ndev, queue_id); |
| 1186 | bdp = txq->dirty_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1188 | /* get next bdp of dirty_tx */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1189 | bdp = fec_enet_get_nextdesc(bdp, fep, queue_id); |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1190 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1191 | while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) { |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1192 | |
| 1193 | /* current queue is empty */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1194 | if (bdp == txq->cur_tx) |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1195 | break; |
| 1196 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1197 | index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep); |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1198 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1199 | skb = txq->tx_skbuff[index]; |
| 1200 | txq->tx_skbuff[index] = NULL; |
| 1201 | if (!IS_TSO_HEADER(txq, bdp->cbd_bufaddr)) |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 1202 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
| 1203 | bdp->cbd_datlen, DMA_TO_DEVICE); |
Sebastian Siewior | 2488a54 | 2013-12-02 10:52:55 +0100 | [diff] [blame] | 1204 | bdp->cbd_bufaddr = 0; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 1205 | if (!skb) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1206 | bdp = fec_enet_get_nextdesc(bdp, fep, queue_id); |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 1207 | continue; |
| 1208 | } |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | /* Check for errors. */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1211 | if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | BD_ENET_TX_RL | BD_ENET_TX_UN | |
| 1213 | BD_ENET_TX_CSL)) { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1214 | ndev->stats.tx_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1215 | if (status & BD_ENET_TX_HB) /* No heartbeat */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1216 | ndev->stats.tx_heartbeat_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1217 | if (status & BD_ENET_TX_LC) /* Late collision */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1218 | ndev->stats.tx_window_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1219 | if (status & BD_ENET_TX_RL) /* Retrans limit */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1220 | ndev->stats.tx_aborted_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1221 | if (status & BD_ENET_TX_UN) /* Underrun */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1222 | ndev->stats.tx_fifo_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1223 | if (status & BD_ENET_TX_CSL) /* Carrier lost */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1224 | ndev->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } else { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1226 | ndev->stats.tx_packets++; |
Nimrod Andy | 6e90928 | 2014-06-12 08:16:22 +0800 | [diff] [blame] | 1227 | ndev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1230 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) && |
| 1231 | fep->bufdesc_ex) { |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 1232 | struct skb_shared_hwtstamps shhwtstamps; |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1233 | struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 1234 | |
Russell King | bfd4ecd | 2014-07-08 13:02:09 +0100 | [diff] [blame] | 1235 | fec_enet_hwtstamp(fep, ebdp->ts, &shhwtstamps); |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 1236 | skb_tstamp_tx(skb, &shhwtstamps); |
| 1237 | } |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | /* Deferred means some collisions occurred during transmit, |
| 1240 | * but we eventually sent the packet OK. |
| 1241 | */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1242 | if (status & BD_ENET_TX_DEF) |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1243 | ndev->stats.collisions++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1244 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1245 | /* Free the sk buffer associated with this last transmit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | dev_kfree_skb_any(skb); |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1247 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1248 | txq->dirty_tx = bdp; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1249 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1250 | /* Update pointer to next buffer descriptor to be transmitted */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1251 | bdp = fec_enet_get_nextdesc(bdp, fep, queue_id); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1252 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1253 | /* Since we have freed up a buffer, the ring is no longer full |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | */ |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 1255 | if (netif_queue_stopped(ndev)) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1256 | entries_free = fec_enet_get_free_txdesc_num(fep, txq); |
| 1257 | if (entries_free >= txq->tx_wake_threshold) |
| 1258 | netif_tx_wake_queue(nq); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 1259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
Russell King | ccea296 | 2014-07-08 13:01:38 +0100 | [diff] [blame] | 1261 | |
| 1262 | /* ERR006538: Keep the transmitter going */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1263 | if (bdp != txq->cur_tx && |
| 1264 | readl(fep->hwp + FEC_X_DES_ACTIVE(queue_id)) == 0) |
| 1265 | writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue_id)); |
| 1266 | } |
| 1267 | |
| 1268 | static void |
| 1269 | fec_enet_tx(struct net_device *ndev) |
| 1270 | { |
| 1271 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1272 | u16 queue_id; |
| 1273 | /* First process class A queue, then Class B and Best Effort queue */ |
| 1274 | for_each_set_bit(queue_id, &fep->work_tx, FEC_ENET_MAX_TX_QS) { |
| 1275 | clear_bit(queue_id, &fep->work_tx); |
| 1276 | fec_enet_tx_queue(ndev, queue_id); |
| 1277 | } |
| 1278 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1281 | static int |
| 1282 | fec_enet_new_rxbdp(struct net_device *ndev, struct bufdesc *bdp, struct sk_buff *skb) |
| 1283 | { |
| 1284 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1285 | int off; |
| 1286 | |
| 1287 | off = ((unsigned long)skb->data) & fep->rx_align; |
| 1288 | if (off) |
| 1289 | skb_reserve(skb, fep->rx_align + 1 - off); |
| 1290 | |
| 1291 | bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data, |
| 1292 | FEC_ENET_RX_FRSIZE - fep->rx_align, |
| 1293 | DMA_FROM_DEVICE); |
| 1294 | if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) { |
| 1295 | if (net_ratelimit()) |
| 1296 | netdev_err(ndev, "Rx DMA memory map failed\n"); |
| 1297 | return -ENOMEM; |
| 1298 | } |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | static bool fec_enet_copybreak(struct net_device *ndev, struct sk_buff **skb, |
Lothar Waßmann | 1310b54 | 2014-11-07 10:02:47 +0100 | [diff] [blame] | 1304 | struct bufdesc *bdp, u32 length, bool swap) |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1305 | { |
| 1306 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1307 | struct sk_buff *new_skb; |
| 1308 | |
| 1309 | if (length > fep->rx_copybreak) |
| 1310 | return false; |
| 1311 | |
| 1312 | new_skb = netdev_alloc_skb(ndev, length); |
| 1313 | if (!new_skb) |
| 1314 | return false; |
| 1315 | |
| 1316 | dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr, |
| 1317 | FEC_ENET_RX_FRSIZE - fep->rx_align, |
| 1318 | DMA_FROM_DEVICE); |
Lothar Waßmann | 1310b54 | 2014-11-07 10:02:47 +0100 | [diff] [blame] | 1319 | if (!swap) |
| 1320 | memcpy(new_skb->data, (*skb)->data, length); |
| 1321 | else |
| 1322 | swap_buffer2(new_skb->data, (*skb)->data, length); |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1323 | *skb = new_skb; |
| 1324 | |
| 1325 | return true; |
| 1326 | } |
| 1327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | /* During a receive, the cur_rx points to the current incoming buffer. |
| 1329 | * When we update through the ring, if the next incoming buffer has |
| 1330 | * not been given to the system, we just set the empty indicator, |
| 1331 | * effectively tossing the packet. |
| 1332 | */ |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1333 | static int |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1334 | fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1336 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1337 | struct fec_enet_priv_rx_q *rxq; |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 1338 | struct bufdesc *bdp; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1339 | unsigned short status; |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1340 | struct sk_buff *skb_new = NULL; |
| 1341 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | ushort pkt_len; |
| 1343 | __u8 *data; |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1344 | int pkt_received = 0; |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1345 | struct bufdesc_ex *ebdp = NULL; |
| 1346 | bool vlan_packet_rcvd = false; |
| 1347 | u16 vlan_tag; |
Duan Fugang-B38611 | d842a31 | 2013-11-14 09:57:10 +0800 | [diff] [blame] | 1348 | int index = 0; |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1349 | bool is_copybreak; |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1350 | bool need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1351 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 1352 | #ifdef CONFIG_M532x |
| 1353 | flush_cache_all(); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1354 | #endif |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1355 | queue_id = FEC_ENET_GET_QUQUE(queue_id); |
| 1356 | rxq = fep->rx_queue[queue_id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | /* First, grab all of the stats for the incoming packet. |
| 1359 | * These get messed up if we get called due to a busy condition. |
| 1360 | */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1361 | bdp = rxq->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1363 | while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1365 | if (pkt_received >= budget) |
| 1366 | break; |
| 1367 | pkt_received++; |
| 1368 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1369 | /* Since we have allocated space to hold a complete frame, |
| 1370 | * the last indicator should be set. |
| 1371 | */ |
| 1372 | if ((status & BD_ENET_RX_LAST) == 0) |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1373 | netdev_err(ndev, "rcv is not +last\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | |
Russell King | db3421c | 2014-07-08 13:01:49 +0100 | [diff] [blame] | 1375 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1376 | /* Check for errors. */ |
| 1377 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | BD_ENET_RX_CR | BD_ENET_RX_OV)) { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1379 | ndev->stats.rx_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1380 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { |
| 1381 | /* Frame too long or too short. */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1382 | ndev->stats.rx_length_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1383 | } |
| 1384 | if (status & BD_ENET_RX_NO) /* Frame alignment */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1385 | ndev->stats.rx_frame_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1386 | if (status & BD_ENET_RX_CR) /* CRC Error */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1387 | ndev->stats.rx_crc_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1388 | if (status & BD_ENET_RX_OV) /* FIFO overrun */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1389 | ndev->stats.rx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1391 | |
| 1392 | /* Report late collisions as a frame error. |
| 1393 | * On this error, the BD is closed, but we don't know what we |
| 1394 | * have in the buffer. So, just drop this frame on the floor. |
| 1395 | */ |
| 1396 | if (status & BD_ENET_RX_CL) { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1397 | ndev->stats.rx_errors++; |
| 1398 | ndev->stats.rx_frame_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1399 | goto rx_processing_done; |
| 1400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1402 | /* Process the incoming frame. */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1403 | ndev->stats.rx_packets++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1404 | pkt_len = bdp->cbd_datlen; |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1405 | ndev->stats.rx_bytes += pkt_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1407 | index = fec_enet_get_bd_index(rxq->rx_bd_base, bdp, fep); |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1408 | skb = rxq->rx_skbuff[index]; |
Sascha Hauer | ccdc4f1 | 2009-01-28 23:03:09 +0000 | [diff] [blame] | 1409 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1410 | /* The packet length includes FCS, but we don't want to |
| 1411 | * include that when passing upstream as it messes up |
| 1412 | * bridging applications. |
| 1413 | */ |
Lothar Waßmann | 1310b54 | 2014-11-07 10:02:47 +0100 | [diff] [blame] | 1414 | is_copybreak = fec_enet_copybreak(ndev, &skb, bdp, pkt_len - 4, |
| 1415 | need_swap); |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1416 | if (!is_copybreak) { |
| 1417 | skb_new = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE); |
| 1418 | if (unlikely(!skb_new)) { |
| 1419 | ndev->stats.rx_dropped++; |
| 1420 | goto rx_processing_done; |
| 1421 | } |
| 1422 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
| 1423 | FEC_ENET_RX_FRSIZE - fep->rx_align, |
| 1424 | DMA_FROM_DEVICE); |
| 1425 | } |
| 1426 | |
| 1427 | prefetch(skb->data - NET_IP_ALIGN); |
| 1428 | skb_put(skb, pkt_len - 4); |
| 1429 | data = skb->data; |
Lothar Waßmann | 1310b54 | 2014-11-07 10:02:47 +0100 | [diff] [blame] | 1430 | if (!is_copybreak && need_swap) |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 1431 | swap_buffer(data, pkt_len); |
| 1432 | |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1433 | /* Extract the enhanced buffer descriptor */ |
| 1434 | ebdp = NULL; |
| 1435 | if (fep->bufdesc_ex) |
| 1436 | ebdp = (struct bufdesc_ex *)bdp; |
| 1437 | |
| 1438 | /* If this is a VLAN packet remove the VLAN Tag */ |
| 1439 | vlan_packet_rcvd = false; |
| 1440 | if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1441 | fep->bufdesc_ex && (ebdp->cbd_esc & BD_ENET_RX_VLAN)) { |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1442 | /* Push and remove the vlan tag */ |
| 1443 | struct vlan_hdr *vlan_header = |
| 1444 | (struct vlan_hdr *) (data + ETH_HLEN); |
| 1445 | vlan_tag = ntohs(vlan_header->h_vlan_TCI); |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1446 | |
| 1447 | vlan_packet_rcvd = true; |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1448 | |
| 1449 | skb_copy_to_linear_data_offset(skb, VLAN_HLEN, |
| 1450 | data, (2 * ETH_ALEN)); |
| 1451 | skb_pull(skb, VLAN_HLEN); |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1454 | skb->protocol = eth_type_trans(skb, ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1456 | /* Get receive timestamp from the skb */ |
| 1457 | if (fep->hwts_rx_en && fep->bufdesc_ex) |
| 1458 | fec_enet_hwtstamp(fep, ebdp->ts, |
| 1459 | skb_hwtstamps(skb)); |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 1460 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1461 | if (fep->bufdesc_ex && |
| 1462 | (fep->csum_flags & FLAG_RX_CSUM_ENABLED)) { |
| 1463 | if (!(ebdp->cbd_esc & FLAG_RX_CSUM_ERROR)) { |
| 1464 | /* don't check it */ |
| 1465 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1466 | } else { |
| 1467 | skb_checksum_none_assert(skb); |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 1468 | } |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1469 | } |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1470 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 1471 | /* Handle received VLAN packets */ |
| 1472 | if (vlan_packet_rcvd) |
| 1473 | __vlan_hwaccel_put_tag(skb, |
| 1474 | htons(ETH_P_8021Q), |
| 1475 | vlan_tag); |
| 1476 | |
| 1477 | napi_gro_receive(&fep->napi, skb); |
| 1478 | |
| 1479 | if (is_copybreak) { |
| 1480 | dma_sync_single_for_device(&fep->pdev->dev, bdp->cbd_bufaddr, |
| 1481 | FEC_ENET_RX_FRSIZE - fep->rx_align, |
| 1482 | DMA_FROM_DEVICE); |
| 1483 | } else { |
| 1484 | rxq->rx_skbuff[index] = skb_new; |
| 1485 | fec_enet_new_rxbdp(ndev, bdp, skb_new); |
| 1486 | } |
| 1487 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1488 | rx_processing_done: |
| 1489 | /* Clear the status flags for this buffer */ |
| 1490 | status &= ~BD_ENET_RX_STATS; |
| 1491 | |
| 1492 | /* Mark the buffer empty */ |
| 1493 | status |= BD_ENET_RX_EMPTY; |
| 1494 | bdp->cbd_sc = status; |
| 1495 | |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 1496 | if (fep->bufdesc_ex) { |
| 1497 | struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; |
| 1498 | |
| 1499 | ebdp->cbd_esc = BD_ENET_RX_INT; |
| 1500 | ebdp->cbd_prot = 0; |
| 1501 | ebdp->cbd_bdu = 0; |
| 1502 | } |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 1503 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1504 | /* Update BD pointer to next entry */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1505 | bdp = fec_enet_get_nextdesc(bdp, fep, queue_id); |
Duan Fugang-B38611 | 36e24e2 | 2013-09-03 10:41:18 +0800 | [diff] [blame] | 1506 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1507 | /* Doing this here will keep the FEC running while we process |
| 1508 | * incoming frames. On a heavily loaded network, we should be |
| 1509 | * able to keep up at the expense of system resources. |
| 1510 | */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1511 | writel(0, fep->hwp + FEC_R_DES_ACTIVE(queue_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | } |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1513 | rxq->cur_rx = bdp; |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1514 | return pkt_received; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1517 | static int |
| 1518 | fec_enet_rx(struct net_device *ndev, int budget) |
| 1519 | { |
| 1520 | int pkt_received = 0; |
| 1521 | u16 queue_id; |
| 1522 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1523 | |
| 1524 | for_each_set_bit(queue_id, &fep->work_rx, FEC_ENET_MAX_RX_QS) { |
| 1525 | clear_bit(queue_id, &fep->work_rx); |
| 1526 | pkt_received += fec_enet_rx_queue(ndev, |
| 1527 | budget - pkt_received, queue_id); |
| 1528 | } |
| 1529 | return pkt_received; |
| 1530 | } |
| 1531 | |
| 1532 | static bool |
| 1533 | fec_enet_collect_events(struct fec_enet_private *fep, uint int_events) |
| 1534 | { |
| 1535 | if (int_events == 0) |
| 1536 | return false; |
| 1537 | |
| 1538 | if (int_events & FEC_ENET_RXF) |
| 1539 | fep->work_rx |= (1 << 2); |
Frank Li | ce99d0d | 2014-09-13 05:00:52 +0800 | [diff] [blame] | 1540 | if (int_events & FEC_ENET_RXF_1) |
| 1541 | fep->work_rx |= (1 << 0); |
| 1542 | if (int_events & FEC_ENET_RXF_2) |
| 1543 | fep->work_rx |= (1 << 1); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1544 | |
| 1545 | if (int_events & FEC_ENET_TXF) |
| 1546 | fep->work_tx |= (1 << 2); |
Frank Li | ce99d0d | 2014-09-13 05:00:52 +0800 | [diff] [blame] | 1547 | if (int_events & FEC_ENET_TXF_1) |
| 1548 | fep->work_tx |= (1 << 0); |
| 1549 | if (int_events & FEC_ENET_TXF_2) |
| 1550 | fep->work_tx |= (1 << 1); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1551 | |
| 1552 | return true; |
| 1553 | } |
| 1554 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1555 | static irqreturn_t |
| 1556 | fec_enet_interrupt(int irq, void *dev_id) |
| 1557 | { |
| 1558 | struct net_device *ndev = dev_id; |
| 1559 | struct fec_enet_private *fep = netdev_priv(ndev); |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1560 | const unsigned napi_mask = FEC_ENET_RXF | FEC_ENET_TXF; |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1561 | uint int_events; |
| 1562 | irqreturn_t ret = IRQ_NONE; |
| 1563 | |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1564 | int_events = readl(fep->hwp + FEC_IEVENT); |
| 1565 | writel(int_events & ~napi_mask, fep->hwp + FEC_IEVENT); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 1566 | fec_enet_collect_events(fep, int_events); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1567 | |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1568 | if (int_events & napi_mask) { |
| 1569 | ret = IRQ_HANDLED; |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1570 | |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1571 | /* Disable the NAPI interrupts */ |
| 1572 | writel(FEC_ENET_MII, fep->hwp + FEC_IMASK); |
| 1573 | napi_schedule(&fep->napi); |
| 1574 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1575 | |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1576 | if (int_events & FEC_ENET_MII) { |
| 1577 | ret = IRQ_HANDLED; |
| 1578 | complete(&fep->mdio_done); |
| 1579 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1580 | |
Philipp Zabel | 81f35ff | 2014-10-22 16:34:35 +0200 | [diff] [blame] | 1581 | if (fep->ptp_clock) |
| 1582 | fec_ptp_check_pps_event(fep); |
Luwei Zhou | 278d240 | 2014-10-10 13:15:30 +0800 | [diff] [blame] | 1583 | |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1584 | return ret; |
| 1585 | } |
| 1586 | |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1587 | static int fec_enet_rx_napi(struct napi_struct *napi, int budget) |
| 1588 | { |
| 1589 | struct net_device *ndev = napi->dev; |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1590 | struct fec_enet_private *fep = netdev_priv(ndev); |
Russell King | 7a16807 | 2014-07-08 00:22:44 +0100 | [diff] [blame] | 1591 | int pkts; |
| 1592 | |
| 1593 | /* |
| 1594 | * Clear any pending transmit or receive interrupts before |
| 1595 | * processing the rings to avoid racing with the hardware. |
| 1596 | */ |
| 1597 | writel(FEC_ENET_RXF | FEC_ENET_TXF, fep->hwp + FEC_IEVENT); |
| 1598 | |
| 1599 | pkts = fec_enet_rx(ndev, budget); |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1600 | |
Frank Li | de5fb0a | 2013-03-03 17:34:25 +0000 | [diff] [blame] | 1601 | fec_enet_tx(ndev); |
| 1602 | |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 1603 | if (pkts < budget) { |
| 1604 | napi_complete(napi); |
| 1605 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); |
| 1606 | } |
| 1607 | return pkts; |
| 1608 | } |
Uwe Kleine-König | 4599365 | 2011-01-19 20:47:04 +0100 | [diff] [blame] | 1609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | /* ------------------------------------------------------------------------- */ |
Fabio Estevam | 0c7768a | 2013-01-07 17:42:56 +0000 | [diff] [blame] | 1611 | static void fec_get_mac(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1613 | struct fec_enet_private *fep = netdev_priv(ndev); |
Jingoo Han | 94660ba | 2013-08-30 13:56:26 +0900 | [diff] [blame] | 1614 | struct fec_platform_data *pdata = dev_get_platdata(&fep->pdev->dev); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1615 | unsigned char *iap, tmpaddr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 1617 | /* |
| 1618 | * try to get mac address in following order: |
| 1619 | * |
| 1620 | * 1) module parameter via kernel command line in form |
| 1621 | * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0 |
| 1622 | */ |
| 1623 | iap = macaddr; |
| 1624 | |
| 1625 | /* |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 1626 | * 2) from device tree data |
| 1627 | */ |
| 1628 | if (!is_valid_ether_addr(iap)) { |
| 1629 | struct device_node *np = fep->pdev->dev.of_node; |
| 1630 | if (np) { |
| 1631 | const char *mac = of_get_mac_address(np); |
| 1632 | if (mac) |
| 1633 | iap = (unsigned char *) mac; |
| 1634 | } |
| 1635 | } |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 1636 | |
| 1637 | /* |
| 1638 | * 3) from flash or fuse (via platform data) |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 1639 | */ |
| 1640 | if (!is_valid_ether_addr(iap)) { |
| 1641 | #ifdef CONFIG_M5272 |
| 1642 | if (FEC_FLASHMAC) |
| 1643 | iap = (unsigned char *)FEC_FLASHMAC; |
| 1644 | #else |
| 1645 | if (pdata) |
Lothar Waßmann | 589efdc | 2011-12-07 21:59:29 +0000 | [diff] [blame] | 1646 | iap = (unsigned char *)&pdata->mac; |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 1647 | #endif |
| 1648 | } |
| 1649 | |
| 1650 | /* |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 1651 | * 4) FEC mac registers set by bootloader |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 1652 | */ |
| 1653 | if (!is_valid_ether_addr(iap)) { |
Dan Carpenter | 7d7628f | 2013-08-29 11:25:14 +0300 | [diff] [blame] | 1654 | *((__be32 *) &tmpaddr[0]) = |
| 1655 | cpu_to_be32(readl(fep->hwp + FEC_ADDR_LOW)); |
| 1656 | *((__be16 *) &tmpaddr[4]) = |
| 1657 | cpu_to_be16(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | iap = &tmpaddr[0]; |
| 1659 | } |
| 1660 | |
Lucas Stach | ff5b2fa | 2013-06-03 00:38:39 +0000 | [diff] [blame] | 1661 | /* |
| 1662 | * 5) random mac address |
| 1663 | */ |
| 1664 | if (!is_valid_ether_addr(iap)) { |
| 1665 | /* Report it and use a random ethernet address instead */ |
| 1666 | netdev_err(ndev, "Invalid MAC address: %pM\n", iap); |
| 1667 | eth_hw_addr_random(ndev); |
| 1668 | netdev_info(ndev, "Using random MAC address: %pM\n", |
| 1669 | ndev->dev_addr); |
| 1670 | return; |
| 1671 | } |
| 1672 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1673 | memcpy(ndev->dev_addr, iap, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 1675 | /* Adjust MAC if using macaddr */ |
| 1676 | if (iap == macaddr) |
Shawn Guo | 43af940 | 2011-12-05 05:01:15 +0000 | [diff] [blame] | 1677 | ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
| 1680 | /* ------------------------------------------------------------------------- */ |
| 1681 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1682 | /* |
| 1683 | * Phy section |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1685 | static void fec_enet_adjust_link(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1687 | struct fec_enet_private *fep = netdev_priv(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1688 | struct phy_device *phy_dev = fep->phy_dev; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1689 | int status_change = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1691 | /* Prevent a state halted on mii error */ |
| 1692 | if (fep->mii_timeout && phy_dev->state == PHY_HALTED) { |
| 1693 | phy_dev->state = PHY_RESUMING; |
Frank Li | 54309fa | 2013-05-07 14:08:44 +0000 | [diff] [blame] | 1694 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1696 | |
Russell King | 8ce5624 | 2014-07-08 12:40:07 +0100 | [diff] [blame] | 1697 | /* |
| 1698 | * If the netdev is down, or is going down, we're not interested |
| 1699 | * in link state events, so just mark our idea of the link as down |
| 1700 | * and ignore the event. |
| 1701 | */ |
| 1702 | if (!netif_running(ndev) || !netif_device_present(ndev)) { |
| 1703 | fep->link = 0; |
| 1704 | } else if (phy_dev->link) { |
Lucas Stach | d97e749 | 2013-03-14 05:12:01 +0000 | [diff] [blame] | 1705 | if (!fep->link) { |
Lothar Waßmann | 6ea0722 | 2011-12-07 21:59:27 +0000 | [diff] [blame] | 1706 | fep->link = phy_dev->link; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1707 | status_change = 1; |
| 1708 | } |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1709 | |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 1710 | if (fep->full_duplex != phy_dev->duplex) { |
| 1711 | fep->full_duplex = phy_dev->duplex; |
Lucas Stach | d97e749 | 2013-03-14 05:12:01 +0000 | [diff] [blame] | 1712 | status_change = 1; |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 1713 | } |
Lucas Stach | d97e749 | 2013-03-14 05:12:01 +0000 | [diff] [blame] | 1714 | |
| 1715 | if (phy_dev->speed != fep->speed) { |
| 1716 | fep->speed = phy_dev->speed; |
| 1717 | status_change = 1; |
| 1718 | } |
| 1719 | |
| 1720 | /* if any of the above changed restart the FEC */ |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1721 | if (status_change) { |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1722 | napi_disable(&fep->napi); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1723 | netif_tx_lock_bh(ndev); |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 1724 | fec_restart(ndev); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1725 | netif_wake_queue(ndev); |
Russell King | 6af42d4 | 2014-07-08 12:40:18 +0100 | [diff] [blame] | 1726 | netif_tx_unlock_bh(ndev); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1727 | napi_enable(&fep->napi); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 1728 | } |
Lucas Stach | d97e749 | 2013-03-14 05:12:01 +0000 | [diff] [blame] | 1729 | } else { |
| 1730 | if (fep->link) { |
Russell King | f208ce1 | 2014-07-08 12:40:38 +0100 | [diff] [blame] | 1731 | napi_disable(&fep->napi); |
| 1732 | netif_tx_lock_bh(ndev); |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1733 | fec_stop(ndev); |
Russell King | f208ce1 | 2014-07-08 12:40:38 +0100 | [diff] [blame] | 1734 | netif_tx_unlock_bh(ndev); |
| 1735 | napi_enable(&fep->napi); |
Lucas Stach | 8d7ed0f | 2013-04-16 00:42:42 +0000 | [diff] [blame] | 1736 | fep->link = phy_dev->link; |
Lucas Stach | d97e749 | 2013-03-14 05:12:01 +0000 | [diff] [blame] | 1737 | status_change = 1; |
| 1738 | } |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1741 | if (status_change) |
| 1742 | phy_print_status(phy_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1745 | static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | { |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1747 | struct fec_enet_private *fep = bus->priv; |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1748 | unsigned long time_left; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1749 | |
| 1750 | fep->mii_timeout = 0; |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1751 | init_completion(&fep->mdio_done); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1752 | |
| 1753 | /* start a read op */ |
| 1754 | writel(FEC_MMFR_ST | FEC_MMFR_OP_READ | |
| 1755 | FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) | |
| 1756 | FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); |
| 1757 | |
| 1758 | /* wait for end of transfer */ |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1759 | time_left = wait_for_completion_timeout(&fep->mdio_done, |
| 1760 | usecs_to_jiffies(FEC_MII_TIMEOUT)); |
| 1761 | if (time_left == 0) { |
| 1762 | fep->mii_timeout = 1; |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1763 | netdev_err(fep->netdev, "MDIO read timeout\n"); |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1764 | return -ETIMEDOUT; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /* return value */ |
| 1768 | return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA)); |
| 1769 | } |
| 1770 | |
| 1771 | static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum, |
| 1772 | u16 value) |
| 1773 | { |
| 1774 | struct fec_enet_private *fep = bus->priv; |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1775 | unsigned long time_left; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1776 | |
| 1777 | fep->mii_timeout = 0; |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1778 | init_completion(&fep->mdio_done); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1779 | |
Shawn Guo | 862f098 | 2011-01-05 21:13:09 +0000 | [diff] [blame] | 1780 | /* start a write op */ |
| 1781 | writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1782 | FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) | |
| 1783 | FEC_MMFR_TA | FEC_MMFR_DATA(value), |
| 1784 | fep->hwp + FEC_MII_DATA); |
| 1785 | |
| 1786 | /* wait for end of transfer */ |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1787 | time_left = wait_for_completion_timeout(&fep->mdio_done, |
| 1788 | usecs_to_jiffies(FEC_MII_TIMEOUT)); |
| 1789 | if (time_left == 0) { |
| 1790 | fep->mii_timeout = 1; |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1791 | netdev_err(fep->netdev, "MDIO write timeout\n"); |
Baruch Siach | 97b72e4 | 2010-07-11 21:12:51 +0000 | [diff] [blame] | 1792 | return -ETIMEDOUT; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1798 | static int fec_enet_clk_enable(struct net_device *ndev, bool enable) |
| 1799 | { |
| 1800 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1801 | int ret; |
| 1802 | |
| 1803 | if (enable) { |
| 1804 | ret = clk_prepare_enable(fep->clk_ahb); |
| 1805 | if (ret) |
| 1806 | return ret; |
| 1807 | ret = clk_prepare_enable(fep->clk_ipg); |
| 1808 | if (ret) |
| 1809 | goto failed_clk_ipg; |
| 1810 | if (fep->clk_enet_out) { |
| 1811 | ret = clk_prepare_enable(fep->clk_enet_out); |
| 1812 | if (ret) |
| 1813 | goto failed_clk_enet_out; |
| 1814 | } |
| 1815 | if (fep->clk_ptp) { |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 1816 | mutex_lock(&fep->ptp_clk_mutex); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1817 | ret = clk_prepare_enable(fep->clk_ptp); |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 1818 | if (ret) { |
| 1819 | mutex_unlock(&fep->ptp_clk_mutex); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1820 | goto failed_clk_ptp; |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 1821 | } else { |
| 1822 | fep->ptp_clk_on = true; |
| 1823 | } |
| 1824 | mutex_unlock(&fep->ptp_clk_mutex); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1825 | } |
Fugang Duan | 9b5330e | 2014-09-13 05:00:46 +0800 | [diff] [blame] | 1826 | if (fep->clk_ref) { |
| 1827 | ret = clk_prepare_enable(fep->clk_ref); |
| 1828 | if (ret) |
| 1829 | goto failed_clk_ref; |
| 1830 | } |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1831 | } else { |
| 1832 | clk_disable_unprepare(fep->clk_ahb); |
| 1833 | clk_disable_unprepare(fep->clk_ipg); |
| 1834 | if (fep->clk_enet_out) |
| 1835 | clk_disable_unprepare(fep->clk_enet_out); |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 1836 | if (fep->clk_ptp) { |
| 1837 | mutex_lock(&fep->ptp_clk_mutex); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1838 | clk_disable_unprepare(fep->clk_ptp); |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 1839 | fep->ptp_clk_on = false; |
| 1840 | mutex_unlock(&fep->ptp_clk_mutex); |
| 1841 | } |
Fugang Duan | 9b5330e | 2014-09-13 05:00:46 +0800 | [diff] [blame] | 1842 | if (fep->clk_ref) |
| 1843 | clk_disable_unprepare(fep->clk_ref); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | return 0; |
Fugang Duan | 9b5330e | 2014-09-13 05:00:46 +0800 | [diff] [blame] | 1847 | |
| 1848 | failed_clk_ref: |
| 1849 | if (fep->clk_ref) |
| 1850 | clk_disable_unprepare(fep->clk_ref); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 1851 | failed_clk_ptp: |
| 1852 | if (fep->clk_enet_out) |
| 1853 | clk_disable_unprepare(fep->clk_enet_out); |
| 1854 | failed_clk_enet_out: |
| 1855 | clk_disable_unprepare(fep->clk_ipg); |
| 1856 | failed_clk_ipg: |
| 1857 | clk_disable_unprepare(fep->clk_ahb); |
| 1858 | |
| 1859 | return ret; |
| 1860 | } |
| 1861 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1862 | static int fec_enet_mii_probe(struct net_device *ndev) |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1863 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1864 | struct fec_enet_private *fep = netdev_priv(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1865 | struct phy_device *phy_dev = NULL; |
Greg Ungerer | 6fcc040 | 2010-10-11 21:03:05 +0000 | [diff] [blame] | 1866 | char mdio_bus_id[MII_BUS_ID_SIZE]; |
| 1867 | char phy_name[MII_BUS_ID_SIZE + 3]; |
| 1868 | int phy_id; |
Shawn Guo | 43af940 | 2011-12-05 05:01:15 +0000 | [diff] [blame] | 1869 | int dev_id = fep->dev_id; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1870 | |
Bryan Wu | 418bd0d | 2010-05-28 03:40:39 -0700 | [diff] [blame] | 1871 | fep->phy_dev = NULL; |
| 1872 | |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 1873 | if (fep->phy_node) { |
| 1874 | phy_dev = of_phy_connect(ndev, fep->phy_node, |
| 1875 | &fec_enet_adjust_link, 0, |
| 1876 | fep->phy_interface); |
| 1877 | } else { |
| 1878 | /* check for attached phy */ |
| 1879 | for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) { |
| 1880 | if ((fep->mii_bus->phy_mask & (1 << phy_id))) |
| 1881 | continue; |
| 1882 | if (fep->mii_bus->phy_map[phy_id] == NULL) |
| 1883 | continue; |
| 1884 | if (fep->mii_bus->phy_map[phy_id]->phy_id == 0) |
| 1885 | continue; |
| 1886 | if (dev_id--) |
| 1887 | continue; |
Rickard Strandqvist | 949bdd2 | 2014-09-14 19:32:42 +0200 | [diff] [blame] | 1888 | strlcpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 1889 | break; |
| 1890 | } |
| 1891 | |
| 1892 | if (phy_id >= PHY_MAX_ADDR) { |
| 1893 | netdev_info(ndev, "no PHY, assuming direct connection to switch\n"); |
Rickard Strandqvist | 949bdd2 | 2014-09-14 19:32:42 +0200 | [diff] [blame] | 1894 | strlcpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 1895 | phy_id = 0; |
| 1896 | } |
| 1897 | |
| 1898 | snprintf(phy_name, sizeof(phy_name), |
| 1899 | PHY_ID_FMT, mdio_bus_id, phy_id); |
| 1900 | phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, |
| 1901 | fep->phy_interface); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Greg Ungerer | 6fcc040 | 2010-10-11 21:03:05 +0000 | [diff] [blame] | 1904 | if (IS_ERR(phy_dev)) { |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1905 | netdev_err(ndev, "could not attach to PHY\n"); |
Greg Ungerer | 6fcc040 | 2010-10-11 21:03:05 +0000 | [diff] [blame] | 1906 | return PTR_ERR(phy_dev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | /* mask with MAC supported features */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1910 | if (fep->quirks & FEC_QUIRK_HAS_GBIT) { |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1911 | phy_dev->supported &= PHY_GBIT_FEATURES; |
Russell King | b44592f | 2014-07-08 00:22:34 +0100 | [diff] [blame] | 1912 | phy_dev->supported &= ~SUPPORTED_1000baseT_Half; |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 1913 | #if !defined(CONFIG_M5272) |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1914 | phy_dev->supported |= SUPPORTED_Pause; |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 1915 | #endif |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 1916 | } |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1917 | else |
| 1918 | phy_dev->supported &= PHY_BASIC_FEATURES; |
| 1919 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1920 | phy_dev->advertising = phy_dev->supported; |
| 1921 | |
| 1922 | fep->phy_dev = phy_dev; |
| 1923 | fep->link = 0; |
| 1924 | fep->full_duplex = 0; |
| 1925 | |
Joe Perches | 31b7720 | 2013-04-13 19:03:17 +0000 | [diff] [blame] | 1926 | netdev_info(ndev, "Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", |
| 1927 | fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev), |
| 1928 | fep->phy_dev->irq); |
Bryan Wu | 418bd0d | 2010-05-28 03:40:39 -0700 | [diff] [blame] | 1929 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | static int fec_enet_mii_init(struct platform_device *pdev) |
| 1934 | { |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 1935 | static struct mii_bus *fec0_mii_bus; |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 1936 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 1937 | struct fec_enet_private *fep = netdev_priv(ndev); |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 1938 | struct device_node *node; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1939 | int err = -ENXIO, i; |
| 1940 | |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 1941 | /* |
| 1942 | * The dual fec interfaces are not equivalent with enet-mac. |
| 1943 | * Here are the differences: |
| 1944 | * |
| 1945 | * - fec0 supports MII & RMII modes while fec1 only supports RMII |
| 1946 | * - fec0 acts as the 1588 time master while fec1 is slave |
| 1947 | * - external phys can only be configured by fec0 |
| 1948 | * |
| 1949 | * That is to say fec1 can not work independently. It only works |
| 1950 | * when fec0 is working. The reason behind this design is that the |
| 1951 | * second interface is added primarily for Switch mode. |
| 1952 | * |
| 1953 | * Because of the last point above, both phys are attached on fec0 |
| 1954 | * mdio interface in board design, and need to be configured by |
| 1955 | * fec0 mii_bus. |
| 1956 | */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1957 | if ((fep->quirks & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) { |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 1958 | /* fec1 uses fec0 mii_bus */ |
Lothar Waßmann | e163cc9 | 2011-12-07 21:59:31 +0000 | [diff] [blame] | 1959 | if (mii_cnt && fec0_mii_bus) { |
| 1960 | fep->mii_bus = fec0_mii_bus; |
| 1961 | mii_cnt++; |
| 1962 | return 0; |
| 1963 | } |
| 1964 | return -ENOENT; |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1967 | fep->mii_timeout = 0; |
| 1968 | |
| 1969 | /* |
| 1970 | * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed) |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1971 | * |
| 1972 | * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while |
| 1973 | * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28 |
| 1974 | * Reference Manual has an error on this, and gets fixed on i.MX6Q |
| 1975 | * document. |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1976 | */ |
Nimrod Andy | 98a6eeb | 2014-05-20 13:23:09 +0800 | [diff] [blame] | 1977 | fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), 5000000); |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 1978 | if (fep->quirks & FEC_QUIRK_ENET_MAC) |
Shawn Guo | 230dec6 | 2011-09-23 02:12:48 +0000 | [diff] [blame] | 1979 | fep->phy_speed--; |
| 1980 | fep->phy_speed <<= 1; |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1981 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); |
| 1982 | |
| 1983 | fep->mii_bus = mdiobus_alloc(); |
| 1984 | if (fep->mii_bus == NULL) { |
| 1985 | err = -ENOMEM; |
| 1986 | goto err_out; |
| 1987 | } |
| 1988 | |
| 1989 | fep->mii_bus->name = "fec_enet_mii_bus"; |
| 1990 | fep->mii_bus->read = fec_enet_mdio_read; |
| 1991 | fep->mii_bus->write = fec_enet_mdio_write; |
Florian Fainelli | 391420f | 2012-01-09 23:59:13 +0000 | [diff] [blame] | 1992 | snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", |
| 1993 | pdev->name, fep->dev_id + 1); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 1994 | fep->mii_bus->priv = fep; |
| 1995 | fep->mii_bus->parent = &pdev->dev; |
| 1996 | |
| 1997 | fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); |
| 1998 | if (!fep->mii_bus->irq) { |
| 1999 | err = -ENOMEM; |
| 2000 | goto err_out_free_mdiobus; |
| 2001 | } |
| 2002 | |
| 2003 | for (i = 0; i < PHY_MAX_ADDR; i++) |
| 2004 | fep->mii_bus->irq[i] = PHY_POLL; |
| 2005 | |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 2006 | node = of_get_child_by_name(pdev->dev.of_node, "mdio"); |
| 2007 | if (node) { |
| 2008 | err = of_mdiobus_register(fep->mii_bus, node); |
| 2009 | of_node_put(node); |
| 2010 | } else { |
| 2011 | err = mdiobus_register(fep->mii_bus); |
| 2012 | } |
| 2013 | |
| 2014 | if (err) |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2015 | goto err_out_free_mdio_irq; |
| 2016 | |
Lothar Waßmann | e163cc9 | 2011-12-07 21:59:31 +0000 | [diff] [blame] | 2017 | mii_cnt++; |
| 2018 | |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 2019 | /* save fec0 mii_bus */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 2020 | if (fep->quirks & FEC_QUIRK_ENET_MAC) |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 2021 | fec0_mii_bus = fep->mii_bus; |
| 2022 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2023 | return 0; |
| 2024 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2025 | err_out_free_mdio_irq: |
| 2026 | kfree(fep->mii_bus->irq); |
| 2027 | err_out_free_mdiobus: |
| 2028 | mdiobus_free(fep->mii_bus); |
| 2029 | err_out: |
| 2030 | return err; |
| 2031 | } |
| 2032 | |
| 2033 | static void fec_enet_mii_remove(struct fec_enet_private *fep) |
| 2034 | { |
Lothar Waßmann | e163cc9 | 2011-12-07 21:59:31 +0000 | [diff] [blame] | 2035 | if (--mii_cnt == 0) { |
| 2036 | mdiobus_unregister(fep->mii_bus); |
| 2037 | kfree(fep->mii_bus->irq); |
| 2038 | mdiobus_free(fep->mii_bus); |
| 2039 | } |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2042 | static int fec_enet_get_settings(struct net_device *ndev, |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2043 | struct ethtool_cmd *cmd) |
| 2044 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2045 | struct fec_enet_private *fep = netdev_priv(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2046 | struct phy_device *phydev = fep->phy_dev; |
| 2047 | |
| 2048 | if (!phydev) |
| 2049 | return -ENODEV; |
| 2050 | |
| 2051 | return phy_ethtool_gset(phydev, cmd); |
| 2052 | } |
| 2053 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2054 | static int fec_enet_set_settings(struct net_device *ndev, |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2055 | struct ethtool_cmd *cmd) |
| 2056 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2057 | struct fec_enet_private *fep = netdev_priv(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2058 | struct phy_device *phydev = fep->phy_dev; |
| 2059 | |
| 2060 | if (!phydev) |
| 2061 | return -ENODEV; |
| 2062 | |
| 2063 | return phy_ethtool_sset(phydev, cmd); |
| 2064 | } |
| 2065 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2066 | static void fec_enet_get_drvinfo(struct net_device *ndev, |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2067 | struct ethtool_drvinfo *info) |
| 2068 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2069 | struct fec_enet_private *fep = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 2071 | strlcpy(info->driver, fep->pdev->dev.driver->name, |
| 2072 | sizeof(info->driver)); |
| 2073 | strlcpy(info->version, "Revision: 1.0", sizeof(info->version)); |
| 2074 | strlcpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2076 | |
Frank Li | 5ebae489 | 2013-01-06 16:25:07 +0000 | [diff] [blame] | 2077 | static int fec_enet_get_ts_info(struct net_device *ndev, |
| 2078 | struct ethtool_ts_info *info) |
| 2079 | { |
| 2080 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2081 | |
| 2082 | if (fep->bufdesc_ex) { |
| 2083 | |
| 2084 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 2085 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 2086 | SOF_TIMESTAMPING_SOFTWARE | |
| 2087 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 2088 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 2089 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 2090 | if (fep->ptp_clock) |
| 2091 | info->phc_index = ptp_clock_index(fep->ptp_clock); |
| 2092 | else |
| 2093 | info->phc_index = -1; |
| 2094 | |
| 2095 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | |
| 2096 | (1 << HWTSTAMP_TX_ON); |
| 2097 | |
| 2098 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 2099 | (1 << HWTSTAMP_FILTER_ALL); |
| 2100 | return 0; |
| 2101 | } else { |
| 2102 | return ethtool_op_get_ts_info(ndev, info); |
| 2103 | } |
| 2104 | } |
| 2105 | |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 2106 | #if !defined(CONFIG_M5272) |
| 2107 | |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 2108 | static void fec_enet_get_pauseparam(struct net_device *ndev, |
| 2109 | struct ethtool_pauseparam *pause) |
| 2110 | { |
| 2111 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2112 | |
| 2113 | pause->autoneg = (fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) != 0; |
| 2114 | pause->tx_pause = (fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) != 0; |
| 2115 | pause->rx_pause = pause->tx_pause; |
| 2116 | } |
| 2117 | |
| 2118 | static int fec_enet_set_pauseparam(struct net_device *ndev, |
| 2119 | struct ethtool_pauseparam *pause) |
| 2120 | { |
| 2121 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2122 | |
Russell King | 0b146ca | 2014-07-08 00:22:59 +0100 | [diff] [blame] | 2123 | if (!fep->phy_dev) |
| 2124 | return -ENODEV; |
| 2125 | |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 2126 | if (pause->tx_pause != pause->rx_pause) { |
| 2127 | netdev_info(ndev, |
| 2128 | "hardware only support enable/disable both tx and rx"); |
| 2129 | return -EINVAL; |
| 2130 | } |
| 2131 | |
| 2132 | fep->pause_flag = 0; |
| 2133 | |
| 2134 | /* tx pause must be same as rx pause */ |
| 2135 | fep->pause_flag |= pause->rx_pause ? FEC_PAUSE_FLAG_ENABLE : 0; |
| 2136 | fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0; |
| 2137 | |
| 2138 | if (pause->rx_pause || pause->autoneg) { |
| 2139 | fep->phy_dev->supported |= ADVERTISED_Pause; |
| 2140 | fep->phy_dev->advertising |= ADVERTISED_Pause; |
| 2141 | } else { |
| 2142 | fep->phy_dev->supported &= ~ADVERTISED_Pause; |
| 2143 | fep->phy_dev->advertising &= ~ADVERTISED_Pause; |
| 2144 | } |
| 2145 | |
| 2146 | if (pause->autoneg) { |
| 2147 | if (netif_running(ndev)) |
| 2148 | fec_stop(ndev); |
| 2149 | phy_start_aneg(fep->phy_dev); |
| 2150 | } |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2151 | if (netif_running(ndev)) { |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2152 | napi_disable(&fep->napi); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2153 | netif_tx_lock_bh(ndev); |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 2154 | fec_restart(ndev); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2155 | netif_wake_queue(ndev); |
Russell King | 6af42d4 | 2014-07-08 12:40:18 +0100 | [diff] [blame] | 2156 | netif_tx_unlock_bh(ndev); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2157 | napi_enable(&fep->napi); |
Russell King | dbc64a8 | 2014-07-08 12:40:12 +0100 | [diff] [blame] | 2158 | } |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 2159 | |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 2163 | static const struct fec_stat { |
| 2164 | char name[ETH_GSTRING_LEN]; |
| 2165 | u16 offset; |
| 2166 | } fec_stats[] = { |
| 2167 | /* RMON TX */ |
| 2168 | { "tx_dropped", RMON_T_DROP }, |
| 2169 | { "tx_packets", RMON_T_PACKETS }, |
| 2170 | { "tx_broadcast", RMON_T_BC_PKT }, |
| 2171 | { "tx_multicast", RMON_T_MC_PKT }, |
| 2172 | { "tx_crc_errors", RMON_T_CRC_ALIGN }, |
| 2173 | { "tx_undersize", RMON_T_UNDERSIZE }, |
| 2174 | { "tx_oversize", RMON_T_OVERSIZE }, |
| 2175 | { "tx_fragment", RMON_T_FRAG }, |
| 2176 | { "tx_jabber", RMON_T_JAB }, |
| 2177 | { "tx_collision", RMON_T_COL }, |
| 2178 | { "tx_64byte", RMON_T_P64 }, |
| 2179 | { "tx_65to127byte", RMON_T_P65TO127 }, |
| 2180 | { "tx_128to255byte", RMON_T_P128TO255 }, |
| 2181 | { "tx_256to511byte", RMON_T_P256TO511 }, |
| 2182 | { "tx_512to1023byte", RMON_T_P512TO1023 }, |
| 2183 | { "tx_1024to2047byte", RMON_T_P1024TO2047 }, |
| 2184 | { "tx_GTE2048byte", RMON_T_P_GTE2048 }, |
| 2185 | { "tx_octets", RMON_T_OCTETS }, |
| 2186 | |
| 2187 | /* IEEE TX */ |
| 2188 | { "IEEE_tx_drop", IEEE_T_DROP }, |
| 2189 | { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK }, |
| 2190 | { "IEEE_tx_1col", IEEE_T_1COL }, |
| 2191 | { "IEEE_tx_mcol", IEEE_T_MCOL }, |
| 2192 | { "IEEE_tx_def", IEEE_T_DEF }, |
| 2193 | { "IEEE_tx_lcol", IEEE_T_LCOL }, |
| 2194 | { "IEEE_tx_excol", IEEE_T_EXCOL }, |
| 2195 | { "IEEE_tx_macerr", IEEE_T_MACERR }, |
| 2196 | { "IEEE_tx_cserr", IEEE_T_CSERR }, |
| 2197 | { "IEEE_tx_sqe", IEEE_T_SQE }, |
| 2198 | { "IEEE_tx_fdxfc", IEEE_T_FDXFC }, |
| 2199 | { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK }, |
| 2200 | |
| 2201 | /* RMON RX */ |
| 2202 | { "rx_packets", RMON_R_PACKETS }, |
| 2203 | { "rx_broadcast", RMON_R_BC_PKT }, |
| 2204 | { "rx_multicast", RMON_R_MC_PKT }, |
| 2205 | { "rx_crc_errors", RMON_R_CRC_ALIGN }, |
| 2206 | { "rx_undersize", RMON_R_UNDERSIZE }, |
| 2207 | { "rx_oversize", RMON_R_OVERSIZE }, |
| 2208 | { "rx_fragment", RMON_R_FRAG }, |
| 2209 | { "rx_jabber", RMON_R_JAB }, |
| 2210 | { "rx_64byte", RMON_R_P64 }, |
| 2211 | { "rx_65to127byte", RMON_R_P65TO127 }, |
| 2212 | { "rx_128to255byte", RMON_R_P128TO255 }, |
| 2213 | { "rx_256to511byte", RMON_R_P256TO511 }, |
| 2214 | { "rx_512to1023byte", RMON_R_P512TO1023 }, |
| 2215 | { "rx_1024to2047byte", RMON_R_P1024TO2047 }, |
| 2216 | { "rx_GTE2048byte", RMON_R_P_GTE2048 }, |
| 2217 | { "rx_octets", RMON_R_OCTETS }, |
| 2218 | |
| 2219 | /* IEEE RX */ |
| 2220 | { "IEEE_rx_drop", IEEE_R_DROP }, |
| 2221 | { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK }, |
| 2222 | { "IEEE_rx_crc", IEEE_R_CRC }, |
| 2223 | { "IEEE_rx_align", IEEE_R_ALIGN }, |
| 2224 | { "IEEE_rx_macerr", IEEE_R_MACERR }, |
| 2225 | { "IEEE_rx_fdxfc", IEEE_R_FDXFC }, |
| 2226 | { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK }, |
| 2227 | }; |
| 2228 | |
| 2229 | static void fec_enet_get_ethtool_stats(struct net_device *dev, |
| 2230 | struct ethtool_stats *stats, u64 *data) |
| 2231 | { |
| 2232 | struct fec_enet_private *fep = netdev_priv(dev); |
| 2233 | int i; |
| 2234 | |
| 2235 | for (i = 0; i < ARRAY_SIZE(fec_stats); i++) |
| 2236 | data[i] = readl(fep->hwp + fec_stats[i].offset); |
| 2237 | } |
| 2238 | |
| 2239 | static void fec_enet_get_strings(struct net_device *netdev, |
| 2240 | u32 stringset, u8 *data) |
| 2241 | { |
| 2242 | int i; |
| 2243 | switch (stringset) { |
| 2244 | case ETH_SS_STATS: |
| 2245 | for (i = 0; i < ARRAY_SIZE(fec_stats); i++) |
| 2246 | memcpy(data + i * ETH_GSTRING_LEN, |
| 2247 | fec_stats[i].name, ETH_GSTRING_LEN); |
| 2248 | break; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | static int fec_enet_get_sset_count(struct net_device *dev, int sset) |
| 2253 | { |
| 2254 | switch (sset) { |
| 2255 | case ETH_SS_STATS: |
| 2256 | return ARRAY_SIZE(fec_stats); |
| 2257 | default: |
| 2258 | return -EOPNOTSUPP; |
| 2259 | } |
| 2260 | } |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 2261 | #endif /* !defined(CONFIG_M5272) */ |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 2262 | |
Chris Healy | 32bc9b4 | 2013-06-17 07:25:06 -0700 | [diff] [blame] | 2263 | static int fec_enet_nway_reset(struct net_device *dev) |
| 2264 | { |
| 2265 | struct fec_enet_private *fep = netdev_priv(dev); |
| 2266 | struct phy_device *phydev = fep->phy_dev; |
| 2267 | |
| 2268 | if (!phydev) |
| 2269 | return -ENODEV; |
| 2270 | |
| 2271 | return genphy_restart_aneg(phydev); |
| 2272 | } |
| 2273 | |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2274 | /* ITR clock source is enet system clock (clk_ahb). |
| 2275 | * TCTT unit is cycle_ns * 64 cycle |
| 2276 | * So, the ICTT value = X us / (cycle_ns * 64) |
| 2277 | */ |
| 2278 | static int fec_enet_us_to_itr_clock(struct net_device *ndev, int us) |
| 2279 | { |
| 2280 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2281 | |
| 2282 | return us * (fep->itr_clk_rate / 64000) / 1000; |
| 2283 | } |
| 2284 | |
| 2285 | /* Set threshold for interrupt coalescing */ |
| 2286 | static void fec_enet_itr_coal_set(struct net_device *ndev) |
| 2287 | { |
| 2288 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2289 | int rx_itr, tx_itr; |
| 2290 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 2291 | if (!(fep->quirks & FEC_QUIRK_HAS_AVB)) |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2292 | return; |
| 2293 | |
| 2294 | /* Must be greater than zero to avoid unpredictable behavior */ |
| 2295 | if (!fep->rx_time_itr || !fep->rx_pkts_itr || |
| 2296 | !fep->tx_time_itr || !fep->tx_pkts_itr) |
| 2297 | return; |
| 2298 | |
| 2299 | /* Select enet system clock as Interrupt Coalescing |
| 2300 | * timer Clock Source |
| 2301 | */ |
| 2302 | rx_itr = FEC_ITR_CLK_SEL; |
| 2303 | tx_itr = FEC_ITR_CLK_SEL; |
| 2304 | |
| 2305 | /* set ICFT and ICTT */ |
| 2306 | rx_itr |= FEC_ITR_ICFT(fep->rx_pkts_itr); |
| 2307 | rx_itr |= FEC_ITR_ICTT(fec_enet_us_to_itr_clock(ndev, fep->rx_time_itr)); |
| 2308 | tx_itr |= FEC_ITR_ICFT(fep->tx_pkts_itr); |
| 2309 | tx_itr |= FEC_ITR_ICTT(fec_enet_us_to_itr_clock(ndev, fep->tx_time_itr)); |
| 2310 | |
| 2311 | rx_itr |= FEC_ITR_EN; |
| 2312 | tx_itr |= FEC_ITR_EN; |
| 2313 | |
| 2314 | writel(tx_itr, fep->hwp + FEC_TXIC0); |
| 2315 | writel(rx_itr, fep->hwp + FEC_RXIC0); |
| 2316 | writel(tx_itr, fep->hwp + FEC_TXIC1); |
| 2317 | writel(rx_itr, fep->hwp + FEC_RXIC1); |
| 2318 | writel(tx_itr, fep->hwp + FEC_TXIC2); |
| 2319 | writel(rx_itr, fep->hwp + FEC_RXIC2); |
| 2320 | } |
| 2321 | |
| 2322 | static int |
| 2323 | fec_enet_get_coalesce(struct net_device *ndev, struct ethtool_coalesce *ec) |
| 2324 | { |
| 2325 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2326 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 2327 | if (!(fep->quirks & FEC_QUIRK_HAS_AVB)) |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2328 | return -EOPNOTSUPP; |
| 2329 | |
| 2330 | ec->rx_coalesce_usecs = fep->rx_time_itr; |
| 2331 | ec->rx_max_coalesced_frames = fep->rx_pkts_itr; |
| 2332 | |
| 2333 | ec->tx_coalesce_usecs = fep->tx_time_itr; |
| 2334 | ec->tx_max_coalesced_frames = fep->tx_pkts_itr; |
| 2335 | |
| 2336 | return 0; |
| 2337 | } |
| 2338 | |
| 2339 | static int |
| 2340 | fec_enet_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *ec) |
| 2341 | { |
| 2342 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2343 | unsigned int cycle; |
| 2344 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 2345 | if (!(fep->quirks & FEC_QUIRK_HAS_AVB)) |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2346 | return -EOPNOTSUPP; |
| 2347 | |
| 2348 | if (ec->rx_max_coalesced_frames > 255) { |
| 2349 | pr_err("Rx coalesced frames exceed hardware limiation"); |
| 2350 | return -EINVAL; |
| 2351 | } |
| 2352 | |
| 2353 | if (ec->tx_max_coalesced_frames > 255) { |
| 2354 | pr_err("Tx coalesced frame exceed hardware limiation"); |
| 2355 | return -EINVAL; |
| 2356 | } |
| 2357 | |
| 2358 | cycle = fec_enet_us_to_itr_clock(ndev, fep->rx_time_itr); |
| 2359 | if (cycle > 0xFFFF) { |
| 2360 | pr_err("Rx coalesed usec exceeed hardware limiation"); |
| 2361 | return -EINVAL; |
| 2362 | } |
| 2363 | |
| 2364 | cycle = fec_enet_us_to_itr_clock(ndev, fep->tx_time_itr); |
| 2365 | if (cycle > 0xFFFF) { |
| 2366 | pr_err("Rx coalesed usec exceeed hardware limiation"); |
| 2367 | return -EINVAL; |
| 2368 | } |
| 2369 | |
| 2370 | fep->rx_time_itr = ec->rx_coalesce_usecs; |
| 2371 | fep->rx_pkts_itr = ec->rx_max_coalesced_frames; |
| 2372 | |
| 2373 | fep->tx_time_itr = ec->tx_coalesce_usecs; |
| 2374 | fep->tx_pkts_itr = ec->tx_max_coalesced_frames; |
| 2375 | |
| 2376 | fec_enet_itr_coal_set(ndev); |
| 2377 | |
| 2378 | return 0; |
| 2379 | } |
| 2380 | |
| 2381 | static void fec_enet_itr_coal_init(struct net_device *ndev) |
| 2382 | { |
| 2383 | struct ethtool_coalesce ec; |
| 2384 | |
| 2385 | ec.rx_coalesce_usecs = FEC_ITR_ICTT_DEFAULT; |
| 2386 | ec.rx_max_coalesced_frames = FEC_ITR_ICFT_DEFAULT; |
| 2387 | |
| 2388 | ec.tx_coalesce_usecs = FEC_ITR_ICTT_DEFAULT; |
| 2389 | ec.tx_max_coalesced_frames = FEC_ITR_ICFT_DEFAULT; |
| 2390 | |
| 2391 | fec_enet_set_coalesce(ndev, &ec); |
| 2392 | } |
| 2393 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 2394 | static int fec_enet_get_tunable(struct net_device *netdev, |
| 2395 | const struct ethtool_tunable *tuna, |
| 2396 | void *data) |
| 2397 | { |
| 2398 | struct fec_enet_private *fep = netdev_priv(netdev); |
| 2399 | int ret = 0; |
| 2400 | |
| 2401 | switch (tuna->id) { |
| 2402 | case ETHTOOL_RX_COPYBREAK: |
| 2403 | *(u32 *)data = fep->rx_copybreak; |
| 2404 | break; |
| 2405 | default: |
| 2406 | ret = -EINVAL; |
| 2407 | break; |
| 2408 | } |
| 2409 | |
| 2410 | return ret; |
| 2411 | } |
| 2412 | |
| 2413 | static int fec_enet_set_tunable(struct net_device *netdev, |
| 2414 | const struct ethtool_tunable *tuna, |
| 2415 | const void *data) |
| 2416 | { |
| 2417 | struct fec_enet_private *fep = netdev_priv(netdev); |
| 2418 | int ret = 0; |
| 2419 | |
| 2420 | switch (tuna->id) { |
| 2421 | case ETHTOOL_RX_COPYBREAK: |
| 2422 | fep->rx_copybreak = *(u32 *)data; |
| 2423 | break; |
| 2424 | default: |
| 2425 | ret = -EINVAL; |
| 2426 | break; |
| 2427 | } |
| 2428 | |
| 2429 | return ret; |
| 2430 | } |
| 2431 | |
stephen hemminger | 9b07be4 | 2012-01-04 12:59:49 +0000 | [diff] [blame] | 2432 | static const struct ethtool_ops fec_enet_ethtool_ops = { |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2433 | .get_settings = fec_enet_get_settings, |
| 2434 | .set_settings = fec_enet_set_settings, |
| 2435 | .get_drvinfo = fec_enet_get_drvinfo, |
Chris Healy | 32bc9b4 | 2013-06-17 07:25:06 -0700 | [diff] [blame] | 2436 | .nway_reset = fec_enet_nway_reset, |
Russell King | c1d7c48 | 2014-07-08 13:01:54 +0100 | [diff] [blame] | 2437 | .get_link = ethtool_op_get_link, |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 2438 | .get_coalesce = fec_enet_get_coalesce, |
| 2439 | .set_coalesce = fec_enet_set_coalesce, |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 2440 | #ifndef CONFIG_M5272 |
Russell King | c1d7c48 | 2014-07-08 13:01:54 +0100 | [diff] [blame] | 2441 | .get_pauseparam = fec_enet_get_pauseparam, |
| 2442 | .set_pauseparam = fec_enet_set_pauseparam, |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 2443 | .get_strings = fec_enet_get_strings, |
Russell King | c1d7c48 | 2014-07-08 13:01:54 +0100 | [diff] [blame] | 2444 | .get_ethtool_stats = fec_enet_get_ethtool_stats, |
Chris Healy | 38ae92d | 2013-06-25 23:18:52 -0700 | [diff] [blame] | 2445 | .get_sset_count = fec_enet_get_sset_count, |
| 2446 | #endif |
Russell King | c1d7c48 | 2014-07-08 13:01:54 +0100 | [diff] [blame] | 2447 | .get_ts_info = fec_enet_get_ts_info, |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 2448 | .get_tunable = fec_enet_get_tunable, |
| 2449 | .set_tunable = fec_enet_set_tunable, |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2450 | }; |
| 2451 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2452 | static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2453 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2454 | struct fec_enet_private *fep = netdev_priv(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2455 | struct phy_device *phydev = fep->phy_dev; |
| 2456 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2457 | if (!netif_running(ndev)) |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2458 | return -EINVAL; |
| 2459 | |
| 2460 | if (!phydev) |
| 2461 | return -ENODEV; |
| 2462 | |
Ben Hutchings | 1d5244d | 2013-11-18 23:02:44 +0000 | [diff] [blame] | 2463 | if (fep->bufdesc_ex) { |
| 2464 | if (cmd == SIOCSHWTSTAMP) |
| 2465 | return fec_ptp_set(ndev, rq); |
| 2466 | if (cmd == SIOCGHWTSTAMP) |
| 2467 | return fec_ptp_get(ndev, rq); |
| 2468 | } |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 2469 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 2470 | return phy_mii_ioctl(phydev, rq, cmd); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2473 | static void fec_enet_free_buffers(struct net_device *ndev) |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2474 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2475 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fabio Estevam | da2191e | 2013-03-20 12:31:07 -0300 | [diff] [blame] | 2476 | unsigned int i; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2477 | struct sk_buff *skb; |
| 2478 | struct bufdesc *bdp; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2479 | struct fec_enet_priv_tx_q *txq; |
| 2480 | struct fec_enet_priv_rx_q *rxq; |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2481 | unsigned int q; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2482 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2483 | for (q = 0; q < fep->num_rx_queues; q++) { |
| 2484 | rxq = fep->rx_queue[q]; |
| 2485 | bdp = rxq->rx_bd_base; |
| 2486 | for (i = 0; i < rxq->rx_ring_size; i++) { |
| 2487 | skb = rxq->rx_skbuff[i]; |
| 2488 | rxq->rx_skbuff[i] = NULL; |
| 2489 | if (skb) { |
| 2490 | dma_unmap_single(&fep->pdev->dev, |
| 2491 | bdp->cbd_bufaddr, |
Nimrod Andy | b64bf4b | 2014-09-23 15:40:57 +0800 | [diff] [blame] | 2492 | FEC_ENET_RX_FRSIZE - fep->rx_align, |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2493 | DMA_FROM_DEVICE); |
| 2494 | dev_kfree_skb(skb); |
| 2495 | } |
| 2496 | bdp = fec_enet_get_nextdesc(bdp, fep, q); |
Russell King | 730ee36 | 2014-07-08 00:23:14 +0100 | [diff] [blame] | 2497 | } |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2500 | for (q = 0; q < fep->num_tx_queues; q++) { |
| 2501 | txq = fep->tx_queue[q]; |
| 2502 | bdp = txq->tx_bd_base; |
| 2503 | for (i = 0; i < txq->tx_ring_size; i++) { |
| 2504 | kfree(txq->tx_bounce[i]); |
| 2505 | txq->tx_bounce[i] = NULL; |
| 2506 | skb = txq->tx_skbuff[i]; |
| 2507 | txq->tx_skbuff[i] = NULL; |
| 2508 | dev_kfree_skb(skb); |
| 2509 | } |
Russell King | 8b7c9ef | 2014-07-08 00:23:25 +0100 | [diff] [blame] | 2510 | } |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2513 | static void fec_enet_free_queue(struct net_device *ndev) |
| 2514 | { |
| 2515 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2516 | int i; |
| 2517 | struct fec_enet_priv_tx_q *txq; |
| 2518 | |
| 2519 | for (i = 0; i < fep->num_tx_queues; i++) |
| 2520 | if (fep->tx_queue[i] && fep->tx_queue[i]->tso_hdrs) { |
| 2521 | txq = fep->tx_queue[i]; |
| 2522 | dma_free_coherent(NULL, |
| 2523 | txq->tx_ring_size * TSO_HEADER_SIZE, |
| 2524 | txq->tso_hdrs, |
| 2525 | txq->tso_hdrs_dma); |
| 2526 | } |
| 2527 | |
| 2528 | for (i = 0; i < fep->num_rx_queues; i++) |
| 2529 | if (fep->rx_queue[i]) |
| 2530 | kfree(fep->rx_queue[i]); |
| 2531 | |
| 2532 | for (i = 0; i < fep->num_tx_queues; i++) |
| 2533 | if (fep->tx_queue[i]) |
| 2534 | kfree(fep->tx_queue[i]); |
| 2535 | } |
| 2536 | |
| 2537 | static int fec_enet_alloc_queue(struct net_device *ndev) |
| 2538 | { |
| 2539 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2540 | int i; |
| 2541 | int ret = 0; |
| 2542 | struct fec_enet_priv_tx_q *txq; |
| 2543 | |
| 2544 | for (i = 0; i < fep->num_tx_queues; i++) { |
| 2545 | txq = kzalloc(sizeof(*txq), GFP_KERNEL); |
| 2546 | if (!txq) { |
| 2547 | ret = -ENOMEM; |
| 2548 | goto alloc_failed; |
| 2549 | } |
| 2550 | |
| 2551 | fep->tx_queue[i] = txq; |
| 2552 | txq->tx_ring_size = TX_RING_SIZE; |
| 2553 | fep->total_tx_ring_size += fep->tx_queue[i]->tx_ring_size; |
| 2554 | |
| 2555 | txq->tx_stop_threshold = FEC_MAX_SKB_DESCS; |
| 2556 | txq->tx_wake_threshold = |
| 2557 | (txq->tx_ring_size - txq->tx_stop_threshold) / 2; |
| 2558 | |
| 2559 | txq->tso_hdrs = dma_alloc_coherent(NULL, |
| 2560 | txq->tx_ring_size * TSO_HEADER_SIZE, |
| 2561 | &txq->tso_hdrs_dma, |
| 2562 | GFP_KERNEL); |
| 2563 | if (!txq->tso_hdrs) { |
| 2564 | ret = -ENOMEM; |
| 2565 | goto alloc_failed; |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | for (i = 0; i < fep->num_rx_queues; i++) { |
| 2570 | fep->rx_queue[i] = kzalloc(sizeof(*fep->rx_queue[i]), |
| 2571 | GFP_KERNEL); |
| 2572 | if (!fep->rx_queue[i]) { |
| 2573 | ret = -ENOMEM; |
| 2574 | goto alloc_failed; |
| 2575 | } |
| 2576 | |
| 2577 | fep->rx_queue[i]->rx_ring_size = RX_RING_SIZE; |
| 2578 | fep->total_rx_ring_size += fep->rx_queue[i]->rx_ring_size; |
| 2579 | } |
| 2580 | return ret; |
| 2581 | |
| 2582 | alloc_failed: |
| 2583 | fec_enet_free_queue(ndev); |
| 2584 | return ret; |
| 2585 | } |
| 2586 | |
| 2587 | static int |
| 2588 | fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2589 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2590 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fabio Estevam | da2191e | 2013-03-20 12:31:07 -0300 | [diff] [blame] | 2591 | unsigned int i; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2592 | struct sk_buff *skb; |
| 2593 | struct bufdesc *bdp; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2594 | struct fec_enet_priv_rx_q *rxq; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2595 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2596 | rxq = fep->rx_queue[queue]; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2597 | bdp = rxq->rx_bd_base; |
| 2598 | for (i = 0; i < rxq->rx_ring_size; i++) { |
Fabio Estevam | b72061a | 2012-02-07 08:27:31 +0000 | [diff] [blame] | 2599 | skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE); |
Russell King | ffdce2c | 2014-07-08 00:23:30 +0100 | [diff] [blame] | 2600 | if (!skb) |
| 2601 | goto err_alloc; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2602 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 2603 | if (fec_enet_new_rxbdp(ndev, bdp, skb)) { |
Russell King | 730ee36 | 2014-07-08 00:23:14 +0100 | [diff] [blame] | 2604 | dev_kfree_skb(skb); |
Russell King | ffdce2c | 2014-07-08 00:23:30 +0100 | [diff] [blame] | 2605 | goto err_alloc; |
Duan Fugang-B38611 | d842a31 | 2013-11-14 09:57:10 +0800 | [diff] [blame] | 2606 | } |
Russell King | 730ee36 | 2014-07-08 00:23:14 +0100 | [diff] [blame] | 2607 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2608 | rxq->rx_skbuff[i] = skb; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2609 | bdp->cbd_sc = BD_ENET_RX_EMPTY; |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 2610 | |
| 2611 | if (fep->bufdesc_ex) { |
| 2612 | struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; |
| 2613 | ebdp->cbd_esc = BD_ENET_RX_INT; |
| 2614 | } |
| 2615 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2616 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* Set the last buffer to wrap. */ |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2620 | bdp = fec_enet_get_prevdesc(bdp, fep, queue); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2621 | bdp->cbd_sc |= BD_SC_WRAP; |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2622 | return 0; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2623 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2624 | err_alloc: |
| 2625 | fec_enet_free_buffers(ndev); |
| 2626 | return -ENOMEM; |
| 2627 | } |
| 2628 | |
| 2629 | static int |
| 2630 | fec_enet_alloc_txq_buffers(struct net_device *ndev, unsigned int queue) |
| 2631 | { |
| 2632 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2633 | unsigned int i; |
| 2634 | struct bufdesc *bdp; |
| 2635 | struct fec_enet_priv_tx_q *txq; |
| 2636 | |
| 2637 | txq = fep->tx_queue[queue]; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2638 | bdp = txq->tx_bd_base; |
| 2639 | for (i = 0; i < txq->tx_ring_size; i++) { |
| 2640 | txq->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL); |
| 2641 | if (!txq->tx_bounce[i]) |
Russell King | ffdce2c | 2014-07-08 00:23:30 +0100 | [diff] [blame] | 2642 | goto err_alloc; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2643 | |
| 2644 | bdp->cbd_sc = 0; |
| 2645 | bdp->cbd_bufaddr = 0; |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 2646 | |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 2647 | if (fep->bufdesc_ex) { |
| 2648 | struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; |
Jim Baxter | 96d2222 | 2013-03-26 05:25:07 +0000 | [diff] [blame] | 2649 | ebdp->cbd_esc = BD_ENET_TX_INT; |
Frank Li | ff43da8 | 2013-01-03 16:04:23 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2652 | bdp = fec_enet_get_nextdesc(bdp, fep, queue); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | /* Set the last buffer to wrap. */ |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2656 | bdp = fec_enet_get_prevdesc(bdp, fep, queue); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2657 | bdp->cbd_sc |= BD_SC_WRAP; |
| 2658 | |
| 2659 | return 0; |
Russell King | ffdce2c | 2014-07-08 00:23:30 +0100 | [diff] [blame] | 2660 | |
| 2661 | err_alloc: |
| 2662 | fec_enet_free_buffers(ndev); |
| 2663 | return -ENOMEM; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2666 | static int fec_enet_alloc_buffers(struct net_device *ndev) |
| 2667 | { |
| 2668 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 2669 | unsigned int i; |
| 2670 | |
| 2671 | for (i = 0; i < fep->num_rx_queues; i++) |
| 2672 | if (fec_enet_alloc_rxq_buffers(ndev, i)) |
| 2673 | return -ENOMEM; |
| 2674 | |
| 2675 | for (i = 0; i < fep->num_tx_queues; i++) |
| 2676 | if (fec_enet_alloc_txq_buffers(ndev, i)) |
| 2677 | return -ENOMEM; |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | static int |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2682 | fec_enet_open(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2684 | struct fec_enet_private *fep = netdev_priv(ndev); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2685 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | |
Nimrod Andy | 5bbde4d | 2014-05-27 15:51:08 +0800 | [diff] [blame] | 2687 | pinctrl_pm_select_default_state(&fep->pdev->dev); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 2688 | ret = fec_enet_clk_enable(ndev, true); |
| 2689 | if (ret) |
| 2690 | return ret; |
| 2691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | /* I should reset the ring buffers here, but I don't yet know |
| 2693 | * a simple way to do that. |
| 2694 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2696 | ret = fec_enet_alloc_buffers(ndev); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2697 | if (ret) |
Fabio Estevam | 681d242 | 2014-10-04 13:40:01 -0300 | [diff] [blame] | 2698 | goto err_enet_alloc; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2699 | |
Bryan Wu | 418bd0d | 2010-05-28 03:40:39 -0700 | [diff] [blame] | 2700 | /* Probe and connect to PHY when open the interface */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2701 | ret = fec_enet_mii_probe(ndev); |
Fabio Estevam | 681d242 | 2014-10-04 13:40:01 -0300 | [diff] [blame] | 2702 | if (ret) |
| 2703 | goto err_enet_mii_probe; |
Russell King | ce5eaf0 | 2014-02-18 12:55:42 +0000 | [diff] [blame] | 2704 | |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 2705 | fec_restart(ndev); |
Russell King | ce5eaf0 | 2014-02-18 12:55:42 +0000 | [diff] [blame] | 2706 | napi_enable(&fep->napi); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 2707 | phy_start(fep->phy_dev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2708 | netif_tx_start_all_queues(ndev); |
| 2709 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 2710 | return 0; |
Fabio Estevam | 681d242 | 2014-10-04 13:40:01 -0300 | [diff] [blame] | 2711 | |
| 2712 | err_enet_mii_probe: |
| 2713 | fec_enet_free_buffers(ndev); |
| 2714 | err_enet_alloc: |
| 2715 | fec_enet_clk_enable(ndev, false); |
| 2716 | pinctrl_pm_select_sleep_state(&fep->pdev->dev); |
| 2717 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | static int |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2721 | fec_enet_close(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2723 | struct fec_enet_private *fep = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Russell King | d76cfae | 2014-07-08 00:23:04 +0100 | [diff] [blame] | 2725 | phy_stop(fep->phy_dev); |
| 2726 | |
Russell King | 31a6de3 | 2014-07-08 12:40:23 +0100 | [diff] [blame] | 2727 | if (netif_device_present(ndev)) { |
| 2728 | napi_disable(&fep->napi); |
| 2729 | netif_tx_disable(ndev); |
Russell King | 8bbbd3c | 2014-07-08 12:40:02 +0100 | [diff] [blame] | 2730 | fec_stop(ndev); |
Russell King | 31a6de3 | 2014-07-08 12:40:23 +0100 | [diff] [blame] | 2731 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Russell King | 635cf17 | 2014-07-08 00:22:54 +0100 | [diff] [blame] | 2733 | phy_disconnect(fep->phy_dev); |
Russell King | 0b146ca | 2014-07-08 00:22:59 +0100 | [diff] [blame] | 2734 | fep->phy_dev = NULL; |
Bryan Wu | 418bd0d | 2010-05-28 03:40:39 -0700 | [diff] [blame] | 2735 | |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 2736 | fec_enet_clk_enable(ndev, false); |
Nimrod Andy | 5bbde4d | 2014-05-27 15:51:08 +0800 | [diff] [blame] | 2737 | pinctrl_pm_select_sleep_state(&fep->pdev->dev); |
Uwe Kleine-König | db8880b | 2011-01-19 20:26:39 +0100 | [diff] [blame] | 2738 | fec_enet_free_buffers(ndev); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | return 0; |
| 2741 | } |
| 2742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | /* Set or clear the multicast filter for this adaptor. |
| 2744 | * Skeleton taken from sunlance driver. |
| 2745 | * The CPM Ethernet implementation allows Multicast as well as individual |
| 2746 | * MAC address filtering. Some of the drivers check to make sure it is |
| 2747 | * a group multicast address, and discard those that are not. I guess I |
| 2748 | * will do the same for now, but just remove the test if you want |
| 2749 | * individual filtering as well (do the upper net layers want or support |
| 2750 | * this kind of feature?). |
| 2751 | */ |
| 2752 | |
| 2753 | #define HASH_BITS 6 /* #bits in hash */ |
| 2754 | #define CRC32_POLY 0xEDB88320 |
| 2755 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2756 | static void set_multicast_list(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2758 | struct fec_enet_private *fep = netdev_priv(ndev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2759 | struct netdev_hw_addr *ha; |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 2760 | unsigned int i, bit, data, crc, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | unsigned char hash; |
| 2762 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2763 | if (ndev->flags & IFF_PROMISC) { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 2764 | tmp = readl(fep->hwp + FEC_R_CNTRL); |
| 2765 | tmp |= 0x8; |
| 2766 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2767 | return; |
| 2768 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2770 | tmp = readl(fep->hwp + FEC_R_CNTRL); |
| 2771 | tmp &= ~0x8; |
| 2772 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2773 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2774 | if (ndev->flags & IFF_ALLMULTI) { |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2775 | /* Catch all multicast addresses, so set the |
| 2776 | * filter to all 1's |
| 2777 | */ |
| 2778 | writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 2779 | writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2781 | return; |
| 2782 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2783 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2784 | /* Clear filter and add the addresses in hash register |
| 2785 | */ |
| 2786 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 2787 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2789 | netdev_for_each_mc_addr(ha, ndev) { |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2790 | /* calculate crc32 value of mac address */ |
| 2791 | crc = 0xffffffff; |
| 2792 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2793 | for (i = 0; i < ndev->addr_len; i++) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2794 | data = ha->addr[i]; |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2795 | for (bit = 0; bit < 8; bit++, data >>= 1) { |
| 2796 | crc = (crc >> 1) ^ |
| 2797 | (((crc ^ data) & 1) ? CRC32_POLY : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | } |
| 2799 | } |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 2800 | |
| 2801 | /* only upper 6 bits (HASH_BITS) are used |
| 2802 | * which point to specific bit in he hash registers |
| 2803 | */ |
| 2804 | hash = (crc >> (32 - HASH_BITS)) & 0x3f; |
| 2805 | |
| 2806 | if (hash > 31) { |
| 2807 | tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 2808 | tmp |= 1 << (hash - 32); |
| 2809 | writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 2810 | } else { |
| 2811 | tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
| 2812 | tmp |= 1 << hash; |
| 2813 | writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
| 2814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | } |
| 2816 | } |
| 2817 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 2818 | /* Set a MAC change in hardware. */ |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2819 | static int |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2820 | fec_set_mac_address(struct net_device *ndev, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2822 | struct fec_enet_private *fep = netdev_priv(ndev); |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2823 | struct sockaddr *addr = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | |
Lucas Stach | 44934fa | 2014-03-30 21:32:08 +0200 | [diff] [blame] | 2825 | if (addr) { |
| 2826 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2827 | return -EADDRNOTAVAIL; |
| 2828 | memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len); |
| 2829 | } |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2830 | |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2831 | writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) | |
| 2832 | (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24), |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 2833 | fep->hwp + FEC_ADDR_LOW); |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2834 | writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24), |
Mattias Walström | 7cff094 | 2010-05-05 00:55:48 -0700 | [diff] [blame] | 2835 | fep->hwp + FEC_ADDR_HIGH); |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2836 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Xiao Jiang | 7f5c6ad | 2011-09-29 02:15:57 +0000 | [diff] [blame] | 2839 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2840 | /** |
| 2841 | * fec_poll_controller - FEC Poll controller function |
Xiao Jiang | 7f5c6ad | 2011-09-29 02:15:57 +0000 | [diff] [blame] | 2842 | * @dev: The FEC network adapter |
| 2843 | * |
| 2844 | * Polled functionality used by netconsole and others in non interrupt mode |
| 2845 | * |
| 2846 | */ |
Wei Yongjun | 47a5247 | 2013-03-20 05:06:11 +0000 | [diff] [blame] | 2847 | static void fec_poll_controller(struct net_device *dev) |
Xiao Jiang | 7f5c6ad | 2011-09-29 02:15:57 +0000 | [diff] [blame] | 2848 | { |
| 2849 | int i; |
| 2850 | struct fec_enet_private *fep = netdev_priv(dev); |
| 2851 | |
| 2852 | for (i = 0; i < FEC_IRQ_NUM; i++) { |
| 2853 | if (fep->irq[i] > 0) { |
| 2854 | disable_irq(fep->irq[i]); |
| 2855 | fec_enet_interrupt(fep->irq[i], dev); |
| 2856 | enable_irq(fep->irq[i]); |
| 2857 | } |
| 2858 | } |
| 2859 | } |
| 2860 | #endif |
| 2861 | |
Russell King | 8506fa1 | 2014-07-08 12:40:33 +0100 | [diff] [blame] | 2862 | #define FEATURES_NEED_QUIESCE NETIF_F_RXCSUM |
Nimrod Andy | 5bc2672 | 2014-10-13 10:53:48 +0800 | [diff] [blame] | 2863 | static inline void fec_enet_set_netdev_features(struct net_device *netdev, |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 2864 | netdev_features_t features) |
| 2865 | { |
| 2866 | struct fec_enet_private *fep = netdev_priv(netdev); |
| 2867 | netdev_features_t changed = features ^ netdev->features; |
| 2868 | |
| 2869 | netdev->features = features; |
| 2870 | |
| 2871 | /* Receive checksum has been changed */ |
| 2872 | if (changed & NETIF_F_RXCSUM) { |
| 2873 | if (features & NETIF_F_RXCSUM) |
| 2874 | fep->csum_flags |= FLAG_RX_CSUM_ENABLED; |
| 2875 | else |
| 2876 | fep->csum_flags &= ~FLAG_RX_CSUM_ENABLED; |
Russell King | 8506fa1 | 2014-07-08 12:40:33 +0100 | [diff] [blame] | 2877 | } |
Nimrod Andy | 5bc2672 | 2014-10-13 10:53:48 +0800 | [diff] [blame] | 2878 | } |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 2879 | |
Nimrod Andy | 5bc2672 | 2014-10-13 10:53:48 +0800 | [diff] [blame] | 2880 | static int fec_set_features(struct net_device *netdev, |
| 2881 | netdev_features_t features) |
| 2882 | { |
| 2883 | struct fec_enet_private *fep = netdev_priv(netdev); |
| 2884 | netdev_features_t changed = features ^ netdev->features; |
| 2885 | |
Russell King | 8506fa1 | 2014-07-08 12:40:33 +0100 | [diff] [blame] | 2886 | if (netif_running(netdev) && changed & FEATURES_NEED_QUIESCE) { |
Nimrod Andy | 5bc2672 | 2014-10-13 10:53:48 +0800 | [diff] [blame] | 2887 | napi_disable(&fep->napi); |
| 2888 | netif_tx_lock_bh(netdev); |
| 2889 | fec_stop(netdev); |
| 2890 | fec_enet_set_netdev_features(netdev, features); |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 2891 | fec_restart(netdev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2892 | netif_tx_wake_all_queues(netdev); |
Russell King | 8506fa1 | 2014-07-08 12:40:33 +0100 | [diff] [blame] | 2893 | netif_tx_unlock_bh(netdev); |
| 2894 | napi_enable(&fep->napi); |
Nimrod Andy | 5bc2672 | 2014-10-13 10:53:48 +0800 | [diff] [blame] | 2895 | } else { |
| 2896 | fec_enet_set_netdev_features(netdev, features); |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | return 0; |
| 2900 | } |
| 2901 | |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2902 | static const struct net_device_ops fec_netdev_ops = { |
| 2903 | .ndo_open = fec_enet_open, |
| 2904 | .ndo_stop = fec_enet_close, |
| 2905 | .ndo_start_xmit = fec_enet_start_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 2906 | .ndo_set_rx_mode = set_multicast_list, |
Ben Hutchings | 635ecaa | 2009-07-09 17:59:01 +0000 | [diff] [blame] | 2907 | .ndo_change_mtu = eth_change_mtu, |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2908 | .ndo_validate_addr = eth_validate_addr, |
| 2909 | .ndo_tx_timeout = fec_timeout, |
| 2910 | .ndo_set_mac_address = fec_set_mac_address, |
Uwe Kleine-König | db8880b | 2011-01-19 20:26:39 +0100 | [diff] [blame] | 2911 | .ndo_do_ioctl = fec_enet_ioctl, |
Xiao Jiang | 7f5c6ad | 2011-09-29 02:15:57 +0000 | [diff] [blame] | 2912 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2913 | .ndo_poll_controller = fec_poll_controller, |
| 2914 | #endif |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 2915 | .ndo_set_features = fec_set_features, |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 2916 | }; |
| 2917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | /* |
| 2919 | * XXX: We need to clean up on failure exits here. |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 2920 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2922 | static int fec_enet_init(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | { |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2924 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2925 | struct fec_enet_priv_tx_q *txq; |
| 2926 | struct fec_enet_priv_rx_q *rxq; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 2927 | struct bufdesc *cbd_base; |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2928 | dma_addr_t bd_dma; |
Nimrod Andy | 55d0218 | 2014-06-12 08:16:21 +0800 | [diff] [blame] | 2929 | int bd_size; |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2930 | unsigned int i; |
Nimrod Andy | 55d0218 | 2014-06-12 08:16:21 +0800 | [diff] [blame] | 2931 | |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 2932 | #if defined(CONFIG_ARM) |
| 2933 | fep->rx_align = 0xf; |
| 2934 | fep->tx_align = 0xf; |
| 2935 | #else |
| 2936 | fep->rx_align = 0x3; |
| 2937 | fep->tx_align = 0x3; |
| 2938 | #endif |
| 2939 | |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2940 | fec_enet_alloc_queue(ndev); |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 2941 | |
Nimrod Andy | 55d0218 | 2014-06-12 08:16:21 +0800 | [diff] [blame] | 2942 | if (fep->bufdesc_ex) |
| 2943 | fep->bufdesc_size = sizeof(struct bufdesc_ex); |
| 2944 | else |
| 2945 | fep->bufdesc_size = sizeof(struct bufdesc); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2946 | bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * |
Nimrod Andy | 55d0218 | 2014-06-12 08:16:21 +0800 | [diff] [blame] | 2947 | fep->bufdesc_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | |
Sascha Hauer | 8d4dd5c | 2009-04-15 01:32:17 +0000 | [diff] [blame] | 2949 | /* Allocate memory for buffer descriptors. */ |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2950 | cbd_base = dma_alloc_coherent(NULL, bd_size, &bd_dma, |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 2951 | GFP_KERNEL); |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2952 | if (!cbd_base) { |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2953 | return -ENOMEM; |
| 2954 | } |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 2955 | |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2956 | memset(cbd_base, 0, bd_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
Shawn Guo | 49da97d | 2011-01-05 21:13:11 +0000 | [diff] [blame] | 2958 | /* Get the Ethernet address */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2959 | fec_get_mac(ndev); |
Lucas Stach | 44934fa | 2014-03-30 21:32:08 +0200 | [diff] [blame] | 2960 | /* make sure MAC we just acquired is programmed into the hw */ |
| 2961 | fec_set_mac_address(ndev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | |
Sascha Hauer | 8d4dd5c | 2009-04-15 01:32:17 +0000 | [diff] [blame] | 2963 | /* Set receive and transmit descriptor base. */ |
Frank Li | 59d0f746 | 2014-09-13 05:00:50 +0800 | [diff] [blame] | 2964 | for (i = 0; i < fep->num_rx_queues; i++) { |
| 2965 | rxq = fep->rx_queue[i]; |
| 2966 | rxq->index = i; |
| 2967 | rxq->rx_bd_base = (struct bufdesc *)cbd_base; |
| 2968 | rxq->bd_dma = bd_dma; |
| 2969 | if (fep->bufdesc_ex) { |
| 2970 | bd_dma += sizeof(struct bufdesc_ex) * rxq->rx_ring_size; |
| 2971 | cbd_base = (struct bufdesc *) |
| 2972 | (((struct bufdesc_ex *)cbd_base) + rxq->rx_ring_size); |
| 2973 | } else { |
| 2974 | bd_dma += sizeof(struct bufdesc) * rxq->rx_ring_size; |
| 2975 | cbd_base += rxq->rx_ring_size; |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | for (i = 0; i < fep->num_tx_queues; i++) { |
| 2980 | txq = fep->tx_queue[i]; |
| 2981 | txq->index = i; |
| 2982 | txq->tx_bd_base = (struct bufdesc *)cbd_base; |
| 2983 | txq->bd_dma = bd_dma; |
| 2984 | if (fep->bufdesc_ex) { |
| 2985 | bd_dma += sizeof(struct bufdesc_ex) * txq->tx_ring_size; |
| 2986 | cbd_base = (struct bufdesc *) |
| 2987 | (((struct bufdesc_ex *)cbd_base) + txq->tx_ring_size); |
| 2988 | } else { |
| 2989 | bd_dma += sizeof(struct bufdesc) * txq->tx_ring_size; |
| 2990 | cbd_base += txq->tx_ring_size; |
| 2991 | } |
| 2992 | } |
Fugang Duan | 4d494cd | 2014-09-13 05:00:48 +0800 | [diff] [blame] | 2993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 2995 | /* The FEC Ethernet specific entries in the device structure */ |
Uwe Kleine-König | c556167 | 2011-01-19 11:58:12 +0100 | [diff] [blame] | 2996 | ndev->watchdog_timeo = TX_TIMEOUT; |
| 2997 | ndev->netdev_ops = &fec_netdev_ops; |
| 2998 | ndev->ethtool_ops = &fec_enet_ethtool_ops; |
Rob Herring | 633e753 | 2010-02-05 08:56:20 +0000 | [diff] [blame] | 2999 | |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 3000 | writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK); |
Fabio Estevam | 322555f | 2013-08-27 17:35:08 -0300 | [diff] [blame] | 3001 | netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, NAPI_POLL_WEIGHT); |
Frank Li | dc97538 | 2013-01-28 18:31:42 +0000 | [diff] [blame] | 3002 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3003 | if (fep->quirks & FEC_QUIRK_HAS_VLAN) |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 3004 | /* enable hw VLAN support */ |
| 3005 | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
Jim Baxter | cdffcf1 | 2013-07-02 22:52:56 +0100 | [diff] [blame] | 3006 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3007 | if (fep->quirks & FEC_QUIRK_HAS_CSUM) { |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 3008 | ndev->gso_max_segs = FEC_MAX_TSO_SEGS; |
| 3009 | |
Shawn Guo | 4849625 | 2013-05-08 21:08:22 +0000 | [diff] [blame] | 3010 | /* enable hw accelerator */ |
| 3011 | ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
Nimrod Andy | 79f3391 | 2014-06-12 08:16:23 +0800 | [diff] [blame] | 3012 | | NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_TSO); |
Shawn Guo | 4849625 | 2013-05-08 21:08:22 +0000 | [diff] [blame] | 3013 | fep->csum_flags |= FLAG_RX_CSUM_ENABLED; |
| 3014 | } |
Jim Baxter | 4c09eed | 2013-04-19 08:10:49 +0000 | [diff] [blame] | 3015 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3016 | if (fep->quirks & FEC_QUIRK_HAS_AVB) { |
Fugang Duan | 41ef84c | 2014-09-13 05:00:54 +0800 | [diff] [blame] | 3017 | fep->tx_align = 0; |
| 3018 | fep->rx_align = 0x3f; |
| 3019 | } |
| 3020 | |
Nimrod Andy | 09d1e54 | 2014-06-12 08:16:20 +0800 | [diff] [blame] | 3021 | ndev->hw_features = ndev->features; |
| 3022 | |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 3023 | fec_restart(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | return 0; |
| 3026 | } |
| 3027 | |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3028 | #ifdef CONFIG_OF |
Bill Pemberton | 33897cc | 2012-12-03 09:23:58 -0500 | [diff] [blame] | 3029 | static void fec_reset_phy(struct platform_device *pdev) |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3030 | { |
| 3031 | int err, phy_reset; |
Shawn Guo | a3caad0 | 2012-06-27 03:45:24 +0000 | [diff] [blame] | 3032 | int msec = 1; |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3033 | struct device_node *np = pdev->dev.of_node; |
| 3034 | |
| 3035 | if (!np) |
Shawn Guo | a9b2c8e | 2011-09-23 02:12:46 +0000 | [diff] [blame] | 3036 | return; |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3037 | |
Shawn Guo | a3caad0 | 2012-06-27 03:45:24 +0000 | [diff] [blame] | 3038 | of_property_read_u32(np, "phy-reset-duration", &msec); |
| 3039 | /* A sane reset duration should not be longer than 1s */ |
| 3040 | if (msec > 1000) |
| 3041 | msec = 1; |
| 3042 | |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3043 | phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0); |
Fabio Estevam | 07dcf8e | 2013-02-18 10:20:31 +0000 | [diff] [blame] | 3044 | if (!gpio_is_valid(phy_reset)) |
| 3045 | return; |
| 3046 | |
Shawn Guo | 119fc00 | 2012-06-27 03:45:22 +0000 | [diff] [blame] | 3047 | err = devm_gpio_request_one(&pdev->dev, phy_reset, |
| 3048 | GPIOF_OUT_INIT_LOW, "phy-reset"); |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3049 | if (err) { |
Fabio Estevam | 07dcf8e | 2013-02-18 10:20:31 +0000 | [diff] [blame] | 3050 | dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err); |
Shawn Guo | a9b2c8e | 2011-09-23 02:12:46 +0000 | [diff] [blame] | 3051 | return; |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3052 | } |
Shawn Guo | a3caad0 | 2012-06-27 03:45:24 +0000 | [diff] [blame] | 3053 | msleep(msec); |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3054 | gpio_set_value(phy_reset, 1); |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3055 | } |
| 3056 | #else /* CONFIG_OF */ |
Fabio Estevam | 0c7768a | 2013-01-07 17:42:56 +0000 | [diff] [blame] | 3057 | static void fec_reset_phy(struct platform_device *pdev) |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3058 | { |
| 3059 | /* |
| 3060 | * In case of platform probe, the reset has been done |
| 3061 | * by machine code. |
| 3062 | */ |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3063 | } |
| 3064 | #endif /* CONFIG_OF */ |
| 3065 | |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3066 | static void |
| 3067 | fec_enet_get_queue_num(struct platform_device *pdev, int *num_tx, int *num_rx) |
| 3068 | { |
| 3069 | struct device_node *np = pdev->dev.of_node; |
| 3070 | int err; |
| 3071 | |
| 3072 | *num_tx = *num_rx = 1; |
| 3073 | |
| 3074 | if (!np || !of_device_is_available(np)) |
| 3075 | return; |
| 3076 | |
| 3077 | /* parse the num of tx and rx queues */ |
| 3078 | err = of_property_read_u32(np, "fsl,num-tx-queues", num_tx); |
Frank Li | b7bd75c | 2014-09-17 05:18:51 +0800 | [diff] [blame] | 3079 | if (err) |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3080 | *num_tx = 1; |
Frank Li | b7bd75c | 2014-09-17 05:18:51 +0800 | [diff] [blame] | 3081 | |
| 3082 | err = of_property_read_u32(np, "fsl,num-rx-queues", num_rx); |
| 3083 | if (err) |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3084 | *num_rx = 1; |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3085 | |
| 3086 | if (*num_tx < 1 || *num_tx > FEC_ENET_MAX_TX_QS) { |
Frank Li | b7bd75c | 2014-09-17 05:18:51 +0800 | [diff] [blame] | 3087 | dev_warn(&pdev->dev, "Invalid num_tx(=%d), fall back to 1\n", |
| 3088 | *num_tx); |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3089 | *num_tx = 1; |
| 3090 | return; |
| 3091 | } |
| 3092 | |
| 3093 | if (*num_rx < 1 || *num_rx > FEC_ENET_MAX_RX_QS) { |
Frank Li | b7bd75c | 2014-09-17 05:18:51 +0800 | [diff] [blame] | 3094 | dev_warn(&pdev->dev, "Invalid num_rx(=%d), fall back to 1\n", |
| 3095 | *num_rx); |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3096 | *num_rx = 1; |
| 3097 | return; |
| 3098 | } |
| 3099 | |
| 3100 | } |
| 3101 | |
Bill Pemberton | 33897cc | 2012-12-03 09:23:58 -0500 | [diff] [blame] | 3102 | static int |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3103 | fec_probe(struct platform_device *pdev) |
| 3104 | { |
| 3105 | struct fec_enet_private *fep; |
Baruch Siach | 5eb32bd | 2010-05-24 00:36:13 -0700 | [diff] [blame] | 3106 | struct fec_platform_data *pdata; |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3107 | struct net_device *ndev; |
| 3108 | int i, irq, ret = 0; |
| 3109 | struct resource *r; |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3110 | const struct of_device_id *of_id; |
Shawn Guo | 43af940 | 2011-12-05 05:01:15 +0000 | [diff] [blame] | 3111 | static int dev_id; |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 3112 | struct device_node *np = pdev->dev.of_node, *phy_node; |
Frank Li | b7bd75c | 2014-09-17 05:18:51 +0800 | [diff] [blame] | 3113 | int num_tx_qs; |
| 3114 | int num_rx_qs; |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3115 | |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3116 | fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs); |
| 3117 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3118 | /* Init network device */ |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3119 | ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private), |
| 3120 | num_tx_qs, num_rx_qs); |
Fabio Estevam | 83e519b | 2013-03-11 07:32:55 +0000 | [diff] [blame] | 3121 | if (!ndev) |
| 3122 | return -ENOMEM; |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3123 | |
| 3124 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 3125 | |
| 3126 | /* setup board info structure */ |
| 3127 | fep = netdev_priv(ndev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3128 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3129 | of_id = of_match_device(fec_dt_ids, &pdev->dev); |
| 3130 | if (of_id) |
| 3131 | pdev->id_entry = of_id->data; |
| 3132 | fep->quirks = pdev->id_entry->driver_data; |
| 3133 | |
Fugang Duan | 9fc095f | 2014-09-13 05:00:49 +0800 | [diff] [blame] | 3134 | fep->num_rx_queues = num_rx_qs; |
| 3135 | fep->num_tx_queues = num_tx_qs; |
| 3136 | |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 3137 | #if !defined(CONFIG_M5272) |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 3138 | /* default enable pause frame auto negotiation */ |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3139 | if (fep->quirks & FEC_QUIRK_HAS_GBIT) |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 3140 | fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG; |
Guenter Roeck | d139193 | 2013-06-18 10:04:59 -0700 | [diff] [blame] | 3141 | #endif |
Frank Li | baa70a5 | 2013-01-16 16:55:58 +0000 | [diff] [blame] | 3142 | |
Nimrod Andy | 5bbde4d | 2014-05-27 15:51:08 +0800 | [diff] [blame] | 3143 | /* Select default pin state */ |
| 3144 | pinctrl_pm_select_default_state(&pdev->dev); |
| 3145 | |
Fabio Estevam | 399db75 | 2013-07-21 13:25:03 -0300 | [diff] [blame] | 3146 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Tushar Behera | 941e173 | 2013-06-10 17:05:05 +0530 | [diff] [blame] | 3147 | fep->hwp = devm_ioremap_resource(&pdev->dev, r); |
| 3148 | if (IS_ERR(fep->hwp)) { |
| 3149 | ret = PTR_ERR(fep->hwp); |
| 3150 | goto failed_ioremap; |
| 3151 | } |
| 3152 | |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 3153 | fep->pdev = pdev; |
Shawn Guo | 43af940 | 2011-12-05 05:01:15 +0000 | [diff] [blame] | 3154 | fep->dev_id = dev_id++; |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3155 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3156 | platform_set_drvdata(pdev, ndev); |
| 3157 | |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 3158 | phy_node = of_parse_phandle(np, "phy-handle", 0); |
| 3159 | if (!phy_node && of_phy_is_fixed_link(np)) { |
| 3160 | ret = of_phy_register_fixed_link(np); |
| 3161 | if (ret < 0) { |
| 3162 | dev_err(&pdev->dev, |
| 3163 | "broken fixed-link specification\n"); |
| 3164 | goto failed_phy; |
| 3165 | } |
| 3166 | phy_node = of_node_get(np); |
| 3167 | } |
| 3168 | fep->phy_node = phy_node; |
| 3169 | |
Guenter Roeck | 6c5f780 | 2013-04-02 09:35:10 +0000 | [diff] [blame] | 3170 | ret = of_get_phy_mode(pdev->dev.of_node); |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3171 | if (ret < 0) { |
Jingoo Han | 94660ba | 2013-08-30 13:56:26 +0900 | [diff] [blame] | 3172 | pdata = dev_get_platdata(&pdev->dev); |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3173 | if (pdata) |
| 3174 | fep->phy_interface = pdata->phy; |
| 3175 | else |
| 3176 | fep->phy_interface = PHY_INTERFACE_MODE_MII; |
| 3177 | } else { |
| 3178 | fep->phy_interface = ret; |
| 3179 | } |
| 3180 | |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3181 | fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); |
| 3182 | if (IS_ERR(fep->clk_ipg)) { |
| 3183 | ret = PTR_ERR(fep->clk_ipg); |
| 3184 | goto failed_clk; |
| 3185 | } |
| 3186 | |
| 3187 | fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); |
| 3188 | if (IS_ERR(fep->clk_ahb)) { |
| 3189 | ret = PTR_ERR(fep->clk_ahb); |
| 3190 | goto failed_clk; |
| 3191 | } |
| 3192 | |
Fugang Duan | d851b47 | 2014-09-17 05:18:52 +0800 | [diff] [blame] | 3193 | fep->itr_clk_rate = clk_get_rate(fep->clk_ahb); |
| 3194 | |
Linus Torvalds | 38f56f3 | 2013-05-07 11:06:17 -0700 | [diff] [blame] | 3195 | /* enet_out is optional, depends on board */ |
| 3196 | fep->clk_enet_out = devm_clk_get(&pdev->dev, "enet_out"); |
| 3197 | if (IS_ERR(fep->clk_enet_out)) |
| 3198 | fep->clk_enet_out = NULL; |
| 3199 | |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 3200 | fep->ptp_clk_on = false; |
| 3201 | mutex_init(&fep->ptp_clk_mutex); |
Fugang Duan | 9b5330e | 2014-09-13 05:00:46 +0800 | [diff] [blame] | 3202 | |
| 3203 | /* clk_ref is optional, depends on board */ |
| 3204 | fep->clk_ref = devm_clk_get(&pdev->dev, "enet_clk_ref"); |
| 3205 | if (IS_ERR(fep->clk_ref)) |
| 3206 | fep->clk_ref = NULL; |
| 3207 | |
Lothar Waßmann | 6b7e400 | 2014-11-17 10:51:21 +0100 | [diff] [blame] | 3208 | fep->bufdesc_ex = fep->quirks & FEC_QUIRK_HAS_BUFDESC_EX; |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3209 | fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp"); |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3210 | if (IS_ERR(fep->clk_ptp)) { |
Linus Torvalds | 38f56f3 | 2013-05-07 11:06:17 -0700 | [diff] [blame] | 3211 | fep->clk_ptp = NULL; |
Lothar Waßmann | 217b584 | 2014-11-17 10:51:20 +0100 | [diff] [blame] | 3212 | fep->bufdesc_ex = false; |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 3215 | ret = fec_enet_clk_enable(ndev, true); |
Fabio Estevam | 13a097b | 2013-07-21 13:25:02 -0300 | [diff] [blame] | 3216 | if (ret) |
| 3217 | goto failed_clk; |
| 3218 | |
Fabio Estevam | f4e9f3d | 2013-05-27 03:48:29 +0000 | [diff] [blame] | 3219 | fep->reg_phy = devm_regulator_get(&pdev->dev, "phy"); |
| 3220 | if (!IS_ERR(fep->reg_phy)) { |
| 3221 | ret = regulator_enable(fep->reg_phy); |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3222 | if (ret) { |
| 3223 | dev_err(&pdev->dev, |
| 3224 | "Failed to enable phy regulator: %d\n", ret); |
| 3225 | goto failed_regulator; |
| 3226 | } |
Fabio Estevam | f6a4d60 | 2013-05-27 03:48:31 +0000 | [diff] [blame] | 3227 | } else { |
| 3228 | fep->reg_phy = NULL; |
Fabio Estevam | e2f8d55 | 2013-02-22 06:40:45 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | fec_reset_phy(pdev); |
| 3232 | |
Fabio Estevam | 7f7d6c2 | 2013-02-21 09:21:50 +0000 | [diff] [blame] | 3233 | if (fep->bufdesc_ex) |
Fabio Estevam | ca162a8 | 2013-06-07 10:48:00 +0000 | [diff] [blame] | 3234 | fec_ptp_init(pdev); |
Fabio Estevam | 7f7d6c2 | 2013-02-21 09:21:50 +0000 | [diff] [blame] | 3235 | |
| 3236 | ret = fec_enet_init(ndev); |
| 3237 | if (ret) |
| 3238 | goto failed_init; |
| 3239 | |
Xiao Jiang | c7c83d1 | 2011-09-29 02:15:56 +0000 | [diff] [blame] | 3240 | for (i = 0; i < FEC_IRQ_NUM; i++) { |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3241 | irq = platform_get_irq(pdev, i); |
Lothar Waßmann | 86f9f2c | 2011-12-07 21:59:28 +0000 | [diff] [blame] | 3242 | if (irq < 0) { |
| 3243 | if (i) |
| 3244 | break; |
| 3245 | ret = irq; |
| 3246 | goto failed_irq; |
| 3247 | } |
Fabio Estevam | 0d9b2ab | 2013-07-21 13:25:04 -0300 | [diff] [blame] | 3248 | ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt, |
Michael Opdenacker | 44a272d | 2013-09-13 05:44:38 +0200 | [diff] [blame] | 3249 | 0, pdev->name, ndev); |
Fabio Estevam | 0d9b2ab | 2013-07-21 13:25:04 -0300 | [diff] [blame] | 3250 | if (ret) |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3251 | goto failed_irq; |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Fugang Duan | b4d39b5 | 2014-09-13 05:00:55 +0800 | [diff] [blame] | 3254 | init_completion(&fep->mdio_done); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 3255 | ret = fec_enet_mii_init(pdev); |
| 3256 | if (ret) |
| 3257 | goto failed_mii_init; |
| 3258 | |
Oskar Schirmer | 03c698c | 2010-10-07 02:30:30 +0000 | [diff] [blame] | 3259 | /* Carrier starts down, phylib will bring it up */ |
| 3260 | netif_carrier_off(ndev); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 3261 | fec_enet_clk_enable(ndev, false); |
Nimrod Andy | 5bbde4d | 2014-05-27 15:51:08 +0800 | [diff] [blame] | 3262 | pinctrl_pm_select_sleep_state(&pdev->dev); |
Oskar Schirmer | 03c698c | 2010-10-07 02:30:30 +0000 | [diff] [blame] | 3263 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3264 | ret = register_netdev(ndev); |
| 3265 | if (ret) |
| 3266 | goto failed_register; |
| 3267 | |
Fabio Estevam | eb1d064 | 2013-04-13 07:25:36 +0000 | [diff] [blame] | 3268 | if (fep->bufdesc_ex && fep->ptp_clock) |
| 3269 | netdev_info(ndev, "registered PHC device %d\n", fep->dev_id); |
| 3270 | |
Nimrod Andy | 1b7bde6 | 2014-09-30 09:28:05 +0800 | [diff] [blame] | 3271 | fep->rx_copybreak = COPYBREAK_DEFAULT; |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 3272 | INIT_WORK(&fep->tx_timeout_work, fec_enet_timeout_work); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3273 | return 0; |
| 3274 | |
| 3275 | failed_register: |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 3276 | fec_enet_mii_remove(fep); |
| 3277 | failed_mii_init: |
Fabio Estevam | 7a2bbd8 | 2013-05-27 03:48:30 +0000 | [diff] [blame] | 3278 | failed_irq: |
Fabio Estevam | 7a2bbd8 | 2013-05-27 03:48:30 +0000 | [diff] [blame] | 3279 | failed_init: |
Fabio Estevam | f6a4d60 | 2013-05-27 03:48:31 +0000 | [diff] [blame] | 3280 | if (fep->reg_phy) |
| 3281 | regulator_disable(fep->reg_phy); |
Shawn Guo | 5fa9c0f | 2012-06-27 03:45:21 +0000 | [diff] [blame] | 3282 | failed_regulator: |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 3283 | fec_enet_clk_enable(ndev, false); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3284 | failed_clk: |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 3285 | failed_phy: |
| 3286 | of_node_put(phy_node); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3287 | failed_ioremap: |
| 3288 | free_netdev(ndev); |
| 3289 | |
| 3290 | return ret; |
| 3291 | } |
| 3292 | |
Bill Pemberton | 33897cc | 2012-12-03 09:23:58 -0500 | [diff] [blame] | 3293 | static int |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3294 | fec_drv_remove(struct platform_device *pdev) |
| 3295 | { |
| 3296 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 3297 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 3298 | |
Nimrod Andy | 91c0d98 | 2014-08-21 17:09:38 +0800 | [diff] [blame] | 3299 | cancel_delayed_work_sync(&fep->time_keep); |
Russell King | 36cdc74 | 2014-07-08 13:01:44 +0100 | [diff] [blame] | 3300 | cancel_work_sync(&fep->tx_timeout_work); |
Lothar Waßmann | e163cc9 | 2011-12-07 21:59:31 +0000 | [diff] [blame] | 3301 | unregister_netdev(ndev); |
Bryan Wu | e6b043d | 2010-03-31 02:10:44 +0000 | [diff] [blame] | 3302 | fec_enet_mii_remove(fep); |
Fabio Estevam | f6a4d60 | 2013-05-27 03:48:31 +0000 | [diff] [blame] | 3303 | if (fep->reg_phy) |
| 3304 | regulator_disable(fep->reg_phy); |
Frank Li | 6605b73 | 2012-10-30 18:25:31 +0000 | [diff] [blame] | 3305 | if (fep->ptp_clock) |
| 3306 | ptp_clock_unregister(fep->ptp_clock); |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 3307 | fec_enet_clk_enable(ndev, false); |
Uwe Kleine-König | 407066f | 2014-08-11 17:35:33 +0200 | [diff] [blame] | 3308 | of_node_put(fep->phy_node); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3309 | free_netdev(ndev); |
Uwe Kleine-König | 28e2188 | 2011-01-13 21:44:18 +0100 | [diff] [blame] | 3310 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3311 | return 0; |
| 3312 | } |
| 3313 | |
Fabio Estevam | dd66d38 | 2014-07-24 18:24:01 -0300 | [diff] [blame] | 3314 | static int __maybe_unused fec_suspend(struct device *dev) |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3315 | { |
Eric Benard | 87cad5c | 2010-06-18 04:19:54 +0000 | [diff] [blame] | 3316 | struct net_device *ndev = dev_get_drvdata(dev); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3317 | struct fec_enet_private *fep = netdev_priv(ndev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3318 | |
Russell King | da1774e | 2014-07-08 12:39:57 +0100 | [diff] [blame] | 3319 | rtnl_lock(); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3320 | if (netif_running(ndev)) { |
Russell King | d76cfae | 2014-07-08 00:23:04 +0100 | [diff] [blame] | 3321 | phy_stop(fep->phy_dev); |
Russell King | 31a6de3 | 2014-07-08 12:40:23 +0100 | [diff] [blame] | 3322 | napi_disable(&fep->napi); |
| 3323 | netif_tx_lock_bh(ndev); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3324 | netif_device_detach(ndev); |
Russell King | 31a6de3 | 2014-07-08 12:40:23 +0100 | [diff] [blame] | 3325 | netif_tx_unlock_bh(ndev); |
| 3326 | fec_stop(ndev); |
Nimrod Andy | f4c4a4e | 2014-11-03 13:26:50 +0800 | [diff] [blame] | 3327 | fec_enet_clk_enable(ndev, false); |
| 3328 | pinctrl_pm_select_sleep_state(&fep->pdev->dev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3329 | } |
Russell King | da1774e | 2014-07-08 12:39:57 +0100 | [diff] [blame] | 3330 | rtnl_unlock(); |
| 3331 | |
Fabio Estevam | 238f7bc | 2013-05-27 03:48:33 +0000 | [diff] [blame] | 3332 | if (fep->reg_phy) |
| 3333 | regulator_disable(fep->reg_phy); |
| 3334 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3335 | return 0; |
| 3336 | } |
| 3337 | |
Fabio Estevam | dd66d38 | 2014-07-24 18:24:01 -0300 | [diff] [blame] | 3338 | static int __maybe_unused fec_resume(struct device *dev) |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3339 | { |
Eric Benard | 87cad5c | 2010-06-18 04:19:54 +0000 | [diff] [blame] | 3340 | struct net_device *ndev = dev_get_drvdata(dev); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3341 | struct fec_enet_private *fep = netdev_priv(ndev); |
Fabio Estevam | 238f7bc | 2013-05-27 03:48:33 +0000 | [diff] [blame] | 3342 | int ret; |
| 3343 | |
| 3344 | if (fep->reg_phy) { |
| 3345 | ret = regulator_enable(fep->reg_phy); |
| 3346 | if (ret) |
| 3347 | return ret; |
| 3348 | } |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3349 | |
Russell King | da1774e | 2014-07-08 12:39:57 +0100 | [diff] [blame] | 3350 | rtnl_lock(); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3351 | if (netif_running(ndev)) { |
Nimrod Andy | f4c4a4e | 2014-11-03 13:26:50 +0800 | [diff] [blame] | 3352 | pinctrl_pm_select_default_state(&fep->pdev->dev); |
| 3353 | ret = fec_enet_clk_enable(ndev, true); |
| 3354 | if (ret) { |
| 3355 | rtnl_unlock(); |
| 3356 | goto failed_clk; |
| 3357 | } |
Russell King | ef83337 | 2014-07-08 12:40:43 +0100 | [diff] [blame] | 3358 | fec_restart(ndev); |
Russell King | 31a6de3 | 2014-07-08 12:40:23 +0100 | [diff] [blame] | 3359 | netif_tx_lock_bh(ndev); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3360 | netif_device_attach(ndev); |
Russell King | 6af42d4 | 2014-07-08 12:40:18 +0100 | [diff] [blame] | 3361 | netif_tx_unlock_bh(ndev); |
Russell King | 6af42d4 | 2014-07-08 12:40:18 +0100 | [diff] [blame] | 3362 | napi_enable(&fep->napi); |
Russell King | d76cfae | 2014-07-08 00:23:04 +0100 | [diff] [blame] | 3363 | phy_start(fep->phy_dev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3364 | } |
Russell King | da1774e | 2014-07-08 12:39:57 +0100 | [diff] [blame] | 3365 | rtnl_unlock(); |
Uwe Kleine-König | 04e5216 | 2011-01-13 21:53:40 +0100 | [diff] [blame] | 3366 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3367 | return 0; |
Fabio Estevam | 13a097b | 2013-07-21 13:25:02 -0300 | [diff] [blame] | 3368 | |
Nimrod Andy | e8fcfcd | 2014-05-20 13:22:51 +0800 | [diff] [blame] | 3369 | failed_clk: |
Fabio Estevam | 13a097b | 2013-07-21 13:25:02 -0300 | [diff] [blame] | 3370 | if (fep->reg_phy) |
| 3371 | regulator_disable(fep->reg_phy); |
| 3372 | return ret; |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
Fabio Estevam | bf7bfd7 | 2013-04-16 08:17:46 +0000 | [diff] [blame] | 3375 | static SIMPLE_DEV_PM_OPS(fec_pm_ops, fec_suspend, fec_resume); |
Denis Kirjanov | 59d4289 | 2010-06-02 09:27:04 +0000 | [diff] [blame] | 3376 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3377 | static struct platform_driver fec_driver = { |
| 3378 | .driver = { |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 3379 | .name = DRIVER_NAME, |
Eric Benard | 87cad5c | 2010-06-18 04:19:54 +0000 | [diff] [blame] | 3380 | .owner = THIS_MODULE, |
Eric Benard | 87cad5c | 2010-06-18 04:19:54 +0000 | [diff] [blame] | 3381 | .pm = &fec_pm_ops, |
Shawn Guo | ca2cc33 | 2011-06-25 02:04:35 +0800 | [diff] [blame] | 3382 | .of_match_table = fec_dt_ids, |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3383 | }, |
Shawn Guo | b5680e0 | 2011-01-05 21:13:13 +0000 | [diff] [blame] | 3384 | .id_table = fec_devtype, |
Eric Benard | 87cad5c | 2010-06-18 04:19:54 +0000 | [diff] [blame] | 3385 | .probe = fec_probe, |
Bill Pemberton | 33897cc | 2012-12-03 09:23:58 -0500 | [diff] [blame] | 3386 | .remove = fec_drv_remove, |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 3387 | }; |
| 3388 | |
Fabio Estevam | aaca237 | 2012-01-23 16:44:50 +0000 | [diff] [blame] | 3389 | module_platform_driver(fec_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
Fabio Estevam | f8c0aca | 2013-07-20 16:20:36 -0300 | [diff] [blame] | 3391 | MODULE_ALIAS("platform:"DRIVER_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | MODULE_LICENSE("GPL"); |