1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
88f23e9faSHans Rosenfeld  * You can obtain a copy of the license at
98f23e9faSHans Rosenfeld  * http://www.opensource.org/licenses/cddl1.txt.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte 
22fcf3ce44SJohn Forte /*
238f23e9faSHans Rosenfeld  * Copyright (c) 2004-2012 Emulex. All rights reserved.
2482527734SSukumar Swaminathan  * Use is subject to license terms.
25*a3170057SPaul Winder  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
26*a3170057SPaul Winder  * Copyright 2020 RackTop Systems, Inc.
27fcf3ce44SJohn Forte  */
28fcf3ce44SJohn Forte 
29fcf3ce44SJohn Forte #ifndef _EMLXS_FC_H
30fcf3ce44SJohn Forte #define	_EMLXS_FC_H
31fcf3ce44SJohn Forte 
32fcf3ce44SJohn Forte #ifdef	__cplusplus
33fcf3ce44SJohn Forte extern "C" {
34fcf3ce44SJohn Forte #endif
35fcf3ce44SJohn Forte 
36291a2b48SSukumar Swaminathan typedef struct emlxs_buf
37291a2b48SSukumar Swaminathan {
38291a2b48SSukumar Swaminathan 	fc_packet_t		*pkt;		/* scsi_pkt reference */
39291a2b48SSukumar Swaminathan 	struct emlxs_port	*port;		/* pointer to port */
40291a2b48SSukumar Swaminathan 	void			*bmp;		/* Save the buffer pointer */
41291a2b48SSukumar Swaminathan 						/* list for later use. */
42291a2b48SSukumar Swaminathan 	struct emlxs_buf	*fc_fwd;	/* Use it by chip_Q */
43291a2b48SSukumar Swaminathan 	struct emlxs_buf	*fc_bkwd;	/* Use it by chip_Q */
44291a2b48SSukumar Swaminathan 	struct emlxs_buf	*next;		/* Use it when the iodone */
45a9800bebSGarrett D'Amore 	struct emlxs_node 	*node;
4682527734SSukumar Swaminathan 	void			*channel;	/* Save channel and used by */
47291a2b48SSukumar Swaminathan 						/* abort */
4882527734SSukumar Swaminathan 	struct emlxs_buf	*fpkt;		/* Flush pkt pointer */
49a9800bebSGarrett D'Amore 	struct XRIobj		*xrip;		/* Exchange resource */
50291a2b48SSukumar Swaminathan 	IOCBQ			iocbq;
51291a2b48SSukumar Swaminathan 	kmutex_t		mtx;
52291a2b48SSukumar Swaminathan 	uint32_t		pkt_flags;
53291a2b48SSukumar Swaminathan 	uint32_t		iotag;		/* iotag for this cmd */
54291a2b48SSukumar Swaminathan 	uint32_t		ticks;		/* save the timeout ticks */
55291a2b48SSukumar Swaminathan 						/* for the fc_packet_t */
56291a2b48SSukumar Swaminathan 	uint32_t		abort_attempts;
57a9800bebSGarrett D'Amore 	uint32_t		lun;
58a9800bebSGarrett D'Amore #define	EMLXS_LUN_NONE		0xFFFFFFFF
59a9800bebSGarrett D'Amore 
60291a2b48SSukumar Swaminathan 	uint32_t		class;		/* Save class and used by */
61291a2b48SSukumar Swaminathan 						/* abort */
62291a2b48SSukumar Swaminathan 	uint32_t		ucmd;		/* Unsolicted command that */
63291a2b48SSukumar Swaminathan 						/* this packet is responding */
64291a2b48SSukumar Swaminathan 						/* to, if any */
65291a2b48SSukumar Swaminathan 	int32_t			flush_count;	/* Valid only in flush pkts */
66291a2b48SSukumar Swaminathan 	uint32_t		did;
67fcf3ce44SJohn Forte 
68fcf3ce44SJohn Forte #ifdef SFCT_SUPPORT
69291a2b48SSukumar Swaminathan 	kmutex_t		fct_mtx;
70291a2b48SSukumar Swaminathan 	fc_packet_t		*fct_pkt;
71291a2b48SSukumar Swaminathan 	fct_cmd_t		*fct_cmd;
72fcf3ce44SJohn Forte 
73291a2b48SSukumar Swaminathan 	uint8_t			fct_type;
74fcf3ce44SJohn Forte 
75fcf3ce44SJohn Forte #define	EMLXS_FCT_ELS_CMD		0x01	/* Unsolicted */
76fcf3ce44SJohn Forte #define	EMLXS_FCT_ELS_REQ		0x02	/* Solicited */
77fcf3ce44SJohn Forte #define	EMLXS_FCT_ELS_RSP		0x04
78fcf3ce44SJohn Forte #define	EMLXS_FCT_CT_REQ		0x08	/* Solicited */
79fcf3ce44SJohn Forte #define	EMLXS_FCT_FCP_CMD		0x10	/* Unsolicted */
80fcf3ce44SJohn Forte #define	EMLXS_FCT_FCP_DATA		0x20
81fcf3ce44SJohn Forte #define	EMLXS_FCT_FCP_STATUS		0x40
82fcf3ce44SJohn Forte 
83fcf3ce44SJohn Forte 
84291a2b48SSukumar Swaminathan 	uint8_t			fct_flags;
85fcf3ce44SJohn Forte 
86fcf3ce44SJohn Forte #define	EMLXS_FCT_SEND_STATUS		0x01
8782527734SSukumar Swaminathan #define	EMLXS_FCT_ABORT_INP		0x02
8882527734SSukumar Swaminathan #define	EMLXS_FCT_IO_INP		0x04
89a9800bebSGarrett D'Amore #define	EMLXS_FCT_PLOGI_RECEIVED	0x10
90a9800bebSGarrett D'Amore #define	EMLXS_FCT_REGISTERED		0x20
91291a2b48SSukumar Swaminathan 
92291a2b48SSukumar Swaminathan 	uint16_t		fct_state;
93291a2b48SSukumar Swaminathan 
94291a2b48SSukumar Swaminathan #define	EMLXS_FCT_FCP_CMD_RECEIVED	1
95291a2b48SSukumar Swaminathan #define	EMLXS_FCT_ELS_CMD_RECEIVED	2
96291a2b48SSukumar Swaminathan #define	EMLXS_FCT_CMD_POSTED		3
97291a2b48SSukumar Swaminathan #define	EMLXS_FCT_CMD_WAITQ		4
9882527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_CMD_RSP		5
9982527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_ELS_RSP		6
10082527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_ELS_REQ		7
10182527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_CT_REQ		8
10282527734SSukumar Swaminathan #define	EMLXS_FCT_RSP_PENDING		9
10382527734SSukumar Swaminathan #define	EMLXS_FCT_REQ_PENDING		10
10482527734SSukumar Swaminathan #define	EMLXS_FCT_REG_PENDING		11
10582527734SSukumar Swaminathan #define	EMLXS_FCT_REG_COMPLETE		12
10682527734SSukumar Swaminathan #define	EMLXS_FCT_OWNED			13
10782527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_FCP_DATA		14
10882527734SSukumar Swaminathan #define	EMLXS_FCT_SEND_FCP_STATUS	15
10982527734SSukumar Swaminathan #define	EMLXS_FCT_DATA_PENDING		16
11082527734SSukumar Swaminathan #define	EMLXS_FCT_STATUS_PENDING	17
11182527734SSukumar Swaminathan #define	EMLXS_FCT_PKT_COMPLETE		18
11282527734SSukumar Swaminathan #define	EMLXS_FCT_PKT_FCPRSP_COMPLETE	19
11382527734SSukumar Swaminathan #define	EMLXS_FCT_PKT_ELSRSP_COMPLETE	20
11482527734SSukumar Swaminathan #define	EMLXS_FCT_PKT_ELSCMD_COMPLETE	21
11582527734SSukumar Swaminathan #define	EMLXS_FCT_PKT_CTCMD_COMPLETE	22
11682527734SSukumar Swaminathan #define	EMLXS_FCT_REQ_COMPLETE		23
11782527734SSukumar Swaminathan #define	EMLXS_FCT_CLOSE_PENDING		24
11882527734SSukumar Swaminathan #define	EMLXS_FCT_ABORT_PENDING		25
11982527734SSukumar Swaminathan #define	EMLXS_FCT_ABORT_DONE		26
12082527734SSukumar Swaminathan #define	EMLXS_FCT_IO_DONE		27
12182527734SSukumar Swaminathan 
12282527734SSukumar Swaminathan #define	EMLXS_FCT_IOCB_ISSUED		256 /* For tracing only */
12382527734SSukumar Swaminathan #define	EMLXS_FCT_IOCB_COMPLETE		257 /* For tracing only */
124291a2b48SSukumar Swaminathan 
125291a2b48SSukumar Swaminathan 	stmf_data_buf_t		*fct_buf;
126291a2b48SSukumar Swaminathan 
127291a2b48SSukumar Swaminathan #endif /* SFCT_SUPPORT */
128291a2b48SSukumar Swaminathan 
129291a2b48SSukumar Swaminathan #ifdef SAN_DIAG_SUPPORT
130291a2b48SSukumar Swaminathan 	hrtime_t		sd_start_time;
1318f23e9faSHans Rosenfeld #endif /* SAN_DIAG_SUPPORT */
1328f23e9faSHans Rosenfeld 
133291a2b48SSukumar Swaminathan } emlxs_buf_t;
134fcf3ce44SJohn Forte 
135fcf3ce44SJohn Forte 
136fcf3ce44SJohn Forte 
137291a2b48SSukumar Swaminathan #ifdef FCT_IO_TRACE
13882527734SSukumar Swaminathan #define	EMLXS_FCT_STATE_CHG(_fct_cmd, _cmd_sbp, _state)	\
13982527734SSukumar Swaminathan 	(_cmd_sbp)->fct_state = _state;			\
14082527734SSukumar Swaminathan 	emlxs_fct_io_trace((_cmd_sbp)->port, _fct_cmd, _state)
141291a2b48SSukumar Swaminathan #else
142291a2b48SSukumar Swaminathan /* define to set fct_state */
14382527734SSukumar Swaminathan #define	EMLXS_FCT_STATE_CHG(_fct_cmd, _cmd_sbp, _state)	\
14482527734SSukumar Swaminathan 	(_cmd_sbp)->fct_state = _state
145291a2b48SSukumar Swaminathan #endif /* FCT_IO_TRACE */
146fcf3ce44SJohn Forte 
147fcf3ce44SJohn Forte 
148fcf3ce44SJohn Forte /* pkt_flags */
149fcf3ce44SJohn Forte #define	PACKET_IN_COMPLETION	0x00000001
150fcf3ce44SJohn Forte #define	PACKET_IN_TXQ		0x00000002
151fcf3ce44SJohn Forte #define	PACKET_IN_CHIPQ		0x00000004
152fcf3ce44SJohn Forte #define	PACKET_IN_DONEQ		0x00000008
153fcf3ce44SJohn Forte 
154fcf3ce44SJohn Forte #define	PACKET_FCP_RESET	0x00000030
155fcf3ce44SJohn Forte #define	PACKET_FCP_TGT_RESET	0x00000010
156fcf3ce44SJohn Forte #define	PACKET_FCP_LUN_RESET	0x00000020
157fcf3ce44SJohn Forte #define	PACKET_POLLED		0x00000040
158fcf3ce44SJohn Forte 
159fcf3ce44SJohn Forte #ifdef EMLXS_I386
160fcf3ce44SJohn Forte #define	PACKET_FCP_SWAPPED	0x00000100
161fcf3ce44SJohn Forte #define	PACKET_ELS_SWAPPED	0x00000200
162fcf3ce44SJohn Forte #define	PACKET_CT_SWAPPED	0x00000400
163fcf3ce44SJohn Forte #define	PACKET_CSP_SWAPPED	0x00000800
164fcf3ce44SJohn Forte #endif	/* EMLXS_I386 */
165fcf3ce44SJohn Forte 
166fcf3ce44SJohn Forte #define	PACKET_STALE		0x00001000
167fcf3ce44SJohn Forte 
168fcf3ce44SJohn Forte #define	PACKET_IN_TIMEOUT	0x00010000
169fcf3ce44SJohn Forte #define	PACKET_IN_FLUSH		0x00020000
170fcf3ce44SJohn Forte #define	PACKET_IN_ABORT		0x00040000
171e2ca2865SSukumar Swaminathan #define	PACKET_XRI_CLOSED	0x00080000 /* An XRI abort/close was issued */
172fcf3ce44SJohn Forte 
173fcf3ce44SJohn Forte #define	PACKET_CHIP_COMP	0x00100000
174fcf3ce44SJohn Forte #define	PACKET_COMPLETED	0x00200000
17582527734SSukumar Swaminathan #define	PACKET_ULP_OWNED	0x00400000
176fcf3ce44SJohn Forte 
177fcf3ce44SJohn Forte #define	PACKET_STATE_VALID	0x01000000
178fcf3ce44SJohn Forte #define	PACKET_FCP_RSP_VALID	0x02000000
179fcf3ce44SJohn Forte #define	PACKET_ELS_RSP_VALID	0x04000000
180fcf3ce44SJohn Forte #define	PACKET_CT_RSP_VALID	0x08000000
181fcf3ce44SJohn Forte 
182fcf3ce44SJohn Forte #define	PACKET_DELAY_REQUIRED	0x10000000
183fcf3ce44SJohn Forte #define	PACKET_ALLOCATED	0x40000000
184fcf3ce44SJohn Forte #define	PACKET_VALID		0x80000000
185fcf3ce44SJohn Forte 
186fcf3ce44SJohn Forte 
187fcf3ce44SJohn Forte #define	STALE_PACKET		((emlxs_buf_t *)0xFFFFFFFF)
188fcf3ce44SJohn Forte 
189fcf3ce44SJohn Forte 
190fcf3ce44SJohn Forte /*
191fcf3ce44SJohn Forte  * From fc_error.h pkt_reason (except for state = NPORT_RJT, FABRIC_RJT,
192fcf3ce44SJohn Forte  * NPORT_BSY, FABRIC_BSY, LS_RJT, BA_RJT, FS_RJT)
193fcf3ce44SJohn Forte  *
194fcf3ce44SJohn Forte  * FCA unique error codes can begin after FC_REASON_FCA_UNIQUE.
195fcf3ce44SJohn Forte  * Each FCA defines its own set with values greater >= 0x7F
196fcf3ce44SJohn Forte  */
197fcf3ce44SJohn Forte #define	FC_REASON_FCA_DEFINED   0x100
198fcf3ce44SJohn Forte 
199fcf3ce44SJohn Forte 
200fcf3ce44SJohn Forte /*
201fcf3ce44SJohn Forte  * Device VPD save area
202fcf3ce44SJohn Forte  */
203fcf3ce44SJohn Forte 
204291a2b48SSukumar Swaminathan typedef struct emlxs_vpd
205291a2b48SSukumar Swaminathan {
206291a2b48SSukumar Swaminathan 	uint32_t	biuRev;
207291a2b48SSukumar Swaminathan 	uint32_t	smRev;
208291a2b48SSukumar Swaminathan 	uint32_t	smFwRev;
209291a2b48SSukumar Swaminathan 	uint32_t	endecRev;
210291a2b48SSukumar Swaminathan 	uint16_t	rBit;
211291a2b48SSukumar Swaminathan 	uint8_t		fcphHigh;
212291a2b48SSukumar Swaminathan 	uint8_t		fcphLow;
213291a2b48SSukumar Swaminathan 	uint8_t		feaLevelHigh;
214291a2b48SSukumar Swaminathan 	uint8_t		feaLevelLow;
215291a2b48SSukumar Swaminathan 
216291a2b48SSukumar Swaminathan 	uint32_t	postKernRev;
217291a2b48SSukumar Swaminathan 	char		postKernName[32];
218291a2b48SSukumar Swaminathan 
219291a2b48SSukumar Swaminathan 	uint32_t	opFwRev;
220291a2b48SSukumar Swaminathan 	char		opFwName[32];
221291a2b48SSukumar Swaminathan 	char		opFwLabel[32];
222291a2b48SSukumar Swaminathan 
223291a2b48SSukumar Swaminathan 	uint32_t	sli1FwRev;
224291a2b48SSukumar Swaminathan 	char		sli1FwName[32];
225291a2b48SSukumar Swaminathan 	char		sli1FwLabel[32];
226291a2b48SSukumar Swaminathan 
227291a2b48SSukumar Swaminathan 	uint32_t	sli2FwRev;
228291a2b48SSukumar Swaminathan 	char		sli2FwName[32];
229291a2b48SSukumar Swaminathan 	char		sli2FwLabel[32];
230291a2b48SSukumar Swaminathan 
231291a2b48SSukumar Swaminathan 	uint32_t	sli3FwRev;
232291a2b48SSukumar Swaminathan 	char		sli3FwName[32];
233291a2b48SSukumar Swaminathan 	char		sli3FwLabel[32];
234291a2b48SSukumar Swaminathan 
235291a2b48SSukumar Swaminathan 	uint32_t	sli4FwRev;
236291a2b48SSukumar Swaminathan 	char		sli4FwName[32];
237291a2b48SSukumar Swaminathan 	char		sli4FwLabel[32];
238291a2b48SSukumar Swaminathan 
239291a2b48SSukumar Swaminathan 	char		fw_version[32];
240291a2b48SSukumar Swaminathan 	char		fw_label[32];
241291a2b48SSukumar Swaminathan 
242291a2b48SSukumar Swaminathan 	char		fcode_version[32];
243291a2b48SSukumar Swaminathan 	char		boot_version[32];
244291a2b48SSukumar Swaminathan 
245291a2b48SSukumar Swaminathan 	char		serial_num[32];
246291a2b48SSukumar Swaminathan 	char		part_num[32];
247291a2b48SSukumar Swaminathan 	char		port_num[20];
248291a2b48SSukumar Swaminathan 	char		eng_change[32];
249291a2b48SSukumar Swaminathan 	char		manufacturer[80];
250291a2b48SSukumar Swaminathan 	char		model[80];
251291a2b48SSukumar Swaminathan 	char		model_desc[256];
252291a2b48SSukumar Swaminathan 	char		prog_types[256];
2538f23e9faSHans Rosenfeld 	char		id[256];
254291a2b48SSukumar Swaminathan 
255291a2b48SSukumar Swaminathan 	uint32_t	port_index;
256a9800bebSGarrett D'Amore 	uint16_t	link_speed;
257fcf3ce44SJohn Forte } emlxs_vpd_t;
258fcf3ce44SJohn Forte 
259fcf3ce44SJohn Forte 
260291a2b48SSukumar Swaminathan typedef struct emlxs_queue
261291a2b48SSukumar Swaminathan {
262a9800bebSGarrett D'Amore 	void		*q_first;	/* queue first element */
263a9800bebSGarrett D'Amore 	void		*q_last;	/* queue last element */
264291a2b48SSukumar Swaminathan 	uint16_t	q_cnt;	/* current length of queue */
265291a2b48SSukumar Swaminathan 	uint16_t	q_max;	/* max length queue can get */
266fcf3ce44SJohn Forte } emlxs_queue_t;
267fcf3ce44SJohn Forte typedef emlxs_queue_t Q;
268fcf3ce44SJohn Forte 
269fcf3ce44SJohn Forte 
270fcf3ce44SJohn Forte 
271fcf3ce44SJohn Forte /*
272fcf3ce44SJohn Forte  * This structure is used when allocating a buffer pool.
273fcf3ce44SJohn Forte  * Note: this should be identical to gasket buf_info (fldl.h).
274fcf3ce44SJohn Forte  */
275291a2b48SSukumar Swaminathan typedef struct emlxs_buf_info
276291a2b48SSukumar Swaminathan {
277291a2b48SSukumar Swaminathan 	int32_t		size;	/* Specifies the number of bytes to allocate. */
278291a2b48SSukumar Swaminathan 	int32_t		align;	/* The desired address boundary. */
279fcf3ce44SJohn Forte 
280291a2b48SSukumar Swaminathan 	int32_t		flags;
281fcf3ce44SJohn Forte 
282fcf3ce44SJohn Forte #define	FC_MBUF_DMA		0x01	/* blocks are for DMA */
283fcf3ce44SJohn Forte #define	FC_MBUF_PHYSONLY	0x02	/* For malloc - map a given virtual */
284291a2b48SSukumar Swaminathan 					/* address to physical address (skip */
285291a2b48SSukumar Swaminathan 					/* the malloc). */
286291a2b48SSukumar Swaminathan 					/* For free - just unmap the given */
287fcf3ce44SJohn Forte 					/* physical address (skip the free). */
288fcf3ce44SJohn Forte #define	FC_MBUF_IOCTL		0x04	/* called from dfc_ioctl */
289fcf3ce44SJohn Forte #define	FC_MBUF_UNLOCK		0x08	/* called with driver unlocked */
290291a2b48SSukumar Swaminathan #define	FC_MBUF_SNGLSG		0x10	/* allocate a single contiguous */
291291a2b48SSukumar Swaminathan 					/* physical memory */
292fcf3ce44SJohn Forte 
293291a2b48SSukumar Swaminathan 	uint64_t	phys;		/* specifies physical buffer pointer */
294291a2b48SSukumar Swaminathan 	void		*virt;		/* specifies virtual buffer pointer */
295291a2b48SSukumar Swaminathan 	void		*data_handle;
296291a2b48SSukumar Swaminathan 	void		*dma_handle;
297fcf3ce44SJohn Forte } emlxs_buf_info_t;
298fcf3ce44SJohn Forte typedef emlxs_buf_info_t MBUF_INFO;
299fcf3ce44SJohn Forte 
300fcf3ce44SJohn Forte 
301fcf3ce44SJohn Forte #define	EMLXS_MAX_HBQ   	16	/* Max HBQs handled by firmware */
302fcf3ce44SJohn Forte #define	EMLXS_ELS_HBQ_ID	0
303fcf3ce44SJohn Forte #define	EMLXS_IP_HBQ_ID		1
304fcf3ce44SJohn Forte #define	EMLXS_CT_HBQ_ID		2
305fcf3ce44SJohn Forte #define	EMLXS_FCT_HBQ_ID	3
306fcf3ce44SJohn Forte 
307fcf3ce44SJohn Forte #ifdef SFCT_SUPPORT
308fcf3ce44SJohn Forte #define	EMLXS_NUM_HBQ		4	/* Number of HBQs supported by driver */
309fcf3ce44SJohn Forte #else
310fcf3ce44SJohn Forte #define	EMLXS_NUM_HBQ		3	/* Number of HBQs supported by driver */
311291a2b48SSukumar Swaminathan #endif /* SFCT_SUPPORT */
312fcf3ce44SJohn Forte 
313fcf3ce44SJohn Forte 
31482527734SSukumar Swaminathan /*
31582527734SSukumar Swaminathan  * An IO Channel is a object that comprises a xmit/cmpl
31682527734SSukumar Swaminathan  * path for IOs.
31782527734SSukumar Swaminathan  * For SLI3, an IO path maps to a ring (cmd/rsp)
31882527734SSukumar Swaminathan  * For SLI4, an IO path map to a queue pair (WQ/CQ)
31982527734SSukumar Swaminathan  */
32082527734SSukumar Swaminathan typedef struct emlxs_channel
32182527734SSukumar Swaminathan {
32282527734SSukumar Swaminathan 	struct emlxs_hba *hba;			/* ptr to hba for channel */
32382527734SSukumar Swaminathan 	void		*iopath;		/* ptr to SLI3/4 io path */
32482527734SSukumar Swaminathan 
32582527734SSukumar Swaminathan 	kmutex_t	rsp_lock;
32682527734SSukumar Swaminathan 	IOCBQ		*rsp_head;	/* deferred completion head */
32782527734SSukumar Swaminathan 	IOCBQ		*rsp_tail;	/* deferred completion tail */
32882527734SSukumar Swaminathan 	emlxs_thread_t  intr_thread;
32982527734SSukumar Swaminathan 
33082527734SSukumar Swaminathan 
33182527734SSukumar Swaminathan 	uint16_t	channelno;
33282527734SSukumar Swaminathan 	uint16_t	chan_flag;
33382527734SSukumar Swaminathan 
33482527734SSukumar Swaminathan #define	EMLXS_NEEDS_TRIGGER 1
33582527734SSukumar Swaminathan 
33682527734SSukumar Swaminathan 	/* Protected by EMLXS_TX_CHANNEL_LOCK */
33782527734SSukumar Swaminathan 	emlxs_queue_t	nodeq;			/* Node service queue */
33882527734SSukumar Swaminathan 
33982527734SSukumar Swaminathan 	kmutex_t	channel_cmd_lock;
34082527734SSukumar Swaminathan 	uint32_t	timeout;
34182527734SSukumar Swaminathan 
34282527734SSukumar Swaminathan 	/* Channel command counters */
34382527734SSukumar Swaminathan 	uint32_t	ulpSendCmd;
34482527734SSukumar Swaminathan 	uint32_t	ulpCmplCmd;
34582527734SSukumar Swaminathan 	uint32_t	hbaSendCmd;
34682527734SSukumar Swaminathan 	uint32_t	hbaCmplCmd;
34782527734SSukumar Swaminathan 	uint32_t	hbaSendCmd_sbp;
34882527734SSukumar Swaminathan 	uint32_t	hbaCmplCmd_sbp;
34982527734SSukumar Swaminathan 
35082527734SSukumar Swaminathan } emlxs_channel_t;
35182527734SSukumar Swaminathan typedef emlxs_channel_t CHANNEL;
35282527734SSukumar Swaminathan 
35382527734SSukumar Swaminathan /*
35482527734SSukumar Swaminathan  * Should be able to handle max number of io paths for a
35582527734SSukumar Swaminathan  * SLI4 HBA (EMLXS_MAX_WQS) or for a SLI3 HBA (MAX_RINGS)
35682527734SSukumar Swaminathan  */
35782527734SSukumar Swaminathan #define	MAX_CHANNEL EMLXS_MSI_MAX_INTRS
358fcf3ce44SJohn Forte 
359fcf3ce44SJohn Forte 
360fcf3ce44SJohn Forte /* Structure used to access adapter rings */
361291a2b48SSukumar Swaminathan typedef struct emlxs_ring
362291a2b48SSukumar Swaminathan {
363291a2b48SSukumar Swaminathan 	void		*fc_cmdringaddr;	/* virtual offset for cmd */
364291a2b48SSukumar Swaminathan 						/* rings */
365291a2b48SSukumar Swaminathan 	void		*fc_rspringaddr;	/* virtual offset for rsp */
366291a2b48SSukumar Swaminathan 						/* rings */
367291a2b48SSukumar Swaminathan 
368a9800bebSGarrett D'Amore 	void		*fc_mpon;		/* index ptr for match */
369291a2b48SSukumar Swaminathan 						/* structure */
370a9800bebSGarrett D'Amore 	void		*fc_mpoff;		/* index ptr for match */
371291a2b48SSukumar Swaminathan 						/* structure */
37282527734SSukumar Swaminathan 	struct emlxs_hba *hba;			/* ptr to hba for ring */
373291a2b48SSukumar Swaminathan 
374291a2b48SSukumar Swaminathan 	uint8_t		fc_numCiocb;		/* number of command iocb's */
375291a2b48SSukumar Swaminathan 						/* per ring */
376291a2b48SSukumar Swaminathan 	uint8_t		fc_numRiocb;		/* number of response iocb's */
377291a2b48SSukumar Swaminathan 						/* per ring */
378291a2b48SSukumar Swaminathan 	uint8_t		fc_rspidx;		/* current index in response */
379291a2b48SSukumar Swaminathan 						/* ring */
380291a2b48SSukumar Swaminathan 	uint8_t		fc_cmdidx;		/* current index in command */
381291a2b48SSukumar Swaminathan 						/* ring */
382291a2b48SSukumar Swaminathan 	uint8_t		fc_port_rspidx;
383291a2b48SSukumar Swaminathan 	uint8_t		fc_port_cmdidx;
384291a2b48SSukumar Swaminathan 	uint8_t		ringno;
385291a2b48SSukumar Swaminathan 
386291a2b48SSukumar Swaminathan 	uint16_t	fc_missbufcnt;		/* buf cnt we need to repost */
38782527734SSukumar Swaminathan 	CHANNEL		*channelp;
388291a2b48SSukumar Swaminathan 
389fcf3ce44SJohn Forte 
390fcf3ce44SJohn Forte } emlxs_ring_t;
391fcf3ce44SJohn Forte typedef emlxs_ring_t RING;
392fcf3ce44SJohn Forte 
393fcf3ce44SJohn Forte 
394291a2b48SSukumar Swaminathan #ifdef SAN_DIAG_SUPPORT
395291a2b48SSukumar Swaminathan /*
396291a2b48SSukumar Swaminathan  * Although right now it's just 1 field, SAN Diag anticipates that this
397291a2b48SSukumar Swaminathan  * structure will grow in the future.
398291a2b48SSukumar Swaminathan  */
399291a2b48SSukumar Swaminathan typedef struct sd_timestat_level0 {
400291a2b48SSukumar Swaminathan 	int		count;
401291a2b48SSukumar Swaminathan } sd_timestat_level0_t;
402291a2b48SSukumar Swaminathan #endif
403291a2b48SSukumar Swaminathan 
404291a2b48SSukumar Swaminathan typedef struct emlxs_node
405291a2b48SSukumar Swaminathan {
406291a2b48SSukumar Swaminathan 	struct emlxs_node	*nlp_list_next;
407291a2b48SSukumar Swaminathan 	struct emlxs_node	*nlp_list_prev;
408fcf3ce44SJohn Forte 
409291a2b48SSukumar Swaminathan 	NAME_TYPE		nlp_portname;	/* port name */
410291a2b48SSukumar Swaminathan 	NAME_TYPE		nlp_nodename;	/* node name */
411fcf3ce44SJohn Forte 
412291a2b48SSukumar Swaminathan 	uint32_t		nlp_DID;	/* fibre channel D_ID */
413fcf3ce44SJohn Forte 
414291a2b48SSukumar Swaminathan 	uint16_t		nlp_Rpi;	/* login id returned by */
415291a2b48SSukumar Swaminathan 						/* REG_LOGIN */
416291a2b48SSukumar Swaminathan 	uint16_t		nlp_Xri;	/* login id returned by */
417291a2b48SSukumar Swaminathan 						/* REG_LOGIN */
418fcf3ce44SJohn Forte 
419291a2b48SSukumar Swaminathan 	uint8_t			nlp_fcp_info;	/* Remote class info */
420fcf3ce44SJohn Forte 
421fcf3ce44SJohn Forte 	/* nlp_fcp_info */
422fcf3ce44SJohn Forte #define	NLP_FCP_TGT_DEVICE	0x10	/* FCP TGT device */
423fcf3ce44SJohn Forte #define	NLP_FCP_INI_DEVICE	0x20	/* FCP Initiator device */
424fcf3ce44SJohn Forte #define	NLP_FCP_2_DEVICE	0x40	/* FCP-2 TGT device */
425291a2b48SSukumar Swaminathan #define	NLP_EMLX_VPORT		0x80    /* Virtual port */
426fcf3ce44SJohn Forte 
4278f23e9faSHans Rosenfeld 	uint8_t			dfc_state;
4288f23e9faSHans Rosenfeld #define	EMLXS_SET_DFC_STATE(_n, _state)	if (_n && _n->nlp_active)\
4298f23e9faSHans Rosenfeld 		{(_n)->dfc_state = (_state); }
4308f23e9faSHans Rosenfeld 
43182527734SSukumar Swaminathan 	uint32_t		nlp_force_rscn;
432291a2b48SSukumar Swaminathan 	uint32_t		nlp_tag;	/* Tag used by port_offline */
433291a2b48SSukumar Swaminathan 	uint32_t		flag;
434fcf3ce44SJohn Forte 
435291a2b48SSukumar Swaminathan #define	NODE_POOL_ALLOCATED 	0x00000001
436fcf3ce44SJohn Forte 
437291a2b48SSukumar Swaminathan 	SERV_PARM		sparm;
438fcf3ce44SJohn Forte 
43982527734SSukumar Swaminathan 	/* Protected by EMLXS_TX_CHANNEL_LOCK */
440291a2b48SSukumar Swaminathan 	uint32_t		nlp_active;	/* Node active flag */
441291a2b48SSukumar Swaminathan 	uint32_t		nlp_base;
44282527734SSukumar Swaminathan 	uint32_t		nlp_flag[MAX_CHANNEL];	/* Node level channel */
443291a2b48SSukumar Swaminathan 							/* flags */
444fcf3ce44SJohn Forte 
445fcf3ce44SJohn Forte 	/* nlp_flag */
446291a2b48SSukumar Swaminathan #define	NLP_CLOSED		0x1
447291a2b48SSukumar Swaminathan #define	NLP_OFFLINE		0x2
448291a2b48SSukumar Swaminathan #define	NLP_RPI_XRI		0x4
449291a2b48SSukumar Swaminathan 
45082527734SSukumar Swaminathan 	uint32_t		nlp_tics[MAX_CHANNEL];	/* gate timeout */
45182527734SSukumar Swaminathan 	emlxs_queue_t		nlp_tx[MAX_CHANNEL];	/* Transmit Q head */
45282527734SSukumar Swaminathan 	emlxs_queue_t		nlp_ptx[MAX_CHANNEL];	/* Priority transmit */
453291a2b48SSukumar Swaminathan 							/* Queue head */
45482527734SSukumar Swaminathan 	void			*nlp_next[MAX_CHANNEL];	/* Service Request */
455291a2b48SSukumar Swaminathan 							/* Queue pointer used */
456291a2b48SSukumar Swaminathan 							/* when node needs */
457291a2b48SSukumar Swaminathan 							/* servicing */
458fcf3ce44SJohn Forte #ifdef DHCHAP_SUPPORT
459291a2b48SSukumar Swaminathan 	emlxs_node_dhc_t	node_dhc;
460fcf3ce44SJohn Forte #endif	/* DHCHAP_SUPPORT */
461fcf3ce44SJohn Forte 
462291a2b48SSukumar Swaminathan #ifdef SAN_DIAG_SUPPORT
463291a2b48SSukumar Swaminathan 	sd_timestat_level0_t	sd_dev_bucket[SD_IO_LATENCY_MAX_BUCKETS];
464291a2b48SSukumar Swaminathan #endif
46582527734SSukumar Swaminathan 
466a9800bebSGarrett D'Amore 	struct RPIobj		*rpip;	/* SLI4 only */
467a9800bebSGarrett D'Amore #define	EMLXS_NODE_TO_RPI(_p, _n)	\
468a9800bebSGarrett D'Amore 	((_n)?((_n->rpip)?_n->rpip:emlxs_rpi_find(_p, _n->nlp_Rpi)):NULL)
46982527734SSukumar Swaminathan 
4708f23e9faSHans Rosenfeld #ifdef NODE_THROTTLE_SUPPORT
4718f23e9faSHans Rosenfeld 	uint32_t io_throttle;
4728f23e9faSHans Rosenfeld 	uint32_t io_active;
4738f23e9faSHans Rosenfeld #endif /* NODE_THROTTLE_SUPPORT */
4748f23e9faSHans Rosenfeld 
475fcf3ce44SJohn Forte } emlxs_node_t;
476fcf3ce44SJohn Forte typedef emlxs_node_t NODELIST;
477fcf3ce44SJohn Forte 
478fcf3ce44SJohn Forte 
479fcf3ce44SJohn Forte 
480fcf3ce44SJohn Forte #define	NADDR_LEN	6	/* MAC network address length */
481291a2b48SSukumar Swaminathan typedef struct emlxs_fcip_nethdr
482291a2b48SSukumar Swaminathan {
483291a2b48SSukumar Swaminathan 	NAME_TYPE	fc_destname;	/* destination port name */
484291a2b48SSukumar Swaminathan 	NAME_TYPE	fc_srcname;	/* source port name */
485fcf3ce44SJohn Forte } emlxs_fcip_nethdr_t;
486fcf3ce44SJohn Forte typedef emlxs_fcip_nethdr_t NETHDR;
487fcf3ce44SJohn Forte 
488fcf3ce44SJohn Forte 
489fcf3ce44SJohn Forte #define	MEM_NLP		0	/* memory segment to hold node list entries */
490fcf3ce44SJohn Forte #define	MEM_IOCB	1	/* memory segment to hold iocb commands */
491291a2b48SSukumar Swaminathan #define	MEM_MBOX	2	/* memory segment to hold mailbox cmds  */
492291a2b48SSukumar Swaminathan #define	MEM_BPL		3	/* and to hold buffer ptr lists - SLI2   */
493291a2b48SSukumar Swaminathan #define	MEM_BUF		4	/* memory segment to hold buffer data   */
494291a2b48SSukumar Swaminathan #define	MEM_ELSBUF	4	/* memory segment to hold buffer data   */
495fcf3ce44SJohn Forte #define	MEM_IPBUF	5	/* memory segment to hold IP buffer data */
496fcf3ce44SJohn Forte #define	MEM_CTBUF	6	/* memory segment to hold CT buffer data */
497fcf3ce44SJohn Forte #define	MEM_FCTBUF	7	/* memory segment to hold FCT buffer data */
498*a3170057SPaul Winder #define MEM_SGL1K	8	/* memory segment to hold 1K SGL entries */
499*a3170057SPaul Winder #define MEM_SGL2K	9	/* memory segment to hold 2K SGL entries */
500*a3170057SPaul Winder #define MEM_SGL4K	10	/* memory segment to hold 4K SGL entries */
501fcf3ce44SJohn Forte 
502fcf3ce44SJohn Forte #ifdef SFCT_SUPPORT
503*a3170057SPaul Winder #define	FC_MAX_SEG	11
504*a3170057SPaul Winder #define	MEM_FCTSEG	13 /* must be greater than FC_MAX_SEG */
505fcf3ce44SJohn Forte #else
506*a3170057SPaul Winder #define	FC_MAX_SEG	10
507291a2b48SSukumar Swaminathan #endif /* SFCT_SUPPORT */
508fcf3ce44SJohn Forte 
509fcf3ce44SJohn Forte 
510fcf3ce44SJohn Forte /* A BPL entry is 12 bytes. Subtract 2 for command and response buffers */
5118f23e9faSHans Rosenfeld #define	BPL_TO_SGLLEN(_bpl)	((_bpl/12)-2)
5128f23e9faSHans Rosenfeld #define	MEM_BPL_SIZE		36 /* Default size */
513fcf3ce44SJohn Forte 
51482527734SSukumar Swaminathan /* A SGL entry is 16 bytes. Subtract 2 for command and response buffers */
5158f23e9faSHans Rosenfeld #define	SGL_TO_SGLLEN(_sgl)	((_sgl/16)-2)
5168f23e9faSHans Rosenfeld #define	MEM_SGL_SIZE		4096 /* Default size */
517fcf3ce44SJohn Forte 
518fcf3ce44SJohn Forte #define	MEM_BUF_SIZE		1024
519fcf3ce44SJohn Forte #define	MEM_BUF_COUNT		64
520fcf3ce44SJohn Forte 
521291a2b48SSukumar Swaminathan #define	MEM_ELSBUF_SIZE   	MEM_BUF_SIZE
522291a2b48SSukumar Swaminathan #define	MEM_ELSBUF_COUNT  	hba->max_nodes
523291a2b48SSukumar Swaminathan #define	MEM_IPBUF_SIZE  	65535
524fcf3ce44SJohn Forte #define	MEM_IPBUF_COUNT		60
525fcf3ce44SJohn Forte #define	MEM_CTBUF_SIZE		MAX_CT_PAYLOAD	/* (1024*320) */
526fcf3ce44SJohn Forte #define	MEM_CTBUF_COUNT		8
527291a2b48SSukumar Swaminathan #define	MEM_FCTBUF_SIZE  	65535
528fcf3ce44SJohn Forte #define	MEM_FCTBUF_COUNT	128
529fcf3ce44SJohn Forte 
530291a2b48SSukumar Swaminathan typedef struct emlxs_memseg
531291a2b48SSukumar Swaminathan {
532a9800bebSGarrett D'Amore 	void			*fc_memget_ptr;
533a9800bebSGarrett D'Amore 	void			*fc_memget_end;
534a9800bebSGarrett D'Amore 	void			*fc_memput_ptr;
535a9800bebSGarrett D'Amore 	void			*fc_memput_end;
536291a2b48SSukumar Swaminathan 
537291a2b48SSukumar Swaminathan 	uint32_t		fc_total_memsize;
538291a2b48SSukumar Swaminathan 	uint32_t		fc_memsize;		/* size of mem blks */
539291a2b48SSukumar Swaminathan 	uint32_t		fc_numblks;		/* no of mem blks */
540291a2b48SSukumar Swaminathan 	uint32_t		fc_memget_cnt;		/* no of mem get blks */
541291a2b48SSukumar Swaminathan 	uint32_t		fc_memput_cnt;		/* no of mem put blks */
54282527734SSukumar Swaminathan 	uint32_t		fc_memflag;  /* emlxs_buf_info_t FLAGS */
5438f23e9faSHans Rosenfeld #define	FC_MEMSEG_PUT_ENABLED	0x20000000
5448f23e9faSHans Rosenfeld #define	FC_MEMSEG_GET_ENABLED	0x40000000
5458f23e9faSHans Rosenfeld #define	FC_MEMSEG_DYNAMIC	0x80000000
5468f23e9faSHans Rosenfeld 
54782527734SSukumar Swaminathan 	uint32_t		fc_memalign;
54882527734SSukumar Swaminathan 	uint32_t		fc_memtag;
54982527734SSukumar Swaminathan 	char			fc_label[32];
55082527734SSukumar Swaminathan 
5518f23e9faSHans Rosenfeld 	uint32_t		fc_hi_water;
5528f23e9faSHans Rosenfeld 	uint32_t		fc_lo_water;
5538f23e9faSHans Rosenfeld 	uint32_t		fc_step;  /* Dyn increment.  Zero = static */
5548f23e9faSHans Rosenfeld 	uint32_t		fc_low;   /* Lowest free count (dyn only) */
5558f23e9faSHans Rosenfeld 	uint32_t		fc_last;  /* Last fc_numblks (dyn only) */
5568f23e9faSHans Rosenfeld 
557fcf3ce44SJohn Forte } emlxs_memseg_t;
558fcf3ce44SJohn Forte typedef emlxs_memseg_t MEMSEG;
559fcf3ce44SJohn Forte 
560fcf3ce44SJohn Forte 
561fcf3ce44SJohn Forte /* Board stat counters */
562