app/testpmd: fix RSS flow action configuration
[dpdk.git] / app / test-pmd / config.c
index 4bb255c..401564f 100644 (file)
@@ -754,6 +754,8 @@ vlan_id_is_invalid(uint16_t vlan_id)
 static int
 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
 {
+       const struct rte_pci_device *pci_dev;
+       const struct rte_bus *bus;
        uint64_t pci_len;
 
        if (reg_off & 0x3) {
@@ -762,7 +764,21 @@ port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
                       (unsigned)reg_off);
                return 1;
        }
-       pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
+
+       if (!ports[port_id].dev_info.device) {
+               printf("Invalid device\n");
+               return 0;
+       }
+
+       bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
+       if (bus && !strcmp(bus->name, "pci")) {
+               pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
+       } else {
+               printf("Not a PCI device\n");
+               return 1;
+       }
+
+       pci_len = pci_dev->mem_resource[0].len;
        if (reg_off >= pci_len) {
                printf("Port %d: register offset %u (0x%X) out of port PCI "
                       "resource (length=%"PRIu64")\n",
@@ -982,31 +998,51 @@ static const struct {
        MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
 };
 
-/** Compute storage space needed by item specification. */
-static void
-flow_item_spec_size(const struct rte_flow_item *item,
-                   size_t *size, size_t *pad)
+/** Pattern item specification types. */
+enum item_spec_type {
+       ITEM_SPEC,
+       ITEM_LAST,
+       ITEM_MASK,
+};
+
+/** Compute storage space needed by item specification and copy it. */
+static size_t
+flow_item_spec_copy(void *buf, const struct rte_flow_item *item,
+                   enum item_spec_type type)
 {
-       if (!item->spec) {
-               *size = 0;
+       size_t size = 0;
+       const void *item_spec =
+               type == ITEM_SPEC ? item->spec :
+               type == ITEM_LAST ? item->last :
+               type == ITEM_MASK ? item->mask :
+               NULL;
+
+       if (!item_spec)
                goto empty;
-       }
        switch (item->type) {
                union {
                        const struct rte_flow_item_raw *raw;
-               } spec;
+               } src;
+               union {
+                       struct rte_flow_item_raw *raw;
+               } dst;
 
        case RTE_FLOW_ITEM_TYPE_RAW:
-               spec.raw = item->spec;
-               *size = offsetof(struct rte_flow_item_raw, pattern) +
-                       spec.raw->length * sizeof(*spec.raw->pattern);
+               src.raw = item_spec;
+               dst.raw = buf;
+               size = offsetof(struct rte_flow_item_raw, pattern) +
+                       src.raw->length * sizeof(*src.raw->pattern);
+               if (dst.raw)
+                       memcpy(dst.raw, src.raw, size);
                break;
        default:
-               *size = flow_item[item->type].size;
+               size = flow_item[item->type].size;
+               if (buf)
+                       memcpy(buf, item_spec, size);
                break;
        }
 empty:
-       *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+       return RTE_ALIGN_CEIL(size, sizeof(double));
 }
 
 /** Generate flow_action[] entry. */
@@ -1036,31 +1072,72 @@ static const struct {
        MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)),
 };
 
-/** Compute storage space needed by action configuration. */
-static void
-flow_action_conf_size(const struct rte_flow_action *action,
-                     size_t *size, size_t *pad)
+/** Compute storage space needed by action configuration and copy it. */
+static size_t
+flow_action_conf_copy(void *buf, const struct rte_flow_action *action)
 {
-       if (!action->conf) {
-               *size = 0;
+       size_t size = 0;
+
+       if (!action->conf)
                goto empty;
-       }
        switch (action->type) {
                union {
                        const struct rte_flow_action_rss *rss;
-               } conf;
+               } src;
+               union {
+                       struct rte_flow_action_rss *rss;
+               } dst;
+               size_t off;
 
        case RTE_FLOW_ACTION_TYPE_RSS:
-               conf.rss = action->conf;
-               *size = offsetof(struct rte_flow_action_rss, queue) +
-                       conf.rss->num * sizeof(*conf.rss->queue);
+               src.rss = action->conf;
+               dst.rss = buf;
+               off = 0;
+               if (dst.rss)
+                       *dst.rss = (struct rte_flow_action_rss){
+                               .num = src.rss->num,
+                       };
+               off += offsetof(struct rte_flow_action_rss, queue);
+               if (src.rss->num) {
+                       size = sizeof(*src.rss->queue) * src.rss->num;
+                       if (dst.rss)
+                               memcpy(dst.rss->queue, src.rss->queue, size);
+                       off += size;
+               }
+               off = RTE_ALIGN_CEIL(off, sizeof(double));
+               if (dst.rss) {
+                       dst.rss->rss_conf = (void *)((uintptr_t)dst.rss + off);
+                       *(struct rte_eth_rss_conf *)(uintptr_t)
+                               dst.rss->rss_conf = (struct rte_eth_rss_conf){
+                               .rss_key_len = src.rss->rss_conf->rss_key_len,
+                               .rss_hf = src.rss->rss_conf->rss_hf,
+                       };
+               }
+               off += sizeof(*src.rss->rss_conf);
+               if (src.rss->rss_conf->rss_key_len) {
+                       off = RTE_ALIGN_CEIL(off, sizeof(double));
+                       size = sizeof(*src.rss->rss_conf->rss_key) *
+                               src.rss->rss_conf->rss_key_len;
+                       if (dst.rss) {
+                               ((struct rte_eth_rss_conf *)(uintptr_t)
+                                dst.rss->rss_conf)->rss_key =
+                                       (void *)((uintptr_t)dst.rss + off);
+                               memcpy(dst.rss->rss_conf->rss_key,
+                                      src.rss->rss_conf->rss_key,
+                                      size);
+                       }
+                       off += size;
+               }
+               size = off;
                break;
        default:
-               *size = flow_action[action->type].size;
+               size = flow_action[action->type].size;
+               if (buf)
+                       memcpy(buf, action->conf, size);
                break;
        }
 empty:
