net/ice/base: check failed acts allocation
[dpdk.git] / drivers / net / ice / ice_rxtx.c
index 3c3f61e..fecb134 100644 (file)
@@ -23,27 +23,40 @@ uint64_t rte_net_ice_dynflag_proto_xtr_ipv4_mask;
 uint64_t rte_net_ice_dynflag_proto_xtr_ipv6_mask;
 uint64_t rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask;
 uint64_t rte_net_ice_dynflag_proto_xtr_tcp_mask;
+uint64_t rte_net_ice_dynflag_proto_xtr_ip_offset_mask;
 
 static inline uint64_t
-ice_rxdid_to_proto_xtr_ol_flag(uint8_t rxdid)
-{
-       static uint64_t *ol_flag_map[] = {
-               [ICE_RXDID_COMMS_AUX_VLAN] =
-                               &rte_net_ice_dynflag_proto_xtr_vlan_mask,
-               [ICE_RXDID_COMMS_AUX_IPV4] =
-                               &rte_net_ice_dynflag_proto_xtr_ipv4_mask,
-               [ICE_RXDID_COMMS_AUX_IPV6] =
-                               &rte_net_ice_dynflag_proto_xtr_ipv6_mask,
-               [ICE_RXDID_COMMS_AUX_IPV6_FLOW] =
-                               &rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask,
-               [ICE_RXDID_COMMS_AUX_TCP] =
-                               &rte_net_ice_dynflag_proto_xtr_tcp_mask,
+ice_rxdid_to_proto_xtr_ol_flag(uint8_t rxdid, bool *chk_valid)
+{
+       static struct {
+               uint64_t *ol_flag;
+               bool chk_valid;
+       } ol_flag_map[] = {
+               [ICE_RXDID_COMMS_AUX_VLAN] = {
+                       &rte_net_ice_dynflag_proto_xtr_vlan_mask, true },
+               [ICE_RXDID_COMMS_AUX_IPV4] = {
+                       &rte_net_ice_dynflag_proto_xtr_ipv4_mask, true },
+               [ICE_RXDID_COMMS_AUX_IPV6] = {
+                       &rte_net_ice_dynflag_proto_xtr_ipv6_mask, true },
+               [ICE_RXDID_COMMS_AUX_IPV6_FLOW] = {
+                       &rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask, true },
+               [ICE_RXDID_COMMS_AUX_TCP] = {
+                       &rte_net_ice_dynflag_proto_xtr_tcp_mask, true },
+               [ICE_RXDID_COMMS_AUX_IP_OFFSET] = {
+                       &rte_net_ice_dynflag_proto_xtr_ip_offset_mask, false },
        };
        uint64_t *ol_flag;
 
-       ol_flag = rxdid < RTE_DIM(ol_flag_map) ? ol_flag_map[rxdid] : NULL;
+       if (rxdid < RTE_DIM(ol_flag_map)) {
+               ol_flag = ol_flag_map[rxdid].ol_flag;
+               if (!ol_flag)
+                       return 0ULL;
 
-       return ol_flag != NULL ? *ol_flag : 0ULL;
+               *chk_valid = ol_flag_map[rxdid].chk_valid;
+               return *ol_flag;
+       }
+
+       return 0ULL;
 }
 
 static inline uint8_t
@@ -56,6 +69,7 @@ ice_proto_xtr_type_to_rxdid(uint8_t xtr_type)
                [PROTO_XTR_IPV6]      = ICE_RXDID_COMMS_AUX_IPV6,
                [PROTO_XTR_IPV6_FLOW] = ICE_RXDID_COMMS_AUX_IPV6_FLOW,
                [PROTO_XTR_TCP]       = ICE_RXDID_COMMS_AUX_TCP,
+               [PROTO_XTR_IP_OFFSET] = ICE_RXDID_COMMS_AUX_IP_OFFSET,
        };
 
        return xtr_type < RTE_DIM(rxdid_map) ?
@@ -244,12 +258,6 @@ _ice_rx_queue_release_mbufs(struct ice_rx_queue *rxq)
        rxq->rx_nb_avail = 0;
 }
 
