Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Marvell PPv2 network controller for Armada 375 SoC. |
| 3 | * |
| 4 | * Copyright (C) 2014 Marvell |
| 5 | * |
| 6 | * Marcin Wojtas <mw@semihalf.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/etherdevice.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/skbuff.h> |
| 18 | #include <linux/inetdevice.h> |
| 19 | #include <linux/mbus.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/cpumask.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_irq.h> |
| 25 | #include <linux/of_mdio.h> |
| 26 | #include <linux/of_net.h> |
| 27 | #include <linux/of_address.h> |
| 28 | #include <linux/phy.h> |
| 29 | #include <linux/clk.h> |
| 30 | #include <uapi/linux/ppp_defs.h> |
| 31 | #include <net/ip.h> |
| 32 | #include <net/ipv6.h> |
| 33 | |
| 34 | /* RX Fifo Registers */ |
| 35 | #define MVPP2_RX_DATA_FIFO_SIZE_REG(port) (0x00 + 4 * (port)) |
| 36 | #define MVPP2_RX_ATTR_FIFO_SIZE_REG(port) (0x20 + 4 * (port)) |
| 37 | #define MVPP2_RX_MIN_PKT_SIZE_REG 0x60 |
| 38 | #define MVPP2_RX_FIFO_INIT_REG 0x64 |
| 39 | |
| 40 | /* RX DMA Top Registers */ |
| 41 | #define MVPP2_RX_CTRL_REG(port) (0x140 + 4 * (port)) |
| 42 | #define MVPP2_RX_LOW_LATENCY_PKT_SIZE(s) (((s) & 0xfff) << 16) |
| 43 | #define MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK BIT(31) |
| 44 | #define MVPP2_POOL_BUF_SIZE_REG(pool) (0x180 + 4 * (pool)) |
| 45 | #define MVPP2_POOL_BUF_SIZE_OFFSET 5 |
| 46 | #define MVPP2_RXQ_CONFIG_REG(rxq) (0x800 + 4 * (rxq)) |
| 47 | #define MVPP2_SNOOP_PKT_SIZE_MASK 0x1ff |
| 48 | #define MVPP2_SNOOP_BUF_HDR_MASK BIT(9) |
| 49 | #define MVPP2_RXQ_POOL_SHORT_OFFS 20 |
| 50 | #define MVPP2_RXQ_POOL_SHORT_MASK 0x700000 |
| 51 | #define MVPP2_RXQ_POOL_LONG_OFFS 24 |
| 52 | #define MVPP2_RXQ_POOL_LONG_MASK 0x7000000 |
| 53 | #define MVPP2_RXQ_PACKET_OFFSET_OFFS 28 |
| 54 | #define MVPP2_RXQ_PACKET_OFFSET_MASK 0x70000000 |
| 55 | #define MVPP2_RXQ_DISABLE_MASK BIT(31) |
| 56 | |
| 57 | /* Parser Registers */ |
| 58 | #define MVPP2_PRS_INIT_LOOKUP_REG 0x1000 |
| 59 | #define MVPP2_PRS_PORT_LU_MAX 0xf |
| 60 | #define MVPP2_PRS_PORT_LU_MASK(port) (0xff << ((port) * 4)) |
| 61 | #define MVPP2_PRS_PORT_LU_VAL(port, val) ((val) << ((port) * 4)) |
| 62 | #define MVPP2_PRS_INIT_OFFS_REG(port) (0x1004 + ((port) & 4)) |
| 63 | #define MVPP2_PRS_INIT_OFF_MASK(port) (0x3f << (((port) % 4) * 8)) |
| 64 | #define MVPP2_PRS_INIT_OFF_VAL(port, val) ((val) << (((port) % 4) * 8)) |
| 65 | #define MVPP2_PRS_MAX_LOOP_REG(port) (0x100c + ((port) & 4)) |
| 66 | #define MVPP2_PRS_MAX_LOOP_MASK(port) (0xff << (((port) % 4) * 8)) |
| 67 | #define MVPP2_PRS_MAX_LOOP_VAL(port, val) ((val) << (((port) % 4) * 8)) |
| 68 | #define MVPP2_PRS_TCAM_IDX_REG 0x1100 |
| 69 | #define MVPP2_PRS_TCAM_DATA_REG(idx) (0x1104 + (idx) * 4) |
| 70 | #define MVPP2_PRS_TCAM_INV_MASK BIT(31) |
| 71 | #define MVPP2_PRS_SRAM_IDX_REG 0x1200 |
| 72 | #define MVPP2_PRS_SRAM_DATA_REG(idx) (0x1204 + (idx) * 4) |
| 73 | #define MVPP2_PRS_TCAM_CTRL_REG 0x1230 |
| 74 | #define MVPP2_PRS_TCAM_EN_MASK BIT(0) |
| 75 | |
| 76 | /* Classifier Registers */ |
| 77 | #define MVPP2_CLS_MODE_REG 0x1800 |
| 78 | #define MVPP2_CLS_MODE_ACTIVE_MASK BIT(0) |
| 79 | #define MVPP2_CLS_PORT_WAY_REG 0x1810 |
| 80 | #define MVPP2_CLS_PORT_WAY_MASK(port) (1 << (port)) |
| 81 | #define MVPP2_CLS_LKP_INDEX_REG 0x1814 |
| 82 | #define MVPP2_CLS_LKP_INDEX_WAY_OFFS 6 |
| 83 | #define MVPP2_CLS_LKP_TBL_REG 0x1818 |
| 84 | #define MVPP2_CLS_LKP_TBL_RXQ_MASK 0xff |
| 85 | #define MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK BIT(25) |
| 86 | #define MVPP2_CLS_FLOW_INDEX_REG 0x1820 |
| 87 | #define MVPP2_CLS_FLOW_TBL0_REG 0x1824 |
| 88 | #define MVPP2_CLS_FLOW_TBL1_REG 0x1828 |
| 89 | #define MVPP2_CLS_FLOW_TBL2_REG 0x182c |
| 90 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port) (0x1980 + ((port) * 4)) |
| 91 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS 3 |
| 92 | #define MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK 0x7 |
| 93 | #define MVPP2_CLS_SWFWD_P2HQ_REG(port) (0x19b0 + ((port) * 4)) |
| 94 | #define MVPP2_CLS_SWFWD_PCTRL_REG 0x19d0 |
| 95 | #define MVPP2_CLS_SWFWD_PCTRL_MASK(port) (1 << (port)) |
| 96 | |
| 97 | /* Descriptor Manager Top Registers */ |
| 98 | #define MVPP2_RXQ_NUM_REG 0x2040 |
| 99 | #define MVPP2_RXQ_DESC_ADDR_REG 0x2044 |
| 100 | #define MVPP2_RXQ_DESC_SIZE_REG 0x2048 |
| 101 | #define MVPP2_RXQ_DESC_SIZE_MASK 0x3ff0 |
| 102 | #define MVPP2_RXQ_STATUS_UPDATE_REG(rxq) (0x3000 + 4 * (rxq)) |
| 103 | #define MVPP2_RXQ_NUM_PROCESSED_OFFSET 0 |
| 104 | #define MVPP2_RXQ_NUM_NEW_OFFSET 16 |
| 105 | #define MVPP2_RXQ_STATUS_REG(rxq) (0x3400 + 4 * (rxq)) |
| 106 | #define MVPP2_RXQ_OCCUPIED_MASK 0x3fff |
| 107 | #define MVPP2_RXQ_NON_OCCUPIED_OFFSET 16 |
| 108 | #define MVPP2_RXQ_NON_OCCUPIED_MASK 0x3fff0000 |
| 109 | #define MVPP2_RXQ_THRESH_REG 0x204c |
| 110 | #define MVPP2_OCCUPIED_THRESH_OFFSET 0 |
| 111 | #define MVPP2_OCCUPIED_THRESH_MASK 0x3fff |
| 112 | #define MVPP2_RXQ_INDEX_REG 0x2050 |
| 113 | #define MVPP2_TXQ_NUM_REG 0x2080 |
| 114 | #define MVPP2_TXQ_DESC_ADDR_REG 0x2084 |
| 115 | #define MVPP2_TXQ_DESC_SIZE_REG 0x2088 |
| 116 | #define MVPP2_TXQ_DESC_SIZE_MASK 0x3ff0 |
| 117 | #define MVPP2_AGGR_TXQ_UPDATE_REG 0x2090 |
| 118 | #define MVPP2_TXQ_THRESH_REG 0x2094 |
| 119 | #define MVPP2_TRANSMITTED_THRESH_OFFSET 16 |
| 120 | #define MVPP2_TRANSMITTED_THRESH_MASK 0x3fff0000 |
| 121 | #define MVPP2_TXQ_INDEX_REG 0x2098 |
| 122 | #define MVPP2_TXQ_PREF_BUF_REG 0x209c |
| 123 | #define MVPP2_PREF_BUF_PTR(desc) ((desc) & 0xfff) |
| 124 | #define MVPP2_PREF_BUF_SIZE_4 (BIT(12) | BIT(13)) |
| 125 | #define MVPP2_PREF_BUF_SIZE_16 (BIT(12) | BIT(14)) |
| 126 | #define MVPP2_PREF_BUF_THRESH(val) ((val) << 17) |
| 127 | #define MVPP2_TXQ_DRAIN_EN_MASK BIT(31) |
| 128 | #define MVPP2_TXQ_PENDING_REG 0x20a0 |
| 129 | #define MVPP2_TXQ_PENDING_MASK 0x3fff |
| 130 | #define MVPP2_TXQ_INT_STATUS_REG 0x20a4 |
| 131 | #define MVPP2_TXQ_SENT_REG(txq) (0x3c00 + 4 * (txq)) |
| 132 | #define MVPP2_TRANSMITTED_COUNT_OFFSET 16 |
| 133 | #define MVPP2_TRANSMITTED_COUNT_MASK 0x3fff0000 |
| 134 | #define MVPP2_TXQ_RSVD_REQ_REG 0x20b0 |
| 135 | #define MVPP2_TXQ_RSVD_REQ_Q_OFFSET 16 |
| 136 | #define MVPP2_TXQ_RSVD_RSLT_REG 0x20b4 |
| 137 | #define MVPP2_TXQ_RSVD_RSLT_MASK 0x3fff |
| 138 | #define MVPP2_TXQ_RSVD_CLR_REG 0x20b8 |
| 139 | #define MVPP2_TXQ_RSVD_CLR_OFFSET 16 |
| 140 | #define MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu) (0x2100 + 4 * (cpu)) |
| 141 | #define MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu) (0x2140 + 4 * (cpu)) |
| 142 | #define MVPP2_AGGR_TXQ_DESC_SIZE_MASK 0x3ff0 |
| 143 | #define MVPP2_AGGR_TXQ_STATUS_REG(cpu) (0x2180 + 4 * (cpu)) |
| 144 | #define MVPP2_AGGR_TXQ_PENDING_MASK 0x3fff |
| 145 | #define MVPP2_AGGR_TXQ_INDEX_REG(cpu) (0x21c0 + 4 * (cpu)) |
| 146 | |
| 147 | /* MBUS bridge registers */ |
| 148 | #define MVPP2_WIN_BASE(w) (0x4000 + ((w) << 2)) |
| 149 | #define MVPP2_WIN_SIZE(w) (0x4020 + ((w) << 2)) |
| 150 | #define MVPP2_WIN_REMAP(w) (0x4040 + ((w) << 2)) |
| 151 | #define MVPP2_BASE_ADDR_ENABLE 0x4060 |
| 152 | |
| 153 | /* Interrupt Cause and Mask registers */ |
| 154 | #define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq)) |
| 155 | #define MVPP2_ISR_RXQ_GROUP_REG(rxq) (0x5400 + 4 * (rxq)) |
| 156 | #define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port)) |
| 157 | #define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff) |
| 158 | #define MVPP2_ISR_DISABLE_INTERRUPT(mask) (((mask) << 16) & 0xffff0000) |
| 159 | #define MVPP2_ISR_RX_TX_CAUSE_REG(port) (0x5480 + 4 * (port)) |
| 160 | #define MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff |
| 161 | #define MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK 0xff0000 |
| 162 | #define MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK BIT(24) |
| 163 | #define MVPP2_CAUSE_FCS_ERR_MASK BIT(25) |
| 164 | #define MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK BIT(26) |
| 165 | #define MVPP2_CAUSE_TX_EXCEPTION_SUM_MASK BIT(29) |
| 166 | #define MVPP2_CAUSE_RX_EXCEPTION_SUM_MASK BIT(30) |
| 167 | #define MVPP2_CAUSE_MISC_SUM_MASK BIT(31) |
| 168 | #define MVPP2_ISR_RX_TX_MASK_REG(port) (0x54a0 + 4 * (port)) |
| 169 | #define MVPP2_ISR_PON_RX_TX_MASK_REG 0x54bc |
| 170 | #define MVPP2_PON_CAUSE_RXQ_OCCUP_DESC_ALL_MASK 0xffff |
| 171 | #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000 |
| 172 | #define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31) |
| 173 | #define MVPP2_ISR_MISC_CAUSE_REG 0x55b0 |
| 174 | |
| 175 | /* Buffer Manager registers */ |
| 176 | #define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4)) |
| 177 | #define MVPP2_BM_POOL_BASE_ADDR_MASK 0xfffff80 |
| 178 | #define MVPP2_BM_POOL_SIZE_REG(pool) (0x6040 + ((pool) * 4)) |
| 179 | #define MVPP2_BM_POOL_SIZE_MASK 0xfff0 |
| 180 | #define MVPP2_BM_POOL_READ_PTR_REG(pool) (0x6080 + ((pool) * 4)) |
| 181 | #define MVPP2_BM_POOL_GET_READ_PTR_MASK 0xfff0 |
| 182 | #define MVPP2_BM_POOL_PTRS_NUM_REG(pool) (0x60c0 + ((pool) * 4)) |
| 183 | #define MVPP2_BM_POOL_PTRS_NUM_MASK 0xfff0 |
| 184 | #define MVPP2_BM_BPPI_READ_PTR_REG(pool) (0x6100 + ((pool) * 4)) |
| 185 | #define MVPP2_BM_BPPI_PTRS_NUM_REG(pool) (0x6140 + ((pool) * 4)) |
| 186 | #define MVPP2_BM_BPPI_PTR_NUM_MASK 0x7ff |
| 187 | #define MVPP2_BM_BPPI_PREFETCH_FULL_MASK BIT(16) |
| 188 | #define MVPP2_BM_POOL_CTRL_REG(pool) (0x6200 + ((pool) * 4)) |
| 189 | #define MVPP2_BM_START_MASK BIT(0) |
| 190 | #define MVPP2_BM_STOP_MASK BIT(1) |
| 191 | #define MVPP2_BM_STATE_MASK BIT(4) |
| 192 | #define MVPP2_BM_LOW_THRESH_OFFS 8 |
| 193 | #define MVPP2_BM_LOW_THRESH_MASK 0x7f00 |
| 194 | #define MVPP2_BM_LOW_THRESH_VALUE(val) ((val) << \ |
| 195 | MVPP2_BM_LOW_THRESH_OFFS) |
| 196 | #define MVPP2_BM_HIGH_THRESH_OFFS 16 |
| 197 | #define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000 |
| 198 | #define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \ |
| 199 | MVPP2_BM_HIGH_THRESH_OFFS) |
| 200 | #define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4)) |
| 201 | #define MVPP2_BM_RELEASED_DELAY_MASK BIT(0) |
| 202 | #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1) |
| 203 | #define MVPP2_BM_BPPE_EMPTY_MASK BIT(2) |
| 204 | #define MVPP2_BM_BPPE_FULL_MASK BIT(3) |
| 205 | #define MVPP2_BM_AVAILABLE_BP_LOW_MASK BIT(4) |
| 206 | #define MVPP2_BM_INTR_MASK_REG(pool) (0x6280 + ((pool) * 4)) |
| 207 | #define MVPP2_BM_PHY_ALLOC_REG(pool) (0x6400 + ((pool) * 4)) |
| 208 | #define MVPP2_BM_PHY_ALLOC_GRNTD_MASK BIT(0) |
| 209 | #define MVPP2_BM_VIRT_ALLOC_REG 0x6440 |
| 210 | #define MVPP2_BM_PHY_RLS_REG(pool) (0x6480 + ((pool) * 4)) |
| 211 | #define MVPP2_BM_PHY_RLS_MC_BUFF_MASK BIT(0) |
| 212 | #define MVPP2_BM_PHY_RLS_PRIO_EN_MASK BIT(1) |
| 213 | #define MVPP2_BM_PHY_RLS_GRNTD_MASK BIT(2) |
| 214 | #define MVPP2_BM_VIRT_RLS_REG 0x64c0 |
| 215 | #define MVPP2_BM_MC_RLS_REG 0x64c4 |
| 216 | #define MVPP2_BM_MC_ID_MASK 0xfff |
| 217 | #define MVPP2_BM_FORCE_RELEASE_MASK BIT(12) |
| 218 | |
| 219 | /* TX Scheduler registers */ |
| 220 | #define MVPP2_TXP_SCHED_PORT_INDEX_REG 0x8000 |
| 221 | #define MVPP2_TXP_SCHED_Q_CMD_REG 0x8004 |
| 222 | #define MVPP2_TXP_SCHED_ENQ_MASK 0xff |
| 223 | #define MVPP2_TXP_SCHED_DISQ_OFFSET 8 |
| 224 | #define MVPP2_TXP_SCHED_CMD_1_REG 0x8010 |
| 225 | #define MVPP2_TXP_SCHED_PERIOD_REG 0x8018 |
| 226 | #define MVPP2_TXP_SCHED_MTU_REG 0x801c |
| 227 | #define MVPP2_TXP_MTU_MAX 0x7FFFF |
| 228 | #define MVPP2_TXP_SCHED_REFILL_REG 0x8020 |
| 229 | #define MVPP2_TXP_REFILL_TOKENS_ALL_MASK 0x7ffff |
| 230 | #define MVPP2_TXP_REFILL_PERIOD_ALL_MASK 0x3ff00000 |
| 231 | #define MVPP2_TXP_REFILL_PERIOD_MASK(v) ((v) << 20) |
| 232 | #define MVPP2_TXP_SCHED_TOKEN_SIZE_REG 0x8024 |
| 233 | #define MVPP2_TXP_TOKEN_SIZE_MAX 0xffffffff |
| 234 | #define MVPP2_TXQ_SCHED_REFILL_REG(q) (0x8040 + ((q) << 2)) |
| 235 | #define MVPP2_TXQ_REFILL_TOKENS_ALL_MASK 0x7ffff |
| 236 | #define MVPP2_TXQ_REFILL_PERIOD_ALL_MASK 0x3ff00000 |
| 237 | #define MVPP2_TXQ_REFILL_PERIOD_MASK(v) ((v) << 20) |
| 238 | #define MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(q) (0x8060 + ((q) << 2)) |
| 239 | #define MVPP2_TXQ_TOKEN_SIZE_MAX 0x7fffffff |
| 240 | #define MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(q) (0x8080 + ((q) << 2)) |
| 241 | #define MVPP2_TXQ_TOKEN_CNTR_MAX 0xffffffff |
| 242 | |
| 243 | /* TX general registers */ |
| 244 | #define MVPP2_TX_SNOOP_REG 0x8800 |
| 245 | #define MVPP2_TX_PORT_FLUSH_REG 0x8810 |
| 246 | #define MVPP2_TX_PORT_FLUSH_MASK(port) (1 << (port)) |
| 247 | |
| 248 | /* LMS registers */ |
| 249 | #define MVPP2_SRC_ADDR_MIDDLE 0x24 |
| 250 | #define MVPP2_SRC_ADDR_HIGH 0x28 |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 251 | #define MVPP2_PHY_AN_CFG0_REG 0x34 |
| 252 | #define MVPP2_PHY_AN_STOP_SMI0_MASK BIT(7) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 253 | #define MVPP2_MIB_COUNTERS_BASE(port) (0x1000 + ((port) >> 1) * \ |
| 254 | 0x400 + (port) * 0x400) |
| 255 | #define MVPP2_MIB_LATE_COLLISION 0x7c |
| 256 | #define MVPP2_ISR_SUM_MASK_REG 0x220c |
| 257 | #define MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG 0x305c |
| 258 | #define MVPP2_EXT_GLOBAL_CTRL_DEFAULT 0x27 |
| 259 | |
| 260 | /* Per-port registers */ |
| 261 | #define MVPP2_GMAC_CTRL_0_REG 0x0 |
| 262 | #define MVPP2_GMAC_PORT_EN_MASK BIT(0) |
| 263 | #define MVPP2_GMAC_MAX_RX_SIZE_OFFS 2 |
| 264 | #define MVPP2_GMAC_MAX_RX_SIZE_MASK 0x7ffc |
| 265 | #define MVPP2_GMAC_MIB_CNTR_EN_MASK BIT(15) |
| 266 | #define MVPP2_GMAC_CTRL_1_REG 0x4 |
Marcin Wojtas | b5c0a80 | 2014-07-21 13:48:11 -0300 | [diff] [blame] | 267 | #define MVPP2_GMAC_PERIODIC_XON_EN_MASK BIT(1) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 268 | #define MVPP2_GMAC_GMII_LB_EN_MASK BIT(5) |
| 269 | #define MVPP2_GMAC_PCS_LB_EN_BIT 6 |
| 270 | #define MVPP2_GMAC_PCS_LB_EN_MASK BIT(6) |
| 271 | #define MVPP2_GMAC_SA_LOW_OFFS 7 |
| 272 | #define MVPP2_GMAC_CTRL_2_REG 0x8 |
| 273 | #define MVPP2_GMAC_INBAND_AN_MASK BIT(0) |
| 274 | #define MVPP2_GMAC_PCS_ENABLE_MASK BIT(3) |
| 275 | #define MVPP2_GMAC_PORT_RGMII_MASK BIT(4) |
| 276 | #define MVPP2_GMAC_PORT_RESET_MASK BIT(6) |
| 277 | #define MVPP2_GMAC_AUTONEG_CONFIG 0xc |
| 278 | #define MVPP2_GMAC_FORCE_LINK_DOWN BIT(0) |
| 279 | #define MVPP2_GMAC_FORCE_LINK_PASS BIT(1) |
| 280 | #define MVPP2_GMAC_CONFIG_MII_SPEED BIT(5) |
| 281 | #define MVPP2_GMAC_CONFIG_GMII_SPEED BIT(6) |
| 282 | #define MVPP2_GMAC_AN_SPEED_EN BIT(7) |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 283 | #define MVPP2_GMAC_FC_ADV_EN BIT(9) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 284 | #define MVPP2_GMAC_CONFIG_FULL_DUPLEX BIT(12) |
| 285 | #define MVPP2_GMAC_AN_DUPLEX_EN BIT(13) |
| 286 | #define MVPP2_GMAC_PORT_FIFO_CFG_1_REG 0x1c |
| 287 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_OFFS 6 |
| 288 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK 0x1fc0 |
| 289 | #define MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(v) (((v) << 6) & \ |
| 290 | MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK) |
| 291 | |
| 292 | #define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff |
| 293 | |
| 294 | /* Descriptor ring Macros */ |
| 295 | #define MVPP2_QUEUE_NEXT_DESC(q, index) \ |
| 296 | (((index) < (q)->last_desc) ? ((index) + 1) : 0) |
| 297 | |
| 298 | /* Various constants */ |
| 299 | |
| 300 | /* Coalescing */ |
| 301 | #define MVPP2_TXDONE_COAL_PKTS_THRESH 15 |
| 302 | #define MVPP2_RX_COAL_PKTS 32 |
| 303 | #define MVPP2_RX_COAL_USEC 100 |
| 304 | |
| 305 | /* The two bytes Marvell header. Either contains a special value used |
| 306 | * by Marvell switches when a specific hardware mode is enabled (not |
| 307 | * supported by this driver) or is filled automatically by zeroes on |
| 308 | * the RX side. Those two bytes being at the front of the Ethernet |
| 309 | * header, they allow to have the IP header aligned on a 4 bytes |
| 310 | * boundary automatically: the hardware skips those two bytes on its |
| 311 | * own. |
| 312 | */ |
| 313 | #define MVPP2_MH_SIZE 2 |
| 314 | #define MVPP2_ETH_TYPE_LEN 2 |
| 315 | #define MVPP2_PPPOE_HDR_SIZE 8 |
| 316 | #define MVPP2_VLAN_TAG_LEN 4 |
| 317 | |
| 318 | /* Lbtd 802.3 type */ |
| 319 | #define MVPP2_IP_LBDT_TYPE 0xfffa |
| 320 | |
| 321 | #define MVPP2_CPU_D_CACHE_LINE_SIZE 32 |
| 322 | #define MVPP2_TX_CSUM_MAX_SIZE 9800 |
| 323 | |
| 324 | /* Timeout constants */ |
| 325 | #define MVPP2_TX_DISABLE_TIMEOUT_MSEC 1000 |
| 326 | #define MVPP2_TX_PENDING_TIMEOUT_MSEC 1000 |
| 327 | |
| 328 | #define MVPP2_TX_MTU_MAX 0x7ffff |
| 329 | |
| 330 | /* Maximum number of T-CONTs of PON port */ |
| 331 | #define MVPP2_MAX_TCONT 16 |
| 332 | |
| 333 | /* Maximum number of supported ports */ |
| 334 | #define MVPP2_MAX_PORTS 4 |
| 335 | |
| 336 | /* Maximum number of TXQs used by single port */ |
| 337 | #define MVPP2_MAX_TXQ 8 |
| 338 | |
| 339 | /* Maximum number of RXQs used by single port */ |
| 340 | #define MVPP2_MAX_RXQ 8 |
| 341 | |
| 342 | /* Dfault number of RXQs in use */ |
| 343 | #define MVPP2_DEFAULT_RXQ 4 |
| 344 | |
| 345 | /* Total number of RXQs available to all ports */ |
| 346 | #define MVPP2_RXQ_TOTAL_NUM (MVPP2_MAX_PORTS * MVPP2_MAX_RXQ) |
| 347 | |
| 348 | /* Max number of Rx descriptors */ |
| 349 | #define MVPP2_MAX_RXD 128 |
| 350 | |
| 351 | /* Max number of Tx descriptors */ |
| 352 | #define MVPP2_MAX_TXD 1024 |
| 353 | |
| 354 | /* Amount of Tx descriptors that can be reserved at once by CPU */ |
| 355 | #define MVPP2_CPU_DESC_CHUNK 64 |
| 356 | |
| 357 | /* Max number of Tx descriptors in each aggregated queue */ |
| 358 | #define MVPP2_AGGR_TXQ_SIZE 256 |
| 359 | |
| 360 | /* Descriptor aligned size */ |
| 361 | #define MVPP2_DESC_ALIGNED_SIZE 32 |
| 362 | |
| 363 | /* Descriptor alignment mask */ |
| 364 | #define MVPP2_TX_DESC_ALIGN (MVPP2_DESC_ALIGNED_SIZE - 1) |
| 365 | |
| 366 | /* RX FIFO constants */ |
| 367 | #define MVPP2_RX_FIFO_PORT_DATA_SIZE 0x2000 |
| 368 | #define MVPP2_RX_FIFO_PORT_ATTR_SIZE 0x80 |
| 369 | #define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80 |
| 370 | |
| 371 | /* RX buffer constants */ |
| 372 | #define MVPP2_SKB_SHINFO_SIZE \ |
| 373 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) |
| 374 | |
| 375 | #define MVPP2_RX_PKT_SIZE(mtu) \ |
| 376 | ALIGN((mtu) + MVPP2_MH_SIZE + MVPP2_VLAN_TAG_LEN + \ |
| 377 | ETH_HLEN + ETH_FCS_LEN, MVPP2_CPU_D_CACHE_LINE_SIZE) |
| 378 | |
| 379 | #define MVPP2_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD) |
| 380 | #define MVPP2_RX_TOTAL_SIZE(buf_size) ((buf_size) + MVPP2_SKB_SHINFO_SIZE) |
| 381 | #define MVPP2_RX_MAX_PKT_SIZE(total_size) \ |
| 382 | ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE) |
| 383 | |
| 384 | #define MVPP2_BIT_TO_BYTE(bit) ((bit) / 8) |
| 385 | |
| 386 | /* IPv6 max L3 address size */ |
| 387 | #define MVPP2_MAX_L3_ADDR_SIZE 16 |
| 388 | |
| 389 | /* Port flags */ |
| 390 | #define MVPP2_F_LOOPBACK BIT(0) |
| 391 | |
| 392 | /* Marvell tag types */ |
| 393 | enum mvpp2_tag_type { |
| 394 | MVPP2_TAG_TYPE_NONE = 0, |
| 395 | MVPP2_TAG_TYPE_MH = 1, |
| 396 | MVPP2_TAG_TYPE_DSA = 2, |
| 397 | MVPP2_TAG_TYPE_EDSA = 3, |
| 398 | MVPP2_TAG_TYPE_VLAN = 4, |
| 399 | MVPP2_TAG_TYPE_LAST = 5 |
| 400 | }; |
| 401 | |
| 402 | /* Parser constants */ |
| 403 | #define MVPP2_PRS_TCAM_SRAM_SIZE 256 |
| 404 | #define MVPP2_PRS_TCAM_WORDS 6 |
| 405 | #define MVPP2_PRS_SRAM_WORDS 4 |
| 406 | #define MVPP2_PRS_FLOW_ID_SIZE 64 |
| 407 | #define MVPP2_PRS_FLOW_ID_MASK 0x3f |
| 408 | #define MVPP2_PRS_TCAM_ENTRY_INVALID 1 |
| 409 | #define MVPP2_PRS_TCAM_DSA_TAGGED_BIT BIT(5) |
| 410 | #define MVPP2_PRS_IPV4_HEAD 0x40 |
| 411 | #define MVPP2_PRS_IPV4_HEAD_MASK 0xf0 |
| 412 | #define MVPP2_PRS_IPV4_MC 0xe0 |
| 413 | #define MVPP2_PRS_IPV4_MC_MASK 0xf0 |
| 414 | #define MVPP2_PRS_IPV4_BC_MASK 0xff |
| 415 | #define MVPP2_PRS_IPV4_IHL 0x5 |
| 416 | #define MVPP2_PRS_IPV4_IHL_MASK 0xf |
| 417 | #define MVPP2_PRS_IPV6_MC 0xff |
| 418 | #define MVPP2_PRS_IPV6_MC_MASK 0xff |
| 419 | #define MVPP2_PRS_IPV6_HOP_MASK 0xff |
| 420 | #define MVPP2_PRS_TCAM_PROTO_MASK 0xff |
| 421 | #define MVPP2_PRS_TCAM_PROTO_MASK_L 0x3f |
| 422 | #define MVPP2_PRS_DBL_VLANS_MAX 100 |
| 423 | |
| 424 | /* Tcam structure: |
| 425 | * - lookup ID - 4 bits |
| 426 | * - port ID - 1 byte |
| 427 | * - additional information - 1 byte |
| 428 | * - header data - 8 bytes |
| 429 | * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(5)->(0). |
| 430 | */ |
| 431 | #define MVPP2_PRS_AI_BITS 8 |
| 432 | #define MVPP2_PRS_PORT_MASK 0xff |
| 433 | #define MVPP2_PRS_LU_MASK 0xf |
| 434 | #define MVPP2_PRS_TCAM_DATA_BYTE(offs) \ |
| 435 | (((offs) - ((offs) % 2)) * 2 + ((offs) % 2)) |
| 436 | #define MVPP2_PRS_TCAM_DATA_BYTE_EN(offs) \ |
| 437 | (((offs) * 2) - ((offs) % 2) + 2) |
| 438 | #define MVPP2_PRS_TCAM_AI_BYTE 16 |
| 439 | #define MVPP2_PRS_TCAM_PORT_BYTE 17 |
| 440 | #define MVPP2_PRS_TCAM_LU_BYTE 20 |
| 441 | #define MVPP2_PRS_TCAM_EN_OFFS(offs) ((offs) + 2) |
| 442 | #define MVPP2_PRS_TCAM_INV_WORD 5 |
| 443 | /* Tcam entries ID */ |
| 444 | #define MVPP2_PE_DROP_ALL 0 |
| 445 | #define MVPP2_PE_FIRST_FREE_TID 1 |
| 446 | #define MVPP2_PE_LAST_FREE_TID (MVPP2_PRS_TCAM_SRAM_SIZE - 31) |
| 447 | #define MVPP2_PE_IP6_EXT_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 30) |
| 448 | #define MVPP2_PE_MAC_MC_IP6 (MVPP2_PRS_TCAM_SRAM_SIZE - 29) |
| 449 | #define MVPP2_PE_IP6_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 28) |
| 450 | #define MVPP2_PE_IP4_ADDR_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 27) |
| 451 | #define MVPP2_PE_LAST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 26) |
| 452 | #define MVPP2_PE_FIRST_DEFAULT_FLOW (MVPP2_PRS_TCAM_SRAM_SIZE - 19) |
| 453 | #define MVPP2_PE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 18) |
| 454 | #define MVPP2_PE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 17) |
| 455 | #define MVPP2_PE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 16) |
| 456 | #define MVPP2_PE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 15) |
| 457 | #define MVPP2_PE_ETYPE_EDSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 14) |
| 458 | #define MVPP2_PE_ETYPE_EDSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 13) |
| 459 | #define MVPP2_PE_ETYPE_DSA_TAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 12) |
| 460 | #define MVPP2_PE_ETYPE_DSA_UNTAGGED (MVPP2_PRS_TCAM_SRAM_SIZE - 11) |
| 461 | #define MVPP2_PE_MH_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 10) |
| 462 | #define MVPP2_PE_DSA_DEFAULT (MVPP2_PRS_TCAM_SRAM_SIZE - 9) |
| 463 | #define MVPP2_PE_IP6_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 8) |
| 464 | #define MVPP2_PE_IP4_PROTO_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 7) |
| 465 | #define MVPP2_PE_ETH_TYPE_UN (MVPP2_PRS_TCAM_SRAM_SIZE - 6) |
| 466 | #define MVPP2_PE_VLAN_DBL (MVPP2_PRS_TCAM_SRAM_SIZE - 5) |
| 467 | #define MVPP2_PE_VLAN_NONE (MVPP2_PRS_TCAM_SRAM_SIZE - 4) |
| 468 | #define MVPP2_PE_MAC_MC_ALL (MVPP2_PRS_TCAM_SRAM_SIZE - 3) |
| 469 | #define MVPP2_PE_MAC_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 2) |
| 470 | #define MVPP2_PE_MAC_NON_PROMISCUOUS (MVPP2_PRS_TCAM_SRAM_SIZE - 1) |
| 471 | |
| 472 | /* Sram structure |
| 473 | * The fields are represented by MVPP2_PRS_TCAM_DATA_REG(3)->(0). |
| 474 | */ |
| 475 | #define MVPP2_PRS_SRAM_RI_OFFS 0 |
| 476 | #define MVPP2_PRS_SRAM_RI_WORD 0 |
| 477 | #define MVPP2_PRS_SRAM_RI_CTRL_OFFS 32 |
| 478 | #define MVPP2_PRS_SRAM_RI_CTRL_WORD 1 |
| 479 | #define MVPP2_PRS_SRAM_RI_CTRL_BITS 32 |
| 480 | #define MVPP2_PRS_SRAM_SHIFT_OFFS 64 |
| 481 | #define MVPP2_PRS_SRAM_SHIFT_SIGN_BIT 72 |
| 482 | #define MVPP2_PRS_SRAM_UDF_OFFS 73 |
| 483 | #define MVPP2_PRS_SRAM_UDF_BITS 8 |
| 484 | #define MVPP2_PRS_SRAM_UDF_MASK 0xff |
| 485 | #define MVPP2_PRS_SRAM_UDF_SIGN_BIT 81 |
| 486 | #define MVPP2_PRS_SRAM_UDF_TYPE_OFFS 82 |
| 487 | #define MVPP2_PRS_SRAM_UDF_TYPE_MASK 0x7 |
| 488 | #define MVPP2_PRS_SRAM_UDF_TYPE_L3 1 |
| 489 | #define MVPP2_PRS_SRAM_UDF_TYPE_L4 4 |
| 490 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS 85 |
| 491 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK 0x3 |
| 492 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD 1 |
| 493 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP4_ADD 2 |
| 494 | #define MVPP2_PRS_SRAM_OP_SEL_SHIFT_IP6_ADD 3 |
| 495 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS 87 |
| 496 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_BITS 2 |
| 497 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_MASK 0x3 |
| 498 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_ADD 0 |
| 499 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP4_ADD 2 |
| 500 | #define MVPP2_PRS_SRAM_OP_SEL_UDF_IP6_ADD 3 |
| 501 | #define MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS 89 |
| 502 | #define MVPP2_PRS_SRAM_AI_OFFS 90 |
| 503 | #define MVPP2_PRS_SRAM_AI_CTRL_OFFS 98 |
| 504 | #define MVPP2_PRS_SRAM_AI_CTRL_BITS 8 |
| 505 | #define MVPP2_PRS_SRAM_AI_MASK 0xff |
| 506 | #define MVPP2_PRS_SRAM_NEXT_LU_OFFS 106 |
| 507 | #define MVPP2_PRS_SRAM_NEXT_LU_MASK 0xf |
| 508 | #define MVPP2_PRS_SRAM_LU_DONE_BIT 110 |
| 509 | #define MVPP2_PRS_SRAM_LU_GEN_BIT 111 |
| 510 | |
| 511 | /* Sram result info bits assignment */ |
| 512 | #define MVPP2_PRS_RI_MAC_ME_MASK 0x1 |
| 513 | #define MVPP2_PRS_RI_DSA_MASK 0x2 |
| 514 | #define MVPP2_PRS_RI_VLAN_MASK 0xc |
| 515 | #define MVPP2_PRS_RI_VLAN_NONE ~(BIT(2) | BIT(3)) |
| 516 | #define MVPP2_PRS_RI_VLAN_SINGLE BIT(2) |
| 517 | #define MVPP2_PRS_RI_VLAN_DOUBLE BIT(3) |
| 518 | #define MVPP2_PRS_RI_VLAN_TRIPLE (BIT(2) | BIT(3)) |
| 519 | #define MVPP2_PRS_RI_CPU_CODE_MASK 0x70 |
| 520 | #define MVPP2_PRS_RI_CPU_CODE_RX_SPEC BIT(4) |
| 521 | #define MVPP2_PRS_RI_L2_CAST_MASK 0x600 |
| 522 | #define MVPP2_PRS_RI_L2_UCAST ~(BIT(9) | BIT(10)) |
| 523 | #define MVPP2_PRS_RI_L2_MCAST BIT(9) |
| 524 | #define MVPP2_PRS_RI_L2_BCAST BIT(10) |
| 525 | #define MVPP2_PRS_RI_PPPOE_MASK 0x800 |
| 526 | #define MVPP2_PRS_RI_L3_PROTO_MASK 0x7000 |
| 527 | #define MVPP2_PRS_RI_L3_UN ~(BIT(12) | BIT(13) | BIT(14)) |
| 528 | #define MVPP2_PRS_RI_L3_IP4 BIT(12) |
| 529 | #define MVPP2_PRS_RI_L3_IP4_OPT BIT(13) |
| 530 | #define MVPP2_PRS_RI_L3_IP4_OTHER (BIT(12) | BIT(13)) |
| 531 | #define MVPP2_PRS_RI_L3_IP6 BIT(14) |
| 532 | #define MVPP2_PRS_RI_L3_IP6_EXT (BIT(12) | BIT(14)) |
| 533 | #define MVPP2_PRS_RI_L3_ARP (BIT(13) | BIT(14)) |
| 534 | #define MVPP2_PRS_RI_L3_ADDR_MASK 0x18000 |
| 535 | #define MVPP2_PRS_RI_L3_UCAST ~(BIT(15) | BIT(16)) |
| 536 | #define MVPP2_PRS_RI_L3_MCAST BIT(15) |
| 537 | #define MVPP2_PRS_RI_L3_BCAST (BIT(15) | BIT(16)) |
| 538 | #define MVPP2_PRS_RI_IP_FRAG_MASK 0x20000 |
| 539 | #define MVPP2_PRS_RI_UDF3_MASK 0x300000 |
| 540 | #define MVPP2_PRS_RI_UDF3_RX_SPECIAL BIT(21) |
| 541 | #define MVPP2_PRS_RI_L4_PROTO_MASK 0x1c00000 |
| 542 | #define MVPP2_PRS_RI_L4_TCP BIT(22) |
| 543 | #define MVPP2_PRS_RI_L4_UDP BIT(23) |
| 544 | #define MVPP2_PRS_RI_L4_OTHER (BIT(22) | BIT(23)) |
| 545 | #define MVPP2_PRS_RI_UDF7_MASK 0x60000000 |
| 546 | #define MVPP2_PRS_RI_UDF7_IP6_LITE BIT(29) |
| 547 | #define MVPP2_PRS_RI_DROP_MASK 0x80000000 |
| 548 | |
| 549 | /* Sram additional info bits assignment */ |
| 550 | #define MVPP2_PRS_IPV4_DIP_AI_BIT BIT(0) |
| 551 | #define MVPP2_PRS_IPV6_NO_EXT_AI_BIT BIT(0) |
| 552 | #define MVPP2_PRS_IPV6_EXT_AI_BIT BIT(1) |
| 553 | #define MVPP2_PRS_IPV6_EXT_AH_AI_BIT BIT(2) |
| 554 | #define MVPP2_PRS_IPV6_EXT_AH_LEN_AI_BIT BIT(3) |
| 555 | #define MVPP2_PRS_IPV6_EXT_AH_L4_AI_BIT BIT(4) |
| 556 | #define MVPP2_PRS_SINGLE_VLAN_AI 0 |
| 557 | #define MVPP2_PRS_DBL_VLAN_AI_BIT BIT(7) |
| 558 | |
| 559 | /* DSA/EDSA type */ |
| 560 | #define MVPP2_PRS_TAGGED true |
| 561 | #define MVPP2_PRS_UNTAGGED false |
| 562 | #define MVPP2_PRS_EDSA true |
| 563 | #define MVPP2_PRS_DSA false |
| 564 | |
| 565 | /* MAC entries, shadow udf */ |
| 566 | enum mvpp2_prs_udf { |
| 567 | MVPP2_PRS_UDF_MAC_DEF, |
| 568 | MVPP2_PRS_UDF_MAC_RANGE, |
| 569 | MVPP2_PRS_UDF_L2_DEF, |
| 570 | MVPP2_PRS_UDF_L2_DEF_COPY, |
| 571 | MVPP2_PRS_UDF_L2_USER, |
| 572 | }; |
| 573 | |
| 574 | /* Lookup ID */ |
| 575 | enum mvpp2_prs_lookup { |
| 576 | MVPP2_PRS_LU_MH, |
| 577 | MVPP2_PRS_LU_MAC, |
| 578 | MVPP2_PRS_LU_DSA, |
| 579 | MVPP2_PRS_LU_VLAN, |
| 580 | MVPP2_PRS_LU_L2, |
| 581 | MVPP2_PRS_LU_PPPOE, |
| 582 | MVPP2_PRS_LU_IP4, |
| 583 | MVPP2_PRS_LU_IP6, |
| 584 | MVPP2_PRS_LU_FLOWS, |
| 585 | MVPP2_PRS_LU_LAST, |
| 586 | }; |
| 587 | |
| 588 | /* L3 cast enum */ |
| 589 | enum mvpp2_prs_l3_cast { |
| 590 | MVPP2_PRS_L3_UNI_CAST, |
| 591 | MVPP2_PRS_L3_MULTI_CAST, |
| 592 | MVPP2_PRS_L3_BROAD_CAST |
| 593 | }; |
| 594 | |
| 595 | /* Classifier constants */ |
| 596 | #define MVPP2_CLS_FLOWS_TBL_SIZE 512 |
| 597 | #define MVPP2_CLS_FLOWS_TBL_DATA_WORDS 3 |
| 598 | #define MVPP2_CLS_LKP_TBL_SIZE 64 |
| 599 | |
| 600 | /* BM constants */ |
| 601 | #define MVPP2_BM_POOLS_NUM 8 |
| 602 | #define MVPP2_BM_LONG_BUF_NUM 1024 |
| 603 | #define MVPP2_BM_SHORT_BUF_NUM 2048 |
| 604 | #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4) |
| 605 | #define MVPP2_BM_POOL_PTR_ALIGN 128 |
| 606 | #define MVPP2_BM_SWF_LONG_POOL(port) ((port > 2) ? 2 : port) |
| 607 | #define MVPP2_BM_SWF_SHORT_POOL 3 |
| 608 | |
| 609 | /* BM cookie (32 bits) definition */ |
| 610 | #define MVPP2_BM_COOKIE_POOL_OFFS 8 |
| 611 | #define MVPP2_BM_COOKIE_CPU_OFFS 24 |
| 612 | |
| 613 | /* BM short pool packet size |
| 614 | * These value assure that for SWF the total number |
| 615 | * of bytes allocated for each buffer will be 512 |
| 616 | */ |
| 617 | #define MVPP2_BM_SHORT_PKT_SIZE MVPP2_RX_MAX_PKT_SIZE(512) |
| 618 | |
| 619 | enum mvpp2_bm_type { |
| 620 | MVPP2_BM_FREE, |
| 621 | MVPP2_BM_SWF_LONG, |
| 622 | MVPP2_BM_SWF_SHORT |
| 623 | }; |
| 624 | |
| 625 | /* Definitions */ |
| 626 | |
| 627 | /* Shared Packet Processor resources */ |
| 628 | struct mvpp2 { |
| 629 | /* Shared registers' base addresses */ |
| 630 | void __iomem *base; |
| 631 | void __iomem *lms_base; |
| 632 | |
| 633 | /* Common clocks */ |
| 634 | struct clk *pp_clk; |
| 635 | struct clk *gop_clk; |
| 636 | |
| 637 | /* List of pointers to port structures */ |
| 638 | struct mvpp2_port **port_list; |
| 639 | |
| 640 | /* Aggregated TXQs */ |
| 641 | struct mvpp2_tx_queue *aggr_txqs; |
| 642 | |
| 643 | /* BM pools */ |
| 644 | struct mvpp2_bm_pool *bm_pools; |
| 645 | |
| 646 | /* PRS shadow table */ |
| 647 | struct mvpp2_prs_shadow *prs_shadow; |
| 648 | /* PRS auxiliary table for double vlan entries control */ |
| 649 | bool *prs_double_vlans; |
| 650 | |
| 651 | /* Tclk value */ |
| 652 | u32 tclk; |
| 653 | }; |
| 654 | |
| 655 | struct mvpp2_pcpu_stats { |
| 656 | struct u64_stats_sync syncp; |
| 657 | u64 rx_packets; |
| 658 | u64 rx_bytes; |
| 659 | u64 tx_packets; |
| 660 | u64 tx_bytes; |
| 661 | }; |
| 662 | |
| 663 | struct mvpp2_port { |
| 664 | u8 id; |
| 665 | |
| 666 | int irq; |
| 667 | |
| 668 | struct mvpp2 *priv; |
| 669 | |
| 670 | /* Per-port registers' base address */ |
| 671 | void __iomem *base; |
| 672 | |
| 673 | struct mvpp2_rx_queue **rxqs; |
| 674 | struct mvpp2_tx_queue **txqs; |
| 675 | struct net_device *dev; |
| 676 | |
| 677 | int pkt_size; |
| 678 | |
| 679 | u32 pending_cause_rx; |
| 680 | struct napi_struct napi; |
| 681 | |
| 682 | /* Flags */ |
| 683 | unsigned long flags; |
| 684 | |
| 685 | u16 tx_ring_size; |
| 686 | u16 rx_ring_size; |
| 687 | struct mvpp2_pcpu_stats __percpu *stats; |
| 688 | |
| 689 | struct phy_device *phy_dev; |
| 690 | phy_interface_t phy_interface; |
| 691 | struct device_node *phy_node; |
| 692 | unsigned int link; |
| 693 | unsigned int duplex; |
| 694 | unsigned int speed; |
| 695 | |
| 696 | struct mvpp2_bm_pool *pool_long; |
| 697 | struct mvpp2_bm_pool *pool_short; |
| 698 | |
| 699 | /* Index of first port's physical RXQ */ |
| 700 | u8 first_rxq; |
| 701 | }; |
| 702 | |
| 703 | /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the |
| 704 | * layout of the transmit and reception DMA descriptors, and their |
| 705 | * layout is therefore defined by the hardware design |
| 706 | */ |
| 707 | |
| 708 | #define MVPP2_TXD_L3_OFF_SHIFT 0 |
| 709 | #define MVPP2_TXD_IP_HLEN_SHIFT 8 |
| 710 | #define MVPP2_TXD_L4_CSUM_FRAG BIT(13) |
| 711 | #define MVPP2_TXD_L4_CSUM_NOT BIT(14) |
| 712 | #define MVPP2_TXD_IP_CSUM_DISABLE BIT(15) |
| 713 | #define MVPP2_TXD_PADDING_DISABLE BIT(23) |
| 714 | #define MVPP2_TXD_L4_UDP BIT(24) |
| 715 | #define MVPP2_TXD_L3_IP6 BIT(26) |
| 716 | #define MVPP2_TXD_L_DESC BIT(28) |
| 717 | #define MVPP2_TXD_F_DESC BIT(29) |
| 718 | |
| 719 | #define MVPP2_RXD_ERR_SUMMARY BIT(15) |
| 720 | #define MVPP2_RXD_ERR_CODE_MASK (BIT(13) | BIT(14)) |
| 721 | #define MVPP2_RXD_ERR_CRC 0x0 |
| 722 | #define MVPP2_RXD_ERR_OVERRUN BIT(13) |
| 723 | #define MVPP2_RXD_ERR_RESOURCE (BIT(13) | BIT(14)) |
| 724 | #define MVPP2_RXD_BM_POOL_ID_OFFS 16 |
| 725 | #define MVPP2_RXD_BM_POOL_ID_MASK (BIT(16) | BIT(17) | BIT(18)) |
| 726 | #define MVPP2_RXD_HWF_SYNC BIT(21) |
| 727 | #define MVPP2_RXD_L4_CSUM_OK BIT(22) |
| 728 | #define MVPP2_RXD_IP4_HEADER_ERR BIT(24) |
| 729 | #define MVPP2_RXD_L4_TCP BIT(25) |
| 730 | #define MVPP2_RXD_L4_UDP BIT(26) |
| 731 | #define MVPP2_RXD_L3_IP4 BIT(28) |
| 732 | #define MVPP2_RXD_L3_IP6 BIT(30) |
| 733 | #define MVPP2_RXD_BUF_HDR BIT(31) |
| 734 | |
| 735 | struct mvpp2_tx_desc { |
| 736 | u32 command; /* Options used by HW for packet transmitting.*/ |
| 737 | u8 packet_offset; /* the offset from the buffer beginning */ |
| 738 | u8 phys_txq; /* destination queue ID */ |
| 739 | u16 data_size; /* data size of transmitted packet in bytes */ |
| 740 | u32 buf_phys_addr; /* physical addr of transmitted buffer */ |
| 741 | u32 buf_cookie; /* cookie for access to TX buffer in tx path */ |
| 742 | u32 reserved1[3]; /* hw_cmd (for future use, BM, PON, PNC) */ |
| 743 | u32 reserved2; /* reserved (for future use) */ |
| 744 | }; |
| 745 | |
| 746 | struct mvpp2_rx_desc { |
| 747 | u32 status; /* info about received packet */ |
| 748 | u16 reserved1; /* parser_info (for future use, PnC) */ |
| 749 | u16 data_size; /* size of received packet in bytes */ |
| 750 | u32 buf_phys_addr; /* physical address of the buffer */ |
| 751 | u32 buf_cookie; /* cookie for access to RX buffer in rx path */ |
| 752 | u16 reserved2; /* gem_port_id (for future use, PON) */ |
| 753 | u16 reserved3; /* csum_l4 (for future use, PnC) */ |
| 754 | u8 reserved4; /* bm_qset (for future use, BM) */ |
| 755 | u8 reserved5; |
| 756 | u16 reserved6; /* classify_info (for future use, PnC) */ |
| 757 | u32 reserved7; /* flow_id (for future use, PnC) */ |
| 758 | u32 reserved8; |
| 759 | }; |
| 760 | |
| 761 | /* Per-CPU Tx queue control */ |
| 762 | struct mvpp2_txq_pcpu { |
| 763 | int cpu; |
| 764 | |
| 765 | /* Number of Tx DMA descriptors in the descriptor ring */ |
| 766 | int size; |
| 767 | |
| 768 | /* Number of currently used Tx DMA descriptor in the |
| 769 | * descriptor ring |
| 770 | */ |
| 771 | int count; |
| 772 | |
| 773 | /* Number of Tx DMA descriptors reserved for each CPU */ |
| 774 | int reserved_num; |
| 775 | |
| 776 | /* Array of transmitted skb */ |
| 777 | struct sk_buff **tx_skb; |
| 778 | |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 779 | /* Array of transmitted buffers' physical addresses */ |
| 780 | dma_addr_t *tx_buffs; |
| 781 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 782 | /* Index of last TX DMA descriptor that was inserted */ |
| 783 | int txq_put_index; |
| 784 | |
| 785 | /* Index of the TX DMA descriptor to be cleaned up */ |
| 786 | int txq_get_index; |
| 787 | }; |
| 788 | |
| 789 | struct mvpp2_tx_queue { |
| 790 | /* Physical number of this Tx queue */ |
| 791 | u8 id; |
| 792 | |
| 793 | /* Logical number of this Tx queue */ |
| 794 | u8 log_id; |
| 795 | |
| 796 | /* Number of Tx DMA descriptors in the descriptor ring */ |
| 797 | int size; |
| 798 | |
| 799 | /* Number of currently used Tx DMA descriptor in the descriptor ring */ |
| 800 | int count; |
| 801 | |
| 802 | /* Per-CPU control of physical Tx queues */ |
| 803 | struct mvpp2_txq_pcpu __percpu *pcpu; |
| 804 | |
| 805 | /* Array of transmitted skb */ |
| 806 | struct sk_buff **tx_skb; |
| 807 | |
| 808 | u32 done_pkts_coal; |
| 809 | |
| 810 | /* Virtual address of thex Tx DMA descriptors array */ |
| 811 | struct mvpp2_tx_desc *descs; |
| 812 | |
| 813 | /* DMA address of the Tx DMA descriptors array */ |
| 814 | dma_addr_t descs_phys; |
| 815 | |
| 816 | /* Index of the last Tx DMA descriptor */ |
| 817 | int last_desc; |
| 818 | |
| 819 | /* Index of the next Tx DMA descriptor to process */ |
| 820 | int next_desc_to_proc; |
| 821 | }; |
| 822 | |
| 823 | struct mvpp2_rx_queue { |
| 824 | /* RX queue number, in the range 0-31 for physical RXQs */ |
| 825 | u8 id; |
| 826 | |
| 827 | /* Num of rx descriptors in the rx descriptor ring */ |
| 828 | int size; |
| 829 | |
| 830 | u32 pkts_coal; |
| 831 | u32 time_coal; |
| 832 | |
| 833 | /* Virtual address of the RX DMA descriptors array */ |
| 834 | struct mvpp2_rx_desc *descs; |
| 835 | |
| 836 | /* DMA address of the RX DMA descriptors array */ |
| 837 | dma_addr_t descs_phys; |
| 838 | |
| 839 | /* Index of the last RX DMA descriptor */ |
| 840 | int last_desc; |
| 841 | |
| 842 | /* Index of the next RX DMA descriptor to process */ |
| 843 | int next_desc_to_proc; |
| 844 | |
| 845 | /* ID of port to which physical RXQ is mapped */ |
| 846 | int port; |
| 847 | |
| 848 | /* Port's logic RXQ number to which physical RXQ is mapped */ |
| 849 | int logic_rxq; |
| 850 | }; |
| 851 | |
| 852 | union mvpp2_prs_tcam_entry { |
| 853 | u32 word[MVPP2_PRS_TCAM_WORDS]; |
| 854 | u8 byte[MVPP2_PRS_TCAM_WORDS * 4]; |
| 855 | }; |
| 856 | |
| 857 | union mvpp2_prs_sram_entry { |
| 858 | u32 word[MVPP2_PRS_SRAM_WORDS]; |
| 859 | u8 byte[MVPP2_PRS_SRAM_WORDS * 4]; |
| 860 | }; |
| 861 | |
| 862 | struct mvpp2_prs_entry { |
| 863 | u32 index; |
| 864 | union mvpp2_prs_tcam_entry tcam; |
| 865 | union mvpp2_prs_sram_entry sram; |
| 866 | }; |
| 867 | |
| 868 | struct mvpp2_prs_shadow { |
| 869 | bool valid; |
| 870 | bool finish; |
| 871 | |
| 872 | /* Lookup ID */ |
| 873 | int lu; |
| 874 | |
| 875 | /* User defined offset */ |
| 876 | int udf; |
| 877 | |
| 878 | /* Result info */ |
| 879 | u32 ri; |
| 880 | u32 ri_mask; |
| 881 | }; |
| 882 | |
| 883 | struct mvpp2_cls_flow_entry { |
| 884 | u32 index; |
| 885 | u32 data[MVPP2_CLS_FLOWS_TBL_DATA_WORDS]; |
| 886 | }; |
| 887 | |
| 888 | struct mvpp2_cls_lookup_entry { |
| 889 | u32 lkpid; |
| 890 | u32 way; |
| 891 | u32 data; |
| 892 | }; |
| 893 | |
| 894 | struct mvpp2_bm_pool { |
| 895 | /* Pool number in the range 0-7 */ |
| 896 | int id; |
| 897 | enum mvpp2_bm_type type; |
| 898 | |
| 899 | /* Buffer Pointers Pool External (BPPE) size */ |
| 900 | int size; |
| 901 | /* Number of buffers for this pool */ |
| 902 | int buf_num; |
| 903 | /* Pool buffer size */ |
| 904 | int buf_size; |
| 905 | /* Packet size */ |
| 906 | int pkt_size; |
| 907 | |
| 908 | /* BPPE virtual base address */ |
| 909 | u32 *virt_addr; |
| 910 | /* BPPE physical base address */ |
| 911 | dma_addr_t phys_addr; |
| 912 | |
| 913 | /* Ports using BM pool */ |
| 914 | u32 port_map; |
| 915 | |
| 916 | /* Occupied buffers indicator */ |
| 917 | atomic_t in_use; |
| 918 | int in_use_thresh; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | struct mvpp2_buff_hdr { |
| 922 | u32 next_buff_phys_addr; |
| 923 | u32 next_buff_virt_addr; |
| 924 | u16 byte_count; |
| 925 | u16 info; |
| 926 | u8 reserved1; /* bm_qset (for future use, BM) */ |
| 927 | }; |
| 928 | |
| 929 | /* Buffer header info bits */ |
| 930 | #define MVPP2_B_HDR_INFO_MC_ID_MASK 0xfff |
| 931 | #define MVPP2_B_HDR_INFO_MC_ID(info) ((info) & MVPP2_B_HDR_INFO_MC_ID_MASK) |
| 932 | #define MVPP2_B_HDR_INFO_LAST_OFFS 12 |
| 933 | #define MVPP2_B_HDR_INFO_LAST_MASK BIT(12) |
| 934 | #define MVPP2_B_HDR_INFO_IS_LAST(info) \ |
| 935 | ((info & MVPP2_B_HDR_INFO_LAST_MASK) >> MVPP2_B_HDR_INFO_LAST_OFFS) |
| 936 | |
| 937 | /* Static declaractions */ |
| 938 | |
| 939 | /* Number of RXQs used by single port */ |
| 940 | static int rxq_number = MVPP2_DEFAULT_RXQ; |
| 941 | /* Number of TXQs used by single port */ |
| 942 | static int txq_number = MVPP2_MAX_TXQ; |
| 943 | |
| 944 | #define MVPP2_DRIVER_NAME "mvpp2" |
| 945 | #define MVPP2_DRIVER_VERSION "1.0" |
| 946 | |
| 947 | /* Utility/helper methods */ |
| 948 | |
| 949 | static void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data) |
| 950 | { |
| 951 | writel(data, priv->base + offset); |
| 952 | } |
| 953 | |
| 954 | static u32 mvpp2_read(struct mvpp2 *priv, u32 offset) |
| 955 | { |
| 956 | return readl(priv->base + offset); |
| 957 | } |
| 958 | |
| 959 | static void mvpp2_txq_inc_get(struct mvpp2_txq_pcpu *txq_pcpu) |
| 960 | { |
| 961 | txq_pcpu->txq_get_index++; |
| 962 | if (txq_pcpu->txq_get_index == txq_pcpu->size) |
| 963 | txq_pcpu->txq_get_index = 0; |
| 964 | } |
| 965 | |
| 966 | static void mvpp2_txq_inc_put(struct mvpp2_txq_pcpu *txq_pcpu, |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 967 | struct sk_buff *skb, |
| 968 | struct mvpp2_tx_desc *tx_desc) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 969 | { |
| 970 | txq_pcpu->tx_skb[txq_pcpu->txq_put_index] = skb; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 971 | if (skb) |
| 972 | txq_pcpu->tx_buffs[txq_pcpu->txq_put_index] = |
| 973 | tx_desc->buf_phys_addr; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 974 | txq_pcpu->txq_put_index++; |
| 975 | if (txq_pcpu->txq_put_index == txq_pcpu->size) |
| 976 | txq_pcpu->txq_put_index = 0; |
| 977 | } |
| 978 | |
| 979 | /* Get number of physical egress port */ |
| 980 | static inline int mvpp2_egress_port(struct mvpp2_port *port) |
| 981 | { |
| 982 | return MVPP2_MAX_TCONT + port->id; |
| 983 | } |
| 984 | |
| 985 | /* Get number of physical TXQ */ |
| 986 | static inline int mvpp2_txq_phys(int port, int txq) |
| 987 | { |
| 988 | return (MVPP2_MAX_TCONT + port) * MVPP2_MAX_TXQ + txq; |
| 989 | } |
| 990 | |
| 991 | /* Parser configuration routines */ |
| 992 | |
| 993 | /* Update parser tcam and sram hw entries */ |
| 994 | static int mvpp2_prs_hw_write(struct mvpp2 *priv, struct mvpp2_prs_entry *pe) |
| 995 | { |
| 996 | int i; |
| 997 | |
| 998 | if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1) |
| 999 | return -EINVAL; |
| 1000 | |
| 1001 | /* Clear entry invalidation bit */ |
| 1002 | pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] &= ~MVPP2_PRS_TCAM_INV_MASK; |
| 1003 | |
| 1004 | /* Write tcam index - indirect access */ |
| 1005 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index); |
| 1006 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) |
| 1007 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), pe->tcam.word[i]); |
| 1008 | |
| 1009 | /* Write sram index - indirect access */ |
| 1010 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index); |
| 1011 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) |
| 1012 | mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), pe->sram.word[i]); |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | /* Read tcam entry from hw */ |
| 1018 | static int mvpp2_prs_hw_read(struct mvpp2 *priv, struct mvpp2_prs_entry *pe) |
| 1019 | { |
| 1020 | int i; |
| 1021 | |
| 1022 | if (pe->index > MVPP2_PRS_TCAM_SRAM_SIZE - 1) |
| 1023 | return -EINVAL; |
| 1024 | |
| 1025 | /* Write tcam index - indirect access */ |
| 1026 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, pe->index); |
| 1027 | |
| 1028 | pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] = mvpp2_read(priv, |
| 1029 | MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD)); |
| 1030 | if (pe->tcam.word[MVPP2_PRS_TCAM_INV_WORD] & MVPP2_PRS_TCAM_INV_MASK) |
| 1031 | return MVPP2_PRS_TCAM_ENTRY_INVALID; |
| 1032 | |
| 1033 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) |
| 1034 | pe->tcam.word[i] = mvpp2_read(priv, MVPP2_PRS_TCAM_DATA_REG(i)); |
| 1035 | |
| 1036 | /* Write sram index - indirect access */ |
| 1037 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, pe->index); |
| 1038 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) |
| 1039 | pe->sram.word[i] = mvpp2_read(priv, MVPP2_PRS_SRAM_DATA_REG(i)); |
| 1040 | |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | /* Invalidate tcam hw entry */ |
| 1045 | static void mvpp2_prs_hw_inv(struct mvpp2 *priv, int index) |
| 1046 | { |
| 1047 | /* Write index - indirect access */ |
| 1048 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index); |
| 1049 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(MVPP2_PRS_TCAM_INV_WORD), |
| 1050 | MVPP2_PRS_TCAM_INV_MASK); |
| 1051 | } |
| 1052 | |
| 1053 | /* Enable shadow table entry and set its lookup ID */ |
| 1054 | static void mvpp2_prs_shadow_set(struct mvpp2 *priv, int index, int lu) |
| 1055 | { |
| 1056 | priv->prs_shadow[index].valid = true; |
| 1057 | priv->prs_shadow[index].lu = lu; |
| 1058 | } |
| 1059 | |
| 1060 | /* Update ri fields in shadow table entry */ |
| 1061 | static void mvpp2_prs_shadow_ri_set(struct mvpp2 *priv, int index, |
| 1062 | unsigned int ri, unsigned int ri_mask) |
| 1063 | { |
| 1064 | priv->prs_shadow[index].ri_mask = ri_mask; |
| 1065 | priv->prs_shadow[index].ri = ri; |
| 1066 | } |
| 1067 | |
| 1068 | /* Update lookup field in tcam sw entry */ |
| 1069 | static void mvpp2_prs_tcam_lu_set(struct mvpp2_prs_entry *pe, unsigned int lu) |
| 1070 | { |
| 1071 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_LU_BYTE); |
| 1072 | |
| 1073 | pe->tcam.byte[MVPP2_PRS_TCAM_LU_BYTE] = lu; |
| 1074 | pe->tcam.byte[enable_off] = MVPP2_PRS_LU_MASK; |
| 1075 | } |
| 1076 | |
| 1077 | /* Update mask for single port in tcam sw entry */ |
| 1078 | static void mvpp2_prs_tcam_port_set(struct mvpp2_prs_entry *pe, |
| 1079 | unsigned int port, bool add) |
| 1080 | { |
| 1081 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); |
| 1082 | |
| 1083 | if (add) |
| 1084 | pe->tcam.byte[enable_off] &= ~(1 << port); |
| 1085 | else |
| 1086 | pe->tcam.byte[enable_off] |= 1 << port; |
| 1087 | } |
| 1088 | |
| 1089 | /* Update port map in tcam sw entry */ |
| 1090 | static void mvpp2_prs_tcam_port_map_set(struct mvpp2_prs_entry *pe, |
| 1091 | unsigned int ports) |
| 1092 | { |
| 1093 | unsigned char port_mask = MVPP2_PRS_PORT_MASK; |
| 1094 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); |
| 1095 | |
| 1096 | pe->tcam.byte[MVPP2_PRS_TCAM_PORT_BYTE] = 0; |
| 1097 | pe->tcam.byte[enable_off] &= ~port_mask; |
| 1098 | pe->tcam.byte[enable_off] |= ~ports & MVPP2_PRS_PORT_MASK; |
| 1099 | } |
| 1100 | |
| 1101 | /* Obtain port map from tcam sw entry */ |
| 1102 | static unsigned int mvpp2_prs_tcam_port_map_get(struct mvpp2_prs_entry *pe) |
| 1103 | { |
| 1104 | int enable_off = MVPP2_PRS_TCAM_EN_OFFS(MVPP2_PRS_TCAM_PORT_BYTE); |
| 1105 | |
| 1106 | return ~(pe->tcam.byte[enable_off]) & MVPP2_PRS_PORT_MASK; |
| 1107 | } |
| 1108 | |
| 1109 | /* Set byte of data and its enable bits in tcam sw entry */ |
| 1110 | static void mvpp2_prs_tcam_data_byte_set(struct mvpp2_prs_entry *pe, |
| 1111 | unsigned int offs, unsigned char byte, |
| 1112 | unsigned char enable) |
| 1113 | { |
| 1114 | pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)] = byte; |
| 1115 | pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)] = enable; |
| 1116 | } |
| 1117 | |
| 1118 | /* Get byte of data and its enable bits from tcam sw entry */ |
| 1119 | static void mvpp2_prs_tcam_data_byte_get(struct mvpp2_prs_entry *pe, |
| 1120 | unsigned int offs, unsigned char *byte, |
| 1121 | unsigned char *enable) |
| 1122 | { |
| 1123 | *byte = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(offs)]; |
| 1124 | *enable = pe->tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(offs)]; |
| 1125 | } |
| 1126 | |
| 1127 | /* Compare tcam data bytes with a pattern */ |
| 1128 | static bool mvpp2_prs_tcam_data_cmp(struct mvpp2_prs_entry *pe, int offs, |
| 1129 | u16 data) |
| 1130 | { |
| 1131 | int off = MVPP2_PRS_TCAM_DATA_BYTE(offs); |
| 1132 | u16 tcam_data; |
| 1133 | |
| 1134 | tcam_data = (8 << pe->tcam.byte[off + 1]) | pe->tcam.byte[off]; |
| 1135 | if (tcam_data != data) |
| 1136 | return false; |
| 1137 | return true; |
| 1138 | } |
| 1139 | |
| 1140 | /* Update ai bits in tcam sw entry */ |
| 1141 | static void mvpp2_prs_tcam_ai_update(struct mvpp2_prs_entry *pe, |
| 1142 | unsigned int bits, unsigned int enable) |
| 1143 | { |
| 1144 | int i, ai_idx = MVPP2_PRS_TCAM_AI_BYTE; |
| 1145 | |
| 1146 | for (i = 0; i < MVPP2_PRS_AI_BITS; i++) { |
| 1147 | |
| 1148 | if (!(enable & BIT(i))) |
| 1149 | continue; |
| 1150 | |
| 1151 | if (bits & BIT(i)) |
| 1152 | pe->tcam.byte[ai_idx] |= 1 << i; |
| 1153 | else |
| 1154 | pe->tcam.byte[ai_idx] &= ~(1 << i); |
| 1155 | } |
| 1156 | |
| 1157 | pe->tcam.byte[MVPP2_PRS_TCAM_EN_OFFS(ai_idx)] |= enable; |
| 1158 | } |
| 1159 | |
| 1160 | /* Get ai bits from tcam sw entry */ |
| 1161 | static int mvpp2_prs_tcam_ai_get(struct mvpp2_prs_entry *pe) |
| 1162 | { |
| 1163 | return pe->tcam.byte[MVPP2_PRS_TCAM_AI_BYTE]; |
| 1164 | } |
| 1165 | |
| 1166 | /* Set ethertype in tcam sw entry */ |
| 1167 | static void mvpp2_prs_match_etype(struct mvpp2_prs_entry *pe, int offset, |
| 1168 | unsigned short ethertype) |
| 1169 | { |
| 1170 | mvpp2_prs_tcam_data_byte_set(pe, offset + 0, ethertype >> 8, 0xff); |
| 1171 | mvpp2_prs_tcam_data_byte_set(pe, offset + 1, ethertype & 0xff, 0xff); |
| 1172 | } |
| 1173 | |
| 1174 | /* Set bits in sram sw entry */ |
| 1175 | static void mvpp2_prs_sram_bits_set(struct mvpp2_prs_entry *pe, int bit_num, |
| 1176 | int val) |
| 1177 | { |
| 1178 | pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] |= (val << (bit_num % 8)); |
| 1179 | } |
| 1180 | |
| 1181 | /* Clear bits in sram sw entry */ |
| 1182 | static void mvpp2_prs_sram_bits_clear(struct mvpp2_prs_entry *pe, int bit_num, |
| 1183 | int val) |
| 1184 | { |
| 1185 | pe->sram.byte[MVPP2_BIT_TO_BYTE(bit_num)] &= ~(val << (bit_num % 8)); |
| 1186 | } |
| 1187 | |
| 1188 | /* Update ri bits in sram sw entry */ |
| 1189 | static void mvpp2_prs_sram_ri_update(struct mvpp2_prs_entry *pe, |
| 1190 | unsigned int bits, unsigned int mask) |
| 1191 | { |
| 1192 | unsigned int i; |
| 1193 | |
| 1194 | for (i = 0; i < MVPP2_PRS_SRAM_RI_CTRL_BITS; i++) { |
| 1195 | int ri_off = MVPP2_PRS_SRAM_RI_OFFS; |
| 1196 | |
| 1197 | if (!(mask & BIT(i))) |
| 1198 | continue; |
| 1199 | |
| 1200 | if (bits & BIT(i)) |
| 1201 | mvpp2_prs_sram_bits_set(pe, ri_off + i, 1); |
| 1202 | else |
| 1203 | mvpp2_prs_sram_bits_clear(pe, ri_off + i, 1); |
| 1204 | |
| 1205 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_RI_CTRL_OFFS + i, 1); |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | /* Obtain ri bits from sram sw entry */ |
| 1210 | static int mvpp2_prs_sram_ri_get(struct mvpp2_prs_entry *pe) |
| 1211 | { |
| 1212 | return pe->sram.word[MVPP2_PRS_SRAM_RI_WORD]; |
| 1213 | } |
| 1214 | |
| 1215 | /* Update ai bits in sram sw entry */ |
| 1216 | static void mvpp2_prs_sram_ai_update(struct mvpp2_prs_entry *pe, |
| 1217 | unsigned int bits, unsigned int mask) |
| 1218 | { |
| 1219 | unsigned int i; |
| 1220 | int ai_off = MVPP2_PRS_SRAM_AI_OFFS; |
| 1221 | |
| 1222 | for (i = 0; i < MVPP2_PRS_SRAM_AI_CTRL_BITS; i++) { |
| 1223 | |
| 1224 | if (!(mask & BIT(i))) |
| 1225 | continue; |
| 1226 | |
| 1227 | if (bits & BIT(i)) |
| 1228 | mvpp2_prs_sram_bits_set(pe, ai_off + i, 1); |
| 1229 | else |
| 1230 | mvpp2_prs_sram_bits_clear(pe, ai_off + i, 1); |
| 1231 | |
| 1232 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_AI_CTRL_OFFS + i, 1); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | /* Read ai bits from sram sw entry */ |
| 1237 | static int mvpp2_prs_sram_ai_get(struct mvpp2_prs_entry *pe) |
| 1238 | { |
| 1239 | u8 bits; |
| 1240 | int ai_off = MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_AI_OFFS); |
| 1241 | int ai_en_off = ai_off + 1; |
| 1242 | int ai_shift = MVPP2_PRS_SRAM_AI_OFFS % 8; |
| 1243 | |
| 1244 | bits = (pe->sram.byte[ai_off] >> ai_shift) | |
| 1245 | (pe->sram.byte[ai_en_off] << (8 - ai_shift)); |
| 1246 | |
| 1247 | return bits; |
| 1248 | } |
| 1249 | |
| 1250 | /* In sram sw entry set lookup ID field of the tcam key to be used in the next |
| 1251 | * lookup interation |
| 1252 | */ |
| 1253 | static void mvpp2_prs_sram_next_lu_set(struct mvpp2_prs_entry *pe, |
| 1254 | unsigned int lu) |
| 1255 | { |
| 1256 | int sram_next_off = MVPP2_PRS_SRAM_NEXT_LU_OFFS; |
| 1257 | |
| 1258 | mvpp2_prs_sram_bits_clear(pe, sram_next_off, |
| 1259 | MVPP2_PRS_SRAM_NEXT_LU_MASK); |
| 1260 | mvpp2_prs_sram_bits_set(pe, sram_next_off, lu); |
| 1261 | } |
| 1262 | |
| 1263 | /* In the sram sw entry set sign and value of the next lookup offset |
| 1264 | * and the offset value generated to the classifier |
| 1265 | */ |
| 1266 | static void mvpp2_prs_sram_shift_set(struct mvpp2_prs_entry *pe, int shift, |
| 1267 | unsigned int op) |
| 1268 | { |
| 1269 | /* Set sign */ |
| 1270 | if (shift < 0) { |
| 1271 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1); |
| 1272 | shift = 0 - shift; |
| 1273 | } else { |
| 1274 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_SHIFT_SIGN_BIT, 1); |
| 1275 | } |
| 1276 | |
| 1277 | /* Set value */ |
| 1278 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_SHIFT_OFFS)] = |
| 1279 | (unsigned char)shift; |
| 1280 | |
| 1281 | /* Reset and set operation */ |
| 1282 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, |
| 1283 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_MASK); |
| 1284 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_SHIFT_OFFS, op); |
| 1285 | |
| 1286 | /* Set base offset as current */ |
| 1287 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1); |
| 1288 | } |
| 1289 | |
| 1290 | /* In the sram sw entry set sign and value of the user defined offset |
| 1291 | * generated to the classifier |
| 1292 | */ |
| 1293 | static void mvpp2_prs_sram_offset_set(struct mvpp2_prs_entry *pe, |
| 1294 | unsigned int type, int offset, |
| 1295 | unsigned int op) |
| 1296 | { |
| 1297 | /* Set sign */ |
| 1298 | if (offset < 0) { |
| 1299 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1); |
| 1300 | offset = 0 - offset; |
| 1301 | } else { |
| 1302 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_SIGN_BIT, 1); |
| 1303 | } |
| 1304 | |
| 1305 | /* Set value */ |
| 1306 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_OFFS, |
| 1307 | MVPP2_PRS_SRAM_UDF_MASK); |
| 1308 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_OFFS, offset); |
| 1309 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS + |
| 1310 | MVPP2_PRS_SRAM_UDF_BITS)] &= |
| 1311 | ~(MVPP2_PRS_SRAM_UDF_MASK >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8))); |
| 1312 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_UDF_OFFS + |
| 1313 | MVPP2_PRS_SRAM_UDF_BITS)] |= |
| 1314 | (offset >> (8 - (MVPP2_PRS_SRAM_UDF_OFFS % 8))); |
| 1315 | |
| 1316 | /* Set offset type */ |
| 1317 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, |
| 1318 | MVPP2_PRS_SRAM_UDF_TYPE_MASK); |
| 1319 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_UDF_TYPE_OFFS, type); |
| 1320 | |
| 1321 | /* Set offset operation */ |
| 1322 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, |
| 1323 | MVPP2_PRS_SRAM_OP_SEL_UDF_MASK); |
| 1324 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS, op); |
| 1325 | |
| 1326 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS + |
| 1327 | MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] &= |
| 1328 | ~(MVPP2_PRS_SRAM_OP_SEL_UDF_MASK >> |
| 1329 | (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8))); |
| 1330 | |
| 1331 | pe->sram.byte[MVPP2_BIT_TO_BYTE(MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS + |
| 1332 | MVPP2_PRS_SRAM_OP_SEL_UDF_BITS)] |= |
| 1333 | (op >> (8 - (MVPP2_PRS_SRAM_OP_SEL_UDF_OFFS % 8))); |
| 1334 | |
| 1335 | /* Set base offset as current */ |
| 1336 | mvpp2_prs_sram_bits_clear(pe, MVPP2_PRS_SRAM_OP_SEL_BASE_OFFS, 1); |
| 1337 | } |
| 1338 | |
| 1339 | /* Find parser flow entry */ |
| 1340 | static struct mvpp2_prs_entry *mvpp2_prs_flow_find(struct mvpp2 *priv, int flow) |
| 1341 | { |
| 1342 | struct mvpp2_prs_entry *pe; |
| 1343 | int tid; |
| 1344 | |
| 1345 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 1346 | if (!pe) |
| 1347 | return NULL; |
| 1348 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS); |
| 1349 | |
| 1350 | /* Go through the all entires with MVPP2_PRS_LU_FLOWS */ |
| 1351 | for (tid = MVPP2_PRS_TCAM_SRAM_SIZE - 1; tid >= 0; tid--) { |
| 1352 | u8 bits; |
| 1353 | |
| 1354 | if (!priv->prs_shadow[tid].valid || |
| 1355 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_FLOWS) |
| 1356 | continue; |
| 1357 | |
| 1358 | pe->index = tid; |
| 1359 | mvpp2_prs_hw_read(priv, pe); |
| 1360 | bits = mvpp2_prs_sram_ai_get(pe); |
| 1361 | |
| 1362 | /* Sram store classification lookup ID in AI bits [5:0] */ |
| 1363 | if ((bits & MVPP2_PRS_FLOW_ID_MASK) == flow) |
| 1364 | return pe; |
| 1365 | } |
| 1366 | kfree(pe); |
| 1367 | |
| 1368 | return NULL; |
| 1369 | } |
| 1370 | |
| 1371 | /* Return first free tcam index, seeking from start to end */ |
| 1372 | static int mvpp2_prs_tcam_first_free(struct mvpp2 *priv, unsigned char start, |
| 1373 | unsigned char end) |
| 1374 | { |
| 1375 | int tid; |
| 1376 | |
| 1377 | if (start > end) |
| 1378 | swap(start, end); |
| 1379 | |
| 1380 | if (end >= MVPP2_PRS_TCAM_SRAM_SIZE) |
| 1381 | end = MVPP2_PRS_TCAM_SRAM_SIZE - 1; |
| 1382 | |
| 1383 | for (tid = start; tid <= end; tid++) { |
| 1384 | if (!priv->prs_shadow[tid].valid) |
| 1385 | return tid; |
| 1386 | } |
| 1387 | |
| 1388 | return -EINVAL; |
| 1389 | } |
| 1390 | |
| 1391 | /* Enable/disable dropping all mac da's */ |
| 1392 | static void mvpp2_prs_mac_drop_all_set(struct mvpp2 *priv, int port, bool add) |
| 1393 | { |
| 1394 | struct mvpp2_prs_entry pe; |
| 1395 | |
| 1396 | if (priv->prs_shadow[MVPP2_PE_DROP_ALL].valid) { |
| 1397 | /* Entry exist - update port only */ |
| 1398 | pe.index = MVPP2_PE_DROP_ALL; |
| 1399 | mvpp2_prs_hw_read(priv, &pe); |
| 1400 | } else { |
| 1401 | /* Entry doesn't exist - create new */ |
| 1402 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1403 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
| 1404 | pe.index = MVPP2_PE_DROP_ALL; |
| 1405 | |
| 1406 | /* Non-promiscuous mode for all ports - DROP unknown packets */ |
| 1407 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK, |
| 1408 | MVPP2_PRS_RI_DROP_MASK); |
| 1409 | |
| 1410 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 1411 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 1412 | |
| 1413 | /* Update shadow table */ |
| 1414 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); |
| 1415 | |
| 1416 | /* Mask all ports */ |
| 1417 | mvpp2_prs_tcam_port_map_set(&pe, 0); |
| 1418 | } |
| 1419 | |
| 1420 | /* Update port mask */ |
| 1421 | mvpp2_prs_tcam_port_set(&pe, port, add); |
| 1422 | |
| 1423 | mvpp2_prs_hw_write(priv, &pe); |
| 1424 | } |
| 1425 | |
| 1426 | /* Set port to promiscuous mode */ |
| 1427 | static void mvpp2_prs_mac_promisc_set(struct mvpp2 *priv, int port, bool add) |
| 1428 | { |
| 1429 | struct mvpp2_prs_entry pe; |
| 1430 | |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 1431 | /* Promiscuous mode - Accept unknown packets */ |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1432 | |
| 1433 | if (priv->prs_shadow[MVPP2_PE_MAC_PROMISCUOUS].valid) { |
| 1434 | /* Entry exist - update port only */ |
| 1435 | pe.index = MVPP2_PE_MAC_PROMISCUOUS; |
| 1436 | mvpp2_prs_hw_read(priv, &pe); |
| 1437 | } else { |
| 1438 | /* Entry doesn't exist - create new */ |
| 1439 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1440 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
| 1441 | pe.index = MVPP2_PE_MAC_PROMISCUOUS; |
| 1442 | |
| 1443 | /* Continue - set next lookup */ |
| 1444 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA); |
| 1445 | |
| 1446 | /* Set result info bits */ |
| 1447 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_UCAST, |
| 1448 | MVPP2_PRS_RI_L2_CAST_MASK); |
| 1449 | |
| 1450 | /* Shift to ethertype */ |
| 1451 | mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN, |
| 1452 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1453 | |
| 1454 | /* Mask all ports */ |
| 1455 | mvpp2_prs_tcam_port_map_set(&pe, 0); |
| 1456 | |
| 1457 | /* Update shadow table */ |
| 1458 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); |
| 1459 | } |
| 1460 | |
| 1461 | /* Update port mask */ |
| 1462 | mvpp2_prs_tcam_port_set(&pe, port, add); |
| 1463 | |
| 1464 | mvpp2_prs_hw_write(priv, &pe); |
| 1465 | } |
| 1466 | |
| 1467 | /* Accept multicast */ |
| 1468 | static void mvpp2_prs_mac_multi_set(struct mvpp2 *priv, int port, int index, |
| 1469 | bool add) |
| 1470 | { |
| 1471 | struct mvpp2_prs_entry pe; |
| 1472 | unsigned char da_mc; |
| 1473 | |
| 1474 | /* Ethernet multicast address first byte is |
| 1475 | * 0x01 for IPv4 and 0x33 for IPv6 |
| 1476 | */ |
| 1477 | da_mc = (index == MVPP2_PE_MAC_MC_ALL) ? 0x01 : 0x33; |
| 1478 | |
| 1479 | if (priv->prs_shadow[index].valid) { |
| 1480 | /* Entry exist - update port only */ |
| 1481 | pe.index = index; |
| 1482 | mvpp2_prs_hw_read(priv, &pe); |
| 1483 | } else { |
| 1484 | /* Entry doesn't exist - create new */ |
| 1485 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1486 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
| 1487 | pe.index = index; |
| 1488 | |
| 1489 | /* Continue - set next lookup */ |
| 1490 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_DSA); |
| 1491 | |
| 1492 | /* Set result info bits */ |
| 1493 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L2_MCAST, |
| 1494 | MVPP2_PRS_RI_L2_CAST_MASK); |
| 1495 | |
| 1496 | /* Update tcam entry data first byte */ |
| 1497 | mvpp2_prs_tcam_data_byte_set(&pe, 0, da_mc, 0xff); |
| 1498 | |
| 1499 | /* Shift to ethertype */ |
| 1500 | mvpp2_prs_sram_shift_set(&pe, 2 * ETH_ALEN, |
| 1501 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1502 | |
| 1503 | /* Mask all ports */ |
| 1504 | mvpp2_prs_tcam_port_map_set(&pe, 0); |
| 1505 | |
| 1506 | /* Update shadow table */ |
| 1507 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); |
| 1508 | } |
| 1509 | |
| 1510 | /* Update port mask */ |
| 1511 | mvpp2_prs_tcam_port_set(&pe, port, add); |
| 1512 | |
| 1513 | mvpp2_prs_hw_write(priv, &pe); |
| 1514 | } |
| 1515 | |
| 1516 | /* Set entry for dsa packets */ |
| 1517 | static void mvpp2_prs_dsa_tag_set(struct mvpp2 *priv, int port, bool add, |
| 1518 | bool tagged, bool extend) |
| 1519 | { |
| 1520 | struct mvpp2_prs_entry pe; |
| 1521 | int tid, shift; |
| 1522 | |
| 1523 | if (extend) { |
| 1524 | tid = tagged ? MVPP2_PE_EDSA_TAGGED : MVPP2_PE_EDSA_UNTAGGED; |
| 1525 | shift = 8; |
| 1526 | } else { |
| 1527 | tid = tagged ? MVPP2_PE_DSA_TAGGED : MVPP2_PE_DSA_UNTAGGED; |
| 1528 | shift = 4; |
| 1529 | } |
| 1530 | |
| 1531 | if (priv->prs_shadow[tid].valid) { |
| 1532 | /* Entry exist - update port only */ |
| 1533 | pe.index = tid; |
| 1534 | mvpp2_prs_hw_read(priv, &pe); |
| 1535 | } else { |
| 1536 | /* Entry doesn't exist - create new */ |
| 1537 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1538 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
| 1539 | pe.index = tid; |
| 1540 | |
| 1541 | /* Shift 4 bytes if DSA tag or 8 bytes in case of EDSA tag*/ |
| 1542 | mvpp2_prs_sram_shift_set(&pe, shift, |
| 1543 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1544 | |
| 1545 | /* Update shadow table */ |
| 1546 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA); |
| 1547 | |
| 1548 | if (tagged) { |
| 1549 | /* Set tagged bit in DSA tag */ |
| 1550 | mvpp2_prs_tcam_data_byte_set(&pe, 0, |
| 1551 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT, |
| 1552 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT); |
| 1553 | /* Clear all ai bits for next iteration */ |
| 1554 | mvpp2_prs_sram_ai_update(&pe, 0, |
| 1555 | MVPP2_PRS_SRAM_AI_MASK); |
| 1556 | /* If packet is tagged continue check vlans */ |
| 1557 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
| 1558 | } else { |
| 1559 | /* Set result info bits to 'no vlans' */ |
| 1560 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, |
| 1561 | MVPP2_PRS_RI_VLAN_MASK); |
| 1562 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 1563 | } |
| 1564 | |
| 1565 | /* Mask all ports */ |
| 1566 | mvpp2_prs_tcam_port_map_set(&pe, 0); |
| 1567 | } |
| 1568 | |
| 1569 | /* Update port mask */ |
| 1570 | mvpp2_prs_tcam_port_set(&pe, port, add); |
| 1571 | |
| 1572 | mvpp2_prs_hw_write(priv, &pe); |
| 1573 | } |
| 1574 | |
| 1575 | /* Set entry for dsa ethertype */ |
| 1576 | static void mvpp2_prs_dsa_tag_ethertype_set(struct mvpp2 *priv, int port, |
| 1577 | bool add, bool tagged, bool extend) |
| 1578 | { |
| 1579 | struct mvpp2_prs_entry pe; |
| 1580 | int tid, shift, port_mask; |
| 1581 | |
| 1582 | if (extend) { |
| 1583 | tid = tagged ? MVPP2_PE_ETYPE_EDSA_TAGGED : |
| 1584 | MVPP2_PE_ETYPE_EDSA_UNTAGGED; |
| 1585 | port_mask = 0; |
| 1586 | shift = 8; |
| 1587 | } else { |
| 1588 | tid = tagged ? MVPP2_PE_ETYPE_DSA_TAGGED : |
| 1589 | MVPP2_PE_ETYPE_DSA_UNTAGGED; |
| 1590 | port_mask = MVPP2_PRS_PORT_MASK; |
| 1591 | shift = 4; |
| 1592 | } |
| 1593 | |
| 1594 | if (priv->prs_shadow[tid].valid) { |
| 1595 | /* Entry exist - update port only */ |
| 1596 | pe.index = tid; |
| 1597 | mvpp2_prs_hw_read(priv, &pe); |
| 1598 | } else { |
| 1599 | /* Entry doesn't exist - create new */ |
| 1600 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1601 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
| 1602 | pe.index = tid; |
| 1603 | |
| 1604 | /* Set ethertype */ |
| 1605 | mvpp2_prs_match_etype(&pe, 0, ETH_P_EDSA); |
| 1606 | mvpp2_prs_match_etype(&pe, 2, 0); |
| 1607 | |
| 1608 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DSA_MASK, |
| 1609 | MVPP2_PRS_RI_DSA_MASK); |
| 1610 | /* Shift ethertype + 2 byte reserved + tag*/ |
| 1611 | mvpp2_prs_sram_shift_set(&pe, 2 + MVPP2_ETH_TYPE_LEN + shift, |
| 1612 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1613 | |
| 1614 | /* Update shadow table */ |
| 1615 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_DSA); |
| 1616 | |
| 1617 | if (tagged) { |
| 1618 | /* Set tagged bit in DSA tag */ |
| 1619 | mvpp2_prs_tcam_data_byte_set(&pe, |
| 1620 | MVPP2_ETH_TYPE_LEN + 2 + 3, |
| 1621 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT, |
| 1622 | MVPP2_PRS_TCAM_DSA_TAGGED_BIT); |
| 1623 | /* Clear all ai bits for next iteration */ |
| 1624 | mvpp2_prs_sram_ai_update(&pe, 0, |
| 1625 | MVPP2_PRS_SRAM_AI_MASK); |
| 1626 | /* If packet is tagged continue check vlans */ |
| 1627 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
| 1628 | } else { |
| 1629 | /* Set result info bits to 'no vlans' */ |
| 1630 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, |
| 1631 | MVPP2_PRS_RI_VLAN_MASK); |
| 1632 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 1633 | } |
| 1634 | /* Mask/unmask all ports, depending on dsa type */ |
| 1635 | mvpp2_prs_tcam_port_map_set(&pe, port_mask); |
| 1636 | } |
| 1637 | |
| 1638 | /* Update port mask */ |
| 1639 | mvpp2_prs_tcam_port_set(&pe, port, add); |
| 1640 | |
| 1641 | mvpp2_prs_hw_write(priv, &pe); |
| 1642 | } |
| 1643 | |
| 1644 | /* Search for existing single/triple vlan entry */ |
| 1645 | static struct mvpp2_prs_entry *mvpp2_prs_vlan_find(struct mvpp2 *priv, |
| 1646 | unsigned short tpid, int ai) |
| 1647 | { |
| 1648 | struct mvpp2_prs_entry *pe; |
| 1649 | int tid; |
| 1650 | |
| 1651 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 1652 | if (!pe) |
| 1653 | return NULL; |
| 1654 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
| 1655 | |
| 1656 | /* Go through the all entries with MVPP2_PRS_LU_VLAN */ |
| 1657 | for (tid = MVPP2_PE_FIRST_FREE_TID; |
| 1658 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { |
| 1659 | unsigned int ri_bits, ai_bits; |
| 1660 | bool match; |
| 1661 | |
| 1662 | if (!priv->prs_shadow[tid].valid || |
| 1663 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN) |
| 1664 | continue; |
| 1665 | |
| 1666 | pe->index = tid; |
| 1667 | |
| 1668 | mvpp2_prs_hw_read(priv, pe); |
| 1669 | match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid)); |
| 1670 | if (!match) |
| 1671 | continue; |
| 1672 | |
| 1673 | /* Get vlan type */ |
| 1674 | ri_bits = mvpp2_prs_sram_ri_get(pe); |
| 1675 | ri_bits &= MVPP2_PRS_RI_VLAN_MASK; |
| 1676 | |
| 1677 | /* Get current ai value from tcam */ |
| 1678 | ai_bits = mvpp2_prs_tcam_ai_get(pe); |
| 1679 | /* Clear double vlan bit */ |
| 1680 | ai_bits &= ~MVPP2_PRS_DBL_VLAN_AI_BIT; |
| 1681 | |
| 1682 | if (ai != ai_bits) |
| 1683 | continue; |
| 1684 | |
| 1685 | if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE || |
| 1686 | ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE) |
| 1687 | return pe; |
| 1688 | } |
| 1689 | kfree(pe); |
| 1690 | |
| 1691 | return NULL; |
| 1692 | } |
| 1693 | |
| 1694 | /* Add/update single/triple vlan entry */ |
| 1695 | static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai, |
| 1696 | unsigned int port_map) |
| 1697 | { |
| 1698 | struct mvpp2_prs_entry *pe; |
| 1699 | int tid_aux, tid; |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1700 | int ret = 0; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1701 | |
| 1702 | pe = mvpp2_prs_vlan_find(priv, tpid, ai); |
| 1703 | |
| 1704 | if (!pe) { |
| 1705 | /* Create new tcam entry */ |
| 1706 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_LAST_FREE_TID, |
| 1707 | MVPP2_PE_FIRST_FREE_TID); |
| 1708 | if (tid < 0) |
| 1709 | return tid; |
| 1710 | |
| 1711 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 1712 | if (!pe) |
| 1713 | return -ENOMEM; |
| 1714 | |
| 1715 | /* Get last double vlan tid */ |
| 1716 | for (tid_aux = MVPP2_PE_LAST_FREE_TID; |
| 1717 | tid_aux >= MVPP2_PE_FIRST_FREE_TID; tid_aux--) { |
| 1718 | unsigned int ri_bits; |
| 1719 | |
| 1720 | if (!priv->prs_shadow[tid_aux].valid || |
| 1721 | priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN) |
| 1722 | continue; |
| 1723 | |
| 1724 | pe->index = tid_aux; |
| 1725 | mvpp2_prs_hw_read(priv, pe); |
| 1726 | ri_bits = mvpp2_prs_sram_ri_get(pe); |
| 1727 | if ((ri_bits & MVPP2_PRS_RI_VLAN_MASK) == |
| 1728 | MVPP2_PRS_RI_VLAN_DOUBLE) |
| 1729 | break; |
| 1730 | } |
| 1731 | |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1732 | if (tid <= tid_aux) { |
| 1733 | ret = -EINVAL; |
| 1734 | goto error; |
| 1735 | } |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1736 | |
| 1737 | memset(pe, 0 , sizeof(struct mvpp2_prs_entry)); |
| 1738 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
| 1739 | pe->index = tid; |
| 1740 | |
| 1741 | mvpp2_prs_match_etype(pe, 0, tpid); |
| 1742 | |
| 1743 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_L2); |
| 1744 | /* Shift 4 bytes - skip 1 vlan tag */ |
| 1745 | mvpp2_prs_sram_shift_set(pe, MVPP2_VLAN_TAG_LEN, |
| 1746 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1747 | /* Clear all ai bits for next iteration */ |
| 1748 | mvpp2_prs_sram_ai_update(pe, 0, MVPP2_PRS_SRAM_AI_MASK); |
| 1749 | |
| 1750 | if (ai == MVPP2_PRS_SINGLE_VLAN_AI) { |
| 1751 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_SINGLE, |
| 1752 | MVPP2_PRS_RI_VLAN_MASK); |
| 1753 | } else { |
| 1754 | ai |= MVPP2_PRS_DBL_VLAN_AI_BIT; |
| 1755 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_TRIPLE, |
| 1756 | MVPP2_PRS_RI_VLAN_MASK); |
| 1757 | } |
| 1758 | mvpp2_prs_tcam_ai_update(pe, ai, MVPP2_PRS_SRAM_AI_MASK); |
| 1759 | |
| 1760 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN); |
| 1761 | } |
| 1762 | /* Update ports' mask */ |
| 1763 | mvpp2_prs_tcam_port_map_set(pe, port_map); |
| 1764 | |
| 1765 | mvpp2_prs_hw_write(priv, pe); |
| 1766 | |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1767 | error: |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1768 | kfree(pe); |
| 1769 | |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1770 | return ret; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | /* Get first free double vlan ai number */ |
| 1774 | static int mvpp2_prs_double_vlan_ai_free_get(struct mvpp2 *priv) |
| 1775 | { |
| 1776 | int i; |
| 1777 | |
| 1778 | for (i = 1; i < MVPP2_PRS_DBL_VLANS_MAX; i++) { |
| 1779 | if (!priv->prs_double_vlans[i]) |
| 1780 | return i; |
| 1781 | } |
| 1782 | |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
| 1786 | /* Search for existing double vlan entry */ |
| 1787 | static struct mvpp2_prs_entry *mvpp2_prs_double_vlan_find(struct mvpp2 *priv, |
| 1788 | unsigned short tpid1, |
| 1789 | unsigned short tpid2) |
| 1790 | { |
| 1791 | struct mvpp2_prs_entry *pe; |
| 1792 | int tid; |
| 1793 | |
| 1794 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 1795 | if (!pe) |
| 1796 | return NULL; |
| 1797 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
| 1798 | |
| 1799 | /* Go through the all entries with MVPP2_PRS_LU_VLAN */ |
| 1800 | for (tid = MVPP2_PE_FIRST_FREE_TID; |
| 1801 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { |
| 1802 | unsigned int ri_mask; |
| 1803 | bool match; |
| 1804 | |
| 1805 | if (!priv->prs_shadow[tid].valid || |
| 1806 | priv->prs_shadow[tid].lu != MVPP2_PRS_LU_VLAN) |
| 1807 | continue; |
| 1808 | |
| 1809 | pe->index = tid; |
| 1810 | mvpp2_prs_hw_read(priv, pe); |
| 1811 | |
| 1812 | match = mvpp2_prs_tcam_data_cmp(pe, 0, swab16(tpid1)) |
| 1813 | && mvpp2_prs_tcam_data_cmp(pe, 4, swab16(tpid2)); |
| 1814 | |
| 1815 | if (!match) |
| 1816 | continue; |
| 1817 | |
| 1818 | ri_mask = mvpp2_prs_sram_ri_get(pe) & MVPP2_PRS_RI_VLAN_MASK; |
| 1819 | if (ri_mask == MVPP2_PRS_RI_VLAN_DOUBLE) |
| 1820 | return pe; |
| 1821 | } |
| 1822 | kfree(pe); |
| 1823 | |
| 1824 | return NULL; |
| 1825 | } |
| 1826 | |
| 1827 | /* Add or update double vlan entry */ |
| 1828 | static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1, |
| 1829 | unsigned short tpid2, |
| 1830 | unsigned int port_map) |
| 1831 | { |
| 1832 | struct mvpp2_prs_entry *pe; |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1833 | int tid_aux, tid, ai, ret = 0; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1834 | |
| 1835 | pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2); |
| 1836 | |
| 1837 | if (!pe) { |
| 1838 | /* Create new tcam entry */ |
| 1839 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 1840 | MVPP2_PE_LAST_FREE_TID); |
| 1841 | if (tid < 0) |
| 1842 | return tid; |
| 1843 | |
| 1844 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 1845 | if (!pe) |
| 1846 | return -ENOMEM; |
| 1847 | |
| 1848 | /* Set ai value for new double vlan entry */ |
| 1849 | ai = mvpp2_prs_double_vlan_ai_free_get(priv); |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1850 | if (ai < 0) { |
| 1851 | ret = ai; |
| 1852 | goto error; |
| 1853 | } |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1854 | |
| 1855 | /* Get first single/triple vlan tid */ |
| 1856 | for (tid_aux = MVPP2_PE_FIRST_FREE_TID; |
| 1857 | tid_aux <= MVPP2_PE_LAST_FREE_TID; tid_aux++) { |
| 1858 | unsigned int ri_bits; |
| 1859 | |
| 1860 | if (!priv->prs_shadow[tid_aux].valid || |
| 1861 | priv->prs_shadow[tid_aux].lu != MVPP2_PRS_LU_VLAN) |
| 1862 | continue; |
| 1863 | |
| 1864 | pe->index = tid_aux; |
| 1865 | mvpp2_prs_hw_read(priv, pe); |
| 1866 | ri_bits = mvpp2_prs_sram_ri_get(pe); |
| 1867 | ri_bits &= MVPP2_PRS_RI_VLAN_MASK; |
| 1868 | if (ri_bits == MVPP2_PRS_RI_VLAN_SINGLE || |
| 1869 | ri_bits == MVPP2_PRS_RI_VLAN_TRIPLE) |
| 1870 | break; |
| 1871 | } |
| 1872 | |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1873 | if (tid >= tid_aux) { |
| 1874 | ret = -ERANGE; |
| 1875 | goto error; |
| 1876 | } |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1877 | |
| 1878 | memset(pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1879 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); |
| 1880 | pe->index = tid; |
| 1881 | |
| 1882 | priv->prs_double_vlans[ai] = true; |
| 1883 | |
| 1884 | mvpp2_prs_match_etype(pe, 0, tpid1); |
| 1885 | mvpp2_prs_match_etype(pe, 4, tpid2); |
| 1886 | |
| 1887 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_VLAN); |
| 1888 | /* Shift 8 bytes - skip 2 vlan tags */ |
| 1889 | mvpp2_prs_sram_shift_set(pe, 2 * MVPP2_VLAN_TAG_LEN, |
| 1890 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1891 | mvpp2_prs_sram_ri_update(pe, MVPP2_PRS_RI_VLAN_DOUBLE, |
| 1892 | MVPP2_PRS_RI_VLAN_MASK); |
| 1893 | mvpp2_prs_sram_ai_update(pe, ai | MVPP2_PRS_DBL_VLAN_AI_BIT, |
| 1894 | MVPP2_PRS_SRAM_AI_MASK); |
| 1895 | |
| 1896 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_VLAN); |
| 1897 | } |
| 1898 | |
| 1899 | /* Update ports' mask */ |
| 1900 | mvpp2_prs_tcam_port_map_set(pe, port_map); |
| 1901 | mvpp2_prs_hw_write(priv, pe); |
| 1902 | |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1903 | error: |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1904 | kfree(pe); |
Sudip Mukherjee | 4373747 | 2014-11-01 16:59:34 +0530 | [diff] [blame] | 1905 | return ret; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | /* IPv4 header parsing for fragmentation and L4 offset */ |
| 1909 | static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned short proto, |
| 1910 | unsigned int ri, unsigned int ri_mask) |
| 1911 | { |
| 1912 | struct mvpp2_prs_entry pe; |
| 1913 | int tid; |
| 1914 | |
| 1915 | if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) && |
| 1916 | (proto != IPPROTO_IGMP)) |
| 1917 | return -EINVAL; |
| 1918 | |
| 1919 | /* Fragmented packet */ |
| 1920 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 1921 | MVPP2_PE_LAST_FREE_TID); |
| 1922 | if (tid < 0) |
| 1923 | return tid; |
| 1924 | |
| 1925 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1926 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 1927 | pe.index = tid; |
| 1928 | |
| 1929 | /* Set next lu to IPv4 */ |
| 1930 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 1931 | mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 1932 | /* Set L4 offset */ |
| 1933 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, |
| 1934 | sizeof(struct iphdr) - 4, |
| 1935 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 1936 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, |
| 1937 | MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 1938 | mvpp2_prs_sram_ri_update(&pe, ri | MVPP2_PRS_RI_IP_FRAG_MASK, |
| 1939 | ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK); |
| 1940 | |
| 1941 | mvpp2_prs_tcam_data_byte_set(&pe, 5, proto, MVPP2_PRS_TCAM_PROTO_MASK); |
| 1942 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 1943 | /* Unmask all ports */ |
| 1944 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 1945 | |
| 1946 | /* Update shadow table and hw entry */ |
| 1947 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 1948 | mvpp2_prs_hw_write(priv, &pe); |
| 1949 | |
| 1950 | /* Not fragmented packet */ |
| 1951 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 1952 | MVPP2_PE_LAST_FREE_TID); |
| 1953 | if (tid < 0) |
| 1954 | return tid; |
| 1955 | |
| 1956 | pe.index = tid; |
| 1957 | /* Clear ri before updating */ |
| 1958 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; |
| 1959 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; |
| 1960 | mvpp2_prs_sram_ri_update(&pe, ri, ri_mask); |
| 1961 | |
| 1962 | mvpp2_prs_tcam_data_byte_set(&pe, 2, 0x00, MVPP2_PRS_TCAM_PROTO_MASK_L); |
| 1963 | mvpp2_prs_tcam_data_byte_set(&pe, 3, 0x00, MVPP2_PRS_TCAM_PROTO_MASK); |
| 1964 | |
| 1965 | /* Update shadow table and hw entry */ |
| 1966 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 1967 | mvpp2_prs_hw_write(priv, &pe); |
| 1968 | |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
| 1972 | /* IPv4 L3 multicast or broadcast */ |
| 1973 | static int mvpp2_prs_ip4_cast(struct mvpp2 *priv, unsigned short l3_cast) |
| 1974 | { |
| 1975 | struct mvpp2_prs_entry pe; |
| 1976 | int mask, tid; |
| 1977 | |
| 1978 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 1979 | MVPP2_PE_LAST_FREE_TID); |
| 1980 | if (tid < 0) |
| 1981 | return tid; |
| 1982 | |
| 1983 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 1984 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 1985 | pe.index = tid; |
| 1986 | |
| 1987 | switch (l3_cast) { |
| 1988 | case MVPP2_PRS_L3_MULTI_CAST: |
| 1989 | mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV4_MC, |
| 1990 | MVPP2_PRS_IPV4_MC_MASK); |
| 1991 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST, |
| 1992 | MVPP2_PRS_RI_L3_ADDR_MASK); |
| 1993 | break; |
| 1994 | case MVPP2_PRS_L3_BROAD_CAST: |
| 1995 | mask = MVPP2_PRS_IPV4_BC_MASK; |
| 1996 | mvpp2_prs_tcam_data_byte_set(&pe, 0, mask, mask); |
| 1997 | mvpp2_prs_tcam_data_byte_set(&pe, 1, mask, mask); |
| 1998 | mvpp2_prs_tcam_data_byte_set(&pe, 2, mask, mask); |
| 1999 | mvpp2_prs_tcam_data_byte_set(&pe, 3, mask, mask); |
| 2000 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_BCAST, |
| 2001 | MVPP2_PRS_RI_L3_ADDR_MASK); |
| 2002 | break; |
| 2003 | default: |
| 2004 | return -EINVAL; |
| 2005 | } |
| 2006 | |
| 2007 | /* Finished: go to flowid generation */ |
| 2008 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2009 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2010 | |
| 2011 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, |
| 2012 | MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 2013 | /* Unmask all ports */ |
| 2014 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2015 | |
| 2016 | /* Update shadow table and hw entry */ |
| 2017 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2018 | mvpp2_prs_hw_write(priv, &pe); |
| 2019 | |
| 2020 | return 0; |
| 2021 | } |
| 2022 | |
| 2023 | /* Set entries for protocols over IPv6 */ |
| 2024 | static int mvpp2_prs_ip6_proto(struct mvpp2 *priv, unsigned short proto, |
| 2025 | unsigned int ri, unsigned int ri_mask) |
| 2026 | { |
| 2027 | struct mvpp2_prs_entry pe; |
| 2028 | int tid; |
| 2029 | |
| 2030 | if ((proto != IPPROTO_TCP) && (proto != IPPROTO_UDP) && |
| 2031 | (proto != IPPROTO_ICMPV6) && (proto != IPPROTO_IPIP)) |
| 2032 | return -EINVAL; |
| 2033 | |
| 2034 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2035 | MVPP2_PE_LAST_FREE_TID); |
| 2036 | if (tid < 0) |
| 2037 | return tid; |
| 2038 | |
| 2039 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2040 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2041 | pe.index = tid; |
| 2042 | |
| 2043 | /* Finished: go to flowid generation */ |
| 2044 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2045 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2046 | mvpp2_prs_sram_ri_update(&pe, ri, ri_mask); |
| 2047 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, |
| 2048 | sizeof(struct ipv6hdr) - 6, |
| 2049 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2050 | |
| 2051 | mvpp2_prs_tcam_data_byte_set(&pe, 0, proto, MVPP2_PRS_TCAM_PROTO_MASK); |
| 2052 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, |
| 2053 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2054 | /* Unmask all ports */ |
| 2055 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2056 | |
| 2057 | /* Write HW */ |
| 2058 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); |
| 2059 | mvpp2_prs_hw_write(priv, &pe); |
| 2060 | |
| 2061 | return 0; |
| 2062 | } |
| 2063 | |
| 2064 | /* IPv6 L3 multicast entry */ |
| 2065 | static int mvpp2_prs_ip6_cast(struct mvpp2 *priv, unsigned short l3_cast) |
| 2066 | { |
| 2067 | struct mvpp2_prs_entry pe; |
| 2068 | int tid; |
| 2069 | |
| 2070 | if (l3_cast != MVPP2_PRS_L3_MULTI_CAST) |
| 2071 | return -EINVAL; |
| 2072 | |
| 2073 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2074 | MVPP2_PE_LAST_FREE_TID); |
| 2075 | if (tid < 0) |
| 2076 | return tid; |
| 2077 | |
| 2078 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2079 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2080 | pe.index = tid; |
| 2081 | |
| 2082 | /* Finished: go to flowid generation */ |
| 2083 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2084 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_MCAST, |
| 2085 | MVPP2_PRS_RI_L3_ADDR_MASK); |
| 2086 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, |
| 2087 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2088 | /* Shift back to IPv6 NH */ |
| 2089 | mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2090 | |
| 2091 | mvpp2_prs_tcam_data_byte_set(&pe, 0, MVPP2_PRS_IPV6_MC, |
| 2092 | MVPP2_PRS_IPV6_MC_MASK); |
| 2093 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2094 | /* Unmask all ports */ |
| 2095 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2096 | |
| 2097 | /* Update shadow table and hw entry */ |
| 2098 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); |
| 2099 | mvpp2_prs_hw_write(priv, &pe); |
| 2100 | |
| 2101 | return 0; |
| 2102 | } |
| 2103 | |
| 2104 | /* Parser per-port initialization */ |
| 2105 | static void mvpp2_prs_hw_port_init(struct mvpp2 *priv, int port, int lu_first, |
| 2106 | int lu_max, int offset) |
| 2107 | { |
| 2108 | u32 val; |
| 2109 | |
| 2110 | /* Set lookup ID */ |
| 2111 | val = mvpp2_read(priv, MVPP2_PRS_INIT_LOOKUP_REG); |
| 2112 | val &= ~MVPP2_PRS_PORT_LU_MASK(port); |
| 2113 | val |= MVPP2_PRS_PORT_LU_VAL(port, lu_first); |
| 2114 | mvpp2_write(priv, MVPP2_PRS_INIT_LOOKUP_REG, val); |
| 2115 | |
| 2116 | /* Set maximum number of loops for packet received from port */ |
| 2117 | val = mvpp2_read(priv, MVPP2_PRS_MAX_LOOP_REG(port)); |
| 2118 | val &= ~MVPP2_PRS_MAX_LOOP_MASK(port); |
| 2119 | val |= MVPP2_PRS_MAX_LOOP_VAL(port, lu_max); |
| 2120 | mvpp2_write(priv, MVPP2_PRS_MAX_LOOP_REG(port), val); |
| 2121 | |
| 2122 | /* Set initial offset for packet header extraction for the first |
| 2123 | * searching loop |
| 2124 | */ |
| 2125 | val = mvpp2_read(priv, MVPP2_PRS_INIT_OFFS_REG(port)); |
| 2126 | val &= ~MVPP2_PRS_INIT_OFF_MASK(port); |
| 2127 | val |= MVPP2_PRS_INIT_OFF_VAL(port, offset); |
| 2128 | mvpp2_write(priv, MVPP2_PRS_INIT_OFFS_REG(port), val); |
| 2129 | } |
| 2130 | |
| 2131 | /* Default flow entries initialization for all ports */ |
| 2132 | static void mvpp2_prs_def_flow_init(struct mvpp2 *priv) |
| 2133 | { |
| 2134 | struct mvpp2_prs_entry pe; |
| 2135 | int port; |
| 2136 | |
| 2137 | for (port = 0; port < MVPP2_MAX_PORTS; port++) { |
| 2138 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2139 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2140 | pe.index = MVPP2_PE_FIRST_DEFAULT_FLOW - port; |
| 2141 | |
| 2142 | /* Mask all ports */ |
| 2143 | mvpp2_prs_tcam_port_map_set(&pe, 0); |
| 2144 | |
| 2145 | /* Set flow ID*/ |
| 2146 | mvpp2_prs_sram_ai_update(&pe, port, MVPP2_PRS_FLOW_ID_MASK); |
| 2147 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1); |
| 2148 | |
| 2149 | /* Update shadow table and hw entry */ |
| 2150 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_FLOWS); |
| 2151 | mvpp2_prs_hw_write(priv, &pe); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | /* Set default entry for Marvell Header field */ |
| 2156 | static void mvpp2_prs_mh_init(struct mvpp2 *priv) |
| 2157 | { |
| 2158 | struct mvpp2_prs_entry pe; |
| 2159 | |
| 2160 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2161 | |
| 2162 | pe.index = MVPP2_PE_MH_DEFAULT; |
| 2163 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MH); |
| 2164 | mvpp2_prs_sram_shift_set(&pe, MVPP2_MH_SIZE, |
| 2165 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2166 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_MAC); |
| 2167 | |
| 2168 | /* Unmask all ports */ |
| 2169 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2170 | |
| 2171 | /* Update shadow table and hw entry */ |
| 2172 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH); |
| 2173 | mvpp2_prs_hw_write(priv, &pe); |
| 2174 | } |
| 2175 | |
| 2176 | /* Set default entires (place holder) for promiscuous, non-promiscuous and |
| 2177 | * multicast MAC addresses |
| 2178 | */ |
| 2179 | static void mvpp2_prs_mac_init(struct mvpp2 *priv) |
| 2180 | { |
| 2181 | struct mvpp2_prs_entry pe; |
| 2182 | |
| 2183 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2184 | |
| 2185 | /* Non-promiscuous mode for all ports - DROP unknown packets */ |
| 2186 | pe.index = MVPP2_PE_MAC_NON_PROMISCUOUS; |
| 2187 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MAC); |
| 2188 | |
| 2189 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_DROP_MASK, |
| 2190 | MVPP2_PRS_RI_DROP_MASK); |
| 2191 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2192 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2193 | |
| 2194 | /* Unmask all ports */ |
| 2195 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2196 | |
| 2197 | /* Update shadow table and hw entry */ |
| 2198 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); |
| 2199 | mvpp2_prs_hw_write(priv, &pe); |
| 2200 | |
| 2201 | /* place holders only - no ports */ |
| 2202 | mvpp2_prs_mac_drop_all_set(priv, 0, false); |
| 2203 | mvpp2_prs_mac_promisc_set(priv, 0, false); |
| 2204 | mvpp2_prs_mac_multi_set(priv, MVPP2_PE_MAC_MC_ALL, 0, false); |
| 2205 | mvpp2_prs_mac_multi_set(priv, MVPP2_PE_MAC_MC_IP6, 0, false); |
| 2206 | } |
| 2207 | |
| 2208 | /* Set default entries for various types of dsa packets */ |
| 2209 | static void mvpp2_prs_dsa_init(struct mvpp2 *priv) |
| 2210 | { |
| 2211 | struct mvpp2_prs_entry pe; |
| 2212 | |
| 2213 | /* None tagged EDSA entry - place holder */ |
| 2214 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED, |
| 2215 | MVPP2_PRS_EDSA); |
| 2216 | |
| 2217 | /* Tagged EDSA entry - place holder */ |
| 2218 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); |
| 2219 | |
| 2220 | /* None tagged DSA entry - place holder */ |
| 2221 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_UNTAGGED, |
| 2222 | MVPP2_PRS_DSA); |
| 2223 | |
| 2224 | /* Tagged DSA entry - place holder */ |
| 2225 | mvpp2_prs_dsa_tag_set(priv, 0, false, MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); |
| 2226 | |
| 2227 | /* None tagged EDSA ethertype entry - place holder*/ |
| 2228 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false, |
| 2229 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); |
| 2230 | |
| 2231 | /* Tagged EDSA ethertype entry - place holder*/ |
| 2232 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, false, |
| 2233 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); |
| 2234 | |
| 2235 | /* None tagged DSA ethertype entry */ |
| 2236 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true, |
| 2237 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); |
| 2238 | |
| 2239 | /* Tagged DSA ethertype entry */ |
| 2240 | mvpp2_prs_dsa_tag_ethertype_set(priv, 0, true, |
| 2241 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); |
| 2242 | |
| 2243 | /* Set default entry, in case DSA or EDSA tag not found */ |
| 2244 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2245 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_DSA); |
| 2246 | pe.index = MVPP2_PE_DSA_DEFAULT; |
| 2247 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
| 2248 | |
| 2249 | /* Shift 0 bytes */ |
| 2250 | mvpp2_prs_sram_shift_set(&pe, 0, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2251 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MAC); |
| 2252 | |
| 2253 | /* Clear all sram ai bits for next iteration */ |
| 2254 | mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK); |
| 2255 | |
| 2256 | /* Unmask all ports */ |
| 2257 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2258 | |
| 2259 | mvpp2_prs_hw_write(priv, &pe); |
| 2260 | } |
| 2261 | |
| 2262 | /* Match basic ethertypes */ |
| 2263 | static int mvpp2_prs_etype_init(struct mvpp2 *priv) |
| 2264 | { |
| 2265 | struct mvpp2_prs_entry pe; |
| 2266 | int tid; |
| 2267 | |
| 2268 | /* Ethertype: PPPoE */ |
| 2269 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2270 | MVPP2_PE_LAST_FREE_TID); |
| 2271 | if (tid < 0) |
| 2272 | return tid; |
| 2273 | |
| 2274 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2275 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2276 | pe.index = tid; |
| 2277 | |
| 2278 | mvpp2_prs_match_etype(&pe, 0, ETH_P_PPP_SES); |
| 2279 | |
| 2280 | mvpp2_prs_sram_shift_set(&pe, MVPP2_PPPOE_HDR_SIZE, |
| 2281 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2282 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
| 2283 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_PPPOE_MASK, |
| 2284 | MVPP2_PRS_RI_PPPOE_MASK); |
| 2285 | |
| 2286 | /* Update shadow table and hw entry */ |
| 2287 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2288 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2289 | priv->prs_shadow[pe.index].finish = false; |
| 2290 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_PPPOE_MASK, |
| 2291 | MVPP2_PRS_RI_PPPOE_MASK); |
| 2292 | mvpp2_prs_hw_write(priv, &pe); |
| 2293 | |
| 2294 | /* Ethertype: ARP */ |
| 2295 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2296 | MVPP2_PE_LAST_FREE_TID); |
| 2297 | if (tid < 0) |
| 2298 | return tid; |
| 2299 | |
| 2300 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2301 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2302 | pe.index = tid; |
| 2303 | |
| 2304 | mvpp2_prs_match_etype(&pe, 0, ETH_P_ARP); |
| 2305 | |
| 2306 | /* Generate flow in the next iteration*/ |
| 2307 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2308 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2309 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_ARP, |
| 2310 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2311 | /* Set L3 offset */ |
| 2312 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2313 | MVPP2_ETH_TYPE_LEN, |
| 2314 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2315 | |
| 2316 | /* Update shadow table and hw entry */ |
| 2317 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2318 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2319 | priv->prs_shadow[pe.index].finish = true; |
| 2320 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_ARP, |
| 2321 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2322 | mvpp2_prs_hw_write(priv, &pe); |
| 2323 | |
| 2324 | /* Ethertype: LBTD */ |
| 2325 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2326 | MVPP2_PE_LAST_FREE_TID); |
| 2327 | if (tid < 0) |
| 2328 | return tid; |
| 2329 | |
| 2330 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2331 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2332 | pe.index = tid; |
| 2333 | |
| 2334 | mvpp2_prs_match_etype(&pe, 0, MVPP2_IP_LBDT_TYPE); |
| 2335 | |
| 2336 | /* Generate flow in the next iteration*/ |
| 2337 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2338 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2339 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_CPU_CODE_RX_SPEC | |
| 2340 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, |
| 2341 | MVPP2_PRS_RI_CPU_CODE_MASK | |
| 2342 | MVPP2_PRS_RI_UDF3_MASK); |
| 2343 | /* Set L3 offset */ |
| 2344 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2345 | MVPP2_ETH_TYPE_LEN, |
| 2346 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2347 | |
| 2348 | /* Update shadow table and hw entry */ |
| 2349 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2350 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2351 | priv->prs_shadow[pe.index].finish = true; |
| 2352 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_CPU_CODE_RX_SPEC | |
| 2353 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, |
| 2354 | MVPP2_PRS_RI_CPU_CODE_MASK | |
| 2355 | MVPP2_PRS_RI_UDF3_MASK); |
| 2356 | mvpp2_prs_hw_write(priv, &pe); |
| 2357 | |
| 2358 | /* Ethertype: IPv4 without options */ |
| 2359 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2360 | MVPP2_PE_LAST_FREE_TID); |
| 2361 | if (tid < 0) |
| 2362 | return tid; |
| 2363 | |
| 2364 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2365 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2366 | pe.index = tid; |
| 2367 | |
| 2368 | mvpp2_prs_match_etype(&pe, 0, ETH_P_IP); |
| 2369 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, |
| 2370 | MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL, |
| 2371 | MVPP2_PRS_IPV4_HEAD_MASK | |
| 2372 | MVPP2_PRS_IPV4_IHL_MASK); |
| 2373 | |
| 2374 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 2375 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4, |
| 2376 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2377 | /* Skip eth_type + 4 bytes of IP header */ |
| 2378 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, |
| 2379 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2380 | /* Set L3 offset */ |
| 2381 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2382 | MVPP2_ETH_TYPE_LEN, |
| 2383 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2384 | |
| 2385 | /* Update shadow table and hw entry */ |
| 2386 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2387 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2388 | priv->prs_shadow[pe.index].finish = false; |
| 2389 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4, |
| 2390 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2391 | mvpp2_prs_hw_write(priv, &pe); |
| 2392 | |
| 2393 | /* Ethertype: IPv4 with options */ |
| 2394 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2395 | MVPP2_PE_LAST_FREE_TID); |
| 2396 | if (tid < 0) |
| 2397 | return tid; |
| 2398 | |
| 2399 | pe.index = tid; |
| 2400 | |
| 2401 | /* Clear tcam data before updating */ |
| 2402 | pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE(MVPP2_ETH_TYPE_LEN)] = 0x0; |
| 2403 | pe.tcam.byte[MVPP2_PRS_TCAM_DATA_BYTE_EN(MVPP2_ETH_TYPE_LEN)] = 0x0; |
| 2404 | |
| 2405 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, |
| 2406 | MVPP2_PRS_IPV4_HEAD, |
| 2407 | MVPP2_PRS_IPV4_HEAD_MASK); |
| 2408 | |
| 2409 | /* Clear ri before updating */ |
| 2410 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; |
| 2411 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; |
| 2412 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT, |
| 2413 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2414 | |
| 2415 | /* Update shadow table and hw entry */ |
| 2416 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2417 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2418 | priv->prs_shadow[pe.index].finish = false; |
| 2419 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4_OPT, |
| 2420 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2421 | mvpp2_prs_hw_write(priv, &pe); |
| 2422 | |
| 2423 | /* Ethertype: IPv6 without options */ |
| 2424 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2425 | MVPP2_PE_LAST_FREE_TID); |
| 2426 | if (tid < 0) |
| 2427 | return tid; |
| 2428 | |
| 2429 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2430 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2431 | pe.index = tid; |
| 2432 | |
| 2433 | mvpp2_prs_match_etype(&pe, 0, ETH_P_IPV6); |
| 2434 | |
| 2435 | /* Skip DIP of IPV6 header */ |
| 2436 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 8 + |
| 2437 | MVPP2_MAX_L3_ADDR_SIZE, |
| 2438 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2439 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2440 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6, |
| 2441 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2442 | /* Set L3 offset */ |
| 2443 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2444 | MVPP2_ETH_TYPE_LEN, |
| 2445 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2446 | |
| 2447 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2448 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2449 | priv->prs_shadow[pe.index].finish = false; |
| 2450 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP6, |
| 2451 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2452 | mvpp2_prs_hw_write(priv, &pe); |
| 2453 | |
| 2454 | /* Default entry for MVPP2_PRS_LU_L2 - Unknown ethtype */ |
| 2455 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2456 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2457 | pe.index = MVPP2_PE_ETH_TYPE_UN; |
| 2458 | |
| 2459 | /* Unmask all ports */ |
| 2460 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2461 | |
| 2462 | /* Generate flow in the next iteration*/ |
| 2463 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2464 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2465 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN, |
| 2466 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2467 | /* Set L3 offset even it's unknown L3 */ |
| 2468 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2469 | MVPP2_ETH_TYPE_LEN, |
| 2470 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2471 | |
| 2472 | /* Update shadow table and hw entry */ |
| 2473 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2); |
| 2474 | priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF; |
| 2475 | priv->prs_shadow[pe.index].finish = true; |
| 2476 | mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_UN, |
| 2477 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2478 | mvpp2_prs_hw_write(priv, &pe); |
| 2479 | |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
| 2483 | /* Configure vlan entries and detect up to 2 successive VLAN tags. |
| 2484 | * Possible options: |
| 2485 | * 0x8100, 0x88A8 |
| 2486 | * 0x8100, 0x8100 |
| 2487 | * 0x8100 |
| 2488 | * 0x88A8 |
| 2489 | */ |
| 2490 | static int mvpp2_prs_vlan_init(struct platform_device *pdev, struct mvpp2 *priv) |
| 2491 | { |
| 2492 | struct mvpp2_prs_entry pe; |
| 2493 | int err; |
| 2494 | |
| 2495 | priv->prs_double_vlans = devm_kcalloc(&pdev->dev, sizeof(bool), |
| 2496 | MVPP2_PRS_DBL_VLANS_MAX, |
| 2497 | GFP_KERNEL); |
| 2498 | if (!priv->prs_double_vlans) |
| 2499 | return -ENOMEM; |
| 2500 | |
| 2501 | /* Double VLAN: 0x8100, 0x88A8 */ |
| 2502 | err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021AD, |
| 2503 | MVPP2_PRS_PORT_MASK); |
| 2504 | if (err) |
| 2505 | return err; |
| 2506 | |
| 2507 | /* Double VLAN: 0x8100, 0x8100 */ |
| 2508 | err = mvpp2_prs_double_vlan_add(priv, ETH_P_8021Q, ETH_P_8021Q, |
| 2509 | MVPP2_PRS_PORT_MASK); |
| 2510 | if (err) |
| 2511 | return err; |
| 2512 | |
| 2513 | /* Single VLAN: 0x88a8 */ |
| 2514 | err = mvpp2_prs_vlan_add(priv, ETH_P_8021AD, MVPP2_PRS_SINGLE_VLAN_AI, |
| 2515 | MVPP2_PRS_PORT_MASK); |
| 2516 | if (err) |
| 2517 | return err; |
| 2518 | |
| 2519 | /* Single VLAN: 0x8100 */ |
| 2520 | err = mvpp2_prs_vlan_add(priv, ETH_P_8021Q, MVPP2_PRS_SINGLE_VLAN_AI, |
| 2521 | MVPP2_PRS_PORT_MASK); |
| 2522 | if (err) |
| 2523 | return err; |
| 2524 | |
| 2525 | /* Set default double vlan entry */ |
| 2526 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2527 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
| 2528 | pe.index = MVPP2_PE_VLAN_DBL; |
| 2529 | |
| 2530 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2531 | /* Clear ai for next iterations */ |
| 2532 | mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_SRAM_AI_MASK); |
| 2533 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_DOUBLE, |
| 2534 | MVPP2_PRS_RI_VLAN_MASK); |
| 2535 | |
| 2536 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_DBL_VLAN_AI_BIT, |
| 2537 | MVPP2_PRS_DBL_VLAN_AI_BIT); |
| 2538 | /* Unmask all ports */ |
| 2539 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2540 | |
| 2541 | /* Update shadow table and hw entry */ |
| 2542 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN); |
| 2543 | mvpp2_prs_hw_write(priv, &pe); |
| 2544 | |
| 2545 | /* Set default vlan none entry */ |
| 2546 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2547 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_VLAN); |
| 2548 | pe.index = MVPP2_PE_VLAN_NONE; |
| 2549 | |
| 2550 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_L2); |
| 2551 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_VLAN_NONE, |
| 2552 | MVPP2_PRS_RI_VLAN_MASK); |
| 2553 | |
| 2554 | /* Unmask all ports */ |
| 2555 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2556 | |
| 2557 | /* Update shadow table and hw entry */ |
| 2558 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_VLAN); |
| 2559 | mvpp2_prs_hw_write(priv, &pe); |
| 2560 | |
| 2561 | return 0; |
| 2562 | } |
| 2563 | |
| 2564 | /* Set entries for PPPoE ethertype */ |
| 2565 | static int mvpp2_prs_pppoe_init(struct mvpp2 *priv) |
| 2566 | { |
| 2567 | struct mvpp2_prs_entry pe; |
| 2568 | int tid; |
| 2569 | |
| 2570 | /* IPv4 over PPPoE with options */ |
| 2571 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2572 | MVPP2_PE_LAST_FREE_TID); |
| 2573 | if (tid < 0) |
| 2574 | return tid; |
| 2575 | |
| 2576 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2577 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
| 2578 | pe.index = tid; |
| 2579 | |
| 2580 | mvpp2_prs_match_etype(&pe, 0, PPP_IP); |
| 2581 | |
| 2582 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 2583 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT, |
| 2584 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2585 | /* Skip eth_type + 4 bytes of IP header */ |
| 2586 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, |
| 2587 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2588 | /* Set L3 offset */ |
| 2589 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2590 | MVPP2_ETH_TYPE_LEN, |
| 2591 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2592 | |
| 2593 | /* Update shadow table and hw entry */ |
| 2594 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); |
| 2595 | mvpp2_prs_hw_write(priv, &pe); |
| 2596 | |
| 2597 | /* IPv4 over PPPoE without options */ |
| 2598 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2599 | MVPP2_PE_LAST_FREE_TID); |
| 2600 | if (tid < 0) |
| 2601 | return tid; |
| 2602 | |
| 2603 | pe.index = tid; |
| 2604 | |
| 2605 | mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN, |
| 2606 | MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL, |
| 2607 | MVPP2_PRS_IPV4_HEAD_MASK | |
| 2608 | MVPP2_PRS_IPV4_IHL_MASK); |
| 2609 | |
| 2610 | /* Clear ri before updating */ |
| 2611 | pe.sram.word[MVPP2_PRS_SRAM_RI_WORD] = 0x0; |
| 2612 | pe.sram.word[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0; |
| 2613 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4, |
| 2614 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2615 | |
| 2616 | /* Update shadow table and hw entry */ |
| 2617 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); |
| 2618 | mvpp2_prs_hw_write(priv, &pe); |
| 2619 | |
| 2620 | /* IPv6 over PPPoE */ |
| 2621 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2622 | MVPP2_PE_LAST_FREE_TID); |
| 2623 | if (tid < 0) |
| 2624 | return tid; |
| 2625 | |
| 2626 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2627 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
| 2628 | pe.index = tid; |
| 2629 | |
| 2630 | mvpp2_prs_match_etype(&pe, 0, PPP_IPV6); |
| 2631 | |
| 2632 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2633 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP6, |
| 2634 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2635 | /* Skip eth_type + 4 bytes of IPv6 header */ |
| 2636 | mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN + 4, |
| 2637 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2638 | /* Set L3 offset */ |
| 2639 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2640 | MVPP2_ETH_TYPE_LEN, |
| 2641 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2642 | |
| 2643 | /* Update shadow table and hw entry */ |
| 2644 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); |
| 2645 | mvpp2_prs_hw_write(priv, &pe); |
| 2646 | |
| 2647 | /* Non-IP over PPPoE */ |
| 2648 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2649 | MVPP2_PE_LAST_FREE_TID); |
| 2650 | if (tid < 0) |
| 2651 | return tid; |
| 2652 | |
| 2653 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2654 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_PPPOE); |
| 2655 | pe.index = tid; |
| 2656 | |
| 2657 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN, |
| 2658 | MVPP2_PRS_RI_L3_PROTO_MASK); |
| 2659 | |
| 2660 | /* Finished: go to flowid generation */ |
| 2661 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2662 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2663 | /* Set L3 offset even if it's unknown L3 */ |
| 2664 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, |
| 2665 | MVPP2_ETH_TYPE_LEN, |
| 2666 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2667 | |
| 2668 | /* Update shadow table and hw entry */ |
| 2669 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_PPPOE); |
| 2670 | mvpp2_prs_hw_write(priv, &pe); |
| 2671 | |
| 2672 | return 0; |
| 2673 | } |
| 2674 | |
| 2675 | /* Initialize entries for IPv4 */ |
| 2676 | static int mvpp2_prs_ip4_init(struct mvpp2 *priv) |
| 2677 | { |
| 2678 | struct mvpp2_prs_entry pe; |
| 2679 | int err; |
| 2680 | |
| 2681 | /* Set entries for TCP, UDP and IGMP over IPv4 */ |
| 2682 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_TCP, MVPP2_PRS_RI_L4_TCP, |
| 2683 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2684 | if (err) |
| 2685 | return err; |
| 2686 | |
| 2687 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_UDP, MVPP2_PRS_RI_L4_UDP, |
| 2688 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2689 | if (err) |
| 2690 | return err; |
| 2691 | |
| 2692 | err = mvpp2_prs_ip4_proto(priv, IPPROTO_IGMP, |
| 2693 | MVPP2_PRS_RI_CPU_CODE_RX_SPEC | |
| 2694 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, |
| 2695 | MVPP2_PRS_RI_CPU_CODE_MASK | |
| 2696 | MVPP2_PRS_RI_UDF3_MASK); |
| 2697 | if (err) |
| 2698 | return err; |
| 2699 | |
| 2700 | /* IPv4 Broadcast */ |
| 2701 | err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_BROAD_CAST); |
| 2702 | if (err) |
| 2703 | return err; |
| 2704 | |
| 2705 | /* IPv4 Multicast */ |
| 2706 | err = mvpp2_prs_ip4_cast(priv, MVPP2_PRS_L3_MULTI_CAST); |
| 2707 | if (err) |
| 2708 | return err; |
| 2709 | |
| 2710 | /* Default IPv4 entry for unknown protocols */ |
| 2711 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2712 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 2713 | pe.index = MVPP2_PE_IP4_PROTO_UN; |
| 2714 | |
| 2715 | /* Set next lu to IPv4 */ |
| 2716 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 2717 | mvpp2_prs_sram_shift_set(&pe, 12, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2718 | /* Set L4 offset */ |
| 2719 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, |
| 2720 | sizeof(struct iphdr) - 4, |
| 2721 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2722 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, |
| 2723 | MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 2724 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, |
| 2725 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2726 | |
| 2727 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 2728 | /* Unmask all ports */ |
| 2729 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2730 | |
| 2731 | /* Update shadow table and hw entry */ |
| 2732 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2733 | mvpp2_prs_hw_write(priv, &pe); |
| 2734 | |
| 2735 | /* Default IPv4 entry for unicast address */ |
| 2736 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2737 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP4); |
| 2738 | pe.index = MVPP2_PE_IP4_ADDR_UN; |
| 2739 | |
| 2740 | /* Finished: go to flowid generation */ |
| 2741 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2742 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2743 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST, |
| 2744 | MVPP2_PRS_RI_L3_ADDR_MASK); |
| 2745 | |
| 2746 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV4_DIP_AI_BIT, |
| 2747 | MVPP2_PRS_IPV4_DIP_AI_BIT); |
| 2748 | /* Unmask all ports */ |
| 2749 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2750 | |
| 2751 | /* Update shadow table and hw entry */ |
| 2752 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2753 | mvpp2_prs_hw_write(priv, &pe); |
| 2754 | |
| 2755 | return 0; |
| 2756 | } |
| 2757 | |
| 2758 | /* Initialize entries for IPv6 */ |
| 2759 | static int mvpp2_prs_ip6_init(struct mvpp2 *priv) |
| 2760 | { |
| 2761 | struct mvpp2_prs_entry pe; |
| 2762 | int tid, err; |
| 2763 | |
| 2764 | /* Set entries for TCP, UDP and ICMP over IPv6 */ |
| 2765 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_TCP, |
| 2766 | MVPP2_PRS_RI_L4_TCP, |
| 2767 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2768 | if (err) |
| 2769 | return err; |
| 2770 | |
| 2771 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_UDP, |
| 2772 | MVPP2_PRS_RI_L4_UDP, |
| 2773 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2774 | if (err) |
| 2775 | return err; |
| 2776 | |
| 2777 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_ICMPV6, |
| 2778 | MVPP2_PRS_RI_CPU_CODE_RX_SPEC | |
| 2779 | MVPP2_PRS_RI_UDF3_RX_SPECIAL, |
| 2780 | MVPP2_PRS_RI_CPU_CODE_MASK | |
| 2781 | MVPP2_PRS_RI_UDF3_MASK); |
| 2782 | if (err) |
| 2783 | return err; |
| 2784 | |
| 2785 | /* IPv4 is the last header. This is similar case as 6-TCP or 17-UDP */ |
| 2786 | /* Result Info: UDF7=1, DS lite */ |
| 2787 | err = mvpp2_prs_ip6_proto(priv, IPPROTO_IPIP, |
| 2788 | MVPP2_PRS_RI_UDF7_IP6_LITE, |
| 2789 | MVPP2_PRS_RI_UDF7_MASK); |
| 2790 | if (err) |
| 2791 | return err; |
| 2792 | |
| 2793 | /* IPv6 multicast */ |
| 2794 | err = mvpp2_prs_ip6_cast(priv, MVPP2_PRS_L3_MULTI_CAST); |
| 2795 | if (err) |
| 2796 | return err; |
| 2797 | |
| 2798 | /* Entry for checking hop limit */ |
| 2799 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 2800 | MVPP2_PE_LAST_FREE_TID); |
| 2801 | if (tid < 0) |
| 2802 | return tid; |
| 2803 | |
| 2804 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2805 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2806 | pe.index = tid; |
| 2807 | |
| 2808 | /* Finished: go to flowid generation */ |
| 2809 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2810 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2811 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UN | |
| 2812 | MVPP2_PRS_RI_DROP_MASK, |
| 2813 | MVPP2_PRS_RI_L3_PROTO_MASK | |
| 2814 | MVPP2_PRS_RI_DROP_MASK); |
| 2815 | |
| 2816 | mvpp2_prs_tcam_data_byte_set(&pe, 1, 0x00, MVPP2_PRS_IPV6_HOP_MASK); |
| 2817 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, |
| 2818 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2819 | |
| 2820 | /* Update shadow table and hw entry */ |
| 2821 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2822 | mvpp2_prs_hw_write(priv, &pe); |
| 2823 | |
| 2824 | /* Default IPv6 entry for unknown protocols */ |
| 2825 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2826 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2827 | pe.index = MVPP2_PE_IP6_PROTO_UN; |
| 2828 | |
| 2829 | /* Finished: go to flowid generation */ |
| 2830 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2831 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2832 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, |
| 2833 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2834 | /* Set L4 offset relatively to our current place */ |
| 2835 | mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4, |
| 2836 | sizeof(struct ipv6hdr) - 4, |
| 2837 | MVPP2_PRS_SRAM_OP_SEL_UDF_ADD); |
| 2838 | |
| 2839 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, |
| 2840 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2841 | /* Unmask all ports */ |
| 2842 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2843 | |
| 2844 | /* Update shadow table and hw entry */ |
| 2845 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2846 | mvpp2_prs_hw_write(priv, &pe); |
| 2847 | |
| 2848 | /* Default IPv6 entry for unknown ext protocols */ |
| 2849 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2850 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2851 | pe.index = MVPP2_PE_IP6_EXT_PROTO_UN; |
| 2852 | |
| 2853 | /* Finished: go to flowid generation */ |
| 2854 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS); |
| 2855 | mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1); |
| 2856 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L4_OTHER, |
| 2857 | MVPP2_PRS_RI_L4_PROTO_MASK); |
| 2858 | |
| 2859 | mvpp2_prs_tcam_ai_update(&pe, MVPP2_PRS_IPV6_EXT_AI_BIT, |
| 2860 | MVPP2_PRS_IPV6_EXT_AI_BIT); |
| 2861 | /* Unmask all ports */ |
| 2862 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2863 | |
| 2864 | /* Update shadow table and hw entry */ |
| 2865 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP4); |
| 2866 | mvpp2_prs_hw_write(priv, &pe); |
| 2867 | |
| 2868 | /* Default IPv6 entry for unicast address */ |
| 2869 | memset(&pe, 0, sizeof(struct mvpp2_prs_entry)); |
| 2870 | mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2871 | pe.index = MVPP2_PE_IP6_ADDR_UN; |
| 2872 | |
| 2873 | /* Finished: go to IPv6 again */ |
| 2874 | mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP6); |
| 2875 | mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_UCAST, |
| 2876 | MVPP2_PRS_RI_L3_ADDR_MASK); |
| 2877 | mvpp2_prs_sram_ai_update(&pe, MVPP2_PRS_IPV6_NO_EXT_AI_BIT, |
| 2878 | MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2879 | /* Shift back to IPV6 NH */ |
| 2880 | mvpp2_prs_sram_shift_set(&pe, -18, MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 2881 | |
| 2882 | mvpp2_prs_tcam_ai_update(&pe, 0, MVPP2_PRS_IPV6_NO_EXT_AI_BIT); |
| 2883 | /* Unmask all ports */ |
| 2884 | mvpp2_prs_tcam_port_map_set(&pe, MVPP2_PRS_PORT_MASK); |
| 2885 | |
| 2886 | /* Update shadow table and hw entry */ |
| 2887 | mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_IP6); |
| 2888 | mvpp2_prs_hw_write(priv, &pe); |
| 2889 | |
| 2890 | return 0; |
| 2891 | } |
| 2892 | |
| 2893 | /* Parser default initialization */ |
| 2894 | static int mvpp2_prs_default_init(struct platform_device *pdev, |
| 2895 | struct mvpp2 *priv) |
| 2896 | { |
| 2897 | int err, index, i; |
| 2898 | |
| 2899 | /* Enable tcam table */ |
| 2900 | mvpp2_write(priv, MVPP2_PRS_TCAM_CTRL_REG, MVPP2_PRS_TCAM_EN_MASK); |
| 2901 | |
| 2902 | /* Clear all tcam and sram entries */ |
| 2903 | for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) { |
| 2904 | mvpp2_write(priv, MVPP2_PRS_TCAM_IDX_REG, index); |
| 2905 | for (i = 0; i < MVPP2_PRS_TCAM_WORDS; i++) |
| 2906 | mvpp2_write(priv, MVPP2_PRS_TCAM_DATA_REG(i), 0); |
| 2907 | |
| 2908 | mvpp2_write(priv, MVPP2_PRS_SRAM_IDX_REG, index); |
| 2909 | for (i = 0; i < MVPP2_PRS_SRAM_WORDS; i++) |
| 2910 | mvpp2_write(priv, MVPP2_PRS_SRAM_DATA_REG(i), 0); |
| 2911 | } |
| 2912 | |
| 2913 | /* Invalidate all tcam entries */ |
| 2914 | for (index = 0; index < MVPP2_PRS_TCAM_SRAM_SIZE; index++) |
| 2915 | mvpp2_prs_hw_inv(priv, index); |
| 2916 | |
| 2917 | priv->prs_shadow = devm_kcalloc(&pdev->dev, MVPP2_PRS_TCAM_SRAM_SIZE, |
| 2918 | sizeof(struct mvpp2_prs_shadow), |
| 2919 | GFP_KERNEL); |
| 2920 | if (!priv->prs_shadow) |
| 2921 | return -ENOMEM; |
| 2922 | |
| 2923 | /* Always start from lookup = 0 */ |
| 2924 | for (index = 0; index < MVPP2_MAX_PORTS; index++) |
| 2925 | mvpp2_prs_hw_port_init(priv, index, MVPP2_PRS_LU_MH, |
| 2926 | MVPP2_PRS_PORT_LU_MAX, 0); |
| 2927 | |
| 2928 | mvpp2_prs_def_flow_init(priv); |
| 2929 | |
| 2930 | mvpp2_prs_mh_init(priv); |
| 2931 | |
| 2932 | mvpp2_prs_mac_init(priv); |
| 2933 | |
| 2934 | mvpp2_prs_dsa_init(priv); |
| 2935 | |
| 2936 | err = mvpp2_prs_etype_init(priv); |
| 2937 | if (err) |
| 2938 | return err; |
| 2939 | |
| 2940 | err = mvpp2_prs_vlan_init(pdev, priv); |
| 2941 | if (err) |
| 2942 | return err; |
| 2943 | |
| 2944 | err = mvpp2_prs_pppoe_init(priv); |
| 2945 | if (err) |
| 2946 | return err; |
| 2947 | |
| 2948 | err = mvpp2_prs_ip6_init(priv); |
| 2949 | if (err) |
| 2950 | return err; |
| 2951 | |
| 2952 | err = mvpp2_prs_ip4_init(priv); |
| 2953 | if (err) |
| 2954 | return err; |
| 2955 | |
| 2956 | return 0; |
| 2957 | } |
| 2958 | |
| 2959 | /* Compare MAC DA with tcam entry data */ |
| 2960 | static bool mvpp2_prs_mac_range_equals(struct mvpp2_prs_entry *pe, |
| 2961 | const u8 *da, unsigned char *mask) |
| 2962 | { |
| 2963 | unsigned char tcam_byte, tcam_mask; |
| 2964 | int index; |
| 2965 | |
| 2966 | for (index = 0; index < ETH_ALEN; index++) { |
| 2967 | mvpp2_prs_tcam_data_byte_get(pe, index, &tcam_byte, &tcam_mask); |
| 2968 | if (tcam_mask != mask[index]) |
| 2969 | return false; |
| 2970 | |
| 2971 | if ((tcam_mask & tcam_byte) != (da[index] & mask[index])) |
| 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | return true; |
| 2976 | } |
| 2977 | |
| 2978 | /* Find tcam entry with matched pair <MAC DA, port> */ |
| 2979 | static struct mvpp2_prs_entry * |
| 2980 | mvpp2_prs_mac_da_range_find(struct mvpp2 *priv, int pmap, const u8 *da, |
| 2981 | unsigned char *mask, int udf_type) |
| 2982 | { |
| 2983 | struct mvpp2_prs_entry *pe; |
| 2984 | int tid; |
| 2985 | |
| 2986 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 2987 | if (!pe) |
| 2988 | return NULL; |
| 2989 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC); |
| 2990 | |
| 2991 | /* Go through the all entires with MVPP2_PRS_LU_MAC */ |
| 2992 | for (tid = MVPP2_PE_FIRST_FREE_TID; |
| 2993 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { |
| 2994 | unsigned int entry_pmap; |
| 2995 | |
| 2996 | if (!priv->prs_shadow[tid].valid || |
| 2997 | (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) || |
| 2998 | (priv->prs_shadow[tid].udf != udf_type)) |
| 2999 | continue; |
| 3000 | |
| 3001 | pe->index = tid; |
| 3002 | mvpp2_prs_hw_read(priv, pe); |
| 3003 | entry_pmap = mvpp2_prs_tcam_port_map_get(pe); |
| 3004 | |
| 3005 | if (mvpp2_prs_mac_range_equals(pe, da, mask) && |
| 3006 | entry_pmap == pmap) |
| 3007 | return pe; |
| 3008 | } |
| 3009 | kfree(pe); |
| 3010 | |
| 3011 | return NULL; |
| 3012 | } |
| 3013 | |
| 3014 | /* Update parser's mac da entry */ |
| 3015 | static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port, |
| 3016 | const u8 *da, bool add) |
| 3017 | { |
| 3018 | struct mvpp2_prs_entry *pe; |
| 3019 | unsigned int pmap, len, ri; |
| 3020 | unsigned char mask[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 3021 | int tid; |
| 3022 | |
| 3023 | /* Scan TCAM and see if entry with this <MAC DA, port> already exist */ |
| 3024 | pe = mvpp2_prs_mac_da_range_find(priv, (1 << port), da, mask, |
| 3025 | MVPP2_PRS_UDF_MAC_DEF); |
| 3026 | |
| 3027 | /* No such entry */ |
| 3028 | if (!pe) { |
| 3029 | if (!add) |
| 3030 | return 0; |
| 3031 | |
| 3032 | /* Create new TCAM entry */ |
| 3033 | /* Find first range mac entry*/ |
| 3034 | for (tid = MVPP2_PE_FIRST_FREE_TID; |
| 3035 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) |
| 3036 | if (priv->prs_shadow[tid].valid && |
| 3037 | (priv->prs_shadow[tid].lu == MVPP2_PRS_LU_MAC) && |
| 3038 | (priv->prs_shadow[tid].udf == |
| 3039 | MVPP2_PRS_UDF_MAC_RANGE)) |
| 3040 | break; |
| 3041 | |
| 3042 | /* Go through the all entries from first to last */ |
| 3043 | tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID, |
| 3044 | tid - 1); |
| 3045 | if (tid < 0) |
| 3046 | return tid; |
| 3047 | |
| 3048 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 3049 | if (!pe) |
| 3050 | return -1; |
| 3051 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC); |
| 3052 | pe->index = tid; |
| 3053 | |
| 3054 | /* Mask all ports */ |
| 3055 | mvpp2_prs_tcam_port_map_set(pe, 0); |
| 3056 | } |
| 3057 | |
| 3058 | /* Update port mask */ |
| 3059 | mvpp2_prs_tcam_port_set(pe, port, add); |
| 3060 | |
| 3061 | /* Invalidate the entry if no ports are left enabled */ |
| 3062 | pmap = mvpp2_prs_tcam_port_map_get(pe); |
| 3063 | if (pmap == 0) { |
| 3064 | if (add) { |
| 3065 | kfree(pe); |
| 3066 | return -1; |
| 3067 | } |
| 3068 | mvpp2_prs_hw_inv(priv, pe->index); |
| 3069 | priv->prs_shadow[pe->index].valid = false; |
| 3070 | kfree(pe); |
| 3071 | return 0; |
| 3072 | } |
| 3073 | |
| 3074 | /* Continue - set next lookup */ |
| 3075 | mvpp2_prs_sram_next_lu_set(pe, MVPP2_PRS_LU_DSA); |
| 3076 | |
| 3077 | /* Set match on DA */ |
| 3078 | len = ETH_ALEN; |
| 3079 | while (len--) |
| 3080 | mvpp2_prs_tcam_data_byte_set(pe, len, da[len], 0xff); |
| 3081 | |
| 3082 | /* Set result info bits */ |
| 3083 | if (is_broadcast_ether_addr(da)) |
| 3084 | ri = MVPP2_PRS_RI_L2_BCAST; |
| 3085 | else if (is_multicast_ether_addr(da)) |
| 3086 | ri = MVPP2_PRS_RI_L2_MCAST; |
| 3087 | else |
| 3088 | ri = MVPP2_PRS_RI_L2_UCAST | MVPP2_PRS_RI_MAC_ME_MASK; |
| 3089 | |
| 3090 | mvpp2_prs_sram_ri_update(pe, ri, MVPP2_PRS_RI_L2_CAST_MASK | |
| 3091 | MVPP2_PRS_RI_MAC_ME_MASK); |
| 3092 | mvpp2_prs_shadow_ri_set(priv, pe->index, ri, MVPP2_PRS_RI_L2_CAST_MASK | |
| 3093 | MVPP2_PRS_RI_MAC_ME_MASK); |
| 3094 | |
| 3095 | /* Shift to ethertype */ |
| 3096 | mvpp2_prs_sram_shift_set(pe, 2 * ETH_ALEN, |
| 3097 | MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD); |
| 3098 | |
| 3099 | /* Update shadow table and hw entry */ |
| 3100 | priv->prs_shadow[pe->index].udf = MVPP2_PRS_UDF_MAC_DEF; |
| 3101 | mvpp2_prs_shadow_set(priv, pe->index, MVPP2_PRS_LU_MAC); |
| 3102 | mvpp2_prs_hw_write(priv, pe); |
| 3103 | |
| 3104 | kfree(pe); |
| 3105 | |
| 3106 | return 0; |
| 3107 | } |
| 3108 | |
| 3109 | static int mvpp2_prs_update_mac_da(struct net_device *dev, const u8 *da) |
| 3110 | { |
| 3111 | struct mvpp2_port *port = netdev_priv(dev); |
| 3112 | int err; |
| 3113 | |
| 3114 | /* Remove old parser entry */ |
| 3115 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, dev->dev_addr, |
| 3116 | false); |
| 3117 | if (err) |
| 3118 | return err; |
| 3119 | |
| 3120 | /* Add new parser entry */ |
| 3121 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, da, true); |
| 3122 | if (err) |
| 3123 | return err; |
| 3124 | |
| 3125 | /* Set addr in the device */ |
| 3126 | ether_addr_copy(dev->dev_addr, da); |
| 3127 | |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
| 3131 | /* Delete all port's multicast simple (not range) entries */ |
| 3132 | static void mvpp2_prs_mcast_del_all(struct mvpp2 *priv, int port) |
| 3133 | { |
| 3134 | struct mvpp2_prs_entry pe; |
| 3135 | int index, tid; |
| 3136 | |
| 3137 | for (tid = MVPP2_PE_FIRST_FREE_TID; |
| 3138 | tid <= MVPP2_PE_LAST_FREE_TID; tid++) { |
| 3139 | unsigned char da[ETH_ALEN], da_mask[ETH_ALEN]; |
| 3140 | |
| 3141 | if (!priv->prs_shadow[tid].valid || |
| 3142 | (priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC) || |
| 3143 | (priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF)) |
| 3144 | continue; |
| 3145 | |
| 3146 | /* Only simple mac entries */ |
| 3147 | pe.index = tid; |
| 3148 | mvpp2_prs_hw_read(priv, &pe); |
| 3149 | |
| 3150 | /* Read mac addr from entry */ |
| 3151 | for (index = 0; index < ETH_ALEN; index++) |
| 3152 | mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index], |
| 3153 | &da_mask[index]); |
| 3154 | |
| 3155 | if (is_multicast_ether_addr(da) && !is_broadcast_ether_addr(da)) |
| 3156 | /* Delete this entry */ |
| 3157 | mvpp2_prs_mac_da_accept(priv, port, da, false); |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | static int mvpp2_prs_tag_mode_set(struct mvpp2 *priv, int port, int type) |
| 3162 | { |
| 3163 | switch (type) { |
| 3164 | case MVPP2_TAG_TYPE_EDSA: |
| 3165 | /* Add port to EDSA entries */ |
| 3166 | mvpp2_prs_dsa_tag_set(priv, port, true, |
| 3167 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); |
| 3168 | mvpp2_prs_dsa_tag_set(priv, port, true, |
| 3169 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); |
| 3170 | /* Remove port from DSA entries */ |
| 3171 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3172 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); |
| 3173 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3174 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); |
| 3175 | break; |
| 3176 | |
| 3177 | case MVPP2_TAG_TYPE_DSA: |
| 3178 | /* Add port to DSA entries */ |
| 3179 | mvpp2_prs_dsa_tag_set(priv, port, true, |
| 3180 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); |
| 3181 | mvpp2_prs_dsa_tag_set(priv, port, true, |
| 3182 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); |
| 3183 | /* Remove port from EDSA entries */ |
| 3184 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3185 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); |
| 3186 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3187 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); |
| 3188 | break; |
| 3189 | |
| 3190 | case MVPP2_TAG_TYPE_MH: |
| 3191 | case MVPP2_TAG_TYPE_NONE: |
| 3192 | /* Remove port form EDSA and DSA entries */ |
| 3193 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3194 | MVPP2_PRS_TAGGED, MVPP2_PRS_DSA); |
| 3195 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3196 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_DSA); |
| 3197 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3198 | MVPP2_PRS_TAGGED, MVPP2_PRS_EDSA); |
| 3199 | mvpp2_prs_dsa_tag_set(priv, port, false, |
| 3200 | MVPP2_PRS_UNTAGGED, MVPP2_PRS_EDSA); |
| 3201 | break; |
| 3202 | |
| 3203 | default: |
| 3204 | if ((type < 0) || (type > MVPP2_TAG_TYPE_EDSA)) |
| 3205 | return -EINVAL; |
| 3206 | } |
| 3207 | |
| 3208 | return 0; |
| 3209 | } |
| 3210 | |
| 3211 | /* Set prs flow for the port */ |
| 3212 | static int mvpp2_prs_def_flow(struct mvpp2_port *port) |
| 3213 | { |
| 3214 | struct mvpp2_prs_entry *pe; |
| 3215 | int tid; |
| 3216 | |
| 3217 | pe = mvpp2_prs_flow_find(port->priv, port->id); |
| 3218 | |
| 3219 | /* Such entry not exist */ |
| 3220 | if (!pe) { |
| 3221 | /* Go through the all entires from last to first */ |
| 3222 | tid = mvpp2_prs_tcam_first_free(port->priv, |
| 3223 | MVPP2_PE_LAST_FREE_TID, |
| 3224 | MVPP2_PE_FIRST_FREE_TID); |
| 3225 | if (tid < 0) |
| 3226 | return tid; |
| 3227 | |
| 3228 | pe = kzalloc(sizeof(*pe), GFP_KERNEL); |
| 3229 | if (!pe) |
| 3230 | return -ENOMEM; |
| 3231 | |
| 3232 | mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_FLOWS); |
| 3233 | pe->index = tid; |
| 3234 | |
| 3235 | /* Set flow ID*/ |
| 3236 | mvpp2_prs_sram_ai_update(pe, port->id, MVPP2_PRS_FLOW_ID_MASK); |
| 3237 | mvpp2_prs_sram_bits_set(pe, MVPP2_PRS_SRAM_LU_DONE_BIT, 1); |
| 3238 | |
| 3239 | /* Update shadow table */ |
| 3240 | mvpp2_prs_shadow_set(port->priv, pe->index, MVPP2_PRS_LU_FLOWS); |
| 3241 | } |
| 3242 | |
| 3243 | mvpp2_prs_tcam_port_map_set(pe, (1 << port->id)); |
| 3244 | mvpp2_prs_hw_write(port->priv, pe); |
| 3245 | kfree(pe); |
| 3246 | |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
| 3250 | /* Classifier configuration routines */ |
| 3251 | |
| 3252 | /* Update classification flow table registers */ |
| 3253 | static void mvpp2_cls_flow_write(struct mvpp2 *priv, |
| 3254 | struct mvpp2_cls_flow_entry *fe) |
| 3255 | { |
| 3256 | mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, fe->index); |
| 3257 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL0_REG, fe->data[0]); |
| 3258 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL1_REG, fe->data[1]); |
| 3259 | mvpp2_write(priv, MVPP2_CLS_FLOW_TBL2_REG, fe->data[2]); |
| 3260 | } |
| 3261 | |
| 3262 | /* Update classification lookup table register */ |
| 3263 | static void mvpp2_cls_lookup_write(struct mvpp2 *priv, |
| 3264 | struct mvpp2_cls_lookup_entry *le) |
| 3265 | { |
| 3266 | u32 val; |
| 3267 | |
| 3268 | val = (le->way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | le->lkpid; |
| 3269 | mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val); |
| 3270 | mvpp2_write(priv, MVPP2_CLS_LKP_TBL_REG, le->data); |
| 3271 | } |
| 3272 | |
| 3273 | /* Classifier default initialization */ |
| 3274 | static void mvpp2_cls_init(struct mvpp2 *priv) |
| 3275 | { |
| 3276 | struct mvpp2_cls_lookup_entry le; |
| 3277 | struct mvpp2_cls_flow_entry fe; |
| 3278 | int index; |
| 3279 | |
| 3280 | /* Enable classifier */ |
| 3281 | mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK); |
| 3282 | |
| 3283 | /* Clear classifier flow table */ |
| 3284 | memset(&fe.data, 0, MVPP2_CLS_FLOWS_TBL_DATA_WORDS); |
| 3285 | for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) { |
| 3286 | fe.index = index; |
| 3287 | mvpp2_cls_flow_write(priv, &fe); |
| 3288 | } |
| 3289 | |
| 3290 | /* Clear classifier lookup table */ |
| 3291 | le.data = 0; |
| 3292 | for (index = 0; index < MVPP2_CLS_LKP_TBL_SIZE; index++) { |
| 3293 | le.lkpid = index; |
| 3294 | le.way = 0; |
| 3295 | mvpp2_cls_lookup_write(priv, &le); |
| 3296 | |
| 3297 | le.way = 1; |
| 3298 | mvpp2_cls_lookup_write(priv, &le); |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | static void mvpp2_cls_port_config(struct mvpp2_port *port) |
| 3303 | { |
| 3304 | struct mvpp2_cls_lookup_entry le; |
| 3305 | u32 val; |
| 3306 | |
| 3307 | /* Set way for the port */ |
| 3308 | val = mvpp2_read(port->priv, MVPP2_CLS_PORT_WAY_REG); |
| 3309 | val &= ~MVPP2_CLS_PORT_WAY_MASK(port->id); |
| 3310 | mvpp2_write(port->priv, MVPP2_CLS_PORT_WAY_REG, val); |
| 3311 | |
| 3312 | /* Pick the entry to be accessed in lookup ID decoding table |
| 3313 | * according to the way and lkpid. |
| 3314 | */ |
| 3315 | le.lkpid = port->id; |
| 3316 | le.way = 0; |
| 3317 | le.data = 0; |
| 3318 | |
| 3319 | /* Set initial CPU queue for receiving packets */ |
| 3320 | le.data &= ~MVPP2_CLS_LKP_TBL_RXQ_MASK; |
| 3321 | le.data |= port->first_rxq; |
| 3322 | |
| 3323 | /* Disable classification engines */ |
| 3324 | le.data &= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK; |
| 3325 | |
| 3326 | /* Update lookup ID table entry */ |
| 3327 | mvpp2_cls_lookup_write(port->priv, &le); |
| 3328 | } |
| 3329 | |
| 3330 | /* Set CPU queue number for oversize packets */ |
| 3331 | static void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port) |
| 3332 | { |
| 3333 | u32 val; |
| 3334 | |
| 3335 | mvpp2_write(port->priv, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port->id), |
| 3336 | port->first_rxq & MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK); |
| 3337 | |
| 3338 | mvpp2_write(port->priv, MVPP2_CLS_SWFWD_P2HQ_REG(port->id), |
| 3339 | (port->first_rxq >> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS)); |
| 3340 | |
| 3341 | val = mvpp2_read(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG); |
| 3342 | val |= MVPP2_CLS_SWFWD_PCTRL_MASK(port->id); |
| 3343 | mvpp2_write(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG, val); |
| 3344 | } |
| 3345 | |
| 3346 | /* Buffer Manager configuration routines */ |
| 3347 | |
| 3348 | /* Create pool */ |
| 3349 | static int mvpp2_bm_pool_create(struct platform_device *pdev, |
| 3350 | struct mvpp2 *priv, |
| 3351 | struct mvpp2_bm_pool *bm_pool, int size) |
| 3352 | { |
| 3353 | int size_bytes; |
| 3354 | u32 val; |
| 3355 | |
| 3356 | size_bytes = sizeof(u32) * size; |
| 3357 | bm_pool->virt_addr = dma_alloc_coherent(&pdev->dev, size_bytes, |
| 3358 | &bm_pool->phys_addr, |
| 3359 | GFP_KERNEL); |
| 3360 | if (!bm_pool->virt_addr) |
| 3361 | return -ENOMEM; |
| 3362 | |
| 3363 | if (!IS_ALIGNED((u32)bm_pool->virt_addr, MVPP2_BM_POOL_PTR_ALIGN)) { |
| 3364 | dma_free_coherent(&pdev->dev, size_bytes, bm_pool->virt_addr, |
| 3365 | bm_pool->phys_addr); |
| 3366 | dev_err(&pdev->dev, "BM pool %d is not %d bytes aligned\n", |
| 3367 | bm_pool->id, MVPP2_BM_POOL_PTR_ALIGN); |
| 3368 | return -ENOMEM; |
| 3369 | } |
| 3370 | |
| 3371 | mvpp2_write(priv, MVPP2_BM_POOL_BASE_REG(bm_pool->id), |
| 3372 | bm_pool->phys_addr); |
| 3373 | mvpp2_write(priv, MVPP2_BM_POOL_SIZE_REG(bm_pool->id), size); |
| 3374 | |
| 3375 | val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); |
| 3376 | val |= MVPP2_BM_START_MASK; |
| 3377 | mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); |
| 3378 | |
| 3379 | bm_pool->type = MVPP2_BM_FREE; |
| 3380 | bm_pool->size = size; |
| 3381 | bm_pool->pkt_size = 0; |
| 3382 | bm_pool->buf_num = 0; |
| 3383 | atomic_set(&bm_pool->in_use, 0); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3384 | |
| 3385 | return 0; |
| 3386 | } |
| 3387 | |
| 3388 | /* Set pool buffer size */ |
| 3389 | static void mvpp2_bm_pool_bufsize_set(struct mvpp2 *priv, |
| 3390 | struct mvpp2_bm_pool *bm_pool, |
| 3391 | int buf_size) |
| 3392 | { |
| 3393 | u32 val; |
| 3394 | |
| 3395 | bm_pool->buf_size = buf_size; |
| 3396 | |
| 3397 | val = ALIGN(buf_size, 1 << MVPP2_POOL_BUF_SIZE_OFFSET); |
| 3398 | mvpp2_write(priv, MVPP2_POOL_BUF_SIZE_REG(bm_pool->id), val); |
| 3399 | } |
| 3400 | |
Ezequiel Garcia | 7861f12 | 2014-07-21 13:48:14 -0300 | [diff] [blame] | 3401 | /* Free all buffers from the pool */ |
| 3402 | static void mvpp2_bm_bufs_free(struct mvpp2 *priv, struct mvpp2_bm_pool *bm_pool) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3403 | { |
| 3404 | int i; |
| 3405 | |
Ezequiel Garcia | 7861f12 | 2014-07-21 13:48:14 -0300 | [diff] [blame] | 3406 | for (i = 0; i < bm_pool->buf_num; i++) { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3407 | u32 vaddr; |
| 3408 | |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 3409 | /* Get buffer virtual address (indirect access) */ |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3410 | mvpp2_read(priv, MVPP2_BM_PHY_ALLOC_REG(bm_pool->id)); |
| 3411 | vaddr = mvpp2_read(priv, MVPP2_BM_VIRT_ALLOC_REG); |
| 3412 | if (!vaddr) |
| 3413 | break; |
| 3414 | dev_kfree_skb_any((struct sk_buff *)vaddr); |
| 3415 | } |
| 3416 | |
| 3417 | /* Update BM driver with number of buffers removed from pool */ |
| 3418 | bm_pool->buf_num -= i; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | /* Cleanup pool */ |
| 3422 | static int mvpp2_bm_pool_destroy(struct platform_device *pdev, |
| 3423 | struct mvpp2 *priv, |
| 3424 | struct mvpp2_bm_pool *bm_pool) |
| 3425 | { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3426 | u32 val; |
| 3427 | |
Ezequiel Garcia | 7861f12 | 2014-07-21 13:48:14 -0300 | [diff] [blame] | 3428 | mvpp2_bm_bufs_free(priv, bm_pool); |
Ezequiel Garcia | d74c96c | 2014-07-21 13:48:13 -0300 | [diff] [blame] | 3429 | if (bm_pool->buf_num) { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3430 | WARN(1, "cannot free all buffers in pool %d\n", bm_pool->id); |
| 3431 | return 0; |
| 3432 | } |
| 3433 | |
| 3434 | val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id)); |
| 3435 | val |= MVPP2_BM_STOP_MASK; |
| 3436 | mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val); |
| 3437 | |
| 3438 | dma_free_coherent(&pdev->dev, sizeof(u32) * bm_pool->size, |
| 3439 | bm_pool->virt_addr, |
| 3440 | bm_pool->phys_addr); |
| 3441 | return 0; |
| 3442 | } |
| 3443 | |
| 3444 | static int mvpp2_bm_pools_init(struct platform_device *pdev, |
| 3445 | struct mvpp2 *priv) |
| 3446 | { |
| 3447 | int i, err, size; |
| 3448 | struct mvpp2_bm_pool *bm_pool; |
| 3449 | |
| 3450 | /* Create all pools with maximum size */ |
| 3451 | size = MVPP2_BM_POOL_SIZE_MAX; |
| 3452 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { |
| 3453 | bm_pool = &priv->bm_pools[i]; |
| 3454 | bm_pool->id = i; |
| 3455 | err = mvpp2_bm_pool_create(pdev, priv, bm_pool, size); |
| 3456 | if (err) |
| 3457 | goto err_unroll_pools; |
| 3458 | mvpp2_bm_pool_bufsize_set(priv, bm_pool, 0); |
| 3459 | } |
| 3460 | return 0; |
| 3461 | |
| 3462 | err_unroll_pools: |
| 3463 | dev_err(&pdev->dev, "failed to create BM pool %d, size %d\n", i, size); |
| 3464 | for (i = i - 1; i >= 0; i--) |
| 3465 | mvpp2_bm_pool_destroy(pdev, priv, &priv->bm_pools[i]); |
| 3466 | return err; |
| 3467 | } |
| 3468 | |
| 3469 | static int mvpp2_bm_init(struct platform_device *pdev, struct mvpp2 *priv) |
| 3470 | { |
| 3471 | int i, err; |
| 3472 | |
| 3473 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { |
| 3474 | /* Mask BM all interrupts */ |
| 3475 | mvpp2_write(priv, MVPP2_BM_INTR_MASK_REG(i), 0); |
| 3476 | /* Clear BM cause register */ |
| 3477 | mvpp2_write(priv, MVPP2_BM_INTR_CAUSE_REG(i), 0); |
| 3478 | } |
| 3479 | |
| 3480 | /* Allocate and initialize BM pools */ |
| 3481 | priv->bm_pools = devm_kcalloc(&pdev->dev, MVPP2_BM_POOLS_NUM, |
| 3482 | sizeof(struct mvpp2_bm_pool), GFP_KERNEL); |
| 3483 | if (!priv->bm_pools) |
| 3484 | return -ENOMEM; |
| 3485 | |
| 3486 | err = mvpp2_bm_pools_init(pdev, priv); |
| 3487 | if (err < 0) |
| 3488 | return err; |
| 3489 | return 0; |
| 3490 | } |
| 3491 | |
| 3492 | /* Attach long pool to rxq */ |
| 3493 | static void mvpp2_rxq_long_pool_set(struct mvpp2_port *port, |
| 3494 | int lrxq, int long_pool) |
| 3495 | { |
| 3496 | u32 val; |
| 3497 | int prxq; |
| 3498 | |
| 3499 | /* Get queue physical ID */ |
| 3500 | prxq = port->rxqs[lrxq]->id; |
| 3501 | |
| 3502 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); |
| 3503 | val &= ~MVPP2_RXQ_POOL_LONG_MASK; |
| 3504 | val |= ((long_pool << MVPP2_RXQ_POOL_LONG_OFFS) & |
| 3505 | MVPP2_RXQ_POOL_LONG_MASK); |
| 3506 | |
| 3507 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); |
| 3508 | } |
| 3509 | |
| 3510 | /* Attach short pool to rxq */ |
| 3511 | static void mvpp2_rxq_short_pool_set(struct mvpp2_port *port, |
| 3512 | int lrxq, int short_pool) |
| 3513 | { |
| 3514 | u32 val; |
| 3515 | int prxq; |
| 3516 | |
| 3517 | /* Get queue physical ID */ |
| 3518 | prxq = port->rxqs[lrxq]->id; |
| 3519 | |
| 3520 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); |
| 3521 | val &= ~MVPP2_RXQ_POOL_SHORT_MASK; |
| 3522 | val |= ((short_pool << MVPP2_RXQ_POOL_SHORT_OFFS) & |
| 3523 | MVPP2_RXQ_POOL_SHORT_MASK); |
| 3524 | |
| 3525 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); |
| 3526 | } |
| 3527 | |
| 3528 | /* Allocate skb for BM pool */ |
| 3529 | static struct sk_buff *mvpp2_skb_alloc(struct mvpp2_port *port, |
| 3530 | struct mvpp2_bm_pool *bm_pool, |
| 3531 | dma_addr_t *buf_phys_addr, |
| 3532 | gfp_t gfp_mask) |
| 3533 | { |
| 3534 | struct sk_buff *skb; |
| 3535 | dma_addr_t phys_addr; |
| 3536 | |
| 3537 | skb = __dev_alloc_skb(bm_pool->pkt_size, gfp_mask); |
| 3538 | if (!skb) |
| 3539 | return NULL; |
| 3540 | |
| 3541 | phys_addr = dma_map_single(port->dev->dev.parent, skb->head, |
| 3542 | MVPP2_RX_BUF_SIZE(bm_pool->pkt_size), |
| 3543 | DMA_FROM_DEVICE); |
| 3544 | if (unlikely(dma_mapping_error(port->dev->dev.parent, phys_addr))) { |
| 3545 | dev_kfree_skb_any(skb); |
| 3546 | return NULL; |
| 3547 | } |
| 3548 | *buf_phys_addr = phys_addr; |
| 3549 | |
| 3550 | return skb; |
| 3551 | } |
| 3552 | |
| 3553 | /* Set pool number in a BM cookie */ |
| 3554 | static inline u32 mvpp2_bm_cookie_pool_set(u32 cookie, int pool) |
| 3555 | { |
| 3556 | u32 bm; |
| 3557 | |
| 3558 | bm = cookie & ~(0xFF << MVPP2_BM_COOKIE_POOL_OFFS); |
| 3559 | bm |= ((pool & 0xFF) << MVPP2_BM_COOKIE_POOL_OFFS); |
| 3560 | |
| 3561 | return bm; |
| 3562 | } |
| 3563 | |
| 3564 | /* Get pool number from a BM cookie */ |
| 3565 | static inline int mvpp2_bm_cookie_pool_get(u32 cookie) |
| 3566 | { |
| 3567 | return (cookie >> MVPP2_BM_COOKIE_POOL_OFFS) & 0xFF; |
| 3568 | } |
| 3569 | |
| 3570 | /* Release buffer to BM */ |
| 3571 | static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool, |
| 3572 | u32 buf_phys_addr, u32 buf_virt_addr) |
| 3573 | { |
| 3574 | mvpp2_write(port->priv, MVPP2_BM_VIRT_RLS_REG, buf_virt_addr); |
| 3575 | mvpp2_write(port->priv, MVPP2_BM_PHY_RLS_REG(pool), buf_phys_addr); |
| 3576 | } |
| 3577 | |
| 3578 | /* Release multicast buffer */ |
| 3579 | static void mvpp2_bm_pool_mc_put(struct mvpp2_port *port, int pool, |
| 3580 | u32 buf_phys_addr, u32 buf_virt_addr, |
| 3581 | int mc_id) |
| 3582 | { |
| 3583 | u32 val = 0; |
| 3584 | |
| 3585 | val |= (mc_id & MVPP2_BM_MC_ID_MASK); |
| 3586 | mvpp2_write(port->priv, MVPP2_BM_MC_RLS_REG, val); |
| 3587 | |
| 3588 | mvpp2_bm_pool_put(port, pool, |
| 3589 | buf_phys_addr | MVPP2_BM_PHY_RLS_MC_BUFF_MASK, |
| 3590 | buf_virt_addr); |
| 3591 | } |
| 3592 | |
| 3593 | /* Refill BM pool */ |
| 3594 | static void mvpp2_pool_refill(struct mvpp2_port *port, u32 bm, |
| 3595 | u32 phys_addr, u32 cookie) |
| 3596 | { |
| 3597 | int pool = mvpp2_bm_cookie_pool_get(bm); |
| 3598 | |
| 3599 | mvpp2_bm_pool_put(port, pool, phys_addr, cookie); |
| 3600 | } |
| 3601 | |
| 3602 | /* Allocate buffers for the pool */ |
| 3603 | static int mvpp2_bm_bufs_add(struct mvpp2_port *port, |
| 3604 | struct mvpp2_bm_pool *bm_pool, int buf_num) |
| 3605 | { |
| 3606 | struct sk_buff *skb; |
| 3607 | int i, buf_size, total_size; |
| 3608 | u32 bm; |
| 3609 | dma_addr_t phys_addr; |
| 3610 | |
| 3611 | buf_size = MVPP2_RX_BUF_SIZE(bm_pool->pkt_size); |
| 3612 | total_size = MVPP2_RX_TOTAL_SIZE(buf_size); |
| 3613 | |
| 3614 | if (buf_num < 0 || |
| 3615 | (buf_num + bm_pool->buf_num > bm_pool->size)) { |
| 3616 | netdev_err(port->dev, |
| 3617 | "cannot allocate %d buffers for pool %d\n", |
| 3618 | buf_num, bm_pool->id); |
| 3619 | return 0; |
| 3620 | } |
| 3621 | |
| 3622 | bm = mvpp2_bm_cookie_pool_set(0, bm_pool->id); |
| 3623 | for (i = 0; i < buf_num; i++) { |
| 3624 | skb = mvpp2_skb_alloc(port, bm_pool, &phys_addr, GFP_KERNEL); |
| 3625 | if (!skb) |
| 3626 | break; |
| 3627 | |
| 3628 | mvpp2_pool_refill(port, bm, (u32)phys_addr, (u32)skb); |
| 3629 | } |
| 3630 | |
| 3631 | /* Update BM driver with number of buffers added to pool */ |
| 3632 | bm_pool->buf_num += i; |
| 3633 | bm_pool->in_use_thresh = bm_pool->buf_num / 4; |
| 3634 | |
| 3635 | netdev_dbg(port->dev, |
| 3636 | "%s pool %d: pkt_size=%4d, buf_size=%4d, total_size=%4d\n", |
| 3637 | bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long", |
| 3638 | bm_pool->id, bm_pool->pkt_size, buf_size, total_size); |
| 3639 | |
| 3640 | netdev_dbg(port->dev, |
| 3641 | "%s pool %d: %d of %d buffers added\n", |
| 3642 | bm_pool->type == MVPP2_BM_SWF_SHORT ? "short" : " long", |
| 3643 | bm_pool->id, i, buf_num); |
| 3644 | return i; |
| 3645 | } |
| 3646 | |
| 3647 | /* Notify the driver that BM pool is being used as specific type and return the |
| 3648 | * pool pointer on success |
| 3649 | */ |
| 3650 | static struct mvpp2_bm_pool * |
| 3651 | mvpp2_bm_pool_use(struct mvpp2_port *port, int pool, enum mvpp2_bm_type type, |
| 3652 | int pkt_size) |
| 3653 | { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3654 | struct mvpp2_bm_pool *new_pool = &port->priv->bm_pools[pool]; |
| 3655 | int num; |
| 3656 | |
| 3657 | if (new_pool->type != MVPP2_BM_FREE && new_pool->type != type) { |
| 3658 | netdev_err(port->dev, "mixing pool types is forbidden\n"); |
| 3659 | return NULL; |
| 3660 | } |
| 3661 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3662 | if (new_pool->type == MVPP2_BM_FREE) |
| 3663 | new_pool->type = type; |
| 3664 | |
| 3665 | /* Allocate buffers in case BM pool is used as long pool, but packet |
| 3666 | * size doesn't match MTU or BM pool hasn't being used yet |
| 3667 | */ |
| 3668 | if (((type == MVPP2_BM_SWF_LONG) && (pkt_size > new_pool->pkt_size)) || |
| 3669 | (new_pool->pkt_size == 0)) { |
| 3670 | int pkts_num; |
| 3671 | |
| 3672 | /* Set default buffer number or free all the buffers in case |
| 3673 | * the pool is not empty |
| 3674 | */ |
| 3675 | pkts_num = new_pool->buf_num; |
| 3676 | if (pkts_num == 0) |
| 3677 | pkts_num = type == MVPP2_BM_SWF_LONG ? |
| 3678 | MVPP2_BM_LONG_BUF_NUM : |
| 3679 | MVPP2_BM_SHORT_BUF_NUM; |
| 3680 | else |
Ezequiel Garcia | 7861f12 | 2014-07-21 13:48:14 -0300 | [diff] [blame] | 3681 | mvpp2_bm_bufs_free(port->priv, new_pool); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3682 | |
| 3683 | new_pool->pkt_size = pkt_size; |
| 3684 | |
| 3685 | /* Allocate buffers for this pool */ |
| 3686 | num = mvpp2_bm_bufs_add(port, new_pool, pkts_num); |
| 3687 | if (num != pkts_num) { |
| 3688 | WARN(1, "pool %d: %d of %d allocated\n", |
| 3689 | new_pool->id, num, pkts_num); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3690 | return NULL; |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | mvpp2_bm_pool_bufsize_set(port->priv, new_pool, |
| 3695 | MVPP2_RX_BUF_SIZE(new_pool->pkt_size)); |
| 3696 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3697 | return new_pool; |
| 3698 | } |
| 3699 | |
| 3700 | /* Initialize pools for swf */ |
| 3701 | static int mvpp2_swf_bm_pool_init(struct mvpp2_port *port) |
| 3702 | { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3703 | int rxq; |
| 3704 | |
| 3705 | if (!port->pool_long) { |
| 3706 | port->pool_long = |
| 3707 | mvpp2_bm_pool_use(port, MVPP2_BM_SWF_LONG_POOL(port->id), |
| 3708 | MVPP2_BM_SWF_LONG, |
| 3709 | port->pkt_size); |
| 3710 | if (!port->pool_long) |
| 3711 | return -ENOMEM; |
| 3712 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3713 | port->pool_long->port_map |= (1 << port->id); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3714 | |
| 3715 | for (rxq = 0; rxq < rxq_number; rxq++) |
| 3716 | mvpp2_rxq_long_pool_set(port, rxq, port->pool_long->id); |
| 3717 | } |
| 3718 | |
| 3719 | if (!port->pool_short) { |
| 3720 | port->pool_short = |
| 3721 | mvpp2_bm_pool_use(port, MVPP2_BM_SWF_SHORT_POOL, |
| 3722 | MVPP2_BM_SWF_SHORT, |
| 3723 | MVPP2_BM_SHORT_PKT_SIZE); |
| 3724 | if (!port->pool_short) |
| 3725 | return -ENOMEM; |
| 3726 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3727 | port->pool_short->port_map |= (1 << port->id); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3728 | |
| 3729 | for (rxq = 0; rxq < rxq_number; rxq++) |
| 3730 | mvpp2_rxq_short_pool_set(port, rxq, |
| 3731 | port->pool_short->id); |
| 3732 | } |
| 3733 | |
| 3734 | return 0; |
| 3735 | } |
| 3736 | |
| 3737 | static int mvpp2_bm_update_mtu(struct net_device *dev, int mtu) |
| 3738 | { |
| 3739 | struct mvpp2_port *port = netdev_priv(dev); |
| 3740 | struct mvpp2_bm_pool *port_pool = port->pool_long; |
| 3741 | int num, pkts_num = port_pool->buf_num; |
| 3742 | int pkt_size = MVPP2_RX_PKT_SIZE(mtu); |
| 3743 | |
| 3744 | /* Update BM pool with new buffer size */ |
Ezequiel Garcia | 7861f12 | 2014-07-21 13:48:14 -0300 | [diff] [blame] | 3745 | mvpp2_bm_bufs_free(port->priv, port_pool); |
Ezequiel Garcia | d74c96c | 2014-07-21 13:48:13 -0300 | [diff] [blame] | 3746 | if (port_pool->buf_num) { |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3747 | WARN(1, "cannot free all buffers in pool %d\n", port_pool->id); |
| 3748 | return -EIO; |
| 3749 | } |
| 3750 | |
| 3751 | port_pool->pkt_size = pkt_size; |
| 3752 | num = mvpp2_bm_bufs_add(port, port_pool, pkts_num); |
| 3753 | if (num != pkts_num) { |
| 3754 | WARN(1, "pool %d: %d of %d allocated\n", |
| 3755 | port_pool->id, num, pkts_num); |
| 3756 | return -EIO; |
| 3757 | } |
| 3758 | |
| 3759 | mvpp2_bm_pool_bufsize_set(port->priv, port_pool, |
| 3760 | MVPP2_RX_BUF_SIZE(port_pool->pkt_size)); |
| 3761 | dev->mtu = mtu; |
| 3762 | netdev_update_features(dev); |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
| 3766 | static inline void mvpp2_interrupts_enable(struct mvpp2_port *port) |
| 3767 | { |
| 3768 | int cpu, cpu_mask = 0; |
| 3769 | |
| 3770 | for_each_present_cpu(cpu) |
| 3771 | cpu_mask |= 1 << cpu; |
| 3772 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), |
| 3773 | MVPP2_ISR_ENABLE_INTERRUPT(cpu_mask)); |
| 3774 | } |
| 3775 | |
| 3776 | static inline void mvpp2_interrupts_disable(struct mvpp2_port *port) |
| 3777 | { |
| 3778 | int cpu, cpu_mask = 0; |
| 3779 | |
| 3780 | for_each_present_cpu(cpu) |
| 3781 | cpu_mask |= 1 << cpu; |
| 3782 | mvpp2_write(port->priv, MVPP2_ISR_ENABLE_REG(port->id), |
| 3783 | MVPP2_ISR_DISABLE_INTERRUPT(cpu_mask)); |
| 3784 | } |
| 3785 | |
| 3786 | /* Mask the current CPU's Rx/Tx interrupts */ |
| 3787 | static void mvpp2_interrupts_mask(void *arg) |
| 3788 | { |
| 3789 | struct mvpp2_port *port = arg; |
| 3790 | |
| 3791 | mvpp2_write(port->priv, MVPP2_ISR_RX_TX_MASK_REG(port->id), 0); |
| 3792 | } |
| 3793 | |
| 3794 | /* Unmask the current CPU's Rx/Tx interrupts */ |
| 3795 | static void mvpp2_interrupts_unmask(void *arg) |
| 3796 | { |
| 3797 | struct mvpp2_port *port = arg; |
| 3798 | |
| 3799 | mvpp2_write(port->priv, MVPP2_ISR_RX_TX_MASK_REG(port->id), |
| 3800 | (MVPP2_CAUSE_MISC_SUM_MASK | |
| 3801 | MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK | |
| 3802 | MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK)); |
| 3803 | } |
| 3804 | |
| 3805 | /* Port configuration routines */ |
| 3806 | |
| 3807 | static void mvpp2_port_mii_set(struct mvpp2_port *port) |
| 3808 | { |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 3809 | u32 val; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3810 | |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 3811 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3812 | |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 3813 | switch (port->phy_interface) { |
| 3814 | case PHY_INTERFACE_MODE_SGMII: |
| 3815 | val |= MVPP2_GMAC_INBAND_AN_MASK; |
| 3816 | break; |
| 3817 | case PHY_INTERFACE_MODE_RGMII: |
| 3818 | val |= MVPP2_GMAC_PORT_RGMII_MASK; |
| 3819 | default: |
| 3820 | val &= ~MVPP2_GMAC_PCS_ENABLE_MASK; |
| 3821 | } |
| 3822 | |
| 3823 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); |
| 3824 | } |
| 3825 | |
| 3826 | static void mvpp2_port_fc_adv_enable(struct mvpp2_port *port) |
| 3827 | { |
| 3828 | u32 val; |
| 3829 | |
| 3830 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
| 3831 | val |= MVPP2_GMAC_FC_ADV_EN; |
| 3832 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | static void mvpp2_port_enable(struct mvpp2_port *port) |
| 3836 | { |
| 3837 | u32 val; |
| 3838 | |
| 3839 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3840 | val |= MVPP2_GMAC_PORT_EN_MASK; |
| 3841 | val |= MVPP2_GMAC_MIB_CNTR_EN_MASK; |
| 3842 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3843 | } |
| 3844 | |
| 3845 | static void mvpp2_port_disable(struct mvpp2_port *port) |
| 3846 | { |
| 3847 | u32 val; |
| 3848 | |
| 3849 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3850 | val &= ~(MVPP2_GMAC_PORT_EN_MASK); |
| 3851 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3852 | } |
| 3853 | |
| 3854 | /* Set IEEE 802.3x Flow Control Xon Packet Transmission Mode */ |
| 3855 | static void mvpp2_port_periodic_xon_disable(struct mvpp2_port *port) |
| 3856 | { |
| 3857 | u32 val; |
| 3858 | |
| 3859 | val = readl(port->base + MVPP2_GMAC_CTRL_1_REG) & |
| 3860 | ~MVPP2_GMAC_PERIODIC_XON_EN_MASK; |
| 3861 | writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); |
| 3862 | } |
| 3863 | |
| 3864 | /* Configure loopback port */ |
| 3865 | static void mvpp2_port_loopback_set(struct mvpp2_port *port) |
| 3866 | { |
| 3867 | u32 val; |
| 3868 | |
| 3869 | val = readl(port->base + MVPP2_GMAC_CTRL_1_REG); |
| 3870 | |
| 3871 | if (port->speed == 1000) |
| 3872 | val |= MVPP2_GMAC_GMII_LB_EN_MASK; |
| 3873 | else |
| 3874 | val &= ~MVPP2_GMAC_GMII_LB_EN_MASK; |
| 3875 | |
| 3876 | if (port->phy_interface == PHY_INTERFACE_MODE_SGMII) |
| 3877 | val |= MVPP2_GMAC_PCS_LB_EN_MASK; |
| 3878 | else |
| 3879 | val &= ~MVPP2_GMAC_PCS_LB_EN_MASK; |
| 3880 | |
| 3881 | writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); |
| 3882 | } |
| 3883 | |
| 3884 | static void mvpp2_port_reset(struct mvpp2_port *port) |
| 3885 | { |
| 3886 | u32 val; |
| 3887 | |
| 3888 | val = readl(port->base + MVPP2_GMAC_CTRL_2_REG) & |
| 3889 | ~MVPP2_GMAC_PORT_RESET_MASK; |
| 3890 | writel(val, port->base + MVPP2_GMAC_CTRL_2_REG); |
| 3891 | |
| 3892 | while (readl(port->base + MVPP2_GMAC_CTRL_2_REG) & |
| 3893 | MVPP2_GMAC_PORT_RESET_MASK) |
| 3894 | continue; |
| 3895 | } |
| 3896 | |
| 3897 | /* Change maximum receive size of the port */ |
| 3898 | static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port *port) |
| 3899 | { |
| 3900 | u32 val; |
| 3901 | |
| 3902 | val = readl(port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3903 | val &= ~MVPP2_GMAC_MAX_RX_SIZE_MASK; |
| 3904 | val |= (((port->pkt_size - MVPP2_MH_SIZE) / 2) << |
| 3905 | MVPP2_GMAC_MAX_RX_SIZE_OFFS); |
| 3906 | writel(val, port->base + MVPP2_GMAC_CTRL_0_REG); |
| 3907 | } |
| 3908 | |
| 3909 | /* Set defaults to the MVPP2 port */ |
| 3910 | static void mvpp2_defaults_set(struct mvpp2_port *port) |
| 3911 | { |
| 3912 | int tx_port_num, val, queue, ptxq, lrxq; |
| 3913 | |
| 3914 | /* Configure port to loopback if needed */ |
| 3915 | if (port->flags & MVPP2_F_LOOPBACK) |
| 3916 | mvpp2_port_loopback_set(port); |
| 3917 | |
| 3918 | /* Update TX FIFO MIN Threshold */ |
| 3919 | val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); |
| 3920 | val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK; |
| 3921 | /* Min. TX threshold must be less than minimal packet length */ |
| 3922 | val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(64 - 4 - 2); |
| 3923 | writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG); |
| 3924 | |
| 3925 | /* Disable Legacy WRR, Disable EJP, Release from reset */ |
| 3926 | tx_port_num = mvpp2_egress_port(port); |
| 3927 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, |
| 3928 | tx_port_num); |
| 3929 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0); |
| 3930 | |
| 3931 | /* Close bandwidth for all queues */ |
| 3932 | for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) { |
| 3933 | ptxq = mvpp2_txq_phys(port->id, queue); |
| 3934 | mvpp2_write(port->priv, |
| 3935 | MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0); |
| 3936 | } |
| 3937 | |
| 3938 | /* Set refill period to 1 usec, refill tokens |
| 3939 | * and bucket size to maximum |
| 3940 | */ |
| 3941 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PERIOD_REG, |
| 3942 | port->priv->tclk / USEC_PER_SEC); |
| 3943 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_REFILL_REG); |
| 3944 | val &= ~MVPP2_TXP_REFILL_PERIOD_ALL_MASK; |
| 3945 | val |= MVPP2_TXP_REFILL_PERIOD_MASK(1); |
| 3946 | val |= MVPP2_TXP_REFILL_TOKENS_ALL_MASK; |
| 3947 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_REFILL_REG, val); |
| 3948 | val = MVPP2_TXP_TOKEN_SIZE_MAX; |
| 3949 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); |
| 3950 | |
| 3951 | /* Set MaximumLowLatencyPacketSize value to 256 */ |
| 3952 | mvpp2_write(port->priv, MVPP2_RX_CTRL_REG(port->id), |
| 3953 | MVPP2_RX_USE_PSEUDO_FOR_CSUM_MASK | |
| 3954 | MVPP2_RX_LOW_LATENCY_PKT_SIZE(256)); |
| 3955 | |
| 3956 | /* Enable Rx cache snoop */ |
| 3957 | for (lrxq = 0; lrxq < rxq_number; lrxq++) { |
| 3958 | queue = port->rxqs[lrxq]->id; |
| 3959 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); |
| 3960 | val |= MVPP2_SNOOP_PKT_SIZE_MASK | |
| 3961 | MVPP2_SNOOP_BUF_HDR_MASK; |
| 3962 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); |
| 3963 | } |
| 3964 | |
| 3965 | /* At default, mask all interrupts to all present cpus */ |
| 3966 | mvpp2_interrupts_disable(port); |
| 3967 | } |
| 3968 | |
| 3969 | /* Enable/disable receiving packets */ |
| 3970 | static void mvpp2_ingress_enable(struct mvpp2_port *port) |
| 3971 | { |
| 3972 | u32 val; |
| 3973 | int lrxq, queue; |
| 3974 | |
| 3975 | for (lrxq = 0; lrxq < rxq_number; lrxq++) { |
| 3976 | queue = port->rxqs[lrxq]->id; |
| 3977 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); |
| 3978 | val &= ~MVPP2_RXQ_DISABLE_MASK; |
| 3979 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); |
| 3980 | } |
| 3981 | } |
| 3982 | |
| 3983 | static void mvpp2_ingress_disable(struct mvpp2_port *port) |
| 3984 | { |
| 3985 | u32 val; |
| 3986 | int lrxq, queue; |
| 3987 | |
| 3988 | for (lrxq = 0; lrxq < rxq_number; lrxq++) { |
| 3989 | queue = port->rxqs[lrxq]->id; |
| 3990 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(queue)); |
| 3991 | val |= MVPP2_RXQ_DISABLE_MASK; |
| 3992 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(queue), val); |
| 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | /* Enable transmit via physical egress queue |
| 3997 | * - HW starts take descriptors from DRAM |
| 3998 | */ |
| 3999 | static void mvpp2_egress_enable(struct mvpp2_port *port) |
| 4000 | { |
| 4001 | u32 qmap; |
| 4002 | int queue; |
| 4003 | int tx_port_num = mvpp2_egress_port(port); |
| 4004 | |
| 4005 | /* Enable all initialized TXs. */ |
| 4006 | qmap = 0; |
| 4007 | for (queue = 0; queue < txq_number; queue++) { |
| 4008 | struct mvpp2_tx_queue *txq = port->txqs[queue]; |
| 4009 | |
| 4010 | if (txq->descs != NULL) |
| 4011 | qmap |= (1 << queue); |
| 4012 | } |
| 4013 | |
| 4014 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); |
| 4015 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, qmap); |
| 4016 | } |
| 4017 | |
| 4018 | /* Disable transmit via physical egress queue |
| 4019 | * - HW doesn't take descriptors from DRAM |
| 4020 | */ |
| 4021 | static void mvpp2_egress_disable(struct mvpp2_port *port) |
| 4022 | { |
| 4023 | u32 reg_data; |
| 4024 | int delay; |
| 4025 | int tx_port_num = mvpp2_egress_port(port); |
| 4026 | |
| 4027 | /* Issue stop command for active channels only */ |
| 4028 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); |
| 4029 | reg_data = (mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG)) & |
| 4030 | MVPP2_TXP_SCHED_ENQ_MASK; |
| 4031 | if (reg_data != 0) |
| 4032 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG, |
| 4033 | (reg_data << MVPP2_TXP_SCHED_DISQ_OFFSET)); |
| 4034 | |
| 4035 | /* Wait for all Tx activity to terminate. */ |
| 4036 | delay = 0; |
| 4037 | do { |
| 4038 | if (delay >= MVPP2_TX_DISABLE_TIMEOUT_MSEC) { |
| 4039 | netdev_warn(port->dev, |
| 4040 | "Tx stop timed out, status=0x%08x\n", |
| 4041 | reg_data); |
| 4042 | break; |
| 4043 | } |
| 4044 | mdelay(1); |
| 4045 | delay++; |
| 4046 | |
| 4047 | /* Check port TX Command register that all |
| 4048 | * Tx queues are stopped |
| 4049 | */ |
| 4050 | reg_data = mvpp2_read(port->priv, MVPP2_TXP_SCHED_Q_CMD_REG); |
| 4051 | } while (reg_data & MVPP2_TXP_SCHED_ENQ_MASK); |
| 4052 | } |
| 4053 | |
| 4054 | /* Rx descriptors helper methods */ |
| 4055 | |
| 4056 | /* Get number of Rx descriptors occupied by received packets */ |
| 4057 | static inline int |
| 4058 | mvpp2_rxq_received(struct mvpp2_port *port, int rxq_id) |
| 4059 | { |
| 4060 | u32 val = mvpp2_read(port->priv, MVPP2_RXQ_STATUS_REG(rxq_id)); |
| 4061 | |
| 4062 | return val & MVPP2_RXQ_OCCUPIED_MASK; |
| 4063 | } |
| 4064 | |
| 4065 | /* Update Rx queue status with the number of occupied and available |
| 4066 | * Rx descriptor slots. |
| 4067 | */ |
| 4068 | static inline void |
| 4069 | mvpp2_rxq_status_update(struct mvpp2_port *port, int rxq_id, |
| 4070 | int used_count, int free_count) |
| 4071 | { |
| 4072 | /* Decrement the number of used descriptors and increment count |
| 4073 | * increment the number of free descriptors. |
| 4074 | */ |
| 4075 | u32 val = used_count | (free_count << MVPP2_RXQ_NUM_NEW_OFFSET); |
| 4076 | |
| 4077 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_UPDATE_REG(rxq_id), val); |
| 4078 | } |
| 4079 | |
| 4080 | /* Get pointer to next RX descriptor to be processed by SW */ |
| 4081 | static inline struct mvpp2_rx_desc * |
| 4082 | mvpp2_rxq_next_desc_get(struct mvpp2_rx_queue *rxq) |
| 4083 | { |
| 4084 | int rx_desc = rxq->next_desc_to_proc; |
| 4085 | |
| 4086 | rxq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(rxq, rx_desc); |
| 4087 | prefetch(rxq->descs + rxq->next_desc_to_proc); |
| 4088 | return rxq->descs + rx_desc; |
| 4089 | } |
| 4090 | |
| 4091 | /* Set rx queue offset */ |
| 4092 | static void mvpp2_rxq_offset_set(struct mvpp2_port *port, |
| 4093 | int prxq, int offset) |
| 4094 | { |
| 4095 | u32 val; |
| 4096 | |
| 4097 | /* Convert offset from bytes to units of 32 bytes */ |
| 4098 | offset = offset >> 5; |
| 4099 | |
| 4100 | val = mvpp2_read(port->priv, MVPP2_RXQ_CONFIG_REG(prxq)); |
| 4101 | val &= ~MVPP2_RXQ_PACKET_OFFSET_MASK; |
| 4102 | |
| 4103 | /* Offset is in */ |
| 4104 | val |= ((offset << MVPP2_RXQ_PACKET_OFFSET_OFFS) & |
| 4105 | MVPP2_RXQ_PACKET_OFFSET_MASK); |
| 4106 | |
| 4107 | mvpp2_write(port->priv, MVPP2_RXQ_CONFIG_REG(prxq), val); |
| 4108 | } |
| 4109 | |
| 4110 | /* Obtain BM cookie information from descriptor */ |
| 4111 | static u32 mvpp2_bm_cookie_build(struct mvpp2_rx_desc *rx_desc) |
| 4112 | { |
| 4113 | int pool = (rx_desc->status & MVPP2_RXD_BM_POOL_ID_MASK) >> |
| 4114 | MVPP2_RXD_BM_POOL_ID_OFFS; |
| 4115 | int cpu = smp_processor_id(); |
| 4116 | |
| 4117 | return ((pool & 0xFF) << MVPP2_BM_COOKIE_POOL_OFFS) | |
| 4118 | ((cpu & 0xFF) << MVPP2_BM_COOKIE_CPU_OFFS); |
| 4119 | } |
| 4120 | |
| 4121 | /* Tx descriptors helper methods */ |
| 4122 | |
| 4123 | /* Get number of Tx descriptors waiting to be transmitted by HW */ |
| 4124 | static int mvpp2_txq_pend_desc_num_get(struct mvpp2_port *port, |
| 4125 | struct mvpp2_tx_queue *txq) |
| 4126 | { |
| 4127 | u32 val; |
| 4128 | |
| 4129 | mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id); |
| 4130 | val = mvpp2_read(port->priv, MVPP2_TXQ_PENDING_REG); |
| 4131 | |
| 4132 | return val & MVPP2_TXQ_PENDING_MASK; |
| 4133 | } |
| 4134 | |
| 4135 | /* Get pointer to next Tx descriptor to be processed (send) by HW */ |
| 4136 | static struct mvpp2_tx_desc * |
| 4137 | mvpp2_txq_next_desc_get(struct mvpp2_tx_queue *txq) |
| 4138 | { |
| 4139 | int tx_desc = txq->next_desc_to_proc; |
| 4140 | |
| 4141 | txq->next_desc_to_proc = MVPP2_QUEUE_NEXT_DESC(txq, tx_desc); |
| 4142 | return txq->descs + tx_desc; |
| 4143 | } |
| 4144 | |
| 4145 | /* Update HW with number of aggregated Tx descriptors to be sent */ |
| 4146 | static void mvpp2_aggr_txq_pend_desc_add(struct mvpp2_port *port, int pending) |
| 4147 | { |
| 4148 | /* aggregated access - relevant TXQ number is written in TX desc */ |
| 4149 | mvpp2_write(port->priv, MVPP2_AGGR_TXQ_UPDATE_REG, pending); |
| 4150 | } |
| 4151 | |
| 4152 | |
| 4153 | /* Check if there are enough free descriptors in aggregated txq. |
| 4154 | * If not, update the number of occupied descriptors and repeat the check. |
| 4155 | */ |
| 4156 | static int mvpp2_aggr_desc_num_check(struct mvpp2 *priv, |
| 4157 | struct mvpp2_tx_queue *aggr_txq, int num) |
| 4158 | { |
| 4159 | if ((aggr_txq->count + num) > aggr_txq->size) { |
| 4160 | /* Update number of occupied aggregated Tx descriptors */ |
| 4161 | int cpu = smp_processor_id(); |
| 4162 | u32 val = mvpp2_read(priv, MVPP2_AGGR_TXQ_STATUS_REG(cpu)); |
| 4163 | |
| 4164 | aggr_txq->count = val & MVPP2_AGGR_TXQ_PENDING_MASK; |
| 4165 | } |
| 4166 | |
| 4167 | if ((aggr_txq->count + num) > aggr_txq->size) |
| 4168 | return -ENOMEM; |
| 4169 | |
| 4170 | return 0; |
| 4171 | } |
| 4172 | |
| 4173 | /* Reserved Tx descriptors allocation request */ |
| 4174 | static int mvpp2_txq_alloc_reserved_desc(struct mvpp2 *priv, |
| 4175 | struct mvpp2_tx_queue *txq, int num) |
| 4176 | { |
| 4177 | u32 val; |
| 4178 | |
| 4179 | val = (txq->id << MVPP2_TXQ_RSVD_REQ_Q_OFFSET) | num; |
| 4180 | mvpp2_write(priv, MVPP2_TXQ_RSVD_REQ_REG, val); |
| 4181 | |
| 4182 | val = mvpp2_read(priv, MVPP2_TXQ_RSVD_RSLT_REG); |
| 4183 | |
| 4184 | return val & MVPP2_TXQ_RSVD_RSLT_MASK; |
| 4185 | } |
| 4186 | |
| 4187 | /* Check if there are enough reserved descriptors for transmission. |
| 4188 | * If not, request chunk of reserved descriptors and check again. |
| 4189 | */ |
| 4190 | static int mvpp2_txq_reserved_desc_num_proc(struct mvpp2 *priv, |
| 4191 | struct mvpp2_tx_queue *txq, |
| 4192 | struct mvpp2_txq_pcpu *txq_pcpu, |
| 4193 | int num) |
| 4194 | { |
| 4195 | int req, cpu, desc_count; |
| 4196 | |
| 4197 | if (txq_pcpu->reserved_num >= num) |
| 4198 | return 0; |
| 4199 | |
| 4200 | /* Not enough descriptors reserved! Update the reserved descriptor |
| 4201 | * count and check again. |
| 4202 | */ |
| 4203 | |
| 4204 | desc_count = 0; |
| 4205 | /* Compute total of used descriptors */ |
| 4206 | for_each_present_cpu(cpu) { |
| 4207 | struct mvpp2_txq_pcpu *txq_pcpu_aux; |
| 4208 | |
| 4209 | txq_pcpu_aux = per_cpu_ptr(txq->pcpu, cpu); |
| 4210 | desc_count += txq_pcpu_aux->count; |
| 4211 | desc_count += txq_pcpu_aux->reserved_num; |
| 4212 | } |
| 4213 | |
| 4214 | req = max(MVPP2_CPU_DESC_CHUNK, num - txq_pcpu->reserved_num); |
| 4215 | desc_count += req; |
| 4216 | |
| 4217 | if (desc_count > |
| 4218 | (txq->size - (num_present_cpus() * MVPP2_CPU_DESC_CHUNK))) |
| 4219 | return -ENOMEM; |
| 4220 | |
| 4221 | txq_pcpu->reserved_num += mvpp2_txq_alloc_reserved_desc(priv, txq, req); |
| 4222 | |
| 4223 | /* OK, the descriptor cound has been updated: check again. */ |
| 4224 | if (txq_pcpu->reserved_num < num) |
| 4225 | return -ENOMEM; |
| 4226 | return 0; |
| 4227 | } |
| 4228 | |
| 4229 | /* Release the last allocated Tx descriptor. Useful to handle DMA |
| 4230 | * mapping failures in the Tx path. |
| 4231 | */ |
| 4232 | static void mvpp2_txq_desc_put(struct mvpp2_tx_queue *txq) |
| 4233 | { |
| 4234 | if (txq->next_desc_to_proc == 0) |
| 4235 | txq->next_desc_to_proc = txq->last_desc - 1; |
| 4236 | else |
| 4237 | txq->next_desc_to_proc--; |
| 4238 | } |
| 4239 | |
| 4240 | /* Set Tx descriptors fields relevant for CSUM calculation */ |
| 4241 | static u32 mvpp2_txq_desc_csum(int l3_offs, int l3_proto, |
| 4242 | int ip_hdr_len, int l4_proto) |
| 4243 | { |
| 4244 | u32 command; |
| 4245 | |
| 4246 | /* fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk, |
| 4247 | * G_L4_chk, L4_type required only for checksum calculation |
| 4248 | */ |
| 4249 | command = (l3_offs << MVPP2_TXD_L3_OFF_SHIFT); |
| 4250 | command |= (ip_hdr_len << MVPP2_TXD_IP_HLEN_SHIFT); |
| 4251 | command |= MVPP2_TXD_IP_CSUM_DISABLE; |
| 4252 | |
| 4253 | if (l3_proto == swab16(ETH_P_IP)) { |
| 4254 | command &= ~MVPP2_TXD_IP_CSUM_DISABLE; /* enable IPv4 csum */ |
| 4255 | command &= ~MVPP2_TXD_L3_IP6; /* enable IPv4 */ |
| 4256 | } else { |
| 4257 | command |= MVPP2_TXD_L3_IP6; /* enable IPv6 */ |
| 4258 | } |
| 4259 | |
| 4260 | if (l4_proto == IPPROTO_TCP) { |
| 4261 | command &= ~MVPP2_TXD_L4_UDP; /* enable TCP */ |
| 4262 | command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */ |
| 4263 | } else if (l4_proto == IPPROTO_UDP) { |
| 4264 | command |= MVPP2_TXD_L4_UDP; /* enable UDP */ |
| 4265 | command &= ~MVPP2_TXD_L4_CSUM_FRAG; /* generate L4 csum */ |
| 4266 | } else { |
| 4267 | command |= MVPP2_TXD_L4_CSUM_NOT; |
| 4268 | } |
| 4269 | |
| 4270 | return command; |
| 4271 | } |
| 4272 | |
| 4273 | /* Get number of sent descriptors and decrement counter. |
| 4274 | * The number of sent descriptors is returned. |
| 4275 | * Per-CPU access |
| 4276 | */ |
| 4277 | static inline int mvpp2_txq_sent_desc_proc(struct mvpp2_port *port, |
| 4278 | struct mvpp2_tx_queue *txq) |
| 4279 | { |
| 4280 | u32 val; |
| 4281 | |
| 4282 | /* Reading status reg resets transmitted descriptor counter */ |
| 4283 | val = mvpp2_read(port->priv, MVPP2_TXQ_SENT_REG(txq->id)); |
| 4284 | |
| 4285 | return (val & MVPP2_TRANSMITTED_COUNT_MASK) >> |
| 4286 | MVPP2_TRANSMITTED_COUNT_OFFSET; |
| 4287 | } |
| 4288 | |
| 4289 | static void mvpp2_txq_sent_counter_clear(void *arg) |
| 4290 | { |
| 4291 | struct mvpp2_port *port = arg; |
| 4292 | int queue; |
| 4293 | |
| 4294 | for (queue = 0; queue < txq_number; queue++) { |
| 4295 | int id = port->txqs[queue]->id; |
| 4296 | |
| 4297 | mvpp2_read(port->priv, MVPP2_TXQ_SENT_REG(id)); |
| 4298 | } |
| 4299 | } |
| 4300 | |
| 4301 | /* Set max sizes for Tx queues */ |
| 4302 | static void mvpp2_txp_max_tx_size_set(struct mvpp2_port *port) |
| 4303 | { |
| 4304 | u32 val, size, mtu; |
| 4305 | int txq, tx_port_num; |
| 4306 | |
| 4307 | mtu = port->pkt_size * 8; |
| 4308 | if (mtu > MVPP2_TXP_MTU_MAX) |
| 4309 | mtu = MVPP2_TXP_MTU_MAX; |
| 4310 | |
| 4311 | /* WA for wrong Token bucket update: Set MTU value = 3*real MTU value */ |
| 4312 | mtu = 3 * mtu; |
| 4313 | |
| 4314 | /* Indirect access to registers */ |
| 4315 | tx_port_num = mvpp2_egress_port(port); |
| 4316 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); |
| 4317 | |
| 4318 | /* Set MTU */ |
| 4319 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_MTU_REG); |
| 4320 | val &= ~MVPP2_TXP_MTU_MAX; |
| 4321 | val |= mtu; |
| 4322 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_MTU_REG, val); |
| 4323 | |
| 4324 | /* TXP token size and all TXQs token size must be larger that MTU */ |
| 4325 | val = mvpp2_read(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG); |
| 4326 | size = val & MVPP2_TXP_TOKEN_SIZE_MAX; |
| 4327 | if (size < mtu) { |
| 4328 | size = mtu; |
| 4329 | val &= ~MVPP2_TXP_TOKEN_SIZE_MAX; |
| 4330 | val |= size; |
| 4331 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_TOKEN_SIZE_REG, val); |
| 4332 | } |
| 4333 | |
| 4334 | for (txq = 0; txq < txq_number; txq++) { |
| 4335 | val = mvpp2_read(port->priv, |
| 4336 | MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq)); |
| 4337 | size = val & MVPP2_TXQ_TOKEN_SIZE_MAX; |
| 4338 | |
| 4339 | if (size < mtu) { |
| 4340 | size = mtu; |
| 4341 | val &= ~MVPP2_TXQ_TOKEN_SIZE_MAX; |
| 4342 | val |= size; |
| 4343 | mvpp2_write(port->priv, |
| 4344 | MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq), |
| 4345 | val); |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | /* Set the number of packets that will be received before Rx interrupt |
| 4351 | * will be generated by HW. |
| 4352 | */ |
| 4353 | static void mvpp2_rx_pkts_coal_set(struct mvpp2_port *port, |
| 4354 | struct mvpp2_rx_queue *rxq, u32 pkts) |
| 4355 | { |
| 4356 | u32 val; |
| 4357 | |
| 4358 | val = (pkts & MVPP2_OCCUPIED_THRESH_MASK); |
| 4359 | mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id); |
| 4360 | mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val); |
| 4361 | |
| 4362 | rxq->pkts_coal = pkts; |
| 4363 | } |
| 4364 | |
| 4365 | /* Set the time delay in usec before Rx interrupt */ |
| 4366 | static void mvpp2_rx_time_coal_set(struct mvpp2_port *port, |
| 4367 | struct mvpp2_rx_queue *rxq, u32 usec) |
| 4368 | { |
| 4369 | u32 val; |
| 4370 | |
| 4371 | val = (port->priv->tclk / USEC_PER_SEC) * usec; |
| 4372 | mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val); |
| 4373 | |
| 4374 | rxq->time_coal = usec; |
| 4375 | } |
| 4376 | |
| 4377 | /* Set threshold for TX_DONE pkts coalescing */ |
| 4378 | static void mvpp2_tx_done_pkts_coal_set(void *arg) |
| 4379 | { |
| 4380 | struct mvpp2_port *port = arg; |
| 4381 | int queue; |
| 4382 | u32 val; |
| 4383 | |
| 4384 | for (queue = 0; queue < txq_number; queue++) { |
| 4385 | struct mvpp2_tx_queue *txq = port->txqs[queue]; |
| 4386 | |
| 4387 | val = (txq->done_pkts_coal << MVPP2_TRANSMITTED_THRESH_OFFSET) & |
| 4388 | MVPP2_TRANSMITTED_THRESH_MASK; |
| 4389 | mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id); |
| 4390 | mvpp2_write(port->priv, MVPP2_TXQ_THRESH_REG, val); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | /* Free Tx queue skbuffs */ |
| 4395 | static void mvpp2_txq_bufs_free(struct mvpp2_port *port, |
| 4396 | struct mvpp2_tx_queue *txq, |
| 4397 | struct mvpp2_txq_pcpu *txq_pcpu, int num) |
| 4398 | { |
| 4399 | int i; |
| 4400 | |
| 4401 | for (i = 0; i < num; i++) { |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 4402 | dma_addr_t buf_phys_addr = |
| 4403 | txq_pcpu->tx_buffs[txq_pcpu->txq_get_index]; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4404 | struct sk_buff *skb = txq_pcpu->tx_skb[txq_pcpu->txq_get_index]; |
| 4405 | |
| 4406 | mvpp2_txq_inc_get(txq_pcpu); |
| 4407 | |
| 4408 | if (!skb) |
| 4409 | continue; |
| 4410 | |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 4411 | dma_unmap_single(port->dev->dev.parent, buf_phys_addr, |
| 4412 | skb_headlen(skb), DMA_TO_DEVICE); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4413 | dev_kfree_skb_any(skb); |
| 4414 | } |
| 4415 | } |
| 4416 | |
| 4417 | static inline struct mvpp2_rx_queue *mvpp2_get_rx_queue(struct mvpp2_port *port, |
| 4418 | u32 cause) |
| 4419 | { |
| 4420 | int queue = fls(cause) - 1; |
| 4421 | |
| 4422 | return port->rxqs[queue]; |
| 4423 | } |
| 4424 | |
| 4425 | static inline struct mvpp2_tx_queue *mvpp2_get_tx_queue(struct mvpp2_port *port, |
| 4426 | u32 cause) |
| 4427 | { |
| 4428 | int queue = fls(cause >> 16) - 1; |
| 4429 | |
| 4430 | return port->txqs[queue]; |
| 4431 | } |
| 4432 | |
| 4433 | /* Handle end of transmission */ |
| 4434 | static void mvpp2_txq_done(struct mvpp2_port *port, struct mvpp2_tx_queue *txq, |
| 4435 | struct mvpp2_txq_pcpu *txq_pcpu) |
| 4436 | { |
| 4437 | struct netdev_queue *nq = netdev_get_tx_queue(port->dev, txq->log_id); |
| 4438 | int tx_done; |
| 4439 | |
| 4440 | if (txq_pcpu->cpu != smp_processor_id()) |
| 4441 | netdev_err(port->dev, "wrong cpu on the end of Tx processing\n"); |
| 4442 | |
| 4443 | tx_done = mvpp2_txq_sent_desc_proc(port, txq); |
| 4444 | if (!tx_done) |
| 4445 | return; |
| 4446 | mvpp2_txq_bufs_free(port, txq, txq_pcpu, tx_done); |
| 4447 | |
| 4448 | txq_pcpu->count -= tx_done; |
| 4449 | |
| 4450 | if (netif_tx_queue_stopped(nq)) |
| 4451 | if (txq_pcpu->size - txq_pcpu->count >= MAX_SKB_FRAGS + 1) |
| 4452 | netif_tx_wake_queue(nq); |
| 4453 | } |
| 4454 | |
| 4455 | /* Rx/Tx queue initialization/cleanup methods */ |
| 4456 | |
| 4457 | /* Allocate and initialize descriptors for aggr TXQ */ |
| 4458 | static int mvpp2_aggr_txq_init(struct platform_device *pdev, |
| 4459 | struct mvpp2_tx_queue *aggr_txq, |
| 4460 | int desc_num, int cpu, |
| 4461 | struct mvpp2 *priv) |
| 4462 | { |
| 4463 | /* Allocate memory for TX descriptors */ |
| 4464 | aggr_txq->descs = dma_alloc_coherent(&pdev->dev, |
| 4465 | desc_num * MVPP2_DESC_ALIGNED_SIZE, |
| 4466 | &aggr_txq->descs_phys, GFP_KERNEL); |
| 4467 | if (!aggr_txq->descs) |
| 4468 | return -ENOMEM; |
| 4469 | |
| 4470 | /* Make sure descriptor address is cache line size aligned */ |
| 4471 | BUG_ON(aggr_txq->descs != |
| 4472 | PTR_ALIGN(aggr_txq->descs, MVPP2_CPU_D_CACHE_LINE_SIZE)); |
| 4473 | |
| 4474 | aggr_txq->last_desc = aggr_txq->size - 1; |
| 4475 | |
| 4476 | /* Aggr TXQ no reset WA */ |
| 4477 | aggr_txq->next_desc_to_proc = mvpp2_read(priv, |
| 4478 | MVPP2_AGGR_TXQ_INDEX_REG(cpu)); |
| 4479 | |
| 4480 | /* Set Tx descriptors queue starting address */ |
| 4481 | /* indirect access */ |
| 4482 | mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_ADDR_REG(cpu), |
| 4483 | aggr_txq->descs_phys); |
| 4484 | mvpp2_write(priv, MVPP2_AGGR_TXQ_DESC_SIZE_REG(cpu), desc_num); |
| 4485 | |
| 4486 | return 0; |
| 4487 | } |
| 4488 | |
| 4489 | /* Create a specified Rx queue */ |
| 4490 | static int mvpp2_rxq_init(struct mvpp2_port *port, |
| 4491 | struct mvpp2_rx_queue *rxq) |
| 4492 | |
| 4493 | { |
| 4494 | rxq->size = port->rx_ring_size; |
| 4495 | |
| 4496 | /* Allocate memory for RX descriptors */ |
| 4497 | rxq->descs = dma_alloc_coherent(port->dev->dev.parent, |
| 4498 | rxq->size * MVPP2_DESC_ALIGNED_SIZE, |
| 4499 | &rxq->descs_phys, GFP_KERNEL); |
| 4500 | if (!rxq->descs) |
| 4501 | return -ENOMEM; |
| 4502 | |
| 4503 | BUG_ON(rxq->descs != |
| 4504 | PTR_ALIGN(rxq->descs, MVPP2_CPU_D_CACHE_LINE_SIZE)); |
| 4505 | |
| 4506 | rxq->last_desc = rxq->size - 1; |
| 4507 | |
| 4508 | /* Zero occupied and non-occupied counters - direct access */ |
| 4509 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); |
| 4510 | |
| 4511 | /* Set Rx descriptors queue starting address - indirect access */ |
| 4512 | mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id); |
| 4513 | mvpp2_write(port->priv, MVPP2_RXQ_DESC_ADDR_REG, rxq->descs_phys); |
| 4514 | mvpp2_write(port->priv, MVPP2_RXQ_DESC_SIZE_REG, rxq->size); |
| 4515 | mvpp2_write(port->priv, MVPP2_RXQ_INDEX_REG, 0); |
| 4516 | |
| 4517 | /* Set Offset */ |
| 4518 | mvpp2_rxq_offset_set(port, rxq->id, NET_SKB_PAD); |
| 4519 | |
| 4520 | /* Set coalescing pkts and time */ |
| 4521 | mvpp2_rx_pkts_coal_set(port, rxq, rxq->pkts_coal); |
| 4522 | mvpp2_rx_time_coal_set(port, rxq, rxq->time_coal); |
| 4523 | |
| 4524 | /* Add number of descriptors ready for receiving packets */ |
| 4525 | mvpp2_rxq_status_update(port, rxq->id, 0, rxq->size); |
| 4526 | |
| 4527 | return 0; |
| 4528 | } |
| 4529 | |
| 4530 | /* Push packets received by the RXQ to BM pool */ |
| 4531 | static void mvpp2_rxq_drop_pkts(struct mvpp2_port *port, |
| 4532 | struct mvpp2_rx_queue *rxq) |
| 4533 | { |
| 4534 | int rx_received, i; |
| 4535 | |
| 4536 | rx_received = mvpp2_rxq_received(port, rxq->id); |
| 4537 | if (!rx_received) |
| 4538 | return; |
| 4539 | |
| 4540 | for (i = 0; i < rx_received; i++) { |
| 4541 | struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq); |
| 4542 | u32 bm = mvpp2_bm_cookie_build(rx_desc); |
| 4543 | |
| 4544 | mvpp2_pool_refill(port, bm, rx_desc->buf_phys_addr, |
| 4545 | rx_desc->buf_cookie); |
| 4546 | } |
| 4547 | mvpp2_rxq_status_update(port, rxq->id, rx_received, rx_received); |
| 4548 | } |
| 4549 | |
| 4550 | /* Cleanup Rx queue */ |
| 4551 | static void mvpp2_rxq_deinit(struct mvpp2_port *port, |
| 4552 | struct mvpp2_rx_queue *rxq) |
| 4553 | { |
| 4554 | mvpp2_rxq_drop_pkts(port, rxq); |
| 4555 | |
| 4556 | if (rxq->descs) |
| 4557 | dma_free_coherent(port->dev->dev.parent, |
| 4558 | rxq->size * MVPP2_DESC_ALIGNED_SIZE, |
| 4559 | rxq->descs, |
| 4560 | rxq->descs_phys); |
| 4561 | |
| 4562 | rxq->descs = NULL; |
| 4563 | rxq->last_desc = 0; |
| 4564 | rxq->next_desc_to_proc = 0; |
| 4565 | rxq->descs_phys = 0; |
| 4566 | |
| 4567 | /* Clear Rx descriptors queue starting address and size; |
| 4568 | * free descriptor number |
| 4569 | */ |
| 4570 | mvpp2_write(port->priv, MVPP2_RXQ_STATUS_REG(rxq->id), 0); |
| 4571 | mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id); |
| 4572 | mvpp2_write(port->priv, MVPP2_RXQ_DESC_ADDR_REG, 0); |
| 4573 | mvpp2_write(port->priv, MVPP2_RXQ_DESC_SIZE_REG, 0); |
| 4574 | } |
| 4575 | |
| 4576 | /* Create and initialize a Tx queue */ |
| 4577 | static int mvpp2_txq_init(struct mvpp2_port *port, |
| 4578 | struct mvpp2_tx_queue *txq) |
| 4579 | { |
| 4580 | u32 val; |
| 4581 | int cpu, desc, desc_per_txq, tx_port_num; |
| 4582 | struct mvpp2_txq_pcpu *txq_pcpu; |
| 4583 | |
| 4584 | txq->size = port->tx_ring_size; |
| 4585 | |
| 4586 | /* Allocate memory for Tx descriptors */ |
| 4587 | txq->descs = dma_alloc_coherent(port->dev->dev.parent, |
| 4588 | txq->size * MVPP2_DESC_ALIGNED_SIZE, |
| 4589 | &txq->descs_phys, GFP_KERNEL); |
| 4590 | if (!txq->descs) |
| 4591 | return -ENOMEM; |
| 4592 | |
| 4593 | /* Make sure descriptor address is cache line size aligned */ |
| 4594 | BUG_ON(txq->descs != |
| 4595 | PTR_ALIGN(txq->descs, MVPP2_CPU_D_CACHE_LINE_SIZE)); |
| 4596 | |
| 4597 | txq->last_desc = txq->size - 1; |
| 4598 | |
| 4599 | /* Set Tx descriptors queue starting address - indirect access */ |
| 4600 | mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id); |
| 4601 | mvpp2_write(port->priv, MVPP2_TXQ_DESC_ADDR_REG, txq->descs_phys); |
| 4602 | mvpp2_write(port->priv, MVPP2_TXQ_DESC_SIZE_REG, txq->size & |
| 4603 | MVPP2_TXQ_DESC_SIZE_MASK); |
| 4604 | mvpp2_write(port->priv, MVPP2_TXQ_INDEX_REG, 0); |
| 4605 | mvpp2_write(port->priv, MVPP2_TXQ_RSVD_CLR_REG, |
| 4606 | txq->id << MVPP2_TXQ_RSVD_CLR_OFFSET); |
| 4607 | val = mvpp2_read(port->priv, MVPP2_TXQ_PENDING_REG); |
| 4608 | val &= ~MVPP2_TXQ_PENDING_MASK; |
| 4609 | mvpp2_write(port->priv, MVPP2_TXQ_PENDING_REG, val); |
| 4610 | |
| 4611 | /* Calculate base address in prefetch buffer. We reserve 16 descriptors |
| 4612 | * for each existing TXQ. |
| 4613 | * TCONTS for PON port must be continuous from 0 to MVPP2_MAX_TCONT |
| 4614 | * GBE ports assumed to be continious from 0 to MVPP2_MAX_PORTS |
| 4615 | */ |
| 4616 | desc_per_txq = 16; |
| 4617 | desc = (port->id * MVPP2_MAX_TXQ * desc_per_txq) + |
| 4618 | (txq->log_id * desc_per_txq); |
| 4619 | |
| 4620 | mvpp2_write(port->priv, MVPP2_TXQ_PREF_BUF_REG, |
| 4621 | MVPP2_PREF_BUF_PTR(desc) | MVPP2_PREF_BUF_SIZE_16 | |
| 4622 | MVPP2_PREF_BUF_THRESH(desc_per_txq/2)); |
| 4623 | |
| 4624 | /* WRR / EJP configuration - indirect access */ |
| 4625 | tx_port_num = mvpp2_egress_port(port); |
| 4626 | mvpp2_write(port->priv, MVPP2_TXP_SCHED_PORT_INDEX_REG, tx_port_num); |
| 4627 | |
| 4628 | val = mvpp2_read(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id)); |
| 4629 | val &= ~MVPP2_TXQ_REFILL_PERIOD_ALL_MASK; |
| 4630 | val |= MVPP2_TXQ_REFILL_PERIOD_MASK(1); |
| 4631 | val |= MVPP2_TXQ_REFILL_TOKENS_ALL_MASK; |
| 4632 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_REFILL_REG(txq->log_id), val); |
| 4633 | |
| 4634 | val = MVPP2_TXQ_TOKEN_SIZE_MAX; |
| 4635 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_SIZE_REG(txq->log_id), |
| 4636 | val); |
| 4637 | |
| 4638 | for_each_present_cpu(cpu) { |
| 4639 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
| 4640 | txq_pcpu->size = txq->size; |
| 4641 | txq_pcpu->tx_skb = kmalloc(txq_pcpu->size * |
| 4642 | sizeof(*txq_pcpu->tx_skb), |
| 4643 | GFP_KERNEL); |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 4644 | if (!txq_pcpu->tx_skb) |
| 4645 | goto error; |
| 4646 | |
| 4647 | txq_pcpu->tx_buffs = kmalloc(txq_pcpu->size * |
| 4648 | sizeof(dma_addr_t), GFP_KERNEL); |
| 4649 | if (!txq_pcpu->tx_buffs) |
| 4650 | goto error; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4651 | |
| 4652 | txq_pcpu->count = 0; |
| 4653 | txq_pcpu->reserved_num = 0; |
| 4654 | txq_pcpu->txq_put_index = 0; |
| 4655 | txq_pcpu->txq_get_index = 0; |
| 4656 | } |
| 4657 | |
| 4658 | return 0; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 4659 | |
| 4660 | error: |
| 4661 | for_each_present_cpu(cpu) { |
| 4662 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
| 4663 | kfree(txq_pcpu->tx_skb); |
| 4664 | kfree(txq_pcpu->tx_buffs); |
| 4665 | } |
| 4666 | |
| 4667 | dma_free_coherent(port->dev->dev.parent, |
| 4668 | txq->size * MVPP2_DESC_ALIGNED_SIZE, |
| 4669 | txq->descs, txq->descs_phys); |
| 4670 | |
| 4671 | return -ENOMEM; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | /* Free allocated TXQ resources */ |
| 4675 | static void mvpp2_txq_deinit(struct mvpp2_port *port, |
| 4676 | struct mvpp2_tx_queue *txq) |
| 4677 | { |
| 4678 | struct mvpp2_txq_pcpu *txq_pcpu; |
| 4679 | int cpu; |
| 4680 | |
| 4681 | for_each_present_cpu(cpu) { |
| 4682 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
| 4683 | kfree(txq_pcpu->tx_skb); |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 4684 | kfree(txq_pcpu->tx_buffs); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | if (txq->descs) |
| 4688 | dma_free_coherent(port->dev->dev.parent, |
| 4689 | txq->size * MVPP2_DESC_ALIGNED_SIZE, |
| 4690 | txq->descs, txq->descs_phys); |
| 4691 | |
| 4692 | txq->descs = NULL; |
| 4693 | txq->last_desc = 0; |
| 4694 | txq->next_desc_to_proc = 0; |
| 4695 | txq->descs_phys = 0; |
| 4696 | |
| 4697 | /* Set minimum bandwidth for disabled TXQs */ |
| 4698 | mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0); |
| 4699 | |
| 4700 | /* Set Tx descriptors queue starting address and size */ |
| 4701 | mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id); |
| 4702 | mvpp2_write(port->priv, MVPP2_TXQ_DESC_ADDR_REG, 0); |
| 4703 | mvpp2_write(port->priv, MVPP2_TXQ_DESC_SIZE_REG, 0); |
| 4704 | } |
| 4705 | |
| 4706 | /* Cleanup Tx ports */ |
| 4707 | static void mvpp2_txq_clean(struct mvpp2_port *port, struct mvpp2_tx_queue *txq) |
| 4708 | { |
| 4709 | struct mvpp2_txq_pcpu *txq_pcpu; |
| 4710 | int delay, pending, cpu; |
| 4711 | u32 val; |
| 4712 | |
| 4713 | mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id); |
| 4714 | val = mvpp2_read(port->priv, MVPP2_TXQ_PREF_BUF_REG); |
| 4715 | val |= MVPP2_TXQ_DRAIN_EN_MASK; |
| 4716 | mvpp2_write(port->priv, MVPP2_TXQ_PREF_BUF_REG, val); |
| 4717 | |
| 4718 | /* The napi queue has been stopped so wait for all packets |
| 4719 | * to be transmitted. |
| 4720 | */ |
| 4721 | delay = 0; |
| 4722 | do { |
| 4723 | if (delay >= MVPP2_TX_PENDING_TIMEOUT_MSEC) { |
| 4724 | netdev_warn(port->dev, |
| 4725 | "port %d: cleaning queue %d timed out\n", |
| 4726 | port->id, txq->log_id); |
| 4727 | break; |
| 4728 | } |
| 4729 | mdelay(1); |
| 4730 | delay++; |
| 4731 | |
| 4732 | pending = mvpp2_txq_pend_desc_num_get(port, txq); |
| 4733 | } while (pending); |
| 4734 | |
| 4735 | val &= ~MVPP2_TXQ_DRAIN_EN_MASK; |
| 4736 | mvpp2_write(port->priv, MVPP2_TXQ_PREF_BUF_REG, val); |
| 4737 | |
| 4738 | for_each_present_cpu(cpu) { |
| 4739 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
| 4740 | |
| 4741 | /* Release all packets */ |
| 4742 | mvpp2_txq_bufs_free(port, txq, txq_pcpu, txq_pcpu->count); |
| 4743 | |
| 4744 | /* Reset queue */ |
| 4745 | txq_pcpu->count = 0; |
| 4746 | txq_pcpu->txq_put_index = 0; |
| 4747 | txq_pcpu->txq_get_index = 0; |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | /* Cleanup all Tx queues */ |
| 4752 | static void mvpp2_cleanup_txqs(struct mvpp2_port *port) |
| 4753 | { |
| 4754 | struct mvpp2_tx_queue *txq; |
| 4755 | int queue; |
| 4756 | u32 val; |
| 4757 | |
| 4758 | val = mvpp2_read(port->priv, MVPP2_TX_PORT_FLUSH_REG); |
| 4759 | |
| 4760 | /* Reset Tx ports and delete Tx queues */ |
| 4761 | val |= MVPP2_TX_PORT_FLUSH_MASK(port->id); |
| 4762 | mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); |
| 4763 | |
| 4764 | for (queue = 0; queue < txq_number; queue++) { |
| 4765 | txq = port->txqs[queue]; |
| 4766 | mvpp2_txq_clean(port, txq); |
| 4767 | mvpp2_txq_deinit(port, txq); |
| 4768 | } |
| 4769 | |
| 4770 | on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1); |
| 4771 | |
| 4772 | val &= ~MVPP2_TX_PORT_FLUSH_MASK(port->id); |
| 4773 | mvpp2_write(port->priv, MVPP2_TX_PORT_FLUSH_REG, val); |
| 4774 | } |
| 4775 | |
| 4776 | /* Cleanup all Rx queues */ |
| 4777 | static void mvpp2_cleanup_rxqs(struct mvpp2_port *port) |
| 4778 | { |
| 4779 | int queue; |
| 4780 | |
| 4781 | for (queue = 0; queue < rxq_number; queue++) |
| 4782 | mvpp2_rxq_deinit(port, port->rxqs[queue]); |
| 4783 | } |
| 4784 | |
| 4785 | /* Init all Rx queues for port */ |
| 4786 | static int mvpp2_setup_rxqs(struct mvpp2_port *port) |
| 4787 | { |
| 4788 | int queue, err; |
| 4789 | |
| 4790 | for (queue = 0; queue < rxq_number; queue++) { |
| 4791 | err = mvpp2_rxq_init(port, port->rxqs[queue]); |
| 4792 | if (err) |
| 4793 | goto err_cleanup; |
| 4794 | } |
| 4795 | return 0; |
| 4796 | |
| 4797 | err_cleanup: |
| 4798 | mvpp2_cleanup_rxqs(port); |
| 4799 | return err; |
| 4800 | } |
| 4801 | |
| 4802 | /* Init all tx queues for port */ |
| 4803 | static int mvpp2_setup_txqs(struct mvpp2_port *port) |
| 4804 | { |
| 4805 | struct mvpp2_tx_queue *txq; |
| 4806 | int queue, err; |
| 4807 | |
| 4808 | for (queue = 0; queue < txq_number; queue++) { |
| 4809 | txq = port->txqs[queue]; |
| 4810 | err = mvpp2_txq_init(port, txq); |
| 4811 | if (err) |
| 4812 | goto err_cleanup; |
| 4813 | } |
| 4814 | |
| 4815 | on_each_cpu(mvpp2_tx_done_pkts_coal_set, port, 1); |
| 4816 | on_each_cpu(mvpp2_txq_sent_counter_clear, port, 1); |
| 4817 | return 0; |
| 4818 | |
| 4819 | err_cleanup: |
| 4820 | mvpp2_cleanup_txqs(port); |
| 4821 | return err; |
| 4822 | } |
| 4823 | |
| 4824 | /* The callback for per-port interrupt */ |
| 4825 | static irqreturn_t mvpp2_isr(int irq, void *dev_id) |
| 4826 | { |
| 4827 | struct mvpp2_port *port = (struct mvpp2_port *)dev_id; |
| 4828 | |
| 4829 | mvpp2_interrupts_disable(port); |
| 4830 | |
| 4831 | napi_schedule(&port->napi); |
| 4832 | |
| 4833 | return IRQ_HANDLED; |
| 4834 | } |
| 4835 | |
| 4836 | /* Adjust link */ |
| 4837 | static void mvpp2_link_event(struct net_device *dev) |
| 4838 | { |
| 4839 | struct mvpp2_port *port = netdev_priv(dev); |
| 4840 | struct phy_device *phydev = port->phy_dev; |
| 4841 | int status_change = 0; |
| 4842 | u32 val; |
| 4843 | |
| 4844 | if (phydev->link) { |
| 4845 | if ((port->speed != phydev->speed) || |
| 4846 | (port->duplex != phydev->duplex)) { |
| 4847 | u32 val; |
| 4848 | |
| 4849 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
| 4850 | val &= ~(MVPP2_GMAC_CONFIG_MII_SPEED | |
| 4851 | MVPP2_GMAC_CONFIG_GMII_SPEED | |
| 4852 | MVPP2_GMAC_CONFIG_FULL_DUPLEX | |
| 4853 | MVPP2_GMAC_AN_SPEED_EN | |
| 4854 | MVPP2_GMAC_AN_DUPLEX_EN); |
| 4855 | |
| 4856 | if (phydev->duplex) |
| 4857 | val |= MVPP2_GMAC_CONFIG_FULL_DUPLEX; |
| 4858 | |
| 4859 | if (phydev->speed == SPEED_1000) |
| 4860 | val |= MVPP2_GMAC_CONFIG_GMII_SPEED; |
Thomas Petazzoni | 2add511 | 2014-07-27 23:21:35 +0200 | [diff] [blame] | 4861 | else if (phydev->speed == SPEED_100) |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 4862 | val |= MVPP2_GMAC_CONFIG_MII_SPEED; |
| 4863 | |
| 4864 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
| 4865 | |
| 4866 | port->duplex = phydev->duplex; |
| 4867 | port->speed = phydev->speed; |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | if (phydev->link != port->link) { |
| 4872 | if (!phydev->link) { |
| 4873 | port->duplex = -1; |
| 4874 | port->speed = 0; |
| 4875 | } |
| 4876 | |
| 4877 | port->link = phydev->link; |
| 4878 | status_change = 1; |
| 4879 | } |
| 4880 | |
| 4881 | if (status_change) { |
| 4882 | if (phydev->link) { |
| 4883 | val = readl(port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
| 4884 | val |= (MVPP2_GMAC_FORCE_LINK_PASS | |
| 4885 | MVPP2_GMAC_FORCE_LINK_DOWN); |
| 4886 | writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG); |
| 4887 | mvpp2_egress_enable(port); |
| 4888 | mvpp2_ingress_enable(port); |
| 4889 | } else { |
| 4890 | mvpp2_ingress_disable(port); |
| 4891 | mvpp2_egress_disable(port); |
| 4892 | } |
| 4893 | phy_print_status(phydev); |
| 4894 | } |
| 4895 | } |
| 4896 | |
| 4897 | /* Main RX/TX processing routines */ |
| 4898 | |
| 4899 | /* Display more error info */ |
| 4900 | static void mvpp2_rx_error(struct mvpp2_port *port, |
| 4901 | struct mvpp2_rx_desc *rx_desc) |
| 4902 | { |
| 4903 | u32 status = rx_desc->status; |
| 4904 | |
| 4905 | switch (status & MVPP2_RXD_ERR_CODE_MASK) { |
| 4906 | case MVPP2_RXD_ERR_CRC: |
| 4907 | netdev_err(port->dev, "bad rx status %08x (crc error), size=%d\n", |
| 4908 | status, rx_desc->data_size); |
| 4909 | break; |
| 4910 | case MVPP2_RXD_ERR_OVERRUN: |
| 4911 | netdev_err(port->dev, "bad rx status %08x (overrun error), size=%d\n", |
| 4912 | status, rx_desc->data_size); |
| 4913 | break; |
| 4914 | case MVPP2_RXD_ERR_RESOURCE: |
| 4915 | netdev_err(port->dev, "bad rx status %08x (resource error), size=%d\n", |
| 4916 | status, rx_desc->data_size); |
| 4917 | break; |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | /* Handle RX checksum offload */ |
| 4922 | static void mvpp2_rx_csum(struct mvpp2_port *port, u32 status, |
| 4923 | struct sk_buff *skb) |
| 4924 | { |
| 4925 | if (((status & MVPP2_RXD_L3_IP4) && |
| 4926 | !(status & MVPP2_RXD_IP4_HEADER_ERR)) || |
| 4927 | (status & MVPP2_RXD_L3_IP6)) |
| 4928 | if (((status & MVPP2_RXD_L4_UDP) || |
| 4929 | (status & MVPP2_RXD_L4_TCP)) && |
| 4930 | (status & MVPP2_RXD_L4_CSUM_OK)) { |
| 4931 | skb->csum = 0; |
| 4932 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4933 | return; |
| 4934 | } |
| 4935 | |
| 4936 | skb->ip_summed = CHECKSUM_NONE; |
| 4937 | } |
| 4938 | |
| 4939 | /* Reuse skb if possible, or allocate a new skb and add it to BM pool */ |
| 4940 | static int mvpp2_rx_refill(struct mvpp2_port *port, |
| 4941 | struct mvpp2_bm_pool *bm_pool, |
| 4942 | u32 bm, int is_recycle) |
| 4943 | { |
| 4944 | struct sk_buff *skb; |
| 4945 | dma_addr_t phys_addr; |
| 4946 | |
| 4947 | if (is_recycle && |
| 4948 | (atomic_read(&bm_pool->in_use) < bm_pool->in_use_thresh)) |
| 4949 | return 0; |
| 4950 | |
| 4951 | /* No recycle or too many buffers are in use, so allocate a new skb */ |
| 4952 | skb = mvpp2_skb_alloc(port, bm_pool, &phys_addr, GFP_ATOMIC); |
| 4953 | if (!skb) |
| 4954 | return -ENOMEM; |
| 4955 | |
| 4956 | mvpp2_pool_refill(port, bm, (u32)phys_addr, (u32)skb); |
| 4957 | atomic_dec(&bm_pool->in_use); |
| 4958 | return 0; |
| 4959 | } |
| 4960 | |
| 4961 | /* Handle tx checksum */ |
| 4962 | static u32 mvpp2_skb_tx_csum(struct mvpp2_port *port, struct sk_buff *skb) |
| 4963 | { |
| 4964 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 4965 | int ip_hdr_len = 0; |
| 4966 | u8 l4_proto; |
| 4967 | |
| 4968 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4969 | struct iphdr *ip4h = ip_hdr(skb); |
| 4970 | |
| 4971 | /* Calculate IPv4 checksum and L4 checksum */ |
| 4972 | ip_hdr_len = ip4h->ihl; |
| 4973 | l4_proto = ip4h->protocol; |
| 4974 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 4975 | struct ipv6hdr *ip6h = ipv6_hdr(skb); |
| 4976 | |
| 4977 | /* Read l4_protocol from one of IPv6 extra headers */ |
| 4978 | if (skb_network_header_len(skb) > 0) |
| 4979 | ip_hdr_len = (skb_network_header_len(skb) >> 2); |
| 4980 | l4_proto = ip6h->nexthdr; |
| 4981 | } else { |
| 4982 | return MVPP2_TXD_L4_CSUM_NOT; |
| 4983 | } |
| 4984 | |
| 4985 | return mvpp2_txq_desc_csum(skb_network_offset(skb), |
| 4986 | skb->protocol, ip_hdr_len, l4_proto); |
| 4987 | } |
| 4988 | |
| 4989 | return MVPP2_TXD_L4_CSUM_NOT | MVPP2_TXD_IP_CSUM_DISABLE; |
| 4990 | } |
| 4991 | |
| 4992 | static void mvpp2_buff_hdr_rx(struct mvpp2_port *port, |
| 4993 | struct mvpp2_rx_desc *rx_desc) |
| 4994 | { |
| 4995 | struct mvpp2_buff_hdr *buff_hdr; |
| 4996 | struct sk_buff *skb; |
| 4997 | u32 rx_status = rx_desc->status; |
| 4998 | u32 buff_phys_addr; |
| 4999 | u32 buff_virt_addr; |
| 5000 | u32 buff_phys_addr_next; |
| 5001 | u32 buff_virt_addr_next; |
| 5002 | int mc_id; |
| 5003 | int pool_id; |
| 5004 | |
| 5005 | pool_id = (rx_status & MVPP2_RXD_BM_POOL_ID_MASK) >> |
| 5006 | MVPP2_RXD_BM_POOL_ID_OFFS; |
| 5007 | buff_phys_addr = rx_desc->buf_phys_addr; |
| 5008 | buff_virt_addr = rx_desc->buf_cookie; |
| 5009 | |
| 5010 | do { |
| 5011 | skb = (struct sk_buff *)buff_virt_addr; |
| 5012 | buff_hdr = (struct mvpp2_buff_hdr *)skb->head; |
| 5013 | |
| 5014 | mc_id = MVPP2_B_HDR_INFO_MC_ID(buff_hdr->info); |
| 5015 | |
| 5016 | buff_phys_addr_next = buff_hdr->next_buff_phys_addr; |
| 5017 | buff_virt_addr_next = buff_hdr->next_buff_virt_addr; |
| 5018 | |
| 5019 | /* Release buffer */ |
| 5020 | mvpp2_bm_pool_mc_put(port, pool_id, buff_phys_addr, |
| 5021 | buff_virt_addr, mc_id); |
| 5022 | |
| 5023 | buff_phys_addr = buff_phys_addr_next; |
| 5024 | buff_virt_addr = buff_virt_addr_next; |
| 5025 | |
| 5026 | } while (!MVPP2_B_HDR_INFO_IS_LAST(buff_hdr->info)); |
| 5027 | } |
| 5028 | |
| 5029 | /* Main rx processing */ |
| 5030 | static int mvpp2_rx(struct mvpp2_port *port, int rx_todo, |
| 5031 | struct mvpp2_rx_queue *rxq) |
| 5032 | { |
| 5033 | struct net_device *dev = port->dev; |
| 5034 | int rx_received, rx_filled, i; |
| 5035 | u32 rcvd_pkts = 0; |
| 5036 | u32 rcvd_bytes = 0; |
| 5037 | |
| 5038 | /* Get number of received packets and clamp the to-do */ |
| 5039 | rx_received = mvpp2_rxq_received(port, rxq->id); |
| 5040 | if (rx_todo > rx_received) |
| 5041 | rx_todo = rx_received; |
| 5042 | |
| 5043 | rx_filled = 0; |
| 5044 | for (i = 0; i < rx_todo; i++) { |
| 5045 | struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq); |
| 5046 | struct mvpp2_bm_pool *bm_pool; |
| 5047 | struct sk_buff *skb; |
| 5048 | u32 bm, rx_status; |
| 5049 | int pool, rx_bytes, err; |
| 5050 | |
| 5051 | rx_filled++; |
| 5052 | rx_status = rx_desc->status; |
| 5053 | rx_bytes = rx_desc->data_size - MVPP2_MH_SIZE; |
| 5054 | |
| 5055 | bm = mvpp2_bm_cookie_build(rx_desc); |
| 5056 | pool = mvpp2_bm_cookie_pool_get(bm); |
| 5057 | bm_pool = &port->priv->bm_pools[pool]; |
| 5058 | /* Check if buffer header is used */ |
| 5059 | if (rx_status & MVPP2_RXD_BUF_HDR) { |
| 5060 | mvpp2_buff_hdr_rx(port, rx_desc); |
| 5061 | continue; |
| 5062 | } |
| 5063 | |
| 5064 | /* In case of an error, release the requested buffer pointer |
| 5065 | * to the Buffer Manager. This request process is controlled |
| 5066 | * by the hardware, and the information about the buffer is |
| 5067 | * comprised by the RX descriptor. |
| 5068 | */ |
| 5069 | if (rx_status & MVPP2_RXD_ERR_SUMMARY) { |
| 5070 | dev->stats.rx_errors++; |
| 5071 | mvpp2_rx_error(port, rx_desc); |
| 5072 | mvpp2_pool_refill(port, bm, rx_desc->buf_phys_addr, |
| 5073 | rx_desc->buf_cookie); |
| 5074 | continue; |
| 5075 | } |
| 5076 | |
| 5077 | skb = (struct sk_buff *)rx_desc->buf_cookie; |
| 5078 | |
| 5079 | rcvd_pkts++; |
| 5080 | rcvd_bytes += rx_bytes; |
| 5081 | atomic_inc(&bm_pool->in_use); |
| 5082 | |
| 5083 | skb_reserve(skb, MVPP2_MH_SIZE); |
| 5084 | skb_put(skb, rx_bytes); |
| 5085 | skb->protocol = eth_type_trans(skb, dev); |
| 5086 | mvpp2_rx_csum(port, rx_status, skb); |
| 5087 | |
| 5088 | napi_gro_receive(&port->napi, skb); |
| 5089 | |
| 5090 | err = mvpp2_rx_refill(port, bm_pool, bm, 0); |
| 5091 | if (err) { |
| 5092 | netdev_err(port->dev, "failed to refill BM pools\n"); |
| 5093 | rx_filled--; |
| 5094 | } |
| 5095 | } |
| 5096 | |
| 5097 | if (rcvd_pkts) { |
| 5098 | struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); |
| 5099 | |
| 5100 | u64_stats_update_begin(&stats->syncp); |
| 5101 | stats->rx_packets += rcvd_pkts; |
| 5102 | stats->rx_bytes += rcvd_bytes; |
| 5103 | u64_stats_update_end(&stats->syncp); |
| 5104 | } |
| 5105 | |
| 5106 | /* Update Rx queue management counters */ |
| 5107 | wmb(); |
| 5108 | mvpp2_rxq_status_update(port, rxq->id, rx_todo, rx_filled); |
| 5109 | |
| 5110 | return rx_todo; |
| 5111 | } |
| 5112 | |
| 5113 | static inline void |
| 5114 | tx_desc_unmap_put(struct device *dev, struct mvpp2_tx_queue *txq, |
| 5115 | struct mvpp2_tx_desc *desc) |
| 5116 | { |
| 5117 | dma_unmap_single(dev, desc->buf_phys_addr, |
| 5118 | desc->data_size, DMA_TO_DEVICE); |
| 5119 | mvpp2_txq_desc_put(txq); |
| 5120 | } |
| 5121 | |
| 5122 | /* Handle tx fragmentation processing */ |
| 5123 | static int mvpp2_tx_frag_process(struct mvpp2_port *port, struct sk_buff *skb, |
| 5124 | struct mvpp2_tx_queue *aggr_txq, |
| 5125 | struct mvpp2_tx_queue *txq) |
| 5126 | { |
| 5127 | struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu); |
| 5128 | struct mvpp2_tx_desc *tx_desc; |
| 5129 | int i; |
| 5130 | dma_addr_t buf_phys_addr; |
| 5131 | |
| 5132 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 5133 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5134 | void *addr = page_address(frag->page.p) + frag->page_offset; |
| 5135 | |
| 5136 | tx_desc = mvpp2_txq_next_desc_get(aggr_txq); |
| 5137 | tx_desc->phys_txq = txq->id; |
| 5138 | tx_desc->data_size = frag->size; |
| 5139 | |
| 5140 | buf_phys_addr = dma_map_single(port->dev->dev.parent, addr, |
| 5141 | tx_desc->data_size, |
| 5142 | DMA_TO_DEVICE); |
| 5143 | if (dma_mapping_error(port->dev->dev.parent, buf_phys_addr)) { |
| 5144 | mvpp2_txq_desc_put(txq); |
| 5145 | goto error; |
| 5146 | } |
| 5147 | |
| 5148 | tx_desc->packet_offset = buf_phys_addr & MVPP2_TX_DESC_ALIGN; |
| 5149 | tx_desc->buf_phys_addr = buf_phys_addr & (~MVPP2_TX_DESC_ALIGN); |
| 5150 | |
| 5151 | if (i == (skb_shinfo(skb)->nr_frags - 1)) { |
| 5152 | /* Last descriptor */ |
| 5153 | tx_desc->command = MVPP2_TXD_L_DESC; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 5154 | mvpp2_txq_inc_put(txq_pcpu, skb, tx_desc); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5155 | } else { |
| 5156 | /* Descriptor in the middle: Not First, Not Last */ |
| 5157 | tx_desc->command = 0; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 5158 | mvpp2_txq_inc_put(txq_pcpu, NULL, tx_desc); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | return 0; |
| 5163 | |
| 5164 | error: |
| 5165 | /* Release all descriptors that were used to map fragments of |
| 5166 | * this packet, as well as the corresponding DMA mappings |
| 5167 | */ |
| 5168 | for (i = i - 1; i >= 0; i--) { |
| 5169 | tx_desc = txq->descs + i; |
| 5170 | tx_desc_unmap_put(port->dev->dev.parent, txq, tx_desc); |
| 5171 | } |
| 5172 | |
| 5173 | return -ENOMEM; |
| 5174 | } |
| 5175 | |
| 5176 | /* Main tx processing */ |
| 5177 | static int mvpp2_tx(struct sk_buff *skb, struct net_device *dev) |
| 5178 | { |
| 5179 | struct mvpp2_port *port = netdev_priv(dev); |
| 5180 | struct mvpp2_tx_queue *txq, *aggr_txq; |
| 5181 | struct mvpp2_txq_pcpu *txq_pcpu; |
| 5182 | struct mvpp2_tx_desc *tx_desc; |
| 5183 | dma_addr_t buf_phys_addr; |
| 5184 | int frags = 0; |
| 5185 | u16 txq_id; |
| 5186 | u32 tx_cmd; |
| 5187 | |
| 5188 | txq_id = skb_get_queue_mapping(skb); |
| 5189 | txq = port->txqs[txq_id]; |
| 5190 | txq_pcpu = this_cpu_ptr(txq->pcpu); |
| 5191 | aggr_txq = &port->priv->aggr_txqs[smp_processor_id()]; |
| 5192 | |
| 5193 | frags = skb_shinfo(skb)->nr_frags + 1; |
| 5194 | |
| 5195 | /* Check number of available descriptors */ |
| 5196 | if (mvpp2_aggr_desc_num_check(port->priv, aggr_txq, frags) || |
| 5197 | mvpp2_txq_reserved_desc_num_proc(port->priv, txq, |
| 5198 | txq_pcpu, frags)) { |
| 5199 | frags = 0; |
| 5200 | goto out; |
| 5201 | } |
| 5202 | |
| 5203 | /* Get a descriptor for the first part of the packet */ |
| 5204 | tx_desc = mvpp2_txq_next_desc_get(aggr_txq); |
| 5205 | tx_desc->phys_txq = txq->id; |
| 5206 | tx_desc->data_size = skb_headlen(skb); |
| 5207 | |
| 5208 | buf_phys_addr = dma_map_single(dev->dev.parent, skb->data, |
| 5209 | tx_desc->data_size, DMA_TO_DEVICE); |
| 5210 | if (unlikely(dma_mapping_error(dev->dev.parent, buf_phys_addr))) { |
| 5211 | mvpp2_txq_desc_put(txq); |
| 5212 | frags = 0; |
| 5213 | goto out; |
| 5214 | } |
| 5215 | tx_desc->packet_offset = buf_phys_addr & MVPP2_TX_DESC_ALIGN; |
| 5216 | tx_desc->buf_phys_addr = buf_phys_addr & ~MVPP2_TX_DESC_ALIGN; |
| 5217 | |
| 5218 | tx_cmd = mvpp2_skb_tx_csum(port, skb); |
| 5219 | |
| 5220 | if (frags == 1) { |
| 5221 | /* First and Last descriptor */ |
| 5222 | tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_L_DESC; |
| 5223 | tx_desc->command = tx_cmd; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 5224 | mvpp2_txq_inc_put(txq_pcpu, skb, tx_desc); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5225 | } else { |
| 5226 | /* First but not Last */ |
| 5227 | tx_cmd |= MVPP2_TXD_F_DESC | MVPP2_TXD_PADDING_DISABLE; |
| 5228 | tx_desc->command = tx_cmd; |
Marcin Wojtas | 71ce391 | 2015-08-06 19:00:29 +0200 | [diff] [blame^] | 5229 | mvpp2_txq_inc_put(txq_pcpu, NULL, tx_desc); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5230 | |
| 5231 | /* Continue with other skb fragments */ |
| 5232 | if (mvpp2_tx_frag_process(port, skb, aggr_txq, txq)) { |
| 5233 | tx_desc_unmap_put(port->dev->dev.parent, txq, tx_desc); |
| 5234 | frags = 0; |
| 5235 | goto out; |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | txq_pcpu->reserved_num -= frags; |
| 5240 | txq_pcpu->count += frags; |
| 5241 | aggr_txq->count += frags; |
| 5242 | |
| 5243 | /* Enable transmit */ |
| 5244 | wmb(); |
| 5245 | mvpp2_aggr_txq_pend_desc_add(port, frags); |
| 5246 | |
| 5247 | if (txq_pcpu->size - txq_pcpu->count < MAX_SKB_FRAGS + 1) { |
| 5248 | struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id); |
| 5249 | |
| 5250 | netif_tx_stop_queue(nq); |
| 5251 | } |
| 5252 | out: |
| 5253 | if (frags > 0) { |
| 5254 | struct mvpp2_pcpu_stats *stats = this_cpu_ptr(port->stats); |
| 5255 | |
| 5256 | u64_stats_update_begin(&stats->syncp); |
| 5257 | stats->tx_packets++; |
| 5258 | stats->tx_bytes += skb->len; |
| 5259 | u64_stats_update_end(&stats->syncp); |
| 5260 | } else { |
| 5261 | dev->stats.tx_dropped++; |
| 5262 | dev_kfree_skb_any(skb); |
| 5263 | } |
| 5264 | |
| 5265 | return NETDEV_TX_OK; |
| 5266 | } |
| 5267 | |
| 5268 | static inline void mvpp2_cause_error(struct net_device *dev, int cause) |
| 5269 | { |
| 5270 | if (cause & MVPP2_CAUSE_FCS_ERR_MASK) |
| 5271 | netdev_err(dev, "FCS error\n"); |
| 5272 | if (cause & MVPP2_CAUSE_RX_FIFO_OVERRUN_MASK) |
| 5273 | netdev_err(dev, "rx fifo overrun error\n"); |
| 5274 | if (cause & MVPP2_CAUSE_TX_FIFO_UNDERRUN_MASK) |
| 5275 | netdev_err(dev, "tx fifo underrun error\n"); |
| 5276 | } |
| 5277 | |
| 5278 | static void mvpp2_txq_done_percpu(void *arg) |
| 5279 | { |
| 5280 | struct mvpp2_port *port = arg; |
| 5281 | u32 cause_rx_tx, cause_tx, cause_misc; |
| 5282 | |
| 5283 | /* Rx/Tx cause register |
| 5284 | * |
| 5285 | * Bits 0-15: each bit indicates received packets on the Rx queue |
| 5286 | * (bit 0 is for Rx queue 0). |
| 5287 | * |
| 5288 | * Bits 16-23: each bit indicates transmitted packets on the Tx queue |
| 5289 | * (bit 16 is for Tx queue 0). |
| 5290 | * |
| 5291 | * Each CPU has its own Rx/Tx cause register |
| 5292 | */ |
| 5293 | cause_rx_tx = mvpp2_read(port->priv, |
| 5294 | MVPP2_ISR_RX_TX_CAUSE_REG(port->id)); |
| 5295 | cause_tx = cause_rx_tx & MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK; |
| 5296 | cause_misc = cause_rx_tx & MVPP2_CAUSE_MISC_SUM_MASK; |
| 5297 | |
| 5298 | if (cause_misc) { |
| 5299 | mvpp2_cause_error(port->dev, cause_misc); |
| 5300 | |
| 5301 | /* Clear the cause register */ |
| 5302 | mvpp2_write(port->priv, MVPP2_ISR_MISC_CAUSE_REG, 0); |
| 5303 | mvpp2_write(port->priv, MVPP2_ISR_RX_TX_CAUSE_REG(port->id), |
| 5304 | cause_rx_tx & ~MVPP2_CAUSE_MISC_SUM_MASK); |
| 5305 | } |
| 5306 | |
| 5307 | /* Release TX descriptors */ |
| 5308 | if (cause_tx) { |
| 5309 | struct mvpp2_tx_queue *txq = mvpp2_get_tx_queue(port, cause_tx); |
| 5310 | struct mvpp2_txq_pcpu *txq_pcpu = this_cpu_ptr(txq->pcpu); |
| 5311 | |
| 5312 | if (txq_pcpu->count) |
| 5313 | mvpp2_txq_done(port, txq, txq_pcpu); |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | static int mvpp2_poll(struct napi_struct *napi, int budget) |
| 5318 | { |
| 5319 | u32 cause_rx_tx, cause_rx; |
| 5320 | int rx_done = 0; |
| 5321 | struct mvpp2_port *port = netdev_priv(napi->dev); |
| 5322 | |
| 5323 | on_each_cpu(mvpp2_txq_done_percpu, port, 1); |
| 5324 | |
| 5325 | cause_rx_tx = mvpp2_read(port->priv, |
| 5326 | MVPP2_ISR_RX_TX_CAUSE_REG(port->id)); |
| 5327 | cause_rx = cause_rx_tx & MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK; |
| 5328 | |
| 5329 | /* Process RX packets */ |
| 5330 | cause_rx |= port->pending_cause_rx; |
| 5331 | while (cause_rx && budget > 0) { |
| 5332 | int count; |
| 5333 | struct mvpp2_rx_queue *rxq; |
| 5334 | |
| 5335 | rxq = mvpp2_get_rx_queue(port, cause_rx); |
| 5336 | if (!rxq) |
| 5337 | break; |
| 5338 | |
| 5339 | count = mvpp2_rx(port, budget, rxq); |
| 5340 | rx_done += count; |
| 5341 | budget -= count; |
| 5342 | if (budget > 0) { |
| 5343 | /* Clear the bit associated to this Rx queue |
| 5344 | * so that next iteration will continue from |
| 5345 | * the next Rx queue. |
| 5346 | */ |
| 5347 | cause_rx &= ~(1 << rxq->logic_rxq); |
| 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | if (budget > 0) { |
| 5352 | cause_rx = 0; |
| 5353 | napi_complete(napi); |
| 5354 | |
| 5355 | mvpp2_interrupts_enable(port); |
| 5356 | } |
| 5357 | port->pending_cause_rx = cause_rx; |
| 5358 | return rx_done; |
| 5359 | } |
| 5360 | |
| 5361 | /* Set hw internals when starting port */ |
| 5362 | static void mvpp2_start_dev(struct mvpp2_port *port) |
| 5363 | { |
| 5364 | mvpp2_gmac_max_rx_size_set(port); |
| 5365 | mvpp2_txp_max_tx_size_set(port); |
| 5366 | |
| 5367 | napi_enable(&port->napi); |
| 5368 | |
| 5369 | /* Enable interrupts on all CPUs */ |
| 5370 | mvpp2_interrupts_enable(port); |
| 5371 | |
| 5372 | mvpp2_port_enable(port); |
| 5373 | phy_start(port->phy_dev); |
| 5374 | netif_tx_start_all_queues(port->dev); |
| 5375 | } |
| 5376 | |
| 5377 | /* Set hw internals when stopping port */ |
| 5378 | static void mvpp2_stop_dev(struct mvpp2_port *port) |
| 5379 | { |
| 5380 | /* Stop new packets from arriving to RXQs */ |
| 5381 | mvpp2_ingress_disable(port); |
| 5382 | |
| 5383 | mdelay(10); |
| 5384 | |
| 5385 | /* Disable interrupts on all CPUs */ |
| 5386 | mvpp2_interrupts_disable(port); |
| 5387 | |
| 5388 | napi_disable(&port->napi); |
| 5389 | |
| 5390 | netif_carrier_off(port->dev); |
| 5391 | netif_tx_stop_all_queues(port->dev); |
| 5392 | |
| 5393 | mvpp2_egress_disable(port); |
| 5394 | mvpp2_port_disable(port); |
| 5395 | phy_stop(port->phy_dev); |
| 5396 | } |
| 5397 | |
| 5398 | /* Return positive if MTU is valid */ |
| 5399 | static inline int mvpp2_check_mtu_valid(struct net_device *dev, int mtu) |
| 5400 | { |
| 5401 | if (mtu < 68) { |
| 5402 | netdev_err(dev, "cannot change mtu to less than 68\n"); |
| 5403 | return -EINVAL; |
| 5404 | } |
| 5405 | |
| 5406 | /* 9676 == 9700 - 20 and rounding to 8 */ |
| 5407 | if (mtu > 9676) { |
| 5408 | netdev_info(dev, "illegal MTU value %d, round to 9676\n", mtu); |
| 5409 | mtu = 9676; |
| 5410 | } |
| 5411 | |
| 5412 | if (!IS_ALIGNED(MVPP2_RX_PKT_SIZE(mtu), 8)) { |
| 5413 | netdev_info(dev, "illegal MTU value %d, round to %d\n", mtu, |
| 5414 | ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8)); |
| 5415 | mtu = ALIGN(MVPP2_RX_PKT_SIZE(mtu), 8); |
| 5416 | } |
| 5417 | |
| 5418 | return mtu; |
| 5419 | } |
| 5420 | |
| 5421 | static int mvpp2_check_ringparam_valid(struct net_device *dev, |
| 5422 | struct ethtool_ringparam *ring) |
| 5423 | { |
| 5424 | u16 new_rx_pending = ring->rx_pending; |
| 5425 | u16 new_tx_pending = ring->tx_pending; |
| 5426 | |
| 5427 | if (ring->rx_pending == 0 || ring->tx_pending == 0) |
| 5428 | return -EINVAL; |
| 5429 | |
| 5430 | if (ring->rx_pending > MVPP2_MAX_RXD) |
| 5431 | new_rx_pending = MVPP2_MAX_RXD; |
| 5432 | else if (!IS_ALIGNED(ring->rx_pending, 16)) |
| 5433 | new_rx_pending = ALIGN(ring->rx_pending, 16); |
| 5434 | |
| 5435 | if (ring->tx_pending > MVPP2_MAX_TXD) |
| 5436 | new_tx_pending = MVPP2_MAX_TXD; |
| 5437 | else if (!IS_ALIGNED(ring->tx_pending, 32)) |
| 5438 | new_tx_pending = ALIGN(ring->tx_pending, 32); |
| 5439 | |
| 5440 | if (ring->rx_pending != new_rx_pending) { |
| 5441 | netdev_info(dev, "illegal Rx ring size value %d, round to %d\n", |
| 5442 | ring->rx_pending, new_rx_pending); |
| 5443 | ring->rx_pending = new_rx_pending; |
| 5444 | } |
| 5445 | |
| 5446 | if (ring->tx_pending != new_tx_pending) { |
| 5447 | netdev_info(dev, "illegal Tx ring size value %d, round to %d\n", |
| 5448 | ring->tx_pending, new_tx_pending); |
| 5449 | ring->tx_pending = new_tx_pending; |
| 5450 | } |
| 5451 | |
| 5452 | return 0; |
| 5453 | } |
| 5454 | |
| 5455 | static void mvpp2_get_mac_address(struct mvpp2_port *port, unsigned char *addr) |
| 5456 | { |
| 5457 | u32 mac_addr_l, mac_addr_m, mac_addr_h; |
| 5458 | |
| 5459 | mac_addr_l = readl(port->base + MVPP2_GMAC_CTRL_1_REG); |
| 5460 | mac_addr_m = readl(port->priv->lms_base + MVPP2_SRC_ADDR_MIDDLE); |
| 5461 | mac_addr_h = readl(port->priv->lms_base + MVPP2_SRC_ADDR_HIGH); |
| 5462 | addr[0] = (mac_addr_h >> 24) & 0xFF; |
| 5463 | addr[1] = (mac_addr_h >> 16) & 0xFF; |
| 5464 | addr[2] = (mac_addr_h >> 8) & 0xFF; |
| 5465 | addr[3] = mac_addr_h & 0xFF; |
| 5466 | addr[4] = mac_addr_m & 0xFF; |
| 5467 | addr[5] = (mac_addr_l >> MVPP2_GMAC_SA_LOW_OFFS) & 0xFF; |
| 5468 | } |
| 5469 | |
| 5470 | static int mvpp2_phy_connect(struct mvpp2_port *port) |
| 5471 | { |
| 5472 | struct phy_device *phy_dev; |
| 5473 | |
| 5474 | phy_dev = of_phy_connect(port->dev, port->phy_node, mvpp2_link_event, 0, |
| 5475 | port->phy_interface); |
| 5476 | if (!phy_dev) { |
| 5477 | netdev_err(port->dev, "cannot connect to phy\n"); |
| 5478 | return -ENODEV; |
| 5479 | } |
| 5480 | phy_dev->supported &= PHY_GBIT_FEATURES; |
| 5481 | phy_dev->advertising = phy_dev->supported; |
| 5482 | |
| 5483 | port->phy_dev = phy_dev; |
| 5484 | port->link = 0; |
| 5485 | port->duplex = 0; |
| 5486 | port->speed = 0; |
| 5487 | |
| 5488 | return 0; |
| 5489 | } |
| 5490 | |
| 5491 | static void mvpp2_phy_disconnect(struct mvpp2_port *port) |
| 5492 | { |
| 5493 | phy_disconnect(port->phy_dev); |
| 5494 | port->phy_dev = NULL; |
| 5495 | } |
| 5496 | |
| 5497 | static int mvpp2_open(struct net_device *dev) |
| 5498 | { |
| 5499 | struct mvpp2_port *port = netdev_priv(dev); |
| 5500 | unsigned char mac_bcast[ETH_ALEN] = { |
| 5501 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 5502 | int err; |
| 5503 | |
| 5504 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, mac_bcast, true); |
| 5505 | if (err) { |
| 5506 | netdev_err(dev, "mvpp2_prs_mac_da_accept BC failed\n"); |
| 5507 | return err; |
| 5508 | } |
| 5509 | err = mvpp2_prs_mac_da_accept(port->priv, port->id, |
| 5510 | dev->dev_addr, true); |
| 5511 | if (err) { |
| 5512 | netdev_err(dev, "mvpp2_prs_mac_da_accept MC failed\n"); |
| 5513 | return err; |
| 5514 | } |
| 5515 | err = mvpp2_prs_tag_mode_set(port->priv, port->id, MVPP2_TAG_TYPE_MH); |
| 5516 | if (err) { |
| 5517 | netdev_err(dev, "mvpp2_prs_tag_mode_set failed\n"); |
| 5518 | return err; |
| 5519 | } |
| 5520 | err = mvpp2_prs_def_flow(port); |
| 5521 | if (err) { |
| 5522 | netdev_err(dev, "mvpp2_prs_def_flow failed\n"); |
| 5523 | return err; |
| 5524 | } |
| 5525 | |
| 5526 | /* Allocate the Rx/Tx queues */ |
| 5527 | err = mvpp2_setup_rxqs(port); |
| 5528 | if (err) { |
| 5529 | netdev_err(port->dev, "cannot allocate Rx queues\n"); |
| 5530 | return err; |
| 5531 | } |
| 5532 | |
| 5533 | err = mvpp2_setup_txqs(port); |
| 5534 | if (err) { |
| 5535 | netdev_err(port->dev, "cannot allocate Tx queues\n"); |
| 5536 | goto err_cleanup_rxqs; |
| 5537 | } |
| 5538 | |
| 5539 | err = request_irq(port->irq, mvpp2_isr, 0, dev->name, port); |
| 5540 | if (err) { |
| 5541 | netdev_err(port->dev, "cannot request IRQ %d\n", port->irq); |
| 5542 | goto err_cleanup_txqs; |
| 5543 | } |
| 5544 | |
| 5545 | /* In default link is down */ |
| 5546 | netif_carrier_off(port->dev); |
| 5547 | |
| 5548 | err = mvpp2_phy_connect(port); |
| 5549 | if (err < 0) |
| 5550 | goto err_free_irq; |
| 5551 | |
| 5552 | /* Unmask interrupts on all CPUs */ |
| 5553 | on_each_cpu(mvpp2_interrupts_unmask, port, 1); |
| 5554 | |
| 5555 | mvpp2_start_dev(port); |
| 5556 | |
| 5557 | return 0; |
| 5558 | |
| 5559 | err_free_irq: |
| 5560 | free_irq(port->irq, port); |
| 5561 | err_cleanup_txqs: |
| 5562 | mvpp2_cleanup_txqs(port); |
| 5563 | err_cleanup_rxqs: |
| 5564 | mvpp2_cleanup_rxqs(port); |
| 5565 | return err; |
| 5566 | } |
| 5567 | |
| 5568 | static int mvpp2_stop(struct net_device *dev) |
| 5569 | { |
| 5570 | struct mvpp2_port *port = netdev_priv(dev); |
| 5571 | |
| 5572 | mvpp2_stop_dev(port); |
| 5573 | mvpp2_phy_disconnect(port); |
| 5574 | |
| 5575 | /* Mask interrupts on all CPUs */ |
| 5576 | on_each_cpu(mvpp2_interrupts_mask, port, 1); |
| 5577 | |
| 5578 | free_irq(port->irq, port); |
| 5579 | mvpp2_cleanup_rxqs(port); |
| 5580 | mvpp2_cleanup_txqs(port); |
| 5581 | |
| 5582 | return 0; |
| 5583 | } |
| 5584 | |
| 5585 | static void mvpp2_set_rx_mode(struct net_device *dev) |
| 5586 | { |
| 5587 | struct mvpp2_port *port = netdev_priv(dev); |
| 5588 | struct mvpp2 *priv = port->priv; |
| 5589 | struct netdev_hw_addr *ha; |
| 5590 | int id = port->id; |
| 5591 | bool allmulti = dev->flags & IFF_ALLMULTI; |
| 5592 | |
| 5593 | mvpp2_prs_mac_promisc_set(priv, id, dev->flags & IFF_PROMISC); |
| 5594 | mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_ALL, allmulti); |
| 5595 | mvpp2_prs_mac_multi_set(priv, id, MVPP2_PE_MAC_MC_IP6, allmulti); |
| 5596 | |
| 5597 | /* Remove all port->id's mcast enries */ |
| 5598 | mvpp2_prs_mcast_del_all(priv, id); |
| 5599 | |
| 5600 | if (allmulti && !netdev_mc_empty(dev)) { |
| 5601 | netdev_for_each_mc_addr(ha, dev) |
| 5602 | mvpp2_prs_mac_da_accept(priv, id, ha->addr, true); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | static int mvpp2_set_mac_address(struct net_device *dev, void *p) |
| 5607 | { |
| 5608 | struct mvpp2_port *port = netdev_priv(dev); |
| 5609 | const struct sockaddr *addr = p; |
| 5610 | int err; |
| 5611 | |
| 5612 | if (!is_valid_ether_addr(addr->sa_data)) { |
| 5613 | err = -EADDRNOTAVAIL; |
| 5614 | goto error; |
| 5615 | } |
| 5616 | |
| 5617 | if (!netif_running(dev)) { |
| 5618 | err = mvpp2_prs_update_mac_da(dev, addr->sa_data); |
| 5619 | if (!err) |
| 5620 | return 0; |
| 5621 | /* Reconfigure parser to accept the original MAC address */ |
| 5622 | err = mvpp2_prs_update_mac_da(dev, dev->dev_addr); |
| 5623 | if (err) |
| 5624 | goto error; |
| 5625 | } |
| 5626 | |
| 5627 | mvpp2_stop_dev(port); |
| 5628 | |
| 5629 | err = mvpp2_prs_update_mac_da(dev, addr->sa_data); |
| 5630 | if (!err) |
| 5631 | goto out_start; |
| 5632 | |
| 5633 | /* Reconfigure parser accept the original MAC address */ |
| 5634 | err = mvpp2_prs_update_mac_da(dev, dev->dev_addr); |
| 5635 | if (err) |
| 5636 | goto error; |
| 5637 | out_start: |
| 5638 | mvpp2_start_dev(port); |
| 5639 | mvpp2_egress_enable(port); |
| 5640 | mvpp2_ingress_enable(port); |
| 5641 | return 0; |
| 5642 | |
| 5643 | error: |
| 5644 | netdev_err(dev, "fail to change MAC address\n"); |
| 5645 | return err; |
| 5646 | } |
| 5647 | |
| 5648 | static int mvpp2_change_mtu(struct net_device *dev, int mtu) |
| 5649 | { |
| 5650 | struct mvpp2_port *port = netdev_priv(dev); |
| 5651 | int err; |
| 5652 | |
| 5653 | mtu = mvpp2_check_mtu_valid(dev, mtu); |
| 5654 | if (mtu < 0) { |
| 5655 | err = mtu; |
| 5656 | goto error; |
| 5657 | } |
| 5658 | |
| 5659 | if (!netif_running(dev)) { |
| 5660 | err = mvpp2_bm_update_mtu(dev, mtu); |
| 5661 | if (!err) { |
| 5662 | port->pkt_size = MVPP2_RX_PKT_SIZE(mtu); |
| 5663 | return 0; |
| 5664 | } |
| 5665 | |
| 5666 | /* Reconfigure BM to the original MTU */ |
| 5667 | err = mvpp2_bm_update_mtu(dev, dev->mtu); |
| 5668 | if (err) |
| 5669 | goto error; |
| 5670 | } |
| 5671 | |
| 5672 | mvpp2_stop_dev(port); |
| 5673 | |
| 5674 | err = mvpp2_bm_update_mtu(dev, mtu); |
| 5675 | if (!err) { |
| 5676 | port->pkt_size = MVPP2_RX_PKT_SIZE(mtu); |
| 5677 | goto out_start; |
| 5678 | } |
| 5679 | |
| 5680 | /* Reconfigure BM to the original MTU */ |
| 5681 | err = mvpp2_bm_update_mtu(dev, dev->mtu); |
| 5682 | if (err) |
| 5683 | goto error; |
| 5684 | |
| 5685 | out_start: |
| 5686 | mvpp2_start_dev(port); |
| 5687 | mvpp2_egress_enable(port); |
| 5688 | mvpp2_ingress_enable(port); |
| 5689 | |
| 5690 | return 0; |
| 5691 | |
| 5692 | error: |
| 5693 | netdev_err(dev, "fail to change MTU\n"); |
| 5694 | return err; |
| 5695 | } |
| 5696 | |
| 5697 | static struct rtnl_link_stats64 * |
| 5698 | mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
| 5699 | { |
| 5700 | struct mvpp2_port *port = netdev_priv(dev); |
| 5701 | unsigned int start; |
| 5702 | int cpu; |
| 5703 | |
| 5704 | for_each_possible_cpu(cpu) { |
| 5705 | struct mvpp2_pcpu_stats *cpu_stats; |
| 5706 | u64 rx_packets; |
| 5707 | u64 rx_bytes; |
| 5708 | u64 tx_packets; |
| 5709 | u64 tx_bytes; |
| 5710 | |
| 5711 | cpu_stats = per_cpu_ptr(port->stats, cpu); |
| 5712 | do { |
| 5713 | start = u64_stats_fetch_begin_irq(&cpu_stats->syncp); |
| 5714 | rx_packets = cpu_stats->rx_packets; |
| 5715 | rx_bytes = cpu_stats->rx_bytes; |
| 5716 | tx_packets = cpu_stats->tx_packets; |
| 5717 | tx_bytes = cpu_stats->tx_bytes; |
| 5718 | } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); |
| 5719 | |
| 5720 | stats->rx_packets += rx_packets; |
| 5721 | stats->rx_bytes += rx_bytes; |
| 5722 | stats->tx_packets += tx_packets; |
| 5723 | stats->tx_bytes += tx_bytes; |
| 5724 | } |
| 5725 | |
| 5726 | stats->rx_errors = dev->stats.rx_errors; |
| 5727 | stats->rx_dropped = dev->stats.rx_dropped; |
| 5728 | stats->tx_dropped = dev->stats.tx_dropped; |
| 5729 | |
| 5730 | return stats; |
| 5731 | } |
| 5732 | |
Thomas Petazzoni | bd695a5 | 2014-07-27 23:21:36 +0200 | [diff] [blame] | 5733 | static int mvpp2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 5734 | { |
| 5735 | struct mvpp2_port *port = netdev_priv(dev); |
| 5736 | int ret; |
| 5737 | |
| 5738 | if (!port->phy_dev) |
| 5739 | return -ENOTSUPP; |
| 5740 | |
| 5741 | ret = phy_mii_ioctl(port->phy_dev, ifr, cmd); |
| 5742 | if (!ret) |
| 5743 | mvpp2_link_event(dev); |
| 5744 | |
| 5745 | return ret; |
| 5746 | } |
| 5747 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5748 | /* Ethtool methods */ |
| 5749 | |
| 5750 | /* Get settings (phy address, speed) for ethtools */ |
| 5751 | static int mvpp2_ethtool_get_settings(struct net_device *dev, |
| 5752 | struct ethtool_cmd *cmd) |
| 5753 | { |
| 5754 | struct mvpp2_port *port = netdev_priv(dev); |
| 5755 | |
| 5756 | if (!port->phy_dev) |
| 5757 | return -ENODEV; |
| 5758 | return phy_ethtool_gset(port->phy_dev, cmd); |
| 5759 | } |
| 5760 | |
| 5761 | /* Set settings (phy address, speed) for ethtools */ |
| 5762 | static int mvpp2_ethtool_set_settings(struct net_device *dev, |
| 5763 | struct ethtool_cmd *cmd) |
| 5764 | { |
| 5765 | struct mvpp2_port *port = netdev_priv(dev); |
| 5766 | |
| 5767 | if (!port->phy_dev) |
| 5768 | return -ENODEV; |
| 5769 | return phy_ethtool_sset(port->phy_dev, cmd); |
| 5770 | } |
| 5771 | |
| 5772 | /* Set interrupt coalescing for ethtools */ |
| 5773 | static int mvpp2_ethtool_set_coalesce(struct net_device *dev, |
| 5774 | struct ethtool_coalesce *c) |
| 5775 | { |
| 5776 | struct mvpp2_port *port = netdev_priv(dev); |
| 5777 | int queue; |
| 5778 | |
| 5779 | for (queue = 0; queue < rxq_number; queue++) { |
| 5780 | struct mvpp2_rx_queue *rxq = port->rxqs[queue]; |
| 5781 | |
| 5782 | rxq->time_coal = c->rx_coalesce_usecs; |
| 5783 | rxq->pkts_coal = c->rx_max_coalesced_frames; |
| 5784 | mvpp2_rx_pkts_coal_set(port, rxq, rxq->pkts_coal); |
| 5785 | mvpp2_rx_time_coal_set(port, rxq, rxq->time_coal); |
| 5786 | } |
| 5787 | |
| 5788 | for (queue = 0; queue < txq_number; queue++) { |
| 5789 | struct mvpp2_tx_queue *txq = port->txqs[queue]; |
| 5790 | |
| 5791 | txq->done_pkts_coal = c->tx_max_coalesced_frames; |
| 5792 | } |
| 5793 | |
| 5794 | on_each_cpu(mvpp2_tx_done_pkts_coal_set, port, 1); |
| 5795 | return 0; |
| 5796 | } |
| 5797 | |
| 5798 | /* get coalescing for ethtools */ |
| 5799 | static int mvpp2_ethtool_get_coalesce(struct net_device *dev, |
| 5800 | struct ethtool_coalesce *c) |
| 5801 | { |
| 5802 | struct mvpp2_port *port = netdev_priv(dev); |
| 5803 | |
| 5804 | c->rx_coalesce_usecs = port->rxqs[0]->time_coal; |
| 5805 | c->rx_max_coalesced_frames = port->rxqs[0]->pkts_coal; |
| 5806 | c->tx_max_coalesced_frames = port->txqs[0]->done_pkts_coal; |
| 5807 | return 0; |
| 5808 | } |
| 5809 | |
| 5810 | static void mvpp2_ethtool_get_drvinfo(struct net_device *dev, |
| 5811 | struct ethtool_drvinfo *drvinfo) |
| 5812 | { |
| 5813 | strlcpy(drvinfo->driver, MVPP2_DRIVER_NAME, |
| 5814 | sizeof(drvinfo->driver)); |
| 5815 | strlcpy(drvinfo->version, MVPP2_DRIVER_VERSION, |
| 5816 | sizeof(drvinfo->version)); |
| 5817 | strlcpy(drvinfo->bus_info, dev_name(&dev->dev), |
| 5818 | sizeof(drvinfo->bus_info)); |
| 5819 | } |
| 5820 | |
| 5821 | static void mvpp2_ethtool_get_ringparam(struct net_device *dev, |
| 5822 | struct ethtool_ringparam *ring) |
| 5823 | { |
| 5824 | struct mvpp2_port *port = netdev_priv(dev); |
| 5825 | |
| 5826 | ring->rx_max_pending = MVPP2_MAX_RXD; |
| 5827 | ring->tx_max_pending = MVPP2_MAX_TXD; |
| 5828 | ring->rx_pending = port->rx_ring_size; |
| 5829 | ring->tx_pending = port->tx_ring_size; |
| 5830 | } |
| 5831 | |
| 5832 | static int mvpp2_ethtool_set_ringparam(struct net_device *dev, |
| 5833 | struct ethtool_ringparam *ring) |
| 5834 | { |
| 5835 | struct mvpp2_port *port = netdev_priv(dev); |
| 5836 | u16 prev_rx_ring_size = port->rx_ring_size; |
| 5837 | u16 prev_tx_ring_size = port->tx_ring_size; |
| 5838 | int err; |
| 5839 | |
| 5840 | err = mvpp2_check_ringparam_valid(dev, ring); |
| 5841 | if (err) |
| 5842 | return err; |
| 5843 | |
| 5844 | if (!netif_running(dev)) { |
| 5845 | port->rx_ring_size = ring->rx_pending; |
| 5846 | port->tx_ring_size = ring->tx_pending; |
| 5847 | return 0; |
| 5848 | } |
| 5849 | |
| 5850 | /* The interface is running, so we have to force a |
| 5851 | * reallocation of the queues |
| 5852 | */ |
| 5853 | mvpp2_stop_dev(port); |
| 5854 | mvpp2_cleanup_rxqs(port); |
| 5855 | mvpp2_cleanup_txqs(port); |
| 5856 | |
| 5857 | port->rx_ring_size = ring->rx_pending; |
| 5858 | port->tx_ring_size = ring->tx_pending; |
| 5859 | |
| 5860 | err = mvpp2_setup_rxqs(port); |
| 5861 | if (err) { |
| 5862 | /* Reallocate Rx queues with the original ring size */ |
| 5863 | port->rx_ring_size = prev_rx_ring_size; |
| 5864 | ring->rx_pending = prev_rx_ring_size; |
| 5865 | err = mvpp2_setup_rxqs(port); |
| 5866 | if (err) |
| 5867 | goto err_out; |
| 5868 | } |
| 5869 | err = mvpp2_setup_txqs(port); |
| 5870 | if (err) { |
| 5871 | /* Reallocate Tx queues with the original ring size */ |
| 5872 | port->tx_ring_size = prev_tx_ring_size; |
| 5873 | ring->tx_pending = prev_tx_ring_size; |
| 5874 | err = mvpp2_setup_txqs(port); |
| 5875 | if (err) |
| 5876 | goto err_clean_rxqs; |
| 5877 | } |
| 5878 | |
| 5879 | mvpp2_start_dev(port); |
| 5880 | mvpp2_egress_enable(port); |
| 5881 | mvpp2_ingress_enable(port); |
| 5882 | |
| 5883 | return 0; |
| 5884 | |
| 5885 | err_clean_rxqs: |
| 5886 | mvpp2_cleanup_rxqs(port); |
| 5887 | err_out: |
| 5888 | netdev_err(dev, "fail to change ring parameters"); |
| 5889 | return err; |
| 5890 | } |
| 5891 | |
| 5892 | /* Device ops */ |
| 5893 | |
| 5894 | static const struct net_device_ops mvpp2_netdev_ops = { |
| 5895 | .ndo_open = mvpp2_open, |
| 5896 | .ndo_stop = mvpp2_stop, |
| 5897 | .ndo_start_xmit = mvpp2_tx, |
| 5898 | .ndo_set_rx_mode = mvpp2_set_rx_mode, |
| 5899 | .ndo_set_mac_address = mvpp2_set_mac_address, |
| 5900 | .ndo_change_mtu = mvpp2_change_mtu, |
| 5901 | .ndo_get_stats64 = mvpp2_get_stats64, |
Thomas Petazzoni | bd695a5 | 2014-07-27 23:21:36 +0200 | [diff] [blame] | 5902 | .ndo_do_ioctl = mvpp2_ioctl, |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5903 | }; |
| 5904 | |
| 5905 | static const struct ethtool_ops mvpp2_eth_tool_ops = { |
| 5906 | .get_link = ethtool_op_get_link, |
| 5907 | .get_settings = mvpp2_ethtool_get_settings, |
| 5908 | .set_settings = mvpp2_ethtool_set_settings, |
| 5909 | .set_coalesce = mvpp2_ethtool_set_coalesce, |
| 5910 | .get_coalesce = mvpp2_ethtool_get_coalesce, |
| 5911 | .get_drvinfo = mvpp2_ethtool_get_drvinfo, |
| 5912 | .get_ringparam = mvpp2_ethtool_get_ringparam, |
| 5913 | .set_ringparam = mvpp2_ethtool_set_ringparam, |
| 5914 | }; |
| 5915 | |
| 5916 | /* Driver initialization */ |
| 5917 | |
| 5918 | static void mvpp2_port_power_up(struct mvpp2_port *port) |
| 5919 | { |
| 5920 | mvpp2_port_mii_set(port); |
| 5921 | mvpp2_port_periodic_xon_disable(port); |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 5922 | mvpp2_port_fc_adv_enable(port); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 5923 | mvpp2_port_reset(port); |
| 5924 | } |
| 5925 | |
| 5926 | /* Initialize port HW */ |
| 5927 | static int mvpp2_port_init(struct mvpp2_port *port) |
| 5928 | { |
| 5929 | struct device *dev = port->dev->dev.parent; |
| 5930 | struct mvpp2 *priv = port->priv; |
| 5931 | struct mvpp2_txq_pcpu *txq_pcpu; |
| 5932 | int queue, cpu, err; |
| 5933 | |
| 5934 | if (port->first_rxq + rxq_number > MVPP2_RXQ_TOTAL_NUM) |
| 5935 | return -EINVAL; |
| 5936 | |
| 5937 | /* Disable port */ |
| 5938 | mvpp2_egress_disable(port); |
| 5939 | mvpp2_port_disable(port); |
| 5940 | |
| 5941 | port->txqs = devm_kcalloc(dev, txq_number, sizeof(*port->txqs), |
| 5942 | GFP_KERNEL); |
| 5943 | if (!port->txqs) |
| 5944 | return -ENOMEM; |
| 5945 | |
| 5946 | /* Associate physical Tx queues to this port and initialize. |
| 5947 | * The mapping is predefined. |
| 5948 | */ |
| 5949 | for (queue = 0; queue < txq_number; queue++) { |
| 5950 | int queue_phy_id = mvpp2_txq_phys(port->id, queue); |
| 5951 | struct mvpp2_tx_queue *txq; |
| 5952 | |
| 5953 | txq = devm_kzalloc(dev, sizeof(*txq), GFP_KERNEL); |
| 5954 | if (!txq) |
| 5955 | return -ENOMEM; |
| 5956 | |
| 5957 | txq->pcpu = alloc_percpu(struct mvpp2_txq_pcpu); |
| 5958 | if (!txq->pcpu) { |
| 5959 | err = -ENOMEM; |
| 5960 | goto err_free_percpu; |
| 5961 | } |
| 5962 | |
| 5963 | txq->id = queue_phy_id; |
| 5964 | txq->log_id = queue; |
| 5965 | txq->done_pkts_coal = MVPP2_TXDONE_COAL_PKTS_THRESH; |
| 5966 | for_each_present_cpu(cpu) { |
| 5967 | txq_pcpu = per_cpu_ptr(txq->pcpu, cpu); |
| 5968 | txq_pcpu->cpu = cpu; |
| 5969 | } |
| 5970 | |
| 5971 | port->txqs[queue] = txq; |
| 5972 | } |
| 5973 | |
| 5974 | port->rxqs = devm_kcalloc(dev, rxq_number, sizeof(*port->rxqs), |
| 5975 | GFP_KERNEL); |
| 5976 | if (!port->rxqs) { |
| 5977 | err = -ENOMEM; |
| 5978 | goto err_free_percpu; |
| 5979 | } |
| 5980 | |
| 5981 | /* Allocate and initialize Rx queue for this port */ |
| 5982 | for (queue = 0; queue < rxq_number; queue++) { |
| 5983 | struct mvpp2_rx_queue *rxq; |
| 5984 | |
| 5985 | /* Map physical Rx queue to port's logical Rx queue */ |
| 5986 | rxq = devm_kzalloc(dev, sizeof(*rxq), GFP_KERNEL); |
| 5987 | if (!rxq) |
| 5988 | goto err_free_percpu; |
| 5989 | /* Map this Rx queue to a physical queue */ |
| 5990 | rxq->id = port->first_rxq + queue; |
| 5991 | rxq->port = port->id; |
| 5992 | rxq->logic_rxq = queue; |
| 5993 | |
| 5994 | port->rxqs[queue] = rxq; |
| 5995 | } |
| 5996 | |
| 5997 | /* Configure Rx queue group interrupt for this port */ |
| 5998 | mvpp2_write(priv, MVPP2_ISR_RXQ_GROUP_REG(port->id), rxq_number); |
| 5999 | |
| 6000 | /* Create Rx descriptor rings */ |
| 6001 | for (queue = 0; queue < rxq_number; queue++) { |
| 6002 | struct mvpp2_rx_queue *rxq = port->rxqs[queue]; |
| 6003 | |
| 6004 | rxq->size = port->rx_ring_size; |
| 6005 | rxq->pkts_coal = MVPP2_RX_COAL_PKTS; |
| 6006 | rxq->time_coal = MVPP2_RX_COAL_USEC; |
| 6007 | } |
| 6008 | |
| 6009 | mvpp2_ingress_disable(port); |
| 6010 | |
| 6011 | /* Port default configuration */ |
| 6012 | mvpp2_defaults_set(port); |
| 6013 | |
| 6014 | /* Port's classifier configuration */ |
| 6015 | mvpp2_cls_oversize_rxq_set(port); |
| 6016 | mvpp2_cls_port_config(port); |
| 6017 | |
| 6018 | /* Provide an initial Rx packet size */ |
| 6019 | port->pkt_size = MVPP2_RX_PKT_SIZE(port->dev->mtu); |
| 6020 | |
| 6021 | /* Initialize pools for swf */ |
| 6022 | err = mvpp2_swf_bm_pool_init(port); |
| 6023 | if (err) |
| 6024 | goto err_free_percpu; |
| 6025 | |
| 6026 | return 0; |
| 6027 | |
| 6028 | err_free_percpu: |
| 6029 | for (queue = 0; queue < txq_number; queue++) { |
| 6030 | if (!port->txqs[queue]) |
| 6031 | continue; |
| 6032 | free_percpu(port->txqs[queue]->pcpu); |
| 6033 | } |
| 6034 | return err; |
| 6035 | } |
| 6036 | |
| 6037 | /* Ports initialization */ |
| 6038 | static int mvpp2_port_probe(struct platform_device *pdev, |
| 6039 | struct device_node *port_node, |
| 6040 | struct mvpp2 *priv, |
| 6041 | int *next_first_rxq) |
| 6042 | { |
| 6043 | struct device_node *phy_node; |
| 6044 | struct mvpp2_port *port; |
| 6045 | struct net_device *dev; |
| 6046 | struct resource *res; |
| 6047 | const char *dt_mac_addr; |
| 6048 | const char *mac_from; |
| 6049 | char hw_mac_addr[ETH_ALEN]; |
| 6050 | u32 id; |
| 6051 | int features; |
| 6052 | int phy_mode; |
| 6053 | int priv_common_regs_num = 2; |
| 6054 | int err, i; |
| 6055 | |
| 6056 | dev = alloc_etherdev_mqs(sizeof(struct mvpp2_port), txq_number, |
| 6057 | rxq_number); |
| 6058 | if (!dev) |
| 6059 | return -ENOMEM; |
| 6060 | |
| 6061 | phy_node = of_parse_phandle(port_node, "phy", 0); |
| 6062 | if (!phy_node) { |
| 6063 | dev_err(&pdev->dev, "missing phy\n"); |
| 6064 | err = -ENODEV; |
| 6065 | goto err_free_netdev; |
| 6066 | } |
| 6067 | |
| 6068 | phy_mode = of_get_phy_mode(port_node); |
| 6069 | if (phy_mode < 0) { |
| 6070 | dev_err(&pdev->dev, "incorrect phy mode\n"); |
| 6071 | err = phy_mode; |
| 6072 | goto err_free_netdev; |
| 6073 | } |
| 6074 | |
| 6075 | if (of_property_read_u32(port_node, "port-id", &id)) { |
| 6076 | err = -EINVAL; |
| 6077 | dev_err(&pdev->dev, "missing port-id value\n"); |
| 6078 | goto err_free_netdev; |
| 6079 | } |
| 6080 | |
| 6081 | dev->tx_queue_len = MVPP2_MAX_TXD; |
| 6082 | dev->watchdog_timeo = 5 * HZ; |
| 6083 | dev->netdev_ops = &mvpp2_netdev_ops; |
| 6084 | dev->ethtool_ops = &mvpp2_eth_tool_ops; |
| 6085 | |
| 6086 | port = netdev_priv(dev); |
| 6087 | |
| 6088 | port->irq = irq_of_parse_and_map(port_node, 0); |
| 6089 | if (port->irq <= 0) { |
| 6090 | err = -EINVAL; |
| 6091 | goto err_free_netdev; |
| 6092 | } |
| 6093 | |
| 6094 | if (of_property_read_bool(port_node, "marvell,loopback")) |
| 6095 | port->flags |= MVPP2_F_LOOPBACK; |
| 6096 | |
| 6097 | port->priv = priv; |
| 6098 | port->id = id; |
| 6099 | port->first_rxq = *next_first_rxq; |
| 6100 | port->phy_node = phy_node; |
| 6101 | port->phy_interface = phy_mode; |
| 6102 | |
| 6103 | res = platform_get_resource(pdev, IORESOURCE_MEM, |
| 6104 | priv_common_regs_num + id); |
| 6105 | port->base = devm_ioremap_resource(&pdev->dev, res); |
| 6106 | if (IS_ERR(port->base)) { |
| 6107 | err = PTR_ERR(port->base); |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 6108 | goto err_free_irq; |
| 6109 | } |
| 6110 | |
| 6111 | /* Alloc per-cpu stats */ |
| 6112 | port->stats = netdev_alloc_pcpu_stats(struct mvpp2_pcpu_stats); |
| 6113 | if (!port->stats) { |
| 6114 | err = -ENOMEM; |
| 6115 | goto err_free_irq; |
| 6116 | } |
| 6117 | |
| 6118 | dt_mac_addr = of_get_mac_address(port_node); |
| 6119 | if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) { |
| 6120 | mac_from = "device tree"; |
| 6121 | ether_addr_copy(dev->dev_addr, dt_mac_addr); |
| 6122 | } else { |
| 6123 | mvpp2_get_mac_address(port, hw_mac_addr); |
| 6124 | if (is_valid_ether_addr(hw_mac_addr)) { |
| 6125 | mac_from = "hardware"; |
| 6126 | ether_addr_copy(dev->dev_addr, hw_mac_addr); |
| 6127 | } else { |
| 6128 | mac_from = "random"; |
| 6129 | eth_hw_addr_random(dev); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | port->tx_ring_size = MVPP2_MAX_TXD; |
| 6134 | port->rx_ring_size = MVPP2_MAX_RXD; |
| 6135 | port->dev = dev; |
| 6136 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 6137 | |
| 6138 | err = mvpp2_port_init(port); |
| 6139 | if (err < 0) { |
| 6140 | dev_err(&pdev->dev, "failed to init port %d\n", id); |
| 6141 | goto err_free_stats; |
| 6142 | } |
| 6143 | mvpp2_port_power_up(port); |
| 6144 | |
| 6145 | netif_napi_add(dev, &port->napi, mvpp2_poll, NAPI_POLL_WEIGHT); |
| 6146 | features = NETIF_F_SG | NETIF_F_IP_CSUM; |
| 6147 | dev->features = features | NETIF_F_RXCSUM; |
| 6148 | dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO; |
| 6149 | dev->vlan_features |= features; |
| 6150 | |
| 6151 | err = register_netdev(dev); |
| 6152 | if (err < 0) { |
| 6153 | dev_err(&pdev->dev, "failed to register netdev\n"); |
| 6154 | goto err_free_txq_pcpu; |
| 6155 | } |
| 6156 | netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr); |
| 6157 | |
| 6158 | /* Increment the first Rx queue number to be used by the next port */ |
| 6159 | *next_first_rxq += rxq_number; |
| 6160 | priv->port_list[id] = port; |
| 6161 | return 0; |
| 6162 | |
| 6163 | err_free_txq_pcpu: |
| 6164 | for (i = 0; i < txq_number; i++) |
| 6165 | free_percpu(port->txqs[i]->pcpu); |
| 6166 | err_free_stats: |
| 6167 | free_percpu(port->stats); |
| 6168 | err_free_irq: |
| 6169 | irq_dispose_mapping(port->irq); |
| 6170 | err_free_netdev: |
| 6171 | free_netdev(dev); |
| 6172 | return err; |
| 6173 | } |
| 6174 | |
| 6175 | /* Ports removal routine */ |
| 6176 | static void mvpp2_port_remove(struct mvpp2_port *port) |
| 6177 | { |
| 6178 | int i; |
| 6179 | |
| 6180 | unregister_netdev(port->dev); |
| 6181 | free_percpu(port->stats); |
| 6182 | for (i = 0; i < txq_number; i++) |
| 6183 | free_percpu(port->txqs[i]->pcpu); |
| 6184 | irq_dispose_mapping(port->irq); |
| 6185 | free_netdev(port->dev); |
| 6186 | } |
| 6187 | |
| 6188 | /* Initialize decoding windows */ |
| 6189 | static void mvpp2_conf_mbus_windows(const struct mbus_dram_target_info *dram, |
| 6190 | struct mvpp2 *priv) |
| 6191 | { |
| 6192 | u32 win_enable; |
| 6193 | int i; |
| 6194 | |
| 6195 | for (i = 0; i < 6; i++) { |
| 6196 | mvpp2_write(priv, MVPP2_WIN_BASE(i), 0); |
| 6197 | mvpp2_write(priv, MVPP2_WIN_SIZE(i), 0); |
| 6198 | |
| 6199 | if (i < 4) |
| 6200 | mvpp2_write(priv, MVPP2_WIN_REMAP(i), 0); |
| 6201 | } |
| 6202 | |
| 6203 | win_enable = 0; |
| 6204 | |
| 6205 | for (i = 0; i < dram->num_cs; i++) { |
| 6206 | const struct mbus_dram_window *cs = dram->cs + i; |
| 6207 | |
| 6208 | mvpp2_write(priv, MVPP2_WIN_BASE(i), |
| 6209 | (cs->base & 0xffff0000) | (cs->mbus_attr << 8) | |
| 6210 | dram->mbus_dram_target_id); |
| 6211 | |
| 6212 | mvpp2_write(priv, MVPP2_WIN_SIZE(i), |
| 6213 | (cs->size - 1) & 0xffff0000); |
| 6214 | |
| 6215 | win_enable |= (1 << i); |
| 6216 | } |
| 6217 | |
| 6218 | mvpp2_write(priv, MVPP2_BASE_ADDR_ENABLE, win_enable); |
| 6219 | } |
| 6220 | |
| 6221 | /* Initialize Rx FIFO's */ |
| 6222 | static void mvpp2_rx_fifo_init(struct mvpp2 *priv) |
| 6223 | { |
| 6224 | int port; |
| 6225 | |
| 6226 | for (port = 0; port < MVPP2_MAX_PORTS; port++) { |
| 6227 | mvpp2_write(priv, MVPP2_RX_DATA_FIFO_SIZE_REG(port), |
| 6228 | MVPP2_RX_FIFO_PORT_DATA_SIZE); |
| 6229 | mvpp2_write(priv, MVPP2_RX_ATTR_FIFO_SIZE_REG(port), |
| 6230 | MVPP2_RX_FIFO_PORT_ATTR_SIZE); |
| 6231 | } |
| 6232 | |
| 6233 | mvpp2_write(priv, MVPP2_RX_MIN_PKT_SIZE_REG, |
| 6234 | MVPP2_RX_FIFO_PORT_MIN_PKT); |
| 6235 | mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1); |
| 6236 | } |
| 6237 | |
| 6238 | /* Initialize network controller common part HW */ |
| 6239 | static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) |
| 6240 | { |
| 6241 | const struct mbus_dram_target_info *dram_target_info; |
| 6242 | int err, i; |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 6243 | u32 val; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 6244 | |
| 6245 | /* Checks for hardware constraints */ |
| 6246 | if (rxq_number % 4 || (rxq_number > MVPP2_MAX_RXQ) || |
| 6247 | (txq_number > MVPP2_MAX_TXQ)) { |
| 6248 | dev_err(&pdev->dev, "invalid queue size parameter\n"); |
| 6249 | return -EINVAL; |
| 6250 | } |
| 6251 | |
| 6252 | /* MBUS windows configuration */ |
| 6253 | dram_target_info = mv_mbus_dram_info(); |
| 6254 | if (dram_target_info) |
| 6255 | mvpp2_conf_mbus_windows(dram_target_info, priv); |
| 6256 | |
Marcin Wojtas | 08a2375 | 2014-07-21 13:48:12 -0300 | [diff] [blame] | 6257 | /* Disable HW PHY polling */ |
| 6258 | val = readl(priv->lms_base + MVPP2_PHY_AN_CFG0_REG); |
| 6259 | val |= MVPP2_PHY_AN_STOP_SMI0_MASK; |
| 6260 | writel(val, priv->lms_base + MVPP2_PHY_AN_CFG0_REG); |
| 6261 | |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 6262 | /* Allocate and initialize aggregated TXQs */ |
| 6263 | priv->aggr_txqs = devm_kcalloc(&pdev->dev, num_present_cpus(), |
| 6264 | sizeof(struct mvpp2_tx_queue), |
| 6265 | GFP_KERNEL); |
| 6266 | if (!priv->aggr_txqs) |
| 6267 | return -ENOMEM; |
| 6268 | |
| 6269 | for_each_present_cpu(i) { |
| 6270 | priv->aggr_txqs[i].id = i; |
| 6271 | priv->aggr_txqs[i].size = MVPP2_AGGR_TXQ_SIZE; |
| 6272 | err = mvpp2_aggr_txq_init(pdev, &priv->aggr_txqs[i], |
| 6273 | MVPP2_AGGR_TXQ_SIZE, i, priv); |
| 6274 | if (err < 0) |
| 6275 | return err; |
| 6276 | } |
| 6277 | |
| 6278 | /* Rx Fifo Init */ |
| 6279 | mvpp2_rx_fifo_init(priv); |
| 6280 | |
| 6281 | /* Reset Rx queue group interrupt configuration */ |
| 6282 | for (i = 0; i < MVPP2_MAX_PORTS; i++) |
| 6283 | mvpp2_write(priv, MVPP2_ISR_RXQ_GROUP_REG(i), rxq_number); |
| 6284 | |
| 6285 | writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT, |
| 6286 | priv->lms_base + MVPP2_MNG_EXTENDED_GLOBAL_CTRL_REG); |
| 6287 | |
| 6288 | /* Allow cache snoop when transmiting packets */ |
| 6289 | mvpp2_write(priv, MVPP2_TX_SNOOP_REG, 0x1); |
| 6290 | |
| 6291 | /* Buffer Manager initialization */ |
| 6292 | err = mvpp2_bm_init(pdev, priv); |
| 6293 | if (err < 0) |
| 6294 | return err; |
| 6295 | |
| 6296 | /* Parser default initialization */ |
| 6297 | err = mvpp2_prs_default_init(pdev, priv); |
| 6298 | if (err < 0) |
| 6299 | return err; |
| 6300 | |
| 6301 | /* Classifier default initialization */ |
| 6302 | mvpp2_cls_init(priv); |
| 6303 | |
| 6304 | return 0; |
| 6305 | } |
| 6306 | |
| 6307 | static int mvpp2_probe(struct platform_device *pdev) |
| 6308 | { |
| 6309 | struct device_node *dn = pdev->dev.of_node; |
| 6310 | struct device_node *port_node; |
| 6311 | struct mvpp2 *priv; |
| 6312 | struct resource *res; |
| 6313 | int port_count, first_rxq; |
| 6314 | int err; |
| 6315 | |
| 6316 | priv = devm_kzalloc(&pdev->dev, sizeof(struct mvpp2), GFP_KERNEL); |
| 6317 | if (!priv) |
| 6318 | return -ENOMEM; |
| 6319 | |
| 6320 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 6321 | priv->base = devm_ioremap_resource(&pdev->dev, res); |
| 6322 | if (IS_ERR(priv->base)) |
| 6323 | return PTR_ERR(priv->base); |
| 6324 | |
| 6325 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 6326 | priv->lms_base = devm_ioremap_resource(&pdev->dev, res); |
| 6327 | if (IS_ERR(priv->lms_base)) |
| 6328 | return PTR_ERR(priv->lms_base); |
| 6329 | |
| 6330 | priv->pp_clk = devm_clk_get(&pdev->dev, "pp_clk"); |
| 6331 | if (IS_ERR(priv->pp_clk)) |
| 6332 | return PTR_ERR(priv->pp_clk); |
| 6333 | err = clk_prepare_enable(priv->pp_clk); |
| 6334 | if (err < 0) |
| 6335 | return err; |
| 6336 | |
| 6337 | priv->gop_clk = devm_clk_get(&pdev->dev, "gop_clk"); |
| 6338 | if (IS_ERR(priv->gop_clk)) { |
| 6339 | err = PTR_ERR(priv->gop_clk); |
| 6340 | goto err_pp_clk; |
| 6341 | } |
| 6342 | err = clk_prepare_enable(priv->gop_clk); |
| 6343 | if (err < 0) |
| 6344 | goto err_pp_clk; |
| 6345 | |
| 6346 | /* Get system's tclk rate */ |
| 6347 | priv->tclk = clk_get_rate(priv->pp_clk); |
| 6348 | |
| 6349 | /* Initialize network controller */ |
| 6350 | err = mvpp2_init(pdev, priv); |
| 6351 | if (err < 0) { |
| 6352 | dev_err(&pdev->dev, "failed to initialize controller\n"); |
| 6353 | goto err_gop_clk; |
| 6354 | } |
| 6355 | |
| 6356 | port_count = of_get_available_child_count(dn); |
| 6357 | if (port_count == 0) { |
| 6358 | dev_err(&pdev->dev, "no ports enabled\n"); |
Wei Yongjun | 575a193 | 2014-07-20 22:02:43 +0800 | [diff] [blame] | 6359 | err = -ENODEV; |
Marcin Wojtas | 3f51850 | 2014-07-10 16:52:13 -0300 | [diff] [blame] | 6360 | goto err_gop_clk; |
| 6361 | } |
| 6362 | |
| 6363 | priv->port_list = devm_kcalloc(&pdev->dev, port_count, |
| 6364 | sizeof(struct mvpp2_port *), |
| 6365 | GFP_KERNEL); |
| 6366 | if (!priv->port_list) { |
| 6367 | err = -ENOMEM; |
| 6368 | goto err_gop_clk; |
| 6369 | } |
| 6370 | |
| 6371 | /* Initialize ports */ |
| 6372 | first_rxq = 0; |
| 6373 | for_each_available_child_of_node(dn, port_node) { |
| 6374 | err = mvpp2_port_probe(pdev, port_node, priv, &first_rxq); |
| 6375 | if (err < 0) |
| 6376 | goto err_gop_clk; |
| 6377 | } |
| 6378 | |
| 6379 | platform_set_drvdata(pdev, priv); |
| 6380 | return 0; |
| 6381 | |
| 6382 | err_gop_clk: |
| 6383 | clk_disable_unprepare(priv->gop_clk); |
| 6384 | err_pp_clk: |
| 6385 | clk_disable_unprepare(priv->pp_clk); |
| 6386 | return err; |
| 6387 | } |
| 6388 | |
| 6389 | static int mvpp2_remove(struct platform_device *pdev) |
| 6390 | { |
| 6391 | struct mvpp2 *priv = platform_get_drvdata(pdev); |
| 6392 | struct device_node *dn = pdev->dev.of_node; |
| 6393 | struct device_node *port_node; |
| 6394 | int i = 0; |
| 6395 | |
| 6396 | for_each_available_child_of_node(dn, port_node) { |
| 6397 | if (priv->port_list[i]) |
| 6398 | mvpp2_port_remove(priv->port_list[i]); |
| 6399 | i++; |
| 6400 | } |
| 6401 | |
| 6402 | for (i = 0; i < MVPP2_BM_POOLS_NUM; i++) { |
| 6403 | struct mvpp2_bm_pool *bm_pool = &priv->bm_pools[i]; |
| 6404 | |
| 6405 | mvpp2_bm_pool_destroy(pdev, priv, bm_pool); |
| 6406 | } |
| 6407 | |
| 6408 | for_each_present_cpu(i) { |
| 6409 | struct mvpp2_tx_queue *aggr_txq = &priv->aggr_txqs[i]; |
| 6410 | |
| 6411 | dma_free_coherent(&pdev->dev, |
| 6412 | MVPP2_AGGR_TXQ_SIZE * MVPP2_DESC_ALIGNED_SIZE, |
| 6413 | aggr_txq->descs, |
| 6414 | aggr_txq->descs_phys); |
| 6415 | } |
| 6416 | |
| 6417 | clk_disable_unprepare(priv->pp_clk); |
| 6418 | clk_disable_unprepare(priv->gop_clk); |
| 6419 | |
| 6420 | return 0; |
| 6421 | } |
| 6422 | |
| 6423 | static const struct of_device_id mvpp2_match[] = { |
| 6424 | { .compatible = "marvell,armada-375-pp2" }, |
| 6425 | { } |
| 6426 | }; |
| 6427 | MODULE_DEVICE_TABLE(of, mvpp2_match); |
| 6428 | |
| 6429 | static struct platform_driver mvpp2_driver = { |
| 6430 | .probe = mvpp2_probe, |
| 6431 | .remove = mvpp2_remove, |
| 6432 | .driver = { |
| 6433 | .name = MVPP2_DRIVER_NAME, |
| 6434 | .of_match_table = mvpp2_match, |
| 6435 | }, |
| 6436 | }; |
| 6437 | |
| 6438 | module_platform_driver(mvpp2_driver); |
| 6439 | |
| 6440 | MODULE_DESCRIPTION("Marvell PPv2 Ethernet Driver - www.marvell.com"); |
| 6441 | MODULE_AUTHOR("Marcin Wojtas <mw@semihalf.com>"); |
Ezequiel Garcia | c634099 | 2014-07-14 10:34:47 -0300 | [diff] [blame] | 6442 | MODULE_LICENSE("GPL v2"); |