app/testpmd: remove useless pointer checks
[dpdk.git] / app / test-pmd / config.c
index 158d1b3..1b1e738 100644 (file)
@@ -249,14 +249,20 @@ nic_stats_display(portid_t port_id)
                                                                diff_ns;
        uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
        struct rte_eth_stats stats;
-
        static const char *nic_stats_border = "########################";
+       int ret;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                print_valid_ports();
                return;
        }
-       rte_eth_stats_get(port_id, &stats);
+       ret = rte_eth_stats_get(port_id, &stats);
+       if (ret != 0) {
+               fprintf(stderr,
+                       "%s: Error: failed to get stats (port %u): %d",
+                       __func__, port_id, ret);
+               return;
+       }
        printf("\n  %s NIC statistics for port %-2d %s\n",
               nic_stats_border, port_id, nic_stats_border);
 
@@ -1248,6 +1254,57 @@ port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
        display_port_reg_value(port_id, reg_off, reg_v);
 }
 
+static uint32_t
+eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
+{
+       uint32_t overhead_len;
+
+       if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
+               overhead_len = max_rx_pktlen - max_mtu;
+       else
+               overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
+
+       return overhead_len;
+}
+
+static int
+eth_dev_validate_mtu(uint16_t port_id, uint16_t mtu)
+{
+       struct rte_eth_dev_info dev_info;
+       uint32_t overhead_len;
+       uint32_t frame_size;
+       int ret;
+
+       ret = rte_eth_dev_info_get(port_id, &dev_info);
+       if (ret != 0)
+               return ret;
+
+       if (mtu < dev_info.min_mtu) {
+               fprintf(stderr,
+                       "MTU (%u) < device min MTU (%u) for port_id %u\n",
+                       mtu, dev_info.min_mtu, port_id);
+               return -EINVAL;
+       }
+       if (mtu > dev_info.max_mtu) {
+               fprintf(stderr,
+                       "MTU (%u) > device max MTU (%u) for port_id %u\n",
+                       mtu, dev_info.max_mtu, port_id);
+               return -EINVAL;
+       }
+
+       overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
+                       dev_info.max_mtu);
+       frame_size = mtu + overhead_len;
+       if (frame_size > dev_info.max_rx_pktlen) {
+               fprintf(stderr,
+                       "Frame size (%u) > device max frame size (%u) for port_id %u\n",
+                       frame_size, dev_info.max_rx_pktlen, port_id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 void
 port_mtu_set(portid_t port_id, uint16_t mtu)
 {
@@ -1257,6 +1314,10 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
+       diag = eth_dev_validate_mtu(port_id, mtu);
+       if (diag != 0)
+               return;
+
        if (port->need_reconfig == 0) {
                diag = rte_eth_dev_set_mtu(port_id, mtu);
                if (diag != 0) {
@@ -2598,6 +2659,137 @@ port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
        return ret;
 }
 
+/** Enqueue indirect action create operation. */
+int
+port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
+                               bool postpone, uint32_t id,
+                               const struct rte_flow_indir_action_conf *conf,
+                               const struct rte_flow_action *action)
+{
+       const struct rte_flow_op_attr attr = { .postpone = postpone};
+       struct rte_port *port;
+       struct port_indirect_action *pia;
+       int ret;
+       struct rte_flow_error error;
+
+       ret = action_alloc(port_id, id, &pia);
+       if (ret)
+               return ret;
+
+       port = &ports[port_id];
+       if (queue_id >= port->queue_nb) {
+               printf("Queue #%u is invalid\n", queue_id);
+               return -EINVAL;
+       }
+
+       if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+               struct rte_flow_action_age *age =
+                       (struct rte_flow_action_age *)(uintptr_t)(action->conf);
+
+               pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
+               age->context = &pia->age_type;
+       }
+       /* Poisoning to make sure PMDs update it in case of error. */
+       memset(&error, 0x88, sizeof(error));
+       pia->handle = rte_flow_async_action_handle_create(port_id, queue_id,
+                                       &attr, conf, action, NULL, &error);
+       if (!pia->handle) {
+               uint32_t destroy_id = pia->id;
+               port_queue_action_handle_destroy(port_id, queue_id,
+                                                postpone, 1, &destroy_id);
+               return port_flow_complain(&error);
+       }
+       pia->type = action->type;
+       printf("Indirect action #%u creation queued\n", pia->id);
+       return 0;
+}
+
+/** Enqueue indirect action destroy operation. */
+int
+port_queue_action_handle_destroy(portid_t port_id,
+                                uint32_t queue_id, bool postpone,
+                                uint32_t n, const uint32_t *actions)
+{
+       const struct rte_flow_op_attr attr = { .postpone = postpone};
+       struct rte_port *port;
+       struct port_indirect_action **tmp;
+       uint32_t c = 0;
+       int ret = 0;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+       port = &ports[port_id];
+
+       if (queue_id >= port->queue_nb) {
+               printf("Queue #%u is invalid\n", queue_id);
+               return -EINVAL;
+       }
+
+       tmp = &port->actions_list;
+       while (*tmp) {
+               uint32_t i;
+
+               for (i = 0; i != n; ++i) {
+                       struct rte_flow_error error;
+                       struct port_indirect_action *pia = *tmp;
+
+                       if (actions[i] != pia->id)
+                               continue;
+                       /*
+                        * Poisoning to make sure PMDs update it in case
+                        * of error.
+                        */
+                       memset(&error, 0x99, sizeof(error));
+
+                       if (pia->handle &&
+                           rte_flow_async_action_handle_destroy(port_id,
+                               queue_id, &attr, pia->handle, NULL, &error)) {
+                               ret = port_flow_complain(&error);
+                               continue;
+                       }
+                       *tmp = pia->next;
+                       printf("Indirect action #%u destruction queued\n",
+                              pia->id);
+                       free(pia);
+                       break;
+               }
+               if (i == n)
+                       tmp = &(*tmp)->next;
+               ++c;
+       }
+       return ret;
+}
+
+/** Enqueue indirect action update operation. */
+int
+port_queue_action_handle_update(portid_t port_id,
+                               uint32_t queue_id, bool postpone, uint32_t id,
+                               const struct rte_flow_action *action)
+{
+       const struct rte_flow_op_attr attr = { .postpone = postpone};
+       struct rte_port *port;
+       struct rte_flow_error error;
+       struct rte_flow_action_handle *action_handle;
+
+       action_handle = port_action_handle_get_by_id(port_id, id);
+       if (!action_handle)
+               return -EINVAL;
+
+       port = &ports[port_id];
+       if (queue_id >= port->queue_nb) {
+               printf("Queue #%u is invalid\n", queue_id);
+               return -EINVAL;
+       }
+
+       if (rte_flow_async_action_handle_update(port_id, queue_id, &attr,
+                                   action_handle, action, NULL, &error)) {
+               return port_flow_complain(&error);
+       }
+       printf("Indirect action #%u update queued\n", id);
+       return 0;
+}
+
 /** Push all the queue operations in the queue to the NIC. */
 int
 port_queue_flow_push(portid_t port_id, queueid_t queue_id)