blob: f5dbeabefcb71dbaed66ec594f8b9794053e722a [file] [log] [blame]
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001/*
2 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
3 * Copyright (C) 2004 - 2005 Leonid Stoljar
4 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
5 * Copyright (C) 2007 - 2010 ID7 Ltd.
6 *
7 * Forward port and refactoring to modern qla2xxx and target/configfs
8 *
9 * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org>
10 *
11 * Additional file for the target driver support.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23/*
24 * This is the global def file that is useful for including from the
25 * target portion.
26 */
27
28#ifndef __QLA_TARGET_H
29#define __QLA_TARGET_H
30
31#include "qla_def.h"
32
33/*
34 * Must be changed on any change in any initiator visible interfaces or
35 * data in the target add-on
36 */
37#define QLA2XXX_TARGET_MAGIC 269
38
39/*
40 * Must be changed on any change in any target visible interfaces or
41 * data in the initiator
42 */
43#define QLA2XXX_INITIATOR_MAGIC 57222
44
45#define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive"
46#define QLA2XXX_INI_MODE_STR_DISABLED "disabled"
47#define QLA2XXX_INI_MODE_STR_ENABLED "enabled"
48
49#define QLA2XXX_INI_MODE_EXCLUSIVE 0
50#define QLA2XXX_INI_MODE_DISABLED 1
51#define QLA2XXX_INI_MODE_ENABLED 2
52
53#define QLA2XXX_COMMAND_COUNT_INIT 250
54#define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
55
56/*
57 * Used to mark which completion handles (for RIO Status's) are for CTIO's
58 * vs. regular (non-target) info. This is checked for in
59 * qla2x00_process_response_queue() to see if a handle coming back in a
60 * multi-complete should come to the tgt driver or be handled there by qla2xxx
61 */
62#define CTIO_COMPLETION_HANDLE_MARK BIT_29
Chad Dupuis8d93f552013-01-30 03:34:37 -050063#if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
64#error "CTIO_COMPLETION_HANDLE_MARK not larger than "
65 "DEFAULT_OUTSTANDING_COMMANDS"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040066#endif
67#define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
68
69/* Used to mark CTIO as intermediate */
70#define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
71
72#ifndef OF_SS_MODE_0
73/*
74 * ISP target entries - Flags bit definitions.
75 */
76#define OF_SS_MODE_0 0
77#define OF_SS_MODE_1 1
78#define OF_SS_MODE_2 2
79#define OF_SS_MODE_3 3
80
81#define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */
82#define OF_DATA_IN BIT_6 /* Data in to initiator */
83 /* (data from target to initiator) */
84#define OF_DATA_OUT BIT_7 /* Data out from initiator */
85 /* (data from initiator to target) */
86#define OF_NO_DATA (BIT_7 | BIT_6)
87#define OF_INC_RC BIT_8 /* Increment command resource count */
88#define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */
89#define OF_CONF_REQ BIT_13 /* Confirmation Requested */
90#define OF_TERM_EXCH BIT_14 /* Terminate exchange */
91#define OF_SSTS BIT_15 /* Send SCSI status */
92#endif
93
94#ifndef QLA_TGT_DATASEGS_PER_CMD32
95#define QLA_TGT_DATASEGS_PER_CMD32 3
96#define QLA_TGT_DATASEGS_PER_CONT32 7
97#define QLA_TGT_MAX_SG32(ql) \
98 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
99 QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
100
101#define QLA_TGT_DATASEGS_PER_CMD64 2
102#define QLA_TGT_DATASEGS_PER_CONT64 5
103#define QLA_TGT_MAX_SG64(ql) \
104 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
105 QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
106#endif
107
108#ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
109#define QLA_TGT_DATASEGS_PER_CMD_24XX 1
110#define QLA_TGT_DATASEGS_PER_CONT_24XX 5
111#define QLA_TGT_MAX_SG_24XX(ql) \
112 (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
113 QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
114#endif
115#endif
116
117#define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
118 ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
119 : (uint16_t)(iocb)->u.isp2x.target.id.standard)
120
121#ifndef IMMED_NOTIFY_TYPE
122#define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */
123/*
124 * ISP queue - immediate notify entry structure definition.
125 * This is sent by the ISP to the Target driver.
126 * This IOCB would have report of events sent by the
127 * initiator, that needs to be handled by the target
128 * driver immediately.
129 */
130struct imm_ntfy_from_isp {
131 uint8_t entry_type; /* Entry type. */
132 uint8_t entry_count; /* Entry count. */
133 uint8_t sys_define; /* System defined. */
134 uint8_t entry_status; /* Entry Status. */
135 union {
136 struct {
137 uint32_t sys_define_2; /* System defined. */
138 target_id_t target;
139 uint16_t lun;
140 uint8_t target_id;
141 uint8_t reserved_1;
142 uint16_t status_modifier;
143 uint16_t status;
144 uint16_t task_flags;
145 uint16_t seq_id;
146 uint16_t srr_rx_id;
147 uint32_t srr_rel_offs;
148 uint16_t srr_ui;
149#define SRR_IU_DATA_IN 0x1
150#define SRR_IU_DATA_OUT 0x5
151#define SRR_IU_STATUS 0x7
152 uint16_t srr_ox_id;
153 uint8_t reserved_2[28];
154 } isp2x;
155 struct {
156 uint32_t reserved;
157 uint16_t nport_handle;
158 uint16_t reserved_2;
159 uint16_t flags;
160#define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1
161#define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0
162 uint16_t srr_rx_id;
163 uint16_t status;
164 uint8_t status_subcode;
Arun Easiaa230bc2013-01-30 03:34:39 -0500165 uint8_t fw_handle;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400166 uint32_t exchange_address;
167 uint32_t srr_rel_offs;
168 uint16_t srr_ui;
169 uint16_t srr_ox_id;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400170 union {
171 struct {
172 uint8_t node_name[8];
173 } plogi; /* PLOGI/ADISC/PDISC */
174 struct {
175 /* PRLI word 3 bit 0-15 */
176 uint16_t wd3_lo;
177 uint8_t resv0[6];
178 } prli;
179 struct {
180 uint8_t port_id[3];
181 uint8_t resv1;
182 uint16_t nport_handle;
183 uint16_t resv2;
184 } req_els;
185 } u;
186 uint8_t port_name[8];
187 uint8_t resv3[3];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400188 uint8_t vp_index;
189 uint32_t reserved_5;
190 uint8_t port_id[3];
191 uint8_t reserved_6;
192 } isp24;
193 } u;
194 uint16_t reserved_7;
195 uint16_t ox_id;
196} __packed;
197#endif
198
199#ifndef NOTIFY_ACK_TYPE
200#define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
201/*
202 * ISP queue - notify acknowledge entry structure definition.
203 * This is sent to the ISP from the target driver.
204 */
205struct nack_to_isp {
206 uint8_t entry_type; /* Entry type. */
207 uint8_t entry_count; /* Entry count. */
208 uint8_t sys_define; /* System defined. */
209 uint8_t entry_status; /* Entry Status. */
210 union {
211 struct {
212 uint32_t sys_define_2; /* System defined. */
213 target_id_t target;
214 uint8_t target_id;
215 uint8_t reserved_1;
216 uint16_t flags;
217 uint16_t resp_code;
218 uint16_t status;
219 uint16_t task_flags;
220 uint16_t seq_id;
221 uint16_t srr_rx_id;
222 uint32_t srr_rel_offs;
223 uint16_t srr_ui;
224 uint16_t srr_flags;
225 uint16_t srr_reject_code;
226 uint8_t srr_reject_vendor_uniq;
227 uint8_t srr_reject_code_expl;
228 uint8_t reserved_2[24];
229 } isp2x;
230 struct {
231 uint32_t handle;
232 uint16_t nport_handle;
233 uint16_t reserved_1;
234 uint16_t flags;
235 uint16_t srr_rx_id;
236 uint16_t status;
237 uint8_t status_subcode;
Arun Easiaa230bc2013-01-30 03:34:39 -0500238 uint8_t fw_handle;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400239 uint32_t exchange_address;
240 uint32_t srr_rel_offs;
241 uint16_t srr_ui;
242 uint16_t srr_flags;
243 uint8_t reserved_4[19];
244 uint8_t vp_index;
245 uint8_t srr_reject_vendor_uniq;
246 uint8_t srr_reject_code_expl;
247 uint8_t srr_reject_code;
248 uint8_t reserved_5[5];
249 } isp24;
250 } u;
251 uint8_t reserved[2];
252 uint16_t ox_id;
253} __packed;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400254#define NOTIFY_ACK_FLAGS_TERMINATE BIT_3
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400255#define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
256#define NOTIFY_ACK_SRR_FLAGS_REJECT 1
257
258#define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
259
260#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
261#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
262
263#define NOTIFY_ACK_SUCCESS 0x01
264#endif
265
266#ifndef ACCEPT_TGT_IO_TYPE
267#define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
268#endif
269
270#ifndef CONTINUE_TGT_IO_TYPE
271#define CONTINUE_TGT_IO_TYPE 0x17
272/*
273 * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
274 * This structure is sent to the ISP 2xxx from target driver.
275 */
276struct ctio_to_2xxx {
277 uint8_t entry_type; /* Entry type. */
278 uint8_t entry_count; /* Entry count. */
279 uint8_t sys_define; /* System defined. */
280 uint8_t entry_status; /* Entry Status. */
281 uint32_t handle; /* System defined handle */
282 target_id_t target;
283 uint16_t rx_id;
284 uint16_t flags;
285 uint16_t status;
286 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */
287 uint16_t dseg_count; /* Data segment count. */
288 uint32_t relative_offset;
289 uint32_t residual;
290 uint16_t reserved_1[3];
291 uint16_t scsi_status;
292 uint32_t transfer_length;
293 uint32_t dseg_0_address; /* Data segment 0 address. */
294 uint32_t dseg_0_length; /* Data segment 0 length. */
295 uint32_t dseg_1_address; /* Data segment 1 address. */
296 uint32_t dseg_1_length; /* Data segment 1 length. */
297 uint32_t dseg_2_address; /* Data segment 2 address. */
298 uint32_t dseg_2_length; /* Data segment 2 length. */
299} __packed;
300#define ATIO_PATH_INVALID 0x07
301#define ATIO_CANT_PROV_CAP 0x16
302#define ATIO_CDB_VALID 0x3D
303
304#define ATIO_EXEC_READ BIT_1
305#define ATIO_EXEC_WRITE BIT_0
306#endif
307
308#ifndef CTIO_A64_TYPE
309#define CTIO_A64_TYPE 0x1F
310#define CTIO_SUCCESS 0x01
311#define CTIO_ABORTED 0x02
312#define CTIO_INVALID_RX_ID 0x08
313#define CTIO_TIMEOUT 0x0B
Quinn Tranf83adb62014-04-11 16:54:43 -0400314#define CTIO_DIF_ERROR 0x0C /* DIF error detected */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400315#define CTIO_LIP_RESET 0x0E
316#define CTIO_TARGET_RESET 0x17
317#define CTIO_PORT_UNAVAILABLE 0x28
318#define CTIO_PORT_LOGGED_OUT 0x29
319#define CTIO_PORT_CONF_CHANGED 0x2A
320#define CTIO_SRR_RECEIVED 0x45
321#endif
322
323#ifndef CTIO_RET_TYPE
324#define CTIO_RET_TYPE 0x17 /* CTIO return entry */
325#define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
326
327struct fcp_hdr {
328 uint8_t r_ctl;
329 uint8_t d_id[3];
330 uint8_t cs_ctl;
331 uint8_t s_id[3];
332 uint8_t type;
333 uint8_t f_ctl[3];
334 uint8_t seq_id;
335 uint8_t df_ctl;
336 uint16_t seq_cnt;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400337 __be16 ox_id;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400338 uint16_t rx_id;
339 uint32_t parameter;
340} __packed;
341
342struct fcp_hdr_le {
343 uint8_t d_id[3];
344 uint8_t r_ctl;
345 uint8_t s_id[3];
346 uint8_t cs_ctl;
347 uint8_t f_ctl[3];
348 uint8_t type;
349 uint16_t seq_cnt;
350 uint8_t df_ctl;
351 uint8_t seq_id;
352 uint16_t rx_id;
353 uint16_t ox_id;
354 uint32_t parameter;
355} __packed;
356
357#define F_CTL_EXCH_CONTEXT_RESP BIT_23
358#define F_CTL_SEQ_CONTEXT_RESIP BIT_22
359#define F_CTL_LAST_SEQ BIT_20
360#define F_CTL_END_SEQ BIT_19
361#define F_CTL_SEQ_INITIATIVE BIT_16
362
363#define R_CTL_BASIC_LINK_SERV 0x80
364#define R_CTL_B_ACC 0x4
365#define R_CTL_B_RJT 0x5
366
367struct atio7_fcp_cmnd {
368 uint64_t lun;
369 uint8_t cmnd_ref;
370 uint8_t task_attr:3;
371 uint8_t reserved:5;
372 uint8_t task_mgmt_flags;
373#define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
374#define FCP_CMND_TASK_MGMT_TARGET_RESET 5
375#define FCP_CMND_TASK_MGMT_LU_RESET 4
376#define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
377#define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
378 uint8_t wrdata:1;
379 uint8_t rddata:1;
380 uint8_t add_cdb_len:6;
381 uint8_t cdb[16];
382 /*
383 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
384 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
385 * BUILD_BUG_ON in qlt_init().
386 */
387 uint8_t add_cdb[4];
388 /* uint32_t data_length; */
389} __packed;
390
391/*
392 * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
393 * This is sent from the ISP to the target driver.
394 */
395struct atio_from_isp {
396 union {
397 struct {
398 uint16_t entry_hdr;
399 uint8_t sys_define; /* System defined. */
400 uint8_t entry_status; /* Entry Status. */
401 uint32_t sys_define_2; /* System defined. */
402 target_id_t target;
403 uint16_t rx_id;
404 uint16_t flags;
405 uint16_t status;
406 uint8_t command_ref;
407 uint8_t task_codes;
408 uint8_t task_flags;
409 uint8_t execution_codes;
410 uint8_t cdb[MAX_CMDSZ];
411 uint32_t data_length;
412 uint16_t lun;
413 uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */
414 uint16_t reserved_32[6];
415 uint16_t ox_id;
416 } isp2x;
417 struct {
418 uint16_t entry_hdr;
419 uint8_t fcp_cmnd_len_low;
420 uint8_t fcp_cmnd_len_high:4;
421 uint8_t attr:4;
422 uint32_t exchange_addr;
423#define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
424 struct fcp_hdr fcp_hdr;
425 struct atio7_fcp_cmnd fcp_cmnd;
426 } isp24;
427 struct {
428 uint8_t entry_type; /* Entry type. */
429 uint8_t entry_count; /* Entry count. */
430 uint8_t data[58];
431 uint32_t signature;
432#define ATIO_PROCESSED 0xDEADDEAD /* Signature */
433 } raw;
434 } u;
435} __packed;
436
437#define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
438
439/*
440 * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
441 * This structure is sent to the ISP 24xx from the target driver.
442 */
443
444struct ctio7_to_24xx {
445 uint8_t entry_type; /* Entry type. */
446 uint8_t entry_count; /* Entry count. */
447 uint8_t sys_define; /* System defined. */
448 uint8_t entry_status; /* Entry Status. */
449 uint32_t handle; /* System defined handle */
450 uint16_t nport_handle;
451#define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
452 uint16_t timeout;
453 uint16_t dseg_count; /* Data segment count. */
454 uint8_t vp_index;
455 uint8_t add_flags;
456 uint8_t initiator_id[3];
457 uint8_t reserved;
458 uint32_t exchange_addr;
459 union {
460 struct {
461 uint16_t reserved1;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400462 __le16 flags;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400463 uint32_t residual;
Quinn Tran33a5fce2014-06-24 00:22:29 -0400464 __le16 ox_id;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400465 uint16_t scsi_status;
466 uint32_t relative_offset;
467 uint32_t reserved2;
468 uint32_t transfer_length;
469 uint32_t reserved3;
470 /* Data segment 0 address. */
471 uint32_t dseg_0_address[2];
472 /* Data segment 0 length. */
473 uint32_t dseg_0_length;
474 } status0;
475 struct {
476 uint16_t sense_length;
477 uint16_t flags;
478 uint32_t residual;
Quinn Tran33a5fce2014-06-24 00:22:29 -0400479 __le16 ox_id;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400480 uint16_t scsi_status;
481 uint16_t response_len;
482 uint16_t reserved;
483 uint8_t sense_data[24];
484 } status1;
485 } u;
486} __packed;
487
488/*
489 * ISP queue - CTIO type 7 from ISP 24xx to target driver
490 * returned entry structure.
491 */
492struct ctio7_from_24xx {
493 uint8_t entry_type; /* Entry type. */
494 uint8_t entry_count; /* Entry count. */
495 uint8_t sys_define; /* System defined. */
496 uint8_t entry_status; /* Entry Status. */
497 uint32_t handle; /* System defined handle */
498 uint16_t status;
499 uint16_t timeout;
500 uint16_t dseg_count; /* Data segment count. */
501 uint8_t vp_index;
502 uint8_t reserved1[5];
503 uint32_t exchange_address;
504 uint16_t reserved2;
505 uint16_t flags;
506 uint32_t residual;
507 uint16_t ox_id;
508 uint16_t reserved3;
509 uint32_t relative_offset;
510 uint8_t reserved4[24];
511} __packed;
512
513/* CTIO7 flags values */
514#define CTIO7_FLAGS_SEND_STATUS BIT_15
515#define CTIO7_FLAGS_TERMINATE BIT_14
516#define CTIO7_FLAGS_CONFORM_REQ BIT_13
517#define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
518#define CTIO7_FLAGS_STATUS_MODE_0 0
519#define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
Quinn Tranf83adb62014-04-11 16:54:43 -0400520#define CTIO7_FLAGS_STATUS_MODE_2 BIT_7
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400521#define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
522#define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
523#define CTIO7_FLAGS_DSD_PTR BIT_2
Quinn Tranf83adb62014-04-11 16:54:43 -0400524#define CTIO7_FLAGS_DATA_IN BIT_1 /* data to initiator */
525#define CTIO7_FLAGS_DATA_OUT BIT_0 /* data from initiator */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400526
527#define ELS_PLOGI 0x3
528#define ELS_FLOGI 0x4
529#define ELS_LOGO 0x5
530#define ELS_PRLI 0x20
531#define ELS_PRLO 0x21
532#define ELS_TPRLO 0x24
533#define ELS_PDISC 0x50
534#define ELS_ADISC 0x52
535
536/*
Quinn Tranf83adb62014-04-11 16:54:43 -0400537 *CTIO Type CRC_2 IOCB
538 */
539struct ctio_crc2_to_fw {
540 uint8_t entry_type; /* Entry type. */
541#define CTIO_CRC2 0x7A
542 uint8_t entry_count; /* Entry count. */
543 uint8_t sys_define; /* System defined. */
544 uint8_t entry_status; /* Entry Status. */
545
546 uint32_t handle; /* System handle. */
547 uint16_t nport_handle; /* N_PORT handle. */
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400548 __le16 timeout; /* Command timeout. */
Quinn Tranf83adb62014-04-11 16:54:43 -0400549
550 uint16_t dseg_count; /* Data segment count. */
551 uint8_t vp_index;
552 uint8_t add_flags; /* additional flags */
553#define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
554
555 uint8_t initiator_id[3]; /* initiator ID */
556 uint8_t reserved1;
557 uint32_t exchange_addr; /* rcv exchange address */
558 uint16_t reserved2;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400559 __le16 flags; /* refer to CTIO7 flags values */
Quinn Tranf83adb62014-04-11 16:54:43 -0400560 uint32_t residual;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400561 __le16 ox_id;
Quinn Tranf83adb62014-04-11 16:54:43 -0400562 uint16_t scsi_status;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400563 __le32 relative_offset;
Quinn Tranf83adb62014-04-11 16:54:43 -0400564 uint32_t reserved5;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400565 __le32 transfer_length; /* total fc transfer length */
Quinn Tranf83adb62014-04-11 16:54:43 -0400566 uint32_t reserved6;
Quinn Tranc7ee3bd2014-06-02 07:02:16 -0400567 __le32 crc_context_address[2];/* Data segment address. */
Quinn Tranf83adb62014-04-11 16:54:43 -0400568 uint16_t crc_context_len; /* Data segment length. */
569 uint16_t reserved_1; /* MUST be set to 0. */
570} __packed;
571
572/* CTIO Type CRC_x Status IOCB */
573struct ctio_crc_from_fw {
574 uint8_t entry_type; /* Entry type. */
575 uint8_t entry_count; /* Entry count. */
576 uint8_t sys_define; /* System defined. */
577 uint8_t entry_status; /* Entry Status. */
578
579 uint32_t handle; /* System handle. */
580 uint16_t status;
581 uint16_t timeout; /* Command timeout. */
582 uint16_t dseg_count; /* Data segment count. */
583 uint32_t reserved1;
584 uint16_t state_flags;
585#define CTIO_CRC_SF_DIF_CHOPPED BIT_4
586
587 uint32_t exchange_address; /* rcv exchange address */
588 uint16_t reserved2;
589 uint16_t flags;
590 uint32_t resid_xfer_length;
591 uint16_t ox_id;
592 uint8_t reserved3[12];
593 uint16_t runt_guard; /* reported runt blk guard */
594 uint8_t actual_dif[8];
595 uint8_t expected_dif[8];
596} __packed;
597
598/*
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400599 * ISP queue - ABTS received/response entries structure definition for 24xx.
600 */
601#define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
602#define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
603
604/*
605 * ISP queue - ABTS received IOCB entry structure definition for 24xx.
606 * The ABTS BLS received from the wire is sent to the
607 * target driver by the ISP 24xx.
608 * The IOCB is placed on the response queue.
609 */
610struct abts_recv_from_24xx {
611 uint8_t entry_type; /* Entry type. */
612 uint8_t entry_count; /* Entry count. */
613 uint8_t sys_define; /* System defined. */
614 uint8_t entry_status; /* Entry Status. */
615 uint8_t reserved_1[6];
616 uint16_t nport_handle;
617 uint8_t reserved_2[2];
618 uint8_t vp_index;
619 uint8_t reserved_3:4;
620 uint8_t sof_type:4;
621 uint32_t exchange_address;
622 struct fcp_hdr_le fcp_hdr_le;
623 uint8_t reserved_4[16];
624 uint32_t exchange_addr_to_abort;
625} __packed;
626
627#define ABTS_PARAM_ABORT_SEQ BIT_0
628
629struct ba_acc_le {
630 uint16_t reserved;
631 uint8_t seq_id_last;
632 uint8_t seq_id_valid;
633#define SEQ_ID_VALID 0x80
634#define SEQ_ID_INVALID 0x00
635 uint16_t rx_id;
636 uint16_t ox_id;
637 uint16_t high_seq_cnt;
638 uint16_t low_seq_cnt;
639} __packed;
640
641struct ba_rjt_le {
642 uint8_t vendor_uniq;
643 uint8_t reason_expl;
644 uint8_t reason_code;
645#define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
646#define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
647 uint8_t reserved;
648} __packed;
649
650/*
651 * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
652 * The ABTS response to the ABTS received is sent by the
653 * target driver to the ISP 24xx.
654 * The IOCB is placed on the request queue.
655 */
656struct abts_resp_to_24xx {
657 uint8_t entry_type; /* Entry type. */
658 uint8_t entry_count; /* Entry count. */
659 uint8_t sys_define; /* System defined. */
660 uint8_t entry_status; /* Entry Status. */
661 uint32_t handle;
662 uint16_t reserved_1;
663 uint16_t nport_handle;
664 uint16_t control_flags;
665#define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
666 uint8_t vp_index;
667 uint8_t reserved_3:4;
668 uint8_t sof_type:4;
669 uint32_t exchange_address;
670 struct fcp_hdr_le fcp_hdr_le;
671 union {
672 struct ba_acc_le ba_acct;
673 struct ba_rjt_le ba_rjt;
674 } __packed payload;
675 uint32_t reserved_4;
676 uint32_t exchange_addr_to_abort;
677} __packed;
678
679/*
680 * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
681 * The ABTS response with completion status to the ABTS response
682 * (sent by the target driver to the ISP 24xx) is sent by the
683 * ISP24xx firmware to the target driver.
684 * The IOCB is placed on the response queue.
685 */
686struct abts_resp_from_24xx_fw {
687 uint8_t entry_type; /* Entry type. */
688 uint8_t entry_count; /* Entry count. */
689 uint8_t sys_define; /* System defined. */
690 uint8_t entry_status; /* Entry Status. */
691 uint32_t handle;
692 uint16_t compl_status;
693#define ABTS_RESP_COMPL_SUCCESS 0
694#define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
695 uint16_t nport_handle;
696 uint16_t reserved_1;
697 uint8_t reserved_2;
698 uint8_t reserved_3:4;
699 uint8_t sof_type:4;
700 uint32_t exchange_address;
701 struct fcp_hdr_le fcp_hdr_le;
702 uint8_t reserved_4[8];
703 uint32_t error_subcode1;
704#define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
705 uint32_t error_subcode2;
706 uint32_t exchange_addr_to_abort;
707} __packed;
708
709/********************************************************************\
710 * Type Definitions used by initiator & target halves
711\********************************************************************/
712
713struct qla_tgt_mgmt_cmd;
714struct qla_tgt_sess;
715
716/*
717 * This structure provides a template of function calls that the
718 * target driver (from within qla_target.c) can issue to the
719 * target module (tcm_qla2xxx).
720 */
721struct qla_tgt_func_tmpl {
722
723 int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
724 unsigned char *, uint32_t, int, int, int);
Christoph Hellwig43381ce2012-07-08 15:58:44 -0400725 void (*handle_data)(struct qla_tgt_cmd *);
Quinn Tranf83adb62014-04-11 16:54:43 -0400726 void (*handle_dif_err)(struct qla_tgt_cmd *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400727 int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t,
728 uint32_t);
729 void (*free_cmd)(struct qla_tgt_cmd *);
730 void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
731 void (*free_session)(struct qla_tgt_sess *);
732
733 int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
734 void *, uint8_t *, uint16_t);
Roland Dreierc8292d12012-10-11 13:41:32 -0700735 void (*update_sess)(struct qla_tgt_sess *, port_id_t, uint16_t, bool);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400736 struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *,
737 const uint16_t);
738 struct qla_tgt_sess *(*find_sess_by_s_id)(struct scsi_qla_host *,
739 const uint8_t *);
740 void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *);
741 void (*put_sess)(struct qla_tgt_sess *);
742 void (*shutdown_sess)(struct qla_tgt_sess *);
743};
744
745int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
746
747#include <target/target_core_base.h>
748
749#define QLA_TGT_TIMEOUT 10 /* in seconds */
750
751#define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
752
753/* Immediate notify status constants */
754#define IMM_NTFY_LIP_RESET 0x000E
755#define IMM_NTFY_LIP_LINK_REINIT 0x000F
756#define IMM_NTFY_IOCB_OVERFLOW 0x0016
757#define IMM_NTFY_ABORT_TASK 0x0020
758#define IMM_NTFY_PORT_LOGOUT 0x0029
759#define IMM_NTFY_PORT_CONFIG 0x002A
760#define IMM_NTFY_GLBL_TPRLO 0x002D
761#define IMM_NTFY_GLBL_LOGO 0x002E
762#define IMM_NTFY_RESOURCE 0x0034
763#define IMM_NTFY_MSG_RX 0x0036
764#define IMM_NTFY_SRR 0x0045
765#define IMM_NTFY_ELS 0x0046
766
767/* Immediate notify task flags */
768#define IMM_NTFY_TASK_MGMT_SHIFT 8
769
770#define QLA_TGT_CLEAR_ACA 0x40
771#define QLA_TGT_TARGET_RESET 0x20
772#define QLA_TGT_LUN_RESET 0x10
773#define QLA_TGT_CLEAR_TS 0x04
774#define QLA_TGT_ABORT_TS 0x02
775#define QLA_TGT_ABORT_ALL_SESS 0xFFFF
776#define QLA_TGT_ABORT_ALL 0xFFFE
777#define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
778#define QLA_TGT_NEXUS_LOSS 0xFFFC
779
780/* Notify Acknowledge flags */
781#define NOTIFY_ACK_RES_COUNT BIT_8
782#define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
783#define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
784
785/* Command's states */
786#define QLA_TGT_STATE_NEW 0 /* New command + target processing */
787#define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
788#define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
789#define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
Quinn Tran193b50b2015-12-17 14:57:03 -0500790
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400791
792/* Special handles */
793#define QLA_TGT_NULL_HANDLE 0
794#define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
795
796/* ATIO task_codes field */
797#define ATIO_SIMPLE_QUEUE 0
798#define ATIO_HEAD_OF_QUEUE 1
799#define ATIO_ORDERED_QUEUE 2
800#define ATIO_ACA_QUEUE 4
801#define ATIO_UNTAGGED 5
802
803/* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
804#define FC_TM_SUCCESS 0
805#define FC_TM_BAD_FCP_DATA 1
806#define FC_TM_BAD_CMD 2
807#define FC_TM_FCP_DATA_MISMATCH 3
808#define FC_TM_REJECT 4
809#define FC_TM_FAILED 5
810
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400811#if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
812#define pci_dma_lo32(a) (a & 0xffffffff)
813#define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
814#else
815#define pci_dma_lo32(a) (a & 0xffffffff)
816#define pci_dma_hi32(a) 0
817#endif
818
819#define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
820 (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
821
822struct qla_port_24xx_data {
823 uint8_t port_name[WWN_SIZE];
824 uint16_t loop_id;
825 uint16_t reserved;
826};
827
828struct qla_tgt {
829 struct scsi_qla_host *vha;
830 struct qla_hw_data *ha;
831
832 /*
833 * To sync between IRQ handlers and qlt_target_release(). Needed,
834 * because req_pkt() can drop/reaquire HW lock inside. Protected by
835 * HW lock.
836 */
837 int irq_cmd_count;
838
839 int datasegs_per_cmd, datasegs_per_cont, sg_tablesize;
840
841 /* Target's flags, serialized by pha->hardware_lock */
842 unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addr enabled */
843 unsigned int link_reinit_iocb_pending:1;
844
845 /*
846 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
847 * OR hardware_lock for reading.
848 */
849 int tgt_stop; /* the target mode driver is being stopped */
850 int tgt_stopped; /* the target mode driver has been stopped */
851
852 /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
853 int sess_count;
854
855 /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
856 struct list_head sess_list;
857
858 /* Protected by hardware_lock */
859 struct list_head del_sess_list;
860 struct delayed_work sess_del_work;
861
862 spinlock_t sess_work_lock;
863 struct list_head sess_works_list;
864 struct work_struct sess_work;
865
866 struct imm_ntfy_from_isp link_reinit_iocb;
867 wait_queue_head_t waitQ;
868 int notify_ack_expected;
869 int abts_resp_expected;
870 int modify_lun_expected;
871
872 int ctio_srr_id;
873 int imm_srr_id;
874 spinlock_t srr_lock;
875 struct list_head srr_ctio_list;
876 struct list_head srr_imm_list;
877 struct work_struct srr_work;
878
879 atomic_t tgt_global_resets_count;
880
881 struct list_head tgt_list_entry;
882};
883
Nicholas Bellinger51a07f82014-05-23 02:00:56 -0700884struct qla_tgt_sess_op {
885 struct scsi_qla_host *vha;
886 struct atio_from_isp atio;
887 struct work_struct work;
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -0400888 struct list_head cmd_list;
889 bool aborted;
Nicholas Bellinger51a07f82014-05-23 02:00:56 -0700890};
891
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400892enum qla_sess_deletion {
893 QLA_SESS_DELETION_NONE = 0,
894 QLA_SESS_DELETION_PENDING = 1, /* hopefully we can get rid of
895 * this one */
896 QLA_SESS_DELETION_IN_PROGRESS = 2,
897};
898
Alexei Potashnikb7bd1042015-12-17 14:57:02 -0500899typedef enum {
900 QLT_PLOGI_LINK_SAME_WWN,
901 QLT_PLOGI_LINK_CONFLICT,
902 QLT_PLOGI_LINK_MAX
903} qlt_plogi_link_t;
904
905typedef struct {
906 struct list_head list;
907 struct imm_ntfy_from_isp iocb;
908 port_id_t id;
909 int ref_count;
910} qlt_plogi_ack_t;
911
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400912/*
913 * Equivilant to IT Nexus (Initiator-Target)
914 */
915struct qla_tgt_sess {
916 uint16_t loop_id;
917 port_id_t s_id;
918
919 unsigned int conf_compl_supported:1;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400920 unsigned int deleted:2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400921 unsigned int local:1;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400922 unsigned int logout_on_delete:1;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400923 unsigned int keep_nport_handle:1;
Alexei Potashnik71cdc072015-12-17 14:57:01 -0500924 unsigned int send_els_logo:1;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400925
926 unsigned char logout_completed;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400927
Alexei Potashnikdf673272015-07-14 16:00:46 -0400928 int generation;
929
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400930 struct se_session *se_sess;
931 struct scsi_qla_host *vha;
932 struct qla_tgt *tgt;
933
934 struct list_head sess_list_entry;
935 unsigned long expires;
936 struct list_head del_list_entry;
937
938 uint8_t port_name[WWN_SIZE];
939 struct work_struct free_work;
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400940
Alexei Potashnikb7bd1042015-12-17 14:57:02 -0500941 qlt_plogi_ack_t *plogi_link[QLT_PLOGI_LINK_MAX];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400942};
943
944struct qla_tgt_cmd {
Quinn Tranf83adb62014-04-11 16:54:43 -0400945 struct se_cmd se_cmd;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400946 struct qla_tgt_sess *sess;
947 int state;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400948 struct work_struct free_work;
949 struct work_struct work;
950 /* Sense buffer that will be mapped into outgoing status */
951 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
952
953 /* to save extra sess dereferences */
954 unsigned int conf_compl_supported:1;
955 unsigned int sg_mapped:1;
956 unsigned int free_sg:1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400957 unsigned int write_data_transferred:1;
Quinn Tranf83adb62014-04-11 16:54:43 -0400958 unsigned int ctx_dsd_alloced:1;
Quinn Tran33e79972014-09-25 06:14:55 -0400959 unsigned int q_full:1;
960 unsigned int term_exchg:1;
Quinn Trand564a372014-09-25 06:14:57 -0400961 unsigned int cmd_sent_to_fw:1;
Saurav Kashyape07f8f62014-09-25 06:14:58 -0400962 unsigned int cmd_in_wq:1;
Quinn Tran193b50b2015-12-17 14:57:03 -0500963 unsigned int aborted:1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400964
965 struct scatterlist *sg; /* cmd data buffer SG vector */
966 int sg_cnt; /* SG segments count */
967 int bufflen; /* cmd buffer length */
968 int offset;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400969 uint32_t unpacked_lun;
970 enum dma_data_direction dma_data_direction;
Arun Easib6a029e2014-09-25 06:14:52 -0400971 uint32_t reset_count;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400972
973 uint16_t loop_id; /* to save extra sess dereferences */
974 struct qla_tgt *tgt; /* to save extra sess dereferences */
975 struct scsi_qla_host *vha;
Quinn Tran33e79972014-09-25 06:14:55 -0400976 struct list_head cmd_list;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400977
978 struct atio_from_isp atio;
Quinn Tranf83adb62014-04-11 16:54:43 -0400979 /* t10dif */
980 struct scatterlist *prot_sg;
981 uint32_t prot_sg_cnt;
982 uint32_t blk_sz;
983 struct crc_context *ctx;
984
Saurav Kashyape07f8f62014-09-25 06:14:58 -0400985 uint64_t jiffies_at_alloc;
986 uint64_t jiffies_at_free;
987 /* BIT_0 - Atio Arrival / schedule to work
988 * BIT_1 - qlt_do_work
989 * BIT_2 - qlt_do work failed
990 * BIT_3 - xfer rdy/tcm_qla2xxx_write_pending
991 * BIT_4 - read respond/tcm_qla2xx_queue_data_in
992 * BIT_5 - status respond / tcm_qla2xx_queue_status
993 * BIT_6 - tcm request to abort/Term exchange.
994 * pre_xmit_response->qlt_send_term_exchange
995 * BIT_7 - SRR received (qlt_handle_srr->qlt_xmit_response)
996 * BIT_8 - SRR received (qlt_handle_srr->qlt_rdy_to_xfer)
997 * BIT_9 - SRR received (qla_handle_srr->qlt_send_term_exchange)
998 * BIT_10 - Data in - hanlde_data->tcm_qla2xxx_handle_data
999 * BIT_11 - Data actually going to TCM : tcm_qla2xx_handle_data_work
1000 * BIT_12 - good completion - qlt_ctio_do_completion -->free_cmd
1001 * BIT_13 - Bad completion -
1002 * qlt_ctio_do_completion --> qlt_term_ctio_exchange
1003 * BIT_14 - Back end data received/sent.
1004 * BIT_15 - SRR prepare ctio
1005 * BIT_16 - complete free
Quinn Trane5fdee82015-06-10 11:05:21 -04001006 * BIT_17 - flush - qlt_abort_cmd_on_host_reset
1007 * BIT_18 - completion w/abort status
1008 * BIT_19 - completion w/unknown status
Saurav Kashyape07f8f62014-09-25 06:14:58 -04001009 */
1010 uint32_t cmd_flags;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001011};
1012
1013struct qla_tgt_sess_work_param {
1014 struct list_head sess_works_list_entry;
1015
1016#define QLA_TGT_SESS_WORK_ABORT 1
1017#define QLA_TGT_SESS_WORK_TM 2
1018 int type;
1019
1020 union {
1021 struct abts_recv_from_24xx abts;
1022 struct imm_ntfy_from_isp tm_iocb;
1023 struct atio_from_isp tm_iocb2;
1024 };
1025};
1026
1027struct qla_tgt_mgmt_cmd {
1028 uint8_t tmr_func;
1029 uint8_t fc_tm_rsp;
1030 struct qla_tgt_sess *sess;
1031 struct se_cmd se_cmd;
1032 struct work_struct free_work;
1033 unsigned int flags;
Arun Easib6a029e2014-09-25 06:14:52 -04001034 uint32_t reset_count;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001035#define QLA24XX_MGMT_SEND_NACK 1
1036 union {
1037 struct atio_from_isp atio;
1038 struct imm_ntfy_from_isp imm_ntfy;
1039 struct abts_recv_from_24xx abts;
1040 } __packed orig_iocb;
1041};
1042
1043struct qla_tgt_prm {
1044 struct qla_tgt_cmd *cmd;
1045 struct qla_tgt *tgt;
1046 void *pkt;
1047 struct scatterlist *sg; /* cmd data buffer SG vector */
Joern Engeldb3a99b2014-09-16 16:23:19 -04001048 unsigned char *sense_buffer;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001049 int seg_cnt;
1050 int req_cnt;
1051 uint16_t rq_result;
1052 uint16_t scsi_status;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001053 int sense_buffer_len;
1054 int residual;
1055 int add_status_pkt;
Quinn Tranf83adb62014-04-11 16:54:43 -04001056 /* dif */
1057 struct scatterlist *prot_sg;
1058 uint16_t prot_seg_cnt;
1059 uint16_t tot_dsds;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001060};
1061
1062struct qla_tgt_srr_imm {
1063 struct list_head srr_list_entry;
1064 int srr_id;
1065 struct imm_ntfy_from_isp imm_ntfy;
1066};
1067
1068struct qla_tgt_srr_ctio {
1069 struct list_head srr_list_entry;
1070 int srr_id;
1071 struct qla_tgt_cmd *cmd;
1072};
1073
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001074/* Check for Switch reserved address */
1075#define IS_SW_RESV_ADDR(_s_id) \
1076 ((_s_id.b.domain == 0xff) && (_s_id.b.area == 0xfc))
1077
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001078#define QLA_TGT_XMIT_DATA 1
1079#define QLA_TGT_XMIT_STATUS 2
1080#define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
1081
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001082
1083extern struct qla_tgt_data qla_target;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001084
1085/*
1086 * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
1087 */
1088extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
1089extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
Nicholas Bellinger49a47f22014-01-14 20:38:58 -08001090extern int qlt_lport_register(void *, u64, u64, u64,
1091 int (*callback)(struct scsi_qla_host *, void *, u64, u64));
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001092extern void qlt_lport_deregister(struct scsi_qla_host *);
1093extern void qlt_unreg_sess(struct qla_tgt_sess *);
1094extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
Alexei Potashnikdf673272015-07-14 16:00:46 -04001095extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001096extern int __init qlt_init(void);
1097extern void qlt_exit(void);
1098extern void qlt_update_vp_map(struct scsi_qla_host *, int);
1099
1100/*
1101 * This macro is used during early initializations when host->active_mode
1102 * is not set. Right now, ha value is ignored.
1103 */
1104#define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
Arun Easiaa230bc2013-01-30 03:34:39 -05001105extern int ql2x_ini_mode;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001106
1107static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
1108{
1109 return ha->host->active_mode & MODE_TARGET;
1110}
1111
1112static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
1113{
1114 return ha->host->active_mode & MODE_INITIATOR;
1115}
1116
1117static inline void qla_reverse_ini_mode(struct scsi_qla_host *ha)
1118{
1119 if (ha->host->active_mode & MODE_INITIATOR)
1120 ha->host->active_mode &= ~MODE_INITIATOR;
1121 else
1122 ha->host->active_mode |= MODE_INITIATOR;
1123}
1124
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04001125static inline uint32_t sid_to_key(const uint8_t *s_id)
1126{
1127 uint32_t key;
1128
1129 key = (((unsigned long)s_id[0] << 16) |
1130 ((unsigned long)s_id[1] << 8) |
1131 (unsigned long)s_id[2]);
1132 return key;
1133}
1134
Alexei Potashnik71cdc072015-12-17 14:57:01 -05001135static inline void sid_to_portid(const uint8_t *s_id, port_id_t *p)
1136{
1137 memset(p, 0, sizeof(*p));
1138 p->b.domain = s_id[0];
1139 p->b.area = s_id[1];
1140 p->b.al_pa = s_id[2];
1141}
1142
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001143/*
1144 * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
1145 */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001146extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, response_t *);
1147extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
1148extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
Alexei Potashnik7359df22015-07-14 16:00:49 -04001149extern void qlt_abort_cmd(struct qla_tgt_cmd *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001150extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
1151extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
1152extern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001153extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
1154extern void qlt_enable_vha(struct scsi_qla_host *);
1155extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
1156extern void qlt_rff_id(struct scsi_qla_host *, struct ct_sns_req *);
1157extern void qlt_init_atio_q_entries(struct scsi_qla_host *);
1158extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *);
Arun Easiaa230bc2013-01-30 03:34:39 -05001159extern void qlt_24xx_config_rings(struct scsi_qla_host *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001160extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
1161 struct nvram_24xx *);
1162extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
1163 struct init_cb_24xx *);
Arun Easiaa230bc2013-01-30 03:34:39 -05001164extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
1165 struct init_cb_81xx *);
1166extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
1167 struct nvram_81xx *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001168extern int qlt_24xx_process_response_error(struct scsi_qla_host *,
1169 struct sts_entry_24xx *);
1170extern void qlt_modify_vp_config(struct scsi_qla_host *,
1171 struct vp_config_entry_24xx *);
1172extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
1173extern int qlt_mem_alloc(struct qla_hw_data *);
1174extern void qlt_mem_free(struct qla_hw_data *);
Nicholas Bellinger3c231bd2014-02-19 17:50:22 -08001175extern int qlt_stop_phase1(struct qla_tgt *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001176extern void qlt_stop_phase2(struct qla_tgt *);
Arun Easiaa230bc2013-01-30 03:34:39 -05001177extern irqreturn_t qla83xx_msix_atio_q(int, void *);
1178extern void qlt_83xx_iospace_config(struct qla_hw_data *);
Quinn Tran33e79972014-09-25 06:14:55 -04001179extern int qlt_free_qfull_cmds(struct scsi_qla_host *);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001180extern void qlt_logo_completion_handler(fc_port_t *, int);
Alexei Potashnikdf673272015-07-14 16:00:46 -04001181extern void qlt_do_generation_tick(struct scsi_qla_host *, int *);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001182
1183#endif /* __QLA_TARGET_H */