blob: 4c0d2ee11428995db5c791b33b4d805efba3d999 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
4 *
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10005 * Right now, I am very wasteful with the buffers. I allocate memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * 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 Ungerer562d2f82005-11-07 14:09:50 +100015 * Support for FEC controller of ColdFire processors.
16 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100017 *
18 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
Philippe De Muyter677177c2006-06-27 13:05:33 +100019 * Copyright (c) 2004-2006 Macq Electronique SA.
Shawn Guob5680e02011-01-05 21:13:13 +000020 *
Shawn Guo230dec62011-09-23 02:12:48 +000021 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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 Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/delay.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/skbuff.h>
Jim Baxter4c09eed2013-04-19 08:10:49 +000036#include <linux/in.h>
37#include <linux/ip.h>
38#include <net/ip.h>
Nimrod Andy79f33912014-06-12 08:16:23 +080039#include <net/tso.h>
Jim Baxter4c09eed2013-04-19 08:10:49 +000040#include <linux/tcp.h>
41#include <linux/udp.h>
42#include <linux/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/spinlock.h>
44#include <linux/workqueue.h>
45#include <linux/bitops.h>
Sascha Hauer6f501b12009-01-28 23:03:05 +000046#include <linux/io.h>
47#include <linux/irq.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000048#include <linux/clk.h>
Sascha Haueread73182009-01-28 23:03:11 +000049#include <linux/platform_device.h>
Bryan Wue6b043d2010-03-31 02:10:44 +000050#include <linux/phy.h>
Baruch Siach5eb32bd2010-05-24 00:36:13 -070051#include <linux/fec.h>
Shawn Guoca2cc332011-06-25 02:04:35 +080052#include <linux/of.h>
53#include <linux/of_device.h>
54#include <linux/of_gpio.h>
Uwe Kleine-König407066f2014-08-11 17:35:33 +020055#include <linux/of_mdio.h>
Shawn Guoca2cc332011-06-25 02:04:35 +080056#include <linux/of_net.h>
Shawn Guo5fa9c0f2012-06-27 03:45:21 +000057#include <linux/regulator/consumer.h>
Jim Baxtercdffcf12013-07-02 22:52:56 +010058#include <linux/if_vlan.h>
Fabio Estevama68ab982014-06-02 15:44:30 -030059#include <linux/pinctrl/consumer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Greg Ungerer080853a2007-07-30 16:28:46 +100061#include <asm/cacheflush.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "fec.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Christoph Müllner772e42b2013-06-27 21:18:23 +020065static void set_multicast_list(struct net_device *ndev);
66
Uwe Kleine-König085e79e2011-01-17 09:52:18 +010067#if defined(CONFIG_ARM)
Sascha Hauer196719e2009-01-28 23:03:10 +000068#define FEC_ALIGNMENT 0xf
69#else
70#define FEC_ALIGNMENT 0x3
71#endif
72
Shawn Guob5680e02011-01-05 21:13:13 +000073#define DRIVER_NAME "fec"
74
Fugang Duan4d494cd2014-09-13 05:00:48 +080075#define FEC_ENET_GET_QUQUE(_x) ((_x == 0) ? 1 : ((_x == 1) ? 2 : 0))
76
Frank Libaa70a52013-01-16 16:55:58 +000077/* Pause frame feild and FIFO threshold */
78#define FEC_ENET_FCE (1 << 5)
79#define FEC_ENET_RSEM_V 0x84
80#define FEC_ENET_RSFL_V 16
81#define FEC_ENET_RAEM_V 0x8
82#define FEC_ENET_RAFL_V 0x8
83#define FEC_ENET_OPD_V 0xFFF0
84
Shawn Guob5680e02011-01-05 21:13:13 +000085/* Controller is ENET-MAC */
86#define FEC_QUIRK_ENET_MAC (1 << 0)
87/* Controller needs driver to swap frame */
88#define FEC_QUIRK_SWAP_FRAME (1 << 1)
Shawn Guo0ca1e292011-07-01 18:11:22 +080089/* Controller uses gasket */
90#define FEC_QUIRK_USE_GASKET (1 << 2)
Shawn Guo230dec62011-09-23 02:12:48 +000091/* Controller has GBIT support */
92#define FEC_QUIRK_HAS_GBIT (1 << 3)
Frank Liff43da82013-01-03 16:04:23 +000093/* Controller has extend desc buffer */
94#define FEC_QUIRK_HAS_BUFDESC_EX (1 << 4)
Shawn Guo48496252013-05-08 21:08:22 +000095/* Controller has hardware checksum support */
96#define FEC_QUIRK_HAS_CSUM (1 << 5)
Jim Baxtercdffcf12013-07-02 22:52:56 +010097/* Controller has hardware vlan support */
98#define FEC_QUIRK_HAS_VLAN (1 << 6)
Frank Li03191652013-07-25 14:05:53 +080099/* ENET IP errata ERR006358
100 *
101 * If the ready bit in the transmit buffer descriptor (TxBD[R]) is previously
102 * detected as not set during a prior frame transmission, then the
103 * ENET_TDAR[TDAR] bit is cleared at a later time, even if additional TxBDs
104 * were added to the ring and the ENET_TDAR[TDAR] bit is set. This results in
Frank Li03191652013-07-25 14:05:53 +0800105 * frames not being transmitted until there is a 0-to-1 transition on
106 * ENET_TDAR[TDAR].
107 */
108#define FEC_QUIRK_ERR006358 (1 << 7)
Fugang Duan95a77472014-09-13 05:00:47 +0800109/* ENET IP hw AVB
110 *
111 * i.MX6SX ENET IP add Audio Video Bridging (AVB) feature support.
112 * - Two class indicators on receive with configurable priority
113 * - Two class indicators and line speed timer on transmit allowing
114 * implementation class credit based shapers externally
115 * - Additional DMA registers provisioned to allow managing up to 3
116 * independent rings
117 */
118#define FEC_QUIRK_HAS_AVB (1 << 8)
Shawn Guob5680e02011-01-05 21:13:13 +0000119
120static struct platform_device_id fec_devtype[] = {
121 {
Shawn Guo0ca1e292011-07-01 18:11:22 +0800122 /* keep it for coldfire */
Shawn Guob5680e02011-01-05 21:13:13 +0000123 .name = DRIVER_NAME,
124 .driver_data = 0,
125 }, {
Shawn Guo0ca1e292011-07-01 18:11:22 +0800126 .name = "imx25-fec",
127 .driver_data = FEC_QUIRK_USE_GASKET,
128 }, {
129 .name = "imx27-fec",
130 .driver_data = 0,
131 }, {
Shawn Guob5680e02011-01-05 21:13:13 +0000132 .name = "imx28-fec",
133 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
Shawn Guo0ca1e292011-07-01 18:11:22 +0800134 }, {
Shawn Guo230dec62011-09-23 02:12:48 +0000135 .name = "imx6q-fec",
Frank Liff43da82013-01-03 16:04:23 +0000136 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
Jim Baxtercdffcf12013-07-02 22:52:56 +0100137 FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
Frank Li03191652013-07-25 14:05:53 +0800138 FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR006358,
Shawn Guo230dec62011-09-23 02:12:48 +0000139 }, {
Shawn Guo36803542013-05-19 04:38:46 +0000140 .name = "mvf600-fec",
Jingchang Luca7c4a42013-04-11 21:12:45 +0000141 .driver_data = FEC_QUIRK_ENET_MAC,
142 }, {
Fugang Duan95a77472014-09-13 05:00:47 +0800143 .name = "imx6sx-fec",
144 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
145 FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
146 FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR006358 |
147 FEC_QUIRK_HAS_AVB,
148 }, {
Shawn Guo0ca1e292011-07-01 18:11:22 +0800149 /* sentinel */
150 }
Shawn Guob5680e02011-01-05 21:13:13 +0000151};
Shawn Guo0ca1e292011-07-01 18:11:22 +0800152MODULE_DEVICE_TABLE(platform, fec_devtype);
Shawn Guob5680e02011-01-05 21:13:13 +0000153
Shawn Guoca2cc332011-06-25 02:04:35 +0800154enum imx_fec_type {
Lothar Waßmanna7dd3212011-12-07 21:59:25 +0000155 IMX25_FEC = 1, /* runs on i.mx25/50/53 */
Shawn Guoca2cc332011-06-25 02:04:35 +0800156 IMX27_FEC, /* runs on i.mx27/35/51 */
157 IMX28_FEC,
Shawn Guo230dec62011-09-23 02:12:48 +0000158 IMX6Q_FEC,
Shawn Guo36803542013-05-19 04:38:46 +0000159 MVF600_FEC,
Shawn Guoca2cc332011-06-25 02:04:35 +0800160};
161
162static const struct of_device_id fec_dt_ids[] = {
163 { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
164 { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
165 { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
Shawn Guo230dec62011-09-23 02:12:48 +0000166 { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
Shawn Guo36803542013-05-19 04:38:46 +0000167 { .compatible = "fsl,mvf600-fec", .data = &fec_devtype[MVF600_FEC], },
Shawn Guoca2cc332011-06-25 02:04:35 +0800168 { /* sentinel */ }
169};
170MODULE_DEVICE_TABLE(of, fec_dt_ids);
171
Shawn Guo49da97d2011-01-05 21:13:11 +0000172static unsigned char macaddr[ETH_ALEN];
173module_param_array(macaddr, byte, NULL, 0);
174MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
175
Greg Ungerer87f4abb2008-06-06 15:55:36 +1000176#if defined(CONFIG_M5272)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/*
178 * Some hardware gets it MAC address out of local flash memory.
179 * if this is non-zero then assume it is the address to get MAC from.
180 */
181#if defined(CONFIG_NETtel)
182#define FEC_FLASHMAC 0xf0006006
183#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
184#define FEC_FLASHMAC 0xf0006000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#elif defined(CONFIG_CANCam)
186#define FEC_FLASHMAC 0xf0020000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000187#elif defined (CONFIG_M5272C3)
188#define FEC_FLASHMAC (0xffe04000 + 4)
189#elif defined(CONFIG_MOD5272)
Lothar Waßmanna7dd3212011-12-07 21:59:25 +0000190#define FEC_FLASHMAC 0xffc0406b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#else
192#define FEC_FLASHMAC 0
193#endif
Greg Ungerer43be6362009-02-26 22:42:51 -0800194#endif /* CONFIG_M5272 */
Sascha Haueread73182009-01-28 23:03:11 +0000195
Sascha Hauer22f6b862009-04-15 01:32:18 +0000196/* Interrupt events/masks. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
198#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
199#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
200#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
201#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
202#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
203#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
204#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
205#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
206#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
207
Wolfram Sang4bee1f92010-07-21 02:51:13 +0000208#define FEC_DEFAULT_IMASK (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII)
Frank Lidc975382013-01-28 18:31:42 +0000209#define FEC_RX_DISABLED_IMASK (FEC_DEFAULT_IMASK & (~FEC_ENET_RXF))
Wolfram Sang4bee1f92010-07-21 02:51:13 +0000210
Jim Baxtercdffcf12013-07-02 22:52:56 +0100211/* The FEC stores dest/src/type/vlan, data, and checksum for receive packets.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 */
Jim Baxtercdffcf12013-07-02 22:52:56 +0100213#define PKT_MAXBUF_SIZE 1522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define PKT_MINBUF_SIZE 64
Jim Baxtercdffcf12013-07-02 22:52:56 +0100215#define PKT_MAXBLR_SIZE 1536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Jim Baxter4c09eed2013-04-19 08:10:49 +0000217/* FEC receive acceleration */
218#define FEC_RACC_IPDIS (1 << 1)
219#define FEC_RACC_PRODIS (1 << 2)
220#define FEC_RACC_OPTIONS (FEC_RACC_IPDIS | FEC_RACC_PRODIS)
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*
Matt Waddel6b265292006-06-27 13:10:56 +1000223 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 * size bits. Other FEC hardware does not, so we need to take that into
225 * account when setting it.
226 */
Greg Ungerer562d2f82005-11-07 14:09:50 +1000227#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
Uwe Kleine-König085e79e2011-01-17 09:52:18 +0100228 defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
230#else
231#define OPT_FRAME_SIZE 0
232#endif
233
Bryan Wue6b043d2010-03-31 02:10:44 +0000234/* FEC MII MMFR bits definition */
235#define FEC_MMFR_ST (1 << 30)
236#define FEC_MMFR_OP_READ (2 << 28)
237#define FEC_MMFR_OP_WRITE (1 << 28)
238#define FEC_MMFR_PA(v) ((v & 0x1f) << 23)
239#define FEC_MMFR_RA(v) ((v & 0x1f) << 18)
240#define FEC_MMFR_TA (2 << 16)
241#define FEC_MMFR_DATA(v) (v & 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Rogerio Pimentelc3b084c2011-12-27 14:07:37 -0500243#define FEC_MII_TIMEOUT 30000 /* us */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Sascha Hauer22f6b862009-04-15 01:32:18 +0000245/* Transmitter timeout */
246#define TX_TIMEOUT (2 * HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Frank Libaa70a52013-01-16 16:55:58 +0000248#define FEC_PAUSE_FLAG_AUTONEG 0x1
249#define FEC_PAUSE_FLAG_ENABLE 0x2
250
Nimrod Andy79f33912014-06-12 08:16:23 +0800251#define TSO_HEADER_SIZE 128
252/* Max number of allowed TCP segments for software TSO */
253#define FEC_MAX_TSO_SEGS 100
254#define FEC_MAX_SKB_DESCS (FEC_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
255
256#define IS_TSO_HEADER(txq, addr) \
257 ((addr >= txq->tso_hdrs_dma) && \
258 (addr < txq->tso_hdrs_dma + txq->tx_ring_size * TSO_HEADER_SIZE))
259
Lothar Waßmanne163cc92011-12-07 21:59:31 +0000260static int mii_cnt;
261
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800262static inline
Fugang Duan4d494cd2014-09-13 05:00:48 +0800263struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp,
264 struct fec_enet_private *fep,
265 int queue_id)
Frank Liff43da82013-01-03 16:04:23 +0000266{
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800267 struct bufdesc *new_bd = bdp + 1;
268 struct bufdesc_ex *ex_new_bd = (struct bufdesc_ex *)bdp + 1;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800269 struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue_id];
270 struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue_id];
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800271 struct bufdesc_ex *ex_base;
272 struct bufdesc *base;
273 int ring_size;
274
Fugang Duan4d494cd2014-09-13 05:00:48 +0800275 if (bdp >= txq->tx_bd_base) {
276 base = txq->tx_bd_base;
277 ring_size = txq->tx_ring_size;
278 ex_base = (struct bufdesc_ex *)txq->tx_bd_base;
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800279 } else {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800280 base = rxq->rx_bd_base;
281 ring_size = rxq->rx_ring_size;
282 ex_base = (struct bufdesc_ex *)rxq->rx_bd_base;
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800283 }
284
285 if (fep->bufdesc_ex)
286 return (struct bufdesc *)((ex_new_bd >= (ex_base + ring_size)) ?
287 ex_base : ex_new_bd);
Frank Liff43da82013-01-03 16:04:23 +0000288 else
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800289 return (new_bd >= (base + ring_size)) ?
290 base : new_bd;
Frank Liff43da82013-01-03 16:04:23 +0000291}
292
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800293static inline
Fugang Duan4d494cd2014-09-13 05:00:48 +0800294struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp,
295 struct fec_enet_private *fep,
296 int queue_id)
Frank Liff43da82013-01-03 16:04:23 +0000297{
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800298 struct bufdesc *new_bd = bdp - 1;
299 struct bufdesc_ex *ex_new_bd = (struct bufdesc_ex *)bdp - 1;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800300 struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue_id];
301 struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue_id];
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800302 struct bufdesc_ex *ex_base;
303 struct bufdesc *base;
304 int ring_size;
305
Fugang Duan4d494cd2014-09-13 05:00:48 +0800306 if (bdp >= txq->tx_bd_base) {
307 base = txq->tx_bd_base;
308 ring_size = txq->tx_ring_size;
309 ex_base = (struct bufdesc_ex *)txq->tx_bd_base;
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800310 } else {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800311 base = rxq->rx_bd_base;
312 ring_size = rxq->rx_ring_size;
313 ex_base = (struct bufdesc_ex *)rxq->rx_bd_base;
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800314 }
315
316 if (fep->bufdesc_ex)
317 return (struct bufdesc *)((ex_new_bd < ex_base) ?
318 (ex_new_bd + ring_size) : ex_new_bd);
Frank Liff43da82013-01-03 16:04:23 +0000319 else
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +0800320 return (new_bd < base) ? (new_bd + ring_size) : new_bd;
Frank Liff43da82013-01-03 16:04:23 +0000321}
322
Nimrod Andy61a44272014-06-12 08:16:18 +0800323static int fec_enet_get_bd_index(struct bufdesc *base, struct bufdesc *bdp,
324 struct fec_enet_private *fep)
325{
326 return ((const char *)bdp - (const char *)base) / fep->bufdesc_size;
327}
328
Fugang Duan4d494cd2014-09-13 05:00:48 +0800329static int fec_enet_get_free_txdesc_num(struct fec_enet_private *fep,
330 struct fec_enet_priv_tx_q *txq)
Nimrod Andy6e909282014-06-12 08:16:22 +0800331{
332 int entries;
333
Fugang Duan4d494cd2014-09-13 05:00:48 +0800334 entries = ((const char *)txq->dirty_tx -
335 (const char *)txq->cur_tx) / fep->bufdesc_size - 1;
Nimrod Andy6e909282014-06-12 08:16:22 +0800336
Fugang Duan4d494cd2014-09-13 05:00:48 +0800337 return entries > 0 ? entries : entries + txq->tx_ring_size;
Nimrod Andy6e909282014-06-12 08:16:22 +0800338}
339
Shawn Guob5680e02011-01-05 21:13:13 +0000340static void *swap_buffer(void *bufaddr, int len)
341{
342 int i;
343 unsigned int *buf = bufaddr;
344
Fabio Estevamffed61e2013-05-21 05:44:26 +0000345 for (i = 0; i < DIV_ROUND_UP(len, 4); i++, buf++)
Shawn Guob5680e02011-01-05 21:13:13 +0000346 *buf = cpu_to_be32(*buf);
347
348 return bufaddr;
349}
350
Russell King344756f2014-07-08 13:01:59 +0100351static void fec_dump(struct net_device *ndev)
352{
353 struct fec_enet_private *fep = netdev_priv(ndev);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800354 struct bufdesc *bdp;
355 struct fec_enet_priv_tx_q *txq;
356 int index = 0;
Russell King344756f2014-07-08 13:01:59 +0100357
358 netdev_info(ndev, "TX ring dump\n");
359 pr_info("Nr SC addr len SKB\n");
360
Fugang Duan4d494cd2014-09-13 05:00:48 +0800361 txq = fep->tx_queue[0];
362 bdp = txq->tx_bd_base;
363
Russell King344756f2014-07-08 13:01:59 +0100364 do {
365 pr_info("%3u %c%c 0x%04x 0x%08lx %4u %p\n",
366 index,
Fugang Duan4d494cd2014-09-13 05:00:48 +0800367 bdp == txq->cur_tx ? 'S' : ' ',
368 bdp == txq->dirty_tx ? 'H' : ' ',
Russell King344756f2014-07-08 13:01:59 +0100369 bdp->cbd_sc, bdp->cbd_bufaddr, bdp->cbd_datlen,
Fugang Duan4d494cd2014-09-13 05:00:48 +0800370 txq->tx_skbuff[index]);
371 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Russell King344756f2014-07-08 13:01:59 +0100372 index++;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800373 } while (bdp != txq->tx_bd_base);
Russell King344756f2014-07-08 13:01:59 +0100374}
375
Fugang Duan62a02c92014-06-18 08:33:52 +0800376static inline bool is_ipv4_pkt(struct sk_buff *skb)
377{
378 return skb->protocol == htons(ETH_P_IP) && ip_hdr(skb)->version == 4;
379}
380
Jim Baxter4c09eed2013-04-19 08:10:49 +0000381static int
382fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)
383{
384 /* Only run for packets requiring a checksum. */
385 if (skb->ip_summed != CHECKSUM_PARTIAL)
386 return 0;
387
388 if (unlikely(skb_cow_head(skb, 0)))
389 return -1;
390
Fugang Duan62a02c92014-06-18 08:33:52 +0800391 if (is_ipv4_pkt(skb))
392 ip_hdr(skb)->check = 0;
Jim Baxter4c09eed2013-04-19 08:10:49 +0000393 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
394
395 return 0;
396}
397
Nimrod Andy6e909282014-06-12 08:16:22 +0800398static int
Fugang Duan4d494cd2014-09-13 05:00:48 +0800399fec_enet_txq_submit_frag_skb(struct fec_enet_priv_tx_q *txq,
400 struct sk_buff *skb,
401 struct net_device *ndev)
Nimrod Andy6e909282014-06-12 08:16:22 +0800402{
403 struct fec_enet_private *fep = netdev_priv(ndev);
404 const struct platform_device_id *id_entry =
405 platform_get_device_id(fep->pdev);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800406 struct bufdesc *bdp = txq->cur_tx;
Nimrod Andy6e909282014-06-12 08:16:22 +0800407 struct bufdesc_ex *ebdp;
408 int nr_frags = skb_shinfo(skb)->nr_frags;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800409 unsigned short queue = skb_get_queue_mapping(skb);
Nimrod Andy6e909282014-06-12 08:16:22 +0800410 int frag, frag_len;
411 unsigned short status;
412 unsigned int estatus = 0;
413 skb_frag_t *this_frag;
414 unsigned int index;
415 void *bufaddr;
Russell Kingd6bf3142014-07-08 00:23:19 +0100416 dma_addr_t addr;
Nimrod Andy6e909282014-06-12 08:16:22 +0800417 int i;
418
419 for (frag = 0; frag < nr_frags; frag++) {
420 this_frag = &skb_shinfo(skb)->frags[frag];
Fugang Duan4d494cd2014-09-13 05:00:48 +0800421 bdp = fec_enet_get_nextdesc(bdp, fep, queue);
Nimrod Andy6e909282014-06-12 08:16:22 +0800422 ebdp = (struct bufdesc_ex *)bdp;
423
424 status = bdp->cbd_sc;
425 status &= ~BD_ENET_TX_STATS;
426 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
427 frag_len = skb_shinfo(skb)->frags[frag].size;
428
429 /* Handle the last BD specially */
430 if (frag == nr_frags - 1) {
431 status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST);
432 if (fep->bufdesc_ex) {
433 estatus |= BD_ENET_TX_INT;
434 if (unlikely(skb_shinfo(skb)->tx_flags &
435 SKBTX_HW_TSTAMP && fep->hwts_tx_en))
436 estatus |= BD_ENET_TX_TS;
437 }
438 }
439
440 if (fep->bufdesc_ex) {
441 if (skb->ip_summed == CHECKSUM_PARTIAL)
442 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
443 ebdp->cbd_bdu = 0;
444 ebdp->cbd_esc = estatus;
445 }
446
447 bufaddr = page_address(this_frag->page.p) + this_frag->page_offset;
448
Fugang Duan4d494cd2014-09-13 05:00:48 +0800449 index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep);
Nimrod Andy6e909282014-06-12 08:16:22 +0800450 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
451 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800452 memcpy(txq->tx_bounce[index], bufaddr, frag_len);
453 bufaddr = txq->tx_bounce[index];
Nimrod Andy6e909282014-06-12 08:16:22 +0800454
455 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
456 swap_buffer(bufaddr, frag_len);
457 }
458
Russell Kingd6bf3142014-07-08 00:23:19 +0100459 addr = dma_map_single(&fep->pdev->dev, bufaddr, frag_len,
460 DMA_TO_DEVICE);
461 if (dma_mapping_error(&fep->pdev->dev, addr)) {
Nimrod Andy6e909282014-06-12 08:16:22 +0800462 dev_kfree_skb_any(skb);
463 if (net_ratelimit())
464 netdev_err(ndev, "Tx DMA memory map failed\n");
465 goto dma_mapping_error;
466 }
467
Russell Kingd6bf3142014-07-08 00:23:19 +0100468 bdp->cbd_bufaddr = addr;
Nimrod Andy6e909282014-06-12 08:16:22 +0800469 bdp->cbd_datlen = frag_len;
470 bdp->cbd_sc = status;
471 }
472
Fugang Duan4d494cd2014-09-13 05:00:48 +0800473 txq->cur_tx = bdp;
Nimrod Andy6e909282014-06-12 08:16:22 +0800474
475 return 0;
476
477dma_mapping_error:
Fugang Duan4d494cd2014-09-13 05:00:48 +0800478 bdp = txq->cur_tx;
Nimrod Andy6e909282014-06-12 08:16:22 +0800479 for (i = 0; i < frag; i++) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800480 bdp = fec_enet_get_nextdesc(bdp, fep, queue);
Nimrod Andy6e909282014-06-12 08:16:22 +0800481 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
482 bdp->cbd_datlen, DMA_TO_DEVICE);
483 }
484 return NETDEV_TX_OK;
485}
486
Fugang Duan4d494cd2014-09-13 05:00:48 +0800487static int fec_enet_txq_submit_skb(struct fec_enet_priv_tx_q *txq,
488 struct sk_buff *skb, struct net_device *ndev)
Nimrod Andy6e909282014-06-12 08:16:22 +0800489{
490 struct fec_enet_private *fep = netdev_priv(ndev);
491 const struct platform_device_id *id_entry =
492 platform_get_device_id(fep->pdev);
493 int nr_frags = skb_shinfo(skb)->nr_frags;
494 struct bufdesc *bdp, *last_bdp;
495 void *bufaddr;
Russell Kingd6bf3142014-07-08 00:23:19 +0100496 dma_addr_t addr;
Nimrod Andy6e909282014-06-12 08:16:22 +0800497 unsigned short status;
498 unsigned short buflen;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800499 unsigned short queue;
Nimrod Andy6e909282014-06-12 08:16:22 +0800500 unsigned int estatus = 0;
501 unsigned int index;
Nimrod Andy79f33912014-06-12 08:16:23 +0800502 int entries_free;
Nimrod Andy6e909282014-06-12 08:16:22 +0800503 int ret;
504
Fugang Duan4d494cd2014-09-13 05:00:48 +0800505 entries_free = fec_enet_get_free_txdesc_num(fep, txq);
Nimrod Andy79f33912014-06-12 08:16:23 +0800506 if (entries_free < MAX_SKB_FRAGS + 1) {
507 dev_kfree_skb_any(skb);
508 if (net_ratelimit())
509 netdev_err(ndev, "NOT enough BD for SG!\n");
510 return NETDEV_TX_OK;
511 }
512
Nimrod Andy6e909282014-06-12 08:16:22 +0800513 /* Protocol checksum off-load for TCP and UDP. */
514 if (fec_enet_clear_csum(skb, ndev)) {
515 dev_kfree_skb_any(skb);
516 return NETDEV_TX_OK;
517 }
518
519 /* Fill in a Tx ring entry */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800520 bdp = txq->cur_tx;
Nimrod Andy6e909282014-06-12 08:16:22 +0800521 status = bdp->cbd_sc;
522 status &= ~BD_ENET_TX_STATS;
523
524 /* Set buffer length and buffer pointer */
525 bufaddr = skb->data;
526 buflen = skb_headlen(skb);
527
Fugang Duan4d494cd2014-09-13 05:00:48 +0800528 queue = skb_get_queue_mapping(skb);
529 index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep);
Nimrod Andy6e909282014-06-12 08:16:22 +0800530 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
531 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800532 memcpy(txq->tx_bounce[index], skb->data, buflen);
533 bufaddr = txq->tx_bounce[index];
Nimrod Andy6e909282014-06-12 08:16:22 +0800534
535 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
536 swap_buffer(bufaddr, buflen);
537 }
538
Russell Kingd6bf3142014-07-08 00:23:19 +0100539 /* Push the data cache so the CPM does not get stale memory data. */
540 addr = dma_map_single(&fep->pdev->dev, bufaddr, buflen, DMA_TO_DEVICE);
541 if (dma_mapping_error(&fep->pdev->dev, addr)) {
Nimrod Andy6e909282014-06-12 08:16:22 +0800542 dev_kfree_skb_any(skb);
543 if (net_ratelimit())
544 netdev_err(ndev, "Tx DMA memory map failed\n");
545 return NETDEV_TX_OK;
546 }
547
548 if (nr_frags) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800549 ret = fec_enet_txq_submit_frag_skb(txq, skb, ndev);
Nimrod Andy6e909282014-06-12 08:16:22 +0800550 if (ret)
551 return ret;
552 } else {
553 status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST);
554 if (fep->bufdesc_ex) {
555 estatus = BD_ENET_TX_INT;
556 if (unlikely(skb_shinfo(skb)->tx_flags &
557 SKBTX_HW_TSTAMP && fep->hwts_tx_en))
558 estatus |= BD_ENET_TX_TS;
559 }
560 }
561
562 if (fep->bufdesc_ex) {
563
564 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
565
566 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
567 fep->hwts_tx_en))
568 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
569
570 if (skb->ip_summed == CHECKSUM_PARTIAL)
571 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
572
573 ebdp->cbd_bdu = 0;
574 ebdp->cbd_esc = estatus;
575 }
576
Fugang Duan4d494cd2014-09-13 05:00:48 +0800577 last_bdp = txq->cur_tx;
578 index = fec_enet_get_bd_index(txq->tx_bd_base, last_bdp, fep);
Nimrod Andy6e909282014-06-12 08:16:22 +0800579 /* Save skb pointer */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800580 txq->tx_skbuff[index] = skb;
Nimrod Andy6e909282014-06-12 08:16:22 +0800581
582 bdp->cbd_datlen = buflen;
Russell Kingd6bf3142014-07-08 00:23:19 +0100583 bdp->cbd_bufaddr = addr;
Nimrod Andy6e909282014-06-12 08:16:22 +0800584
585 /* Send it on its way. Tell FEC it's ready, interrupt when done,
586 * it's the last BD of the frame, and to put the CRC on the end.
587 */
588 status |= (BD_ENET_TX_READY | BD_ENET_TX_TC);
589 bdp->cbd_sc = status;
590
Sascha Hauer22f6b862009-04-15 01:32:18 +0000591 /* If this was the last BD in the ring, start at the beginning again. */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800592 bdp = fec_enet_get_nextdesc(last_bdp, fep, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Eric Dumazet7a2a8452013-12-19 10:53:02 -0800594 skb_tx_timestamp(skb);
595
Fugang Duan4d494cd2014-09-13 05:00:48 +0800596 txq->cur_tx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Frank Lide5fb0a2013-03-03 17:34:25 +0000598 /* Trigger transmission start */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800599 writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue));
Frank Lide5fb0a2013-03-03 17:34:25 +0000600
Nimrod Andy6e909282014-06-12 08:16:22 +0800601 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
Nimrod Andy79f33912014-06-12 08:16:23 +0800604static int
Fugang Duan4d494cd2014-09-13 05:00:48 +0800605fec_enet_txq_put_data_tso(struct fec_enet_priv_tx_q *txq, struct sk_buff *skb,
606 struct net_device *ndev,
607 struct bufdesc *bdp, int index, char *data,
608 int size, bool last_tcp, bool is_last)
Nimrod Andy79f33912014-06-12 08:16:23 +0800609{
610 struct fec_enet_private *fep = netdev_priv(ndev);
611 const struct platform_device_id *id_entry =
612 platform_get_device_id(fep->pdev);
613 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
614 unsigned short status;
615 unsigned int estatus = 0;
Russell Kingd6bf3142014-07-08 00:23:19 +0100616 dma_addr_t addr;
Nimrod Andy79f33912014-06-12 08:16:23 +0800617
618 status = bdp->cbd_sc;
619 status &= ~BD_ENET_TX_STATS;
620
621 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
Nimrod Andy79f33912014-06-12 08:16:23 +0800622
623 if (((unsigned long) data) & FEC_ALIGNMENT ||
624 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800625 memcpy(txq->tx_bounce[index], data, size);
626 data = txq->tx_bounce[index];
Nimrod Andy79f33912014-06-12 08:16:23 +0800627
628 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
629 swap_buffer(data, size);
630 }
631
Russell Kingd6bf3142014-07-08 00:23:19 +0100632 addr = dma_map_single(&fep->pdev->dev, data, size, DMA_TO_DEVICE);
633 if (dma_mapping_error(&fep->pdev->dev, addr)) {
Nimrod Andy79f33912014-06-12 08:16:23 +0800634 dev_kfree_skb_any(skb);
635 if (net_ratelimit())
636 netdev_err(ndev, "Tx DMA memory map failed\n");
637 return NETDEV_TX_BUSY;
638 }
639
Russell Kingd6bf3142014-07-08 00:23:19 +0100640 bdp->cbd_datlen = size;
641 bdp->cbd_bufaddr = addr;
642
Nimrod Andy79f33912014-06-12 08:16:23 +0800643 if (fep->bufdesc_ex) {
644 if (skb->ip_summed == CHECKSUM_PARTIAL)
645 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
646 ebdp->cbd_bdu = 0;
647 ebdp->cbd_esc = estatus;
648 }
649
650 /* Handle the last BD specially */
651 if (last_tcp)
652 status |= (BD_ENET_TX_LAST | BD_ENET_TX_TC);
653 if (is_last) {
654 status |= BD_ENET_TX_INTR;
655 if (fep->bufdesc_ex)
656 ebdp->cbd_esc |= BD_ENET_TX_INT;
657 }
658
659 bdp->cbd_sc = status;
660
661 return 0;
662}
663
664static int
Fugang Duan4d494cd2014-09-13 05:00:48 +0800665fec_enet_txq_put_hdr_tso(struct fec_enet_priv_tx_q *txq,
666 struct sk_buff *skb, struct net_device *ndev,
667 struct bufdesc *bdp, int index)
Nimrod Andy79f33912014-06-12 08:16:23 +0800668{
669 struct fec_enet_private *fep = netdev_priv(ndev);
670 const struct platform_device_id *id_entry =
671 platform_get_device_id(fep->pdev);
672 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
673 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
674 void *bufaddr;
675 unsigned long dmabuf;
676 unsigned short status;
677 unsigned int estatus = 0;
678
679 status = bdp->cbd_sc;
680 status &= ~BD_ENET_TX_STATS;
681 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
682
Fugang Duan4d494cd2014-09-13 05:00:48 +0800683 bufaddr = txq->tso_hdrs + index * TSO_HEADER_SIZE;
684 dmabuf = txq->tso_hdrs_dma + index * TSO_HEADER_SIZE;
Nimrod Andy79f33912014-06-12 08:16:23 +0800685 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
686 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800687 memcpy(txq->tx_bounce[index], skb->data, hdr_len);
688 bufaddr = txq->tx_bounce[index];
Nimrod Andy79f33912014-06-12 08:16:23 +0800689
690 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
691 swap_buffer(bufaddr, hdr_len);
692
693 dmabuf = dma_map_single(&fep->pdev->dev, bufaddr,
694 hdr_len, DMA_TO_DEVICE);
695 if (dma_mapping_error(&fep->pdev->dev, dmabuf)) {
696 dev_kfree_skb_any(skb);
697 if (net_ratelimit())
698 netdev_err(ndev, "Tx DMA memory map failed\n");
699 return NETDEV_TX_BUSY;
700 }
701 }
702
703 bdp->cbd_bufaddr = dmabuf;
704 bdp->cbd_datlen = hdr_len;
705
706 if (fep->bufdesc_ex) {
707 if (skb->ip_summed == CHECKSUM_PARTIAL)
708 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
709 ebdp->cbd_bdu = 0;
710 ebdp->cbd_esc = estatus;
711 }
712
713 bdp->cbd_sc = status;
714
715 return 0;
716}
717
Fugang Duan4d494cd2014-09-13 05:00:48 +0800718static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq,
719 struct sk_buff *skb,
720 struct net_device *ndev)
Nimrod Andy79f33912014-06-12 08:16:23 +0800721{
722 struct fec_enet_private *fep = netdev_priv(ndev);
723 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
724 int total_len, data_left;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800725 struct bufdesc *bdp = txq->cur_tx;
726 unsigned short queue = skb_get_queue_mapping(skb);
Nimrod Andy79f33912014-06-12 08:16:23 +0800727 struct tso_t tso;
728 unsigned int index = 0;
729 int ret;
730
Fugang Duan4d494cd2014-09-13 05:00:48 +0800731 if (tso_count_descs(skb) >= fec_enet_get_free_txdesc_num(fep, txq)) {
Nimrod Andy79f33912014-06-12 08:16:23 +0800732 dev_kfree_skb_any(skb);
733 if (net_ratelimit())
734 netdev_err(ndev, "NOT enough BD for TSO!\n");
735 return NETDEV_TX_OK;
736 }
737
738 /* Protocol checksum off-load for TCP and UDP. */
739 if (fec_enet_clear_csum(skb, ndev)) {
740 dev_kfree_skb_any(skb);
741 return NETDEV_TX_OK;
742 }
743
744 /* Initialize the TSO handler, and prepare the first payload */
745 tso_start(skb, &tso);
746
747 total_len = skb->len - hdr_len;
748 while (total_len > 0) {
749 char *hdr;
750
Fugang Duan4d494cd2014-09-13 05:00:48 +0800751 index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep);
Nimrod Andy79f33912014-06-12 08:16:23 +0800752 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
753 total_len -= data_left;
754
755 /* prepare packet headers: MAC + IP + TCP */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800756 hdr = txq->tso_hdrs + index * TSO_HEADER_SIZE;
Nimrod Andy79f33912014-06-12 08:16:23 +0800757 tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800758 ret = fec_enet_txq_put_hdr_tso(txq, skb, ndev, bdp, index);
Nimrod Andy79f33912014-06-12 08:16:23 +0800759 if (ret)
760 goto err_release;
761
762 while (data_left > 0) {
763 int size;
764
765 size = min_t(int, tso.size, data_left);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800766 bdp = fec_enet_get_nextdesc(bdp, fep, queue);
767 index = fec_enet_get_bd_index(txq->tx_bd_base,
768 bdp, fep);
769 ret = fec_enet_txq_put_data_tso(txq, skb, ndev,
770 bdp, index,
771 tso.data, size,
772 size == data_left,
Nimrod Andy79f33912014-06-12 08:16:23 +0800773 total_len == 0);
774 if (ret)
775 goto err_release;
776
777 data_left -= size;
778 tso_build_data(skb, &tso, size);
779 }
780
Fugang Duan4d494cd2014-09-13 05:00:48 +0800781 bdp = fec_enet_get_nextdesc(bdp, fep, queue);
Nimrod Andy79f33912014-06-12 08:16:23 +0800782 }
783
784 /* Save skb pointer */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800785 txq->tx_skbuff[index] = skb;
Nimrod Andy79f33912014-06-12 08:16:23 +0800786
Nimrod Andy79f33912014-06-12 08:16:23 +0800787 skb_tx_timestamp(skb);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800788 txq->cur_tx = bdp;
Nimrod Andy79f33912014-06-12 08:16:23 +0800789
790 /* Trigger transmission start */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800791 writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue));
Nimrod Andy79f33912014-06-12 08:16:23 +0800792
793 return 0;
794
795err_release:
796 /* TODO: Release all used data descriptors for TSO */
797 return ret;
798}
799
Nimrod Andy61a44272014-06-12 08:16:18 +0800800static netdev_tx_t
801fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
802{
803 struct fec_enet_private *fep = netdev_priv(ndev);
Nimrod Andy6e909282014-06-12 08:16:22 +0800804 int entries_free;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800805 unsigned short queue;
806 struct fec_enet_priv_tx_q *txq;
807 struct netdev_queue *nq;
Nimrod Andy61a44272014-06-12 08:16:18 +0800808 int ret;
809
Fugang Duan4d494cd2014-09-13 05:00:48 +0800810 queue = skb_get_queue_mapping(skb);
811 txq = fep->tx_queue[queue];
812 nq = netdev_get_tx_queue(ndev, queue);
813
Nimrod Andy79f33912014-06-12 08:16:23 +0800814 if (skb_is_gso(skb))
Fugang Duan4d494cd2014-09-13 05:00:48 +0800815 ret = fec_enet_txq_submit_tso(txq, skb, ndev);
Nimrod Andy79f33912014-06-12 08:16:23 +0800816 else
Fugang Duan4d494cd2014-09-13 05:00:48 +0800817 ret = fec_enet_txq_submit_skb(txq, skb, ndev);
Nimrod Andy6e909282014-06-12 08:16:22 +0800818 if (ret)
819 return ret;
Nimrod Andy61a44272014-06-12 08:16:18 +0800820
Fugang Duan4d494cd2014-09-13 05:00:48 +0800821 entries_free = fec_enet_get_free_txdesc_num(fep, txq);
822 if (entries_free <= txq->tx_stop_threshold)
823 netif_tx_stop_queue(nq);
Nimrod Andy61a44272014-06-12 08:16:18 +0800824
825 return NETDEV_TX_OK;
826}
827
Frank Li14109a52013-03-26 16:12:03 +0000828/* Init RX & TX buffer descriptors
829 */
830static void fec_enet_bd_init(struct net_device *dev)
831{
832 struct fec_enet_private *fep = netdev_priv(dev);
Fugang Duan4d494cd2014-09-13 05:00:48 +0800833 struct fec_enet_priv_tx_q *txq;
834 struct fec_enet_priv_rx_q *rxq;
Frank Li14109a52013-03-26 16:12:03 +0000835 struct bufdesc *bdp;
836 unsigned int i;
837
838 /* Initialize the receive buffer descriptors. */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800839 rxq = fep->rx_queue[0];
840 bdp = rxq->rx_bd_base;
841
842 for (i = 0; i < rxq->rx_ring_size; i++) {
Frank Li14109a52013-03-26 16:12:03 +0000843
844 /* Initialize the BD for every fragment in the page. */
845 if (bdp->cbd_bufaddr)
846 bdp->cbd_sc = BD_ENET_RX_EMPTY;
847 else
848 bdp->cbd_sc = 0;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800849 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Frank Li14109a52013-03-26 16:12:03 +0000850 }
851
852 /* Set the last buffer to wrap */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800853 bdp = fec_enet_get_prevdesc(bdp, fep, 0);
Frank Li14109a52013-03-26 16:12:03 +0000854 bdp->cbd_sc |= BD_SC_WRAP;
855
Fugang Duan4d494cd2014-09-13 05:00:48 +0800856 rxq->cur_rx = rxq->rx_bd_base;
Frank Li14109a52013-03-26 16:12:03 +0000857
858 /* ...and the same for transmit */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800859 txq = fep->tx_queue[0];
860 bdp = txq->tx_bd_base;
861 txq->cur_tx = bdp;
Frank Li14109a52013-03-26 16:12:03 +0000862
Fugang Duan4d494cd2014-09-13 05:00:48 +0800863 for (i = 0; i < txq->tx_ring_size; i++) {
Frank Li14109a52013-03-26 16:12:03 +0000864 /* Initialize the BD for every fragment in the page. */
865 bdp->cbd_sc = 0;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800866 if (txq->tx_skbuff[i]) {
867 dev_kfree_skb_any(txq->tx_skbuff[i]);
868 txq->tx_skbuff[i] = NULL;
Frank Li14109a52013-03-26 16:12:03 +0000869 }
870 bdp->cbd_bufaddr = 0;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800871 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Frank Li14109a52013-03-26 16:12:03 +0000872 }
873
874 /* Set the last buffer to wrap */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800875 bdp = fec_enet_get_prevdesc(bdp, fep, 0);
Frank Li14109a52013-03-26 16:12:03 +0000876 bdp->cbd_sc |= BD_SC_WRAP;
Fugang Duan4d494cd2014-09-13 05:00:48 +0800877 txq->dirty_tx = bdp;
Frank Li14109a52013-03-26 16:12:03 +0000878}
879
Russell Kingdbc64a82014-07-08 12:40:12 +0100880/*
881 * This function is called to start or restart the FEC during a link
882 * change, transmit timeout, or to reconfigure the FEC. The network
883 * packet processing for this device must be stopped before this call.
Uwe Kleine-König45993652011-01-19 20:47:04 +0100884 */
885static void
Russell Kingef833372014-07-08 12:40:43 +0100886fec_restart(struct net_device *ndev)
Uwe Kleine-König45993652011-01-19 20:47:04 +0100887{
888 struct fec_enet_private *fep = netdev_priv(ndev);
889 const struct platform_device_id *id_entry =
890 platform_get_device_id(fep->pdev);
891 int i;
Jim Baxter4c09eed2013-04-19 08:10:49 +0000892 u32 val;
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100893 u32 temp_mac[2];
894 u32 rcntl = OPT_FRAME_SIZE | 0x04;
Shawn Guo230dec62011-09-23 02:12:48 +0000895 u32 ecntl = 0x2; /* ETHEREN */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800896 struct fec_enet_priv_tx_q *txq;
897 struct fec_enet_priv_rx_q *rxq;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100898
899 /* Whack a reset. We should wait for this. */
900 writel(1, fep->hwp + FEC_ECNTRL);
901 udelay(10);
902
903 /*
904 * enet-mac reset will reset mac address registers too,
905 * so need to reconfigure it.
906 */
907 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
908 memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
909 writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
910 writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
911 }
912
913 /* Clear any outstanding interrupt. */
914 writel(0xffc00000, fep->hwp + FEC_IEVENT);
915
Uwe Kleine-König45993652011-01-19 20:47:04 +0100916 /* Set maximum receive buffer size. */
917 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
918
Frank Li14109a52013-03-26 16:12:03 +0000919 fec_enet_bd_init(ndev);
920
Uwe Kleine-König45993652011-01-19 20:47:04 +0100921 /* Set receive and transmit descriptor base. */
Fugang Duan4d494cd2014-09-13 05:00:48 +0800922 rxq = fep->rx_queue[0];
923 writel(rxq->bd_dma, fep->hwp + FEC_R_DES_START(0));
Frank Liff43da82013-01-03 16:04:23 +0000924 if (fep->bufdesc_ex)
Fugang Duan4d494cd2014-09-13 05:00:48 +0800925 writel((unsigned long)rxq->bd_dma + sizeof(struct bufdesc_ex)
926 * rxq->rx_ring_size, fep->hwp + FEC_X_DES_START(0));
Frank Liff43da82013-01-03 16:04:23 +0000927 else
Fugang Duan4d494cd2014-09-13 05:00:48 +0800928 writel((unsigned long)rxq->bd_dma + sizeof(struct bufdesc)
929 * rxq->rx_ring_size, fep->hwp + FEC_X_DES_START(0));
Uwe Kleine-König45993652011-01-19 20:47:04 +0100930
Uwe Kleine-König45993652011-01-19 20:47:04 +0100931
Fugang Duan4d494cd2014-09-13 05:00:48 +0800932 txq = fep->tx_queue[0];
Uwe Kleine-König45993652011-01-19 20:47:04 +0100933 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
Fugang Duan4d494cd2014-09-13 05:00:48 +0800934 if (txq->tx_skbuff[i]) {
935 dev_kfree_skb_any(txq->tx_skbuff[i]);
936 txq->tx_skbuff[i] = NULL;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100937 }
938 }
939
940 /* Enable MII mode */
Russell Kingef833372014-07-08 12:40:43 +0100941 if (fep->full_duplex == DUPLEX_FULL) {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100942 /* FD enable */
Uwe Kleine-König45993652011-01-19 20:47:04 +0100943 writel(0x04, fep->hwp + FEC_X_CNTRL);
944 } else {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100945 /* No Rcv on Xmit */
946 rcntl |= 0x02;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100947 writel(0x0, fep->hwp + FEC_X_CNTRL);
948 }
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100949
Uwe Kleine-König45993652011-01-19 20:47:04 +0100950 /* Set MII speed */
951 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
952
Guenter Roeckd1391932013-06-18 10:04:59 -0700953#if !defined(CONFIG_M5272)
Jim Baxter4c09eed2013-04-19 08:10:49 +0000954 /* set RX checksum */
955 val = readl(fep->hwp + FEC_RACC);
956 if (fep->csum_flags & FLAG_RX_CSUM_ENABLED)
957 val |= FEC_RACC_OPTIONS;
958 else
959 val &= ~FEC_RACC_OPTIONS;
960 writel(val, fep->hwp + FEC_RACC);
Guenter Roeckd1391932013-06-18 10:04:59 -0700961#endif
Jim Baxter4c09eed2013-04-19 08:10:49 +0000962
Uwe Kleine-König45993652011-01-19 20:47:04 +0100963 /*
964 * The phy interface and speed need to get configured
965 * differently on enet-mac.
966 */
967 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100968 /* Enable flow control and length check */
969 rcntl |= 0x40000000 | 0x00000020;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100970
Shawn Guo230dec62011-09-23 02:12:48 +0000971 /* RGMII, RMII or MII */
972 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII)
973 rcntl |= (1 << 6);
974 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100975 rcntl |= (1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100976 else
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100977 rcntl &= ~(1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100978
Shawn Guo230dec62011-09-23 02:12:48 +0000979 /* 1G, 100M or 10M */
980 if (fep->phy_dev) {
981 if (fep->phy_dev->speed == SPEED_1000)
982 ecntl |= (1 << 5);
983 else if (fep->phy_dev->speed == SPEED_100)
984 rcntl &= ~(1 << 9);
985 else
986 rcntl |= (1 << 9);
987 }
Uwe Kleine-König45993652011-01-19 20:47:04 +0100988 } else {
989#ifdef FEC_MIIGSK_ENR
Shawn Guo0ca1e292011-07-01 18:11:22 +0800990 if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
Eric Benard8d82f212012-01-12 06:10:28 +0000991 u32 cfgr;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100992 /* disable the gasket and wait */
993 writel(0, fep->hwp + FEC_MIIGSK_ENR);
994 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
995 udelay(1);
996
997 /*
998 * configure the gasket:
999 * RMII, 50 MHz, no loopback, no echo
Shawn Guo0ca1e292011-07-01 18:11:22 +08001000 * MII, 25 MHz, no loopback, no echo
Uwe Kleine-König45993652011-01-19 20:47:04 +01001001 */
Eric Benard8d82f212012-01-12 06:10:28 +00001002 cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
1003 ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
1004 if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
1005 cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
1006 writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001007
1008 /* re-enable the gasket */
1009 writel(2, fep->hwp + FEC_MIIGSK_ENR);
1010 }
1011#endif
1012 }
Frank Libaa70a52013-01-16 16:55:58 +00001013
Guenter Roeckd1391932013-06-18 10:04:59 -07001014#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00001015 /* enable pause frame*/
1016 if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) ||
1017 ((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) &&
1018 fep->phy_dev && fep->phy_dev->pause)) {
1019 rcntl |= FEC_ENET_FCE;
1020
Jim Baxter4c09eed2013-04-19 08:10:49 +00001021 /* set FIFO threshold parameter to reduce overrun */
Frank Libaa70a52013-01-16 16:55:58 +00001022 writel(FEC_ENET_RSEM_V, fep->hwp + FEC_R_FIFO_RSEM);
1023 writel(FEC_ENET_RSFL_V, fep->hwp + FEC_R_FIFO_RSFL);
1024 writel(FEC_ENET_RAEM_V, fep->hwp + FEC_R_FIFO_RAEM);
1025 writel(FEC_ENET_RAFL_V, fep->hwp + FEC_R_FIFO_RAFL);
1026
1027 /* OPD */
1028 writel(FEC_ENET_OPD_V, fep->hwp + FEC_OPD);
1029 } else {
1030 rcntl &= ~FEC_ENET_FCE;
1031 }
Guenter Roeckd1391932013-06-18 10:04:59 -07001032#endif /* !defined(CONFIG_M5272) */
Frank Libaa70a52013-01-16 16:55:58 +00001033
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +01001034 writel(rcntl, fep->hwp + FEC_R_CNTRL);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001035
Stefan Wahren84fe6182014-03-12 11:28:19 +01001036 /* Setup multicast filter. */
1037 set_multicast_list(ndev);
1038#ifndef CONFIG_M5272
1039 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
1040 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
1041#endif
1042
Shawn Guo230dec62011-09-23 02:12:48 +00001043 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
1044 /* enable ENET endian swap */
1045 ecntl |= (1 << 8);
1046 /* enable ENET store and forward mode */
1047 writel(1 << 8, fep->hwp + FEC_X_WMRK);
1048 }
1049
Frank Liff43da82013-01-03 16:04:23 +00001050 if (fep->bufdesc_ex)
1051 ecntl |= (1 << 4);
Frank Li6605b732012-10-30 18:25:31 +00001052
Chris Healy38ae92d2013-06-25 23:18:52 -07001053#ifndef CONFIG_M5272
Jim Baxterb9eef552013-07-01 14:57:54 +01001054 /* Enable the MIB statistic event counters */
1055 writel(0 << 31, fep->hwp + FEC_MIB_CTRLSTAT);
Chris Healy38ae92d2013-06-25 23:18:52 -07001056#endif
1057
Uwe Kleine-König45993652011-01-19 20:47:04 +01001058 /* And last, enable the transmit and receive processing */
Shawn Guo230dec62011-09-23 02:12:48 +00001059 writel(ecntl, fep->hwp + FEC_ECNTRL);
Fugang Duan4d494cd2014-09-13 05:00:48 +08001060 writel(0, fep->hwp + FEC_R_DES_ACTIVE(0));
Uwe Kleine-König45993652011-01-19 20:47:04 +01001061
Frank Liff43da82013-01-03 16:04:23 +00001062 if (fep->bufdesc_ex)
1063 fec_ptp_start_cyclecounter(ndev);
1064
Uwe Kleine-König45993652011-01-19 20:47:04 +01001065 /* Enable interrupts we wish to service */
1066 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
1067}
1068
1069static void
1070fec_stop(struct net_device *ndev)
1071{
1072 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo230dec62011-09-23 02:12:48 +00001073 const struct platform_device_id *id_entry =
1074 platform_get_device_id(fep->pdev);
Lothar Waßmann42431dc2011-12-07 21:59:30 +00001075 u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001076
1077 /* We cannot expect a graceful transmit stop without link !!! */
1078 if (fep->link) {
1079 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
1080 udelay(10);
1081 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
Joe Perches31b77202013-04-13 19:03:17 +00001082 netdev_err(ndev, "Graceful transmit stop did not complete!\n");
Uwe Kleine-König45993652011-01-19 20:47:04 +01001083 }
1084
1085 /* Whack a reset. We should wait for this. */
1086 writel(1, fep->hwp + FEC_ECNTRL);
1087 udelay(10);
1088 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1089 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
Shawn Guo230dec62011-09-23 02:12:48 +00001090
1091 /* We have to keep ENET enabled to have MII interrupt stay working */
Lothar Waßmann42431dc2011-12-07 21:59:30 +00001092 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
Shawn Guo230dec62011-09-23 02:12:48 +00001093 writel(2, fep->hwp + FEC_ECNTRL);
Lothar Waßmann42431dc2011-12-07 21:59:30 +00001094 writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
1095 }
Uwe Kleine-König45993652011-01-19 20:47:04 +01001096}
1097
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099static void
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001100fec_timeout(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001102 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Russell King344756f2014-07-08 13:01:59 +01001104 fec_dump(ndev);
1105
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001106 ndev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Russell King36cdc742014-07-08 13:01:44 +01001108 schedule_work(&fep->tx_timeout_work);
Frank Li54309fa2013-05-07 14:08:44 +00001109}
1110
Russell King36cdc742014-07-08 13:01:44 +01001111static void fec_enet_timeout_work(struct work_struct *work)
Frank Li54309fa2013-05-07 14:08:44 +00001112{
1113 struct fec_enet_private *fep =
Russell King36cdc742014-07-08 13:01:44 +01001114 container_of(work, struct fec_enet_private, tx_timeout_work);
Russell King8ce56242014-07-08 12:40:07 +01001115 struct net_device *ndev = fep->netdev;
Frank Li54309fa2013-05-07 14:08:44 +00001116
Russell King36cdc742014-07-08 13:01:44 +01001117 rtnl_lock();
1118 if (netif_device_present(ndev) || netif_running(ndev)) {
1119 napi_disable(&fep->napi);
1120 netif_tx_lock_bh(ndev);
1121 fec_restart(ndev);
1122 netif_wake_queue(ndev);
1123 netif_tx_unlock_bh(ndev);
1124 napi_enable(&fep->napi);
Frank Li54309fa2013-05-07 14:08:44 +00001125 }
Russell King36cdc742014-07-08 13:01:44 +01001126 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129static void
Russell Kingbfd4ecd2014-07-08 13:02:09 +01001130fec_enet_hwtstamp(struct fec_enet_private *fep, unsigned ts,
1131 struct skb_shared_hwtstamps *hwtstamps)
1132{
1133 unsigned long flags;
1134 u64 ns;
1135
1136 spin_lock_irqsave(&fep->tmreg_lock, flags);
1137 ns = timecounter_cyc2time(&fep->tc, ts);
1138 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
1139
1140 memset(hwtstamps, 0, sizeof(*hwtstamps));
1141 hwtstamps->hwtstamp = ns_to_ktime(ns);
1142}
1143
1144static void
Fugang Duan4d494cd2014-09-13 05:00:48 +08001145fec_enet_tx_queue(struct net_device *ndev, u16 queue_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
1147 struct fec_enet_private *fep;
Sascha Hauer2e285322009-04-15 01:32:16 +00001148 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001149 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 struct sk_buff *skb;
Fugang Duan4d494cd2014-09-13 05:00:48 +08001151 struct fec_enet_priv_tx_q *txq;
1152 struct netdev_queue *nq;
Frank Lide5fb0a2013-03-03 17:34:25 +00001153 int index = 0;
Nimrod Andy79f33912014-06-12 08:16:23 +08001154 int entries_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001156 fep = netdev_priv(ndev);
Fugang Duan4d494cd2014-09-13 05:00:48 +08001157
1158 queue_id = FEC_ENET_GET_QUQUE(queue_id);
1159
1160 txq = fep->tx_queue[queue_id];
1161 /* get next bdp of dirty_tx */
1162 nq = netdev_get_tx_queue(ndev, queue_id);
1163 bdp = txq->dirty_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Frank Lide5fb0a2013-03-03 17:34:25 +00001165 /* get next bdp of dirty_tx */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001166 bdp = fec_enet_get_nextdesc(bdp, fep, queue_id);
Frank Lide5fb0a2013-03-03 17:34:25 +00001167
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001168 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
Frank Lide5fb0a2013-03-03 17:34:25 +00001169
1170 /* current queue is empty */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001171 if (bdp == txq->cur_tx)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001172 break;
1173
Fugang Duan4d494cd2014-09-13 05:00:48 +08001174 index = fec_enet_get_bd_index(txq->tx_bd_base, bdp, fep);
Frank Lide5fb0a2013-03-03 17:34:25 +00001175
Fugang Duan4d494cd2014-09-13 05:00:48 +08001176 skb = txq->tx_skbuff[index];
1177 txq->tx_skbuff[index] = NULL;
1178 if (!IS_TSO_HEADER(txq, bdp->cbd_bufaddr))
Nimrod Andy79f33912014-06-12 08:16:23 +08001179 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
1180 bdp->cbd_datlen, DMA_TO_DEVICE);
Sebastian Siewior2488a542013-12-02 10:52:55 +01001181 bdp->cbd_bufaddr = 0;
Nimrod Andy6e909282014-06-12 08:16:22 +08001182 if (!skb) {
Fugang Duan4d494cd2014-09-13 05:00:48 +08001183 bdp = fec_enet_get_nextdesc(bdp, fep, queue_id);
Nimrod Andy6e909282014-06-12 08:16:22 +08001184 continue;
1185 }
Frank Lide5fb0a2013-03-03 17:34:25 +00001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001188 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 BD_ENET_TX_RL | BD_ENET_TX_UN |
1190 BD_ENET_TX_CSL)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001191 ndev->stats.tx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001192 if (status & BD_ENET_TX_HB) /* No heartbeat */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001193 ndev->stats.tx_heartbeat_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001194 if (status & BD_ENET_TX_LC) /* Late collision */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001195 ndev->stats.tx_window_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001196 if (status & BD_ENET_TX_RL) /* Retrans limit */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001197 ndev->stats.tx_aborted_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001198 if (status & BD_ENET_TX_UN) /* Underrun */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001199 ndev->stats.tx_fifo_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001200 if (status & BD_ENET_TX_CSL) /* Carrier lost */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001201 ndev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 } else {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001203 ndev->stats.tx_packets++;
Nimrod Andy6e909282014-06-12 08:16:22 +08001204 ndev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206
Frank Liff43da82013-01-03 16:04:23 +00001207 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
1208 fep->bufdesc_ex) {
Frank Li6605b732012-10-30 18:25:31 +00001209 struct skb_shared_hwtstamps shhwtstamps;
Frank Liff43da82013-01-03 16:04:23 +00001210 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
Frank Li6605b732012-10-30 18:25:31 +00001211
Russell Kingbfd4ecd2014-07-08 13:02:09 +01001212 fec_enet_hwtstamp(fep, ebdp->ts, &shhwtstamps);
Frank Li6605b732012-10-30 18:25:31 +00001213 skb_tstamp_tx(skb, &shhwtstamps);
1214 }
Frank Liff43da82013-01-03 16:04:23 +00001215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 /* Deferred means some collisions occurred during transmit,
1217 * but we eventually sent the packet OK.
1218 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001219 if (status & BD_ENET_TX_DEF)
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001220 ndev->stats.collisions++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001221
Sascha Hauer22f6b862009-04-15 01:32:18 +00001222 /* Free the sk buffer associated with this last transmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 dev_kfree_skb_any(skb);
Frank Lide5fb0a2013-03-03 17:34:25 +00001224
Fugang Duan4d494cd2014-09-13 05:00:48 +08001225 txq->dirty_tx = bdp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001226
Sascha Hauer22f6b862009-04-15 01:32:18 +00001227 /* Update pointer to next buffer descriptor to be transmitted */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001228 bdp = fec_enet_get_nextdesc(bdp, fep, queue_id);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001229
Sascha Hauer22f6b862009-04-15 01:32:18 +00001230 /* Since we have freed up a buffer, the ring is no longer full
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 */
Nimrod Andy79f33912014-06-12 08:16:23 +08001232 if (netif_queue_stopped(ndev)) {
Fugang Duan4d494cd2014-09-13 05:00:48 +08001233 entries_free = fec_enet_get_free_txdesc_num(fep, txq);
1234 if (entries_free >= txq->tx_wake_threshold)
1235 netif_tx_wake_queue(nq);
Nimrod Andy79f33912014-06-12 08:16:23 +08001236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
Russell Kingccea2962014-07-08 13:01:38 +01001238
1239 /* ERR006538: Keep the transmitter going */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001240 if (bdp != txq->cur_tx &&
1241 readl(fep->hwp + FEC_X_DES_ACTIVE(queue_id)) == 0)
1242 writel(0, fep->hwp + FEC_X_DES_ACTIVE(queue_id));
1243}
1244
1245static void
1246fec_enet_tx(struct net_device *ndev)
1247{
1248 struct fec_enet_private *fep = netdev_priv(ndev);
1249 u16 queue_id;
1250 /* First process class A queue, then Class B and Best Effort queue */
1251 for_each_set_bit(queue_id, &fep->work_tx, FEC_ENET_MAX_TX_QS) {
1252 clear_bit(queue_id, &fep->work_tx);
1253 fec_enet_tx_queue(ndev, queue_id);
1254 }
1255 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258/* During a receive, the cur_rx points to the current incoming buffer.
1259 * When we update through the ring, if the next incoming buffer has
1260 * not been given to the system, we just set the empty indicator,
1261 * effectively tossing the packet.
1262 */
Frank Lidc975382013-01-28 18:31:42 +00001263static int
Fugang Duan4d494cd2014-09-13 05:00:48 +08001264fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001266 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guob5680e02011-01-05 21:13:13 +00001267 const struct platform_device_id *id_entry =
1268 platform_get_device_id(fep->pdev);
Fugang Duan4d494cd2014-09-13 05:00:48 +08001269 struct fec_enet_priv_rx_q *rxq;
Sascha Hauer2e285322009-04-15 01:32:16 +00001270 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001271 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 struct sk_buff *skb;
1273 ushort pkt_len;
1274 __u8 *data;
Frank Lidc975382013-01-28 18:31:42 +00001275 int pkt_received = 0;
Jim Baxtercdffcf12013-07-02 22:52:56 +01001276 struct bufdesc_ex *ebdp = NULL;
1277 bool vlan_packet_rcvd = false;
1278 u16 vlan_tag;
Duan Fugang-B38611d842a312013-11-14 09:57:10 +08001279 int index = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001280
Greg Ungerer0e702ab2006-06-27 13:19:33 +10001281#ifdef CONFIG_M532x
1282 flush_cache_all();
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001283#endif
Fugang Duan4d494cd2014-09-13 05:00:48 +08001284 queue_id = FEC_ENET_GET_QUQUE(queue_id);
1285 rxq = fep->rx_queue[queue_id];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 /* First, grab all of the stats for the incoming packet.
1288 * These get messed up if we get called due to a busy condition.
1289 */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001290 bdp = rxq->cur_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Sascha Hauer22f6b862009-04-15 01:32:18 +00001292 while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Frank Lidc975382013-01-28 18:31:42 +00001294 if (pkt_received >= budget)
1295 break;
1296 pkt_received++;
1297
Sascha Hauer22f6b862009-04-15 01:32:18 +00001298 /* Since we have allocated space to hold a complete frame,
1299 * the last indicator should be set.
1300 */
1301 if ((status & BD_ENET_RX_LAST) == 0)
Joe Perches31b77202013-04-13 19:03:17 +00001302 netdev_err(ndev, "rcv is not +last\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Russell Kingdb3421c2014-07-08 13:01:49 +01001304
Sascha Hauer22f6b862009-04-15 01:32:18 +00001305 /* Check for errors. */
1306 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001308 ndev->stats.rx_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001309 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
1310 /* Frame too long or too short. */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001311 ndev->stats.rx_length_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001312 }
1313 if (status & BD_ENET_RX_NO) /* Frame alignment */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001314 ndev->stats.rx_frame_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001315 if (status & BD_ENET_RX_CR) /* CRC Error */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001316 ndev->stats.rx_crc_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001317 if (status & BD_ENET_RX_OV) /* FIFO overrun */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001318 ndev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 }
Sascha Hauer22f6b862009-04-15 01:32:18 +00001320
1321 /* Report late collisions as a frame error.
1322 * On this error, the BD is closed, but we don't know what we
1323 * have in the buffer. So, just drop this frame on the floor.
1324 */
1325 if (status & BD_ENET_RX_CL) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001326 ndev->stats.rx_errors++;
1327 ndev->stats.rx_frame_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001328 goto rx_processing_done;
1329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Sascha Hauer22f6b862009-04-15 01:32:18 +00001331 /* Process the incoming frame. */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001332 ndev->stats.rx_packets++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001333 pkt_len = bdp->cbd_datlen;
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001334 ndev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Fugang Duan4d494cd2014-09-13 05:00:48 +08001336 index = fec_enet_get_bd_index(rxq->rx_bd_base, bdp, fep);
1337 data = rxq->rx_skbuff[index]->data;
Duan Fugang-B38611d842a312013-11-14 09:57:10 +08001338 dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr,
1339 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
Sascha Hauerccdc4f12009-01-28 23:03:09 +00001340
Shawn Guob5680e02011-01-05 21:13:13 +00001341 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
1342 swap_buffer(data, pkt_len);
1343
Jim Baxtercdffcf12013-07-02 22:52:56 +01001344 /* Extract the enhanced buffer descriptor */
1345 ebdp = NULL;
1346 if (fep->bufdesc_ex)
1347 ebdp = (struct bufdesc_ex *)bdp;
1348
1349 /* If this is a VLAN packet remove the VLAN Tag */
1350 vlan_packet_rcvd = false;
1351 if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
Fugang Duan4d494cd2014-09-13 05:00:48 +08001352 fep->bufdesc_ex && (ebdp->cbd_esc & BD_ENET_RX_VLAN)) {
Jim Baxtercdffcf12013-07-02 22:52:56 +01001353 /* Push and remove the vlan tag */
1354 struct vlan_hdr *vlan_header =
1355 (struct vlan_hdr *) (data + ETH_HLEN);
1356 vlan_tag = ntohs(vlan_header->h_vlan_TCI);
1357 pkt_len -= VLAN_HLEN;
1358
1359 vlan_packet_rcvd = true;
1360 }
1361
Sascha Hauer22f6b862009-04-15 01:32:18 +00001362 /* This does 16 byte alignment, exactly what we need.
1363 * The packet length includes FCS, but we don't want to
1364 * include that when passing upstream as it messes up
1365 * bridging applications.
1366 */
Fabio Estevamb72061a2012-02-07 08:27:31 +00001367 skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Sascha Hauer85498892009-04-15 01:32:21 +00001369 if (unlikely(!skb)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001370 ndev->stats.rx_dropped++;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001371 } else {
Jim Baxtercdffcf12013-07-02 22:52:56 +01001372 int payload_offset = (2 * ETH_ALEN);
Sascha Hauer85498892009-04-15 01:32:21 +00001373 skb_reserve(skb, NET_IP_ALIGN);
Sascha Hauer22f6b862009-04-15 01:32:18 +00001374 skb_put(skb, pkt_len - 4); /* Make room */
Jim Baxtercdffcf12013-07-02 22:52:56 +01001375
1376 /* Extract the frame data without the VLAN header. */
1377 skb_copy_to_linear_data(skb, data, (2 * ETH_ALEN));
1378 if (vlan_packet_rcvd)
1379 payload_offset = (2 * ETH_ALEN) + VLAN_HLEN;
Fugang Duan4d494cd2014-09-13 05:00:48 +08001380 skb_copy_to_linear_data_offset(skb, (2 * ETH_ALEN),
Jim Baxtercdffcf12013-07-02 22:52:56 +01001381 data + payload_offset,
1382 pkt_len - 4 - (2 * ETH_ALEN));
1383
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001384 skb->protocol = eth_type_trans(skb, ndev);
Frank Liff43da82013-01-03 16:04:23 +00001385
Frank Li6605b732012-10-30 18:25:31 +00001386 /* Get receive timestamp from the skb */
Russell Kingbfd4ecd2014-07-08 13:02:09 +01001387 if (fep->hwts_rx_en && fep->bufdesc_ex)
1388 fec_enet_hwtstamp(fep, ebdp->ts,
1389 skb_hwtstamps(skb));
Frank Liff43da82013-01-03 16:04:23 +00001390
Jim Baxter4c09eed2013-04-19 08:10:49 +00001391 if (fep->bufdesc_ex &&
Jim Baxtercdffcf12013-07-02 22:52:56 +01001392 (fep->csum_flags & FLAG_RX_CSUM_ENABLED)) {
Jim Baxter4c09eed2013-04-19 08:10:49 +00001393 if (!(ebdp->cbd_esc & FLAG_RX_CSUM_ERROR)) {
1394 /* don't check it */
1395 skb->ip_summed = CHECKSUM_UNNECESSARY;
1396 } else {
1397 skb_checksum_none_assert(skb);
1398 }
1399 }
1400
Jim Baxtercdffcf12013-07-02 22:52:56 +01001401 /* Handle received VLAN packets */
1402 if (vlan_packet_rcvd)
1403 __vlan_hwaccel_put_tag(skb,
1404 htons(ETH_P_8021Q),
1405 vlan_tag);
1406
Richard Cochran0affdf32013-08-30 20:28:10 +02001407 napi_gro_receive(&fep->napi, skb);
Sascha Hauer22f6b862009-04-15 01:32:18 +00001408 }
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001409
Duan Fugang-B38611d842a312013-11-14 09:57:10 +08001410 dma_sync_single_for_device(&fep->pdev->dev, bdp->cbd_bufaddr,
1411 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
Sascha Hauer22f6b862009-04-15 01:32:18 +00001412rx_processing_done:
1413 /* Clear the status flags for this buffer */
1414 status &= ~BD_ENET_RX_STATS;
1415
1416 /* Mark the buffer empty */
1417 status |= BD_ENET_RX_EMPTY;
1418 bdp->cbd_sc = status;
1419
Frank Liff43da82013-01-03 16:04:23 +00001420 if (fep->bufdesc_ex) {
1421 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
1422
1423 ebdp->cbd_esc = BD_ENET_RX_INT;
1424 ebdp->cbd_prot = 0;
1425 ebdp->cbd_bdu = 0;
1426 }
Frank Li6605b732012-10-30 18:25:31 +00001427
Sascha Hauer22f6b862009-04-15 01:32:18 +00001428 /* Update BD pointer to next entry */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001429 bdp = fec_enet_get_nextdesc(bdp, fep, queue_id);
Duan Fugang-B3861136e24e22013-09-03 10:41:18 +08001430
Sascha Hauer22f6b862009-04-15 01:32:18 +00001431 /* Doing this here will keep the FEC running while we process
1432 * incoming frames. On a heavily loaded network, we should be
1433 * able to keep up at the expense of system resources.
1434 */
Fugang Duan4d494cd2014-09-13 05:00:48 +08001435 writel(0, fep->hwp + FEC_R_DES_ACTIVE(queue_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
Fugang Duan4d494cd2014-09-13 05:00:48 +08001437 rxq->cur_rx = bdp;
Frank Lidc975382013-01-28 18:31:42 +00001438 return pkt_received;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Fugang Duan4d494cd2014-09-13 05:00:48 +08001441static int
1442fec_enet_rx(struct net_device *ndev, int budget)
1443{
1444 int pkt_received = 0;
1445 u16 queue_id;
1446 struct fec_enet_private *fep = netdev_priv(ndev);
1447
1448 for_each_set_bit(queue_id, &fep->work_rx, FEC_ENET_MAX_RX_QS) {
1449 clear_bit(queue_id, &fep->work_rx);
1450 pkt_received += fec_enet_rx_queue(ndev,
1451 budget - pkt_received, queue_id);
1452 }
1453 return pkt_received;
1454}
1455
1456static bool
1457fec_enet_collect_events(struct fec_enet_private *fep, uint int_events)
1458{
1459 if (int_events == 0)
1460 return false;
1461
1462 if (int_events & FEC_ENET_RXF)
1463 fep->work_rx |= (1 << 2);
1464
1465 if (int_events & FEC_ENET_TXF)
1466 fep->work_tx |= (1 << 2);
1467
1468 return true;
1469}
1470
Uwe Kleine-König45993652011-01-19 20:47:04 +01001471static irqreturn_t
1472fec_enet_interrupt(int irq, void *dev_id)
1473{
1474 struct net_device *ndev = dev_id;
1475 struct fec_enet_private *fep = netdev_priv(ndev);
Russell King7a168072014-07-08 00:22:44 +01001476 const unsigned napi_mask = FEC_ENET_RXF | FEC_ENET_TXF;
Uwe Kleine-König45993652011-01-19 20:47:04 +01001477 uint int_events;
1478 irqreturn_t ret = IRQ_NONE;
1479
Russell King7a168072014-07-08 00:22:44 +01001480 int_events = readl(fep->hwp + FEC_IEVENT);
1481 writel(int_events & ~napi_mask, fep->hwp + FEC_IEVENT);
Fugang Duan4d494cd2014-09-13 05:00:48 +08001482 fec_enet_collect_events(fep, int_events);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001483
Russell King7a168072014-07-08 00:22:44 +01001484 if (int_events & napi_mask) {
1485 ret = IRQ_HANDLED;
Frank Lidc975382013-01-28 18:31:42 +00001486
Russell King7a168072014-07-08 00:22:44 +01001487 /* Disable the NAPI interrupts */
1488 writel(FEC_ENET_MII, fep->hwp + FEC_IMASK);
1489 napi_schedule(&fep->napi);
1490 }
Uwe Kleine-König45993652011-01-19 20:47:04 +01001491
Russell King7a168072014-07-08 00:22:44 +01001492 if (int_events & FEC_ENET_MII) {
1493 ret = IRQ_HANDLED;
1494 complete(&fep->mdio_done);
1495 }
Uwe Kleine-König45993652011-01-19 20:47:04 +01001496
1497 return ret;
1498}
1499
Frank Lidc975382013-01-28 18:31:42 +00001500static int fec_enet_rx_napi(struct napi_struct *napi, int budget)
1501{
1502 struct net_device *ndev = napi->dev;
Frank Lidc975382013-01-28 18:31:42 +00001503 struct fec_enet_private *fep = netdev_priv(ndev);
Russell King7a168072014-07-08 00:22:44 +01001504 int pkts;
1505
1506 /*
1507 * Clear any pending transmit or receive interrupts before
1508 * processing the rings to avoid racing with the hardware.
1509 */
1510 writel(FEC_ENET_RXF | FEC_ENET_TXF, fep->hwp + FEC_IEVENT);
1511
1512 pkts = fec_enet_rx(ndev, budget);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001513
Frank Lide5fb0a2013-03-03 17:34:25 +00001514 fec_enet_tx(ndev);
1515
Frank Lidc975382013-01-28 18:31:42 +00001516 if (pkts < budget) {
1517 napi_complete(napi);
1518 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
1519 }
1520 return pkts;
1521}
Uwe Kleine-König45993652011-01-19 20:47:04 +01001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523/* ------------------------------------------------------------------------- */
Fabio Estevam0c7768a2013-01-07 17:42:56 +00001524static void fec_get_mac(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001526 struct fec_enet_private *fep = netdev_priv(ndev);
Jingoo Han94660ba2013-08-30 13:56:26 +09001527 struct fec_platform_data *pdata = dev_get_platdata(&fep->pdev->dev);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001528 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Shawn Guo49da97d2011-01-05 21:13:11 +00001530 /*
1531 * try to get mac address in following order:
1532 *
1533 * 1) module parameter via kernel command line in form
1534 * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
1535 */
1536 iap = macaddr;
1537
1538 /*
Shawn Guoca2cc332011-06-25 02:04:35 +08001539 * 2) from device tree data
1540 */
1541 if (!is_valid_ether_addr(iap)) {
1542 struct device_node *np = fep->pdev->dev.of_node;
1543 if (np) {
1544 const char *mac = of_get_mac_address(np);
1545 if (mac)
1546 iap = (unsigned char *) mac;
1547 }
1548 }
Shawn Guoca2cc332011-06-25 02:04:35 +08001549
1550 /*
1551 * 3) from flash or fuse (via platform data)
Shawn Guo49da97d2011-01-05 21:13:11 +00001552 */
1553 if (!is_valid_ether_addr(iap)) {
1554#ifdef CONFIG_M5272
1555 if (FEC_FLASHMAC)
1556 iap = (unsigned char *)FEC_FLASHMAC;
1557#else
1558 if (pdata)
Lothar Waßmann589efdc2011-12-07 21:59:29 +00001559 iap = (unsigned char *)&pdata->mac;
Shawn Guo49da97d2011-01-05 21:13:11 +00001560#endif
1561 }
1562
1563 /*
Shawn Guoca2cc332011-06-25 02:04:35 +08001564 * 4) FEC mac registers set by bootloader
Shawn Guo49da97d2011-01-05 21:13:11 +00001565 */
1566 if (!is_valid_ether_addr(iap)) {
Dan Carpenter7d7628f2013-08-29 11:25:14 +03001567 *((__be32 *) &tmpaddr[0]) =
1568 cpu_to_be32(readl(fep->hwp + FEC_ADDR_LOW));
1569 *((__be16 *) &tmpaddr[4]) =
1570 cpu_to_be16(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 iap = &tmpaddr[0];
1572 }
1573
Lucas Stachff5b2fa2013-06-03 00:38:39 +00001574 /*
1575 * 5) random mac address
1576 */
1577 if (!is_valid_ether_addr(iap)) {
1578 /* Report it and use a random ethernet address instead */
1579 netdev_err(ndev, "Invalid MAC address: %pM\n", iap);
1580 eth_hw_addr_random(ndev);
1581 netdev_info(ndev, "Using random MAC address: %pM\n",
1582 ndev->dev_addr);
1583 return;
1584 }
1585
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001586 memcpy(ndev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Shawn Guo49da97d2011-01-05 21:13:11 +00001588 /* Adjust MAC if using macaddr */
1589 if (iap == macaddr)
Shawn Guo43af9402011-12-05 05:01:15 +00001590 ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
1593/* ------------------------------------------------------------------------- */
1594
Bryan Wue6b043d2010-03-31 02:10:44 +00001595/*
1596 * Phy section
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001598static void fec_enet_adjust_link(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001600 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001601 struct phy_device *phy_dev = fep->phy_dev;
Bryan Wue6b043d2010-03-31 02:10:44 +00001602 int status_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Bryan Wue6b043d2010-03-31 02:10:44 +00001604 /* Prevent a state halted on mii error */
1605 if (fep->mii_timeout && phy_dev->state == PHY_HALTED) {
1606 phy_dev->state = PHY_RESUMING;
Frank Li54309fa2013-05-07 14:08:44 +00001607 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001609
Russell King8ce56242014-07-08 12:40:07 +01001610 /*
1611 * If the netdev is down, or is going down, we're not interested
1612 * in link state events, so just mark our idea of the link as down
1613 * and ignore the event.
1614 */
1615 if (!netif_running(ndev) || !netif_device_present(ndev)) {
1616 fep->link = 0;
1617 } else if (phy_dev->link) {
Lucas Stachd97e7492013-03-14 05:12:01 +00001618 if (!fep->link) {
Lothar Waßmann6ea07222011-12-07 21:59:27 +00001619 fep->link = phy_dev->link;
Bryan Wue6b043d2010-03-31 02:10:44 +00001620 status_change = 1;
1621 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001622
Russell Kingef833372014-07-08 12:40:43 +01001623 if (fep->full_duplex != phy_dev->duplex) {
1624 fep->full_duplex = phy_dev->duplex;
Lucas Stachd97e7492013-03-14 05:12:01 +00001625 status_change = 1;
Russell Kingef833372014-07-08 12:40:43 +01001626 }
Lucas Stachd97e7492013-03-14 05:12:01 +00001627
1628 if (phy_dev->speed != fep->speed) {
1629 fep->speed = phy_dev->speed;
1630 status_change = 1;
1631 }
1632
1633 /* if any of the above changed restart the FEC */
Russell Kingdbc64a82014-07-08 12:40:12 +01001634 if (status_change) {
Russell Kingdbc64a82014-07-08 12:40:12 +01001635 napi_disable(&fep->napi);
Russell Kingdbc64a82014-07-08 12:40:12 +01001636 netif_tx_lock_bh(ndev);
Russell Kingef833372014-07-08 12:40:43 +01001637 fec_restart(ndev);
Russell Kingdbc64a82014-07-08 12:40:12 +01001638 netif_wake_queue(ndev);
Russell King6af42d42014-07-08 12:40:18 +01001639 netif_tx_unlock_bh(ndev);
Russell Kingdbc64a82014-07-08 12:40:12 +01001640 napi_enable(&fep->napi);
Russell Kingdbc64a82014-07-08 12:40:12 +01001641 }
Lucas Stachd97e7492013-03-14 05:12:01 +00001642 } else {
1643 if (fep->link) {
Russell Kingf208ce12014-07-08 12:40:38 +01001644 napi_disable(&fep->napi);
1645 netif_tx_lock_bh(ndev);
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001646 fec_stop(ndev);
Russell Kingf208ce12014-07-08 12:40:38 +01001647 netif_tx_unlock_bh(ndev);
1648 napi_enable(&fep->napi);
Lucas Stach8d7ed0f2013-04-16 00:42:42 +00001649 fep->link = phy_dev->link;
Lucas Stachd97e7492013-03-14 05:12:01 +00001650 status_change = 1;
1651 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001652 }
1653
Bryan Wue6b043d2010-03-31 02:10:44 +00001654 if (status_change)
1655 phy_print_status(phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Bryan Wue6b043d2010-03-31 02:10:44 +00001658static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Bryan Wue6b043d2010-03-31 02:10:44 +00001660 struct fec_enet_private *fep = bus->priv;
Baruch Siach97b72e42010-07-11 21:12:51 +00001661 unsigned long time_left;
Bryan Wue6b043d2010-03-31 02:10:44 +00001662
1663 fep->mii_timeout = 0;
Baruch Siach97b72e42010-07-11 21:12:51 +00001664 init_completion(&fep->mdio_done);
Bryan Wue6b043d2010-03-31 02:10:44 +00001665
1666 /* start a read op */
1667 writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
1668 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1669 FEC_MMFR_TA, fep->hwp + FEC_MII_DATA);
1670
1671 /* wait for end of transfer */
Baruch Siach97b72e42010-07-11 21:12:51 +00001672 time_left = wait_for_completion_timeout(&fep->mdio_done,
1673 usecs_to_jiffies(FEC_MII_TIMEOUT));
1674 if (time_left == 0) {
1675 fep->mii_timeout = 1;
Joe Perches31b77202013-04-13 19:03:17 +00001676 netdev_err(fep->netdev, "MDIO read timeout\n");
Baruch Siach97b72e42010-07-11 21:12:51 +00001677 return -ETIMEDOUT;
Bryan Wue6b043d2010-03-31 02:10:44 +00001678 }
1679
1680 /* return value */
1681 return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA));
1682}
1683
1684static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
1685 u16 value)
1686{
1687 struct fec_enet_private *fep = bus->priv;
Baruch Siach97b72e42010-07-11 21:12:51 +00001688 unsigned long time_left;
Bryan Wue6b043d2010-03-31 02:10:44 +00001689
1690 fep->mii_timeout = 0;
Baruch Siach97b72e42010-07-11 21:12:51 +00001691 init_completion(&fep->mdio_done);
Bryan Wue6b043d2010-03-31 02:10:44 +00001692
Shawn Guo862f0982011-01-05 21:13:09 +00001693 /* start a write op */
1694 writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
Bryan Wue6b043d2010-03-31 02:10:44 +00001695 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1696 FEC_MMFR_TA | FEC_MMFR_DATA(value),
1697 fep->hwp + FEC_MII_DATA);
1698
1699 /* wait for end of transfer */
Baruch Siach97b72e42010-07-11 21:12:51 +00001700 time_left = wait_for_completion_timeout(&fep->mdio_done,
1701 usecs_to_jiffies(FEC_MII_TIMEOUT));
1702 if (time_left == 0) {
1703 fep->mii_timeout = 1;
Joe Perches31b77202013-04-13 19:03:17 +00001704 netdev_err(fep->netdev, "MDIO write timeout\n");
Baruch Siach97b72e42010-07-11 21:12:51 +00001705 return -ETIMEDOUT;
Bryan Wue6b043d2010-03-31 02:10:44 +00001706 }
1707
1708 return 0;
1709}
1710
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001711static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
1712{
1713 struct fec_enet_private *fep = netdev_priv(ndev);
1714 int ret;
1715
1716 if (enable) {
1717 ret = clk_prepare_enable(fep->clk_ahb);
1718 if (ret)
1719 return ret;
1720 ret = clk_prepare_enable(fep->clk_ipg);
1721 if (ret)
1722 goto failed_clk_ipg;
1723 if (fep->clk_enet_out) {
1724 ret = clk_prepare_enable(fep->clk_enet_out);
1725 if (ret)
1726 goto failed_clk_enet_out;
1727 }
1728 if (fep->clk_ptp) {
Nimrod Andy91c0d982014-08-21 17:09:38 +08001729 mutex_lock(&fep->ptp_clk_mutex);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001730 ret = clk_prepare_enable(fep->clk_ptp);
Nimrod Andy91c0d982014-08-21 17:09:38 +08001731 if (ret) {
1732 mutex_unlock(&fep->ptp_clk_mutex);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001733 goto failed_clk_ptp;
Nimrod Andy91c0d982014-08-21 17:09:38 +08001734 } else {
1735 fep->ptp_clk_on = true;
1736 }
1737 mutex_unlock(&fep->ptp_clk_mutex);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001738 }
Fugang Duan9b5330e2014-09-13 05:00:46 +08001739 if (fep->clk_ref) {
1740 ret = clk_prepare_enable(fep->clk_ref);
1741 if (ret)
1742 goto failed_clk_ref;
1743 }
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001744 } else {
1745 clk_disable_unprepare(fep->clk_ahb);
1746 clk_disable_unprepare(fep->clk_ipg);
1747 if (fep->clk_enet_out)
1748 clk_disable_unprepare(fep->clk_enet_out);
Nimrod Andy91c0d982014-08-21 17:09:38 +08001749 if (fep->clk_ptp) {
1750 mutex_lock(&fep->ptp_clk_mutex);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001751 clk_disable_unprepare(fep->clk_ptp);
Nimrod Andy91c0d982014-08-21 17:09:38 +08001752 fep->ptp_clk_on = false;
1753 mutex_unlock(&fep->ptp_clk_mutex);
1754 }
Fugang Duan9b5330e2014-09-13 05:00:46 +08001755 if (fep->clk_ref)
1756 clk_disable_unprepare(fep->clk_ref);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001757 }
1758
1759 return 0;
Fugang Duan9b5330e2014-09-13 05:00:46 +08001760
1761failed_clk_ref:
1762 if (fep->clk_ref)
1763 clk_disable_unprepare(fep->clk_ref);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08001764failed_clk_ptp:
1765 if (fep->clk_enet_out)
1766 clk_disable_unprepare(fep->clk_enet_out);
1767failed_clk_enet_out:
1768 clk_disable_unprepare(fep->clk_ipg);
1769failed_clk_ipg:
1770 clk_disable_unprepare(fep->clk_ahb);
1771
1772 return ret;
1773}
1774
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001775static int fec_enet_mii_probe(struct net_device *ndev)
Bryan Wue6b043d2010-03-31 02:10:44 +00001776{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001777 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo230dec62011-09-23 02:12:48 +00001778 const struct platform_device_id *id_entry =
1779 platform_get_device_id(fep->pdev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001780 struct phy_device *phy_dev = NULL;
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001781 char mdio_bus_id[MII_BUS_ID_SIZE];
1782 char phy_name[MII_BUS_ID_SIZE + 3];
1783 int phy_id;
Shawn Guo43af9402011-12-05 05:01:15 +00001784 int dev_id = fep->dev_id;
Bryan Wue6b043d2010-03-31 02:10:44 +00001785
Bryan Wu418bd0d2010-05-28 03:40:39 -07001786 fep->phy_dev = NULL;
1787
Uwe Kleine-König407066f2014-08-11 17:35:33 +02001788 if (fep->phy_node) {
1789 phy_dev = of_phy_connect(ndev, fep->phy_node,
1790 &fec_enet_adjust_link, 0,
1791 fep->phy_interface);
1792 } else {
1793 /* check for attached phy */
1794 for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
1795 if ((fep->mii_bus->phy_mask & (1 << phy_id)))
1796 continue;
1797 if (fep->mii_bus->phy_map[phy_id] == NULL)
1798 continue;
1799 if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
1800 continue;
1801 if (dev_id--)
1802 continue;
1803 strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
1804 break;
1805 }
1806
1807 if (phy_id >= PHY_MAX_ADDR) {
1808 netdev_info(ndev, "no PHY, assuming direct connection to switch\n");
1809 strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
1810 phy_id = 0;
1811 }
1812
1813 snprintf(phy_name, sizeof(phy_name),
1814 PHY_ID_FMT, mdio_bus_id, phy_id);
1815 phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link,
1816 fep->phy_interface);
Bryan Wue6b043d2010-03-31 02:10:44 +00001817 }
1818
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001819 if (IS_ERR(phy_dev)) {
Joe Perches31b77202013-04-13 19:03:17 +00001820 netdev_err(ndev, "could not attach to PHY\n");
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001821 return PTR_ERR(phy_dev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001822 }
1823
1824 /* mask with MAC supported features */
Frank Libaa70a52013-01-16 16:55:58 +00001825 if (id_entry->driver_data & FEC_QUIRK_HAS_GBIT) {
Shawn Guo230dec62011-09-23 02:12:48 +00001826 phy_dev->supported &= PHY_GBIT_FEATURES;
Russell Kingb44592f2014-07-08 00:22:34 +01001827 phy_dev->supported &= ~SUPPORTED_1000baseT_Half;
Guenter Roeckd1391932013-06-18 10:04:59 -07001828#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00001829 phy_dev->supported |= SUPPORTED_Pause;
Guenter Roeckd1391932013-06-18 10:04:59 -07001830#endif
Frank Libaa70a52013-01-16 16:55:58 +00001831 }
Shawn Guo230dec62011-09-23 02:12:48 +00001832 else
1833 phy_dev->supported &= PHY_BASIC_FEATURES;
1834
Bryan Wue6b043d2010-03-31 02:10:44 +00001835 phy_dev->advertising = phy_dev->supported;
1836
1837 fep->phy_dev = phy_dev;
1838 fep->link = 0;
1839 fep->full_duplex = 0;
1840
Joe Perches31b77202013-04-13 19:03:17 +00001841 netdev_info(ndev, "Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1842 fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
1843 fep->phy_dev->irq);
Bryan Wu418bd0d2010-05-28 03:40:39 -07001844
Bryan Wue6b043d2010-03-31 02:10:44 +00001845 return 0;
1846}
1847
1848static int fec_enet_mii_init(struct platform_device *pdev)
1849{
Shawn Guob5680e02011-01-05 21:13:13 +00001850 static struct mii_bus *fec0_mii_bus;
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001851 struct net_device *ndev = platform_get_drvdata(pdev);
1852 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guob5680e02011-01-05 21:13:13 +00001853 const struct platform_device_id *id_entry =
1854 platform_get_device_id(fep->pdev);
Uwe Kleine-König407066f2014-08-11 17:35:33 +02001855 struct device_node *node;
Bryan Wue6b043d2010-03-31 02:10:44 +00001856 int err = -ENXIO, i;
1857
Shawn Guob5680e02011-01-05 21:13:13 +00001858 /*
1859 * The dual fec interfaces are not equivalent with enet-mac.
1860 * Here are the differences:
1861 *
1862 * - fec0 supports MII & RMII modes while fec1 only supports RMII
1863 * - fec0 acts as the 1588 time master while fec1 is slave
1864 * - external phys can only be configured by fec0
1865 *
1866 * That is to say fec1 can not work independently. It only works
1867 * when fec0 is working. The reason behind this design is that the
1868 * second interface is added primarily for Switch mode.
1869 *
1870 * Because of the last point above, both phys are attached on fec0
1871 * mdio interface in board design, and need to be configured by
1872 * fec0 mii_bus.
1873 */
Shawn Guo43af9402011-12-05 05:01:15 +00001874 if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) {
Shawn Guob5680e02011-01-05 21:13:13 +00001875 /* fec1 uses fec0 mii_bus */
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001876 if (mii_cnt && fec0_mii_bus) {
1877 fep->mii_bus = fec0_mii_bus;
1878 mii_cnt++;
1879 return 0;
1880 }
1881 return -ENOENT;
Shawn Guob5680e02011-01-05 21:13:13 +00001882 }
1883
Bryan Wue6b043d2010-03-31 02:10:44 +00001884 fep->mii_timeout = 0;
1885
1886 /*
1887 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
Shawn Guo230dec62011-09-23 02:12:48 +00001888 *
1889 * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
1890 * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28
1891 * Reference Manual has an error on this, and gets fixed on i.MX6Q
1892 * document.
Bryan Wue6b043d2010-03-31 02:10:44 +00001893 */
Nimrod Andy98a6eeb2014-05-20 13:23:09 +08001894 fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), 5000000);
Shawn Guo230dec62011-09-23 02:12:48 +00001895 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1896 fep->phy_speed--;
1897 fep->phy_speed <<= 1;
Bryan Wue6b043d2010-03-31 02:10:44 +00001898 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1899
1900 fep->mii_bus = mdiobus_alloc();
1901 if (fep->mii_bus == NULL) {
1902 err = -ENOMEM;
1903 goto err_out;
1904 }
1905
1906 fep->mii_bus->name = "fec_enet_mii_bus";
1907 fep->mii_bus->read = fec_enet_mdio_read;
1908 fep->mii_bus->write = fec_enet_mdio_write;
Florian Fainelli391420f2012-01-09 23:59:13 +00001909 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1910 pdev->name, fep->dev_id + 1);
Bryan Wue6b043d2010-03-31 02:10:44 +00001911 fep->mii_bus->priv = fep;
1912 fep->mii_bus->parent = &pdev->dev;
1913
1914 fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
1915 if (!fep->mii_bus->irq) {
1916 err = -ENOMEM;
1917 goto err_out_free_mdiobus;
1918 }
1919
1920 for (i = 0; i < PHY_MAX_ADDR; i++)
1921 fep->mii_bus->irq[i] = PHY_POLL;
1922
Uwe Kleine-König407066f2014-08-11 17:35:33 +02001923 node = of_get_child_by_name(pdev->dev.of_node, "mdio");
1924 if (node) {
1925 err = of_mdiobus_register(fep->mii_bus, node);
1926 of_node_put(node);
1927 } else {
1928 err = mdiobus_register(fep->mii_bus);
1929 }
1930
1931 if (err)
Bryan Wue6b043d2010-03-31 02:10:44 +00001932 goto err_out_free_mdio_irq;
1933
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001934 mii_cnt++;
1935
Shawn Guob5680e02011-01-05 21:13:13 +00001936 /* save fec0 mii_bus */
1937 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1938 fec0_mii_bus = fep->mii_bus;
1939
Bryan Wue6b043d2010-03-31 02:10:44 +00001940 return 0;
1941
Bryan Wue6b043d2010-03-31 02:10:44 +00001942err_out_free_mdio_irq:
1943 kfree(fep->mii_bus->irq);
1944err_out_free_mdiobus:
1945 mdiobus_free(fep->mii_bus);
1946err_out:
1947 return err;
1948}
1949
1950static void fec_enet_mii_remove(struct fec_enet_private *fep)
1951{
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001952 if (--mii_cnt == 0) {
1953 mdiobus_unregister(fep->mii_bus);
1954 kfree(fep->mii_bus->irq);
1955 mdiobus_free(fep->mii_bus);
1956 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001957}
1958
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001959static int fec_enet_get_settings(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001960 struct ethtool_cmd *cmd)
1961{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001962 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001963 struct phy_device *phydev = fep->phy_dev;
1964
1965 if (!phydev)
1966 return -ENODEV;
1967
1968 return phy_ethtool_gset(phydev, cmd);
1969}
1970
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001971static int fec_enet_set_settings(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001972 struct ethtool_cmd *cmd)
1973{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001974 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001975 struct phy_device *phydev = fep->phy_dev;
1976
1977 if (!phydev)
1978 return -ENODEV;
1979
1980 return phy_ethtool_sset(phydev, cmd);
1981}
1982
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001983static void fec_enet_get_drvinfo(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001984 struct ethtool_drvinfo *info)
1985{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001986 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
Jiri Pirko7826d432013-01-06 00:44:26 +00001988 strlcpy(info->driver, fep->pdev->dev.driver->name,
1989 sizeof(info->driver));
1990 strlcpy(info->version, "Revision: 1.0", sizeof(info->version));
1991 strlcpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
Bryan Wue6b043d2010-03-31 02:10:44 +00001993
Frank Li5ebae4892013-01-06 16:25:07 +00001994static int fec_enet_get_ts_info(struct net_device *ndev,
1995 struct ethtool_ts_info *info)
1996{
1997 struct fec_enet_private *fep = netdev_priv(ndev);
1998
1999 if (fep->bufdesc_ex) {
2000
2001 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
2002 SOF_TIMESTAMPING_RX_SOFTWARE |
2003 SOF_TIMESTAMPING_SOFTWARE |
2004 SOF_TIMESTAMPING_TX_HARDWARE |
2005 SOF_TIMESTAMPING_RX_HARDWARE |
2006 SOF_TIMESTAMPING_RAW_HARDWARE;
2007 if (fep->ptp_clock)
2008 info->phc_index = ptp_clock_index(fep->ptp_clock);
2009 else
2010 info->phc_index = -1;
2011
2012 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
2013 (1 << HWTSTAMP_TX_ON);
2014
2015 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
2016 (1 << HWTSTAMP_FILTER_ALL);
2017 return 0;
2018 } else {
2019 return ethtool_op_get_ts_info(ndev, info);
2020 }
2021}
2022
Guenter Roeckd1391932013-06-18 10:04:59 -07002023#if !defined(CONFIG_M5272)
2024
Frank Libaa70a52013-01-16 16:55:58 +00002025static void fec_enet_get_pauseparam(struct net_device *ndev,
2026 struct ethtool_pauseparam *pause)
2027{
2028 struct fec_enet_private *fep = netdev_priv(ndev);
2029
2030 pause->autoneg = (fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) != 0;
2031 pause->tx_pause = (fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) != 0;
2032 pause->rx_pause = pause->tx_pause;
2033}
2034
2035static int fec_enet_set_pauseparam(struct net_device *ndev,
2036 struct ethtool_pauseparam *pause)
2037{
2038 struct fec_enet_private *fep = netdev_priv(ndev);
2039
Russell King0b146ca2014-07-08 00:22:59 +01002040 if (!fep->phy_dev)
2041 return -ENODEV;
2042
Frank Libaa70a52013-01-16 16:55:58 +00002043 if (pause->tx_pause != pause->rx_pause) {
2044 netdev_info(ndev,
2045 "hardware only support enable/disable both tx and rx");
2046 return -EINVAL;
2047 }
2048
2049 fep->pause_flag = 0;
2050
2051 /* tx pause must be same as rx pause */
2052 fep->pause_flag |= pause->rx_pause ? FEC_PAUSE_FLAG_ENABLE : 0;
2053 fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0;
2054
2055 if (pause->rx_pause || pause->autoneg) {
2056 fep->phy_dev->supported |= ADVERTISED_Pause;
2057 fep->phy_dev->advertising |= ADVERTISED_Pause;
2058 } else {
2059 fep->phy_dev->supported &= ~ADVERTISED_Pause;
2060 fep->phy_dev->advertising &= ~ADVERTISED_Pause;
2061 }
2062
2063 if (pause->autoneg) {
2064 if (netif_running(ndev))
2065 fec_stop(ndev);
2066 phy_start_aneg(fep->phy_dev);
2067 }
Russell Kingdbc64a82014-07-08 12:40:12 +01002068 if (netif_running(ndev)) {
Russell Kingdbc64a82014-07-08 12:40:12 +01002069 napi_disable(&fep->napi);
Russell Kingdbc64a82014-07-08 12:40:12 +01002070 netif_tx_lock_bh(ndev);
Russell Kingef833372014-07-08 12:40:43 +01002071 fec_restart(ndev);
Russell Kingdbc64a82014-07-08 12:40:12 +01002072 netif_wake_queue(ndev);
Russell King6af42d42014-07-08 12:40:18 +01002073 netif_tx_unlock_bh(ndev);
Russell Kingdbc64a82014-07-08 12:40:12 +01002074 napi_enable(&fep->napi);
Russell Kingdbc64a82014-07-08 12:40:12 +01002075 }
Frank Libaa70a52013-01-16 16:55:58 +00002076
2077 return 0;
2078}
2079
Chris Healy38ae92d2013-06-25 23:18:52 -07002080static const struct fec_stat {
2081 char name[ETH_GSTRING_LEN];
2082 u16 offset;
2083} fec_stats[] = {
2084 /* RMON TX */
2085 { "tx_dropped", RMON_T_DROP },
2086 { "tx_packets", RMON_T_PACKETS },
2087 { "tx_broadcast", RMON_T_BC_PKT },
2088 { "tx_multicast", RMON_T_MC_PKT },
2089 { "tx_crc_errors", RMON_T_CRC_ALIGN },
2090 { "tx_undersize", RMON_T_UNDERSIZE },
2091 { "tx_oversize", RMON_T_OVERSIZE },
2092 { "tx_fragment", RMON_T_FRAG },
2093 { "tx_jabber", RMON_T_JAB },
2094 { "tx_collision", RMON_T_COL },
2095 { "tx_64byte", RMON_T_P64 },
2096 { "tx_65to127byte", RMON_T_P65TO127 },
2097 { "tx_128to255byte", RMON_T_P128TO255 },
2098 { "tx_256to511byte", RMON_T_P256TO511 },
2099 { "tx_512to1023byte", RMON_T_P512TO1023 },
2100 { "tx_1024to2047byte", RMON_T_P1024TO2047 },
2101 { "tx_GTE2048byte", RMON_T_P_GTE2048 },
2102 { "tx_octets", RMON_T_OCTETS },
2103
2104 /* IEEE TX */
2105 { "IEEE_tx_drop", IEEE_T_DROP },
2106 { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK },
2107 { "IEEE_tx_1col", IEEE_T_1COL },
2108 { "IEEE_tx_mcol", IEEE_T_MCOL },
2109 { "IEEE_tx_def", IEEE_T_DEF },
2110 { "IEEE_tx_lcol", IEEE_T_LCOL },
2111 { "IEEE_tx_excol", IEEE_T_EXCOL },
2112 { "IEEE_tx_macerr", IEEE_T_MACERR },
2113 { "IEEE_tx_cserr", IEEE_T_CSERR },
2114 { "IEEE_tx_sqe", IEEE_T_SQE },
2115 { "IEEE_tx_fdxfc", IEEE_T_FDXFC },
2116 { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK },
2117
2118 /* RMON RX */
2119 { "rx_packets", RMON_R_PACKETS },
2120 { "rx_broadcast", RMON_R_BC_PKT },
2121 { "rx_multicast", RMON_R_MC_PKT },
2122 { "rx_crc_errors", RMON_R_CRC_ALIGN },
2123 { "rx_undersize", RMON_R_UNDERSIZE },
2124 { "rx_oversize", RMON_R_OVERSIZE },
2125 { "rx_fragment", RMON_R_FRAG },
2126 { "rx_jabber", RMON_R_JAB },
2127 { "rx_64byte", RMON_R_P64 },
2128 { "rx_65to127byte", RMON_R_P65TO127 },
2129 { "rx_128to255byte", RMON_R_P128TO255 },
2130 { "rx_256to511byte", RMON_R_P256TO511 },
2131 { "rx_512to1023byte", RMON_R_P512TO1023 },
2132 { "rx_1024to2047byte", RMON_R_P1024TO2047 },
2133 { "rx_GTE2048byte", RMON_R_P_GTE2048 },
2134 { "rx_octets", RMON_R_OCTETS },
2135
2136 /* IEEE RX */
2137 { "IEEE_rx_drop", IEEE_R_DROP },
2138 { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK },
2139 { "IEEE_rx_crc", IEEE_R_CRC },
2140 { "IEEE_rx_align", IEEE_R_ALIGN },
2141 { "IEEE_rx_macerr", IEEE_R_MACERR },
2142 { "IEEE_rx_fdxfc", IEEE_R_FDXFC },
2143 { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
2144};
2145
2146static void fec_enet_get_ethtool_stats(struct net_device *dev,
2147 struct ethtool_stats *stats, u64 *data)
2148{
2149 struct fec_enet_private *fep = netdev_priv(dev);
2150 int i;
2151
2152 for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
2153 data[i] = readl(fep->hwp + fec_stats[i].offset);
2154}
2155
2156static void fec_enet_get_strings(struct net_device *netdev,
2157 u32 stringset, u8 *data)
2158{
2159 int i;
2160 switch (stringset) {
2161 case ETH_SS_STATS:
2162 for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
2163 memcpy(data + i * ETH_GSTRING_LEN,
2164 fec_stats[i].name, ETH_GSTRING_LEN);
2165 break;
2166 }
2167}
2168
2169static int fec_enet_get_sset_count(struct net_device *dev, int sset)
2170{
2171 switch (sset) {
2172 case ETH_SS_STATS:
2173 return ARRAY_SIZE(fec_stats);
2174 default:
2175 return -EOPNOTSUPP;
2176 }
2177}
Guenter Roeckd1391932013-06-18 10:04:59 -07002178#endif /* !defined(CONFIG_M5272) */
Chris Healy38ae92d2013-06-25 23:18:52 -07002179
Chris Healy32bc9b42013-06-17 07:25:06 -07002180static int fec_enet_nway_reset(struct net_device *dev)
2181{
2182 struct fec_enet_private *fep = netdev_priv(dev);
2183 struct phy_device *phydev = fep->phy_dev;
2184
2185 if (!phydev)
2186 return -ENODEV;
2187
2188 return genphy_restart_aneg(phydev);
2189}
2190
stephen hemminger9b07be42012-01-04 12:59:49 +00002191static const struct ethtool_ops fec_enet_ethtool_ops = {
Bryan Wue6b043d2010-03-31 02:10:44 +00002192 .get_settings = fec_enet_get_settings,
2193 .set_settings = fec_enet_set_settings,
2194 .get_drvinfo = fec_enet_get_drvinfo,
Chris Healy32bc9b42013-06-17 07:25:06 -07002195 .nway_reset = fec_enet_nway_reset,
Russell Kingc1d7c482014-07-08 13:01:54 +01002196 .get_link = ethtool_op_get_link,
Chris Healy38ae92d2013-06-25 23:18:52 -07002197#ifndef CONFIG_M5272
Russell Kingc1d7c482014-07-08 13:01:54 +01002198 .get_pauseparam = fec_enet_get_pauseparam,
2199 .set_pauseparam = fec_enet_set_pauseparam,
Chris Healy38ae92d2013-06-25 23:18:52 -07002200 .get_strings = fec_enet_get_strings,
Russell Kingc1d7c482014-07-08 13:01:54 +01002201 .get_ethtool_stats = fec_enet_get_ethtool_stats,
Chris Healy38ae92d2013-06-25 23:18:52 -07002202 .get_sset_count = fec_enet_get_sset_count,
2203#endif
Russell Kingc1d7c482014-07-08 13:01:54 +01002204 .get_ts_info = fec_enet_get_ts_info,
Bryan Wue6b043d2010-03-31 02:10:44 +00002205};
2206
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002207static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
Bryan Wue6b043d2010-03-31 02:10:44 +00002208{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002209 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00002210 struct phy_device *phydev = fep->phy_dev;
2211
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002212 if (!netif_running(ndev))
Bryan Wue6b043d2010-03-31 02:10:44 +00002213 return -EINVAL;
2214
2215 if (!phydev)
2216 return -ENODEV;
2217
Ben Hutchings1d5244d2013-11-18 23:02:44 +00002218 if (fep->bufdesc_ex) {
2219 if (cmd == SIOCSHWTSTAMP)
2220 return fec_ptp_set(ndev, rq);
2221 if (cmd == SIOCGHWTSTAMP)
2222 return fec_ptp_get(ndev, rq);
2223 }
Frank Liff43da82013-01-03 16:04:23 +00002224
Richard Cochran28b04112010-07-17 08:48:55 +00002225 return phy_mii_ioctl(phydev, rq, cmd);
Bryan Wue6b043d2010-03-31 02:10:44 +00002226}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002228static void fec_enet_free_buffers(struct net_device *ndev)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002229{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002230 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevamda2191e2013-03-20 12:31:07 -03002231 unsigned int i;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002232 struct sk_buff *skb;
2233 struct bufdesc *bdp;
Fugang Duan4d494cd2014-09-13 05:00:48 +08002234 struct fec_enet_priv_tx_q *txq;
2235 struct fec_enet_priv_rx_q *rxq;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002236
Fugang Duan4d494cd2014-09-13 05:00:48 +08002237 rxq = fep->rx_queue[0];
2238 bdp = rxq->rx_bd_base;
2239 for (i = 0; i < rxq->rx_ring_size; i++) {
2240 skb = rxq->rx_skbuff[i];
2241 rxq->rx_skbuff[i] = NULL;
Russell King730ee362014-07-08 00:23:14 +01002242 if (skb) {
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +01002243 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002244 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002245 dev_kfree_skb(skb);
Russell King730ee362014-07-08 00:23:14 +01002246 }
Fugang Duan4d494cd2014-09-13 05:00:48 +08002247 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002248 }
2249
Fugang Duan4d494cd2014-09-13 05:00:48 +08002250 txq = fep->tx_queue[0];
2251 bdp = txq->tx_bd_base;
2252 for (i = 0; i < txq->tx_ring_size; i++) {
2253 kfree(txq->tx_bounce[i]);
2254 txq->tx_bounce[i] = NULL;
2255 skb = txq->tx_skbuff[i];
2256 txq->tx_skbuff[i] = NULL;
Russell King8b7c9ef2014-07-08 00:23:25 +01002257 dev_kfree_skb(skb);
2258 }
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002259}
2260
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002261static int fec_enet_alloc_buffers(struct net_device *ndev)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002262{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002263 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevamda2191e2013-03-20 12:31:07 -03002264 unsigned int i;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002265 struct sk_buff *skb;
2266 struct bufdesc *bdp;
Fugang Duan4d494cd2014-09-13 05:00:48 +08002267 struct fec_enet_priv_tx_q *txq;
2268 struct fec_enet_priv_rx_q *rxq;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002269
Fugang Duan4d494cd2014-09-13 05:00:48 +08002270 rxq = fep->rx_queue[0];
2271 bdp = rxq->rx_bd_base;
2272 for (i = 0; i < rxq->rx_ring_size; i++) {
Russell King730ee362014-07-08 00:23:14 +01002273 dma_addr_t addr;
2274
Fabio Estevamb72061a2012-02-07 08:27:31 +00002275 skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
Russell Kingffdce2c2014-07-08 00:23:30 +01002276 if (!skb)
2277 goto err_alloc;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002278
Russell King730ee362014-07-08 00:23:14 +01002279 addr = dma_map_single(&fep->pdev->dev, skb->data,
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002280 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
Russell King730ee362014-07-08 00:23:14 +01002281 if (dma_mapping_error(&fep->pdev->dev, addr)) {
2282 dev_kfree_skb(skb);
Duan Fugang-B38611d842a312013-11-14 09:57:10 +08002283 if (net_ratelimit())
2284 netdev_err(ndev, "Rx DMA memory map failed\n");
Russell Kingffdce2c2014-07-08 00:23:30 +01002285 goto err_alloc;
Duan Fugang-B38611d842a312013-11-14 09:57:10 +08002286 }
Russell King730ee362014-07-08 00:23:14 +01002287
Fugang Duan4d494cd2014-09-13 05:00:48 +08002288 rxq->rx_skbuff[i] = skb;
Russell King730ee362014-07-08 00:23:14 +01002289 bdp->cbd_bufaddr = addr;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002290 bdp->cbd_sc = BD_ENET_RX_EMPTY;
Frank Liff43da82013-01-03 16:04:23 +00002291
2292 if (fep->bufdesc_ex) {
2293 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
2294 ebdp->cbd_esc = BD_ENET_RX_INT;
2295 }
2296
Fugang Duan4d494cd2014-09-13 05:00:48 +08002297 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002298 }
2299
2300 /* Set the last buffer to wrap. */
Fugang Duan4d494cd2014-09-13 05:00:48 +08002301 bdp = fec_enet_get_prevdesc(bdp, fep, 0);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002302 bdp->cbd_sc |= BD_SC_WRAP;
2303
Fugang Duan4d494cd2014-09-13 05:00:48 +08002304 txq = fep->tx_queue[0];
2305 bdp = txq->tx_bd_base;
2306 for (i = 0; i < txq->tx_ring_size; i++) {
2307 txq->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL);
2308 if (!txq->tx_bounce[i])
Russell Kingffdce2c2014-07-08 00:23:30 +01002309 goto err_alloc;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002310
2311 bdp->cbd_sc = 0;
2312 bdp->cbd_bufaddr = 0;
Frank Li6605b732012-10-30 18:25:31 +00002313
Frank Liff43da82013-01-03 16:04:23 +00002314 if (fep->bufdesc_ex) {
2315 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
Jim Baxter96d22222013-03-26 05:25:07 +00002316 ebdp->cbd_esc = BD_ENET_TX_INT;
Frank Liff43da82013-01-03 16:04:23 +00002317 }
2318
Fugang Duan4d494cd2014-09-13 05:00:48 +08002319 bdp = fec_enet_get_nextdesc(bdp, fep, 0);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002320 }
2321
2322 /* Set the last buffer to wrap. */
Fugang Duan4d494cd2014-09-13 05:00:48 +08002323 bdp = fec_enet_get_prevdesc(bdp, fep, 0);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002324 bdp->cbd_sc |= BD_SC_WRAP;
2325
2326 return 0;
Russell Kingffdce2c2014-07-08 00:23:30 +01002327
2328 err_alloc:
2329 fec_enet_free_buffers(ndev);
2330 return -ENOMEM;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002331}
2332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002334fec_enet_open(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002336 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002337 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002339 pinctrl_pm_select_default_state(&fep->pdev->dev);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002340 ret = fec_enet_clk_enable(ndev, true);
2341 if (ret)
2342 return ret;
2343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 /* I should reset the ring buffers here, but I don't yet know
2345 * a simple way to do that.
2346 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002348 ret = fec_enet_alloc_buffers(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002349 if (ret)
2350 return ret;
2351
Bryan Wu418bd0d2010-05-28 03:40:39 -07002352 /* Probe and connect to PHY when open the interface */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002353 ret = fec_enet_mii_probe(ndev);
Bryan Wu418bd0d2010-05-28 03:40:39 -07002354 if (ret) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002355 fec_enet_free_buffers(ndev);
Bryan Wu418bd0d2010-05-28 03:40:39 -07002356 return ret;
2357 }
Russell Kingce5eaf02014-02-18 12:55:42 +00002358
Russell Kingef833372014-07-08 12:40:43 +01002359 fec_restart(ndev);
Russell Kingce5eaf02014-02-18 12:55:42 +00002360 napi_enable(&fep->napi);
Bryan Wue6b043d2010-03-31 02:10:44 +00002361 phy_start(fep->phy_dev);
Fugang Duan4d494cd2014-09-13 05:00:48 +08002362 netif_tx_start_all_queues(ndev);
2363
Sascha Hauer22f6b862009-04-15 01:32:18 +00002364 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
2367static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002368fec_enet_close(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002370 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
Russell Kingd76cfae2014-07-08 00:23:04 +01002372 phy_stop(fep->phy_dev);
2373
Russell King31a6de32014-07-08 12:40:23 +01002374 if (netif_device_present(ndev)) {
2375 napi_disable(&fep->napi);
2376 netif_tx_disable(ndev);
Russell King8bbbd3c2014-07-08 12:40:02 +01002377 fec_stop(ndev);
Russell King31a6de32014-07-08 12:40:23 +01002378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Russell King635cf172014-07-08 00:22:54 +01002380 phy_disconnect(fep->phy_dev);
Russell King0b146ca2014-07-08 00:22:59 +01002381 fep->phy_dev = NULL;
Bryan Wu418bd0d2010-05-28 03:40:39 -07002382
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002383 fec_enet_clk_enable(ndev, false);
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002384 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
Uwe Kleine-Königdb8880b2011-01-19 20:26:39 +01002385 fec_enet_free_buffers(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 return 0;
2388}
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390/* Set or clear the multicast filter for this adaptor.
2391 * Skeleton taken from sunlance driver.
2392 * The CPM Ethernet implementation allows Multicast as well as individual
2393 * MAC address filtering. Some of the drivers check to make sure it is
2394 * a group multicast address, and discard those that are not. I guess I
2395 * will do the same for now, but just remove the test if you want
2396 * individual filtering as well (do the upper net layers want or support
2397 * this kind of feature?).
2398 */
2399
2400#define HASH_BITS 6 /* #bits in hash */
2401#define CRC32_POLY 0xEDB88320
2402
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002403static void set_multicast_list(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002405 struct fec_enet_private *fep = netdev_priv(ndev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002406 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002407 unsigned int i, bit, data, crc, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 unsigned char hash;
2409
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002410 if (ndev->flags & IFF_PROMISC) {
Sascha Hauerf44d6302009-04-15 03:11:30 +00002411 tmp = readl(fep->hwp + FEC_R_CNTRL);
2412 tmp |= 0x8;
2413 writel(tmp, fep->hwp + FEC_R_CNTRL);
Sascha Hauer4e831832009-04-15 01:32:19 +00002414 return;
2415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Sascha Hauer4e831832009-04-15 01:32:19 +00002417 tmp = readl(fep->hwp + FEC_R_CNTRL);
2418 tmp &= ~0x8;
2419 writel(tmp, fep->hwp + FEC_R_CNTRL);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002420
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002421 if (ndev->flags & IFF_ALLMULTI) {
Sascha Hauer4e831832009-04-15 01:32:19 +00002422 /* Catch all multicast addresses, so set the
2423 * filter to all 1's
2424 */
2425 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
2426 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Sascha Hauer4e831832009-04-15 01:32:19 +00002428 return;
2429 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002430
Sascha Hauer4e831832009-04-15 01:32:19 +00002431 /* Clear filter and add the addresses in hash register
2432 */
2433 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
2434 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002436 netdev_for_each_mc_addr(ha, ndev) {
Sascha Hauer4e831832009-04-15 01:32:19 +00002437 /* calculate crc32 value of mac address */
2438 crc = 0xffffffff;
2439
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002440 for (i = 0; i < ndev->addr_len; i++) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00002441 data = ha->addr[i];
Sascha Hauer4e831832009-04-15 01:32:19 +00002442 for (bit = 0; bit < 8; bit++, data >>= 1) {
2443 crc = (crc >> 1) ^
2444 (((crc ^ data) & 1) ? CRC32_POLY : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 }
2446 }
Sascha Hauer4e831832009-04-15 01:32:19 +00002447
2448 /* only upper 6 bits (HASH_BITS) are used
2449 * which point to specific bit in he hash registers
2450 */
2451 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
2452
2453 if (hash > 31) {
2454 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
2455 tmp |= 1 << (hash - 32);
2456 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
2457 } else {
2458 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
2459 tmp |= 1 << hash;
2460 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
2461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463}
2464
Sascha Hauer22f6b862009-04-15 01:32:18 +00002465/* Set a MAC change in hardware. */
Sascha Hauer009fda82009-04-15 01:32:23 +00002466static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002467fec_set_mac_address(struct net_device *ndev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002469 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Hauer009fda82009-04-15 01:32:23 +00002470 struct sockaddr *addr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Lucas Stach44934fa2014-03-30 21:32:08 +02002472 if (addr) {
2473 if (!is_valid_ether_addr(addr->sa_data))
2474 return -EADDRNOTAVAIL;
2475 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
2476 }
Sascha Hauer009fda82009-04-15 01:32:23 +00002477
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002478 writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
2479 (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
Sascha Hauerf44d6302009-04-15 03:11:30 +00002480 fep->hwp + FEC_ADDR_LOW);
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002481 writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
Mattias Walström7cff0942010-05-05 00:55:48 -07002482 fep->hwp + FEC_ADDR_HIGH);
Sascha Hauer009fda82009-04-15 01:32:23 +00002483 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00002486#ifdef CONFIG_NET_POLL_CONTROLLER
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002487/**
2488 * fec_poll_controller - FEC Poll controller function
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00002489 * @dev: The FEC network adapter
2490 *
2491 * Polled functionality used by netconsole and others in non interrupt mode
2492 *
2493 */
Wei Yongjun47a52472013-03-20 05:06:11 +00002494static void fec_poll_controller(struct net_device *dev)
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00002495{
2496 int i;
2497 struct fec_enet_private *fep = netdev_priv(dev);
2498
2499 for (i = 0; i < FEC_IRQ_NUM; i++) {
2500 if (fep->irq[i] > 0) {
2501 disable_irq(fep->irq[i]);
2502 fec_enet_interrupt(fep->irq[i], dev);
2503 enable_irq(fep->irq[i]);
2504 }
2505 }
2506}
2507#endif
2508
Russell King8506fa12014-07-08 12:40:33 +01002509#define FEATURES_NEED_QUIESCE NETIF_F_RXCSUM
2510
Jim Baxter4c09eed2013-04-19 08:10:49 +00002511static int fec_set_features(struct net_device *netdev,
2512 netdev_features_t features)
2513{
2514 struct fec_enet_private *fep = netdev_priv(netdev);
2515 netdev_features_t changed = features ^ netdev->features;
2516
Russell King8506fa12014-07-08 12:40:33 +01002517 /* Quiesce the device if necessary */
2518 if (netif_running(netdev) && changed & FEATURES_NEED_QUIESCE) {
2519 napi_disable(&fep->napi);
2520 netif_tx_lock_bh(netdev);
2521 fec_stop(netdev);
2522 }
2523
Jim Baxter4c09eed2013-04-19 08:10:49 +00002524 netdev->features = features;
2525
2526 /* Receive checksum has been changed */
2527 if (changed & NETIF_F_RXCSUM) {
2528 if (features & NETIF_F_RXCSUM)
2529 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
2530 else
2531 fep->csum_flags &= ~FLAG_RX_CSUM_ENABLED;
Russell King8506fa12014-07-08 12:40:33 +01002532 }
Jim Baxter4c09eed2013-04-19 08:10:49 +00002533
Russell King8506fa12014-07-08 12:40:33 +01002534 /* Resume the device after updates */
2535 if (netif_running(netdev) && changed & FEATURES_NEED_QUIESCE) {
Russell Kingef833372014-07-08 12:40:43 +01002536 fec_restart(netdev);
Fugang Duan4d494cd2014-09-13 05:00:48 +08002537 netif_tx_wake_all_queues(netdev);
Russell King8506fa12014-07-08 12:40:33 +01002538 netif_tx_unlock_bh(netdev);
2539 napi_enable(&fep->napi);
Jim Baxter4c09eed2013-04-19 08:10:49 +00002540 }
2541
2542 return 0;
2543}
2544
Fugang Duan4d494cd2014-09-13 05:00:48 +08002545u16 fec_enet_select_queue(struct net_device *ndev, struct sk_buff *skb,
2546 void *accel_priv, select_queue_fallback_t fallback)
2547{
2548 return skb_tx_hash(ndev, skb);
2549}
2550
Sascha Hauer009fda82009-04-15 01:32:23 +00002551static const struct net_device_ops fec_netdev_ops = {
2552 .ndo_open = fec_enet_open,
2553 .ndo_stop = fec_enet_close,
2554 .ndo_start_xmit = fec_enet_start_xmit,
Fugang Duan4d494cd2014-09-13 05:00:48 +08002555 .ndo_select_queue = fec_enet_select_queue,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002556 .ndo_set_rx_mode = set_multicast_list,
Ben Hutchings635ecaa2009-07-09 17:59:01 +00002557 .ndo_change_mtu = eth_change_mtu,
Sascha Hauer009fda82009-04-15 01:32:23 +00002558 .ndo_validate_addr = eth_validate_addr,
2559 .ndo_tx_timeout = fec_timeout,
2560 .ndo_set_mac_address = fec_set_mac_address,
Uwe Kleine-Königdb8880b2011-01-19 20:26:39 +01002561 .ndo_do_ioctl = fec_enet_ioctl,
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00002562#ifdef CONFIG_NET_POLL_CONTROLLER
2563 .ndo_poll_controller = fec_poll_controller,
2564#endif
Jim Baxter4c09eed2013-04-19 08:10:49 +00002565 .ndo_set_features = fec_set_features,
Sascha Hauer009fda82009-04-15 01:32:23 +00002566};
2567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 /*
2569 * XXX: We need to clean up on failure exits here.
Sascha Haueread73182009-01-28 23:03:11 +00002570 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002572static int fec_enet_init(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002574 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo48496252013-05-08 21:08:22 +00002575 const struct platform_device_id *id_entry =
2576 platform_get_device_id(fep->pdev);
Fugang Duan4d494cd2014-09-13 05:00:48 +08002577 struct fec_enet_priv_tx_q *txq;
2578 struct fec_enet_priv_rx_q *rxq;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00002579 struct bufdesc *cbd_base;
Fugang Duan4d494cd2014-09-13 05:00:48 +08002580 dma_addr_t bd_dma;
Nimrod Andy55d02182014-06-12 08:16:21 +08002581 int bd_size;
2582
Fugang Duan4d494cd2014-09-13 05:00:48 +08002583 txq = kzalloc(sizeof(*txq), GFP_KERNEL);
2584 if (!txq)
2585 return -ENOMEM;
2586 fep->tx_queue[0] = txq;
Nimrod Andy55d02182014-06-12 08:16:21 +08002587
Fugang Duan4d494cd2014-09-13 05:00:48 +08002588 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
2589 if (!rxq) {
2590 kfree(txq);
2591 return -ENOMEM;
2592 }
2593
2594 fep->rx_queue[0] = rxq;
2595
2596
2597 txq->tx_ring_size = TX_RING_SIZE;
2598 rxq->rx_ring_size = RX_RING_SIZE;
2599 fep->total_tx_ring_size = txq->tx_ring_size;
2600 fep->total_rx_ring_size = rxq->rx_ring_size;
2601
2602 txq->tx_stop_threshold = FEC_MAX_SKB_DESCS;
2603 txq->tx_wake_threshold = (txq->tx_ring_size - txq->tx_stop_threshold) / 2;
Nimrod Andy79f33912014-06-12 08:16:23 +08002604
Nimrod Andy55d02182014-06-12 08:16:21 +08002605 if (fep->bufdesc_ex)
2606 fep->bufdesc_size = sizeof(struct bufdesc_ex);
2607 else
2608 fep->bufdesc_size = sizeof(struct bufdesc);
Fugang Duan4d494cd2014-09-13 05:00:48 +08002609 bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) *
Nimrod Andy55d02182014-06-12 08:16:21 +08002610 fep->bufdesc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00002612 /* Allocate memory for buffer descriptors. */
Fugang Duan4d494cd2014-09-13 05:00:48 +08002613 cbd_base = dma_alloc_coherent(NULL, bd_size, &bd_dma,
Joe Perchesd0320f72013-03-14 13:07:21 +00002614 GFP_KERNEL);
Fugang Duan4d494cd2014-09-13 05:00:48 +08002615 if (!cbd_base) {
2616 kfree(rxq);
2617 kfree(txq);
Nimrod Andy79f33912014-06-12 08:16:23 +08002618 return -ENOMEM;
2619 }
2620
Fugang Duan4d494cd2014-09-13 05:00:48 +08002621 txq->tso_hdrs = dma_alloc_coherent(NULL, txq->tx_ring_size * TSO_HEADER_SIZE,
2622 &txq->tso_hdrs_dma, GFP_KERNEL);
2623 if (!txq->tso_hdrs) {
2624 kfree(rxq);
2625 kfree(txq);
2626 dma_free_coherent(NULL, bd_size, cbd_base, bd_dma);
2627 return -ENOMEM;
2628 }
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +10002629
Fugang Duan4d494cd2014-09-13 05:00:48 +08002630 memset(cbd_base, 0, bd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Shawn Guo49da97d2011-01-05 21:13:11 +00002632 /* Get the Ethernet address */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002633 fec_get_mac(ndev);
Lucas Stach44934fa2014-03-30 21:32:08 +02002634 /* make sure MAC we just acquired is programmed into the hw */
2635 fec_set_mac_address(ndev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00002637 /* Set receive and transmit descriptor base. */
Fugang Duan4d494cd2014-09-13 05:00:48 +08002638 rxq->rx_bd_base = cbd_base;
Nimrod Andy55d02182014-06-12 08:16:21 +08002639 if (fep->bufdesc_ex)
Fugang Duan4d494cd2014-09-13 05:00:48 +08002640 txq->tx_bd_base = (struct bufdesc *)
2641 (((struct bufdesc_ex *)cbd_base) + rxq->rx_ring_size);
Nimrod Andy55d02182014-06-12 08:16:21 +08002642 else
Fugang Duan4d494cd2014-09-13 05:00:48 +08002643 txq->tx_bd_base = cbd_base + rxq->rx_ring_size;
2644
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
Sascha Hauer22f6b862009-04-15 01:32:18 +00002646 /* The FEC Ethernet specific entries in the device structure */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01002647 ndev->watchdog_timeo = TX_TIMEOUT;
2648 ndev->netdev_ops = &fec_netdev_ops;
2649 ndev->ethtool_ops = &fec_enet_ethtool_ops;
Rob Herring633e7532010-02-05 08:56:20 +00002650
Frank Lidc975382013-01-28 18:31:42 +00002651 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK);
Fabio Estevam322555f2013-08-27 17:35:08 -03002652 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, NAPI_POLL_WEIGHT);
Frank Lidc975382013-01-28 18:31:42 +00002653
Nimrod Andy09d1e542014-06-12 08:16:20 +08002654 if (id_entry->driver_data & FEC_QUIRK_HAS_VLAN)
Jim Baxtercdffcf12013-07-02 22:52:56 +01002655 /* enable hw VLAN support */
2656 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
Jim Baxtercdffcf12013-07-02 22:52:56 +01002657
Shawn Guo48496252013-05-08 21:08:22 +00002658 if (id_entry->driver_data & FEC_QUIRK_HAS_CSUM) {
Nimrod Andy79f33912014-06-12 08:16:23 +08002659 ndev->gso_max_segs = FEC_MAX_TSO_SEGS;
2660
Shawn Guo48496252013-05-08 21:08:22 +00002661 /* enable hw accelerator */
2662 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
Nimrod Andy79f33912014-06-12 08:16:23 +08002663 | NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_TSO);
Shawn Guo48496252013-05-08 21:08:22 +00002664 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
2665 }
Jim Baxter4c09eed2013-04-19 08:10:49 +00002666
Nimrod Andy09d1e542014-06-12 08:16:20 +08002667 ndev->hw_features = ndev->features;
2668
Russell Kingef833372014-07-08 12:40:43 +01002669 fec_restart(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 return 0;
2672}
2673
Shawn Guoca2cc332011-06-25 02:04:35 +08002674#ifdef CONFIG_OF
Bill Pemberton33897cc2012-12-03 09:23:58 -05002675static void fec_reset_phy(struct platform_device *pdev)
Shawn Guoca2cc332011-06-25 02:04:35 +08002676{
2677 int err, phy_reset;
Shawn Guoa3caad02012-06-27 03:45:24 +00002678 int msec = 1;
Shawn Guoca2cc332011-06-25 02:04:35 +08002679 struct device_node *np = pdev->dev.of_node;
2680
2681 if (!np)
Shawn Guoa9b2c8e2011-09-23 02:12:46 +00002682 return;
Shawn Guoca2cc332011-06-25 02:04:35 +08002683
Shawn Guoa3caad02012-06-27 03:45:24 +00002684 of_property_read_u32(np, "phy-reset-duration", &msec);
2685 /* A sane reset duration should not be longer than 1s */
2686 if (msec > 1000)
2687 msec = 1;
2688
Shawn Guoca2cc332011-06-25 02:04:35 +08002689 phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
Fabio Estevam07dcf8e2013-02-18 10:20:31 +00002690 if (!gpio_is_valid(phy_reset))
2691 return;
2692
Shawn Guo119fc002012-06-27 03:45:22 +00002693 err = devm_gpio_request_one(&pdev->dev, phy_reset,
2694 GPIOF_OUT_INIT_LOW, "phy-reset");
Shawn Guoca2cc332011-06-25 02:04:35 +08002695 if (err) {
Fabio Estevam07dcf8e2013-02-18 10:20:31 +00002696 dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
Shawn Guoa9b2c8e2011-09-23 02:12:46 +00002697 return;
Shawn Guoca2cc332011-06-25 02:04:35 +08002698 }
Shawn Guoa3caad02012-06-27 03:45:24 +00002699 msleep(msec);
Shawn Guoca2cc332011-06-25 02:04:35 +08002700 gpio_set_value(phy_reset, 1);
Shawn Guoca2cc332011-06-25 02:04:35 +08002701}
2702#else /* CONFIG_OF */
Fabio Estevam0c7768a2013-01-07 17:42:56 +00002703static void fec_reset_phy(struct platform_device *pdev)
Shawn Guoca2cc332011-06-25 02:04:35 +08002704{
2705 /*
2706 * In case of platform probe, the reset has been done
2707 * by machine code.
2708 */
Shawn Guoca2cc332011-06-25 02:04:35 +08002709}
2710#endif /* CONFIG_OF */
2711
Bill Pemberton33897cc2012-12-03 09:23:58 -05002712static int
Sascha Haueread73182009-01-28 23:03:11 +00002713fec_probe(struct platform_device *pdev)
2714{
2715 struct fec_enet_private *fep;
Baruch Siach5eb32bd2010-05-24 00:36:13 -07002716 struct fec_platform_data *pdata;
Sascha Haueread73182009-01-28 23:03:11 +00002717 struct net_device *ndev;
2718 int i, irq, ret = 0;
2719 struct resource *r;
Shawn Guoca2cc332011-06-25 02:04:35 +08002720 const struct of_device_id *of_id;
Shawn Guo43af9402011-12-05 05:01:15 +00002721 static int dev_id;
Uwe Kleine-König407066f2014-08-11 17:35:33 +02002722 struct device_node *np = pdev->dev.of_node, *phy_node;
Shawn Guoca2cc332011-06-25 02:04:35 +08002723
2724 of_id = of_match_device(fec_dt_ids, &pdev->dev);
2725 if (of_id)
2726 pdev->id_entry = of_id->data;
Sascha Haueread73182009-01-28 23:03:11 +00002727
Sascha Haueread73182009-01-28 23:03:11 +00002728 /* Init network device */
2729 ndev = alloc_etherdev(sizeof(struct fec_enet_private));
Fabio Estevam83e519b2013-03-11 07:32:55 +00002730 if (!ndev)
2731 return -ENOMEM;
Sascha Haueread73182009-01-28 23:03:11 +00002732
2733 SET_NETDEV_DEV(ndev, &pdev->dev);
2734
2735 /* setup board info structure */
2736 fep = netdev_priv(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002737
Guenter Roeckd1391932013-06-18 10:04:59 -07002738#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00002739 /* default enable pause frame auto negotiation */
2740 if (pdev->id_entry &&
2741 (pdev->id_entry->driver_data & FEC_QUIRK_HAS_GBIT))
2742 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG;
Guenter Roeckd1391932013-06-18 10:04:59 -07002743#endif
Frank Libaa70a52013-01-16 16:55:58 +00002744
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002745 /* Select default pin state */
2746 pinctrl_pm_select_default_state(&pdev->dev);
2747
Fabio Estevam399db752013-07-21 13:25:03 -03002748 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Tushar Behera941e1732013-06-10 17:05:05 +05302749 fep->hwp = devm_ioremap_resource(&pdev->dev, r);
2750 if (IS_ERR(fep->hwp)) {
2751 ret = PTR_ERR(fep->hwp);
2752 goto failed_ioremap;
2753 }
2754
Bryan Wue6b043d2010-03-31 02:10:44 +00002755 fep->pdev = pdev;
Shawn Guo43af9402011-12-05 05:01:15 +00002756 fep->dev_id = dev_id++;
Sascha Haueread73182009-01-28 23:03:11 +00002757
Frank Liff43da82013-01-03 16:04:23 +00002758 fep->bufdesc_ex = 0;
2759
Sascha Haueread73182009-01-28 23:03:11 +00002760 platform_set_drvdata(pdev, ndev);
2761
Uwe Kleine-König407066f2014-08-11 17:35:33 +02002762 phy_node = of_parse_phandle(np, "phy-handle", 0);
2763 if (!phy_node && of_phy_is_fixed_link(np)) {
2764 ret = of_phy_register_fixed_link(np);
2765 if (ret < 0) {
2766 dev_err(&pdev->dev,
2767 "broken fixed-link specification\n");
2768 goto failed_phy;
2769 }
2770 phy_node = of_node_get(np);
2771 }
2772 fep->phy_node = phy_node;
2773
Guenter Roeck6c5f7802013-04-02 09:35:10 +00002774 ret = of_get_phy_mode(pdev->dev.of_node);
Shawn Guoca2cc332011-06-25 02:04:35 +08002775 if (ret < 0) {
Jingoo Han94660ba2013-08-30 13:56:26 +09002776 pdata = dev_get_platdata(&pdev->dev);
Shawn Guoca2cc332011-06-25 02:04:35 +08002777 if (pdata)
2778 fep->phy_interface = pdata->phy;
2779 else
2780 fep->phy_interface = PHY_INTERFACE_MODE_MII;
2781 } else {
2782 fep->phy_interface = ret;
2783 }
2784
Fabio Estevame2f8d552013-02-22 06:40:45 +00002785 fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
2786 if (IS_ERR(fep->clk_ipg)) {
2787 ret = PTR_ERR(fep->clk_ipg);
2788 goto failed_clk;
2789 }
2790
2791 fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
2792 if (IS_ERR(fep->clk_ahb)) {
2793 ret = PTR_ERR(fep->clk_ahb);
2794 goto failed_clk;
2795 }
2796
Linus Torvalds38f56f32013-05-07 11:06:17 -07002797 /* enet_out is optional, depends on board */
2798 fep->clk_enet_out = devm_clk_get(&pdev->dev, "enet_out");
2799 if (IS_ERR(fep->clk_enet_out))
2800 fep->clk_enet_out = NULL;
2801
Nimrod Andy91c0d982014-08-21 17:09:38 +08002802 fep->ptp_clk_on = false;
2803 mutex_init(&fep->ptp_clk_mutex);
Fugang Duan9b5330e2014-09-13 05:00:46 +08002804
2805 /* clk_ref is optional, depends on board */
2806 fep->clk_ref = devm_clk_get(&pdev->dev, "enet_clk_ref");
2807 if (IS_ERR(fep->clk_ref))
2808 fep->clk_ref = NULL;
2809
Fabio Estevame2f8d552013-02-22 06:40:45 +00002810 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp");
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002811 fep->bufdesc_ex =
2812 pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002813 if (IS_ERR(fep->clk_ptp)) {
Linus Torvalds38f56f32013-05-07 11:06:17 -07002814 fep->clk_ptp = NULL;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002815 fep->bufdesc_ex = 0;
2816 }
2817
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002818 ret = fec_enet_clk_enable(ndev, true);
Fabio Estevam13a097b2013-07-21 13:25:02 -03002819 if (ret)
2820 goto failed_clk;
2821
Fabio Estevamf4e9f3d2013-05-27 03:48:29 +00002822 fep->reg_phy = devm_regulator_get(&pdev->dev, "phy");
2823 if (!IS_ERR(fep->reg_phy)) {
2824 ret = regulator_enable(fep->reg_phy);
Fabio Estevame2f8d552013-02-22 06:40:45 +00002825 if (ret) {
2826 dev_err(&pdev->dev,
2827 "Failed to enable phy regulator: %d\n", ret);
2828 goto failed_regulator;
2829 }
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002830 } else {
2831 fep->reg_phy = NULL;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002832 }
2833
2834 fec_reset_phy(pdev);
2835
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002836 if (fep->bufdesc_ex)
Fabio Estevamca162a82013-06-07 10:48:00 +00002837 fec_ptp_init(pdev);
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002838
2839 ret = fec_enet_init(ndev);
2840 if (ret)
2841 goto failed_init;
2842
Xiao Jiangc7c83d12011-09-29 02:15:56 +00002843 for (i = 0; i < FEC_IRQ_NUM; i++) {
Sascha Haueread73182009-01-28 23:03:11 +00002844 irq = platform_get_irq(pdev, i);
Lothar Waßmann86f9f2c2011-12-07 21:59:28 +00002845 if (irq < 0) {
2846 if (i)
2847 break;
2848 ret = irq;
2849 goto failed_irq;
2850 }
Fabio Estevam0d9b2ab2013-07-21 13:25:04 -03002851 ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt,
Michael Opdenacker44a272d2013-09-13 05:44:38 +02002852 0, pdev->name, ndev);
Fabio Estevam0d9b2ab2013-07-21 13:25:04 -03002853 if (ret)
Sascha Haueread73182009-01-28 23:03:11 +00002854 goto failed_irq;
Sascha Haueread73182009-01-28 23:03:11 +00002855 }
2856
Bryan Wue6b043d2010-03-31 02:10:44 +00002857 ret = fec_enet_mii_init(pdev);
2858 if (ret)
2859 goto failed_mii_init;
2860
Oskar Schirmer03c698c2010-10-07 02:30:30 +00002861 /* Carrier starts down, phylib will bring it up */
2862 netif_carrier_off(ndev);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002863 fec_enet_clk_enable(ndev, false);
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002864 pinctrl_pm_select_sleep_state(&pdev->dev);
Oskar Schirmer03c698c2010-10-07 02:30:30 +00002865
Sascha Haueread73182009-01-28 23:03:11 +00002866 ret = register_netdev(ndev);
2867 if (ret)
2868 goto failed_register;
2869
Fabio Estevameb1d0642013-04-13 07:25:36 +00002870 if (fep->bufdesc_ex && fep->ptp_clock)
2871 netdev_info(ndev, "registered PHC device %d\n", fep->dev_id);
2872
Russell King36cdc742014-07-08 13:01:44 +01002873 INIT_WORK(&fep->tx_timeout_work, fec_enet_timeout_work);
Sascha Haueread73182009-01-28 23:03:11 +00002874 return 0;
2875
2876failed_register:
Bryan Wue6b043d2010-03-31 02:10:44 +00002877 fec_enet_mii_remove(fep);
2878failed_mii_init:
Fabio Estevam7a2bbd82013-05-27 03:48:30 +00002879failed_irq:
Fabio Estevam7a2bbd82013-05-27 03:48:30 +00002880failed_init:
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002881 if (fep->reg_phy)
2882 regulator_disable(fep->reg_phy);
Shawn Guo5fa9c0f2012-06-27 03:45:21 +00002883failed_regulator:
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002884 fec_enet_clk_enable(ndev, false);
Sascha Haueread73182009-01-28 23:03:11 +00002885failed_clk:
Uwe Kleine-König407066f2014-08-11 17:35:33 +02002886failed_phy:
2887 of_node_put(phy_node);
Sascha Haueread73182009-01-28 23:03:11 +00002888failed_ioremap:
2889 free_netdev(ndev);
2890
2891 return ret;
2892}
2893
Bill Pemberton33897cc2012-12-03 09:23:58 -05002894static int
Sascha Haueread73182009-01-28 23:03:11 +00002895fec_drv_remove(struct platform_device *pdev)
2896{
2897 struct net_device *ndev = platform_get_drvdata(pdev);
2898 struct fec_enet_private *fep = netdev_priv(ndev);
2899
Nimrod Andy91c0d982014-08-21 17:09:38 +08002900 cancel_delayed_work_sync(&fep->time_keep);
Russell King36cdc742014-07-08 13:01:44 +01002901 cancel_work_sync(&fep->tx_timeout_work);
Lothar Waßmanne163cc92011-12-07 21:59:31 +00002902 unregister_netdev(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00002903 fec_enet_mii_remove(fep);
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002904 if (fep->reg_phy)
2905 regulator_disable(fep->reg_phy);
Frank Li6605b732012-10-30 18:25:31 +00002906 if (fep->ptp_clock)
2907 ptp_clock_unregister(fep->ptp_clock);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002908 fec_enet_clk_enable(ndev, false);
Uwe Kleine-König407066f2014-08-11 17:35:33 +02002909 of_node_put(fep->phy_node);
Sascha Haueread73182009-01-28 23:03:11 +00002910 free_netdev(ndev);
Uwe Kleine-König28e21882011-01-13 21:44:18 +01002911
Sascha Haueread73182009-01-28 23:03:11 +00002912 return 0;
2913}
2914
Fabio Estevamdd66d382014-07-24 18:24:01 -03002915static int __maybe_unused fec_suspend(struct device *dev)
Sascha Haueread73182009-01-28 23:03:11 +00002916{
Eric Benard87cad5c2010-06-18 04:19:54 +00002917 struct net_device *ndev = dev_get_drvdata(dev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002918 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002919
Russell Kingda1774e2014-07-08 12:39:57 +01002920 rtnl_lock();
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002921 if (netif_running(ndev)) {
Russell Kingd76cfae2014-07-08 00:23:04 +01002922 phy_stop(fep->phy_dev);
Russell King31a6de32014-07-08 12:40:23 +01002923 napi_disable(&fep->napi);
2924 netif_tx_lock_bh(ndev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002925 netif_device_detach(ndev);
Russell King31a6de32014-07-08 12:40:23 +01002926 netif_tx_unlock_bh(ndev);
2927 fec_stop(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002928 }
Russell Kingda1774e2014-07-08 12:39:57 +01002929 rtnl_unlock();
2930
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002931 fec_enet_clk_enable(ndev, false);
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002932 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002933
Fabio Estevam238f7bc2013-05-27 03:48:33 +00002934 if (fep->reg_phy)
2935 regulator_disable(fep->reg_phy);
2936
Sascha Haueread73182009-01-28 23:03:11 +00002937 return 0;
2938}
2939
Fabio Estevamdd66d382014-07-24 18:24:01 -03002940static int __maybe_unused fec_resume(struct device *dev)
Sascha Haueread73182009-01-28 23:03:11 +00002941{
Eric Benard87cad5c2010-06-18 04:19:54 +00002942 struct net_device *ndev = dev_get_drvdata(dev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002943 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevam238f7bc2013-05-27 03:48:33 +00002944 int ret;
2945
2946 if (fep->reg_phy) {
2947 ret = regulator_enable(fep->reg_phy);
2948 if (ret)
2949 return ret;
2950 }
Sascha Haueread73182009-01-28 23:03:11 +00002951
Nimrod Andy5bbde4d2014-05-27 15:51:08 +08002952 pinctrl_pm_select_default_state(&fep->pdev->dev);
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002953 ret = fec_enet_clk_enable(ndev, true);
Fabio Estevam13a097b2013-07-21 13:25:02 -03002954 if (ret)
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002955 goto failed_clk;
Fabio Estevam13a097b2013-07-21 13:25:02 -03002956
Russell Kingda1774e2014-07-08 12:39:57 +01002957 rtnl_lock();
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002958 if (netif_running(ndev)) {
Russell Kingef833372014-07-08 12:40:43 +01002959 fec_restart(ndev);
Russell King31a6de32014-07-08 12:40:23 +01002960 netif_tx_lock_bh(ndev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002961 netif_device_attach(ndev);
Russell King6af42d42014-07-08 12:40:18 +01002962 netif_tx_unlock_bh(ndev);
Russell King6af42d42014-07-08 12:40:18 +01002963 napi_enable(&fep->napi);
Russell Kingd76cfae2014-07-08 00:23:04 +01002964 phy_start(fep->phy_dev);
Sascha Haueread73182009-01-28 23:03:11 +00002965 }
Russell Kingda1774e2014-07-08 12:39:57 +01002966 rtnl_unlock();
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002967
Sascha Haueread73182009-01-28 23:03:11 +00002968 return 0;
Fabio Estevam13a097b2013-07-21 13:25:02 -03002969
Nimrod Andye8fcfcd2014-05-20 13:22:51 +08002970failed_clk:
Fabio Estevam13a097b2013-07-21 13:25:02 -03002971 if (fep->reg_phy)
2972 regulator_disable(fep->reg_phy);
2973 return ret;
Sascha Haueread73182009-01-28 23:03:11 +00002974}
2975
Fabio Estevambf7bfd72013-04-16 08:17:46 +00002976static SIMPLE_DEV_PM_OPS(fec_pm_ops, fec_suspend, fec_resume);
Denis Kirjanov59d42892010-06-02 09:27:04 +00002977
Sascha Haueread73182009-01-28 23:03:11 +00002978static struct platform_driver fec_driver = {
2979 .driver = {
Shawn Guob5680e02011-01-05 21:13:13 +00002980 .name = DRIVER_NAME,
Eric Benard87cad5c2010-06-18 04:19:54 +00002981 .owner = THIS_MODULE,
Eric Benard87cad5c2010-06-18 04:19:54 +00002982 .pm = &fec_pm_ops,
Shawn Guoca2cc332011-06-25 02:04:35 +08002983 .of_match_table = fec_dt_ids,
Sascha Haueread73182009-01-28 23:03:11 +00002984 },
Shawn Guob5680e02011-01-05 21:13:13 +00002985 .id_table = fec_devtype,
Eric Benard87cad5c2010-06-18 04:19:54 +00002986 .probe = fec_probe,
Bill Pemberton33897cc2012-12-03 09:23:58 -05002987 .remove = fec_drv_remove,
Sascha Haueread73182009-01-28 23:03:11 +00002988};
2989
Fabio Estevamaaca2372012-01-23 16:44:50 +00002990module_platform_driver(fec_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Fabio Estevamf8c0aca2013-07-20 16:20:36 -03002992MODULE_ALIAS("platform:"DRIVER_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993MODULE_LICENSE("GPL");