Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1 | /* |
| 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 Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 14 | #include <linux/clk.h> |
| 15 | #include <linux/cpu.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 16 | #include <linux/etherdevice.h> |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 17 | #include <linux/if_vlan.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 18 | #include <linux/inetdevice.h> |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/kernel.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 22 | #include <linux/mbus.h> |
| 23 | #include <linux/module.h> |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 24 | #include <linux/netdevice.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 25 | #include <linux/of.h> |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 26 | #include <linux/of_address.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 27 | #include <linux/of_irq.h> |
| 28 | #include <linux/of_mdio.h> |
| 29 | #include <linux/of_net.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 30 | #include <linux/phy.h> |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 31 | #include <linux/phylink.h> |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/skbuff.h> |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 34 | #include <net/hwbm.h> |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 35 | #include "mvneta_bm.h" |
Jisheng Zhang | 0e03f56 | 2016-01-20 19:27:22 +0800 | [diff] [blame] | 36 | #include <net/ip.h> |
| 37 | #include <net/ipv6.h> |
| 38 | #include <net/tso.h> |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 39 | |
| 40 | /* Registers */ |
| 41 | #define MVNETA_RXQ_CONFIG_REG(q) (0x1400 + ((q) << 2)) |
Marcin Wojtas | e5bdf68 | 2015-11-30 13:27:42 +0100 | [diff] [blame] | 42 | #define MVNETA_RXQ_HW_BUF_ALLOC BIT(0) |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 43 | #define MVNETA_RXQ_SHORT_POOL_ID_SHIFT 4 |
| 44 | #define MVNETA_RXQ_SHORT_POOL_ID_MASK 0x30 |
| 45 | #define MVNETA_RXQ_LONG_POOL_ID_SHIFT 6 |
| 46 | #define MVNETA_RXQ_LONG_POOL_ID_MASK 0xc0 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 47 | #define MVNETA_RXQ_PKT_OFFSET_ALL_MASK (0xf << 8) |
| 48 | #define MVNETA_RXQ_PKT_OFFSET_MASK(offs) ((offs) << 8) |
| 49 | #define MVNETA_RXQ_THRESHOLD_REG(q) (0x14c0 + ((q) << 2)) |
| 50 | #define MVNETA_RXQ_NON_OCCUPIED(v) ((v) << 16) |
| 51 | #define MVNETA_RXQ_BASE_ADDR_REG(q) (0x1480 + ((q) << 2)) |
| 52 | #define MVNETA_RXQ_SIZE_REG(q) (0x14a0 + ((q) << 2)) |
| 53 | #define MVNETA_RXQ_BUF_SIZE_SHIFT 19 |
| 54 | #define MVNETA_RXQ_BUF_SIZE_MASK (0x1fff << 19) |
| 55 | #define MVNETA_RXQ_STATUS_REG(q) (0x14e0 + ((q) << 2)) |
| 56 | #define MVNETA_RXQ_OCCUPIED_ALL_MASK 0x3fff |
| 57 | #define MVNETA_RXQ_STATUS_UPDATE_REG(q) (0x1500 + ((q) << 2)) |
| 58 | #define MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT 16 |
| 59 | #define MVNETA_RXQ_ADD_NON_OCCUPIED_MAX 255 |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 60 | #define MVNETA_PORT_POOL_BUFFER_SZ_REG(pool) (0x1700 + ((pool) << 2)) |
| 61 | #define MVNETA_PORT_POOL_BUFFER_SZ_SHIFT 3 |
| 62 | #define MVNETA_PORT_POOL_BUFFER_SZ_MASK 0xfff8 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 63 | #define MVNETA_PORT_RX_RESET 0x1cc0 |
| 64 | #define MVNETA_PORT_RX_DMA_RESET BIT(0) |
| 65 | #define MVNETA_PHY_ADDR 0x2000 |
| 66 | #define MVNETA_PHY_ADDR_MASK 0x1f |
| 67 | #define MVNETA_MBUS_RETRY 0x2010 |
| 68 | #define MVNETA_UNIT_INTR_CAUSE 0x2080 |
| 69 | #define MVNETA_UNIT_CONTROL 0x20B0 |
| 70 | #define MVNETA_PHY_POLLING_ENABLE BIT(1) |
| 71 | #define MVNETA_WIN_BASE(w) (0x2200 + ((w) << 3)) |
| 72 | #define MVNETA_WIN_SIZE(w) (0x2204 + ((w) << 3)) |
| 73 | #define MVNETA_WIN_REMAP(w) (0x2280 + ((w) << 2)) |
| 74 | #define MVNETA_BASE_ADDR_ENABLE 0x2290 |
Marcin Wojtas | db6ba9a | 2015-11-30 13:27:41 +0100 | [diff] [blame] | 75 | #define MVNETA_ACCESS_PROTECT_ENABLE 0x2294 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 76 | #define MVNETA_PORT_CONFIG 0x2400 |
| 77 | #define MVNETA_UNI_PROMISC_MODE BIT(0) |
| 78 | #define MVNETA_DEF_RXQ(q) ((q) << 1) |
| 79 | #define MVNETA_DEF_RXQ_ARP(q) ((q) << 4) |
| 80 | #define MVNETA_TX_UNSET_ERR_SUM BIT(12) |
| 81 | #define MVNETA_DEF_RXQ_TCP(q) ((q) << 16) |
| 82 | #define MVNETA_DEF_RXQ_UDP(q) ((q) << 19) |
| 83 | #define MVNETA_DEF_RXQ_BPDU(q) ((q) << 22) |
| 84 | #define MVNETA_RX_CSUM_WITH_PSEUDO_HDR BIT(25) |
| 85 | #define MVNETA_PORT_CONFIG_DEFL_VALUE(q) (MVNETA_DEF_RXQ(q) | \ |
| 86 | MVNETA_DEF_RXQ_ARP(q) | \ |
| 87 | MVNETA_DEF_RXQ_TCP(q) | \ |
| 88 | MVNETA_DEF_RXQ_UDP(q) | \ |
| 89 | MVNETA_DEF_RXQ_BPDU(q) | \ |
| 90 | MVNETA_TX_UNSET_ERR_SUM | \ |
| 91 | MVNETA_RX_CSUM_WITH_PSEUDO_HDR) |
| 92 | #define MVNETA_PORT_CONFIG_EXTEND 0x2404 |
| 93 | #define MVNETA_MAC_ADDR_LOW 0x2414 |
| 94 | #define MVNETA_MAC_ADDR_HIGH 0x2418 |
| 95 | #define MVNETA_SDMA_CONFIG 0x241c |
| 96 | #define MVNETA_SDMA_BRST_SIZE_16 4 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 97 | #define MVNETA_RX_BRST_SZ_MASK(burst) ((burst) << 1) |
| 98 | #define MVNETA_RX_NO_DATA_SWAP BIT(4) |
| 99 | #define MVNETA_TX_NO_DATA_SWAP BIT(5) |
Thomas Petazzoni | 9ad8fef | 2013-07-29 15:21:28 +0200 | [diff] [blame] | 100 | #define MVNETA_DESC_SWAP BIT(6) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 101 | #define MVNETA_TX_BRST_SZ_MASK(burst) ((burst) << 22) |
| 102 | #define MVNETA_PORT_STATUS 0x2444 |
| 103 | #define MVNETA_TX_IN_PRGRS BIT(1) |
| 104 | #define MVNETA_TX_FIFO_EMPTY BIT(8) |
| 105 | #define MVNETA_RX_MIN_FRAME_SIZE 0x247c |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 106 | #define MVNETA_SERDES_CFG 0x24A0 |
Arnaud Patard \(Rtp\) | 5445eaf | 2013-07-29 21:56:48 +0200 | [diff] [blame] | 107 | #define MVNETA_SGMII_SERDES_PROTO 0x0cc7 |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 108 | #define MVNETA_QSGMII_SERDES_PROTO 0x0667 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 109 | #define MVNETA_TYPE_PRIO 0x24bc |
| 110 | #define MVNETA_FORCE_UNI BIT(21) |
| 111 | #define MVNETA_TXQ_CMD_1 0x24e4 |
| 112 | #define MVNETA_TXQ_CMD 0x2448 |
| 113 | #define MVNETA_TXQ_DISABLE_SHIFT 8 |
| 114 | #define MVNETA_TXQ_ENABLE_MASK 0x000000ff |
Andrew Lunn | e483911 | 2015-10-22 18:37:36 +0100 | [diff] [blame] | 115 | #define MVNETA_RX_DISCARD_FRAME_COUNT 0x2484 |
| 116 | #define MVNETA_OVERRUN_FRAME_COUNT 0x2488 |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 117 | #define MVNETA_GMAC_CLOCK_DIVIDER 0x24f4 |
| 118 | #define MVNETA_GMAC_1MS_CLOCK_ENABLE BIT(31) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 119 | #define MVNETA_ACC_MODE 0x2500 |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 120 | #define MVNETA_BM_ADDRESS 0x2504 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 121 | #define MVNETA_CPU_MAP(cpu) (0x2540 + ((cpu) << 2)) |
| 122 | #define MVNETA_CPU_RXQ_ACCESS_ALL_MASK 0x000000ff |
| 123 | #define MVNETA_CPU_TXQ_ACCESS_ALL_MASK 0x0000ff00 |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 124 | #define MVNETA_CPU_RXQ_ACCESS(rxq) BIT(rxq) |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 125 | #define MVNETA_CPU_TXQ_ACCESS(txq) BIT(txq + 8) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 126 | #define MVNETA_RXQ_TIME_COAL_REG(q) (0x2580 + ((q) << 2)) |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 127 | |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 128 | /* Exception Interrupt Port/Queue Cause register |
| 129 | * |
| 130 | * Their behavior depend of the mapping done using the PCPX2Q |
| 131 | * registers. For a given CPU if the bit associated to a queue is not |
| 132 | * set, then for the register a read from this CPU will always return |
| 133 | * 0 and a write won't do anything |
| 134 | */ |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 135 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 136 | #define MVNETA_INTR_NEW_CAUSE 0x25a0 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 137 | #define MVNETA_INTR_NEW_MASK 0x25a4 |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 138 | |
| 139 | /* bits 0..7 = TXQ SENT, one bit per queue. |
| 140 | * bits 8..15 = RXQ OCCUP, one bit per queue. |
| 141 | * bits 16..23 = RXQ FREE, one bit per queue. |
| 142 | * bit 29 = OLD_REG_SUM, see old reg ? |
| 143 | * bit 30 = TX_ERR_SUM, one bit for 4 ports |
| 144 | * bit 31 = MISC_SUM, one bit for 4 ports |
| 145 | */ |
| 146 | #define MVNETA_TX_INTR_MASK(nr_txqs) (((1 << nr_txqs) - 1) << 0) |
| 147 | #define MVNETA_TX_INTR_MASK_ALL (0xff << 0) |
| 148 | #define MVNETA_RX_INTR_MASK(nr_rxqs) (((1 << nr_rxqs) - 1) << 8) |
| 149 | #define MVNETA_RX_INTR_MASK_ALL (0xff << 8) |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 150 | #define MVNETA_MISCINTR_INTR_MASK BIT(31) |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 151 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 152 | #define MVNETA_INTR_OLD_CAUSE 0x25a8 |
| 153 | #define MVNETA_INTR_OLD_MASK 0x25ac |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 154 | |
| 155 | /* Data Path Port/Queue Cause Register */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 156 | #define MVNETA_INTR_MISC_CAUSE 0x25b0 |
| 157 | #define MVNETA_INTR_MISC_MASK 0x25b4 |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 158 | |
| 159 | #define MVNETA_CAUSE_PHY_STATUS_CHANGE BIT(0) |
| 160 | #define MVNETA_CAUSE_LINK_CHANGE BIT(1) |
| 161 | #define MVNETA_CAUSE_PTP BIT(4) |
| 162 | |
| 163 | #define MVNETA_CAUSE_INTERNAL_ADDR_ERR BIT(7) |
| 164 | #define MVNETA_CAUSE_RX_OVERRUN BIT(8) |
| 165 | #define MVNETA_CAUSE_RX_CRC_ERROR BIT(9) |
| 166 | #define MVNETA_CAUSE_RX_LARGE_PKT BIT(10) |
| 167 | #define MVNETA_CAUSE_TX_UNDERUN BIT(11) |
| 168 | #define MVNETA_CAUSE_PRBS_ERR BIT(12) |
| 169 | #define MVNETA_CAUSE_PSC_SYNC_CHANGE BIT(13) |
| 170 | #define MVNETA_CAUSE_SERDES_SYNC_ERR BIT(14) |
| 171 | |
| 172 | #define MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT 16 |
| 173 | #define MVNETA_CAUSE_BMU_ALLOC_ERR_ALL_MASK (0xF << MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT) |
| 174 | #define MVNETA_CAUSE_BMU_ALLOC_ERR_MASK(pool) (1 << (MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT + (pool))) |
| 175 | |
| 176 | #define MVNETA_CAUSE_TXQ_ERROR_SHIFT 24 |
| 177 | #define MVNETA_CAUSE_TXQ_ERROR_ALL_MASK (0xFF << MVNETA_CAUSE_TXQ_ERROR_SHIFT) |
| 178 | #define MVNETA_CAUSE_TXQ_ERROR_MASK(q) (1 << (MVNETA_CAUSE_TXQ_ERROR_SHIFT + (q))) |
| 179 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 180 | #define MVNETA_INTR_ENABLE 0x25b8 |
| 181 | #define MVNETA_TXQ_INTR_ENABLE_ALL_MASK 0x0000ff00 |
Marcin Wojtas | dc1aadf | 2015-11-30 13:27:43 +0100 | [diff] [blame] | 182 | #define MVNETA_RXQ_INTR_ENABLE_ALL_MASK 0x000000ff |
willy tarreau | 40ba35e | 2014-01-16 08:20:10 +0100 | [diff] [blame] | 183 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 184 | #define MVNETA_RXQ_CMD 0x2680 |
| 185 | #define MVNETA_RXQ_DISABLE_SHIFT 8 |
| 186 | #define MVNETA_RXQ_ENABLE_MASK 0x000000ff |
| 187 | #define MVETH_TXQ_TOKEN_COUNT_REG(q) (0x2700 + ((q) << 4)) |
| 188 | #define MVETH_TXQ_TOKEN_CFG_REG(q) (0x2704 + ((q) << 4)) |
| 189 | #define MVNETA_GMAC_CTRL_0 0x2c00 |
| 190 | #define MVNETA_GMAC_MAX_RX_SIZE_SHIFT 2 |
| 191 | #define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 192 | #define MVNETA_GMAC0_PORT_1000BASE_X BIT(1) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 193 | #define MVNETA_GMAC0_PORT_ENABLE BIT(0) |
| 194 | #define MVNETA_GMAC_CTRL_2 0x2c08 |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 195 | #define MVNETA_GMAC2_INBAND_AN_ENABLE BIT(0) |
Thomas Petazzoni | a79121d | 2014-03-26 00:25:41 +0100 | [diff] [blame] | 196 | #define MVNETA_GMAC2_PCS_ENABLE BIT(3) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 197 | #define MVNETA_GMAC2_PORT_RGMII BIT(4) |
| 198 | #define MVNETA_GMAC2_PORT_RESET BIT(6) |
| 199 | #define MVNETA_GMAC_STATUS 0x2c10 |
| 200 | #define MVNETA_GMAC_LINK_UP BIT(0) |
| 201 | #define MVNETA_GMAC_SPEED_1000 BIT(1) |
| 202 | #define MVNETA_GMAC_SPEED_100 BIT(2) |
| 203 | #define MVNETA_GMAC_FULL_DUPLEX BIT(3) |
| 204 | #define MVNETA_GMAC_RX_FLOW_CTRL_ENABLE BIT(4) |
| 205 | #define MVNETA_GMAC_TX_FLOW_CTRL_ENABLE BIT(5) |
| 206 | #define MVNETA_GMAC_RX_FLOW_CTRL_ACTIVE BIT(6) |
| 207 | #define MVNETA_GMAC_TX_FLOW_CTRL_ACTIVE BIT(7) |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 208 | #define MVNETA_GMAC_AN_COMPLETE BIT(11) |
| 209 | #define MVNETA_GMAC_SYNC_OK BIT(14) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 210 | #define MVNETA_GMAC_AUTONEG_CONFIG 0x2c0c |
| 211 | #define MVNETA_GMAC_FORCE_LINK_DOWN BIT(0) |
| 212 | #define MVNETA_GMAC_FORCE_LINK_PASS BIT(1) |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 213 | #define MVNETA_GMAC_INBAND_AN_ENABLE BIT(2) |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 214 | #define MVNETA_GMAC_AN_BYPASS_ENABLE BIT(3) |
| 215 | #define MVNETA_GMAC_INBAND_RESTART_AN BIT(4) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 216 | #define MVNETA_GMAC_CONFIG_MII_SPEED BIT(5) |
| 217 | #define MVNETA_GMAC_CONFIG_GMII_SPEED BIT(6) |
Thomas Petazzoni | 7140860 | 2013-09-04 16:21:18 +0200 | [diff] [blame] | 218 | #define MVNETA_GMAC_AN_SPEED_EN BIT(7) |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 219 | #define MVNETA_GMAC_CONFIG_FLOW_CTRL BIT(8) |
| 220 | #define MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL BIT(9) |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 221 | #define MVNETA_GMAC_AN_FLOW_CTRL_EN BIT(11) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 222 | #define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12) |
Thomas Petazzoni | 7140860 | 2013-09-04 16:21:18 +0200 | [diff] [blame] | 223 | #define MVNETA_GMAC_AN_DUPLEX_EN BIT(13) |
Andrew Lunn | e483911 | 2015-10-22 18:37:36 +0100 | [diff] [blame] | 224 | #define MVNETA_MIB_COUNTERS_BASE 0x3000 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 225 | #define MVNETA_MIB_LATE_COLLISION 0x7c |
| 226 | #define MVNETA_DA_FILT_SPEC_MCAST 0x3400 |
| 227 | #define MVNETA_DA_FILT_OTH_MCAST 0x3500 |
| 228 | #define MVNETA_DA_FILT_UCAST_BASE 0x3600 |
| 229 | #define MVNETA_TXQ_BASE_ADDR_REG(q) (0x3c00 + ((q) << 2)) |
| 230 | #define MVNETA_TXQ_SIZE_REG(q) (0x3c20 + ((q) << 2)) |
| 231 | #define MVNETA_TXQ_SENT_THRESH_ALL_MASK 0x3fff0000 |
| 232 | #define MVNETA_TXQ_SENT_THRESH_MASK(coal) ((coal) << 16) |
| 233 | #define MVNETA_TXQ_UPDATE_REG(q) (0x3c60 + ((q) << 2)) |
| 234 | #define MVNETA_TXQ_DEC_SENT_SHIFT 16 |
Simon Guinot | 2a90f7e | 2017-01-16 18:08:31 +0100 | [diff] [blame] | 235 | #define MVNETA_TXQ_DEC_SENT_MASK 0xff |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 236 | #define MVNETA_TXQ_STATUS_REG(q) (0x3c40 + ((q) << 2)) |
| 237 | #define MVNETA_TXQ_SENT_DESC_SHIFT 16 |
| 238 | #define MVNETA_TXQ_SENT_DESC_MASK 0x3fff0000 |
| 239 | #define MVNETA_PORT_TX_RESET 0x3cf0 |
| 240 | #define MVNETA_PORT_TX_DMA_RESET BIT(0) |
| 241 | #define MVNETA_TX_MTU 0x3e0c |
| 242 | #define MVNETA_TX_TOKEN_SIZE 0x3e14 |
| 243 | #define MVNETA_TX_TOKEN_SIZE_MAX 0xffffffff |
| 244 | #define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2)) |
| 245 | #define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff |
| 246 | |
| 247 | #define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff |
| 248 | |
| 249 | /* Descriptor ring Macros */ |
| 250 | #define MVNETA_QUEUE_NEXT_DESC(q, index) \ |
| 251 | (((index) < (q)->last_desc) ? ((index) + 1) : 0) |
| 252 | |
| 253 | /* Various constants */ |
| 254 | |
| 255 | /* Coalescing */ |
Dmitri Epshtein | 06708f8 | 2016-07-06 04:18:58 +0200 | [diff] [blame] | 256 | #define MVNETA_TXDONE_COAL_PKTS 0 /* interrupt per packet */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 257 | #define MVNETA_RX_COAL_PKTS 32 |
| 258 | #define MVNETA_RX_COAL_USEC 100 |
| 259 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 260 | /* The two bytes Marvell header. Either contains a special value used |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 261 | * by Marvell switches when a specific hardware mode is enabled (not |
| 262 | * supported by this driver) or is filled automatically by zeroes on |
| 263 | * the RX side. Those two bytes being at the front of the Ethernet |
| 264 | * header, they allow to have the IP header aligned on a 4 bytes |
| 265 | * boundary automatically: the hardware skips those two bytes on its |
| 266 | * own. |
| 267 | */ |
| 268 | #define MVNETA_MH_SIZE 2 |
| 269 | |
| 270 | #define MVNETA_VLAN_TAG_LEN 4 |
| 271 | |
Marcin Wojtas | 9110ee0 | 2015-11-30 13:27:45 +0100 | [diff] [blame] | 272 | #define MVNETA_TX_CSUM_DEF_SIZE 1600 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 273 | #define MVNETA_TX_CSUM_MAX_SIZE 9800 |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 274 | #define MVNETA_ACC_MODE_EXT1 1 |
| 275 | #define MVNETA_ACC_MODE_EXT2 2 |
| 276 | |
| 277 | #define MVNETA_MAX_DECODE_WIN 6 |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 278 | |
| 279 | /* Timeout constants */ |
| 280 | #define MVNETA_TX_DISABLE_TIMEOUT_MSEC 1000 |
| 281 | #define MVNETA_RX_DISABLE_TIMEOUT_MSEC 1000 |
| 282 | #define MVNETA_TX_FIFO_EMPTY_TIMEOUT 10000 |
| 283 | |
| 284 | #define MVNETA_TX_MTU_MAX 0x3ffff |
| 285 | |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 286 | /* The RSS lookup table actually has 256 entries but we do not use |
| 287 | * them yet |
| 288 | */ |
| 289 | #define MVNETA_RSS_LU_TABLE_SIZE 1 |
| 290 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 291 | /* Max number of Rx descriptors */ |
| 292 | #define MVNETA_MAX_RXD 128 |
| 293 | |
| 294 | /* Max number of Tx descriptors */ |
| 295 | #define MVNETA_MAX_TXD 532 |
| 296 | |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 297 | /* Max number of allowed TCP segments for software TSO */ |
| 298 | #define MVNETA_MAX_TSO_SEGS 100 |
| 299 | |
| 300 | #define MVNETA_MAX_SKB_DESCS (MVNETA_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS) |
| 301 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 302 | /* descriptor aligned size */ |
| 303 | #define MVNETA_DESC_ALIGNED_SIZE 32 |
| 304 | |
Marcin Wojtas | 8d5047c | 2016-12-01 18:03:07 +0100 | [diff] [blame] | 305 | /* Number of bytes to be taken into account by HW when putting incoming data |
| 306 | * to the buffers. It is needed in case NET_SKB_PAD exceeds maximum packet |
| 307 | * offset supported in MVNETA_RXQ_CONFIG_REG(q) registers. |
| 308 | */ |
| 309 | #define MVNETA_RX_PKT_OFFSET_CORRECTION 64 |
| 310 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 311 | #define MVNETA_RX_PKT_SIZE(mtu) \ |
| 312 | ALIGN((mtu) + MVNETA_MH_SIZE + MVNETA_VLAN_TAG_LEN + \ |
| 313 | ETH_HLEN + ETH_FCS_LEN, \ |
Jisheng Zhang | c66e98c | 2016-04-01 17:12:49 +0800 | [diff] [blame] | 314 | cache_line_size()) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 315 | |
Ezequiel Garcia | 2e3173a | 2014-05-30 13:40:07 -0300 | [diff] [blame] | 316 | #define IS_TSO_HEADER(txq, addr) \ |
| 317 | ((addr >= txq->tso_hdrs_phys) && \ |
| 318 | (addr < txq->tso_hdrs_phys + txq->size * TSO_HEADER_SIZE)) |
| 319 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 320 | #define MVNETA_RX_GET_BM_POOL_ID(rxd) \ |
| 321 | (((rxd)->status & MVNETA_RXD_BM_POOL_MASK) >> MVNETA_RXD_BM_POOL_SHIFT) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 322 | |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 323 | struct mvneta_statistic { |
| 324 | unsigned short offset; |
| 325 | unsigned short type; |
| 326 | const char name[ETH_GSTRING_LEN]; |
| 327 | }; |
| 328 | |
| 329 | #define T_REG_32 32 |
| 330 | #define T_REG_64 64 |
| 331 | |
| 332 | static const struct mvneta_statistic mvneta_statistics[] = { |
| 333 | { 0x3000, T_REG_64, "good_octets_received", }, |
| 334 | { 0x3010, T_REG_32, "good_frames_received", }, |
| 335 | { 0x3008, T_REG_32, "bad_octets_received", }, |
| 336 | { 0x3014, T_REG_32, "bad_frames_received", }, |
| 337 | { 0x3018, T_REG_32, "broadcast_frames_received", }, |
| 338 | { 0x301c, T_REG_32, "multicast_frames_received", }, |
| 339 | { 0x3050, T_REG_32, "unrec_mac_control_received", }, |
| 340 | { 0x3058, T_REG_32, "good_fc_received", }, |
| 341 | { 0x305c, T_REG_32, "bad_fc_received", }, |
| 342 | { 0x3060, T_REG_32, "undersize_received", }, |
| 343 | { 0x3064, T_REG_32, "fragments_received", }, |
| 344 | { 0x3068, T_REG_32, "oversize_received", }, |
| 345 | { 0x306c, T_REG_32, "jabber_received", }, |
| 346 | { 0x3070, T_REG_32, "mac_receive_error", }, |
| 347 | { 0x3074, T_REG_32, "bad_crc_event", }, |
| 348 | { 0x3078, T_REG_32, "collision", }, |
| 349 | { 0x307c, T_REG_32, "late_collision", }, |
| 350 | { 0x2484, T_REG_32, "rx_discard", }, |
| 351 | { 0x2488, T_REG_32, "rx_overrun", }, |
| 352 | { 0x3020, T_REG_32, "frames_64_octets", }, |
| 353 | { 0x3024, T_REG_32, "frames_65_to_127_octets", }, |
| 354 | { 0x3028, T_REG_32, "frames_128_to_255_octets", }, |
| 355 | { 0x302c, T_REG_32, "frames_256_to_511_octets", }, |
| 356 | { 0x3030, T_REG_32, "frames_512_to_1023_octets", }, |
| 357 | { 0x3034, T_REG_32, "frames_1024_to_max_octets", }, |
| 358 | { 0x3038, T_REG_64, "good_octets_sent", }, |
| 359 | { 0x3040, T_REG_32, "good_frames_sent", }, |
| 360 | { 0x3044, T_REG_32, "excessive_collision", }, |
| 361 | { 0x3048, T_REG_32, "multicast_frames_sent", }, |
| 362 | { 0x304c, T_REG_32, "broadcast_frames_sent", }, |
| 363 | { 0x3054, T_REG_32, "fc_sent", }, |
| 364 | { 0x300c, T_REG_32, "internal_mac_transmit_err", }, |
| 365 | }; |
| 366 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 367 | struct mvneta_pcpu_stats { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 368 | struct u64_stats_sync syncp; |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 369 | u64 rx_packets; |
| 370 | u64 rx_bytes; |
| 371 | u64 tx_packets; |
| 372 | u64 tx_bytes; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 373 | }; |
| 374 | |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 375 | struct mvneta_pcpu_port { |
| 376 | /* Pointer to the shared port */ |
| 377 | struct mvneta_port *pp; |
| 378 | |
| 379 | /* Pointer to the CPU-local NAPI struct */ |
| 380 | struct napi_struct napi; |
| 381 | |
| 382 | /* Cause of the previous interrupt */ |
| 383 | u32 cause_rx_tx; |
| 384 | }; |
| 385 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 386 | struct mvneta_port { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 387 | u8 id; |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 388 | struct mvneta_pcpu_port __percpu *ports; |
| 389 | struct mvneta_pcpu_stats __percpu *stats; |
| 390 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 391 | int pkt_size; |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 392 | unsigned int frag_size; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 393 | void __iomem *base; |
| 394 | struct mvneta_rx_queue *rxqs; |
| 395 | struct mvneta_tx_queue *txqs; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 396 | struct net_device *dev; |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 397 | struct hlist_node node_online; |
| 398 | struct hlist_node node_dead; |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 399 | int rxq_def; |
Gregory CLEMENT | 5888511 | 2016-02-04 22:09:28 +0100 | [diff] [blame] | 400 | /* Protect the access to the percpu interrupt registers, |
| 401 | * ensuring that the configuration remains coherent. |
| 402 | */ |
| 403 | spinlock_t lock; |
Gregory CLEMENT | 120cfa5 | 2016-02-04 22:09:29 +0100 | [diff] [blame] | 404 | bool is_stopped; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 405 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 406 | u32 cause_rx_tx; |
| 407 | struct napi_struct napi; |
| 408 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 409 | /* Core clock */ |
Thomas Petazzoni | 189dd62 | 2012-11-19 14:15:25 +0100 | [diff] [blame] | 410 | struct clk *clk; |
Jisheng Zhang | 15cc4a4 | 2016-01-20 19:27:24 +0800 | [diff] [blame] | 411 | /* AXI clock */ |
| 412 | struct clk *clk_bus; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 413 | u8 mcast_count[256]; |
| 414 | u16 tx_ring_size; |
| 415 | u16 rx_ring_size; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 416 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 417 | phy_interface_t phy_interface; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 418 | struct device_node *dn; |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 419 | unsigned int tx_csum_limit; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 420 | struct phylink *phylink; |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 421 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 422 | struct mvneta_bm *bm_priv; |
| 423 | struct mvneta_bm_pool *pool_long; |
| 424 | struct mvneta_bm_pool *pool_short; |
| 425 | int bm_win_id; |
| 426 | |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 427 | u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)]; |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 428 | |
| 429 | u32 indir[MVNETA_RSS_LU_TABLE_SIZE]; |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 430 | |
| 431 | /* Flags for special SoC configurations */ |
| 432 | bool neta_armada3700; |
Marcin Wojtas | 8d5047c | 2016-12-01 18:03:07 +0100 | [diff] [blame] | 433 | u16 rx_offset_correction; |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 434 | const struct mbus_dram_target_info *dram_target_info; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 435 | }; |
| 436 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 437 | /* The mvneta_tx_desc and mvneta_rx_desc structures describe the |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 438 | * layout of the transmit and reception DMA descriptors, and their |
| 439 | * layout is therefore defined by the hardware design |
| 440 | */ |
Thomas Petazzoni | 6083ed4 | 2013-07-29 15:21:27 +0200 | [diff] [blame] | 441 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 442 | #define MVNETA_TX_L3_OFF_SHIFT 0 |
| 443 | #define MVNETA_TX_IP_HLEN_SHIFT 8 |
| 444 | #define MVNETA_TX_L4_UDP BIT(16) |
| 445 | #define MVNETA_TX_L3_IP6 BIT(17) |
| 446 | #define MVNETA_TXD_IP_CSUM BIT(18) |
| 447 | #define MVNETA_TXD_Z_PAD BIT(19) |
| 448 | #define MVNETA_TXD_L_DESC BIT(20) |
| 449 | #define MVNETA_TXD_F_DESC BIT(21) |
| 450 | #define MVNETA_TXD_FLZ_DESC (MVNETA_TXD_Z_PAD | \ |
| 451 | MVNETA_TXD_L_DESC | \ |
| 452 | MVNETA_TXD_F_DESC) |
| 453 | #define MVNETA_TX_L4_CSUM_FULL BIT(30) |
| 454 | #define MVNETA_TX_L4_CSUM_NOT BIT(31) |
| 455 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 456 | #define MVNETA_RXD_ERR_CRC 0x0 |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 457 | #define MVNETA_RXD_BM_POOL_SHIFT 13 |
| 458 | #define MVNETA_RXD_BM_POOL_MASK (BIT(13) | BIT(14)) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 459 | #define MVNETA_RXD_ERR_SUMMARY BIT(16) |
| 460 | #define MVNETA_RXD_ERR_OVERRUN BIT(17) |
| 461 | #define MVNETA_RXD_ERR_LEN BIT(18) |
| 462 | #define MVNETA_RXD_ERR_RESOURCE (BIT(17) | BIT(18)) |
| 463 | #define MVNETA_RXD_ERR_CODE_MASK (BIT(17) | BIT(18)) |
| 464 | #define MVNETA_RXD_L3_IP4 BIT(25) |
| 465 | #define MVNETA_RXD_FIRST_LAST_DESC (BIT(26) | BIT(27)) |
| 466 | #define MVNETA_RXD_L4_CSUM_OK BIT(30) |
| 467 | |
Thomas Petazzoni | 9ad8fef | 2013-07-29 15:21:28 +0200 | [diff] [blame] | 468 | #if defined(__LITTLE_ENDIAN) |
Thomas Petazzoni | 6083ed4 | 2013-07-29 15:21:27 +0200 | [diff] [blame] | 469 | struct mvneta_tx_desc { |
| 470 | u32 command; /* Options used by HW for packet transmitting.*/ |
| 471 | u16 reserverd1; /* csum_l4 (for future use) */ |
| 472 | u16 data_size; /* Data size of transmitted packet in bytes */ |
| 473 | u32 buf_phys_addr; /* Physical addr of transmitted buffer */ |
| 474 | u32 reserved2; /* hw_cmd - (for future use, PMT) */ |
| 475 | u32 reserved3[4]; /* Reserved - (for future use) */ |
| 476 | }; |
| 477 | |
| 478 | struct mvneta_rx_desc { |
| 479 | u32 status; /* Info about received packet */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 480 | u16 reserved1; /* pnc_info - (for future use, PnC) */ |
| 481 | u16 data_size; /* Size of received packet in bytes */ |
Thomas Petazzoni | 6083ed4 | 2013-07-29 15:21:27 +0200 | [diff] [blame] | 482 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 483 | u32 buf_phys_addr; /* Physical address of the buffer */ |
| 484 | u32 reserved2; /* pnc_flow_id (for future use, PnC) */ |
Thomas Petazzoni | 6083ed4 | 2013-07-29 15:21:27 +0200 | [diff] [blame] | 485 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 486 | u32 buf_cookie; /* cookie for access to RX buffer in rx path */ |
| 487 | u16 reserved3; /* prefetch_cmd, for future use */ |
| 488 | u16 reserved4; /* csum_l4 - (for future use, PnC) */ |
Thomas Petazzoni | 6083ed4 | 2013-07-29 15:21:27 +0200 | [diff] [blame] | 489 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 490 | u32 reserved5; /* pnc_extra PnC (for future use, PnC) */ |
| 491 | u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */ |
| 492 | }; |
Thomas Petazzoni | 9ad8fef | 2013-07-29 15:21:28 +0200 | [diff] [blame] | 493 | #else |
| 494 | struct mvneta_tx_desc { |
| 495 | u16 data_size; /* Data size of transmitted packet in bytes */ |
| 496 | u16 reserverd1; /* csum_l4 (for future use) */ |
| 497 | u32 command; /* Options used by HW for packet transmitting.*/ |
| 498 | u32 reserved2; /* hw_cmd - (for future use, PMT) */ |
| 499 | u32 buf_phys_addr; /* Physical addr of transmitted buffer */ |
| 500 | u32 reserved3[4]; /* Reserved - (for future use) */ |
| 501 | }; |
| 502 | |
| 503 | struct mvneta_rx_desc { |
| 504 | u16 data_size; /* Size of received packet in bytes */ |
| 505 | u16 reserved1; /* pnc_info - (for future use, PnC) */ |
| 506 | u32 status; /* Info about received packet */ |
| 507 | |
| 508 | u32 reserved2; /* pnc_flow_id (for future use, PnC) */ |
| 509 | u32 buf_phys_addr; /* Physical address of the buffer */ |
| 510 | |
| 511 | u16 reserved4; /* csum_l4 - (for future use, PnC) */ |
| 512 | u16 reserved3; /* prefetch_cmd, for future use */ |
| 513 | u32 buf_cookie; /* cookie for access to RX buffer in rx path */ |
| 514 | |
| 515 | u32 reserved5; /* pnc_extra PnC (for future use, PnC) */ |
| 516 | u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */ |
| 517 | }; |
| 518 | #endif |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 519 | |
| 520 | struct mvneta_tx_queue { |
| 521 | /* Number of this TX queue, in the range 0-7 */ |
| 522 | u8 id; |
| 523 | |
| 524 | /* Number of TX DMA descriptors in the descriptor ring */ |
| 525 | int size; |
| 526 | |
| 527 | /* Number of currently used TX DMA descriptor in the |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 528 | * descriptor ring |
| 529 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 530 | int count; |
Simon Guinot | 2a90f7e | 2017-01-16 18:08:31 +0100 | [diff] [blame] | 531 | int pending; |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 532 | int tx_stop_threshold; |
| 533 | int tx_wake_threshold; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 534 | |
| 535 | /* Array of transmitted skb */ |
| 536 | struct sk_buff **tx_skb; |
| 537 | |
| 538 | /* Index of last TX DMA descriptor that was inserted */ |
| 539 | int txq_put_index; |
| 540 | |
| 541 | /* Index of the TX DMA descriptor to be cleaned up */ |
| 542 | int txq_get_index; |
| 543 | |
| 544 | u32 done_pkts_coal; |
| 545 | |
| 546 | /* Virtual address of the TX DMA descriptors array */ |
| 547 | struct mvneta_tx_desc *descs; |
| 548 | |
| 549 | /* DMA address of the TX DMA descriptors array */ |
| 550 | dma_addr_t descs_phys; |
| 551 | |
| 552 | /* Index of the last TX DMA descriptor */ |
| 553 | int last_desc; |
| 554 | |
| 555 | /* Index of the next TX DMA descriptor to process */ |
| 556 | int next_desc_to_proc; |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 557 | |
| 558 | /* DMA buffers for TSO headers */ |
| 559 | char *tso_hdrs; |
| 560 | |
| 561 | /* DMA address of TSO headers */ |
| 562 | dma_addr_t tso_hdrs_phys; |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 563 | |
| 564 | /* Affinity mask for CPUs*/ |
| 565 | cpumask_t affinity_mask; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 566 | }; |
| 567 | |
| 568 | struct mvneta_rx_queue { |
| 569 | /* rx queue number, in the range 0-7 */ |
| 570 | u8 id; |
| 571 | |
| 572 | /* num of rx descriptors in the rx descriptor ring */ |
| 573 | int size; |
| 574 | |
| 575 | /* counter of times when mvneta_refill() failed */ |
| 576 | int missed; |
| 577 | |
| 578 | u32 pkts_coal; |
| 579 | u32 time_coal; |
| 580 | |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 581 | /* Virtual address of the RX buffer */ |
| 582 | void **buf_virt_addr; |
| 583 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 584 | /* Virtual address of the RX DMA descriptors array */ |
| 585 | struct mvneta_rx_desc *descs; |
| 586 | |
| 587 | /* DMA address of the RX DMA descriptors array */ |
| 588 | dma_addr_t descs_phys; |
| 589 | |
| 590 | /* Index of the last RX DMA descriptor */ |
| 591 | int last_desc; |
| 592 | |
| 593 | /* Index of the next RX DMA descriptor to process */ |
| 594 | int next_desc_to_proc; |
| 595 | }; |
| 596 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 597 | static enum cpuhp_state online_hpstate; |
Ezequiel Garcia | edadb7f | 2014-05-22 20:07:01 -0300 | [diff] [blame] | 598 | /* The hardware supports eight (8) rx queues, but we are only allowing |
| 599 | * the first one to be used. Therefore, let's just allocate one queue. |
| 600 | */ |
Maxime Ripard | d893665 | 2015-09-25 18:09:37 +0200 | [diff] [blame] | 601 | static int rxq_number = 8; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 602 | static int txq_number = 8; |
| 603 | |
| 604 | static int rxq_def; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 605 | |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 606 | static int rx_copybreak __read_mostly = 256; |
| 607 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 608 | /* HW BM need that each port be identify by a unique ID */ |
| 609 | static int global_port_id; |
| 610 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 611 | #define MVNETA_DRIVER_NAME "mvneta" |
| 612 | #define MVNETA_DRIVER_VERSION "1.0" |
| 613 | |
| 614 | /* Utility/helper methods */ |
| 615 | |
| 616 | /* Write helper method */ |
| 617 | static void mvreg_write(struct mvneta_port *pp, u32 offset, u32 data) |
| 618 | { |
| 619 | writel(data, pp->base + offset); |
| 620 | } |
| 621 | |
| 622 | /* Read helper method */ |
| 623 | static u32 mvreg_read(struct mvneta_port *pp, u32 offset) |
| 624 | { |
| 625 | return readl(pp->base + offset); |
| 626 | } |
| 627 | |
| 628 | /* Increment txq get counter */ |
| 629 | static void mvneta_txq_inc_get(struct mvneta_tx_queue *txq) |
| 630 | { |
| 631 | txq->txq_get_index++; |
| 632 | if (txq->txq_get_index == txq->size) |
| 633 | txq->txq_get_index = 0; |
| 634 | } |
| 635 | |
| 636 | /* Increment txq put counter */ |
| 637 | static void mvneta_txq_inc_put(struct mvneta_tx_queue *txq) |
| 638 | { |
| 639 | txq->txq_put_index++; |
| 640 | if (txq->txq_put_index == txq->size) |
| 641 | txq->txq_put_index = 0; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | /* Clear all MIB counters */ |
| 646 | static void mvneta_mib_counters_clear(struct mvneta_port *pp) |
| 647 | { |
| 648 | int i; |
| 649 | u32 dummy; |
| 650 | |
| 651 | /* Perform dummy reads from MIB counters */ |
| 652 | for (i = 0; i < MVNETA_MIB_LATE_COLLISION; i += 4) |
| 653 | dummy = mvreg_read(pp, (MVNETA_MIB_COUNTERS_BASE + i)); |
Andrew Lunn | e483911 | 2015-10-22 18:37:36 +0100 | [diff] [blame] | 654 | dummy = mvreg_read(pp, MVNETA_RX_DISCARD_FRAME_COUNT); |
| 655 | dummy = mvreg_read(pp, MVNETA_OVERRUN_FRAME_COUNT); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /* Get System Network Statistics */ |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 659 | static void |
Baoyou Xie | 2dc0d2b | 2016-09-25 17:20:41 +0800 | [diff] [blame] | 660 | mvneta_get_stats64(struct net_device *dev, |
| 661 | struct rtnl_link_stats64 *stats) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 662 | { |
| 663 | struct mvneta_port *pp = netdev_priv(dev); |
| 664 | unsigned int start; |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 665 | int cpu; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 666 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 667 | for_each_possible_cpu(cpu) { |
| 668 | struct mvneta_pcpu_stats *cpu_stats; |
| 669 | u64 rx_packets; |
| 670 | u64 rx_bytes; |
| 671 | u64 tx_packets; |
| 672 | u64 tx_bytes; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 673 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 674 | cpu_stats = per_cpu_ptr(pp->stats, cpu); |
| 675 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 676 | start = u64_stats_fetch_begin_irq(&cpu_stats->syncp); |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 677 | rx_packets = cpu_stats->rx_packets; |
| 678 | rx_bytes = cpu_stats->rx_bytes; |
| 679 | tx_packets = cpu_stats->tx_packets; |
| 680 | tx_bytes = cpu_stats->tx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 681 | } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 682 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 683 | stats->rx_packets += rx_packets; |
| 684 | stats->rx_bytes += rx_bytes; |
| 685 | stats->tx_packets += tx_packets; |
| 686 | stats->tx_bytes += tx_bytes; |
| 687 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 688 | |
| 689 | stats->rx_errors = dev->stats.rx_errors; |
| 690 | stats->rx_dropped = dev->stats.rx_dropped; |
| 691 | |
| 692 | stats->tx_dropped = dev->stats.tx_dropped; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /* Rx descriptors helper methods */ |
| 696 | |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 697 | /* Checks whether the RX descriptor having this status is both the first |
| 698 | * and the last descriptor for the RX packet. Each RX packet is currently |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 699 | * received through a single RX descriptor, so not having each RX |
| 700 | * descriptor with its first and last bits set is an error |
| 701 | */ |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 702 | static int mvneta_rxq_desc_is_first_last(u32 status) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 703 | { |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 704 | return (status & MVNETA_RXD_FIRST_LAST_DESC) == |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 705 | MVNETA_RXD_FIRST_LAST_DESC; |
| 706 | } |
| 707 | |
| 708 | /* Add number of descriptors ready to receive new packets */ |
| 709 | static void mvneta_rxq_non_occup_desc_add(struct mvneta_port *pp, |
| 710 | struct mvneta_rx_queue *rxq, |
| 711 | int ndescs) |
| 712 | { |
| 713 | /* Only MVNETA_RXQ_ADD_NON_OCCUPIED_MAX (255) descriptors can |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 714 | * be added at once |
| 715 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 716 | while (ndescs > MVNETA_RXQ_ADD_NON_OCCUPIED_MAX) { |
| 717 | mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), |
| 718 | (MVNETA_RXQ_ADD_NON_OCCUPIED_MAX << |
| 719 | MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT)); |
| 720 | ndescs -= MVNETA_RXQ_ADD_NON_OCCUPIED_MAX; |
| 721 | } |
| 722 | |
| 723 | mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), |
| 724 | (ndescs << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT)); |
| 725 | } |
| 726 | |
| 727 | /* Get number of RX descriptors occupied by received packets */ |
| 728 | static int mvneta_rxq_busy_desc_num_get(struct mvneta_port *pp, |
| 729 | struct mvneta_rx_queue *rxq) |
| 730 | { |
| 731 | u32 val; |
| 732 | |
| 733 | val = mvreg_read(pp, MVNETA_RXQ_STATUS_REG(rxq->id)); |
| 734 | return val & MVNETA_RXQ_OCCUPIED_ALL_MASK; |
| 735 | } |
| 736 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 737 | /* Update num of rx desc called upon return from rx path or |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 738 | * from mvneta_rxq_drop_pkts(). |
| 739 | */ |
| 740 | static void mvneta_rxq_desc_num_update(struct mvneta_port *pp, |
| 741 | struct mvneta_rx_queue *rxq, |
| 742 | int rx_done, int rx_filled) |
| 743 | { |
| 744 | u32 val; |
| 745 | |
| 746 | if ((rx_done <= 0xff) && (rx_filled <= 0xff)) { |
| 747 | val = rx_done | |
| 748 | (rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT); |
| 749 | mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | /* Only 255 descriptors can be added at once */ |
| 754 | while ((rx_done > 0) || (rx_filled > 0)) { |
| 755 | if (rx_done <= 0xff) { |
| 756 | val = rx_done; |
| 757 | rx_done = 0; |
| 758 | } else { |
| 759 | val = 0xff; |
| 760 | rx_done -= 0xff; |
| 761 | } |
| 762 | if (rx_filled <= 0xff) { |
| 763 | val |= rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT; |
| 764 | rx_filled = 0; |
| 765 | } else { |
| 766 | val |= 0xff << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT; |
| 767 | rx_filled -= 0xff; |
| 768 | } |
| 769 | mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | /* Get pointer to next RX descriptor to be processed by SW */ |
| 774 | static struct mvneta_rx_desc * |
| 775 | mvneta_rxq_next_desc_get(struct mvneta_rx_queue *rxq) |
| 776 | { |
| 777 | int rx_desc = rxq->next_desc_to_proc; |
| 778 | |
| 779 | rxq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(rxq, rx_desc); |
willy tarreau | 34e4179 | 2014-01-16 08:20:15 +0100 | [diff] [blame] | 780 | prefetch(rxq->descs + rxq->next_desc_to_proc); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 781 | return rxq->descs + rx_desc; |
| 782 | } |
| 783 | |
| 784 | /* Change maximum receive size of the port. */ |
| 785 | static void mvneta_max_rx_size_set(struct mvneta_port *pp, int max_rx_size) |
| 786 | { |
| 787 | u32 val; |
| 788 | |
| 789 | val = mvreg_read(pp, MVNETA_GMAC_CTRL_0); |
| 790 | val &= ~MVNETA_GMAC_MAX_RX_SIZE_MASK; |
| 791 | val |= ((max_rx_size - MVNETA_MH_SIZE) / 2) << |
| 792 | MVNETA_GMAC_MAX_RX_SIZE_SHIFT; |
| 793 | mvreg_write(pp, MVNETA_GMAC_CTRL_0, val); |
| 794 | } |
| 795 | |
| 796 | |
| 797 | /* Set rx queue offset */ |
| 798 | static void mvneta_rxq_offset_set(struct mvneta_port *pp, |
| 799 | struct mvneta_rx_queue *rxq, |
| 800 | int offset) |
| 801 | { |
| 802 | u32 val; |
| 803 | |
| 804 | val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id)); |
| 805 | val &= ~MVNETA_RXQ_PKT_OFFSET_ALL_MASK; |
| 806 | |
| 807 | /* Offset is in */ |
| 808 | val |= MVNETA_RXQ_PKT_OFFSET_MASK(offset >> 3); |
| 809 | mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | /* Tx descriptors helper methods */ |
| 814 | |
| 815 | /* Update HW with number of TX descriptors to be sent */ |
| 816 | static void mvneta_txq_pend_desc_add(struct mvneta_port *pp, |
| 817 | struct mvneta_tx_queue *txq, |
| 818 | int pend_desc) |
| 819 | { |
| 820 | u32 val; |
| 821 | |
Simon Guinot | 0d63785 | 2017-11-13 16:27:02 +0100 | [diff] [blame] | 822 | pend_desc += txq->pending; |
| 823 | |
| 824 | /* Only 255 Tx descriptors can be added at once */ |
| 825 | do { |
| 826 | val = min(pend_desc, 255); |
| 827 | mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val); |
| 828 | pend_desc -= val; |
| 829 | } while (pend_desc > 0); |
Simon Guinot | 2a90f7e | 2017-01-16 18:08:31 +0100 | [diff] [blame] | 830 | txq->pending = 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* Get pointer to next TX descriptor to be processed (send) by HW */ |
| 834 | static struct mvneta_tx_desc * |
| 835 | mvneta_txq_next_desc_get(struct mvneta_tx_queue *txq) |
| 836 | { |
| 837 | int tx_desc = txq->next_desc_to_proc; |
| 838 | |
| 839 | txq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(txq, tx_desc); |
| 840 | return txq->descs + tx_desc; |
| 841 | } |
| 842 | |
| 843 | /* Release the last allocated TX descriptor. Useful to handle DMA |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 844 | * mapping failures in the TX path. |
| 845 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 846 | static void mvneta_txq_desc_put(struct mvneta_tx_queue *txq) |
| 847 | { |
| 848 | if (txq->next_desc_to_proc == 0) |
| 849 | txq->next_desc_to_proc = txq->last_desc - 1; |
| 850 | else |
| 851 | txq->next_desc_to_proc--; |
| 852 | } |
| 853 | |
| 854 | /* Set rxq buf size */ |
| 855 | static void mvneta_rxq_buf_size_set(struct mvneta_port *pp, |
| 856 | struct mvneta_rx_queue *rxq, |
| 857 | int buf_size) |
| 858 | { |
| 859 | u32 val; |
| 860 | |
| 861 | val = mvreg_read(pp, MVNETA_RXQ_SIZE_REG(rxq->id)); |
| 862 | |
| 863 | val &= ~MVNETA_RXQ_BUF_SIZE_MASK; |
| 864 | val |= ((buf_size >> 3) << MVNETA_RXQ_BUF_SIZE_SHIFT); |
| 865 | |
| 866 | mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val); |
| 867 | } |
| 868 | |
| 869 | /* Disable buffer management (BM) */ |
| 870 | static void mvneta_rxq_bm_disable(struct mvneta_port *pp, |
| 871 | struct mvneta_rx_queue *rxq) |
| 872 | { |
| 873 | u32 val; |
| 874 | |
| 875 | val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id)); |
| 876 | val &= ~MVNETA_RXQ_HW_BUF_ALLOC; |
| 877 | mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); |
| 878 | } |
| 879 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 880 | /* Enable buffer management (BM) */ |
| 881 | static void mvneta_rxq_bm_enable(struct mvneta_port *pp, |
| 882 | struct mvneta_rx_queue *rxq) |
| 883 | { |
| 884 | u32 val; |
| 885 | |
| 886 | val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id)); |
| 887 | val |= MVNETA_RXQ_HW_BUF_ALLOC; |
| 888 | mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); |
| 889 | } |
| 890 | |
| 891 | /* Notify HW about port's assignment of pool for bigger packets */ |
| 892 | static void mvneta_rxq_long_pool_set(struct mvneta_port *pp, |
| 893 | struct mvneta_rx_queue *rxq) |
| 894 | { |
| 895 | u32 val; |
| 896 | |
| 897 | val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id)); |
| 898 | val &= ~MVNETA_RXQ_LONG_POOL_ID_MASK; |
| 899 | val |= (pp->pool_long->id << MVNETA_RXQ_LONG_POOL_ID_SHIFT); |
| 900 | |
| 901 | mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); |
| 902 | } |
| 903 | |
| 904 | /* Notify HW about port's assignment of pool for smaller packets */ |
| 905 | static void mvneta_rxq_short_pool_set(struct mvneta_port *pp, |
| 906 | struct mvneta_rx_queue *rxq) |
| 907 | { |
| 908 | u32 val; |
| 909 | |
| 910 | val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id)); |
| 911 | val &= ~MVNETA_RXQ_SHORT_POOL_ID_MASK; |
| 912 | val |= (pp->pool_short->id << MVNETA_RXQ_SHORT_POOL_ID_SHIFT); |
| 913 | |
| 914 | mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); |
| 915 | } |
| 916 | |
| 917 | /* Set port's receive buffer size for assigned BM pool */ |
| 918 | static inline void mvneta_bm_pool_bufsize_set(struct mvneta_port *pp, |
| 919 | int buf_size, |
| 920 | u8 pool_id) |
| 921 | { |
| 922 | u32 val; |
| 923 | |
| 924 | if (!IS_ALIGNED(buf_size, 8)) { |
| 925 | dev_warn(pp->dev->dev.parent, |
| 926 | "illegal buf_size value %d, round to %d\n", |
| 927 | buf_size, ALIGN(buf_size, 8)); |
| 928 | buf_size = ALIGN(buf_size, 8); |
| 929 | } |
| 930 | |
| 931 | val = mvreg_read(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id)); |
| 932 | val |= buf_size & MVNETA_PORT_POOL_BUFFER_SZ_MASK; |
| 933 | mvreg_write(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id), val); |
| 934 | } |
| 935 | |
| 936 | /* Configure MBUS window in order to enable access BM internal SRAM */ |
| 937 | static int mvneta_mbus_io_win_set(struct mvneta_port *pp, u32 base, u32 wsize, |
| 938 | u8 target, u8 attr) |
| 939 | { |
| 940 | u32 win_enable, win_protect; |
| 941 | int i; |
| 942 | |
| 943 | win_enable = mvreg_read(pp, MVNETA_BASE_ADDR_ENABLE); |
| 944 | |
| 945 | if (pp->bm_win_id < 0) { |
| 946 | /* Find first not occupied window */ |
| 947 | for (i = 0; i < MVNETA_MAX_DECODE_WIN; i++) { |
| 948 | if (win_enable & (1 << i)) { |
| 949 | pp->bm_win_id = i; |
| 950 | break; |
| 951 | } |
| 952 | } |
| 953 | if (i == MVNETA_MAX_DECODE_WIN) |
| 954 | return -ENOMEM; |
| 955 | } else { |
| 956 | i = pp->bm_win_id; |
| 957 | } |
| 958 | |
| 959 | mvreg_write(pp, MVNETA_WIN_BASE(i), 0); |
| 960 | mvreg_write(pp, MVNETA_WIN_SIZE(i), 0); |
| 961 | |
| 962 | if (i < 4) |
| 963 | mvreg_write(pp, MVNETA_WIN_REMAP(i), 0); |
| 964 | |
| 965 | mvreg_write(pp, MVNETA_WIN_BASE(i), (base & 0xffff0000) | |
| 966 | (attr << 8) | target); |
| 967 | |
| 968 | mvreg_write(pp, MVNETA_WIN_SIZE(i), (wsize - 1) & 0xffff0000); |
| 969 | |
| 970 | win_protect = mvreg_read(pp, MVNETA_ACCESS_PROTECT_ENABLE); |
| 971 | win_protect |= 3 << (2 * i); |
| 972 | mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect); |
| 973 | |
| 974 | win_enable &= ~(1 << i); |
| 975 | mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable); |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 980 | static int mvneta_bm_port_mbus_init(struct mvneta_port *pp) |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 981 | { |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 982 | u32 wsize; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 983 | u8 target, attr; |
| 984 | int err; |
| 985 | |
| 986 | /* Get BM window information */ |
| 987 | err = mvebu_mbus_get_io_win_info(pp->bm_priv->bppi_phys_addr, &wsize, |
| 988 | &target, &attr); |
| 989 | if (err < 0) |
| 990 | return err; |
| 991 | |
| 992 | pp->bm_win_id = -1; |
| 993 | |
| 994 | /* Open NETA -> BM window */ |
| 995 | err = mvneta_mbus_io_win_set(pp, pp->bm_priv->bppi_phys_addr, wsize, |
| 996 | target, attr); |
| 997 | if (err < 0) { |
| 998 | netdev_info(pp->dev, "fail to configure mbus window to BM\n"); |
| 999 | return err; |
| 1000 | } |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | /* Assign and initialize pools for port. In case of fail |
| 1005 | * buffer manager will remain disabled for current port. |
| 1006 | */ |
| 1007 | static int mvneta_bm_port_init(struct platform_device *pdev, |
| 1008 | struct mvneta_port *pp) |
| 1009 | { |
| 1010 | struct device_node *dn = pdev->dev.of_node; |
| 1011 | u32 long_pool_id, short_pool_id; |
| 1012 | |
| 1013 | if (!pp->neta_armada3700) { |
| 1014 | int ret; |
| 1015 | |
| 1016 | ret = mvneta_bm_port_mbus_init(pp); |
| 1017 | if (ret) |
| 1018 | return ret; |
| 1019 | } |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1020 | |
| 1021 | if (of_property_read_u32(dn, "bm,pool-long", &long_pool_id)) { |
| 1022 | netdev_info(pp->dev, "missing long pool id\n"); |
| 1023 | return -EINVAL; |
| 1024 | } |
| 1025 | |
| 1026 | /* Create port's long pool depending on mtu */ |
| 1027 | pp->pool_long = mvneta_bm_pool_use(pp->bm_priv, long_pool_id, |
| 1028 | MVNETA_BM_LONG, pp->id, |
| 1029 | MVNETA_RX_PKT_SIZE(pp->dev->mtu)); |
| 1030 | if (!pp->pool_long) { |
| 1031 | netdev_info(pp->dev, "fail to obtain long pool for port\n"); |
| 1032 | return -ENOMEM; |
| 1033 | } |
| 1034 | |
| 1035 | pp->pool_long->port_map |= 1 << pp->id; |
| 1036 | |
| 1037 | mvneta_bm_pool_bufsize_set(pp, pp->pool_long->buf_size, |
| 1038 | pp->pool_long->id); |
| 1039 | |
| 1040 | /* If short pool id is not defined, assume using single pool */ |
| 1041 | if (of_property_read_u32(dn, "bm,pool-short", &short_pool_id)) |
| 1042 | short_pool_id = long_pool_id; |
| 1043 | |
| 1044 | /* Create port's short pool */ |
| 1045 | pp->pool_short = mvneta_bm_pool_use(pp->bm_priv, short_pool_id, |
| 1046 | MVNETA_BM_SHORT, pp->id, |
| 1047 | MVNETA_BM_SHORT_PKT_SIZE); |
| 1048 | if (!pp->pool_short) { |
| 1049 | netdev_info(pp->dev, "fail to obtain short pool for port\n"); |
| 1050 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); |
| 1051 | return -ENOMEM; |
| 1052 | } |
| 1053 | |
| 1054 | if (short_pool_id != long_pool_id) { |
| 1055 | pp->pool_short->port_map |= 1 << pp->id; |
| 1056 | mvneta_bm_pool_bufsize_set(pp, pp->pool_short->buf_size, |
| 1057 | pp->pool_short->id); |
| 1058 | } |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | /* Update settings of a pool for bigger packets */ |
| 1064 | static void mvneta_bm_update_mtu(struct mvneta_port *pp, int mtu) |
| 1065 | { |
| 1066 | struct mvneta_bm_pool *bm_pool = pp->pool_long; |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 1067 | struct hwbm_pool *hwbm_pool = &bm_pool->hwbm_pool; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1068 | int num; |
| 1069 | |
| 1070 | /* Release all buffers from long pool */ |
| 1071 | mvneta_bm_bufs_free(pp->bm_priv, bm_pool, 1 << pp->id); |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 1072 | if (hwbm_pool->buf_num) { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1073 | WARN(1, "cannot free all buffers in pool %d\n", |
| 1074 | bm_pool->id); |
| 1075 | goto bm_mtu_err; |
| 1076 | } |
| 1077 | |
| 1078 | bm_pool->pkt_size = MVNETA_RX_PKT_SIZE(mtu); |
| 1079 | bm_pool->buf_size = MVNETA_RX_BUF_SIZE(bm_pool->pkt_size); |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 1080 | hwbm_pool->frag_size = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
| 1081 | SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(bm_pool->pkt_size)); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1082 | |
| 1083 | /* Fill entire long pool */ |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 1084 | num = hwbm_pool_add(hwbm_pool, hwbm_pool->size, GFP_ATOMIC); |
| 1085 | if (num != hwbm_pool->size) { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1086 | WARN(1, "pool %d: %d of %d allocated\n", |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 1087 | bm_pool->id, num, hwbm_pool->size); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1088 | goto bm_mtu_err; |
| 1089 | } |
| 1090 | mvneta_bm_pool_bufsize_set(pp, bm_pool->buf_size, bm_pool->id); |
| 1091 | |
| 1092 | return; |
| 1093 | |
| 1094 | bm_mtu_err: |
| 1095 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); |
| 1096 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, 1 << pp->id); |
| 1097 | |
| 1098 | pp->bm_priv = NULL; |
| 1099 | mvreg_write(pp, MVNETA_ACC_MODE, MVNETA_ACC_MODE_EXT1); |
| 1100 | netdev_info(pp->dev, "fail to update MTU, fall back to software BM\n"); |
| 1101 | } |
| 1102 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1103 | /* Start the Ethernet port RX and TX activity */ |
| 1104 | static void mvneta_port_up(struct mvneta_port *pp) |
| 1105 | { |
| 1106 | int queue; |
| 1107 | u32 q_map; |
| 1108 | |
| 1109 | /* Enable all initialized TXs. */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1110 | q_map = 0; |
| 1111 | for (queue = 0; queue < txq_number; queue++) { |
| 1112 | struct mvneta_tx_queue *txq = &pp->txqs[queue]; |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 1113 | if (txq->descs) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1114 | q_map |= (1 << queue); |
| 1115 | } |
| 1116 | mvreg_write(pp, MVNETA_TXQ_CMD, q_map); |
| 1117 | |
| 1118 | /* Enable all initialized RXQs. */ |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1119 | for (queue = 0; queue < rxq_number; queue++) { |
| 1120 | struct mvneta_rx_queue *rxq = &pp->rxqs[queue]; |
| 1121 | |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 1122 | if (rxq->descs) |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1123 | q_map |= (1 << queue); |
| 1124 | } |
| 1125 | mvreg_write(pp, MVNETA_RXQ_CMD, q_map); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /* Stop the Ethernet port activity */ |
| 1129 | static void mvneta_port_down(struct mvneta_port *pp) |
| 1130 | { |
| 1131 | u32 val; |
| 1132 | int count; |
| 1133 | |
| 1134 | /* Stop Rx port activity. Check port Rx activity. */ |
| 1135 | val = mvreg_read(pp, MVNETA_RXQ_CMD) & MVNETA_RXQ_ENABLE_MASK; |
| 1136 | |
| 1137 | /* Issue stop command for active channels only */ |
| 1138 | if (val != 0) |
| 1139 | mvreg_write(pp, MVNETA_RXQ_CMD, |
| 1140 | val << MVNETA_RXQ_DISABLE_SHIFT); |
| 1141 | |
| 1142 | /* Wait for all Rx activity to terminate. */ |
| 1143 | count = 0; |
| 1144 | do { |
| 1145 | if (count++ >= MVNETA_RX_DISABLE_TIMEOUT_MSEC) { |
| 1146 | netdev_warn(pp->dev, |
Dmitri Epshtein | 0838abb3 | 2016-03-12 18:44:19 +0100 | [diff] [blame] | 1147 | "TIMEOUT for RX stopped ! rx_queue_cmd: 0x%08x\n", |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1148 | val); |
| 1149 | break; |
| 1150 | } |
| 1151 | mdelay(1); |
| 1152 | |
| 1153 | val = mvreg_read(pp, MVNETA_RXQ_CMD); |
Dmitri Epshtein | a3703fb | 2016-03-12 18:44:20 +0100 | [diff] [blame] | 1154 | } while (val & MVNETA_RXQ_ENABLE_MASK); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1155 | |
| 1156 | /* Stop Tx port activity. Check port Tx activity. Issue stop |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1157 | * command for active channels only |
| 1158 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1159 | val = (mvreg_read(pp, MVNETA_TXQ_CMD)) & MVNETA_TXQ_ENABLE_MASK; |
| 1160 | |
| 1161 | if (val != 0) |
| 1162 | mvreg_write(pp, MVNETA_TXQ_CMD, |
| 1163 | (val << MVNETA_TXQ_DISABLE_SHIFT)); |
| 1164 | |
| 1165 | /* Wait for all Tx activity to terminate. */ |
| 1166 | count = 0; |
| 1167 | do { |
| 1168 | if (count++ >= MVNETA_TX_DISABLE_TIMEOUT_MSEC) { |
| 1169 | netdev_warn(pp->dev, |
| 1170 | "TIMEOUT for TX stopped status=0x%08x\n", |
| 1171 | val); |
| 1172 | break; |
| 1173 | } |
| 1174 | mdelay(1); |
| 1175 | |
| 1176 | /* Check TX Command reg that all Txqs are stopped */ |
| 1177 | val = mvreg_read(pp, MVNETA_TXQ_CMD); |
| 1178 | |
Dmitri Epshtein | a3703fb | 2016-03-12 18:44:20 +0100 | [diff] [blame] | 1179 | } while (val & MVNETA_TXQ_ENABLE_MASK); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1180 | |
| 1181 | /* Double check to verify that TX FIFO is empty */ |
| 1182 | count = 0; |
| 1183 | do { |
| 1184 | if (count++ >= MVNETA_TX_FIFO_EMPTY_TIMEOUT) { |
| 1185 | netdev_warn(pp->dev, |
Dmitri Epshtein | 0838abb3 | 2016-03-12 18:44:19 +0100 | [diff] [blame] | 1186 | "TX FIFO empty timeout status=0x%08x\n", |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1187 | val); |
| 1188 | break; |
| 1189 | } |
| 1190 | mdelay(1); |
| 1191 | |
| 1192 | val = mvreg_read(pp, MVNETA_PORT_STATUS); |
| 1193 | } while (!(val & MVNETA_TX_FIFO_EMPTY) && |
| 1194 | (val & MVNETA_TX_IN_PRGRS)); |
| 1195 | |
| 1196 | udelay(200); |
| 1197 | } |
| 1198 | |
| 1199 | /* Enable the port by setting the port enable bit of the MAC control register */ |
| 1200 | static void mvneta_port_enable(struct mvneta_port *pp) |
| 1201 | { |
| 1202 | u32 val; |
| 1203 | |
| 1204 | /* Enable port */ |
| 1205 | val = mvreg_read(pp, MVNETA_GMAC_CTRL_0); |
| 1206 | val |= MVNETA_GMAC0_PORT_ENABLE; |
| 1207 | mvreg_write(pp, MVNETA_GMAC_CTRL_0, val); |
| 1208 | } |
| 1209 | |
| 1210 | /* Disable the port and wait for about 200 usec before retuning */ |
| 1211 | static void mvneta_port_disable(struct mvneta_port *pp) |
| 1212 | { |
| 1213 | u32 val; |
| 1214 | |
| 1215 | /* Reset the Enable bit in the Serial Control Register */ |
| 1216 | val = mvreg_read(pp, MVNETA_GMAC_CTRL_0); |
| 1217 | val &= ~MVNETA_GMAC0_PORT_ENABLE; |
| 1218 | mvreg_write(pp, MVNETA_GMAC_CTRL_0, val); |
| 1219 | |
| 1220 | udelay(200); |
| 1221 | } |
| 1222 | |
| 1223 | /* Multicast tables methods */ |
| 1224 | |
| 1225 | /* Set all entries in Unicast MAC Table; queue==-1 means reject all */ |
| 1226 | static void mvneta_set_ucast_table(struct mvneta_port *pp, int queue) |
| 1227 | { |
| 1228 | int offset; |
| 1229 | u32 val; |
| 1230 | |
| 1231 | if (queue == -1) { |
| 1232 | val = 0; |
| 1233 | } else { |
| 1234 | val = 0x1 | (queue << 1); |
| 1235 | val |= (val << 24) | (val << 16) | (val << 8); |
| 1236 | } |
| 1237 | |
| 1238 | for (offset = 0; offset <= 0xc; offset += 4) |
| 1239 | mvreg_write(pp, MVNETA_DA_FILT_UCAST_BASE + offset, val); |
| 1240 | } |
| 1241 | |
| 1242 | /* Set all entries in Special Multicast MAC Table; queue==-1 means reject all */ |
| 1243 | static void mvneta_set_special_mcast_table(struct mvneta_port *pp, int queue) |
| 1244 | { |
| 1245 | int offset; |
| 1246 | u32 val; |
| 1247 | |
| 1248 | if (queue == -1) { |
| 1249 | val = 0; |
| 1250 | } else { |
| 1251 | val = 0x1 | (queue << 1); |
| 1252 | val |= (val << 24) | (val << 16) | (val << 8); |
| 1253 | } |
| 1254 | |
| 1255 | for (offset = 0; offset <= 0xfc; offset += 4) |
| 1256 | mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + offset, val); |
| 1257 | |
| 1258 | } |
| 1259 | |
| 1260 | /* Set all entries in Other Multicast MAC Table. queue==-1 means reject all */ |
| 1261 | static void mvneta_set_other_mcast_table(struct mvneta_port *pp, int queue) |
| 1262 | { |
| 1263 | int offset; |
| 1264 | u32 val; |
| 1265 | |
| 1266 | if (queue == -1) { |
| 1267 | memset(pp->mcast_count, 0, sizeof(pp->mcast_count)); |
| 1268 | val = 0; |
| 1269 | } else { |
| 1270 | memset(pp->mcast_count, 1, sizeof(pp->mcast_count)); |
| 1271 | val = 0x1 | (queue << 1); |
| 1272 | val |= (val << 24) | (val << 16) | (val << 8); |
| 1273 | } |
| 1274 | |
| 1275 | for (offset = 0; offset <= 0xfc; offset += 4) |
| 1276 | mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + offset, val); |
| 1277 | } |
| 1278 | |
Gregory CLEMENT | db488c1 | 2016-02-04 22:09:27 +0100 | [diff] [blame] | 1279 | static void mvneta_percpu_unmask_interrupt(void *arg) |
| 1280 | { |
| 1281 | struct mvneta_port *pp = arg; |
| 1282 | |
| 1283 | /* All the queue are unmasked, but actually only the ones |
| 1284 | * mapped to this CPU will be unmasked |
| 1285 | */ |
| 1286 | mvreg_write(pp, MVNETA_INTR_NEW_MASK, |
| 1287 | MVNETA_RX_INTR_MASK_ALL | |
| 1288 | MVNETA_TX_INTR_MASK_ALL | |
| 1289 | MVNETA_MISCINTR_INTR_MASK); |
| 1290 | } |
| 1291 | |
| 1292 | static void mvneta_percpu_mask_interrupt(void *arg) |
| 1293 | { |
| 1294 | struct mvneta_port *pp = arg; |
| 1295 | |
| 1296 | /* All the queue are masked, but actually only the ones |
| 1297 | * mapped to this CPU will be masked |
| 1298 | */ |
| 1299 | mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0); |
| 1300 | mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0); |
| 1301 | mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0); |
| 1302 | } |
| 1303 | |
| 1304 | static void mvneta_percpu_clear_intr_cause(void *arg) |
| 1305 | { |
| 1306 | struct mvneta_port *pp = arg; |
| 1307 | |
| 1308 | /* All the queue are cleared, but actually only the ones |
| 1309 | * mapped to this CPU will be cleared |
| 1310 | */ |
| 1311 | mvreg_write(pp, MVNETA_INTR_NEW_CAUSE, 0); |
| 1312 | mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0); |
| 1313 | mvreg_write(pp, MVNETA_INTR_OLD_CAUSE, 0); |
| 1314 | } |
| 1315 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1316 | /* This method sets defaults to the NETA port: |
| 1317 | * Clears interrupt Cause and Mask registers. |
| 1318 | * Clears all MAC tables. |
| 1319 | * Sets defaults to all registers. |
| 1320 | * Resets RX and TX descriptor rings. |
| 1321 | * Resets PHY. |
| 1322 | * This method can be called after mvneta_port_down() to return the port |
| 1323 | * settings to defaults. |
| 1324 | */ |
| 1325 | static void mvneta_defaults_set(struct mvneta_port *pp) |
| 1326 | { |
| 1327 | int cpu; |
| 1328 | int queue; |
| 1329 | u32 val; |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1330 | int max_cpu = num_present_cpus(); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1331 | |
| 1332 | /* Clear all Cause registers */ |
Gregory CLEMENT | db488c1 | 2016-02-04 22:09:27 +0100 | [diff] [blame] | 1333 | on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1334 | |
| 1335 | /* Mask all interrupts */ |
Gregory CLEMENT | db488c1 | 2016-02-04 22:09:27 +0100 | [diff] [blame] | 1336 | on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1337 | mvreg_write(pp, MVNETA_INTR_ENABLE, 0); |
| 1338 | |
| 1339 | /* Enable MBUS Retry bit16 */ |
| 1340 | mvreg_write(pp, MVNETA_MBUS_RETRY, 0x20); |
| 1341 | |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 1342 | /* Set CPU queue access map. CPUs are assigned to the RX and |
| 1343 | * TX queues modulo their number. If there is only one TX |
| 1344 | * queue then it is assigned to the CPU associated to the |
| 1345 | * default RX queue. |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1346 | */ |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1347 | for_each_present_cpu(cpu) { |
| 1348 | int rxq_map = 0, txq_map = 0; |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 1349 | int rxq, txq; |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 1350 | if (!pp->neta_armada3700) { |
| 1351 | for (rxq = 0; rxq < rxq_number; rxq++) |
| 1352 | if ((rxq % max_cpu) == cpu) |
| 1353 | rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq); |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1354 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 1355 | for (txq = 0; txq < txq_number; txq++) |
| 1356 | if ((txq % max_cpu) == cpu) |
| 1357 | txq_map |= MVNETA_CPU_TXQ_ACCESS(txq); |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1358 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 1359 | /* With only one TX queue we configure a special case |
| 1360 | * which will allow to get all the irq on a single |
| 1361 | * CPU |
| 1362 | */ |
| 1363 | if (txq_number == 1) |
| 1364 | txq_map = (cpu == pp->rxq_def) ? |
| 1365 | MVNETA_CPU_TXQ_ACCESS(1) : 0; |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 1366 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 1367 | } else { |
| 1368 | txq_map = MVNETA_CPU_TXQ_ACCESS_ALL_MASK; |
| 1369 | rxq_map = MVNETA_CPU_RXQ_ACCESS_ALL_MASK; |
| 1370 | } |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 1371 | |
| 1372 | mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map); |
| 1373 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1374 | |
| 1375 | /* Reset RX and TX DMAs */ |
| 1376 | mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET); |
| 1377 | mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET); |
| 1378 | |
| 1379 | /* Disable Legacy WRR, Disable EJP, Release from reset */ |
| 1380 | mvreg_write(pp, MVNETA_TXQ_CMD_1, 0); |
| 1381 | for (queue = 0; queue < txq_number; queue++) { |
| 1382 | mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(queue), 0); |
| 1383 | mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(queue), 0); |
| 1384 | } |
| 1385 | |
| 1386 | mvreg_write(pp, MVNETA_PORT_TX_RESET, 0); |
| 1387 | mvreg_write(pp, MVNETA_PORT_RX_RESET, 0); |
| 1388 | |
| 1389 | /* Set Port Acceleration Mode */ |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1390 | if (pp->bm_priv) |
| 1391 | /* HW buffer management + legacy parser */ |
| 1392 | val = MVNETA_ACC_MODE_EXT2; |
| 1393 | else |
| 1394 | /* SW buffer management + legacy parser */ |
| 1395 | val = MVNETA_ACC_MODE_EXT1; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1396 | mvreg_write(pp, MVNETA_ACC_MODE, val); |
| 1397 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1398 | if (pp->bm_priv) |
| 1399 | mvreg_write(pp, MVNETA_BM_ADDRESS, pp->bm_priv->bppi_phys_addr); |
| 1400 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1401 | /* Update val of portCfg register accordingly with all RxQueue types */ |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 1402 | val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1403 | mvreg_write(pp, MVNETA_PORT_CONFIG, val); |
| 1404 | |
| 1405 | val = 0; |
| 1406 | mvreg_write(pp, MVNETA_PORT_CONFIG_EXTEND, val); |
| 1407 | mvreg_write(pp, MVNETA_RX_MIN_FRAME_SIZE, 64); |
| 1408 | |
| 1409 | /* Build PORT_SDMA_CONFIG_REG */ |
| 1410 | val = 0; |
| 1411 | |
| 1412 | /* Default burst size */ |
| 1413 | val |= MVNETA_TX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16); |
| 1414 | val |= MVNETA_RX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16); |
Thomas Petazzoni | 9ad8fef | 2013-07-29 15:21:28 +0200 | [diff] [blame] | 1415 | val |= MVNETA_RX_NO_DATA_SWAP | MVNETA_TX_NO_DATA_SWAP; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1416 | |
Thomas Petazzoni | 9ad8fef | 2013-07-29 15:21:28 +0200 | [diff] [blame] | 1417 | #if defined(__BIG_ENDIAN) |
| 1418 | val |= MVNETA_DESC_SWAP; |
| 1419 | #endif |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1420 | |
| 1421 | /* Assign port SDMA configuration */ |
| 1422 | mvreg_write(pp, MVNETA_SDMA_CONFIG, val); |
| 1423 | |
Thomas Petazzoni | 7140860 | 2013-09-04 16:21:18 +0200 | [diff] [blame] | 1424 | /* Disable PHY polling in hardware, since we're using the |
| 1425 | * kernel phylib to do this. |
| 1426 | */ |
| 1427 | val = mvreg_read(pp, MVNETA_UNIT_CONTROL); |
| 1428 | val &= ~MVNETA_PHY_POLLING_ENABLE; |
| 1429 | mvreg_write(pp, MVNETA_UNIT_CONTROL, val); |
| 1430 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1431 | mvneta_set_ucast_table(pp, -1); |
| 1432 | mvneta_set_special_mcast_table(pp, -1); |
| 1433 | mvneta_set_other_mcast_table(pp, -1); |
| 1434 | |
| 1435 | /* Set port interrupt enable register - default enable all */ |
| 1436 | mvreg_write(pp, MVNETA_INTR_ENABLE, |
| 1437 | (MVNETA_RXQ_INTR_ENABLE_ALL_MASK |
| 1438 | | MVNETA_TXQ_INTR_ENABLE_ALL_MASK)); |
Andrew Lunn | e483911 | 2015-10-22 18:37:36 +0100 | [diff] [blame] | 1439 | |
| 1440 | mvneta_mib_counters_clear(pp); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /* Set max sizes for tx queues */ |
| 1444 | static void mvneta_txq_max_tx_size_set(struct mvneta_port *pp, int max_tx_size) |
| 1445 | |
| 1446 | { |
| 1447 | u32 val, size, mtu; |
| 1448 | int queue; |
| 1449 | |
| 1450 | mtu = max_tx_size * 8; |
| 1451 | if (mtu > MVNETA_TX_MTU_MAX) |
| 1452 | mtu = MVNETA_TX_MTU_MAX; |
| 1453 | |
| 1454 | /* Set MTU */ |
| 1455 | val = mvreg_read(pp, MVNETA_TX_MTU); |
| 1456 | val &= ~MVNETA_TX_MTU_MAX; |
| 1457 | val |= mtu; |
| 1458 | mvreg_write(pp, MVNETA_TX_MTU, val); |
| 1459 | |
| 1460 | /* TX token size and all TXQs token size must be larger that MTU */ |
| 1461 | val = mvreg_read(pp, MVNETA_TX_TOKEN_SIZE); |
| 1462 | |
| 1463 | size = val & MVNETA_TX_TOKEN_SIZE_MAX; |
| 1464 | if (size < mtu) { |
| 1465 | size = mtu; |
| 1466 | val &= ~MVNETA_TX_TOKEN_SIZE_MAX; |
| 1467 | val |= size; |
| 1468 | mvreg_write(pp, MVNETA_TX_TOKEN_SIZE, val); |
| 1469 | } |
| 1470 | for (queue = 0; queue < txq_number; queue++) { |
| 1471 | val = mvreg_read(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue)); |
| 1472 | |
| 1473 | size = val & MVNETA_TXQ_TOKEN_SIZE_MAX; |
| 1474 | if (size < mtu) { |
| 1475 | size = mtu; |
| 1476 | val &= ~MVNETA_TXQ_TOKEN_SIZE_MAX; |
| 1477 | val |= size; |
| 1478 | mvreg_write(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue), val); |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | /* Set unicast address */ |
| 1484 | static void mvneta_set_ucast_addr(struct mvneta_port *pp, u8 last_nibble, |
| 1485 | int queue) |
| 1486 | { |
| 1487 | unsigned int unicast_reg; |
| 1488 | unsigned int tbl_offset; |
| 1489 | unsigned int reg_offset; |
| 1490 | |
| 1491 | /* Locate the Unicast table entry */ |
| 1492 | last_nibble = (0xf & last_nibble); |
| 1493 | |
| 1494 | /* offset from unicast tbl base */ |
| 1495 | tbl_offset = (last_nibble / 4) * 4; |
| 1496 | |
| 1497 | /* offset within the above reg */ |
| 1498 | reg_offset = last_nibble % 4; |
| 1499 | |
| 1500 | unicast_reg = mvreg_read(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset)); |
| 1501 | |
| 1502 | if (queue == -1) { |
| 1503 | /* Clear accepts frame bit at specified unicast DA tbl entry */ |
| 1504 | unicast_reg &= ~(0xff << (8 * reg_offset)); |
| 1505 | } else { |
| 1506 | unicast_reg &= ~(0xff << (8 * reg_offset)); |
| 1507 | unicast_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset)); |
| 1508 | } |
| 1509 | |
| 1510 | mvreg_write(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset), unicast_reg); |
| 1511 | } |
| 1512 | |
| 1513 | /* Set mac address */ |
| 1514 | static void mvneta_mac_addr_set(struct mvneta_port *pp, unsigned char *addr, |
| 1515 | int queue) |
| 1516 | { |
| 1517 | unsigned int mac_h; |
| 1518 | unsigned int mac_l; |
| 1519 | |
| 1520 | if (queue != -1) { |
| 1521 | mac_l = (addr[4] << 8) | (addr[5]); |
| 1522 | mac_h = (addr[0] << 24) | (addr[1] << 16) | |
| 1523 | (addr[2] << 8) | (addr[3] << 0); |
| 1524 | |
| 1525 | mvreg_write(pp, MVNETA_MAC_ADDR_LOW, mac_l); |
| 1526 | mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, mac_h); |
| 1527 | } |
| 1528 | |
| 1529 | /* Accept frames of this address */ |
| 1530 | mvneta_set_ucast_addr(pp, addr[5], queue); |
| 1531 | } |
| 1532 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1533 | /* Set the number of packets that will be received before RX interrupt |
| 1534 | * will be generated by HW. |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1535 | */ |
| 1536 | static void mvneta_rx_pkts_coal_set(struct mvneta_port *pp, |
| 1537 | struct mvneta_rx_queue *rxq, u32 value) |
| 1538 | { |
| 1539 | mvreg_write(pp, MVNETA_RXQ_THRESHOLD_REG(rxq->id), |
| 1540 | value | MVNETA_RXQ_NON_OCCUPIED(0)); |
| 1541 | rxq->pkts_coal = value; |
| 1542 | } |
| 1543 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1544 | /* Set the time delay in usec before RX interrupt will be generated by |
| 1545 | * HW. |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1546 | */ |
| 1547 | static void mvneta_rx_time_coal_set(struct mvneta_port *pp, |
| 1548 | struct mvneta_rx_queue *rxq, u32 value) |
| 1549 | { |
Thomas Petazzoni | 189dd62 | 2012-11-19 14:15:25 +0100 | [diff] [blame] | 1550 | u32 val; |
| 1551 | unsigned long clk_rate; |
| 1552 | |
| 1553 | clk_rate = clk_get_rate(pp->clk); |
| 1554 | val = (clk_rate / 1000000) * value; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1555 | |
| 1556 | mvreg_write(pp, MVNETA_RXQ_TIME_COAL_REG(rxq->id), val); |
| 1557 | rxq->time_coal = value; |
| 1558 | } |
| 1559 | |
| 1560 | /* Set threshold for TX_DONE pkts coalescing */ |
| 1561 | static void mvneta_tx_done_pkts_coal_set(struct mvneta_port *pp, |
| 1562 | struct mvneta_tx_queue *txq, u32 value) |
| 1563 | { |
| 1564 | u32 val; |
| 1565 | |
| 1566 | val = mvreg_read(pp, MVNETA_TXQ_SIZE_REG(txq->id)); |
| 1567 | |
| 1568 | val &= ~MVNETA_TXQ_SENT_THRESH_ALL_MASK; |
| 1569 | val |= MVNETA_TXQ_SENT_THRESH_MASK(value); |
| 1570 | |
| 1571 | mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), val); |
| 1572 | |
| 1573 | txq->done_pkts_coal = value; |
| 1574 | } |
| 1575 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1576 | /* Handle rx descriptor fill by setting buf_cookie and buf_phys_addr */ |
| 1577 | static void mvneta_rx_desc_fill(struct mvneta_rx_desc *rx_desc, |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1578 | u32 phys_addr, void *virt_addr, |
| 1579 | struct mvneta_rx_queue *rxq) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1580 | { |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1581 | int i; |
| 1582 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1583 | rx_desc->buf_phys_addr = phys_addr; |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1584 | i = rx_desc - rxq->descs; |
| 1585 | rxq->buf_virt_addr[i] = virt_addr; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | /* Decrement sent descriptors counter */ |
| 1589 | static void mvneta_txq_sent_desc_dec(struct mvneta_port *pp, |
| 1590 | struct mvneta_tx_queue *txq, |
| 1591 | int sent_desc) |
| 1592 | { |
| 1593 | u32 val; |
| 1594 | |
| 1595 | /* Only 255 TX descriptors can be updated at once */ |
| 1596 | while (sent_desc > 0xff) { |
| 1597 | val = 0xff << MVNETA_TXQ_DEC_SENT_SHIFT; |
| 1598 | mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val); |
| 1599 | sent_desc = sent_desc - 0xff; |
| 1600 | } |
| 1601 | |
| 1602 | val = sent_desc << MVNETA_TXQ_DEC_SENT_SHIFT; |
| 1603 | mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val); |
| 1604 | } |
| 1605 | |
| 1606 | /* Get number of TX descriptors already sent by HW */ |
| 1607 | static int mvneta_txq_sent_desc_num_get(struct mvneta_port *pp, |
| 1608 | struct mvneta_tx_queue *txq) |
| 1609 | { |
| 1610 | u32 val; |
| 1611 | int sent_desc; |
| 1612 | |
| 1613 | val = mvreg_read(pp, MVNETA_TXQ_STATUS_REG(txq->id)); |
| 1614 | sent_desc = (val & MVNETA_TXQ_SENT_DESC_MASK) >> |
| 1615 | MVNETA_TXQ_SENT_DESC_SHIFT; |
| 1616 | |
| 1617 | return sent_desc; |
| 1618 | } |
| 1619 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1620 | /* Get number of sent descriptors and decrement counter. |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1621 | * The number of sent descriptors is returned. |
| 1622 | */ |
| 1623 | static int mvneta_txq_sent_desc_proc(struct mvneta_port *pp, |
| 1624 | struct mvneta_tx_queue *txq) |
| 1625 | { |
| 1626 | int sent_desc; |
| 1627 | |
| 1628 | /* Get number of sent descriptors */ |
| 1629 | sent_desc = mvneta_txq_sent_desc_num_get(pp, txq); |
| 1630 | |
| 1631 | /* Decrement sent descriptors counter */ |
| 1632 | if (sent_desc) |
| 1633 | mvneta_txq_sent_desc_dec(pp, txq, sent_desc); |
| 1634 | |
| 1635 | return sent_desc; |
| 1636 | } |
| 1637 | |
| 1638 | /* Set TXQ descriptors fields relevant for CSUM calculation */ |
| 1639 | static u32 mvneta_txq_desc_csum(int l3_offs, int l3_proto, |
| 1640 | int ip_hdr_len, int l4_proto) |
| 1641 | { |
| 1642 | u32 command; |
| 1643 | |
| 1644 | /* Fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk, |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 1645 | * G_L4_chk, L4_type; required only for checksum |
| 1646 | * calculation |
| 1647 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1648 | command = l3_offs << MVNETA_TX_L3_OFF_SHIFT; |
| 1649 | command |= ip_hdr_len << MVNETA_TX_IP_HLEN_SHIFT; |
| 1650 | |
Thomas Fitzsimmons | 0a19858 | 2014-07-08 19:44:07 -0400 | [diff] [blame] | 1651 | if (l3_proto == htons(ETH_P_IP)) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1652 | command |= MVNETA_TXD_IP_CSUM; |
| 1653 | else |
| 1654 | command |= MVNETA_TX_L3_IP6; |
| 1655 | |
| 1656 | if (l4_proto == IPPROTO_TCP) |
| 1657 | command |= MVNETA_TX_L4_CSUM_FULL; |
| 1658 | else if (l4_proto == IPPROTO_UDP) |
| 1659 | command |= MVNETA_TX_L4_UDP | MVNETA_TX_L4_CSUM_FULL; |
| 1660 | else |
| 1661 | command |= MVNETA_TX_L4_CSUM_NOT; |
| 1662 | |
| 1663 | return command; |
| 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | /* Display more error info */ |
| 1668 | static void mvneta_rx_error(struct mvneta_port *pp, |
| 1669 | struct mvneta_rx_desc *rx_desc) |
| 1670 | { |
| 1671 | u32 status = rx_desc->status; |
| 1672 | |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1673 | if (!mvneta_rxq_desc_is_first_last(status)) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1674 | netdev_err(pp->dev, |
| 1675 | "bad rx status %08x (buffer oversize), size=%d\n", |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1676 | status, rx_desc->data_size); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1677 | return; |
| 1678 | } |
| 1679 | |
| 1680 | switch (status & MVNETA_RXD_ERR_CODE_MASK) { |
| 1681 | case MVNETA_RXD_ERR_CRC: |
| 1682 | netdev_err(pp->dev, "bad rx status %08x (crc error), size=%d\n", |
| 1683 | status, rx_desc->data_size); |
| 1684 | break; |
| 1685 | case MVNETA_RXD_ERR_OVERRUN: |
| 1686 | netdev_err(pp->dev, "bad rx status %08x (overrun error), size=%d\n", |
| 1687 | status, rx_desc->data_size); |
| 1688 | break; |
| 1689 | case MVNETA_RXD_ERR_LEN: |
| 1690 | netdev_err(pp->dev, "bad rx status %08x (max frame length error), size=%d\n", |
| 1691 | status, rx_desc->data_size); |
| 1692 | break; |
| 1693 | case MVNETA_RXD_ERR_RESOURCE: |
| 1694 | netdev_err(pp->dev, "bad rx status %08x (resource error), size=%d\n", |
| 1695 | status, rx_desc->data_size); |
| 1696 | break; |
| 1697 | } |
| 1698 | } |
| 1699 | |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1700 | /* Handle RX checksum offload based on the descriptor's status */ |
| 1701 | static void mvneta_rx_csum(struct mvneta_port *pp, u32 status, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1702 | struct sk_buff *skb) |
| 1703 | { |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1704 | if ((status & MVNETA_RXD_L3_IP4) && |
| 1705 | (status & MVNETA_RXD_L4_CSUM_OK)) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1706 | skb->csum = 0; |
| 1707 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1708 | return; |
| 1709 | } |
| 1710 | |
| 1711 | skb->ip_summed = CHECKSUM_NONE; |
| 1712 | } |
| 1713 | |
willy tarreau | 6c49897 | 2014-01-16 08:20:12 +0100 | [diff] [blame] | 1714 | /* Return tx queue pointer (find last set bit) according to <cause> returned |
| 1715 | * form tx_done reg. <cause> must not be null. The return value is always a |
| 1716 | * valid queue for matching the first one found in <cause>. |
| 1717 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1718 | static struct mvneta_tx_queue *mvneta_tx_done_policy(struct mvneta_port *pp, |
| 1719 | u32 cause) |
| 1720 | { |
| 1721 | int queue = fls(cause) - 1; |
| 1722 | |
willy tarreau | 6c49897 | 2014-01-16 08:20:12 +0100 | [diff] [blame] | 1723 | return &pp->txqs[queue]; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | /* Free tx queue skbuffs */ |
| 1727 | static void mvneta_txq_bufs_free(struct mvneta_port *pp, |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 1728 | struct mvneta_tx_queue *txq, int num, |
| 1729 | struct netdev_queue *nq) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1730 | { |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 1731 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1732 | int i; |
| 1733 | |
| 1734 | for (i = 0; i < num; i++) { |
| 1735 | struct mvneta_tx_desc *tx_desc = txq->descs + |
| 1736 | txq->txq_get_index; |
| 1737 | struct sk_buff *skb = txq->tx_skb[txq->txq_get_index]; |
| 1738 | |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 1739 | if (skb) { |
| 1740 | bytes_compl += skb->len; |
| 1741 | pkts_compl++; |
| 1742 | } |
| 1743 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1744 | mvneta_txq_inc_get(txq); |
| 1745 | |
Ezequiel Garcia | 2e3173a | 2014-05-30 13:40:07 -0300 | [diff] [blame] | 1746 | if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr)) |
| 1747 | dma_unmap_single(pp->dev->dev.parent, |
| 1748 | tx_desc->buf_phys_addr, |
| 1749 | tx_desc->data_size, DMA_TO_DEVICE); |
Ezequiel Garcia | ba7e46e | 2014-05-30 13:40:06 -0300 | [diff] [blame] | 1750 | if (!skb) |
| 1751 | continue; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1752 | dev_kfree_skb_any(skb); |
| 1753 | } |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 1754 | |
| 1755 | netdev_tx_completed_queue(nq, pkts_compl, bytes_compl); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /* Handle end of transmission */ |
Arnaud Ebalard | cd71319 | 2014-01-16 08:20:19 +0100 | [diff] [blame] | 1759 | static void mvneta_txq_done(struct mvneta_port *pp, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1760 | struct mvneta_tx_queue *txq) |
| 1761 | { |
| 1762 | struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id); |
| 1763 | int tx_done; |
| 1764 | |
| 1765 | tx_done = mvneta_txq_sent_desc_proc(pp, txq); |
Arnaud Ebalard | cd71319 | 2014-01-16 08:20:19 +0100 | [diff] [blame] | 1766 | if (!tx_done) |
| 1767 | return; |
| 1768 | |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 1769 | mvneta_txq_bufs_free(pp, txq, tx_done, nq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1770 | |
| 1771 | txq->count -= tx_done; |
| 1772 | |
| 1773 | if (netif_tx_queue_stopped(nq)) { |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 1774 | if (txq->count <= txq->tx_wake_threshold) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1775 | netif_tx_wake_queue(nq); |
| 1776 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1777 | } |
| 1778 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1779 | void *mvneta_frag_alloc(unsigned int frag_size) |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1780 | { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1781 | if (likely(frag_size <= PAGE_SIZE)) |
| 1782 | return netdev_alloc_frag(frag_size); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1783 | else |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1784 | return kmalloc(frag_size, GFP_ATOMIC); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1785 | } |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1786 | EXPORT_SYMBOL_GPL(mvneta_frag_alloc); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1787 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1788 | void mvneta_frag_free(unsigned int frag_size, void *data) |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1789 | { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1790 | if (likely(frag_size <= PAGE_SIZE)) |
Alexander Duyck | 13dc0d2 | 2015-05-06 21:12:14 -0700 | [diff] [blame] | 1791 | skb_free_frag(data); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1792 | else |
| 1793 | kfree(data); |
| 1794 | } |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1795 | EXPORT_SYMBOL_GPL(mvneta_frag_free); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1796 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1797 | /* Refill processing for SW buffer management */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1798 | static int mvneta_rx_refill(struct mvneta_port *pp, |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1799 | struct mvneta_rx_desc *rx_desc, |
| 1800 | struct mvneta_rx_queue *rxq) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1801 | |
| 1802 | { |
| 1803 | dma_addr_t phys_addr; |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1804 | void *data; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1805 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1806 | data = mvneta_frag_alloc(pp->frag_size); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1807 | if (!data) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1808 | return -ENOMEM; |
| 1809 | |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1810 | phys_addr = dma_map_single(pp->dev->dev.parent, data, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1811 | MVNETA_RX_BUF_SIZE(pp->pkt_size), |
| 1812 | DMA_FROM_DEVICE); |
| 1813 | if (unlikely(dma_mapping_error(pp->dev->dev.parent, phys_addr))) { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1814 | mvneta_frag_free(pp->frag_size, data); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1815 | return -ENOMEM; |
| 1816 | } |
| 1817 | |
Marcin Wojtas | 8d5047c | 2016-12-01 18:03:07 +0100 | [diff] [blame] | 1818 | phys_addr += pp->rx_offset_correction; |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1819 | mvneta_rx_desc_fill(rx_desc, phys_addr, data, rxq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1820 | return 0; |
| 1821 | } |
| 1822 | |
| 1823 | /* Handle tx checksum */ |
| 1824 | static u32 mvneta_skb_tx_csum(struct mvneta_port *pp, struct sk_buff *skb) |
| 1825 | { |
| 1826 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 1827 | int ip_hdr_len = 0; |
Vlad Yasevich | 817dbfa | 2014-08-25 10:34:54 -0400 | [diff] [blame] | 1828 | __be16 l3_proto = vlan_get_protocol(skb); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1829 | u8 l4_proto; |
| 1830 | |
Vlad Yasevich | 817dbfa | 2014-08-25 10:34:54 -0400 | [diff] [blame] | 1831 | if (l3_proto == htons(ETH_P_IP)) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1832 | struct iphdr *ip4h = ip_hdr(skb); |
| 1833 | |
| 1834 | /* Calculate IPv4 checksum and L4 checksum */ |
| 1835 | ip_hdr_len = ip4h->ihl; |
| 1836 | l4_proto = ip4h->protocol; |
Vlad Yasevich | 817dbfa | 2014-08-25 10:34:54 -0400 | [diff] [blame] | 1837 | } else if (l3_proto == htons(ETH_P_IPV6)) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1838 | struct ipv6hdr *ip6h = ipv6_hdr(skb); |
| 1839 | |
| 1840 | /* Read l4_protocol from one of IPv6 extra headers */ |
| 1841 | if (skb_network_header_len(skb) > 0) |
| 1842 | ip_hdr_len = (skb_network_header_len(skb) >> 2); |
| 1843 | l4_proto = ip6h->nexthdr; |
| 1844 | } else |
| 1845 | return MVNETA_TX_L4_CSUM_NOT; |
| 1846 | |
| 1847 | return mvneta_txq_desc_csum(skb_network_offset(skb), |
Vlad Yasevich | 817dbfa | 2014-08-25 10:34:54 -0400 | [diff] [blame] | 1848 | l3_proto, ip_hdr_len, l4_proto); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | return MVNETA_TX_L4_CSUM_NOT; |
| 1852 | } |
| 1853 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1854 | /* Drop packets received by the RXQ and free buffers */ |
| 1855 | static void mvneta_rxq_drop_pkts(struct mvneta_port *pp, |
| 1856 | struct mvneta_rx_queue *rxq) |
| 1857 | { |
| 1858 | int rx_done, i; |
| 1859 | |
| 1860 | rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1861 | if (rx_done) |
| 1862 | mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done); |
| 1863 | |
| 1864 | if (pp->bm_priv) { |
| 1865 | for (i = 0; i < rx_done; i++) { |
| 1866 | struct mvneta_rx_desc *rx_desc = |
| 1867 | mvneta_rxq_next_desc_get(rxq); |
| 1868 | u8 pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc); |
| 1869 | struct mvneta_bm_pool *bm_pool; |
| 1870 | |
| 1871 | bm_pool = &pp->bm_priv->bm_pools[pool_id]; |
| 1872 | /* Return dropped buffer to the pool */ |
| 1873 | mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool, |
| 1874 | rx_desc->buf_phys_addr); |
| 1875 | } |
| 1876 | return; |
| 1877 | } |
| 1878 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1879 | for (i = 0; i < rxq->size; i++) { |
| 1880 | struct mvneta_rx_desc *rx_desc = rxq->descs + i; |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1881 | void *data = rxq->buf_virt_addr[i]; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1882 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1883 | dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr, |
Ezequiel Garcia | a328f3a | 2013-12-05 13:35:37 -0300 | [diff] [blame] | 1884 | MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1885 | mvneta_frag_free(pp->frag_size, data); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1886 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1887 | } |
| 1888 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1889 | /* Main rx processing when using software buffer management */ |
| 1890 | static int mvneta_rx_swbm(struct mvneta_port *pp, int rx_todo, |
| 1891 | struct mvneta_rx_queue *rxq) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1892 | { |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 1893 | struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1894 | struct net_device *dev = pp->dev; |
Simon Guinot | a84e328 | 2015-07-19 13:00:53 +0200 | [diff] [blame] | 1895 | int rx_done; |
willy tarreau | dc4277d | 2014-01-16 08:20:07 +0100 | [diff] [blame] | 1896 | u32 rcvd_pkts = 0; |
| 1897 | u32 rcvd_bytes = 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1898 | |
| 1899 | /* Get number of received packets */ |
| 1900 | rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq); |
| 1901 | |
| 1902 | if (rx_todo > rx_done) |
| 1903 | rx_todo = rx_done; |
| 1904 | |
| 1905 | rx_done = 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1906 | |
| 1907 | /* Fairness NAPI loop */ |
| 1908 | while (rx_done < rx_todo) { |
| 1909 | struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq); |
| 1910 | struct sk_buff *skb; |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1911 | unsigned char *data; |
Simon Guinot | daf158d | 2015-09-15 22:41:21 +0200 | [diff] [blame] | 1912 | dma_addr_t phys_addr; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1913 | u32 rx_status, frag_size; |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1914 | int rx_bytes, err, index; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1915 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1916 | rx_done++; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1917 | rx_status = rx_desc->status; |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1918 | rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE); |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1919 | index = rx_desc - rxq->descs; |
| 1920 | data = rxq->buf_virt_addr[index]; |
Simon Guinot | daf158d | 2015-09-15 22:41:21 +0200 | [diff] [blame] | 1921 | phys_addr = rx_desc->buf_phys_addr; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1922 | |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1923 | if (!mvneta_rxq_desc_is_first_last(rx_status) || |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1924 | (rx_status & MVNETA_RXD_ERR_SUMMARY)) { |
Yelena Krivosheev | 2eecb2e | 2017-12-19 17:59:47 +0100 | [diff] [blame] | 1925 | mvneta_rx_error(pp, rx_desc); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1926 | err_drop_frame: |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1927 | dev->stats.rx_errors++; |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1928 | /* leave the descriptor untouched */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1929 | continue; |
| 1930 | } |
| 1931 | |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1932 | if (rx_bytes <= rx_copybreak) { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1933 | /* better copy a small frame and not unmap the DMA region */ |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1934 | skb = netdev_alloc_skb_ip_align(dev, rx_bytes); |
| 1935 | if (unlikely(!skb)) |
| 1936 | goto err_drop_frame; |
| 1937 | |
| 1938 | dma_sync_single_range_for_cpu(dev->dev.parent, |
Gregory CLEMENT | ac83b7d | 2016-12-01 18:03:04 +0100 | [diff] [blame] | 1939 | phys_addr, |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1940 | MVNETA_MH_SIZE + NET_SKB_PAD, |
| 1941 | rx_bytes, |
| 1942 | DMA_FROM_DEVICE); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1943 | skb_put_data(skb, data + MVNETA_MH_SIZE + NET_SKB_PAD, |
| 1944 | rx_bytes); |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1945 | |
| 1946 | skb->protocol = eth_type_trans(skb, dev); |
| 1947 | mvneta_rx_csum(pp, rx_status, skb); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 1948 | napi_gro_receive(&port->napi, skb); |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1949 | |
| 1950 | rcvd_pkts++; |
| 1951 | rcvd_bytes += rx_bytes; |
| 1952 | |
| 1953 | /* leave the descriptor and buffer untouched */ |
| 1954 | continue; |
| 1955 | } |
| 1956 | |
Simon Guinot | a84e328 | 2015-07-19 13:00:53 +0200 | [diff] [blame] | 1957 | /* Refill processing */ |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 1958 | err = mvneta_rx_refill(pp, rx_desc, rxq); |
Simon Guinot | a84e328 | 2015-07-19 13:00:53 +0200 | [diff] [blame] | 1959 | if (err) { |
| 1960 | netdev_err(dev, "Linux processing - Can't refill\n"); |
| 1961 | rxq->missed++; |
| 1962 | goto err_drop_frame; |
| 1963 | } |
| 1964 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1965 | frag_size = pp->frag_size; |
| 1966 | |
| 1967 | skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size); |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 1968 | |
Marcin Wojtas | 26c17a17 | 2015-11-30 13:27:44 +0100 | [diff] [blame] | 1969 | /* After refill old buffer has to be unmapped regardless |
| 1970 | * the skb is successfully built or not. |
| 1971 | */ |
Simon Guinot | daf158d | 2015-09-15 22:41:21 +0200 | [diff] [blame] | 1972 | dma_unmap_single(dev->dev.parent, phys_addr, |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 1973 | MVNETA_RX_BUF_SIZE(pp->pkt_size), |
| 1974 | DMA_FROM_DEVICE); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1975 | |
Marcin Wojtas | 26c17a17 | 2015-11-30 13:27:44 +0100 | [diff] [blame] | 1976 | if (!skb) |
| 1977 | goto err_drop_frame; |
| 1978 | |
willy tarreau | dc4277d | 2014-01-16 08:20:07 +0100 | [diff] [blame] | 1979 | rcvd_pkts++; |
| 1980 | rcvd_bytes += rx_bytes; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1981 | |
| 1982 | /* Linux processing */ |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 1983 | skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1984 | skb_put(skb, rx_bytes); |
| 1985 | |
| 1986 | skb->protocol = eth_type_trans(skb, dev); |
| 1987 | |
willy tarreau | 5428213 | 2014-01-16 08:20:14 +0100 | [diff] [blame] | 1988 | mvneta_rx_csum(pp, rx_status, skb); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1989 | |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 1990 | napi_gro_receive(&port->napi, skb); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 1991 | } |
| 1992 | |
willy tarreau | dc4277d | 2014-01-16 08:20:07 +0100 | [diff] [blame] | 1993 | if (rcvd_pkts) { |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 1994 | struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); |
| 1995 | |
| 1996 | u64_stats_update_begin(&stats->syncp); |
| 1997 | stats->rx_packets += rcvd_pkts; |
| 1998 | stats->rx_bytes += rcvd_bytes; |
| 1999 | u64_stats_update_end(&stats->syncp); |
willy tarreau | dc4277d | 2014-01-16 08:20:07 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2002 | /* Update rxq management counters */ |
Simon Guinot | a84e328 | 2015-07-19 13:00:53 +0200 | [diff] [blame] | 2003 | mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2004 | |
| 2005 | return rx_done; |
| 2006 | } |
| 2007 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2008 | /* Main rx processing when using hardware buffer management */ |
| 2009 | static int mvneta_rx_hwbm(struct mvneta_port *pp, int rx_todo, |
| 2010 | struct mvneta_rx_queue *rxq) |
| 2011 | { |
| 2012 | struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports); |
| 2013 | struct net_device *dev = pp->dev; |
| 2014 | int rx_done; |
| 2015 | u32 rcvd_pkts = 0; |
| 2016 | u32 rcvd_bytes = 0; |
| 2017 | |
| 2018 | /* Get number of received packets */ |
| 2019 | rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq); |
| 2020 | |
| 2021 | if (rx_todo > rx_done) |
| 2022 | rx_todo = rx_done; |
| 2023 | |
| 2024 | rx_done = 0; |
| 2025 | |
| 2026 | /* Fairness NAPI loop */ |
| 2027 | while (rx_done < rx_todo) { |
| 2028 | struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq); |
| 2029 | struct mvneta_bm_pool *bm_pool = NULL; |
| 2030 | struct sk_buff *skb; |
| 2031 | unsigned char *data; |
| 2032 | dma_addr_t phys_addr; |
| 2033 | u32 rx_status, frag_size; |
| 2034 | int rx_bytes, err; |
| 2035 | u8 pool_id; |
| 2036 | |
| 2037 | rx_done++; |
| 2038 | rx_status = rx_desc->status; |
| 2039 | rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE); |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 2040 | data = (u8 *)(uintptr_t)rx_desc->buf_cookie; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2041 | phys_addr = rx_desc->buf_phys_addr; |
| 2042 | pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc); |
| 2043 | bm_pool = &pp->bm_priv->bm_pools[pool_id]; |
| 2044 | |
| 2045 | if (!mvneta_rxq_desc_is_first_last(rx_status) || |
| 2046 | (rx_status & MVNETA_RXD_ERR_SUMMARY)) { |
| 2047 | err_drop_frame_ret_pool: |
| 2048 | /* Return the buffer to the pool */ |
| 2049 | mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool, |
| 2050 | rx_desc->buf_phys_addr); |
| 2051 | err_drop_frame: |
| 2052 | dev->stats.rx_errors++; |
| 2053 | mvneta_rx_error(pp, rx_desc); |
| 2054 | /* leave the descriptor untouched */ |
| 2055 | continue; |
| 2056 | } |
| 2057 | |
| 2058 | if (rx_bytes <= rx_copybreak) { |
| 2059 | /* better copy a small frame and not unmap the DMA region */ |
| 2060 | skb = netdev_alloc_skb_ip_align(dev, rx_bytes); |
| 2061 | if (unlikely(!skb)) |
| 2062 | goto err_drop_frame_ret_pool; |
| 2063 | |
| 2064 | dma_sync_single_range_for_cpu(dev->dev.parent, |
| 2065 | rx_desc->buf_phys_addr, |
| 2066 | MVNETA_MH_SIZE + NET_SKB_PAD, |
| 2067 | rx_bytes, |
| 2068 | DMA_FROM_DEVICE); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 2069 | skb_put_data(skb, data + MVNETA_MH_SIZE + NET_SKB_PAD, |
| 2070 | rx_bytes); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2071 | |
| 2072 | skb->protocol = eth_type_trans(skb, dev); |
| 2073 | mvneta_rx_csum(pp, rx_status, skb); |
| 2074 | napi_gro_receive(&port->napi, skb); |
| 2075 | |
| 2076 | rcvd_pkts++; |
| 2077 | rcvd_bytes += rx_bytes; |
| 2078 | |
| 2079 | /* Return the buffer to the pool */ |
| 2080 | mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool, |
| 2081 | rx_desc->buf_phys_addr); |
| 2082 | |
| 2083 | /* leave the descriptor and buffer untouched */ |
| 2084 | continue; |
| 2085 | } |
| 2086 | |
| 2087 | /* Refill processing */ |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 2088 | err = hwbm_pool_refill(&bm_pool->hwbm_pool, GFP_ATOMIC); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2089 | if (err) { |
| 2090 | netdev_err(dev, "Linux processing - Can't refill\n"); |
| 2091 | rxq->missed++; |
| 2092 | goto err_drop_frame_ret_pool; |
| 2093 | } |
| 2094 | |
Gregory CLEMENT | baa11eb | 2016-03-14 09:39:05 +0100 | [diff] [blame] | 2095 | frag_size = bm_pool->hwbm_pool.frag_size; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2096 | |
| 2097 | skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size); |
| 2098 | |
| 2099 | /* After refill old buffer has to be unmapped regardless |
| 2100 | * the skb is successfully built or not. |
| 2101 | */ |
| 2102 | dma_unmap_single(&pp->bm_priv->pdev->dev, phys_addr, |
| 2103 | bm_pool->buf_size, DMA_FROM_DEVICE); |
| 2104 | if (!skb) |
| 2105 | goto err_drop_frame; |
| 2106 | |
| 2107 | rcvd_pkts++; |
| 2108 | rcvd_bytes += rx_bytes; |
| 2109 | |
| 2110 | /* Linux processing */ |
| 2111 | skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD); |
| 2112 | skb_put(skb, rx_bytes); |
| 2113 | |
| 2114 | skb->protocol = eth_type_trans(skb, dev); |
| 2115 | |
| 2116 | mvneta_rx_csum(pp, rx_status, skb); |
| 2117 | |
| 2118 | napi_gro_receive(&port->napi, skb); |
| 2119 | } |
| 2120 | |
| 2121 | if (rcvd_pkts) { |
| 2122 | struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); |
| 2123 | |
| 2124 | u64_stats_update_begin(&stats->syncp); |
| 2125 | stats->rx_packets += rcvd_pkts; |
| 2126 | stats->rx_bytes += rcvd_bytes; |
| 2127 | u64_stats_update_end(&stats->syncp); |
| 2128 | } |
| 2129 | |
| 2130 | /* Update rxq management counters */ |
| 2131 | mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done); |
| 2132 | |
| 2133 | return rx_done; |
| 2134 | } |
| 2135 | |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2136 | static inline void |
| 2137 | mvneta_tso_put_hdr(struct sk_buff *skb, |
| 2138 | struct mvneta_port *pp, struct mvneta_tx_queue *txq) |
| 2139 | { |
| 2140 | struct mvneta_tx_desc *tx_desc; |
| 2141 | int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 2142 | |
| 2143 | txq->tx_skb[txq->txq_put_index] = NULL; |
| 2144 | tx_desc = mvneta_txq_next_desc_get(txq); |
| 2145 | tx_desc->data_size = hdr_len; |
| 2146 | tx_desc->command = mvneta_skb_tx_csum(pp, skb); |
| 2147 | tx_desc->command |= MVNETA_TXD_F_DESC; |
| 2148 | tx_desc->buf_phys_addr = txq->tso_hdrs_phys + |
| 2149 | txq->txq_put_index * TSO_HEADER_SIZE; |
| 2150 | mvneta_txq_inc_put(txq); |
| 2151 | } |
| 2152 | |
| 2153 | static inline int |
| 2154 | mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq, |
| 2155 | struct sk_buff *skb, char *data, int size, |
| 2156 | bool last_tcp, bool is_last) |
| 2157 | { |
| 2158 | struct mvneta_tx_desc *tx_desc; |
| 2159 | |
| 2160 | tx_desc = mvneta_txq_next_desc_get(txq); |
| 2161 | tx_desc->data_size = size; |
| 2162 | tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, data, |
| 2163 | size, DMA_TO_DEVICE); |
| 2164 | if (unlikely(dma_mapping_error(dev->dev.parent, |
| 2165 | tx_desc->buf_phys_addr))) { |
| 2166 | mvneta_txq_desc_put(txq); |
| 2167 | return -ENOMEM; |
| 2168 | } |
| 2169 | |
| 2170 | tx_desc->command = 0; |
| 2171 | txq->tx_skb[txq->txq_put_index] = NULL; |
| 2172 | |
| 2173 | if (last_tcp) { |
| 2174 | /* last descriptor in the TCP packet */ |
| 2175 | tx_desc->command = MVNETA_TXD_L_DESC; |
| 2176 | |
| 2177 | /* last descriptor in SKB */ |
| 2178 | if (is_last) |
| 2179 | txq->tx_skb[txq->txq_put_index] = skb; |
| 2180 | } |
| 2181 | mvneta_txq_inc_put(txq); |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | static int mvneta_tx_tso(struct sk_buff *skb, struct net_device *dev, |
| 2186 | struct mvneta_tx_queue *txq) |
| 2187 | { |
| 2188 | int total_len, data_left; |
| 2189 | int desc_count = 0; |
| 2190 | struct mvneta_port *pp = netdev_priv(dev); |
| 2191 | struct tso_t tso; |
| 2192 | int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 2193 | int i; |
| 2194 | |
| 2195 | /* Count needed descriptors */ |
| 2196 | if ((txq->count + tso_count_descs(skb)) >= txq->size) |
| 2197 | return 0; |
| 2198 | |
| 2199 | if (skb_headlen(skb) < (skb_transport_offset(skb) + tcp_hdrlen(skb))) { |
| 2200 | pr_info("*** Is this even possible???!?!?\n"); |
| 2201 | return 0; |
| 2202 | } |
| 2203 | |
| 2204 | /* Initialize the TSO handler, and prepare the first payload */ |
| 2205 | tso_start(skb, &tso); |
| 2206 | |
| 2207 | total_len = skb->len - hdr_len; |
| 2208 | while (total_len > 0) { |
| 2209 | char *hdr; |
| 2210 | |
| 2211 | data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len); |
| 2212 | total_len -= data_left; |
| 2213 | desc_count++; |
| 2214 | |
| 2215 | /* prepare packet headers: MAC + IP + TCP */ |
| 2216 | hdr = txq->tso_hdrs + txq->txq_put_index * TSO_HEADER_SIZE; |
| 2217 | tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0); |
| 2218 | |
| 2219 | mvneta_tso_put_hdr(skb, pp, txq); |
| 2220 | |
| 2221 | while (data_left > 0) { |
| 2222 | int size; |
| 2223 | desc_count++; |
| 2224 | |
| 2225 | size = min_t(int, tso.size, data_left); |
| 2226 | |
| 2227 | if (mvneta_tso_put_data(dev, txq, skb, |
| 2228 | tso.data, size, |
| 2229 | size == data_left, |
| 2230 | total_len == 0)) |
| 2231 | goto err_release; |
| 2232 | data_left -= size; |
| 2233 | |
| 2234 | tso_build_data(skb, &tso, size); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | return desc_count; |
| 2239 | |
| 2240 | err_release: |
| 2241 | /* Release all used data descriptors; header descriptors must not |
| 2242 | * be DMA-unmapped. |
| 2243 | */ |
| 2244 | for (i = desc_count - 1; i >= 0; i--) { |
| 2245 | struct mvneta_tx_desc *tx_desc = txq->descs + i; |
Ezequiel Garcia | 2e3173a | 2014-05-30 13:40:07 -0300 | [diff] [blame] | 2246 | if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr)) |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2247 | dma_unmap_single(pp->dev->dev.parent, |
| 2248 | tx_desc->buf_phys_addr, |
| 2249 | tx_desc->data_size, |
| 2250 | DMA_TO_DEVICE); |
| 2251 | mvneta_txq_desc_put(txq); |
| 2252 | } |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2256 | /* Handle tx fragmentation processing */ |
| 2257 | static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb, |
| 2258 | struct mvneta_tx_queue *txq) |
| 2259 | { |
| 2260 | struct mvneta_tx_desc *tx_desc; |
Ezequiel Garcia | 3d4ea02 | 2014-05-22 20:06:57 -0300 | [diff] [blame] | 2261 | int i, nr_frags = skb_shinfo(skb)->nr_frags; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2262 | |
Ezequiel Garcia | 3d4ea02 | 2014-05-22 20:06:57 -0300 | [diff] [blame] | 2263 | for (i = 0; i < nr_frags; i++) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2264 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2265 | void *addr = page_address(frag->page.p) + frag->page_offset; |
| 2266 | |
| 2267 | tx_desc = mvneta_txq_next_desc_get(txq); |
| 2268 | tx_desc->data_size = frag->size; |
| 2269 | |
| 2270 | tx_desc->buf_phys_addr = |
| 2271 | dma_map_single(pp->dev->dev.parent, addr, |
| 2272 | tx_desc->data_size, DMA_TO_DEVICE); |
| 2273 | |
| 2274 | if (dma_mapping_error(pp->dev->dev.parent, |
| 2275 | tx_desc->buf_phys_addr)) { |
| 2276 | mvneta_txq_desc_put(txq); |
| 2277 | goto error; |
| 2278 | } |
| 2279 | |
Ezequiel Garcia | 3d4ea02 | 2014-05-22 20:06:57 -0300 | [diff] [blame] | 2280 | if (i == nr_frags - 1) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2281 | /* Last descriptor */ |
| 2282 | tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2283 | txq->tx_skb[txq->txq_put_index] = skb; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2284 | } else { |
| 2285 | /* Descriptor in the middle: Not First, Not Last */ |
| 2286 | tx_desc->command = 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2287 | txq->tx_skb[txq->txq_put_index] = NULL; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2288 | } |
Ezequiel Garcia | 3d4ea02 | 2014-05-22 20:06:57 -0300 | [diff] [blame] | 2289 | mvneta_txq_inc_put(txq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | return 0; |
| 2293 | |
| 2294 | error: |
| 2295 | /* Release all descriptors that were used to map fragments of |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 2296 | * this packet, as well as the corresponding DMA mappings |
| 2297 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2298 | for (i = i - 1; i >= 0; i--) { |
| 2299 | tx_desc = txq->descs + i; |
| 2300 | dma_unmap_single(pp->dev->dev.parent, |
| 2301 | tx_desc->buf_phys_addr, |
| 2302 | tx_desc->data_size, |
| 2303 | DMA_TO_DEVICE); |
| 2304 | mvneta_txq_desc_put(txq); |
| 2305 | } |
| 2306 | |
| 2307 | return -ENOMEM; |
| 2308 | } |
| 2309 | |
| 2310 | /* Main tx processing */ |
| 2311 | static int mvneta_tx(struct sk_buff *skb, struct net_device *dev) |
| 2312 | { |
| 2313 | struct mvneta_port *pp = netdev_priv(dev); |
Willy Tarreau | ee40a11 | 2013-04-11 23:00:37 +0200 | [diff] [blame] | 2314 | u16 txq_id = skb_get_queue_mapping(skb); |
| 2315 | struct mvneta_tx_queue *txq = &pp->txqs[txq_id]; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2316 | struct mvneta_tx_desc *tx_desc; |
Eric Dumazet | 5f478b4 | 2014-12-02 04:30:59 -0800 | [diff] [blame] | 2317 | int len = skb->len; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2318 | int frags = 0; |
| 2319 | u32 tx_cmd; |
| 2320 | |
| 2321 | if (!netif_running(dev)) |
| 2322 | goto out; |
| 2323 | |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2324 | if (skb_is_gso(skb)) { |
| 2325 | frags = mvneta_tx_tso(skb, dev, txq); |
| 2326 | goto out; |
| 2327 | } |
| 2328 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2329 | frags = skb_shinfo(skb)->nr_frags + 1; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2330 | |
| 2331 | /* Get a descriptor for the first part of the packet */ |
| 2332 | tx_desc = mvneta_txq_next_desc_get(txq); |
| 2333 | |
| 2334 | tx_cmd = mvneta_skb_tx_csum(pp, skb); |
| 2335 | |
| 2336 | tx_desc->data_size = skb_headlen(skb); |
| 2337 | |
| 2338 | tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, skb->data, |
| 2339 | tx_desc->data_size, |
| 2340 | DMA_TO_DEVICE); |
| 2341 | if (unlikely(dma_mapping_error(dev->dev.parent, |
| 2342 | tx_desc->buf_phys_addr))) { |
| 2343 | mvneta_txq_desc_put(txq); |
| 2344 | frags = 0; |
| 2345 | goto out; |
| 2346 | } |
| 2347 | |
| 2348 | if (frags == 1) { |
| 2349 | /* First and Last descriptor */ |
| 2350 | tx_cmd |= MVNETA_TXD_FLZ_DESC; |
| 2351 | tx_desc->command = tx_cmd; |
| 2352 | txq->tx_skb[txq->txq_put_index] = skb; |
| 2353 | mvneta_txq_inc_put(txq); |
| 2354 | } else { |
| 2355 | /* First but not Last */ |
| 2356 | tx_cmd |= MVNETA_TXD_F_DESC; |
| 2357 | txq->tx_skb[txq->txq_put_index] = NULL; |
| 2358 | mvneta_txq_inc_put(txq); |
| 2359 | tx_desc->command = tx_cmd; |
| 2360 | /* Continue with other skb fragments */ |
| 2361 | if (mvneta_tx_frag_process(pp, skb, txq)) { |
| 2362 | dma_unmap_single(dev->dev.parent, |
| 2363 | tx_desc->buf_phys_addr, |
| 2364 | tx_desc->data_size, |
| 2365 | DMA_TO_DEVICE); |
| 2366 | mvneta_txq_desc_put(txq); |
| 2367 | frags = 0; |
| 2368 | goto out; |
| 2369 | } |
| 2370 | } |
| 2371 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2372 | out: |
| 2373 | if (frags > 0) { |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 2374 | struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats); |
Ezequiel Garcia | e19d2dd | 2014-05-19 13:59:54 -0300 | [diff] [blame] | 2375 | struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id); |
| 2376 | |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 2377 | netdev_tx_sent_queue(nq, len); |
| 2378 | |
Ezequiel Garcia | e19d2dd | 2014-05-19 13:59:54 -0300 | [diff] [blame] | 2379 | txq->count += frags; |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 2380 | if (txq->count >= txq->tx_stop_threshold) |
Ezequiel Garcia | e19d2dd | 2014-05-19 13:59:54 -0300 | [diff] [blame] | 2381 | netif_tx_stop_queue(nq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2382 | |
Simon Guinot | 2a90f7e | 2017-01-16 18:08:31 +0100 | [diff] [blame] | 2383 | if (!skb->xmit_more || netif_xmit_stopped(nq) || |
| 2384 | txq->pending + frags > MVNETA_TXQ_DEC_SENT_MASK) |
| 2385 | mvneta_txq_pend_desc_add(pp, txq, frags); |
| 2386 | else |
| 2387 | txq->pending += frags; |
| 2388 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 2389 | u64_stats_update_begin(&stats->syncp); |
| 2390 | stats->tx_packets++; |
Eric Dumazet | 5f478b4 | 2014-12-02 04:30:59 -0800 | [diff] [blame] | 2391 | stats->tx_bytes += len; |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 2392 | u64_stats_update_end(&stats->syncp); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2393 | } else { |
| 2394 | dev->stats.tx_dropped++; |
| 2395 | dev_kfree_skb_any(skb); |
| 2396 | } |
| 2397 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2398 | return NETDEV_TX_OK; |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | /* Free tx resources, when resetting a port */ |
| 2403 | static void mvneta_txq_done_force(struct mvneta_port *pp, |
| 2404 | struct mvneta_tx_queue *txq) |
| 2405 | |
| 2406 | { |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 2407 | struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2408 | int tx_done = txq->count; |
| 2409 | |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 2410 | mvneta_txq_bufs_free(pp, txq, tx_done, nq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2411 | |
| 2412 | /* reset txq */ |
| 2413 | txq->count = 0; |
| 2414 | txq->txq_put_index = 0; |
| 2415 | txq->txq_get_index = 0; |
| 2416 | } |
| 2417 | |
willy tarreau | 6c49897 | 2014-01-16 08:20:12 +0100 | [diff] [blame] | 2418 | /* Handle tx done - called in softirq context. The <cause_tx_done> argument |
| 2419 | * must be a valid cause according to MVNETA_TXQ_INTR_MASK_ALL. |
| 2420 | */ |
Arnaud Ebalard | 0713a86 | 2014-01-16 08:20:18 +0100 | [diff] [blame] | 2421 | static void mvneta_tx_done_gbe(struct mvneta_port *pp, u32 cause_tx_done) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2422 | { |
| 2423 | struct mvneta_tx_queue *txq; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2424 | struct netdev_queue *nq; |
| 2425 | |
willy tarreau | 6c49897 | 2014-01-16 08:20:12 +0100 | [diff] [blame] | 2426 | while (cause_tx_done) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2427 | txq = mvneta_tx_done_policy(pp, cause_tx_done); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2428 | |
| 2429 | nq = netdev_get_tx_queue(pp->dev, txq->id); |
| 2430 | __netif_tx_lock(nq, smp_processor_id()); |
| 2431 | |
Arnaud Ebalard | 0713a86 | 2014-01-16 08:20:18 +0100 | [diff] [blame] | 2432 | if (txq->count) |
| 2433 | mvneta_txq_done(pp, txq); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2434 | |
| 2435 | __netif_tx_unlock(nq); |
| 2436 | cause_tx_done &= ~((1 << txq->id)); |
| 2437 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2438 | } |
| 2439 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 2440 | /* Compute crc8 of the specified address, using a unique algorithm , |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2441 | * according to hw spec, different than generic crc8 algorithm |
| 2442 | */ |
| 2443 | static int mvneta_addr_crc(unsigned char *addr) |
| 2444 | { |
| 2445 | int crc = 0; |
| 2446 | int i; |
| 2447 | |
| 2448 | for (i = 0; i < ETH_ALEN; i++) { |
| 2449 | int j; |
| 2450 | |
| 2451 | crc = (crc ^ addr[i]) << 8; |
| 2452 | for (j = 7; j >= 0; j--) { |
| 2453 | if (crc & (0x100 << j)) |
| 2454 | crc ^= 0x107 << j; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | return crc; |
| 2459 | } |
| 2460 | |
| 2461 | /* This method controls the net device special MAC multicast support. |
| 2462 | * The Special Multicast Table for MAC addresses supports MAC of the form |
| 2463 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF). |
| 2464 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast |
| 2465 | * Table entries in the DA-Filter table. This method set the Special |
| 2466 | * Multicast Table appropriate entry. |
| 2467 | */ |
| 2468 | static void mvneta_set_special_mcast_addr(struct mvneta_port *pp, |
| 2469 | unsigned char last_byte, |
| 2470 | int queue) |
| 2471 | { |
| 2472 | unsigned int smc_table_reg; |
| 2473 | unsigned int tbl_offset; |
| 2474 | unsigned int reg_offset; |
| 2475 | |
| 2476 | /* Register offset from SMC table base */ |
| 2477 | tbl_offset = (last_byte / 4); |
| 2478 | /* Entry offset within the above reg */ |
| 2479 | reg_offset = last_byte % 4; |
| 2480 | |
| 2481 | smc_table_reg = mvreg_read(pp, (MVNETA_DA_FILT_SPEC_MCAST |
| 2482 | + tbl_offset * 4)); |
| 2483 | |
| 2484 | if (queue == -1) |
| 2485 | smc_table_reg &= ~(0xff << (8 * reg_offset)); |
| 2486 | else { |
| 2487 | smc_table_reg &= ~(0xff << (8 * reg_offset)); |
| 2488 | smc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset)); |
| 2489 | } |
| 2490 | |
| 2491 | mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + tbl_offset * 4, |
| 2492 | smc_table_reg); |
| 2493 | } |
| 2494 | |
| 2495 | /* This method controls the network device Other MAC multicast support. |
| 2496 | * The Other Multicast Table is used for multicast of another type. |
| 2497 | * A CRC-8 is used as an index to the Other Multicast Table entries |
| 2498 | * in the DA-Filter table. |
| 2499 | * The method gets the CRC-8 value from the calling routine and |
| 2500 | * sets the Other Multicast Table appropriate entry according to the |
| 2501 | * specified CRC-8 . |
| 2502 | */ |
| 2503 | static void mvneta_set_other_mcast_addr(struct mvneta_port *pp, |
| 2504 | unsigned char crc8, |
| 2505 | int queue) |
| 2506 | { |
| 2507 | unsigned int omc_table_reg; |
| 2508 | unsigned int tbl_offset; |
| 2509 | unsigned int reg_offset; |
| 2510 | |
| 2511 | tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */ |
| 2512 | reg_offset = crc8 % 4; /* Entry offset within the above reg */ |
| 2513 | |
| 2514 | omc_table_reg = mvreg_read(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset); |
| 2515 | |
| 2516 | if (queue == -1) { |
| 2517 | /* Clear accepts frame bit at specified Other DA table entry */ |
| 2518 | omc_table_reg &= ~(0xff << (8 * reg_offset)); |
| 2519 | } else { |
| 2520 | omc_table_reg &= ~(0xff << (8 * reg_offset)); |
| 2521 | omc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset)); |
| 2522 | } |
| 2523 | |
| 2524 | mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset, omc_table_reg); |
| 2525 | } |
| 2526 | |
| 2527 | /* The network device supports multicast using two tables: |
| 2528 | * 1) Special Multicast Table for MAC addresses of the form |
| 2529 | * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF). |
| 2530 | * The MAC DA[7:0] bits are used as a pointer to the Special Multicast |
| 2531 | * Table entries in the DA-Filter table. |
| 2532 | * 2) Other Multicast Table for multicast of another type. A CRC-8 value |
| 2533 | * is used as an index to the Other Multicast Table entries in the |
| 2534 | * DA-Filter table. |
| 2535 | */ |
| 2536 | static int mvneta_mcast_addr_set(struct mvneta_port *pp, unsigned char *p_addr, |
| 2537 | int queue) |
| 2538 | { |
| 2539 | unsigned char crc_result = 0; |
| 2540 | |
| 2541 | if (memcmp(p_addr, "\x01\x00\x5e\x00\x00", 5) == 0) { |
| 2542 | mvneta_set_special_mcast_addr(pp, p_addr[5], queue); |
| 2543 | return 0; |
| 2544 | } |
| 2545 | |
| 2546 | crc_result = mvneta_addr_crc(p_addr); |
| 2547 | if (queue == -1) { |
| 2548 | if (pp->mcast_count[crc_result] == 0) { |
| 2549 | netdev_info(pp->dev, "No valid Mcast for crc8=0x%02x\n", |
| 2550 | crc_result); |
| 2551 | return -EINVAL; |
| 2552 | } |
| 2553 | |
| 2554 | pp->mcast_count[crc_result]--; |
| 2555 | if (pp->mcast_count[crc_result] != 0) { |
| 2556 | netdev_info(pp->dev, |
| 2557 | "After delete there are %d valid Mcast for crc8=0x%02x\n", |
| 2558 | pp->mcast_count[crc_result], crc_result); |
| 2559 | return -EINVAL; |
| 2560 | } |
| 2561 | } else |
| 2562 | pp->mcast_count[crc_result]++; |
| 2563 | |
| 2564 | mvneta_set_other_mcast_addr(pp, crc_result, queue); |
| 2565 | |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | /* Configure Fitering mode of Ethernet port */ |
| 2570 | static void mvneta_rx_unicast_promisc_set(struct mvneta_port *pp, |
| 2571 | int is_promisc) |
| 2572 | { |
| 2573 | u32 port_cfg_reg, val; |
| 2574 | |
| 2575 | port_cfg_reg = mvreg_read(pp, MVNETA_PORT_CONFIG); |
| 2576 | |
| 2577 | val = mvreg_read(pp, MVNETA_TYPE_PRIO); |
| 2578 | |
| 2579 | /* Set / Clear UPM bit in port configuration register */ |
| 2580 | if (is_promisc) { |
| 2581 | /* Accept all Unicast addresses */ |
| 2582 | port_cfg_reg |= MVNETA_UNI_PROMISC_MODE; |
| 2583 | val |= MVNETA_FORCE_UNI; |
| 2584 | mvreg_write(pp, MVNETA_MAC_ADDR_LOW, 0xffff); |
| 2585 | mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, 0xffffffff); |
| 2586 | } else { |
| 2587 | /* Reject all Unicast addresses */ |
| 2588 | port_cfg_reg &= ~MVNETA_UNI_PROMISC_MODE; |
| 2589 | val &= ~MVNETA_FORCE_UNI; |
| 2590 | } |
| 2591 | |
| 2592 | mvreg_write(pp, MVNETA_PORT_CONFIG, port_cfg_reg); |
| 2593 | mvreg_write(pp, MVNETA_TYPE_PRIO, val); |
| 2594 | } |
| 2595 | |
| 2596 | /* register unicast and multicast addresses */ |
| 2597 | static void mvneta_set_rx_mode(struct net_device *dev) |
| 2598 | { |
| 2599 | struct mvneta_port *pp = netdev_priv(dev); |
| 2600 | struct netdev_hw_addr *ha; |
| 2601 | |
| 2602 | if (dev->flags & IFF_PROMISC) { |
| 2603 | /* Accept all: Multicast + Unicast */ |
| 2604 | mvneta_rx_unicast_promisc_set(pp, 1); |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 2605 | mvneta_set_ucast_table(pp, pp->rxq_def); |
| 2606 | mvneta_set_special_mcast_table(pp, pp->rxq_def); |
| 2607 | mvneta_set_other_mcast_table(pp, pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2608 | } else { |
| 2609 | /* Accept single Unicast */ |
| 2610 | mvneta_rx_unicast_promisc_set(pp, 0); |
| 2611 | mvneta_set_ucast_table(pp, -1); |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 2612 | mvneta_mac_addr_set(pp, dev->dev_addr, pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2613 | |
| 2614 | if (dev->flags & IFF_ALLMULTI) { |
| 2615 | /* Accept all multicast */ |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 2616 | mvneta_set_special_mcast_table(pp, pp->rxq_def); |
| 2617 | mvneta_set_other_mcast_table(pp, pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2618 | } else { |
| 2619 | /* Accept only initialized multicast */ |
| 2620 | mvneta_set_special_mcast_table(pp, -1); |
| 2621 | mvneta_set_other_mcast_table(pp, -1); |
| 2622 | |
| 2623 | if (!netdev_mc_empty(dev)) { |
| 2624 | netdev_for_each_mc_addr(ha, dev) { |
| 2625 | mvneta_mcast_addr_set(pp, ha->addr, |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 2626 | pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | /* Interrupt handling - the callback for request_irq() */ |
| 2634 | static irqreturn_t mvneta_isr(int irq, void *dev_id) |
| 2635 | { |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 2636 | struct mvneta_port *pp = (struct mvneta_port *)dev_id; |
| 2637 | |
| 2638 | mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0); |
| 2639 | napi_schedule(&pp->napi); |
| 2640 | |
| 2641 | return IRQ_HANDLED; |
| 2642 | } |
| 2643 | |
| 2644 | /* Interrupt handling - the callback for request_percpu_irq() */ |
| 2645 | static irqreturn_t mvneta_percpu_isr(int irq, void *dev_id) |
| 2646 | { |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 2647 | struct mvneta_pcpu_port *port = (struct mvneta_pcpu_port *)dev_id; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2648 | |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 2649 | disable_percpu_irq(port->pp->dev->irq); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 2650 | napi_schedule(&port->napi); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2651 | |
| 2652 | return IRQ_HANDLED; |
| 2653 | } |
| 2654 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 2655 | static void mvneta_link_change(struct mvneta_port *pp) |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 2656 | { |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 2657 | u32 gmac_stat = mvreg_read(pp, MVNETA_GMAC_STATUS); |
| 2658 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 2659 | phylink_mac_change(pp->phylink, !!(gmac_stat & MVNETA_GMAC_LINK_UP)); |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 2660 | } |
| 2661 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2662 | /* NAPI handler |
| 2663 | * Bits 0 - 7 of the causeRxTx register indicate that are transmitted |
| 2664 | * packets on the corresponding TXQ (Bit 0 is for TX queue 1). |
| 2665 | * Bits 8 -15 of the cause Rx Tx register indicate that are received |
| 2666 | * packets on the corresponding RXQ (Bit 8 is for RX queue 0). |
| 2667 | * Each CPU has its own causeRxTx register |
| 2668 | */ |
| 2669 | static int mvneta_poll(struct napi_struct *napi, int budget) |
| 2670 | { |
| 2671 | int rx_done = 0; |
| 2672 | u32 cause_rx_tx; |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2673 | int rx_queue; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2674 | struct mvneta_port *pp = netdev_priv(napi->dev); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 2675 | struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2676 | |
| 2677 | if (!netif_running(pp->dev)) { |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 2678 | napi_complete(napi); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2679 | return rx_done; |
| 2680 | } |
| 2681 | |
| 2682 | /* Read cause register */ |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 2683 | cause_rx_tx = mvreg_read(pp, MVNETA_INTR_NEW_CAUSE); |
| 2684 | if (cause_rx_tx & MVNETA_MISCINTR_INTR_MASK) { |
| 2685 | u32 cause_misc = mvreg_read(pp, MVNETA_INTR_MISC_CAUSE); |
| 2686 | |
| 2687 | mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 2688 | |
| 2689 | if (cause_misc & (MVNETA_CAUSE_PHY_STATUS_CHANGE | |
| 2690 | MVNETA_CAUSE_LINK_CHANGE | |
| 2691 | MVNETA_CAUSE_PSC_SYNC_CHANGE)) |
| 2692 | mvneta_link_change(pp); |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 2693 | } |
willy tarreau | 71f6d1b | 2014-01-16 08:20:11 +0100 | [diff] [blame] | 2694 | |
| 2695 | /* Release Tx descriptors */ |
| 2696 | if (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL) { |
Arnaud Ebalard | 0713a86 | 2014-01-16 08:20:18 +0100 | [diff] [blame] | 2697 | mvneta_tx_done_gbe(pp, (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL)); |
willy tarreau | 71f6d1b | 2014-01-16 08:20:11 +0100 | [diff] [blame] | 2698 | cause_rx_tx &= ~MVNETA_TX_INTR_MASK_ALL; |
| 2699 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2700 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 2701 | /* For the case where the last mvneta_poll did not process all |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2702 | * RX packets |
| 2703 | */ |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2704 | rx_queue = fls(((cause_rx_tx >> 8) & 0xff)); |
| 2705 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 2706 | cause_rx_tx |= pp->neta_armada3700 ? pp->cause_rx_tx : |
| 2707 | port->cause_rx_tx; |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2708 | |
| 2709 | if (rx_queue) { |
| 2710 | rx_queue = rx_queue - 1; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2711 | if (pp->bm_priv) |
| 2712 | rx_done = mvneta_rx_hwbm(pp, budget, &pp->rxqs[rx_queue]); |
| 2713 | else |
| 2714 | rx_done = mvneta_rx_swbm(pp, budget, &pp->rxqs[rx_queue]); |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 2717 | if (rx_done < budget) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2718 | cause_rx_tx = 0; |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 2719 | napi_complete_done(napi, rx_done); |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 2720 | |
| 2721 | if (pp->neta_armada3700) { |
| 2722 | unsigned long flags; |
| 2723 | |
| 2724 | local_irq_save(flags); |
| 2725 | mvreg_write(pp, MVNETA_INTR_NEW_MASK, |
| 2726 | MVNETA_RX_INTR_MASK(rxq_number) | |
| 2727 | MVNETA_TX_INTR_MASK(txq_number) | |
| 2728 | MVNETA_MISCINTR_INTR_MASK); |
| 2729 | local_irq_restore(flags); |
| 2730 | } else { |
| 2731 | enable_percpu_irq(pp->dev->irq, 0); |
| 2732 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2733 | } |
| 2734 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 2735 | if (pp->neta_armada3700) |
| 2736 | pp->cause_rx_tx = cause_rx_tx; |
| 2737 | else |
| 2738 | port->cause_rx_tx = cause_rx_tx; |
| 2739 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2740 | return rx_done; |
| 2741 | } |
| 2742 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2743 | /* Handle rxq fill: allocates rxq skbs; called when initializing a port */ |
| 2744 | static int mvneta_rxq_fill(struct mvneta_port *pp, struct mvneta_rx_queue *rxq, |
| 2745 | int num) |
| 2746 | { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2747 | int i; |
| 2748 | |
| 2749 | for (i = 0; i < num; i++) { |
willy tarreau | a1a65ab | 2014-01-16 08:20:13 +0100 | [diff] [blame] | 2750 | memset(rxq->descs + i, 0, sizeof(struct mvneta_rx_desc)); |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 2751 | if (mvneta_rx_refill(pp, rxq->descs + i, rxq) != 0) { |
willy tarreau | a1a65ab | 2014-01-16 08:20:13 +0100 | [diff] [blame] | 2752 | netdev_err(pp->dev, "%s:rxq %d, %d of %d buffs filled\n", |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2753 | __func__, rxq->id, i, num); |
| 2754 | break; |
| 2755 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /* Add this number of RX descriptors as non occupied (ready to |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 2759 | * get packets) |
| 2760 | */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2761 | mvneta_rxq_non_occup_desc_add(pp, rxq, i); |
| 2762 | |
| 2763 | return i; |
| 2764 | } |
| 2765 | |
| 2766 | /* Free all packets pending transmit from all TXQs and reset TX port */ |
| 2767 | static void mvneta_tx_reset(struct mvneta_port *pp) |
| 2768 | { |
| 2769 | int queue; |
| 2770 | |
Ezequiel Garcia | 9672850 | 2014-05-22 20:06:59 -0300 | [diff] [blame] | 2771 | /* free the skb's in the tx ring */ |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2772 | for (queue = 0; queue < txq_number; queue++) |
| 2773 | mvneta_txq_done_force(pp, &pp->txqs[queue]); |
| 2774 | |
| 2775 | mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET); |
| 2776 | mvreg_write(pp, MVNETA_PORT_TX_RESET, 0); |
| 2777 | } |
| 2778 | |
| 2779 | static void mvneta_rx_reset(struct mvneta_port *pp) |
| 2780 | { |
| 2781 | mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET); |
| 2782 | mvreg_write(pp, MVNETA_PORT_RX_RESET, 0); |
| 2783 | } |
| 2784 | |
| 2785 | /* Rx/Tx queue initialization/cleanup methods */ |
| 2786 | |
| 2787 | /* Create a specified RX queue */ |
| 2788 | static int mvneta_rxq_init(struct mvneta_port *pp, |
| 2789 | struct mvneta_rx_queue *rxq) |
| 2790 | |
| 2791 | { |
| 2792 | rxq->size = pp->rx_ring_size; |
| 2793 | |
| 2794 | /* Allocate memory for RX descriptors */ |
| 2795 | rxq->descs = dma_alloc_coherent(pp->dev->dev.parent, |
| 2796 | rxq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2797 | &rxq->descs_phys, GFP_KERNEL); |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 2798 | if (!rxq->descs) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2799 | return -ENOMEM; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2800 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2801 | rxq->last_desc = rxq->size - 1; |
| 2802 | |
| 2803 | /* Set Rx descriptors queue starting address */ |
| 2804 | mvreg_write(pp, MVNETA_RXQ_BASE_ADDR_REG(rxq->id), rxq->descs_phys); |
| 2805 | mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), rxq->size); |
| 2806 | |
| 2807 | /* Set Offset */ |
Marcin Wojtas | 8d5047c | 2016-12-01 18:03:07 +0100 | [diff] [blame] | 2808 | mvneta_rxq_offset_set(pp, rxq, NET_SKB_PAD - pp->rx_offset_correction); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2809 | |
| 2810 | /* Set coalescing pkts and time */ |
| 2811 | mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal); |
| 2812 | mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal); |
| 2813 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2814 | if (!pp->bm_priv) { |
| 2815 | /* Fill RXQ with buffers from RX pool */ |
| 2816 | mvneta_rxq_buf_size_set(pp, rxq, |
| 2817 | MVNETA_RX_BUF_SIZE(pp->pkt_size)); |
| 2818 | mvneta_rxq_bm_disable(pp, rxq); |
Gregory CLEMENT | e9f6499 | 2016-12-01 18:03:05 +0100 | [diff] [blame] | 2819 | mvneta_rxq_fill(pp, rxq, rxq->size); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2820 | } else { |
| 2821 | mvneta_rxq_bm_enable(pp, rxq); |
| 2822 | mvneta_rxq_long_pool_set(pp, rxq); |
| 2823 | mvneta_rxq_short_pool_set(pp, rxq); |
Gregory CLEMENT | e9f6499 | 2016-12-01 18:03:05 +0100 | [diff] [blame] | 2824 | mvneta_rxq_non_occup_desc_add(pp, rxq, rxq->size); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 2825 | } |
| 2826 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2827 | return 0; |
| 2828 | } |
| 2829 | |
| 2830 | /* Cleanup Rx queue */ |
| 2831 | static void mvneta_rxq_deinit(struct mvneta_port *pp, |
| 2832 | struct mvneta_rx_queue *rxq) |
| 2833 | { |
| 2834 | mvneta_rxq_drop_pkts(pp, rxq); |
| 2835 | |
| 2836 | if (rxq->descs) |
| 2837 | dma_free_coherent(pp->dev->dev.parent, |
| 2838 | rxq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2839 | rxq->descs, |
| 2840 | rxq->descs_phys); |
| 2841 | |
| 2842 | rxq->descs = NULL; |
| 2843 | rxq->last_desc = 0; |
| 2844 | rxq->next_desc_to_proc = 0; |
| 2845 | rxq->descs_phys = 0; |
| 2846 | } |
| 2847 | |
| 2848 | /* Create and initialize a tx queue */ |
| 2849 | static int mvneta_txq_init(struct mvneta_port *pp, |
| 2850 | struct mvneta_tx_queue *txq) |
| 2851 | { |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 2852 | int cpu; |
| 2853 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2854 | txq->size = pp->tx_ring_size; |
| 2855 | |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 2856 | /* A queue must always have room for at least one skb. |
| 2857 | * Therefore, stop the queue when the free entries reaches |
| 2858 | * the maximum number of descriptors per skb. |
| 2859 | */ |
| 2860 | txq->tx_stop_threshold = txq->size - MVNETA_MAX_SKB_DESCS; |
| 2861 | txq->tx_wake_threshold = txq->tx_stop_threshold / 2; |
| 2862 | |
| 2863 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2864 | /* Allocate memory for TX descriptors */ |
| 2865 | txq->descs = dma_alloc_coherent(pp->dev->dev.parent, |
| 2866 | txq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2867 | &txq->descs_phys, GFP_KERNEL); |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 2868 | if (!txq->descs) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2869 | return -ENOMEM; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2870 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2871 | txq->last_desc = txq->size - 1; |
| 2872 | |
| 2873 | /* Set maximum bandwidth for enabled TXQs */ |
| 2874 | mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0x03ffffff); |
| 2875 | mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0x3fffffff); |
| 2876 | |
| 2877 | /* Set Tx descriptors queue starting address */ |
| 2878 | mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), txq->descs_phys); |
| 2879 | mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), txq->size); |
| 2880 | |
Markus Elfring | d441b68 | 2017-04-16 22:11:22 +0200 | [diff] [blame] | 2881 | txq->tx_skb = kmalloc_array(txq->size, sizeof(*txq->tx_skb), |
| 2882 | GFP_KERNEL); |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 2883 | if (!txq->tx_skb) { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2884 | dma_free_coherent(pp->dev->dev.parent, |
| 2885 | txq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2886 | txq->descs, txq->descs_phys); |
| 2887 | return -ENOMEM; |
| 2888 | } |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2889 | |
| 2890 | /* Allocate DMA buffers for TSO MAC/IP/TCP headers */ |
| 2891 | txq->tso_hdrs = dma_alloc_coherent(pp->dev->dev.parent, |
| 2892 | txq->size * TSO_HEADER_SIZE, |
| 2893 | &txq->tso_hdrs_phys, GFP_KERNEL); |
Markus Elfring | f95936c | 2017-04-16 22:45:33 +0200 | [diff] [blame] | 2894 | if (!txq->tso_hdrs) { |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2895 | kfree(txq->tx_skb); |
| 2896 | dma_free_coherent(pp->dev->dev.parent, |
| 2897 | txq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2898 | txq->descs, txq->descs_phys); |
| 2899 | return -ENOMEM; |
| 2900 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2901 | mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal); |
| 2902 | |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 2903 | /* Setup XPS mapping */ |
| 2904 | if (txq_number > 1) |
| 2905 | cpu = txq->id % num_present_cpus(); |
| 2906 | else |
| 2907 | cpu = pp->rxq_def % num_present_cpus(); |
| 2908 | cpumask_set_cpu(cpu, &txq->affinity_mask); |
| 2909 | netif_set_xps_queue(pp->dev, &txq->affinity_mask, txq->id); |
| 2910 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2911 | return 0; |
| 2912 | } |
| 2913 | |
| 2914 | /* Free allocated resources when mvneta_txq_init() fails to allocate memory*/ |
| 2915 | static void mvneta_txq_deinit(struct mvneta_port *pp, |
| 2916 | struct mvneta_tx_queue *txq) |
| 2917 | { |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 2918 | struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id); |
| 2919 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2920 | kfree(txq->tx_skb); |
| 2921 | |
Ezequiel Garcia | 2adb719d | 2014-05-19 13:59:55 -0300 | [diff] [blame] | 2922 | if (txq->tso_hdrs) |
| 2923 | dma_free_coherent(pp->dev->dev.parent, |
| 2924 | txq->size * TSO_HEADER_SIZE, |
| 2925 | txq->tso_hdrs, txq->tso_hdrs_phys); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2926 | if (txq->descs) |
| 2927 | dma_free_coherent(pp->dev->dev.parent, |
| 2928 | txq->size * MVNETA_DESC_ALIGNED_SIZE, |
| 2929 | txq->descs, txq->descs_phys); |
| 2930 | |
Marcin Wojtas | a29b623 | 2017-01-16 18:08:32 +0100 | [diff] [blame] | 2931 | netdev_tx_reset_queue(nq); |
| 2932 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2933 | txq->descs = NULL; |
| 2934 | txq->last_desc = 0; |
| 2935 | txq->next_desc_to_proc = 0; |
| 2936 | txq->descs_phys = 0; |
| 2937 | |
| 2938 | /* Set minimum bandwidth for disabled TXQs */ |
| 2939 | mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0); |
| 2940 | mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0); |
| 2941 | |
| 2942 | /* Set Tx descriptors queue starting address and size */ |
| 2943 | mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), 0); |
| 2944 | mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), 0); |
| 2945 | } |
| 2946 | |
| 2947 | /* Cleanup all Tx queues */ |
| 2948 | static void mvneta_cleanup_txqs(struct mvneta_port *pp) |
| 2949 | { |
| 2950 | int queue; |
| 2951 | |
| 2952 | for (queue = 0; queue < txq_number; queue++) |
| 2953 | mvneta_txq_deinit(pp, &pp->txqs[queue]); |
| 2954 | } |
| 2955 | |
| 2956 | /* Cleanup all Rx queues */ |
| 2957 | static void mvneta_cleanup_rxqs(struct mvneta_port *pp) |
| 2958 | { |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2959 | int queue; |
| 2960 | |
Yelena Krivosheev | ca5902a | 2017-12-19 17:59:46 +0100 | [diff] [blame] | 2961 | for (queue = 0; queue < rxq_number; queue++) |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2962 | mvneta_rxq_deinit(pp, &pp->rxqs[queue]); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | |
| 2966 | /* Init all Rx queues */ |
| 2967 | static int mvneta_setup_rxqs(struct mvneta_port *pp) |
| 2968 | { |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 2969 | int queue; |
| 2970 | |
| 2971 | for (queue = 0; queue < rxq_number; queue++) { |
| 2972 | int err = mvneta_rxq_init(pp, &pp->rxqs[queue]); |
| 2973 | |
| 2974 | if (err) { |
| 2975 | netdev_err(pp->dev, "%s: can't create rxq=%d\n", |
| 2976 | __func__, queue); |
| 2977 | mvneta_cleanup_rxqs(pp); |
| 2978 | return err; |
| 2979 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | return 0; |
| 2983 | } |
| 2984 | |
| 2985 | /* Init all tx queues */ |
| 2986 | static int mvneta_setup_txqs(struct mvneta_port *pp) |
| 2987 | { |
| 2988 | int queue; |
| 2989 | |
| 2990 | for (queue = 0; queue < txq_number; queue++) { |
| 2991 | int err = mvneta_txq_init(pp, &pp->txqs[queue]); |
| 2992 | if (err) { |
| 2993 | netdev_err(pp->dev, "%s: can't create txq=%d\n", |
| 2994 | __func__, queue); |
| 2995 | mvneta_cleanup_txqs(pp); |
| 2996 | return err; |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | return 0; |
| 3001 | } |
| 3002 | |
| 3003 | static void mvneta_start_dev(struct mvneta_port *pp) |
| 3004 | { |
Gregory CLEMENT | 6b125d6 | 2016-02-04 22:09:25 +0100 | [diff] [blame] | 3005 | int cpu; |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3006 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3007 | mvneta_max_rx_size_set(pp, pp->pkt_size); |
| 3008 | mvneta_txq_max_tx_size_set(pp, pp->pkt_size); |
| 3009 | |
| 3010 | /* start the Rx/Tx activity */ |
| 3011 | mvneta_port_enable(pp); |
| 3012 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3013 | if (!pp->neta_armada3700) { |
| 3014 | /* Enable polling on the port */ |
| 3015 | for_each_online_cpu(cpu) { |
| 3016 | struct mvneta_pcpu_port *port = |
| 3017 | per_cpu_ptr(pp->ports, cpu); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3018 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3019 | napi_enable(&port->napi); |
| 3020 | } |
| 3021 | } else { |
| 3022 | napi_enable(&pp->napi); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3023 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3024 | |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3025 | /* Unmask interrupts. It has to be done from each CPU */ |
Gregory CLEMENT | 6b125d6 | 2016-02-04 22:09:25 +0100 | [diff] [blame] | 3026 | on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); |
| 3027 | |
Stas Sergeev | 898b2970 | 2015-04-01 20:32:49 +0300 | [diff] [blame] | 3028 | mvreg_write(pp, MVNETA_INTR_MISC_MASK, |
| 3029 | MVNETA_CAUSE_PHY_STATUS_CHANGE | |
| 3030 | MVNETA_CAUSE_LINK_CHANGE | |
| 3031 | MVNETA_CAUSE_PSC_SYNC_CHANGE); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3032 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3033 | phylink_start(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3034 | netif_tx_start_all_queues(pp->dev); |
| 3035 | } |
| 3036 | |
| 3037 | static void mvneta_stop_dev(struct mvneta_port *pp) |
| 3038 | { |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3039 | unsigned int cpu; |
| 3040 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3041 | phylink_stop(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3042 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3043 | if (!pp->neta_armada3700) { |
| 3044 | for_each_online_cpu(cpu) { |
| 3045 | struct mvneta_pcpu_port *port = |
| 3046 | per_cpu_ptr(pp->ports, cpu); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3047 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3048 | napi_disable(&port->napi); |
| 3049 | } |
| 3050 | } else { |
| 3051 | napi_disable(&pp->napi); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 3052 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3053 | |
| 3054 | netif_carrier_off(pp->dev); |
| 3055 | |
| 3056 | mvneta_port_down(pp); |
| 3057 | netif_tx_stop_all_queues(pp->dev); |
| 3058 | |
| 3059 | /* Stop the port activity */ |
| 3060 | mvneta_port_disable(pp); |
| 3061 | |
| 3062 | /* Clear all ethernet port interrupts */ |
Gregory CLEMENT | db488c1 | 2016-02-04 22:09:27 +0100 | [diff] [blame] | 3063 | on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3064 | |
| 3065 | /* Mask all ethernet port interrupts */ |
Gregory CLEMENT | db488c1 | 2016-02-04 22:09:27 +0100 | [diff] [blame] | 3066 | on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3067 | |
| 3068 | mvneta_tx_reset(pp); |
| 3069 | mvneta_rx_reset(pp); |
| 3070 | } |
| 3071 | |
Marcin Wojtas | db5dd0d | 2016-04-01 15:21:18 +0200 | [diff] [blame] | 3072 | static void mvneta_percpu_enable(void *arg) |
| 3073 | { |
| 3074 | struct mvneta_port *pp = arg; |
| 3075 | |
| 3076 | enable_percpu_irq(pp->dev->irq, IRQ_TYPE_NONE); |
| 3077 | } |
| 3078 | |
| 3079 | static void mvneta_percpu_disable(void *arg) |
| 3080 | { |
| 3081 | struct mvneta_port *pp = arg; |
| 3082 | |
| 3083 | disable_percpu_irq(pp->dev->irq); |
| 3084 | } |
| 3085 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3086 | /* Change the device mtu */ |
| 3087 | static int mvneta_change_mtu(struct net_device *dev, int mtu) |
| 3088 | { |
| 3089 | struct mvneta_port *pp = netdev_priv(dev); |
| 3090 | int ret; |
| 3091 | |
Jarod Wilson | 5777987 | 2016-10-17 15:54:06 -0400 | [diff] [blame] | 3092 | if (!IS_ALIGNED(MVNETA_RX_PKT_SIZE(mtu), 8)) { |
| 3093 | netdev_info(dev, "Illegal MTU value %d, rounding to %d\n", |
| 3094 | mtu, ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8)); |
| 3095 | mtu = ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8); |
| 3096 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3097 | |
| 3098 | dev->mtu = mtu; |
| 3099 | |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 3100 | if (!netif_running(dev)) { |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 3101 | if (pp->bm_priv) |
| 3102 | mvneta_bm_update_mtu(pp, mtu); |
| 3103 | |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 3104 | netdev_update_features(dev); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3105 | return 0; |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 3106 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3107 | |
Thomas Petazzoni | 6a20c17 | 2012-11-19 11:41:25 +0100 | [diff] [blame] | 3108 | /* The interface is running, so we have to force a |
Ezequiel Garcia | a92dbd9 | 2014-05-22 20:06:58 -0300 | [diff] [blame] | 3109 | * reallocation of the queues |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3110 | */ |
| 3111 | mvneta_stop_dev(pp); |
Marcin Wojtas | db5dd0d | 2016-04-01 15:21:18 +0200 | [diff] [blame] | 3112 | on_each_cpu(mvneta_percpu_disable, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3113 | |
| 3114 | mvneta_cleanup_txqs(pp); |
| 3115 | mvneta_cleanup_rxqs(pp); |
| 3116 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 3117 | if (pp->bm_priv) |
| 3118 | mvneta_bm_update_mtu(pp, mtu); |
| 3119 | |
Ezequiel Garcia | a92dbd9 | 2014-05-22 20:06:58 -0300 | [diff] [blame] | 3120 | pp->pkt_size = MVNETA_RX_PKT_SIZE(dev->mtu); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 3121 | pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) + |
| 3122 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3123 | |
| 3124 | ret = mvneta_setup_rxqs(pp); |
| 3125 | if (ret) { |
Ezequiel Garcia | a92dbd9 | 2014-05-22 20:06:58 -0300 | [diff] [blame] | 3126 | netdev_err(dev, "unable to setup rxqs after MTU change\n"); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3127 | return ret; |
| 3128 | } |
| 3129 | |
Ezequiel Garcia | a92dbd9 | 2014-05-22 20:06:58 -0300 | [diff] [blame] | 3130 | ret = mvneta_setup_txqs(pp); |
| 3131 | if (ret) { |
| 3132 | netdev_err(dev, "unable to setup txqs after MTU change\n"); |
| 3133 | return ret; |
| 3134 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3135 | |
Marcin Wojtas | db5dd0d | 2016-04-01 15:21:18 +0200 | [diff] [blame] | 3136 | on_each_cpu(mvneta_percpu_enable, pp, true); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3137 | mvneta_start_dev(pp); |
| 3138 | mvneta_port_up(pp); |
| 3139 | |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 3140 | netdev_update_features(dev); |
| 3141 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3142 | return 0; |
| 3143 | } |
| 3144 | |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 3145 | static netdev_features_t mvneta_fix_features(struct net_device *dev, |
| 3146 | netdev_features_t features) |
| 3147 | { |
| 3148 | struct mvneta_port *pp = netdev_priv(dev); |
| 3149 | |
| 3150 | if (pp->tx_csum_limit && dev->mtu > pp->tx_csum_limit) { |
| 3151 | features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 3152 | netdev_info(dev, |
| 3153 | "Disable IP checksum for MTU greater than %dB\n", |
| 3154 | pp->tx_csum_limit); |
| 3155 | } |
| 3156 | |
| 3157 | return features; |
| 3158 | } |
| 3159 | |
Thomas Petazzoni | 8cc3e43 | 2013-06-04 04:52:23 +0000 | [diff] [blame] | 3160 | /* Get mac address */ |
| 3161 | static void mvneta_get_mac_addr(struct mvneta_port *pp, unsigned char *addr) |
| 3162 | { |
| 3163 | u32 mac_addr_l, mac_addr_h; |
| 3164 | |
| 3165 | mac_addr_l = mvreg_read(pp, MVNETA_MAC_ADDR_LOW); |
| 3166 | mac_addr_h = mvreg_read(pp, MVNETA_MAC_ADDR_HIGH); |
| 3167 | addr[0] = (mac_addr_h >> 24) & 0xFF; |
| 3168 | addr[1] = (mac_addr_h >> 16) & 0xFF; |
| 3169 | addr[2] = (mac_addr_h >> 8) & 0xFF; |
| 3170 | addr[3] = mac_addr_h & 0xFF; |
| 3171 | addr[4] = (mac_addr_l >> 8) & 0xFF; |
| 3172 | addr[5] = mac_addr_l & 0xFF; |
| 3173 | } |
| 3174 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3175 | /* Handle setting mac address */ |
| 3176 | static int mvneta_set_mac_addr(struct net_device *dev, void *addr) |
| 3177 | { |
| 3178 | struct mvneta_port *pp = netdev_priv(dev); |
Ezequiel Garcia | e68de36 | 2014-05-22 20:07:00 -0300 | [diff] [blame] | 3179 | struct sockaddr *sockaddr = addr; |
| 3180 | int ret; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3181 | |
Ezequiel Garcia | e68de36 | 2014-05-22 20:07:00 -0300 | [diff] [blame] | 3182 | ret = eth_prepare_mac_addr_change(dev, addr); |
| 3183 | if (ret < 0) |
| 3184 | return ret; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3185 | /* Remove previous address table entry */ |
| 3186 | mvneta_mac_addr_set(pp, dev->dev_addr, -1); |
| 3187 | |
| 3188 | /* Set new addr in hw */ |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 3189 | mvneta_mac_addr_set(pp, sockaddr->sa_data, pp->rxq_def); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3190 | |
Ezequiel Garcia | e68de36 | 2014-05-22 20:07:00 -0300 | [diff] [blame] | 3191 | eth_commit_mac_addr_change(dev, addr); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3192 | return 0; |
| 3193 | } |
| 3194 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3195 | static void mvneta_validate(struct net_device *ndev, unsigned long *supported, |
| 3196 | struct phylink_link_state *state) |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3197 | { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3198 | __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3199 | |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3200 | /* We only support QSGMII, SGMII, 802.3z and RGMII modes */ |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3201 | if (state->interface != PHY_INTERFACE_MODE_NA && |
| 3202 | state->interface != PHY_INTERFACE_MODE_QSGMII && |
| 3203 | state->interface != PHY_INTERFACE_MODE_SGMII && |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3204 | !phy_interface_mode_is_8023z(state->interface) && |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3205 | !phy_interface_mode_is_rgmii(state->interface)) { |
| 3206 | bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 3207 | return; |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3208 | } |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3209 | |
| 3210 | /* Allow all the expected bits */ |
| 3211 | phylink_set(mask, Autoneg); |
| 3212 | phylink_set_port_modes(mask); |
| 3213 | |
| 3214 | /* Half-duplex at speeds higher than 100Mbit is unsupported */ |
| 3215 | phylink_set(mask, 1000baseT_Full); |
| 3216 | phylink_set(mask, 1000baseX_Full); |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3217 | |
| 3218 | if (!phy_interface_mode_is_8023z(state->interface)) { |
| 3219 | /* 10M and 100M are only supported in non-802.3z mode */ |
| 3220 | phylink_set(mask, 10baseT_Half); |
| 3221 | phylink_set(mask, 10baseT_Full); |
| 3222 | phylink_set(mask, 100baseT_Half); |
| 3223 | phylink_set(mask, 100baseT_Full); |
| 3224 | } |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3225 | |
| 3226 | bitmap_and(supported, supported, mask, |
| 3227 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 3228 | bitmap_and(state->advertising, state->advertising, mask, |
| 3229 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3232 | static int mvneta_mac_link_state(struct net_device *ndev, |
| 3233 | struct phylink_link_state *state) |
| 3234 | { |
| 3235 | struct mvneta_port *pp = netdev_priv(ndev); |
| 3236 | u32 gmac_stat; |
| 3237 | |
| 3238 | gmac_stat = mvreg_read(pp, MVNETA_GMAC_STATUS); |
| 3239 | |
| 3240 | if (gmac_stat & MVNETA_GMAC_SPEED_1000) |
| 3241 | state->speed = SPEED_1000; |
| 3242 | else if (gmac_stat & MVNETA_GMAC_SPEED_100) |
| 3243 | state->speed = SPEED_100; |
| 3244 | else |
| 3245 | state->speed = SPEED_10; |
| 3246 | |
| 3247 | state->an_complete = !!(gmac_stat & MVNETA_GMAC_AN_COMPLETE); |
| 3248 | state->link = !!(gmac_stat & MVNETA_GMAC_LINK_UP); |
| 3249 | state->duplex = !!(gmac_stat & MVNETA_GMAC_FULL_DUPLEX); |
| 3250 | |
| 3251 | state->pause = 0; |
| 3252 | |
| 3253 | return 1; |
| 3254 | } |
| 3255 | |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3256 | static void mvneta_mac_an_restart(struct net_device *ndev) |
| 3257 | { |
| 3258 | struct mvneta_port *pp = netdev_priv(ndev); |
| 3259 | u32 gmac_an = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG); |
| 3260 | |
| 3261 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, |
| 3262 | gmac_an | MVNETA_GMAC_INBAND_RESTART_AN); |
| 3263 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, |
| 3264 | gmac_an & ~MVNETA_GMAC_INBAND_RESTART_AN); |
| 3265 | } |
| 3266 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3267 | static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, |
| 3268 | const struct phylink_link_state *state) |
| 3269 | { |
| 3270 | struct mvneta_port *pp = netdev_priv(ndev); |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3271 | u32 new_ctrl0, gmac_ctrl0 = mvreg_read(pp, MVNETA_GMAC_CTRL_0); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3272 | u32 new_ctrl2, gmac_ctrl2 = mvreg_read(pp, MVNETA_GMAC_CTRL_2); |
| 3273 | u32 new_clk, gmac_clk = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER); |
| 3274 | u32 new_an, gmac_an = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG); |
| 3275 | |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3276 | new_ctrl0 = gmac_ctrl0 & ~MVNETA_GMAC0_PORT_1000BASE_X; |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 3277 | new_ctrl2 = gmac_ctrl2 & ~(MVNETA_GMAC2_INBAND_AN_ENABLE | |
| 3278 | MVNETA_GMAC2_PORT_RESET); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3279 | new_clk = gmac_clk & ~MVNETA_GMAC_1MS_CLOCK_ENABLE; |
| 3280 | new_an = gmac_an & ~(MVNETA_GMAC_INBAND_AN_ENABLE | |
| 3281 | MVNETA_GMAC_INBAND_RESTART_AN | |
| 3282 | MVNETA_GMAC_CONFIG_MII_SPEED | |
| 3283 | MVNETA_GMAC_CONFIG_GMII_SPEED | |
| 3284 | MVNETA_GMAC_AN_SPEED_EN | |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3285 | MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL | |
| 3286 | MVNETA_GMAC_CONFIG_FLOW_CTRL | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3287 | MVNETA_GMAC_AN_FLOW_CTRL_EN | |
| 3288 | MVNETA_GMAC_CONFIG_FULL_DUPLEX | |
| 3289 | MVNETA_GMAC_AN_DUPLEX_EN); |
| 3290 | |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 3291 | /* Even though it might look weird, when we're configured in |
| 3292 | * SGMII or QSGMII mode, the RGMII bit needs to be set. |
| 3293 | */ |
| 3294 | new_ctrl2 |= MVNETA_GMAC2_PORT_RGMII; |
| 3295 | |
| 3296 | if (state->interface == PHY_INTERFACE_MODE_QSGMII || |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3297 | state->interface == PHY_INTERFACE_MODE_SGMII || |
| 3298 | phy_interface_mode_is_8023z(state->interface)) |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 3299 | new_ctrl2 |= MVNETA_GMAC2_PCS_ENABLE; |
| 3300 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3301 | if (!phylink_autoneg_inband(mode)) { |
| 3302 | /* Phy or fixed speed */ |
| 3303 | if (state->duplex) |
| 3304 | new_an |= MVNETA_GMAC_CONFIG_FULL_DUPLEX; |
| 3305 | |
| 3306 | if (state->speed == SPEED_1000) |
| 3307 | new_an |= MVNETA_GMAC_CONFIG_GMII_SPEED; |
| 3308 | else if (state->speed == SPEED_100) |
| 3309 | new_an |= MVNETA_GMAC_CONFIG_MII_SPEED; |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3310 | } else if (state->interface == PHY_INTERFACE_MODE_SGMII) { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3311 | /* SGMII mode receives the state from the PHY */ |
| 3312 | new_ctrl2 |= MVNETA_GMAC2_INBAND_AN_ENABLE; |
| 3313 | new_clk |= MVNETA_GMAC_1MS_CLOCK_ENABLE; |
| 3314 | new_an = (new_an & ~(MVNETA_GMAC_FORCE_LINK_DOWN | |
| 3315 | MVNETA_GMAC_FORCE_LINK_PASS)) | |
| 3316 | MVNETA_GMAC_INBAND_AN_ENABLE | |
| 3317 | MVNETA_GMAC_AN_SPEED_EN | |
| 3318 | MVNETA_GMAC_AN_DUPLEX_EN; |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3319 | } else { |
| 3320 | /* 802.3z negotiation - only 1000base-X */ |
| 3321 | new_ctrl0 |= MVNETA_GMAC0_PORT_1000BASE_X; |
| 3322 | new_clk |= MVNETA_GMAC_1MS_CLOCK_ENABLE; |
| 3323 | new_an = (new_an & ~(MVNETA_GMAC_FORCE_LINK_DOWN | |
| 3324 | MVNETA_GMAC_FORCE_LINK_PASS)) | |
| 3325 | MVNETA_GMAC_INBAND_AN_ENABLE | |
| 3326 | MVNETA_GMAC_CONFIG_GMII_SPEED | |
| 3327 | /* The MAC only supports FD mode */ |
| 3328 | MVNETA_GMAC_CONFIG_FULL_DUPLEX; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | /* Armada 370 documentation says we can only change the port mode |
| 3332 | * and in-band enable when the link is down, so force it down |
| 3333 | * while making these changes. We also do this for GMAC_CTRL2 */ |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3334 | if ((new_ctrl0 ^ gmac_ctrl0) & MVNETA_GMAC0_PORT_1000BASE_X || |
| 3335 | (new_ctrl2 ^ gmac_ctrl2) & MVNETA_GMAC2_INBAND_AN_ENABLE || |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3336 | (new_an ^ gmac_an) & MVNETA_GMAC_INBAND_AN_ENABLE) { |
| 3337 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, |
| 3338 | (gmac_an & ~MVNETA_GMAC_FORCE_LINK_PASS) | |
| 3339 | MVNETA_GMAC_FORCE_LINK_DOWN); |
| 3340 | } |
| 3341 | |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3342 | if (new_ctrl0 != gmac_ctrl0) |
| 3343 | mvreg_write(pp, MVNETA_GMAC_CTRL_0, new_ctrl0); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3344 | if (new_ctrl2 != gmac_ctrl2) |
| 3345 | mvreg_write(pp, MVNETA_GMAC_CTRL_2, new_ctrl2); |
| 3346 | if (new_clk != gmac_clk) |
| 3347 | mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, new_clk); |
| 3348 | if (new_an != gmac_an) |
| 3349 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, new_an); |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 3350 | |
| 3351 | if (gmac_ctrl2 & MVNETA_GMAC2_PORT_RESET) { |
| 3352 | while ((mvreg_read(pp, MVNETA_GMAC_CTRL_2) & |
| 3353 | MVNETA_GMAC2_PORT_RESET) != 0) |
| 3354 | continue; |
| 3355 | } |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | static void mvneta_mac_link_down(struct net_device *ndev, unsigned int mode) |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3359 | { |
| 3360 | struct mvneta_port *pp = netdev_priv(ndev); |
| 3361 | u32 val; |
| 3362 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3363 | mvneta_port_down(pp); |
| 3364 | |
| 3365 | if (!phylink_autoneg_inband(mode)) { |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3366 | val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG); |
| 3367 | val &= ~MVNETA_GMAC_FORCE_LINK_PASS; |
| 3368 | val |= MVNETA_GMAC_FORCE_LINK_DOWN; |
| 3369 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val); |
| 3370 | } |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3373 | static void mvneta_mac_link_up(struct net_device *ndev, unsigned int mode, |
| 3374 | struct phy_device *phy) |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3375 | { |
| 3376 | struct mvneta_port *pp = netdev_priv(ndev); |
| 3377 | u32 val; |
| 3378 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3379 | if (!phylink_autoneg_inband(mode)) { |
Russell King | fc548b9 | 2018-01-02 17:24:39 +0000 | [diff] [blame] | 3380 | val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG); |
| 3381 | val &= ~MVNETA_GMAC_FORCE_LINK_DOWN; |
| 3382 | val |= MVNETA_GMAC_FORCE_LINK_PASS; |
| 3383 | mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val); |
| 3384 | } |
| 3385 | |
| 3386 | mvneta_port_up(pp); |
| 3387 | } |
| 3388 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3389 | static const struct phylink_mac_ops mvneta_phylink_ops = { |
| 3390 | .validate = mvneta_validate, |
| 3391 | .mac_link_state = mvneta_mac_link_state, |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 3392 | .mac_an_restart = mvneta_mac_an_restart, |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3393 | .mac_config = mvneta_mac_config, |
| 3394 | .mac_link_down = mvneta_mac_link_down, |
| 3395 | .mac_link_up = mvneta_mac_link_up, |
| 3396 | }; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3397 | |
| 3398 | static int mvneta_mdio_probe(struct mvneta_port *pp) |
| 3399 | { |
Jisheng Zhang | 82960ff | 2017-04-14 19:07:32 +0800 | [diff] [blame] | 3400 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3401 | int err = phylink_of_phy_connect(pp->phylink, pp->dn, 0); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3402 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3403 | if (err) |
| 3404 | netdev_err(pp->dev, "could not attach PHY: %d\n", err); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3405 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3406 | phylink_ethtool_get_wol(pp->phylink, &wol); |
Jisheng Zhang | 82960ff | 2017-04-14 19:07:32 +0800 | [diff] [blame] | 3407 | device_set_wakeup_capable(&pp->dev->dev, !!wol.supported); |
| 3408 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3409 | return err; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | static void mvneta_mdio_remove(struct mvneta_port *pp) |
| 3413 | { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3414 | phylink_disconnect_phy(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3415 | } |
| 3416 | |
Gregory CLEMENT | 120cfa5 | 2016-02-04 22:09:29 +0100 | [diff] [blame] | 3417 | /* Electing a CPU must be done in an atomic way: it should be done |
| 3418 | * after or before the removal/insertion of a CPU and this function is |
| 3419 | * not reentrant. |
| 3420 | */ |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3421 | static void mvneta_percpu_elect(struct mvneta_port *pp) |
| 3422 | { |
Gregory CLEMENT | cad5d84 | 2016-02-04 22:09:24 +0100 | [diff] [blame] | 3423 | int elected_cpu = 0, max_cpu, cpu, i = 0; |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3424 | |
Gregory CLEMENT | cad5d84 | 2016-02-04 22:09:24 +0100 | [diff] [blame] | 3425 | /* Use the cpu associated to the rxq when it is online, in all |
| 3426 | * the other cases, use the cpu 0 which can't be offline. |
| 3427 | */ |
| 3428 | if (cpu_online(pp->rxq_def)) |
| 3429 | elected_cpu = pp->rxq_def; |
| 3430 | |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3431 | max_cpu = num_present_cpus(); |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3432 | |
| 3433 | for_each_online_cpu(cpu) { |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3434 | int rxq_map = 0, txq_map = 0; |
| 3435 | int rxq; |
| 3436 | |
| 3437 | for (rxq = 0; rxq < rxq_number; rxq++) |
| 3438 | if ((rxq % max_cpu) == cpu) |
| 3439 | rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq); |
| 3440 | |
Gregory CLEMENT | cad5d84 | 2016-02-04 22:09:24 +0100 | [diff] [blame] | 3441 | if (cpu == elected_cpu) |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 3442 | /* Map the default receive queue queue to the |
| 3443 | * elected CPU |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3444 | */ |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3445 | rxq_map |= MVNETA_CPU_RXQ_ACCESS(pp->rxq_def); |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 3446 | |
| 3447 | /* We update the TX queue map only if we have one |
| 3448 | * queue. In this case we associate the TX queue to |
| 3449 | * the CPU bound to the default RX queue |
| 3450 | */ |
| 3451 | if (txq_number == 1) |
Gregory CLEMENT | cad5d84 | 2016-02-04 22:09:24 +0100 | [diff] [blame] | 3452 | txq_map = (cpu == elected_cpu) ? |
Gregory CLEMENT | 50bf8cb | 2015-12-09 18:23:51 +0100 | [diff] [blame] | 3453 | MVNETA_CPU_TXQ_ACCESS(1) : 0; |
| 3454 | else |
| 3455 | txq_map = mvreg_read(pp, MVNETA_CPU_MAP(cpu)) & |
| 3456 | MVNETA_CPU_TXQ_ACCESS_ALL_MASK; |
| 3457 | |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3458 | mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map); |
| 3459 | |
| 3460 | /* Update the interrupt mask on each CPU according the |
| 3461 | * new mapping |
| 3462 | */ |
| 3463 | smp_call_function_single(cpu, mvneta_percpu_unmask_interrupt, |
| 3464 | pp, true); |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3465 | i++; |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3466 | |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3467 | } |
| 3468 | }; |
| 3469 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3470 | static int mvneta_cpu_online(unsigned int cpu, struct hlist_node *node) |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3471 | { |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3472 | int other_cpu; |
| 3473 | struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, |
| 3474 | node_online); |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3475 | struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu); |
| 3476 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3477 | |
| 3478 | spin_lock(&pp->lock); |
| 3479 | /* |
| 3480 | * Configuring the driver for a new CPU while the driver is |
| 3481 | * stopping is racy, so just avoid it. |
| 3482 | */ |
| 3483 | if (pp->is_stopped) { |
| 3484 | spin_unlock(&pp->lock); |
| 3485 | return 0; |
| 3486 | } |
| 3487 | netif_tx_stop_all_queues(pp->dev); |
| 3488 | |
| 3489 | /* |
| 3490 | * We have to synchronise on tha napi of each CPU except the one |
| 3491 | * just being woken up |
| 3492 | */ |
| 3493 | for_each_online_cpu(other_cpu) { |
| 3494 | if (other_cpu != cpu) { |
| 3495 | struct mvneta_pcpu_port *other_port = |
| 3496 | per_cpu_ptr(pp->ports, other_cpu); |
| 3497 | |
| 3498 | napi_synchronize(&other_port->napi); |
Gregory CLEMENT | 120cfa5 | 2016-02-04 22:09:29 +0100 | [diff] [blame] | 3499 | } |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3500 | } |
| 3501 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3502 | /* Mask all ethernet port interrupts */ |
| 3503 | on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); |
| 3504 | napi_enable(&port->napi); |
| 3505 | |
| 3506 | /* |
| 3507 | * Enable per-CPU interrupts on the CPU that is |
| 3508 | * brought up. |
| 3509 | */ |
| 3510 | mvneta_percpu_enable(pp); |
| 3511 | |
| 3512 | /* |
| 3513 | * Enable per-CPU interrupt on the one CPU we care |
| 3514 | * about. |
| 3515 | */ |
| 3516 | mvneta_percpu_elect(pp); |
| 3517 | |
| 3518 | /* Unmask all ethernet port interrupts */ |
| 3519 | on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); |
| 3520 | mvreg_write(pp, MVNETA_INTR_MISC_MASK, |
| 3521 | MVNETA_CAUSE_PHY_STATUS_CHANGE | |
| 3522 | MVNETA_CAUSE_LINK_CHANGE | |
| 3523 | MVNETA_CAUSE_PSC_SYNC_CHANGE); |
| 3524 | netif_tx_start_all_queues(pp->dev); |
| 3525 | spin_unlock(&pp->lock); |
| 3526 | return 0; |
| 3527 | } |
| 3528 | |
| 3529 | static int mvneta_cpu_down_prepare(unsigned int cpu, struct hlist_node *node) |
| 3530 | { |
| 3531 | struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, |
| 3532 | node_online); |
| 3533 | struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu); |
| 3534 | |
| 3535 | /* |
| 3536 | * Thanks to this lock we are sure that any pending cpu election is |
| 3537 | * done. |
| 3538 | */ |
| 3539 | spin_lock(&pp->lock); |
| 3540 | /* Mask all ethernet port interrupts */ |
| 3541 | on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); |
| 3542 | spin_unlock(&pp->lock); |
| 3543 | |
| 3544 | napi_synchronize(&port->napi); |
| 3545 | napi_disable(&port->napi); |
| 3546 | /* Disable per-CPU interrupts on the CPU that is brought down. */ |
| 3547 | mvneta_percpu_disable(pp); |
| 3548 | return 0; |
| 3549 | } |
| 3550 | |
| 3551 | static int mvneta_cpu_dead(unsigned int cpu, struct hlist_node *node) |
| 3552 | { |
| 3553 | struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, |
| 3554 | node_dead); |
| 3555 | |
| 3556 | /* Check if a new CPU must be elected now this on is down */ |
| 3557 | spin_lock(&pp->lock); |
| 3558 | mvneta_percpu_elect(pp); |
| 3559 | spin_unlock(&pp->lock); |
| 3560 | /* Unmask all ethernet port interrupts */ |
| 3561 | on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); |
| 3562 | mvreg_write(pp, MVNETA_INTR_MISC_MASK, |
| 3563 | MVNETA_CAUSE_PHY_STATUS_CHANGE | |
| 3564 | MVNETA_CAUSE_LINK_CHANGE | |
| 3565 | MVNETA_CAUSE_PSC_SYNC_CHANGE); |
| 3566 | netif_tx_start_all_queues(pp->dev); |
| 3567 | return 0; |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3568 | } |
| 3569 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3570 | static int mvneta_open(struct net_device *dev) |
| 3571 | { |
| 3572 | struct mvneta_port *pp = netdev_priv(dev); |
Gregory CLEMENT | 6b125d6 | 2016-02-04 22:09:25 +0100 | [diff] [blame] | 3573 | int ret; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3574 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3575 | pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu); |
willy tarreau | 8ec2cd4 | 2014-01-16 08:20:16 +0100 | [diff] [blame] | 3576 | pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) + |
| 3577 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3578 | |
| 3579 | ret = mvneta_setup_rxqs(pp); |
| 3580 | if (ret) |
| 3581 | return ret; |
| 3582 | |
| 3583 | ret = mvneta_setup_txqs(pp); |
| 3584 | if (ret) |
| 3585 | goto err_cleanup_rxqs; |
| 3586 | |
| 3587 | /* Connect to port interrupt line */ |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3588 | if (pp->neta_armada3700) |
| 3589 | ret = request_irq(pp->dev->irq, mvneta_isr, 0, |
| 3590 | dev->name, pp); |
| 3591 | else |
| 3592 | ret = request_percpu_irq(pp->dev->irq, mvneta_percpu_isr, |
| 3593 | dev->name, pp->ports); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3594 | if (ret) { |
| 3595 | netdev_err(pp->dev, "cannot request irq %d\n", pp->dev->irq); |
| 3596 | goto err_cleanup_txqs; |
| 3597 | } |
| 3598 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3599 | if (!pp->neta_armada3700) { |
| 3600 | /* Enable per-CPU interrupt on all the CPU to handle our RX |
| 3601 | * queue interrupts |
| 3602 | */ |
| 3603 | on_each_cpu(mvneta_percpu_enable, pp, true); |
Gregory CLEMENT | 2dcf75e | 2015-12-09 18:23:49 +0100 | [diff] [blame] | 3604 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3605 | pp->is_stopped = false; |
| 3606 | /* Register a CPU notifier to handle the case where our CPU |
| 3607 | * might be taken offline. |
| 3608 | */ |
| 3609 | ret = cpuhp_state_add_instance_nocalls(online_hpstate, |
| 3610 | &pp->node_online); |
| 3611 | if (ret) |
| 3612 | goto err_free_irq; |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3613 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3614 | ret = cpuhp_state_add_instance_nocalls(CPUHP_NET_MVNETA_DEAD, |
| 3615 | &pp->node_dead); |
| 3616 | if (ret) |
| 3617 | goto err_free_online_hp; |
| 3618 | } |
Maxime Ripard | f864288 | 2015-09-25 18:09:38 +0200 | [diff] [blame] | 3619 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3620 | /* In default link is down */ |
| 3621 | netif_carrier_off(pp->dev); |
| 3622 | |
| 3623 | ret = mvneta_mdio_probe(pp); |
| 3624 | if (ret < 0) { |
| 3625 | netdev_err(dev, "cannot probe MDIO bus\n"); |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3626 | goto err_free_dead_hp; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | mvneta_start_dev(pp); |
| 3630 | |
| 3631 | return 0; |
| 3632 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3633 | err_free_dead_hp: |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3634 | if (!pp->neta_armada3700) |
| 3635 | cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD, |
| 3636 | &pp->node_dead); |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3637 | err_free_online_hp: |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3638 | if (!pp->neta_armada3700) |
| 3639 | cpuhp_state_remove_instance_nocalls(online_hpstate, |
| 3640 | &pp->node_online); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3641 | err_free_irq: |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3642 | if (pp->neta_armada3700) { |
| 3643 | free_irq(pp->dev->irq, pp); |
| 3644 | } else { |
| 3645 | on_each_cpu(mvneta_percpu_disable, pp, true); |
| 3646 | free_percpu_irq(pp->dev->irq, pp->ports); |
| 3647 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3648 | err_cleanup_txqs: |
| 3649 | mvneta_cleanup_txqs(pp); |
| 3650 | err_cleanup_rxqs: |
| 3651 | mvneta_cleanup_rxqs(pp); |
| 3652 | return ret; |
| 3653 | } |
| 3654 | |
| 3655 | /* Stop the port, free port interrupt line */ |
| 3656 | static int mvneta_stop(struct net_device *dev) |
| 3657 | { |
| 3658 | struct mvneta_port *pp = netdev_priv(dev); |
| 3659 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3660 | if (!pp->neta_armada3700) { |
| 3661 | /* Inform that we are stopping so we don't want to setup the |
| 3662 | * driver for new CPUs in the notifiers. The code of the |
| 3663 | * notifier for CPU online is protected by the same spinlock, |
| 3664 | * so when we get the lock, the notifer work is done. |
| 3665 | */ |
| 3666 | spin_lock(&pp->lock); |
| 3667 | pp->is_stopped = true; |
| 3668 | spin_unlock(&pp->lock); |
Gregory CLEMENT | 1c2722a | 2016-03-12 18:44:17 +0100 | [diff] [blame] | 3669 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3670 | mvneta_stop_dev(pp); |
| 3671 | mvneta_mdio_remove(pp); |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 3672 | |
Dan Carpenter | d26aac2 | 2016-12-07 14:32:17 +0300 | [diff] [blame] | 3673 | cpuhp_state_remove_instance_nocalls(online_hpstate, |
| 3674 | &pp->node_online); |
| 3675 | cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD, |
| 3676 | &pp->node_dead); |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3677 | on_each_cpu(mvneta_percpu_disable, pp, true); |
| 3678 | free_percpu_irq(dev->irq, pp->ports); |
| 3679 | } else { |
| 3680 | mvneta_stop_dev(pp); |
| 3681 | mvneta_mdio_remove(pp); |
| 3682 | free_irq(dev->irq, pp); |
| 3683 | } |
| 3684 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3685 | mvneta_cleanup_rxqs(pp); |
| 3686 | mvneta_cleanup_txqs(pp); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3687 | |
| 3688 | return 0; |
| 3689 | } |
| 3690 | |
Thomas Petazzoni | 15f5945 | 2013-09-04 16:26:52 +0200 | [diff] [blame] | 3691 | static int mvneta_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 3692 | { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3693 | struct mvneta_port *pp = netdev_priv(dev); |
Thomas Petazzoni | 15f5945 | 2013-09-04 16:26:52 +0200 | [diff] [blame] | 3694 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3695 | return phylink_mii_ioctl(pp->phylink, ifr, cmd); |
Thomas Petazzoni | 15f5945 | 2013-09-04 16:26:52 +0200 | [diff] [blame] | 3696 | } |
| 3697 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3698 | /* Ethtool methods */ |
| 3699 | |
Philippe Reynes | 013ad40 | 2016-07-30 17:42:12 +0200 | [diff] [blame] | 3700 | /* Set link ksettings (phy address, speed) for ethtools */ |
Baoyou Xie | 2dc0d2b | 2016-09-25 17:20:41 +0800 | [diff] [blame] | 3701 | static int |
| 3702 | mvneta_ethtool_set_link_ksettings(struct net_device *ndev, |
| 3703 | const struct ethtool_link_ksettings *cmd) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3704 | { |
Philippe Reynes | 013ad40 | 2016-07-30 17:42:12 +0200 | [diff] [blame] | 3705 | struct mvneta_port *pp = netdev_priv(ndev); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3706 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3707 | return phylink_ethtool_ksettings_set(pp->phylink, cmd); |
| 3708 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3709 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3710 | /* Get link ksettings for ethtools */ |
| 3711 | static int |
| 3712 | mvneta_ethtool_get_link_ksettings(struct net_device *ndev, |
| 3713 | struct ethtool_link_ksettings *cmd) |
| 3714 | { |
| 3715 | struct mvneta_port *pp = netdev_priv(ndev); |
Stas Sergeev | 0c0744f | 2015-12-02 20:35:11 +0300 | [diff] [blame] | 3716 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3717 | return phylink_ethtool_ksettings_get(pp->phylink, cmd); |
| 3718 | } |
Stas Sergeev | 0c0744f | 2015-12-02 20:35:11 +0300 | [diff] [blame] | 3719 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3720 | static int mvneta_ethtool_nway_reset(struct net_device *dev) |
| 3721 | { |
| 3722 | struct mvneta_port *pp = netdev_priv(dev); |
Stas Sergeev | 0c0744f | 2015-12-02 20:35:11 +0300 | [diff] [blame] | 3723 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3724 | return phylink_ethtool_nway_reset(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | /* Set interrupt coalescing for ethtools */ |
| 3728 | static int mvneta_ethtool_set_coalesce(struct net_device *dev, |
| 3729 | struct ethtool_coalesce *c) |
| 3730 | { |
| 3731 | struct mvneta_port *pp = netdev_priv(dev); |
| 3732 | int queue; |
| 3733 | |
| 3734 | for (queue = 0; queue < rxq_number; queue++) { |
| 3735 | struct mvneta_rx_queue *rxq = &pp->rxqs[queue]; |
| 3736 | rxq->time_coal = c->rx_coalesce_usecs; |
| 3737 | rxq->pkts_coal = c->rx_max_coalesced_frames; |
| 3738 | mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal); |
| 3739 | mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal); |
| 3740 | } |
| 3741 | |
| 3742 | for (queue = 0; queue < txq_number; queue++) { |
| 3743 | struct mvneta_tx_queue *txq = &pp->txqs[queue]; |
| 3744 | txq->done_pkts_coal = c->tx_max_coalesced_frames; |
| 3745 | mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal); |
| 3746 | } |
| 3747 | |
| 3748 | return 0; |
| 3749 | } |
| 3750 | |
| 3751 | /* get coalescing for ethtools */ |
| 3752 | static int mvneta_ethtool_get_coalesce(struct net_device *dev, |
| 3753 | struct ethtool_coalesce *c) |
| 3754 | { |
| 3755 | struct mvneta_port *pp = netdev_priv(dev); |
| 3756 | |
| 3757 | c->rx_coalesce_usecs = pp->rxqs[0].time_coal; |
| 3758 | c->rx_max_coalesced_frames = pp->rxqs[0].pkts_coal; |
| 3759 | |
| 3760 | c->tx_max_coalesced_frames = pp->txqs[0].done_pkts_coal; |
| 3761 | return 0; |
| 3762 | } |
| 3763 | |
| 3764 | |
| 3765 | static void mvneta_ethtool_get_drvinfo(struct net_device *dev, |
| 3766 | struct ethtool_drvinfo *drvinfo) |
| 3767 | { |
| 3768 | strlcpy(drvinfo->driver, MVNETA_DRIVER_NAME, |
| 3769 | sizeof(drvinfo->driver)); |
| 3770 | strlcpy(drvinfo->version, MVNETA_DRIVER_VERSION, |
| 3771 | sizeof(drvinfo->version)); |
| 3772 | strlcpy(drvinfo->bus_info, dev_name(&dev->dev), |
| 3773 | sizeof(drvinfo->bus_info)); |
| 3774 | } |
| 3775 | |
| 3776 | |
| 3777 | static void mvneta_ethtool_get_ringparam(struct net_device *netdev, |
| 3778 | struct ethtool_ringparam *ring) |
| 3779 | { |
| 3780 | struct mvneta_port *pp = netdev_priv(netdev); |
| 3781 | |
| 3782 | ring->rx_max_pending = MVNETA_MAX_RXD; |
| 3783 | ring->tx_max_pending = MVNETA_MAX_TXD; |
| 3784 | ring->rx_pending = pp->rx_ring_size; |
| 3785 | ring->tx_pending = pp->tx_ring_size; |
| 3786 | } |
| 3787 | |
| 3788 | static int mvneta_ethtool_set_ringparam(struct net_device *dev, |
| 3789 | struct ethtool_ringparam *ring) |
| 3790 | { |
| 3791 | struct mvneta_port *pp = netdev_priv(dev); |
| 3792 | |
| 3793 | if ((ring->rx_pending == 0) || (ring->tx_pending == 0)) |
| 3794 | return -EINVAL; |
| 3795 | pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ? |
| 3796 | ring->rx_pending : MVNETA_MAX_RXD; |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 3797 | |
| 3798 | pp->tx_ring_size = clamp_t(u16, ring->tx_pending, |
| 3799 | MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD); |
| 3800 | if (pp->tx_ring_size != ring->tx_pending) |
| 3801 | netdev_warn(dev, "TX queue size set to %u (requested %u)\n", |
| 3802 | pp->tx_ring_size, ring->tx_pending); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 3803 | |
| 3804 | if (netif_running(dev)) { |
| 3805 | mvneta_stop(dev); |
| 3806 | if (mvneta_open(dev)) { |
| 3807 | netdev_err(dev, |
| 3808 | "error on opening device after ring param change\n"); |
| 3809 | return -ENOMEM; |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | return 0; |
| 3814 | } |
| 3815 | |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3816 | static void mvneta_ethtool_get_strings(struct net_device *netdev, u32 sset, |
| 3817 | u8 *data) |
| 3818 | { |
| 3819 | if (sset == ETH_SS_STATS) { |
| 3820 | int i; |
| 3821 | |
| 3822 | for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++) |
| 3823 | memcpy(data + i * ETH_GSTRING_LEN, |
| 3824 | mvneta_statistics[i].name, ETH_GSTRING_LEN); |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | static void mvneta_ethtool_update_stats(struct mvneta_port *pp) |
| 3829 | { |
| 3830 | const struct mvneta_statistic *s; |
| 3831 | void __iomem *base = pp->base; |
| 3832 | u32 high, low, val; |
Jisheng Zhang | 2c83229 | 2016-01-20 16:36:25 +0800 | [diff] [blame] | 3833 | u64 val64; |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3834 | int i; |
| 3835 | |
| 3836 | for (i = 0, s = mvneta_statistics; |
| 3837 | s < mvneta_statistics + ARRAY_SIZE(mvneta_statistics); |
| 3838 | s++, i++) { |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3839 | switch (s->type) { |
| 3840 | case T_REG_32: |
| 3841 | val = readl_relaxed(base + s->offset); |
Jisheng Zhang | 2c83229 | 2016-01-20 16:36:25 +0800 | [diff] [blame] | 3842 | pp->ethtool_stats[i] += val; |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3843 | break; |
| 3844 | case T_REG_64: |
| 3845 | /* Docs say to read low 32-bit then high */ |
| 3846 | low = readl_relaxed(base + s->offset); |
| 3847 | high = readl_relaxed(base + s->offset + 4); |
Jisheng Zhang | 2c83229 | 2016-01-20 16:36:25 +0800 | [diff] [blame] | 3848 | val64 = (u64)high << 32 | low; |
| 3849 | pp->ethtool_stats[i] += val64; |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3850 | break; |
| 3851 | } |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | static void mvneta_ethtool_get_stats(struct net_device *dev, |
| 3856 | struct ethtool_stats *stats, u64 *data) |
| 3857 | { |
| 3858 | struct mvneta_port *pp = netdev_priv(dev); |
| 3859 | int i; |
| 3860 | |
| 3861 | mvneta_ethtool_update_stats(pp); |
| 3862 | |
| 3863 | for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++) |
| 3864 | *data++ = pp->ethtool_stats[i]; |
| 3865 | } |
| 3866 | |
| 3867 | static int mvneta_ethtool_get_sset_count(struct net_device *dev, int sset) |
| 3868 | { |
| 3869 | if (sset == ETH_SS_STATS) |
| 3870 | return ARRAY_SIZE(mvneta_statistics); |
| 3871 | return -EOPNOTSUPP; |
| 3872 | } |
| 3873 | |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3874 | static u32 mvneta_ethtool_get_rxfh_indir_size(struct net_device *dev) |
| 3875 | { |
| 3876 | return MVNETA_RSS_LU_TABLE_SIZE; |
| 3877 | } |
| 3878 | |
| 3879 | static int mvneta_ethtool_get_rxnfc(struct net_device *dev, |
| 3880 | struct ethtool_rxnfc *info, |
| 3881 | u32 *rules __always_unused) |
| 3882 | { |
| 3883 | switch (info->cmd) { |
| 3884 | case ETHTOOL_GRXRINGS: |
| 3885 | info->data = rxq_number; |
| 3886 | return 0; |
| 3887 | case ETHTOOL_GRXFH: |
| 3888 | return -EOPNOTSUPP; |
| 3889 | default: |
| 3890 | return -EOPNOTSUPP; |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | static int mvneta_config_rss(struct mvneta_port *pp) |
| 3895 | { |
| 3896 | int cpu; |
| 3897 | u32 val; |
| 3898 | |
| 3899 | netif_tx_stop_all_queues(pp->dev); |
| 3900 | |
Gregory CLEMENT | 6b125d6 | 2016-02-04 22:09:25 +0100 | [diff] [blame] | 3901 | on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3902 | |
| 3903 | /* We have to synchronise on the napi of each CPU */ |
| 3904 | for_each_online_cpu(cpu) { |
| 3905 | struct mvneta_pcpu_port *pcpu_port = |
| 3906 | per_cpu_ptr(pp->ports, cpu); |
| 3907 | |
| 3908 | napi_synchronize(&pcpu_port->napi); |
| 3909 | napi_disable(&pcpu_port->napi); |
| 3910 | } |
| 3911 | |
| 3912 | pp->rxq_def = pp->indir[0]; |
| 3913 | |
| 3914 | /* Update unicast mapping */ |
| 3915 | mvneta_set_rx_mode(pp->dev); |
| 3916 | |
| 3917 | /* Update val of portCfg register accordingly with all RxQueue types */ |
| 3918 | val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def); |
| 3919 | mvreg_write(pp, MVNETA_PORT_CONFIG, val); |
| 3920 | |
| 3921 | /* Update the elected CPU matching the new rxq_def */ |
Gregory CLEMENT | 120cfa5 | 2016-02-04 22:09:29 +0100 | [diff] [blame] | 3922 | spin_lock(&pp->lock); |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3923 | mvneta_percpu_elect(pp); |
Gregory CLEMENT | 120cfa5 | 2016-02-04 22:09:29 +0100 | [diff] [blame] | 3924 | spin_unlock(&pp->lock); |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3925 | |
| 3926 | /* We have to synchronise on the napi of each CPU */ |
| 3927 | for_each_online_cpu(cpu) { |
| 3928 | struct mvneta_pcpu_port *pcpu_port = |
| 3929 | per_cpu_ptr(pp->ports, cpu); |
| 3930 | |
| 3931 | napi_enable(&pcpu_port->napi); |
| 3932 | } |
| 3933 | |
| 3934 | netif_tx_start_all_queues(pp->dev); |
| 3935 | |
| 3936 | return 0; |
| 3937 | } |
| 3938 | |
| 3939 | static int mvneta_ethtool_set_rxfh(struct net_device *dev, const u32 *indir, |
| 3940 | const u8 *key, const u8 hfunc) |
| 3941 | { |
| 3942 | struct mvneta_port *pp = netdev_priv(dev); |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3943 | |
| 3944 | /* Current code for Armada 3700 doesn't support RSS features yet */ |
| 3945 | if (pp->neta_armada3700) |
| 3946 | return -EOPNOTSUPP; |
| 3947 | |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3948 | /* We require at least one supported parameter to be changed |
| 3949 | * and no change in any of the unsupported parameters |
| 3950 | */ |
| 3951 | if (key || |
| 3952 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) |
| 3953 | return -EOPNOTSUPP; |
| 3954 | |
| 3955 | if (!indir) |
| 3956 | return 0; |
| 3957 | |
| 3958 | memcpy(pp->indir, indir, MVNETA_RSS_LU_TABLE_SIZE); |
| 3959 | |
| 3960 | return mvneta_config_rss(pp); |
| 3961 | } |
| 3962 | |
| 3963 | static int mvneta_ethtool_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, |
| 3964 | u8 *hfunc) |
| 3965 | { |
| 3966 | struct mvneta_port *pp = netdev_priv(dev); |
| 3967 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 3968 | /* Current code for Armada 3700 doesn't support RSS features yet */ |
| 3969 | if (pp->neta_armada3700) |
| 3970 | return -EOPNOTSUPP; |
| 3971 | |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 3972 | if (hfunc) |
| 3973 | *hfunc = ETH_RSS_HASH_TOP; |
| 3974 | |
| 3975 | if (!indir) |
| 3976 | return 0; |
| 3977 | |
| 3978 | memcpy(indir, pp->indir, MVNETA_RSS_LU_TABLE_SIZE); |
| 3979 | |
| 3980 | return 0; |
| 3981 | } |
| 3982 | |
Jingju Hou | b60a00f | 2017-02-06 14:58:13 +0800 | [diff] [blame] | 3983 | static void mvneta_ethtool_get_wol(struct net_device *dev, |
| 3984 | struct ethtool_wolinfo *wol) |
| 3985 | { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3986 | struct mvneta_port *pp = netdev_priv(dev); |
Jingju Hou | b60a00f | 2017-02-06 14:58:13 +0800 | [diff] [blame] | 3987 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3988 | phylink_ethtool_get_wol(pp->phylink, wol); |
Jingju Hou | b60a00f | 2017-02-06 14:58:13 +0800 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | static int mvneta_ethtool_set_wol(struct net_device *dev, |
| 3992 | struct ethtool_wolinfo *wol) |
| 3993 | { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3994 | struct mvneta_port *pp = netdev_priv(dev); |
Jisheng Zhang | 82960ff | 2017-04-14 19:07:32 +0800 | [diff] [blame] | 3995 | int ret; |
| 3996 | |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 3997 | ret = phylink_ethtool_set_wol(pp->phylink, wol); |
Jisheng Zhang | 82960ff | 2017-04-14 19:07:32 +0800 | [diff] [blame] | 3998 | if (!ret) |
| 3999 | device_set_wakeup_enable(&dev->dev, !!wol->wolopts); |
| 4000 | |
| 4001 | return ret; |
Jingju Hou | b60a00f | 2017-02-06 14:58:13 +0800 | [diff] [blame] | 4002 | } |
| 4003 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4004 | static const struct net_device_ops mvneta_netdev_ops = { |
| 4005 | .ndo_open = mvneta_open, |
| 4006 | .ndo_stop = mvneta_stop, |
| 4007 | .ndo_start_xmit = mvneta_tx, |
| 4008 | .ndo_set_rx_mode = mvneta_set_rx_mode, |
| 4009 | .ndo_set_mac_address = mvneta_set_mac_addr, |
| 4010 | .ndo_change_mtu = mvneta_change_mtu, |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 4011 | .ndo_fix_features = mvneta_fix_features, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4012 | .ndo_get_stats64 = mvneta_get_stats64, |
Thomas Petazzoni | 15f5945 | 2013-09-04 16:26:52 +0200 | [diff] [blame] | 4013 | .ndo_do_ioctl = mvneta_ioctl, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4014 | }; |
| 4015 | |
Jisheng Zhang | 4581be4 | 2017-02-16 17:07:39 +0800 | [diff] [blame] | 4016 | static const struct ethtool_ops mvneta_eth_tool_ops = { |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4017 | .nway_reset = mvneta_ethtool_nway_reset, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4018 | .get_link = ethtool_op_get_link, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4019 | .set_coalesce = mvneta_ethtool_set_coalesce, |
| 4020 | .get_coalesce = mvneta_ethtool_get_coalesce, |
| 4021 | .get_drvinfo = mvneta_ethtool_get_drvinfo, |
| 4022 | .get_ringparam = mvneta_ethtool_get_ringparam, |
| 4023 | .set_ringparam = mvneta_ethtool_set_ringparam, |
Russell King | 9b0cdef | 2015-10-22 18:37:30 +0100 | [diff] [blame] | 4024 | .get_strings = mvneta_ethtool_get_strings, |
| 4025 | .get_ethtool_stats = mvneta_ethtool_get_stats, |
| 4026 | .get_sset_count = mvneta_ethtool_get_sset_count, |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 4027 | .get_rxfh_indir_size = mvneta_ethtool_get_rxfh_indir_size, |
| 4028 | .get_rxnfc = mvneta_ethtool_get_rxnfc, |
| 4029 | .get_rxfh = mvneta_ethtool_get_rxfh, |
| 4030 | .set_rxfh = mvneta_ethtool_set_rxfh, |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4031 | .get_link_ksettings = mvneta_ethtool_get_link_ksettings, |
Philippe Reynes | 013ad40 | 2016-07-30 17:42:12 +0200 | [diff] [blame] | 4032 | .set_link_ksettings = mvneta_ethtool_set_link_ksettings, |
Jingju Hou | b60a00f | 2017-02-06 14:58:13 +0800 | [diff] [blame] | 4033 | .get_wol = mvneta_ethtool_get_wol, |
| 4034 | .set_wol = mvneta_ethtool_set_wol, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4035 | }; |
| 4036 | |
| 4037 | /* Initialize hw */ |
Ezequiel Garcia | 9672850 | 2014-05-22 20:06:59 -0300 | [diff] [blame] | 4038 | static int mvneta_init(struct device *dev, struct mvneta_port *pp) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4039 | { |
| 4040 | int queue; |
| 4041 | |
| 4042 | /* Disable port */ |
| 4043 | mvneta_port_disable(pp); |
| 4044 | |
| 4045 | /* Set port default values */ |
| 4046 | mvneta_defaults_set(pp); |
| 4047 | |
Markus Elfring | 5d6312ed | 2017-04-16 21:45:38 +0200 | [diff] [blame] | 4048 | pp->txqs = devm_kcalloc(dev, txq_number, sizeof(*pp->txqs), GFP_KERNEL); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4049 | if (!pp->txqs) |
| 4050 | return -ENOMEM; |
| 4051 | |
| 4052 | /* Initialize TX descriptor rings */ |
| 4053 | for (queue = 0; queue < txq_number; queue++) { |
| 4054 | struct mvneta_tx_queue *txq = &pp->txqs[queue]; |
| 4055 | txq->id = queue; |
| 4056 | txq->size = pp->tx_ring_size; |
| 4057 | txq->done_pkts_coal = MVNETA_TXDONE_COAL_PKTS; |
| 4058 | } |
| 4059 | |
Markus Elfring | 5d6312ed | 2017-04-16 21:45:38 +0200 | [diff] [blame] | 4060 | pp->rxqs = devm_kcalloc(dev, rxq_number, sizeof(*pp->rxqs), GFP_KERNEL); |
Ezequiel Garcia | 9672850 | 2014-05-22 20:06:59 -0300 | [diff] [blame] | 4061 | if (!pp->rxqs) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4062 | return -ENOMEM; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4063 | |
| 4064 | /* Create Rx descriptor rings */ |
| 4065 | for (queue = 0; queue < rxq_number; queue++) { |
| 4066 | struct mvneta_rx_queue *rxq = &pp->rxqs[queue]; |
| 4067 | rxq->id = queue; |
| 4068 | rxq->size = pp->rx_ring_size; |
| 4069 | rxq->pkts_coal = MVNETA_RX_COAL_PKTS; |
| 4070 | rxq->time_coal = MVNETA_RX_COAL_USEC; |
Markus Elfring | 2911063 | 2017-04-16 21:23:19 +0200 | [diff] [blame] | 4071 | rxq->buf_virt_addr |
| 4072 | = devm_kmalloc_array(pp->dev->dev.parent, |
| 4073 | rxq->size, |
| 4074 | sizeof(*rxq->buf_virt_addr), |
| 4075 | GFP_KERNEL); |
Gregory CLEMENT | f88bee1 | 2016-12-01 18:03:06 +0100 | [diff] [blame] | 4076 | if (!rxq->buf_virt_addr) |
| 4077 | return -ENOMEM; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | return 0; |
| 4081 | } |
| 4082 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4083 | /* platform glue : initialize decoding windows */ |
Greg KH | 03ce758 | 2012-12-21 13:42:15 +0000 | [diff] [blame] | 4084 | static void mvneta_conf_mbus_windows(struct mvneta_port *pp, |
| 4085 | const struct mbus_dram_target_info *dram) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4086 | { |
| 4087 | u32 win_enable; |
| 4088 | u32 win_protect; |
| 4089 | int i; |
| 4090 | |
| 4091 | for (i = 0; i < 6; i++) { |
| 4092 | mvreg_write(pp, MVNETA_WIN_BASE(i), 0); |
| 4093 | mvreg_write(pp, MVNETA_WIN_SIZE(i), 0); |
| 4094 | |
| 4095 | if (i < 4) |
| 4096 | mvreg_write(pp, MVNETA_WIN_REMAP(i), 0); |
| 4097 | } |
| 4098 | |
| 4099 | win_enable = 0x3f; |
| 4100 | win_protect = 0; |
| 4101 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4102 | if (dram) { |
| 4103 | for (i = 0; i < dram->num_cs; i++) { |
| 4104 | const struct mbus_dram_window *cs = dram->cs + i; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4105 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4106 | mvreg_write(pp, MVNETA_WIN_BASE(i), |
| 4107 | (cs->base & 0xffff0000) | |
| 4108 | (cs->mbus_attr << 8) | |
| 4109 | dram->mbus_dram_target_id); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4110 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4111 | mvreg_write(pp, MVNETA_WIN_SIZE(i), |
| 4112 | (cs->size - 1) & 0xffff0000); |
| 4113 | |
| 4114 | win_enable &= ~(1 << i); |
| 4115 | win_protect |= 3 << (2 * i); |
| 4116 | } |
| 4117 | } else { |
| 4118 | /* For Armada3700 open default 4GB Mbus window, leaving |
| 4119 | * arbitration of target/attribute to a different layer |
| 4120 | * of configuration. |
| 4121 | */ |
| 4122 | mvreg_write(pp, MVNETA_WIN_SIZE(0), 0xffff0000); |
| 4123 | win_enable &= ~BIT(0); |
| 4124 | win_protect = 3; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable); |
Marcin Wojtas | db6ba9a | 2015-11-30 13:27:41 +0100 | [diff] [blame] | 4128 | mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | /* Power up the port */ |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4132 | static int mvneta_port_power_up(struct mvneta_port *pp, int phy_mode) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4133 | { |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4134 | /* MAC Cause register should be cleared */ |
| 4135 | mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0); |
| 4136 | |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 4137 | if (phy_mode == PHY_INTERFACE_MODE_QSGMII) |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4138 | mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_QSGMII_SERDES_PROTO); |
Russell King | 22f4bf8 | 2018-01-02 17:24:54 +0000 | [diff] [blame^] | 4139 | else if (phy_mode == PHY_INTERFACE_MODE_SGMII || |
| 4140 | phy_mode == PHY_INTERFACE_MODE_1000BASEX) |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4141 | mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO); |
Russell King | 3269995 | 2018-01-02 17:24:49 +0000 | [diff] [blame] | 4142 | else if (!phy_interface_mode_is_rgmii(phy_mode)) |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4143 | return -EINVAL; |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4144 | |
| 4145 | return 0; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | /* Device initialization routine */ |
Greg KH | 03ce758 | 2012-12-21 13:42:15 +0000 | [diff] [blame] | 4149 | static int mvneta_probe(struct platform_device *pdev) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4150 | { |
Thomas Petazzoni | c3f0dd3 | 2014-03-27 11:39:29 +0100 | [diff] [blame] | 4151 | struct resource *res; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4152 | struct device_node *dn = pdev->dev.of_node; |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4153 | struct device_node *bm_node; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4154 | struct mvneta_port *pp; |
| 4155 | struct net_device *dev; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4156 | struct phylink *phylink; |
Thomas Petazzoni | 8cc3e43 | 2013-06-04 04:52:23 +0000 | [diff] [blame] | 4157 | const char *dt_mac_addr; |
| 4158 | char hw_mac_addr[ETH_ALEN]; |
| 4159 | const char *mac_from; |
Marcin Wojtas | 9110ee0 | 2015-11-30 13:27:45 +0100 | [diff] [blame] | 4160 | int tx_csum_limit; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4161 | int phy_mode; |
| 4162 | int err; |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4163 | int cpu; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4164 | |
Willy Tarreau | ee40a11 | 2013-04-11 23:00:37 +0200 | [diff] [blame] | 4165 | dev = alloc_etherdev_mqs(sizeof(struct mvneta_port), txq_number, rxq_number); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4166 | if (!dev) |
| 4167 | return -ENOMEM; |
| 4168 | |
| 4169 | dev->irq = irq_of_parse_and_map(dn, 0); |
| 4170 | if (dev->irq == 0) { |
| 4171 | err = -EINVAL; |
| 4172 | goto err_free_netdev; |
| 4173 | } |
| 4174 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4175 | phy_mode = of_get_phy_mode(dn); |
| 4176 | if (phy_mode < 0) { |
| 4177 | dev_err(&pdev->dev, "incorrect phy-mode\n"); |
| 4178 | err = -EINVAL; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4179 | goto err_free_irq; |
| 4180 | } |
| 4181 | |
| 4182 | phylink = phylink_create(dev, pdev->dev.fwnode, phy_mode, |
| 4183 | &mvneta_phylink_ops); |
| 4184 | if (IS_ERR(phylink)) { |
| 4185 | err = PTR_ERR(phylink); |
| 4186 | goto err_free_irq; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4187 | } |
| 4188 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4189 | dev->tx_queue_len = MVNETA_MAX_TXD; |
| 4190 | dev->watchdog_timeo = 5 * HZ; |
| 4191 | dev->netdev_ops = &mvneta_netdev_ops; |
| 4192 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 4193 | dev->ethtool_ops = &mvneta_eth_tool_ops; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4194 | |
| 4195 | pp = netdev_priv(dev); |
Gregory CLEMENT | 1c2722a | 2016-03-12 18:44:17 +0100 | [diff] [blame] | 4196 | spin_lock_init(&pp->lock); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4197 | pp->phylink = phylink; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4198 | pp->phy_interface = phy_mode; |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4199 | pp->dn = dn; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4200 | |
Gregory CLEMENT | 90b74c0 | 2015-12-09 18:23:48 +0100 | [diff] [blame] | 4201 | pp->rxq_def = rxq_def; |
| 4202 | |
Marcin Wojtas | 8d5047c | 2016-12-01 18:03:07 +0100 | [diff] [blame] | 4203 | /* Set RX packet offset correction for platforms, whose |
| 4204 | * NET_SKB_PAD, exceeds 64B. It should be 64B for 64-bit |
| 4205 | * platforms and 0B for 32-bit ones. |
| 4206 | */ |
| 4207 | pp->rx_offset_correction = |
| 4208 | max(0, NET_SKB_PAD - MVNETA_RX_PKT_OFFSET_CORRECTION); |
| 4209 | |
Gregory CLEMENT | 9a401de | 2015-12-09 18:23:50 +0100 | [diff] [blame] | 4210 | pp->indir[0] = rxq_def; |
| 4211 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4212 | /* Get special SoC configurations */ |
| 4213 | if (of_device_is_compatible(dn, "marvell,armada-3700-neta")) |
| 4214 | pp->neta_armada3700 = true; |
| 4215 | |
Jisheng Zhang | 2804ba4 | 2016-01-20 19:27:23 +0800 | [diff] [blame] | 4216 | pp->clk = devm_clk_get(&pdev->dev, "core"); |
| 4217 | if (IS_ERR(pp->clk)) |
| 4218 | pp->clk = devm_clk_get(&pdev->dev, NULL); |
Thomas Petazzoni | 189dd62 | 2012-11-19 14:15:25 +0100 | [diff] [blame] | 4219 | if (IS_ERR(pp->clk)) { |
| 4220 | err = PTR_ERR(pp->clk); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4221 | goto err_free_phylink; |
Thomas Petazzoni | 189dd62 | 2012-11-19 14:15:25 +0100 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | clk_prepare_enable(pp->clk); |
| 4225 | |
Jisheng Zhang | 15cc4a4 | 2016-01-20 19:27:24 +0800 | [diff] [blame] | 4226 | pp->clk_bus = devm_clk_get(&pdev->dev, "bus"); |
| 4227 | if (!IS_ERR(pp->clk_bus)) |
| 4228 | clk_prepare_enable(pp->clk_bus); |
| 4229 | |
Thomas Petazzoni | c3f0dd3 | 2014-03-27 11:39:29 +0100 | [diff] [blame] | 4230 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 4231 | pp->base = devm_ioremap_resource(&pdev->dev, res); |
| 4232 | if (IS_ERR(pp->base)) { |
| 4233 | err = PTR_ERR(pp->base); |
Arnaud Patard \(Rtp\) | 5445eaf | 2013-07-29 21:56:48 +0200 | [diff] [blame] | 4234 | goto err_clk; |
| 4235 | } |
| 4236 | |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4237 | /* Alloc per-cpu port structure */ |
| 4238 | pp->ports = alloc_percpu(struct mvneta_pcpu_port); |
| 4239 | if (!pp->ports) { |
| 4240 | err = -ENOMEM; |
| 4241 | goto err_clk; |
| 4242 | } |
| 4243 | |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 4244 | /* Alloc per-cpu stats */ |
WANG Cong | 1c213bd | 2014-02-13 11:46:28 -0800 | [diff] [blame] | 4245 | pp->stats = netdev_alloc_pcpu_stats(struct mvneta_pcpu_stats); |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 4246 | if (!pp->stats) { |
| 4247 | err = -ENOMEM; |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4248 | goto err_free_ports; |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Thomas Petazzoni | 8cc3e43 | 2013-06-04 04:52:23 +0000 | [diff] [blame] | 4251 | dt_mac_addr = of_get_mac_address(dn); |
Luka Perkov | 6c7a9a3 | 2013-10-30 00:10:01 +0100 | [diff] [blame] | 4252 | if (dt_mac_addr) { |
Thomas Petazzoni | 8cc3e43 | 2013-06-04 04:52:23 +0000 | [diff] [blame] | 4253 | mac_from = "device tree"; |
| 4254 | memcpy(dev->dev_addr, dt_mac_addr, ETH_ALEN); |
| 4255 | } else { |
| 4256 | mvneta_get_mac_addr(pp, hw_mac_addr); |
| 4257 | if (is_valid_ether_addr(hw_mac_addr)) { |
| 4258 | mac_from = "hardware"; |
| 4259 | memcpy(dev->dev_addr, hw_mac_addr, ETH_ALEN); |
| 4260 | } else { |
| 4261 | mac_from = "random"; |
| 4262 | eth_hw_addr_random(dev); |
| 4263 | } |
| 4264 | } |
| 4265 | |
Marcin Wojtas | 9110ee0 | 2015-11-30 13:27:45 +0100 | [diff] [blame] | 4266 | if (!of_property_read_u32(dn, "tx-csum-limit", &tx_csum_limit)) { |
| 4267 | if (tx_csum_limit < 0 || |
| 4268 | tx_csum_limit > MVNETA_TX_CSUM_MAX_SIZE) { |
| 4269 | tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE; |
| 4270 | dev_info(&pdev->dev, |
| 4271 | "Wrong TX csum limit in DT, set to %dB\n", |
| 4272 | MVNETA_TX_CSUM_DEF_SIZE); |
| 4273 | } |
| 4274 | } else if (of_device_is_compatible(dn, "marvell,armada-370-neta")) { |
| 4275 | tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE; |
| 4276 | } else { |
| 4277 | tx_csum_limit = MVNETA_TX_CSUM_MAX_SIZE; |
| 4278 | } |
| 4279 | |
| 4280 | pp->tx_csum_limit = tx_csum_limit; |
Simon Guinot | b65657f | 2015-06-30 16:20:22 +0200 | [diff] [blame] | 4281 | |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4282 | pp->dram_target_info = mv_mbus_dram_info(); |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4283 | /* Armada3700 requires setting default configuration of Mbus |
| 4284 | * windows, however without using filled mbus_dram_target_info |
| 4285 | * structure. |
| 4286 | */ |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4287 | if (pp->dram_target_info || pp->neta_armada3700) |
| 4288 | mvneta_conf_mbus_windows(pp, pp->dram_target_info); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4289 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4290 | pp->tx_ring_size = MVNETA_MAX_TXD; |
| 4291 | pp->rx_ring_size = MVNETA_MAX_RXD; |
| 4292 | |
| 4293 | pp->dev = dev; |
| 4294 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 4295 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4296 | pp->id = global_port_id++; |
| 4297 | |
| 4298 | /* Obtain access to BM resources if enabled and already initialized */ |
| 4299 | bm_node = of_parse_phandle(dn, "buffer-manager", 0); |
| 4300 | if (bm_node && bm_node->data) { |
| 4301 | pp->bm_priv = bm_node->data; |
| 4302 | err = mvneta_bm_port_init(pdev, pp); |
| 4303 | if (err < 0) { |
| 4304 | dev_info(&pdev->dev, "use SW buffer management\n"); |
| 4305 | pp->bm_priv = NULL; |
| 4306 | } |
| 4307 | } |
Peter Chen | d4e4da0 | 2016-08-01 15:02:36 +0800 | [diff] [blame] | 4308 | of_node_put(bm_node); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4309 | |
Ezequiel Garcia | 9672850 | 2014-05-22 20:06:59 -0300 | [diff] [blame] | 4310 | err = mvneta_init(&pdev->dev, pp); |
| 4311 | if (err < 0) |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4312 | goto err_netdev; |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4313 | |
| 4314 | err = mvneta_port_power_up(pp, phy_mode); |
| 4315 | if (err < 0) { |
| 4316 | dev_err(&pdev->dev, "can't power up port\n"); |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4317 | goto err_netdev; |
Thomas Petazzoni | 3f1dd4b | 2014-04-15 15:50:20 +0200 | [diff] [blame] | 4318 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4319 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4320 | /* Armada3700 network controller does not support per-cpu |
| 4321 | * operation, so only single NAPI should be initialized. |
| 4322 | */ |
| 4323 | if (pp->neta_armada3700) { |
| 4324 | netif_napi_add(dev, &pp->napi, mvneta_poll, NAPI_POLL_WEIGHT); |
| 4325 | } else { |
| 4326 | for_each_present_cpu(cpu) { |
| 4327 | struct mvneta_pcpu_port *port = |
| 4328 | per_cpu_ptr(pp->ports, cpu); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4329 | |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4330 | netif_napi_add(dev, &port->napi, mvneta_poll, |
| 4331 | NAPI_POLL_WEIGHT); |
| 4332 | port->pp = pp; |
| 4333 | } |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4334 | } |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4335 | |
Andrew Pilloud | c54a504 | 2017-09-01 07:49:49 -0700 | [diff] [blame] | 4336 | dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_TSO; |
Ezequiel Garcia | 01ef26c | 2014-05-19 13:59:53 -0300 | [diff] [blame] | 4337 | dev->hw_features |= dev->features; |
| 4338 | dev->vlan_features |= dev->features; |
Andrew Lunn | 97db8af | 2016-11-24 00:08:13 +0100 | [diff] [blame] | 4339 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Ezequiel Garcia | 8eef5f9 | 2014-05-30 13:40:05 -0300 | [diff] [blame] | 4340 | dev->gso_max_segs = MVNETA_MAX_TSO_SEGS; |
willy tarreau | b50b72d | 2013-04-06 08:47:01 +0000 | [diff] [blame] | 4341 | |
Jarod Wilson | 5777987 | 2016-10-17 15:54:06 -0400 | [diff] [blame] | 4342 | /* MTU range: 68 - 9676 */ |
| 4343 | dev->min_mtu = ETH_MIN_MTU; |
| 4344 | /* 9676 == 9700 - 20 and rounding to 8 */ |
| 4345 | dev->max_mtu = 9676; |
| 4346 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4347 | err = register_netdev(dev); |
| 4348 | if (err < 0) { |
| 4349 | dev_err(&pdev->dev, "failed to register\n"); |
Ezequiel Garcia | 9672850 | 2014-05-22 20:06:59 -0300 | [diff] [blame] | 4350 | goto err_free_stats; |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4351 | } |
| 4352 | |
Thomas Petazzoni | 8cc3e43 | 2013-06-04 04:52:23 +0000 | [diff] [blame] | 4353 | netdev_info(dev, "Using %s mac address %pM\n", mac_from, |
| 4354 | dev->dev_addr); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4355 | |
| 4356 | platform_set_drvdata(pdev, pp->dev); |
| 4357 | |
| 4358 | return 0; |
| 4359 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4360 | err_netdev: |
| 4361 | unregister_netdev(dev); |
| 4362 | if (pp->bm_priv) { |
| 4363 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); |
| 4364 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, |
| 4365 | 1 << pp->id); |
| 4366 | } |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 4367 | err_free_stats: |
| 4368 | free_percpu(pp->stats); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4369 | err_free_ports: |
| 4370 | free_percpu(pp->ports); |
Arnaud Patard \(Rtp\) | 5445eaf | 2013-07-29 21:56:48 +0200 | [diff] [blame] | 4371 | err_clk: |
Jisheng Zhang | 15cc4a4 | 2016-01-20 19:27:24 +0800 | [diff] [blame] | 4372 | clk_disable_unprepare(pp->clk_bus); |
Arnaud Patard \(Rtp\) | 5445eaf | 2013-07-29 21:56:48 +0200 | [diff] [blame] | 4373 | clk_disable_unprepare(pp->clk); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4374 | err_free_phylink: |
| 4375 | if (pp->phylink) |
| 4376 | phylink_destroy(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4377 | err_free_irq: |
| 4378 | irq_dispose_mapping(dev->irq); |
| 4379 | err_free_netdev: |
| 4380 | free_netdev(dev); |
| 4381 | return err; |
| 4382 | } |
| 4383 | |
| 4384 | /* Device removal routine */ |
Greg KH | 03ce758 | 2012-12-21 13:42:15 +0000 | [diff] [blame] | 4385 | static int mvneta_remove(struct platform_device *pdev) |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4386 | { |
| 4387 | struct net_device *dev = platform_get_drvdata(pdev); |
| 4388 | struct mvneta_port *pp = netdev_priv(dev); |
| 4389 | |
| 4390 | unregister_netdev(dev); |
Jisheng Zhang | 15cc4a4 | 2016-01-20 19:27:24 +0800 | [diff] [blame] | 4391 | clk_disable_unprepare(pp->clk_bus); |
Thomas Petazzoni | 189dd62 | 2012-11-19 14:15:25 +0100 | [diff] [blame] | 4392 | clk_disable_unprepare(pp->clk); |
Maxime Ripard | 12bb03b | 2015-09-25 18:09:36 +0200 | [diff] [blame] | 4393 | free_percpu(pp->ports); |
willy tarreau | 74c41b0 | 2014-01-16 08:20:08 +0100 | [diff] [blame] | 4394 | free_percpu(pp->stats); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4395 | irq_dispose_mapping(dev->irq); |
Russell King | 503f9aa9 | 2018-01-02 17:24:44 +0000 | [diff] [blame] | 4396 | phylink_destroy(pp->phylink); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4397 | free_netdev(dev); |
| 4398 | |
Marcin Wojtas | dc35a10 | 2016-03-14 09:39:03 +0100 | [diff] [blame] | 4399 | if (pp->bm_priv) { |
| 4400 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id); |
| 4401 | mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, |
| 4402 | 1 << pp->id); |
| 4403 | } |
| 4404 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4405 | return 0; |
| 4406 | } |
| 4407 | |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4408 | #ifdef CONFIG_PM_SLEEP |
| 4409 | static int mvneta_suspend(struct device *device) |
| 4410 | { |
| 4411 | struct net_device *dev = dev_get_drvdata(device); |
| 4412 | struct mvneta_port *pp = netdev_priv(dev); |
| 4413 | |
Russell King | 3b8bc67 | 2018-01-02 17:24:34 +0000 | [diff] [blame] | 4414 | rtnl_lock(); |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4415 | if (netif_running(dev)) |
| 4416 | mvneta_stop(dev); |
Russell King | 3b8bc67 | 2018-01-02 17:24:34 +0000 | [diff] [blame] | 4417 | rtnl_unlock(); |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4418 | netif_device_detach(dev); |
| 4419 | clk_disable_unprepare(pp->clk_bus); |
| 4420 | clk_disable_unprepare(pp->clk); |
| 4421 | return 0; |
| 4422 | } |
| 4423 | |
| 4424 | static int mvneta_resume(struct device *device) |
| 4425 | { |
| 4426 | struct platform_device *pdev = to_platform_device(device); |
| 4427 | struct net_device *dev = dev_get_drvdata(device); |
| 4428 | struct mvneta_port *pp = netdev_priv(dev); |
| 4429 | int err; |
| 4430 | |
| 4431 | clk_prepare_enable(pp->clk); |
| 4432 | if (!IS_ERR(pp->clk_bus)) |
| 4433 | clk_prepare_enable(pp->clk_bus); |
| 4434 | if (pp->dram_target_info || pp->neta_armada3700) |
| 4435 | mvneta_conf_mbus_windows(pp, pp->dram_target_info); |
| 4436 | if (pp->bm_priv) { |
| 4437 | err = mvneta_bm_port_init(pdev, pp); |
| 4438 | if (err < 0) { |
| 4439 | dev_info(&pdev->dev, "use SW buffer management\n"); |
| 4440 | pp->bm_priv = NULL; |
| 4441 | } |
| 4442 | } |
| 4443 | mvneta_defaults_set(pp); |
| 4444 | err = mvneta_port_power_up(pp, pp->phy_interface); |
| 4445 | if (err < 0) { |
| 4446 | dev_err(device, "can't power up port\n"); |
| 4447 | return err; |
| 4448 | } |
| 4449 | |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4450 | netif_device_attach(dev); |
Russell King | 3b8bc67 | 2018-01-02 17:24:34 +0000 | [diff] [blame] | 4451 | rtnl_lock(); |
Jisheng Zhang | d6956ac | 2017-03-29 16:47:19 +0800 | [diff] [blame] | 4452 | if (netif_running(dev)) { |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4453 | mvneta_open(dev); |
Jisheng Zhang | d6956ac | 2017-03-29 16:47:19 +0800 | [diff] [blame] | 4454 | mvneta_set_rx_mode(dev); |
| 4455 | } |
Russell King | 3b8bc67 | 2018-01-02 17:24:34 +0000 | [diff] [blame] | 4456 | rtnl_unlock(); |
Jisheng Zhang | d6956ac | 2017-03-29 16:47:19 +0800 | [diff] [blame] | 4457 | |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4458 | return 0; |
| 4459 | } |
| 4460 | #endif |
| 4461 | |
| 4462 | static SIMPLE_DEV_PM_OPS(mvneta_pm_ops, mvneta_suspend, mvneta_resume); |
| 4463 | |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4464 | static const struct of_device_id mvneta_match[] = { |
| 4465 | { .compatible = "marvell,armada-370-neta" }, |
Simon Guinot | f522a97 | 2015-06-30 16:20:20 +0200 | [diff] [blame] | 4466 | { .compatible = "marvell,armada-xp-neta" }, |
Marcin Wojtas | 2636ac3 | 2016-12-01 18:03:09 +0100 | [diff] [blame] | 4467 | { .compatible = "marvell,armada-3700-neta" }, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4468 | { } |
| 4469 | }; |
| 4470 | MODULE_DEVICE_TABLE(of, mvneta_match); |
| 4471 | |
| 4472 | static struct platform_driver mvneta_driver = { |
| 4473 | .probe = mvneta_probe, |
Greg KH | 03ce758 | 2012-12-21 13:42:15 +0000 | [diff] [blame] | 4474 | .remove = mvneta_remove, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4475 | .driver = { |
| 4476 | .name = MVNETA_DRIVER_NAME, |
| 4477 | .of_match_table = mvneta_match, |
Jane Li | 9768b45 | 2017-03-16 16:22:28 +0800 | [diff] [blame] | 4478 | .pm = &mvneta_pm_ops, |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4479 | }, |
| 4480 | }; |
| 4481 | |
Sebastian Andrzej Siewior | 84a3f4d | 2016-08-18 14:57:23 +0200 | [diff] [blame] | 4482 | static int __init mvneta_driver_init(void) |
| 4483 | { |
| 4484 | int ret; |
| 4485 | |
| 4486 | ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "net/mvmeta:online", |
| 4487 | mvneta_cpu_online, |
| 4488 | mvneta_cpu_down_prepare); |
| 4489 | if (ret < 0) |
| 4490 | goto out; |
| 4491 | online_hpstate = ret; |
| 4492 | ret = cpuhp_setup_state_multi(CPUHP_NET_MVNETA_DEAD, "net/mvneta:dead", |
| 4493 | NULL, mvneta_cpu_dead); |
| 4494 | if (ret) |
| 4495 | goto err_dead; |
| 4496 | |
| 4497 | ret = platform_driver_register(&mvneta_driver); |
| 4498 | if (ret) |
| 4499 | goto err; |
| 4500 | return 0; |
| 4501 | |
| 4502 | err: |
| 4503 | cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD); |
| 4504 | err_dead: |
| 4505 | cpuhp_remove_multi_state(online_hpstate); |
| 4506 | out: |
| 4507 | return ret; |
| 4508 | } |
| 4509 | module_init(mvneta_driver_init); |
| 4510 | |
| 4511 | static void __exit mvneta_driver_exit(void) |
| 4512 | { |
| 4513 | platform_driver_unregister(&mvneta_driver); |
| 4514 | cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD); |
| 4515 | cpuhp_remove_multi_state(online_hpstate); |
| 4516 | } |
| 4517 | module_exit(mvneta_driver_exit); |
Thomas Petazzoni | c5aff18 | 2012-08-17 14:04:28 +0300 | [diff] [blame] | 4518 | |
| 4519 | MODULE_DESCRIPTION("Marvell NETA Ethernet Driver - www.marvell.com"); |
| 4520 | MODULE_AUTHOR("Rami Rosen <rosenr@marvell.com>, Thomas Petazzoni <thomas.petazzoni@free-electrons.com>"); |
| 4521 | MODULE_LICENSE("GPL"); |
| 4522 | |
| 4523 | module_param(rxq_number, int, S_IRUGO); |
| 4524 | module_param(txq_number, int, S_IRUGO); |
| 4525 | |
| 4526 | module_param(rxq_def, int, S_IRUGO); |
willy tarreau | f19fadf | 2014-01-16 08:20:17 +0100 | [diff] [blame] | 4527 | module_param(rx_copybreak, int, S_IRUGO | S_IWUSR); |