Skip to content

Commit c33c997

Browse files
Intiyaz Bashadavem330
authored andcommitted
liquidio: enhanced ethtool --set-channels feature
Enhancing driver to accept max supported queues for ethtool --set-channels Signed-off-by: Intiyaz Basha <[email protected]> Acked-by: Derek Chickles <[email protected]> Signed-off-by: Felix Manlunas <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 128ea39 commit c33c997

File tree

10 files changed

+316
-58
lines changed

10 files changed

+316
-58
lines changed

drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ static void cn23xx_setup_reg_address(struct octeon_device *oct)
12451245
CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
12461246
}
12471247

1248-
static int cn23xx_sriov_config(struct octeon_device *oct)
1248+
int cn23xx_sriov_config(struct octeon_device *oct)
12491249
{
12501250
struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
12511251
u32 max_rings, total_rings, max_vfs, rings_per_vf;
@@ -1269,8 +1269,8 @@ static int cn23xx_sriov_config(struct octeon_device *oct)
12691269
break;
12701270
}
12711271

1272-
if (max_rings <= num_present_cpus())
1273-
num_pf_rings = 1;
1272+
if (oct->sriov_info.num_pf_rings)
1273+
num_pf_rings = oct->sriov_info.num_pf_rings;
12741274
else
12751275
num_pf_rings = num_present_cpus();
12761276

drivers/net/ethernet/cavium/liquidio/cn23xx_pf_device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ u32 cn23xx_pf_get_oq_ticks(struct octeon_device *oct, u32 time_intr_in_us);
6161

6262
void cn23xx_dump_pf_initialized_regs(struct octeon_device *oct);
6363

64+
int cn23xx_sriov_config(struct octeon_device *oct);
65+
6466
int cn23xx_fw_loaded(struct octeon_device *oct);
6567

