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_RING_H__ 9 #define __EEA_RING_H__ 10 11 #include <linux/dma-mapping.h> 12 #include "eea_desc.h" 13 14 #define EEA_RING_DESC_F_MORE BIT(0) 15 #define EEA_RING_DESC_F_CQ_PHASE BIT(7) 16 17 /* These two values define the bounds for the queue depth returned by the 18 * hardware. 19 */ 20 #define EEA_NET_IO_HW_RING_DEPTH_MAX (32 * 1024) 21 #define EEA_NET_IO_HW_RING_DEPTH_MIN 128 22 23 /* This value constrains the minimum queue depth that the driver configures for 24 * the hardware, which typically applies to user-provided settings. Naturally, 25 * the configured depth must also not exceed the maximum capacity supported by 26 * the hardware. 27 */ 28 #define EEA_NET_IO_RING_DEPTH_MIN 64 29 30 struct eea_common_desc { 31 __le16 flags; 32 __le16 id; 33 }; 34 35 struct eea_device; 36 37 struct eea_ring_sq { 38 void *desc; 39 40 u16 head; 41 u16 hw_idx; 42 43 u16 shadow_idx; 44 __le16 shadow_id; 45 u16 shadow_num; 46 47 u8 desc_size; 48 u8 desc_size_shift; 49 50 dma_addr_t dma_addr; 51 u32 dma_size; 52 }; 53 54 struct eea_ring_cq { 55 void *desc; 56 57 u16 head; 58 u16 hw_idx; 59 60 u8 phase; 61 u8 desc_size_shift; 62 u8 desc_size; 63 64 dma_addr_t dma_addr; 65 u32 dma_size; 66 }; 67 68 struct eea_ring { 69 const char *name; 70 struct eea_device *edev; 71 u32 index; 72 void __iomem *db; 73 u16 msix_vec; 74 75 u32 num; 76 77 u32 num_free; 78 79 struct eea_ring_sq sq; 80 struct eea_ring_cq cq; 81 }; 82 83 struct eea_ring *eea_ering_alloc(u32 index, u32 num, struct eea_device *edev, 84 u8 sq_desc_size, u8 cq_desc_size, 85 const char *name); 86 void eea_ering_free(struct eea_ring *ering); 87 void eea_ering_kick(struct eea_ring *ering); 88 89 void *eea_ering_sq_alloc_desc(struct eea_ring *ering, u16 id, 90 bool is_last, u16 flags); 91 void *eea_ering_aq_alloc_desc(struct eea_ring *ering); 92 void eea_ering_sq_commit_desc(struct eea_ring *ering); 93 void eea_ering_sq_cancel(struct eea_ring *ering); 94 95 void eea_ering_cq_ack_desc(struct eea_ring *ering, u32 num); 96 97 void eea_ering_irq_active(struct eea_ring *ering, struct eea_ring *tx_ering); 98 void *eea_ering_cq_get_desc(const struct eea_ring *ering); 99 #endif 100