The patch introduces following commands.
- port attach [ident]
- port detach [port_id]
- attach: attaching a port
- detach: detaching a port
- ident: pci address of physical device.
Or device name and parameters of virtual device.
(ex. 0000:02:00.0, eth_pcap0,iface=eth0)
- port_id: port identifier
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
"port close (port_id|all)\n"
" Close all ports or port_id.\n\n"
+ "port attach (ident)\n"
+ " Attach physical or virtual dev by pci address or virtual device name\n\n"
+
+ "port detach (port_id)\n"
+ " Detach physical or virtual dev by port_id\n\n"
+
"port config (port_id|all)"
" speed (10|100|1000|10000|40000|auto)"
" duplex (half|full|auto)\n"
},
};
+/* *** attach a specified port *** */
+struct cmd_operate_attach_port_result {
+ cmdline_fixed_string_t port;
+ cmdline_fixed_string_t keyword;
+ cmdline_fixed_string_t identifier;
+};
+
+static void cmd_operate_attach_port_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_operate_attach_port_result *res = parsed_result;
+
+ if (!strcmp(res->keyword, "attach"))
+ attach_port(res->identifier);
+ else
+ printf("Unknown parameter\n");
+}
+
+cmdline_parse_token_string_t cmd_operate_attach_port_port =
+ TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
+ port, "port");
+cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
+ TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
+ keyword, "attach");
+cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
+ TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
+ identifier, NULL);
+
+cmdline_parse_inst_t cmd_operate_attach_port = {
+ .f = cmd_operate_attach_port_parsed,
+ .data = NULL,
+ .help_str = "port attach identifier, "
+ "identifier: pci address or virtual dev name",
+ .tokens = {
+ (void *)&cmd_operate_attach_port_port,
+ (void *)&cmd_operate_attach_port_keyword,
+ (void *)&cmd_operate_attach_port_identifier,
+ NULL,
+ },
+};
+
+/* *** detach a specified port *** */
+struct cmd_operate_detach_port_result {
+ cmdline_fixed_string_t port;
+ cmdline_fixed_string_t keyword;
+ uint8_t port_id;
+};
+
+static void cmd_operate_detach_port_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_operate_detach_port_result *res = parsed_result;
+
+ if (!strcmp(res->keyword, "detach"))
+ detach_port(res->port_id);
+ else
+ printf("Unknown parameter\n");
+}
+
+cmdline_parse_token_string_t cmd_operate_detach_port_port =
+ TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
+ port, "port");
+cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
+ TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
+ keyword, "detach");
+cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
+ port_id, UINT8);
+
+cmdline_parse_inst_t cmd_operate_detach_port = {
+ .f = cmd_operate_detach_port_parsed,
+ .data = NULL,
+ .help_str = "port detach port_id",
+ .tokens = {
+ (void *)&cmd_operate_detach_port_port,
+ (void *)&cmd_operate_detach_port_keyword,
+ (void *)&cmd_operate_detach_port_port_id,
+ NULL,
+ },
+};
+
/* *** configure speed for all ports *** */
struct cmd_config_speed_all {
cmdline_fixed_string_t port;
return;
}
- for (pid = 0; pid < nb_ports; pid++) {
+ FOREACH_PORT(pid, ports) {
ports[pid].dev_conf.link_speed = link_speed;
ports[pid].dev_conf.link_duplex = link_duplex;
}
return;
}
- if (res->id >= nb_ports) {
- printf("Port id %d must be less than %d\n", res->id, nb_ports);
+ if (port_id_is_invalid(res->id, ENABLED_WARN))
return;
- }
if (!strcmp(res->value1, "10"))
link_speed = ETH_LINK_SPEED_10;
return;
}
- if (port_id_is_invalid(res->portid))
+ if (port_id_is_invalid(res->portid, ENABLED_WARN))
return;
if (port_is_started(res->portid) != 1) {
int hw = 0;
uint16_t mask = 0;
- if (port_id_is_invalid(res->port_id)) {
+ if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
printf("invalid port %d\n", res->port_id);
return;
}
{
struct cmd_csum_tunnel_result *res = parsed_result;
- if (port_id_is_invalid(res->port_id)) {
- printf("invalid port %d\n", res->port_id);
+ if (port_id_is_invalid(res->port_id, ENABLED_WARN))
return;
- }
if (!strcmp(res->onoff, "on"))
ports[res->port_id].tx_ol_flags |=
struct cmd_tso_set_result *res = parsed_result;
struct rte_eth_dev_info dev_info;
- if (port_id_is_invalid(res->port_id))
+ if (port_id_is_invalid(res->port_id, ENABLED_WARN))
return;
if (!strcmp(res->mode, "set"))
struct cmd_set_bond_mac_addr_result *res = parsed_result;
int ret;
- if (res->port_num >= nb_ports) {
- printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
+ if (port_id_is_invalid(res->port_num, ENABLED_WARN))
return;
- }
ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
/* all ports */
if (allports) {
- for (i = 0; i < nb_ports; i++) {
+ FOREACH_PORT(i, ports) {
if (enable)
rte_eth_promiscuous_enable(i);
else
/* all ports */
if (allports) {
- for (i = 0; i < nb_ports; i++) {
+ FOREACH_PORT(i, ports) {
if (enable)
rte_eth_allmulticast_enable(i);
else
struct cmd_showportall_result *res = parsed_result;
if (!strcmp(res->show, "clear")) {
if (!strcmp(res->what, "stats"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
nic_stats_clear(i);
else if (!strcmp(res->what, "xstats"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
nic_xstats_clear(i);
} else if (!strcmp(res->what, "info"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
port_infos_display(i);
else if (!strcmp(res->what, "stats"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
nic_stats_display(i);
else if (!strcmp(res->what, "xstats"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
nic_xstats_display(i);
else if (!strcmp(res->what, "fdir"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
fdir_get_infos(i);
else if (!strcmp(res->what, "stat_qmap"))
- for (i = 0; i < nb_ports; i++)
+ FOREACH_PORT(i, ports)
nic_stats_mapping_display(i);
}
(cmdline_parse_inst_t *)&cmd_set_qmap,
(cmdline_parse_inst_t *)&cmd_operate_port,
(cmdline_parse_inst_t *)&cmd_operate_specific_port,
+ (cmdline_parse_inst_t *)&cmd_operate_attach_port,
+ (cmdline_parse_inst_t *)&cmd_operate_detach_port,
(cmdline_parse_inst_t *)&cmd_config_speed_all,
(cmdline_parse_inst_t *)&cmd_config_speed_specific,
(cmdline_parse_inst_t *)&cmd_config_rx_tx,
static void
cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
{
- if (id < nb_ports) {
+ if (!port_id_is_invalid(id, DISABLED_WARN)) {
/* check if need_reconfig has been set to 1 */
if (ports[id].need_reconfig == 0)
ports[id].need_reconfig = dev;
} else {
portid_t pid;
- for (pid = 0; pid < nb_ports; pid++) {
+ FOREACH_PORT(pid, ports) {
/* check if need_reconfig has been set to 1 */
if (ports[pid].need_reconfig == 0)
ports[pid].need_reconfig = dev;
struct rte_port *port;
struct rte_pci_id *pci_id;
- if (port_id >= nb_ports) {
- printf("\tPort id must be less than %d.\n", nb_ports);
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return 0;
- }
/* Get the device id. */
port = &ports[port_id];
struct rte_eth_stats stats;
struct rte_port *port = &ports[port_id];
uint8_t i;
+ portid_t pid;
static const char *nic_stats_border = "########################";
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return;
}
rte_eth_stats_get(port_id, &stats);
void
nic_stats_clear(portid_t port_id)
{
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ portid_t pid;
+
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return;
}
rte_eth_stats_reset(port_id);
{
struct rte_port *port = &ports[port_id];
uint16_t i;
+ portid_t pid;
static const char *nic_stats_mapping_border = "########################";
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return;
}
int vlan_offload;
struct rte_mempool * mp;
static const char *info_border = "*********************";
+ portid_t pid;
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return;
}
port = &ports[port_id];
}
int
-port_id_is_invalid(portid_t port_id)
+port_id_is_invalid(portid_t port_id, enum print_warning warning)
{
- if (port_id < nb_ports)
+ if (ports[port_id].enabled)
return 0;
- printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
+
+ if (warning == ENABLED_WARN)
+ printf("Invalid port %d\n", port_id);
+
return 1;
}
uint32_t reg_v;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
uint8_t l_bit;
uint8_t h_bit;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
{
uint32_t reg_v;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
{
uint32_t reg_v;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
uint8_t l_bit;
uint8_t h_bit;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
void
port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
{
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (port_reg_off_is_invalid(port_id, reg_off))
return;
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
diag = rte_eth_dev_set_mtu(port_id, mtu);
if (diag == 0)
{
const struct rte_memzone *rx_mz;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (rx_queue_id_is_invalid(rxq_id))
return;
{
const struct rte_memzone *tx_mz;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (tx_queue_id_is_invalid(txq_id))
return;
uint16_t i, idx, shift;
int ret;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
uint8_t i;
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
/* Get RSS hash key if asked to display it */
rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
again:
for (i = 0; i < nb_pt; i++) {
port_id = (portid_t) portlist[i];
- if (port_id >= nb_ports) {
- printf("Invalid port id %u >= %u\n",
- (unsigned int) port_id,
- (unsigned int) nb_ports);
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
- }
if (record_now)
fwd_ports_ids[i] = port_id;
}
int diag;
int vlan_offload;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
int diag;
int vlan_offload;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
int diag;
int vlan_offload;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (vlan_id_is_invalid(vlan_id))
return;
{
uint16_t vlan_id;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
for (vlan_id = 0; vlan_id < 4096; vlan_id++)
rx_vft_set(port_id, vlan_id, on);
vlan_tpid_set(portid_t port_id, uint16_t tp_id)
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
void
tx_vlan_set(portid_t port_id, uint16_t vlan_id)
{
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (vlan_id_is_invalid(vlan_id))
return;
void
tx_vlan_reset(portid_t port_id)
{
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_INSERT_VLAN;
}
void
tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
{
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
uint16_t i;
uint8_t existing_mapping_found = 0;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
static const char *fdir_stats_border = "########################";
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR);
if (ret < 0) {
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (is_rx)
diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
{
int diag;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
if (vlan_id_is_invalid(vlan_id))
return;
int diag;
struct rte_eth_link link;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return 1;
rte_eth_link_get_nowait(port_id, &link);
if (rate > link.link_speed) {
if (q_msk == 0)
return 0;
- if (port_id_is_invalid(port_id))
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
return 1;
rte_eth_link_get_nowait(port_id, &link);
if (rate > link.link_speed) {
};
unsigned long int_fld[_NUM_FLD];
char *str_fld[_NUM_FLD];
+ portid_t pid;
/* reset from value set at definition */
while ((p = strchr(p0,'(')) != NULL) {
return -1;
}
port_id = (uint8_t)int_fld[FLD_PORT];
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return -1;
}
socket_id = (uint8_t)int_fld[FLD_SOCKET];
};
unsigned long int_fld[_NUM_FLD];
char *str_fld[_NUM_FLD];
+ portid_t pid;
#define RX_RING_ONLY 0x1
#define TX_RING_ONLY 0x2
#define RXTX_RING 0x3
return -1;
}
port_id = (uint8_t)int_fld[FLD_PORT];
- if (port_id >= nb_ports) {
- printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+ if (port_id_is_invalid(port_id, ENABLED_WARN)) {
+ printf("Valid port range is [0");
+ FOREACH_PORT(pid, ports)
+ printf(", %d", pid);
+ printf("]\n");
return -1;
}
socket_id = (uint8_t)int_fld[FLD_SOCKET];
#endif
if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
n = atoi(optarg);
- if (n > 0 && n <= nb_ports)
+ if (n > 0 &&
+ !port_id_is_invalid(n, DISABLED_WARN))
nb_fwd_ports = (uint8_t) n;
else
rte_exit(EXIT_FAILURE,
- "nb-ports should be > 0 and <= %d\n",
- nb_ports);
+ "Invalid port %d\n", n);
}
if (!strcmp(lgopts[opt_idx].name, "nb-cores")) {
n = atoi(optarg);
#include <rte_pci.h>
#include <rte_ether.h>
#include <rte_ethdev.h>
+#include <rte_dev.h>
#include <rte_string_fns.h>
#ifdef RTE_LIBRTE_PMD_XENVIRT
#include <rte_eth_xenvirt.h>
/* Forward function declarations */
static void map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port);
-static void check_all_ports_link_status(uint8_t port_num, uint32_t port_mask);
+static void check_all_ports_link_status(uint32_t port_mask);
/*
* Check if all the ports are started.
*/
static int all_ports_started(void);
+/*
+ * Find next enabled port
+ */
+portid_t
+find_next_port(portid_t p, struct rte_port *ports, int size)
+{
+ if (ports == NULL)
+ rte_exit(-EINVAL, "failed to find a next port id\n");
+
+ while ((ports[p].enabled == 0) && (p < size))
+ p++;
+ return p;
+}
+
/*
* Setup default configuration.
*/
+ RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
if (!numa_support)
- nb_mbuf_per_pool = (nb_mbuf_per_pool * nb_ports);
+ nb_mbuf_per_pool =
+ (nb_mbuf_per_pool * RTE_MAX_ETHPORTS);
}
if (!numa_support) {
/* Configuration of Ethernet ports. */
ports = rte_zmalloc("testpmd: ports",
- sizeof(struct rte_port) * nb_ports,
+ sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
RTE_CACHE_LINE_SIZE);
if (ports == NULL) {
- rte_exit(EXIT_FAILURE, "rte_zmalloc(%d struct rte_port) "
- "failed\n", nb_ports);
+ rte_exit(EXIT_FAILURE,
+ "rte_zmalloc(%d struct rte_port) failed\n",
+ RTE_MAX_ETHPORTS);
}
- for (pid = 0; pid < nb_ports; pid++) {
+ /* enabled allocated ports */
+ for (pid = 0; pid < nb_ports; pid++)
+ ports[pid].enabled = 1;
+
+ FOREACH_PORT(pid, ports) {
port = &ports[pid];
rte_eth_dev_info_get(pid, &port->dev_info);
nb_mbuf_per_pool = nb_mbuf_per_pool/nb_ports;
for (i = 0; i < MAX_SOCKET; i++) {
- nb_mbuf = (nb_mbuf_per_pool *
- port_per_socket[i]);
+ nb_mbuf = (nb_mbuf_per_pool * RTE_MAX_ETHPORTS);
if (nb_mbuf)
mbuf_pool_create(mbuf_data_size,
nb_mbuf,i);
struct rte_port *port;
/* Reconfiguration of Ethernet ports. */
- ports = rte_realloc(ports,
- sizeof(struct rte_port) * nb_ports,
- RTE_CACHE_LINE_SIZE);
- if (ports == NULL) {
- rte_exit(EXIT_FAILURE, "rte_realloc(%d struct rte_port) failed\n",
- nb_ports);
- }
-
port = &ports[new_port_id];
rte_eth_dev_info_get(new_port_id, &port->dev_info);
streamid_t sm_id, nb_fwd_streams_new;
/* set socket id according to numa or not */
- for (pid = 0; pid < nb_ports; pid++) {
+ FOREACH_PORT(pid, ports) {
port = &ports[pid];
if (nb_rxq > port->dev_info.max_rx_queues) {
printf("Fail: nb_rxq(%d) is greater than "
portid_t pi;
struct rte_port *port;
- for (pi = 0; pi < nb_ports; pi++) {
+ FOREACH_PORT(pi, ports) {
port = &ports[pi];
/* Check if there is a port which is not started */
if (port->port_status != RTE_PORT_STARTED)
return 1;
}
+int
+all_ports_stopped(void)
+{
+ portid_t pi;
+ struct rte_port *port;
+
+ FOREACH_PORT(pi, ports) {
+ port = &ports[pi];
+ if (port->port_status != RTE_PORT_STOPPED)
+ return 0;
+ }
+
+ return 1;
+}
+
+int
+port_is_started(portid_t port_id)
+{
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
+ return 0;
+
+ if (ports[port_id].port_status != RTE_PORT_STARTED)
+ return 0;
+
+ return 1;
+}
+
+static int
+port_is_closed(portid_t port_id)
+{
+ if (port_id_is_invalid(port_id, ENABLED_WARN))
+ return 0;
+
+ if (ports[port_id].port_status != RTE_PORT_CLOSED)
+ return 0;
+
+ return 1;
+}
+
int
start_port(portid_t pid)
{
if(dcb_config)
dcb_test = 1;
- for (pi = 0; pi < nb_ports; pi++) {
- if (pid < nb_ports && pid != pi)
+ FOREACH_PORT(pi, ports) {
+ if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
continue;
port = &ports[pi];
}
if (need_check_link_status && !no_link_check)
- check_all_ports_link_status(nb_ports, RTE_PORT_ALL);
+ check_all_ports_link_status(RTE_PORT_ALL);
else
printf("Please stop the ports first\n");
}
printf("Stopping ports...\n");
- for (pi = 0; pi < nb_ports; pi++) {
- if (pid < nb_ports && pid != pi)
+ FOREACH_PORT(pi, ports) {
+ if (!port_id_is_invalid(pid, DISABLED_WARN) && pid != pi)
continue;
port = &ports[pi];
need_check_link_status = 1;
}
if (need_check_link_status && !no_link_check)
- check_all_ports_link_status(nb_ports, RTE_PORT_ALL);
+ check_all_ports_link_status(RTE_PORT_ALL);
printf("Done\n");
}
printf("Closing ports...\n");
- for (pi = 0; pi < nb_ports; pi++) {
- if (pid < nb_ports && pid != pi)
+ FOREACH_PORT(pi, ports) {
+ if (!port_id_is_invalid(pid, DISABLED_WARN) && pid != pi)
continue;
port = &ports[pi];
printf("Done\n");
}
-int
-all_ports_stopped(void)
+void
+attach_port(char *identifier)
{
- portid_t pi;
- struct rte_port *port;
+ portid_t i, j, pi = 0;
- for (pi = 0; pi < nb_ports; pi++) {
- port = &ports[pi];
- if (port->port_status != RTE_PORT_STOPPED)
- return 0;
+ printf("Attaching a new port...\n");
+
+ if (identifier == NULL) {
+ printf("Invalid parameters are specified\n");
+ return;
}
- return 1;
+ if (test_done == 0) {
+ printf("Please stop forwarding first\n");
+ return;
+ }
+
+ if (rte_eth_dev_attach(identifier, &pi))
+ return;
+
+ ports[pi].enabled = 1;
+ reconfig(pi, rte_eth_dev_socket_id(pi));
+ rte_eth_promiscuous_enable(pi);
+
+ nb_ports = rte_eth_dev_count();
+
+ /* set_default_fwd_ports_config(); */
+ bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+ i = 0;
+ FOREACH_PORT(j, ports) {
+ fwd_ports_ids[i] = j;
+ i++;
+ }
+ nb_cfg_ports = nb_ports;
+ nb_fwd_ports++;
+
+ ports[pi].port_status = RTE_PORT_STOPPED;
+
+ printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
+ printf("Done\n");
}
-int
-port_is_started(portid_t port_id)
+void
+detach_port(uint8_t port_id)
{
- if (port_id_is_invalid(port_id))
- return -1;
+ portid_t i, pi = 0;
+ char name[RTE_ETH_NAME_MAX_LEN];
- if (ports[port_id].port_status != RTE_PORT_STARTED)
- return 0;
+ printf("Detaching a port...\n");
- return 1;
+ if (!port_is_closed(port_id)) {
+ printf("Please close port first\n");
+ return;
+ }
+
+ rte_eth_promiscuous_disable(port_id);
+
+ if (rte_eth_dev_detach(port_id, name))
+ return;
+
+ ports[port_id].enabled = 0;
+ nb_ports = rte_eth_dev_count();
+
+ /* set_default_fwd_ports_config(); */
+ bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+ i = 0;
+ FOREACH_PORT(pi, ports) {
+ fwd_ports_ids[i] = pi;
+ i++;
+ }
+ nb_cfg_ports = nb_ports;
+ nb_fwd_ports--;
+
+ printf("Port '%s' is detached. Now total ports is %d\n",
+ name, nb_ports);
+ printf("Done\n");
+ return;
}
void
{
portid_t pt_id;
- for (pt_id = 0; pt_id < nb_ports; pt_id++) {
+ FOREACH_PORT(pt_id, ports) {
printf("Stopping port %d...", pt_id);
fflush(stdout);
rte_eth_dev_close(pt_id);
/* Check the link status of all ports in up to 9s, and print them finally */
static void
-check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
+check_all_ports_link_status(uint32_t port_mask)
{
#define CHECK_INTERVAL 100 /* 100ms */
#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
fflush(stdout);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
- for (portid = 0; portid < port_num; portid++) {
+ FOREACH_PORT(portid, ports) {
if ((port_mask & (1 << portid)) == 0)
continue;
memset(&link, 0, sizeof(link));
portid_t pid;
struct rte_port *port;
- for (pid = 0; pid < nb_ports; pid++) {
+ FOREACH_PORT(pid, ports) {
port = &ports[pid];
port->dev_conf.rxmode = rx_mode;
port->dev_conf.fdir_conf = fdir_conf;
nb_ports = (portid_t) rte_eth_dev_count();
if (nb_ports == 0)
- rte_exit(EXIT_FAILURE, "No probed ethernet device\n");
+ RTE_LOG(WARNING, EAL, "No probed ethernet devices\n");
set_def_fwd_config();
if (nb_lcores == 0)
rte_exit(EXIT_FAILURE, "Start ports failed\n");
/* set all ports to promiscuous mode by default */
- for (port_id = 0; port_id < nb_ports; port_id++)
+ FOREACH_PORT(port_id, ports)
rte_eth_promiscuous_enable(port_id);
#ifdef RTE_LIBRTE_CMDLINE
* The data structure associated with each port.
*/
struct rte_port {
+ uint8_t enabled; /**< Port enabled or not */
struct rte_eth_dev_info dev_info; /**< PCI info + driver name */
struct rte_eth_conf dev_conf; /**< Port configuration. */
struct ether_addr eth_addr; /**< Port ethernet address */
struct rte_eth_txconf tx_conf; /**< tx configuration */
};
+extern portid_t __rte_unused
+find_next_port(portid_t p, struct rte_port *ports, int size);
+
+#define FOREACH_PORT(p, ports) \
+ for (p = find_next_port(0, ports, RTE_MAX_ETHPORTS); \
+ p < RTE_MAX_ETHPORTS; \
+ p = find_next_port(p + 1, ports, RTE_MAX_ETHPORTS))
+
/**
* The data structure associated with each forwarding logical core.
* The logical cores are internally numbered by a core index from 0 to
int start_port(portid_t pid);
void stop_port(portid_t pid);
void close_port(portid_t pid);
+void attach_port(char *identifier);
+void detach_port(uint8_t port_id);
int all_ports_stopped(void);
int port_is_started(portid_t port_id);
void pmd_test_exit(void);
void get_ethertype_filter(uint8_t port_id, uint16_t index);
void get_2tuple_filter(uint8_t port_id, uint16_t index);
void get_5tuple_filter(uint8_t port_id, uint16_t index);
-int port_id_is_invalid(portid_t port_id);
int rx_queue_id_is_invalid(queueid_t rxq_id);
int tx_queue_id_is_invalid(queueid_t txq_id);
+enum print_warning {
+ ENABLED_WARN = 0,
+ DISABLED_WARN
+};
+int port_id_is_invalid(portid_t port_id, enum print_warning warning);
+
/*
* Work-around of a compilation error with ICC on invocations of the
* rte_be_to_cpu_16() function.
Port configuration changes only become active when forwarding is started/restarted.
+port attach
+~~~~~~~~~~~
+
+Attach a port specified by pci address or virtual device args.
+
+To attach a new pci device, the device should be recognized by kernel first.
+Then it should be moved under DPDK management.
+Finally the port can be attached to testpmd.
+On the other hand, to attach a port created by virtual device, above steps are not needed.
+
+port attach (identifier)
+
+For example, to attach a port whose pci address is 0000:02:00.0.
+
+.. code-block:: console
+
+ testpmd> port attach 0000:02:00.0
+ Attaching a new port...
+ ... snip ...
+ Port 0 is attached. Now total ports is 1
+ Done
+
+For example, to attach a port created by pcap PMD.
+
+.. code-block:: console
+
+ testpmd> port attach eth_pcap0,iface=eth0
+ Attaching a new port...
+ ... snip ...
+ Port 0 is attached. Now total ports is 1
+ Done
+
+In this case, identifier is "eth_pcap0,iface=eth0".
+This identifier format is the same as "--vdev" format of DPDK applications.
+
+port detach
+~~~~~~~~~~~
+
+Detach a specific port.
+
+Before detaching a port, the port should be closed.
+Also to remove a pci device completely from the system, first detach the port from testpmd.
+Then the device should be moved under kernel management.
+Finally the device can be removed using kernel pci hotplug functionality.
+On the other hand, to remove a port created by a virtual device, above steps are not needed.
+
+port detach (port_id)
+
+For example, to detach a port 0.
+
+.. code-block:: console
+
+ testpmd> port detach 0
+ Detaching a port...
+ ... snip ...
+ Done
+
port start
~~~~~~~~~~