examples/ipsec-secgw: replace strncpy with strlcpy
[dpdk.git] / drivers / net / e1000 / igb_rxtx.c
index 450beea..a3776a0 100644 (file)
@@ -181,6 +181,7 @@ struct igb_tx_queue {
        /**< Start context position for transmit queue. */
        struct igb_advctx_info ctx_cache[IGB_CTX_NUM];
        /**< Hardware context history.*/
+       uint64_t               offloads; /**< offloads of DEV_TX_OFFLOAD_* */
 };
 
 #if 1
@@ -1448,6 +1449,48 @@ igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
        igb_reset_tx_queue_stat(txq);
 }
 
+uint64_t
+igb_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
+{
+       uint64_t rx_offload_capa;
+
+       RTE_SET_USED(dev);
+       rx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
+                         DEV_TX_OFFLOAD_IPV4_CKSUM  |
+                         DEV_TX_OFFLOAD_UDP_CKSUM   |
+                         DEV_TX_OFFLOAD_TCP_CKSUM   |
+                         DEV_TX_OFFLOAD_SCTP_CKSUM  |
+                         DEV_TX_OFFLOAD_TCP_TSO;
+
+       return rx_offload_capa;
+}
+
+uint64_t
+igb_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
+{
+       uint64_t rx_queue_offload_capa;
+
+       rx_queue_offload_capa = igb_get_tx_port_offloads_capa(dev);
+
+       return rx_queue_offload_capa;
+}
+
+static int
+igb_check_tx_queue_offloads(struct rte_eth_dev *dev, uint64_t requested)
+{
+       uint64_t port_offloads = dev->data->dev_conf.txmode.offloads;
+       uint64_t queue_supported = igb_get_tx_queue_offloads_capa(dev);
+       uint64_t port_supported = igb_get_tx_port_offloads_capa(dev);
+
+       if ((requested & (queue_supported | port_supported)) != requested)
+               return 0;
+
+       if ((port_offloads ^ requested) & port_supported)
+               return 0;
+
+       return 1;
+}
+
 int
 eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
                         uint16_t queue_idx,
@@ -1460,6 +1503,19 @@ eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
        struct e1000_hw     *hw;
        uint32_t size;
 
+       if (!igb_check_tx_queue_offloads(dev, tx_conf->offloads)) {
+               PMD_INIT_LOG(ERR, "%p: Tx queue offloads 0x%" PRIx64
+                       " don't match port offloads 0x%" PRIx64
+                       " or supported port offloads 0x%" PRIx64
+                       " or supported queue offloads 0x%" PRIx64,
+                       (void *)dev,
+                       tx_conf->offloads,
+                       dev->data->dev_conf.txmode.offloads,
+                       igb_get_tx_port_offloads_capa(dev),
+                       igb_get_tx_queue_offloads_capa(dev));
+               return -ENOTSUP;
+       }
+
        hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        /*
@@ -1543,6 +1599,7 @@ eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
        dev->tx_pkt_burst = eth_igb_xmit_pkts;
        dev->tx_pkt_prepare = &eth_igb_prep_pkts;
        dev->data->tx_queues[queue_idx] = txq;
+       txq->offloads = tx_conf->offloads;
 
        return 0;
 }
@@ -2837,6 +2894,41 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
        qinfo->conf.tx_thresh.pthresh = txq->pthresh;
        qinfo->conf.tx_thresh.hthresh = txq->hthresh;
        qinfo->conf.tx_thresh.wthresh = txq->wthresh;
+       qinfo->conf.offloads = txq->offloads;
+}
+
+int
+igb_rss_conf_init(struct igb_rte_flow_rss_conf *out,
+                 const struct rte_flow_action_rss *in)
+{
+       if (in->key_len > RTE_DIM(out->key) ||
+           in->queue_num > RTE_DIM(out->queue))
+               return -EINVAL;
+       out->conf = (struct rte_flow_action_rss){
+               .func = in->func,
+               .level = in->level,
+               .types = in->types,
+               .key_len = in->key_len,
+               .queue_num = in->queue_num,
+               .key = memcpy(out->key, in->key, in->key_len),
+               .queue = memcpy(out->queue, in->queue,
+                               sizeof(*in->queue) * in->queue_num),
+       };
+       return 0;
+}
+
+int
+igb_action_rss_same(const struct rte_flow_action_rss *comp,
+                   const struct rte_flow_action_rss *with)
+{
+       return (comp->func == with->func &&
+               comp->level == with->level &&
+               comp->types == with->types &&
+               comp->key_len == with->key_len &&
+               comp->queue_num == with->queue_num &&
+               !memcmp(comp->key, with->key, with->key_len) &&
+               !memcmp(comp->queue, with->queue,
+                       sizeof(*with->queue) * with->queue_num));
 }
 
 int
@@ -2845,7 +2937,12 @@ igb_config_rss_filter(struct rte_eth_dev *dev,
 {
        uint32_t shift;
        uint16_t i, j;
-       struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+       struct rte_eth_rss_conf rss_conf = {
+               .rss_key = conf->conf.key_len ?
+                       (void *)(uintptr_t)conf->conf.key : NULL,
+               .rss_key_len = conf->conf.key_len,
+               .rss_hf = conf->conf.types,
+       };
        struct e1000_filter_info *filter_info =
                E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -2853,8 +2950,8 @@ igb_config_rss_filter(struct rte_eth_dev *dev,
        hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        if (!add) {
-               if (memcmp(conf, &filter_info->rss_info,
-                       sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+               if (igb_action_rss_same(&filter_info->rss_info.conf,
+                                       &conf->conf)) {
                        igb_rss_disable(dev);
                        memset(&filter_info->rss_info, 0,
                                sizeof(struct igb_rte_flow_rss_conf));
@@ -2863,7 +2960,7 @@ igb_config_rss_filter(struct rte_eth_dev *dev,
                return -EINVAL;
        }
 
-       if (filter_info->rss_info.num)
+       if (filter_info->rss_info.conf.queue_num)
                return -EINVAL;
 
        /* Fill in redirection table. */
@@ -2875,9 +2972,9 @@ igb_config_rss_filter(struct rte_eth_dev *dev,
                } reta;
                uint8_t q_idx;
 
-               if (j == conf->num)
+               if (j == conf->conf.queue_num)
                        j = 0;
-               q_idx = conf->queue[j];
+               q_idx = conf->conf.queue[j];
                reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
                if ((i & 3) == 3)
                        E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
@@ -2894,8 +2991,8 @@ igb_config_rss_filter(struct rte_eth_dev *dev,
                rss_conf.rss_key = rss_intel_key; /* Default hash key */
        igb_hw_rss_hash_set(hw, &rss_conf);
 
-       rte_memcpy(&filter_info->rss_info,
-               conf, sizeof(struct igb_rte_flow_rss_conf));
+       if (igb_rss_conf_init(&filter_info->rss_info, &conf->conf))
+               return -EINVAL;
 
        return 0;
 }