blob: 9624537219a8de3f70c0c99ec2e6e71b3c5641db [file] [log] [blame]
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001/*
2 * Driver for Marvell NETA network card for Armada XP and Armada 370 SoCs.
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Rami Rosen <rosenr@marvell.com>
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
Jisheng Zhang0e03f562016-01-20 19:27:22 +080014#include <linux/clk.h>
15#include <linux/cpu.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030016#include <linux/etherdevice.h>
Jisheng Zhang0e03f562016-01-20 19:27:22 +080017#include <linux/if_vlan.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030018#include <linux/inetdevice.h>
Jisheng Zhang0e03f562016-01-20 19:27:22 +080019#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/kernel.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030022#include <linux/mbus.h>
23#include <linux/module.h>
Jisheng Zhang0e03f562016-01-20 19:27:22 +080024#include <linux/netdevice.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030025#include <linux/of.h>
Jisheng Zhang0e03f562016-01-20 19:27:22 +080026#include <linux/of_address.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030027#include <linux/of_irq.h>
28#include <linux/of_mdio.h>
29#include <linux/of_net.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030030#include <linux/phy.h>
Jisheng Zhang0e03f562016-01-20 19:27:22 +080031#include <linux/platform_device.h>
32#include <linux/skbuff.h>
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +010033#include <net/hwbm.h>
Marcin Wojtasdc35a102016-03-14 09:39:03 +010034#include "mvneta_bm.h"
Jisheng Zhang0e03f562016-01-20 19:27:22 +080035#include <net/ip.h>
36#include <net/ipv6.h>
37#include <net/tso.h>
Thomas Petazzonic5aff182012-08-17 14:04:28 +030038
39/* Registers */
40#define MVNETA_RXQ_CONFIG_REG(q) (0x1400 + ((q) << 2))
Marcin Wojtase5bdf682015-11-30 13:27:42 +010041#define MVNETA_RXQ_HW_BUF_ALLOC BIT(0)
Marcin Wojtasdc35a102016-03-14 09:39:03 +010042#define MVNETA_RXQ_SHORT_POOL_ID_SHIFT 4
43#define MVNETA_RXQ_SHORT_POOL_ID_MASK 0x30
44#define MVNETA_RXQ_LONG_POOL_ID_SHIFT 6
45#define MVNETA_RXQ_LONG_POOL_ID_MASK 0xc0
Thomas Petazzonic5aff182012-08-17 14:04:28 +030046#define MVNETA_RXQ_PKT_OFFSET_ALL_MASK (0xf << 8)
47#define MVNETA_RXQ_PKT_OFFSET_MASK(offs) ((offs) << 8)
48#define MVNETA_RXQ_THRESHOLD_REG(q) (0x14c0 + ((q) << 2))
49#define MVNETA_RXQ_NON_OCCUPIED(v) ((v) << 16)
50#define MVNETA_RXQ_BASE_ADDR_REG(q) (0x1480 + ((q) << 2))
51#define MVNETA_RXQ_SIZE_REG(q) (0x14a0 + ((q) << 2))
52#define MVNETA_RXQ_BUF_SIZE_SHIFT 19
53#define MVNETA_RXQ_BUF_SIZE_MASK (0x1fff << 19)
54#define MVNETA_RXQ_STATUS_REG(q) (0x14e0 + ((q) << 2))
55#define MVNETA_RXQ_OCCUPIED_ALL_MASK 0x3fff
56#define MVNETA_RXQ_STATUS_UPDATE_REG(q) (0x1500 + ((q) << 2))
57#define MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT 16
58#define MVNETA_RXQ_ADD_NON_OCCUPIED_MAX 255
Marcin Wojtasdc35a102016-03-14 09:39:03 +010059#define MVNETA_PORT_POOL_BUFFER_SZ_REG(pool) (0x1700 + ((pool) << 2))
60#define MVNETA_PORT_POOL_BUFFER_SZ_SHIFT 3
61#define MVNETA_PORT_POOL_BUFFER_SZ_MASK 0xfff8
Thomas Petazzonic5aff182012-08-17 14:04:28 +030062#define MVNETA_PORT_RX_RESET 0x1cc0
63#define MVNETA_PORT_RX_DMA_RESET BIT(0)
64#define MVNETA_PHY_ADDR 0x2000
65#define MVNETA_PHY_ADDR_MASK 0x1f
66#define MVNETA_MBUS_RETRY 0x2010
67#define MVNETA_UNIT_INTR_CAUSE 0x2080
68#define MVNETA_UNIT_CONTROL 0x20B0
69#define MVNETA_PHY_POLLING_ENABLE BIT(1)
70#define MVNETA_WIN_BASE(w) (0x2200 + ((w) << 3))
71#define MVNETA_WIN_SIZE(w) (0x2204 + ((w) << 3))
72#define MVNETA_WIN_REMAP(w) (0x2280 + ((w) << 2))
73#define MVNETA_BASE_ADDR_ENABLE 0x2290
Marcin Wojtasdb6ba9a2015-11-30 13:27:41 +010074#define MVNETA_ACCESS_PROTECT_ENABLE 0x2294
Thomas Petazzonic5aff182012-08-17 14:04:28 +030075#define MVNETA_PORT_CONFIG 0x2400
76#define MVNETA_UNI_PROMISC_MODE BIT(0)
77#define MVNETA_DEF_RXQ(q) ((q) << 1)
78#define MVNETA_DEF_RXQ_ARP(q) ((q) << 4)
79#define MVNETA_TX_UNSET_ERR_SUM BIT(12)
80#define MVNETA_DEF_RXQ_TCP(q) ((q) << 16)
81#define MVNETA_DEF_RXQ_UDP(q) ((q) << 19)
82#define MVNETA_DEF_RXQ_BPDU(q) ((q) << 22)
83#define MVNETA_RX_CSUM_WITH_PSEUDO_HDR BIT(25)
84#define MVNETA_PORT_CONFIG_DEFL_VALUE(q) (MVNETA_DEF_RXQ(q) | \
85 MVNETA_DEF_RXQ_ARP(q) | \
86 MVNETA_DEF_RXQ_TCP(q) | \
87 MVNETA_DEF_RXQ_UDP(q) | \
88 MVNETA_DEF_RXQ_BPDU(q) | \
89 MVNETA_TX_UNSET_ERR_SUM | \
90 MVNETA_RX_CSUM_WITH_PSEUDO_HDR)
91#define MVNETA_PORT_CONFIG_EXTEND 0x2404
92#define MVNETA_MAC_ADDR_LOW 0x2414
93#define MVNETA_MAC_ADDR_HIGH 0x2418
94#define MVNETA_SDMA_CONFIG 0x241c
95#define MVNETA_SDMA_BRST_SIZE_16 4
Thomas Petazzonic5aff182012-08-17 14:04:28 +030096#define MVNETA_RX_BRST_SZ_MASK(burst) ((burst) << 1)
97#define MVNETA_RX_NO_DATA_SWAP BIT(4)
98#define MVNETA_TX_NO_DATA_SWAP BIT(5)
Thomas Petazzoni9ad8fef2013-07-29 15:21:28 +020099#define MVNETA_DESC_SWAP BIT(6)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300100#define MVNETA_TX_BRST_SZ_MASK(burst) ((burst) << 22)
101#define MVNETA_PORT_STATUS 0x2444
102#define MVNETA_TX_IN_PRGRS BIT(1)
103#define MVNETA_TX_FIFO_EMPTY BIT(8)
104#define MVNETA_RX_MIN_FRAME_SIZE 0x247c
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +0200105#define MVNETA_SERDES_CFG 0x24A0
Arnaud Patard \(Rtp\)5445eaf2013-07-29 21:56:48 +0200106#define MVNETA_SGMII_SERDES_PROTO 0x0cc7
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +0200107#define MVNETA_QSGMII_SERDES_PROTO 0x0667
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300108#define MVNETA_TYPE_PRIO 0x24bc
109#define MVNETA_FORCE_UNI BIT(21)
110#define MVNETA_TXQ_CMD_1 0x24e4
111#define MVNETA_TXQ_CMD 0x2448
112#define MVNETA_TXQ_DISABLE_SHIFT 8
113#define MVNETA_TXQ_ENABLE_MASK 0x000000ff
Andrew Lunne4839112015-10-22 18:37:36 +0100114#define MVNETA_RX_DISCARD_FRAME_COUNT 0x2484
115#define MVNETA_OVERRUN_FRAME_COUNT 0x2488
Stas Sergeev898b29702015-04-01 20:32:49 +0300116#define MVNETA_GMAC_CLOCK_DIVIDER 0x24f4
117#define MVNETA_GMAC_1MS_CLOCK_ENABLE BIT(31)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300118#define MVNETA_ACC_MODE 0x2500
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100119#define MVNETA_BM_ADDRESS 0x2504
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300120#define MVNETA_CPU_MAP(cpu) (0x2540 + ((cpu) << 2))
121#define MVNETA_CPU_RXQ_ACCESS_ALL_MASK 0x000000ff
122#define MVNETA_CPU_TXQ_ACCESS_ALL_MASK 0x0000ff00
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +0100123#define MVNETA_CPU_RXQ_ACCESS(rxq) BIT(rxq)
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +0100124#define MVNETA_CPU_TXQ_ACCESS(txq) BIT(txq + 8)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300125#define MVNETA_RXQ_TIME_COAL_REG(q) (0x2580 + ((q) << 2))
willy tarreau40ba35e2014-01-16 08:20:10 +0100126
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +0100127/* Exception Interrupt Port/Queue Cause register
128 *
129 * Their behavior depend of the mapping done using the PCPX2Q
130 * registers. For a given CPU if the bit associated to a queue is not
131 * set, then for the register a read from this CPU will always return
132 * 0 and a write won't do anything
133 */
willy tarreau40ba35e2014-01-16 08:20:10 +0100134
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300135#define MVNETA_INTR_NEW_CAUSE 0x25a0
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300136#define MVNETA_INTR_NEW_MASK 0x25a4
willy tarreau40ba35e2014-01-16 08:20:10 +0100137
138/* bits 0..7 = TXQ SENT, one bit per queue.
139 * bits 8..15 = RXQ OCCUP, one bit per queue.
140 * bits 16..23 = RXQ FREE, one bit per queue.
141 * bit 29 = OLD_REG_SUM, see old reg ?
142 * bit 30 = TX_ERR_SUM, one bit for 4 ports
143 * bit 31 = MISC_SUM, one bit for 4 ports
144 */
145#define MVNETA_TX_INTR_MASK(nr_txqs) (((1 << nr_txqs) - 1) << 0)
146#define MVNETA_TX_INTR_MASK_ALL (0xff << 0)
147#define MVNETA_RX_INTR_MASK(nr_rxqs) (((1 << nr_rxqs) - 1) << 8)
148#define MVNETA_RX_INTR_MASK_ALL (0xff << 8)
Stas Sergeev898b29702015-04-01 20:32:49 +0300149#define MVNETA_MISCINTR_INTR_MASK BIT(31)
willy tarreau40ba35e2014-01-16 08:20:10 +0100150
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300151#define MVNETA_INTR_OLD_CAUSE 0x25a8
152#define MVNETA_INTR_OLD_MASK 0x25ac
willy tarreau40ba35e2014-01-16 08:20:10 +0100153
154/* Data Path Port/Queue Cause Register */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300155#define MVNETA_INTR_MISC_CAUSE 0x25b0
156#define MVNETA_INTR_MISC_MASK 0x25b4
willy tarreau40ba35e2014-01-16 08:20:10 +0100157
158#define MVNETA_CAUSE_PHY_STATUS_CHANGE BIT(0)
159#define MVNETA_CAUSE_LINK_CHANGE BIT(1)
160#define MVNETA_CAUSE_PTP BIT(4)
161
162#define MVNETA_CAUSE_INTERNAL_ADDR_ERR BIT(7)
163#define MVNETA_CAUSE_RX_OVERRUN BIT(8)
164#define MVNETA_CAUSE_RX_CRC_ERROR BIT(9)
165#define MVNETA_CAUSE_RX_LARGE_PKT BIT(10)
166#define MVNETA_CAUSE_TX_UNDERUN BIT(11)
167#define MVNETA_CAUSE_PRBS_ERR BIT(12)
168#define MVNETA_CAUSE_PSC_SYNC_CHANGE BIT(13)
169#define MVNETA_CAUSE_SERDES_SYNC_ERR BIT(14)
170
171#define MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT 16
172#define MVNETA_CAUSE_BMU_ALLOC_ERR_ALL_MASK (0xF << MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT)
173#define MVNETA_CAUSE_BMU_ALLOC_ERR_MASK(pool) (1 << (MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT + (pool)))
174
175#define MVNETA_CAUSE_TXQ_ERROR_SHIFT 24
176#define MVNETA_CAUSE_TXQ_ERROR_ALL_MASK (0xFF << MVNETA_CAUSE_TXQ_ERROR_SHIFT)
177#define MVNETA_CAUSE_TXQ_ERROR_MASK(q) (1 << (MVNETA_CAUSE_TXQ_ERROR_SHIFT + (q)))
178
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300179#define MVNETA_INTR_ENABLE 0x25b8
180#define MVNETA_TXQ_INTR_ENABLE_ALL_MASK 0x0000ff00
Marcin Wojtasdc1aadf2015-11-30 13:27:43 +0100181#define MVNETA_RXQ_INTR_ENABLE_ALL_MASK 0x000000ff
willy tarreau40ba35e2014-01-16 08:20:10 +0100182
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300183#define MVNETA_RXQ_CMD 0x2680
184#define MVNETA_RXQ_DISABLE_SHIFT 8
185#define MVNETA_RXQ_ENABLE_MASK 0x000000ff
186#define MVETH_TXQ_TOKEN_COUNT_REG(q) (0x2700 + ((q) << 4))
187#define MVETH_TXQ_TOKEN_CFG_REG(q) (0x2704 + ((q) << 4))
188#define MVNETA_GMAC_CTRL_0 0x2c00
189#define MVNETA_GMAC_MAX_RX_SIZE_SHIFT 2
190#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc
191#define MVNETA_GMAC0_PORT_ENABLE BIT(0)
192#define MVNETA_GMAC_CTRL_2 0x2c08
Stas Sergeev898b29702015-04-01 20:32:49 +0300193#define MVNETA_GMAC2_INBAND_AN_ENABLE BIT(0)
Thomas Petazzonia79121d2014-03-26 00:25:41 +0100194#define MVNETA_GMAC2_PCS_ENABLE BIT(3)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300195#define MVNETA_GMAC2_PORT_RGMII BIT(4)
196#define MVNETA_GMAC2_PORT_RESET BIT(6)
197#define MVNETA_GMAC_STATUS 0x2c10
198#define MVNETA_GMAC_LINK_UP BIT(0)
199#define MVNETA_GMAC_SPEED_1000 BIT(1)
200#define MVNETA_GMAC_SPEED_100 BIT(2)
201#define MVNETA_GMAC_FULL_DUPLEX BIT(3)
202#define MVNETA_GMAC_RX_FLOW_CTRL_ENABLE BIT(4)
203#define MVNETA_GMAC_TX_FLOW_CTRL_ENABLE BIT(5)
204#define MVNETA_GMAC_RX_FLOW_CTRL_ACTIVE BIT(6)
205#define MVNETA_GMAC_TX_FLOW_CTRL_ACTIVE BIT(7)
206#define MVNETA_GMAC_AUTONEG_CONFIG 0x2c0c
207#define MVNETA_GMAC_FORCE_LINK_DOWN BIT(0)
208#define MVNETA_GMAC_FORCE_LINK_PASS BIT(1)
Stas Sergeev898b29702015-04-01 20:32:49 +0300209#define MVNETA_GMAC_INBAND_AN_ENABLE BIT(2)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300210#define MVNETA_GMAC_CONFIG_MII_SPEED BIT(5)
211#define MVNETA_GMAC_CONFIG_GMII_SPEED BIT(6)
Thomas Petazzoni71408602013-09-04 16:21:18 +0200212#define MVNETA_GMAC_AN_SPEED_EN BIT(7)
Stas Sergeev898b29702015-04-01 20:32:49 +0300213#define MVNETA_GMAC_AN_FLOW_CTRL_EN BIT(11)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300214#define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12)
Thomas Petazzoni71408602013-09-04 16:21:18 +0200215#define MVNETA_GMAC_AN_DUPLEX_EN BIT(13)
Andrew Lunne4839112015-10-22 18:37:36 +0100216#define MVNETA_MIB_COUNTERS_BASE 0x3000
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300217#define MVNETA_MIB_LATE_COLLISION 0x7c
218#define MVNETA_DA_FILT_SPEC_MCAST 0x3400
219#define MVNETA_DA_FILT_OTH_MCAST 0x3500
220#define MVNETA_DA_FILT_UCAST_BASE 0x3600
221#define MVNETA_TXQ_BASE_ADDR_REG(q) (0x3c00 + ((q) << 2))
222#define MVNETA_TXQ_SIZE_REG(q) (0x3c20 + ((q) << 2))
223#define MVNETA_TXQ_SENT_THRESH_ALL_MASK 0x3fff0000
224#define MVNETA_TXQ_SENT_THRESH_MASK(coal) ((coal) << 16)
225#define MVNETA_TXQ_UPDATE_REG(q) (0x3c60 + ((q) << 2))
226#define MVNETA_TXQ_DEC_SENT_SHIFT 16
Simon Guinot2a90f7e2017-01-16 18:08:31 +0100227#define MVNETA_TXQ_DEC_SENT_MASK 0xff
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300228#define MVNETA_TXQ_STATUS_REG(q) (0x3c40 + ((q) << 2))
229#define MVNETA_TXQ_SENT_DESC_SHIFT 16
230#define MVNETA_TXQ_SENT_DESC_MASK 0x3fff0000
231#define MVNETA_PORT_TX_RESET 0x3cf0
232#define MVNETA_PORT_TX_DMA_RESET BIT(0)
233#define MVNETA_TX_MTU 0x3e0c
234#define MVNETA_TX_TOKEN_SIZE 0x3e14
235#define MVNETA_TX_TOKEN_SIZE_MAX 0xffffffff
236#define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2))
237#define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff
238
239#define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
240
241/* Descriptor ring Macros */
242#define MVNETA_QUEUE_NEXT_DESC(q, index) \
243 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
244
245/* Various constants */
246
247/* Coalescing */
Dmitri Epshtein06708f82016-07-06 04:18:58 +0200248#define MVNETA_TXDONE_COAL_PKTS 0 /* interrupt per packet */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300249#define MVNETA_RX_COAL_PKTS 32
250#define MVNETA_RX_COAL_USEC 100
251
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100252/* The two bytes Marvell header. Either contains a special value used
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300253 * by Marvell switches when a specific hardware mode is enabled (not
254 * supported by this driver) or is filled automatically by zeroes on
255 * the RX side. Those two bytes being at the front of the Ethernet
256 * header, they allow to have the IP header aligned on a 4 bytes
257 * boundary automatically: the hardware skips those two bytes on its
258 * own.
259 */
260#define MVNETA_MH_SIZE 2
261
262#define MVNETA_VLAN_TAG_LEN 4
263
Marcin Wojtas9110ee02015-11-30 13:27:45 +0100264#define MVNETA_TX_CSUM_DEF_SIZE 1600
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300265#define MVNETA_TX_CSUM_MAX_SIZE 9800
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100266#define MVNETA_ACC_MODE_EXT1 1
267#define MVNETA_ACC_MODE_EXT2 2
268
269#define MVNETA_MAX_DECODE_WIN 6
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300270
271/* Timeout constants */
272#define MVNETA_TX_DISABLE_TIMEOUT_MSEC 1000
273#define MVNETA_RX_DISABLE_TIMEOUT_MSEC 1000
274#define MVNETA_TX_FIFO_EMPTY_TIMEOUT 10000
275
276#define MVNETA_TX_MTU_MAX 0x3ffff
277
Gregory CLEMENT9a401de2015-12-09 18:23:50 +0100278/* The RSS lookup table actually has 256 entries but we do not use
279 * them yet
280 */
281#define MVNETA_RSS_LU_TABLE_SIZE 1
282
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -0300283/* TSO header size */
284#define TSO_HEADER_SIZE 128
285
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300286/* Max number of Rx descriptors */
287#define MVNETA_MAX_RXD 128
288
289/* Max number of Tx descriptors */
290#define MVNETA_MAX_TXD 532
291
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -0300292/* Max number of allowed TCP segments for software TSO */
293#define MVNETA_MAX_TSO_SEGS 100
294
295#define MVNETA_MAX_SKB_DESCS (MVNETA_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
296
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300297/* descriptor aligned size */
298#define MVNETA_DESC_ALIGNED_SIZE 32
299
Marcin Wojtas8d5047c2016-12-01 18:03:07 +0100300/* Number of bytes to be taken into account by HW when putting incoming data
301 * to the buffers. It is needed in case NET_SKB_PAD exceeds maximum packet
302 * offset supported in MVNETA_RXQ_CONFIG_REG(q) registers.
303 */
304#define MVNETA_RX_PKT_OFFSET_CORRECTION 64
305
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300306#define MVNETA_RX_PKT_SIZE(mtu) \
307 ALIGN((mtu) + MVNETA_MH_SIZE + MVNETA_VLAN_TAG_LEN + \
308 ETH_HLEN + ETH_FCS_LEN, \
Jisheng Zhangc66e98c2016-04-01 17:12:49 +0800309 cache_line_size())
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300310
Ezequiel Garcia2e3173a2014-05-30 13:40:07 -0300311#define IS_TSO_HEADER(txq, addr) \
312 ((addr >= txq->tso_hdrs_phys) && \
313 (addr < txq->tso_hdrs_phys + txq->size * TSO_HEADER_SIZE))
314
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100315#define MVNETA_RX_GET_BM_POOL_ID(rxd) \
316 (((rxd)->status & MVNETA_RXD_BM_POOL_MASK) >> MVNETA_RXD_BM_POOL_SHIFT)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300317
Russell King9b0cdef2015-10-22 18:37:30 +0100318struct mvneta_statistic {
319 unsigned short offset;
320 unsigned short type;
321 const char name[ETH_GSTRING_LEN];
322};
323
324#define T_REG_32 32
325#define T_REG_64 64
326
327static const struct mvneta_statistic mvneta_statistics[] = {
328 { 0x3000, T_REG_64, "good_octets_received", },
329 { 0x3010, T_REG_32, "good_frames_received", },
330 { 0x3008, T_REG_32, "bad_octets_received", },
331 { 0x3014, T_REG_32, "bad_frames_received", },
332 { 0x3018, T_REG_32, "broadcast_frames_received", },
333 { 0x301c, T_REG_32, "multicast_frames_received", },
334 { 0x3050, T_REG_32, "unrec_mac_control_received", },
335 { 0x3058, T_REG_32, "good_fc_received", },
336 { 0x305c, T_REG_32, "bad_fc_received", },
337 { 0x3060, T_REG_32, "undersize_received", },
338 { 0x3064, T_REG_32, "fragments_received", },
339 { 0x3068, T_REG_32, "oversize_received", },
340 { 0x306c, T_REG_32, "jabber_received", },
341 { 0x3070, T_REG_32, "mac_receive_error", },
342 { 0x3074, T_REG_32, "bad_crc_event", },
343 { 0x3078, T_REG_32, "collision", },
344 { 0x307c, T_REG_32, "late_collision", },
345 { 0x2484, T_REG_32, "rx_discard", },
346 { 0x2488, T_REG_32, "rx_overrun", },
347 { 0x3020, T_REG_32, "frames_64_octets", },
348 { 0x3024, T_REG_32, "frames_65_to_127_octets", },
349 { 0x3028, T_REG_32, "frames_128_to_255_octets", },
350 { 0x302c, T_REG_32, "frames_256_to_511_octets", },
351 { 0x3030, T_REG_32, "frames_512_to_1023_octets", },
352 { 0x3034, T_REG_32, "frames_1024_to_max_octets", },
353 { 0x3038, T_REG_64, "good_octets_sent", },
354 { 0x3040, T_REG_32, "good_frames_sent", },
355 { 0x3044, T_REG_32, "excessive_collision", },
356 { 0x3048, T_REG_32, "multicast_frames_sent", },
357 { 0x304c, T_REG_32, "broadcast_frames_sent", },
358 { 0x3054, T_REG_32, "fc_sent", },
359 { 0x300c, T_REG_32, "internal_mac_transmit_err", },
360};
361
willy tarreau74c41b02014-01-16 08:20:08 +0100362struct mvneta_pcpu_stats {
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300363 struct u64_stats_sync syncp;
willy tarreau74c41b02014-01-16 08:20:08 +0100364 u64 rx_packets;
365 u64 rx_bytes;
366 u64 tx_packets;
367 u64 tx_bytes;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300368};
369
Maxime Ripard12bb03b2015-09-25 18:09:36 +0200370struct mvneta_pcpu_port {
371 /* Pointer to the shared port */
372 struct mvneta_port *pp;
373
374 /* Pointer to the CPU-local NAPI struct */
375 struct napi_struct napi;
376
377 /* Cause of the previous interrupt */
378 u32 cause_rx_tx;
379};
380
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300381struct mvneta_port {
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100382 u8 id;
Maxime Ripard12bb03b2015-09-25 18:09:36 +0200383 struct mvneta_pcpu_port __percpu *ports;
384 struct mvneta_pcpu_stats __percpu *stats;
385
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300386 int pkt_size;
willy tarreau8ec2cd42014-01-16 08:20:16 +0100387 unsigned int frag_size;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300388 void __iomem *base;
389 struct mvneta_rx_queue *rxqs;
390 struct mvneta_tx_queue *txqs;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300391 struct net_device *dev;
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +0200392 struct hlist_node node_online;
393 struct hlist_node node_dead;
Gregory CLEMENT90b74c02015-12-09 18:23:48 +0100394 int rxq_def;
Gregory CLEMENT58885112016-02-04 22:09:28 +0100395 /* Protect the access to the percpu interrupt registers,
396 * ensuring that the configuration remains coherent.
397 */
398 spinlock_t lock;
Gregory CLEMENT120cfa52016-02-04 22:09:29 +0100399 bool is_stopped;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300400
Marcin Wojtas2636ac32016-12-01 18:03:09 +0100401 u32 cause_rx_tx;
402 struct napi_struct napi;
403
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300404 /* Core clock */
Thomas Petazzoni189dd622012-11-19 14:15:25 +0100405 struct clk *clk;
Jisheng Zhang15cc4a42016-01-20 19:27:24 +0800406 /* AXI clock */
407 struct clk *clk_bus;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300408 u8 mcast_count[256];
409 u16 tx_ring_size;
410 u16 rx_ring_size;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300411
412 struct mii_bus *mii_bus;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300413 phy_interface_t phy_interface;
414 struct device_node *phy_node;
415 unsigned int link;
416 unsigned int duplex;
417 unsigned int speed;
Simon Guinotb65657f2015-06-30 16:20:22 +0200418 unsigned int tx_csum_limit;
Stas Sergeev0c0744f2015-12-02 20:35:11 +0300419 unsigned int use_inband_status:1;
Russell King9b0cdef2015-10-22 18:37:30 +0100420
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100421 struct mvneta_bm *bm_priv;
422 struct mvneta_bm_pool *pool_long;
423 struct mvneta_bm_pool *pool_short;
424 int bm_win_id;
425
Russell King9b0cdef2015-10-22 18:37:30 +0100426 u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)];
Gregory CLEMENT9a401de2015-12-09 18:23:50 +0100427
428 u32 indir[MVNETA_RSS_LU_TABLE_SIZE];
Marcin Wojtas2636ac32016-12-01 18:03:09 +0100429
430 /* Flags for special SoC configurations */
431 bool neta_armada3700;
Marcin Wojtas8d5047c2016-12-01 18:03:07 +0100432 u16 rx_offset_correction;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300433};
434
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100435/* The mvneta_tx_desc and mvneta_rx_desc structures describe the
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300436 * layout of the transmit and reception DMA descriptors, and their
437 * layout is therefore defined by the hardware design
438 */
Thomas Petazzoni6083ed42013-07-29 15:21:27 +0200439
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300440#define MVNETA_TX_L3_OFF_SHIFT 0
441#define MVNETA_TX_IP_HLEN_SHIFT 8
442#define MVNETA_TX_L4_UDP BIT(16)
443#define MVNETA_TX_L3_IP6 BIT(17)
444#define MVNETA_TXD_IP_CSUM BIT(18)
445#define MVNETA_TXD_Z_PAD BIT(19)
446#define MVNETA_TXD_L_DESC BIT(20)
447#define MVNETA_TXD_F_DESC BIT(21)
448#define MVNETA_TXD_FLZ_DESC (MVNETA_TXD_Z_PAD | \
449 MVNETA_TXD_L_DESC | \
450 MVNETA_TXD_F_DESC)
451#define MVNETA_TX_L4_CSUM_FULL BIT(30)
452#define MVNETA_TX_L4_CSUM_NOT BIT(31)
453
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300454#define MVNETA_RXD_ERR_CRC 0x0
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100455#define MVNETA_RXD_BM_POOL_SHIFT 13
456#define MVNETA_RXD_BM_POOL_MASK (BIT(13) | BIT(14))
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300457#define MVNETA_RXD_ERR_SUMMARY BIT(16)
458#define MVNETA_RXD_ERR_OVERRUN BIT(17)
459#define MVNETA_RXD_ERR_LEN BIT(18)
460#define MVNETA_RXD_ERR_RESOURCE (BIT(17) | BIT(18))
461#define MVNETA_RXD_ERR_CODE_MASK (BIT(17) | BIT(18))
462#define MVNETA_RXD_L3_IP4 BIT(25)
463#define MVNETA_RXD_FIRST_LAST_DESC (BIT(26) | BIT(27))
464#define MVNETA_RXD_L4_CSUM_OK BIT(30)
465
Thomas Petazzoni9ad8fef2013-07-29 15:21:28 +0200466#if defined(__LITTLE_ENDIAN)
Thomas Petazzoni6083ed42013-07-29 15:21:27 +0200467struct mvneta_tx_desc {
468 u32 command; /* Options used by HW for packet transmitting.*/
469 u16 reserverd1; /* csum_l4 (for future use) */
470 u16 data_size; /* Data size of transmitted packet in bytes */
471 u32 buf_phys_addr; /* Physical addr of transmitted buffer */
472 u32 reserved2; /* hw_cmd - (for future use, PMT) */
473 u32 reserved3[4]; /* Reserved - (for future use) */
474};
475
476struct mvneta_rx_desc {
477 u32 status; /* Info about received packet */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300478 u16 reserved1; /* pnc_info - (for future use, PnC) */
479 u16 data_size; /* Size of received packet in bytes */
Thomas Petazzoni6083ed42013-07-29 15:21:27 +0200480
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300481 u32 buf_phys_addr; /* Physical address of the buffer */
482 u32 reserved2; /* pnc_flow_id (for future use, PnC) */
Thomas Petazzoni6083ed42013-07-29 15:21:27 +0200483
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300484 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
485 u16 reserved3; /* prefetch_cmd, for future use */
486 u16 reserved4; /* csum_l4 - (for future use, PnC) */
Thomas Petazzoni6083ed42013-07-29 15:21:27 +0200487
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300488 u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
489 u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
490};
Thomas Petazzoni9ad8fef2013-07-29 15:21:28 +0200491#else
492struct mvneta_tx_desc {
493 u16 data_size; /* Data size of transmitted packet in bytes */
494 u16 reserverd1; /* csum_l4 (for future use) */
495 u32 command; /* Options used by HW for packet transmitting.*/
496 u32 reserved2; /* hw_cmd - (for future use, PMT) */
497 u32 buf_phys_addr; /* Physical addr of transmitted buffer */
498 u32 reserved3[4]; /* Reserved - (for future use) */
499};
500
501struct mvneta_rx_desc {
502 u16 data_size; /* Size of received packet in bytes */
503 u16 reserved1; /* pnc_info - (for future use, PnC) */
504 u32 status; /* Info about received packet */
505
506 u32 reserved2; /* pnc_flow_id (for future use, PnC) */
507 u32 buf_phys_addr; /* Physical address of the buffer */
508
509 u16 reserved4; /* csum_l4 - (for future use, PnC) */
510 u16 reserved3; /* prefetch_cmd, for future use */
511 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
512
513 u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
514 u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
515};
516#endif
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300517
518struct mvneta_tx_queue {
519 /* Number of this TX queue, in the range 0-7 */
520 u8 id;
521
522 /* Number of TX DMA descriptors in the descriptor ring */
523 int size;
524
525 /* Number of currently used TX DMA descriptor in the
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100526 * descriptor ring
527 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300528 int count;
Simon Guinot2a90f7e2017-01-16 18:08:31 +0100529 int pending;
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -0300530 int tx_stop_threshold;
531 int tx_wake_threshold;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300532
533 /* Array of transmitted skb */
534 struct sk_buff **tx_skb;
535
536 /* Index of last TX DMA descriptor that was inserted */
537 int txq_put_index;
538
539 /* Index of the TX DMA descriptor to be cleaned up */
540 int txq_get_index;
541
542 u32 done_pkts_coal;
543
544 /* Virtual address of the TX DMA descriptors array */
545 struct mvneta_tx_desc *descs;
546
547 /* DMA address of the TX DMA descriptors array */
548 dma_addr_t descs_phys;
549
550 /* Index of the last TX DMA descriptor */
551 int last_desc;
552
553 /* Index of the next TX DMA descriptor to process */
554 int next_desc_to_proc;
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -0300555
556 /* DMA buffers for TSO headers */
557 char *tso_hdrs;
558
559 /* DMA address of TSO headers */
560 dma_addr_t tso_hdrs_phys;
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +0100561
562 /* Affinity mask for CPUs*/
563 cpumask_t affinity_mask;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300564};
565
566struct mvneta_rx_queue {
567 /* rx queue number, in the range 0-7 */
568 u8 id;
569
570 /* num of rx descriptors in the rx descriptor ring */
571 int size;
572
573 /* counter of times when mvneta_refill() failed */
574 int missed;
575
576 u32 pkts_coal;
577 u32 time_coal;
578
Gregory CLEMENTf88bee12016-12-01 18:03:06 +0100579 /* Virtual address of the RX buffer */
580 void **buf_virt_addr;
581
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300582 /* Virtual address of the RX DMA descriptors array */
583 struct mvneta_rx_desc *descs;
584
585 /* DMA address of the RX DMA descriptors array */
586 dma_addr_t descs_phys;
587
588 /* Index of the last RX DMA descriptor */
589 int last_desc;
590
591 /* Index of the next RX DMA descriptor to process */
592 int next_desc_to_proc;
593};
594
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +0200595static enum cpuhp_state online_hpstate;
Ezequiel Garciaedadb7f2014-05-22 20:07:01 -0300596/* The hardware supports eight (8) rx queues, but we are only allowing
597 * the first one to be used. Therefore, let's just allocate one queue.
598 */
Maxime Ripardd8936652015-09-25 18:09:37 +0200599static int rxq_number = 8;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300600static int txq_number = 8;
601
602static int rxq_def;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300603
willy tarreauf19fadf2014-01-16 08:20:17 +0100604static int rx_copybreak __read_mostly = 256;
605
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100606/* HW BM need that each port be identify by a unique ID */
607static int global_port_id;
608
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300609#define MVNETA_DRIVER_NAME "mvneta"
610#define MVNETA_DRIVER_VERSION "1.0"
611
612/* Utility/helper methods */
613
614/* Write helper method */
615static void mvreg_write(struct mvneta_port *pp, u32 offset, u32 data)
616{
617 writel(data, pp->base + offset);
618}
619
620/* Read helper method */
621static u32 mvreg_read(struct mvneta_port *pp, u32 offset)
622{
623 return readl(pp->base + offset);
624}
625
626/* Increment txq get counter */
627static void mvneta_txq_inc_get(struct mvneta_tx_queue *txq)
628{
629 txq->txq_get_index++;
630 if (txq->txq_get_index == txq->size)
631 txq->txq_get_index = 0;
632}
633
634/* Increment txq put counter */
635static void mvneta_txq_inc_put(struct mvneta_tx_queue *txq)
636{
637 txq->txq_put_index++;
638 if (txq->txq_put_index == txq->size)
639 txq->txq_put_index = 0;
640}
641
642
643/* Clear all MIB counters */
644static void mvneta_mib_counters_clear(struct mvneta_port *pp)
645{
646 int i;
647 u32 dummy;
648
649 /* Perform dummy reads from MIB counters */
650 for (i = 0; i < MVNETA_MIB_LATE_COLLISION; i += 4)
651 dummy = mvreg_read(pp, (MVNETA_MIB_COUNTERS_BASE + i));
Andrew Lunne4839112015-10-22 18:37:36 +0100652 dummy = mvreg_read(pp, MVNETA_RX_DISCARD_FRAME_COUNT);
653 dummy = mvreg_read(pp, MVNETA_OVERRUN_FRAME_COUNT);
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300654}
655
656/* Get System Network Statistics */
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800657static void
Baoyou Xie2dc0d2b2016-09-25 17:20:41 +0800658mvneta_get_stats64(struct net_device *dev,
659 struct rtnl_link_stats64 *stats)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300660{
661 struct mvneta_port *pp = netdev_priv(dev);
662 unsigned int start;
willy tarreau74c41b02014-01-16 08:20:08 +0100663 int cpu;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300664
willy tarreau74c41b02014-01-16 08:20:08 +0100665 for_each_possible_cpu(cpu) {
666 struct mvneta_pcpu_stats *cpu_stats;
667 u64 rx_packets;
668 u64 rx_bytes;
669 u64 tx_packets;
670 u64 tx_bytes;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300671
willy tarreau74c41b02014-01-16 08:20:08 +0100672 cpu_stats = per_cpu_ptr(pp->stats, cpu);
673 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700674 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
willy tarreau74c41b02014-01-16 08:20:08 +0100675 rx_packets = cpu_stats->rx_packets;
676 rx_bytes = cpu_stats->rx_bytes;
677 tx_packets = cpu_stats->tx_packets;
678 tx_bytes = cpu_stats->tx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700679 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300680
willy tarreau74c41b02014-01-16 08:20:08 +0100681 stats->rx_packets += rx_packets;
682 stats->rx_bytes += rx_bytes;
683 stats->tx_packets += tx_packets;
684 stats->tx_bytes += tx_bytes;
685 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300686
687 stats->rx_errors = dev->stats.rx_errors;
688 stats->rx_dropped = dev->stats.rx_dropped;
689
690 stats->tx_dropped = dev->stats.tx_dropped;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300691}
692
693/* Rx descriptors helper methods */
694
willy tarreau54282132014-01-16 08:20:14 +0100695/* Checks whether the RX descriptor having this status is both the first
696 * and the last descriptor for the RX packet. Each RX packet is currently
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300697 * received through a single RX descriptor, so not having each RX
698 * descriptor with its first and last bits set is an error
699 */
willy tarreau54282132014-01-16 08:20:14 +0100700static int mvneta_rxq_desc_is_first_last(u32 status)
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300701{
willy tarreau54282132014-01-16 08:20:14 +0100702 return (status & MVNETA_RXD_FIRST_LAST_DESC) ==
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300703 MVNETA_RXD_FIRST_LAST_DESC;
704}
705
706/* Add number of descriptors ready to receive new packets */
707static void mvneta_rxq_non_occup_desc_add(struct mvneta_port *pp,
708 struct mvneta_rx_queue *rxq,
709 int ndescs)
710{
711 /* Only MVNETA_RXQ_ADD_NON_OCCUPIED_MAX (255) descriptors can
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100712 * be added at once
713 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300714 while (ndescs > MVNETA_RXQ_ADD_NON_OCCUPIED_MAX) {
715 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
716 (MVNETA_RXQ_ADD_NON_OCCUPIED_MAX <<
717 MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
718 ndescs -= MVNETA_RXQ_ADD_NON_OCCUPIED_MAX;
719 }
720
721 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
722 (ndescs << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
723}
724
725/* Get number of RX descriptors occupied by received packets */
726static int mvneta_rxq_busy_desc_num_get(struct mvneta_port *pp,
727 struct mvneta_rx_queue *rxq)
728{
729 u32 val;
730
731 val = mvreg_read(pp, MVNETA_RXQ_STATUS_REG(rxq->id));
732 return val & MVNETA_RXQ_OCCUPIED_ALL_MASK;
733}
734
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100735/* Update num of rx desc called upon return from rx path or
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300736 * from mvneta_rxq_drop_pkts().
737 */
738static void mvneta_rxq_desc_num_update(struct mvneta_port *pp,
739 struct mvneta_rx_queue *rxq,
740 int rx_done, int rx_filled)
741{
742 u32 val;
743
744 if ((rx_done <= 0xff) && (rx_filled <= 0xff)) {
745 val = rx_done |
746 (rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT);
747 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
748 return;
749 }
750
751 /* Only 255 descriptors can be added at once */
752 while ((rx_done > 0) || (rx_filled > 0)) {
753 if (rx_done <= 0xff) {
754 val = rx_done;
755 rx_done = 0;
756 } else {
757 val = 0xff;
758 rx_done -= 0xff;
759 }
760 if (rx_filled <= 0xff) {
761 val |= rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
762 rx_filled = 0;
763 } else {
764 val |= 0xff << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
765 rx_filled -= 0xff;
766 }
767 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
768 }
769}
770
771/* Get pointer to next RX descriptor to be processed by SW */
772static struct mvneta_rx_desc *
773mvneta_rxq_next_desc_get(struct mvneta_rx_queue *rxq)
774{
775 int rx_desc = rxq->next_desc_to_proc;
776
777 rxq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(rxq, rx_desc);
willy tarreau34e41792014-01-16 08:20:15 +0100778 prefetch(rxq->descs + rxq->next_desc_to_proc);
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300779 return rxq->descs + rx_desc;
780}
781
782/* Change maximum receive size of the port. */
783static void mvneta_max_rx_size_set(struct mvneta_port *pp, int max_rx_size)
784{
785 u32 val;
786
787 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
788 val &= ~MVNETA_GMAC_MAX_RX_SIZE_MASK;
789 val |= ((max_rx_size - MVNETA_MH_SIZE) / 2) <<
790 MVNETA_GMAC_MAX_RX_SIZE_SHIFT;
791 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
792}
793
794
795/* Set rx queue offset */
796static void mvneta_rxq_offset_set(struct mvneta_port *pp,
797 struct mvneta_rx_queue *rxq,
798 int offset)
799{
800 u32 val;
801
802 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
803 val &= ~MVNETA_RXQ_PKT_OFFSET_ALL_MASK;
804
805 /* Offset is in */
806 val |= MVNETA_RXQ_PKT_OFFSET_MASK(offset >> 3);
807 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
808}
809
810
811/* Tx descriptors helper methods */
812
813/* Update HW with number of TX descriptors to be sent */
814static void mvneta_txq_pend_desc_add(struct mvneta_port *pp,
815 struct mvneta_tx_queue *txq,
816 int pend_desc)
817{
818 u32 val;
819
820 /* Only 255 descriptors can be added at once ; Assume caller
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100821 * process TX desriptors in quanta less than 256
822 */
Simon Guinot2a90f7e2017-01-16 18:08:31 +0100823 val = pend_desc + txq->pending;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300824 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
Simon Guinot2a90f7e2017-01-16 18:08:31 +0100825 txq->pending = 0;
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300826}
827
828/* Get pointer to next TX descriptor to be processed (send) by HW */
829static struct mvneta_tx_desc *
830mvneta_txq_next_desc_get(struct mvneta_tx_queue *txq)
831{
832 int tx_desc = txq->next_desc_to_proc;
833
834 txq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(txq, tx_desc);
835 return txq->descs + tx_desc;
836}
837
838/* Release the last allocated TX descriptor. Useful to handle DMA
Thomas Petazzoni6a20c172012-11-19 11:41:25 +0100839 * mapping failures in the TX path.
840 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +0300841static void mvneta_txq_desc_put(struct mvneta_tx_queue *txq)
842{
843 if (txq->next_desc_to_proc == 0)
844 txq->next_desc_to_proc = txq->last_desc - 1;
845 else
846 txq->next_desc_to_proc--;
847}
848
849/* Set rxq buf size */
850static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
851 struct mvneta_rx_queue *rxq,
852 int buf_size)
853{
854 u32 val;
855
856 val = mvreg_read(pp, MVNETA_RXQ_SIZE_REG(rxq->id));
857
858 val &= ~MVNETA_RXQ_BUF_SIZE_MASK;
859 val |= ((buf_size >> 3) << MVNETA_RXQ_BUF_SIZE_SHIFT);
860
861 mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
862}
863
864/* Disable buffer management (BM) */
865static void mvneta_rxq_bm_disable(struct mvneta_port *pp,
866 struct mvneta_rx_queue *rxq)
867{
868 u32 val;
869
870 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
871 val &= ~MVNETA_RXQ_HW_BUF_ALLOC;
872 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
873}
874
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100875/* Enable buffer management (BM) */
876static void mvneta_rxq_bm_enable(struct mvneta_port *pp,
877 struct mvneta_rx_queue *rxq)
878{
879 u32 val;
880
881 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
882 val |= MVNETA_RXQ_HW_BUF_ALLOC;
883 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
884}
885
886/* Notify HW about port's assignment of pool for bigger packets */
887static void mvneta_rxq_long_pool_set(struct mvneta_port *pp,
888 struct mvneta_rx_queue *rxq)
889{
890 u32 val;
891
892 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
893 val &= ~MVNETA_RXQ_LONG_POOL_ID_MASK;
894 val |= (pp->pool_long->id << MVNETA_RXQ_LONG_POOL_ID_SHIFT);
895
896 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
897}
898
899/* Notify HW about port's assignment of pool for smaller packets */
900static void mvneta_rxq_short_pool_set(struct mvneta_port *pp,
901 struct mvneta_rx_queue *rxq)
902{
903 u32 val;
904
905 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
906 val &= ~MVNETA_RXQ_SHORT_POOL_ID_MASK;
907 val |= (pp->pool_short->id << MVNETA_RXQ_SHORT_POOL_ID_SHIFT);
908
909 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
910}
911
912/* Set port's receive buffer size for assigned BM pool */
913static inline void mvneta_bm_pool_bufsize_set(struct mvneta_port *pp,
914 int buf_size,
915 u8 pool_id)
916{
917 u32 val;
918
919 if (!IS_ALIGNED(buf_size, 8)) {
920 dev_warn(pp->dev->dev.parent,
921 "illegal buf_size value %d, round to %d\n",
922 buf_size, ALIGN(buf_size, 8));
923 buf_size = ALIGN(buf_size, 8);
924 }
925
926 val = mvreg_read(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id));
927 val |= buf_size & MVNETA_PORT_POOL_BUFFER_SZ_MASK;
928 mvreg_write(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id), val);
929}
930
931/* Configure MBUS window in order to enable access BM internal SRAM */
932static int mvneta_mbus_io_win_set(struct mvneta_port *pp, u32 base, u32 wsize,
933 u8 target, u8 attr)
934{
935 u32 win_enable, win_protect;
936 int i;
937
938 win_enable = mvreg_read(pp, MVNETA_BASE_ADDR_ENABLE);
939
940 if (pp->bm_win_id < 0) {
941 /* Find first not occupied window */
942 for (i = 0; i < MVNETA_MAX_DECODE_WIN; i++) {
943 if (win_enable & (1 << i)) {
944 pp->bm_win_id = i;
945 break;
946 }
947 }
948 if (i == MVNETA_MAX_DECODE_WIN)
949 return -ENOMEM;
950 } else {
951 i = pp->bm_win_id;
952 }
953
954 mvreg_write(pp, MVNETA_WIN_BASE(i), 0);
955 mvreg_write(pp, MVNETA_WIN_SIZE(i), 0);
956
957 if (i < 4)
958 mvreg_write(pp, MVNETA_WIN_REMAP(i), 0);
959
960 mvreg_write(pp, MVNETA_WIN_BASE(i), (base & 0xffff0000) |
961 (attr << 8) | target);
962
963 mvreg_write(pp, MVNETA_WIN_SIZE(i), (wsize - 1) & 0xffff0000);
964
965 win_protect = mvreg_read(pp, MVNETA_ACCESS_PROTECT_ENABLE);
966 win_protect |= 3 << (2 * i);
967 mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect);
968
969 win_enable &= ~(1 << i);
970 mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable);
971
972 return 0;
973}
974
Marcin Wojtas2636ac32016-12-01 18:03:09 +0100975static int mvneta_bm_port_mbus_init(struct mvneta_port *pp)
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100976{
Marcin Wojtas2636ac32016-12-01 18:03:09 +0100977 u32 wsize;
Marcin Wojtasdc35a102016-03-14 09:39:03 +0100978 u8 target, attr;
979 int err;
980
981 /* Get BM window information */
982 err = mvebu_mbus_get_io_win_info(pp->bm_priv->bppi_phys_addr, &wsize,
983 &target, &attr);
984 if (err < 0)
985 return err;
986
987 pp->bm_win_id = -1;
988
989 /* Open NETA -> BM window */
990 err = mvneta_mbus_io_win_set(pp, pp->bm_priv->bppi_phys_addr, wsize,
991 target, attr);
992 if (err < 0) {
993 netdev_info(pp->dev, "fail to configure mbus window to BM\n");
994 return err;
995 }
Marcin Wojtas2636ac32016-12-01 18:03:09 +0100996 return 0;
997}
998
999/* Assign and initialize pools for port. In case of fail
1000 * buffer manager will remain disabled for current port.
1001 */
1002static int mvneta_bm_port_init(struct platform_device *pdev,
1003 struct mvneta_port *pp)
1004{
1005 struct device_node *dn = pdev->dev.of_node;
1006 u32 long_pool_id, short_pool_id;
1007
1008 if (!pp->neta_armada3700) {
1009 int ret;
1010
1011 ret = mvneta_bm_port_mbus_init(pp);
1012 if (ret)
1013 return ret;
1014 }
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001015
1016 if (of_property_read_u32(dn, "bm,pool-long", &long_pool_id)) {
1017 netdev_info(pp->dev, "missing long pool id\n");
1018 return -EINVAL;
1019 }
1020
1021 /* Create port's long pool depending on mtu */
1022 pp->pool_long = mvneta_bm_pool_use(pp->bm_priv, long_pool_id,
1023 MVNETA_BM_LONG, pp->id,
1024 MVNETA_RX_PKT_SIZE(pp->dev->mtu));
1025 if (!pp->pool_long) {
1026 netdev_info(pp->dev, "fail to obtain long pool for port\n");
1027 return -ENOMEM;
1028 }
1029
1030 pp->pool_long->port_map |= 1 << pp->id;
1031
1032 mvneta_bm_pool_bufsize_set(pp, pp->pool_long->buf_size,
1033 pp->pool_long->id);
1034
1035 /* If short pool id is not defined, assume using single pool */
1036 if (of_property_read_u32(dn, "bm,pool-short", &short_pool_id))
1037 short_pool_id = long_pool_id;
1038
1039 /* Create port's short pool */
1040 pp->pool_short = mvneta_bm_pool_use(pp->bm_priv, short_pool_id,
1041 MVNETA_BM_SHORT, pp->id,
1042 MVNETA_BM_SHORT_PKT_SIZE);
1043 if (!pp->pool_short) {
1044 netdev_info(pp->dev, "fail to obtain short pool for port\n");
1045 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
1046 return -ENOMEM;
1047 }
1048
1049 if (short_pool_id != long_pool_id) {
1050 pp->pool_short->port_map |= 1 << pp->id;
1051 mvneta_bm_pool_bufsize_set(pp, pp->pool_short->buf_size,
1052 pp->pool_short->id);
1053 }
1054
1055 return 0;
1056}
1057
1058/* Update settings of a pool for bigger packets */
1059static void mvneta_bm_update_mtu(struct mvneta_port *pp, int mtu)
1060{
1061 struct mvneta_bm_pool *bm_pool = pp->pool_long;
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01001062 struct hwbm_pool *hwbm_pool = &bm_pool->hwbm_pool;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001063 int num;
1064
1065 /* Release all buffers from long pool */
1066 mvneta_bm_bufs_free(pp->bm_priv, bm_pool, 1 << pp->id);
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01001067 if (hwbm_pool->buf_num) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001068 WARN(1, "cannot free all buffers in pool %d\n",
1069 bm_pool->id);
1070 goto bm_mtu_err;
1071 }
1072
1073 bm_pool->pkt_size = MVNETA_RX_PKT_SIZE(mtu);
1074 bm_pool->buf_size = MVNETA_RX_BUF_SIZE(bm_pool->pkt_size);
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01001075 hwbm_pool->frag_size = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
1076 SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(bm_pool->pkt_size));
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001077
1078 /* Fill entire long pool */
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01001079 num = hwbm_pool_add(hwbm_pool, hwbm_pool->size, GFP_ATOMIC);
1080 if (num != hwbm_pool->size) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001081 WARN(1, "pool %d: %d of %d allocated\n",
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01001082 bm_pool->id, num, hwbm_pool->size);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001083 goto bm_mtu_err;
1084 }
1085 mvneta_bm_pool_bufsize_set(pp, bm_pool->buf_size, bm_pool->id);
1086
1087 return;
1088
1089bm_mtu_err:
1090 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
1091 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, 1 << pp->id);
1092
1093 pp->bm_priv = NULL;
1094 mvreg_write(pp, MVNETA_ACC_MODE, MVNETA_ACC_MODE_EXT1);
1095 netdev_info(pp->dev, "fail to update MTU, fall back to software BM\n");
1096}
1097
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001098/* Start the Ethernet port RX and TX activity */
1099static void mvneta_port_up(struct mvneta_port *pp)
1100{
1101 int queue;
1102 u32 q_map;
1103
1104 /* Enable all initialized TXs. */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001105 q_map = 0;
1106 for (queue = 0; queue < txq_number; queue++) {
1107 struct mvneta_tx_queue *txq = &pp->txqs[queue];
1108 if (txq->descs != NULL)
1109 q_map |= (1 << queue);
1110 }
1111 mvreg_write(pp, MVNETA_TXQ_CMD, q_map);
1112
1113 /* Enable all initialized RXQs. */
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001114 for (queue = 0; queue < rxq_number; queue++) {
1115 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
1116
1117 if (rxq->descs != NULL)
1118 q_map |= (1 << queue);
1119 }
1120 mvreg_write(pp, MVNETA_RXQ_CMD, q_map);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001121}
1122
1123/* Stop the Ethernet port activity */
1124static void mvneta_port_down(struct mvneta_port *pp)
1125{
1126 u32 val;
1127 int count;
1128
1129 /* Stop Rx port activity. Check port Rx activity. */
1130 val = mvreg_read(pp, MVNETA_RXQ_CMD) & MVNETA_RXQ_ENABLE_MASK;
1131
1132 /* Issue stop command for active channels only */
1133 if (val != 0)
1134 mvreg_write(pp, MVNETA_RXQ_CMD,
1135 val << MVNETA_RXQ_DISABLE_SHIFT);
1136
1137 /* Wait for all Rx activity to terminate. */
1138 count = 0;
1139 do {
1140 if (count++ >= MVNETA_RX_DISABLE_TIMEOUT_MSEC) {
1141 netdev_warn(pp->dev,
Dmitri Epshtein0838abb32016-03-12 18:44:19 +01001142 "TIMEOUT for RX stopped ! rx_queue_cmd: 0x%08x\n",
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001143 val);
1144 break;
1145 }
1146 mdelay(1);
1147
1148 val = mvreg_read(pp, MVNETA_RXQ_CMD);
Dmitri Epshteina3703fb2016-03-12 18:44:20 +01001149 } while (val & MVNETA_RXQ_ENABLE_MASK);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001150
1151 /* Stop Tx port activity. Check port Tx activity. Issue stop
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001152 * command for active channels only
1153 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001154 val = (mvreg_read(pp, MVNETA_TXQ_CMD)) & MVNETA_TXQ_ENABLE_MASK;
1155
1156 if (val != 0)
1157 mvreg_write(pp, MVNETA_TXQ_CMD,
1158 (val << MVNETA_TXQ_DISABLE_SHIFT));
1159
1160 /* Wait for all Tx activity to terminate. */
1161 count = 0;
1162 do {
1163 if (count++ >= MVNETA_TX_DISABLE_TIMEOUT_MSEC) {
1164 netdev_warn(pp->dev,
1165 "TIMEOUT for TX stopped status=0x%08x\n",
1166 val);
1167 break;
1168 }
1169 mdelay(1);
1170
1171 /* Check TX Command reg that all Txqs are stopped */
1172 val = mvreg_read(pp, MVNETA_TXQ_CMD);
1173
Dmitri Epshteina3703fb2016-03-12 18:44:20 +01001174 } while (val & MVNETA_TXQ_ENABLE_MASK);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001175
1176 /* Double check to verify that TX FIFO is empty */
1177 count = 0;
1178 do {
1179 if (count++ >= MVNETA_TX_FIFO_EMPTY_TIMEOUT) {
1180 netdev_warn(pp->dev,
Dmitri Epshtein0838abb32016-03-12 18:44:19 +01001181 "TX FIFO empty timeout status=0x%08x\n",
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001182 val);
1183 break;
1184 }
1185 mdelay(1);
1186
1187 val = mvreg_read(pp, MVNETA_PORT_STATUS);
1188 } while (!(val & MVNETA_TX_FIFO_EMPTY) &&
1189 (val & MVNETA_TX_IN_PRGRS));
1190
1191 udelay(200);
1192}
1193
1194/* Enable the port by setting the port enable bit of the MAC control register */
1195static void mvneta_port_enable(struct mvneta_port *pp)
1196{
1197 u32 val;
1198
1199 /* Enable port */
1200 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
1201 val |= MVNETA_GMAC0_PORT_ENABLE;
1202 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
1203}
1204
1205/* Disable the port and wait for about 200 usec before retuning */
1206static void mvneta_port_disable(struct mvneta_port *pp)
1207{
1208 u32 val;
1209
1210 /* Reset the Enable bit in the Serial Control Register */
1211 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
1212 val &= ~MVNETA_GMAC0_PORT_ENABLE;
1213 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
1214
1215 udelay(200);
1216}
1217
1218/* Multicast tables methods */
1219
1220/* Set all entries in Unicast MAC Table; queue==-1 means reject all */
1221static void mvneta_set_ucast_table(struct mvneta_port *pp, int queue)
1222{
1223 int offset;
1224 u32 val;
1225
1226 if (queue == -1) {
1227 val = 0;
1228 } else {
1229 val = 0x1 | (queue << 1);
1230 val |= (val << 24) | (val << 16) | (val << 8);
1231 }
1232
1233 for (offset = 0; offset <= 0xc; offset += 4)
1234 mvreg_write(pp, MVNETA_DA_FILT_UCAST_BASE + offset, val);
1235}
1236
1237/* Set all entries in Special Multicast MAC Table; queue==-1 means reject all */
1238static void mvneta_set_special_mcast_table(struct mvneta_port *pp, int queue)
1239{
1240 int offset;
1241 u32 val;
1242
1243 if (queue == -1) {
1244 val = 0;
1245 } else {
1246 val = 0x1 | (queue << 1);
1247 val |= (val << 24) | (val << 16) | (val << 8);
1248 }
1249
1250 for (offset = 0; offset <= 0xfc; offset += 4)
1251 mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + offset, val);
1252
1253}
1254
1255/* Set all entries in Other Multicast MAC Table. queue==-1 means reject all */
1256static void mvneta_set_other_mcast_table(struct mvneta_port *pp, int queue)
1257{
1258 int offset;
1259 u32 val;
1260
1261 if (queue == -1) {
1262 memset(pp->mcast_count, 0, sizeof(pp->mcast_count));
1263 val = 0;
1264 } else {
1265 memset(pp->mcast_count, 1, sizeof(pp->mcast_count));
1266 val = 0x1 | (queue << 1);
1267 val |= (val << 24) | (val << 16) | (val << 8);
1268 }
1269
1270 for (offset = 0; offset <= 0xfc; offset += 4)
1271 mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + offset, val);
1272}
1273
Stas Sergeev0c0744f2015-12-02 20:35:11 +03001274static void mvneta_set_autoneg(struct mvneta_port *pp, int enable)
1275{
1276 u32 val;
1277
1278 if (enable) {
1279 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
1280 val &= ~(MVNETA_GMAC_FORCE_LINK_PASS |
1281 MVNETA_GMAC_FORCE_LINK_DOWN |
1282 MVNETA_GMAC_AN_FLOW_CTRL_EN);
1283 val |= MVNETA_GMAC_INBAND_AN_ENABLE |
1284 MVNETA_GMAC_AN_SPEED_EN |
1285 MVNETA_GMAC_AN_DUPLEX_EN;
1286 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
1287
1288 val = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER);
1289 val |= MVNETA_GMAC_1MS_CLOCK_ENABLE;
1290 mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, val);
1291
1292 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
1293 val |= MVNETA_GMAC2_INBAND_AN_ENABLE;
1294 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
1295 } else {
1296 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
1297 val &= ~(MVNETA_GMAC_INBAND_AN_ENABLE |
1298 MVNETA_GMAC_AN_SPEED_EN |
1299 MVNETA_GMAC_AN_DUPLEX_EN);
1300 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
1301
1302 val = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER);
1303 val &= ~MVNETA_GMAC_1MS_CLOCK_ENABLE;
1304 mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, val);
1305
1306 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
1307 val &= ~MVNETA_GMAC2_INBAND_AN_ENABLE;
1308 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
1309 }
1310}
1311
Gregory CLEMENTdb488c12016-02-04 22:09:27 +01001312static void mvneta_percpu_unmask_interrupt(void *arg)
1313{
1314 struct mvneta_port *pp = arg;
1315
1316 /* All the queue are unmasked, but actually only the ones
1317 * mapped to this CPU will be unmasked
1318 */
1319 mvreg_write(pp, MVNETA_INTR_NEW_MASK,
1320 MVNETA_RX_INTR_MASK_ALL |
1321 MVNETA_TX_INTR_MASK_ALL |
1322 MVNETA_MISCINTR_INTR_MASK);
1323}
1324
1325static void mvneta_percpu_mask_interrupt(void *arg)
1326{
1327 struct mvneta_port *pp = arg;
1328
1329 /* All the queue are masked, but actually only the ones
1330 * mapped to this CPU will be masked
1331 */
1332 mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
1333 mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0);
1334 mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0);
1335}
1336
1337static void mvneta_percpu_clear_intr_cause(void *arg)
1338{
1339 struct mvneta_port *pp = arg;
1340
1341 /* All the queue are cleared, but actually only the ones
1342 * mapped to this CPU will be cleared
1343 */
1344 mvreg_write(pp, MVNETA_INTR_NEW_CAUSE, 0);
1345 mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
1346 mvreg_write(pp, MVNETA_INTR_OLD_CAUSE, 0);
1347}
1348
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001349/* This method sets defaults to the NETA port:
1350 * Clears interrupt Cause and Mask registers.
1351 * Clears all MAC tables.
1352 * Sets defaults to all registers.
1353 * Resets RX and TX descriptor rings.
1354 * Resets PHY.
1355 * This method can be called after mvneta_port_down() to return the port
1356 * settings to defaults.
1357 */
1358static void mvneta_defaults_set(struct mvneta_port *pp)
1359{
1360 int cpu;
1361 int queue;
1362 u32 val;
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001363 int max_cpu = num_present_cpus();
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001364
1365 /* Clear all Cause registers */
Gregory CLEMENTdb488c12016-02-04 22:09:27 +01001366 on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001367
1368 /* Mask all interrupts */
Gregory CLEMENTdb488c12016-02-04 22:09:27 +01001369 on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001370 mvreg_write(pp, MVNETA_INTR_ENABLE, 0);
1371
1372 /* Enable MBUS Retry bit16 */
1373 mvreg_write(pp, MVNETA_MBUS_RETRY, 0x20);
1374
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01001375 /* Set CPU queue access map. CPUs are assigned to the RX and
1376 * TX queues modulo their number. If there is only one TX
1377 * queue then it is assigned to the CPU associated to the
1378 * default RX queue.
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001379 */
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001380 for_each_present_cpu(cpu) {
1381 int rxq_map = 0, txq_map = 0;
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01001382 int rxq, txq;
Marcin Wojtas2636ac32016-12-01 18:03:09 +01001383 if (!pp->neta_armada3700) {
1384 for (rxq = 0; rxq < rxq_number; rxq++)
1385 if ((rxq % max_cpu) == cpu)
1386 rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001387
Marcin Wojtas2636ac32016-12-01 18:03:09 +01001388 for (txq = 0; txq < txq_number; txq++)
1389 if ((txq % max_cpu) == cpu)
1390 txq_map |= MVNETA_CPU_TXQ_ACCESS(txq);
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001391
Marcin Wojtas2636ac32016-12-01 18:03:09 +01001392 /* With only one TX queue we configure a special case
1393 * which will allow to get all the irq on a single
1394 * CPU
1395 */
1396 if (txq_number == 1)
1397 txq_map = (cpu == pp->rxq_def) ?
1398 MVNETA_CPU_TXQ_ACCESS(1) : 0;
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01001399
Marcin Wojtas2636ac32016-12-01 18:03:09 +01001400 } else {
1401 txq_map = MVNETA_CPU_TXQ_ACCESS_ALL_MASK;
1402 rxq_map = MVNETA_CPU_RXQ_ACCESS_ALL_MASK;
1403 }
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01001404
1405 mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map);
1406 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001407
1408 /* Reset RX and TX DMAs */
1409 mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
1410 mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
1411
1412 /* Disable Legacy WRR, Disable EJP, Release from reset */
1413 mvreg_write(pp, MVNETA_TXQ_CMD_1, 0);
1414 for (queue = 0; queue < txq_number; queue++) {
1415 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(queue), 0);
1416 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(queue), 0);
1417 }
1418
1419 mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
1420 mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
1421
1422 /* Set Port Acceleration Mode */
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001423 if (pp->bm_priv)
1424 /* HW buffer management + legacy parser */
1425 val = MVNETA_ACC_MODE_EXT2;
1426 else
1427 /* SW buffer management + legacy parser */
1428 val = MVNETA_ACC_MODE_EXT1;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001429 mvreg_write(pp, MVNETA_ACC_MODE, val);
1430
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001431 if (pp->bm_priv)
1432 mvreg_write(pp, MVNETA_BM_ADDRESS, pp->bm_priv->bppi_phys_addr);
1433
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001434 /* Update val of portCfg register accordingly with all RxQueue types */
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01001435 val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001436 mvreg_write(pp, MVNETA_PORT_CONFIG, val);
1437
1438 val = 0;
1439 mvreg_write(pp, MVNETA_PORT_CONFIG_EXTEND, val);
1440 mvreg_write(pp, MVNETA_RX_MIN_FRAME_SIZE, 64);
1441
1442 /* Build PORT_SDMA_CONFIG_REG */
1443 val = 0;
1444
1445 /* Default burst size */
1446 val |= MVNETA_TX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
1447 val |= MVNETA_RX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
Thomas Petazzoni9ad8fef2013-07-29 15:21:28 +02001448 val |= MVNETA_RX_NO_DATA_SWAP | MVNETA_TX_NO_DATA_SWAP;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001449
Thomas Petazzoni9ad8fef2013-07-29 15:21:28 +02001450#if defined(__BIG_ENDIAN)
1451 val |= MVNETA_DESC_SWAP;
1452#endif
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001453
1454 /* Assign port SDMA configuration */
1455 mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
1456
Thomas Petazzoni71408602013-09-04 16:21:18 +02001457 /* Disable PHY polling in hardware, since we're using the
1458 * kernel phylib to do this.
1459 */
1460 val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
1461 val &= ~MVNETA_PHY_POLLING_ENABLE;
1462 mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
1463
Stas Sergeev0c0744f2015-12-02 20:35:11 +03001464 mvneta_set_autoneg(pp, pp->use_inband_status);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001465 mvneta_set_ucast_table(pp, -1);
1466 mvneta_set_special_mcast_table(pp, -1);
1467 mvneta_set_other_mcast_table(pp, -1);
1468
1469 /* Set port interrupt enable register - default enable all */
1470 mvreg_write(pp, MVNETA_INTR_ENABLE,
1471 (MVNETA_RXQ_INTR_ENABLE_ALL_MASK
1472 | MVNETA_TXQ_INTR_ENABLE_ALL_MASK));
Andrew Lunne4839112015-10-22 18:37:36 +01001473
1474 mvneta_mib_counters_clear(pp);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001475}
1476
1477/* Set max sizes for tx queues */
1478static void mvneta_txq_max_tx_size_set(struct mvneta_port *pp, int max_tx_size)
1479
1480{
1481 u32 val, size, mtu;
1482 int queue;
1483
1484 mtu = max_tx_size * 8;
1485 if (mtu > MVNETA_TX_MTU_MAX)
1486 mtu = MVNETA_TX_MTU_MAX;
1487
1488 /* Set MTU */
1489 val = mvreg_read(pp, MVNETA_TX_MTU);
1490 val &= ~MVNETA_TX_MTU_MAX;
1491 val |= mtu;
1492 mvreg_write(pp, MVNETA_TX_MTU, val);
1493
1494 /* TX token size and all TXQs token size must be larger that MTU */
1495 val = mvreg_read(pp, MVNETA_TX_TOKEN_SIZE);
1496
1497 size = val & MVNETA_TX_TOKEN_SIZE_MAX;
1498 if (size < mtu) {
1499 size = mtu;
1500 val &= ~MVNETA_TX_TOKEN_SIZE_MAX;
1501 val |= size;
1502 mvreg_write(pp, MVNETA_TX_TOKEN_SIZE, val);
1503 }
1504 for (queue = 0; queue < txq_number; queue++) {
1505 val = mvreg_read(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue));
1506
1507 size = val & MVNETA_TXQ_TOKEN_SIZE_MAX;
1508 if (size < mtu) {
1509 size = mtu;
1510 val &= ~MVNETA_TXQ_TOKEN_SIZE_MAX;
1511 val |= size;
1512 mvreg_write(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue), val);
1513 }
1514 }
1515}
1516
1517/* Set unicast address */
1518static void mvneta_set_ucast_addr(struct mvneta_port *pp, u8 last_nibble,
1519 int queue)
1520{
1521 unsigned int unicast_reg;
1522 unsigned int tbl_offset;
1523 unsigned int reg_offset;
1524
1525 /* Locate the Unicast table entry */
1526 last_nibble = (0xf & last_nibble);
1527
1528 /* offset from unicast tbl base */
1529 tbl_offset = (last_nibble / 4) * 4;
1530
1531 /* offset within the above reg */
1532 reg_offset = last_nibble % 4;
1533
1534 unicast_reg = mvreg_read(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset));
1535
1536 if (queue == -1) {
1537 /* Clear accepts frame bit at specified unicast DA tbl entry */
1538 unicast_reg &= ~(0xff << (8 * reg_offset));
1539 } else {
1540 unicast_reg &= ~(0xff << (8 * reg_offset));
1541 unicast_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
1542 }
1543
1544 mvreg_write(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset), unicast_reg);
1545}
1546
1547/* Set mac address */
1548static void mvneta_mac_addr_set(struct mvneta_port *pp, unsigned char *addr,
1549 int queue)
1550{
1551 unsigned int mac_h;
1552 unsigned int mac_l;
1553
1554 if (queue != -1) {
1555 mac_l = (addr[4] << 8) | (addr[5]);
1556 mac_h = (addr[0] << 24) | (addr[1] << 16) |
1557 (addr[2] << 8) | (addr[3] << 0);
1558
1559 mvreg_write(pp, MVNETA_MAC_ADDR_LOW, mac_l);
1560 mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, mac_h);
1561 }
1562
1563 /* Accept frames of this address */
1564 mvneta_set_ucast_addr(pp, addr[5], queue);
1565}
1566
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001567/* Set the number of packets that will be received before RX interrupt
1568 * will be generated by HW.
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001569 */
1570static void mvneta_rx_pkts_coal_set(struct mvneta_port *pp,
1571 struct mvneta_rx_queue *rxq, u32 value)
1572{
1573 mvreg_write(pp, MVNETA_RXQ_THRESHOLD_REG(rxq->id),
1574 value | MVNETA_RXQ_NON_OCCUPIED(0));
1575 rxq->pkts_coal = value;
1576}
1577
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001578/* Set the time delay in usec before RX interrupt will be generated by
1579 * HW.
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001580 */
1581static void mvneta_rx_time_coal_set(struct mvneta_port *pp,
1582 struct mvneta_rx_queue *rxq, u32 value)
1583{
Thomas Petazzoni189dd622012-11-19 14:15:25 +01001584 u32 val;
1585 unsigned long clk_rate;
1586
1587 clk_rate = clk_get_rate(pp->clk);
1588 val = (clk_rate / 1000000) * value;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001589
1590 mvreg_write(pp, MVNETA_RXQ_TIME_COAL_REG(rxq->id), val);
1591 rxq->time_coal = value;
1592}
1593
1594/* Set threshold for TX_DONE pkts coalescing */
1595static void mvneta_tx_done_pkts_coal_set(struct mvneta_port *pp,
1596 struct mvneta_tx_queue *txq, u32 value)
1597{
1598 u32 val;
1599
1600 val = mvreg_read(pp, MVNETA_TXQ_SIZE_REG(txq->id));
1601
1602 val &= ~MVNETA_TXQ_SENT_THRESH_ALL_MASK;
1603 val |= MVNETA_TXQ_SENT_THRESH_MASK(value);
1604
1605 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), val);
1606
1607 txq->done_pkts_coal = value;
1608}
1609
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001610/* Handle rx descriptor fill by setting buf_cookie and buf_phys_addr */
1611static void mvneta_rx_desc_fill(struct mvneta_rx_desc *rx_desc,
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001612 u32 phys_addr, void *virt_addr,
1613 struct mvneta_rx_queue *rxq)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001614{
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001615 int i;
1616
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001617 rx_desc->buf_phys_addr = phys_addr;
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001618 i = rx_desc - rxq->descs;
1619 rxq->buf_virt_addr[i] = virt_addr;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001620}
1621
1622/* Decrement sent descriptors counter */
1623static void mvneta_txq_sent_desc_dec(struct mvneta_port *pp,
1624 struct mvneta_tx_queue *txq,
1625 int sent_desc)
1626{
1627 u32 val;
1628
1629 /* Only 255 TX descriptors can be updated at once */
1630 while (sent_desc > 0xff) {
1631 val = 0xff << MVNETA_TXQ_DEC_SENT_SHIFT;
1632 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
1633 sent_desc = sent_desc - 0xff;
1634 }
1635
1636 val = sent_desc << MVNETA_TXQ_DEC_SENT_SHIFT;
1637 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
1638}
1639
1640/* Get number of TX descriptors already sent by HW */
1641static int mvneta_txq_sent_desc_num_get(struct mvneta_port *pp,
1642 struct mvneta_tx_queue *txq)
1643{
1644 u32 val;
1645 int sent_desc;
1646
1647 val = mvreg_read(pp, MVNETA_TXQ_STATUS_REG(txq->id));
1648 sent_desc = (val & MVNETA_TXQ_SENT_DESC_MASK) >>
1649 MVNETA_TXQ_SENT_DESC_SHIFT;
1650
1651 return sent_desc;
1652}
1653
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001654/* Get number of sent descriptors and decrement counter.
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001655 * The number of sent descriptors is returned.
1656 */
1657static int mvneta_txq_sent_desc_proc(struct mvneta_port *pp,
1658 struct mvneta_tx_queue *txq)
1659{
1660 int sent_desc;
1661
1662 /* Get number of sent descriptors */
1663 sent_desc = mvneta_txq_sent_desc_num_get(pp, txq);
1664
1665 /* Decrement sent descriptors counter */
1666 if (sent_desc)
1667 mvneta_txq_sent_desc_dec(pp, txq, sent_desc);
1668
1669 return sent_desc;
1670}
1671
1672/* Set TXQ descriptors fields relevant for CSUM calculation */
1673static u32 mvneta_txq_desc_csum(int l3_offs, int l3_proto,
1674 int ip_hdr_len, int l4_proto)
1675{
1676 u32 command;
1677
1678 /* Fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01001679 * G_L4_chk, L4_type; required only for checksum
1680 * calculation
1681 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001682 command = l3_offs << MVNETA_TX_L3_OFF_SHIFT;
1683 command |= ip_hdr_len << MVNETA_TX_IP_HLEN_SHIFT;
1684
Thomas Fitzsimmons0a198582014-07-08 19:44:07 -04001685 if (l3_proto == htons(ETH_P_IP))
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001686 command |= MVNETA_TXD_IP_CSUM;
1687 else
1688 command |= MVNETA_TX_L3_IP6;
1689
1690 if (l4_proto == IPPROTO_TCP)
1691 command |= MVNETA_TX_L4_CSUM_FULL;
1692 else if (l4_proto == IPPROTO_UDP)
1693 command |= MVNETA_TX_L4_UDP | MVNETA_TX_L4_CSUM_FULL;
1694 else
1695 command |= MVNETA_TX_L4_CSUM_NOT;
1696
1697 return command;
1698}
1699
1700
1701/* Display more error info */
1702static void mvneta_rx_error(struct mvneta_port *pp,
1703 struct mvneta_rx_desc *rx_desc)
1704{
1705 u32 status = rx_desc->status;
1706
willy tarreau54282132014-01-16 08:20:14 +01001707 if (!mvneta_rxq_desc_is_first_last(status)) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001708 netdev_err(pp->dev,
1709 "bad rx status %08x (buffer oversize), size=%d\n",
willy tarreau54282132014-01-16 08:20:14 +01001710 status, rx_desc->data_size);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001711 return;
1712 }
1713
1714 switch (status & MVNETA_RXD_ERR_CODE_MASK) {
1715 case MVNETA_RXD_ERR_CRC:
1716 netdev_err(pp->dev, "bad rx status %08x (crc error), size=%d\n",
1717 status, rx_desc->data_size);
1718 break;
1719 case MVNETA_RXD_ERR_OVERRUN:
1720 netdev_err(pp->dev, "bad rx status %08x (overrun error), size=%d\n",
1721 status, rx_desc->data_size);
1722 break;
1723 case MVNETA_RXD_ERR_LEN:
1724 netdev_err(pp->dev, "bad rx status %08x (max frame length error), size=%d\n",
1725 status, rx_desc->data_size);
1726 break;
1727 case MVNETA_RXD_ERR_RESOURCE:
1728 netdev_err(pp->dev, "bad rx status %08x (resource error), size=%d\n",
1729 status, rx_desc->data_size);
1730 break;
1731 }
1732}
1733
willy tarreau54282132014-01-16 08:20:14 +01001734/* Handle RX checksum offload based on the descriptor's status */
1735static void mvneta_rx_csum(struct mvneta_port *pp, u32 status,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001736 struct sk_buff *skb)
1737{
willy tarreau54282132014-01-16 08:20:14 +01001738 if ((status & MVNETA_RXD_L3_IP4) &&
1739 (status & MVNETA_RXD_L4_CSUM_OK)) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001740 skb->csum = 0;
1741 skb->ip_summed = CHECKSUM_UNNECESSARY;
1742 return;
1743 }
1744
1745 skb->ip_summed = CHECKSUM_NONE;
1746}
1747
willy tarreau6c498972014-01-16 08:20:12 +01001748/* Return tx queue pointer (find last set bit) according to <cause> returned
1749 * form tx_done reg. <cause> must not be null. The return value is always a
1750 * valid queue for matching the first one found in <cause>.
1751 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001752static struct mvneta_tx_queue *mvneta_tx_done_policy(struct mvneta_port *pp,
1753 u32 cause)
1754{
1755 int queue = fls(cause) - 1;
1756
willy tarreau6c498972014-01-16 08:20:12 +01001757 return &pp->txqs[queue];
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001758}
1759
1760/* Free tx queue skbuffs */
1761static void mvneta_txq_bufs_free(struct mvneta_port *pp,
1762 struct mvneta_tx_queue *txq, int num)
1763{
1764 int i;
1765
1766 for (i = 0; i < num; i++) {
1767 struct mvneta_tx_desc *tx_desc = txq->descs +
1768 txq->txq_get_index;
1769 struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
1770
1771 mvneta_txq_inc_get(txq);
1772
Ezequiel Garcia2e3173a2014-05-30 13:40:07 -03001773 if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
1774 dma_unmap_single(pp->dev->dev.parent,
1775 tx_desc->buf_phys_addr,
1776 tx_desc->data_size, DMA_TO_DEVICE);
Ezequiel Garciaba7e46e2014-05-30 13:40:06 -03001777 if (!skb)
1778 continue;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001779 dev_kfree_skb_any(skb);
1780 }
1781}
1782
1783/* Handle end of transmission */
Arnaud Ebalardcd713192014-01-16 08:20:19 +01001784static void mvneta_txq_done(struct mvneta_port *pp,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001785 struct mvneta_tx_queue *txq)
1786{
1787 struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
1788 int tx_done;
1789
1790 tx_done = mvneta_txq_sent_desc_proc(pp, txq);
Arnaud Ebalardcd713192014-01-16 08:20:19 +01001791 if (!tx_done)
1792 return;
1793
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001794 mvneta_txq_bufs_free(pp, txq, tx_done);
1795
1796 txq->count -= tx_done;
1797
1798 if (netif_tx_queue_stopped(nq)) {
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -03001799 if (txq->count <= txq->tx_wake_threshold)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001800 netif_tx_wake_queue(nq);
1801 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001802}
1803
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001804void *mvneta_frag_alloc(unsigned int frag_size)
willy tarreau8ec2cd42014-01-16 08:20:16 +01001805{
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001806 if (likely(frag_size <= PAGE_SIZE))
1807 return netdev_alloc_frag(frag_size);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001808 else
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001809 return kmalloc(frag_size, GFP_ATOMIC);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001810}
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001811EXPORT_SYMBOL_GPL(mvneta_frag_alloc);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001812
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001813void mvneta_frag_free(unsigned int frag_size, void *data)
willy tarreau8ec2cd42014-01-16 08:20:16 +01001814{
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001815 if (likely(frag_size <= PAGE_SIZE))
Alexander Duyck13dc0d22015-05-06 21:12:14 -07001816 skb_free_frag(data);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001817 else
1818 kfree(data);
1819}
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001820EXPORT_SYMBOL_GPL(mvneta_frag_free);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001821
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001822/* Refill processing for SW buffer management */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001823static int mvneta_rx_refill(struct mvneta_port *pp,
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001824 struct mvneta_rx_desc *rx_desc,
1825 struct mvneta_rx_queue *rxq)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001826
1827{
1828 dma_addr_t phys_addr;
willy tarreau8ec2cd42014-01-16 08:20:16 +01001829 void *data;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001830
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001831 data = mvneta_frag_alloc(pp->frag_size);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001832 if (!data)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001833 return -ENOMEM;
1834
willy tarreau8ec2cd42014-01-16 08:20:16 +01001835 phys_addr = dma_map_single(pp->dev->dev.parent, data,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001836 MVNETA_RX_BUF_SIZE(pp->pkt_size),
1837 DMA_FROM_DEVICE);
1838 if (unlikely(dma_mapping_error(pp->dev->dev.parent, phys_addr))) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001839 mvneta_frag_free(pp->frag_size, data);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001840 return -ENOMEM;
1841 }
1842
Marcin Wojtas8d5047c2016-12-01 18:03:07 +01001843 phys_addr += pp->rx_offset_correction;
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001844 mvneta_rx_desc_fill(rx_desc, phys_addr, data, rxq);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001845 return 0;
1846}
1847
1848/* Handle tx checksum */
1849static u32 mvneta_skb_tx_csum(struct mvneta_port *pp, struct sk_buff *skb)
1850{
1851 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1852 int ip_hdr_len = 0;
Vlad Yasevich817dbfa2014-08-25 10:34:54 -04001853 __be16 l3_proto = vlan_get_protocol(skb);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001854 u8 l4_proto;
1855
Vlad Yasevich817dbfa2014-08-25 10:34:54 -04001856 if (l3_proto == htons(ETH_P_IP)) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001857 struct iphdr *ip4h = ip_hdr(skb);
1858
1859 /* Calculate IPv4 checksum and L4 checksum */
1860 ip_hdr_len = ip4h->ihl;
1861 l4_proto = ip4h->protocol;
Vlad Yasevich817dbfa2014-08-25 10:34:54 -04001862 } else if (l3_proto == htons(ETH_P_IPV6)) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001863 struct ipv6hdr *ip6h = ipv6_hdr(skb);
1864
1865 /* Read l4_protocol from one of IPv6 extra headers */
1866 if (skb_network_header_len(skb) > 0)
1867 ip_hdr_len = (skb_network_header_len(skb) >> 2);
1868 l4_proto = ip6h->nexthdr;
1869 } else
1870 return MVNETA_TX_L4_CSUM_NOT;
1871
1872 return mvneta_txq_desc_csum(skb_network_offset(skb),
Vlad Yasevich817dbfa2014-08-25 10:34:54 -04001873 l3_proto, ip_hdr_len, l4_proto);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001874 }
1875
1876 return MVNETA_TX_L4_CSUM_NOT;
1877}
1878
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001879/* Drop packets received by the RXQ and free buffers */
1880static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
1881 struct mvneta_rx_queue *rxq)
1882{
1883 int rx_done, i;
1884
1885 rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001886 if (rx_done)
1887 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
1888
1889 if (pp->bm_priv) {
1890 for (i = 0; i < rx_done; i++) {
1891 struct mvneta_rx_desc *rx_desc =
1892 mvneta_rxq_next_desc_get(rxq);
1893 u8 pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc);
1894 struct mvneta_bm_pool *bm_pool;
1895
1896 bm_pool = &pp->bm_priv->bm_pools[pool_id];
1897 /* Return dropped buffer to the pool */
1898 mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
1899 rx_desc->buf_phys_addr);
1900 }
1901 return;
1902 }
1903
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001904 for (i = 0; i < rxq->size; i++) {
1905 struct mvneta_rx_desc *rx_desc = rxq->descs + i;
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001906 void *data = rxq->buf_virt_addr[i];
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001907
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001908 dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
Ezequiel Garciaa328f3a2013-12-05 13:35:37 -03001909 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001910 mvneta_frag_free(pp->frag_size, data);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001911 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001912}
1913
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001914/* Main rx processing when using software buffer management */
1915static int mvneta_rx_swbm(struct mvneta_port *pp, int rx_todo,
1916 struct mvneta_rx_queue *rxq)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001917{
Maxime Ripard12bb03b2015-09-25 18:09:36 +02001918 struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001919 struct net_device *dev = pp->dev;
Simon Guinota84e3282015-07-19 13:00:53 +02001920 int rx_done;
willy tarreaudc4277d2014-01-16 08:20:07 +01001921 u32 rcvd_pkts = 0;
1922 u32 rcvd_bytes = 0;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001923
1924 /* Get number of received packets */
1925 rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
1926
1927 if (rx_todo > rx_done)
1928 rx_todo = rx_done;
1929
1930 rx_done = 0;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001931
1932 /* Fairness NAPI loop */
1933 while (rx_done < rx_todo) {
1934 struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq);
1935 struct sk_buff *skb;
willy tarreau8ec2cd42014-01-16 08:20:16 +01001936 unsigned char *data;
Simon Guinotdaf158d2015-09-15 22:41:21 +02001937 dma_addr_t phys_addr;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001938 u32 rx_status, frag_size;
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001939 int rx_bytes, err, index;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001940
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001941 rx_done++;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001942 rx_status = rx_desc->status;
willy tarreauf19fadf2014-01-16 08:20:17 +01001943 rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE);
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001944 index = rx_desc - rxq->descs;
1945 data = rxq->buf_virt_addr[index];
Simon Guinotdaf158d2015-09-15 22:41:21 +02001946 phys_addr = rx_desc->buf_phys_addr;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001947
willy tarreau54282132014-01-16 08:20:14 +01001948 if (!mvneta_rxq_desc_is_first_last(rx_status) ||
willy tarreauf19fadf2014-01-16 08:20:17 +01001949 (rx_status & MVNETA_RXD_ERR_SUMMARY)) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001950err_drop_frame:
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001951 dev->stats.rx_errors++;
1952 mvneta_rx_error(pp, rx_desc);
willy tarreau8ec2cd42014-01-16 08:20:16 +01001953 /* leave the descriptor untouched */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03001954 continue;
1955 }
1956
willy tarreauf19fadf2014-01-16 08:20:17 +01001957 if (rx_bytes <= rx_copybreak) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001958 /* better copy a small frame and not unmap the DMA region */
willy tarreauf19fadf2014-01-16 08:20:17 +01001959 skb = netdev_alloc_skb_ip_align(dev, rx_bytes);
1960 if (unlikely(!skb))
1961 goto err_drop_frame;
1962
1963 dma_sync_single_range_for_cpu(dev->dev.parent,
Gregory CLEMENTac83b7d2016-12-01 18:03:04 +01001964 phys_addr,
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001965 MVNETA_MH_SIZE + NET_SKB_PAD,
1966 rx_bytes,
1967 DMA_FROM_DEVICE);
willy tarreauf19fadf2014-01-16 08:20:17 +01001968 memcpy(skb_put(skb, rx_bytes),
1969 data + MVNETA_MH_SIZE + NET_SKB_PAD,
1970 rx_bytes);
1971
1972 skb->protocol = eth_type_trans(skb, dev);
1973 mvneta_rx_csum(pp, rx_status, skb);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02001974 napi_gro_receive(&port->napi, skb);
willy tarreauf19fadf2014-01-16 08:20:17 +01001975
1976 rcvd_pkts++;
1977 rcvd_bytes += rx_bytes;
1978
1979 /* leave the descriptor and buffer untouched */
1980 continue;
1981 }
1982
Simon Guinota84e3282015-07-19 13:00:53 +02001983 /* Refill processing */
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01001984 err = mvneta_rx_refill(pp, rx_desc, rxq);
Simon Guinota84e3282015-07-19 13:00:53 +02001985 if (err) {
1986 netdev_err(dev, "Linux processing - Can't refill\n");
1987 rxq->missed++;
1988 goto err_drop_frame;
1989 }
1990
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001991 frag_size = pp->frag_size;
1992
1993 skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size);
willy tarreauf19fadf2014-01-16 08:20:17 +01001994
Marcin Wojtas26c17a172015-11-30 13:27:44 +01001995 /* After refill old buffer has to be unmapped regardless
1996 * the skb is successfully built or not.
1997 */
Simon Guinotdaf158d2015-09-15 22:41:21 +02001998 dma_unmap_single(dev->dev.parent, phys_addr,
Marcin Wojtasdc35a102016-03-14 09:39:03 +01001999 MVNETA_RX_BUF_SIZE(pp->pkt_size),
2000 DMA_FROM_DEVICE);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002001
Marcin Wojtas26c17a172015-11-30 13:27:44 +01002002 if (!skb)
2003 goto err_drop_frame;
2004
willy tarreaudc4277d2014-01-16 08:20:07 +01002005 rcvd_pkts++;
2006 rcvd_bytes += rx_bytes;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002007
2008 /* Linux processing */
willy tarreau8ec2cd42014-01-16 08:20:16 +01002009 skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002010 skb_put(skb, rx_bytes);
2011
2012 skb->protocol = eth_type_trans(skb, dev);
2013
willy tarreau54282132014-01-16 08:20:14 +01002014 mvneta_rx_csum(pp, rx_status, skb);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002015
Maxime Ripard12bb03b2015-09-25 18:09:36 +02002016 napi_gro_receive(&port->napi, skb);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002017 }
2018
willy tarreaudc4277d2014-01-16 08:20:07 +01002019 if (rcvd_pkts) {
willy tarreau74c41b02014-01-16 08:20:08 +01002020 struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
2021
2022 u64_stats_update_begin(&stats->syncp);
2023 stats->rx_packets += rcvd_pkts;
2024 stats->rx_bytes += rcvd_bytes;
2025 u64_stats_update_end(&stats->syncp);
willy tarreaudc4277d2014-01-16 08:20:07 +01002026 }
2027
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002028 /* Update rxq management counters */
Simon Guinota84e3282015-07-19 13:00:53 +02002029 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002030
2031 return rx_done;
2032}
2033
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002034/* Main rx processing when using hardware buffer management */
2035static int mvneta_rx_hwbm(struct mvneta_port *pp, int rx_todo,
2036 struct mvneta_rx_queue *rxq)
2037{
2038 struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
2039 struct net_device *dev = pp->dev;
2040 int rx_done;
2041 u32 rcvd_pkts = 0;
2042 u32 rcvd_bytes = 0;
2043
2044 /* Get number of received packets */
2045 rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
2046
2047 if (rx_todo > rx_done)
2048 rx_todo = rx_done;
2049
2050 rx_done = 0;
2051
2052 /* Fairness NAPI loop */
2053 while (rx_done < rx_todo) {
2054 struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq);
2055 struct mvneta_bm_pool *bm_pool = NULL;
2056 struct sk_buff *skb;
2057 unsigned char *data;
2058 dma_addr_t phys_addr;
2059 u32 rx_status, frag_size;
2060 int rx_bytes, err;
2061 u8 pool_id;
2062
2063 rx_done++;
2064 rx_status = rx_desc->status;
2065 rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE);
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01002066 data = (u8 *)(uintptr_t)rx_desc->buf_cookie;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002067 phys_addr = rx_desc->buf_phys_addr;
2068 pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc);
2069 bm_pool = &pp->bm_priv->bm_pools[pool_id];
2070
2071 if (!mvneta_rxq_desc_is_first_last(rx_status) ||
2072 (rx_status & MVNETA_RXD_ERR_SUMMARY)) {
2073err_drop_frame_ret_pool:
2074 /* Return the buffer to the pool */
2075 mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
2076 rx_desc->buf_phys_addr);
2077err_drop_frame:
2078 dev->stats.rx_errors++;
2079 mvneta_rx_error(pp, rx_desc);
2080 /* leave the descriptor untouched */
2081 continue;
2082 }
2083
2084 if (rx_bytes <= rx_copybreak) {
2085 /* better copy a small frame and not unmap the DMA region */
2086 skb = netdev_alloc_skb_ip_align(dev, rx_bytes);
2087 if (unlikely(!skb))
2088 goto err_drop_frame_ret_pool;
2089
2090 dma_sync_single_range_for_cpu(dev->dev.parent,
2091 rx_desc->buf_phys_addr,
2092 MVNETA_MH_SIZE + NET_SKB_PAD,
2093 rx_bytes,
2094 DMA_FROM_DEVICE);
2095 memcpy(skb_put(skb, rx_bytes),
2096 data + MVNETA_MH_SIZE + NET_SKB_PAD,
2097 rx_bytes);
2098
2099 skb->protocol = eth_type_trans(skb, dev);
2100 mvneta_rx_csum(pp, rx_status, skb);
2101 napi_gro_receive(&port->napi, skb);
2102
2103 rcvd_pkts++;
2104 rcvd_bytes += rx_bytes;
2105
2106 /* Return the buffer to the pool */
2107 mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
2108 rx_desc->buf_phys_addr);
2109
2110 /* leave the descriptor and buffer untouched */
2111 continue;
2112 }
2113
2114 /* Refill processing */
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01002115 err = hwbm_pool_refill(&bm_pool->hwbm_pool, GFP_ATOMIC);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002116 if (err) {
2117 netdev_err(dev, "Linux processing - Can't refill\n");
2118 rxq->missed++;
2119 goto err_drop_frame_ret_pool;
2120 }
2121
Gregory CLEMENTbaa11eb2016-03-14 09:39:05 +01002122 frag_size = bm_pool->hwbm_pool.frag_size;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002123
2124 skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size);
2125
2126 /* After refill old buffer has to be unmapped regardless
2127 * the skb is successfully built or not.
2128 */
2129 dma_unmap_single(&pp->bm_priv->pdev->dev, phys_addr,
2130 bm_pool->buf_size, DMA_FROM_DEVICE);
2131 if (!skb)
2132 goto err_drop_frame;
2133
2134 rcvd_pkts++;
2135 rcvd_bytes += rx_bytes;
2136
2137 /* Linux processing */
2138 skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD);
2139 skb_put(skb, rx_bytes);
2140
2141 skb->protocol = eth_type_trans(skb, dev);
2142
2143 mvneta_rx_csum(pp, rx_status, skb);
2144
2145 napi_gro_receive(&port->napi, skb);
2146 }
2147
2148 if (rcvd_pkts) {
2149 struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
2150
2151 u64_stats_update_begin(&stats->syncp);
2152 stats->rx_packets += rcvd_pkts;
2153 stats->rx_bytes += rcvd_bytes;
2154 u64_stats_update_end(&stats->syncp);
2155 }
2156
2157 /* Update rxq management counters */
2158 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
2159
2160 return rx_done;
2161}
2162
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03002163static inline void
2164mvneta_tso_put_hdr(struct sk_buff *skb,
2165 struct mvneta_port *pp, struct mvneta_tx_queue *txq)
2166{
2167 struct mvneta_tx_desc *tx_desc;
2168 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2169
2170 txq->tx_skb[txq->txq_put_index] = NULL;
2171 tx_desc = mvneta_txq_next_desc_get(txq);
2172 tx_desc->data_size = hdr_len;
2173 tx_desc->command = mvneta_skb_tx_csum(pp, skb);
2174 tx_desc->command |= MVNETA_TXD_F_DESC;
2175 tx_desc->buf_phys_addr = txq->tso_hdrs_phys +
2176 txq->txq_put_index * TSO_HEADER_SIZE;
2177 mvneta_txq_inc_put(txq);
2178}
2179
2180static inline int
2181mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq,
2182 struct sk_buff *skb, char *data, int size,
2183 bool last_tcp, bool is_last)
2184{
2185 struct mvneta_tx_desc *tx_desc;
2186
2187 tx_desc = mvneta_txq_next_desc_get(txq);
2188 tx_desc->data_size = size;
2189 tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, data,
2190 size, DMA_TO_DEVICE);
2191 if (unlikely(dma_mapping_error(dev->dev.parent,
2192 tx_desc->buf_phys_addr))) {
2193 mvneta_txq_desc_put(txq);
2194 return -ENOMEM;
2195 }
2196
2197 tx_desc->command = 0;
2198 txq->tx_skb[txq->txq_put_index] = NULL;
2199
2200 if (last_tcp) {
2201 /* last descriptor in the TCP packet */
2202 tx_desc->command = MVNETA_TXD_L_DESC;
2203
2204 /* last descriptor in SKB */
2205 if (is_last)
2206 txq->tx_skb[txq->txq_put_index] = skb;
2207 }
2208 mvneta_txq_inc_put(txq);
2209 return 0;
2210}
2211
2212static int mvneta_tx_tso(struct sk_buff *skb, struct net_device *dev,
2213 struct mvneta_tx_queue *txq)
2214{
2215 int total_len, data_left;
2216 int desc_count = 0;
2217 struct mvneta_port *pp = netdev_priv(dev);
2218 struct tso_t tso;
2219 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2220 int i;
2221
2222 /* Count needed descriptors */
2223 if ((txq->count + tso_count_descs(skb)) >= txq->size)
2224 return 0;
2225
2226 if (skb_headlen(skb) < (skb_transport_offset(skb) + tcp_hdrlen(skb))) {
2227 pr_info("*** Is this even possible???!?!?\n");
2228 return 0;
2229 }
2230
2231 /* Initialize the TSO handler, and prepare the first payload */
2232 tso_start(skb, &tso);
2233
2234 total_len = skb->len - hdr_len;
2235 while (total_len > 0) {
2236 char *hdr;
2237
2238 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
2239 total_len -= data_left;
2240 desc_count++;
2241
2242 /* prepare packet headers: MAC + IP + TCP */
2243 hdr = txq->tso_hdrs + txq->txq_put_index * TSO_HEADER_SIZE;
2244 tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
2245
2246 mvneta_tso_put_hdr(skb, pp, txq);
2247
2248 while (data_left > 0) {
2249 int size;
2250 desc_count++;
2251
2252 size = min_t(int, tso.size, data_left);
2253
2254 if (mvneta_tso_put_data(dev, txq, skb,
2255 tso.data, size,
2256 size == data_left,
2257 total_len == 0))
2258 goto err_release;
2259 data_left -= size;
2260
2261 tso_build_data(skb, &tso, size);
2262 }
2263 }
2264
2265 return desc_count;
2266
2267err_release:
2268 /* Release all used data descriptors; header descriptors must not
2269 * be DMA-unmapped.
2270 */
2271 for (i = desc_count - 1; i >= 0; i--) {
2272 struct mvneta_tx_desc *tx_desc = txq->descs + i;
Ezequiel Garcia2e3173a2014-05-30 13:40:07 -03002273 if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03002274 dma_unmap_single(pp->dev->dev.parent,
2275 tx_desc->buf_phys_addr,
2276 tx_desc->data_size,
2277 DMA_TO_DEVICE);
2278 mvneta_txq_desc_put(txq);
2279 }
2280 return 0;
2281}
2282
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002283/* Handle tx fragmentation processing */
2284static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb,
2285 struct mvneta_tx_queue *txq)
2286{
2287 struct mvneta_tx_desc *tx_desc;
Ezequiel Garcia3d4ea022014-05-22 20:06:57 -03002288 int i, nr_frags = skb_shinfo(skb)->nr_frags;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002289
Ezequiel Garcia3d4ea022014-05-22 20:06:57 -03002290 for (i = 0; i < nr_frags; i++) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002291 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2292 void *addr = page_address(frag->page.p) + frag->page_offset;
2293
2294 tx_desc = mvneta_txq_next_desc_get(txq);
2295 tx_desc->data_size = frag->size;
2296
2297 tx_desc->buf_phys_addr =
2298 dma_map_single(pp->dev->dev.parent, addr,
2299 tx_desc->data_size, DMA_TO_DEVICE);
2300
2301 if (dma_mapping_error(pp->dev->dev.parent,
2302 tx_desc->buf_phys_addr)) {
2303 mvneta_txq_desc_put(txq);
2304 goto error;
2305 }
2306
Ezequiel Garcia3d4ea022014-05-22 20:06:57 -03002307 if (i == nr_frags - 1) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002308 /* Last descriptor */
2309 tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002310 txq->tx_skb[txq->txq_put_index] = skb;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002311 } else {
2312 /* Descriptor in the middle: Not First, Not Last */
2313 tx_desc->command = 0;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002314 txq->tx_skb[txq->txq_put_index] = NULL;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002315 }
Ezequiel Garcia3d4ea022014-05-22 20:06:57 -03002316 mvneta_txq_inc_put(txq);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002317 }
2318
2319 return 0;
2320
2321error:
2322 /* Release all descriptors that were used to map fragments of
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01002323 * this packet, as well as the corresponding DMA mappings
2324 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002325 for (i = i - 1; i >= 0; i--) {
2326 tx_desc = txq->descs + i;
2327 dma_unmap_single(pp->dev->dev.parent,
2328 tx_desc->buf_phys_addr,
2329 tx_desc->data_size,
2330 DMA_TO_DEVICE);
2331 mvneta_txq_desc_put(txq);
2332 }
2333
2334 return -ENOMEM;
2335}
2336
2337/* Main tx processing */
2338static int mvneta_tx(struct sk_buff *skb, struct net_device *dev)
2339{
2340 struct mvneta_port *pp = netdev_priv(dev);
Willy Tarreauee40a112013-04-11 23:00:37 +02002341 u16 txq_id = skb_get_queue_mapping(skb);
2342 struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002343 struct mvneta_tx_desc *tx_desc;
Eric Dumazet5f478b42014-12-02 04:30:59 -08002344 int len = skb->len;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002345 int frags = 0;
2346 u32 tx_cmd;
2347
2348 if (!netif_running(dev))
2349 goto out;
2350
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03002351 if (skb_is_gso(skb)) {
2352 frags = mvneta_tx_tso(skb, dev, txq);
2353 goto out;
2354 }
2355
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002356 frags = skb_shinfo(skb)->nr_frags + 1;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002357
2358 /* Get a descriptor for the first part of the packet */
2359 tx_desc = mvneta_txq_next_desc_get(txq);
2360
2361 tx_cmd = mvneta_skb_tx_csum(pp, skb);
2362
2363 tx_desc->data_size = skb_headlen(skb);
2364
2365 tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, skb->data,
2366 tx_desc->data_size,
2367 DMA_TO_DEVICE);
2368 if (unlikely(dma_mapping_error(dev->dev.parent,
2369 tx_desc->buf_phys_addr))) {
2370 mvneta_txq_desc_put(txq);
2371 frags = 0;
2372 goto out;
2373 }
2374
2375 if (frags == 1) {
2376 /* First and Last descriptor */
2377 tx_cmd |= MVNETA_TXD_FLZ_DESC;
2378 tx_desc->command = tx_cmd;
2379 txq->tx_skb[txq->txq_put_index] = skb;
2380 mvneta_txq_inc_put(txq);
2381 } else {
2382 /* First but not Last */
2383 tx_cmd |= MVNETA_TXD_F_DESC;
2384 txq->tx_skb[txq->txq_put_index] = NULL;
2385 mvneta_txq_inc_put(txq);
2386 tx_desc->command = tx_cmd;
2387 /* Continue with other skb fragments */
2388 if (mvneta_tx_frag_process(pp, skb, txq)) {
2389 dma_unmap_single(dev->dev.parent,
2390 tx_desc->buf_phys_addr,
2391 tx_desc->data_size,
2392 DMA_TO_DEVICE);
2393 mvneta_txq_desc_put(txq);
2394 frags = 0;
2395 goto out;
2396 }
2397 }
2398
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002399out:
2400 if (frags > 0) {
willy tarreau74c41b02014-01-16 08:20:08 +01002401 struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
Ezequiel Garciae19d2dd2014-05-19 13:59:54 -03002402 struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id);
2403
2404 txq->count += frags;
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -03002405 if (txq->count >= txq->tx_stop_threshold)
Ezequiel Garciae19d2dd2014-05-19 13:59:54 -03002406 netif_tx_stop_queue(nq);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002407
Simon Guinot2a90f7e2017-01-16 18:08:31 +01002408 if (!skb->xmit_more || netif_xmit_stopped(nq) ||
2409 txq->pending + frags > MVNETA_TXQ_DEC_SENT_MASK)
2410 mvneta_txq_pend_desc_add(pp, txq, frags);
2411 else
2412 txq->pending += frags;
2413
willy tarreau74c41b02014-01-16 08:20:08 +01002414 u64_stats_update_begin(&stats->syncp);
2415 stats->tx_packets++;
Eric Dumazet5f478b42014-12-02 04:30:59 -08002416 stats->tx_bytes += len;
willy tarreau74c41b02014-01-16 08:20:08 +01002417 u64_stats_update_end(&stats->syncp);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002418 } else {
2419 dev->stats.tx_dropped++;
2420 dev_kfree_skb_any(skb);
2421 }
2422
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002423 return NETDEV_TX_OK;
2424}
2425
2426
2427/* Free tx resources, when resetting a port */
2428static void mvneta_txq_done_force(struct mvneta_port *pp,
2429 struct mvneta_tx_queue *txq)
2430
2431{
2432 int tx_done = txq->count;
2433
2434 mvneta_txq_bufs_free(pp, txq, tx_done);
2435
2436 /* reset txq */
2437 txq->count = 0;
2438 txq->txq_put_index = 0;
2439 txq->txq_get_index = 0;
2440}
2441
willy tarreau6c498972014-01-16 08:20:12 +01002442/* Handle tx done - called in softirq context. The <cause_tx_done> argument
2443 * must be a valid cause according to MVNETA_TXQ_INTR_MASK_ALL.
2444 */
Arnaud Ebalard0713a862014-01-16 08:20:18 +01002445static void mvneta_tx_done_gbe(struct mvneta_port *pp, u32 cause_tx_done)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002446{
2447 struct mvneta_tx_queue *txq;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002448 struct netdev_queue *nq;
2449
willy tarreau6c498972014-01-16 08:20:12 +01002450 while (cause_tx_done) {
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002451 txq = mvneta_tx_done_policy(pp, cause_tx_done);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002452
2453 nq = netdev_get_tx_queue(pp->dev, txq->id);
2454 __netif_tx_lock(nq, smp_processor_id());
2455
Arnaud Ebalard0713a862014-01-16 08:20:18 +01002456 if (txq->count)
2457 mvneta_txq_done(pp, txq);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002458
2459 __netif_tx_unlock(nq);
2460 cause_tx_done &= ~((1 << txq->id));
2461 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002462}
2463
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01002464/* Compute crc8 of the specified address, using a unique algorithm ,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002465 * according to hw spec, different than generic crc8 algorithm
2466 */
2467static int mvneta_addr_crc(unsigned char *addr)
2468{
2469 int crc = 0;
2470 int i;
2471
2472 for (i = 0; i < ETH_ALEN; i++) {
2473 int j;
2474
2475 crc = (crc ^ addr[i]) << 8;
2476 for (j = 7; j >= 0; j--) {
2477 if (crc & (0x100 << j))
2478 crc ^= 0x107 << j;
2479 }
2480 }
2481
2482 return crc;
2483}
2484
2485/* This method controls the net device special MAC multicast support.
2486 * The Special Multicast Table for MAC addresses supports MAC of the form
2487 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
2488 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
2489 * Table entries in the DA-Filter table. This method set the Special
2490 * Multicast Table appropriate entry.
2491 */
2492static void mvneta_set_special_mcast_addr(struct mvneta_port *pp,
2493 unsigned char last_byte,
2494 int queue)
2495{
2496 unsigned int smc_table_reg;
2497 unsigned int tbl_offset;
2498 unsigned int reg_offset;
2499
2500 /* Register offset from SMC table base */
2501 tbl_offset = (last_byte / 4);
2502 /* Entry offset within the above reg */
2503 reg_offset = last_byte % 4;
2504
2505 smc_table_reg = mvreg_read(pp, (MVNETA_DA_FILT_SPEC_MCAST
2506 + tbl_offset * 4));
2507
2508 if (queue == -1)
2509 smc_table_reg &= ~(0xff << (8 * reg_offset));
2510 else {
2511 smc_table_reg &= ~(0xff << (8 * reg_offset));
2512 smc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
2513 }
2514
2515 mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + tbl_offset * 4,
2516 smc_table_reg);
2517}
2518
2519/* This method controls the network device Other MAC multicast support.
2520 * The Other Multicast Table is used for multicast of another type.
2521 * A CRC-8 is used as an index to the Other Multicast Table entries
2522 * in the DA-Filter table.
2523 * The method gets the CRC-8 value from the calling routine and
2524 * sets the Other Multicast Table appropriate entry according to the
2525 * specified CRC-8 .
2526 */
2527static void mvneta_set_other_mcast_addr(struct mvneta_port *pp,
2528 unsigned char crc8,
2529 int queue)
2530{
2531 unsigned int omc_table_reg;
2532 unsigned int tbl_offset;
2533 unsigned int reg_offset;
2534
2535 tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
2536 reg_offset = crc8 % 4; /* Entry offset within the above reg */
2537
2538 omc_table_reg = mvreg_read(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset);
2539
2540 if (queue == -1) {
2541 /* Clear accepts frame bit at specified Other DA table entry */
2542 omc_table_reg &= ~(0xff << (8 * reg_offset));
2543 } else {
2544 omc_table_reg &= ~(0xff << (8 * reg_offset));
2545 omc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
2546 }
2547
2548 mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset, omc_table_reg);
2549}
2550
2551/* The network device supports multicast using two tables:
2552 * 1) Special Multicast Table for MAC addresses of the form
2553 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
2554 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
2555 * Table entries in the DA-Filter table.
2556 * 2) Other Multicast Table for multicast of another type. A CRC-8 value
2557 * is used as an index to the Other Multicast Table entries in the
2558 * DA-Filter table.
2559 */
2560static int mvneta_mcast_addr_set(struct mvneta_port *pp, unsigned char *p_addr,
2561 int queue)
2562{
2563 unsigned char crc_result = 0;
2564
2565 if (memcmp(p_addr, "\x01\x00\x5e\x00\x00", 5) == 0) {
2566 mvneta_set_special_mcast_addr(pp, p_addr[5], queue);
2567 return 0;
2568 }
2569
2570 crc_result = mvneta_addr_crc(p_addr);
2571 if (queue == -1) {
2572 if (pp->mcast_count[crc_result] == 0) {
2573 netdev_info(pp->dev, "No valid Mcast for crc8=0x%02x\n",
2574 crc_result);
2575 return -EINVAL;
2576 }
2577
2578 pp->mcast_count[crc_result]--;
2579 if (pp->mcast_count[crc_result] != 0) {
2580 netdev_info(pp->dev,
2581 "After delete there are %d valid Mcast for crc8=0x%02x\n",
2582 pp->mcast_count[crc_result], crc_result);
2583 return -EINVAL;
2584 }
2585 } else
2586 pp->mcast_count[crc_result]++;
2587
2588 mvneta_set_other_mcast_addr(pp, crc_result, queue);
2589
2590 return 0;
2591}
2592
2593/* Configure Fitering mode of Ethernet port */
2594static void mvneta_rx_unicast_promisc_set(struct mvneta_port *pp,
2595 int is_promisc)
2596{
2597 u32 port_cfg_reg, val;
2598
2599 port_cfg_reg = mvreg_read(pp, MVNETA_PORT_CONFIG);
2600
2601 val = mvreg_read(pp, MVNETA_TYPE_PRIO);
2602
2603 /* Set / Clear UPM bit in port configuration register */
2604 if (is_promisc) {
2605 /* Accept all Unicast addresses */
2606 port_cfg_reg |= MVNETA_UNI_PROMISC_MODE;
2607 val |= MVNETA_FORCE_UNI;
2608 mvreg_write(pp, MVNETA_MAC_ADDR_LOW, 0xffff);
2609 mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, 0xffffffff);
2610 } else {
2611 /* Reject all Unicast addresses */
2612 port_cfg_reg &= ~MVNETA_UNI_PROMISC_MODE;
2613 val &= ~MVNETA_FORCE_UNI;
2614 }
2615
2616 mvreg_write(pp, MVNETA_PORT_CONFIG, port_cfg_reg);
2617 mvreg_write(pp, MVNETA_TYPE_PRIO, val);
2618}
2619
2620/* register unicast and multicast addresses */
2621static void mvneta_set_rx_mode(struct net_device *dev)
2622{
2623 struct mvneta_port *pp = netdev_priv(dev);
2624 struct netdev_hw_addr *ha;
2625
2626 if (dev->flags & IFF_PROMISC) {
2627 /* Accept all: Multicast + Unicast */
2628 mvneta_rx_unicast_promisc_set(pp, 1);
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01002629 mvneta_set_ucast_table(pp, pp->rxq_def);
2630 mvneta_set_special_mcast_table(pp, pp->rxq_def);
2631 mvneta_set_other_mcast_table(pp, pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002632 } else {
2633 /* Accept single Unicast */
2634 mvneta_rx_unicast_promisc_set(pp, 0);
2635 mvneta_set_ucast_table(pp, -1);
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01002636 mvneta_mac_addr_set(pp, dev->dev_addr, pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002637
2638 if (dev->flags & IFF_ALLMULTI) {
2639 /* Accept all multicast */
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01002640 mvneta_set_special_mcast_table(pp, pp->rxq_def);
2641 mvneta_set_other_mcast_table(pp, pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002642 } else {
2643 /* Accept only initialized multicast */
2644 mvneta_set_special_mcast_table(pp, -1);
2645 mvneta_set_other_mcast_table(pp, -1);
2646
2647 if (!netdev_mc_empty(dev)) {
2648 netdev_for_each_mc_addr(ha, dev) {
2649 mvneta_mcast_addr_set(pp, ha->addr,
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01002650 pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002651 }
2652 }
2653 }
2654 }
2655}
2656
2657/* Interrupt handling - the callback for request_irq() */
2658static irqreturn_t mvneta_isr(int irq, void *dev_id)
2659{
Marcin Wojtas2636ac32016-12-01 18:03:09 +01002660 struct mvneta_port *pp = (struct mvneta_port *)dev_id;
2661
2662 mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
2663 napi_schedule(&pp->napi);
2664
2665 return IRQ_HANDLED;
2666}
2667
2668/* Interrupt handling - the callback for request_percpu_irq() */
2669static irqreturn_t mvneta_percpu_isr(int irq, void *dev_id)
2670{
Maxime Ripard12bb03b2015-09-25 18:09:36 +02002671 struct mvneta_pcpu_port *port = (struct mvneta_pcpu_port *)dev_id;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002672
Maxime Ripard12bb03b2015-09-25 18:09:36 +02002673 disable_percpu_irq(port->pp->dev->irq);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02002674 napi_schedule(&port->napi);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002675
2676 return IRQ_HANDLED;
2677}
2678
Stas Sergeev898b29702015-04-01 20:32:49 +03002679static int mvneta_fixed_link_update(struct mvneta_port *pp,
2680 struct phy_device *phy)
2681{
2682 struct fixed_phy_status status;
2683 struct fixed_phy_status changed = {};
2684 u32 gmac_stat = mvreg_read(pp, MVNETA_GMAC_STATUS);
2685
2686 status.link = !!(gmac_stat & MVNETA_GMAC_LINK_UP);
2687 if (gmac_stat & MVNETA_GMAC_SPEED_1000)
2688 status.speed = SPEED_1000;
2689 else if (gmac_stat & MVNETA_GMAC_SPEED_100)
2690 status.speed = SPEED_100;
2691 else
2692 status.speed = SPEED_10;
2693 status.duplex = !!(gmac_stat & MVNETA_GMAC_FULL_DUPLEX);
2694 changed.link = 1;
2695 changed.speed = 1;
2696 changed.duplex = 1;
2697 fixed_phy_update_state(phy, &status, &changed);
2698 return 0;
2699}
2700
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002701/* NAPI handler
2702 * Bits 0 - 7 of the causeRxTx register indicate that are transmitted
2703 * packets on the corresponding TXQ (Bit 0 is for TX queue 1).
2704 * Bits 8 -15 of the cause Rx Tx register indicate that are received
2705 * packets on the corresponding RXQ (Bit 8 is for RX queue 0).
2706 * Each CPU has its own causeRxTx register
2707 */
2708static int mvneta_poll(struct napi_struct *napi, int budget)
2709{
2710 int rx_done = 0;
2711 u32 cause_rx_tx;
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01002712 int rx_queue;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002713 struct mvneta_port *pp = netdev_priv(napi->dev);
Philippe Reynesc6c022e2016-07-30 17:42:11 +02002714 struct net_device *ndev = pp->dev;
Maxime Ripard12bb03b2015-09-25 18:09:36 +02002715 struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002716
2717 if (!netif_running(pp->dev)) {
Marcin Wojtas2636ac32016-12-01 18:03:09 +01002718 napi_complete(napi);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002719 return rx_done;
2720 }
2721
2722 /* Read cause register */
Stas Sergeev898b29702015-04-01 20:32:49 +03002723 cause_rx_tx = mvreg_read(pp, MVNETA_INTR_NEW_CAUSE);
2724 if (cause_rx_tx & MVNETA_MISCINTR_INTR_MASK) {
2725 u32 cause_misc = mvreg_read(pp, MVNETA_INTR_MISC_CAUSE);
2726
2727 mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
2728 if (pp->use_inband_status && (cause_misc &
2729 (MVNETA_CAUSE_PHY_STATUS_CHANGE |
2730 MVNETA_CAUSE_LINK_CHANGE |
2731 MVNETA_CAUSE_PSC_SYNC_CHANGE))) {
Philippe Reynesc6c022e2016-07-30 17:42:11 +02002732 mvneta_fixed_link_update(pp, ndev->phydev);
Stas Sergeev898b29702015-04-01 20:32:49 +03002733 }
2734 }
willy tarreau71f6d1b2014-01-16 08:20:11 +01002735
2736 /* Release Tx descriptors */
2737 if (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL) {
Arnaud Ebalard0713a862014-01-16 08:20:18 +01002738 mvneta_tx_done_gbe(pp, (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL));
willy tarreau71f6d1b2014-01-16 08:20:11 +01002739 cause_rx_tx &= ~MVNETA_TX_INTR_MASK_ALL;
2740 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002741
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01002742 /* For the case where the last mvneta_poll did not process all
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002743 * RX packets
2744 */
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01002745 rx_queue = fls(((cause_rx_tx >> 8) & 0xff));
2746
Marcin Wojtas2636ac32016-12-01 18:03:09 +01002747 cause_rx_tx |= pp->neta_armada3700 ? pp->cause_rx_tx :
2748 port->cause_rx_tx;
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01002749
2750 if (rx_queue) {
2751 rx_queue = rx_queue - 1;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002752 if (pp->bm_priv)
2753 rx_done = mvneta_rx_hwbm(pp, budget, &pp->rxqs[rx_queue]);
2754 else
2755 rx_done = mvneta_rx_swbm(pp, budget, &pp->rxqs[rx_queue]);
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01002756 }
2757
Maxime Ripardd8936652015-09-25 18:09:37 +02002758 budget -= rx_done;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002759
2760 if (budget > 0) {
2761 cause_rx_tx = 0;
Marcin Wojtas2636ac32016-12-01 18:03:09 +01002762 napi_complete(napi);
2763
2764 if (pp->neta_armada3700) {
2765 unsigned long flags;
2766
2767 local_irq_save(flags);
2768 mvreg_write(pp, MVNETA_INTR_NEW_MASK,
2769 MVNETA_RX_INTR_MASK(rxq_number) |
2770 MVNETA_TX_INTR_MASK(txq_number) |
2771 MVNETA_MISCINTR_INTR_MASK);
2772 local_irq_restore(flags);
2773 } else {
2774 enable_percpu_irq(pp->dev->irq, 0);
2775 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002776 }
2777
Marcin Wojtas2636ac32016-12-01 18:03:09 +01002778 if (pp->neta_armada3700)
2779 pp->cause_rx_tx = cause_rx_tx;
2780 else
2781 port->cause_rx_tx = cause_rx_tx;
2782
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002783 return rx_done;
2784}
2785
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002786/* Handle rxq fill: allocates rxq skbs; called when initializing a port */
2787static int mvneta_rxq_fill(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
2788 int num)
2789{
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002790 int i;
2791
2792 for (i = 0; i < num; i++) {
willy tarreaua1a65ab2014-01-16 08:20:13 +01002793 memset(rxq->descs + i, 0, sizeof(struct mvneta_rx_desc));
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01002794 if (mvneta_rx_refill(pp, rxq->descs + i, rxq) != 0) {
willy tarreaua1a65ab2014-01-16 08:20:13 +01002795 netdev_err(pp->dev, "%s:rxq %d, %d of %d buffs filled\n",
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002796 __func__, rxq->id, i, num);
2797 break;
2798 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002799 }
2800
2801 /* Add this number of RX descriptors as non occupied (ready to
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01002802 * get packets)
2803 */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002804 mvneta_rxq_non_occup_desc_add(pp, rxq, i);
2805
2806 return i;
2807}
2808
2809/* Free all packets pending transmit from all TXQs and reset TX port */
2810static void mvneta_tx_reset(struct mvneta_port *pp)
2811{
2812 int queue;
2813
Ezequiel Garcia96728502014-05-22 20:06:59 -03002814 /* free the skb's in the tx ring */
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002815 for (queue = 0; queue < txq_number; queue++)
2816 mvneta_txq_done_force(pp, &pp->txqs[queue]);
2817
2818 mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
2819 mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
2820}
2821
2822static void mvneta_rx_reset(struct mvneta_port *pp)
2823{
2824 mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
2825 mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
2826}
2827
2828/* Rx/Tx queue initialization/cleanup methods */
2829
2830/* Create a specified RX queue */
2831static int mvneta_rxq_init(struct mvneta_port *pp,
2832 struct mvneta_rx_queue *rxq)
2833
2834{
2835 rxq->size = pp->rx_ring_size;
2836
2837 /* Allocate memory for RX descriptors */
2838 rxq->descs = dma_alloc_coherent(pp->dev->dev.parent,
2839 rxq->size * MVNETA_DESC_ALIGNED_SIZE,
2840 &rxq->descs_phys, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00002841 if (rxq->descs == NULL)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002842 return -ENOMEM;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002843
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002844 rxq->last_desc = rxq->size - 1;
2845
2846 /* Set Rx descriptors queue starting address */
2847 mvreg_write(pp, MVNETA_RXQ_BASE_ADDR_REG(rxq->id), rxq->descs_phys);
2848 mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), rxq->size);
2849
2850 /* Set Offset */
Marcin Wojtas8d5047c2016-12-01 18:03:07 +01002851 mvneta_rxq_offset_set(pp, rxq, NET_SKB_PAD - pp->rx_offset_correction);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002852
2853 /* Set coalescing pkts and time */
2854 mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
2855 mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
2856
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002857 if (!pp->bm_priv) {
2858 /* Fill RXQ with buffers from RX pool */
2859 mvneta_rxq_buf_size_set(pp, rxq,
2860 MVNETA_RX_BUF_SIZE(pp->pkt_size));
2861 mvneta_rxq_bm_disable(pp, rxq);
Gregory CLEMENTe9f64992016-12-01 18:03:05 +01002862 mvneta_rxq_fill(pp, rxq, rxq->size);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002863 } else {
2864 mvneta_rxq_bm_enable(pp, rxq);
2865 mvneta_rxq_long_pool_set(pp, rxq);
2866 mvneta_rxq_short_pool_set(pp, rxq);
Gregory CLEMENTe9f64992016-12-01 18:03:05 +01002867 mvneta_rxq_non_occup_desc_add(pp, rxq, rxq->size);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01002868 }
2869
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002870 return 0;
2871}
2872
2873/* Cleanup Rx queue */
2874static void mvneta_rxq_deinit(struct mvneta_port *pp,
2875 struct mvneta_rx_queue *rxq)
2876{
2877 mvneta_rxq_drop_pkts(pp, rxq);
2878
2879 if (rxq->descs)
2880 dma_free_coherent(pp->dev->dev.parent,
2881 rxq->size * MVNETA_DESC_ALIGNED_SIZE,
2882 rxq->descs,
2883 rxq->descs_phys);
2884
2885 rxq->descs = NULL;
2886 rxq->last_desc = 0;
2887 rxq->next_desc_to_proc = 0;
2888 rxq->descs_phys = 0;
2889}
2890
2891/* Create and initialize a tx queue */
2892static int mvneta_txq_init(struct mvneta_port *pp,
2893 struct mvneta_tx_queue *txq)
2894{
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01002895 int cpu;
2896
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002897 txq->size = pp->tx_ring_size;
2898
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -03002899 /* A queue must always have room for at least one skb.
2900 * Therefore, stop the queue when the free entries reaches
2901 * the maximum number of descriptors per skb.
2902 */
2903 txq->tx_stop_threshold = txq->size - MVNETA_MAX_SKB_DESCS;
2904 txq->tx_wake_threshold = txq->tx_stop_threshold / 2;
2905
2906
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002907 /* Allocate memory for TX descriptors */
2908 txq->descs = dma_alloc_coherent(pp->dev->dev.parent,
2909 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2910 &txq->descs_phys, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00002911 if (txq->descs == NULL)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002912 return -ENOMEM;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002913
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002914 txq->last_desc = txq->size - 1;
2915
2916 /* Set maximum bandwidth for enabled TXQs */
2917 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0x03ffffff);
2918 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0x3fffffff);
2919
2920 /* Set Tx descriptors queue starting address */
2921 mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), txq->descs_phys);
2922 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), txq->size);
2923
2924 txq->tx_skb = kmalloc(txq->size * sizeof(*txq->tx_skb), GFP_KERNEL);
2925 if (txq->tx_skb == NULL) {
2926 dma_free_coherent(pp->dev->dev.parent,
2927 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2928 txq->descs, txq->descs_phys);
2929 return -ENOMEM;
2930 }
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03002931
2932 /* Allocate DMA buffers for TSO MAC/IP/TCP headers */
2933 txq->tso_hdrs = dma_alloc_coherent(pp->dev->dev.parent,
2934 txq->size * TSO_HEADER_SIZE,
2935 &txq->tso_hdrs_phys, GFP_KERNEL);
2936 if (txq->tso_hdrs == NULL) {
2937 kfree(txq->tx_skb);
2938 dma_free_coherent(pp->dev->dev.parent,
2939 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2940 txq->descs, txq->descs_phys);
2941 return -ENOMEM;
2942 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002943 mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
2944
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01002945 /* Setup XPS mapping */
2946 if (txq_number > 1)
2947 cpu = txq->id % num_present_cpus();
2948 else
2949 cpu = pp->rxq_def % num_present_cpus();
2950 cpumask_set_cpu(cpu, &txq->affinity_mask);
2951 netif_set_xps_queue(pp->dev, &txq->affinity_mask, txq->id);
2952
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002953 return 0;
2954}
2955
2956/* Free allocated resources when mvneta_txq_init() fails to allocate memory*/
2957static void mvneta_txq_deinit(struct mvneta_port *pp,
2958 struct mvneta_tx_queue *txq)
2959{
2960 kfree(txq->tx_skb);
2961
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03002962 if (txq->tso_hdrs)
2963 dma_free_coherent(pp->dev->dev.parent,
2964 txq->size * TSO_HEADER_SIZE,
2965 txq->tso_hdrs, txq->tso_hdrs_phys);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03002966 if (txq->descs)
2967 dma_free_coherent(pp->dev->dev.parent,
2968 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2969 txq->descs, txq->descs_phys);
2970
2971 txq->descs = NULL;
2972 txq->last_desc = 0;
2973 txq->next_desc_to_proc = 0;
2974 txq->descs_phys = 0;
2975
2976 /* Set minimum bandwidth for disabled TXQs */
2977 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0);
2978 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0);
2979
2980 /* Set Tx descriptors queue starting address and size */
2981 mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), 0);
2982 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), 0);
2983}
2984
2985/* Cleanup all Tx queues */
2986static void mvneta_cleanup_txqs(struct mvneta_port *pp)
2987{
2988 int queue;
2989
2990 for (queue = 0; queue < txq_number; queue++)
2991 mvneta_txq_deinit(pp, &pp->txqs[queue]);
2992}
2993
2994/* Cleanup all Rx queues */
2995static void mvneta_cleanup_rxqs(struct mvneta_port *pp)
2996{
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01002997 int queue;
2998
2999 for (queue = 0; queue < txq_number; queue++)
3000 mvneta_rxq_deinit(pp, &pp->rxqs[queue]);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003001}
3002
3003
3004/* Init all Rx queues */
3005static int mvneta_setup_rxqs(struct mvneta_port *pp)
3006{
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003007 int queue;
3008
3009 for (queue = 0; queue < rxq_number; queue++) {
3010 int err = mvneta_rxq_init(pp, &pp->rxqs[queue]);
3011
3012 if (err) {
3013 netdev_err(pp->dev, "%s: can't create rxq=%d\n",
3014 __func__, queue);
3015 mvneta_cleanup_rxqs(pp);
3016 return err;
3017 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003018 }
3019
3020 return 0;
3021}
3022
3023/* Init all tx queues */
3024static int mvneta_setup_txqs(struct mvneta_port *pp)
3025{
3026 int queue;
3027
3028 for (queue = 0; queue < txq_number; queue++) {
3029 int err = mvneta_txq_init(pp, &pp->txqs[queue]);
3030 if (err) {
3031 netdev_err(pp->dev, "%s: can't create txq=%d\n",
3032 __func__, queue);
3033 mvneta_cleanup_txqs(pp);
3034 return err;
3035 }
3036 }
3037
3038 return 0;
3039}
3040
3041static void mvneta_start_dev(struct mvneta_port *pp)
3042{
Gregory CLEMENT6b125d62016-02-04 22:09:25 +01003043 int cpu;
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003044 struct net_device *ndev = pp->dev;
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003045
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003046 mvneta_max_rx_size_set(pp, pp->pkt_size);
3047 mvneta_txq_max_tx_size_set(pp, pp->pkt_size);
3048
3049 /* start the Rx/Tx activity */
3050 mvneta_port_enable(pp);
3051
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003052 if (!pp->neta_armada3700) {
3053 /* Enable polling on the port */
3054 for_each_online_cpu(cpu) {
3055 struct mvneta_pcpu_port *port =
3056 per_cpu_ptr(pp->ports, cpu);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003057
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003058 napi_enable(&port->napi);
3059 }
3060 } else {
3061 napi_enable(&pp->napi);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003062 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003063
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003064 /* Unmask interrupts. It has to be done from each CPU */
Gregory CLEMENT6b125d62016-02-04 22:09:25 +01003065 on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
3066
Stas Sergeev898b29702015-04-01 20:32:49 +03003067 mvreg_write(pp, MVNETA_INTR_MISC_MASK,
3068 MVNETA_CAUSE_PHY_STATUS_CHANGE |
3069 MVNETA_CAUSE_LINK_CHANGE |
3070 MVNETA_CAUSE_PSC_SYNC_CHANGE);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003071
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003072 phy_start(ndev->phydev);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003073 netif_tx_start_all_queues(pp->dev);
3074}
3075
3076static void mvneta_stop_dev(struct mvneta_port *pp)
3077{
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003078 unsigned int cpu;
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003079 struct net_device *ndev = pp->dev;
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003080
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003081 phy_stop(ndev->phydev);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003082
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003083 if (!pp->neta_armada3700) {
3084 for_each_online_cpu(cpu) {
3085 struct mvneta_pcpu_port *port =
3086 per_cpu_ptr(pp->ports, cpu);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003087
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003088 napi_disable(&port->napi);
3089 }
3090 } else {
3091 napi_disable(&pp->napi);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02003092 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003093
3094 netif_carrier_off(pp->dev);
3095
3096 mvneta_port_down(pp);
3097 netif_tx_stop_all_queues(pp->dev);
3098
3099 /* Stop the port activity */
3100 mvneta_port_disable(pp);
3101
3102 /* Clear all ethernet port interrupts */
Gregory CLEMENTdb488c12016-02-04 22:09:27 +01003103 on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003104
3105 /* Mask all ethernet port interrupts */
Gregory CLEMENTdb488c12016-02-04 22:09:27 +01003106 on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003107
3108 mvneta_tx_reset(pp);
3109 mvneta_rx_reset(pp);
3110}
3111
Marcin Wojtasdb5dd0d2016-04-01 15:21:18 +02003112static void mvneta_percpu_enable(void *arg)
3113{
3114 struct mvneta_port *pp = arg;
3115
3116 enable_percpu_irq(pp->dev->irq, IRQ_TYPE_NONE);
3117}
3118
3119static void mvneta_percpu_disable(void *arg)
3120{
3121 struct mvneta_port *pp = arg;
3122
3123 disable_percpu_irq(pp->dev->irq);
3124}
3125
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003126/* Change the device mtu */
3127static int mvneta_change_mtu(struct net_device *dev, int mtu)
3128{
3129 struct mvneta_port *pp = netdev_priv(dev);
3130 int ret;
3131
Jarod Wilson57779872016-10-17 15:54:06 -04003132 if (!IS_ALIGNED(MVNETA_RX_PKT_SIZE(mtu), 8)) {
3133 netdev_info(dev, "Illegal MTU value %d, rounding to %d\n",
3134 mtu, ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8));
3135 mtu = ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8);
3136 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003137
3138 dev->mtu = mtu;
3139
Simon Guinotb65657f2015-06-30 16:20:22 +02003140 if (!netif_running(dev)) {
Marcin Wojtasdc35a102016-03-14 09:39:03 +01003141 if (pp->bm_priv)
3142 mvneta_bm_update_mtu(pp, mtu);
3143
Simon Guinotb65657f2015-06-30 16:20:22 +02003144 netdev_update_features(dev);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003145 return 0;
Simon Guinotb65657f2015-06-30 16:20:22 +02003146 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003147
Thomas Petazzoni6a20c172012-11-19 11:41:25 +01003148 /* The interface is running, so we have to force a
Ezequiel Garciaa92dbd92014-05-22 20:06:58 -03003149 * reallocation of the queues
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003150 */
3151 mvneta_stop_dev(pp);
Marcin Wojtasdb5dd0d2016-04-01 15:21:18 +02003152 on_each_cpu(mvneta_percpu_disable, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003153
3154 mvneta_cleanup_txqs(pp);
3155 mvneta_cleanup_rxqs(pp);
3156
Marcin Wojtasdc35a102016-03-14 09:39:03 +01003157 if (pp->bm_priv)
3158 mvneta_bm_update_mtu(pp, mtu);
3159
Ezequiel Garciaa92dbd92014-05-22 20:06:58 -03003160 pp->pkt_size = MVNETA_RX_PKT_SIZE(dev->mtu);
willy tarreau8ec2cd42014-01-16 08:20:16 +01003161 pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
3162 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003163
3164 ret = mvneta_setup_rxqs(pp);
3165 if (ret) {
Ezequiel Garciaa92dbd92014-05-22 20:06:58 -03003166 netdev_err(dev, "unable to setup rxqs after MTU change\n");
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003167 return ret;
3168 }
3169
Ezequiel Garciaa92dbd92014-05-22 20:06:58 -03003170 ret = mvneta_setup_txqs(pp);
3171 if (ret) {
3172 netdev_err(dev, "unable to setup txqs after MTU change\n");
3173 return ret;
3174 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003175
Marcin Wojtasdb5dd0d2016-04-01 15:21:18 +02003176 on_each_cpu(mvneta_percpu_enable, pp, true);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003177 mvneta_start_dev(pp);
3178 mvneta_port_up(pp);
3179
Simon Guinotb65657f2015-06-30 16:20:22 +02003180 netdev_update_features(dev);
3181
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003182 return 0;
3183}
3184
Simon Guinotb65657f2015-06-30 16:20:22 +02003185static netdev_features_t mvneta_fix_features(struct net_device *dev,
3186 netdev_features_t features)
3187{
3188 struct mvneta_port *pp = netdev_priv(dev);
3189
3190 if (pp->tx_csum_limit && dev->mtu > pp->tx_csum_limit) {
3191 features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
3192 netdev_info(dev,
3193 "Disable IP checksum for MTU greater than %dB\n",
3194 pp->tx_csum_limit);
3195 }
3196
3197 return features;
3198}
3199
Thomas Petazzoni8cc3e432013-06-04 04:52:23 +00003200/* Get mac address */
3201static void mvneta_get_mac_addr(struct mvneta_port *pp, unsigned char *addr)
3202{
3203 u32 mac_addr_l, mac_addr_h;
3204
3205 mac_addr_l = mvreg_read(pp, MVNETA_MAC_ADDR_LOW);
3206 mac_addr_h = mvreg_read(pp, MVNETA_MAC_ADDR_HIGH);
3207 addr[0] = (mac_addr_h >> 24) & 0xFF;
3208 addr[1] = (mac_addr_h >> 16) & 0xFF;
3209 addr[2] = (mac_addr_h >> 8) & 0xFF;
3210 addr[3] = mac_addr_h & 0xFF;
3211 addr[4] = (mac_addr_l >> 8) & 0xFF;
3212 addr[5] = mac_addr_l & 0xFF;
3213}
3214
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003215/* Handle setting mac address */
3216static int mvneta_set_mac_addr(struct net_device *dev, void *addr)
3217{
3218 struct mvneta_port *pp = netdev_priv(dev);
Ezequiel Garciae68de362014-05-22 20:07:00 -03003219 struct sockaddr *sockaddr = addr;
3220 int ret;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003221
Ezequiel Garciae68de362014-05-22 20:07:00 -03003222 ret = eth_prepare_mac_addr_change(dev, addr);
3223 if (ret < 0)
3224 return ret;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003225 /* Remove previous address table entry */
3226 mvneta_mac_addr_set(pp, dev->dev_addr, -1);
3227
3228 /* Set new addr in hw */
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01003229 mvneta_mac_addr_set(pp, sockaddr->sa_data, pp->rxq_def);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003230
Ezequiel Garciae68de362014-05-22 20:07:00 -03003231 eth_commit_mac_addr_change(dev, addr);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003232 return 0;
3233}
3234
3235static void mvneta_adjust_link(struct net_device *ndev)
3236{
3237 struct mvneta_port *pp = netdev_priv(ndev);
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003238 struct phy_device *phydev = ndev->phydev;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003239 int status_change = 0;
3240
3241 if (phydev->link) {
3242 if ((pp->speed != phydev->speed) ||
3243 (pp->duplex != phydev->duplex)) {
3244 u32 val;
3245
3246 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
3247 val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
3248 MVNETA_GMAC_CONFIG_GMII_SPEED |
Stas Sergeev898b29702015-04-01 20:32:49 +03003249 MVNETA_GMAC_CONFIG_FULL_DUPLEX);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003250
3251 if (phydev->duplex)
3252 val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
3253
3254 if (phydev->speed == SPEED_1000)
3255 val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
Thomas Petazzoni4d12bc62014-07-08 10:49:43 +02003256 else if (phydev->speed == SPEED_100)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003257 val |= MVNETA_GMAC_CONFIG_MII_SPEED;
3258
3259 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
3260
3261 pp->duplex = phydev->duplex;
3262 pp->speed = phydev->speed;
3263 }
3264 }
3265
3266 if (phydev->link != pp->link) {
3267 if (!phydev->link) {
3268 pp->duplex = -1;
3269 pp->speed = 0;
3270 }
3271
3272 pp->link = phydev->link;
3273 status_change = 1;
3274 }
3275
3276 if (status_change) {
3277 if (phydev->link) {
Stas Sergeev898b29702015-04-01 20:32:49 +03003278 if (!pp->use_inband_status) {
3279 u32 val = mvreg_read(pp,
3280 MVNETA_GMAC_AUTONEG_CONFIG);
3281 val &= ~MVNETA_GMAC_FORCE_LINK_DOWN;
3282 val |= MVNETA_GMAC_FORCE_LINK_PASS;
3283 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG,
3284 val);
3285 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003286 mvneta_port_up(pp);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003287 } else {
Stas Sergeev898b29702015-04-01 20:32:49 +03003288 if (!pp->use_inband_status) {
3289 u32 val = mvreg_read(pp,
3290 MVNETA_GMAC_AUTONEG_CONFIG);
3291 val &= ~MVNETA_GMAC_FORCE_LINK_PASS;
3292 val |= MVNETA_GMAC_FORCE_LINK_DOWN;
3293 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG,
3294 val);
3295 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003296 mvneta_port_down(pp);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003297 }
Ezequiel Garcia0089b742014-10-31 12:57:20 -03003298 phy_print_status(phydev);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003299 }
3300}
3301
3302static int mvneta_mdio_probe(struct mvneta_port *pp)
3303{
3304 struct phy_device *phy_dev;
3305
3306 phy_dev = of_phy_connect(pp->dev, pp->phy_node, mvneta_adjust_link, 0,
3307 pp->phy_interface);
3308 if (!phy_dev) {
3309 netdev_err(pp->dev, "could not find the PHY\n");
3310 return -ENODEV;
3311 }
3312
3313 phy_dev->supported &= PHY_GBIT_FEATURES;
3314 phy_dev->advertising = phy_dev->supported;
3315
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003316 pp->link = 0;
3317 pp->duplex = 0;
3318 pp->speed = 0;
3319
3320 return 0;
3321}
3322
3323static void mvneta_mdio_remove(struct mvneta_port *pp)
3324{
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003325 struct net_device *ndev = pp->dev;
3326
3327 phy_disconnect(ndev->phydev);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003328}
3329
Gregory CLEMENT120cfa52016-02-04 22:09:29 +01003330/* Electing a CPU must be done in an atomic way: it should be done
3331 * after or before the removal/insertion of a CPU and this function is
3332 * not reentrant.
3333 */
Maxime Ripardf8642882015-09-25 18:09:38 +02003334static void mvneta_percpu_elect(struct mvneta_port *pp)
3335{
Gregory CLEMENTcad5d842016-02-04 22:09:24 +01003336 int elected_cpu = 0, max_cpu, cpu, i = 0;
Maxime Ripardf8642882015-09-25 18:09:38 +02003337
Gregory CLEMENTcad5d842016-02-04 22:09:24 +01003338 /* Use the cpu associated to the rxq when it is online, in all
3339 * the other cases, use the cpu 0 which can't be offline.
3340 */
3341 if (cpu_online(pp->rxq_def))
3342 elected_cpu = pp->rxq_def;
3343
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003344 max_cpu = num_present_cpus();
Maxime Ripardf8642882015-09-25 18:09:38 +02003345
3346 for_each_online_cpu(cpu) {
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003347 int rxq_map = 0, txq_map = 0;
3348 int rxq;
3349
3350 for (rxq = 0; rxq < rxq_number; rxq++)
3351 if ((rxq % max_cpu) == cpu)
3352 rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
3353
Gregory CLEMENTcad5d842016-02-04 22:09:24 +01003354 if (cpu == elected_cpu)
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01003355 /* Map the default receive queue queue to the
3356 * elected CPU
Maxime Ripardf8642882015-09-25 18:09:38 +02003357 */
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003358 rxq_map |= MVNETA_CPU_RXQ_ACCESS(pp->rxq_def);
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01003359
3360 /* We update the TX queue map only if we have one
3361 * queue. In this case we associate the TX queue to
3362 * the CPU bound to the default RX queue
3363 */
3364 if (txq_number == 1)
Gregory CLEMENTcad5d842016-02-04 22:09:24 +01003365 txq_map = (cpu == elected_cpu) ?
Gregory CLEMENT50bf8cb2015-12-09 18:23:51 +01003366 MVNETA_CPU_TXQ_ACCESS(1) : 0;
3367 else
3368 txq_map = mvreg_read(pp, MVNETA_CPU_MAP(cpu)) &
3369 MVNETA_CPU_TXQ_ACCESS_ALL_MASK;
3370
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003371 mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map);
3372
3373 /* Update the interrupt mask on each CPU according the
3374 * new mapping
3375 */
3376 smp_call_function_single(cpu, mvneta_percpu_unmask_interrupt,
3377 pp, true);
Maxime Ripardf8642882015-09-25 18:09:38 +02003378 i++;
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003379
Maxime Ripardf8642882015-09-25 18:09:38 +02003380 }
3381};
3382
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003383static int mvneta_cpu_online(unsigned int cpu, struct hlist_node *node)
Maxime Ripardf8642882015-09-25 18:09:38 +02003384{
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003385 int other_cpu;
3386 struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
3387 node_online);
Maxime Ripardf8642882015-09-25 18:09:38 +02003388 struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
3389
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003390
3391 spin_lock(&pp->lock);
3392 /*
3393 * Configuring the driver for a new CPU while the driver is
3394 * stopping is racy, so just avoid it.
3395 */
3396 if (pp->is_stopped) {
3397 spin_unlock(&pp->lock);
3398 return 0;
3399 }
3400 netif_tx_stop_all_queues(pp->dev);
3401
3402 /*
3403 * We have to synchronise on tha napi of each CPU except the one
3404 * just being woken up
3405 */
3406 for_each_online_cpu(other_cpu) {
3407 if (other_cpu != cpu) {
3408 struct mvneta_pcpu_port *other_port =
3409 per_cpu_ptr(pp->ports, other_cpu);
3410
3411 napi_synchronize(&other_port->napi);
Gregory CLEMENT120cfa52016-02-04 22:09:29 +01003412 }
Maxime Ripardf8642882015-09-25 18:09:38 +02003413 }
3414
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003415 /* Mask all ethernet port interrupts */
3416 on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
3417 napi_enable(&port->napi);
3418
3419 /*
3420 * Enable per-CPU interrupts on the CPU that is
3421 * brought up.
3422 */
3423 mvneta_percpu_enable(pp);
3424
3425 /*
3426 * Enable per-CPU interrupt on the one CPU we care
3427 * about.
3428 */
3429 mvneta_percpu_elect(pp);
3430
3431 /* Unmask all ethernet port interrupts */
3432 on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
3433 mvreg_write(pp, MVNETA_INTR_MISC_MASK,
3434 MVNETA_CAUSE_PHY_STATUS_CHANGE |
3435 MVNETA_CAUSE_LINK_CHANGE |
3436 MVNETA_CAUSE_PSC_SYNC_CHANGE);
3437 netif_tx_start_all_queues(pp->dev);
3438 spin_unlock(&pp->lock);
3439 return 0;
3440}
3441
3442static int mvneta_cpu_down_prepare(unsigned int cpu, struct hlist_node *node)
3443{
3444 struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
3445 node_online);
3446 struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
3447
3448 /*
3449 * Thanks to this lock we are sure that any pending cpu election is
3450 * done.
3451 */
3452 spin_lock(&pp->lock);
3453 /* Mask all ethernet port interrupts */
3454 on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
3455 spin_unlock(&pp->lock);
3456
3457 napi_synchronize(&port->napi);
3458 napi_disable(&port->napi);
3459 /* Disable per-CPU interrupts on the CPU that is brought down. */
3460 mvneta_percpu_disable(pp);
3461 return 0;
3462}
3463
3464static int mvneta_cpu_dead(unsigned int cpu, struct hlist_node *node)
3465{
3466 struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
3467 node_dead);
3468
3469 /* Check if a new CPU must be elected now this on is down */
3470 spin_lock(&pp->lock);
3471 mvneta_percpu_elect(pp);
3472 spin_unlock(&pp->lock);
3473 /* Unmask all ethernet port interrupts */
3474 on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
3475 mvreg_write(pp, MVNETA_INTR_MISC_MASK,
3476 MVNETA_CAUSE_PHY_STATUS_CHANGE |
3477 MVNETA_CAUSE_LINK_CHANGE |
3478 MVNETA_CAUSE_PSC_SYNC_CHANGE);
3479 netif_tx_start_all_queues(pp->dev);
3480 return 0;
Maxime Ripardf8642882015-09-25 18:09:38 +02003481}
3482
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003483static int mvneta_open(struct net_device *dev)
3484{
3485 struct mvneta_port *pp = netdev_priv(dev);
Gregory CLEMENT6b125d62016-02-04 22:09:25 +01003486 int ret;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003487
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003488 pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
willy tarreau8ec2cd42014-01-16 08:20:16 +01003489 pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
3490 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003491
3492 ret = mvneta_setup_rxqs(pp);
3493 if (ret)
3494 return ret;
3495
3496 ret = mvneta_setup_txqs(pp);
3497 if (ret)
3498 goto err_cleanup_rxqs;
3499
3500 /* Connect to port interrupt line */
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003501 if (pp->neta_armada3700)
3502 ret = request_irq(pp->dev->irq, mvneta_isr, 0,
3503 dev->name, pp);
3504 else
3505 ret = request_percpu_irq(pp->dev->irq, mvneta_percpu_isr,
3506 dev->name, pp->ports);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003507 if (ret) {
3508 netdev_err(pp->dev, "cannot request irq %d\n", pp->dev->irq);
3509 goto err_cleanup_txqs;
3510 }
3511
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003512 if (!pp->neta_armada3700) {
3513 /* Enable per-CPU interrupt on all the CPU to handle our RX
3514 * queue interrupts
3515 */
3516 on_each_cpu(mvneta_percpu_enable, pp, true);
Gregory CLEMENT2dcf75e2015-12-09 18:23:49 +01003517
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003518 pp->is_stopped = false;
3519 /* Register a CPU notifier to handle the case where our CPU
3520 * might be taken offline.
3521 */
3522 ret = cpuhp_state_add_instance_nocalls(online_hpstate,
3523 &pp->node_online);
3524 if (ret)
3525 goto err_free_irq;
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003526
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003527 ret = cpuhp_state_add_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
3528 &pp->node_dead);
3529 if (ret)
3530 goto err_free_online_hp;
3531 }
Maxime Ripardf8642882015-09-25 18:09:38 +02003532
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003533 /* In default link is down */
3534 netif_carrier_off(pp->dev);
3535
3536 ret = mvneta_mdio_probe(pp);
3537 if (ret < 0) {
3538 netdev_err(dev, "cannot probe MDIO bus\n");
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003539 goto err_free_dead_hp;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003540 }
3541
3542 mvneta_start_dev(pp);
3543
3544 return 0;
3545
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003546err_free_dead_hp:
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003547 if (!pp->neta_armada3700)
3548 cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
3549 &pp->node_dead);
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003550err_free_online_hp:
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003551 if (!pp->neta_armada3700)
3552 cpuhp_state_remove_instance_nocalls(online_hpstate,
3553 &pp->node_online);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003554err_free_irq:
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003555 if (pp->neta_armada3700) {
3556 free_irq(pp->dev->irq, pp);
3557 } else {
3558 on_each_cpu(mvneta_percpu_disable, pp, true);
3559 free_percpu_irq(pp->dev->irq, pp->ports);
3560 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003561err_cleanup_txqs:
3562 mvneta_cleanup_txqs(pp);
3563err_cleanup_rxqs:
3564 mvneta_cleanup_rxqs(pp);
3565 return ret;
3566}
3567
3568/* Stop the port, free port interrupt line */
3569static int mvneta_stop(struct net_device *dev)
3570{
3571 struct mvneta_port *pp = netdev_priv(dev);
3572
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003573 if (!pp->neta_armada3700) {
3574 /* Inform that we are stopping so we don't want to setup the
3575 * driver for new CPUs in the notifiers. The code of the
3576 * notifier for CPU online is protected by the same spinlock,
3577 * so when we get the lock, the notifer work is done.
3578 */
3579 spin_lock(&pp->lock);
3580 pp->is_stopped = true;
3581 spin_unlock(&pp->lock);
Gregory CLEMENT1c2722a2016-03-12 18:44:17 +01003582
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003583 mvneta_stop_dev(pp);
3584 mvneta_mdio_remove(pp);
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02003585
Dan Carpenterd26aac22016-12-07 14:32:17 +03003586 cpuhp_state_remove_instance_nocalls(online_hpstate,
3587 &pp->node_online);
3588 cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
3589 &pp->node_dead);
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003590 on_each_cpu(mvneta_percpu_disable, pp, true);
3591 free_percpu_irq(dev->irq, pp->ports);
3592 } else {
3593 mvneta_stop_dev(pp);
3594 mvneta_mdio_remove(pp);
3595 free_irq(dev->irq, pp);
3596 }
3597
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003598 mvneta_cleanup_rxqs(pp);
3599 mvneta_cleanup_txqs(pp);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003600
3601 return 0;
3602}
3603
Thomas Petazzoni15f59452013-09-04 16:26:52 +02003604static int mvneta_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3605{
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003606 if (!dev->phydev)
Thomas Petazzoni15f59452013-09-04 16:26:52 +02003607 return -ENOTSUPP;
3608
Philippe Reynesc6c022e2016-07-30 17:42:11 +02003609 return phy_mii_ioctl(dev->phydev, ifr, cmd);
Thomas Petazzoni15f59452013-09-04 16:26:52 +02003610}
3611
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003612/* Ethtool methods */
3613
Philippe Reynes013ad402016-07-30 17:42:12 +02003614/* Set link ksettings (phy address, speed) for ethtools */
Baoyou Xie2dc0d2b2016-09-25 17:20:41 +08003615static int
3616mvneta_ethtool_set_link_ksettings(struct net_device *ndev,
3617 const struct ethtool_link_ksettings *cmd)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003618{
Philippe Reynes013ad402016-07-30 17:42:12 +02003619 struct mvneta_port *pp = netdev_priv(ndev);
3620 struct phy_device *phydev = ndev->phydev;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003621
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003622 if (!phydev)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003623 return -ENODEV;
3624
Philippe Reynes013ad402016-07-30 17:42:12 +02003625 if ((cmd->base.autoneg == AUTONEG_ENABLE) != pp->use_inband_status) {
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003626 u32 val;
3627
Philippe Reynes013ad402016-07-30 17:42:12 +02003628 mvneta_set_autoneg(pp, cmd->base.autoneg == AUTONEG_ENABLE);
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003629
Philippe Reynes013ad402016-07-30 17:42:12 +02003630 if (cmd->base.autoneg == AUTONEG_DISABLE) {
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003631 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
3632 val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
3633 MVNETA_GMAC_CONFIG_GMII_SPEED |
3634 MVNETA_GMAC_CONFIG_FULL_DUPLEX);
3635
3636 if (phydev->duplex)
3637 val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
3638
3639 if (phydev->speed == SPEED_1000)
3640 val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
3641 else if (phydev->speed == SPEED_100)
3642 val |= MVNETA_GMAC_CONFIG_MII_SPEED;
3643
3644 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
3645 }
3646
Philippe Reynes013ad402016-07-30 17:42:12 +02003647 pp->use_inband_status = (cmd->base.autoneg == AUTONEG_ENABLE);
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003648 netdev_info(pp->dev, "autoneg status set to %i\n",
3649 pp->use_inband_status);
3650
Philippe Reynes013ad402016-07-30 17:42:12 +02003651 if (netif_running(ndev)) {
Stas Sergeev0c0744f2015-12-02 20:35:11 +03003652 mvneta_port_down(pp);
3653 mvneta_port_up(pp);
3654 }
3655 }
3656
Philippe Reynes013ad402016-07-30 17:42:12 +02003657 return phy_ethtool_ksettings_set(ndev->phydev, cmd);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003658}
3659
3660/* Set interrupt coalescing for ethtools */
3661static int mvneta_ethtool_set_coalesce(struct net_device *dev,
3662 struct ethtool_coalesce *c)
3663{
3664 struct mvneta_port *pp = netdev_priv(dev);
3665 int queue;
3666
3667 for (queue = 0; queue < rxq_number; queue++) {
3668 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
3669 rxq->time_coal = c->rx_coalesce_usecs;
3670 rxq->pkts_coal = c->rx_max_coalesced_frames;
3671 mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
3672 mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
3673 }
3674
3675 for (queue = 0; queue < txq_number; queue++) {
3676 struct mvneta_tx_queue *txq = &pp->txqs[queue];
3677 txq->done_pkts_coal = c->tx_max_coalesced_frames;
3678 mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
3679 }
3680
3681 return 0;
3682}
3683
3684/* get coalescing for ethtools */
3685static int mvneta_ethtool_get_coalesce(struct net_device *dev,
3686 struct ethtool_coalesce *c)
3687{
3688 struct mvneta_port *pp = netdev_priv(dev);
3689
3690 c->rx_coalesce_usecs = pp->rxqs[0].time_coal;
3691 c->rx_max_coalesced_frames = pp->rxqs[0].pkts_coal;
3692
3693 c->tx_max_coalesced_frames = pp->txqs[0].done_pkts_coal;
3694 return 0;
3695}
3696
3697
3698static void mvneta_ethtool_get_drvinfo(struct net_device *dev,
3699 struct ethtool_drvinfo *drvinfo)
3700{
3701 strlcpy(drvinfo->driver, MVNETA_DRIVER_NAME,
3702 sizeof(drvinfo->driver));
3703 strlcpy(drvinfo->version, MVNETA_DRIVER_VERSION,
3704 sizeof(drvinfo->version));
3705 strlcpy(drvinfo->bus_info, dev_name(&dev->dev),
3706 sizeof(drvinfo->bus_info));
3707}
3708
3709
3710static void mvneta_ethtool_get_ringparam(struct net_device *netdev,
3711 struct ethtool_ringparam *ring)
3712{
3713 struct mvneta_port *pp = netdev_priv(netdev);
3714
3715 ring->rx_max_pending = MVNETA_MAX_RXD;
3716 ring->tx_max_pending = MVNETA_MAX_TXD;
3717 ring->rx_pending = pp->rx_ring_size;
3718 ring->tx_pending = pp->tx_ring_size;
3719}
3720
3721static int mvneta_ethtool_set_ringparam(struct net_device *dev,
3722 struct ethtool_ringparam *ring)
3723{
3724 struct mvneta_port *pp = netdev_priv(dev);
3725
3726 if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
3727 return -EINVAL;
3728 pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
3729 ring->rx_pending : MVNETA_MAX_RXD;
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -03003730
3731 pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
3732 MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
3733 if (pp->tx_ring_size != ring->tx_pending)
3734 netdev_warn(dev, "TX queue size set to %u (requested %u)\n",
3735 pp->tx_ring_size, ring->tx_pending);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003736
3737 if (netif_running(dev)) {
3738 mvneta_stop(dev);
3739 if (mvneta_open(dev)) {
3740 netdev_err(dev,
3741 "error on opening device after ring param change\n");
3742 return -ENOMEM;
3743 }
3744 }
3745
3746 return 0;
3747}
3748
Russell King9b0cdef2015-10-22 18:37:30 +01003749static void mvneta_ethtool_get_strings(struct net_device *netdev, u32 sset,
3750 u8 *data)
3751{
3752 if (sset == ETH_SS_STATS) {
3753 int i;
3754
3755 for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++)
3756 memcpy(data + i * ETH_GSTRING_LEN,
3757 mvneta_statistics[i].name, ETH_GSTRING_LEN);
3758 }
3759}
3760
3761static void mvneta_ethtool_update_stats(struct mvneta_port *pp)
3762{
3763 const struct mvneta_statistic *s;
3764 void __iomem *base = pp->base;
3765 u32 high, low, val;
Jisheng Zhang2c832292016-01-20 16:36:25 +08003766 u64 val64;
Russell King9b0cdef2015-10-22 18:37:30 +01003767 int i;
3768
3769 for (i = 0, s = mvneta_statistics;
3770 s < mvneta_statistics + ARRAY_SIZE(mvneta_statistics);
3771 s++, i++) {
Russell King9b0cdef2015-10-22 18:37:30 +01003772 switch (s->type) {
3773 case T_REG_32:
3774 val = readl_relaxed(base + s->offset);
Jisheng Zhang2c832292016-01-20 16:36:25 +08003775 pp->ethtool_stats[i] += val;
Russell King9b0cdef2015-10-22 18:37:30 +01003776 break;
3777 case T_REG_64:
3778 /* Docs say to read low 32-bit then high */
3779 low = readl_relaxed(base + s->offset);
3780 high = readl_relaxed(base + s->offset + 4);
Jisheng Zhang2c832292016-01-20 16:36:25 +08003781 val64 = (u64)high << 32 | low;
3782 pp->ethtool_stats[i] += val64;
Russell King9b0cdef2015-10-22 18:37:30 +01003783 break;
3784 }
Russell King9b0cdef2015-10-22 18:37:30 +01003785 }
3786}
3787
3788static void mvneta_ethtool_get_stats(struct net_device *dev,
3789 struct ethtool_stats *stats, u64 *data)
3790{
3791 struct mvneta_port *pp = netdev_priv(dev);
3792 int i;
3793
3794 mvneta_ethtool_update_stats(pp);
3795
3796 for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++)
3797 *data++ = pp->ethtool_stats[i];
3798}
3799
3800static int mvneta_ethtool_get_sset_count(struct net_device *dev, int sset)
3801{
3802 if (sset == ETH_SS_STATS)
3803 return ARRAY_SIZE(mvneta_statistics);
3804 return -EOPNOTSUPP;
3805}
3806
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003807static u32 mvneta_ethtool_get_rxfh_indir_size(struct net_device *dev)
3808{
3809 return MVNETA_RSS_LU_TABLE_SIZE;
3810}
3811
3812static int mvneta_ethtool_get_rxnfc(struct net_device *dev,
3813 struct ethtool_rxnfc *info,
3814 u32 *rules __always_unused)
3815{
3816 switch (info->cmd) {
3817 case ETHTOOL_GRXRINGS:
3818 info->data = rxq_number;
3819 return 0;
3820 case ETHTOOL_GRXFH:
3821 return -EOPNOTSUPP;
3822 default:
3823 return -EOPNOTSUPP;
3824 }
3825}
3826
3827static int mvneta_config_rss(struct mvneta_port *pp)
3828{
3829 int cpu;
3830 u32 val;
3831
3832 netif_tx_stop_all_queues(pp->dev);
3833
Gregory CLEMENT6b125d62016-02-04 22:09:25 +01003834 on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003835
3836 /* We have to synchronise on the napi of each CPU */
3837 for_each_online_cpu(cpu) {
3838 struct mvneta_pcpu_port *pcpu_port =
3839 per_cpu_ptr(pp->ports, cpu);
3840
3841 napi_synchronize(&pcpu_port->napi);
3842 napi_disable(&pcpu_port->napi);
3843 }
3844
3845 pp->rxq_def = pp->indir[0];
3846
3847 /* Update unicast mapping */
3848 mvneta_set_rx_mode(pp->dev);
3849
3850 /* Update val of portCfg register accordingly with all RxQueue types */
3851 val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def);
3852 mvreg_write(pp, MVNETA_PORT_CONFIG, val);
3853
3854 /* Update the elected CPU matching the new rxq_def */
Gregory CLEMENT120cfa52016-02-04 22:09:29 +01003855 spin_lock(&pp->lock);
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003856 mvneta_percpu_elect(pp);
Gregory CLEMENT120cfa52016-02-04 22:09:29 +01003857 spin_unlock(&pp->lock);
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003858
3859 /* We have to synchronise on the napi of each CPU */
3860 for_each_online_cpu(cpu) {
3861 struct mvneta_pcpu_port *pcpu_port =
3862 per_cpu_ptr(pp->ports, cpu);
3863
3864 napi_enable(&pcpu_port->napi);
3865 }
3866
3867 netif_tx_start_all_queues(pp->dev);
3868
3869 return 0;
3870}
3871
3872static int mvneta_ethtool_set_rxfh(struct net_device *dev, const u32 *indir,
3873 const u8 *key, const u8 hfunc)
3874{
3875 struct mvneta_port *pp = netdev_priv(dev);
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003876
3877 /* Current code for Armada 3700 doesn't support RSS features yet */
3878 if (pp->neta_armada3700)
3879 return -EOPNOTSUPP;
3880
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003881 /* We require at least one supported parameter to be changed
3882 * and no change in any of the unsupported parameters
3883 */
3884 if (key ||
3885 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
3886 return -EOPNOTSUPP;
3887
3888 if (!indir)
3889 return 0;
3890
3891 memcpy(pp->indir, indir, MVNETA_RSS_LU_TABLE_SIZE);
3892
3893 return mvneta_config_rss(pp);
3894}
3895
3896static int mvneta_ethtool_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
3897 u8 *hfunc)
3898{
3899 struct mvneta_port *pp = netdev_priv(dev);
3900
Marcin Wojtas2636ac32016-12-01 18:03:09 +01003901 /* Current code for Armada 3700 doesn't support RSS features yet */
3902 if (pp->neta_armada3700)
3903 return -EOPNOTSUPP;
3904
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003905 if (hfunc)
3906 *hfunc = ETH_RSS_HASH_TOP;
3907
3908 if (!indir)
3909 return 0;
3910
3911 memcpy(indir, pp->indir, MVNETA_RSS_LU_TABLE_SIZE);
3912
3913 return 0;
3914}
3915
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003916static const struct net_device_ops mvneta_netdev_ops = {
3917 .ndo_open = mvneta_open,
3918 .ndo_stop = mvneta_stop,
3919 .ndo_start_xmit = mvneta_tx,
3920 .ndo_set_rx_mode = mvneta_set_rx_mode,
3921 .ndo_set_mac_address = mvneta_set_mac_addr,
3922 .ndo_change_mtu = mvneta_change_mtu,
Simon Guinotb65657f2015-06-30 16:20:22 +02003923 .ndo_fix_features = mvneta_fix_features,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003924 .ndo_get_stats64 = mvneta_get_stats64,
Thomas Petazzoni15f59452013-09-04 16:26:52 +02003925 .ndo_do_ioctl = mvneta_ioctl,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003926};
3927
3928const struct ethtool_ops mvneta_eth_tool_ops = {
Florian Fainelli5489ee82016-11-15 11:19:47 -08003929 .nway_reset = phy_ethtool_nway_reset,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003930 .get_link = ethtool_op_get_link,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003931 .set_coalesce = mvneta_ethtool_set_coalesce,
3932 .get_coalesce = mvneta_ethtool_get_coalesce,
3933 .get_drvinfo = mvneta_ethtool_get_drvinfo,
3934 .get_ringparam = mvneta_ethtool_get_ringparam,
3935 .set_ringparam = mvneta_ethtool_set_ringparam,
Russell King9b0cdef2015-10-22 18:37:30 +01003936 .get_strings = mvneta_ethtool_get_strings,
3937 .get_ethtool_stats = mvneta_ethtool_get_stats,
3938 .get_sset_count = mvneta_ethtool_get_sset_count,
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01003939 .get_rxfh_indir_size = mvneta_ethtool_get_rxfh_indir_size,
3940 .get_rxnfc = mvneta_ethtool_get_rxnfc,
3941 .get_rxfh = mvneta_ethtool_get_rxfh,
3942 .set_rxfh = mvneta_ethtool_set_rxfh,
Philippe Reynes013ad402016-07-30 17:42:12 +02003943 .get_link_ksettings = phy_ethtool_get_link_ksettings,
3944 .set_link_ksettings = mvneta_ethtool_set_link_ksettings,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003945};
3946
3947/* Initialize hw */
Ezequiel Garcia96728502014-05-22 20:06:59 -03003948static int mvneta_init(struct device *dev, struct mvneta_port *pp)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003949{
3950 int queue;
3951
3952 /* Disable port */
3953 mvneta_port_disable(pp);
3954
3955 /* Set port default values */
3956 mvneta_defaults_set(pp);
3957
Ezequiel Garcia96728502014-05-22 20:06:59 -03003958 pp->txqs = devm_kcalloc(dev, txq_number, sizeof(struct mvneta_tx_queue),
3959 GFP_KERNEL);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003960 if (!pp->txqs)
3961 return -ENOMEM;
3962
3963 /* Initialize TX descriptor rings */
3964 for (queue = 0; queue < txq_number; queue++) {
3965 struct mvneta_tx_queue *txq = &pp->txqs[queue];
3966 txq->id = queue;
3967 txq->size = pp->tx_ring_size;
3968 txq->done_pkts_coal = MVNETA_TXDONE_COAL_PKTS;
3969 }
3970
Ezequiel Garcia96728502014-05-22 20:06:59 -03003971 pp->rxqs = devm_kcalloc(dev, rxq_number, sizeof(struct mvneta_rx_queue),
3972 GFP_KERNEL);
3973 if (!pp->rxqs)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003974 return -ENOMEM;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003975
3976 /* Create Rx descriptor rings */
3977 for (queue = 0; queue < rxq_number; queue++) {
3978 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
3979 rxq->id = queue;
3980 rxq->size = pp->rx_ring_size;
3981 rxq->pkts_coal = MVNETA_RX_COAL_PKTS;
3982 rxq->time_coal = MVNETA_RX_COAL_USEC;
Gregory CLEMENTf88bee12016-12-01 18:03:06 +01003983 rxq->buf_virt_addr = devm_kmalloc(pp->dev->dev.parent,
3984 rxq->size * sizeof(void *),
3985 GFP_KERNEL);
3986 if (!rxq->buf_virt_addr)
3987 return -ENOMEM;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003988 }
3989
3990 return 0;
3991}
3992
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003993/* platform glue : initialize decoding windows */
Greg KH03ce7582012-12-21 13:42:15 +00003994static void mvneta_conf_mbus_windows(struct mvneta_port *pp,
3995 const struct mbus_dram_target_info *dram)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03003996{
3997 u32 win_enable;
3998 u32 win_protect;
3999 int i;
4000
4001 for (i = 0; i < 6; i++) {
4002 mvreg_write(pp, MVNETA_WIN_BASE(i), 0);
4003 mvreg_write(pp, MVNETA_WIN_SIZE(i), 0);
4004
4005 if (i < 4)
4006 mvreg_write(pp, MVNETA_WIN_REMAP(i), 0);
4007 }
4008
4009 win_enable = 0x3f;
4010 win_protect = 0;
4011
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004012 if (dram) {
4013 for (i = 0; i < dram->num_cs; i++) {
4014 const struct mbus_dram_window *cs = dram->cs + i;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004015
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004016 mvreg_write(pp, MVNETA_WIN_BASE(i),
4017 (cs->base & 0xffff0000) |
4018 (cs->mbus_attr << 8) |
4019 dram->mbus_dram_target_id);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004020
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004021 mvreg_write(pp, MVNETA_WIN_SIZE(i),
4022 (cs->size - 1) & 0xffff0000);
4023
4024 win_enable &= ~(1 << i);
4025 win_protect |= 3 << (2 * i);
4026 }
4027 } else {
4028 /* For Armada3700 open default 4GB Mbus window, leaving
4029 * arbitration of target/attribute to a different layer
4030 * of configuration.
4031 */
4032 mvreg_write(pp, MVNETA_WIN_SIZE(0), 0xffff0000);
4033 win_enable &= ~BIT(0);
4034 win_protect = 3;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004035 }
4036
4037 mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable);
Marcin Wojtasdb6ba9a2015-11-30 13:27:41 +01004038 mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004039}
4040
4041/* Power up the port */
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004042static int mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004043{
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004044 u32 ctrl;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004045
4046 /* MAC Cause register should be cleared */
4047 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0);
4048
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004049 ctrl = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004050
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004051 /* Even though it might look weird, when we're configured in
4052 * SGMII or QSGMII mode, the RGMII bit needs to be set.
4053 */
4054 switch(phy_mode) {
4055 case PHY_INTERFACE_MODE_QSGMII:
4056 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_QSGMII_SERDES_PROTO);
4057 ctrl |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
4058 break;
4059 case PHY_INTERFACE_MODE_SGMII:
4060 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
4061 ctrl |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
4062 break;
4063 case PHY_INTERFACE_MODE_RGMII:
4064 case PHY_INTERFACE_MODE_RGMII_ID:
4065 ctrl |= MVNETA_GMAC2_PORT_RGMII;
4066 break;
4067 default:
4068 return -EINVAL;
4069 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004070
4071 /* Cancel Port Reset */
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004072 ctrl &= ~MVNETA_GMAC2_PORT_RESET;
4073 mvreg_write(pp, MVNETA_GMAC_CTRL_2, ctrl);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004074
4075 while ((mvreg_read(pp, MVNETA_GMAC_CTRL_2) &
4076 MVNETA_GMAC2_PORT_RESET) != 0)
4077 continue;
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004078
4079 return 0;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004080}
4081
4082/* Device initialization routine */
Greg KH03ce7582012-12-21 13:42:15 +00004083static int mvneta_probe(struct platform_device *pdev)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004084{
4085 const struct mbus_dram_target_info *dram_target_info;
Thomas Petazzonic3f0dd32014-03-27 11:39:29 +01004086 struct resource *res;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004087 struct device_node *dn = pdev->dev.of_node;
4088 struct device_node *phy_node;
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004089 struct device_node *bm_node;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004090 struct mvneta_port *pp;
4091 struct net_device *dev;
Thomas Petazzoni8cc3e432013-06-04 04:52:23 +00004092 const char *dt_mac_addr;
4093 char hw_mac_addr[ETH_ALEN];
4094 const char *mac_from;
Stas Sergeevf8af8e62015-07-20 17:49:58 -07004095 const char *managed;
Marcin Wojtas9110ee02015-11-30 13:27:45 +01004096 int tx_csum_limit;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004097 int phy_mode;
4098 int err;
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004099 int cpu;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004100
Willy Tarreauee40a112013-04-11 23:00:37 +02004101 dev = alloc_etherdev_mqs(sizeof(struct mvneta_port), txq_number, rxq_number);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004102 if (!dev)
4103 return -ENOMEM;
4104
4105 dev->irq = irq_of_parse_and_map(dn, 0);
4106 if (dev->irq == 0) {
4107 err = -EINVAL;
4108 goto err_free_netdev;
4109 }
4110
4111 phy_node = of_parse_phandle(dn, "phy", 0);
4112 if (!phy_node) {
Thomas Petazzoni83895be2014-05-16 16:14:06 +02004113 if (!of_phy_is_fixed_link(dn)) {
4114 dev_err(&pdev->dev, "no PHY specified\n");
4115 err = -ENODEV;
4116 goto err_free_irq;
4117 }
4118
4119 err = of_phy_register_fixed_link(dn);
4120 if (err < 0) {
4121 dev_err(&pdev->dev, "cannot register fixed PHY\n");
4122 goto err_free_irq;
4123 }
4124
4125 /* In the case of a fixed PHY, the DT node associated
4126 * to the PHY is the Ethernet MAC DT node.
4127 */
Uwe Kleine-Königc891c242014-08-07 21:58:46 +02004128 phy_node = of_node_get(dn);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004129 }
4130
4131 phy_mode = of_get_phy_mode(dn);
4132 if (phy_mode < 0) {
4133 dev_err(&pdev->dev, "incorrect phy-mode\n");
4134 err = -EINVAL;
Uwe Kleine-Königc891c242014-08-07 21:58:46 +02004135 goto err_put_phy_node;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004136 }
4137
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004138 dev->tx_queue_len = MVNETA_MAX_TXD;
4139 dev->watchdog_timeo = 5 * HZ;
4140 dev->netdev_ops = &mvneta_netdev_ops;
4141
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004142 dev->ethtool_ops = &mvneta_eth_tool_ops;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004143
4144 pp = netdev_priv(dev);
Gregory CLEMENT1c2722a2016-03-12 18:44:17 +01004145 spin_lock_init(&pp->lock);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004146 pp->phy_node = phy_node;
4147 pp->phy_interface = phy_mode;
Stas Sergeevf8af8e62015-07-20 17:49:58 -07004148
4149 err = of_property_read_string(dn, "managed", &managed);
4150 pp->use_inband_status = (err == 0 &&
4151 strcmp(managed, "in-band-status") == 0);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004152
Gregory CLEMENT90b74c02015-12-09 18:23:48 +01004153 pp->rxq_def = rxq_def;
4154
Marcin Wojtas8d5047c2016-12-01 18:03:07 +01004155 /* Set RX packet offset correction for platforms, whose
4156 * NET_SKB_PAD, exceeds 64B. It should be 64B for 64-bit
4157 * platforms and 0B for 32-bit ones.
4158 */
4159 pp->rx_offset_correction =
4160 max(0, NET_SKB_PAD - MVNETA_RX_PKT_OFFSET_CORRECTION);
4161
Gregory CLEMENT9a401de2015-12-09 18:23:50 +01004162 pp->indir[0] = rxq_def;
4163
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004164 /* Get special SoC configurations */
4165 if (of_device_is_compatible(dn, "marvell,armada-3700-neta"))
4166 pp->neta_armada3700 = true;
4167
Jisheng Zhang2804ba42016-01-20 19:27:23 +08004168 pp->clk = devm_clk_get(&pdev->dev, "core");
4169 if (IS_ERR(pp->clk))
4170 pp->clk = devm_clk_get(&pdev->dev, NULL);
Thomas Petazzoni189dd622012-11-19 14:15:25 +01004171 if (IS_ERR(pp->clk)) {
4172 err = PTR_ERR(pp->clk);
Uwe Kleine-Königc891c242014-08-07 21:58:46 +02004173 goto err_put_phy_node;
Thomas Petazzoni189dd622012-11-19 14:15:25 +01004174 }
4175
4176 clk_prepare_enable(pp->clk);
4177
Jisheng Zhang15cc4a42016-01-20 19:27:24 +08004178 pp->clk_bus = devm_clk_get(&pdev->dev, "bus");
4179 if (!IS_ERR(pp->clk_bus))
4180 clk_prepare_enable(pp->clk_bus);
4181
Thomas Petazzonic3f0dd32014-03-27 11:39:29 +01004182 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4183 pp->base = devm_ioremap_resource(&pdev->dev, res);
4184 if (IS_ERR(pp->base)) {
4185 err = PTR_ERR(pp->base);
Arnaud Patard \(Rtp\)5445eaf2013-07-29 21:56:48 +02004186 goto err_clk;
4187 }
4188
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004189 /* Alloc per-cpu port structure */
4190 pp->ports = alloc_percpu(struct mvneta_pcpu_port);
4191 if (!pp->ports) {
4192 err = -ENOMEM;
4193 goto err_clk;
4194 }
4195
willy tarreau74c41b02014-01-16 08:20:08 +01004196 /* Alloc per-cpu stats */
WANG Cong1c213bd2014-02-13 11:46:28 -08004197 pp->stats = netdev_alloc_pcpu_stats(struct mvneta_pcpu_stats);
willy tarreau74c41b02014-01-16 08:20:08 +01004198 if (!pp->stats) {
4199 err = -ENOMEM;
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004200 goto err_free_ports;
willy tarreau74c41b02014-01-16 08:20:08 +01004201 }
4202
Thomas Petazzoni8cc3e432013-06-04 04:52:23 +00004203 dt_mac_addr = of_get_mac_address(dn);
Luka Perkov6c7a9a32013-10-30 00:10:01 +01004204 if (dt_mac_addr) {
Thomas Petazzoni8cc3e432013-06-04 04:52:23 +00004205 mac_from = "device tree";
4206 memcpy(dev->dev_addr, dt_mac_addr, ETH_ALEN);
4207 } else {
4208 mvneta_get_mac_addr(pp, hw_mac_addr);
4209 if (is_valid_ether_addr(hw_mac_addr)) {
4210 mac_from = "hardware";
4211 memcpy(dev->dev_addr, hw_mac_addr, ETH_ALEN);
4212 } else {
4213 mac_from = "random";
4214 eth_hw_addr_random(dev);
4215 }
4216 }
4217
Marcin Wojtas9110ee02015-11-30 13:27:45 +01004218 if (!of_property_read_u32(dn, "tx-csum-limit", &tx_csum_limit)) {
4219 if (tx_csum_limit < 0 ||
4220 tx_csum_limit > MVNETA_TX_CSUM_MAX_SIZE) {
4221 tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE;
4222 dev_info(&pdev->dev,
4223 "Wrong TX csum limit in DT, set to %dB\n",
4224 MVNETA_TX_CSUM_DEF_SIZE);
4225 }
4226 } else if (of_device_is_compatible(dn, "marvell,armada-370-neta")) {
4227 tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE;
4228 } else {
4229 tx_csum_limit = MVNETA_TX_CSUM_MAX_SIZE;
4230 }
4231
4232 pp->tx_csum_limit = tx_csum_limit;
Simon Guinotb65657f2015-06-30 16:20:22 +02004233
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004234 dram_target_info = mv_mbus_dram_info();
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004235 /* Armada3700 requires setting default configuration of Mbus
4236 * windows, however without using filled mbus_dram_target_info
4237 * structure.
4238 */
4239 if (dram_target_info || pp->neta_armada3700)
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004240 mvneta_conf_mbus_windows(pp, dram_target_info);
4241
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004242 pp->tx_ring_size = MVNETA_MAX_TXD;
4243 pp->rx_ring_size = MVNETA_MAX_RXD;
4244
4245 pp->dev = dev;
4246 SET_NETDEV_DEV(dev, &pdev->dev);
4247
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004248 pp->id = global_port_id++;
4249
4250 /* Obtain access to BM resources if enabled and already initialized */
4251 bm_node = of_parse_phandle(dn, "buffer-manager", 0);
4252 if (bm_node && bm_node->data) {
4253 pp->bm_priv = bm_node->data;
4254 err = mvneta_bm_port_init(pdev, pp);
4255 if (err < 0) {
4256 dev_info(&pdev->dev, "use SW buffer management\n");
4257 pp->bm_priv = NULL;
4258 }
4259 }
Peter Chend4e4da02016-08-01 15:02:36 +08004260 of_node_put(bm_node);
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004261
Ezequiel Garcia96728502014-05-22 20:06:59 -03004262 err = mvneta_init(&pdev->dev, pp);
4263 if (err < 0)
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004264 goto err_netdev;
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004265
4266 err = mvneta_port_power_up(pp, phy_mode);
4267 if (err < 0) {
4268 dev_err(&pdev->dev, "can't power up port\n");
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004269 goto err_netdev;
Thomas Petazzoni3f1dd4b2014-04-15 15:50:20 +02004270 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004271
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004272 /* Armada3700 network controller does not support per-cpu
4273 * operation, so only single NAPI should be initialized.
4274 */
4275 if (pp->neta_armada3700) {
4276 netif_napi_add(dev, &pp->napi, mvneta_poll, NAPI_POLL_WEIGHT);
4277 } else {
4278 for_each_present_cpu(cpu) {
4279 struct mvneta_pcpu_port *port =
4280 per_cpu_ptr(pp->ports, cpu);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004281
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004282 netif_napi_add(dev, &port->napi, mvneta_poll,
4283 NAPI_POLL_WEIGHT);
4284 port->pp = pp;
4285 }
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004286 }
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004287
Ezequiel Garcia2adb719d2014-05-19 13:59:55 -03004288 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
Ezequiel Garcia01ef26c2014-05-19 13:59:53 -03004289 dev->hw_features |= dev->features;
4290 dev->vlan_features |= dev->features;
Andrew Lunn97db8af2016-11-24 00:08:13 +01004291 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
Ezequiel Garcia8eef5f92014-05-30 13:40:05 -03004292 dev->gso_max_segs = MVNETA_MAX_TSO_SEGS;
willy tarreaub50b72d2013-04-06 08:47:01 +00004293
Jarod Wilson57779872016-10-17 15:54:06 -04004294 /* MTU range: 68 - 9676 */
4295 dev->min_mtu = ETH_MIN_MTU;
4296 /* 9676 == 9700 - 20 and rounding to 8 */
4297 dev->max_mtu = 9676;
4298
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004299 err = register_netdev(dev);
4300 if (err < 0) {
4301 dev_err(&pdev->dev, "failed to register\n");
Ezequiel Garcia96728502014-05-22 20:06:59 -03004302 goto err_free_stats;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004303 }
4304
Thomas Petazzoni8cc3e432013-06-04 04:52:23 +00004305 netdev_info(dev, "Using %s mac address %pM\n", mac_from,
4306 dev->dev_addr);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004307
4308 platform_set_drvdata(pdev, pp->dev);
4309
Stas Sergeev898b29702015-04-01 20:32:49 +03004310 if (pp->use_inband_status) {
4311 struct phy_device *phy = of_phy_find_device(dn);
4312
4313 mvneta_fixed_link_update(pp, phy);
Russell King04d53b22015-09-24 20:36:18 +01004314
Andrew Lunne5a03bf2016-01-06 20:11:16 +01004315 put_device(&phy->mdio.dev);
Stas Sergeev898b29702015-04-01 20:32:49 +03004316 }
4317
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004318 return 0;
4319
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004320err_netdev:
4321 unregister_netdev(dev);
4322 if (pp->bm_priv) {
4323 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
4324 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short,
4325 1 << pp->id);
4326 }
willy tarreau74c41b02014-01-16 08:20:08 +01004327err_free_stats:
4328 free_percpu(pp->stats);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004329err_free_ports:
4330 free_percpu(pp->ports);
Arnaud Patard \(Rtp\)5445eaf2013-07-29 21:56:48 +02004331err_clk:
Jisheng Zhang15cc4a42016-01-20 19:27:24 +08004332 clk_disable_unprepare(pp->clk_bus);
Arnaud Patard \(Rtp\)5445eaf2013-07-29 21:56:48 +02004333 clk_disable_unprepare(pp->clk);
Uwe Kleine-Königc891c242014-08-07 21:58:46 +02004334err_put_phy_node:
4335 of_node_put(phy_node);
Johan Hovold5a57a302016-11-28 19:25:04 +01004336 if (of_phy_is_fixed_link(dn))
4337 of_phy_deregister_fixed_link(dn);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004338err_free_irq:
4339 irq_dispose_mapping(dev->irq);
4340err_free_netdev:
4341 free_netdev(dev);
4342 return err;
4343}
4344
4345/* Device removal routine */
Greg KH03ce7582012-12-21 13:42:15 +00004346static int mvneta_remove(struct platform_device *pdev)
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004347{
4348 struct net_device *dev = platform_get_drvdata(pdev);
Johan Hovold5a57a302016-11-28 19:25:04 +01004349 struct device_node *dn = pdev->dev.of_node;
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004350 struct mvneta_port *pp = netdev_priv(dev);
4351
4352 unregister_netdev(dev);
Jisheng Zhang15cc4a42016-01-20 19:27:24 +08004353 clk_disable_unprepare(pp->clk_bus);
Thomas Petazzoni189dd622012-11-19 14:15:25 +01004354 clk_disable_unprepare(pp->clk);
Maxime Ripard12bb03b2015-09-25 18:09:36 +02004355 free_percpu(pp->ports);
willy tarreau74c41b02014-01-16 08:20:08 +01004356 free_percpu(pp->stats);
Johan Hovold5a57a302016-11-28 19:25:04 +01004357 if (of_phy_is_fixed_link(dn))
4358 of_phy_deregister_fixed_link(dn);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004359 irq_dispose_mapping(dev->irq);
Uwe Kleine-Königc891c242014-08-07 21:58:46 +02004360 of_node_put(pp->phy_node);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004361 free_netdev(dev);
4362
Marcin Wojtasdc35a102016-03-14 09:39:03 +01004363 if (pp->bm_priv) {
4364 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
4365 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short,
4366 1 << pp->id);
4367 }
4368
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004369 return 0;
4370}
4371
4372static const struct of_device_id mvneta_match[] = {
4373 { .compatible = "marvell,armada-370-neta" },
Simon Guinotf522a972015-06-30 16:20:20 +02004374 { .compatible = "marvell,armada-xp-neta" },
Marcin Wojtas2636ac32016-12-01 18:03:09 +01004375 { .compatible = "marvell,armada-3700-neta" },
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004376 { }
4377};
4378MODULE_DEVICE_TABLE(of, mvneta_match);
4379
4380static struct platform_driver mvneta_driver = {
4381 .probe = mvneta_probe,
Greg KH03ce7582012-12-21 13:42:15 +00004382 .remove = mvneta_remove,
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004383 .driver = {
4384 .name = MVNETA_DRIVER_NAME,
4385 .of_match_table = mvneta_match,
4386 },
4387};
4388
Sebastian Andrzej Siewior84a3f4d2016-08-18 14:57:23 +02004389static int __init mvneta_driver_init(void)
4390{
4391 int ret;
4392
4393 ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "net/mvmeta:online",
4394 mvneta_cpu_online,
4395 mvneta_cpu_down_prepare);
4396 if (ret < 0)
4397 goto out;
4398 online_hpstate = ret;
4399 ret = cpuhp_setup_state_multi(CPUHP_NET_MVNETA_DEAD, "net/mvneta:dead",
4400 NULL, mvneta_cpu_dead);
4401 if (ret)
4402 goto err_dead;
4403
4404 ret = platform_driver_register(&mvneta_driver);
4405 if (ret)
4406 goto err;
4407 return 0;
4408
4409err:
4410 cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD);
4411err_dead:
4412 cpuhp_remove_multi_state(online_hpstate);
4413out:
4414 return ret;
4415}
4416module_init(mvneta_driver_init);
4417
4418static void __exit mvneta_driver_exit(void)
4419{
4420 platform_driver_unregister(&mvneta_driver);
4421 cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD);
4422 cpuhp_remove_multi_state(online_hpstate);
4423}
4424module_exit(mvneta_driver_exit);
Thomas Petazzonic5aff182012-08-17 14:04:28 +03004425
4426MODULE_DESCRIPTION("Marvell NETA Ethernet Driver - www.marvell.com");
4427MODULE_AUTHOR("Rami Rosen <rosenr@marvell.com>, Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
4428MODULE_LICENSE("GPL");
4429
4430module_param(rxq_number, int, S_IRUGO);
4431module_param(txq_number, int, S_IRUGO);
4432
4433module_param(rxq_def, int, S_IRUGO);
willy tarreauf19fadf2014-01-16 08:20:17 +01004434module_param(rx_copybreak, int, S_IRUGO | S_IWUSR);