| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Texas Instruments Ethernet Switch Driver ethtool intf |
| 4 |
* |
| 5 |
* Copyright (C) 2019 Texas Instruments |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/if_ether.h> |
| 9 |
#include <linux/if_vlan.h> |
| 10 |
#include <linux/kmemleak.h> |
| 11 |
#include <linux/module.h> |
| 12 |
#include <linux/netdevice.h> |
| 13 |
#include <linux/net_tstamp.h> |
| 14 |
#include <linux/phy.h> |
| 15 |
#include <linux/pm_runtime.h> |
| 16 |
#include <linux/skbuff.h> |
| 17 |
|
| 18 |
#include "cpsw.h" |
| 19 |
#include "cpts.h" |
| 20 |
#include "cpsw_ale.h" |
| 21 |
#include "cpsw_priv.h" |
| 22 |
#include "davinci_cpdma.h" |
| 23 |
|
| 24 |
struct cpsw_hw_stats { |
| 25 |
u32 rxgoodframes; |
| 26 |
u32 rxbroadcastframes; |
| 27 |
u32 rxmulticastframes; |
| 28 |
u32 rxpauseframes; |
| 29 |
u32 rxcrcerrors; |
| 30 |
u32 rxaligncodeerrors; |
| 31 |
u32 rxoversizedframes; |
| 32 |
u32 rxjabberframes; |
| 33 |
u32 rxundersizedframes; |
| 34 |
u32 rxfragments; |
| 35 |
u32 __pad_0[2]; |
| 36 |
u32 rxoctets; |
| 37 |
u32 txgoodframes; |
| 38 |
u32 txbroadcastframes; |
| 39 |
u32 txmulticastframes; |
| 40 |
u32 txpauseframes; |
| 41 |
u32 txdeferredframes; |
| 42 |
u32 txcollisionframes; |
| 43 |
u32 txsinglecollframes; |
| 44 |
u32 txmultcollframes; |
| 45 |
u32 txexcessivecollisions; |
| 46 |
u32 txlatecollisions; |
| 47 |
u32 txunderrun; |
| 48 |
u32 txcarriersenseerrors; |
| 49 |
u32 txoctets; |
| 50 |
u32 octetframes64; |
| 51 |
u32 octetframes65t127; |
| 52 |
u32 octetframes128t255; |
| 53 |
u32 octetframes256t511; |
| 54 |
u32 octetframes512t1023; |
| 55 |
u32 octetframes1024tup; |
| 56 |
u32 netoctets; |
| 57 |
u32 rxsofoverruns; |
| 58 |
u32 rxmofoverruns; |
| 59 |
u32 rxdmaoverruns; |
| 60 |
}; |
| 61 |
|
| 62 |
struct cpsw_stats { |
| 63 |
char stat_string[ETH_GSTRING_LEN]; |
| 64 |
int type; |
| 65 |
int sizeof_stat; |
| 66 |
int stat_offset; |
| 67 |
}; |
| 68 |
|
| 69 |
enum { |
| 70 |
CPSW_STATS, |
| 71 |
CPDMA_RX_STATS, |
| 72 |
CPDMA_TX_STATS, |
| 73 |
}; |
| 74 |
|
| 75 |
#define CPSW_STAT(m) CPSW_STATS, \ |
| 76 |
sizeof_field(struct cpsw_hw_stats, m), \ |
| 77 |
offsetof(struct cpsw_hw_stats, m) |
| 78 |
#define CPDMA_RX_STAT(m) CPDMA_RX_STATS, \ |
| 79 |
sizeof_field(struct cpdma_chan_stats, m), \ |
| 80 |
offsetof(struct cpdma_chan_stats, m) |
| 81 |
#define CPDMA_TX_STAT(m) CPDMA_TX_STATS, \ |
| 82 |
sizeof_field(struct cpdma_chan_stats, m), \ |
| 83 |
offsetof(struct cpdma_chan_stats, m) |
| 84 |
|
| 85 |
static const struct cpsw_stats cpsw_gstrings_stats[] = { |
| 86 |
{ "Good Rx Frames", CPSW_STAT(rxgoodframes) }, |
| 87 |
{ "Broadcast Rx Frames", CPSW_STAT(rxbroadcastframes) }, |
| 88 |
{ "Multicast Rx Frames", CPSW_STAT(rxmulticastframes) }, |
| 89 |
{ "Pause Rx Frames", CPSW_STAT(rxpauseframes) }, |
| 90 |
{ "Rx CRC Errors", CPSW_STAT(rxcrcerrors) }, |
| 91 |
{ "Rx Align/Code Errors", CPSW_STAT(rxaligncodeerrors) }, |
| 92 |
{ "Oversize Rx Frames", CPSW_STAT(rxoversizedframes) }, |
| 93 |
{ "Rx Jabbers", CPSW_STAT(rxjabberframes) }, |
| 94 |
{ "Undersize (Short) Rx Frames", CPSW_STAT(rxundersizedframes) }, |
| 95 |
{ "Rx Fragments", CPSW_STAT(rxfragments) }, |
| 96 |
{ "Rx Octets", CPSW_STAT(rxoctets) }, |
| 97 |
{ "Good Tx Frames", CPSW_STAT(txgoodframes) }, |
| 98 |
{ "Broadcast Tx Frames", CPSW_STAT(txbroadcastframes) }, |
| 99 |
{ "Multicast Tx Frames", CPSW_STAT(txmulticastframes) }, |
| 100 |
{ "Pause Tx Frames", CPSW_STAT(txpauseframes) }, |
| 101 |
{ "Deferred Tx Frames", CPSW_STAT(txdeferredframes) }, |
| 102 |
{ "Collisions", CPSW_STAT(txcollisionframes) }, |
| 103 |
{ "Single Collision Tx Frames", CPSW_STAT(txsinglecollframes) }, |
| 104 |
{ "Multiple Collision Tx Frames", CPSW_STAT(txmultcollframes) }, |
| 105 |
{ "Excessive Collisions", CPSW_STAT(txexcessivecollisions) }, |
| 106 |
{ "Late Collisions", CPSW_STAT(txlatecollisions) }, |
| 107 |
{ "Tx Underrun", CPSW_STAT(txunderrun) }, |
| 108 |
{ "Carrier Sense Errors", CPSW_STAT(txcarriersenseerrors) }, |
| 109 |
{ "Tx Octets", CPSW_STAT(txoctets) }, |
| 110 |
{ "Rx + Tx 64 Octet Frames", CPSW_STAT(octetframes64) }, |
| 111 |
{ "Rx + Tx 65-127 Octet Frames", CPSW_STAT(octetframes65t127) }, |
| 112 |
{ "Rx + Tx 128-255 Octet Frames", CPSW_STAT(octetframes128t255) }, |
| 113 |
{ "Rx + Tx 256-511 Octet Frames", CPSW_STAT(octetframes256t511) }, |
| 114 |
{ "Rx + Tx 512-1023 Octet Frames", CPSW_STAT(octetframes512t1023) }, |
| 115 |
{ "Rx + Tx 1024-Up Octet Frames", CPSW_STAT(octetframes1024tup) }, |
| 116 |
{ "Net Octets", CPSW_STAT(netoctets) }, |
| 117 |
{ "Rx Start of Frame Overruns", CPSW_STAT(rxsofoverruns) }, |
| 118 |
{ "Rx Middle of Frame Overruns", CPSW_STAT(rxmofoverruns) }, |
| 119 |
{ "Rx DMA Overruns", CPSW_STAT(rxdmaoverruns) }, |
| 120 |
}; |
| 121 |
|
| 122 |
static const struct cpsw_stats cpsw_gstrings_ch_stats[] = { |
| 123 |
{ "head_enqueue", CPDMA_RX_STAT(head_enqueue) }, |
| 124 |
{ "tail_enqueue", CPDMA_RX_STAT(tail_enqueue) }, |
| 125 |
{ "pad_enqueue", CPDMA_RX_STAT(pad_enqueue) }, |
| 126 |
{ "misqueued", CPDMA_RX_STAT(misqueued) }, |
| 127 |
{ "desc_alloc_fail", CPDMA_RX_STAT(desc_alloc_fail) }, |
| 128 |
{ "pad_alloc_fail", CPDMA_RX_STAT(pad_alloc_fail) }, |
| 129 |
{ "runt_receive_buf", CPDMA_RX_STAT(runt_receive_buff) }, |
| 130 |
{ "runt_transmit_buf", CPDMA_RX_STAT(runt_transmit_buff) }, |
| 131 |
{ "empty_dequeue", CPDMA_RX_STAT(empty_dequeue) }, |
| 132 |
{ "busy_dequeue", CPDMA_RX_STAT(busy_dequeue) }, |
| 133 |
{ "good_dequeue", CPDMA_RX_STAT(good_dequeue) }, |
| 134 |
{ "requeue", CPDMA_RX_STAT(requeue) }, |
| 135 |
{ "teardown_dequeue", CPDMA_RX_STAT(teardown_dequeue) }, |
| 136 |
}; |
| 137 |
|
| 138 |
#define CPSW_STATS_COMMON_LEN ARRAY_SIZE(cpsw_gstrings_stats) |
| 139 |
#define CPSW_STATS_CH_LEN ARRAY_SIZE(cpsw_gstrings_ch_stats) |
| 140 |
|
| 141 |
u32 cpsw_get_msglevel(struct net_device *ndev) |
| 142 |
{ |
| 143 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 144 |
|
| 145 |
return priv->msg_enable; |
| 146 |
} |
| 147 |
|
| 148 |
void cpsw_set_msglevel(struct net_device *ndev, u32 value) |
| 149 |
{ |
| 150 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 151 |
|
| 152 |
priv->msg_enable = value; |
| 153 |
} |
| 154 |
|
| 155 |
int cpsw_get_coalesce(struct net_device *ndev, struct ethtool_coalesce *coal, |
| 156 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 157 |
struct netlink_ext_ack *extack) |
| 158 |
{ |
| 159 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 160 |
|
| 161 |
coal->rx_coalesce_usecs = cpsw->coal_intvl; |
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
int cpsw_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *coal, |
| 166 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 167 |
struct netlink_ext_ack *extack) |
| 168 |
{ |
| 169 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 170 |
u32 int_ctrl; |
| 171 |
u32 num_interrupts = 0; |
| 172 |
u32 prescale = 0; |
| 173 |
u32 addnl_dvdr = 1; |
| 174 |
u32 coal_intvl = 0; |
| 175 |
struct cpsw_common *cpsw = priv->cpsw; |
| 176 |
|
| 177 |
coal_intvl = coal->rx_coalesce_usecs; |
| 178 |
|
| 179 |
int_ctrl = readl(&cpsw->wr_regs->int_control); |
| 180 |
prescale = cpsw->bus_freq_mhz * 4; |
| 181 |
|
| 182 |
if (!coal->rx_coalesce_usecs) { |
| 183 |
int_ctrl &= ~(CPSW_INTPRESCALE_MASK | CPSW_INTPACEEN); |
| 184 |
goto update_return; |
| 185 |
} |
| 186 |
|
| 187 |
if (coal_intvl < CPSW_CMINTMIN_INTVL) |
| 188 |
coal_intvl = CPSW_CMINTMIN_INTVL; |
| 189 |
|
| 190 |
if (coal_intvl > CPSW_CMINTMAX_INTVL) { |
| 191 |
/* Interrupt pacer works with 4us Pulse, we can |
| 192 |
* throttle further by dilating the 4us pulse. |
| 193 |
*/ |
| 194 |
addnl_dvdr = CPSW_INTPRESCALE_MASK / prescale; |
| 195 |
|
| 196 |
if (addnl_dvdr > 1) { |
| 197 |
prescale *= addnl_dvdr; |
| 198 |
if (coal_intvl > (CPSW_CMINTMAX_INTVL * addnl_dvdr)) |
| 199 |
coal_intvl = (CPSW_CMINTMAX_INTVL |
| 200 |
* addnl_dvdr); |
| 201 |
} else { |
| 202 |
addnl_dvdr = 1; |
| 203 |
coal_intvl = CPSW_CMINTMAX_INTVL; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
num_interrupts = (1000 * addnl_dvdr) / coal_intvl; |
| 208 |
writel(num_interrupts, &cpsw->wr_regs->rx_imax); |
| 209 |
writel(num_interrupts, &cpsw->wr_regs->tx_imax); |
| 210 |
|
| 211 |
int_ctrl |= CPSW_INTPACEEN; |
| 212 |
int_ctrl &= (~CPSW_INTPRESCALE_MASK); |
| 213 |
int_ctrl |= (prescale & CPSW_INTPRESCALE_MASK); |
| 214 |
|
| 215 |
update_return: |
| 216 |
writel(int_ctrl, &cpsw->wr_regs->int_control); |
| 217 |
|
| 218 |
cpsw_notice(priv, timer, "Set coalesce to %d usecs.\n", coal_intvl); |
| 219 |
cpsw->coal_intvl = coal_intvl; |
| 220 |
|
| 221 |
return 0; |
| 222 |
} |
| 223 |
|
| 224 |
int cpsw_get_sset_count(struct net_device *ndev, int sset) |
| 225 |
{ |
| 226 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 227 |
|
| 228 |
switch (sset) { |
| 229 |
case ETH_SS_STATS: |
| 230 |
return (CPSW_STATS_COMMON_LEN + |
| 231 |
(cpsw->rx_ch_num + cpsw->tx_ch_num) * |
| 232 |
CPSW_STATS_CH_LEN); |
| 233 |
default: |
| 234 |
return -EOPNOTSUPP; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
static void cpsw_add_ch_strings(u8 **p, int ch_num, int rx_dir) |
| 239 |
{ |
| 240 |
int ch_stats_len; |
| 241 |
int line; |
| 242 |
int i; |
| 243 |
|
| 244 |
ch_stats_len = CPSW_STATS_CH_LEN * ch_num; |
| 245 |
for (i = 0; i < ch_stats_len; i++) { |
| 246 |
line = i % CPSW_STATS_CH_LEN; |
| 247 |
snprintf(*p, ETH_GSTRING_LEN, |
| 248 |
"%s DMA chan %ld: %s", rx_dir ? "Rx" : "Tx", |
| 249 |
(long)(i / CPSW_STATS_CH_LEN), |
| 250 |
cpsw_gstrings_ch_stats[line].stat_string); |
| 251 |
*p += ETH_GSTRING_LEN; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data) |
| 256 |
{ |
| 257 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 258 |
u8 *p = data; |
| 259 |
int i; |
| 260 |
|
| 261 |
switch (stringset) { |
| 262 |
case ETH_SS_STATS: |
| 263 |
for (i = 0; i < CPSW_STATS_COMMON_LEN; i++) { |
| 264 |
memcpy(p, cpsw_gstrings_stats[i].stat_string, |
| 265 |
ETH_GSTRING_LEN); |
| 266 |
p += ETH_GSTRING_LEN; |
| 267 |
} |
| 268 |
|
| 269 |
cpsw_add_ch_strings(&p, cpsw->rx_ch_num, 1); |
| 270 |
cpsw_add_ch_strings(&p, cpsw->tx_ch_num, 0); |
| 271 |
break; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
void cpsw_get_ethtool_stats(struct net_device *ndev, |
| 276 |
struct ethtool_stats *stats, u64 *data) |
| 277 |
{ |
| 278 |
u8 *p; |
| 279 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 280 |
struct cpdma_chan_stats ch_stats; |
| 281 |
int i, l, ch; |
| 282 |
|
| 283 |
/* Collect Davinci CPDMA stats for Rx and Tx Channel */ |
| 284 |
for (l = 0; l < CPSW_STATS_COMMON_LEN; l++) |
| 285 |
data[l] = readl(cpsw->hw_stats + |
| 286 |
cpsw_gstrings_stats[l].stat_offset); |
| 287 |
|
| 288 |
for (ch = 0; ch < cpsw->rx_ch_num; ch++) { |
| 289 |
cpdma_chan_get_stats(cpsw->rxv[ch].ch, &ch_stats); |
| 290 |
for (i = 0; i < CPSW_STATS_CH_LEN; i++, l++) { |
| 291 |
p = (u8 *)&ch_stats + |
| 292 |
cpsw_gstrings_ch_stats[i].stat_offset; |
| 293 |
data[l] = *(u32 *)p; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
for (ch = 0; ch < cpsw->tx_ch_num; ch++) { |
| 298 |
cpdma_chan_get_stats(cpsw->txv[ch].ch, &ch_stats); |
| 299 |
for (i = 0; i < CPSW_STATS_CH_LEN; i++, l++) { |
| 300 |
p = (u8 *)&ch_stats + |
| 301 |
cpsw_gstrings_ch_stats[i].stat_offset; |
| 302 |
data[l] = *(u32 *)p; |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
void cpsw_get_pauseparam(struct net_device *ndev, |
| 308 |
struct ethtool_pauseparam *pause) |
| 309 |
{ |
| 310 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 311 |
|
| 312 |
pause->autoneg = AUTONEG_DISABLE; |
| 313 |
pause->rx_pause = priv->rx_pause ? true : false; |
| 314 |
pause->tx_pause = priv->tx_pause ? true : false; |
| 315 |
} |
| 316 |
|
| 317 |
void cpsw_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 318 |
{ |
| 319 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 320 |
struct cpsw_common *cpsw = priv->cpsw; |
| 321 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 322 |
|
| 323 |
wol->supported = 0; |
| 324 |
wol->wolopts = 0; |
| 325 |
|
| 326 |
if (cpsw->slaves[slave_no].phy) |
| 327 |
phy_ethtool_get_wol(cpsw->slaves[slave_no].phy, wol); |
| 328 |
} |
| 329 |
|
| 330 |
int cpsw_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) |
| 331 |
{ |
| 332 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 333 |
struct cpsw_common *cpsw = priv->cpsw; |
| 334 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 335 |
|
| 336 |
if (cpsw->slaves[slave_no].phy) |
| 337 |
return phy_ethtool_set_wol(cpsw->slaves[slave_no].phy, wol); |
| 338 |
else |
| 339 |
return -EOPNOTSUPP; |
| 340 |
} |
| 341 |
|
| 342 |
int cpsw_get_regs_len(struct net_device *ndev) |
| 343 |
{ |
| 344 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 345 |
|
| 346 |
return cpsw_ale_get_num_entries(cpsw->ale) * |
| 347 |
ALE_ENTRY_WORDS * sizeof(u32); |
| 348 |
} |
| 349 |
|
| 350 |
void cpsw_get_regs(struct net_device *ndev, struct ethtool_regs *regs, void *p) |
| 351 |
{ |
| 352 |
u32 *reg = p; |
| 353 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 354 |
|
| 355 |
/* update CPSW IP version */ |
| 356 |
regs->version = cpsw->version; |
| 357 |
|
| 358 |
cpsw_ale_dump(cpsw->ale, reg); |
| 359 |
} |
| 360 |
|
| 361 |
int cpsw_ethtool_op_begin(struct net_device *ndev) |
| 362 |
{ |
| 363 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 364 |
struct cpsw_common *cpsw = priv->cpsw; |
| 365 |
int ret; |
| 366 |
|
| 367 |
ret = pm_runtime_resume_and_get(cpsw->dev); |
| 368 |
if (ret < 0) |
| 369 |
cpsw_err(priv, drv, "ethtool begin failed %d\n", ret); |
| 370 |
|
| 371 |
return ret; |
| 372 |
} |
| 373 |
|
| 374 |
void cpsw_ethtool_op_complete(struct net_device *ndev) |
| 375 |
{ |
| 376 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 377 |
|
| 378 |
pm_runtime_put(priv->cpsw->dev); |
| 379 |
} |
| 380 |
|
| 381 |
void cpsw_get_channels(struct net_device *ndev, struct ethtool_channels *ch) |
| 382 |
{ |
| 383 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 384 |
|
| 385 |
ch->max_rx = cpsw->quirk_irq ? 1 : CPSW_MAX_QUEUES; |
| 386 |
ch->max_tx = cpsw->quirk_irq ? 1 : CPSW_MAX_QUEUES; |
| 387 |
ch->max_combined = 0; |
| 388 |
ch->max_other = 0; |
| 389 |
ch->other_count = 0; |
| 390 |
ch->rx_count = cpsw->rx_ch_num; |
| 391 |
ch->tx_count = cpsw->tx_ch_num; |
| 392 |
ch->combined_count = 0; |
| 393 |
} |
| 394 |
|
| 395 |
int cpsw_get_link_ksettings(struct net_device *ndev, |
| 396 |
struct ethtool_link_ksettings *ecmd) |
| 397 |
{ |
| 398 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 399 |
struct cpsw_common *cpsw = priv->cpsw; |
| 400 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 401 |
|
| 402 |
if (!cpsw->slaves[slave_no].phy) |
| 403 |
return -EOPNOTSUPP; |
| 404 |
|
| 405 |
phy_ethtool_ksettings_get(cpsw->slaves[slave_no].phy, ecmd); |
| 406 |
return 0; |
| 407 |
} |
| 408 |
|
| 409 |
int cpsw_set_link_ksettings(struct net_device *ndev, |
| 410 |
const struct ethtool_link_ksettings *ecmd) |
| 411 |
{ |
| 412 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 413 |
struct cpsw_common *cpsw = priv->cpsw; |
| 414 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 415 |
|
| 416 |
if (!cpsw->slaves[slave_no].phy) |
| 417 |
return -EOPNOTSUPP; |
| 418 |
|
| 419 |
return phy_ethtool_ksettings_set(cpsw->slaves[slave_no].phy, ecmd); |
| 420 |
} |
| 421 |
|
| 422 |
int cpsw_get_eee(struct net_device *ndev, struct ethtool_keee *edata) |
| 423 |
{ |
| 424 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 425 |
struct cpsw_common *cpsw = priv->cpsw; |
| 426 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 427 |
|
| 428 |
if (cpsw->slaves[slave_no].phy) |
| 429 |
return phy_ethtool_get_eee(cpsw->slaves[slave_no].phy, edata); |
| 430 |
else |
| 431 |
return -EOPNOTSUPP; |
| 432 |
} |
| 433 |
|
| 434 |
int cpsw_nway_reset(struct net_device *ndev) |
| 435 |
{ |
| 436 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 437 |
struct cpsw_common *cpsw = priv->cpsw; |
| 438 |
int slave_no = cpsw_slave_index(cpsw, priv); |
| 439 |
|
| 440 |
if (cpsw->slaves[slave_no].phy) |
| 441 |
return genphy_restart_aneg(cpsw->slaves[slave_no].phy); |
| 442 |
else |
| 443 |
return -EOPNOTSUPP; |
| 444 |
} |
| 445 |
|
| 446 |
static void cpsw_suspend_data_pass(struct net_device *ndev) |
| 447 |
{ |
| 448 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 449 |
int i; |
| 450 |
|
| 451 |
/* Disable NAPI scheduling */ |
| 452 |
cpsw_intr_disable(cpsw); |
| 453 |
|
| 454 |
/* Stop all transmit queues for every network device. |
| 455 |
*/ |
| 456 |
for (i = 0; i < cpsw->data.slaves; i++) { |
| 457 |
ndev = cpsw->slaves[i].ndev; |
| 458 |
if (!(ndev && netif_running(ndev))) |
| 459 |
continue; |
| 460 |
|
| 461 |
netif_tx_stop_all_queues(ndev); |
| 462 |
|
| 463 |
/* Barrier, so that stop_queue visible to other cpus */ |
| 464 |
smp_mb__after_atomic(); |
| 465 |
} |
| 466 |
|
| 467 |
/* Handle rest of tx packets and stop cpdma channels */ |
| 468 |
cpdma_ctlr_stop(cpsw->dma); |
| 469 |
} |
| 470 |
|
| 471 |
static int cpsw_resume_data_pass(struct net_device *ndev) |
| 472 |
{ |
| 473 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 474 |
struct cpsw_common *cpsw = priv->cpsw; |
| 475 |
int i, ret; |
| 476 |
|
| 477 |
/* After this receive is started */ |
| 478 |
if (cpsw->usage_count) { |
| 479 |
ret = cpsw_fill_rx_channels(priv); |
| 480 |
if (ret) |
| 481 |
return ret; |
| 482 |
|
| 483 |
cpdma_ctlr_start(cpsw->dma); |
| 484 |
cpsw_intr_enable(cpsw); |
| 485 |
} |
| 486 |
|
| 487 |
/* Resume transmit for every affected interface */ |
| 488 |
for (i = 0; i < cpsw->data.slaves; i++) { |
| 489 |
ndev = cpsw->slaves[i].ndev; |
| 490 |
if (ndev && netif_running(ndev)) |
| 491 |
netif_tx_start_all_queues(ndev); |
| 492 |
} |
| 493 |
|
| 494 |
return 0; |
| 495 |
} |
| 496 |
|
| 497 |
static int cpsw_check_ch_settings(struct cpsw_common *cpsw, |
| 498 |
struct ethtool_channels *ch) |
| 499 |
{ |
| 500 |
if (cpsw->quirk_irq) { |
| 501 |
dev_err(cpsw->dev, "Maximum one tx/rx queue is allowed"); |
| 502 |
return -EOPNOTSUPP; |
| 503 |
} |
| 504 |
|
| 505 |
if (ch->combined_count) |
| 506 |
return -EINVAL; |
| 507 |
|
| 508 |
/* verify we have at least one channel in each direction */ |
| 509 |
if (!ch->rx_count || !ch->tx_count) |
| 510 |
return -EINVAL; |
| 511 |
|
| 512 |
if (ch->rx_count > cpsw->data.channels || |
| 513 |
ch->tx_count > cpsw->data.channels) |
| 514 |
return -EINVAL; |
| 515 |
|
| 516 |
return 0; |
| 517 |
} |
| 518 |
|
| 519 |
static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, |
| 520 |
cpdma_handler_fn rx_handler) |
| 521 |
{ |
| 522 |
struct cpsw_common *cpsw = priv->cpsw; |
| 523 |
void (*handler)(void *, int, int); |
| 524 |
struct netdev_queue *queue; |
| 525 |
struct cpsw_vector *vec; |
| 526 |
int ret, *ch, vch; |
| 527 |
|
| 528 |
if (rx) { |
| 529 |
ch = &cpsw->rx_ch_num; |
| 530 |
vec = cpsw->rxv; |
| 531 |
handler = rx_handler; |
| 532 |
} else { |
| 533 |
ch = &cpsw->tx_ch_num; |
| 534 |
vec = cpsw->txv; |
| 535 |
handler = cpsw_tx_handler; |
| 536 |
} |
| 537 |
|
| 538 |
while (*ch < ch_num) { |
| 539 |
vch = rx ? *ch : 7 - *ch; |
| 540 |
vec[*ch].ch = cpdma_chan_create(cpsw->dma, vch, handler, rx); |
| 541 |
queue = netdev_get_tx_queue(priv->ndev, *ch); |
| 542 |
queue->tx_maxrate = 0; |
| 543 |
|
| 544 |
if (IS_ERR(vec[*ch].ch)) |
| 545 |
return PTR_ERR(vec[*ch].ch); |
| 546 |
|
| 547 |
if (!vec[*ch].ch) |
| 548 |
return -EINVAL; |
| 549 |
|
| 550 |
cpsw_info(priv, ifup, "created new %d %s channel\n", *ch, |
| 551 |
(rx ? "rx" : "tx")); |
| 552 |
(*ch)++; |
| 553 |
} |
| 554 |
|
| 555 |
while (*ch > ch_num) { |
| 556 |
(*ch)--; |
| 557 |
|
| 558 |
ret = cpdma_chan_destroy(vec[*ch].ch); |
| 559 |
if (ret) |
| 560 |
return ret; |
| 561 |
|
| 562 |
cpsw_info(priv, ifup, "destroyed %d %s channel\n", *ch, |
| 563 |
(rx ? "rx" : "tx")); |
| 564 |
} |
| 565 |
|
| 566 |
return 0; |
| 567 |
} |
| 568 |
|
| 569 |
static void cpsw_fail(struct cpsw_common *cpsw) |
| 570 |
{ |
| 571 |
struct net_device *ndev; |
| 572 |
int i; |
| 573 |
|
| 574 |
for (i = 0; i < cpsw->data.slaves; i++) { |
| 575 |
ndev = cpsw->slaves[i].ndev; |
| 576 |
if (ndev) |
| 577 |
dev_close(ndev); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
int cpsw_set_channels_common(struct net_device *ndev, |
| 582 |
struct ethtool_channels *chs, |
| 583 |
cpdma_handler_fn rx_handler) |
| 584 |
{ |
| 585 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 586 |
struct cpsw_common *cpsw = priv->cpsw; |
| 587 |
struct net_device *sl_ndev; |
| 588 |
int i, new_pools, ret; |
| 589 |
|
| 590 |
ret = cpsw_check_ch_settings(cpsw, chs); |
| 591 |
if (ret < 0) |
| 592 |
return ret; |
| 593 |
|
| 594 |
cpsw_suspend_data_pass(ndev); |
| 595 |
|
| 596 |
new_pools = (chs->rx_count != cpsw->rx_ch_num) && cpsw->usage_count; |
| 597 |
|
| 598 |
ret = cpsw_update_channels_res(priv, chs->rx_count, 1, rx_handler); |
| 599 |
if (ret) |
| 600 |
goto err; |
| 601 |
|
| 602 |
ret = cpsw_update_channels_res(priv, chs->tx_count, 0, rx_handler); |
| 603 |
if (ret) |
| 604 |
goto err; |
| 605 |
|
| 606 |
for (i = 0; i < cpsw->data.slaves; i++) { |
| 607 |
sl_ndev = cpsw->slaves[i].ndev; |
| 608 |
if (!(sl_ndev && netif_running(sl_ndev))) |
| 609 |
continue; |
| 610 |
|
| 611 |
/* Inform stack about new count of queues */ |
| 612 |
ret = netif_set_real_num_tx_queues(sl_ndev, cpsw->tx_ch_num); |
| 613 |
if (ret) { |
| 614 |
dev_err(priv->dev, "cannot set real number of tx queues\n"); |
| 615 |
goto err; |
| 616 |
} |
| 617 |
|
| 618 |
ret = netif_set_real_num_rx_queues(sl_ndev, cpsw->rx_ch_num); |
| 619 |
if (ret) { |
| 620 |
dev_err(priv->dev, "cannot set real number of rx queues\n"); |
| 621 |
goto err; |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
cpsw_split_res(cpsw); |
| 626 |
|
| 627 |
if (new_pools) { |
| 628 |
cpsw_destroy_xdp_rxqs(cpsw); |
| 629 |
ret = cpsw_create_xdp_rxqs(cpsw); |
| 630 |
if (ret) |
| 631 |
goto err; |
| 632 |
} |
| 633 |
|
| 634 |
ret = cpsw_resume_data_pass(ndev); |
| 635 |
if (!ret) |
| 636 |
return 0; |
| 637 |
err: |
| 638 |
dev_err(priv->dev, "cannot update channels number, closing device\n"); |
| 639 |
cpsw_fail(cpsw); |
| 640 |
return ret; |
| 641 |
} |
| 642 |
|
| 643 |
void cpsw_get_ringparam(struct net_device *ndev, |
| 644 |
struct ethtool_ringparam *ering, |
| 645 |
struct kernel_ethtool_ringparam *kernel_ering, |
| 646 |
struct netlink_ext_ack *extack) |
| 647 |
{ |
| 648 |
struct cpsw_priv *priv = netdev_priv(ndev); |
| 649 |
struct cpsw_common *cpsw = priv->cpsw; |
| 650 |
|
| 651 |
/* not supported */ |
| 652 |
ering->tx_max_pending = cpsw->descs_pool_size - CPSW_MAX_QUEUES; |
| 653 |
ering->tx_pending = cpdma_get_num_tx_descs(cpsw->dma); |
| 654 |
ering->rx_max_pending = cpsw->descs_pool_size - CPSW_MAX_QUEUES; |
| 655 |
ering->rx_pending = cpdma_get_num_rx_descs(cpsw->dma); |
| 656 |
} |
| 657 |
|
| 658 |
int cpsw_set_ringparam(struct net_device *ndev, |
| 659 |
struct ethtool_ringparam *ering, |
| 660 |
struct kernel_ethtool_ringparam *kernel_ering, |
| 661 |
struct netlink_ext_ack *extack) |
| 662 |
{ |
| 663 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 664 |
int descs_num, ret; |
| 665 |
|
| 666 |
/* ignore ering->tx_pending - only rx_pending adjustment is supported */ |
| 667 |
|
| 668 |
if (ering->rx_mini_pending || ering->rx_jumbo_pending || |
| 669 |
ering->rx_pending < CPSW_MAX_QUEUES || |
| 670 |
ering->rx_pending > (cpsw->descs_pool_size - CPSW_MAX_QUEUES)) |
| 671 |
return -EINVAL; |
| 672 |
|
| 673 |
descs_num = cpdma_get_num_rx_descs(cpsw->dma); |
| 674 |
if (ering->rx_pending == descs_num) |
| 675 |
return 0; |
| 676 |
|
| 677 |
cpsw_suspend_data_pass(ndev); |
| 678 |
|
| 679 |
ret = cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); |
| 680 |
if (ret) { |
| 681 |
if (cpsw_resume_data_pass(ndev)) |
| 682 |
goto err; |
| 683 |
|
| 684 |
return ret; |
| 685 |
} |
| 686 |
|
| 687 |
if (cpsw->usage_count) { |
| 688 |
cpsw_destroy_xdp_rxqs(cpsw); |
| 689 |
ret = cpsw_create_xdp_rxqs(cpsw); |
| 690 |
if (ret) |
| 691 |
goto err; |
| 692 |
} |
| 693 |
|
| 694 |
ret = cpsw_resume_data_pass(ndev); |
| 695 |
if (!ret) |
| 696 |
return 0; |
| 697 |
err: |
| 698 |
cpdma_set_num_rx_descs(cpsw->dma, descs_num); |
| 699 |
dev_err(cpsw->dev, "cannot set ring params, closing device\n"); |
| 700 |
cpsw_fail(cpsw); |
| 701 |
return ret; |
| 702 |
} |
| 703 |
|
| 704 |
#if IS_ENABLED(CONFIG_TI_CPTS) |
| 705 |
int cpsw_get_ts_info(struct net_device *ndev, struct kernel_ethtool_ts_info *info) |
| 706 |
{ |
| 707 |
struct cpsw_common *cpsw = ndev_to_cpsw(ndev); |
| 708 |
|
| 709 |
info->so_timestamping = |
| 710 |
SOF_TIMESTAMPING_TX_HARDWARE | |
| 711 |
SOF_TIMESTAMPING_TX_SOFTWARE | |
| 712 |
SOF_TIMESTAMPING_RX_HARDWARE | |
| 713 |
SOF_TIMESTAMPING_RAW_HARDWARE; |
| 714 |
info->phc_index = cpsw->cpts->phc_index; |
| 715 |
info->tx_types = |
| 716 |
(1 << HWTSTAMP_TX_OFF) | |
| 717 |
(1 << HWTSTAMP_TX_ON); |
| 718 |
info->rx_filters = |
| 719 |
(1 << HWTSTAMP_FILTER_NONE) | |
| 720 |
(1 << HWTSTAMP_FILTER_PTP_V2_EVENT); |
| 721 |
return 0; |
| 722 |
} |
| 723 |
#else |
| 724 |
int cpsw_get_ts_info(struct net_device *ndev, struct kernel_ethtool_ts_info *info) |
| 725 |
{ |
| 726 |
info->so_timestamping = |
| 727 |
SOF_TIMESTAMPING_TX_SOFTWARE; |
| 728 |
info->tx_types = 0; |
| 729 |
info->rx_filters = 0; |
| 730 |
return 0; |
| 731 |
} |
| 732 |
#endif |