-static void
-ice_rx_queue_release_mbufs(struct ice_rx_queue *rxq)
-{
-       rxq->rx_rel_mbufs(rxq);
-}
-
 /* turn on or off rx queue
  * @q_idx: queue index in pf scope
  * @on: turn on or off the queue
@@ -408,7 +416,7 @@ ice_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
                PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
                            rx_queue_id);
 
-               ice_rx_queue_release_mbufs(rxq);
+               rxq->rx_rel_mbufs(rxq);
                ice_reset_rx_queue(rxq);
                return -EINVAL;
        }
@@ -435,7 +443,7 @@ ice_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
                                    rx_queue_id);
                        return -EINVAL;
                }
-               ice_rx_queue_release_mbufs(rxq);
+               rxq->rx_rel_mbufs(rxq);
                ice_reset_rx_queue(rxq);
                dev->data->rx_queue_state[rx_queue_id] =
                        RTE_ETH_QUEUE_STATE_STOPPED;
@@ -451,8 +459,9 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
        int err;
        struct ice_vsi *vsi;
        struct ice_hw *hw;
-       struct ice_aqc_add_tx_qgrp txq_elem;
+       struct ice_aqc_add_tx_qgrp *txq_elem;
        struct ice_tlan_ctx tx_ctx;
+       int buf_len;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -469,13 +478,17 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
                return -EINVAL;
        }
 
+       buf_len = ice_struct_size(txq_elem, txqs, 1);
+       txq_elem = ice_malloc(hw, buf_len);
+       if (!txq_elem)
+               return -ENOMEM;
+
        vsi = txq->vsi;
        hw = ICE_VSI_TO_HW(vsi);
 
-       memset(&txq_elem, 0, sizeof(txq_elem));
        memset(&tx_ctx, 0, sizeof(tx_ctx));
-       txq_elem.num_txqs = 1;
-       txq_elem.txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
+       txq_elem->num_txqs = 1;
+       txq_elem->txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
 
        tx_ctx.base = txq->tx_ring_dma / ICE_QUEUE_BASE_ADDR_UNIT;
        tx_ctx.qlen = txq->nb_tx_desc;
@@ -487,7 +500,7 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
        tx_ctx.tso_qnum = txq->reg_idx; /* index for tso state structure */
        tx_ctx.legacy_int = 1; /* Legacy or Advanced Host Interface */
 
-       ice_set_ctx((uint8_t *)&tx_ctx, txq_elem.txqs[0].txq_ctx,
+       ice_set_ctx(hw, (uint8_t *)&tx_ctx, txq_elem->txqs[0].txq_ctx,
                    ice_tlan_ctx_info);
 
        txq->qtx_tail = hw->hw_addr + QTX_COMM_DBELL(txq->reg_idx);
@@ -497,15 +510,18 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 
        /* Fix me, we assume TC always 0 here */
        err = ice_ena_vsi_txq(hw->port_info, vsi->idx, 0, tx_queue_id, 1,
-                       &txq_elem, sizeof(txq_elem), NULL);
+                       txq_elem, buf_len, NULL);
        if (err) {
                PMD_DRV_LOG(ERR, "Failed to add lan txq");
+               rte_free(txq_elem);
                return -EIO;
        }
        /* store the schedule node id */
-       txq->q_teid = txq_elem.txqs[0].q_teid;
+       txq->q_teid = txq_elem->txqs[0].q_teid;
 
        dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
+
+       rte_free(txq_elem);
        return 0;
 }
 
@@ -629,8 +645,9 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
        int err;
        struct ice_vsi *vsi;
        struct ice_hw *hw;
-       struct ice_aqc_add_tx_qgrp txq_elem;
+       struct ice_aqc_add_tx_qgrp *txq_elem;
        struct ice_tlan_ctx tx_ctx;
+       int buf_len;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -641,13 +658,17 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
                return -EINVAL;
        }
 
+       buf_len = ice_struct_size(txq_elem, txqs, 1);
+       txq_elem = ice_malloc(hw, buf_len);
+       if (!txq_elem)
+               return -ENOMEM;
+
        vsi = txq->vsi;
        hw = ICE_VSI_TO_HW(vsi);
 
-       memset(&txq_elem, 0, sizeof(txq_elem));
        memset(&tx_ctx, 0, sizeof(tx_ctx));
-       txq_elem.num_txqs = 1;
-       txq_elem.txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
+       txq_elem->num_txqs = 1;
+       txq_elem->txqs[0].txq_id = rte_cpu_to_le_16(txq->reg_idx);
 
        tx_ctx.base = txq->tx_ring_dma / ICE_QUEUE_BASE_ADDR_UNIT;
        tx_ctx.qlen = txq->nb_tx_desc;
