1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Driver for Alibaba Elastic Ethernet Adapter. 4 * 5 * Copyright (C) 2025 Alibaba Inc. 6 */ 7 8 #ifndef __EEA_NET_H__ 9 #define __EEA_NET_H__ 10 11 #include <linux/ethtool.h> 12 #include <linux/netdevice.h> 13 14 #include "eea_adminq.h" 15 #include "eea_ethtool.h" 16 #include "eea_ring.h" 17 18 #define EEA_VER_MAJOR 1 19 #define EEA_VER_MINOR 0 20 #define EEA_VER_SUB_MINOR 0 21 22 struct eea_tx_meta; 23 24 struct eea_net_tx { 25 struct eea_net *enet; 26 27 struct eea_ring *ering; 28 29 struct eea_tx_meta *meta; 30 struct eea_tx_meta *free; 31 32 struct device *dma_dev; 33 34 u32 index; 35 36 char name[16]; 37 38 struct eea_tx_stats stats; 39 }; 40 41 struct eea_rx_meta { 42 struct eea_rx_meta *next; 43 44 struct page *page; 45 dma_addr_t dma; 46 u32 offset; 47 u32 sync_for_cpu; 48 u32 frags; 49 50 struct page *hdr_page; 51 void *hdr_addr; 52 dma_addr_t hdr_dma; 53 54 u32 id; 55 56 u32 truesize; 57 u32 headroom; 58 u32 tailroom; 59 60 u32 len; 61 62 bool in_use; 63 }; 64 65 struct eea_net_rx_pkt_ctx { 66 u16 idx; 67 68 bool data_valid; 69 bool do_drop; 70 71 u32 recv_len; 72 struct sk_buff *head_skb; 73 }; 74 75 struct eea_net_rx { 76 struct eea_net *enet; 77 78 struct eea_ring *ering; 79 80 struct eea_rx_meta *meta; 81 struct eea_rx_meta *free; 82 83 struct device *dma_dev; 84 85 u32 index; 86 87 u32 flags; 88 89 u32 headroom; 90 91 struct napi_struct *napi; 92 93 struct eea_rx_stats stats; 94 95 char name[16]; 96 97 struct eea_net_rx_pkt_ctx pkt; 98 99 struct page_pool *pp; 100 }; 101 102 struct eea_net_cfg { 103 u32 rx_ring_depth; 104 u32 tx_ring_depth; 105 u32 rx_ring_num; 106 u32 tx_ring_num; 107 108 u8 rx_sq_desc_size; 109 u8 rx_cq_desc_size; 110 u8 tx_sq_desc_size; 111 u8 tx_cq_desc_size; 112 113 u32 split_hdr; 114 115 struct hwtstamp_config ts_cfg; 116 }; 117 118 struct eea_net_init_ctx { 119 struct eea_net_cfg cfg; 120 121 struct eea_net_tx *tx; 122 struct eea_net_rx **rx; 123 124 struct net_device *netdev; 125 struct eea_device *edev; 126 }; 127 128 enum { 129 EEA_LINK_ERR_NONE, 130 EEA_LINK_ERR_HA_RESET_DEV, 131 EEA_LINK_ERR_LINK_DOWN, 132 }; 133 134 struct eea_irq_blk { 135 struct napi_struct napi; 136 u16 msix_vec; 137 bool ready; 138 struct eea_net_rx *rx; 139 char irq_name[32]; 140 int irq; 141 int idx; 142 143 }; 144 145 struct eea_net { 146 struct eea_device *edev; 147 struct net_device *netdev; 148 149 struct eea_aq adminq; 150 151 struct eea_net_tx *tx; 152 struct eea_net_rx **rx; 153 154 struct eea_net_cfg cfg; 155 struct eea_net_cfg cfg_hw; 156 157 struct eea_irq_blk *irq_blks; 158 159 u32 link_err; 160 161 bool started; 162 bool wait_pci_ready; 163 164 u8 duplex; 165 u32 speed; 166 167 u64 hw_ts_offset; 168 169 /* Protect the tx and rx of struct eea_net, when eea_stats accesses the 170 * stats from rx and tx queues. 171 */ 172 spinlock_t stats_lock; 173 }; 174 175 int eea_net_probe(struct eea_device *edev); 176 void eea_net_remove(struct eea_device *edev, bool ha); 177 void eea_net_shutdown(struct eea_device *edev); 178 179 int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx); 180 void eea_init_ctx(struct eea_net *enet, struct eea_net_init_ctx *ctx); 181 int eea_queues_check_and_reset(struct eea_device *edev); 182 183 /* rx apis */ 184 185 void enet_rx_stop(struct eea_net_rx *rx); 186 void enet_rx_start(struct eea_net_rx *rx); 187 188 void eea_free_rx(struct eea_net_rx *rx, struct eea_net_cfg *cfg); 189 struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx); 190 191 /* tx apis */ 192 int eea_poll_tx(struct eea_net_tx *tx, int budget); 193 netdev_tx_t eea_tx_xmit(struct sk_buff *skb, struct net_device *netdev); 194 195 void eea_free_tx(struct eea_net_tx *tx, struct eea_net_cfg *cfg); 196 int eea_alloc_tx(struct eea_net_init_ctx *ctx, struct eea_net_tx *tx, u32 idx); 197 198 #endif 199