6668
void cn23xx_tell_vf_its_macaddr_changed(struct octeon_device *oct, int vfidx,

drivers/net/ethernet/cavium/liquidio/lio_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void lio_delete_glists(struct lio *lio)
7878
if (!lio->glist)
7979
return;
8080

81-
for (i = 0; i < lio->linfo.num_txpciq; i++) {
81+
for (i = 0; i < lio->oct_dev->num_iqs; i++) {
8282
do {
8383
g = (struct octnic_gather *)
8484
lio_list_delete_head(&lio->glist[i]);
@@ -1036,8 +1036,8 @@ int octeon_setup_interrupt(struct octeon_device *oct, u32 num_ioqs)
10361036
int num_ioq_vectors;
10371037
int irqret, err;
10381038

1039-
oct->num_msix_irqs = num_ioqs;
10401039
if (oct->msix_on) {
1040+
oct->num_msix_irqs = num_ioqs;
10411041
if (OCTEON_CN23XX_PF(oct)) {
10421042
num_interrupts = MAX_IOQ_INTERRUPTS_PER_PF + 1;
10431043

drivers/net/ethernet/cavium/liquidio/lio_ethtool.c

Lines changed: 245 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,14 @@ lio_ethtool_get_channels(struct net_device *dev,
361361
rx_count = CFG_GET_NUM_RXQS_NIC_IF(conf6x, lio->ifidx);
362362
tx_count = CFG_GET_NUM_TXQS_NIC_IF(conf6x, lio->ifidx);
363363
} else if (OCTEON_CN23XX_PF(oct)) {
364-
max_combined = lio->linfo.num_txpciq;
364+
if (oct->sriov_info.sriov_enabled) {
365+
max_combined = lio->linfo.num_txpciq;
366+
} else {
367+
struct octeon_config *conf23_pf =
368+
CHIP_CONF(oct, cn23xx_pf);
369+
370+
max_combined = CFG_GET_IQ_MAX_Q(conf23_pf);
371+
}
365372
combined_count = oct->num_iqs;
366373
} else if (OCTEON_CN23XX_VF(oct)) {
367374
u64 reg_val = 0ULL;
@@ -425,9 +432,15 @@ lio_irq_reallocate_irqs(struct octeon_device *oct, uint32_t num_ioqs)
425432

426433
kfree(oct->irq_name_storage);
427434
oct->irq_name_storage = NULL;
435+
436+
if (octeon_allocate_ioq_vector(oct, num_ioqs)) {
437+
dev_err(&oct->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
438+
return -1;
439+
}
440+
428441
if (octeon_setup_interrupt(oct, num_ioqs)) {
429442
dev_info(&oct->pci_dev->dev, "Setup interrupt failed\n");
430-
return 1;
443+
return -1;
431444
}
432445

433446
/* Enable Octeon device interrupts */
@@ -457,7 +470,16 @@ lio_ethtool_set_channels(struct net_device *dev,
457470
combined_count = channel->combined_count;
458471

459472
if (OCTEON_CN23XX_PF(oct)) {
460-
max_combined = channel->max_combined;
473+
if (oct->sriov_info.sriov_enabled) {
474+
max_combined = lio->linfo.num_txpciq;
475+
} else {
476+
struct octeon_config *conf23_pf =
477+
CHIP_CONF(oct,
478+
cn23xx_pf);
479+
480+
max_combined =
481+
CFG_GET_IQ_MAX_Q(conf23_pf);
482+
}
461483
} else if (OCTEON_CN23XX_VF(oct)) {
462484
u64 reg_val = 0ULL;
463485
u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
@@ -485,7 +507,6 @@ lio_ethtool_set_channels(struct net_device *dev,
485507
if (lio_reset_queues(dev, combined_count))
486508
return -EINVAL;
487509

488-
lio_irq_reallocate_irqs(oct, combined_count);
489510
if (stopped)
490511
dev->netdev_ops->ndo_open(dev);
491512

@@ -824,12 +845,120 @@ lio_ethtool_get_ringparam(struct net_device *netdev,
824845
ering->rx_jumbo_max_pending = 0;
825846
}
826847

848+
static int lio_23xx_reconfigure_queue_count(struct lio *lio)
849+
{
850+
struct octeon_device *oct = lio->oct_dev;
851+
struct liquidio_if_cfg_context *ctx;
852+
u32 resp_size, ctx_size, data_size;
853+
struct liquidio_if_cfg_resp *resp;
854+
struct octeon_soft_command *sc;
855+
union oct_nic_if_cfg if_cfg;
856+
struct lio_version *vdata;
857+
u32 ifidx_or_pfnum;
858+
int retval;
859+
int j;
860+
861+
resp_size = sizeof(struct liquidio_if_cfg_resp);
862+
ctx_size = sizeof(struct liquidio_if_cfg_context);
863+
data_size = sizeof(struct lio_version);
864+
sc = (struct octeon_soft_command *)
865+
octeon_alloc_soft_command(oct, data_size,
866+
resp_size, ctx_size);
867+
if (!sc) {
868+
dev_err(&oct->pci_dev->dev, "%s: Failed to allocate soft command\n",
869+
__func__);
870+
return -1;
871+
}
872+
873+
resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
874+
ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
875+
vdata = (struct lio_version *)sc->virtdptr;
876+
877+
vdata->major = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
878+
vdata->minor = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
879+
vdata->micro = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
880+
881+
ifidx_or_pfnum = oct->pf_num;
882+
WRITE_ONCE(ctx->cond, 0);
883+
ctx->octeon_id = lio_get_device_id(oct);
884+
init_waitqueue_head(&ctx->wc);
885+
886+
if_cfg.u64 = 0;
887+
if_cfg.s.num_iqueues = oct->sriov_info.num_pf_rings;
888+
if_cfg.s.num_oqueues = oct->sriov_info.num_pf_rings;
889+
if_cfg.s.base_queue = oct->sriov_info.pf_srn;
890+
if_cfg.s.gmx_port_id = oct->pf_num;
891+
892+
sc->iq_no = 0;
893+
octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
894+
OPCODE_NIC_QCOUNT_UPDATE, 0,
895+
if_cfg.u64, 0);
896+
sc->callback = lio_if_cfg_callback;
897+
sc->callback_arg = sc;
898+
sc->wait_time = LIO_IFCFG_WAIT_TIME;
899+
900+
retval = octeon_send_soft_command(oct, sc);
901+
if (retval == IQ_SEND_FAILED) {
902+
dev_err(&oct->pci_dev->dev,
903+
"iq/oq config failed status: %x\n",
904+
retval);
905+
goto qcount_update_fail;
906+
}
907+
908+
if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
909+
dev_err(&oct->pci_dev->dev, "Wait interrupted\n");
910+
return -1;
911+
}
912+
913+
retval = resp->status;
914+
if (retval) {
915+
dev_err(&oct->pci_dev->dev, "iq/oq config failed\n");
916+
goto qcount_update_fail;
917+
}
918+
919+
octeon_swap_8B_data((u64 *)(&resp->cfg_info),
920+
(sizeof(struct liquidio_if_cfg_info)) >> 3);
921+
922+
lio->ifidx = ifidx_or_pfnum;
923+
lio->linfo.num_rxpciq = hweight64(resp->cfg_info.iqmask);
924+
lio->linfo.num_txpciq = hweight64(resp->cfg_info.iqmask);
925+
for (j = 0; j < lio->linfo.num_rxpciq; j++) {
926+
lio->linfo.rxpciq[j].u64 =
927+
resp->cfg_info.linfo.rxpciq[j].u64;
928+
}
929+
930+
for (j = 0; j < lio->linfo.num_txpciq; j++) {
931+
lio->linfo.txpciq[j].u64 =
932+
resp->cfg_info.linfo.txpciq[j].u64;
933+
}
934+
935+
lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
936+
lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
937+
lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
938+
lio->txq = lio->linfo.txpciq[0].s.q_no;
939+
lio->rxq = lio->linfo.rxpciq[0].s.q_no;
940+
941+
octeon_free_soft_command(oct, sc);
942+
dev_info(&oct->pci_dev->dev, "Queue count updated to %d\n",
943+
lio->linfo.num_rxpciq);
944+
945+
return 0;
946+
947+
qcount_update_fail:
948+
octeon_free_soft_command(oct, sc);
949+
950+
return -1;
951+
}
952+
827953
static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
828954
{
829955
struct lio *lio = GET_LIO(netdev);
830956
struct octeon_device *oct = lio->oct_dev;
957+
int i, queue_count_update = 0;
831958
struct napi_struct *napi, *n;
832-
int i, update = 0;
959+
int ret;
960+
961+
schedule_timeout_uninterruptible(msecs_to_jiffies(100));
833962

834963
if (wait_for_pending_requests(oct))
835964
dev_err(&oct->pci_dev->dev, "There were pending requests\n");
@@ -838,7 +967,7 @@ static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
838967
dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
839968

840969
if (octeon_set_io_queues_off(oct)) {
841-
dev_err(&oct->pci_dev->dev, "setting io queues off failed\n");
970+
dev_err(&oct->pci_dev->dev, "Setting io queues off failed\n");
842971
return -1;
843972
}
844973

@@ -851,9 +980,40 @@ static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
851980
netif_napi_del(napi);
852981

853982
if (num_qs != oct->num_iqs) {
854-
netif_set_real_num_rx_queues(netdev, num_qs);
855-
netif_set_real_num_tx_queues(netdev, num_qs);
856-
update = 1;
983+
ret = netif_set_real_num_rx_queues(netdev, num_qs);
984+
if (ret) {
985+
dev_err(&oct->pci_dev->dev,
986+
"Setting real number rx failed\n");
987+
return ret;
988+
}
989+
990+
ret = netif_set_real_num_tx_queues(netdev, num_qs);
991+
if (ret) {
992+
dev_err(&oct->pci_dev->dev,
993+
"Setting real number tx failed\n");
994+
return ret;
995+
}
996+
997+
/* The value of queue_count_update decides whether it is the
998+
* queue count or the descriptor count that is being
999+
* re-configured.
1000+
*/
1001+
queue_count_update = 1;
1002+
}
1003+
1004+
/* Re-configuration of queues can happen in two scenarios, SRIOV enabled
1005+
* and SRIOV disabled. Few things like recreating queue zero, resetting
1006+
* glists and IRQs are required for both. For the latter, some more
1007+
* steps like updating sriov_info for the octeon device need to be done.
1008+
*/
1009+
if (queue_count_update) {
1010+
lio_delete_glists(lio);
1011+
1012+
/* Delete mbox for PF which is SRIOV disabled because sriov_info
1013+
* will be now changed.
1014+
*/
1015+
if ((OCTEON_CN23XX_PF(oct)) && !oct->sriov_info.sriov_enabled)
1016+
oct->fn_list.free_mbox(oct);
8571017
}
8581018

8591019
for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
@@ -868,24 +1028,91 @@ static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
8681028
octeon_delete_instr_queue(oct, i);
8691029
}
8701030

1031+
if (queue_count_update) {
1032+
/* For PF re-configure sriov related information */
1033+
if ((OCTEON_CN23XX_PF(oct)) &&
1034+
!oct->sriov_info.sriov_enabled) {
1035+
oct->sriov_info.num_pf_rings = num_qs;
1036+
if (cn23xx_sriov_config(oct)) {
1037+
dev_err(&oct->pci_dev->dev,
1038+
"Queue reset aborted: SRIOV config failed\n");
1039+
return -1;
1040+
}
1041+
1042+
num_qs = oct->sriov_info.num_pf_rings;
1043+
}
1044+
}
1045+
8711046
if (oct->fn_list.setup_device_regs(oct)) {
8721047
dev_err(&oct->pci_dev->dev, "Failed to configure device registers\n");
8731048
return -1;
8741049
}
8751050

876-
if (liquidio_setup_io_queues(oct, 0, num_qs, num_qs)) {
877-
dev_err(&oct->pci_dev->dev, "IO queues initialization failed\n");
878-
return -1;
1051+
/* The following are needed in case of queue count re-configuration and
1052+
* not for descriptor count re-configuration.
1053+
*/
1054+
if (queue_count_update) {
1055+
if (octeon_setup_instr_queues(oct))
1056+
return -1;
1057+
1058+
if (octeon_setup_output_queues(oct))
1059+
return -1;
1060+
1061+
/* Recreating mbox for PF that is SRIOV disabled */
1062+
if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1063+
if (oct->fn_list.setup_mbox(oct)) {
1064+
dev_err(&oct->pci_dev->dev, "Mailbox setup failed\n");
1065+
return -1;
1066+
}
1067+
}
1068+
1069+
/* Deleting and recreating IRQs whether the interface is SRIOV
1070+
* enabled or disabled.
1071+
*/
1072+
if (lio_irq_reallocate_irqs(oct, num_qs)) {
1073+
dev_err(&oct->pci_dev->dev, "IRQs could not be allocated\n");
1074+
return -1;
1075+
}
1076+
1077+
/* Enable the input and output queues for this Octeon device */
1078+
if (oct->fn_list.enable_io_queues(oct)) {
1079+
dev_err(&oct->pci_dev->dev, "Failed to enable input/output queues\n");
1080+
return -1;
1081+
}
1082+
1083+
for (i = 0; i < oct->num_oqs; i++)
1084+
writel(oct->droq[i]->max_count,
1085+
oct->droq[i]->pkts_credit_reg);
1086+
1087+
/* Informing firmware about the new queue count. It is required
1088+
* for firmware to allocate more number of queues than those at
1089+
* load time.
1090+
*/
1091+
if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
1092+
if (lio_23xx_reconfigure_queue_count(lio))
1093+
return -1;
1094+
}
8791095
}
8801096

881-
/* Enable the input and output queues for this Octeon device */
882-
if (oct->fn_list.enable_io_queues(oct)) {
883-
dev_err(&oct->pci_dev->dev, "Failed to enable input/output queues");
1097+
/* Once firmware is aware of the new value, queues can be recreated */
1098+
if (liquidio_setup_io_queues(oct, 0, num_qs, num_qs)) {
1099+
dev_err(&oct->pci_dev->dev, "I/O queues creation failed\n");
8841100
return -1;
8851101
}
8861102

887-
if (update && lio_send_queue_count_update(netdev, num_qs))
888-
return -1;
1103+
if (queue_count_update) {
1104+
if (lio_setup_glists(oct, lio, num_qs)) {
1105+
dev_err(&oct->pci_dev->dev, "Gather list allocation failed\n");
1106+
return -1;
1107+
}
1108+
1109+
/* Send firmware the information about new number of queues
1110+
* if the interface is a VF or a PF that is SRIOV enabled.
1111+
*/
1112+
if (oct->sriov_info.sriov_enabled || OCTEON_CN23XX_VF(oct))
1113+
if (lio_send_queue_count_update(netdev, num_qs))
1114+
return -1;
1115+
}
8891116

8901117
return 0;
8911118
}
@@ -930,7 +1157,7 @@ static int lio_ethtool_set_ringparam(struct net_device *netdev,
9301157
CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
9311158
rx_count);
9321159

933-
if (lio_reset_queues(netdev, lio->linfo.num_txpciq))
1160+
if (lio_reset_queues(netdev, oct->num_iqs))
9341161
goto err_lio_reset_queues;
9351162

9361163
if (stopped)

0 commit comments

Comments
 (0)