-       *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+       return RTE_ALIGN_CEIL(size, sizeof(double));
 }
 
 /** Generate a port_flow entry from attributes/pattern/actions. */
@@ -1073,7 +1150,6 @@ port_flow_new(const struct rte_flow_attr *attr,
        const struct rte_flow_action *action;
        struct port_flow *pf = NULL;
        size_t tmp;
-       size_t pad;
        size_t off1 = 0;
        size_t off2 = 0;
        int err = ENOTSUP;
@@ -1091,24 +1167,23 @@ store:
                if (pf)
                        dst = memcpy(pf->data + off1, item, sizeof(*item));
                off1 += sizeof(*item);
-               flow_item_spec_size(item, &tmp, &pad);
                if (item->spec) {
                        if (pf)
-                               dst->spec = memcpy(pf->data + off2,
-                                                  item->spec, tmp);
-                       off2 += tmp + pad;
+                               dst->spec = pf->data + off2;
+                       off2 += flow_item_spec_copy
+                               (pf ? pf->data + off2 : NULL, item, ITEM_SPEC);
                }
                if (item->last) {
                        if (pf)
-                               dst->last = memcpy(pf->data + off2,
-                                                  item->last, tmp);
-                       off2 += tmp + pad;
+                               dst->last = pf->data + off2;
+                       off2 += flow_item_spec_copy
+                               (pf ? pf->data + off2 : NULL, item, ITEM_LAST);
                }
                if (item->mask) {
                        if (pf)
-                               dst->mask = memcpy(pf->data + off2,
-                                                  item->mask, tmp);
-                       off2 += tmp + pad;
+                               dst->mask = pf->data + off2;
+                       off2 += flow_item_spec_copy
+                               (pf ? pf->data + off2 : NULL, item, ITEM_MASK);
                }
                off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
        } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
@@ -1125,12 +1200,11 @@ store:
                if (pf)
                        dst = memcpy(pf->data + off1, action, sizeof(*action));
                off1 += sizeof(*action);
-               flow_action_conf_size(action, &tmp, &pad);
                if (action->conf) {
                        if (pf)
-                               dst->conf = memcpy(pf->data + off2,
-                                                  action->conf, tmp);
-                       off2 += tmp + pad;
+                               dst->conf = pf->data + off2;
+                       off2 += flow_action_conf_copy
+                               (pf ? pf->data + off2 : NULL, action);
                }
                off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
        } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
@@ -1682,10 +1756,6 @@ rxtx_config_display(void)
                struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf;
 
                printf("  port %d:\n", (unsigned int)pid);
-               printf("  CRC stripping %s\n",
-                               (ports[pid].dev_conf.rxmode.offloads &
-                                DEV_RX_OFFLOAD_CRC_STRIP) ?
-                               "enabled" : "disabled");
                printf("  RX queues=%d - RX desc=%d - RX free threshold=%d\n",
                                nb_rxq, nb_rxd, rx_conf->rx_free_thresh);
                printf("  RX threshold registers: pthresh=%d hthresh=%d "
@@ -1693,6 +1763,9 @@ rxtx_config_display(void)
                                rx_conf->rx_thresh.pthresh,
                                rx_conf->rx_thresh.hthresh,
                                rx_conf->rx_thresh.wthresh);
+               printf("  Rx offloads=0x%"PRIx64" RXQ offloads=0x%"PRIx64"\n",
+                               ports[pid].dev_conf.rxmode.offloads,
+                               rx_conf->offloads);
                printf("  TX queues=%d - TX desc=%d - TX free threshold=%d\n",
                                nb_txq, nb_txd, tx_conf->tx_free_thresh);
                printf("  TX threshold registers: pthresh=%d hthresh=%d "
@@ -1700,8 +1773,10 @@ rxtx_config_display(void)
                                tx_conf->tx_thresh.pthresh,
                                tx_conf->tx_thresh.hthresh,
                                tx_conf->tx_thresh.wthresh);
-               printf("  TX RS bit threshold=%d - TXQ offloads=0x%"PRIx64"\n",
-                               tx_conf->tx_rs_thresh, tx_conf->offloads);
+               printf("  TX RS bit threshold=%d\n", tx_conf->tx_rs_thresh);
+               printf("  Tx offloads=0x%"PRIx64" TXQ offloads=0x%"PRIx64"\n",
+                               ports[pid].dev_conf.txmode.offloads,
+                               tx_conf->offloads);
        }
 }