18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
28c2ecf20Sopenharmony_ci/* QLogic qede NIC Driver
38c2ecf20Sopenharmony_ci * Copyright (c) 2015-2017  QLogic Corporation
48c2ecf20Sopenharmony_ci * Copyright (c) 2019-2020 Marvell International Ltd.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
88c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
98c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
108c2ecf20Sopenharmony_ci#include <linux/bpf_trace.h>
118c2ecf20Sopenharmony_ci#include <net/udp_tunnel.h>
128c2ecf20Sopenharmony_ci#include <linux/ip.h>
138c2ecf20Sopenharmony_ci#include <net/ipv6.h>
148c2ecf20Sopenharmony_ci#include <net/tcp.h>
158c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
168c2ecf20Sopenharmony_ci#include <linux/if_vlan.h>
178c2ecf20Sopenharmony_ci#include <net/ip6_checksum.h>
188c2ecf20Sopenharmony_ci#include "qede_ptp.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/qed/qed_if.h>
218c2ecf20Sopenharmony_ci#include "qede.h"
228c2ecf20Sopenharmony_ci/*********************************
238c2ecf20Sopenharmony_ci * Content also used by slowpath *
248c2ecf20Sopenharmony_ci *********************************/
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciint qede_alloc_rx_buffer(struct qede_rx_queue *rxq, bool allow_lazy)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	struct sw_rx_data *sw_rx_data;
298c2ecf20Sopenharmony_ci	struct eth_rx_bd *rx_bd;
308c2ecf20Sopenharmony_ci	dma_addr_t mapping;
318c2ecf20Sopenharmony_ci	struct page *data;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* In case lazy-allocation is allowed, postpone allocation until the
348c2ecf20Sopenharmony_ci	 * end of the NAPI run. We'd still need to make sure the Rx ring has
358c2ecf20Sopenharmony_ci	 * sufficient buffers to guarantee an additional Rx interrupt.
368c2ecf20Sopenharmony_ci	 */
378c2ecf20Sopenharmony_ci	if (allow_lazy && likely(rxq->filled_buffers > 12)) {
388c2ecf20Sopenharmony_ci		rxq->filled_buffers--;
398c2ecf20Sopenharmony_ci		return 0;
408c2ecf20Sopenharmony_ci	}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	data = alloc_pages(GFP_ATOMIC, 0);
438c2ecf20Sopenharmony_ci	if (unlikely(!data))
448c2ecf20Sopenharmony_ci		return -ENOMEM;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	/* Map the entire page as it would be used
478c2ecf20Sopenharmony_ci	 * for multiple RX buffer segment size mapping.
488c2ecf20Sopenharmony_ci	 */
498c2ecf20Sopenharmony_ci	mapping = dma_map_page(rxq->dev, data, 0,
508c2ecf20Sopenharmony_ci			       PAGE_SIZE, rxq->data_direction);
518c2ecf20Sopenharmony_ci	if (unlikely(dma_mapping_error(rxq->dev, mapping))) {
528c2ecf20Sopenharmony_ci		__free_page(data);
538c2ecf20Sopenharmony_ci		return -ENOMEM;
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod & NUM_RX_BDS_MAX];
578c2ecf20Sopenharmony_ci	sw_rx_data->page_offset = 0;
588c2ecf20Sopenharmony_ci	sw_rx_data->data = data;
598c2ecf20Sopenharmony_ci	sw_rx_data->mapping = mapping;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	/* Advance PROD and get BD pointer */
628c2ecf20Sopenharmony_ci	rx_bd = (struct eth_rx_bd *)qed_chain_produce(&rxq->rx_bd_ring);
638c2ecf20Sopenharmony_ci	WARN_ON(!rx_bd);
648c2ecf20Sopenharmony_ci	rx_bd->addr.hi = cpu_to_le32(upper_32_bits(mapping));
658c2ecf20Sopenharmony_ci	rx_bd->addr.lo = cpu_to_le32(lower_32_bits(mapping) +
668c2ecf20Sopenharmony_ci				     rxq->rx_headroom);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	rxq->sw_rx_prod++;
698c2ecf20Sopenharmony_ci	rxq->filled_buffers++;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	return 0;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Unmap the data and free skb */
758c2ecf20Sopenharmony_ciint qede_free_tx_pkt(struct qede_dev *edev, struct qede_tx_queue *txq, int *len)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	u16 idx = txq->sw_tx_cons;
788c2ecf20Sopenharmony_ci	struct sk_buff *skb = txq->sw_tx_ring.skbs[idx].skb;
798c2ecf20Sopenharmony_ci	struct eth_tx_1st_bd *first_bd;
808c2ecf20Sopenharmony_ci	struct eth_tx_bd *tx_data_bd;
818c2ecf20Sopenharmony_ci	int bds_consumed = 0;
828c2ecf20Sopenharmony_ci	int nbds;
838c2ecf20Sopenharmony_ci	bool data_split = txq->sw_tx_ring.skbs[idx].flags & QEDE_TSO_SPLIT_BD;
848c2ecf20Sopenharmony_ci	int i, split_bd_len = 0;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	if (unlikely(!skb)) {
878c2ecf20Sopenharmony_ci		DP_ERR(edev,
888c2ecf20Sopenharmony_ci		       "skb is null for txq idx=%d txq->sw_tx_cons=%d txq->sw_tx_prod=%d\n",
898c2ecf20Sopenharmony_ci		       idx, txq->sw_tx_cons, txq->sw_tx_prod);
908c2ecf20Sopenharmony_ci		return -1;
918c2ecf20Sopenharmony_ci	}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	*len = skb->len;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	bds_consumed++;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	nbds = first_bd->data.nbds;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	if (data_split) {
1028c2ecf20Sopenharmony_ci		struct eth_tx_bd *split = (struct eth_tx_bd *)
1038c2ecf20Sopenharmony_ci			qed_chain_consume(&txq->tx_pbl);
1048c2ecf20Sopenharmony_ci		split_bd_len = BD_UNMAP_LEN(split);
1058c2ecf20Sopenharmony_ci		bds_consumed++;
1068c2ecf20Sopenharmony_ci	}
1078c2ecf20Sopenharmony_ci	dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1088c2ecf20Sopenharmony_ci			 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* Unmap the data of the skb frags */
1118c2ecf20Sopenharmony_ci	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, bds_consumed++) {
1128c2ecf20Sopenharmony_ci		tx_data_bd = (struct eth_tx_bd *)
1138c2ecf20Sopenharmony_ci			qed_chain_consume(&txq->tx_pbl);
1148c2ecf20Sopenharmony_ci		dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(tx_data_bd),
1158c2ecf20Sopenharmony_ci			       BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
1168c2ecf20Sopenharmony_ci	}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	while (bds_consumed++ < nbds)
1198c2ecf20Sopenharmony_ci		qed_chain_consume(&txq->tx_pbl);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	/* Free skb */
1228c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
1238c2ecf20Sopenharmony_ci	txq->sw_tx_ring.skbs[idx].skb = NULL;
1248c2ecf20Sopenharmony_ci	txq->sw_tx_ring.skbs[idx].flags = 0;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	return 0;
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* Unmap the data and free skb when mapping failed during start_xmit */
1308c2ecf20Sopenharmony_cistatic void qede_free_failed_tx_pkt(struct qede_tx_queue *txq,
1318c2ecf20Sopenharmony_ci				    struct eth_tx_1st_bd *first_bd,
1328c2ecf20Sopenharmony_ci				    int nbd, bool data_split)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	u16 idx = txq->sw_tx_prod;
1358c2ecf20Sopenharmony_ci	struct sk_buff *skb = txq->sw_tx_ring.skbs[idx].skb;
1368c2ecf20Sopenharmony_ci	struct eth_tx_bd *tx_data_bd;
1378c2ecf20Sopenharmony_ci	int i, split_bd_len = 0;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	/* Return prod to its position before this skb was handled */
1408c2ecf20Sopenharmony_ci	qed_chain_set_prod(&txq->tx_pbl,
1418c2ecf20Sopenharmony_ci			   le16_to_cpu(txq->tx_db.data.bd_prod), first_bd);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	first_bd = (struct eth_tx_1st_bd *)qed_chain_produce(&txq->tx_pbl);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	if (data_split) {
1468c2ecf20Sopenharmony_ci		struct eth_tx_bd *split = (struct eth_tx_bd *)
1478c2ecf20Sopenharmony_ci					  qed_chain_produce(&txq->tx_pbl);
1488c2ecf20Sopenharmony_ci		split_bd_len = BD_UNMAP_LEN(split);
1498c2ecf20Sopenharmony_ci		nbd--;
1508c2ecf20Sopenharmony_ci	}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	dma_unmap_single(txq->dev, BD_UNMAP_ADDR(first_bd),
1538c2ecf20Sopenharmony_ci			 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* Unmap the data of the skb frags */
1568c2ecf20Sopenharmony_ci	for (i = 0; i < nbd; i++) {
1578c2ecf20Sopenharmony_ci		tx_data_bd = (struct eth_tx_bd *)
1588c2ecf20Sopenharmony_ci			qed_chain_produce(&txq->tx_pbl);
1598c2ecf20Sopenharmony_ci		if (tx_data_bd->nbytes)
1608c2ecf20Sopenharmony_ci			dma_unmap_page(txq->dev,
1618c2ecf20Sopenharmony_ci				       BD_UNMAP_ADDR(tx_data_bd),
1628c2ecf20Sopenharmony_ci				       BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
1638c2ecf20Sopenharmony_ci	}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	/* Return again prod to its position before this skb was handled */
1668c2ecf20Sopenharmony_ci	qed_chain_set_prod(&txq->tx_pbl,
1678c2ecf20Sopenharmony_ci			   le16_to_cpu(txq->tx_db.data.bd_prod), first_bd);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	/* Free skb */
1708c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
1718c2ecf20Sopenharmony_ci	txq->sw_tx_ring.skbs[idx].skb = NULL;
1728c2ecf20Sopenharmony_ci	txq->sw_tx_ring.skbs[idx].flags = 0;
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic u32 qede_xmit_type(struct sk_buff *skb, int *ipv6_ext)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	u32 rc = XMIT_L4_CSUM;
1788c2ecf20Sopenharmony_ci	__be16 l3_proto;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	if (skb->ip_summed != CHECKSUM_PARTIAL)
1818c2ecf20Sopenharmony_ci		return XMIT_PLAIN;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	l3_proto = vlan_get_protocol(skb);
1848c2ecf20Sopenharmony_ci	if (l3_proto == htons(ETH_P_IPV6) &&
1858c2ecf20Sopenharmony_ci	    (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
1868c2ecf20Sopenharmony_ci		*ipv6_ext = 1;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	if (skb->encapsulation) {
1898c2ecf20Sopenharmony_ci		rc |= XMIT_ENC;
1908c2ecf20Sopenharmony_ci		if (skb_is_gso(skb)) {
1918c2ecf20Sopenharmony_ci			unsigned short gso_type = skb_shinfo(skb)->gso_type;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci			if ((gso_type & SKB_GSO_UDP_TUNNEL_CSUM) ||
1948c2ecf20Sopenharmony_ci			    (gso_type & SKB_GSO_GRE_CSUM))
1958c2ecf20Sopenharmony_ci				rc |= XMIT_ENC_GSO_L4_CSUM;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci			rc |= XMIT_LSO;
1988c2ecf20Sopenharmony_ci			return rc;
1998c2ecf20Sopenharmony_ci		}
2008c2ecf20Sopenharmony_ci	}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	if (skb_is_gso(skb))
2038c2ecf20Sopenharmony_ci		rc |= XMIT_LSO;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	return rc;
2068c2ecf20Sopenharmony_ci}
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic void qede_set_params_for_ipv6_ext(struct sk_buff *skb,
2098c2ecf20Sopenharmony_ci					 struct eth_tx_2nd_bd *second_bd,
2108c2ecf20Sopenharmony_ci					 struct eth_tx_3rd_bd *third_bd)
2118c2ecf20Sopenharmony_ci{
2128c2ecf20Sopenharmony_ci	u8 l4_proto;
2138c2ecf20Sopenharmony_ci	u16 bd2_bits1 = 0, bd2_bits2 = 0;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	bd2_bits1 |= (1 << ETH_TX_DATA_2ND_BD_IPV6_EXT_SHIFT);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	bd2_bits2 |= ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) &
2188c2ecf20Sopenharmony_ci		     ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_MASK)
2198c2ecf20Sopenharmony_ci		    << ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_SHIFT;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	bd2_bits1 |= (ETH_L4_PSEUDO_CSUM_CORRECT_LENGTH <<
2228c2ecf20Sopenharmony_ci		      ETH_TX_DATA_2ND_BD_L4_PSEUDO_CSUM_MODE_SHIFT);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	if (vlan_get_protocol(skb) == htons(ETH_P_IPV6))
2258c2ecf20Sopenharmony_ci		l4_proto = ipv6_hdr(skb)->nexthdr;
2268c2ecf20Sopenharmony_ci	else
2278c2ecf20Sopenharmony_ci		l4_proto = ip_hdr(skb)->protocol;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	if (l4_proto == IPPROTO_UDP)
2308c2ecf20Sopenharmony_ci		bd2_bits1 |= 1 << ETH_TX_DATA_2ND_BD_L4_UDP_SHIFT;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	if (third_bd)
2338c2ecf20Sopenharmony_ci		third_bd->data.bitfields |=
2348c2ecf20Sopenharmony_ci			cpu_to_le16(((tcp_hdrlen(skb) / 4) &
2358c2ecf20Sopenharmony_ci				ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_MASK) <<
2368c2ecf20Sopenharmony_ci				ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_SHIFT);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	second_bd->data.bitfields1 = cpu_to_le16(bd2_bits1);
2398c2ecf20Sopenharmony_ci	second_bd->data.bitfields2 = cpu_to_le16(bd2_bits2);
2408c2ecf20Sopenharmony_ci}
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistatic int map_frag_to_bd(struct qede_tx_queue *txq,
2438c2ecf20Sopenharmony_ci			  skb_frag_t *frag, struct eth_tx_bd *bd)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	dma_addr_t mapping;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	/* Map skb non-linear frag data for DMA */
2488c2ecf20Sopenharmony_ci	mapping = skb_frag_dma_map(txq->dev, frag, 0,
2498c2ecf20Sopenharmony_ci				   skb_frag_size(frag), DMA_TO_DEVICE);
2508c2ecf20Sopenharmony_ci	if (unlikely(dma_mapping_error(txq->dev, mapping)))
2518c2ecf20Sopenharmony_ci		return -ENOMEM;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	/* Setup the data pointer of the frag data */
2548c2ecf20Sopenharmony_ci	BD_SET_UNMAP_ADDR_LEN(bd, mapping, skb_frag_size(frag));
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	return 0;
2578c2ecf20Sopenharmony_ci}
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistatic u16 qede_get_skb_hlen(struct sk_buff *skb, bool is_encap_pkt)
2608c2ecf20Sopenharmony_ci{
2618c2ecf20Sopenharmony_ci	if (is_encap_pkt)
2628c2ecf20Sopenharmony_ci		return (skb_inner_transport_header(skb) +
2638c2ecf20Sopenharmony_ci			inner_tcp_hdrlen(skb) - skb->data);
2648c2ecf20Sopenharmony_ci	else
2658c2ecf20Sopenharmony_ci		return (skb_transport_header(skb) +
2668c2ecf20Sopenharmony_ci			tcp_hdrlen(skb) - skb->data);
2678c2ecf20Sopenharmony_ci}
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/* +2 for 1st BD for headers and 2nd BD for headlen (if required) */
2708c2ecf20Sopenharmony_ci#if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
2718c2ecf20Sopenharmony_cistatic bool qede_pkt_req_lin(struct sk_buff *skb, u8 xmit_type)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	int allowed_frags = ETH_TX_MAX_BDS_PER_NON_LSO_PACKET - 1;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	if (xmit_type & XMIT_LSO) {
2768c2ecf20Sopenharmony_ci		int hlen;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci		hlen = qede_get_skb_hlen(skb, xmit_type & XMIT_ENC);
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci		/* linear payload would require its own BD */
2818c2ecf20Sopenharmony_ci		if (skb_headlen(skb) > hlen)
2828c2ecf20Sopenharmony_ci			allowed_frags--;
2838c2ecf20Sopenharmony_ci	}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	return (skb_shinfo(skb)->nr_frags > allowed_frags);
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci#endif
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_cistatic inline void qede_update_tx_producer(struct qede_tx_queue *txq)
2908c2ecf20Sopenharmony_ci{
2918c2ecf20Sopenharmony_ci	/* wmb makes sure that the BDs data is updated before updating the
2928c2ecf20Sopenharmony_ci	 * producer, otherwise FW may read old data from the BDs.
2938c2ecf20Sopenharmony_ci	 */
2948c2ecf20Sopenharmony_ci	wmb();
2958c2ecf20Sopenharmony_ci	barrier();
2968c2ecf20Sopenharmony_ci	writel(txq->tx_db.raw, txq->doorbell_addr);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	/* Fence required to flush the write combined buffer, since another
2998c2ecf20Sopenharmony_ci	 * CPU may write to the same doorbell address and data may be lost
3008c2ecf20Sopenharmony_ci	 * due to relaxed order nature of write combined bar.
3018c2ecf20Sopenharmony_ci	 */
3028c2ecf20Sopenharmony_ci	wmb();
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic int qede_xdp_xmit(struct qede_tx_queue *txq, dma_addr_t dma, u16 pad,
3068c2ecf20Sopenharmony_ci			 u16 len, struct page *page, struct xdp_frame *xdpf)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	struct eth_tx_1st_bd *bd;
3098c2ecf20Sopenharmony_ci	struct sw_tx_xdp *xdp;
3108c2ecf20Sopenharmony_ci	u16 val;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	if (unlikely(qed_chain_get_elem_used(&txq->tx_pbl) >=
3138c2ecf20Sopenharmony_ci		     txq->num_tx_buffers)) {
3148c2ecf20Sopenharmony_ci		txq->stopped_cnt++;
3158c2ecf20Sopenharmony_ci		return -ENOMEM;
3168c2ecf20Sopenharmony_ci	}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	bd = qed_chain_produce(&txq->tx_pbl);
3198c2ecf20Sopenharmony_ci	bd->data.nbds = 1;
3208c2ecf20Sopenharmony_ci	bd->data.bd_flags.bitfields = BIT(ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	val = (len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK) <<
3238c2ecf20Sopenharmony_ci	       ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	bd->data.bitfields = cpu_to_le16(val);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	/* We can safely ignore the offset, as it's 0 for XDP */
3288c2ecf20Sopenharmony_ci	BD_SET_UNMAP_ADDR_LEN(bd, dma + pad, len);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	xdp = txq->sw_tx_ring.xdp + txq->sw_tx_prod;
3318c2ecf20Sopenharmony_ci	xdp->mapping = dma;
3328c2ecf20Sopenharmony_ci	xdp->page = page;
3338c2ecf20Sopenharmony_ci	xdp->xdpf = xdpf;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	return 0;
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ciint qede_xdp_transmit(struct net_device *dev, int n_frames,
3418c2ecf20Sopenharmony_ci		      struct xdp_frame **frames, u32 flags)
3428c2ecf20Sopenharmony_ci{
3438c2ecf20Sopenharmony_ci	struct qede_dev *edev = netdev_priv(dev);
3448c2ecf20Sopenharmony_ci	struct device *dmadev = &edev->pdev->dev;
3458c2ecf20Sopenharmony_ci	struct qede_tx_queue *xdp_tx;
3468c2ecf20Sopenharmony_ci	struct xdp_frame *xdpf;
3478c2ecf20Sopenharmony_ci	dma_addr_t mapping;
3488c2ecf20Sopenharmony_ci	int i, drops = 0;
3498c2ecf20Sopenharmony_ci	u16 xdp_prod;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
3528c2ecf20Sopenharmony_ci		return -EINVAL;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	if (unlikely(!netif_running(dev)))
3558c2ecf20Sopenharmony_ci		return -ENETDOWN;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	i = smp_processor_id() % edev->total_xdp_queues;
3588c2ecf20Sopenharmony_ci	xdp_tx = edev->fp_array[i].xdp_tx;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	spin_lock(&xdp_tx->xdp_tx_lock);
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	for (i = 0; i < n_frames; i++) {
3638c2ecf20Sopenharmony_ci		xdpf = frames[i];
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci		mapping = dma_map_single(dmadev, xdpf->data, xdpf->len,
3668c2ecf20Sopenharmony_ci					 DMA_TO_DEVICE);
3678c2ecf20Sopenharmony_ci		if (unlikely(dma_mapping_error(dmadev, mapping))) {
3688c2ecf20Sopenharmony_ci			xdp_return_frame_rx_napi(xdpf);
3698c2ecf20Sopenharmony_ci			drops++;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci			continue;
3728c2ecf20Sopenharmony_ci		}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci		if (unlikely(qede_xdp_xmit(xdp_tx, mapping, 0, xdpf->len,
3758c2ecf20Sopenharmony_ci					   NULL, xdpf))) {
3768c2ecf20Sopenharmony_ci			xdp_return_frame_rx_napi(xdpf);
3778c2ecf20Sopenharmony_ci			drops++;
3788c2ecf20Sopenharmony_ci		}
3798c2ecf20Sopenharmony_ci	}
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	if (flags & XDP_XMIT_FLUSH) {
3828c2ecf20Sopenharmony_ci		xdp_prod = qed_chain_get_prod_idx(&xdp_tx->tx_pbl);
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci		xdp_tx->tx_db.data.bd_prod = cpu_to_le16(xdp_prod);
3858c2ecf20Sopenharmony_ci		qede_update_tx_producer(xdp_tx);
3868c2ecf20Sopenharmony_ci	}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	spin_unlock(&xdp_tx->xdp_tx_lock);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	return n_frames - drops;
3918c2ecf20Sopenharmony_ci}
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ciint qede_txq_has_work(struct qede_tx_queue *txq)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	u16 hw_bd_cons;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	/* Tell compiler that consumer and producer can change */
3988c2ecf20Sopenharmony_ci	barrier();
3998c2ecf20Sopenharmony_ci	hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
4008c2ecf20Sopenharmony_ci	if (qed_chain_get_cons_idx(&txq->tx_pbl) == hw_bd_cons + 1)
4018c2ecf20Sopenharmony_ci		return 0;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	return hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl);
4048c2ecf20Sopenharmony_ci}
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic void qede_xdp_tx_int(struct qede_dev *edev, struct qede_tx_queue *txq)
4078c2ecf20Sopenharmony_ci{
4088c2ecf20Sopenharmony_ci	struct sw_tx_xdp *xdp_info, *xdp_arr = txq->sw_tx_ring.xdp;
4098c2ecf20Sopenharmony_ci	struct device *dev = &edev->pdev->dev;
4108c2ecf20Sopenharmony_ci	struct xdp_frame *xdpf;
4118c2ecf20Sopenharmony_ci	u16 hw_bd_cons;
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci	hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
4148c2ecf20Sopenharmony_ci	barrier();
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	while (hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl)) {
4178c2ecf20Sopenharmony_ci		xdp_info = xdp_arr + txq->sw_tx_cons;
4188c2ecf20Sopenharmony_ci		xdpf = xdp_info->xdpf;
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci		if (xdpf) {
4218c2ecf20Sopenharmony_ci			dma_unmap_single(dev, xdp_info->mapping, xdpf->len,
4228c2ecf20Sopenharmony_ci					 DMA_TO_DEVICE);
4238c2ecf20Sopenharmony_ci			xdp_return_frame(xdpf);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci			xdp_info->xdpf = NULL;
4268c2ecf20Sopenharmony_ci		} else {
4278c2ecf20Sopenharmony_ci			dma_unmap_page(dev, xdp_info->mapping, PAGE_SIZE,
4288c2ecf20Sopenharmony_ci				       DMA_BIDIRECTIONAL);
4298c2ecf20Sopenharmony_ci			__free_page(xdp_info->page);
4308c2ecf20Sopenharmony_ci		}
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci		qed_chain_consume(&txq->tx_pbl);
4338c2ecf20Sopenharmony_ci		txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
4348c2ecf20Sopenharmony_ci		txq->xmit_pkts++;
4358c2ecf20Sopenharmony_ci	}
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cistatic int qede_tx_int(struct qede_dev *edev, struct qede_tx_queue *txq)
4398c2ecf20Sopenharmony_ci{
4408c2ecf20Sopenharmony_ci	unsigned int pkts_compl = 0, bytes_compl = 0;
4418c2ecf20Sopenharmony_ci	struct netdev_queue *netdev_txq;
4428c2ecf20Sopenharmony_ci	u16 hw_bd_cons;
4438c2ecf20Sopenharmony_ci	int rc;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	netdev_txq = netdev_get_tx_queue(edev->ndev, txq->ndev_txq_id);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
4488c2ecf20Sopenharmony_ci	barrier();
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	while (hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl)) {
4518c2ecf20Sopenharmony_ci		int len = 0;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci		rc = qede_free_tx_pkt(edev, txq, &len);
4548c2ecf20Sopenharmony_ci		if (rc) {
4558c2ecf20Sopenharmony_ci			DP_NOTICE(edev, "hw_bd_cons = %d, chain_cons=%d\n",
4568c2ecf20Sopenharmony_ci				  hw_bd_cons,
4578c2ecf20Sopenharmony_ci				  qed_chain_get_cons_idx(&txq->tx_pbl));
4588c2ecf20Sopenharmony_ci			break;
4598c2ecf20Sopenharmony_ci		}
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci		bytes_compl += len;
4628c2ecf20Sopenharmony_ci		pkts_compl++;
4638c2ecf20Sopenharmony_ci		txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
4648c2ecf20Sopenharmony_ci		txq->xmit_pkts++;
4658c2ecf20Sopenharmony_ci	}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	netdev_tx_completed_queue(netdev_txq, pkts_compl, bytes_compl);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	/* Need to make the tx_bd_cons update visible to start_xmit()
4708c2ecf20Sopenharmony_ci	 * before checking for netif_tx_queue_stopped().  Without the
4718c2ecf20Sopenharmony_ci	 * memory barrier, there is a small possibility that
4728c2ecf20Sopenharmony_ci	 * start_xmit() will miss it and cause the queue to be stopped
4738c2ecf20Sopenharmony_ci	 * forever.
4748c2ecf20Sopenharmony_ci	 * On the other hand we need an rmb() here to ensure the proper
4758c2ecf20Sopenharmony_ci	 * ordering of bit testing in the following
4768c2ecf20Sopenharmony_ci	 * netif_tx_queue_stopped(txq) call.
4778c2ecf20Sopenharmony_ci	 */
4788c2ecf20Sopenharmony_ci	smp_mb();
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	if (unlikely(netif_tx_queue_stopped(netdev_txq))) {
4818c2ecf20Sopenharmony_ci		/* Taking tx_lock is needed to prevent reenabling the queue
4828c2ecf20Sopenharmony_ci		 * while it's empty. This could have happen if rx_action() gets
4838c2ecf20Sopenharmony_ci		 * suspended in qede_tx_int() after the condition before
4848c2ecf20Sopenharmony_ci		 * netif_tx_wake_queue(), while tx_action (qede_start_xmit()):
4858c2ecf20Sopenharmony_ci		 *
4868c2ecf20Sopenharmony_ci		 * stops the queue->sees fresh tx_bd_cons->releases the queue->
4878c2ecf20Sopenharmony_ci		 * sends some packets consuming the whole queue again->
4888c2ecf20Sopenharmony_ci		 * stops the queue
4898c2ecf20Sopenharmony_ci		 */
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci		__netif_tx_lock(netdev_txq, smp_processor_id());
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci		if ((netif_tx_queue_stopped(netdev_txq)) &&
4948c2ecf20Sopenharmony_ci		    (edev->state == QEDE_STATE_OPEN) &&
4958c2ecf20Sopenharmony_ci		    (qed_chain_get_elem_left(&txq->tx_pbl)
4968c2ecf20Sopenharmony_ci		      >= (MAX_SKB_FRAGS + 1))) {
4978c2ecf20Sopenharmony_ci			netif_tx_wake_queue(netdev_txq);
4988c2ecf20Sopenharmony_ci			DP_VERBOSE(edev, NETIF_MSG_TX_DONE,
4998c2ecf20Sopenharmony_ci				   "Wake queue was called\n");
5008c2ecf20Sopenharmony_ci		}
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci		__netif_tx_unlock(netdev_txq);
5038c2ecf20Sopenharmony_ci	}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	return 0;
5068c2ecf20Sopenharmony_ci}
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_cibool qede_has_rx_work(struct qede_rx_queue *rxq)
5098c2ecf20Sopenharmony_ci{
5108c2ecf20Sopenharmony_ci	u16 hw_comp_cons, sw_comp_cons;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	/* Tell compiler that status block fields can change */
5138c2ecf20Sopenharmony_ci	barrier();
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
5168c2ecf20Sopenharmony_ci	sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	return hw_comp_cons != sw_comp_cons;
5198c2ecf20Sopenharmony_ci}
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_cistatic inline void qede_rx_bd_ring_consume(struct qede_rx_queue *rxq)
5228c2ecf20Sopenharmony_ci{
5238c2ecf20Sopenharmony_ci	qed_chain_consume(&rxq->rx_bd_ring);
5248c2ecf20Sopenharmony_ci	rxq->sw_rx_cons++;
5258c2ecf20Sopenharmony_ci}
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci/* This function reuses the buffer(from an offset) from
5288c2ecf20Sopenharmony_ci * consumer index to producer index in the bd ring
5298c2ecf20Sopenharmony_ci */
5308c2ecf20Sopenharmony_cistatic inline void qede_reuse_page(struct qede_rx_queue *rxq,
5318c2ecf20Sopenharmony_ci				   struct sw_rx_data *curr_cons)
5328c2ecf20Sopenharmony_ci{
5338c2ecf20Sopenharmony_ci	struct eth_rx_bd *rx_bd_prod = qed_chain_produce(&rxq->rx_bd_ring);
5348c2ecf20Sopenharmony_ci	struct sw_rx_data *curr_prod;
5358c2ecf20Sopenharmony_ci	dma_addr_t new_mapping;
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	curr_prod = &rxq->sw_rx_ring[rxq->sw_rx_prod & NUM_RX_BDS_MAX];
5388c2ecf20Sopenharmony_ci	*curr_prod = *curr_cons;
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	new_mapping = curr_prod->mapping + curr_prod->page_offset;
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	rx_bd_prod->addr.hi = cpu_to_le32(upper_32_bits(new_mapping));
5438c2ecf20Sopenharmony_ci	rx_bd_prod->addr.lo = cpu_to_le32(lower_32_bits(new_mapping) +
5448c2ecf20Sopenharmony_ci					  rxq->rx_headroom);
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	rxq->sw_rx_prod++;
5478c2ecf20Sopenharmony_ci	curr_cons->data = NULL;
5488c2ecf20Sopenharmony_ci}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/* In case of allocation failures reuse buffers
5518c2ecf20Sopenharmony_ci * from consumer index to produce buffers for firmware
5528c2ecf20Sopenharmony_ci */
5538c2ecf20Sopenharmony_civoid qede_recycle_rx_bd_ring(struct qede_rx_queue *rxq, u8 count)
5548c2ecf20Sopenharmony_ci{
5558c2ecf20Sopenharmony_ci	struct sw_rx_data *curr_cons;
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	for (; count > 0; count--) {
5588c2ecf20Sopenharmony_ci		curr_cons = &rxq->sw_rx_ring[rxq->sw_rx_cons & NUM_RX_BDS_MAX];
5598c2ecf20Sopenharmony_ci		qede_reuse_page(rxq, curr_cons);
5608c2ecf20Sopenharmony_ci		qede_rx_bd_ring_consume(rxq);
5618c2ecf20Sopenharmony_ci	}
5628c2ecf20Sopenharmony_ci}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic inline int qede_realloc_rx_buffer(struct qede_rx_queue *rxq,
5658c2ecf20Sopenharmony_ci					 struct sw_rx_data *curr_cons)
5668c2ecf20Sopenharmony_ci{
5678c2ecf20Sopenharmony_ci	/* Move to the next segment in the page */
5688c2ecf20Sopenharmony_ci	curr_cons->page_offset += rxq->rx_buf_seg_size;
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci	if (curr_cons->page_offset == PAGE_SIZE) {
5718c2ecf20Sopenharmony_ci		if (unlikely(qede_alloc_rx_buffer(rxq, true))) {
5728c2ecf20Sopenharmony_ci			/* Since we failed to allocate new buffer
5738c2ecf20Sopenharmony_ci			 * current buffer can be used again.
5748c2ecf20Sopenharmony_ci			 */
5758c2ecf20Sopenharmony_ci			curr_cons->page_offset -= rxq->rx_buf_seg_size;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci			return -ENOMEM;
5788c2ecf20Sopenharmony_ci		}
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci		dma_unmap_page(rxq->dev, curr_cons->mapping,
5818c2ecf20Sopenharmony_ci			       PAGE_SIZE, rxq->data_direction);
5828c2ecf20Sopenharmony_ci	} else {
5838c2ecf20Sopenharmony_ci		/* Increment refcount of the page as we don't want
5848c2ecf20Sopenharmony_ci		 * network stack to take the ownership of the page
5858c2ecf20Sopenharmony_ci		 * which can be recycled multiple times by the driver.
5868c2ecf20Sopenharmony_ci		 */
5878c2ecf20Sopenharmony_ci		page_ref_inc(curr_cons->data);
5888c2ecf20Sopenharmony_ci		qede_reuse_page(rxq, curr_cons);
5898c2ecf20Sopenharmony_ci	}
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	return 0;
5928c2ecf20Sopenharmony_ci}
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_civoid qede_update_rx_prod(struct qede_dev *edev, struct qede_rx_queue *rxq)
5958c2ecf20Sopenharmony_ci{
5968c2ecf20Sopenharmony_ci	u16 bd_prod = qed_chain_get_prod_idx(&rxq->rx_bd_ring);
5978c2ecf20Sopenharmony_ci	u16 cqe_prod = qed_chain_get_prod_idx(&rxq->rx_comp_ring);
5988c2ecf20Sopenharmony_ci	struct eth_rx_prod_data rx_prods = {0};
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	/* Update producers */
6018c2ecf20Sopenharmony_ci	rx_prods.bd_prod = cpu_to_le16(bd_prod);
6028c2ecf20Sopenharmony_ci	rx_prods.cqe_prod = cpu_to_le16(cqe_prod);
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ci	/* Make sure that the BD and SGE data is updated before updating the
6058c2ecf20Sopenharmony_ci	 * producers since FW might read the BD/SGE right after the producer
6068c2ecf20Sopenharmony_ci	 * is updated.
6078c2ecf20Sopenharmony_ci	 */
6088c2ecf20Sopenharmony_ci	wmb();
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci	internal_ram_wr(rxq->hw_rxq_prod_addr, sizeof(rx_prods),
6118c2ecf20Sopenharmony_ci			(u32 *)&rx_prods);
6128c2ecf20Sopenharmony_ci}
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_cistatic void qede_get_rxhash(struct sk_buff *skb, u8 bitfields, __le32 rss_hash)
6158c2ecf20Sopenharmony_ci{
6168c2ecf20Sopenharmony_ci	enum pkt_hash_types hash_type = PKT_HASH_TYPE_NONE;
6178c2ecf20Sopenharmony_ci	enum rss_hash_type htype;
6188c2ecf20Sopenharmony_ci	u32 hash = 0;
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	htype = GET_FIELD(bitfields, ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE);
6218c2ecf20Sopenharmony_ci	if (htype) {
6228c2ecf20Sopenharmony_ci		hash_type = ((htype == RSS_HASH_TYPE_IPV4) ||
6238c2ecf20Sopenharmony_ci			     (htype == RSS_HASH_TYPE_IPV6)) ?
6248c2ecf20Sopenharmony_ci			    PKT_HASH_TYPE_L3 : PKT_HASH_TYPE_L4;
6258c2ecf20Sopenharmony_ci		hash = le32_to_cpu(rss_hash);
6268c2ecf20Sopenharmony_ci	}
6278c2ecf20Sopenharmony_ci	skb_set_hash(skb, hash, hash_type);
6288c2ecf20Sopenharmony_ci}
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_cistatic void qede_set_skb_csum(struct sk_buff *skb, u8 csum_flag)
6318c2ecf20Sopenharmony_ci{
6328c2ecf20Sopenharmony_ci	skb_checksum_none_assert(skb);
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	if (csum_flag & QEDE_CSUM_UNNECESSARY)
6358c2ecf20Sopenharmony_ci		skb->ip_summed = CHECKSUM_UNNECESSARY;
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	if (csum_flag & QEDE_TUNN_CSUM_UNNECESSARY) {
6388c2ecf20Sopenharmony_ci		skb->csum_level = 1;
6398c2ecf20Sopenharmony_ci		skb->encapsulation = 1;
6408c2ecf20Sopenharmony_ci	}
6418c2ecf20Sopenharmony_ci}
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_cistatic inline void qede_skb_receive(struct qede_dev *edev,
6448c2ecf20Sopenharmony_ci				    struct qede_fastpath *fp,
6458c2ecf20Sopenharmony_ci				    struct qede_rx_queue *rxq,
6468c2ecf20Sopenharmony_ci				    struct sk_buff *skb, u16 vlan_tag)
6478c2ecf20Sopenharmony_ci{
6488c2ecf20Sopenharmony_ci	if (vlan_tag)
6498c2ecf20Sopenharmony_ci		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci	napi_gro_receive(&fp->napi, skb);
6528c2ecf20Sopenharmony_ci}
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistatic void qede_set_gro_params(struct qede_dev *edev,
6558c2ecf20Sopenharmony_ci				struct sk_buff *skb,
6568c2ecf20Sopenharmony_ci				struct eth_fast_path_rx_tpa_start_cqe *cqe)
6578c2ecf20Sopenharmony_ci{
6588c2ecf20Sopenharmony_ci	u16 parsing_flags = le16_to_cpu(cqe->pars_flags.flags);
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci	if (((parsing_flags >> PARSING_AND_ERR_FLAGS_L3TYPE_SHIFT) &
6618c2ecf20Sopenharmony_ci	    PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == 2)
6628c2ecf20Sopenharmony_ci		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
6638c2ecf20Sopenharmony_ci	else
6648c2ecf20Sopenharmony_ci		skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	skb_shinfo(skb)->gso_size = __le16_to_cpu(cqe->len_on_first_bd) -
6678c2ecf20Sopenharmony_ci				    cqe->header_len;
6688c2ecf20Sopenharmony_ci}
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_cistatic int qede_fill_frag_skb(struct qede_dev *edev,
6718c2ecf20Sopenharmony_ci			      struct qede_rx_queue *rxq,
6728c2ecf20Sopenharmony_ci			      u8 tpa_agg_index, u16 len_on_bd)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	struct sw_rx_data *current_bd = &rxq->sw_rx_ring[rxq->sw_rx_cons &
6758c2ecf20Sopenharmony_ci							 NUM_RX_BDS_MAX];
6768c2ecf20Sopenharmony_ci	struct qede_agg_info *tpa_info = &rxq->tpa_info[tpa_agg_index];
6778c2ecf20Sopenharmony_ci	struct sk_buff *skb = tpa_info->skb;
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	if (unlikely(tpa_info->state != QEDE_AGG_STATE_START))
6808c2ecf20Sopenharmony_ci		goto out;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	/* Add one frag and update the appropriate fields in the skb */
6838c2ecf20Sopenharmony_ci	skb_fill_page_desc(skb, tpa_info->frag_id++,
6848c2ecf20Sopenharmony_ci			   current_bd->data,
6858c2ecf20Sopenharmony_ci			   current_bd->page_offset + rxq->rx_headroom,
6868c2ecf20Sopenharmony_ci			   len_on_bd);
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	if (unlikely(qede_realloc_rx_buffer(rxq, current_bd))) {
6898c2ecf20Sopenharmony_ci		/* Incr page ref count to reuse on allocation failure
6908c2ecf20Sopenharmony_ci		 * so that it doesn't get freed while freeing SKB.
6918c2ecf20Sopenharmony_ci		 */
6928c2ecf20Sopenharmony_ci		page_ref_inc(current_bd->data);
6938c2ecf20Sopenharmony_ci		goto out;
6948c2ecf20Sopenharmony_ci	}
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	qede_rx_bd_ring_consume(rxq);
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci	skb->data_len += len_on_bd;
6998c2ecf20Sopenharmony_ci	skb->truesize += rxq->rx_buf_seg_size;
7008c2ecf20Sopenharmony_ci	skb->len += len_on_bd;
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	return 0;
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ciout:
7058c2ecf20Sopenharmony_ci	tpa_info->state = QEDE_AGG_STATE_ERROR;
7068c2ecf20Sopenharmony_ci	qede_recycle_rx_bd_ring(rxq, 1);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	return -ENOMEM;
7098c2ecf20Sopenharmony_ci}
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_cistatic bool qede_tunn_exist(u16 flag)
7128c2ecf20Sopenharmony_ci{
7138c2ecf20Sopenharmony_ci	return !!(flag & (PARSING_AND_ERR_FLAGS_TUNNELEXIST_MASK <<
7148c2ecf20Sopenharmony_ci			  PARSING_AND_ERR_FLAGS_TUNNELEXIST_SHIFT));
7158c2ecf20Sopenharmony_ci}
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_cistatic u8 qede_check_tunn_csum(u16 flag)
7188c2ecf20Sopenharmony_ci{
7198c2ecf20Sopenharmony_ci	u16 csum_flag = 0;
7208c2ecf20Sopenharmony_ci	u8 tcsum = 0;
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	if (flag & (PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_MASK <<
7238c2ecf20Sopenharmony_ci		    PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_SHIFT))
7248c2ecf20Sopenharmony_ci		csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_MASK <<
7258c2ecf20Sopenharmony_ci			     PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_SHIFT;
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	if (flag & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
7288c2ecf20Sopenharmony_ci		    PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT)) {
7298c2ecf20Sopenharmony_ci		csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
7308c2ecf20Sopenharmony_ci			     PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
7318c2ecf20Sopenharmony_ci		tcsum = QEDE_TUNN_CSUM_UNNECESSARY;
7328c2ecf20Sopenharmony_ci	}
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_MASK <<
7358c2ecf20Sopenharmony_ci		     PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_SHIFT |
7368c2ecf20Sopenharmony_ci		     PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
7378c2ecf20Sopenharmony_ci		     PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	if (csum_flag & flag)
7408c2ecf20Sopenharmony_ci		return QEDE_CSUM_ERROR;
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci	return QEDE_CSUM_UNNECESSARY | tcsum;
7438c2ecf20Sopenharmony_ci}
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_cistatic inline struct sk_buff *
7468c2ecf20Sopenharmony_ciqede_build_skb(struct qede_rx_queue *rxq,
7478c2ecf20Sopenharmony_ci	       struct sw_rx_data *bd, u16 len, u16 pad)
7488c2ecf20Sopenharmony_ci{
7498c2ecf20Sopenharmony_ci	struct sk_buff *skb;
7508c2ecf20Sopenharmony_ci	void *buf;
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	buf = page_address(bd->data) + bd->page_offset;
7538c2ecf20Sopenharmony_ci	skb = build_skb(buf, rxq->rx_buf_seg_size);
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	if (unlikely(!skb))
7568c2ecf20Sopenharmony_ci		return NULL;
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	skb_reserve(skb, pad);
7598c2ecf20Sopenharmony_ci	skb_put(skb, len);
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci	return skb;
7628c2ecf20Sopenharmony_ci}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_cistatic struct sk_buff *
7658c2ecf20Sopenharmony_ciqede_tpa_rx_build_skb(struct qede_dev *edev,
7668c2ecf20Sopenharmony_ci		      struct qede_rx_queue *rxq,
7678c2ecf20Sopenharmony_ci		      struct sw_rx_data *bd, u16 len, u16 pad,
7688c2ecf20Sopenharmony_ci		      bool alloc_skb)
7698c2ecf20Sopenharmony_ci{
7708c2ecf20Sopenharmony_ci	struct sk_buff *skb;
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	skb = qede_build_skb(rxq, bd, len, pad);
7738c2ecf20Sopenharmony_ci	bd->page_offset += rxq->rx_buf_seg_size;
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci	if (bd->page_offset == PAGE_SIZE) {
7768c2ecf20Sopenharmony_ci		if (unlikely(qede_alloc_rx_buffer(rxq, true))) {
7778c2ecf20Sopenharmony_ci			DP_NOTICE(edev,
7788c2ecf20Sopenharmony_ci				  "Failed to allocate RX buffer for tpa start\n");
7798c2ecf20Sopenharmony_ci			bd->page_offset -= rxq->rx_buf_seg_size;
7808c2ecf20Sopenharmony_ci			page_ref_inc(bd->data);
7818c2ecf20Sopenharmony_ci			dev_kfree_skb_any(skb);
7828c2ecf20Sopenharmony_ci			return NULL;
7838c2ecf20Sopenharmony_ci		}
7848c2ecf20Sopenharmony_ci	} else {
7858c2ecf20Sopenharmony_ci		page_ref_inc(bd->data);
7868c2ecf20Sopenharmony_ci		qede_reuse_page(rxq, bd);
7878c2ecf20Sopenharmony_ci	}
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	/* We've consumed the first BD and prepared an SKB */
7908c2ecf20Sopenharmony_ci	qede_rx_bd_ring_consume(rxq);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	return skb;
7938c2ecf20Sopenharmony_ci}
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_cistatic struct sk_buff *
7968c2ecf20Sopenharmony_ciqede_rx_build_skb(struct qede_dev *edev,
7978c2ecf20Sopenharmony_ci		  struct qede_rx_queue *rxq,
7988c2ecf20Sopenharmony_ci		  struct sw_rx_data *bd, u16 len, u16 pad)
7998c2ecf20Sopenharmony_ci{
8008c2ecf20Sopenharmony_ci	struct sk_buff *skb = NULL;
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	/* For smaller frames still need to allocate skb, memcpy
8038c2ecf20Sopenharmony_ci	 * data and benefit in reusing the page segment instead of
8048c2ecf20Sopenharmony_ci	 * un-mapping it.
8058c2ecf20Sopenharmony_ci	 */
8068c2ecf20Sopenharmony_ci	if ((len + pad <= edev->rx_copybreak)) {
8078c2ecf20Sopenharmony_ci		unsigned int offset = bd->page_offset + pad;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci		skb = netdev_alloc_skb(edev->ndev, QEDE_RX_HDR_SIZE);
8108c2ecf20Sopenharmony_ci		if (unlikely(!skb))
8118c2ecf20Sopenharmony_ci			return NULL;
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci		skb_reserve(skb, pad);
8148c2ecf20Sopenharmony_ci		skb_put_data(skb, page_address(bd->data) + offset, len);
8158c2ecf20Sopenharmony_ci		qede_reuse_page(rxq, bd);
8168c2ecf20Sopenharmony_ci		goto out;
8178c2ecf20Sopenharmony_ci	}
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci	skb = qede_build_skb(rxq, bd, len, pad);
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	if (unlikely(qede_realloc_rx_buffer(rxq, bd))) {
8228c2ecf20Sopenharmony_ci		/* Incr page ref count to reuse on allocation failure so
8238c2ecf20Sopenharmony_ci		 * that it doesn't get freed while freeing SKB [as its
8248c2ecf20Sopenharmony_ci		 * already mapped there].
8258c2ecf20Sopenharmony_ci		 */
8268c2ecf20Sopenharmony_ci		page_ref_inc(bd->data);
8278c2ecf20Sopenharmony_ci		dev_kfree_skb_any(skb);
8288c2ecf20Sopenharmony_ci		return NULL;
8298c2ecf20Sopenharmony_ci	}
8308c2ecf20Sopenharmony_ciout:
8318c2ecf20Sopenharmony_ci	/* We've consumed the first BD and prepared an SKB */
8328c2ecf20Sopenharmony_ci	qede_rx_bd_ring_consume(rxq);
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	return skb;
8358c2ecf20Sopenharmony_ci}
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_cistatic void qede_tpa_start(struct qede_dev *edev,
8388c2ecf20Sopenharmony_ci			   struct qede_rx_queue *rxq,
8398c2ecf20Sopenharmony_ci			   struct eth_fast_path_rx_tpa_start_cqe *cqe)
8408c2ecf20Sopenharmony_ci{
8418c2ecf20Sopenharmony_ci	struct qede_agg_info *tpa_info = &rxq->tpa_info[cqe->tpa_agg_index];
8428c2ecf20Sopenharmony_ci	struct sw_rx_data *sw_rx_data_cons;
8438c2ecf20Sopenharmony_ci	u16 pad;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci	sw_rx_data_cons = &rxq->sw_rx_ring[rxq->sw_rx_cons & NUM_RX_BDS_MAX];
8468c2ecf20Sopenharmony_ci	pad = cqe->placement_offset + rxq->rx_headroom;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci	tpa_info->skb = qede_tpa_rx_build_skb(edev, rxq, sw_rx_data_cons,
8498c2ecf20Sopenharmony_ci					      le16_to_cpu(cqe->len_on_first_bd),
8508c2ecf20Sopenharmony_ci					      pad, false);
8518c2ecf20Sopenharmony_ci	tpa_info->buffer.page_offset = sw_rx_data_cons->page_offset;
8528c2ecf20Sopenharmony_ci	tpa_info->buffer.mapping = sw_rx_data_cons->mapping;
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci	if (unlikely(!tpa_info->skb)) {
8558c2ecf20Sopenharmony_ci		DP_NOTICE(edev, "Failed to allocate SKB for gro\n");
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci		/* Consume from ring but do not produce since
8588c2ecf20Sopenharmony_ci		 * this might be used by FW still, it will be re-used
8598c2ecf20Sopenharmony_ci		 * at TPA end.
8608c2ecf20Sopenharmony_ci		 */
8618c2ecf20Sopenharmony_ci		tpa_info->tpa_start_fail = true;
8628c2ecf20Sopenharmony_ci		qede_rx_bd_ring_consume(rxq);
8638c2ecf20Sopenharmony_ci		tpa_info->state = QEDE_AGG_STATE_ERROR;
8648c2ecf20Sopenharmony_ci		goto cons_buf;
8658c2ecf20Sopenharmony_ci	}
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci	tpa_info->frag_id = 0;
8688c2ecf20Sopenharmony_ci	tpa_info->state = QEDE_AGG_STATE_START;
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci	if ((le16_to_cpu(cqe->pars_flags.flags) >>
8718c2ecf20Sopenharmony_ci	     PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT) &
8728c2ecf20Sopenharmony_ci	    PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK)
8738c2ecf20Sopenharmony_ci		tpa_info->vlan_tag = le16_to_cpu(cqe->vlan_tag);
8748c2ecf20Sopenharmony_ci	else
8758c2ecf20Sopenharmony_ci		tpa_info->vlan_tag = 0;
8768c2ecf20Sopenharmony_ci
8778c2ecf20Sopenharmony_ci	qede_get_rxhash(tpa_info->skb, cqe->bitfields, cqe->rss_hash);
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci	/* This is needed in order to enable forwarding support */
8808c2ecf20Sopenharmony_ci	qede_set_gro_params(edev, tpa_info->skb, cqe);
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_cicons_buf: /* We still need to handle bd_len_list to consume buffers */
8838c2ecf20Sopenharmony_ci	if (likely(cqe->bw_ext_bd_len_list[0]))
8848c2ecf20Sopenharmony_ci		qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
8858c2ecf20Sopenharmony_ci				   le16_to_cpu(cqe->bw_ext_bd_len_list[0]));
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_ci	if (unlikely(cqe->bw_ext_bd_len_list[1])) {
8888c2ecf20Sopenharmony_ci		DP_ERR(edev,
8898c2ecf20Sopenharmony_ci		       "Unlikely - got a TPA aggregation with more than one bw_ext_bd_len_list entry in the TPA start\n");
8908c2ecf20Sopenharmony_ci		tpa_info->state = QEDE_AGG_STATE_ERROR;
8918c2ecf20Sopenharmony_ci	}
8928c2ecf20Sopenharmony_ci}
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci#ifdef CONFIG_INET
8958c2ecf20Sopenharmony_cistatic void qede_gro_ip_csum(struct sk_buff *skb)
8968c2ecf20Sopenharmony_ci{
8978c2ecf20Sopenharmony_ci	const struct iphdr *iph = ip_hdr(skb);
8988c2ecf20Sopenharmony_ci	struct tcphdr *th;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	skb_set_transport_header(skb, sizeof(struct iphdr));
9018c2ecf20Sopenharmony_ci	th = tcp_hdr(skb);
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	th->check = ~tcp_v4_check(skb->len - skb_transport_offset(skb),
9048c2ecf20Sopenharmony_ci				  iph->saddr, iph->daddr, 0);
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci	tcp_gro_complete(skb);
9078c2ecf20Sopenharmony_ci}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_cistatic void qede_gro_ipv6_csum(struct sk_buff *skb)
9108c2ecf20Sopenharmony_ci{
9118c2ecf20Sopenharmony_ci	struct ipv6hdr *iph = ipv6_hdr(skb);
9128c2ecf20Sopenharmony_ci	struct tcphdr *th;
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_ci	skb_set_transport_header(skb, sizeof(struct ipv6hdr));
9158c2ecf20Sopenharmony_ci	th = tcp_hdr(skb);
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_ci	th->check = ~tcp_v6_check(skb->len - skb_transport_offset(skb),
9188c2ecf20Sopenharmony_ci				  &iph->saddr, &iph->daddr, 0);
9198c2ecf20Sopenharmony_ci	tcp_gro_complete(skb);
9208c2ecf20Sopenharmony_ci}
9218c2ecf20Sopenharmony_ci#endif
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_cistatic void qede_gro_receive(struct qede_dev *edev,
9248c2ecf20Sopenharmony_ci			     struct qede_fastpath *fp,
9258c2ecf20Sopenharmony_ci			     struct sk_buff *skb,
9268c2ecf20Sopenharmony_ci			     u16 vlan_tag)
9278c2ecf20Sopenharmony_ci{
9288c2ecf20Sopenharmony_ci	/* FW can send a single MTU sized packet from gro flow
9298c2ecf20Sopenharmony_ci	 * due to aggregation timeout/last segment etc. which
9308c2ecf20Sopenharmony_ci	 * is not expected to be a gro packet. If a skb has zero
9318c2ecf20Sopenharmony_ci	 * frags then simply push it in the stack as non gso skb.
9328c2ecf20Sopenharmony_ci	 */
9338c2ecf20Sopenharmony_ci	if (unlikely(!skb->data_len)) {
9348c2ecf20Sopenharmony_ci		skb_shinfo(skb)->gso_type = 0;
9358c2ecf20Sopenharmony_ci		skb_shinfo(skb)->gso_size = 0;
9368c2ecf20Sopenharmony_ci		goto send_skb;
9378c2ecf20Sopenharmony_ci	}
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci#ifdef CONFIG_INET
9408c2ecf20Sopenharmony_ci	if (skb_shinfo(skb)->gso_size) {
9418c2ecf20Sopenharmony_ci		skb_reset_network_header(skb);
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci		switch (skb->protocol) {
9448c2ecf20Sopenharmony_ci		case htons(ETH_P_IP):
9458c2ecf20Sopenharmony_ci			qede_gro_ip_csum(skb);
9468c2ecf20Sopenharmony_ci			break;
9478c2ecf20Sopenharmony_ci		case htons(ETH_P_IPV6):
9488c2ecf20Sopenharmony_ci			qede_gro_ipv6_csum(skb);
9498c2ecf20Sopenharmony_ci			break;
9508c2ecf20Sopenharmony_ci		default:
9518c2ecf20Sopenharmony_ci			DP_ERR(edev,
9528c2ecf20Sopenharmony_ci			       "Error: FW GRO supports only IPv4/IPv6, not 0x%04x\n",
9538c2ecf20Sopenharmony_ci			       ntohs(skb->protocol));
9548c2ecf20Sopenharmony_ci		}
9558c2ecf20Sopenharmony_ci	}
9568c2ecf20Sopenharmony_ci#endif
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_cisend_skb:
9598c2ecf20Sopenharmony_ci	skb_record_rx_queue(skb, fp->rxq->rxq_id);
9608c2ecf20Sopenharmony_ci	qede_skb_receive(edev, fp, fp->rxq, skb, vlan_tag);
9618c2ecf20Sopenharmony_ci}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_cistatic inline void qede_tpa_cont(struct qede_dev *edev,
9648c2ecf20Sopenharmony_ci				 struct qede_rx_queue *rxq,
9658c2ecf20Sopenharmony_ci				 struct eth_fast_path_rx_tpa_cont_cqe *cqe)
9668c2ecf20Sopenharmony_ci{
9678c2ecf20Sopenharmony_ci	int i;
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	for (i = 0; cqe->len_list[i]; i++)
9708c2ecf20Sopenharmony_ci		qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
9718c2ecf20Sopenharmony_ci				   le16_to_cpu(cqe->len_list[i]));
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci	if (unlikely(i > 1))
9748c2ecf20Sopenharmony_ci		DP_ERR(edev,
9758c2ecf20Sopenharmony_ci		       "Strange - TPA cont with more than a single len_list entry\n");
9768c2ecf20Sopenharmony_ci}
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_cistatic int qede_tpa_end(struct qede_dev *edev,
9798c2ecf20Sopenharmony_ci			struct qede_fastpath *fp,
9808c2ecf20Sopenharmony_ci			struct eth_fast_path_rx_tpa_end_cqe *cqe)
9818c2ecf20Sopenharmony_ci{
9828c2ecf20Sopenharmony_ci	struct qede_rx_queue *rxq = fp->rxq;
9838c2ecf20Sopenharmony_ci	struct qede_agg_info *tpa_info;
9848c2ecf20Sopenharmony_ci	struct sk_buff *skb;
9858c2ecf20Sopenharmony_ci	int i;
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	tpa_info = &rxq->tpa_info[cqe->tpa_agg_index];
9888c2ecf20Sopenharmony_ci	skb = tpa_info->skb;
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ci	if (tpa_info->buffer.page_offset == PAGE_SIZE)
9918c2ecf20Sopenharmony_ci		dma_unmap_page(rxq->dev, tpa_info->buffer.mapping,
9928c2ecf20Sopenharmony_ci			       PAGE_SIZE, rxq->data_direction);
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci	for (i = 0; cqe->len_list[i]; i++)
9958c2ecf20Sopenharmony_ci		qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
9968c2ecf20Sopenharmony_ci				   le16_to_cpu(cqe->len_list[i]));
9978c2ecf20Sopenharmony_ci	if (unlikely(i > 1))
9988c2ecf20Sopenharmony_ci		DP_ERR(edev,
9998c2ecf20Sopenharmony_ci		       "Strange - TPA emd with more than a single len_list entry\n");
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci	if (unlikely(tpa_info->state != QEDE_AGG_STATE_START))
10028c2ecf20Sopenharmony_ci		goto err;
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ci	/* Sanity */
10058c2ecf20Sopenharmony_ci	if (unlikely(cqe->num_of_bds != tpa_info->frag_id + 1))
10068c2ecf20Sopenharmony_ci		DP_ERR(edev,
10078c2ecf20Sopenharmony_ci		       "Strange - TPA had %02x BDs, but SKB has only %d frags\n",
10088c2ecf20Sopenharmony_ci		       cqe->num_of_bds, tpa_info->frag_id);
10098c2ecf20Sopenharmony_ci	if (unlikely(skb->len != le16_to_cpu(cqe->total_packet_len)))
10108c2ecf20Sopenharmony_ci		DP_ERR(edev,
10118c2ecf20Sopenharmony_ci		       "Strange - total packet len [cqe] is %4x but SKB has len %04x\n",
10128c2ecf20Sopenharmony_ci		       le16_to_cpu(cqe->total_packet_len), skb->len);
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_ci	/* Finalize the SKB */
10158c2ecf20Sopenharmony_ci	skb->protocol = eth_type_trans(skb, edev->ndev);
10168c2ecf20Sopenharmony_ci	skb->ip_summed = CHECKSUM_UNNECESSARY;
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	/* tcp_gro_complete() will copy NAPI_GRO_CB(skb)->count
10198c2ecf20Sopenharmony_ci	 * to skb_shinfo(skb)->gso_segs
10208c2ecf20Sopenharmony_ci	 */
10218c2ecf20Sopenharmony_ci	NAPI_GRO_CB(skb)->count = le16_to_cpu(cqe->num_of_coalesced_segs);
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci	qede_gro_receive(edev, fp, skb, tpa_info->vlan_tag);
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_ci	tpa_info->state = QEDE_AGG_STATE_NONE;
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	return 1;
10288c2ecf20Sopenharmony_cierr:
10298c2ecf20Sopenharmony_ci	tpa_info->state = QEDE_AGG_STATE_NONE;
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci	if (tpa_info->tpa_start_fail) {
10328c2ecf20Sopenharmony_ci		qede_reuse_page(rxq, &tpa_info->buffer);
10338c2ecf20Sopenharmony_ci		tpa_info->tpa_start_fail = false;
10348c2ecf20Sopenharmony_ci	}
10358c2ecf20Sopenharmony_ci
10368c2ecf20Sopenharmony_ci	dev_kfree_skb_any(tpa_info->skb);
10378c2ecf20Sopenharmony_ci	tpa_info->skb = NULL;
10388c2ecf20Sopenharmony_ci	return 0;
10398c2ecf20Sopenharmony_ci}
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_cistatic u8 qede_check_notunn_csum(u16 flag)
10428c2ecf20Sopenharmony_ci{
10438c2ecf20Sopenharmony_ci	u16 csum_flag = 0;
10448c2ecf20Sopenharmony_ci	u8 csum = 0;
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	if (flag & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
10478c2ecf20Sopenharmony_ci		    PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT)) {
10488c2ecf20Sopenharmony_ci		csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
10498c2ecf20Sopenharmony_ci			     PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
10508c2ecf20Sopenharmony_ci		csum = QEDE_CSUM_UNNECESSARY;
10518c2ecf20Sopenharmony_ci	}
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci	csum_flag |= PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
10548c2ecf20Sopenharmony_ci		     PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
10558c2ecf20Sopenharmony_ci
10568c2ecf20Sopenharmony_ci	if (csum_flag & flag)
10578c2ecf20Sopenharmony_ci		return QEDE_CSUM_ERROR;
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	return csum;
10608c2ecf20Sopenharmony_ci}
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_cistatic u8 qede_check_csum(u16 flag)
10638c2ecf20Sopenharmony_ci{
10648c2ecf20Sopenharmony_ci	if (!qede_tunn_exist(flag))
10658c2ecf20Sopenharmony_ci		return qede_check_notunn_csum(flag);
10668c2ecf20Sopenharmony_ci	else
10678c2ecf20Sopenharmony_ci		return qede_check_tunn_csum(flag);
10688c2ecf20Sopenharmony_ci}
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_cistatic bool qede_pkt_is_ip_fragmented(struct eth_fast_path_rx_reg_cqe *cqe,
10718c2ecf20Sopenharmony_ci				      u16 flag)
10728c2ecf20Sopenharmony_ci{
10738c2ecf20Sopenharmony_ci	u8 tun_pars_flg = cqe->tunnel_pars_flags.flags;
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_ci	if ((tun_pars_flg & (ETH_TUNNEL_PARSING_FLAGS_IPV4_FRAGMENT_MASK <<
10768c2ecf20Sopenharmony_ci			     ETH_TUNNEL_PARSING_FLAGS_IPV4_FRAGMENT_SHIFT)) ||
10778c2ecf20Sopenharmony_ci	    (flag & (PARSING_AND_ERR_FLAGS_IPV4FRAG_MASK <<
10788c2ecf20Sopenharmony_ci		     PARSING_AND_ERR_FLAGS_IPV4FRAG_SHIFT)))
10798c2ecf20Sopenharmony_ci		return true;
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	return false;
10828c2ecf20Sopenharmony_ci}
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci/* Return true iff packet is to be passed to stack */
10858c2ecf20Sopenharmony_cistatic bool qede_rx_xdp(struct qede_dev *edev,
10868c2ecf20Sopenharmony_ci			struct qede_fastpath *fp,
10878c2ecf20Sopenharmony_ci			struct qede_rx_queue *rxq,
10888c2ecf20Sopenharmony_ci			struct bpf_prog *prog,
10898c2ecf20Sopenharmony_ci			struct sw_rx_data *bd,
10908c2ecf20Sopenharmony_ci			struct eth_fast_path_rx_reg_cqe *cqe,
10918c2ecf20Sopenharmony_ci			u16 *data_offset, u16 *len)
10928c2ecf20Sopenharmony_ci{
10938c2ecf20Sopenharmony_ci	struct xdp_buff xdp;
10948c2ecf20Sopenharmony_ci	enum xdp_action act;
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	xdp.data_hard_start = page_address(bd->data);
10978c2ecf20Sopenharmony_ci	xdp.data = xdp.data_hard_start + *data_offset;
10988c2ecf20Sopenharmony_ci	xdp_set_data_meta_invalid(&xdp);
10998c2ecf20Sopenharmony_ci	xdp.data_end = xdp.data + *len;
11008c2ecf20Sopenharmony_ci	xdp.rxq = &rxq->xdp_rxq;
11018c2ecf20Sopenharmony_ci	xdp.frame_sz = rxq->rx_buf_seg_size; /* PAGE_SIZE when XDP enabled */
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	/* Queues always have a full reset currently, so for the time
11048c2ecf20Sopenharmony_ci	 * being until there's atomic program replace just mark read
11058c2ecf20Sopenharmony_ci	 * side for map helpers.
11068c2ecf20Sopenharmony_ci	 */
11078c2ecf20Sopenharmony_ci	rcu_read_lock();
11088c2ecf20Sopenharmony_ci	act = bpf_prog_run_xdp(prog, &xdp);
11098c2ecf20Sopenharmony_ci	rcu_read_unlock();
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_ci	/* Recalculate, as XDP might have changed the headers */
11128c2ecf20Sopenharmony_ci	*data_offset = xdp.data - xdp.data_hard_start;
11138c2ecf20Sopenharmony_ci	*len = xdp.data_end - xdp.data;
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	if (act == XDP_PASS)
11168c2ecf20Sopenharmony_ci		return true;
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_ci	/* Count number of packets not to be passed to stack */
11198c2ecf20Sopenharmony_ci	rxq->xdp_no_pass++;
11208c2ecf20Sopenharmony_ci
11218c2ecf20Sopenharmony_ci	switch (act) {
11228c2ecf20Sopenharmony_ci	case XDP_TX:
11238c2ecf20Sopenharmony_ci		/* We need the replacement buffer before transmit. */
11248c2ecf20Sopenharmony_ci		if (unlikely(qede_alloc_rx_buffer(rxq, true))) {
11258c2ecf20Sopenharmony_ci			qede_recycle_rx_bd_ring(rxq, 1);
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci			trace_xdp_exception(edev->ndev, prog, act);
11288c2ecf20Sopenharmony_ci			break;
11298c2ecf20Sopenharmony_ci		}
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ci		/* Now if there's a transmission problem, we'd still have to
11328c2ecf20Sopenharmony_ci		 * throw current buffer, as replacement was already allocated.
11338c2ecf20Sopenharmony_ci		 */
11348c2ecf20Sopenharmony_ci		if (unlikely(qede_xdp_xmit(fp->xdp_tx, bd->mapping,
11358c2ecf20Sopenharmony_ci					   *data_offset, *len, bd->data,
11368c2ecf20Sopenharmony_ci					   NULL))) {
11378c2ecf20Sopenharmony_ci			dma_unmap_page(rxq->dev, bd->mapping, PAGE_SIZE,
11388c2ecf20Sopenharmony_ci				       rxq->data_direction);
11398c2ecf20Sopenharmony_ci			__free_page(bd->data);
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci			trace_xdp_exception(edev->ndev, prog, act);
11428c2ecf20Sopenharmony_ci		} else {
11438c2ecf20Sopenharmony_ci			dma_sync_single_for_device(rxq->dev,
11448c2ecf20Sopenharmony_ci						   bd->mapping + *data_offset,
11458c2ecf20Sopenharmony_ci						   *len, rxq->data_direction);
11468c2ecf20Sopenharmony_ci			fp->xdp_xmit |= QEDE_XDP_TX;
11478c2ecf20Sopenharmony_ci		}
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci		/* Regardless, we've consumed an Rx BD */
11508c2ecf20Sopenharmony_ci		qede_rx_bd_ring_consume(rxq);
11518c2ecf20Sopenharmony_ci		break;
11528c2ecf20Sopenharmony_ci	case XDP_REDIRECT:
11538c2ecf20Sopenharmony_ci		/* We need the replacement buffer before transmit. */
11548c2ecf20Sopenharmony_ci		if (unlikely(qede_alloc_rx_buffer(rxq, true))) {
11558c2ecf20Sopenharmony_ci			qede_recycle_rx_bd_ring(rxq, 1);
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci			trace_xdp_exception(edev->ndev, prog, act);
11588c2ecf20Sopenharmony_ci			break;
11598c2ecf20Sopenharmony_ci		}
11608c2ecf20Sopenharmony_ci
11618c2ecf20Sopenharmony_ci		dma_unmap_page(rxq->dev, bd->mapping, PAGE_SIZE,
11628c2ecf20Sopenharmony_ci			       rxq->data_direction);
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_ci		if (unlikely(xdp_do_redirect(edev->ndev, &xdp, prog)))
11658c2ecf20Sopenharmony_ci			DP_NOTICE(edev, "Failed to redirect the packet\n");
11668c2ecf20Sopenharmony_ci		else
11678c2ecf20Sopenharmony_ci			fp->xdp_xmit |= QEDE_XDP_REDIRECT;
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci		qede_rx_bd_ring_consume(rxq);
11708c2ecf20Sopenharmony_ci		break;
11718c2ecf20Sopenharmony_ci	default:
11728c2ecf20Sopenharmony_ci		bpf_warn_invalid_xdp_action(act);
11738c2ecf20Sopenharmony_ci		fallthrough;
11748c2ecf20Sopenharmony_ci	case XDP_ABORTED:
11758c2ecf20Sopenharmony_ci		trace_xdp_exception(edev->ndev, prog, act);
11768c2ecf20Sopenharmony_ci		fallthrough;
11778c2ecf20Sopenharmony_ci	case XDP_DROP:
11788c2ecf20Sopenharmony_ci		qede_recycle_rx_bd_ring(rxq, cqe->bd_num);
11798c2ecf20Sopenharmony_ci	}
11808c2ecf20Sopenharmony_ci
11818c2ecf20Sopenharmony_ci	return false;
11828c2ecf20Sopenharmony_ci}
11838c2ecf20Sopenharmony_ci
11848c2ecf20Sopenharmony_cistatic int qede_rx_build_jumbo(struct qede_dev *edev,
11858c2ecf20Sopenharmony_ci			       struct qede_rx_queue *rxq,
11868c2ecf20Sopenharmony_ci			       struct sk_buff *skb,
11878c2ecf20Sopenharmony_ci			       struct eth_fast_path_rx_reg_cqe *cqe,
11888c2ecf20Sopenharmony_ci			       u16 first_bd_len)
11898c2ecf20Sopenharmony_ci{
11908c2ecf20Sopenharmony_ci	u16 pkt_len = le16_to_cpu(cqe->pkt_len);
11918c2ecf20Sopenharmony_ci	struct sw_rx_data *bd;
11928c2ecf20Sopenharmony_ci	u16 bd_cons_idx;
11938c2ecf20Sopenharmony_ci	u8 num_frags;
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_ci	pkt_len -= first_bd_len;
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci	/* We've already used one BD for the SKB. Now take care of the rest */
11988c2ecf20Sopenharmony_ci	for (num_frags = cqe->bd_num - 1; num_frags > 0; num_frags--) {
11998c2ecf20Sopenharmony_ci		u16 cur_size = pkt_len > rxq->rx_buf_size ? rxq->rx_buf_size :
12008c2ecf20Sopenharmony_ci		    pkt_len;
12018c2ecf20Sopenharmony_ci
12028c2ecf20Sopenharmony_ci		if (unlikely(!cur_size)) {
12038c2ecf20Sopenharmony_ci			DP_ERR(edev,
12048c2ecf20Sopenharmony_ci			       "Still got %d BDs for mapping jumbo, but length became 0\n",
12058c2ecf20Sopenharmony_ci			       num_frags);
12068c2ecf20Sopenharmony_ci			goto out;
12078c2ecf20Sopenharmony_ci		}
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_ci		/* We need a replacement buffer for each BD */
12108c2ecf20Sopenharmony_ci		if (unlikely(qede_alloc_rx_buffer(rxq, true)))
12118c2ecf20Sopenharmony_ci			goto out;
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci		/* Now that we've allocated the replacement buffer,
12148c2ecf20Sopenharmony_ci		 * we can safely consume the next BD and map it to the SKB.
12158c2ecf20Sopenharmony_ci		 */
12168c2ecf20Sopenharmony_ci		bd_cons_idx = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
12178c2ecf20Sopenharmony_ci		bd = &rxq->sw_rx_ring[bd_cons_idx];
12188c2ecf20Sopenharmony_ci		qede_rx_bd_ring_consume(rxq);
12198c2ecf20Sopenharmony_ci
12208c2ecf20Sopenharmony_ci		dma_unmap_page(rxq->dev, bd->mapping,
12218c2ecf20Sopenharmony_ci			       PAGE_SIZE, DMA_FROM_DEVICE);
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_ci		skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
12248c2ecf20Sopenharmony_ci				   bd->data, rxq->rx_headroom, cur_size);
12258c2ecf20Sopenharmony_ci
12268c2ecf20Sopenharmony_ci		skb->truesize += PAGE_SIZE;
12278c2ecf20Sopenharmony_ci		skb->data_len += cur_size;
12288c2ecf20Sopenharmony_ci		skb->len += cur_size;
12298c2ecf20Sopenharmony_ci		pkt_len -= cur_size;
12308c2ecf20Sopenharmony_ci	}
12318c2ecf20Sopenharmony_ci
12328c2ecf20Sopenharmony_ci	if (unlikely(pkt_len))
12338c2ecf20Sopenharmony_ci		DP_ERR(edev,
12348c2ecf20Sopenharmony_ci		       "Mapped all BDs of jumbo, but still have %d bytes\n",
12358c2ecf20Sopenharmony_ci		       pkt_len);
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ciout:
12388c2ecf20Sopenharmony_ci	return num_frags;
12398c2ecf20Sopenharmony_ci}
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_cistatic int qede_rx_process_tpa_cqe(struct qede_dev *edev,
12428c2ecf20Sopenharmony_ci				   struct qede_fastpath *fp,
12438c2ecf20Sopenharmony_ci				   struct qede_rx_queue *rxq,
12448c2ecf20Sopenharmony_ci				   union eth_rx_cqe *cqe,
12458c2ecf20Sopenharmony_ci				   enum eth_rx_cqe_type type)
12468c2ecf20Sopenharmony_ci{
12478c2ecf20Sopenharmony_ci	switch (type) {
12488c2ecf20Sopenharmony_ci	case ETH_RX_CQE_TYPE_TPA_START:
12498c2ecf20Sopenharmony_ci		qede_tpa_start(edev, rxq, &cqe->fast_path_tpa_start);
12508c2ecf20Sopenharmony_ci		return 0;
12518c2ecf20Sopenharmony_ci	case ETH_RX_CQE_TYPE_TPA_CONT:
12528c2ecf20Sopenharmony_ci		qede_tpa_cont(edev, rxq, &cqe->fast_path_tpa_cont);
12538c2ecf20Sopenharmony_ci		return 0;
12548c2ecf20Sopenharmony_ci	case ETH_RX_CQE_TYPE_TPA_END:
12558c2ecf20Sopenharmony_ci		return qede_tpa_end(edev, fp, &cqe->fast_path_tpa_end);
12568c2ecf20Sopenharmony_ci	default:
12578c2ecf20Sopenharmony_ci		return 0;
12588c2ecf20Sopenharmony_ci	}
12598c2ecf20Sopenharmony_ci}
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_cistatic int qede_rx_process_cqe(struct qede_dev *edev,
12628c2ecf20Sopenharmony_ci			       struct qede_fastpath *fp,
12638c2ecf20Sopenharmony_ci			       struct qede_rx_queue *rxq)
12648c2ecf20Sopenharmony_ci{
12658c2ecf20Sopenharmony_ci	struct bpf_prog *xdp_prog = READ_ONCE(rxq->xdp_prog);
12668c2ecf20Sopenharmony_ci	struct eth_fast_path_rx_reg_cqe *fp_cqe;
12678c2ecf20Sopenharmony_ci	u16 len, pad, bd_cons_idx, parse_flag;
12688c2ecf20Sopenharmony_ci	enum eth_rx_cqe_type cqe_type;
12698c2ecf20Sopenharmony_ci	union eth_rx_cqe *cqe;
12708c2ecf20Sopenharmony_ci	struct sw_rx_data *bd;
12718c2ecf20Sopenharmony_ci	struct sk_buff *skb;
12728c2ecf20Sopenharmony_ci	__le16 flags;
12738c2ecf20Sopenharmony_ci	u8 csum_flag;
12748c2ecf20Sopenharmony_ci
12758c2ecf20Sopenharmony_ci	/* Get the CQE from the completion ring */
12768c2ecf20Sopenharmony_ci	cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
12778c2ecf20Sopenharmony_ci	cqe_type = cqe->fast_path_regular.type;
12788c2ecf20Sopenharmony_ci
12798c2ecf20Sopenharmony_ci	/* Process an unlikely slowpath event */
12808c2ecf20Sopenharmony_ci	if (unlikely(cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH)) {
12818c2ecf20Sopenharmony_ci		struct eth_slow_path_rx_cqe *sp_cqe;
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci		sp_cqe = (struct eth_slow_path_rx_cqe *)cqe;
12848c2ecf20Sopenharmony_ci		edev->ops->eth_cqe_completion(edev->cdev, fp->id, sp_cqe);
12858c2ecf20Sopenharmony_ci		return 0;
12868c2ecf20Sopenharmony_ci	}
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_ci	/* Handle TPA cqes */
12898c2ecf20Sopenharmony_ci	if (cqe_type != ETH_RX_CQE_TYPE_REGULAR)
12908c2ecf20Sopenharmony_ci		return qede_rx_process_tpa_cqe(edev, fp, rxq, cqe, cqe_type);
12918c2ecf20Sopenharmony_ci
12928c2ecf20Sopenharmony_ci	/* Get the data from the SW ring; Consume it only after it's evident
12938c2ecf20Sopenharmony_ci	 * we wouldn't recycle it.
12948c2ecf20Sopenharmony_ci	 */
12958c2ecf20Sopenharmony_ci	bd_cons_idx = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
12968c2ecf20Sopenharmony_ci	bd = &rxq->sw_rx_ring[bd_cons_idx];
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci	fp_cqe = &cqe->fast_path_regular;
12998c2ecf20Sopenharmony_ci	len = le16_to_cpu(fp_cqe->len_on_first_bd);
13008c2ecf20Sopenharmony_ci	pad = fp_cqe->placement_offset + rxq->rx_headroom;
13018c2ecf20Sopenharmony_ci
13028c2ecf20Sopenharmony_ci	/* Run eBPF program if one is attached */
13038c2ecf20Sopenharmony_ci	if (xdp_prog)
13048c2ecf20Sopenharmony_ci		if (!qede_rx_xdp(edev, fp, rxq, xdp_prog, bd, fp_cqe,
13058c2ecf20Sopenharmony_ci				 &pad, &len))
13068c2ecf20Sopenharmony_ci			return 0;
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci	/* If this is an error packet then drop it */
13098c2ecf20Sopenharmony_ci	flags = cqe->fast_path_regular.pars_flags.flags;
13108c2ecf20Sopenharmony_ci	parse_flag = le16_to_cpu(flags);
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	csum_flag = qede_check_csum(parse_flag);
13138c2ecf20Sopenharmony_ci	if (unlikely(csum_flag == QEDE_CSUM_ERROR)) {
13148c2ecf20Sopenharmony_ci		if (qede_pkt_is_ip_fragmented(fp_cqe, parse_flag))
13158c2ecf20Sopenharmony_ci			rxq->rx_ip_frags++;
13168c2ecf20Sopenharmony_ci		else
13178c2ecf20Sopenharmony_ci			rxq->rx_hw_errors++;
13188c2ecf20Sopenharmony_ci	}
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci	/* Basic validation passed; Need to prepare an SKB. This would also
13218c2ecf20Sopenharmony_ci	 * guarantee to finally consume the first BD upon success.
13228c2ecf20Sopenharmony_ci	 */
13238c2ecf20Sopenharmony_ci	skb = qede_rx_build_skb(edev, rxq, bd, len, pad);
13248c2ecf20Sopenharmony_ci	if (!skb) {
13258c2ecf20Sopenharmony_ci		rxq->rx_alloc_errors++;
13268c2ecf20Sopenharmony_ci		qede_recycle_rx_bd_ring(rxq, fp_cqe->bd_num);
13278c2ecf20Sopenharmony_ci		return 0;
13288c2ecf20Sopenharmony_ci	}
13298c2ecf20Sopenharmony_ci
13308c2ecf20Sopenharmony_ci	/* In case of Jumbo packet, several PAGE_SIZEd buffers will be pointed
13318c2ecf20Sopenharmony_ci	 * by a single cqe.
13328c2ecf20Sopenharmony_ci	 */
13338c2ecf20Sopenharmony_ci	if (fp_cqe->bd_num > 1) {
13348c2ecf20Sopenharmony_ci		u16 unmapped_frags = qede_rx_build_jumbo(edev, rxq, skb,
13358c2ecf20Sopenharmony_ci							 fp_cqe, len);
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci		if (unlikely(unmapped_frags > 0)) {
13388c2ecf20Sopenharmony_ci			qede_recycle_rx_bd_ring(rxq, unmapped_frags);
13398c2ecf20Sopenharmony_ci			dev_kfree_skb_any(skb);
13408c2ecf20Sopenharmony_ci			return 0;
13418c2ecf20Sopenharmony_ci		}
13428c2ecf20Sopenharmony_ci	}
13438c2ecf20Sopenharmony_ci
13448c2ecf20Sopenharmony_ci	/* The SKB contains all the data. Now prepare meta-magic */
13458c2ecf20Sopenharmony_ci	skb->protocol = eth_type_trans(skb, edev->ndev);
13468c2ecf20Sopenharmony_ci	qede_get_rxhash(skb, fp_cqe->bitfields, fp_cqe->rss_hash);
13478c2ecf20Sopenharmony_ci	qede_set_skb_csum(skb, csum_flag);
13488c2ecf20Sopenharmony_ci	skb_record_rx_queue(skb, rxq->rxq_id);
13498c2ecf20Sopenharmony_ci	qede_ptp_record_rx_ts(edev, cqe, skb);
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci	/* SKB is prepared - pass it to stack */
13528c2ecf20Sopenharmony_ci	qede_skb_receive(edev, fp, rxq, skb, le16_to_cpu(fp_cqe->vlan_tag));
13538c2ecf20Sopenharmony_ci
13548c2ecf20Sopenharmony_ci	return 1;
13558c2ecf20Sopenharmony_ci}
13568c2ecf20Sopenharmony_ci
13578c2ecf20Sopenharmony_cistatic int qede_rx_int(struct qede_fastpath *fp, int budget)
13588c2ecf20Sopenharmony_ci{
13598c2ecf20Sopenharmony_ci	struct qede_rx_queue *rxq = fp->rxq;
13608c2ecf20Sopenharmony_ci	struct qede_dev *edev = fp->edev;
13618c2ecf20Sopenharmony_ci	int work_done = 0, rcv_pkts = 0;
13628c2ecf20Sopenharmony_ci	u16 hw_comp_cons, sw_comp_cons;
13638c2ecf20Sopenharmony_ci
13648c2ecf20Sopenharmony_ci	hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
13658c2ecf20Sopenharmony_ci	sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
13668c2ecf20Sopenharmony_ci
13678c2ecf20Sopenharmony_ci	/* Memory barrier to prevent the CPU from doing speculative reads of CQE
13688c2ecf20Sopenharmony_ci	 * / BD in the while-loop before reading hw_comp_cons. If the CQE is
13698c2ecf20Sopenharmony_ci	 * read before it is written by FW, then FW writes CQE and SB, and then
13708c2ecf20Sopenharmony_ci	 * the CPU reads the hw_comp_cons, it will use an old CQE.
13718c2ecf20Sopenharmony_ci	 */
13728c2ecf20Sopenharmony_ci	rmb();
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci	/* Loop to complete all indicated BDs */
13758c2ecf20Sopenharmony_ci	while ((sw_comp_cons != hw_comp_cons) && (work_done < budget)) {
13768c2ecf20Sopenharmony_ci		rcv_pkts += qede_rx_process_cqe(edev, fp, rxq);
13778c2ecf20Sopenharmony_ci		qed_chain_recycle_consumed(&rxq->rx_comp_ring);
13788c2ecf20Sopenharmony_ci		sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
13798c2ecf20Sopenharmony_ci		work_done++;
13808c2ecf20Sopenharmony_ci	}
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci	rxq->rcv_pkts += rcv_pkts;
13838c2ecf20Sopenharmony_ci
13848c2ecf20Sopenharmony_ci	/* Allocate replacement buffers */
13858c2ecf20Sopenharmony_ci	while (rxq->num_rx_buffers - rxq->filled_buffers)
13868c2ecf20Sopenharmony_ci		if (qede_alloc_rx_buffer(rxq, false))
13878c2ecf20Sopenharmony_ci			break;
13888c2ecf20Sopenharmony_ci
13898c2ecf20Sopenharmony_ci	/* Update producers */
13908c2ecf20Sopenharmony_ci	qede_update_rx_prod(edev, rxq);
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_ci	return work_done;
13938c2ecf20Sopenharmony_ci}
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_cistatic bool qede_poll_is_more_work(struct qede_fastpath *fp)
13968c2ecf20Sopenharmony_ci{
13978c2ecf20Sopenharmony_ci	qed_sb_update_sb_idx(fp->sb_info);
13988c2ecf20Sopenharmony_ci
13998c2ecf20Sopenharmony_ci	/* *_has_*_work() reads the status block, thus we need to ensure that
14008c2ecf20Sopenharmony_ci	 * status block indices have been actually read (qed_sb_update_sb_idx)
14018c2ecf20Sopenharmony_ci	 * prior to this check (*_has_*_work) so that we won't write the
14028c2ecf20Sopenharmony_ci	 * "newer" value of the status block to HW (if there was a DMA right
14038c2ecf20Sopenharmony_ci	 * after qede_has_rx_work and if there is no rmb, the memory reading
14048c2ecf20Sopenharmony_ci	 * (qed_sb_update_sb_idx) may be postponed to right before *_ack_sb).
14058c2ecf20Sopenharmony_ci	 * In this case there will never be another interrupt until there is
14068c2ecf20Sopenharmony_ci	 * another update of the status block, while there is still unhandled
14078c2ecf20Sopenharmony_ci	 * work.
14088c2ecf20Sopenharmony_ci	 */
14098c2ecf20Sopenharmony_ci	rmb();
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	if (likely(fp->type & QEDE_FASTPATH_RX))
14128c2ecf20Sopenharmony_ci		if (qede_has_rx_work(fp->rxq))
14138c2ecf20Sopenharmony_ci			return true;
14148c2ecf20Sopenharmony_ci
14158c2ecf20Sopenharmony_ci	if (fp->type & QEDE_FASTPATH_XDP)
14168c2ecf20Sopenharmony_ci		if (qede_txq_has_work(fp->xdp_tx))
14178c2ecf20Sopenharmony_ci			return true;
14188c2ecf20Sopenharmony_ci
14198c2ecf20Sopenharmony_ci	if (likely(fp->type & QEDE_FASTPATH_TX)) {
14208c2ecf20Sopenharmony_ci		int cos;
14218c2ecf20Sopenharmony_ci
14228c2ecf20Sopenharmony_ci		for_each_cos_in_txq(fp->edev, cos) {
14238c2ecf20Sopenharmony_ci			if (qede_txq_has_work(&fp->txq[cos]))
14248c2ecf20Sopenharmony_ci				return true;
14258c2ecf20Sopenharmony_ci		}
14268c2ecf20Sopenharmony_ci	}
14278c2ecf20Sopenharmony_ci
14288c2ecf20Sopenharmony_ci	return false;
14298c2ecf20Sopenharmony_ci}
14308c2ecf20Sopenharmony_ci
14318c2ecf20Sopenharmony_ci/*********************
14328c2ecf20Sopenharmony_ci * NDO & API related *
14338c2ecf20Sopenharmony_ci *********************/
14348c2ecf20Sopenharmony_ciint qede_poll(struct napi_struct *napi, int budget)
14358c2ecf20Sopenharmony_ci{
14368c2ecf20Sopenharmony_ci	struct qede_fastpath *fp = container_of(napi, struct qede_fastpath,
14378c2ecf20Sopenharmony_ci						napi);
14388c2ecf20Sopenharmony_ci	struct qede_dev *edev = fp->edev;
14398c2ecf20Sopenharmony_ci	int rx_work_done = 0;
14408c2ecf20Sopenharmony_ci	u16 xdp_prod;
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	fp->xdp_xmit = 0;
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	if (likely(fp->type & QEDE_FASTPATH_TX)) {
14458c2ecf20Sopenharmony_ci		int cos;
14468c2ecf20Sopenharmony_ci
14478c2ecf20Sopenharmony_ci		for_each_cos_in_txq(fp->edev, cos) {
14488c2ecf20Sopenharmony_ci			if (qede_txq_has_work(&fp->txq[cos]))
14498c2ecf20Sopenharmony_ci				qede_tx_int(edev, &fp->txq[cos]);
14508c2ecf20Sopenharmony_ci		}
14518c2ecf20Sopenharmony_ci	}
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_ci	if ((fp->type & QEDE_FASTPATH_XDP) && qede_txq_has_work(fp->xdp_tx))
14548c2ecf20Sopenharmony_ci		qede_xdp_tx_int(edev, fp->xdp_tx);
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	rx_work_done = (likely(fp->type & QEDE_FASTPATH_RX) &&
14578c2ecf20Sopenharmony_ci			qede_has_rx_work(fp->rxq)) ?
14588c2ecf20Sopenharmony_ci			qede_rx_int(fp, budget) : 0;
14598c2ecf20Sopenharmony_ci
14608c2ecf20Sopenharmony_ci	if (fp->xdp_xmit & QEDE_XDP_REDIRECT)
14618c2ecf20Sopenharmony_ci		xdp_do_flush();
14628c2ecf20Sopenharmony_ci
14638c2ecf20Sopenharmony_ci	/* Handle case where we are called by netpoll with a budget of 0 */
14648c2ecf20Sopenharmony_ci	if (rx_work_done < budget || !budget) {
14658c2ecf20Sopenharmony_ci		if (!qede_poll_is_more_work(fp)) {
14668c2ecf20Sopenharmony_ci			napi_complete_done(napi, rx_work_done);
14678c2ecf20Sopenharmony_ci
14688c2ecf20Sopenharmony_ci			/* Update and reenable interrupts */
14698c2ecf20Sopenharmony_ci			qed_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
14708c2ecf20Sopenharmony_ci		} else {
14718c2ecf20Sopenharmony_ci			rx_work_done = budget;
14728c2ecf20Sopenharmony_ci		}
14738c2ecf20Sopenharmony_ci	}
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_ci	if (fp->xdp_xmit & QEDE_XDP_TX) {
14768c2ecf20Sopenharmony_ci		xdp_prod = qed_chain_get_prod_idx(&fp->xdp_tx->tx_pbl);
14778c2ecf20Sopenharmony_ci
14788c2ecf20Sopenharmony_ci		fp->xdp_tx->tx_db.data.bd_prod = cpu_to_le16(xdp_prod);
14798c2ecf20Sopenharmony_ci		qede_update_tx_producer(fp->xdp_tx);
14808c2ecf20Sopenharmony_ci	}
14818c2ecf20Sopenharmony_ci
14828c2ecf20Sopenharmony_ci	return rx_work_done;
14838c2ecf20Sopenharmony_ci}
14848c2ecf20Sopenharmony_ci
14858c2ecf20Sopenharmony_ciirqreturn_t qede_msix_fp_int(int irq, void *fp_cookie)
14868c2ecf20Sopenharmony_ci{
14878c2ecf20Sopenharmony_ci	struct qede_fastpath *fp = fp_cookie;
14888c2ecf20Sopenharmony_ci
14898c2ecf20Sopenharmony_ci	qed_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0 /*do not update*/);
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci	napi_schedule_irqoff(&fp->napi);
14928c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
14938c2ecf20Sopenharmony_ci}
14948c2ecf20Sopenharmony_ci
14958c2ecf20Sopenharmony_ci/* Main transmit function */
14968c2ecf20Sopenharmony_cinetdev_tx_t qede_start_xmit(struct sk_buff *skb, struct net_device *ndev)
14978c2ecf20Sopenharmony_ci{
14988c2ecf20Sopenharmony_ci	struct qede_dev *edev = netdev_priv(ndev);
14998c2ecf20Sopenharmony_ci	struct netdev_queue *netdev_txq;
15008c2ecf20Sopenharmony_ci	struct qede_tx_queue *txq;
15018c2ecf20Sopenharmony_ci	struct eth_tx_1st_bd *first_bd;
15028c2ecf20Sopenharmony_ci	struct eth_tx_2nd_bd *second_bd = NULL;
15038c2ecf20Sopenharmony_ci	struct eth_tx_3rd_bd *third_bd = NULL;
15048c2ecf20Sopenharmony_ci	struct eth_tx_bd *tx_data_bd = NULL;
15058c2ecf20Sopenharmony_ci	u16 txq_index, val = 0;
15068c2ecf20Sopenharmony_ci	u8 nbd = 0;
15078c2ecf20Sopenharmony_ci	dma_addr_t mapping;
15088c2ecf20Sopenharmony_ci	int rc, frag_idx = 0, ipv6_ext = 0;
15098c2ecf20Sopenharmony_ci	u8 xmit_type;
15108c2ecf20Sopenharmony_ci	u16 idx;
15118c2ecf20Sopenharmony_ci	u16 hlen;
15128c2ecf20Sopenharmony_ci	bool data_split = false;
15138c2ecf20Sopenharmony_ci
15148c2ecf20Sopenharmony_ci	/* Get tx-queue context and netdev index */
15158c2ecf20Sopenharmony_ci	txq_index = skb_get_queue_mapping(skb);
15168c2ecf20Sopenharmony_ci	WARN_ON(txq_index >= QEDE_TSS_COUNT(edev) * edev->dev_info.num_tc);
15178c2ecf20Sopenharmony_ci	txq = QEDE_NDEV_TXQ_ID_TO_TXQ(edev, txq_index);
15188c2ecf20Sopenharmony_ci	netdev_txq = netdev_get_tx_queue(ndev, txq_index);
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_ci	WARN_ON(qed_chain_get_elem_left(&txq->tx_pbl) < (MAX_SKB_FRAGS + 1));
15218c2ecf20Sopenharmony_ci
15228c2ecf20Sopenharmony_ci	xmit_type = qede_xmit_type(skb, &ipv6_ext);
15238c2ecf20Sopenharmony_ci
15248c2ecf20Sopenharmony_ci#if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
15258c2ecf20Sopenharmony_ci	if (qede_pkt_req_lin(skb, xmit_type)) {
15268c2ecf20Sopenharmony_ci		if (skb_linearize(skb)) {
15278c2ecf20Sopenharmony_ci			txq->tx_mem_alloc_err++;
15288c2ecf20Sopenharmony_ci
15298c2ecf20Sopenharmony_ci			dev_kfree_skb_any(skb);
15308c2ecf20Sopenharmony_ci			return NETDEV_TX_OK;
15318c2ecf20Sopenharmony_ci		}
15328c2ecf20Sopenharmony_ci	}
15338c2ecf20Sopenharmony_ci#endif
15348c2ecf20Sopenharmony_ci
15358c2ecf20Sopenharmony_ci	/* Fill the entry in the SW ring and the BDs in the FW ring */
15368c2ecf20Sopenharmony_ci	idx = txq->sw_tx_prod;
15378c2ecf20Sopenharmony_ci	txq->sw_tx_ring.skbs[idx].skb = skb;
15388c2ecf20Sopenharmony_ci	first_bd = (struct eth_tx_1st_bd *)
15398c2ecf20Sopenharmony_ci		   qed_chain_produce(&txq->tx_pbl);
15408c2ecf20Sopenharmony_ci	memset(first_bd, 0, sizeof(*first_bd));
15418c2ecf20Sopenharmony_ci	first_bd->data.bd_flags.bitfields =
15428c2ecf20Sopenharmony_ci		1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
15438c2ecf20Sopenharmony_ci
15448c2ecf20Sopenharmony_ci	if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
15458c2ecf20Sopenharmony_ci		qede_ptp_tx_ts(edev, skb);
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_ci	/* Map skb linear data for DMA and set in the first BD */
15488c2ecf20Sopenharmony_ci	mapping = dma_map_single(txq->dev, skb->data,
15498c2ecf20Sopenharmony_ci				 skb_headlen(skb), DMA_TO_DEVICE);
15508c2ecf20Sopenharmony_ci	if (unlikely(dma_mapping_error(txq->dev, mapping))) {
15518c2ecf20Sopenharmony_ci		DP_NOTICE(edev, "SKB mapping failed\n");
15528c2ecf20Sopenharmony_ci		qede_free_failed_tx_pkt(txq, first_bd, 0, false);
15538c2ecf20Sopenharmony_ci		qede_update_tx_producer(txq);
15548c2ecf20Sopenharmony_ci		return NETDEV_TX_OK;
15558c2ecf20Sopenharmony_ci	}
15568c2ecf20Sopenharmony_ci	nbd++;
15578c2ecf20Sopenharmony_ci	BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci	/* In case there is IPv6 with extension headers or LSO we need 2nd and
15608c2ecf20Sopenharmony_ci	 * 3rd BDs.
15618c2ecf20Sopenharmony_ci	 */
15628c2ecf20Sopenharmony_ci	if (unlikely((xmit_type & XMIT_LSO) | ipv6_ext)) {
15638c2ecf20Sopenharmony_ci		second_bd = (struct eth_tx_2nd_bd *)
15648c2ecf20Sopenharmony_ci			qed_chain_produce(&txq->tx_pbl);
15658c2ecf20Sopenharmony_ci		memset(second_bd, 0, sizeof(*second_bd));
15668c2ecf20Sopenharmony_ci
15678c2ecf20Sopenharmony_ci		nbd++;
15688c2ecf20Sopenharmony_ci		third_bd = (struct eth_tx_3rd_bd *)
15698c2ecf20Sopenharmony_ci			qed_chain_produce(&txq->tx_pbl);
15708c2ecf20Sopenharmony_ci		memset(third_bd, 0, sizeof(*third_bd));
15718c2ecf20Sopenharmony_ci
15728c2ecf20Sopenharmony_ci		nbd++;
15738c2ecf20Sopenharmony_ci		/* We need to fill in additional data in second_bd... */
15748c2ecf20Sopenharmony_ci		tx_data_bd = (struct eth_tx_bd *)second_bd;
15758c2ecf20Sopenharmony_ci	}
15768c2ecf20Sopenharmony_ci
15778c2ecf20Sopenharmony_ci	if (skb_vlan_tag_present(skb)) {
15788c2ecf20Sopenharmony_ci		first_bd->data.vlan = cpu_to_le16(skb_vlan_tag_get(skb));
15798c2ecf20Sopenharmony_ci		first_bd->data.bd_flags.bitfields |=
15808c2ecf20Sopenharmony_ci			1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT;
15818c2ecf20Sopenharmony_ci	}
15828c2ecf20Sopenharmony_ci
15838c2ecf20Sopenharmony_ci	/* Fill the parsing flags & params according to the requested offload */
15848c2ecf20Sopenharmony_ci	if (xmit_type & XMIT_L4_CSUM) {
15858c2ecf20Sopenharmony_ci		/* We don't re-calculate IP checksum as it is already done by
15868c2ecf20Sopenharmony_ci		 * the upper stack
15878c2ecf20Sopenharmony_ci		 */
15888c2ecf20Sopenharmony_ci		first_bd->data.bd_flags.bitfields |=
15898c2ecf20Sopenharmony_ci			1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT;
15908c2ecf20Sopenharmony_ci
15918c2ecf20Sopenharmony_ci		if (xmit_type & XMIT_ENC) {
15928c2ecf20Sopenharmony_ci			first_bd->data.bd_flags.bitfields |=
15938c2ecf20Sopenharmony_ci				1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT;
15948c2ecf20Sopenharmony_ci
15958c2ecf20Sopenharmony_ci			val |= (1 << ETH_TX_DATA_1ST_BD_TUNN_FLAG_SHIFT);
15968c2ecf20Sopenharmony_ci		}
15978c2ecf20Sopenharmony_ci
15988c2ecf20Sopenharmony_ci		/* Legacy FW had flipped behavior in regard to this bit -
15998c2ecf20Sopenharmony_ci		 * I.e., needed to set to prevent FW from touching encapsulated
16008c2ecf20Sopenharmony_ci		 * packets when it didn't need to.
16018c2ecf20Sopenharmony_ci		 */
16028c2ecf20Sopenharmony_ci		if (unlikely(txq->is_legacy))
16038c2ecf20Sopenharmony_ci			val ^= (1 << ETH_TX_DATA_1ST_BD_TUNN_FLAG_SHIFT);
16048c2ecf20Sopenharmony_ci
16058c2ecf20Sopenharmony_ci		/* If the packet is IPv6 with extension header, indicate that
16068c2ecf20Sopenharmony_ci		 * to FW and pass few params, since the device cracker doesn't
16078c2ecf20Sopenharmony_ci		 * support parsing IPv6 with extension header/s.
16088c2ecf20Sopenharmony_ci		 */
16098c2ecf20Sopenharmony_ci		if (unlikely(ipv6_ext))
16108c2ecf20Sopenharmony_ci			qede_set_params_for_ipv6_ext(skb, second_bd, third_bd);
16118c2ecf20Sopenharmony_ci	}
16128c2ecf20Sopenharmony_ci
16138c2ecf20Sopenharmony_ci	if (xmit_type & XMIT_LSO) {
16148c2ecf20Sopenharmony_ci		first_bd->data.bd_flags.bitfields |=
16158c2ecf20Sopenharmony_ci			(1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT);
16168c2ecf20Sopenharmony_ci		third_bd->data.lso_mss =
16178c2ecf20Sopenharmony_ci			cpu_to_le16(skb_shinfo(skb)->gso_size);
16188c2ecf20Sopenharmony_ci
16198c2ecf20Sopenharmony_ci		if (unlikely(xmit_type & XMIT_ENC)) {
16208c2ecf20Sopenharmony_ci			first_bd->data.bd_flags.bitfields |=
16218c2ecf20Sopenharmony_ci				1 << ETH_TX_1ST_BD_FLAGS_TUNN_IP_CSUM_SHIFT;
16228c2ecf20Sopenharmony_ci
16238c2ecf20Sopenharmony_ci			if (xmit_type & XMIT_ENC_GSO_L4_CSUM) {
16248c2ecf20Sopenharmony_ci				u8 tmp = ETH_TX_1ST_BD_FLAGS_TUNN_L4_CSUM_SHIFT;
16258c2ecf20Sopenharmony_ci
16268c2ecf20Sopenharmony_ci				first_bd->data.bd_flags.bitfields |= 1 << tmp;
16278c2ecf20Sopenharmony_ci			}
16288c2ecf20Sopenharmony_ci			hlen = qede_get_skb_hlen(skb, true);
16298c2ecf20Sopenharmony_ci		} else {
16308c2ecf20Sopenharmony_ci			first_bd->data.bd_flags.bitfields |=
16318c2ecf20Sopenharmony_ci				1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT;
16328c2ecf20Sopenharmony_ci			hlen = qede_get_skb_hlen(skb, false);
16338c2ecf20Sopenharmony_ci		}
16348c2ecf20Sopenharmony_ci
16358c2ecf20Sopenharmony_ci		/* @@@TBD - if will not be removed need to check */
16368c2ecf20Sopenharmony_ci		third_bd->data.bitfields |=
16378c2ecf20Sopenharmony_ci			cpu_to_le16(1 << ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
16388c2ecf20Sopenharmony_ci
16398c2ecf20Sopenharmony_ci		/* Make life easier for FW guys who can't deal with header and
16408c2ecf20Sopenharmony_ci		 * data on same BD. If we need to split, use the second bd...
16418c2ecf20Sopenharmony_ci		 */
16428c2ecf20Sopenharmony_ci		if (unlikely(skb_headlen(skb) > hlen)) {
16438c2ecf20Sopenharmony_ci			DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
16448c2ecf20Sopenharmony_ci				   "TSO split header size is %d (%x:%x)\n",
16458c2ecf20Sopenharmony_ci				   first_bd->nbytes, first_bd->addr.hi,
16468c2ecf20Sopenharmony_ci				   first_bd->addr.lo);
16478c2ecf20Sopenharmony_ci
16488c2ecf20Sopenharmony_ci			mapping = HILO_U64(le32_to_cpu(first_bd->addr.hi),
16498c2ecf20Sopenharmony_ci					   le32_to_cpu(first_bd->addr.lo)) +
16508c2ecf20Sopenharmony_ci					   hlen;
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_ci			BD_SET_UNMAP_ADDR_LEN(tx_data_bd, mapping,
16538c2ecf20Sopenharmony_ci					      le16_to_cpu(first_bd->nbytes) -
16548c2ecf20Sopenharmony_ci					      hlen);
16558c2ecf20Sopenharmony_ci
16568c2ecf20Sopenharmony_ci			/* this marks the BD as one that has no
16578c2ecf20Sopenharmony_ci			 * individual mapping
16588c2ecf20Sopenharmony_ci			 */
16598c2ecf20Sopenharmony_ci			txq->sw_tx_ring.skbs[idx].flags |= QEDE_TSO_SPLIT_BD;
16608c2ecf20Sopenharmony_ci
16618c2ecf20Sopenharmony_ci			first_bd->nbytes = cpu_to_le16(hlen);
16628c2ecf20Sopenharmony_ci
16638c2ecf20Sopenharmony_ci			tx_data_bd = (struct eth_tx_bd *)third_bd;
16648c2ecf20Sopenharmony_ci			data_split = true;
16658c2ecf20Sopenharmony_ci		}
16668c2ecf20Sopenharmony_ci	} else {
16678c2ecf20Sopenharmony_ci		if (unlikely(skb->len > ETH_TX_MAX_NON_LSO_PKT_LEN)) {
16688c2ecf20Sopenharmony_ci			DP_ERR(edev, "Unexpected non LSO skb length = 0x%x\n", skb->len);
16698c2ecf20Sopenharmony_ci			qede_free_failed_tx_pkt(txq, first_bd, 0, false);
16708c2ecf20Sopenharmony_ci			qede_update_tx_producer(txq);
16718c2ecf20Sopenharmony_ci			return NETDEV_TX_OK;
16728c2ecf20Sopenharmony_ci		}
16738c2ecf20Sopenharmony_ci
16748c2ecf20Sopenharmony_ci		val |= ((skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK) <<
16758c2ecf20Sopenharmony_ci			 ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
16768c2ecf20Sopenharmony_ci	}
16778c2ecf20Sopenharmony_ci
16788c2ecf20Sopenharmony_ci	first_bd->data.bitfields = cpu_to_le16(val);
16798c2ecf20Sopenharmony_ci
16808c2ecf20Sopenharmony_ci	/* Handle fragmented skb */
16818c2ecf20Sopenharmony_ci	/* special handle for frags inside 2nd and 3rd bds.. */
16828c2ecf20Sopenharmony_ci	while (tx_data_bd && frag_idx < skb_shinfo(skb)->nr_frags) {
16838c2ecf20Sopenharmony_ci		rc = map_frag_to_bd(txq,
16848c2ecf20Sopenharmony_ci				    &skb_shinfo(skb)->frags[frag_idx],
16858c2ecf20Sopenharmony_ci				    tx_data_bd);
16868c2ecf20Sopenharmony_ci		if (rc) {
16878c2ecf20Sopenharmony_ci			qede_free_failed_tx_pkt(txq, first_bd, nbd, data_split);
16888c2ecf20Sopenharmony_ci			qede_update_tx_producer(txq);
16898c2ecf20Sopenharmony_ci			return NETDEV_TX_OK;
16908c2ecf20Sopenharmony_ci		}
16918c2ecf20Sopenharmony_ci
16928c2ecf20Sopenharmony_ci		if (tx_data_bd == (struct eth_tx_bd *)second_bd)
16938c2ecf20Sopenharmony_ci			tx_data_bd = (struct eth_tx_bd *)third_bd;
16948c2ecf20Sopenharmony_ci		else
16958c2ecf20Sopenharmony_ci			tx_data_bd = NULL;
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_ci		frag_idx++;
16988c2ecf20Sopenharmony_ci	}
16998c2ecf20Sopenharmony_ci
17008c2ecf20Sopenharmony_ci	/* map last frags into 4th, 5th .... */
17018c2ecf20Sopenharmony_ci	for (; frag_idx < skb_shinfo(skb)->nr_frags; frag_idx++, nbd++) {
17028c2ecf20Sopenharmony_ci		tx_data_bd = (struct eth_tx_bd *)
17038c2ecf20Sopenharmony_ci			     qed_chain_produce(&txq->tx_pbl);
17048c2ecf20Sopenharmony_ci
17058c2ecf20Sopenharmony_ci		memset(tx_data_bd, 0, sizeof(*tx_data_bd));
17068c2ecf20Sopenharmony_ci
17078c2ecf20Sopenharmony_ci		rc = map_frag_to_bd(txq,
17088c2ecf20Sopenharmony_ci				    &skb_shinfo(skb)->frags[frag_idx],
17098c2ecf20Sopenharmony_ci				    tx_data_bd);
17108c2ecf20Sopenharmony_ci		if (rc) {
17118c2ecf20Sopenharmony_ci			qede_free_failed_tx_pkt(txq, first_bd, nbd, data_split);
17128c2ecf20Sopenharmony_ci			qede_update_tx_producer(txq);
17138c2ecf20Sopenharmony_ci			return NETDEV_TX_OK;
17148c2ecf20Sopenharmony_ci		}
17158c2ecf20Sopenharmony_ci	}
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci	/* update the first BD with the actual num BDs */
17188c2ecf20Sopenharmony_ci	first_bd->data.nbds = nbd;
17198c2ecf20Sopenharmony_ci
17208c2ecf20Sopenharmony_ci	netdev_tx_sent_queue(netdev_txq, skb->len);
17218c2ecf20Sopenharmony_ci
17228c2ecf20Sopenharmony_ci	skb_tx_timestamp(skb);
17238c2ecf20Sopenharmony_ci
17248c2ecf20Sopenharmony_ci	/* Advance packet producer only before sending the packet since mapping
17258c2ecf20Sopenharmony_ci	 * of pages may fail.
17268c2ecf20Sopenharmony_ci	 */
17278c2ecf20Sopenharmony_ci	txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
17288c2ecf20Sopenharmony_ci
17298c2ecf20Sopenharmony_ci	/* 'next page' entries are counted in the producer value */
17308c2ecf20Sopenharmony_ci	txq->tx_db.data.bd_prod =
17318c2ecf20Sopenharmony_ci		cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
17328c2ecf20Sopenharmony_ci
17338c2ecf20Sopenharmony_ci	if (!netdev_xmit_more() || netif_xmit_stopped(netdev_txq))
17348c2ecf20Sopenharmony_ci		qede_update_tx_producer(txq);
17358c2ecf20Sopenharmony_ci
17368c2ecf20Sopenharmony_ci	if (unlikely(qed_chain_get_elem_left(&txq->tx_pbl)
17378c2ecf20Sopenharmony_ci		      < (MAX_SKB_FRAGS + 1))) {
17388c2ecf20Sopenharmony_ci		if (netdev_xmit_more())
17398c2ecf20Sopenharmony_ci			qede_update_tx_producer(txq);
17408c2ecf20Sopenharmony_ci
17418c2ecf20Sopenharmony_ci		netif_tx_stop_queue(netdev_txq);
17428c2ecf20Sopenharmony_ci		txq->stopped_cnt++;
17438c2ecf20Sopenharmony_ci		DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
17448c2ecf20Sopenharmony_ci			   "Stop queue was called\n");
17458c2ecf20Sopenharmony_ci		/* paired memory barrier is in qede_tx_int(), we have to keep
17468c2ecf20Sopenharmony_ci		 * ordering of set_bit() in netif_tx_stop_queue() and read of
17478c2ecf20Sopenharmony_ci		 * fp->bd_tx_cons
17488c2ecf20Sopenharmony_ci		 */
17498c2ecf20Sopenharmony_ci		smp_mb();
17508c2ecf20Sopenharmony_ci
17518c2ecf20Sopenharmony_ci		if ((qed_chain_get_elem_left(&txq->tx_pbl) >=
17528c2ecf20Sopenharmony_ci		     (MAX_SKB_FRAGS + 1)) &&
17538c2ecf20Sopenharmony_ci		    (edev->state == QEDE_STATE_OPEN)) {
17548c2ecf20Sopenharmony_ci			netif_tx_wake_queue(netdev_txq);
17558c2ecf20Sopenharmony_ci			DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
17568c2ecf20Sopenharmony_ci				   "Wake queue was called\n");
17578c2ecf20Sopenharmony_ci		}
17588c2ecf20Sopenharmony_ci	}
17598c2ecf20Sopenharmony_ci
17608c2ecf20Sopenharmony_ci	return NETDEV_TX_OK;
17618c2ecf20Sopenharmony_ci}
17628c2ecf20Sopenharmony_ci
17638c2ecf20Sopenharmony_ciu16 qede_select_queue(struct net_device *dev, struct sk_buff *skb,
17648c2ecf20Sopenharmony_ci		      struct net_device *sb_dev)
17658c2ecf20Sopenharmony_ci{
17668c2ecf20Sopenharmony_ci	struct qede_dev *edev = netdev_priv(dev);
17678c2ecf20Sopenharmony_ci	int total_txq;
17688c2ecf20Sopenharmony_ci
17698c2ecf20Sopenharmony_ci	total_txq = QEDE_TSS_COUNT(edev) * edev->dev_info.num_tc;
17708c2ecf20Sopenharmony_ci
17718c2ecf20Sopenharmony_ci	return QEDE_TSS_COUNT(edev) ?
17728c2ecf20Sopenharmony_ci		netdev_pick_tx(dev, skb, NULL) % total_txq :  0;
17738c2ecf20Sopenharmony_ci}
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_ci/* 8B udp header + 8B base tunnel header + 32B option length */
17768c2ecf20Sopenharmony_ci#define QEDE_MAX_TUN_HDR_LEN 48
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_cinetdev_features_t qede_features_check(struct sk_buff *skb,
17798c2ecf20Sopenharmony_ci				      struct net_device *dev,
17808c2ecf20Sopenharmony_ci				      netdev_features_t features)
17818c2ecf20Sopenharmony_ci{
17828c2ecf20Sopenharmony_ci	if (skb->encapsulation) {
17838c2ecf20Sopenharmony_ci		u8 l4_proto = 0;
17848c2ecf20Sopenharmony_ci
17858c2ecf20Sopenharmony_ci		switch (vlan_get_protocol(skb)) {
17868c2ecf20Sopenharmony_ci		case htons(ETH_P_IP):
17878c2ecf20Sopenharmony_ci			l4_proto = ip_hdr(skb)->protocol;
17888c2ecf20Sopenharmony_ci			break;
17898c2ecf20Sopenharmony_ci		case htons(ETH_P_IPV6):
17908c2ecf20Sopenharmony_ci			l4_proto = ipv6_hdr(skb)->nexthdr;
17918c2ecf20Sopenharmony_ci			break;
17928c2ecf20Sopenharmony_ci		default:
17938c2ecf20Sopenharmony_ci			return features;
17948c2ecf20Sopenharmony_ci		}
17958c2ecf20Sopenharmony_ci
17968c2ecf20Sopenharmony_ci		/* Disable offloads for geneve tunnels, as HW can't parse
17978c2ecf20Sopenharmony_ci		 * the geneve header which has option length greater than 32b
17988c2ecf20Sopenharmony_ci		 * and disable offloads for the ports which are not offloaded.
17998c2ecf20Sopenharmony_ci		 */
18008c2ecf20Sopenharmony_ci		if (l4_proto == IPPROTO_UDP) {
18018c2ecf20Sopenharmony_ci			struct qede_dev *edev = netdev_priv(dev);
18028c2ecf20Sopenharmony_ci			u16 hdrlen, vxln_port, gnv_port;
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_ci			hdrlen = QEDE_MAX_TUN_HDR_LEN;
18058c2ecf20Sopenharmony_ci			vxln_port = edev->vxlan_dst_port;
18068c2ecf20Sopenharmony_ci			gnv_port = edev->geneve_dst_port;
18078c2ecf20Sopenharmony_ci
18088c2ecf20Sopenharmony_ci			if ((skb_inner_mac_header(skb) -
18098c2ecf20Sopenharmony_ci			     skb_transport_header(skb)) > hdrlen ||
18108c2ecf20Sopenharmony_ci			     (ntohs(udp_hdr(skb)->dest) != vxln_port &&
18118c2ecf20Sopenharmony_ci			      ntohs(udp_hdr(skb)->dest) != gnv_port))
18128c2ecf20Sopenharmony_ci				return features & ~(NETIF_F_CSUM_MASK |
18138c2ecf20Sopenharmony_ci						    NETIF_F_GSO_MASK);
18148c2ecf20Sopenharmony_ci		} else if (l4_proto == IPPROTO_IPIP) {
18158c2ecf20Sopenharmony_ci			/* IPIP tunnels are unknown to the device or at least unsupported natively,
18168c2ecf20Sopenharmony_ci			 * offloads for them can't be done trivially, so disable them for such skb.
18178c2ecf20Sopenharmony_ci			 */
18188c2ecf20Sopenharmony_ci			return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
18198c2ecf20Sopenharmony_ci		}
18208c2ecf20Sopenharmony_ci	}
18218c2ecf20Sopenharmony_ci
18228c2ecf20Sopenharmony_ci	return features;
18238c2ecf20Sopenharmony_ci}
1824