xref: /linux/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2024 Hisilicon Limited. */
3 
4 #ifndef __HBG_TXRX_H
5 #define __HBG_TXRX_H
6 
7 #include <linux/etherdevice.h>
8 #include "hbg_hw.h"
9 
10 static inline u32 hbg_spec_max_frame_len(struct hbg_priv *priv,
11 					 enum hbg_dir dir)
12 {
13 	return (dir == HBG_DIR_TX) ? priv->dev_specs.max_frame_len :
14 		priv->dev_specs.rx_buf_size;
15 }
16 
17 static inline u32 hbg_get_spec_fifo_max_num(struct hbg_priv *priv,
18 					    enum hbg_dir dir)
19 {
20 	return (dir == HBG_DIR_TX) ? priv->dev_specs.tx_fifo_num :
21 		priv->dev_specs.rx_fifo_num;
22 }
23 
24 static inline bool hbg_fifo_is_full(struct hbg_priv *priv, enum hbg_dir dir)
25 {
26 	return hbg_hw_get_fifo_used_num(priv, dir) >=
27 	       hbg_get_spec_fifo_max_num(priv, dir);
28 }
29 
30 static inline u32 hbg_get_queue_used_num(struct hbg_ring *ring)
31 {
32 	return (ring->ntu + ring->len - ring->ntc) % ring->len;
33 }
34 
35 netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *netdev);
36 int hbg_txrx_init(struct hbg_priv *priv);
37 void hbg_txrx_uninit(struct hbg_priv *priv);
38 
39 #endif
40