xref: /src/sys/dev/aq/aq_ring.h (revision 96156003ec0c70de88a448d48d8e9bd37913589f)
1493d26c5SEd Maste /*
2493d26c5SEd Maste  * aQuantia Corporation Network Driver
3493d26c5SEd Maste  * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4493d26c5SEd Maste  *
5493d26c5SEd Maste  * Redistribution and use in source and binary forms, with or without
6493d26c5SEd Maste  * modification, are permitted provided that the following conditions
7493d26c5SEd Maste  * are met:
8493d26c5SEd Maste  *
9493d26c5SEd Maste  *   (1) Redistributions of source code must retain the above
10493d26c5SEd Maste  *   copyright notice, this list of conditions and the following
11493d26c5SEd Maste  *   disclaimer.
12493d26c5SEd Maste  *
13493d26c5SEd Maste  *   (2) Redistributions in binary form must reproduce the above
14493d26c5SEd Maste  *   copyright notice, this list of conditions and the following
15493d26c5SEd Maste  *   disclaimer in the documentation and/or other materials provided
16493d26c5SEd Maste  *   with the distribution.
17493d26c5SEd Maste  *
18493d26c5SEd Maste  *   (3)The name of the author may not be used to endorse or promote
19493d26c5SEd Maste  *   products derived from this software without specific prior
20493d26c5SEd Maste  *   written permission.
21493d26c5SEd Maste  *
22493d26c5SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23493d26c5SEd Maste  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24493d26c5SEd Maste  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25493d26c5SEd Maste  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26493d26c5SEd Maste  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27493d26c5SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28493d26c5SEd Maste  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29493d26c5SEd Maste  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30493d26c5SEd Maste  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31493d26c5SEd Maste  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32493d26c5SEd Maste  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33493d26c5SEd Maste  */
34493d26c5SEd Maste 
35493d26c5SEd Maste #ifndef _AQ_RING_H_
36493d26c5SEd Maste #define _AQ_RING_H_
37493d26c5SEd Maste 
38493d26c5SEd Maste #include "aq_hw.h"
39493d26c5SEd Maste 
40493d26c5SEd Maste #define REFILL_THRESHOLD 128
41493d26c5SEd Maste 
42493d26c5SEd Maste 
43493d26c5SEd Maste typedef volatile struct {
4496156003SEd Maste 	uint32_t rss_type:4;
4596156003SEd Maste 	uint32_t pkt_type:8;
4696156003SEd Maste 	uint32_t rdm_err:1;
4796156003SEd Maste 	uint32_t rsvd:6;
4896156003SEd Maste 	uint32_t rx_cntl:2;
4996156003SEd Maste 	uint32_t sph:1;
5096156003SEd Maste 	uint32_t hdr_len:10;
5196156003SEd Maste 	uint32_t rss_hash;
5296156003SEd Maste 	uint16_t dd:1;
5396156003SEd Maste 	uint16_t eop:1;
5496156003SEd Maste 	uint16_t rx_stat:4;
5596156003SEd Maste 	uint16_t rx_estat:6;
5696156003SEd Maste 	uint16_t rsc_cnt:4;
5796156003SEd Maste 	uint16_t pkt_len;
5896156003SEd Maste 	uint16_t next_desp;
5996156003SEd Maste 	uint16_t vlan;
60493d26c5SEd Maste } __attribute__((__packed__)) aq_rx_wb_t;
61493d26c5SEd Maste 
62493d26c5SEd Maste typedef volatile struct {
63493d26c5SEd Maste 	union {
64493d26c5SEd Maste 		/* HW RX descriptor */
65493d26c5SEd Maste 		struct __packed {
6696156003SEd Maste 			uint64_t buf_addr;
6796156003SEd Maste 			uint64_t hdr_addr;
68493d26c5SEd Maste 		} read;
69493d26c5SEd Maste 
70493d26c5SEd Maste 		/* HW RX descriptor writeback */
71493d26c5SEd Maste 		aq_rx_wb_t wb;
72493d26c5SEd Maste 	};
73493d26c5SEd Maste } __attribute__((__packed__)) aq_rx_desc_t;
74493d26c5SEd Maste 
75493d26c5SEd Maste /* Hardware tx descriptor */
76493d26c5SEd Maste typedef volatile struct {
7796156003SEd Maste 	uint64_t buf_addr;
78493d26c5SEd Maste 
79493d26c5SEd Maste 	union {
80493d26c5SEd Maste 		struct {
8196156003SEd Maste 			uint32_t type:3;
8296156003SEd Maste 			uint32_t :1;
8396156003SEd Maste 			uint32_t len:16;
8496156003SEd Maste 			uint32_t dd:1;
8596156003SEd Maste 			uint32_t eop:1;
8696156003SEd Maste 			uint32_t cmd:8;
8796156003SEd Maste 			uint32_t :14;
8896156003SEd Maste 			uint32_t ct_idx:1;
8996156003SEd Maste 			uint32_t ct_en:1;
9096156003SEd Maste 			uint32_t pay_len:18;
91493d26c5SEd Maste 		} __attribute__((__packed__));
9296156003SEd Maste 		uint64_t flags;
93493d26c5SEd Maste 	};
94493d26c5SEd Maste } __attribute__((__packed__)) aq_tx_desc_t;
95493d26c5SEd Maste 
96493d26c5SEd Maste enum aq_tx_desc_type {
97493d26c5SEd Maste 	tx_desc_type_desc = 1,
98493d26c5SEd Maste 	tx_desc_type_ctx = 2,
99493d26c5SEd Maste };
100493d26c5SEd Maste 
101493d26c5SEd Maste enum aq_tx_desc_cmd {
102493d26c5SEd Maste 	tx_desc_cmd_vlan = 1,
103493d26c5SEd Maste 	tx_desc_cmd_fcs = 2,
104493d26c5SEd Maste 	tx_desc_cmd_ipv4 = 4,
105493d26c5SEd Maste 	tx_desc_cmd_l4cs = 8,
106493d26c5SEd Maste 	tx_desc_cmd_lso = 0x10,
107493d26c5SEd Maste 	tx_desc_cmd_wb = 0x20,
108493d26c5SEd Maste };
109493d26c5SEd Maste 
110493d26c5SEd Maste /* Hardware tx context descriptor */
111493d26c5SEd Maste typedef volatile union {
112493d26c5SEd Maste 	struct __packed {
11396156003SEd Maste 		uint64_t flags1;
11496156003SEd Maste 		uint64_t flags2;
115493d26c5SEd Maste 	};
116493d26c5SEd Maste 
117493d26c5SEd Maste 	struct __packed {
11896156003SEd Maste 		uint64_t :40;
11996156003SEd Maste 		uint32_t tun_len:8;
12096156003SEd Maste 		uint32_t out_len:16;
12196156003SEd Maste 		uint32_t type:3;
12296156003SEd Maste 		uint32_t idx:1;
12396156003SEd Maste 		uint32_t vlan_tag:16;
12496156003SEd Maste 		uint32_t cmd:4;
12596156003SEd Maste 		uint32_t l2_len:7;
12696156003SEd Maste 		uint32_t l3_len:9;
12796156003SEd Maste 		uint32_t l4_len:8;
12896156003SEd Maste 		uint32_t mss_len:16;
129493d26c5SEd Maste 	};
130493d26c5SEd Maste } __attribute__((__packed__)) aq_txc_desc_t;
131493d26c5SEd Maste 
132493d26c5SEd Maste struct aq_ring_stats {
13396156003SEd Maste 	uint64_t rx_pkts;
13496156003SEd Maste 	uint64_t rx_bytes;
13596156003SEd Maste 	uint64_t jumbo_pkts;
13696156003SEd Maste 	uint64_t rx_err;
13796156003SEd Maste 	uint64_t irq;
138493d26c5SEd Maste 
13996156003SEd Maste 	uint64_t tx_pkts;
14096156003SEd Maste 	uint64_t tx_bytes;
14196156003SEd Maste 	uint64_t tx_drops;
14296156003SEd Maste 	uint64_t tx_queue_full;
143493d26c5SEd Maste };
144493d26c5SEd Maste 
145493d26c5SEd Maste struct aq_dev;
146493d26c5SEd Maste 
147493d26c5SEd Maste struct aq_ring {
148493d26c5SEd Maste 	struct aq_dev *dev;
149493d26c5SEd Maste 	int index;
150493d26c5SEd Maste 
151493d26c5SEd Maste 	struct if_irq irq;
152493d26c5SEd Maste 	int msix;
153493d26c5SEd Maste /* RX */
154493d26c5SEd Maste 	qidx_t rx_size;
155493d26c5SEd Maste 	int rx_max_frame_size;
156493d26c5SEd Maste 	void *rx_desc_area_ptr;
157493d26c5SEd Maste 	aq_rx_desc_t *rx_descs;
158493d26c5SEd Maste 	uint64_t rx_descs_phys;
159493d26c5SEd Maste 
160493d26c5SEd Maste /* TX */
161493d26c5SEd Maste 	int tx_head, tx_tail;
162493d26c5SEd Maste 	qidx_t tx_size;
163493d26c5SEd Maste 	void *tx_desc_area_ptr;
164493d26c5SEd Maste 	aq_tx_desc_t *tx_descs;
165493d26c5SEd Maste 	uint64_t tx_descs_phys;
166493d26c5SEd Maste 
167493d26c5SEd Maste 	struct aq_ring_stats stats;
168493d26c5SEd Maste };
169493d26c5SEd Maste 
170493d26c5SEd Maste int aq_ring_rx_init(struct aq_hw *hw, struct aq_ring *ring);
171493d26c5SEd Maste int aq_ring_tx_init(struct aq_hw *hw, struct aq_ring *ring);
172493d26c5SEd Maste 
173493d26c5SEd Maste int aq_ring_tx_start(struct aq_hw *hw, struct aq_ring *ring);
174493d26c5SEd Maste int aq_ring_tx_stop(struct aq_hw *hw, struct aq_ring *ring);
175493d26c5SEd Maste int aq_ring_rx_start(struct aq_hw *hw, struct aq_ring *ring);
176493d26c5SEd Maste int aq_ring_rx_stop(struct aq_hw *hw, struct aq_ring *ring);
177493d26c5SEd Maste 
17896156003SEd Maste int aq_ring_tx_tail_update(struct aq_hw *hw, struct aq_ring *ring, uint32_t tail);
179493d26c5SEd Maste 
180493d26c5SEd Maste 
181493d26c5SEd Maste extern struct if_txrx aq_txrx;
182493d26c5SEd Maste int		aq_intr(void *arg);
183493d26c5SEd Maste 
184493d26c5SEd Maste #endif /* _AQ_RING_H_ */
185