xref: /freebsd/sys/dev/aq/aq_ring.h (revision 493d26c58e732dcfcdd87993ef71880adfe9d0cb)
1 /*
2  * aQuantia Corporation Network Driver
3  * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *   (1) Redistributions of source code must retain the above
10  *   copyright notice, this list of conditions and the following
11  *   disclaimer.
12  *
13  *   (2) Redistributions in binary form must reproduce the above
14  *   copyright notice, this list of conditions and the following
15  *   disclaimer in the documentation and/or other materials provided
16  *   with the distribution.
17  *
18  *   (3)The name of the author may not be used to endorse or promote
19  *   products derived from this software without specific prior
20  *   written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef _AQ_RING_H_
36 #define _AQ_RING_H_
37 
38 #include "aq_hw.h"
39 
40 #define REFILL_THRESHOLD 128
41 
42 
43 typedef volatile struct {
44     u32 rss_type:4;
45     u32 pkt_type:8;
46     u32 rdm_err:1;
47     u32 rsvd:6;
48     u32 rx_cntl:2;
49     u32 sph:1;
50     u32 hdr_len:10;
51     u32 rss_hash;
52     u16 dd:1;
53     u16 eop:1;
54     u16 rx_stat:4;
55     u16 rx_estat:6;
56     u16 rsc_cnt:4;
57     u16 pkt_len;
58     u16 next_desp;
59     u16 vlan;
60 } __attribute__((__packed__)) aq_rx_wb_t;
61 
62 typedef volatile struct {
63     union {
64         /* HW RX descriptor */
65         struct __packed {
66             u64 buf_addr;
67             u64 hdr_addr;
68         } read;
69 
70         /* HW RX descriptor writeback */
71         aq_rx_wb_t wb;
72     };
73 } __attribute__((__packed__)) aq_rx_desc_t;
74 
75 /* Hardware tx descriptor */
76 typedef volatile struct {
77     u64 buf_addr;
78 
79     union {
80         struct {
81             u32 type:3;
82             u32 :1;
83             u32 len:16;
84             u32 dd:1;
85             u32 eop:1;
86             u32 cmd:8;
87             u32 :14;
88             u32 ct_idx:1;
89             u32 ct_en:1;
90             u32 pay_len:18;
91         } __attribute__((__packed__));
92         u64 flags;
93     };
94 } __attribute__((__packed__)) aq_tx_desc_t;
95 
96 enum aq_tx_desc_type {
97     tx_desc_type_desc = 1,
98     tx_desc_type_ctx = 2,
99 };
100 
101 enum aq_tx_desc_cmd {
102     tx_desc_cmd_vlan = 1,
103     tx_desc_cmd_fcs = 2,
104     tx_desc_cmd_ipv4 = 4,
105     tx_desc_cmd_l4cs = 8,
106     tx_desc_cmd_lso = 0x10,
107     tx_desc_cmd_wb = 0x20,
108 };
109 
110 /* Hardware tx context descriptor */
111 typedef volatile union {
112     struct __packed {
113         u64 flags1;
114         u64 flags2;
115     };
116 
117     struct __packed {
118         u64 :40;
119         u32 tun_len:8;
120         u32 out_len:16;
121         u32 type:3;
122         u32 idx:1;
123         u32 vlan_tag:16;
124         u32 cmd:4;
125         u32 l2_len:7;
126         u32 l3_len:9;
127         u32 l4_len:8;
128         u32 mss_len:16;
129     };
130 } __attribute__((__packed__)) aq_txc_desc_t;
131 
132 struct aq_ring_stats {
133 	u64 rx_pkts;
134 	u64 rx_bytes;
135 	u64 jumbo_pkts;
136 	u64 rx_err;
137 	u64 irq;
138 
139 	u64 tx_pkts;
140 	u64 tx_bytes;
141 	u64 tx_drops;
142 	u64 tx_queue_full;
143 };
144 
145 struct aq_dev;
146 
147 struct aq_ring {
148     struct aq_dev *dev;
149     int index;
150 
151     struct if_irq irq;
152     int msix;
153 /* RX */
154     qidx_t rx_size;
155     int rx_max_frame_size;
156     void *rx_desc_area_ptr;
157     aq_rx_desc_t *rx_descs;
158     uint64_t rx_descs_phys;
159 
160 /* TX */
161     int tx_head, tx_tail;
162     qidx_t tx_size;
163     void *tx_desc_area_ptr;
164     aq_tx_desc_t *tx_descs;
165     uint64_t tx_descs_phys;
166 
167     struct aq_ring_stats stats;
168 };
169 
170 int aq_ring_rx_init(struct aq_hw *hw, struct aq_ring *ring);
171 int aq_ring_tx_init(struct aq_hw *hw, struct aq_ring *ring);
172 
173 int aq_ring_tx_start(struct aq_hw *hw, struct aq_ring *ring);
174 int aq_ring_tx_stop(struct aq_hw *hw, struct aq_ring *ring);
175 int aq_ring_rx_start(struct aq_hw *hw, struct aq_ring *ring);
176 int aq_ring_rx_stop(struct aq_hw *hw, struct aq_ring *ring);
177 
178 int aq_ring_tx_tail_update(struct aq_hw *hw, struct aq_ring *ring, u32 tail);
179 
180 
181 extern struct if_txrx aq_txrx;
182 int		aq_intr(void *arg);
183 
184 #endif /* _AQ_RING_H_ */
185