1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * aQuantia Corporation Network Driver
4 * Copyright (C) 2014-2019 aQuantia Corporation. All rights reserved
7 /* File aq_ring.h: Declaration of functions for Rx/Tx rings. */
12 #include "aq_common.h"
25 * +----------+----------+----------+-----------
26 * 8bytes|len l3,l4 | pa | pa | pa
27 * +----------+----------+----------+-----------
28 * 4/8bytes|len pkt |len pkt | | skb
29 * +----------+----------+----------+-----------
30 * 4/8bytes|is_gso |len,flags |len |len,is_eop
31 * +----------+----------+----------+-----------
33 * This aq_ring_buff_s doesn't have endianness dependency.
34 * It is __packed for cache line optimizations.
36 struct __packed aq_ring_buff_s
{
46 struct aq_rxpage rxdata
;
90 struct aq_ring_stats_rx_s
{
101 struct aq_ring_stats_tx_s
{
108 union aq_ring_stats_s
{
109 struct aq_ring_stats_rx_s rx
;
110 struct aq_ring_stats_tx_s tx
;
114 struct aq_ring_buff_s
*buff_ring
;
115 u8
*dx_ring
; /* descriptors ring, dma shared mem */
116 struct aq_nic_s
*aq_nic
;
117 unsigned int idx
; /* for HW layer registers operations */
118 unsigned int hw_head
;
119 unsigned int sw_head
;
120 unsigned int sw_tail
;
121 unsigned int size
; /* descriptors number */
122 unsigned int dx_size
; /* TX or RX descriptor size, */
123 /* stored here for fater math */
124 unsigned int page_order
;
125 union aq_ring_stats_s stats
;
126 dma_addr_t dx_ring_pa
;
129 struct aq_ring_param_s
{
130 unsigned int vec_idx
;
132 cpumask_t affinity_mask
;
135 static inline void *aq_buf_vaddr(struct aq_rxpage
*rxpage
)
137 return page_to_virt(rxpage
->page
) + rxpage
->pg_off
;
140 static inline dma_addr_t
aq_buf_daddr(struct aq_rxpage
*rxpage
)
142 return rxpage
->daddr
+ rxpage
->pg_off
;
145 static inline unsigned int aq_ring_next_dx(struct aq_ring_s
*self
,
148 return (++dx
>= self
->size
) ? 0U : dx
;
151 static inline unsigned int aq_ring_avail_dx(struct aq_ring_s
*self
)
153 return (((self
->sw_tail
>= self
->sw_head
)) ?
154 (self
->size
- 1) - self
->sw_tail
+ self
->sw_head
:
155 self
->sw_head
- self
->sw_tail
- 1);
158 struct aq_ring_s
*aq_ring_tx_alloc(struct aq_ring_s
*self
,
159 struct aq_nic_s
*aq_nic
,
161 struct aq_nic_cfg_s
*aq_nic_cfg
);
162 struct aq_ring_s
*aq_ring_rx_alloc(struct aq_ring_s
*self
,
163 struct aq_nic_s
*aq_nic
,
165 struct aq_nic_cfg_s
*aq_nic_cfg
);
166 int aq_ring_init(struct aq_ring_s
*self
);
167 void aq_ring_rx_deinit(struct aq_ring_s
*self
);
168 void aq_ring_free(struct aq_ring_s
*self
);
169 void aq_ring_update_queue_state(struct aq_ring_s
*ring
);
170 void aq_ring_queue_wake(struct aq_ring_s
*ring
);
171 void aq_ring_queue_stop(struct aq_ring_s
*ring
);
172 bool aq_ring_tx_clean(struct aq_ring_s
*self
);
173 int aq_ring_rx_clean(struct aq_ring_s
*self
,
174 struct napi_struct
*napi
,
177 int aq_ring_rx_fill(struct aq_ring_s
*self
);
179 struct aq_ring_s
*aq_ring_hwts_rx_alloc(struct aq_ring_s
*self
,
180 struct aq_nic_s
*aq_nic
, unsigned int idx
,
181 unsigned int size
, unsigned int dx_size
);
182 void aq_ring_hwts_rx_clean(struct aq_ring_s
*self
, struct aq_nic_s
*aq_nic
);
184 #endif /* AQ_RING_H */