xref: /freebsd/sys/dev/qlxgbe/ql_def.h (revision 95ee2897)
1718cf2ccSPedro F. Giffuni /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
435291c22SDavid C Somayajulu  * Copyright (c) 2013-2016 Qlogic Corporation
5f10a77bbSDavid C Somayajulu  * All rights reserved.
6f10a77bbSDavid C Somayajulu  *
7f10a77bbSDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
8f10a77bbSDavid C Somayajulu  *  modification, are permitted provided that the following conditions
9f10a77bbSDavid C Somayajulu  *  are met:
10f10a77bbSDavid C Somayajulu  *
11f10a77bbSDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
12f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
13f10a77bbSDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
14f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
15f10a77bbSDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
16f10a77bbSDavid C Somayajulu  *
17f10a77bbSDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18f10a77bbSDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f10a77bbSDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f10a77bbSDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21f10a77bbSDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22f10a77bbSDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23f10a77bbSDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24f10a77bbSDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25f10a77bbSDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26f10a77bbSDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27f10a77bbSDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
28f10a77bbSDavid C Somayajulu  */
29f10a77bbSDavid C Somayajulu 
30f10a77bbSDavid C Somayajulu /*
31f10a77bbSDavid C Somayajulu  * File: ql_def.h
32f10a77bbSDavid C Somayajulu  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
33f10a77bbSDavid C Somayajulu  */
34f10a77bbSDavid C Somayajulu 
35f10a77bbSDavid C Somayajulu #ifndef _QL_DEF_H_
36f10a77bbSDavid C Somayajulu #define _QL_DEF_H_
37f10a77bbSDavid C Somayajulu 
38f10a77bbSDavid C Somayajulu #define BIT_0                   (0x1 << 0)
39f10a77bbSDavid C Somayajulu #define BIT_1                   (0x1 << 1)
40f10a77bbSDavid C Somayajulu #define BIT_2                   (0x1 << 2)
41f10a77bbSDavid C Somayajulu #define BIT_3                   (0x1 << 3)
42f10a77bbSDavid C Somayajulu #define BIT_4                   (0x1 << 4)
43f10a77bbSDavid C Somayajulu #define BIT_5                   (0x1 << 5)
44f10a77bbSDavid C Somayajulu #define BIT_6                   (0x1 << 6)
45f10a77bbSDavid C Somayajulu #define BIT_7                   (0x1 << 7)
46f10a77bbSDavid C Somayajulu #define BIT_8                   (0x1 << 8)
47f10a77bbSDavid C Somayajulu #define BIT_9                   (0x1 << 9)
48f10a77bbSDavid C Somayajulu #define BIT_10                  (0x1 << 10)
49f10a77bbSDavid C Somayajulu #define BIT_11                  (0x1 << 11)
50f10a77bbSDavid C Somayajulu #define BIT_12                  (0x1 << 12)
51f10a77bbSDavid C Somayajulu #define BIT_13                  (0x1 << 13)
52f10a77bbSDavid C Somayajulu #define BIT_14                  (0x1 << 14)
53f10a77bbSDavid C Somayajulu #define BIT_15                  (0x1 << 15)
54f10a77bbSDavid C Somayajulu #define BIT_16                  (0x1 << 16)
55f10a77bbSDavid C Somayajulu #define BIT_17                  (0x1 << 17)
56f10a77bbSDavid C Somayajulu #define BIT_18                  (0x1 << 18)
57f10a77bbSDavid C Somayajulu #define BIT_19                  (0x1 << 19)
58f10a77bbSDavid C Somayajulu #define BIT_20                  (0x1 << 20)
59f10a77bbSDavid C Somayajulu #define BIT_21                  (0x1 << 21)
60f10a77bbSDavid C Somayajulu #define BIT_22                  (0x1 << 22)
61f10a77bbSDavid C Somayajulu #define BIT_23                  (0x1 << 23)
62f10a77bbSDavid C Somayajulu #define BIT_24                  (0x1 << 24)
63f10a77bbSDavid C Somayajulu #define BIT_25                  (0x1 << 25)
64f10a77bbSDavid C Somayajulu #define BIT_26                  (0x1 << 26)
65f10a77bbSDavid C Somayajulu #define BIT_27                  (0x1 << 27)
66f10a77bbSDavid C Somayajulu #define BIT_28                  (0x1 << 28)
67f10a77bbSDavid C Somayajulu #define BIT_29                  (0x1 << 29)
68f10a77bbSDavid C Somayajulu #define BIT_30                  (0x1 << 30)
69f10a77bbSDavid C Somayajulu #define BIT_31                  (0x1 << 31)
70f10a77bbSDavid C Somayajulu 
71f10a77bbSDavid C Somayajulu struct qla_rx_buf {
72f10a77bbSDavid C Somayajulu 	struct mbuf	*m_head;
73f10a77bbSDavid C Somayajulu 	bus_dmamap_t	map;
74f10a77bbSDavid C Somayajulu 	bus_addr_t      paddr;
75f10a77bbSDavid C Somayajulu 	uint32_t	handle;
76f10a77bbSDavid C Somayajulu 	void		*next;
77f10a77bbSDavid C Somayajulu };
78f10a77bbSDavid C Somayajulu typedef struct qla_rx_buf qla_rx_buf_t;
79f10a77bbSDavid C Somayajulu 
80f10a77bbSDavid C Somayajulu struct qla_rx_ring {
81f10a77bbSDavid C Somayajulu 	qla_rx_buf_t	rx_buf[NUM_RX_DESCRIPTORS];
82f10a77bbSDavid C Somayajulu };
83f10a77bbSDavid C Somayajulu typedef struct qla_rx_ring qla_rx_ring_t;
84f10a77bbSDavid C Somayajulu 
85f10a77bbSDavid C Somayajulu struct qla_tx_buf {
86f10a77bbSDavid C Somayajulu 	struct mbuf	*m_head;
87f10a77bbSDavid C Somayajulu 	bus_dmamap_t	map;
88f10a77bbSDavid C Somayajulu };
89f10a77bbSDavid C Somayajulu typedef struct qla_tx_buf qla_tx_buf_t;
90f10a77bbSDavid C Somayajulu 
91f10a77bbSDavid C Somayajulu #define QLA_MAX_SEGMENTS	62	/* maximum # of segs in a sg list */
92f10a77bbSDavid C Somayajulu #define QLA_MAX_MTU		9000
93f10a77bbSDavid C Somayajulu #define QLA_STD_FRAME_SIZE	1514
94f10a77bbSDavid C Somayajulu #define QLA_MAX_TSO_FRAME_SIZE	((64 * 1024 - 1) + 22)
95f10a77bbSDavid C Somayajulu 
96f10a77bbSDavid C Somayajulu /* Number of MSIX/MSI Vectors required */
97f10a77bbSDavid C Somayajulu 
98f10a77bbSDavid C Somayajulu struct qla_ivec {
99f10a77bbSDavid C Somayajulu 	uint32_t		sds_idx;
100f10a77bbSDavid C Somayajulu 	void			*ha;
101f10a77bbSDavid C Somayajulu 	struct resource		*irq;
102f10a77bbSDavid C Somayajulu 	void			*handle;
103f10a77bbSDavid C Somayajulu 	int			irq_rid;
104f10a77bbSDavid C Somayajulu };
105f10a77bbSDavid C Somayajulu 
106f10a77bbSDavid C Somayajulu typedef struct qla_ivec qla_ivec_t;
107f10a77bbSDavid C Somayajulu 
10812e46badSDavid C Somayajulu #define QLA_WATCHDOG_CALLOUT_TICKS	2
109f10a77bbSDavid C Somayajulu 
110f10a77bbSDavid C Somayajulu typedef struct _qla_tx_ring {
111f10a77bbSDavid C Somayajulu 	qla_tx_buf_t	tx_buf[NUM_TX_DESCRIPTORS];
112f10a77bbSDavid C Somayajulu 	uint64_t	count;
1137fb51846SDavid C Somayajulu 	uint64_t	iscsi_pkt_count;
114f10a77bbSDavid C Somayajulu } qla_tx_ring_t;
115f10a77bbSDavid C Somayajulu 
116b89f2279SDavid C Somayajulu typedef struct _qla_tx_fp {
117b89f2279SDavid C Somayajulu 	struct mtx		tx_mtx;
118b89f2279SDavid C Somayajulu 	char			tx_mtx_name[32];
119b89f2279SDavid C Somayajulu 	struct buf_ring		*tx_br;
120b89f2279SDavid C Somayajulu 	struct task		fp_task;
121b89f2279SDavid C Somayajulu 	struct taskqueue	*fp_taskqueue;
122b89f2279SDavid C Somayajulu 	void			*ha;
123b89f2279SDavid C Somayajulu 	uint32_t		txr_idx;
124b89f2279SDavid C Somayajulu } qla_tx_fp_t;
125b89f2279SDavid C Somayajulu 
126f10a77bbSDavid C Somayajulu /*
127f1294737SGordon Bergling  * Adapter structure contains the hardware independent information of the
128f10a77bbSDavid C Somayajulu  * pci function.
129f10a77bbSDavid C Somayajulu  */
130f10a77bbSDavid C Somayajulu struct qla_host {
131f10a77bbSDavid C Somayajulu         volatile struct {
132f10a77bbSDavid C Somayajulu                 volatile uint32_t
133f10a77bbSDavid C Somayajulu 			qla_callout_init	:1,
134f10a77bbSDavid C Somayajulu 			qla_watchdog_active	:1,
135f10a77bbSDavid C Somayajulu 			parent_tag		:1,
136f10a77bbSDavid C Somayajulu 			lock_init		:1;
137f10a77bbSDavid C Somayajulu         } flags;
138f10a77bbSDavid C Somayajulu 
1397fb51846SDavid C Somayajulu 	volatile uint32_t	qla_interface_up;
1407fb51846SDavid C Somayajulu 	volatile uint32_t	stop_rcv;
1417fb51846SDavid C Somayajulu 	volatile uint32_t	qla_watchdog_exit;
142f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_watchdog_exited;
1437fb51846SDavid C Somayajulu 	volatile uint32_t	qla_watchdog_pause;
144f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_watchdog_paused;
145f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_initiate_recovery;
1467fb51846SDavid C Somayajulu 	volatile uint32_t	qla_detach_active;
147b65c0c07SDavid C Somayajulu 	volatile uint32_t	offline;
148f10a77bbSDavid C Somayajulu 
149f10a77bbSDavid C Somayajulu 	device_t		pci_dev;
150f10a77bbSDavid C Somayajulu 
151b65c0c07SDavid C Somayajulu 	volatile uint16_t	watchdog_ticks;
152f10a77bbSDavid C Somayajulu 	uint8_t			pci_func;
153f10a77bbSDavid C Somayajulu 
154f10a77bbSDavid C Somayajulu         /* ioctl related */
155f10a77bbSDavid C Somayajulu         struct cdev             *ioctl_dev;
156f10a77bbSDavid C Somayajulu 
157f10a77bbSDavid C Somayajulu 	/* register mapping */
158f10a77bbSDavid C Somayajulu 	struct resource		*pci_reg;
159f10a77bbSDavid C Somayajulu 	int			reg_rid;
160f10a77bbSDavid C Somayajulu 	struct resource		*pci_reg1;
161f10a77bbSDavid C Somayajulu 	int			reg_rid1;
162f10a77bbSDavid C Somayajulu 
163f10a77bbSDavid C Somayajulu 	/* interrupts */
164f10a77bbSDavid C Somayajulu 	struct resource         *mbx_irq;
165f10a77bbSDavid C Somayajulu 	void			*mbx_handle;
166f10a77bbSDavid C Somayajulu 	int			mbx_irq_rid;
167f10a77bbSDavid C Somayajulu 
168f10a77bbSDavid C Somayajulu 	int			msix_count;
169f10a77bbSDavid C Somayajulu 
170f10a77bbSDavid C Somayajulu 	qla_ivec_t		irq_vec[MAX_SDS_RINGS];
171f10a77bbSDavid C Somayajulu 
172f10a77bbSDavid C Somayajulu 	/* parent dma tag */
173f10a77bbSDavid C Somayajulu 	bus_dma_tag_t           parent_tag;
174f10a77bbSDavid C Somayajulu 
175f10a77bbSDavid C Somayajulu 	/* interface to o.s */
17654ab3b4aSJustin Hibbits 	if_t			ifp;
177f10a77bbSDavid C Somayajulu 
178f10a77bbSDavid C Somayajulu 	struct ifmedia		media;
179f10a77bbSDavid C Somayajulu 	uint16_t		max_frame_size;
180f10a77bbSDavid C Somayajulu 	uint16_t		rsrvd0;
181f10a77bbSDavid C Somayajulu 	int			if_flags;
182f10a77bbSDavid C Somayajulu 
183f10a77bbSDavid C Somayajulu 	/* hardware access lock */
184f10a77bbSDavid C Somayajulu 
185b65c0c07SDavid C Somayajulu 	struct mtx		sp_log_lock;
186f10a77bbSDavid C Somayajulu 	struct mtx		hw_lock;
187f10a77bbSDavid C Somayajulu 	volatile uint32_t	hw_lock_held;
1887fb51846SDavid C Somayajulu 	uint64_t		hw_lock_failed;
189f10a77bbSDavid C Somayajulu 
190f10a77bbSDavid C Somayajulu 	/* transmit and receive buffers */
191f10a77bbSDavid C Somayajulu 	uint32_t		txr_idx; /* index of the current tx ring */
192f10a77bbSDavid C Somayajulu 	qla_tx_ring_t		tx_ring[NUM_TX_RINGS];
193f10a77bbSDavid C Somayajulu 
194f10a77bbSDavid C Somayajulu 	bus_dma_tag_t		tx_tag;
195f10a77bbSDavid C Somayajulu 	struct callout		tx_callout;
196b89f2279SDavid C Somayajulu 
197b89f2279SDavid C Somayajulu 	qla_tx_fp_t		tx_fp[MAX_SDS_RINGS];
198f10a77bbSDavid C Somayajulu 
199f10a77bbSDavid C Somayajulu 	qla_rx_ring_t		rx_ring[MAX_RDS_RINGS];
200f10a77bbSDavid C Somayajulu 	bus_dma_tag_t		rx_tag;
201f10a77bbSDavid C Somayajulu 	uint32_t		std_replenish;
202f10a77bbSDavid C Somayajulu 
203f10a77bbSDavid C Somayajulu 	qla_rx_buf_t		*rxb_free;
204f10a77bbSDavid C Somayajulu 	uint32_t		rxb_free_count;
205f10a77bbSDavid C Somayajulu 
206f10a77bbSDavid C Somayajulu 	/* stats */
207f10a77bbSDavid C Somayajulu 	uint32_t		err_m_getcl;
208f10a77bbSDavid C Somayajulu 	uint32_t		err_m_getjcl;
209f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_dmamap_create;
210f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_dmamap_load;
211f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_defrag;
212f10a77bbSDavid C Somayajulu 
213f10a77bbSDavid C Somayajulu 	uint64_t		rx_frames;
214f10a77bbSDavid C Somayajulu 	uint64_t		rx_bytes;
215f10a77bbSDavid C Somayajulu 
216f10a77bbSDavid C Somayajulu 	uint64_t		lro_pkt_count;
217f10a77bbSDavid C Somayajulu 	uint64_t		lro_bytes;
218f10a77bbSDavid C Somayajulu 
219f10a77bbSDavid C Somayajulu 	uint64_t		ipv4_lro;
220f10a77bbSDavid C Somayajulu 	uint64_t		ipv6_lro;
221f10a77bbSDavid C Somayajulu 
222f10a77bbSDavid C Somayajulu 	uint64_t		tx_frames;
223f10a77bbSDavid C Somayajulu 	uint64_t		tx_bytes;
224f10a77bbSDavid C Somayajulu 	uint64_t		tx_tso_frames;
225f10a77bbSDavid C Somayajulu 	uint64_t		hw_vlan_tx_frames;
226f10a77bbSDavid C Somayajulu 
2277fb51846SDavid C Somayajulu 	struct task             stats_task;
2287fb51846SDavid C Somayajulu 	struct taskqueue	*stats_tq;
2297fb51846SDavid C Somayajulu 
230f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_major;
231f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_minor;
232f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_sub;
233f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_build;
234f10a77bbSDavid C Somayajulu 
235f10a77bbSDavid C Somayajulu 	/* hardware specific */
236f10a77bbSDavid C Somayajulu 	qla_hw_t		hw;
237f10a77bbSDavid C Somayajulu 
238f10a77bbSDavid C Somayajulu 	/* debug stuff */
239f10a77bbSDavid C Somayajulu 	volatile const char 	*qla_lock;
240f10a77bbSDavid C Somayajulu 	volatile const char	*qla_unlock;
241f10a77bbSDavid C Somayajulu 	uint32_t		dbg_level;
2421faeac0fSDavid C Somayajulu 	uint32_t		enable_minidump;
243b65c0c07SDavid C Somayajulu 	uint32_t		enable_driverstate_dump;
244b65c0c07SDavid C Somayajulu 	uint32_t		enable_error_recovery;
245b65c0c07SDavid C Somayajulu 	uint32_t		ms_delay_after_init;
246f10a77bbSDavid C Somayajulu 
247f10a77bbSDavid C Somayajulu 	uint8_t			fw_ver_str[32];
248f10a77bbSDavid C Somayajulu 
249f10a77bbSDavid C Somayajulu 	/* Error Injection Related */
250f10a77bbSDavid C Somayajulu 	uint32_t		err_inject;
251f10a77bbSDavid C Somayajulu 	struct task		err_task;
252f10a77bbSDavid C Somayajulu 	struct taskqueue	*err_tq;
253f10a77bbSDavid C Somayajulu 
25435291c22SDavid C Somayajulu 	/* Async Event Related */
25535291c22SDavid C Somayajulu 	uint32_t                async_event;
25635291c22SDavid C Somayajulu 	struct task             async_event_task;
25735291c22SDavid C Somayajulu 	struct taskqueue        *async_event_tq;
25835291c22SDavid C Somayajulu 
259f10a77bbSDavid C Somayajulu 	/* Peer Device */
260f10a77bbSDavid C Somayajulu 	device_t		peer_dev;
261f10a77bbSDavid C Somayajulu 
262f10a77bbSDavid C Somayajulu 	volatile uint32_t	msg_from_peer;
263f10a77bbSDavid C Somayajulu #define QL_PEER_MSG_RESET	0x01
264f10a77bbSDavid C Somayajulu #define QL_PEER_MSG_ACK		0x02
265f10a77bbSDavid C Somayajulu 
266f10a77bbSDavid C Somayajulu };
267f10a77bbSDavid C Somayajulu typedef struct qla_host qla_host_t;
268f10a77bbSDavid C Somayajulu 
269f10a77bbSDavid C Somayajulu /* note that align has to be a power of 2 */
270dd00a8cdSRyan Libby #define QL_ALIGN(size, align) (((size) + ((align) - 1)) & (~((align) - 1)))
271f10a77bbSDavid C Somayajulu #define QL_MIN(x, y) ((x < y) ? x : y)
272f10a77bbSDavid C Somayajulu 
27354ab3b4aSJustin Hibbits #define QL_RUNNING(ifp) (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
274f10a77bbSDavid C Somayajulu 
275f10a77bbSDavid C Somayajulu /* Return 0, if identical, else 1 */
276f10a77bbSDavid C Somayajulu #define QL_MAC_CMP(mac1, mac2)    \
277f10a77bbSDavid C Somayajulu 	((((*(uint32_t *) mac1) == (*(uint32_t *) mac2) && \
278f10a77bbSDavid C Somayajulu 	(*(uint16_t *)(mac1 + 4)) == (*(uint16_t *)(mac2 + 4)))) ? 0 : 1)
279f10a77bbSDavid C Somayajulu 
280b65c0c07SDavid C Somayajulu #define QL_INITIATE_RECOVERY(ha) qla_set_error_recovery(ha)
281b65c0c07SDavid C Somayajulu 
282f10a77bbSDavid C Somayajulu #endif /* #ifndef _QL_DEF_H_ */
283