| 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 |
u32 len = READ_ONCE(ring->len); |
| 33 |
|
| 34 |
if (!len) |
| 35 |
return 0; |
| 36 |
|
| 37 |
return (READ_ONCE(ring->ntu) + len - READ_ONCE(ring->ntc)) % len; |
| 38 |
} |
| 39 |
|
| 40 |
netdev_tx_t hbg_net_start_xmit(struct sk_buff *skb, struct net_device *netdev); |
| 41 |
int hbg_txrx_init(struct hbg_priv *priv); |
| 42 |
void hbg_txrx_uninit(struct hbg_priv *priv); |
| 43 |
|
| 44 |
#endif |