xref: /freebsd/sys/dev/qlxgbe/ql_def.h (revision 35291c22)
1f10a77bbSDavid C Somayajulu /*
235291c22SDavid C Somayajulu  * Copyright (c) 2013-2016 Qlogic Corporation
3f10a77bbSDavid C Somayajulu  * All rights reserved.
4f10a77bbSDavid C Somayajulu  *
5f10a77bbSDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
6f10a77bbSDavid C Somayajulu  *  modification, are permitted provided that the following conditions
7f10a77bbSDavid C Somayajulu  *  are met:
8f10a77bbSDavid C Somayajulu  *
9f10a77bbSDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
10f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
11f10a77bbSDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
12f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
13f10a77bbSDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
14f10a77bbSDavid C Somayajulu  *
15f10a77bbSDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16f10a77bbSDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17f10a77bbSDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18f10a77bbSDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19f10a77bbSDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20f10a77bbSDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21f10a77bbSDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22f10a77bbSDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23f10a77bbSDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24f10a77bbSDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25f10a77bbSDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
26f10a77bbSDavid C Somayajulu  *
27f10a77bbSDavid C Somayajulu  * $FreeBSD$
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 
108f10a77bbSDavid C Somayajulu #define QLA_WATCHDOG_CALLOUT_TICKS	1
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;
113f10a77bbSDavid C Somayajulu } qla_tx_ring_t;
114f10a77bbSDavid C Somayajulu 
115f10a77bbSDavid C Somayajulu /*
116f10a77bbSDavid C Somayajulu  * Adapter structure contains the hardware independant information of the
117f10a77bbSDavid C Somayajulu  * pci function.
118f10a77bbSDavid C Somayajulu  */
119f10a77bbSDavid C Somayajulu struct qla_host {
120f10a77bbSDavid C Somayajulu         volatile struct {
121f10a77bbSDavid C Somayajulu                 volatile uint32_t
122f10a77bbSDavid C Somayajulu 			qla_callout_init	:1,
123f10a77bbSDavid C Somayajulu 			qla_watchdog_active	:1,
124f10a77bbSDavid C Somayajulu 			qla_watchdog_exit	:1,
125f10a77bbSDavid C Somayajulu 			qla_watchdog_pause	:1,
126f10a77bbSDavid C Somayajulu 			lro_init		:1,
127f10a77bbSDavid C Somayajulu 			stop_rcv		:1,
128f10a77bbSDavid C Somayajulu 			parent_tag		:1,
129f10a77bbSDavid C Somayajulu 			lock_init		:1;
130f10a77bbSDavid C Somayajulu         } flags;
131f10a77bbSDavid C Somayajulu 
132f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_watchdog_exited;
133f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_watchdog_paused;
134f10a77bbSDavid C Somayajulu 	volatile uint32_t	qla_initiate_recovery;
135f10a77bbSDavid C Somayajulu 
136f10a77bbSDavid C Somayajulu 	device_t		pci_dev;
137f10a77bbSDavid C Somayajulu 
138f10a77bbSDavid C Somayajulu 	uint16_t		watchdog_ticks;
139f10a77bbSDavid C Somayajulu 	uint8_t			pci_func;
140f10a77bbSDavid C Somayajulu 	uint8_t			resvd;
141f10a77bbSDavid C Somayajulu 
142f10a77bbSDavid C Somayajulu         /* ioctl related */
143f10a77bbSDavid C Somayajulu         struct cdev             *ioctl_dev;
144f10a77bbSDavid C Somayajulu 
145f10a77bbSDavid C Somayajulu 	/* register mapping */
146f10a77bbSDavid C Somayajulu 	struct resource		*pci_reg;
147f10a77bbSDavid C Somayajulu 	int			reg_rid;
148f10a77bbSDavid C Somayajulu 	struct resource		*pci_reg1;
149f10a77bbSDavid C Somayajulu 	int			reg_rid1;
150f10a77bbSDavid C Somayajulu 
151f10a77bbSDavid C Somayajulu 	/* interrupts */
152f10a77bbSDavid C Somayajulu 	struct resource         *mbx_irq;
153f10a77bbSDavid C Somayajulu 	void			*mbx_handle;
154f10a77bbSDavid C Somayajulu 	int			mbx_irq_rid;
155f10a77bbSDavid C Somayajulu 
156f10a77bbSDavid C Somayajulu 	int			msix_count;
157f10a77bbSDavid C Somayajulu 
158f10a77bbSDavid C Somayajulu 	qla_ivec_t		irq_vec[MAX_SDS_RINGS];
159f10a77bbSDavid C Somayajulu 
160f10a77bbSDavid C Somayajulu 	/* parent dma tag */
161f10a77bbSDavid C Somayajulu 	bus_dma_tag_t           parent_tag;
162f10a77bbSDavid C Somayajulu 
163f10a77bbSDavid C Somayajulu 	/* interface to o.s */
164f10a77bbSDavid C Somayajulu 	struct ifnet		*ifp;
165f10a77bbSDavid C Somayajulu 
166f10a77bbSDavid C Somayajulu 	struct ifmedia		media;
167f10a77bbSDavid C Somayajulu 	uint16_t		max_frame_size;
168f10a77bbSDavid C Somayajulu 	uint16_t		rsrvd0;
169f10a77bbSDavid C Somayajulu 	int			if_flags;
170f10a77bbSDavid C Somayajulu 
171f10a77bbSDavid C Somayajulu 	/* hardware access lock */
172f10a77bbSDavid C Somayajulu 
173f10a77bbSDavid C Somayajulu 	struct mtx		hw_lock;
174f10a77bbSDavid C Somayajulu 	volatile uint32_t	hw_lock_held;
175f10a77bbSDavid C Somayajulu 
176f10a77bbSDavid C Somayajulu 	/* transmit and receive buffers */
177f10a77bbSDavid C Somayajulu 	uint32_t		txr_idx; /* index of the current tx ring */
178f10a77bbSDavid C Somayajulu 	qla_tx_ring_t		tx_ring[NUM_TX_RINGS];
179f10a77bbSDavid C Somayajulu 
180f10a77bbSDavid C Somayajulu 	bus_dma_tag_t		tx_tag;
181f10a77bbSDavid C Somayajulu 	struct task		tx_task;
182f10a77bbSDavid C Somayajulu 	struct taskqueue	*tx_tq;
183f10a77bbSDavid C Somayajulu 	struct callout		tx_callout;
184f10a77bbSDavid C Somayajulu 	struct mtx		tx_lock;
185f10a77bbSDavid C Somayajulu 
186f10a77bbSDavid C Somayajulu 	qla_rx_ring_t		rx_ring[MAX_RDS_RINGS];
187f10a77bbSDavid C Somayajulu 	bus_dma_tag_t		rx_tag;
188f10a77bbSDavid C Somayajulu 	uint32_t		std_replenish;
189f10a77bbSDavid C Somayajulu 
190f10a77bbSDavid C Somayajulu 	qla_rx_buf_t		*rxb_free;
191f10a77bbSDavid C Somayajulu 	uint32_t		rxb_free_count;
192f10a77bbSDavid C Somayajulu 	volatile uint32_t	posting;
193f10a77bbSDavid C Somayajulu 
194f10a77bbSDavid C Somayajulu 	/* stats */
195f10a77bbSDavid C Somayajulu 	uint32_t		err_m_getcl;
196f10a77bbSDavid C Somayajulu 	uint32_t		err_m_getjcl;
197f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_dmamap_create;
198f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_dmamap_load;
199f10a77bbSDavid C Somayajulu 	uint32_t		err_tx_defrag;
200f10a77bbSDavid C Somayajulu 
201f10a77bbSDavid C Somayajulu 	uint64_t		rx_frames;
202f10a77bbSDavid C Somayajulu 	uint64_t		rx_bytes;
203f10a77bbSDavid C Somayajulu 
204f10a77bbSDavid C Somayajulu 	uint64_t		lro_pkt_count;
205f10a77bbSDavid C Somayajulu 	uint64_t		lro_bytes;
206f10a77bbSDavid C Somayajulu 
207f10a77bbSDavid C Somayajulu 	uint64_t		ipv4_lro;
208f10a77bbSDavid C Somayajulu 	uint64_t		ipv6_lro;
209f10a77bbSDavid C Somayajulu 
210f10a77bbSDavid C Somayajulu 	uint64_t		tx_frames;
211f10a77bbSDavid C Somayajulu 	uint64_t		tx_bytes;
212f10a77bbSDavid C Somayajulu 	uint64_t		tx_tso_frames;
213f10a77bbSDavid C Somayajulu 	uint64_t		hw_vlan_tx_frames;
214f10a77bbSDavid C Somayajulu 
215f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_major;
216f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_minor;
217f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_sub;
218f10a77bbSDavid C Somayajulu         uint32_t                fw_ver_build;
219f10a77bbSDavid C Somayajulu 
220f10a77bbSDavid C Somayajulu 	/* hardware specific */
221f10a77bbSDavid C Somayajulu 	qla_hw_t		hw;
222f10a77bbSDavid C Somayajulu 
223f10a77bbSDavid C Somayajulu 	/* debug stuff */
224f10a77bbSDavid C Somayajulu 	volatile const char 	*qla_lock;
225f10a77bbSDavid C Somayajulu 	volatile const char	*qla_unlock;
226f10a77bbSDavid C Somayajulu 	uint32_t		dbg_level;
227f10a77bbSDavid C Somayajulu 
228f10a77bbSDavid C Somayajulu 	uint8_t			fw_ver_str[32];
229f10a77bbSDavid C Somayajulu 
230f10a77bbSDavid C Somayajulu 	/* Error Injection Related */
231f10a77bbSDavid C Somayajulu 	uint32_t		err_inject;
232f10a77bbSDavid C Somayajulu 	struct task		err_task;
233f10a77bbSDavid C Somayajulu 	struct taskqueue	*err_tq;
234f10a77bbSDavid C Somayajulu 
23535291c22SDavid C Somayajulu 	/* Async Event Related */
23635291c22SDavid C Somayajulu 	uint32_t                async_event;
23735291c22SDavid C Somayajulu 	struct task             async_event_task;
23835291c22SDavid C Somayajulu 	struct taskqueue        *async_event_tq;
23935291c22SDavid C Somayajulu 
240f10a77bbSDavid C Somayajulu 	/* Peer Device */
241f10a77bbSDavid C Somayajulu 	device_t		peer_dev;
242f10a77bbSDavid C Somayajulu 
243f10a77bbSDavid C Somayajulu 	volatile uint32_t	msg_from_peer;
244f10a77bbSDavid C Somayajulu #define QL_PEER_MSG_RESET	0x01
245f10a77bbSDavid C Somayajulu #define QL_PEER_MSG_ACK		0x02
246f10a77bbSDavid C Somayajulu 
247f10a77bbSDavid C Somayajulu };
248f10a77bbSDavid C Somayajulu typedef struct qla_host qla_host_t;
249f10a77bbSDavid C Somayajulu 
250f10a77bbSDavid C Somayajulu /* note that align has to be a power of 2 */
251f10a77bbSDavid C Somayajulu #define QL_ALIGN(size, align) (size + (align - 1)) & ~(align - 1);
252f10a77bbSDavid C Somayajulu #define QL_MIN(x, y) ((x < y) ? x : y)
253f10a77bbSDavid C Somayajulu 
254f10a77bbSDavid C Somayajulu #define QL_RUNNING(ifp) \
255f10a77bbSDavid C Somayajulu 		((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) == \
256f10a77bbSDavid C Somayajulu 			IFF_DRV_RUNNING)
257f10a77bbSDavid C Somayajulu 
258f10a77bbSDavid C Somayajulu /* Return 0, if identical, else 1 */
259f10a77bbSDavid C Somayajulu #define QL_MAC_CMP(mac1, mac2)    \
260f10a77bbSDavid C Somayajulu 	((((*(uint32_t *) mac1) == (*(uint32_t *) mac2) && \
261f10a77bbSDavid C Somayajulu 	(*(uint16_t *)(mac1 + 4)) == (*(uint16_t *)(mac2 + 4)))) ? 0 : 1)
262f10a77bbSDavid C Somayajulu 
263f10a77bbSDavid C Somayajulu #endif /* #ifndef _QL_DEF_H_ */
264