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 int ret; 378 379 ret = pm_runtime_put(priv->cpsw->dev); 380 if (ret < 0) 381 cpsw_err(priv, drv, "ethtool complete failed %d\n", ret); 382 } 383 384 void cpsw_get_channels(struct net_device *ndev, struct ethtool_channels *ch) 385 { 386 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); 387 388 ch->max_rx = cpsw->quirk_irq ? 1 : CPSW_MAX_QUEUES; 389 ch->max_tx = cpsw->quirk_irq ? 1 : CPSW_MAX_QUEUES; 390 ch->max_combined = 0; 391 ch->max_other = 0; 392 ch->other_count = 0; 393 ch->rx_count = cpsw->rx_ch_num; 394 ch->tx_count = cpsw->tx_ch_num; 395 ch->combined_count = 0; 396 } 397 398 int cpsw_get_link_ksettings(struct net_device *ndev, 399 struct ethtool_link_ksettings *ecmd) 400 { 401 struct cpsw_priv *priv = netdev_priv(ndev); 402 struct cpsw_common *cpsw = priv->cpsw; 403 int slave_no = cpsw_slave_index(cpsw, priv); 404 405 if (!cpsw->slaves[slave_no].phy) 406 return -EOPNOTSUPP; 407 408 phy_ethtool_ksettings_get(cpsw->slaves[slave_no].phy, ecmd); 409 return 0; 410 } 411 412 int cpsw_set_link_ksettings(struct net_device *ndev, 413 const struct ethtool_link_ksettings *ecmd) 414 { 415 struct cpsw_priv *priv = netdev_priv(ndev); 416 struct cpsw_common *cpsw = priv->cpsw; 417 int slave_no = cpsw_slave_index(cpsw, priv); 418 419 if (!cpsw->slaves[slave_no].phy) 420 return -EOPNOTSUPP; 421 422 return phy_ethtool_ksettings_set(cpsw->slaves[slave_no].phy, ecmd); 423 } 424 425 int cpsw_get_eee(struct net_device *ndev, struct ethtool_keee *edata) 426 { 427 struct cpsw_priv *priv = netdev_priv(ndev); 428 struct cpsw_common *cpsw = priv->cpsw; 429 int slave_no = cpsw_slave_index(cpsw, priv); 430 431 if (cpsw->slaves[slave_no].phy) 432 return phy_ethtool_get_eee(cpsw->slaves[slave_no].phy, edata); 433 else 434 return -EOPNOTSUPP; 435 } 436 437 int cpsw_nway_reset(struct net_device *ndev) 438 { 439 struct cpsw_priv *priv = netdev_priv(ndev); 440 struct cpsw_common *cpsw = priv->cpsw; 441 int slave_no = cpsw_slave_index(cpsw, priv); 442 443 if (cpsw->slaves[slave_no].phy) 444 return genphy_restart_aneg(cpsw->slaves[slave_no].phy); 445 else 446 return -EOPNOTSUPP; 447 } 448 449 static void cpsw_suspend_data_pass(struct net_device *ndev) 450 { 451 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); 452 int i; 453 454 /* Disable NAPI scheduling */ 455 cpsw_intr_disable(cpsw); 456 457 /* Stop all transmit queues for every network device. 458 */ 459 for (i = 0; i < cpsw->data.slaves; i++) { 460 ndev = cpsw->slaves[i].ndev; 461 if (!(ndev && netif_running(ndev))) 462 continue; 463 464 netif_tx_stop_all_queues(ndev); 465 466 /* Barrier, so that stop_queue visible to other cpus */ 467 smp_mb__after_atomic(); 468 } 469 470 /* Handle rest of tx packets and stop cpdma channels */ 471 cpdma_ctlr_stop(cpsw->dma); 472 } 473 474 static int cpsw_resume_data_pass(struct net_device *ndev) 475 { 476 struct cpsw_priv *priv = netdev_priv(ndev); 477 struct cpsw_common *cpsw = priv->cpsw; 478 int i, ret; 479 480 /* After this receive is started */ 481 if (cpsw->usage_count) { 482 ret = cpsw_fill_rx_channels(priv); 483 if (ret) 484 return ret; 485 486 cpdma_ctlr_start(cpsw->dma); 487 cpsw_intr_enable(cpsw); 488 } 489 490 /* Resume transmit for every affected interface */ 491 for (i = 0; i < cpsw->data.slaves; i++) { 492 ndev = cpsw->slaves[i].ndev; 493 if (ndev && netif_running(ndev)) 494 netif_tx_start_all_queues(ndev); 495 } 496 497 return 0; 498 } 499 500 static int cpsw_check_ch_settings(struct cpsw_common *cpsw, 501 struct ethtool_channels *ch) 502 { 503 if (cpsw->quirk_irq) { 504 dev_err(cpsw->dev, "Maximum one tx/rx queue is allowed"); 505 return -EOPNOTSUPP; 506 } 507 508 if (ch->combined_count) 509 return -EINVAL; 510 511 /* verify we have at least one channel in each direction */ 512 if (!ch->rx_count || !ch->tx_count) 513 return -EINVAL; 514 515 if (ch->rx_count > cpsw->data.channels || 516 ch->tx_count > cpsw->data.channels) 517 return -EINVAL; 518 519 return 0; 520 } 521 522 static int cpsw_update_channels_res(struct cpsw_priv *priv, int ch_num, int rx, 523 cpdma_handler_fn rx_handler) 524 { 525 struct cpsw_common *cpsw = priv->cpsw; 526 void (*handler)(void *, int, int); 527 struct netdev_queue *queue; 528 struct cpsw_vector *vec; 529 int ret, *ch, vch; 530 531 if (rx) { 532 ch = &cpsw->rx_ch_num; 533 vec = cpsw->rxv; 534 handler = rx_handler; 535 } else { 536 ch = &cpsw->tx_ch_num; 537 vec = cpsw->txv; 538 handler = cpsw_tx_handler; 539 } 540 541 while (*ch < ch_num) { 542 vch = rx ? *ch : 7 - *ch; 543 vec[*ch].ch = cpdma_chan_create(cpsw->dma, vch, handler, rx); 544 queue = netdev_get_tx_queue(priv->ndev, *ch); 545 queue->tx_maxrate = 0; 546 547 if (IS_ERR(vec[*ch].ch)) 548 return PTR_ERR(vec[*ch].ch); 549 550 if (!vec[*ch].ch) 551 return -EINVAL; 552 553 cpsw_info(priv, ifup, "created new %d %s channel\n", *ch, 554 (rx ? "rx" : "tx")); 555 (*ch)++; 556 } 557 558 while (*ch > ch_num) { 559 (*ch)--; 560 561 ret = cpdma_chan_destroy(vec[*ch].ch); 562 if (ret) 563 return ret; 564 565 cpsw_info(priv, ifup, "destroyed %d %s channel\n", *ch, 566 (rx ? "rx" : "tx")); 567 } 568 569 return 0; 570 } 571 572 static void cpsw_fail(struct cpsw_common *cpsw) 573 { 574 struct net_device *ndev; 575 int i; 576 577 for (i = 0; i < cpsw->data.slaves; i++) { 578 ndev = cpsw->slaves[i].ndev; 579 if (ndev) 580 dev_close(ndev); 581 } 582 } 583 584 int cpsw_set_channels_common(struct net_device *ndev, 585 struct ethtool_channels *chs, 586 cpdma_handler_fn rx_handler) 587 { 588 struct cpsw_priv *priv = netdev_priv(ndev); 589 struct cpsw_common *cpsw = priv->cpsw; 590 struct net_device *sl_ndev; 591 int i, new_pools, ret; 592 593 ret = cpsw_check_ch_settings(cpsw, chs); 594 if (ret < 0) 595 return ret; 596 597 cpsw_suspend_data_pass(ndev); 598 599 new_pools = (chs->rx_count != cpsw->rx_ch_num) && cpsw->usage_count; 600 601 ret = cpsw_update_channels_res(priv, chs->rx_count, 1, rx_handler); 602 if (ret) 603 goto err; 604 605 ret = cpsw_update_channels_res(priv, chs->tx_count, 0, rx_handler); 606 if (ret) 607 goto err; 608 609 for (i = 0; i < cpsw->data.slaves; i++) { 610 sl_ndev = cpsw->slaves[i].ndev; 611 if (!(sl_ndev && netif_running(sl_ndev))) 612 continue; 613 614 /* Inform stack about new count of queues */ 615 ret = netif_set_real_num_tx_queues(sl_ndev, cpsw->tx_ch_num); 616 if (ret) { 617 dev_err(priv->dev, "cannot set real number of tx queues\n"); 618 goto err; 619 } 620 621 ret = netif_set_real_num_rx_queues(sl_ndev, cpsw->rx_ch_num); 622 if (ret) { 623 dev_err(priv->dev, "cannot set real number of rx queues\n"); 624 goto err; 625 } 626 } 627 628 cpsw_split_res(cpsw); 629 630 if (new_pools) { 631 cpsw_destroy_xdp_rxqs(cpsw); 632 ret = cpsw_create_xdp_rxqs(cpsw); 633 if (ret) 634 goto err; 635 } 636 637 ret = cpsw_resume_data_pass(ndev); 638 if (!ret) 639 return 0; 640 err: 641 dev_err(priv->dev, "cannot update channels number, closing device\n"); 642 cpsw_fail(cpsw); 643 return ret; 644 } 645 646 void cpsw_get_ringparam(struct net_device *ndev, 647 struct ethtool_ringparam *ering, 648 struct kernel_ethtool_ringparam *kernel_ering, 649 struct netlink_ext_ack *extack) 650 { 651 struct cpsw_priv *priv = netdev_priv(ndev); 652 struct cpsw_common *cpsw = priv->cpsw; 653 654 /* not supported */ 655 ering->tx_max_pending = cpsw->descs_pool_size - CPSW_MAX_QUEUES; 656 ering->tx_pending = cpdma_get_num_tx_descs(cpsw->dma); 657 ering->rx_max_pending = cpsw->descs_pool_size - CPSW_MAX_QUEUES; 658 ering->rx_pending = cpdma_get_num_rx_descs(cpsw->dma); 659 } 660 661 int cpsw_set_ringparam(struct net_device *ndev, 662 struct ethtool_ringparam *ering, 663 struct kernel_ethtool_ringparam *kernel_ering, 664 struct netlink_ext_ack *extack) 665 { 666 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); 667 int descs_num, ret; 668 669 /* ignore ering->tx_pending - only rx_pending adjustment is supported */ 670 671 if (ering->rx_mini_pending || ering->rx_jumbo_pending || 672 ering->rx_pending < CPSW_MAX_QUEUES || 673 ering->rx_pending > (cpsw->descs_pool_size - CPSW_MAX_QUEUES)) 674 return -EINVAL; 675 676 descs_num = cpdma_get_num_rx_descs(cpsw->dma); 677 if (ering->rx_pending == descs_num) 678 return 0; 679 680 cpsw_suspend_data_pass(ndev); 681 682 ret = cpdma_set_num_rx_descs(cpsw->dma, ering->rx_pending); 683 if (ret) { 684 if (cpsw_resume_data_pass(ndev)) 685 goto err; 686 687 return ret; 688 } 689 690 if (cpsw->usage_count) { 691 cpsw_destroy_xdp_rxqs(cpsw); 692 ret = cpsw_create_xdp_rxqs(cpsw); 693 if (ret) 694 goto err; 695 } 696 697 ret = cpsw_resume_data_pass(ndev); 698 if (!ret) 699 return 0; 700 err: 701 cpdma_set_num_rx_descs(cpsw->dma, descs_num); 702 dev_err(cpsw->dev, "cannot set ring params, closing device\n"); 703 cpsw_fail(cpsw); 704 return ret; 705 } 706 707 #if IS_ENABLED(CONFIG_TI_CPTS) 708 int cpsw_get_ts_info(struct net_device *ndev, struct kernel_ethtool_ts_info *info) 709 { 710 struct cpsw_common *cpsw = ndev_to_cpsw(ndev); 711 712 info->so_timestamping = 713 SOF_TIMESTAMPING_TX_HARDWARE | 714 SOF_TIMESTAMPING_TX_SOFTWARE | 715 SOF_TIMESTAMPING_RX_HARDWARE | 716 SOF_TIMESTAMPING_RAW_HARDWARE; 717 info->phc_index = cpsw->cpts->phc_index; 718 info->tx_types = 719 (1 << HWTSTAMP_TX_OFF) | 720 (1 << HWTSTAMP_TX_ON); 721 info->rx_filters = 722 (1 << HWTSTAMP_FILTER_NONE) | 723 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); 724 return 0; 725 } 726 #else 727 int cpsw_get_ts_info(struct net_device *ndev, struct kernel_ethtool_ts_info *info) 728 { 729 info->so_timestamping = 730 SOF_TIMESTAMPING_TX_SOFTWARE; 731 info->tx_types = 0; 732 info->rx_filters = 0; 733 return 0; 734 } 735 #endif 736