@@ -659,7 +680,7 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
        tx_ctx.tso_qnum = txq->reg_idx; /* index for tso state structure */
        tx_ctx.legacy_int = 1; /* Legacy or Advanced Host Interface */
 
-       ice_set_ctx((uint8_t *)&tx_ctx, txq_elem.txqs[0].txq_ctx,
+       ice_set_ctx(hw, (uint8_t *)&tx_ctx, txq_elem->txqs[0].txq_ctx,
                    ice_tlan_ctx_info);
 
        txq->qtx_tail = hw->hw_addr + QTX_COMM_DBELL(txq->reg_idx);
@@ -669,14 +690,16 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 
        /* Fix me, we assume TC always 0 here */
        err = ice_ena_vsi_txq(hw->port_info, vsi->idx, 0, tx_queue_id, 1,
-                             &txq_elem, sizeof(txq_elem), NULL);
+                             txq_elem, buf_len, NULL);
        if (err) {
                PMD_DRV_LOG(ERR, "Failed to add FDIR txq");
+               rte_free(txq_elem);
                return -EIO;
        }
        /* store the schedule node id */
-       txq->q_teid = txq_elem.txqs[0].q_teid;
+       txq->q_teid = txq_elem->txqs[0].q_teid;
 
+       rte_free(txq_elem);
        return 0;
 }
 
@@ -698,11 +721,6 @@ _ice_tx_queue_release_mbufs(struct ice_tx_queue *txq)
                }
        }
 }
-static void
-ice_tx_queue_release_mbufs(struct ice_tx_queue *txq)
-{
-       txq->tx_rel_mbufs(txq);
-}
 
 static void
 ice_reset_tx_queue(struct ice_tx_queue *txq)
@@ -778,7 +796,7 @@ ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
                return -EINVAL;
        }
 
-       ice_tx_queue_release_mbufs(txq);
+       txq->tx_rel_mbufs(txq);
        ice_reset_tx_queue(txq);
        dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
 
@@ -801,7 +819,7 @@ ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
                            rx_queue_id);
                return -EINVAL;
        }
-       ice_rx_queue_release_mbufs(rxq);
+       rxq->rx_rel_mbufs(rxq);
 
        return 0;
 }
@@ -837,7 +855,7 @@ ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
                return -EINVAL;
        }
 
-       ice_tx_queue_release_mbufs(txq);
+       txq->tx_rel_mbufs(txq);
 
        return 0;
 }
@@ -976,7 +994,7 @@ ice_rx_queue_release(void *rxq)
                return;
        }
 
-       ice_rx_queue_release_mbufs(q);
+       q->rx_rel_mbufs(q);
        rte_free(q->sw_ring);
        rte_free(q);
 }
@@ -1172,7 +1190,7 @@ ice_tx_queue_release(void *txq)
                return;
        }
 
-       ice_tx_queue_release_mbufs(q);
+       q->tx_rel_mbufs(q);
        rte_free(q->sw_ring);
        rte_free(q);
 }
@@ -1323,23 +1341,32 @@ ice_rxd_to_proto_xtr(struct rte_mbuf *mb,
                     volatile struct ice_32b_rx_flex_desc_comms *desc)
 {
        uint16_t stat_err = rte_le_to_cpu_16(desc->status_error1);
-       uint32_t metadata;
+       uint32_t metadata = 0;
        uint64_t ol_flag;
+       bool chk_valid;
 
-       if (unlikely(!(stat_err & ICE_RX_PROTO_XTR_VALID)))
-               return;
-
-       ol_flag = ice_rxdid_to_proto_xtr_ol_flag(desc->rxdid);
+       ol_flag = ice_rxdid_to_proto_xtr_ol_flag(desc->rxdid, &chk_valid);
        if (unlikely(!ol_flag))
                return;
 
-       mb->ol_flags |= ol_flag;
+       if (chk_valid) {
+               if (stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD4_VALID_S))
+                       metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
 
-       metadata = stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD4_VALID_S) ?
-                               rte_le_to_cpu_16(desc->flex_ts.flex.aux0) : 0;
+               if (stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD5_VALID_S))
+                       metadata |=
+                               rte_le_to_cpu_16(desc->flex_ts.flex.aux1) << 16;
+       } else {
+               if (rte_le_to_cpu_16(desc->flex_ts.flex.aux0) != 0xFFFF)
+                       metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
+               else if (rte_le_to_cpu_16(desc->flex_ts.flex.aux1) != 0xFFFF)
+                       metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux1);
+       }
+
+       if (!metadata)
+               return;
 
