brintos

brintos / linux-shallow public Read only

0
0
Text · 3.7 KiB · 2f91f68 Raw
138 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/* Copyright (c) Meta Platforms, Inc. and affiliates. */3 4#ifndef _FBNIC_TXRX_H_5#define _FBNIC_TXRX_H_6 7#include <linux/netdevice.h>8#include <linux/skbuff.h>9#include <linux/types.h>10#include <linux/u64_stats_sync.h>11#include <net/xdp.h>12 13struct fbnic_net;14 15/* Guarantee we have space needed for storing the buffer16 * To store the buffer we need:17 *	1 descriptor per page18 *	+ 1 descriptor for skb head19 *	+ 2 descriptors for metadata and optional metadata20 *	+ 7 descriptors to keep tail out of the same cacheline as head21 * If we cannot guarantee that then we should return TX_BUSY22 */23#define FBNIC_MAX_SKB_DESC	(MAX_SKB_FRAGS + 10)24#define FBNIC_TX_DESC_WAKEUP	(FBNIC_MAX_SKB_DESC * 2)25#define FBNIC_TX_DESC_MIN	roundup_pow_of_two(FBNIC_TX_DESC_WAKEUP)26 27#define FBNIC_MAX_TXQS			128u28#define FBNIC_MAX_RXQS			128u29 30#define FBNIC_TXQ_SIZE_DEFAULT		102431#define FBNIC_HPQ_SIZE_DEFAULT		25632#define FBNIC_PPQ_SIZE_DEFAULT		25633#define FBNIC_RCQ_SIZE_DEFAULT		102434 35#define FBNIC_RX_TROOM \36	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))37#define FBNIC_RX_HROOM \38	(ALIGN(FBNIC_RX_TROOM + NET_SKB_PAD, 128) - FBNIC_RX_TROOM)39#define FBNIC_RX_PAD			040#define FBNIC_RX_MAX_HDR		(1536 - FBNIC_RX_PAD)41#define FBNIC_RX_PAYLD_OFFSET		042#define FBNIC_RX_PAYLD_PG_CL		043 44#define FBNIC_RING_F_DISABLED		BIT(0)45#define FBNIC_RING_F_CTX		BIT(1)46#define FBNIC_RING_F_STATS		BIT(2)	/* Ring's stats may be used */47 48struct fbnic_pkt_buff {49	struct xdp_buff buff;50	u32 data_truesize;51	u16 data_len;52	u16 nr_frags;53};54 55struct fbnic_queue_stats {56	u64 packets;57	u64 bytes;58	u64 dropped;59	struct u64_stats_sync syncp;60};61 62/* Pagecnt bias is long max to reserve the last bit to catch overflow63 * cases where if we overcharge the bias it will flip over to be negative.64 */65#define PAGECNT_BIAS_MAX	LONG_MAX66struct fbnic_rx_buf {67	struct page *page;68	long pagecnt_bias;69};70 71struct fbnic_ring {72	/* Pointer to buffer specific info */73	union {74		struct fbnic_pkt_buff *pkt;	/* RCQ */75		struct fbnic_rx_buf *rx_buf;	/* BDQ */76		void **tx_buf;			/* TWQ */77		void *buffer;			/* Generic pointer */78	};79 80	u32 __iomem *doorbell;		/* Pointer to CSR space for ring */81	__le64 *desc;			/* Descriptor ring memory */82	u16 size_mask;			/* Size of ring in descriptors - 1 */83	u8 q_idx;			/* Logical netdev ring index */84	u8 flags;			/* Ring flags (FBNIC_RING_F_*) */85 86	u32 head, tail;			/* Head/Tail of ring */87 88	struct fbnic_queue_stats stats;89 90	/* Slow path fields follow */91	dma_addr_t dma;			/* Phys addr of descriptor memory */92	size_t size;			/* Size of descriptor ring in memory */93};94 95struct fbnic_q_triad {96	struct fbnic_ring sub0, sub1, cmpl;97};98 99struct fbnic_napi_vector {100	struct napi_struct napi;101	struct device *dev;		/* Device for DMA unmapping */102	struct page_pool *page_pool;103	struct fbnic_dev *fbd;104	char name[IFNAMSIZ + 9];105 106	u16 v_idx;107	u8 txt_count;108	u8 rxt_count;109 110	struct list_head napis;111 112	struct fbnic_q_triad qt[];113};114 115#define FBNIC_MAX_TXQS			128u116#define FBNIC_MAX_RXQS			128u117 118netdev_tx_t fbnic_xmit_frame(struct sk_buff *skb, struct net_device *dev);119netdev_features_t120fbnic_features_check(struct sk_buff *skb, struct net_device *dev,121		     netdev_features_t features);122 123int fbnic_alloc_napi_vectors(struct fbnic_net *fbn);124void fbnic_free_napi_vectors(struct fbnic_net *fbn);125int fbnic_alloc_resources(struct fbnic_net *fbn);126void fbnic_free_resources(struct fbnic_net *fbn);127void fbnic_napi_enable(struct fbnic_net *fbn);128void fbnic_napi_disable(struct fbnic_net *fbn);129void fbnic_enable(struct fbnic_net *fbn);130void fbnic_disable(struct fbnic_net *fbn);131void fbnic_flush(struct fbnic_net *fbn);132void fbnic_fill(struct fbnic_net *fbn);133 134void fbnic_napi_depletion_check(struct net_device *netdev);135int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail);136 137#endif /* _FBNIC_TXRX_H_ */138