net/octeontx2: create security context
[dpdk.git] / drivers / net / octeontx2 / otx2_ethdev.c
index 83a76fe..29426b8 100644 (file)
 #include <rte_mempool.h>
 
 #include "otx2_ethdev.h"
+#include "otx2_ethdev_sec.h"
 
 static inline uint64_t
 nix_get_rx_offload_capa(struct otx2_eth_dev *dev)
 {
        uint64_t capa = NIX_RX_OFFLOAD_CAPA;
 
-       if (otx2_dev_is_vf(dev))
+       if (otx2_dev_is_vf(dev) ||
+           dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG)
                capa &= ~DEV_RX_OFFLOAD_TIMESTAMP;
 
        return capa;
@@ -69,6 +71,8 @@ nix_lf_alloc(struct otx2_eth_dev *dev, uint32_t nb_rxq, uint32_t nb_txq)
                req->rx_cfg |= BIT_ULL(36 /* CSUM_IL4 */);
        }
        req->rx_cfg |= BIT_ULL(32 /* DROP_RE */);
+       if (dev->rss_tag_as_xor == 0)
+               req->flags = NIX_LF_RSS_TAG_LSB_AS_ADDER;
 
        rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
        if (rc)
@@ -92,7 +96,7 @@ nix_lf_alloc(struct otx2_eth_dev *dev, uint32_t nb_rxq, uint32_t nb_txq)
 }
 
 static int
-nix_lf_switch_header_type_enable(struct otx2_eth_dev *dev)
+nix_lf_switch_header_type_enable(struct otx2_eth_dev *dev, bool enable)
 {
        struct otx2_mbox *mbox = dev->mbox;
        struct npc_set_pkind *req;
@@ -105,12 +109,16 @@ nix_lf_switch_header_type_enable(struct otx2_eth_dev *dev)
        /* Notify AF about higig2 config */
        req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
        req->mode = dev->npc_flow.switch_header_type;
+       if (enable == 0)
+               req->mode = OTX2_PRIV_FLAGS_DEFAULT;
        req->dir = PKIND_RX;
        rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
        if (rc)
                return rc;
        req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
        req->mode = dev->npc_flow.switch_header_type;
+       if (enable == 0)
+               req->mode = OTX2_PRIV_FLAGS_DEFAULT;
        req->dir = PKIND_TX;
        return otx2_mbox_process_msg(mbox, (void *)&rsp);
 }
@@ -204,8 +212,8 @@ cgx_intlbk_enable(struct otx2_eth_dev *dev, bool en)
 {
        struct otx2_mbox *mbox = dev->mbox;
 
-       if (otx2_dev_is_vf_or_sdp(dev))
-               return 0;
+       if (en && otx2_dev_is_vf_or_sdp(dev))
+               return -ENOTSUP;
 
        if (en)
                otx2_mbox_alloc_msg_cgx_intlbk_enable(mbox);
@@ -622,6 +630,9 @@ nix_rx_offload_flags(struct rte_eth_dev *eth_dev)
        if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP))
                flags |= NIX_RX_OFFLOAD_TSTAMP_F;
 
+       if (!dev->ptype_disable)
+               flags |= NIX_RX_OFFLOAD_PTYPE_F;
+
        return flags;
 }
 
@@ -1638,7 +1649,13 @@ otx2_nix_configure(struct rte_eth_dev *eth_dev)
                goto fail_offloads;
        }
 
-       rc = nix_lf_switch_header_type_enable(dev);
+       if (dev->ptp_en &&
+           dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG) {
+               otx2_err("Both PTP and switch header enabled");
+               goto free_nix_lf;
+       }
+
+       rc = nix_lf_switch_header_type_enable(dev, true);
        if (rc) {
                otx2_err("Failed to enable switch type nix_lf rc=%d", rc);
                goto free_nix_lf;
@@ -1872,6 +1889,7 @@ otx2_nix_dev_stop(struct rte_eth_dev *eth_dev)
        struct otx2_eth_rxq *rxq;
        int count, i, j, rc;
 
+       nix_lf_switch_header_type_enable(dev, false);
        nix_cgx_stop_link_event(dev);
        npc_rx_disable(dev);
 
@@ -1995,6 +2013,7 @@ static const struct eth_dev_ops otx2_eth_dev_ops = {
        .dev_set_link_up          = otx2_nix_dev_set_link_up,
        .dev_set_link_down        = otx2_nix_dev_set_link_down,
        .dev_supported_ptypes_get = otx2_nix_supported_ptypes_get,
+       .dev_ptypes_set           = otx2_nix_ptypes_set,
        .dev_reset                = otx2_nix_dev_reset,
        .stats_get                = otx2_nix_dev_stats_get,
        .stats_reset              = otx2_nix_dev_stats_reset,
@@ -2167,6 +2186,7 @@ otx2_eth_dev_init(struct rte_eth_dev *eth_dev)
 
        dev->configured = 0;
        dev->drv_inited = true;
+       dev->ptype_disable = 0;
        dev->base = dev->bar2 + (RVU_BLOCK_ADDR_NIX0 << 20);
        dev->lmt_addr = dev->bar2 + (RVU_BLOCK_ADDR_LMT << 20);
 
@@ -2231,10 +2251,17 @@ otx2_eth_dev_init(struct rte_eth_dev *eth_dev)
                dev->hwcap |= OTX2_FIXUP_F_LIMIT_CQ_FULL;
        }
 
+       /* Create security ctx */
+       rc = otx2_eth_sec_ctx_create(eth_dev);
+       if (rc)
+               goto free_mac_addrs;
+       dev->tx_offload_capa |= DEV_TX_OFFLOAD_SECURITY;
+       dev->rx_offload_capa |= DEV_RX_OFFLOAD_SECURITY;
+
        /* Initialize rte-flow */
        rc = otx2_flow_init(dev);
        if (rc)
-               goto free_mac_addrs;
+               goto sec_ctx_destroy;
 
        otx2_nix_mc_filter_init(dev);
 
@@ -2245,6 +2272,8 @@ otx2_eth_dev_init(struct rte_eth_dev *eth_dev)
                     dev->rx_offload_capa, dev->tx_offload_capa);
        return 0;
 
+sec_ctx_destroy:
+       otx2_eth_sec_ctx_destroy(eth_dev);
 free_mac_addrs:
        rte_free(eth_dev->data->mac_addrs);
 unregister_irq:
@@ -2328,6 +2357,9 @@ otx2_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool mbox_close)
        if (rc)
                otx2_err("Failed to cleanup npa lf, rc=%d", rc);
 
+       /* Destroy security ctx */
+       otx2_eth_sec_ctx_destroy(eth_dev);
+
        rte_free(eth_dev->data->mac_addrs);
        eth_dev->data->mac_addrs = NULL;
        dev->drv_inited = false;