| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* Marvell RVU Ethernet driver |
| 3 |
* |
| 4 |
* Copyright (C) 2020 Marvell. |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/pci.h> |
| 9 |
#include <linux/ethtool.h> |
| 10 |
#include <linux/stddef.h> |
| 11 |
#include <linux/etherdevice.h> |
| 12 |
#include <linux/log2.h> |
| 13 |
#include <linux/net_tstamp.h> |
| 14 |
#include <linux/linkmode.h> |
| 15 |
|
| 16 |
#include "otx2_common.h" |
| 17 |
#include "otx2_ptp.h" |
| 18 |
#include <cgx_fw_if.h> |
| 19 |
|
| 20 |
#define DRV_NAME "rvu-nicpf" |
| 21 |
#define DRV_VF_NAME "rvu-nicvf" |
| 22 |
|
| 23 |
struct otx2_stat { |
| 24 |
char name[ETH_GSTRING_LEN]; |
| 25 |
unsigned int index; |
| 26 |
}; |
| 27 |
|
| 28 |
/* HW device stats */ |
| 29 |
#define OTX2_DEV_STAT(stat) { \ |
| 30 |
.name = #stat, \ |
| 31 |
.index = offsetof(struct otx2_dev_stats, stat) / sizeof(u64), \ |
| 32 |
} |
| 33 |
|
| 34 |
enum link_mode { |
| 35 |
OTX2_MODE_SUPPORTED, |
| 36 |
OTX2_MODE_ADVERTISED |
| 37 |
}; |
| 38 |
|
| 39 |
static const struct otx2_stat otx2_dev_stats[] = { |
| 40 |
OTX2_DEV_STAT(rx_ucast_frames), |
| 41 |
OTX2_DEV_STAT(rx_bcast_frames), |
| 42 |
OTX2_DEV_STAT(rx_mcast_frames), |
| 43 |
|
| 44 |
OTX2_DEV_STAT(tx_ucast_frames), |
| 45 |
OTX2_DEV_STAT(tx_bcast_frames), |
| 46 |
OTX2_DEV_STAT(tx_mcast_frames), |
| 47 |
}; |
| 48 |
|
| 49 |
/* Driver level stats */ |
| 50 |
#define OTX2_DRV_STAT(stat) { \ |
| 51 |
.name = #stat, \ |
| 52 |
.index = offsetof(struct otx2_drv_stats, stat) / sizeof(atomic_t), \ |
| 53 |
} |
| 54 |
|
| 55 |
static const struct otx2_stat otx2_drv_stats[] = { |
| 56 |
OTX2_DRV_STAT(rx_fcs_errs), |
| 57 |
OTX2_DRV_STAT(rx_oversize_errs), |
| 58 |
OTX2_DRV_STAT(rx_undersize_errs), |
| 59 |
OTX2_DRV_STAT(rx_csum_errs), |
| 60 |
OTX2_DRV_STAT(rx_len_errs), |
| 61 |
OTX2_DRV_STAT(rx_other_errs), |
| 62 |
}; |
| 63 |
|
| 64 |
static const struct otx2_stat otx2_queue_stats[] = { |
| 65 |
{ "bytes", 0 }, |
| 66 |
{ "frames", 1 }, |
| 67 |
}; |
| 68 |
|
| 69 |
#define OTX2_FEC_MAX_INDEX 4 |
| 70 |
|
| 71 |
static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats); |
| 72 |
static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats); |
| 73 |
static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats); |
| 74 |
|
| 75 |
static struct cgx_fw_data *otx2_get_fwdata(struct otx2_nic *pfvf); |
| 76 |
|
| 77 |
static void otx2_get_drvinfo(struct net_device *netdev, |
| 78 |
struct ethtool_drvinfo *info) |
| 79 |
{ |
| 80 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 81 |
|
| 82 |
strscpy(info->driver, DRV_NAME, sizeof(info->driver)); |
| 83 |
strscpy(info->bus_info, pci_name(pfvf->pdev), sizeof(info->bus_info)); |
| 84 |
} |
| 85 |
|
| 86 |
static void otx2_get_qset_strings(struct otx2_nic *pfvf, u8 **data, int qset) |
| 87 |
{ |
| 88 |
int start_qidx = qset * pfvf->hw.rx_queues; |
| 89 |
int qidx, stats; |
| 90 |
|
| 91 |
for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) |
| 92 |
for (stats = 0; stats < otx2_n_queue_stats; stats++) |
| 93 |
ethtool_sprintf(data, "rxq%d: %s", qidx + start_qidx, |
| 94 |
otx2_queue_stats[stats].name); |
| 95 |
|
| 96 |
for (qidx = 0; qidx < otx2_get_total_tx_queues(pfvf); qidx++) |
| 97 |
for (stats = 0; stats < otx2_n_queue_stats; stats++) |
| 98 |
if (qidx >= pfvf->hw.non_qos_queues) |
| 99 |
ethtool_sprintf(data, "txq_qos%d: %s", |
| 100 |
qidx + start_qidx - |
| 101 |
pfvf->hw.non_qos_queues, |
| 102 |
otx2_queue_stats[stats].name); |
| 103 |
else |
| 104 |
ethtool_sprintf(data, "txq%d: %s", |
| 105 |
qidx + start_qidx, |
| 106 |
otx2_queue_stats[stats].name); |
| 107 |
} |
| 108 |
|
| 109 |
static void otx2_get_strings(struct net_device *netdev, u32 sset, u8 *data) |
| 110 |
{ |
| 111 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 112 |
int stats; |
| 113 |
|
| 114 |
if (sset != ETH_SS_STATS) |
| 115 |
return; |
| 116 |
|
| 117 |
for (stats = 0; stats < otx2_n_dev_stats; stats++) |
| 118 |
ethtool_puts(&data, otx2_dev_stats[stats].name); |
| 119 |
|
| 120 |
for (stats = 0; stats < otx2_n_drv_stats; stats++) |
| 121 |
ethtool_puts(&data, otx2_drv_stats[stats].name); |
| 122 |
|
| 123 |
otx2_get_qset_strings(pfvf, &data, 0); |
| 124 |
|
| 125 |
if (!test_bit(CN10K_RPM, &pfvf->hw.cap_flag)) { |
| 126 |
for (stats = 0; stats < CGX_RX_STATS_COUNT; stats++) |
| 127 |
ethtool_sprintf(&data, "cgx_rxstat%d: ", stats); |
| 128 |
|
| 129 |
for (stats = 0; stats < CGX_TX_STATS_COUNT; stats++) |
| 130 |
ethtool_sprintf(&data, "cgx_txstat%d: ", stats); |
| 131 |
} |
| 132 |
|
| 133 |
ethtool_puts(&data, "reset_count"); |
| 134 |
ethtool_puts(&data, "Fec Corrected Errors: "); |
| 135 |
ethtool_puts(&data, "Fec Uncorrected Errors: "); |
| 136 |
} |
| 137 |
|
| 138 |
static void otx2_get_qset_stats(struct otx2_nic *pfvf, |
| 139 |
struct ethtool_stats *stats, u64 **data) |
| 140 |
{ |
| 141 |
int stat, qidx; |
| 142 |
|
| 143 |
if (!pfvf) |
| 144 |
return; |
| 145 |
for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) { |
| 146 |
if (!otx2_update_rq_stats(pfvf, qidx)) { |
| 147 |
for (stat = 0; stat < otx2_n_queue_stats; stat++) |
| 148 |
*((*data)++) = 0; |
| 149 |
continue; |
| 150 |
} |
| 151 |
for (stat = 0; stat < otx2_n_queue_stats; stat++) |
| 152 |
*((*data)++) = ((u64 *)&pfvf->qset.rq[qidx].stats) |
| 153 |
[otx2_queue_stats[stat].index]; |
| 154 |
} |
| 155 |
|
| 156 |
for (qidx = 0; qidx < otx2_get_total_tx_queues(pfvf); qidx++) { |
| 157 |
if (!otx2_update_sq_stats(pfvf, qidx)) { |
| 158 |
for (stat = 0; stat < otx2_n_queue_stats; stat++) |
| 159 |
*((*data)++) = 0; |
| 160 |
continue; |
| 161 |
} |
| 162 |
for (stat = 0; stat < otx2_n_queue_stats; stat++) |
| 163 |
*((*data)++) = ((u64 *)&pfvf->qset.sq[qidx].stats) |
| 164 |
[otx2_queue_stats[stat].index]; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
static int otx2_get_phy_fec_stats(struct otx2_nic *pfvf) |
| 169 |
{ |
| 170 |
struct msg_req *req; |
| 171 |
int rc = -ENOMEM; |
| 172 |
|
| 173 |
mutex_lock(&pfvf->mbox.lock); |
| 174 |
req = otx2_mbox_alloc_msg_cgx_get_phy_fec_stats(&pfvf->mbox); |
| 175 |
if (!req) |
| 176 |
goto end; |
| 177 |
|
| 178 |
if (!otx2_sync_mbox_msg(&pfvf->mbox)) |
| 179 |
rc = 0; |
| 180 |
end: |
| 181 |
mutex_unlock(&pfvf->mbox.lock); |
| 182 |
return rc; |
| 183 |
} |
| 184 |
|
| 185 |
/* Get device and per queue statistics */ |
| 186 |
static void otx2_get_ethtool_stats(struct net_device *netdev, |
| 187 |
struct ethtool_stats *stats, u64 *data) |
| 188 |
{ |
| 189 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 190 |
u64 fec_corr_blks, fec_uncorr_blks; |
| 191 |
struct cgx_fw_data *rsp; |
| 192 |
int stat; |
| 193 |
|
| 194 |
otx2_get_dev_stats(pfvf); |
| 195 |
for (stat = 0; stat < otx2_n_dev_stats; stat++) |
| 196 |
*(data++) = ((u64 *)&pfvf->hw.dev_stats) |
| 197 |
[otx2_dev_stats[stat].index]; |
| 198 |
|
| 199 |
for (stat = 0; stat < otx2_n_drv_stats; stat++) |
| 200 |
*(data++) = atomic_read(&((atomic_t *)&pfvf->hw.drv_stats) |
| 201 |
[otx2_drv_stats[stat].index]); |
| 202 |
|
| 203 |
otx2_get_qset_stats(pfvf, stats, &data); |
| 204 |
|
| 205 |
if (!test_bit(CN10K_RPM, &pfvf->hw.cap_flag)) { |
| 206 |
otx2_update_lmac_stats(pfvf); |
| 207 |
for (stat = 0; stat < CGX_RX_STATS_COUNT; stat++) |
| 208 |
*(data++) = pfvf->hw.cgx_rx_stats[stat]; |
| 209 |
for (stat = 0; stat < CGX_TX_STATS_COUNT; stat++) |
| 210 |
*(data++) = pfvf->hw.cgx_tx_stats[stat]; |
| 211 |
} |
| 212 |
|
| 213 |
*(data++) = pfvf->reset_count; |
| 214 |
|
| 215 |
fec_corr_blks = pfvf->hw.cgx_fec_corr_blks; |
| 216 |
fec_uncorr_blks = pfvf->hw.cgx_fec_uncorr_blks; |
| 217 |
|
| 218 |
rsp = otx2_get_fwdata(pfvf); |
| 219 |
if (!IS_ERR(rsp) && rsp->fwdata.phy.misc.has_fec_stats && |
| 220 |
!otx2_get_phy_fec_stats(pfvf)) { |
| 221 |
/* Fetch fwdata again because it's been recently populated with |
| 222 |
* latest PHY FEC stats. |
| 223 |
*/ |
| 224 |
rsp = otx2_get_fwdata(pfvf); |
| 225 |
if (!IS_ERR(rsp)) { |
| 226 |
struct fec_stats_s *p = &rsp->fwdata.phy.fec_stats; |
| 227 |
|
| 228 |
if (pfvf->linfo.fec == OTX2_FEC_BASER) { |
| 229 |
fec_corr_blks = p->brfec_corr_blks; |
| 230 |
fec_uncorr_blks = p->brfec_uncorr_blks; |
| 231 |
} else { |
| 232 |
fec_corr_blks = p->rsfec_corr_cws; |
| 233 |
fec_uncorr_blks = p->rsfec_uncorr_cws; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
*(data++) = fec_corr_blks; |
| 239 |
*(data++) = fec_uncorr_blks; |
| 240 |
} |
| 241 |
|
| 242 |
static int otx2_get_sset_count(struct net_device *netdev, int sset) |
| 243 |
{ |
| 244 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 245 |
int qstats_count, mac_stats = 0; |
| 246 |
|
| 247 |
if (sset != ETH_SS_STATS) |
| 248 |
return -EINVAL; |
| 249 |
|
| 250 |
qstats_count = otx2_n_queue_stats * |
| 251 |
(pfvf->hw.rx_queues + otx2_get_total_tx_queues(pfvf)); |
| 252 |
if (!test_bit(CN10K_RPM, &pfvf->hw.cap_flag)) |
| 253 |
mac_stats = CGX_RX_STATS_COUNT + CGX_TX_STATS_COUNT; |
| 254 |
otx2_update_lmac_fec_stats(pfvf); |
| 255 |
|
| 256 |
return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + |
| 257 |
mac_stats + OTX2_FEC_STATS_CNT + 1; |
| 258 |
} |
| 259 |
|
| 260 |
/* Get no of queues device supports and current queue count */ |
| 261 |
static void otx2_get_channels(struct net_device *dev, |
| 262 |
struct ethtool_channels *channel) |
| 263 |
{ |
| 264 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 265 |
|
| 266 |
channel->max_rx = pfvf->hw.max_queues; |
| 267 |
channel->max_tx = pfvf->hw.max_queues; |
| 268 |
|
| 269 |
channel->rx_count = pfvf->hw.rx_queues; |
| 270 |
channel->tx_count = pfvf->hw.tx_queues; |
| 271 |
} |
| 272 |
|
| 273 |
/* Set no of Tx, Rx queues to be used */ |
| 274 |
static int otx2_set_channels(struct net_device *dev, |
| 275 |
struct ethtool_channels *channel) |
| 276 |
{ |
| 277 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 278 |
bool if_up = netif_running(dev); |
| 279 |
int err, qos_txqs; |
| 280 |
|
| 281 |
if (!channel->rx_count || !channel->tx_count) |
| 282 |
return -EINVAL; |
| 283 |
|
| 284 |
if (bitmap_weight(&pfvf->rq_bmap, pfvf->hw.rx_queues) > 1) { |
| 285 |
netdev_err(dev, |
| 286 |
"Receive queues are in use by TC police action\n"); |
| 287 |
return -EINVAL; |
| 288 |
} |
| 289 |
|
| 290 |
if (if_up) |
| 291 |
dev->netdev_ops->ndo_stop(dev); |
| 292 |
|
| 293 |
qos_txqs = bitmap_weight(pfvf->qos.qos_sq_bmap, |
| 294 |
OTX2_QOS_MAX_LEAF_NODES); |
| 295 |
|
| 296 |
err = otx2_set_real_num_queues(dev, channel->tx_count + qos_txqs, |
| 297 |
channel->rx_count); |
| 298 |
if (err) |
| 299 |
return err; |
| 300 |
|
| 301 |
pfvf->hw.rx_queues = channel->rx_count; |
| 302 |
pfvf->hw.tx_queues = channel->tx_count; |
| 303 |
if (pfvf->xdp_prog) |
| 304 |
pfvf->hw.xdp_queues = channel->rx_count; |
| 305 |
|
| 306 |
if (if_up) |
| 307 |
err = dev->netdev_ops->ndo_open(dev); |
| 308 |
|
| 309 |
netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n", |
| 310 |
pfvf->hw.tx_queues, pfvf->hw.rx_queues); |
| 311 |
|
| 312 |
return err; |
| 313 |
} |
| 314 |
|
| 315 |
static void otx2_get_pauseparam(struct net_device *netdev, |
| 316 |
struct ethtool_pauseparam *pause) |
| 317 |
{ |
| 318 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 319 |
struct cgx_pause_frm_cfg *req, *rsp; |
| 320 |
|
| 321 |
if (is_otx2_lbkvf(pfvf->pdev) || is_otx2_sdp_rep(pfvf->pdev)) |
| 322 |
return; |
| 323 |
|
| 324 |
mutex_lock(&pfvf->mbox.lock); |
| 325 |
req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox); |
| 326 |
if (!req) { |
| 327 |
mutex_unlock(&pfvf->mbox.lock); |
| 328 |
return; |
| 329 |
} |
| 330 |
|
| 331 |
if (!otx2_sync_mbox_msg(&pfvf->mbox)) { |
| 332 |
rsp = (struct cgx_pause_frm_cfg *) |
| 333 |
otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr); |
| 334 |
if (IS_ERR(rsp)) { |
| 335 |
mutex_unlock(&pfvf->mbox.lock); |
| 336 |
return; |
| 337 |
} |
| 338 |
|
| 339 |
pause->rx_pause = rsp->rx_pause; |
| 340 |
pause->tx_pause = rsp->tx_pause; |
| 341 |
} |
| 342 |
mutex_unlock(&pfvf->mbox.lock); |
| 343 |
} |
| 344 |
|
| 345 |
static int otx2_set_pauseparam(struct net_device *netdev, |
| 346 |
struct ethtool_pauseparam *pause) |
| 347 |
{ |
| 348 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 349 |
|
| 350 |
if (pause->autoneg) |
| 351 |
return -EOPNOTSUPP; |
| 352 |
|
| 353 |
if (is_otx2_lbkvf(pfvf->pdev) || is_otx2_sdp_rep(pfvf->pdev)) |
| 354 |
return -EOPNOTSUPP; |
| 355 |
|
| 356 |
if (pause->rx_pause) |
| 357 |
pfvf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED; |
| 358 |
else |
| 359 |
pfvf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED; |
| 360 |
|
| 361 |
if (pause->tx_pause) |
| 362 |
pfvf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED; |
| 363 |
else |
| 364 |
pfvf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED; |
| 365 |
|
| 366 |
return otx2_config_pause_frm(pfvf); |
| 367 |
} |
| 368 |
|
| 369 |
static void otx2_get_ringparam(struct net_device *netdev, |
| 370 |
struct ethtool_ringparam *ring, |
| 371 |
struct kernel_ethtool_ringparam *kernel_ring, |
| 372 |
struct netlink_ext_ack *extack) |
| 373 |
{ |
| 374 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 375 |
struct otx2_qset *qs = &pfvf->qset; |
| 376 |
|
| 377 |
ring->rx_max_pending = Q_COUNT(Q_SIZE_MAX); |
| 378 |
ring->rx_pending = qs->rqe_cnt ? qs->rqe_cnt : Q_COUNT(Q_SIZE_256); |
| 379 |
ring->tx_max_pending = Q_COUNT(Q_SIZE_MAX); |
| 380 |
ring->tx_pending = qs->sqe_cnt ? qs->sqe_cnt : Q_COUNT(Q_SIZE_4K); |
| 381 |
kernel_ring->rx_buf_len = pfvf->hw.rbuf_len; |
| 382 |
kernel_ring->cqe_size = pfvf->hw.xqe_size; |
| 383 |
} |
| 384 |
|
| 385 |
static int otx2_set_ringparam(struct net_device *netdev, |
| 386 |
struct ethtool_ringparam *ring, |
| 387 |
struct kernel_ethtool_ringparam *kernel_ring, |
| 388 |
struct netlink_ext_ack *extack) |
| 389 |
{ |
| 390 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 391 |
u32 rx_buf_len = kernel_ring->rx_buf_len; |
| 392 |
u32 old_rx_buf_len = pfvf->hw.rbuf_len; |
| 393 |
u32 xqe_size = kernel_ring->cqe_size; |
| 394 |
bool if_up = netif_running(netdev); |
| 395 |
struct otx2_qset *qs = &pfvf->qset; |
| 396 |
u32 rx_count, tx_count; |
| 397 |
|
| 398 |
if (ring->rx_mini_pending || ring->rx_jumbo_pending) |
| 399 |
return -EINVAL; |
| 400 |
|
| 401 |
/* Hardware supports max size of 32k for a receive buffer |
| 402 |
* and 1536 is typical ethernet frame size. |
| 403 |
*/ |
| 404 |
if (rx_buf_len && (rx_buf_len < 1536 || rx_buf_len > 32768)) { |
| 405 |
netdev_err(netdev, |
| 406 |
"Receive buffer range is 1536 - 32768"); |
| 407 |
return -EINVAL; |
| 408 |
} |
| 409 |
|
| 410 |
if (xqe_size != 128 && xqe_size != 512) { |
| 411 |
netdev_err(netdev, |
| 412 |
"Completion event size must be 128 or 512"); |
| 413 |
return -EINVAL; |
| 414 |
} |
| 415 |
|
| 416 |
/* Permitted lengths are 16 64 256 1K 4K 16K 64K 256K 1M */ |
| 417 |
rx_count = ring->rx_pending; |
| 418 |
/* On some silicon variants a skid or reserved CQEs are |
| 419 |
* needed to avoid CQ overflow. |
| 420 |
*/ |
| 421 |
if (rx_count < pfvf->hw.rq_skid) |
| 422 |
rx_count = pfvf->hw.rq_skid; |
| 423 |
|
| 424 |
if (ring->rx_pending < 16) { |
| 425 |
netdev_err(netdev, |
| 426 |
"rx ring size %u invalid, min is 16\n", |
| 427 |
ring->rx_pending); |
| 428 |
return -EINVAL; |
| 429 |
} |
| 430 |
|
| 431 |
rx_count = Q_COUNT(Q_SIZE(rx_count, 3)); |
| 432 |
|
| 433 |
/* Due pipelining impact minimum 2000 unused SQ CQE's |
| 434 |
* need to be maintained to avoid CQ overflow, hence the |
| 435 |
* minimum 4K size. |
| 436 |
*/ |
| 437 |
tx_count = clamp_t(u32, ring->tx_pending, |
| 438 |
Q_COUNT(Q_SIZE_4K), Q_COUNT(Q_SIZE_MAX)); |
| 439 |
tx_count = Q_COUNT(Q_SIZE(tx_count, 3)); |
| 440 |
|
| 441 |
if (tx_count == qs->sqe_cnt && rx_count == qs->rqe_cnt && |
| 442 |
rx_buf_len == old_rx_buf_len && xqe_size == pfvf->hw.xqe_size) |
| 443 |
return 0; |
| 444 |
|
| 445 |
if (if_up) |
| 446 |
netdev->netdev_ops->ndo_stop(netdev); |
| 447 |
|
| 448 |
/* Assigned to the nearest possible exponent. */ |
| 449 |
qs->sqe_cnt = tx_count; |
| 450 |
qs->rqe_cnt = rx_count; |
| 451 |
|
| 452 |
pfvf->hw.rbuf_len = rx_buf_len; |
| 453 |
pfvf->hw.xqe_size = xqe_size; |
| 454 |
|
| 455 |
if (if_up) |
| 456 |
return netdev->netdev_ops->ndo_open(netdev); |
| 457 |
|
| 458 |
return 0; |
| 459 |
} |
| 460 |
|
| 461 |
static int otx2_get_coalesce(struct net_device *netdev, |
| 462 |
struct ethtool_coalesce *cmd, |
| 463 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 464 |
struct netlink_ext_ack *extack) |
| 465 |
{ |
| 466 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 467 |
struct otx2_hw *hw = &pfvf->hw; |
| 468 |
|
| 469 |
cmd->rx_coalesce_usecs = hw->cq_time_wait; |
| 470 |
cmd->rx_max_coalesced_frames = hw->cq_ecount_wait; |
| 471 |
cmd->tx_coalesce_usecs = hw->cq_time_wait; |
| 472 |
cmd->tx_max_coalesced_frames = hw->cq_ecount_wait; |
| 473 |
if ((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) == |
| 474 |
OTX2_FLAG_ADPTV_INT_COAL_ENABLED) { |
| 475 |
cmd->use_adaptive_rx_coalesce = 1; |
| 476 |
cmd->use_adaptive_tx_coalesce = 1; |
| 477 |
} else { |
| 478 |
cmd->use_adaptive_rx_coalesce = 0; |
| 479 |
cmd->use_adaptive_tx_coalesce = 0; |
| 480 |
} |
| 481 |
|
| 482 |
return 0; |
| 483 |
} |
| 484 |
|
| 485 |
static int otx2_set_coalesce(struct net_device *netdev, |
| 486 |
struct ethtool_coalesce *ec, |
| 487 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 488 |
struct netlink_ext_ack *extack) |
| 489 |
{ |
| 490 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 491 |
struct otx2_hw *hw = &pfvf->hw; |
| 492 |
u8 priv_coalesce_status; |
| 493 |
int qidx; |
| 494 |
|
| 495 |
if (!ec->rx_max_coalesced_frames || !ec->tx_max_coalesced_frames) |
| 496 |
return 0; |
| 497 |
|
| 498 |
if (ec->use_adaptive_rx_coalesce != ec->use_adaptive_tx_coalesce) { |
| 499 |
netdev_err(netdev, |
| 500 |
"adaptive-rx should be same as adaptive-tx"); |
| 501 |
return -EINVAL; |
| 502 |
} |
| 503 |
|
| 504 |
/* Check and update coalesce status */ |
| 505 |
if ((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) == |
| 506 |
OTX2_FLAG_ADPTV_INT_COAL_ENABLED) { |
| 507 |
priv_coalesce_status = 1; |
| 508 |
if (!ec->use_adaptive_rx_coalesce) |
| 509 |
pfvf->flags &= ~OTX2_FLAG_ADPTV_INT_COAL_ENABLED; |
| 510 |
} else { |
| 511 |
priv_coalesce_status = 0; |
| 512 |
if (ec->use_adaptive_rx_coalesce) |
| 513 |
pfvf->flags |= OTX2_FLAG_ADPTV_INT_COAL_ENABLED; |
| 514 |
} |
| 515 |
|
| 516 |
/* 'cq_time_wait' is 8bit and is in multiple of 100ns, |
| 517 |
* so clamp the user given value to the range of 1 to 25usec. |
| 518 |
*/ |
| 519 |
ec->rx_coalesce_usecs = clamp_t(u32, ec->rx_coalesce_usecs, |
| 520 |
1, CQ_TIMER_THRESH_MAX); |
| 521 |
ec->tx_coalesce_usecs = clamp_t(u32, ec->tx_coalesce_usecs, |
| 522 |
1, CQ_TIMER_THRESH_MAX); |
| 523 |
|
| 524 |
/* Rx and Tx are mapped to same CQ, check which one |
| 525 |
* is changed, if both then choose the min. |
| 526 |
*/ |
| 527 |
if (hw->cq_time_wait == ec->rx_coalesce_usecs) |
| 528 |
hw->cq_time_wait = ec->tx_coalesce_usecs; |
| 529 |
else if (hw->cq_time_wait == ec->tx_coalesce_usecs) |
| 530 |
hw->cq_time_wait = ec->rx_coalesce_usecs; |
| 531 |
else |
| 532 |
hw->cq_time_wait = min_t(u8, ec->rx_coalesce_usecs, |
| 533 |
ec->tx_coalesce_usecs); |
| 534 |
|
| 535 |
/* Max ecount_wait supported is 16bit, |
| 536 |
* so clamp the user given value to the range of 1 to 64k. |
| 537 |
*/ |
| 538 |
ec->rx_max_coalesced_frames = clamp_t(u32, ec->rx_max_coalesced_frames, |
| 539 |
1, NAPI_POLL_WEIGHT); |
| 540 |
ec->tx_max_coalesced_frames = clamp_t(u32, ec->tx_max_coalesced_frames, |
| 541 |
1, NAPI_POLL_WEIGHT); |
| 542 |
|
| 543 |
/* Rx and Tx are mapped to same CQ, check which one |
| 544 |
* is changed, if both then choose the min. |
| 545 |
*/ |
| 546 |
if (hw->cq_ecount_wait == ec->rx_max_coalesced_frames) |
| 547 |
hw->cq_ecount_wait = ec->tx_max_coalesced_frames; |
| 548 |
else if (hw->cq_ecount_wait == ec->tx_max_coalesced_frames) |
| 549 |
hw->cq_ecount_wait = ec->rx_max_coalesced_frames; |
| 550 |
else |
| 551 |
hw->cq_ecount_wait = min_t(u16, ec->rx_max_coalesced_frames, |
| 552 |
ec->tx_max_coalesced_frames); |
| 553 |
|
| 554 |
/* Reset 'cq_time_wait' and 'cq_ecount_wait' to |
| 555 |
* default values if coalesce status changed from |
| 556 |
* 'on' to 'off'. |
| 557 |
*/ |
| 558 |
if (priv_coalesce_status && |
| 559 |
((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) != |
| 560 |
OTX2_FLAG_ADPTV_INT_COAL_ENABLED)) { |
| 561 |
hw->cq_time_wait = CQ_TIMER_THRESH_DEFAULT; |
| 562 |
hw->cq_ecount_wait = CQ_CQE_THRESH_DEFAULT; |
| 563 |
} |
| 564 |
|
| 565 |
if (netif_running(netdev)) { |
| 566 |
for (qidx = 0; qidx < pfvf->hw.cint_cnt; qidx++) |
| 567 |
otx2_config_irq_coalescing(pfvf, qidx); |
| 568 |
} |
| 569 |
|
| 570 |
return 0; |
| 571 |
} |
| 572 |
|
| 573 |
static u32 otx2_get_rx_ring_count(struct net_device *dev) |
| 574 |
{ |
| 575 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 576 |
|
| 577 |
return pfvf->hw.rx_queues; |
| 578 |
} |
| 579 |
|
| 580 |
static int otx2_get_rss_hash_opts(struct net_device *dev, |
| 581 |
struct ethtool_rxfh_fields *nfc) |
| 582 |
{ |
| 583 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 584 |
struct otx2_rss_info *rss; |
| 585 |
|
| 586 |
rss = &pfvf->hw.rss_info; |
| 587 |
|
| 588 |
if (!(rss->flowkey_cfg & |
| 589 |
(NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6))) |
| 590 |
return 0; |
| 591 |
|
| 592 |
/* Mimimum is IPv4 and IPv6, SIP/DIP */ |
| 593 |
nfc->data = RXH_IP_SRC | RXH_IP_DST; |
| 594 |
if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_VLAN) |
| 595 |
nfc->data |= RXH_VLAN; |
| 596 |
|
| 597 |
switch (nfc->flow_type) { |
| 598 |
case TCP_V4_FLOW: |
| 599 |
case TCP_V6_FLOW: |
| 600 |
if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_TCP) |
| 601 |
nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 602 |
break; |
| 603 |
case UDP_V4_FLOW: |
| 604 |
case UDP_V6_FLOW: |
| 605 |
if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_UDP) |
| 606 |
nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 607 |
break; |
| 608 |
case SCTP_V4_FLOW: |
| 609 |
case SCTP_V6_FLOW: |
| 610 |
if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_SCTP) |
| 611 |
nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 612 |
break; |
| 613 |
case AH_ESP_V4_FLOW: |
| 614 |
case AH_ESP_V6_FLOW: |
| 615 |
if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_ESP) |
| 616 |
nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 617 |
break; |
| 618 |
case AH_V4_FLOW: |
| 619 |
case ESP_V4_FLOW: |
| 620 |
case IPV4_FLOW: |
| 621 |
break; |
| 622 |
case AH_V6_FLOW: |
| 623 |
case ESP_V6_FLOW: |
| 624 |
case IPV6_FLOW: |
| 625 |
break; |
| 626 |
default: |
| 627 |
return -EINVAL; |
| 628 |
} |
| 629 |
|
| 630 |
return 0; |
| 631 |
} |
| 632 |
|
| 633 |
static int otx2_set_rss_hash_opts(struct net_device *dev, |
| 634 |
const struct ethtool_rxfh_fields *nfc, |
| 635 |
struct netlink_ext_ack *extack) |
| 636 |
{ |
| 637 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 638 |
u32 rxh_l4 = RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 639 |
struct otx2_rss_info *rss; |
| 640 |
u32 rss_cfg; |
| 641 |
|
| 642 |
rss = &pfvf->hw.rss_info; |
| 643 |
rss_cfg = rss->flowkey_cfg; |
| 644 |
|
| 645 |
if (!rss->enable) { |
| 646 |
netdev_err(pfvf->netdev, |
| 647 |
"RSS is disabled, cannot change settings\n"); |
| 648 |
return -EIO; |
| 649 |
} |
| 650 |
|
| 651 |
/* Mimimum is IPv4 and IPv6, SIP/DIP */ |
| 652 |
if (!(nfc->data & RXH_IP_SRC) || !(nfc->data & RXH_IP_DST)) |
| 653 |
return -EINVAL; |
| 654 |
|
| 655 |
if (nfc->data & RXH_VLAN) |
| 656 |
rss_cfg |= NIX_FLOW_KEY_TYPE_VLAN; |
| 657 |
else |
| 658 |
rss_cfg &= ~NIX_FLOW_KEY_TYPE_VLAN; |
| 659 |
|
| 660 |
switch (nfc->flow_type) { |
| 661 |
case TCP_V4_FLOW: |
| 662 |
case TCP_V6_FLOW: |
| 663 |
/* Different config for v4 and v6 is not supported. |
| 664 |
* Both of them have to be either 4-tuple or 2-tuple. |
| 665 |
*/ |
| 666 |
switch (nfc->data & rxh_l4) { |
| 667 |
case 0: |
| 668 |
rss_cfg &= ~NIX_FLOW_KEY_TYPE_TCP; |
| 669 |
break; |
| 670 |
case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 671 |
rss_cfg |= NIX_FLOW_KEY_TYPE_TCP; |
| 672 |
break; |
| 673 |
default: |
| 674 |
return -EINVAL; |
| 675 |
} |
| 676 |
break; |
| 677 |
case UDP_V4_FLOW: |
| 678 |
case UDP_V6_FLOW: |
| 679 |
switch (nfc->data & rxh_l4) { |
| 680 |
case 0: |
| 681 |
rss_cfg &= ~NIX_FLOW_KEY_TYPE_UDP; |
| 682 |
break; |
| 683 |
case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 684 |
rss_cfg |= NIX_FLOW_KEY_TYPE_UDP; |
| 685 |
break; |
| 686 |
default: |
| 687 |
return -EINVAL; |
| 688 |
} |
| 689 |
break; |
| 690 |
case SCTP_V4_FLOW: |
| 691 |
case SCTP_V6_FLOW: |
| 692 |
switch (nfc->data & rxh_l4) { |
| 693 |
case 0: |
| 694 |
rss_cfg &= ~NIX_FLOW_KEY_TYPE_SCTP; |
| 695 |
break; |
| 696 |
case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 697 |
rss_cfg |= NIX_FLOW_KEY_TYPE_SCTP; |
| 698 |
break; |
| 699 |
default: |
| 700 |
return -EINVAL; |
| 701 |
} |
| 702 |
break; |
| 703 |
case AH_ESP_V4_FLOW: |
| 704 |
case AH_ESP_V6_FLOW: |
| 705 |
switch (nfc->data & rxh_l4) { |
| 706 |
case 0: |
| 707 |
rss_cfg &= ~(NIX_FLOW_KEY_TYPE_ESP | |
| 708 |
NIX_FLOW_KEY_TYPE_AH); |
| 709 |
rss_cfg |= NIX_FLOW_KEY_TYPE_VLAN | |
| 710 |
NIX_FLOW_KEY_TYPE_IPV4_PROTO; |
| 711 |
break; |
| 712 |
case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 713 |
/* If VLAN hashing is also requested for ESP then do not |
| 714 |
* allow because of hardware 40 bytes flow key limit. |
| 715 |
*/ |
| 716 |
if (rss_cfg & NIX_FLOW_KEY_TYPE_VLAN) { |
| 717 |
netdev_err(pfvf->netdev, |
| 718 |
"RSS hash of ESP or AH with VLAN is not supported\n"); |
| 719 |
return -EOPNOTSUPP; |
| 720 |
} |
| 721 |
|
| 722 |
rss_cfg |= NIX_FLOW_KEY_TYPE_ESP | NIX_FLOW_KEY_TYPE_AH; |
| 723 |
/* Disable IPv4 proto hashing since IPv6 SA+DA(32 bytes) |
| 724 |
* and ESP SPI+sequence(8 bytes) uses hardware maximum |
| 725 |
* limit of 40 byte flow key. |
| 726 |
*/ |
| 727 |
rss_cfg &= ~NIX_FLOW_KEY_TYPE_IPV4_PROTO; |
| 728 |
break; |
| 729 |
default: |
| 730 |
return -EINVAL; |
| 731 |
} |
| 732 |
break; |
| 733 |
case IPV4_FLOW: |
| 734 |
case IPV6_FLOW: |
| 735 |
rss_cfg = NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6; |
| 736 |
break; |
| 737 |
default: |
| 738 |
return -EINVAL; |
| 739 |
} |
| 740 |
|
| 741 |
rss->flowkey_cfg = rss_cfg; |
| 742 |
otx2_set_flowkey_cfg(pfvf); |
| 743 |
return 0; |
| 744 |
} |
| 745 |
|
| 746 |
static int otx2_get_rxnfc(struct net_device *dev, |
| 747 |
struct ethtool_rxnfc *nfc, u32 *rules) |
| 748 |
{ |
| 749 |
bool ntuple = !!(dev->features & NETIF_F_NTUPLE); |
| 750 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 751 |
int ret = -EOPNOTSUPP; |
| 752 |
|
| 753 |
switch (nfc->cmd) { |
| 754 |
case ETHTOOL_GRXCLSRLCNT: |
| 755 |
if (netif_running(dev) && ntuple) { |
| 756 |
nfc->rule_cnt = pfvf->flow_cfg->nr_flows; |
| 757 |
ret = 0; |
| 758 |
} |
| 759 |
break; |
| 760 |
case ETHTOOL_GRXCLSRULE: |
| 761 |
if (netif_running(dev) && ntuple) |
| 762 |
ret = otx2_get_flow(pfvf, nfc, nfc->fs.location); |
| 763 |
break; |
| 764 |
case ETHTOOL_GRXCLSRLALL: |
| 765 |
if (netif_running(dev) && ntuple) |
| 766 |
ret = otx2_get_all_flows(pfvf, nfc, rules); |
| 767 |
break; |
| 768 |
default: |
| 769 |
break; |
| 770 |
} |
| 771 |
return ret; |
| 772 |
} |
| 773 |
|
| 774 |
static int otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc) |
| 775 |
{ |
| 776 |
bool ntuple = !!(dev->features & NETIF_F_NTUPLE); |
| 777 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 778 |
int ret = -EOPNOTSUPP; |
| 779 |
|
| 780 |
pfvf->flow_cfg->ntuple = ntuple; |
| 781 |
switch (nfc->cmd) { |
| 782 |
case ETHTOOL_SRXCLSRLINS: |
| 783 |
if (netif_running(dev) && ntuple) |
| 784 |
ret = otx2_add_flow(pfvf, nfc); |
| 785 |
break; |
| 786 |
case ETHTOOL_SRXCLSRLDEL: |
| 787 |
if (netif_running(dev) && ntuple) |
| 788 |
ret = otx2_remove_flow(pfvf, nfc->fs.location); |
| 789 |
break; |
| 790 |
default: |
| 791 |
break; |
| 792 |
} |
| 793 |
|
| 794 |
return ret; |
| 795 |
} |
| 796 |
|
| 797 |
static u32 otx2_get_rxfh_key_size(struct net_device *netdev) |
| 798 |
{ |
| 799 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 800 |
struct otx2_rss_info *rss; |
| 801 |
|
| 802 |
rss = &pfvf->hw.rss_info; |
| 803 |
|
| 804 |
return sizeof(rss->key); |
| 805 |
} |
| 806 |
|
| 807 |
static u32 otx2_get_rxfh_indir_size(struct net_device *dev) |
| 808 |
{ |
| 809 |
return MAX_RSS_INDIR_TBL_SIZE; |
| 810 |
} |
| 811 |
|
| 812 |
static int otx2_create_rxfh(struct net_device *dev, |
| 813 |
struct ethtool_rxfh_context *ctx, |
| 814 |
const struct ethtool_rxfh_param *rxfh, |
| 815 |
struct netlink_ext_ack *extack) |
| 816 |
{ |
| 817 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 818 |
struct otx2_rss_info *rss; |
| 819 |
unsigned int queues; |
| 820 |
u32 *ind_tbl; |
| 821 |
int idx; |
| 822 |
|
| 823 |
rss = &pfvf->hw.rss_info; |
| 824 |
queues = pfvf->hw.rx_queues; |
| 825 |
|
| 826 |
if (rxfh->hfunc && rxfh->hfunc != ETH_RSS_HASH_TOP) |
| 827 |
return -EOPNOTSUPP; |
| 828 |
ctx->hfunc = ETH_RSS_HASH_TOP; |
| 829 |
|
| 830 |
if (!rss->enable) { |
| 831 |
netdev_err(dev, "RSS is disabled, cannot change settings\n"); |
| 832 |
return -EIO; |
| 833 |
} |
| 834 |
|
| 835 |
ind_tbl = rxfh->indir; |
| 836 |
if (!ind_tbl) { |
| 837 |
ind_tbl = ethtool_rxfh_context_indir(ctx); |
| 838 |
for (idx = 0; idx < rss->rss_size; idx++) |
| 839 |
ind_tbl[idx] = ethtool_rxfh_indir_default(idx, queues); |
| 840 |
} |
| 841 |
|
| 842 |
otx2_set_rss_table(pfvf, rxfh->rss_context, ind_tbl); |
| 843 |
return 0; |
| 844 |
} |
| 845 |
|
| 846 |
static int otx2_modify_rxfh(struct net_device *dev, |
| 847 |
struct ethtool_rxfh_context *ctx, |
| 848 |
const struct ethtool_rxfh_param *rxfh, |
| 849 |
struct netlink_ext_ack *extack) |
| 850 |
{ |
| 851 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 852 |
|
| 853 |
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && |
| 854 |
rxfh->hfunc != ETH_RSS_HASH_TOP) |
| 855 |
return -EOPNOTSUPP; |
| 856 |
|
| 857 |
if (!pfvf->hw.rss_info.enable) { |
| 858 |
netdev_err(dev, "RSS is disabled, cannot change settings\n"); |
| 859 |
return -EIO; |
| 860 |
} |
| 861 |
|
| 862 |
if (rxfh->indir) |
| 863 |
otx2_set_rss_table(pfvf, rxfh->rss_context, rxfh->indir); |
| 864 |
|
| 865 |
return 0; |
| 866 |
} |
| 867 |
|
| 868 |
static int otx2_remove_rxfh(struct net_device *dev, |
| 869 |
struct ethtool_rxfh_context *ctx, |
| 870 |
u32 rss_context, |
| 871 |
struct netlink_ext_ack *extack) |
| 872 |
{ |
| 873 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 874 |
|
| 875 |
if (!pfvf->hw.rss_info.enable) { |
| 876 |
netdev_err(dev, "RSS is disabled, cannot change settings\n"); |
| 877 |
return -EIO; |
| 878 |
} |
| 879 |
|
| 880 |
otx2_rss_ctx_flow_del(pfvf, rss_context); |
| 881 |
return 0; |
| 882 |
} |
| 883 |
|
| 884 |
/* Configure RSS table and hash key */ |
| 885 |
static int otx2_set_rxfh(struct net_device *dev, |
| 886 |
struct ethtool_rxfh_param *rxfh, |
| 887 |
struct netlink_ext_ack *extack) |
| 888 |
{ |
| 889 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 890 |
struct otx2_rss_info *rss; |
| 891 |
int idx; |
| 892 |
|
| 893 |
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && |
| 894 |
rxfh->hfunc != ETH_RSS_HASH_TOP) |
| 895 |
return -EOPNOTSUPP; |
| 896 |
|
| 897 |
rss = &pfvf->hw.rss_info; |
| 898 |
|
| 899 |
if (!rss->enable) { |
| 900 |
netdev_err(dev, "RSS is disabled, cannot change settings\n"); |
| 901 |
return -EIO; |
| 902 |
} |
| 903 |
|
| 904 |
if (rxfh->key) { |
| 905 |
memcpy(rss->key, rxfh->key, sizeof(rss->key)); |
| 906 |
otx2_set_rss_key(pfvf); |
| 907 |
} |
| 908 |
|
| 909 |
if (rxfh->indir) { |
| 910 |
for (idx = 0; idx < rss->rss_size; idx++) |
| 911 |
rss->ind_tbl[idx] = rxfh->indir[idx]; |
| 912 |
} |
| 913 |
otx2_set_rss_table(pfvf, DEFAULT_RSS_CONTEXT_GROUP, NULL); |
| 914 |
|
| 915 |
return 0; |
| 916 |
} |
| 917 |
|
| 918 |
/* Get RSS configuration */ |
| 919 |
static int otx2_get_rxfh(struct net_device *dev, |
| 920 |
struct ethtool_rxfh_param *rxfh) |
| 921 |
{ |
| 922 |
struct otx2_nic *pfvf = netdev_priv(dev); |
| 923 |
struct otx2_rss_info *rss; |
| 924 |
u32 *indir = rxfh->indir; |
| 925 |
int idx, rx_queues; |
| 926 |
|
| 927 |
rss = &pfvf->hw.rss_info; |
| 928 |
|
| 929 |
rxfh->hfunc = ETH_RSS_HASH_TOP; |
| 930 |
if (!indir) |
| 931 |
return 0; |
| 932 |
|
| 933 |
if (!rss->enable) { |
| 934 |
rx_queues = pfvf->hw.rx_queues; |
| 935 |
for (idx = 0; idx < MAX_RSS_INDIR_TBL_SIZE; idx++) |
| 936 |
indir[idx] = ethtool_rxfh_indir_default(idx, rx_queues); |
| 937 |
return 0; |
| 938 |
} |
| 939 |
|
| 940 |
for (idx = 0; idx < rss->rss_size; idx++) { |
| 941 |
/* Ignore if the rx queue is AF_XDP zero copy enabled */ |
| 942 |
if (test_bit(rss->ind_tbl[idx], pfvf->af_xdp_zc_qidx)) |
| 943 |
continue; |
| 944 |
indir[idx] = rss->ind_tbl[idx]; |
| 945 |
} |
| 946 |
if (rxfh->key) |
| 947 |
memcpy(rxfh->key, rss->key, sizeof(rss->key)); |
| 948 |
|
| 949 |
return 0; |
| 950 |
} |
| 951 |
|
| 952 |
static u32 otx2_get_msglevel(struct net_device *netdev) |
| 953 |
{ |
| 954 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 955 |
|
| 956 |
return pfvf->msg_enable; |
| 957 |
} |
| 958 |
|
| 959 |
static void otx2_set_msglevel(struct net_device *netdev, u32 val) |
| 960 |
{ |
| 961 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 962 |
|
| 963 |
pfvf->msg_enable = val; |
| 964 |
} |
| 965 |
|
| 966 |
static u32 otx2_get_link(struct net_device *netdev) |
| 967 |
{ |
| 968 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 969 |
|
| 970 |
/* LBK and SDP links are internal and always UP */ |
| 971 |
if (is_otx2_lbkvf(pfvf->pdev) || is_otx2_sdp_rep(pfvf->pdev)) |
| 972 |
return 1; |
| 973 |
return pfvf->linfo.link_up; |
| 974 |
} |
| 975 |
|
| 976 |
static int otx2_get_ts_info(struct net_device *netdev, |
| 977 |
struct kernel_ethtool_ts_info *info) |
| 978 |
{ |
| 979 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 980 |
|
| 981 |
if (!pfvf->ptp) |
| 982 |
return ethtool_op_get_ts_info(netdev, info); |
| 983 |
|
| 984 |
info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 985 |
SOF_TIMESTAMPING_TX_HARDWARE | |
| 986 |
SOF_TIMESTAMPING_RX_HARDWARE | |
| 987 |
SOF_TIMESTAMPING_RAW_HARDWARE; |
| 988 |
|
| 989 |
info->phc_index = otx2_ptp_clock_index(pfvf); |
| 990 |
|
| 991 |
info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); |
| 992 |
if (test_bit(CN10K_PTP_ONESTEP, &pfvf->hw.cap_flag)) |
| 993 |
info->tx_types |= BIT(HWTSTAMP_TX_ONESTEP_SYNC); |
| 994 |
|
| 995 |
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | |
| 996 |
BIT(HWTSTAMP_FILTER_ALL); |
| 997 |
|
| 998 |
return 0; |
| 999 |
} |
| 1000 |
|
| 1001 |
static struct cgx_fw_data *otx2_get_fwdata(struct otx2_nic *pfvf) |
| 1002 |
{ |
| 1003 |
struct cgx_fw_data *rsp = NULL; |
| 1004 |
struct msg_req *req; |
| 1005 |
int err = 0; |
| 1006 |
|
| 1007 |
mutex_lock(&pfvf->mbox.lock); |
| 1008 |
req = otx2_mbox_alloc_msg_cgx_get_aux_link_info(&pfvf->mbox); |
| 1009 |
if (!req) { |
| 1010 |
mutex_unlock(&pfvf->mbox.lock); |
| 1011 |
return ERR_PTR(-ENOMEM); |
| 1012 |
} |
| 1013 |
|
| 1014 |
err = otx2_sync_mbox_msg(&pfvf->mbox); |
| 1015 |
if (!err) { |
| 1016 |
rsp = (struct cgx_fw_data *) |
| 1017 |
otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr); |
| 1018 |
} else { |
| 1019 |
rsp = ERR_PTR(err); |
| 1020 |
} |
| 1021 |
|
| 1022 |
mutex_unlock(&pfvf->mbox.lock); |
| 1023 |
return rsp; |
| 1024 |
} |
| 1025 |
|
| 1026 |
static int otx2_get_fecparam(struct net_device *netdev, |
| 1027 |
struct ethtool_fecparam *fecparam) |
| 1028 |
{ |
| 1029 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 1030 |
struct cgx_fw_data *rsp; |
| 1031 |
const int fec[] = { |
| 1032 |
ETHTOOL_FEC_OFF, |
| 1033 |
ETHTOOL_FEC_BASER, |
| 1034 |
ETHTOOL_FEC_RS, |
| 1035 |
ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS}; |
| 1036 |
|
| 1037 |
fecparam->active_fec = fec[pfvf->linfo.fec]; |
| 1038 |
|
| 1039 |
rsp = otx2_get_fwdata(pfvf); |
| 1040 |
if (IS_ERR(rsp)) |
| 1041 |
return PTR_ERR(rsp); |
| 1042 |
|
| 1043 |
if (rsp->fwdata.supported_fec < OTX2_FEC_MAX_INDEX) { |
| 1044 |
if (!rsp->fwdata.supported_fec) |
| 1045 |
fecparam->fec = ETHTOOL_FEC_NONE; |
| 1046 |
else |
| 1047 |
fecparam->fec = fec[rsp->fwdata.supported_fec]; |
| 1048 |
} |
| 1049 |
return 0; |
| 1050 |
} |
| 1051 |
|
| 1052 |
static int otx2_set_fecparam(struct net_device *netdev, |
| 1053 |
struct ethtool_fecparam *fecparam) |
| 1054 |
{ |
| 1055 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 1056 |
struct mbox *mbox = &pfvf->mbox; |
| 1057 |
struct fec_mode *req, *rsp; |
| 1058 |
int err = 0, fec = 0; |
| 1059 |
|
| 1060 |
switch (fecparam->fec) { |
| 1061 |
/* Firmware does not support AUTO mode consider it as FEC_OFF */ |
| 1062 |
case ETHTOOL_FEC_OFF: |
| 1063 |
case ETHTOOL_FEC_AUTO: |
| 1064 |
fec = OTX2_FEC_OFF; |
| 1065 |
break; |
| 1066 |
case ETHTOOL_FEC_RS: |
| 1067 |
fec = OTX2_FEC_RS; |
| 1068 |
break; |
| 1069 |
case ETHTOOL_FEC_BASER: |
| 1070 |
fec = OTX2_FEC_BASER; |
| 1071 |
break; |
| 1072 |
default: |
| 1073 |
netdev_warn(pfvf->netdev, "Unsupported FEC mode: %d", |
| 1074 |
fecparam->fec); |
| 1075 |
return -EINVAL; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (fec == pfvf->linfo.fec) |
| 1079 |
return 0; |
| 1080 |
|
| 1081 |
mutex_lock(&mbox->lock); |
| 1082 |
req = otx2_mbox_alloc_msg_cgx_set_fec_param(&pfvf->mbox); |
| 1083 |
if (!req) { |
| 1084 |
err = -ENOMEM; |
| 1085 |
goto end; |
| 1086 |
} |
| 1087 |
req->fec = fec; |
| 1088 |
err = otx2_sync_mbox_msg(&pfvf->mbox); |
| 1089 |
if (err) |
| 1090 |
goto end; |
| 1091 |
|
| 1092 |
rsp = (struct fec_mode *)otx2_mbox_get_rsp(&pfvf->mbox.mbox, |
| 1093 |
0, &req->hdr); |
| 1094 |
if (IS_ERR(rsp)) { |
| 1095 |
err = PTR_ERR(rsp); |
| 1096 |
goto end; |
| 1097 |
} |
| 1098 |
|
| 1099 |
if (rsp->fec >= 0) |
| 1100 |
pfvf->linfo.fec = rsp->fec; |
| 1101 |
else |
| 1102 |
err = rsp->fec; |
| 1103 |
end: |
| 1104 |
mutex_unlock(&mbox->lock); |
| 1105 |
return err; |
| 1106 |
} |
| 1107 |
|
| 1108 |
static void otx2_get_fec_info(u64 index, int req_mode, |
| 1109 |
struct ethtool_link_ksettings *link_ksettings) |
| 1110 |
{ |
| 1111 |
__ETHTOOL_DECLARE_LINK_MODE_MASK(otx2_fec_modes) = { 0, }; |
| 1112 |
|
| 1113 |
switch (index) { |
| 1114 |
case OTX2_FEC_NONE: |
| 1115 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT, |
| 1116 |
otx2_fec_modes); |
| 1117 |
break; |
| 1118 |
case OTX2_FEC_BASER: |
| 1119 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT, |
| 1120 |
otx2_fec_modes); |
| 1121 |
break; |
| 1122 |
case OTX2_FEC_RS: |
| 1123 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT, |
| 1124 |
otx2_fec_modes); |
| 1125 |
break; |
| 1126 |
case OTX2_FEC_BASER | OTX2_FEC_RS: |
| 1127 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT, |
| 1128 |
otx2_fec_modes); |
| 1129 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT, |
| 1130 |
otx2_fec_modes); |
| 1131 |
break; |
| 1132 |
} |
| 1133 |
|
| 1134 |
/* Add fec modes to existing modes */ |
| 1135 |
if (req_mode == OTX2_MODE_ADVERTISED) |
| 1136 |
linkmode_or(link_ksettings->link_modes.advertising, |
| 1137 |
link_ksettings->link_modes.advertising, |
| 1138 |
otx2_fec_modes); |
| 1139 |
else |
| 1140 |
linkmode_or(link_ksettings->link_modes.supported, |
| 1141 |
link_ksettings->link_modes.supported, |
| 1142 |
otx2_fec_modes); |
| 1143 |
} |
| 1144 |
|
| 1145 |
static void otx2_get_link_mode_info(u64 link_mode_bmap, |
| 1146 |
bool req_mode, |
| 1147 |
struct ethtool_link_ksettings |
| 1148 |
*link_ksettings) |
| 1149 |
{ |
| 1150 |
__ETHTOOL_DECLARE_LINK_MODE_MASK(otx2_link_modes) = { 0, }; |
| 1151 |
/* CGX link modes to Ethtool link mode mapping */ |
| 1152 |
const int cgx_link_mode[CGX_MODE_MAX] = { |
| 1153 |
0, /* SGMII 1000baseT */ |
| 1154 |
ETHTOOL_LINK_MODE_1000baseX_Full_BIT, |
| 1155 |
ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
| 1156 |
ETHTOOL_LINK_MODE_10000baseSR_Full_BIT, |
| 1157 |
ETHTOOL_LINK_MODE_10000baseLR_Full_BIT, |
| 1158 |
ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, |
| 1159 |
0, |
| 1160 |
ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, |
| 1161 |
0, |
| 1162 |
0, |
| 1163 |
ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, |
| 1164 |
ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, |
| 1165 |
ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT, |
| 1166 |
ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT, |
| 1167 |
ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, |
| 1168 |
ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, |
| 1169 |
0, |
| 1170 |
ETHTOOL_LINK_MODE_50000baseSR_Full_BIT, |
| 1171 |
0, |
| 1172 |
ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT, |
| 1173 |
ETHTOOL_LINK_MODE_50000baseCR_Full_BIT, |
| 1174 |
ETHTOOL_LINK_MODE_50000baseKR_Full_BIT, |
| 1175 |
0, |
| 1176 |
ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT, |
| 1177 |
ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT, |
| 1178 |
ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, |
| 1179 |
ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT |
| 1180 |
}; |
| 1181 |
u8 bit; |
| 1182 |
|
| 1183 |
for_each_set_bit(bit, (unsigned long *)&link_mode_bmap, ARRAY_SIZE(cgx_link_mode)) { |
| 1184 |
if (bit == CGX_MODE_SGMII_10M_BIT) { |
| 1185 |
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, otx2_link_modes); |
| 1186 |
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, otx2_link_modes); |
| 1187 |
} else if (bit == CGX_MODE_SGMII_100M_BIT) { |
| 1188 |
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, otx2_link_modes); |
| 1189 |
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, otx2_link_modes); |
| 1190 |
} else if (bit == CGX_MODE_SGMII) { |
| 1191 |
linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, otx2_link_modes); |
| 1192 |
linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, otx2_link_modes); |
| 1193 |
} else { |
| 1194 |
linkmode_set_bit(cgx_link_mode[bit], otx2_link_modes); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
if (req_mode == OTX2_MODE_ADVERTISED) |
| 1199 |
linkmode_copy(link_ksettings->link_modes.advertising, |
| 1200 |
otx2_link_modes); |
| 1201 |
else |
| 1202 |
linkmode_copy(link_ksettings->link_modes.supported, |
| 1203 |
otx2_link_modes); |
| 1204 |
} |
| 1205 |
|
| 1206 |
static int otx2_get_link_ksettings(struct net_device *netdev, |
| 1207 |
struct ethtool_link_ksettings *cmd) |
| 1208 |
{ |
| 1209 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 1210 |
struct cgx_fw_data *rsp = NULL; |
| 1211 |
|
| 1212 |
cmd->base.duplex = pfvf->linfo.full_duplex; |
| 1213 |
cmd->base.speed = pfvf->linfo.speed; |
| 1214 |
cmd->base.autoneg = pfvf->linfo.an; |
| 1215 |
|
| 1216 |
rsp = otx2_get_fwdata(pfvf); |
| 1217 |
if (IS_ERR(rsp)) |
| 1218 |
return PTR_ERR(rsp); |
| 1219 |
|
| 1220 |
if (rsp->fwdata.supported_an) |
| 1221 |
ethtool_link_ksettings_add_link_mode(cmd, |
| 1222 |
supported, |
| 1223 |
Autoneg); |
| 1224 |
|
| 1225 |
otx2_get_link_mode_info(rsp->fwdata.advertised_link_modes, |
| 1226 |
OTX2_MODE_ADVERTISED, cmd); |
| 1227 |
otx2_get_fec_info(rsp->fwdata.advertised_fec, |
| 1228 |
OTX2_MODE_ADVERTISED, cmd); |
| 1229 |
otx2_get_link_mode_info(rsp->fwdata.supported_link_modes, |
| 1230 |
OTX2_MODE_SUPPORTED, cmd); |
| 1231 |
otx2_get_fec_info(rsp->fwdata.supported_fec, |
| 1232 |
OTX2_MODE_SUPPORTED, cmd); |
| 1233 |
return 0; |
| 1234 |
} |
| 1235 |
|
| 1236 |
static int otx2_set_link_ksettings(struct net_device *netdev, |
| 1237 |
const struct ethtool_link_ksettings *cmd) |
| 1238 |
{ |
| 1239 |
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; |
| 1240 |
struct otx2_nic *pf = netdev_priv(netdev); |
| 1241 |
struct ethtool_link_ksettings cur_ks; |
| 1242 |
struct cgx_set_link_mode_req *req; |
| 1243 |
struct mbox *mbox = &pf->mbox; |
| 1244 |
int err = 0; |
| 1245 |
|
| 1246 |
memset(&cur_ks, 0, sizeof(struct ethtool_link_ksettings)); |
| 1247 |
|
| 1248 |
if (!ethtool_validate_speed(cmd->base.speed) || |
| 1249 |
!ethtool_validate_duplex(cmd->base.duplex)) |
| 1250 |
return -EINVAL; |
| 1251 |
|
| 1252 |
if (cmd->base.autoneg != AUTONEG_ENABLE && |
| 1253 |
cmd->base.autoneg != AUTONEG_DISABLE) |
| 1254 |
return -EINVAL; |
| 1255 |
|
| 1256 |
otx2_get_link_ksettings(netdev, &cur_ks); |
| 1257 |
|
| 1258 |
/* Check requested modes against supported modes by hardware */ |
| 1259 |
if (!linkmode_subset(cmd->link_modes.advertising, |
| 1260 |
cur_ks.link_modes.supported)) |
| 1261 |
return -EINVAL; |
| 1262 |
|
| 1263 |
mutex_lock(&mbox->lock); |
| 1264 |
req = otx2_mbox_alloc_msg_cgx_set_link_mode(&pf->mbox); |
| 1265 |
if (!req) { |
| 1266 |
err = -ENOMEM; |
| 1267 |
goto end; |
| 1268 |
} |
| 1269 |
|
| 1270 |
req->args.speed = cmd->base.speed; |
| 1271 |
/* firmware expects 1 for half duplex and 0 for full duplex |
| 1272 |
* hence inverting |
| 1273 |
*/ |
| 1274 |
req->args.duplex = cmd->base.duplex ^ 0x1; |
| 1275 |
req->args.an = cmd->base.autoneg; |
| 1276 |
/* Mask unsupported modes and send message to AF */ |
| 1277 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT, mask); |
| 1278 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT, mask); |
| 1279 |
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT, mask); |
| 1280 |
|
| 1281 |
linkmode_copy(req->args.advertising, |
| 1282 |
cmd->link_modes.advertising); |
| 1283 |
linkmode_andnot(req->args.advertising, |
| 1284 |
req->args.advertising, mask); |
| 1285 |
|
| 1286 |
/* inform AF that we need parse this differently */ |
| 1287 |
if (bitmap_weight(req->args.advertising, |
| 1288 |
__ETHTOOL_LINK_MODE_MASK_NBITS) >= 2) |
| 1289 |
req->args.multimode = true; |
| 1290 |
|
| 1291 |
err = otx2_sync_mbox_msg(&pf->mbox); |
| 1292 |
end: |
| 1293 |
mutex_unlock(&mbox->lock); |
| 1294 |
return err; |
| 1295 |
} |
| 1296 |
|
| 1297 |
static void otx2_get_fec_stats(struct net_device *netdev, |
| 1298 |
struct ethtool_fec_stats *fec_stats, |
| 1299 |
struct ethtool_fec_hist *hist) |
| 1300 |
{ |
| 1301 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 1302 |
struct cgx_fw_data *rsp; |
| 1303 |
|
| 1304 |
otx2_update_lmac_fec_stats(pfvf); |
| 1305 |
|
| 1306 |
/* Report MAC FEC stats */ |
| 1307 |
fec_stats->corrected_blocks.total = pfvf->hw.cgx_fec_corr_blks; |
| 1308 |
fec_stats->uncorrectable_blocks.total = pfvf->hw.cgx_fec_uncorr_blks; |
| 1309 |
|
| 1310 |
rsp = otx2_get_fwdata(pfvf); |
| 1311 |
if (!IS_ERR(rsp) && rsp->fwdata.phy.misc.has_fec_stats && |
| 1312 |
!otx2_get_phy_fec_stats(pfvf)) { |
| 1313 |
/* Fetch fwdata again because it's been recently populated with |
| 1314 |
* latest PHY FEC stats. |
| 1315 |
*/ |
| 1316 |
rsp = otx2_get_fwdata(pfvf); |
| 1317 |
if (!IS_ERR(rsp)) { |
| 1318 |
struct fec_stats_s *p = &rsp->fwdata.phy.fec_stats; |
| 1319 |
|
| 1320 |
if (pfvf->linfo.fec == OTX2_FEC_BASER) { |
| 1321 |
fec_stats->corrected_blocks.total = p->brfec_corr_blks; |
| 1322 |
fec_stats->uncorrectable_blocks.total = p->brfec_uncorr_blks; |
| 1323 |
} else { |
| 1324 |
fec_stats->corrected_blocks.total = p->rsfec_corr_cws; |
| 1325 |
fec_stats->uncorrectable_blocks.total = p->rsfec_uncorr_cws; |
| 1326 |
} |
| 1327 |
} |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
static const struct ethtool_ops otx2_ethtool_ops = { |
| 1332 |
.supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
| 1333 |
ETHTOOL_COALESCE_MAX_FRAMES | |
| 1334 |
ETHTOOL_COALESCE_USE_ADAPTIVE, |
| 1335 |
.supported_ring_params = ETHTOOL_RING_USE_RX_BUF_LEN | |
| 1336 |
ETHTOOL_RING_USE_CQE_SIZE, |
| 1337 |
.rxfh_max_num_contexts = MAX_RSS_GROUPS, |
| 1338 |
.get_link = otx2_get_link, |
| 1339 |
.get_drvinfo = otx2_get_drvinfo, |
| 1340 |
.get_strings = otx2_get_strings, |
| 1341 |
.get_ethtool_stats = otx2_get_ethtool_stats, |
| 1342 |
.get_sset_count = otx2_get_sset_count, |
| 1343 |
.set_channels = otx2_set_channels, |
| 1344 |
.get_channels = otx2_get_channels, |
| 1345 |
.get_ringparam = otx2_get_ringparam, |
| 1346 |
.set_ringparam = otx2_set_ringparam, |
| 1347 |
.get_coalesce = otx2_get_coalesce, |
| 1348 |
.set_coalesce = otx2_set_coalesce, |
| 1349 |
.get_rxnfc = otx2_get_rxnfc, |
| 1350 |
.set_rxnfc = otx2_set_rxnfc, |
| 1351 |
.get_rx_ring_count = otx2_get_rx_ring_count, |
| 1352 |
.get_rxfh_key_size = otx2_get_rxfh_key_size, |
| 1353 |
.get_rxfh_indir_size = otx2_get_rxfh_indir_size, |
| 1354 |
.get_rxfh = otx2_get_rxfh, |
| 1355 |
.set_rxfh = otx2_set_rxfh, |
| 1356 |
.get_rxfh_fields = otx2_get_rss_hash_opts, |
| 1357 |
.set_rxfh_fields = otx2_set_rss_hash_opts, |
| 1358 |
.create_rxfh_context = otx2_create_rxfh, |
| 1359 |
.modify_rxfh_context = otx2_modify_rxfh, |
| 1360 |
.remove_rxfh_context = otx2_remove_rxfh, |
| 1361 |
.get_msglevel = otx2_get_msglevel, |
| 1362 |
.set_msglevel = otx2_set_msglevel, |
| 1363 |
.get_pauseparam = otx2_get_pauseparam, |
| 1364 |
.set_pauseparam = otx2_set_pauseparam, |
| 1365 |
.get_ts_info = otx2_get_ts_info, |
| 1366 |
.get_fec_stats = otx2_get_fec_stats, |
| 1367 |
.get_fecparam = otx2_get_fecparam, |
| 1368 |
.set_fecparam = otx2_set_fecparam, |
| 1369 |
.get_link_ksettings = otx2_get_link_ksettings, |
| 1370 |
.set_link_ksettings = otx2_set_link_ksettings, |
| 1371 |
}; |
| 1372 |
|
| 1373 |
void otx2_set_ethtool_ops(struct net_device *netdev) |
| 1374 |
{ |
| 1375 |
netdev->ethtool_ops = &otx2_ethtool_ops; |
| 1376 |
} |
| 1377 |
|
| 1378 |
/* VF's ethtool APIs */ |
| 1379 |
static void otx2vf_get_drvinfo(struct net_device *netdev, |
| 1380 |
struct ethtool_drvinfo *info) |
| 1381 |
{ |
| 1382 |
struct otx2_nic *vf = netdev_priv(netdev); |
| 1383 |
|
| 1384 |
strscpy(info->driver, DRV_VF_NAME, sizeof(info->driver)); |
| 1385 |
strscpy(info->bus_info, pci_name(vf->pdev), sizeof(info->bus_info)); |
| 1386 |
} |
| 1387 |
|
| 1388 |
static void otx2vf_get_strings(struct net_device *netdev, u32 sset, u8 *data) |
| 1389 |
{ |
| 1390 |
struct otx2_nic *vf = netdev_priv(netdev); |
| 1391 |
int stats; |
| 1392 |
|
| 1393 |
if (sset != ETH_SS_STATS) |
| 1394 |
return; |
| 1395 |
|
| 1396 |
for (stats = 0; stats < otx2_n_dev_stats; stats++) |
| 1397 |
ethtool_puts(&data, otx2_dev_stats[stats].name); |
| 1398 |
|
| 1399 |
for (stats = 0; stats < otx2_n_drv_stats; stats++) |
| 1400 |
ethtool_puts(&data, otx2_drv_stats[stats].name); |
| 1401 |
|
| 1402 |
otx2_get_qset_strings(vf, &data, 0); |
| 1403 |
|
| 1404 |
ethtool_puts(&data, "reset_count"); |
| 1405 |
} |
| 1406 |
|
| 1407 |
static void otx2vf_get_ethtool_stats(struct net_device *netdev, |
| 1408 |
struct ethtool_stats *stats, u64 *data) |
| 1409 |
{ |
| 1410 |
struct otx2_nic *vf = netdev_priv(netdev); |
| 1411 |
int stat; |
| 1412 |
|
| 1413 |
otx2_get_dev_stats(vf); |
| 1414 |
for (stat = 0; stat < otx2_n_dev_stats; stat++) |
| 1415 |
*(data++) = ((u64 *)&vf->hw.dev_stats) |
| 1416 |
[otx2_dev_stats[stat].index]; |
| 1417 |
|
| 1418 |
for (stat = 0; stat < otx2_n_drv_stats; stat++) |
| 1419 |
*(data++) = atomic_read(&((atomic_t *)&vf->hw.drv_stats) |
| 1420 |
[otx2_drv_stats[stat].index]); |
| 1421 |
|
| 1422 |
otx2_get_qset_stats(vf, stats, &data); |
| 1423 |
*(data++) = vf->reset_count; |
| 1424 |
} |
| 1425 |
|
| 1426 |
static int otx2vf_get_sset_count(struct net_device *netdev, int sset) |
| 1427 |
{ |
| 1428 |
struct otx2_nic *vf = netdev_priv(netdev); |
| 1429 |
int qstats_count; |
| 1430 |
|
| 1431 |
if (sset != ETH_SS_STATS) |
| 1432 |
return -EINVAL; |
| 1433 |
|
| 1434 |
qstats_count = otx2_n_queue_stats * |
| 1435 |
(vf->hw.rx_queues + otx2_get_total_tx_queues(vf)); |
| 1436 |
|
| 1437 |
return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + 1; |
| 1438 |
} |
| 1439 |
|
| 1440 |
static int otx2vf_get_link_ksettings(struct net_device *netdev, |
| 1441 |
struct ethtool_link_ksettings *cmd) |
| 1442 |
{ |
| 1443 |
struct otx2_nic *pfvf = netdev_priv(netdev); |
| 1444 |
|
| 1445 |
if (is_otx2_lbkvf(pfvf->pdev) || is_otx2_sdp_rep(pfvf->pdev)) { |
| 1446 |
cmd->base.duplex = DUPLEX_FULL; |
| 1447 |
cmd->base.speed = SPEED_100000; |
| 1448 |
} else { |
| 1449 |
return otx2_get_link_ksettings(netdev, cmd); |
| 1450 |
} |
| 1451 |
return 0; |
| 1452 |
} |
| 1453 |
|
| 1454 |
static const struct ethtool_ops otx2vf_ethtool_ops = { |
| 1455 |
.supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
| 1456 |
ETHTOOL_COALESCE_MAX_FRAMES | |
| 1457 |
ETHTOOL_COALESCE_USE_ADAPTIVE, |
| 1458 |
.supported_ring_params = ETHTOOL_RING_USE_RX_BUF_LEN | |
| 1459 |
ETHTOOL_RING_USE_CQE_SIZE, |
| 1460 |
.rxfh_max_num_contexts = MAX_RSS_GROUPS, |
| 1461 |
.get_link = otx2_get_link, |
| 1462 |
.get_drvinfo = otx2vf_get_drvinfo, |
| 1463 |
.get_strings = otx2vf_get_strings, |
| 1464 |
.get_ethtool_stats = otx2vf_get_ethtool_stats, |
| 1465 |
.get_sset_count = otx2vf_get_sset_count, |
| 1466 |
.set_channels = otx2_set_channels, |
| 1467 |
.get_channels = otx2_get_channels, |
| 1468 |
.get_rxnfc = otx2_get_rxnfc, |
| 1469 |
.set_rxnfc = otx2_set_rxnfc, |
| 1470 |
.get_rx_ring_count = otx2_get_rx_ring_count, |
| 1471 |
.get_rxfh_key_size = otx2_get_rxfh_key_size, |
| 1472 |
.get_rxfh_indir_size = otx2_get_rxfh_indir_size, |
| 1473 |
.get_rxfh = otx2_get_rxfh, |
| 1474 |
.set_rxfh = otx2_set_rxfh, |
| 1475 |
.get_rxfh_fields = otx2_get_rss_hash_opts, |
| 1476 |
.set_rxfh_fields = otx2_set_rss_hash_opts, |
| 1477 |
.create_rxfh_context = otx2_create_rxfh, |
| 1478 |
.modify_rxfh_context = otx2_modify_rxfh, |
| 1479 |
.remove_rxfh_context = otx2_remove_rxfh, |
| 1480 |
.get_ringparam = otx2_get_ringparam, |
| 1481 |
.set_ringparam = otx2_set_ringparam, |
| 1482 |
.get_coalesce = otx2_get_coalesce, |
| 1483 |
.set_coalesce = otx2_set_coalesce, |
| 1484 |
.get_msglevel = otx2_get_msglevel, |
| 1485 |
.set_msglevel = otx2_set_msglevel, |
| 1486 |
.get_pauseparam = otx2_get_pauseparam, |
| 1487 |
.set_pauseparam = otx2_set_pauseparam, |
| 1488 |
.get_link_ksettings = otx2vf_get_link_ksettings, |
| 1489 |
.get_ts_info = otx2_get_ts_info, |
| 1490 |
}; |
| 1491 |
|
| 1492 |
void otx2vf_set_ethtool_ops(struct net_device *netdev) |
| 1493 |
{ |
| 1494 |
netdev->ethtool_ops = &otx2vf_ethtool_ops; |
| 1495 |
} |
| 1496 |
EXPORT_SYMBOL(otx2vf_set_ethtool_ops); |