1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* Copyright (c) 2021, Microsoft Corporation. */ 3 4 #include <linux/inetdevice.h> 5 #include <linux/etherdevice.h> 6 #include <linux/ethtool.h> 7 8 #include <net/mana/mana.h> 9 10 struct mana_stats_desc { 11 char name[ETH_GSTRING_LEN]; 12 u16 offset; 13 }; 14 15 static const struct mana_stats_desc mana_eth_stats[] = { 16 {"stop_queue", offsetof(struct mana_ethtool_stats, stop_queue)}, 17 {"wake_queue", offsetof(struct mana_ethtool_stats, wake_queue)}, 18 {"tx_cq_err", offsetof(struct mana_ethtool_stats, tx_cqe_err)}, 19 {"tx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, 20 tx_cqe_unknown_type)}, 21 {"rx_coalesced_err", offsetof(struct mana_ethtool_stats, 22 rx_coalesced_err)}, 23 {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, 24 rx_cqe_unknown_type)}, 25 }; 26 27 static const struct mana_stats_desc mana_hc_stats[] = { 28 {"hc_rx_discards_no_wqe", offsetof(struct mana_ethtool_hc_stats, 29 hc_rx_discards_no_wqe)}, 30 {"hc_rx_err_vport_disabled", offsetof(struct mana_ethtool_hc_stats, 31 hc_rx_err_vport_disabled)}, 32 {"hc_rx_bytes", offsetof(struct mana_ethtool_hc_stats, hc_rx_bytes)}, 33 {"hc_rx_ucast_pkts", offsetof(struct mana_ethtool_hc_stats, 34 hc_rx_ucast_pkts)}, 35 {"hc_rx_ucast_bytes", offsetof(struct mana_ethtool_hc_stats, 36 hc_rx_ucast_bytes)}, 37 {"hc_rx_bcast_pkts", offsetof(struct mana_ethtool_hc_stats, 38 hc_rx_bcast_pkts)}, 39 {"hc_rx_bcast_bytes", offsetof(struct mana_ethtool_hc_stats, 40 hc_rx_bcast_bytes)}, 41 {"hc_rx_mcast_pkts", offsetof(struct mana_ethtool_hc_stats, 42 hc_rx_mcast_pkts)}, 43 {"hc_rx_mcast_bytes", offsetof(struct mana_ethtool_hc_stats, 44 hc_rx_mcast_bytes)}, 45 {"hc_tx_err_gf_disabled", offsetof(struct mana_ethtool_hc_stats, 46 hc_tx_err_gf_disabled)}, 47 {"hc_tx_err_vport_disabled", offsetof(struct mana_ethtool_hc_stats, 48 hc_tx_err_vport_disabled)}, 49 {"hc_tx_err_inval_vportoffset_pkt", 50 offsetof(struct mana_ethtool_hc_stats, 51 hc_tx_err_inval_vportoffset_pkt)}, 52 {"hc_tx_err_vlan_enforcement", offsetof(struct mana_ethtool_hc_stats, 53 hc_tx_err_vlan_enforcement)}, 54 {"hc_tx_err_eth_type_enforcement", 55 offsetof(struct mana_ethtool_hc_stats, hc_tx_err_eth_type_enforcement)}, 56 {"hc_tx_err_sa_enforcement", offsetof(struct mana_ethtool_hc_stats, 57 hc_tx_err_sa_enforcement)}, 58 {"hc_tx_err_sqpdid_enforcement", 59 offsetof(struct mana_ethtool_hc_stats, hc_tx_err_sqpdid_enforcement)}, 60 {"hc_tx_err_cqpdid_enforcement", 61 offsetof(struct mana_ethtool_hc_stats, hc_tx_err_cqpdid_enforcement)}, 62 {"hc_tx_err_mtu_violation", offsetof(struct mana_ethtool_hc_stats, 63 hc_tx_err_mtu_violation)}, 64 {"hc_tx_err_inval_oob", offsetof(struct mana_ethtool_hc_stats, 65 hc_tx_err_inval_oob)}, 66 {"hc_tx_err_gdma", offsetof(struct mana_ethtool_hc_stats, 67 hc_tx_err_gdma)}, 68 {"hc_tx_bytes", offsetof(struct mana_ethtool_hc_stats, hc_tx_bytes)}, 69 {"hc_tx_ucast_pkts", offsetof(struct mana_ethtool_hc_stats, 70 hc_tx_ucast_pkts)}, 71 {"hc_tx_ucast_bytes", offsetof(struct mana_ethtool_hc_stats, 72 hc_tx_ucast_bytes)}, 73 {"hc_tx_bcast_pkts", offsetof(struct mana_ethtool_hc_stats, 74 hc_tx_bcast_pkts)}, 75 {"hc_tx_bcast_bytes", offsetof(struct mana_ethtool_hc_stats, 76 hc_tx_bcast_bytes)}, 77 {"hc_tx_mcast_pkts", offsetof(struct mana_ethtool_hc_stats, 78 hc_tx_mcast_pkts)}, 79 {"hc_tx_mcast_bytes", offsetof(struct mana_ethtool_hc_stats, 80 hc_tx_mcast_bytes)}, 81 }; 82 83 static const struct mana_stats_desc mana_phy_stats[] = { 84 { "hc_rx_pkt_drop_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_drop_phy) }, 85 { "hc_tx_pkt_drop_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_drop_phy) }, 86 { "hc_tc0_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc0_phy) }, 87 { "hc_tc0_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc0_phy) }, 88 { "hc_tc0_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc0_phy) }, 89 { "hc_tc0_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc0_phy) }, 90 { "hc_tc1_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc1_phy) }, 91 { "hc_tc1_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc1_phy) }, 92 { "hc_tc1_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc1_phy) }, 93 { "hc_tc1_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc1_phy) }, 94 { "hc_tc2_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc2_phy) }, 95 { "hc_tc2_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc2_phy) }, 96 { "hc_tc2_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc2_phy) }, 97 { "hc_tc2_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc2_phy) }, 98 { "hc_tc3_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc3_phy) }, 99 { "hc_tc3_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc3_phy) }, 100 { "hc_tc3_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc3_phy) }, 101 { "hc_tc3_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc3_phy) }, 102 { "hc_tc4_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc4_phy) }, 103 { "hc_tc4_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc4_phy) }, 104 { "hc_tc4_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc4_phy) }, 105 { "hc_tc4_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc4_phy) }, 106 { "hc_tc5_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc5_phy) }, 107 { "hc_tc5_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc5_phy) }, 108 { "hc_tc5_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc5_phy) }, 109 { "hc_tc5_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc5_phy) }, 110 { "hc_tc6_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc6_phy) }, 111 { "hc_tc6_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc6_phy) }, 112 { "hc_tc6_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc6_phy) }, 113 { "hc_tc6_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc6_phy) }, 114 { "hc_tc7_rx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, rx_pkt_tc7_phy) }, 115 { "hc_tc7_rx_byte_phy", offsetof(struct mana_ethtool_phy_stats, rx_byte_tc7_phy) }, 116 { "hc_tc7_tx_pkt_phy", offsetof(struct mana_ethtool_phy_stats, tx_pkt_tc7_phy) }, 117 { "hc_tc7_tx_byte_phy", offsetof(struct mana_ethtool_phy_stats, tx_byte_tc7_phy) }, 118 { "hc_tc0_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc0_phy) }, 119 { "hc_tc0_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc0_phy) }, 120 { "hc_tc1_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc1_phy) }, 121 { "hc_tc1_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc1_phy) }, 122 { "hc_tc2_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc2_phy) }, 123 { "hc_tc2_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc2_phy) }, 124 { "hc_tc3_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc3_phy) }, 125 { "hc_tc3_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc3_phy) }, 126 { "hc_tc4_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc4_phy) }, 127 { "hc_tc4_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc4_phy) }, 128 { "hc_tc5_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc5_phy) }, 129 { "hc_tc5_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc5_phy) }, 130 { "hc_tc6_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc6_phy) }, 131 { "hc_tc6_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc6_phy) }, 132 { "hc_tc7_rx_pause_phy", offsetof(struct mana_ethtool_phy_stats, rx_pause_tc7_phy) }, 133 { "hc_tc7_tx_pause_phy", offsetof(struct mana_ethtool_phy_stats, tx_pause_tc7_phy) }, 134 }; 135 136 static int mana_get_sset_count(struct net_device *ndev, int stringset) 137 { 138 struct mana_port_context *apc = netdev_priv(ndev); 139 unsigned int num_queues = apc->num_queues; 140 141 if (stringset != ETH_SS_STATS) 142 return -EINVAL; 143 144 return ARRAY_SIZE(mana_eth_stats) + ARRAY_SIZE(mana_phy_stats) + ARRAY_SIZE(mana_hc_stats) + 145 num_queues * (MANA_STATS_RX_COUNT + MANA_STATS_TX_COUNT); 146 } 147 148 static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) 149 { 150 struct mana_port_context *apc = netdev_priv(ndev); 151 unsigned int num_queues = apc->num_queues; 152 int i; 153 154 if (stringset != ETH_SS_STATS) 155 return; 156 for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) 157 ethtool_puts(&data, mana_eth_stats[i].name); 158 159 for (i = 0; i < ARRAY_SIZE(mana_hc_stats); i++) 160 ethtool_puts(&data, mana_hc_stats[i].name); 161 162 for (i = 0; i < ARRAY_SIZE(mana_phy_stats); i++) 163 ethtool_puts(&data, mana_phy_stats[i].name); 164 165 for (i = 0; i < num_queues; i++) { 166 ethtool_sprintf(&data, "rx_%d_packets", i); 167 ethtool_sprintf(&data, "rx_%d_bytes", i); 168 ethtool_sprintf(&data, "rx_%d_xdp_drop", i); 169 ethtool_sprintf(&data, "rx_%d_xdp_tx", i); 170 ethtool_sprintf(&data, "rx_%d_xdp_redirect", i); 171 } 172 173 for (i = 0; i < num_queues; i++) { 174 ethtool_sprintf(&data, "tx_%d_packets", i); 175 ethtool_sprintf(&data, "tx_%d_bytes", i); 176 ethtool_sprintf(&data, "tx_%d_xdp_xmit", i); 177 ethtool_sprintf(&data, "tx_%d_tso_packets", i); 178 ethtool_sprintf(&data, "tx_%d_tso_bytes", i); 179 ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i); 180 ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i); 181 ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i); 182 ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i); 183 ethtool_sprintf(&data, "tx_%d_csum_partial", i); 184 ethtool_sprintf(&data, "tx_%d_mana_map_err", i); 185 } 186 } 187 188 static void mana_get_ethtool_stats(struct net_device *ndev, 189 struct ethtool_stats *e_stats, u64 *data) 190 { 191 struct mana_port_context *apc = netdev_priv(ndev); 192 unsigned int num_queues = apc->num_queues; 193 void *eth_stats = &apc->eth_stats; 194 void *hc_stats = &apc->ac->hc_stats; 195 void *phy_stats = &apc->phy_stats; 196 struct mana_stats_rx *rx_stats; 197 struct mana_stats_tx *tx_stats; 198 unsigned int start; 199 u64 packets, bytes; 200 u64 xdp_redirect; 201 u64 xdp_xmit; 202 u64 xdp_drop; 203 u64 xdp_tx; 204 u64 tso_packets; 205 u64 tso_bytes; 206 u64 tso_inner_packets; 207 u64 tso_inner_bytes; 208 u64 long_pkt_fmt; 209 u64 short_pkt_fmt; 210 u64 csum_partial; 211 u64 mana_map_err; 212 int q, i = 0; 213 214 if (!apc->port_is_up) 215 return; 216 217 /* We call this mana function to get the phy stats from GDMA and includes 218 * aggregate tx/rx drop counters, Per-TC(Traffic Channel) tx/rx and pause 219 * counters. 220 */ 221 mana_query_phy_stats(apc); 222 223 for (q = 0; q < ARRAY_SIZE(mana_eth_stats); q++) 224 data[i++] = *(u64 *)(eth_stats + mana_eth_stats[q].offset); 225 226 for (q = 0; q < ARRAY_SIZE(mana_hc_stats); q++) 227 data[i++] = *(u64 *)(hc_stats + mana_hc_stats[q].offset); 228 229 for (q = 0; q < ARRAY_SIZE(mana_phy_stats); q++) 230 data[i++] = *(u64 *)(phy_stats + mana_phy_stats[q].offset); 231 232 for (q = 0; q < num_queues; q++) { 233 rx_stats = &apc->rxqs[q]->stats; 234 235 do { 236 start = u64_stats_fetch_begin(&rx_stats->syncp); 237 packets = rx_stats->packets; 238 bytes = rx_stats->bytes; 239 xdp_drop = rx_stats->xdp_drop; 240 xdp_tx = rx_stats->xdp_tx; 241 xdp_redirect = rx_stats->xdp_redirect; 242 } while (u64_stats_fetch_retry(&rx_stats->syncp, start)); 243 244 data[i++] = packets; 245 data[i++] = bytes; 246 data[i++] = xdp_drop; 247 data[i++] = xdp_tx; 248 data[i++] = xdp_redirect; 249 } 250 251 for (q = 0; q < num_queues; q++) { 252 tx_stats = &apc->tx_qp[q].txq.stats; 253 254 do { 255 start = u64_stats_fetch_begin(&tx_stats->syncp); 256 packets = tx_stats->packets; 257 bytes = tx_stats->bytes; 258 xdp_xmit = tx_stats->xdp_xmit; 259 tso_packets = tx_stats->tso_packets; 260 tso_bytes = tx_stats->tso_bytes; 261 tso_inner_packets = tx_stats->tso_inner_packets; 262 tso_inner_bytes = tx_stats->tso_inner_bytes; 263 long_pkt_fmt = tx_stats->long_pkt_fmt; 264 short_pkt_fmt = tx_stats->short_pkt_fmt; 265 csum_partial = tx_stats->csum_partial; 266 mana_map_err = tx_stats->mana_map_err; 267 } while (u64_stats_fetch_retry(&tx_stats->syncp, start)); 268 269 data[i++] = packets; 270 data[i++] = bytes; 271 data[i++] = xdp_xmit; 272 data[i++] = tso_packets; 273 data[i++] = tso_bytes; 274 data[i++] = tso_inner_packets; 275 data[i++] = tso_inner_bytes; 276 data[i++] = long_pkt_fmt; 277 data[i++] = short_pkt_fmt; 278 data[i++] = csum_partial; 279 data[i++] = mana_map_err; 280 } 281 } 282 283 static int mana_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *cmd, 284 u32 *rules) 285 { 286 struct mana_port_context *apc = netdev_priv(ndev); 287 288 switch (cmd->cmd) { 289 case ETHTOOL_GRXRINGS: 290 cmd->data = apc->num_queues; 291 return 0; 292 } 293 294 return -EOPNOTSUPP; 295 } 296 297 static u32 mana_get_rxfh_key_size(struct net_device *ndev) 298 { 299 return MANA_HASH_KEY_SIZE; 300 } 301 302 static u32 mana_rss_indir_size(struct net_device *ndev) 303 { 304 struct mana_port_context *apc = netdev_priv(ndev); 305 306 return apc->indir_table_sz; 307 } 308 309 static int mana_get_rxfh(struct net_device *ndev, 310 struct ethtool_rxfh_param *rxfh) 311 { 312 struct mana_port_context *apc = netdev_priv(ndev); 313 int i; 314 315 rxfh->hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */ 316 317 if (rxfh->indir) { 318 for (i = 0; i < apc->indir_table_sz; i++) 319 rxfh->indir[i] = apc->indir_table[i]; 320 } 321 322 if (rxfh->key) 323 memcpy(rxfh->key, apc->hashkey, MANA_HASH_KEY_SIZE); 324 325 return 0; 326 } 327 328 static int mana_set_rxfh(struct net_device *ndev, 329 struct ethtool_rxfh_param *rxfh, 330 struct netlink_ext_ack *extack) 331 { 332 struct mana_port_context *apc = netdev_priv(ndev); 333 bool update_hash = false, update_table = false; 334 u8 save_key[MANA_HASH_KEY_SIZE]; 335 u32 *save_table; 336 int i, err; 337 338 if (!apc->port_is_up) 339 return -EOPNOTSUPP; 340 341 if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && 342 rxfh->hfunc != ETH_RSS_HASH_TOP) 343 return -EOPNOTSUPP; 344 345 save_table = kcalloc(apc->indir_table_sz, sizeof(u32), GFP_KERNEL); 346 if (!save_table) 347 return -ENOMEM; 348 349 if (rxfh->indir) { 350 for (i = 0; i < apc->indir_table_sz; i++) 351 if (rxfh->indir[i] >= apc->num_queues) { 352 err = -EINVAL; 353 goto cleanup; 354 } 355 356 update_table = true; 357 for (i = 0; i < apc->indir_table_sz; i++) { 358 save_table[i] = apc->indir_table[i]; 359 apc->indir_table[i] = rxfh->indir[i]; 360 } 361 } 362 363 if (rxfh->key) { 364 update_hash = true; 365 memcpy(save_key, apc->hashkey, MANA_HASH_KEY_SIZE); 366 memcpy(apc->hashkey, rxfh->key, MANA_HASH_KEY_SIZE); 367 } 368 369 err = mana_config_rss(apc, TRI_STATE_TRUE, update_hash, update_table); 370 371 if (err) { /* recover to original values */ 372 if (update_table) { 373 for (i = 0; i < apc->indir_table_sz; i++) 374 apc->indir_table[i] = save_table[i]; 375 } 376 377 if (update_hash) 378 memcpy(apc->hashkey, save_key, MANA_HASH_KEY_SIZE); 379 380 mana_config_rss(apc, TRI_STATE_TRUE, update_hash, update_table); 381 } 382 383 cleanup: 384 kfree(save_table); 385 386 return err; 387 } 388 389 static void mana_get_channels(struct net_device *ndev, 390 struct ethtool_channels *channel) 391 { 392 struct mana_port_context *apc = netdev_priv(ndev); 393 394 channel->max_combined = apc->max_queues; 395 channel->combined_count = apc->num_queues; 396 } 397 398 static int mana_set_channels(struct net_device *ndev, 399 struct ethtool_channels *channels) 400 { 401 struct mana_port_context *apc = netdev_priv(ndev); 402 unsigned int new_count = channels->combined_count; 403 unsigned int old_count = apc->num_queues; 404 int err; 405 406 err = mana_pre_alloc_rxbufs(apc, ndev->mtu, new_count); 407 if (err) { 408 netdev_err(ndev, "Insufficient memory for new allocations"); 409 return err; 410 } 411 412 err = mana_detach(ndev, false); 413 if (err) { 414 netdev_err(ndev, "mana_detach failed: %d\n", err); 415 goto out; 416 } 417 418 apc->num_queues = new_count; 419 err = mana_attach(ndev); 420 if (err) { 421 apc->num_queues = old_count; 422 netdev_err(ndev, "mana_attach failed: %d\n", err); 423 } 424 425 out: 426 mana_pre_dealloc_rxbufs(apc); 427 return err; 428 } 429 430 static void mana_get_ringparam(struct net_device *ndev, 431 struct ethtool_ringparam *ring, 432 struct kernel_ethtool_ringparam *kernel_ring, 433 struct netlink_ext_ack *extack) 434 { 435 struct mana_port_context *apc = netdev_priv(ndev); 436 437 ring->rx_pending = apc->rx_queue_size; 438 ring->tx_pending = apc->tx_queue_size; 439 ring->rx_max_pending = MAX_RX_BUFFERS_PER_QUEUE; 440 ring->tx_max_pending = MAX_TX_BUFFERS_PER_QUEUE; 441 } 442 443 static int mana_set_ringparam(struct net_device *ndev, 444 struct ethtool_ringparam *ring, 445 struct kernel_ethtool_ringparam *kernel_ring, 446 struct netlink_ext_ack *extack) 447 { 448 struct mana_port_context *apc = netdev_priv(ndev); 449 u32 new_tx, new_rx; 450 u32 old_tx, old_rx; 451 int err; 452 453 old_tx = apc->tx_queue_size; 454 old_rx = apc->rx_queue_size; 455 456 if (ring->tx_pending < MIN_TX_BUFFERS_PER_QUEUE) { 457 NL_SET_ERR_MSG_FMT(extack, "tx:%d less than the min:%d", ring->tx_pending, 458 MIN_TX_BUFFERS_PER_QUEUE); 459 return -EINVAL; 460 } 461 462 if (ring->rx_pending < MIN_RX_BUFFERS_PER_QUEUE) { 463 NL_SET_ERR_MSG_FMT(extack, "rx:%d less than the min:%d", ring->rx_pending, 464 MIN_RX_BUFFERS_PER_QUEUE); 465 return -EINVAL; 466 } 467 468 new_rx = roundup_pow_of_two(ring->rx_pending); 469 new_tx = roundup_pow_of_two(ring->tx_pending); 470 netdev_info(ndev, "Using nearest power of 2 values for Txq:%d Rxq:%d\n", 471 new_tx, new_rx); 472 473 /* pre-allocating new buffers to prevent failures in mana_attach() later */ 474 apc->rx_queue_size = new_rx; 475 err = mana_pre_alloc_rxbufs(apc, ndev->mtu, apc->num_queues); 476 apc->rx_queue_size = old_rx; 477 if (err) { 478 netdev_err(ndev, "Insufficient memory for new allocations\n"); 479 return err; 480 } 481 482 err = mana_detach(ndev, false); 483 if (err) { 484 netdev_err(ndev, "mana_detach failed: %d\n", err); 485 goto out; 486 } 487 488 apc->tx_queue_size = new_tx; 489 apc->rx_queue_size = new_rx; 490 491 err = mana_attach(ndev); 492 if (err) { 493 netdev_err(ndev, "mana_attach failed: %d\n", err); 494 apc->tx_queue_size = old_tx; 495 apc->rx_queue_size = old_rx; 496 } 497 out: 498 mana_pre_dealloc_rxbufs(apc); 499 return err; 500 } 501 502 static int mana_get_link_ksettings(struct net_device *ndev, 503 struct ethtool_link_ksettings *cmd) 504 { 505 struct mana_port_context *apc = netdev_priv(ndev); 506 int err; 507 508 err = mana_query_link_cfg(apc); 509 cmd->base.speed = (err) ? SPEED_UNKNOWN : apc->max_speed; 510 511 cmd->base.duplex = DUPLEX_FULL; 512 cmd->base.port = PORT_OTHER; 513 514 return 0; 515 } 516 517 const struct ethtool_ops mana_ethtool_ops = { 518 .get_ethtool_stats = mana_get_ethtool_stats, 519 .get_sset_count = mana_get_sset_count, 520 .get_strings = mana_get_strings, 521 .get_rxnfc = mana_get_rxnfc, 522 .get_rxfh_key_size = mana_get_rxfh_key_size, 523 .get_rxfh_indir_size = mana_rss_indir_size, 524 .get_rxfh = mana_get_rxfh, 525 .set_rxfh = mana_set_rxfh, 526 .get_channels = mana_get_channels, 527 .set_channels = mana_set_channels, 528 .get_ringparam = mana_get_ringparam, 529 .set_ringparam = mana_set_ringparam, 530 .get_link_ksettings = mana_get_link_ksettings, 531 .get_link = ethtool_op_get_link, 532 }; 533