2 * aQuantia Corporation Network Driver
3 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
10 /* File aq_ring.h: Declaration of functions for Rx/Tx rings. */
15 #include "aq_common.h"
20 * +----------+----------+----------+-----------
21 * 8bytes|len l3,l4 | pa | pa | pa
22 * +----------+----------+----------+-----------
23 * 4/8bytes|len pkt |len pkt | | skb
24 * +----------+----------+----------+-----------
25 * 4/8bytes|is_txc |len,flags |len |len,is_eop
26 * +----------+----------+----------+-----------
28 * This aq_ring_buff_s doesn't have endianness dependency.
29 * It is __packed for cache line optimizations.
31 struct __packed aq_ring_buff_s {
87 struct aq_ring_stats_rx_s {
95 struct aq_ring_stats_tx_s {
102 union aq_ring_stats_s {
103 struct aq_ring_stats_rx_s rx;
104 struct aq_ring_stats_tx_s tx;
108 struct aq_obj_s header;
109 struct aq_ring_buff_s *buff_ring;
110 u8 *dx_ring; /* descriptors ring, dma shared mem */
111 struct aq_nic_s *aq_nic;
112 unsigned int idx; /* for HW layer registers operations */
113 unsigned int hw_head;
114 unsigned int sw_head;
115 unsigned int sw_tail;
116 unsigned int size; /* descriptors number */
117 unsigned int dx_size; /* TX or RX descriptor size, */
118 /* stored here for fater math */
119 union aq_ring_stats_s stats;
120 dma_addr_t dx_ring_pa;
123 struct aq_ring_param_s {
124 unsigned int vec_idx;
126 cpumask_t affinity_mask;
129 static inline unsigned int aq_ring_next_dx(struct aq_ring_s *self,
132 return (++dx >= self->size) ? 0U : dx;
135 static inline unsigned int aq_ring_avail_dx(struct aq_ring_s *self)
137 return (((self->sw_tail >= self->sw_head)) ?
138 (self->size - 1) - self->sw_tail + self->sw_head :
139 self->sw_head - self->sw_tail - 1);
142 struct aq_ring_s *aq_ring_tx_alloc(struct aq_ring_s *self,
143 struct aq_nic_s *aq_nic,
145 struct aq_nic_cfg_s *aq_nic_cfg);
146 struct aq_ring_s *aq_ring_rx_alloc(struct aq_ring_s *self,
147 struct aq_nic_s *aq_nic,
149 struct aq_nic_cfg_s *aq_nic_cfg);
150 int aq_ring_init(struct aq_ring_s *self);
151 void aq_ring_rx_deinit(struct aq_ring_s *self);
152 void aq_ring_free(struct aq_ring_s *self);
153 void aq_ring_update_queue_state(struct aq_ring_s *ring);
154 void aq_ring_queue_wake(struct aq_ring_s *ring);
155 void aq_ring_queue_stop(struct aq_ring_s *ring);
156 void aq_ring_tx_clean(struct aq_ring_s *self);
157 int aq_ring_rx_clean(struct aq_ring_s *self,
158 struct napi_struct *napi,
161 int aq_ring_rx_fill(struct aq_ring_s *self);
163 #endif /* AQ_RING_H */