Skip to content

Commit b741f55

Browse files
damodhar-aiferruhy
authored andcommitted
ethdev: support link speed lanes
Update the eth_dev_ops structure with new function vectors to get, get capabilities and set Ethernet link speed lanes. Update the testpmd to provide required config and information display infrastructure. The supporting Ethernet controller driver will register callbacks to avail link speed lanes config and get services. This lanes configuration is applicable only when the NIC is forced to fixed speeds. In Autonegotiation mode, the hardware automatically negotiates the number of lanes. These are the new commands. testpmd> show port 0 speed_lanes capabilities Supported speeds Valid lanes ----------------------------------- 10 Gbps 1 25 Gbps 1 40 Gbps 4 50 Gbps 1 2 100 Gbps 1 2 4 200 Gbps 2 4 400 Gbps 4 8 testpmd> testpmd> testpmd> port stop 0 testpmd> port config 0 speed_lanes 4 testpmd> port config 0 speed 200000 duplex full testpmd> port start 0 testpmd> testpmd> show port info 0 ********************* Infos for port 0 ********************* MAC address: 14:23:F2:C3:BA:D2 Device name: 0000:b1:00.0 Driver name: net_bnxt Firmware-version: 228.9.115.0 Connect to socket: 2 memory allocation on the socket: 2 Link status: up Link speed: 200 Gbps Active Lanes: 4 Link duplex: full-duplex Autoneg status: Off Signed-off-by: Damodharam Ammepalli <[email protected]> Reviewed-by: Ferruh Yigit <[email protected]> Reviewed-by: Ajit Khaparde <[email protected]>
1 parent 3fa84cc commit b741f55

File tree

6 files changed

+480
-1
lines changed

6 files changed

+480
-1
lines changed

app/test-pmd/cmdline.c

Lines changed: 247 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ static void cmd_help_long_parsed(void *parsed_result,
284284

285285
"dump_log_types\n"
286286
" Dumps the log level for all the dpdk modules\n\n"
287+
288+
"show port (port_id) speed_lanes capabilities"
289+
" Show speed lanes capabilities of a port.\n\n"
287290
);
288291
}
289292

@@ -823,6 +826,9 @@ static void cmd_help_long_parsed(void *parsed_result,
823826
"port config (port_id) txq (queue_id) affinity (value)\n"
824827
" Map a Tx queue with an aggregated port "
825828
"of the DPDK port\n\n"
829+
830+
"port config (port_id|all) speed_lanes (value)\n"
831+
" Set number of lanes for all ports or port_id for a forced speed\n\n"
826832
);
827833
}
828834

@@ -1560,6 +1566,244 @@ static cmdline_parse_inst_t cmd_config_speed_specific = {
15601566
},
15611567
};
15621568