-       if (likely(stat_err & (1 << ICE_RX_FLEX_DESC_STATUS1_XTRMD5_VALID_S)))
-               metadata |= rte_le_to_cpu_16(desc->flex_ts.flex.aux1) << 16;
+       mb->ol_flags |= ol_flag;
 
        *RTE_NET_ICE_DYNF_PROTO_XTR_METADATA(mb) = metadata;
 }
@@ -1904,24 +1931,6 @@ ice_tx_descriptor_status(void *tx_queue, uint16_t offset)
        return RTE_ETH_TX_DESC_FULL;
 }
 
-void
-ice_clear_queues(struct rte_eth_dev *dev)
-{
-       uint16_t i;
-
-       PMD_INIT_FUNC_TRACE();
-
-       for (i = 0; i < dev->data->nb_tx_queues; i++) {
-               ice_tx_queue_release_mbufs(dev->data->tx_queues[i]);
-               ice_reset_tx_queue(dev->data->tx_queues[i]);
-       }
-
-       for (i = 0; i < dev->data->nb_rx_queues; i++) {
-               ice_rx_queue_release_mbufs(dev->data->rx_queues[i]);
-               ice_reset_rx_queue(dev->data->rx_queues[i]);
-       }
-}
-
 void
 ice_free_queues(struct rte_eth_dev *dev)
 {
@@ -1934,6 +1943,7 @@ ice_free_queues(struct rte_eth_dev *dev)
                        continue;
                ice_rx_queue_release(dev->data->rx_queues[i]);
                dev->data->rx_queues[i] = NULL;
+               rte_eth_dma_zone_free(dev, "rx_ring", i);
        }
        dev->data->nb_rx_queues = 0;
 
@@ -1942,6 +1952,7 @@ ice_free_queues(struct rte_eth_dev *dev)
                        continue;
                ice_tx_queue_release(dev->data->tx_queues[i]);
                dev->data->tx_queues[i] = NULL;
+               rte_eth_dma_zone_free(dev, "tx_ring", i);
        }
        dev->data->nb_tx_queues = 0;
 }
@@ -2436,6 +2447,8 @@ ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
                tx_pkt = *tx_pkts++;
 
                td_cmd = 0;
+               td_tag = 0;
+               td_offset = 0;
                ol_flags = tx_pkt->ol_flags;
                tx_offload.l2_len = tx_pkt->l2_len;
                tx_offload.l3_len = tx_pkt->l3_len;
@@ -2494,10 +2507,9 @@ ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
                                                   &cd_tunneling_params);
 
                /* Enable checksum offloading */
-               if (ol_flags & ICE_TX_CKSUM_OFFLOAD_MASK) {
+               if (ol_flags & ICE_TX_CKSUM_OFFLOAD_MASK)
                        ice_txd_enable_checksum(ol_flags, &td_cmd,
                                                &td_offset, tx_offload);
-               }
 
                if (nb_ctx) {
                        /* Setup TX context descriptor if required */
@@ -2614,7 +2626,7 @@ end_of_tx:
        return nb_tx;
 }
 
-static inline int __attribute__((always_inline))
+static __rte_always_inline int
 ice_tx_free_bufs(struct ice_tx_queue *txq)
 {
        struct ice_tx_entry *txep;
@@ -2903,7 +2915,7 @@ ice_xmit_pkts_simple(void *tx_queue,
        return nb_tx;
 }
 
-void __attribute__((cold))
+void __rte_cold
 ice_set_rx_function(struct rte_eth_dev *dev)
 {
        PMD_INIT_FUNC_TRACE();
@@ -3013,7 +3025,7 @@ ice_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
        return ret;
 }
 
-void __attribute__((cold))
+void __rte_cold
 ice_set_tx_function_flag(struct rte_eth_dev *dev, struct ice_tx_queue *txq)
 {
        struct ice_adapter *ad =
@@ -3082,7 +3094,7 @@ ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
        return i;
 }
 
-void __attribute__((cold))
+void __rte_cold
 ice_set_tx_function(struct rte_eth_dev *dev)
 {
        struct ice_adapter *ad =
@@ -3711,7 +3723,7 @@ ice_get_default_pkt_type(uint16_t ptype)
        return type_table[ptype];
 }
 
-void __attribute__((cold))
+void __rte_cold
 ice_set_default_ptype_table(struct rte_eth_dev *dev)
 {
        struct ice_adapter *ad =