| 1 |
// SPDX-License-Identifier: (GPL-2.0 OR MIT) |
| 2 |
/* |
| 3 |
* Copyright (c) 2018 Synopsys, Inc. and/or its affiliates. |
| 4 |
* stmmac XGMAC support. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <linux/bitrev.h> |
| 8 |
#include <linux/crc32.h> |
| 9 |
#include <linux/iopoll.h> |
| 10 |
#include "stmmac.h" |
| 11 |
#include "stmmac_fpe.h" |
| 12 |
#include "stmmac_ptp.h" |
| 13 |
#include "stmmac_vlan.h" |
| 14 |
#include "dwxlgmac2.h" |
| 15 |
#include "dwxgmac2.h" |
| 16 |
|
| 17 |
static void dwxgmac2_core_init(struct mac_device_info *hw, |
| 18 |
struct net_device *dev) |
| 19 |
{ |
| 20 |
void __iomem *ioaddr = hw->pcsr; |
| 21 |
u32 tx, rx; |
| 22 |
|
| 23 |
tx = readl(ioaddr + XGMAC_TX_CONFIG); |
| 24 |
rx = readl(ioaddr + XGMAC_RX_CONFIG); |
| 25 |
|
| 26 |
writel(tx | XGMAC_CORE_INIT_TX, ioaddr + XGMAC_TX_CONFIG); |
| 27 |
writel(rx | XGMAC_CORE_INIT_RX, ioaddr + XGMAC_RX_CONFIG); |
| 28 |
writel(XGMAC_INT_DEFAULT_EN, ioaddr + XGMAC_INT_EN); |
| 29 |
} |
| 30 |
|
| 31 |
static void dwxgmac2_irq_modify(struct mac_device_info *hw, u32 disable, |
| 32 |
u32 enable) |
| 33 |
{ |
| 34 |
void __iomem *int_mask = hw->pcsr + XGMAC_INT_EN; |
| 35 |
unsigned long flags; |
| 36 |
u32 value; |
| 37 |
|
| 38 |
spin_lock_irqsave(&hw->irq_ctrl_lock, flags); |
| 39 |
value = readl(int_mask) & ~disable; |
| 40 |
value |= enable; |
| 41 |
writel(value, int_mask); |
| 42 |
spin_unlock_irqrestore(&hw->irq_ctrl_lock, flags); |
| 43 |
} |
| 44 |
|
| 45 |
static void dwxgmac2_update_caps(struct stmmac_priv *priv) |
| 46 |
{ |
| 47 |
if (!priv->dma_cap.mbps_10_100) |
| 48 |
priv->hw->link.caps &= ~(MAC_10 | MAC_100); |
| 49 |
} |
| 50 |
|
| 51 |
static void dwxgmac2_set_mac(void __iomem *ioaddr, bool enable) |
| 52 |
{ |
| 53 |
u32 tx = readl(ioaddr + XGMAC_TX_CONFIG); |
| 54 |
u32 rx = readl(ioaddr + XGMAC_RX_CONFIG); |
| 55 |
|
| 56 |
if (enable) { |
| 57 |
tx |= XGMAC_CONFIG_TE; |
| 58 |
rx |= XGMAC_CONFIG_RE; |
| 59 |
} else { |
| 60 |
tx &= ~XGMAC_CONFIG_TE; |
| 61 |
rx &= ~XGMAC_CONFIG_RE; |
| 62 |
} |
| 63 |
|
| 64 |
writel(tx, ioaddr + XGMAC_TX_CONFIG); |
| 65 |
writel(rx, ioaddr + XGMAC_RX_CONFIG); |
| 66 |
} |
| 67 |
|
| 68 |
static int dwxgmac2_rx_ipc(struct mac_device_info *hw) |
| 69 |
{ |
| 70 |
void __iomem *ioaddr = hw->pcsr; |
| 71 |
u32 value; |
| 72 |
|
| 73 |
value = readl(ioaddr + XGMAC_RX_CONFIG); |
| 74 |
if (hw->rx_csum) |
| 75 |
value |= XGMAC_CONFIG_IPC; |
| 76 |
else |
| 77 |
value &= ~XGMAC_CONFIG_IPC; |
| 78 |
writel(value, ioaddr + XGMAC_RX_CONFIG); |
| 79 |
|
| 80 |
return !!(readl(ioaddr + XGMAC_RX_CONFIG) & XGMAC_CONFIG_IPC); |
| 81 |
} |
| 82 |
|
| 83 |
static void dwxgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode, |
| 84 |
u32 queue) |
| 85 |
{ |
| 86 |
void __iomem *ioaddr = hw->pcsr; |
| 87 |
u32 value; |
| 88 |
|
| 89 |
value = readl(ioaddr + XGMAC_RXQ_CTRL0) & ~XGMAC_RXQEN(queue); |
| 90 |
if (mode == MTL_QUEUE_AVB) |
| 91 |
value |= 0x1 << XGMAC_RXQEN_SHIFT(queue); |
| 92 |
else if (mode == MTL_QUEUE_DCB) |
| 93 |
value |= 0x2 << XGMAC_RXQEN_SHIFT(queue); |
| 94 |
writel(value, ioaddr + XGMAC_RXQ_CTRL0); |
| 95 |
} |
| 96 |
|
| 97 |
static void dwxgmac2_rx_queue_prio(struct mac_device_info *hw, u32 prio, |
| 98 |
u32 queue) |
| 99 |
{ |
| 100 |
void __iomem *ioaddr = hw->pcsr; |
| 101 |
u32 clear_mask = 0; |
| 102 |
u32 ctrl2, ctrl3; |
| 103 |
int i; |
| 104 |
|
| 105 |
ctrl2 = readl(ioaddr + XGMAC_RXQ_CTRL2); |
| 106 |
ctrl3 = readl(ioaddr + XGMAC_RXQ_CTRL3); |
| 107 |
|
| 108 |
/* The software must ensure that the same priority |
| 109 |
* is not mapped to multiple Rx queues |
| 110 |
*/ |
| 111 |
for (i = 0; i < 4; i++) |
| 112 |
clear_mask |= ((prio << XGMAC_PSRQ_SHIFT(i)) & |
| 113 |
XGMAC_PSRQ(i)); |
| 114 |
|
| 115 |
ctrl2 &= ~clear_mask; |
| 116 |
ctrl3 &= ~clear_mask; |
| 117 |
|
| 118 |
/* First assign new priorities to a queue, then |
| 119 |
* clear them from others queues |
| 120 |
*/ |
| 121 |
if (queue < 4) { |
| 122 |
ctrl2 |= (prio << XGMAC_PSRQ_SHIFT(queue)) & |
| 123 |
XGMAC_PSRQ(queue); |
| 124 |
|
| 125 |
writel(ctrl2, ioaddr + XGMAC_RXQ_CTRL2); |
| 126 |
writel(ctrl3, ioaddr + XGMAC_RXQ_CTRL3); |
| 127 |
} else { |
| 128 |
queue -= 4; |
| 129 |
|
| 130 |
ctrl3 |= (prio << XGMAC_PSRQ_SHIFT(queue)) & |
| 131 |
XGMAC_PSRQ(queue); |
| 132 |
|
| 133 |
writel(ctrl3, ioaddr + XGMAC_RXQ_CTRL3); |
| 134 |
writel(ctrl2, ioaddr + XGMAC_RXQ_CTRL2); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
static void dwxgmac2_tx_queue_prio(struct mac_device_info *hw, u32 prio, |
| 139 |
u32 queue) |
| 140 |
{ |
| 141 |
void __iomem *ioaddr = hw->pcsr; |
| 142 |
u32 value, reg; |
| 143 |
|
| 144 |
reg = (queue < 4) ? XGMAC_TC_PRTY_MAP0 : XGMAC_TC_PRTY_MAP1; |
| 145 |
if (queue >= 4) |
| 146 |
queue -= 4; |
| 147 |
|
| 148 |
value = readl(ioaddr + reg); |
| 149 |
value &= ~XGMAC_PSTC(queue); |
| 150 |
value |= (prio << XGMAC_PSTC_SHIFT(queue)) & XGMAC_PSTC(queue); |
| 151 |
|
| 152 |
writel(value, ioaddr + reg); |
| 153 |
} |
| 154 |
|
| 155 |
static void dwxgmac2_rx_queue_routing(struct mac_device_info *hw, |
| 156 |
u8 packet, u32 queue) |
| 157 |
{ |
| 158 |
void __iomem *ioaddr = hw->pcsr; |
| 159 |
u32 value; |
| 160 |
|
| 161 |
static const struct stmmac_rx_routing dwxgmac2_route_possibilities[] = { |
| 162 |
{ XGMAC_AVCPQ, XGMAC_AVCPQ_SHIFT }, |
| 163 |
{ XGMAC_PTPQ, XGMAC_PTPQ_SHIFT }, |
| 164 |
{ XGMAC_DCBCPQ, XGMAC_DCBCPQ_SHIFT }, |
| 165 |
{ XGMAC_UPQ, XGMAC_UPQ_SHIFT }, |
| 166 |
{ XGMAC_MCBCQ, XGMAC_MCBCQ_SHIFT }, |
| 167 |
}; |
| 168 |
|
| 169 |
value = readl(ioaddr + XGMAC_RXQ_CTRL1); |
| 170 |
|
| 171 |
/* routing configuration */ |
| 172 |
value &= ~dwxgmac2_route_possibilities[packet - 1].reg_mask; |
| 173 |
value |= (queue << dwxgmac2_route_possibilities[packet - 1].reg_shift) & |
| 174 |
dwxgmac2_route_possibilities[packet - 1].reg_mask; |
| 175 |
|
| 176 |
/* some packets require extra ops */ |
| 177 |
if (packet == PACKET_AVCPQ) |
| 178 |
value |= FIELD_PREP(XGMAC_TACPQE, 1); |
| 179 |
else if (packet == PACKET_MCBCQ) |
| 180 |
value |= FIELD_PREP(XGMAC_MCBCQEN, 1); |
| 181 |
|
| 182 |
writel(value, ioaddr + XGMAC_RXQ_CTRL1); |
| 183 |
} |
| 184 |
|
| 185 |
static void dwxgmac2_prog_mtl_rx_algorithms(struct mac_device_info *hw, |
| 186 |
u32 rx_alg) |
| 187 |
{ |
| 188 |
void __iomem *ioaddr = hw->pcsr; |
| 189 |
u32 value; |
| 190 |
|
| 191 |
value = readl(ioaddr + XGMAC_MTL_OPMODE); |
| 192 |
value &= ~XGMAC_RAA; |
| 193 |
|
| 194 |
switch (rx_alg) { |
| 195 |
case MTL_RX_ALGORITHM_SP: |
| 196 |
break; |
| 197 |
case MTL_RX_ALGORITHM_WSP: |
| 198 |
value |= XGMAC_RAA; |
| 199 |
break; |
| 200 |
default: |
| 201 |
break; |
| 202 |
} |
| 203 |
|
| 204 |
writel(value, ioaddr + XGMAC_MTL_OPMODE); |
| 205 |
} |
| 206 |
|
| 207 |
static void dwxgmac2_prog_mtl_tx_algorithms(struct mac_device_info *hw, |
| 208 |
u32 tx_alg) |
| 209 |
{ |
| 210 |
void __iomem *ioaddr = hw->pcsr; |
| 211 |
bool ets = true; |
| 212 |
u32 value; |
| 213 |
int i; |
| 214 |
|
| 215 |
value = readl(ioaddr + XGMAC_MTL_OPMODE); |
| 216 |
value &= ~XGMAC_ETSALG; |
| 217 |
|
| 218 |
switch (tx_alg) { |
| 219 |
case MTL_TX_ALGORITHM_WRR: |
| 220 |
value |= XGMAC_WRR; |
| 221 |
break; |
| 222 |
case MTL_TX_ALGORITHM_WFQ: |
| 223 |
value |= XGMAC_WFQ; |
| 224 |
break; |
| 225 |
case MTL_TX_ALGORITHM_DWRR: |
| 226 |
value |= XGMAC_DWRR; |
| 227 |
break; |
| 228 |
default: |
| 229 |
ets = false; |
| 230 |
break; |
| 231 |
} |
| 232 |
|
| 233 |
writel(value, ioaddr + XGMAC_MTL_OPMODE); |
| 234 |
|
| 235 |
/* Set ETS if desired */ |
| 236 |
for (i = 0; i < MTL_MAX_TX_QUEUES; i++) { |
| 237 |
value = readl(ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(i)); |
| 238 |
value &= ~XGMAC_TSA; |
| 239 |
if (ets) |
| 240 |
value |= XGMAC_ETS; |
| 241 |
writel(value, ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(i)); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
static void dwxgmac2_set_mtl_tx_queue_weight(struct stmmac_priv *priv, |
| 246 |
struct mac_device_info *hw, |
| 247 |
u32 weight, u32 queue) |
| 248 |
{ |
| 249 |
void __iomem *ioaddr = hw->pcsr; |
| 250 |
|
| 251 |
writel(weight, ioaddr + XGMAC_MTL_TCx_QUANTUM_WEIGHT(queue)); |
| 252 |
} |
| 253 |
|
| 254 |
static void dwxgmac2_map_mtl_to_dma(struct mac_device_info *hw, u32 queue, |
| 255 |
u32 chan) |
| 256 |
{ |
| 257 |
void __iomem *ioaddr = hw->pcsr; |
| 258 |
u32 value, reg; |
| 259 |
|
| 260 |
reg = (queue < 4) ? XGMAC_MTL_RXQ_DMA_MAP0 : XGMAC_MTL_RXQ_DMA_MAP1; |
| 261 |
if (queue >= 4) |
| 262 |
queue -= 4; |
| 263 |
|
| 264 |
value = readl(ioaddr + reg); |
| 265 |
value &= ~XGMAC_QxMDMACH(queue); |
| 266 |
value |= (chan << XGMAC_QxMDMACH_SHIFT(queue)) & XGMAC_QxMDMACH(queue); |
| 267 |
|
| 268 |
writel(value, ioaddr + reg); |
| 269 |
} |
| 270 |
|
| 271 |
static void dwxgmac2_config_cbs(struct stmmac_priv *priv, |
| 272 |
struct mac_device_info *hw, |
| 273 |
u32 send_slope, u32 idle_slope, |
| 274 |
u32 high_credit, u32 low_credit, u32 queue) |
| 275 |
{ |
| 276 |
void __iomem *ioaddr = hw->pcsr; |
| 277 |
u32 value; |
| 278 |
|
| 279 |
writel(send_slope, ioaddr + XGMAC_MTL_TCx_SENDSLOPE(queue)); |
| 280 |
writel(idle_slope, ioaddr + XGMAC_MTL_TCx_QUANTUM_WEIGHT(queue)); |
| 281 |
writel(high_credit, ioaddr + XGMAC_MTL_TCx_HICREDIT(queue)); |
| 282 |
writel(low_credit, ioaddr + XGMAC_MTL_TCx_LOCREDIT(queue)); |
| 283 |
|
| 284 |
value = readl(ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(queue)); |
| 285 |
value &= ~XGMAC_TSA; |
| 286 |
value |= XGMAC_CC | XGMAC_CBS; |
| 287 |
writel(value, ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(queue)); |
| 288 |
} |
| 289 |
|
| 290 |
static void dwxgmac2_dump_regs(struct mac_device_info *hw, u32 *reg_space) |
| 291 |
{ |
| 292 |
void __iomem *ioaddr = hw->pcsr; |
| 293 |
int i; |
| 294 |
|
| 295 |
for (i = 0; i < XGMAC_MAC_REGSIZE; i++) |
| 296 |
reg_space[i] = readl(ioaddr + i * 4); |
| 297 |
} |
| 298 |
|
| 299 |
static int dwxgmac2_host_irq_status(struct stmmac_priv *priv, |
| 300 |
struct stmmac_extra_stats *x) |
| 301 |
{ |
| 302 |
void __iomem *ioaddr = priv->hw->pcsr; |
| 303 |
u32 stat, en; |
| 304 |
int ret = 0; |
| 305 |
|
| 306 |
en = readl(ioaddr + XGMAC_INT_EN); |
| 307 |
stat = readl(ioaddr + XGMAC_INT_STATUS); |
| 308 |
|
| 309 |
stat &= en; |
| 310 |
|
| 311 |
if (stat & XGMAC_PMTIS) { |
| 312 |
x->irq_receive_pmt_irq_n++; |
| 313 |
readl(ioaddr + XGMAC_PMT); |
| 314 |
} |
| 315 |
|
| 316 |
if (stat & XGMAC_LPIIS) { |
| 317 |
u32 lpi = readl(ioaddr + XGMAC_LPI_CTRL); |
| 318 |
|
| 319 |
if (lpi & LPI_CTRL_STATUS_TLPIEN) { |
| 320 |
ret |= CORE_IRQ_TX_PATH_IN_LPI_MODE; |
| 321 |
x->irq_tx_path_in_lpi_mode_n++; |
| 322 |
} |
| 323 |
if (lpi & LPI_CTRL_STATUS_TLPIEX) { |
| 324 |
ret |= CORE_IRQ_TX_PATH_EXIT_LPI_MODE; |
| 325 |
x->irq_tx_path_exit_lpi_mode_n++; |
| 326 |
} |
| 327 |
if (lpi & LPI_CTRL_STATUS_RLPIEN) |
| 328 |
x->irq_rx_path_in_lpi_mode_n++; |
| 329 |
if (lpi & LPI_CTRL_STATUS_RLPIEX) |
| 330 |
x->irq_rx_path_exit_lpi_mode_n++; |
| 331 |
} |
| 332 |
|
| 333 |
return ret; |
| 334 |
} |
| 335 |
|
| 336 |
static int dwxgmac2_host_mtl_irq_status(struct stmmac_priv *priv, |
| 337 |
struct mac_device_info *hw, u32 chan) |
| 338 |
{ |
| 339 |
void __iomem *ioaddr = hw->pcsr; |
| 340 |
int ret = 0; |
| 341 |
u32 status; |
| 342 |
|
| 343 |
status = readl(ioaddr + XGMAC_MTL_INT_STATUS); |
| 344 |
if (status & BIT(chan)) { |
| 345 |
u32 chan_status = readl(ioaddr + XGMAC_MTL_QINT_STATUS(chan)); |
| 346 |
|
| 347 |
if (chan_status & XGMAC_RXOVFIS) |
| 348 |
ret |= CORE_IRQ_MTL_RX_OVERFLOW; |
| 349 |
|
| 350 |
writel(~0x0, ioaddr + XGMAC_MTL_QINT_STATUS(chan)); |
| 351 |
} |
| 352 |
|
| 353 |
return ret; |
| 354 |
} |
| 355 |
|
| 356 |
static void dwxgmac2_flow_ctrl(struct mac_device_info *hw, unsigned int duplex, |
| 357 |
unsigned int fc, unsigned int pause_time, |
| 358 |
u32 tx_cnt) |
| 359 |
{ |
| 360 |
void __iomem *ioaddr = hw->pcsr; |
| 361 |
u32 i; |
| 362 |
|
| 363 |
if (fc & FLOW_RX) |
| 364 |
writel(XGMAC_RFE, ioaddr + XGMAC_RX_FLOW_CTRL); |
| 365 |
if (fc & FLOW_TX) { |
| 366 |
for (i = 0; i < tx_cnt; i++) { |
| 367 |
u32 value = XGMAC_TFE; |
| 368 |
|
| 369 |
if (duplex) |
| 370 |
value |= FIELD_PREP(XGMAC_PT, pause_time); |
| 371 |
|
| 372 |
writel(value, ioaddr + XGMAC_Qx_TX_FLOW_CTRL(i)); |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
static void dwxgmac2_pmt(struct mac_device_info *hw, unsigned long mode) |
| 378 |
{ |
| 379 |
void __iomem *ioaddr = hw->pcsr; |
| 380 |
u32 val = 0x0; |
| 381 |
|
| 382 |
if (mode & WAKE_MAGIC) |
| 383 |
val |= XGMAC_PWRDWN | XGMAC_MGKPKTEN; |
| 384 |
if (mode & WAKE_UCAST) |
| 385 |
val |= XGMAC_PWRDWN | XGMAC_GLBLUCAST | XGMAC_RWKPKTEN; |
| 386 |
if (val) { |
| 387 |
u32 cfg = readl(ioaddr + XGMAC_RX_CONFIG); |
| 388 |
cfg |= XGMAC_CONFIG_RE; |
| 389 |
writel(cfg, ioaddr + XGMAC_RX_CONFIG); |
| 390 |
} |
| 391 |
|
| 392 |
writel(val, ioaddr + XGMAC_PMT); |
| 393 |
} |
| 394 |
|
| 395 |
static void dwxgmac2_set_umac_addr(struct mac_device_info *hw, |
| 396 |
const unsigned char *addr, |
| 397 |
unsigned int reg_n) |
| 398 |
{ |
| 399 |
void __iomem *ioaddr = hw->pcsr; |
| 400 |
u32 value; |
| 401 |
|
| 402 |
value = (addr[5] << 8) | addr[4]; |
| 403 |
writel(value | XGMAC_AE, ioaddr + XGMAC_ADDRx_HIGH(reg_n)); |
| 404 |
|
| 405 |
value = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0]; |
| 406 |
writel(value, ioaddr + XGMAC_ADDRx_LOW(reg_n)); |
| 407 |
} |
| 408 |
|
| 409 |
static void dwxgmac2_get_umac_addr(struct mac_device_info *hw, |
| 410 |
unsigned char *addr, unsigned int reg_n) |
| 411 |
{ |
| 412 |
void __iomem *ioaddr = hw->pcsr; |
| 413 |
u32 hi_addr, lo_addr; |
| 414 |
|
| 415 |
/* Read the MAC address from the hardware */ |
| 416 |
hi_addr = readl(ioaddr + XGMAC_ADDRx_HIGH(reg_n)); |
| 417 |
lo_addr = readl(ioaddr + XGMAC_ADDRx_LOW(reg_n)); |
| 418 |
|
| 419 |
/* Extract the MAC address from the high and low words */ |
| 420 |
addr[0] = lo_addr & 0xff; |
| 421 |
addr[1] = (lo_addr >> 8) & 0xff; |
| 422 |
addr[2] = (lo_addr >> 16) & 0xff; |
| 423 |
addr[3] = (lo_addr >> 24) & 0xff; |
| 424 |
addr[4] = hi_addr & 0xff; |
| 425 |
addr[5] = (hi_addr >> 8) & 0xff; |
| 426 |
} |
| 427 |
|
| 428 |
static int dwxgmac2_set_lpi_mode(struct mac_device_info *hw, |
| 429 |
enum stmmac_lpi_mode mode, |
| 430 |
bool en_tx_lpi_clockgating, u32 et) |
| 431 |
{ |
| 432 |
void __iomem *ioaddr = hw->pcsr; |
| 433 |
u32 value; |
| 434 |
|
| 435 |
if (mode == STMMAC_LPI_TIMER) |
| 436 |
return -EOPNOTSUPP; |
| 437 |
|
| 438 |
value = readl(ioaddr + XGMAC_LPI_CTRL); |
| 439 |
if (mode == STMMAC_LPI_FORCED) { |
| 440 |
value |= LPI_CTRL_STATUS_LPIEN | LPI_CTRL_STATUS_LPITXA; |
| 441 |
if (en_tx_lpi_clockgating) |
| 442 |
value |= LPI_CTRL_STATUS_LPITCSE; |
| 443 |
} else { |
| 444 |
value &= ~(LPI_CTRL_STATUS_LPIEN | LPI_CTRL_STATUS_LPITXA | |
| 445 |
LPI_CTRL_STATUS_LPITCSE); |
| 446 |
} |
| 447 |
writel(value, ioaddr + XGMAC_LPI_CTRL); |
| 448 |
|
| 449 |
return 0; |
| 450 |
} |
| 451 |
|
| 452 |
static void dwxgmac2_set_eee_pls(struct mac_device_info *hw, int link) |
| 453 |
{ |
| 454 |
void __iomem *ioaddr = hw->pcsr; |
| 455 |
u32 value; |
| 456 |
|
| 457 |
value = readl(ioaddr + XGMAC_LPI_CTRL); |
| 458 |
if (link) |
| 459 |
value |= LPI_CTRL_STATUS_PLS; |
| 460 |
else |
| 461 |
value &= ~LPI_CTRL_STATUS_PLS; |
| 462 |
writel(value, ioaddr + XGMAC_LPI_CTRL); |
| 463 |
} |
| 464 |
|
| 465 |
static void dwxgmac2_set_eee_timer(struct mac_device_info *hw, int ls, int tw) |
| 466 |
{ |
| 467 |
void __iomem *ioaddr = hw->pcsr; |
| 468 |
u32 value; |
| 469 |
|
| 470 |
value = (tw & 0xffff) | ((ls & 0x3ff) << 16); |
| 471 |
writel(value, ioaddr + XGMAC_LPI_TIMER_CTRL); |
| 472 |
} |
| 473 |
|
| 474 |
static void dwxgmac2_set_mchash(void __iomem *ioaddr, u32 *mcfilterbits, |
| 475 |
int mcbitslog2) |
| 476 |
{ |
| 477 |
int numhashregs, regs; |
| 478 |
|
| 479 |
switch (mcbitslog2) { |
| 480 |
case 6: |
| 481 |
numhashregs = 2; |
| 482 |
break; |
| 483 |
case 7: |
| 484 |
numhashregs = 4; |
| 485 |
break; |
| 486 |
case 8: |
| 487 |
numhashregs = 8; |
| 488 |
break; |
| 489 |
default: |
| 490 |
return; |
| 491 |
} |
| 492 |
|
| 493 |
for (regs = 0; regs < numhashregs; regs++) |
| 494 |
writel(mcfilterbits[regs], ioaddr + XGMAC_HASH_TABLE(regs)); |
| 495 |
} |
| 496 |
|
| 497 |
static void dwxgmac2_set_filter(struct mac_device_info *hw, |
| 498 |
struct net_device *dev) |
| 499 |
{ |
| 500 |
void __iomem *ioaddr = (void __iomem *)dev->base_addr; |
| 501 |
u32 value = readl(ioaddr + XGMAC_PACKET_FILTER); |
| 502 |
int mcbitslog2 = hw->mcast_bits_log2; |
| 503 |
u32 mc_filter[8]; |
| 504 |
int i; |
| 505 |
|
| 506 |
value &= ~(XGMAC_FILTER_PR | XGMAC_FILTER_HMC | XGMAC_FILTER_PM); |
| 507 |
value |= XGMAC_FILTER_HPF; |
| 508 |
|
| 509 |
memset(mc_filter, 0, sizeof(mc_filter)); |
| 510 |
|
| 511 |
if (dev->flags & IFF_PROMISC) { |
| 512 |
value |= XGMAC_FILTER_PR; |
| 513 |
value |= XGMAC_FILTER_PCF; |
| 514 |
} else if ((dev->flags & IFF_ALLMULTI) || |
| 515 |
(netdev_mc_count(dev) > hw->multicast_filter_bins)) { |
| 516 |
value |= XGMAC_FILTER_PM; |
| 517 |
|
| 518 |
for (i = 0; i < XGMAC_MAX_HASH_TABLE; i++) |
| 519 |
writel(~0x0, ioaddr + XGMAC_HASH_TABLE(i)); |
| 520 |
} else if (!netdev_mc_empty(dev) && (dev->flags & IFF_MULTICAST)) { |
| 521 |
struct netdev_hw_addr *ha; |
| 522 |
|
| 523 |
value |= XGMAC_FILTER_HMC; |
| 524 |
|
| 525 |
netdev_for_each_mc_addr(ha, dev) { |
| 526 |
u32 nr = (bitrev32(~crc32_le(~0, ha->addr, 6)) >> |
| 527 |
(32 - mcbitslog2)); |
| 528 |
mc_filter[nr >> 5] |= (1 << (nr & 0x1F)); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
dwxgmac2_set_mchash(ioaddr, mc_filter, mcbitslog2); |
| 533 |
|
| 534 |
/* Handle multiple unicast addresses */ |
| 535 |
if (netdev_uc_count(dev) > hw->unicast_filter_entries) { |
| 536 |
value |= XGMAC_FILTER_PR; |
| 537 |
} else { |
| 538 |
struct netdev_hw_addr *ha; |
| 539 |
int reg = 1; |
| 540 |
|
| 541 |
netdev_for_each_uc_addr(ha, dev) { |
| 542 |
dwxgmac2_set_umac_addr(hw, ha->addr, reg); |
| 543 |
reg++; |
| 544 |
} |
| 545 |
|
| 546 |
for ( ; reg < XGMAC_ADDR_MAX; reg++) { |
| 547 |
writel(0, ioaddr + XGMAC_ADDRx_HIGH(reg)); |
| 548 |
writel(0, ioaddr + XGMAC_ADDRx_LOW(reg)); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
writel(value, ioaddr + XGMAC_PACKET_FILTER); |
| 553 |
} |
| 554 |
|
| 555 |
static void dwxgmac2_set_mac_loopback(void __iomem *ioaddr, bool enable) |
| 556 |
{ |
| 557 |
u32 value = readl(ioaddr + XGMAC_RX_CONFIG); |
| 558 |
|
| 559 |
if (enable) |
| 560 |
value |= XGMAC_CONFIG_LM; |
| 561 |
else |
| 562 |
value &= ~XGMAC_CONFIG_LM; |
| 563 |
|
| 564 |
writel(value, ioaddr + XGMAC_RX_CONFIG); |
| 565 |
} |
| 566 |
|
| 567 |
static int dwxgmac2_rss_write_reg(void __iomem *ioaddr, bool is_key, int idx, |
| 568 |
u32 val) |
| 569 |
{ |
| 570 |
u32 ctrl = 0; |
| 571 |
|
| 572 |
writel(val, ioaddr + XGMAC_RSS_DATA); |
| 573 |
ctrl |= idx << XGMAC_RSSIA_SHIFT; |
| 574 |
ctrl |= is_key ? XGMAC_ADDRT : 0x0; |
| 575 |
ctrl |= XGMAC_OB; |
| 576 |
writel(ctrl, ioaddr + XGMAC_RSS_ADDR); |
| 577 |
|
| 578 |
return readl_poll_timeout(ioaddr + XGMAC_RSS_ADDR, ctrl, |
| 579 |
!(ctrl & XGMAC_OB), 100, 10000); |
| 580 |
} |
| 581 |
|
| 582 |
static int dwxgmac2_rss_configure(struct mac_device_info *hw, |
| 583 |
struct stmmac_rss *cfg, u32 num_rxq) |
| 584 |
{ |
| 585 |
void __iomem *ioaddr = hw->pcsr; |
| 586 |
u32 value, *key; |
| 587 |
int i, ret; |
| 588 |
|
| 589 |
value = readl(ioaddr + XGMAC_RSS_CTRL); |
| 590 |
if (!cfg || !cfg->enable) { |
| 591 |
value &= ~XGMAC_RSSE; |
| 592 |
writel(value, ioaddr + XGMAC_RSS_CTRL); |
| 593 |
return 0; |
| 594 |
} |
| 595 |
|
| 596 |
key = (u32 *)cfg->key; |
| 597 |
for (i = 0; i < (ARRAY_SIZE(cfg->key) / sizeof(u32)); i++) { |
| 598 |
ret = dwxgmac2_rss_write_reg(ioaddr, true, i, key[i]); |
| 599 |
if (ret) |
| 600 |
return ret; |
| 601 |
} |
| 602 |
|
| 603 |
for (i = 0; i < ARRAY_SIZE(cfg->table); i++) { |
| 604 |
ret = dwxgmac2_rss_write_reg(ioaddr, false, i, cfg->table[i]); |
| 605 |
if (ret) |
| 606 |
return ret; |
| 607 |
} |
| 608 |
|
| 609 |
for (i = 0; i < num_rxq; i++) |
| 610 |
dwxgmac2_map_mtl_to_dma(hw, i, XGMAC_QDDMACH); |
| 611 |
|
| 612 |
value |= XGMAC_UDP4TE | XGMAC_TCP4TE | XGMAC_IP2TE | XGMAC_RSSE; |
| 613 |
writel(value, ioaddr + XGMAC_RSS_CTRL); |
| 614 |
return 0; |
| 615 |
} |
| 616 |
|
| 617 |
struct dwxgmac3_error_desc { |
| 618 |
bool valid; |
| 619 |
const char *desc; |
| 620 |
const char *detailed_desc; |
| 621 |
}; |
| 622 |
|
| 623 |
#define STAT_OFF(field) offsetof(struct stmmac_safety_stats, field) |
| 624 |
|
| 625 |
static void dwxgmac3_log_error(struct net_device *ndev, u32 value, bool corr, |
| 626 |
const char *module_name, |
| 627 |
const struct dwxgmac3_error_desc *desc, |
| 628 |
unsigned long field_offset, |
| 629 |
struct stmmac_safety_stats *stats) |
| 630 |
{ |
| 631 |
unsigned long loc, mask; |
| 632 |
u8 *bptr = (u8 *)stats; |
| 633 |
unsigned long *ptr; |
| 634 |
|
| 635 |
ptr = (unsigned long *)(bptr + field_offset); |
| 636 |
|
| 637 |
mask = value; |
| 638 |
for_each_set_bit(loc, &mask, 32) { |
| 639 |
netdev_err(ndev, "Found %s error in %s: '%s: %s'\n", corr ? |
| 640 |
"correctable" : "uncorrectable", module_name, |
| 641 |
desc[loc].desc, desc[loc].detailed_desc); |
| 642 |
|
| 643 |
/* Update counters */ |
| 644 |
ptr[loc]++; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
static const struct dwxgmac3_error_desc dwxgmac3_mac_errors[32]= { |
| 649 |
{ true, "ATPES", "Application Transmit Interface Parity Check Error" }, |
| 650 |
{ true, "DPES", "Descriptor Cache Data Path Parity Check Error" }, |
| 651 |
{ true, "TPES", "TSO Data Path Parity Check Error" }, |
| 652 |
{ true, "TSOPES", "TSO Header Data Path Parity Check Error" }, |
| 653 |
{ true, "MTPES", "MTL Data Path Parity Check Error" }, |
| 654 |
{ true, "MTSPES", "MTL TX Status Data Path Parity Check Error" }, |
| 655 |
{ true, "MTBUPES", "MAC TBU Data Path Parity Check Error" }, |
| 656 |
{ true, "MTFCPES", "MAC TFC Data Path Parity Check Error" }, |
| 657 |
{ true, "ARPES", "Application Receive Interface Data Path Parity Check Error" }, |
| 658 |
{ true, "MRWCPES", "MTL RWC Data Path Parity Check Error" }, |
| 659 |
{ true, "MRRCPES", "MTL RCC Data Path Parity Check Error" }, |
| 660 |
{ true, "CWPES", "CSR Write Data Path Parity Check Error" }, |
| 661 |
{ true, "ASRPES", "AXI Slave Read Data Path Parity Check Error" }, |
| 662 |
{ true, "TTES", "TX FSM Timeout Error" }, |
| 663 |
{ true, "RTES", "RX FSM Timeout Error" }, |
| 664 |
{ true, "CTES", "CSR FSM Timeout Error" }, |
| 665 |
{ true, "ATES", "APP FSM Timeout Error" }, |
| 666 |
{ true, "PTES", "PTP FSM Timeout Error" }, |
| 667 |
{ false, "UNKNOWN", "Unknown Error" }, /* 18 */ |
| 668 |
{ false, "UNKNOWN", "Unknown Error" }, /* 19 */ |
| 669 |
{ false, "UNKNOWN", "Unknown Error" }, /* 20 */ |
| 670 |
{ true, "MSTTES", "Master Read/Write Timeout Error" }, |
| 671 |
{ true, "SLVTES", "Slave Read/Write Timeout Error" }, |
| 672 |
{ true, "ATITES", "Application Timeout on ATI Interface Error" }, |
| 673 |
{ true, "ARITES", "Application Timeout on ARI Interface Error" }, |
| 674 |
{ true, "FSMPES", "FSM State Parity Error" }, |
| 675 |
{ false, "UNKNOWN", "Unknown Error" }, /* 26 */ |
| 676 |
{ false, "UNKNOWN", "Unknown Error" }, /* 27 */ |
| 677 |
{ false, "UNKNOWN", "Unknown Error" }, /* 28 */ |
| 678 |
{ false, "UNKNOWN", "Unknown Error" }, /* 29 */ |
| 679 |
{ false, "UNKNOWN", "Unknown Error" }, /* 30 */ |
| 680 |
{ true, "CPI", "Control Register Parity Check Error" }, |
| 681 |
}; |
| 682 |
|
| 683 |
static void dwxgmac3_handle_mac_err(struct net_device *ndev, |
| 684 |
void __iomem *ioaddr, bool correctable, |
| 685 |
struct stmmac_safety_stats *stats) |
| 686 |
{ |
| 687 |
u32 value; |
| 688 |
|
| 689 |
value = readl(ioaddr + XGMAC_MAC_DPP_FSM_INT_STATUS); |
| 690 |
writel(value, ioaddr + XGMAC_MAC_DPP_FSM_INT_STATUS); |
| 691 |
|
| 692 |
dwxgmac3_log_error(ndev, value, correctable, "MAC", |
| 693 |
dwxgmac3_mac_errors, STAT_OFF(mac_errors), stats); |
| 694 |
} |
| 695 |
|
| 696 |
static const struct dwxgmac3_error_desc dwxgmac3_mtl_errors[32]= { |
| 697 |
{ true, "TXCES", "MTL TX Memory Error" }, |
| 698 |
{ true, "TXAMS", "MTL TX Memory Address Mismatch Error" }, |
| 699 |
{ true, "TXUES", "MTL TX Memory Error" }, |
| 700 |
{ false, "UNKNOWN", "Unknown Error" }, /* 3 */ |
| 701 |
{ true, "RXCES", "MTL RX Memory Error" }, |
| 702 |
{ true, "RXAMS", "MTL RX Memory Address Mismatch Error" }, |
| 703 |
{ true, "RXUES", "MTL RX Memory Error" }, |
| 704 |
{ false, "UNKNOWN", "Unknown Error" }, /* 7 */ |
| 705 |
{ true, "ECES", "MTL EST Memory Error" }, |
| 706 |
{ true, "EAMS", "MTL EST Memory Address Mismatch Error" }, |
| 707 |
{ true, "EUES", "MTL EST Memory Error" }, |
| 708 |
{ false, "UNKNOWN", "Unknown Error" }, /* 11 */ |
| 709 |
{ true, "RPCES", "MTL RX Parser Memory Error" }, |
| 710 |
{ true, "RPAMS", "MTL RX Parser Memory Address Mismatch Error" }, |
| 711 |
{ true, "RPUES", "MTL RX Parser Memory Error" }, |
| 712 |
{ false, "UNKNOWN", "Unknown Error" }, /* 15 */ |
| 713 |
{ false, "UNKNOWN", "Unknown Error" }, /* 16 */ |
| 714 |
{ false, "UNKNOWN", "Unknown Error" }, /* 17 */ |
| 715 |
{ false, "UNKNOWN", "Unknown Error" }, /* 18 */ |
| 716 |
{ false, "UNKNOWN", "Unknown Error" }, /* 19 */ |
| 717 |
{ false, "UNKNOWN", "Unknown Error" }, /* 20 */ |
| 718 |
{ false, "UNKNOWN", "Unknown Error" }, /* 21 */ |
| 719 |
{ false, "UNKNOWN", "Unknown Error" }, /* 22 */ |
| 720 |
{ false, "UNKNOWN", "Unknown Error" }, /* 23 */ |
| 721 |
{ false, "UNKNOWN", "Unknown Error" }, /* 24 */ |
| 722 |
{ false, "UNKNOWN", "Unknown Error" }, /* 25 */ |
| 723 |
{ false, "UNKNOWN", "Unknown Error" }, /* 26 */ |
| 724 |
{ false, "UNKNOWN", "Unknown Error" }, /* 27 */ |
| 725 |
{ false, "UNKNOWN", "Unknown Error" }, /* 28 */ |
| 726 |
{ false, "UNKNOWN", "Unknown Error" }, /* 29 */ |
| 727 |
{ false, "UNKNOWN", "Unknown Error" }, /* 30 */ |
| 728 |
{ false, "UNKNOWN", "Unknown Error" }, /* 31 */ |
| 729 |
}; |
| 730 |
|
| 731 |
static void dwxgmac3_handle_mtl_err(struct net_device *ndev, |
| 732 |
void __iomem *ioaddr, bool correctable, |
| 733 |
struct stmmac_safety_stats *stats) |
| 734 |
{ |
| 735 |
u32 value; |
| 736 |
|
| 737 |
value = readl(ioaddr + XGMAC_MTL_ECC_INT_STATUS); |
| 738 |
writel(value, ioaddr + XGMAC_MTL_ECC_INT_STATUS); |
| 739 |
|
| 740 |
dwxgmac3_log_error(ndev, value, correctable, "MTL", |
| 741 |
dwxgmac3_mtl_errors, STAT_OFF(mtl_errors), stats); |
| 742 |
} |
| 743 |
|
| 744 |
static const struct dwxgmac3_error_desc dwxgmac3_dma_errors[32]= { |
| 745 |
{ true, "TCES", "DMA TSO Memory Error" }, |
| 746 |
{ true, "TAMS", "DMA TSO Memory Address Mismatch Error" }, |
| 747 |
{ true, "TUES", "DMA TSO Memory Error" }, |
| 748 |
{ false, "UNKNOWN", "Unknown Error" }, /* 3 */ |
| 749 |
{ true, "DCES", "DMA DCACHE Memory Error" }, |
| 750 |
{ true, "DAMS", "DMA DCACHE Address Mismatch Error" }, |
| 751 |
{ true, "DUES", "DMA DCACHE Memory Error" }, |
| 752 |
{ false, "UNKNOWN", "Unknown Error" }, /* 7 */ |
| 753 |
{ false, "UNKNOWN", "Unknown Error" }, /* 8 */ |
| 754 |
{ false, "UNKNOWN", "Unknown Error" }, /* 9 */ |
| 755 |
{ false, "UNKNOWN", "Unknown Error" }, /* 10 */ |
| 756 |
{ false, "UNKNOWN", "Unknown Error" }, /* 11 */ |
| 757 |
{ false, "UNKNOWN", "Unknown Error" }, /* 12 */ |
| 758 |
{ false, "UNKNOWN", "Unknown Error" }, /* 13 */ |
| 759 |
{ false, "UNKNOWN", "Unknown Error" }, /* 14 */ |
| 760 |
{ false, "UNKNOWN", "Unknown Error" }, /* 15 */ |
| 761 |
{ false, "UNKNOWN", "Unknown Error" }, /* 16 */ |
| 762 |
{ false, "UNKNOWN", "Unknown Error" }, /* 17 */ |
| 763 |
{ false, "UNKNOWN", "Unknown Error" }, /* 18 */ |
| 764 |
{ false, "UNKNOWN", "Unknown Error" }, /* 19 */ |
| 765 |
{ false, "UNKNOWN", "Unknown Error" }, /* 20 */ |
| 766 |
{ false, "UNKNOWN", "Unknown Error" }, /* 21 */ |
| 767 |
{ false, "UNKNOWN", "Unknown Error" }, /* 22 */ |
| 768 |
{ false, "UNKNOWN", "Unknown Error" }, /* 23 */ |
| 769 |
{ false, "UNKNOWN", "Unknown Error" }, /* 24 */ |
| 770 |
{ false, "UNKNOWN", "Unknown Error" }, /* 25 */ |
| 771 |
{ false, "UNKNOWN", "Unknown Error" }, /* 26 */ |
| 772 |
{ false, "UNKNOWN", "Unknown Error" }, /* 27 */ |
| 773 |
{ false, "UNKNOWN", "Unknown Error" }, /* 28 */ |
| 774 |
{ false, "UNKNOWN", "Unknown Error" }, /* 29 */ |
| 775 |
{ false, "UNKNOWN", "Unknown Error" }, /* 30 */ |
| 776 |
{ false, "UNKNOWN", "Unknown Error" }, /* 31 */ |
| 777 |
}; |
| 778 |
|
| 779 |
static const char dpp_rx_err[] = "Read Rx Descriptor Parity checker Error"; |
| 780 |
static const char dpp_tx_err[] = "Read Tx Descriptor Parity checker Error"; |
| 781 |
static const struct dwxgmac3_error_desc dwxgmac3_dma_dpp_errors[32] = { |
| 782 |
{ true, "TDPES0", dpp_tx_err }, |
| 783 |
{ true, "TDPES1", dpp_tx_err }, |
| 784 |
{ true, "TDPES2", dpp_tx_err }, |
| 785 |
{ true, "TDPES3", dpp_tx_err }, |
| 786 |
{ true, "TDPES4", dpp_tx_err }, |
| 787 |
{ true, "TDPES5", dpp_tx_err }, |
| 788 |
{ true, "TDPES6", dpp_tx_err }, |
| 789 |
{ true, "TDPES7", dpp_tx_err }, |
| 790 |
{ true, "TDPES8", dpp_tx_err }, |
| 791 |
{ true, "TDPES9", dpp_tx_err }, |
| 792 |
{ true, "TDPES10", dpp_tx_err }, |
| 793 |
{ true, "TDPES11", dpp_tx_err }, |
| 794 |
{ true, "TDPES12", dpp_tx_err }, |
| 795 |
{ true, "TDPES13", dpp_tx_err }, |
| 796 |
{ true, "TDPES14", dpp_tx_err }, |
| 797 |
{ true, "TDPES15", dpp_tx_err }, |
| 798 |
{ true, "RDPES0", dpp_rx_err }, |
| 799 |
{ true, "RDPES1", dpp_rx_err }, |
| 800 |
{ true, "RDPES2", dpp_rx_err }, |
| 801 |
{ true, "RDPES3", dpp_rx_err }, |
| 802 |
{ true, "RDPES4", dpp_rx_err }, |
| 803 |
{ true, "RDPES5", dpp_rx_err }, |
| 804 |
{ true, "RDPES6", dpp_rx_err }, |
| 805 |
{ true, "RDPES7", dpp_rx_err }, |
| 806 |
{ true, "RDPES8", dpp_rx_err }, |
| 807 |
{ true, "RDPES9", dpp_rx_err }, |
| 808 |
{ true, "RDPES10", dpp_rx_err }, |
| 809 |
{ true, "RDPES11", dpp_rx_err }, |
| 810 |
{ true, "RDPES12", dpp_rx_err }, |
| 811 |
{ true, "RDPES13", dpp_rx_err }, |
| 812 |
{ true, "RDPES14", dpp_rx_err }, |
| 813 |
{ true, "RDPES15", dpp_rx_err }, |
| 814 |
}; |
| 815 |
|
| 816 |
static void dwxgmac3_handle_dma_err(struct net_device *ndev, |
| 817 |
void __iomem *ioaddr, bool correctable, |
| 818 |
struct stmmac_safety_stats *stats) |
| 819 |
{ |
| 820 |
u32 value; |
| 821 |
|
| 822 |
value = readl(ioaddr + XGMAC_DMA_ECC_INT_STATUS); |
| 823 |
writel(value, ioaddr + XGMAC_DMA_ECC_INT_STATUS); |
| 824 |
|
| 825 |
dwxgmac3_log_error(ndev, value, correctable, "DMA", |
| 826 |
dwxgmac3_dma_errors, STAT_OFF(dma_errors), stats); |
| 827 |
|
| 828 |
value = readl(ioaddr + XGMAC_DMA_DPP_INT_STATUS); |
| 829 |
writel(value, ioaddr + XGMAC_DMA_DPP_INT_STATUS); |
| 830 |
|
| 831 |
dwxgmac3_log_error(ndev, value, false, "DMA_DPP", |
| 832 |
dwxgmac3_dma_dpp_errors, |
| 833 |
STAT_OFF(dma_dpp_errors), stats); |
| 834 |
} |
| 835 |
|
| 836 |
static int |
| 837 |
dwxgmac3_safety_feat_config(void __iomem *ioaddr, unsigned int asp, |
| 838 |
struct stmmac_safety_feature_cfg *safety_cfg) |
| 839 |
{ |
| 840 |
u32 value; |
| 841 |
|
| 842 |
if (!asp) |
| 843 |
return -EINVAL; |
| 844 |
|
| 845 |
/* 1. Enable Safety Features */ |
| 846 |
writel(0x0, ioaddr + XGMAC_MTL_ECC_CONTROL); |
| 847 |
|
| 848 |
/* 2. Enable MTL Safety Interrupts */ |
| 849 |
value = readl(ioaddr + XGMAC_MTL_ECC_INT_ENABLE); |
| 850 |
value |= XGMAC_RPCEIE; /* RX Parser Memory Correctable Error */ |
| 851 |
value |= XGMAC_ECEIE; /* EST Memory Correctable Error */ |
| 852 |
value |= XGMAC_RXCEIE; /* RX Memory Correctable Error */ |
| 853 |
value |= XGMAC_TXCEIE; /* TX Memory Correctable Error */ |
| 854 |
writel(value, ioaddr + XGMAC_MTL_ECC_INT_ENABLE); |
| 855 |
|
| 856 |
/* 3. Enable DMA Safety Interrupts */ |
| 857 |
value = readl(ioaddr + XGMAC_DMA_ECC_INT_ENABLE); |
| 858 |
value |= XGMAC_DCEIE; /* Descriptor Cache Memory Correctable Error */ |
| 859 |
value |= XGMAC_TCEIE; /* TSO Memory Correctable Error */ |
| 860 |
writel(value, ioaddr + XGMAC_DMA_ECC_INT_ENABLE); |
| 861 |
|
| 862 |
/* 0x2: Without ECC or Parity Ports on External Application Interface |
| 863 |
* 0x4: Only ECC Protection for External Memory feature is selected |
| 864 |
*/ |
| 865 |
if (asp == 0x2 || asp == 0x4) |
| 866 |
return 0; |
| 867 |
|
| 868 |
/* 4. Enable Parity and Timeout for FSM */ |
| 869 |
value = readl(ioaddr + XGMAC_MAC_FSM_CONTROL); |
| 870 |
value |= XGMAC_PRTYEN; /* FSM Parity Feature */ |
| 871 |
value |= XGMAC_TMOUTEN; /* FSM Timeout Feature */ |
| 872 |
writel(value, ioaddr + XGMAC_MAC_FSM_CONTROL); |
| 873 |
|
| 874 |
/* 5. Enable Data Path Parity Protection */ |
| 875 |
value = readl(ioaddr + XGMAC_MTL_DPP_CONTROL); |
| 876 |
/* already enabled by default, explicit enable it again */ |
| 877 |
value &= ~XGMAC_DPP_DISABLE; |
| 878 |
writel(value, ioaddr + XGMAC_MTL_DPP_CONTROL); |
| 879 |
|
| 880 |
return 0; |
| 881 |
} |
| 882 |
|
| 883 |
static int dwxgmac3_safety_feat_irq_status(struct net_device *ndev, |
| 884 |
void __iomem *ioaddr, |
| 885 |
unsigned int asp, |
| 886 |
struct stmmac_safety_stats *stats) |
| 887 |
{ |
| 888 |
bool err, corr; |
| 889 |
u32 mtl, dma; |
| 890 |
int ret = 0; |
| 891 |
|
| 892 |
if (!asp) |
| 893 |
return -EINVAL; |
| 894 |
|
| 895 |
mtl = readl(ioaddr + XGMAC_MTL_SAFETY_INT_STATUS); |
| 896 |
dma = readl(ioaddr + XGMAC_DMA_SAFETY_INT_STATUS); |
| 897 |
|
| 898 |
err = (mtl & XGMAC_MCSIS) || (dma & XGMAC_MCSIS); |
| 899 |
corr = false; |
| 900 |
if (err) { |
| 901 |
dwxgmac3_handle_mac_err(ndev, ioaddr, corr, stats); |
| 902 |
ret |= !corr; |
| 903 |
} |
| 904 |
|
| 905 |
err = (mtl & (XGMAC_MEUIS | XGMAC_MECIS)) || |
| 906 |
(dma & (XGMAC_MSUIS | XGMAC_MSCIS)); |
| 907 |
corr = (mtl & XGMAC_MECIS) || (dma & XGMAC_MSCIS); |
| 908 |
if (err) { |
| 909 |
dwxgmac3_handle_mtl_err(ndev, ioaddr, corr, stats); |
| 910 |
ret |= !corr; |
| 911 |
} |
| 912 |
|
| 913 |
/* DMA_DPP_Interrupt_Status is indicated by MCSIS bit in |
| 914 |
* DMA_Safety_Interrupt_Status, so we handle DMA Data Path |
| 915 |
* Parity Errors here |
| 916 |
*/ |
| 917 |
err = dma & (XGMAC_DEUIS | XGMAC_DECIS | XGMAC_MCSIS); |
| 918 |
corr = dma & XGMAC_DECIS; |
| 919 |
if (err) { |
| 920 |
dwxgmac3_handle_dma_err(ndev, ioaddr, corr, stats); |
| 921 |
ret |= !corr; |
| 922 |
} |
| 923 |
|
| 924 |
return ret; |
| 925 |
} |
| 926 |
|
| 927 |
static const struct dwxgmac3_error { |
| 928 |
const struct dwxgmac3_error_desc *desc; |
| 929 |
} dwxgmac3_all_errors[] = { |
| 930 |
{ dwxgmac3_mac_errors }, |
| 931 |
{ dwxgmac3_mtl_errors }, |
| 932 |
{ dwxgmac3_dma_errors }, |
| 933 |
{ dwxgmac3_dma_dpp_errors }, |
| 934 |
}; |
| 935 |
|
| 936 |
static int dwxgmac3_safety_feat_dump(struct stmmac_safety_stats *stats, |
| 937 |
int index, unsigned long *count, |
| 938 |
const char **desc) |
| 939 |
{ |
| 940 |
int module = index / 32, offset = index % 32; |
| 941 |
unsigned long *ptr = (unsigned long *)stats; |
| 942 |
|
| 943 |
if (module >= ARRAY_SIZE(dwxgmac3_all_errors)) |
| 944 |
return -EINVAL; |
| 945 |
if (!dwxgmac3_all_errors[module].desc[offset].valid) |
| 946 |
return -EINVAL; |
| 947 |
if (count) |
| 948 |
*count = *(ptr + index); |
| 949 |
if (desc) |
| 950 |
*desc = dwxgmac3_all_errors[module].desc[offset].desc; |
| 951 |
return 0; |
| 952 |
} |
| 953 |
|
| 954 |
static int dwxgmac3_rxp_disable(void __iomem *ioaddr) |
| 955 |
{ |
| 956 |
u32 val = readl(ioaddr + XGMAC_MTL_OPMODE); |
| 957 |
|
| 958 |
val &= ~XGMAC_FRPE; |
| 959 |
writel(val, ioaddr + XGMAC_MTL_OPMODE); |
| 960 |
|
| 961 |
return 0; |
| 962 |
} |
| 963 |
|
| 964 |
static void dwxgmac3_rxp_enable(void __iomem *ioaddr) |
| 965 |
{ |
| 966 |
u32 val; |
| 967 |
|
| 968 |
val = readl(ioaddr + XGMAC_MTL_OPMODE); |
| 969 |
val |= XGMAC_FRPE; |
| 970 |
writel(val, ioaddr + XGMAC_MTL_OPMODE); |
| 971 |
} |
| 972 |
|
| 973 |
static int dwxgmac3_rxp_update_single_entry(void __iomem *ioaddr, |
| 974 |
struct stmmac_tc_entry *entry, |
| 975 |
int pos) |
| 976 |
{ |
| 977 |
int ret, i; |
| 978 |
|
| 979 |
for (i = 0; i < (sizeof(entry->val) / sizeof(u32)); i++) { |
| 980 |
int real_pos = pos * (sizeof(entry->val) / sizeof(u32)) + i; |
| 981 |
u32 val; |
| 982 |
|
| 983 |
/* Wait for ready */ |
| 984 |
ret = readl_poll_timeout(ioaddr + XGMAC_MTL_RXP_IACC_CTRL_ST, |
| 985 |
val, !(val & XGMAC_STARTBUSY), 1, 10000); |
| 986 |
if (ret) |
| 987 |
return ret; |
| 988 |
|
| 989 |
/* Write data */ |
| 990 |
val = *((u32 *)&entry->val + i); |
| 991 |
writel(val, ioaddr + XGMAC_MTL_RXP_IACC_DATA); |
| 992 |
|
| 993 |
/* Write pos */ |
| 994 |
val = real_pos & XGMAC_ADDR; |
| 995 |
writel(val, ioaddr + XGMAC_MTL_RXP_IACC_CTRL_ST); |
| 996 |
|
| 997 |
/* Write OP */ |
| 998 |
val |= XGMAC_WRRDN; |
| 999 |
writel(val, ioaddr + XGMAC_MTL_RXP_IACC_CTRL_ST); |
| 1000 |
|
| 1001 |
/* Start Write */ |
| 1002 |
val |= XGMAC_STARTBUSY; |
| 1003 |
writel(val, ioaddr + XGMAC_MTL_RXP_IACC_CTRL_ST); |
| 1004 |
|
| 1005 |
/* Wait for done */ |
| 1006 |
ret = readl_poll_timeout(ioaddr + XGMAC_MTL_RXP_IACC_CTRL_ST, |
| 1007 |
val, !(val & XGMAC_STARTBUSY), 1, 10000); |
| 1008 |
if (ret) |
| 1009 |
return ret; |
| 1010 |
} |
| 1011 |
|
| 1012 |
return 0; |
| 1013 |
} |
| 1014 |
|
| 1015 |
static struct stmmac_tc_entry * |
| 1016 |
dwxgmac3_rxp_get_next_entry(struct stmmac_tc_entry *entries, |
| 1017 |
unsigned int count, u32 curr_prio) |
| 1018 |
{ |
| 1019 |
struct stmmac_tc_entry *entry; |
| 1020 |
u32 min_prio = ~0x0; |
| 1021 |
int i, min_prio_idx; |
| 1022 |
bool found = false; |
| 1023 |
|
| 1024 |
for (i = count - 1; i >= 0; i--) { |
| 1025 |
entry = &entries[i]; |
| 1026 |
|
| 1027 |
/* Do not update unused entries */ |
| 1028 |
if (!entry->in_use) |
| 1029 |
continue; |
| 1030 |
/* Do not update already updated entries (i.e. fragments) */ |
| 1031 |
if (entry->in_hw) |
| 1032 |
continue; |
| 1033 |
/* Let last entry be updated last */ |
| 1034 |
if (entry->is_last) |
| 1035 |
continue; |
| 1036 |
/* Do not return fragments */ |
| 1037 |
if (entry->is_frag) |
| 1038 |
continue; |
| 1039 |
/* Check if we already checked this prio */ |
| 1040 |
if (entry->prio < curr_prio) |
| 1041 |
continue; |
| 1042 |
/* Check if this is the minimum prio */ |
| 1043 |
if (entry->prio < min_prio) { |
| 1044 |
min_prio = entry->prio; |
| 1045 |
min_prio_idx = i; |
| 1046 |
found = true; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
if (found) |
| 1051 |
return &entries[min_prio_idx]; |
| 1052 |
return NULL; |
| 1053 |
} |
| 1054 |
|
| 1055 |
static int dwxgmac3_rxp_config(void __iomem *ioaddr, |
| 1056 |
struct stmmac_tc_entry *entries, |
| 1057 |
unsigned int count) |
| 1058 |
{ |
| 1059 |
struct stmmac_tc_entry *entry, *frag; |
| 1060 |
int i, ret, nve = 0; |
| 1061 |
u32 curr_prio = 0; |
| 1062 |
u32 old_val, val; |
| 1063 |
|
| 1064 |
/* Force disable RX */ |
| 1065 |
old_val = readl(ioaddr + XGMAC_RX_CONFIG); |
| 1066 |
val = old_val & ~XGMAC_CONFIG_RE; |
| 1067 |
writel(val, ioaddr + XGMAC_RX_CONFIG); |
| 1068 |
|
| 1069 |
/* Disable RX Parser */ |
| 1070 |
ret = dwxgmac3_rxp_disable(ioaddr); |
| 1071 |
if (ret) |
| 1072 |
goto re_enable; |
| 1073 |
|
| 1074 |
/* Set all entries as NOT in HW */ |
| 1075 |
for (i = 0; i < count; i++) { |
| 1076 |
entry = &entries[i]; |
| 1077 |
entry->in_hw = false; |
| 1078 |
} |
| 1079 |
|
| 1080 |
/* Update entries by reverse order */ |
| 1081 |
while (1) { |
| 1082 |
entry = dwxgmac3_rxp_get_next_entry(entries, count, curr_prio); |
| 1083 |
if (!entry) |
| 1084 |
break; |
| 1085 |
|
| 1086 |
curr_prio = entry->prio; |
| 1087 |
frag = entry->frag_ptr; |
| 1088 |
|
| 1089 |
/* Set special fragment requirements */ |
| 1090 |
if (frag) { |
| 1091 |
entry->val.af = 0; |
| 1092 |
entry->val.rf = 0; |
| 1093 |
entry->val.nc = 1; |
| 1094 |
entry->val.ok_index = nve + 2; |
| 1095 |
} |
| 1096 |
|
| 1097 |
ret = dwxgmac3_rxp_update_single_entry(ioaddr, entry, nve); |
| 1098 |
if (ret) |
| 1099 |
goto re_enable; |
| 1100 |
|
| 1101 |
entry->table_pos = nve++; |
| 1102 |
entry->in_hw = true; |
| 1103 |
|
| 1104 |
if (frag && !frag->in_hw) { |
| 1105 |
ret = dwxgmac3_rxp_update_single_entry(ioaddr, frag, nve); |
| 1106 |
if (ret) |
| 1107 |
goto re_enable; |
| 1108 |
frag->table_pos = nve++; |
| 1109 |
frag->in_hw = true; |
| 1110 |
} |
| 1111 |
} |
| 1112 |
|
| 1113 |
if (!nve) |
| 1114 |
goto re_enable; |
| 1115 |
|
| 1116 |
/* Update all pass entry */ |
| 1117 |
for (i = 0; i < count; i++) { |
| 1118 |
entry = &entries[i]; |
| 1119 |
if (!entry->is_last) |
| 1120 |
continue; |
| 1121 |
|
| 1122 |
ret = dwxgmac3_rxp_update_single_entry(ioaddr, entry, nve); |
| 1123 |
if (ret) |
| 1124 |
goto re_enable; |
| 1125 |
|
| 1126 |
entry->table_pos = nve++; |
| 1127 |
} |
| 1128 |
|
| 1129 |
/* Assume n. of parsable entries == n. of valid entries */ |
| 1130 |
val = (nve << 16) & XGMAC_NPE; |
| 1131 |
val |= nve & XGMAC_NVE; |
| 1132 |
writel(val, ioaddr + XGMAC_MTL_RXP_CONTROL_STATUS); |
| 1133 |
|
| 1134 |
/* Enable RX Parser */ |
| 1135 |
dwxgmac3_rxp_enable(ioaddr); |
| 1136 |
|
| 1137 |
re_enable: |
| 1138 |
/* Re-enable RX */ |
| 1139 |
writel(old_val, ioaddr + XGMAC_RX_CONFIG); |
| 1140 |
return ret; |
| 1141 |
} |
| 1142 |
|
| 1143 |
static int dwxgmac2_get_mac_tx_timestamp(struct mac_device_info *hw, u64 *ts) |
| 1144 |
{ |
| 1145 |
void __iomem *ioaddr = hw->pcsr; |
| 1146 |
u32 value; |
| 1147 |
|
| 1148 |
if (readl_poll_timeout_atomic(ioaddr + XGMAC_TIMESTAMP_STATUS, |
| 1149 |
value, value & XGMAC_TXTSC, 100, 10000)) |
| 1150 |
return -EBUSY; |
| 1151 |
|
| 1152 |
*ts = readl(ioaddr + XGMAC_TXTIMESTAMP_NSEC) & XGMAC_TXTSSTSLO; |
| 1153 |
*ts += readl(ioaddr + XGMAC_TXTIMESTAMP_SEC) * 1000000000ULL; |
| 1154 |
return 0; |
| 1155 |
} |
| 1156 |
|
| 1157 |
static int dwxgmac2_flex_pps_config(void __iomem *ioaddr, int index, |
| 1158 |
struct stmmac_pps_cfg *cfg, bool enable, |
| 1159 |
u32 sub_second_inc, u32 systime_flags) |
| 1160 |
{ |
| 1161 |
u32 tnsec = readl(ioaddr + XGMAC_PPSx_TARGET_TIME_NSEC(index)); |
| 1162 |
u32 val = readl(ioaddr + XGMAC_PPS_CONTROL); |
| 1163 |
u64 period; |
| 1164 |
|
| 1165 |
if (!cfg->available) |
| 1166 |
return -EINVAL; |
| 1167 |
if (tnsec & XGMAC_TRGTBUSY0) |
| 1168 |
return -EBUSY; |
| 1169 |
if (!sub_second_inc || !systime_flags) |
| 1170 |
return -EINVAL; |
| 1171 |
|
| 1172 |
val &= ~XGMAC_PPSx_MASK(index); |
| 1173 |
|
| 1174 |
if (!enable) { |
| 1175 |
val |= XGMAC_PPSCMDx(index, XGMAC_PPSCMD_STOP); |
| 1176 |
writel(val, ioaddr + XGMAC_PPS_CONTROL); |
| 1177 |
return 0; |
| 1178 |
} |
| 1179 |
|
| 1180 |
val |= XGMAC_PPSCMDx(index, XGMAC_PPSCMD_START); |
| 1181 |
val |= XGMAC_TRGTMODSELx(index, XGMAC_PPSCMD_START); |
| 1182 |
|
| 1183 |
/* XGMAC Core has 4 PPS outputs at most. |
| 1184 |
* |
| 1185 |
* Prior XGMAC Core 3.20, Fixed mode or Flexible mode are selectable for |
| 1186 |
* PPS0 only via PPSEN0. PPS{1,2,3} are in Flexible mode by default, |
| 1187 |
* and can not be switched to Fixed mode, since PPSEN{1,2,3} are |
| 1188 |
* read-only reserved to 0. |
| 1189 |
* But we always set PPSEN{1,2,3} do not make things worse ;-) |
| 1190 |
* |
| 1191 |
* From XGMAC Core 3.20 and later, PPSEN{0,1,2,3} are writable and must |
| 1192 |
* be set, or the PPS outputs stay in Fixed PPS mode by default. |
| 1193 |
*/ |
| 1194 |
val |= XGMAC_PPSENx(index); |
| 1195 |
|
| 1196 |
writel(cfg->start.tv_sec, ioaddr + XGMAC_PPSx_TARGET_TIME_SEC(index)); |
| 1197 |
|
| 1198 |
if (!(systime_flags & PTP_TCR_TSCTRLSSR)) |
| 1199 |
cfg->start.tv_nsec = (cfg->start.tv_nsec * 1000) / 465; |
| 1200 |
writel(cfg->start.tv_nsec, ioaddr + XGMAC_PPSx_TARGET_TIME_NSEC(index)); |
| 1201 |
|
| 1202 |
period = cfg->period.tv_sec * 1000000000; |
| 1203 |
period += cfg->period.tv_nsec; |
| 1204 |
|
| 1205 |
do_div(period, sub_second_inc); |
| 1206 |
|
| 1207 |
if (period <= 1) |
| 1208 |
return -EINVAL; |
| 1209 |
|
| 1210 |
writel(period - 1, ioaddr + XGMAC_PPSx_INTERVAL(index)); |
| 1211 |
|
| 1212 |
period >>= 1; |
| 1213 |
if (period <= 1) |
| 1214 |
return -EINVAL; |
| 1215 |
|
| 1216 |
writel(period - 1, ioaddr + XGMAC_PPSx_WIDTH(index)); |
| 1217 |
|
| 1218 |
/* Finally, activate it */ |
| 1219 |
writel(val, ioaddr + XGMAC_PPS_CONTROL); |
| 1220 |
return 0; |
| 1221 |
} |
| 1222 |
|
| 1223 |
static void dwxgmac2_sarc_configure(void __iomem *ioaddr, int val) |
| 1224 |
{ |
| 1225 |
u32 value = readl(ioaddr + XGMAC_TX_CONFIG); |
| 1226 |
|
| 1227 |
value = u32_replace_bits(value, val, XGMAC_CONFIG_SARC); |
| 1228 |
|
| 1229 |
writel(value, ioaddr + XGMAC_TX_CONFIG); |
| 1230 |
} |
| 1231 |
|
| 1232 |
static int dwxgmac2_filter_wait(struct mac_device_info *hw) |
| 1233 |
{ |
| 1234 |
void __iomem *ioaddr = hw->pcsr; |
| 1235 |
u32 value; |
| 1236 |
|
| 1237 |
if (readl_poll_timeout(ioaddr + XGMAC_L3L4_ADDR_CTRL, value, |
| 1238 |
!(value & XGMAC_XB), 100, 10000)) |
| 1239 |
return -EBUSY; |
| 1240 |
return 0; |
| 1241 |
} |
| 1242 |
|
| 1243 |
static int dwxgmac2_filter_read(struct mac_device_info *hw, u32 filter_no, |
| 1244 |
u8 reg, u32 *data) |
| 1245 |
{ |
| 1246 |
void __iomem *ioaddr = hw->pcsr; |
| 1247 |
u32 value, iddr; |
| 1248 |
int ret; |
| 1249 |
|
| 1250 |
ret = dwxgmac2_filter_wait(hw); |
| 1251 |
if (ret) |
| 1252 |
return ret; |
| 1253 |
|
| 1254 |
iddr = FIELD_PREP(XGMAC_IDDR_FNUM_MASK, filter_no) | |
| 1255 |
FIELD_PREP(XGMAC_IDDR_REG_MASK, reg); |
| 1256 |
value = FIELD_PREP(XGMAC_IDDR, iddr); |
| 1257 |
value |= XGMAC_TT | XGMAC_XB; |
| 1258 |
writel(value, ioaddr + XGMAC_L3L4_ADDR_CTRL); |
| 1259 |
|
| 1260 |
ret = dwxgmac2_filter_wait(hw); |
| 1261 |
if (ret) |
| 1262 |
return ret; |
| 1263 |
|
| 1264 |
*data = readl(ioaddr + XGMAC_L3L4_DATA); |
| 1265 |
return 0; |
| 1266 |
} |
| 1267 |
|
| 1268 |
static int dwxgmac2_filter_write(struct mac_device_info *hw, u32 filter_no, |
| 1269 |
u8 reg, u32 data) |
| 1270 |
{ |
| 1271 |
void __iomem *ioaddr = hw->pcsr; |
| 1272 |
u32 value, iddr; |
| 1273 |
int ret; |
| 1274 |
|
| 1275 |
ret = dwxgmac2_filter_wait(hw); |
| 1276 |
if (ret) |
| 1277 |
return ret; |
| 1278 |
|
| 1279 |
writel(data, ioaddr + XGMAC_L3L4_DATA); |
| 1280 |
|
| 1281 |
iddr = FIELD_PREP(XGMAC_IDDR_FNUM_MASK, filter_no) | |
| 1282 |
FIELD_PREP(XGMAC_IDDR_REG_MASK, reg); |
| 1283 |
value = FIELD_PREP(XGMAC_IDDR, iddr); |
| 1284 |
value |= XGMAC_XB; |
| 1285 |
writel(value, ioaddr + XGMAC_L3L4_ADDR_CTRL); |
| 1286 |
|
| 1287 |
return dwxgmac2_filter_wait(hw); |
| 1288 |
} |
| 1289 |
|
| 1290 |
static int dwxgmac2_config_l3_filter(struct mac_device_info *hw, u32 filter_no, |
| 1291 |
bool en, bool ipv6, bool sa, bool inv, |
| 1292 |
u32 match) |
| 1293 |
{ |
| 1294 |
void __iomem *ioaddr = hw->pcsr; |
| 1295 |
u32 value; |
| 1296 |
int ret; |
| 1297 |
|
| 1298 |
value = readl(ioaddr + XGMAC_PACKET_FILTER); |
| 1299 |
value |= XGMAC_FILTER_IPFE; |
| 1300 |
writel(value, ioaddr + XGMAC_PACKET_FILTER); |
| 1301 |
|
| 1302 |
ret = dwxgmac2_filter_read(hw, filter_no, XGMAC_L3L4_CTRL, &value); |
| 1303 |
if (ret) |
| 1304 |
return ret; |
| 1305 |
|
| 1306 |
/* For IPv6 not both SA/DA filters can be active */ |
| 1307 |
if (ipv6) { |
| 1308 |
value |= XGMAC_L3PEN0; |
| 1309 |
value &= ~(XGMAC_L3SAM0 | XGMAC_L3SAIM0); |
| 1310 |
value &= ~(XGMAC_L3DAM0 | XGMAC_L3DAIM0); |
| 1311 |
if (sa) { |
| 1312 |
value |= XGMAC_L3SAM0; |
| 1313 |
if (inv) |
| 1314 |
value |= XGMAC_L3SAIM0; |
| 1315 |
} else { |
| 1316 |
value |= XGMAC_L3DAM0; |
| 1317 |
if (inv) |
| 1318 |
value |= XGMAC_L3DAIM0; |
| 1319 |
} |
| 1320 |
} else { |
| 1321 |
value &= ~XGMAC_L3PEN0; |
| 1322 |
if (sa) { |
| 1323 |
value |= XGMAC_L3SAM0; |
| 1324 |
if (inv) |
| 1325 |
value |= XGMAC_L3SAIM0; |
| 1326 |
} else { |
| 1327 |
value |= XGMAC_L3DAM0; |
| 1328 |
if (inv) |
| 1329 |
value |= XGMAC_L3DAIM0; |
| 1330 |
} |
| 1331 |
} |
| 1332 |
|
| 1333 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L3L4_CTRL, value); |
| 1334 |
if (ret) |
| 1335 |
return ret; |
| 1336 |
|
| 1337 |
if (sa) { |
| 1338 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L3_ADDR0, match); |
| 1339 |
if (ret) |
| 1340 |
return ret; |
| 1341 |
} else { |
| 1342 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L3_ADDR1, match); |
| 1343 |
if (ret) |
| 1344 |
return ret; |
| 1345 |
} |
| 1346 |
|
| 1347 |
if (!en) |
| 1348 |
return dwxgmac2_filter_write(hw, filter_no, XGMAC_L3L4_CTRL, 0); |
| 1349 |
|
| 1350 |
return 0; |
| 1351 |
} |
| 1352 |
|
| 1353 |
static int dwxgmac2_config_l4_filter(struct mac_device_info *hw, u32 filter_no, |
| 1354 |
bool en, bool udp, bool sa, bool inv, |
| 1355 |
u32 match) |
| 1356 |
{ |
| 1357 |
void __iomem *ioaddr = hw->pcsr; |
| 1358 |
u32 value; |
| 1359 |
int ret; |
| 1360 |
|
| 1361 |
value = readl(ioaddr + XGMAC_PACKET_FILTER); |
| 1362 |
value |= XGMAC_FILTER_IPFE; |
| 1363 |
writel(value, ioaddr + XGMAC_PACKET_FILTER); |
| 1364 |
|
| 1365 |
ret = dwxgmac2_filter_read(hw, filter_no, XGMAC_L3L4_CTRL, &value); |
| 1366 |
if (ret) |
| 1367 |
return ret; |
| 1368 |
|
| 1369 |
if (udp) { |
| 1370 |
value |= XGMAC_L4PEN0; |
| 1371 |
} else { |
| 1372 |
value &= ~XGMAC_L4PEN0; |
| 1373 |
} |
| 1374 |
|
| 1375 |
value &= ~(XGMAC_L4SPM0 | XGMAC_L4SPIM0); |
| 1376 |
value &= ~(XGMAC_L4DPM0 | XGMAC_L4DPIM0); |
| 1377 |
if (sa) { |
| 1378 |
value |= XGMAC_L4SPM0; |
| 1379 |
if (inv) |
| 1380 |
value |= XGMAC_L4SPIM0; |
| 1381 |
} else { |
| 1382 |
value |= XGMAC_L4DPM0; |
| 1383 |
if (inv) |
| 1384 |
value |= XGMAC_L4DPIM0; |
| 1385 |
} |
| 1386 |
|
| 1387 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L3L4_CTRL, value); |
| 1388 |
if (ret) |
| 1389 |
return ret; |
| 1390 |
|
| 1391 |
if (sa) { |
| 1392 |
value = FIELD_PREP(XGMAC_L4SP0, match); |
| 1393 |
|
| 1394 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L4_ADDR, value); |
| 1395 |
if (ret) |
| 1396 |
return ret; |
| 1397 |
} else { |
| 1398 |
value = FIELD_PREP(XGMAC_L4DP0, match); |
| 1399 |
|
| 1400 |
ret = dwxgmac2_filter_write(hw, filter_no, XGMAC_L4_ADDR, value); |
| 1401 |
if (ret) |
| 1402 |
return ret; |
| 1403 |
} |
| 1404 |
|
| 1405 |
if (!en) |
| 1406 |
return dwxgmac2_filter_write(hw, filter_no, XGMAC_L3L4_CTRL, 0); |
| 1407 |
|
| 1408 |
return 0; |
| 1409 |
} |
| 1410 |
|
| 1411 |
static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en, |
| 1412 |
u32 addr) |
| 1413 |
{ |
| 1414 |
void __iomem *ioaddr = hw->pcsr; |
| 1415 |
u32 value; |
| 1416 |
|
| 1417 |
writel(addr, ioaddr + XGMAC_ARP_ADDR); |
| 1418 |
|
| 1419 |
value = readl(ioaddr + XGMAC_RX_CONFIG); |
| 1420 |
if (en) |
| 1421 |
value |= XGMAC_CONFIG_ARPEN; |
| 1422 |
else |
| 1423 |
value &= ~XGMAC_CONFIG_ARPEN; |
| 1424 |
writel(value, ioaddr + XGMAC_RX_CONFIG); |
| 1425 |
} |
| 1426 |
|
| 1427 |
const struct stmmac_ops dwxgmac210_ops = { |
| 1428 |
.core_init = dwxgmac2_core_init, |
| 1429 |
.irq_modify = dwxgmac2_irq_modify, |
| 1430 |
.update_caps = dwxgmac2_update_caps, |
| 1431 |
.set_mac = dwxgmac2_set_mac, |
| 1432 |
.rx_ipc = dwxgmac2_rx_ipc, |
| 1433 |
.rx_queue_enable = dwxgmac2_rx_queue_enable, |
| 1434 |
.rx_queue_prio = dwxgmac2_rx_queue_prio, |
| 1435 |
.tx_queue_prio = dwxgmac2_tx_queue_prio, |
| 1436 |
.rx_queue_routing = dwxgmac2_rx_queue_routing, |
| 1437 |
.prog_mtl_rx_algorithms = dwxgmac2_prog_mtl_rx_algorithms, |
| 1438 |
.prog_mtl_tx_algorithms = dwxgmac2_prog_mtl_tx_algorithms, |
| 1439 |
.set_mtl_tx_queue_weight = dwxgmac2_set_mtl_tx_queue_weight, |
| 1440 |
.map_mtl_to_dma = dwxgmac2_map_mtl_to_dma, |
| 1441 |
.config_cbs = dwxgmac2_config_cbs, |
| 1442 |
.dump_regs = dwxgmac2_dump_regs, |
| 1443 |
.host_irq_status = dwxgmac2_host_irq_status, |
| 1444 |
.host_mtl_irq_status = dwxgmac2_host_mtl_irq_status, |
| 1445 |
.flow_ctrl = dwxgmac2_flow_ctrl, |
| 1446 |
.pmt = dwxgmac2_pmt, |
| 1447 |
.set_umac_addr = dwxgmac2_set_umac_addr, |
| 1448 |
.get_umac_addr = dwxgmac2_get_umac_addr, |
| 1449 |
.set_lpi_mode = dwxgmac2_set_lpi_mode, |
| 1450 |
.set_eee_timer = dwxgmac2_set_eee_timer, |
| 1451 |
.set_eee_pls = dwxgmac2_set_eee_pls, |
| 1452 |
.debug = NULL, |
| 1453 |
.set_filter = dwxgmac2_set_filter, |
| 1454 |
.safety_feat_config = dwxgmac3_safety_feat_config, |
| 1455 |
.safety_feat_irq_status = dwxgmac3_safety_feat_irq_status, |
| 1456 |
.safety_feat_dump = dwxgmac3_safety_feat_dump, |
| 1457 |
.set_mac_loopback = dwxgmac2_set_mac_loopback, |
| 1458 |
.rss_configure = dwxgmac2_rss_configure, |
| 1459 |
.rxp_config = dwxgmac3_rxp_config, |
| 1460 |
.get_mac_tx_timestamp = dwxgmac2_get_mac_tx_timestamp, |
| 1461 |
.flex_pps_config = dwxgmac2_flex_pps_config, |
| 1462 |
.sarc_configure = dwxgmac2_sarc_configure, |
| 1463 |
.config_l3_filter = dwxgmac2_config_l3_filter, |
| 1464 |
.config_l4_filter = dwxgmac2_config_l4_filter, |
| 1465 |
.set_arp_offload = dwxgmac2_set_arp_offload, |
| 1466 |
.fpe_map_preemption_class = dwxgmac3_fpe_map_preemption_class, |
| 1467 |
}; |
| 1468 |
|
| 1469 |
static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode, |
| 1470 |
u32 queue) |
| 1471 |
{ |
| 1472 |
void __iomem *ioaddr = hw->pcsr; |
| 1473 |
u32 value; |
| 1474 |
|
| 1475 |
value = readl(ioaddr + XLGMAC_RXQ_ENABLE_CTRL0) & ~XGMAC_RXQEN(queue); |
| 1476 |
if (mode == MTL_QUEUE_AVB) |
| 1477 |
value |= 0x1 << XGMAC_RXQEN_SHIFT(queue); |
| 1478 |
else if (mode == MTL_QUEUE_DCB) |
| 1479 |
value |= 0x2 << XGMAC_RXQEN_SHIFT(queue); |
| 1480 |
writel(value, ioaddr + XLGMAC_RXQ_ENABLE_CTRL0); |
| 1481 |
} |
| 1482 |
|
| 1483 |
const struct stmmac_ops dwxlgmac2_ops = { |
| 1484 |
.core_init = dwxgmac2_core_init, |
| 1485 |
.irq_modify = dwxgmac2_irq_modify, |
| 1486 |
.set_mac = dwxgmac2_set_mac, |
| 1487 |
.rx_ipc = dwxgmac2_rx_ipc, |
| 1488 |
.rx_queue_enable = dwxlgmac2_rx_queue_enable, |
| 1489 |
.rx_queue_prio = dwxgmac2_rx_queue_prio, |
| 1490 |
.tx_queue_prio = dwxgmac2_tx_queue_prio, |
| 1491 |
.rx_queue_routing = dwxgmac2_rx_queue_routing, |
| 1492 |
.prog_mtl_rx_algorithms = dwxgmac2_prog_mtl_rx_algorithms, |
| 1493 |
.prog_mtl_tx_algorithms = dwxgmac2_prog_mtl_tx_algorithms, |
| 1494 |
.set_mtl_tx_queue_weight = dwxgmac2_set_mtl_tx_queue_weight, |
| 1495 |
.map_mtl_to_dma = dwxgmac2_map_mtl_to_dma, |
| 1496 |
.config_cbs = dwxgmac2_config_cbs, |
| 1497 |
.dump_regs = dwxgmac2_dump_regs, |
| 1498 |
.host_irq_status = dwxgmac2_host_irq_status, |
| 1499 |
.host_mtl_irq_status = dwxgmac2_host_mtl_irq_status, |
| 1500 |
.flow_ctrl = dwxgmac2_flow_ctrl, |
| 1501 |
.pmt = dwxgmac2_pmt, |
| 1502 |
.set_umac_addr = dwxgmac2_set_umac_addr, |
| 1503 |
.get_umac_addr = dwxgmac2_get_umac_addr, |
| 1504 |
.set_lpi_mode = dwxgmac2_set_lpi_mode, |
| 1505 |
.set_eee_timer = dwxgmac2_set_eee_timer, |
| 1506 |
.set_eee_pls = dwxgmac2_set_eee_pls, |
| 1507 |
.debug = NULL, |
| 1508 |
.set_filter = dwxgmac2_set_filter, |
| 1509 |
.safety_feat_config = dwxgmac3_safety_feat_config, |
| 1510 |
.safety_feat_irq_status = dwxgmac3_safety_feat_irq_status, |
| 1511 |
.safety_feat_dump = dwxgmac3_safety_feat_dump, |
| 1512 |
.set_mac_loopback = dwxgmac2_set_mac_loopback, |
| 1513 |
.rss_configure = dwxgmac2_rss_configure, |
| 1514 |
.rxp_config = dwxgmac3_rxp_config, |
| 1515 |
.get_mac_tx_timestamp = dwxgmac2_get_mac_tx_timestamp, |
| 1516 |
.flex_pps_config = dwxgmac2_flex_pps_config, |
| 1517 |
.sarc_configure = dwxgmac2_sarc_configure, |
| 1518 |
.config_l3_filter = dwxgmac2_config_l3_filter, |
| 1519 |
.config_l4_filter = dwxgmac2_config_l4_filter, |
| 1520 |
.set_arp_offload = dwxgmac2_set_arp_offload, |
| 1521 |
.fpe_map_preemption_class = dwxgmac3_fpe_map_preemption_class, |
| 1522 |
}; |
| 1523 |
|
| 1524 |
int dwxgmac2_setup(struct stmmac_priv *priv) |
| 1525 |
{ |
| 1526 |
struct mac_device_info *mac = priv->hw; |
| 1527 |
|
| 1528 |
dev_info(priv->device, "\tXGMAC2\n"); |
| 1529 |
|
| 1530 |
priv->dev->priv_flags |= IFF_UNICAST_FLT; |
| 1531 |
mac->pcsr = priv->ioaddr; |
| 1532 |
mac->multicast_filter_bins = priv->plat->multicast_filter_bins; |
| 1533 |
mac->unicast_filter_entries = priv->plat->unicast_filter_entries; |
| 1534 |
mac->mcast_bits_log2 = 0; |
| 1535 |
|
| 1536 |
if (mac->multicast_filter_bins) |
| 1537 |
mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins); |
| 1538 |
|
| 1539 |
mac->link.caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | |
| 1540 |
MAC_10 | MAC_100 | MAC_1000FD | |
| 1541 |
MAC_2500FD | MAC_5000FD | MAC_10000FD; |
| 1542 |
mac->link.duplex = 0; |
| 1543 |
mac->link.speed10 = XGMAC_CONFIG_SS_10_MII; |
| 1544 |
mac->link.speed100 = XGMAC_CONFIG_SS_100_MII; |
| 1545 |
mac->link.speed1000 = XGMAC_CONFIG_SS_1000_GMII; |
| 1546 |
mac->link.speed2500 = XGMAC_CONFIG_SS_2500_GMII; |
| 1547 |
mac->link.xgmii.speed2500 = XGMAC_CONFIG_SS_2500; |
| 1548 |
mac->link.xgmii.speed5000 = XGMAC_CONFIG_SS_5000; |
| 1549 |
mac->link.xgmii.speed10000 = XGMAC_CONFIG_SS_10000; |
| 1550 |
mac->link.speed_mask = XGMAC_CONFIG_SS_MASK; |
| 1551 |
|
| 1552 |
mac->mii.addr = XGMAC_MDIO_ADDR; |
| 1553 |
mac->mii.data = XGMAC_MDIO_DATA; |
| 1554 |
mac->mii.addr_shift = 16; |
| 1555 |
mac->mii.addr_mask = GENMASK(20, 16); |
| 1556 |
mac->mii.reg_shift = 0; |
| 1557 |
mac->mii.reg_mask = GENMASK(15, 0); |
| 1558 |
mac->mii.clk_csr_shift = 19; |
| 1559 |
mac->mii.clk_csr_mask = GENMASK(21, 19); |
| 1560 |
mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr); |
| 1561 |
|
| 1562 |
return 0; |
| 1563 |
} |
| 1564 |
|
| 1565 |
int dwxlgmac2_setup(struct stmmac_priv *priv) |
| 1566 |
{ |
| 1567 |
struct mac_device_info *mac = priv->hw; |
| 1568 |
|
| 1569 |
dev_info(priv->device, "\tXLGMAC\n"); |
| 1570 |
|
| 1571 |
priv->dev->priv_flags |= IFF_UNICAST_FLT; |
| 1572 |
mac->pcsr = priv->ioaddr; |
| 1573 |
mac->multicast_filter_bins = priv->plat->multicast_filter_bins; |
| 1574 |
mac->unicast_filter_entries = priv->plat->unicast_filter_entries; |
| 1575 |
mac->mcast_bits_log2 = 0; |
| 1576 |
|
| 1577 |
if (mac->multicast_filter_bins) |
| 1578 |
mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins); |
| 1579 |
|
| 1580 |
mac->link.caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | |
| 1581 |
MAC_1000FD | MAC_2500FD | MAC_5000FD | |
| 1582 |
MAC_10000FD | MAC_25000FD | |
| 1583 |
MAC_40000FD | MAC_50000FD | |
| 1584 |
MAC_100000FD; |
| 1585 |
mac->link.duplex = 0; |
| 1586 |
mac->link.speed1000 = XLGMAC_CONFIG_SS_1000; |
| 1587 |
mac->link.speed2500 = XLGMAC_CONFIG_SS_2500; |
| 1588 |
mac->link.xgmii.speed10000 = XLGMAC_CONFIG_SS_10G; |
| 1589 |
mac->link.xlgmii.speed25000 = XLGMAC_CONFIG_SS_25G; |
| 1590 |
mac->link.xlgmii.speed40000 = XLGMAC_CONFIG_SS_40G; |
| 1591 |
mac->link.xlgmii.speed50000 = XLGMAC_CONFIG_SS_50G; |
| 1592 |
mac->link.xlgmii.speed100000 = XLGMAC_CONFIG_SS_100G; |
| 1593 |
mac->link.speed_mask = XLGMAC_CONFIG_SS; |
| 1594 |
|
| 1595 |
mac->mii.addr = XGMAC_MDIO_ADDR; |
| 1596 |
mac->mii.data = XGMAC_MDIO_DATA; |
| 1597 |
mac->mii.addr_shift = 16; |
| 1598 |
mac->mii.addr_mask = GENMASK(20, 16); |
| 1599 |
mac->mii.reg_shift = 0; |
| 1600 |
mac->mii.reg_mask = GENMASK(15, 0); |
| 1601 |
mac->mii.clk_csr_shift = 19; |
| 1602 |
mac->mii.clk_csr_mask = GENMASK(21, 19); |
| 1603 |
|
| 1604 |
return 0; |
| 1605 |
} |