1569+
static int
1570+
parse_speed_lanes_cfg(portid_t pid, uint32_t lanes)
1571+
{
1572+
int ret;
1573+
1574+
ret = rte_eth_speed_lanes_set(pid, lanes);
1575+
if (ret == -ENOTSUP) {
1576+
fprintf(stderr, "Function not implemented\n");
1577+
return -1;
1578+
} else if (ret < 0) {
1579+
fprintf(stderr, "Set speed lanes failed\n");
1580+
return -1;
1581+
}
1582+
1583+
return 0;
1584+
}
1585+
1586+
static void
1587+
show_speed_lanes_capability(unsigned int num, struct rte_eth_speed_lanes_capa *speed_lanes_capa)
1588+
{
1589+
unsigned int i;
1590+
uint32_t capa;
1591+
1592+
printf("\n%-15s %-10s", "Supported-speeds", "Valid-lanes");
1593+
printf("\n-----------------------------------\n");
1594+
for (i = 0; i < num; i++) {
1595+
printf("%-17s ",
1596+
rte_eth_link_speed_to_str(speed_lanes_capa[i].speed));
1597+
capa = speed_lanes_capa[i].capa;
1598+
int s = 0;
1599+
1600+
while (capa) {
1601+
if (capa & 0x1)
1602+
printf("%-2d ", s);
1603+
s++;
1604+
capa = capa >> 1;
1605+
}
1606+
printf("\n");
1607+
}
1608+
}
1609+
1610+
/* *** display speed lanes per port capabilities *** */
1611+
struct cmd_show_speed_lanes_result {
1612+
cmdline_fixed_string_t cmd_show;
1613+
cmdline_fixed_string_t cmd_port;
1614+
cmdline_fixed_string_t cmd_keyword;
1615+
portid_t cmd_pid;
1616+
};
1617+
1618+
static void
1619+
cmd_show_speed_lanes_parsed(void *parsed_result,
1620+
__rte_unused struct cmdline *cl,
1621+
__rte_unused void *data)
1622+
{
1623+
struct cmd_show_speed_lanes_result *res = parsed_result;
1624+
struct rte_eth_speed_lanes_capa *speed_lanes_capa;
1625+
unsigned int num;
1626+
int ret;
1627+
1628+
if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
1629+
fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
1630+
return;
1631+
}
1632+
1633+
ret = rte_eth_speed_lanes_get_capability(res->cmd_pid, NULL, 0);
1634+
if (ret == -ENOTSUP) {
1635+
fprintf(stderr, "Function not implemented\n");
1636+
return;
1637+
} else if (ret < 0) {
1638+
fprintf(stderr, "Get speed lanes capability failed: %d\n", ret);
1639+
return;
1640+
}
1641+
1642+
num = (unsigned int)ret;
1643+
speed_lanes_capa = calloc(num, sizeof(*speed_lanes_capa));
1644+
if (speed_lanes_capa == NULL) {
1645+
fprintf(stderr, "Failed to alloc speed lanes capability buffer\n");
1646+
return;
1647+
}
1648+
1649+
ret = rte_eth_speed_lanes_get_capability(res->cmd_pid, speed_lanes_capa, num);
1650+
if (ret < 0) {
1651+
fprintf(stderr, "Error getting speed lanes capability: %d\n", ret);
1652+
goto out;
1653+
}
1654+
1655+
show_speed_lanes_capability(num, speed_lanes_capa);
1656+
out:
1657+
free(speed_lanes_capa);
1658+
}
1659+
1660+
static cmdline_parse_token_string_t cmd_show_speed_lanes_show =
1661+
TOKEN_STRING_INITIALIZER(struct cmd_show_speed_lanes_result,
1662+
cmd_show, "show");
1663+
static cmdline_parse_token_string_t cmd_show_speed_lanes_port =
1664+
TOKEN_STRING_INITIALIZER(struct cmd_show_speed_lanes_result,
1665+
cmd_port, "port");
1666+
static cmdline_parse_token_num_t cmd_show_speed_lanes_pid =
1667+
TOKEN_NUM_INITIALIZER(struct cmd_show_speed_lanes_result,
1668+
cmd_pid, RTE_UINT16);
1669+
static cmdline_parse_token_string_t cmd_show_speed_lanes_keyword =
1670+
TOKEN_STRING_INITIALIZER(struct cmd_show_speed_lanes_result,
1671+
cmd_keyword, "speed_lanes");
1672+
static cmdline_parse_token_string_t cmd_show_speed_lanes_cap_keyword =
1673+
TOKEN_STRING_INITIALIZER(struct cmd_show_speed_lanes_result,
1674+
cmd_keyword, "capabilities");
1675+
1676+
static cmdline_parse_inst_t cmd_show_speed_lanes = {
1677+
.f = cmd_show_speed_lanes_parsed,
1678+
.data = NULL,
1679+
.help_str = "show port <port_id> speed_lanes capabilities",
1680+
.tokens = {
1681+
(void *)&cmd_show_speed_lanes_show,
1682+
(void *)&cmd_show_speed_lanes_port,
1683+
(void *)&cmd_show_speed_lanes_pid,
1684+
(void *)&cmd_show_speed_lanes_keyword,
1685+
(void *)&cmd_show_speed_lanes_cap_keyword,
1686+
NULL,
1687+
},
1688+
};
1689+
1690+
/* *** configure speed_lanes for all ports *** */
1691+
struct cmd_config_speed_lanes_all {
1692+
cmdline_fixed_string_t port;
1693+
cmdline_fixed_string_t keyword;
1694+
cmdline_fixed_string_t all;
1695+
cmdline_fixed_string_t item;
1696+
uint32_t lanes;
1697+
};
1698+
1699+
static void
1700+
cmd_config_speed_lanes_all_parsed(void *parsed_result,
1701+
__rte_unused struct cmdline *cl,
1702+
__rte_unused void *data)
1703+
{
1704+
struct cmd_config_speed_lanes_all *res = parsed_result;
1705+
portid_t pid;
1706+
1707+
if (!all_ports_stopped()) {
1708+
fprintf(stderr, "Please stop all ports first\n");
1709+
return;
1710+
}
1711+
1712+
RTE_ETH_FOREACH_DEV(pid) {
1713+
if (parse_speed_lanes_cfg(pid, res->lanes))
1714+
return;
1715+
}
1716+
1717+
cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1718+
}
1719+
1720+
static cmdline_parse_token_string_t cmd_config_speed_lanes_all_port =
1721+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_all, port, "port");
1722+
static cmdline_parse_token_string_t cmd_config_speed_lanes_all_keyword =
1723+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_all, keyword,
1724+
"config");
1725+
static cmdline_parse_token_string_t cmd_config_speed_lanes_all_all =
1726+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_all, all, "all");
1727+
static cmdline_parse_token_string_t cmd_config_speed_lanes_all_item =
1728+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_all, item,
1729+
"speed_lanes");
1730+
static cmdline_parse_token_num_t cmd_config_speed_lanes_all_lanes =
1731+
TOKEN_NUM_INITIALIZER(struct cmd_config_speed_lanes_all, lanes, RTE_UINT32);
1732+
1733+
static cmdline_parse_inst_t cmd_config_speed_lanes_all = {
1734+
.f = cmd_config_speed_lanes_all_parsed,
1735+
.data = NULL,
1736+
.help_str = "port config all speed_lanes <value>",
1737+
.tokens = {
1738+
(void *)&cmd_config_speed_lanes_all_port,
1739+
(void *)&cmd_config_speed_lanes_all_keyword,
1740+
(void *)&cmd_config_speed_lanes_all_all,
1741+
(void *)&cmd_config_speed_lanes_all_item,
1742+
(void *)&cmd_config_speed_lanes_all_lanes,
1743+
NULL,
1744+
},
1745+
};
1746+
1747+
/* *** configure speed_lanes for specific port *** */
1748+
struct cmd_config_speed_lanes_specific {
1749+
cmdline_fixed_string_t port;
1750+
cmdline_fixed_string_t keyword;
1751+
uint16_t port_id;
1752+
cmdline_fixed_string_t item;
1753+
uint32_t lanes;
1754+
};
1755+
1756+
static void
1757+
cmd_config_speed_lanes_specific_parsed(void *parsed_result,
1758+
__rte_unused struct cmdline *cl,
1759+
__rte_unused void *data)
1760+
{
1761+
struct cmd_config_speed_lanes_specific *res = parsed_result;
1762+
1763+
if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1764+
return;
1765+
1766+
if (!port_is_stopped(res->port_id)) {
1767+
fprintf(stderr, "Please stop port %u first\n", res->port_id);
1768+
return;
1769+
}
1770+
1771+
if (parse_speed_lanes_cfg(res->port_id, res->lanes))
1772+
return;
1773+
1774+
cmd_reconfig_device_queue(res->port_id, 1, 1);
1775+
}
1776+
1777+
static cmdline_parse_token_string_t cmd_config_speed_lanes_specific_port =
1778+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_specific, port,
1779+
"port");
1780+
static cmdline_parse_token_string_t cmd_config_speed_lanes_specific_keyword =
1781+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_specific, keyword,
1782+
"config");
1783+
static cmdline_parse_token_num_t cmd_config_speed_lanes_specific_id =
1784+
TOKEN_NUM_INITIALIZER(struct cmd_config_speed_lanes_specific, port_id,
1785+
RTE_UINT16);
1786+
static cmdline_parse_token_string_t cmd_config_speed_lanes_specific_item =
1787+
TOKEN_STRING_INITIALIZER(struct cmd_config_speed_lanes_specific, item,
1788+
"speed_lanes");
1789+
static cmdline_parse_token_num_t cmd_config_speed_lanes_specific_lanes =
1790+
TOKEN_NUM_INITIALIZER(struct cmd_config_speed_lanes_specific, lanes,
1791+
RTE_UINT32);
1792+
1793+
static cmdline_parse_inst_t cmd_config_speed_lanes_specific = {
1794+
.f = cmd_config_speed_lanes_specific_parsed,
1795+
.data = NULL,
1796+
.help_str = "port config <port_id> speed_lanes <value>",
1797+
.tokens = {
1798+
(void *)&cmd_config_speed_lanes_specific_port,
1799+
(void *)&cmd_config_speed_lanes_specific_keyword,
1800+
(void *)&cmd_config_speed_lanes_specific_id,
1801+
(void *)&cmd_config_speed_lanes_specific_item,
1802+
(void *)&cmd_config_speed_lanes_specific_lanes,
1803+
NULL,
1804+
},
1805+
};
1806+
15631807
/* *** configure loopback for all ports *** */
15641808
struct cmd_config_loopback_all {
15651809
cmdline_fixed_string_t port;
@@ -1645,7 +1889,6 @@ cmd_config_loopback_specific_parsed(void *parsed_result,
16451889
cmd_reconfig_device_queue(res->port_id, 1, 1);
16461890
}
16471891

1648-
16491892
static cmdline_parse_token_string_t cmd_config_loopback_specific_port =
16501893
TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
16511894
"port");
@@ -13238,6 +13481,9 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
1323813481
&cmd_set_port_setup_on,
1323913482
&cmd_config_speed_all,
1324013483
&cmd_config_speed_specific,
13484+
&cmd_config_speed_lanes_all,
13485+
&cmd_config_speed_lanes_specific,
13486+
&cmd_show_speed_lanes,
1324113487
&cmd_config_loopback_all,
1324213488
&cmd_config_loopback_specific,
1324313489
&cmd_config_rx_tx,

app/test-pmd/config.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ port_infos_display(portid_t port_id)
786786
char name[RTE_ETH_NAME_MAX_LEN];
787787
int ret;
788788
char fw_version[ETHDEV_FWVERS_LEN];
789+
uint32_t lanes;
789790

790791
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
791792
print_valid_ports();
@@ -828,6 +829,8 @@ port_infos_display(portid_t port_id)
828829

829830
printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
830831
printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
832+
if (rte_eth_speed_lanes_get(port_id, &lanes) == 0)
833+
printf("Active Lanes: %d\n", lanes);
831834
printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
832835
("full-duplex") : ("half-duplex"));
833836
printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
@@ -7254,3 +7257,4 @@ show_mcast_macs(portid_t port_id)
72547257
printf(" %s\n", buf);
72557258
}
72567259
}
7260+

0 commit comments

Comments
 (0)