1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#ifndef __QLA_TARGET_H
29#define __QLA_TARGET_H
30
31#include <asm/unaligned.h>
32#include "qla_def.h"
33
34
35
36
37
38#define QLA2XXX_TARGET_MAGIC 269
39
40
41
42
43
44#define QLA2XXX_INITIATOR_MAGIC 57222
45
46#define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive"
47#define QLA2XXX_INI_MODE_STR_DISABLED "disabled"
48#define QLA2XXX_INI_MODE_STR_ENABLED "enabled"
49#define QLA2XXX_INI_MODE_STR_DUAL "dual"
50
51#define QLA2XXX_INI_MODE_EXCLUSIVE 0
52#define QLA2XXX_INI_MODE_DISABLED 1
53#define QLA2XXX_INI_MODE_ENABLED 2
54#define QLA2XXX_INI_MODE_DUAL 3
55
56#define QLA2XXX_COMMAND_COUNT_INIT 250
57#define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
58
59
60
61
62
63
64
65#define CTIO_COMPLETION_HANDLE_MARK BIT_29
66#if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
67#error "CTIO_COMPLETION_HANDLE_MARK not larger than "
68 "DEFAULT_OUTSTANDING_COMMANDS"
69#endif
70#define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
71
72
73#define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
74#define QLA_TGT_NULL_HANDLE 0
75
76#define QLA_TGT_HANDLE_MASK 0xF0000000
77#define QLA_QPID_HANDLE_MASK 0x00FF0000
78#define QLA_CMD_HANDLE_MASK 0x0000FFFF
79#define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~QLA_TGT_HANDLE_MASK)
80
81#define QLA_QPID_HANDLE_SHIFT 16
82#define GET_QID(_h) ((_h & QLA_QPID_HANDLE_MASK) >> QLA_QPID_HANDLE_SHIFT)
83
84
85#ifndef OF_SS_MODE_0
86
87
88
89#define OF_SS_MODE_0 0
90#define OF_SS_MODE_1 1
91#define OF_SS_MODE_2 2
92#define OF_SS_MODE_3 3
93
94#define OF_EXPL_CONF BIT_5
95#define OF_DATA_IN BIT_6
96
97#define OF_DATA_OUT BIT_7
98
99#define OF_NO_DATA (BIT_7 | BIT_6)
100#define OF_INC_RC BIT_8
101#define OF_FAST_POST BIT_9
102#define OF_CONF_REQ BIT_13
103#define OF_TERM_EXCH BIT_14
104#define OF_SSTS BIT_15
105#endif
106
107#ifndef QLA_TGT_DATASEGS_PER_CMD32
108#define QLA_TGT_DATASEGS_PER_CMD32 3
109#define QLA_TGT_DATASEGS_PER_CONT32 7
110#define QLA_TGT_MAX_SG32(ql) \
111 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
112 QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
113
114#define QLA_TGT_DATASEGS_PER_CMD64 2
115#define QLA_TGT_DATASEGS_PER_CONT64 5
116#define QLA_TGT_MAX_SG64(ql) \
117 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
118 QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
119#endif
120
121#ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
122#define QLA_TGT_DATASEGS_PER_CMD_24XX 1
123#define QLA_TGT_DATASEGS_PER_CONT_24XX 5
124#define QLA_TGT_MAX_SG_24XX(ql) \
125 (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
126 QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
127#endif
128#endif
129
130#define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
131 ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
132 : (uint16_t)(iocb)->u.isp2x.target.id.standard)
133
134#ifndef NOTIFY_ACK_TYPE
135#define NOTIFY_ACK_TYPE 0x0E
136
137
138
139
140struct nack_to_isp {
141 uint8_t entry_type;
142 uint8_t entry_count;
143 uint8_t sys_define;
144 uint8_t entry_status;
145 union {
146 struct {
147 uint32_t sys_define_2;
148 target_id_t target;
149 uint8_t target_id;
150 uint8_t reserved_1;
151 uint16_t flags;
152 uint16_t resp_code;
153 uint16_t status;
154 uint16_t task_flags;
155 uint16_t seq_id;
156 uint16_t srr_rx_id;
157 uint32_t srr_rel_offs;
158 uint16_t srr_ui;
159 uint16_t srr_flags;
160 uint16_t srr_reject_code;
161 uint8_t srr_reject_vendor_uniq;
162 uint8_t srr_reject_code_expl;
163 uint8_t reserved_2[24];
164 } isp2x;
165 struct {
166 uint32_t handle;
167 uint16_t nport_handle;
168 uint16_t reserved_1;
169 uint16_t flags;
170 uint16_t srr_rx_id;
171 uint16_t status;
172 uint8_t status_subcode;
173 uint8_t fw_handle;
174 uint32_t exchange_address;
175 uint32_t srr_rel_offs;
176 uint16_t srr_ui;
177 uint16_t srr_flags;
178 uint8_t reserved_4[19];
179 uint8_t vp_index;
180 uint8_t srr_reject_vendor_uniq;
181 uint8_t srr_reject_code_expl;
182 uint8_t srr_reject_code;
183 uint8_t reserved_5[5];
184 } isp24;
185 } u;
186 uint8_t reserved[2];
187 uint16_t ox_id;
188} __packed;
189#define NOTIFY_ACK_FLAGS_TERMINATE BIT_3
190#define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
191#define NOTIFY_ACK_SRR_FLAGS_REJECT 1
192
193#define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
194
195#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
196#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
197
198#define NOTIFY_ACK_SUCCESS 0x01
199#endif
200
201#ifndef ACCEPT_TGT_IO_TYPE
202#define ACCEPT_TGT_IO_TYPE 0x16
203#endif
204
205#ifndef CONTINUE_TGT_IO_TYPE
206#define CONTINUE_TGT_IO_TYPE 0x17
207
208
209
210
211struct ctio_to_2xxx {
212 uint8_t entry_type;
213 uint8_t entry_count;
214 uint8_t sys_define;
215 uint8_t entry_status;
216 uint32_t handle;
217 target_id_t target;
218 uint16_t rx_id;
219 uint16_t flags;
220 uint16_t status;
221 uint16_t timeout;
222 uint16_t dseg_count;
223 uint32_t relative_offset;
224 uint32_t residual;
225 uint16_t reserved_1[3];
226 uint16_t scsi_status;
227 uint32_t transfer_length;
228 uint32_t dseg_0_address;
229 uint32_t dseg_0_length;
230 uint32_t dseg_1_address;
231 uint32_t dseg_1_length;
232 uint32_t dseg_2_address;
233 uint32_t dseg_2_length;
234} __packed;
235#define ATIO_PATH_INVALID 0x07
236#define ATIO_CANT_PROV_CAP 0x16
237#define ATIO_CDB_VALID 0x3D
238
239#define ATIO_EXEC_READ BIT_1
240#define ATIO_EXEC_WRITE BIT_0
241#endif
242
243#ifndef CTIO_A64_TYPE
244#define CTIO_A64_TYPE 0x1F
245#define CTIO_SUCCESS 0x01
246#define CTIO_ABORTED 0x02
247#define CTIO_INVALID_RX_ID 0x08
248#define CTIO_TIMEOUT 0x0B
249#define CTIO_DIF_ERROR 0x0C
250#define CTIO_LIP_RESET 0x0E
251#define CTIO_TARGET_RESET 0x17
252#define CTIO_PORT_UNAVAILABLE 0x28
253#define CTIO_PORT_LOGGED_OUT 0x29
254#define CTIO_PORT_CONF_CHANGED 0x2A
255#define CTIO_SRR_RECEIVED 0x45
256#endif
257
258#ifndef CTIO_RET_TYPE
259#define CTIO_RET_TYPE 0x17
260#define ATIO_TYPE7 0x06
261
262struct fcp_hdr {
263 uint8_t r_ctl;
264 uint8_t d_id[3];
265 uint8_t cs_ctl;
266 uint8_t s_id[3];
267 uint8_t type;
268 uint8_t f_ctl[3];
269 uint8_t seq_id;
270 uint8_t df_ctl;
271 uint16_t seq_cnt;
272 __be16 ox_id;
273 uint16_t rx_id;
274 uint32_t parameter;
275} __packed;
276
277struct fcp_hdr_le {
278 uint8_t d_id[3];
279 uint8_t r_ctl;
280 uint8_t s_id[3];
281 uint8_t cs_ctl;
282 uint8_t f_ctl[3];
283 uint8_t type;
284 uint16_t seq_cnt;
285 uint8_t df_ctl;
286 uint8_t seq_id;
287 uint16_t rx_id;
288 uint16_t ox_id;
289 uint32_t parameter;
290} __packed;
291
292#define F_CTL_EXCH_CONTEXT_RESP BIT_23
293#define F_CTL_SEQ_CONTEXT_RESIP BIT_22
294#define F_CTL_LAST_SEQ BIT_20
295#define F_CTL_END_SEQ BIT_19
296#define F_CTL_SEQ_INITIATIVE BIT_16
297
298#define R_CTL_BASIC_LINK_SERV 0x80
299#define R_CTL_B_ACC 0x4
300#define R_CTL_B_RJT 0x5
301
302struct atio7_fcp_cmnd {
303 uint64_t lun;
304 uint8_t cmnd_ref;
305 uint8_t task_attr:3;
306 uint8_t reserved:5;
307 uint8_t task_mgmt_flags;
308#define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
309#define FCP_CMND_TASK_MGMT_TARGET_RESET 5
310#define FCP_CMND_TASK_MGMT_LU_RESET 4
311#define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
312#define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
313 uint8_t wrdata:1;
314 uint8_t rddata:1;
315 uint8_t add_cdb_len:6;
316 uint8_t cdb[16];
317
318
319
320
321
322 uint8_t add_cdb[4];
323
324} __packed;
325
326
327
328
329
330struct atio_from_isp {
331 union {
332 struct {
333 uint16_t entry_hdr;
334 uint8_t sys_define;
335 uint8_t entry_status;
336 uint32_t sys_define_2;
337 target_id_t target;
338 uint16_t rx_id;
339 uint16_t flags;
340 uint16_t status;
341 uint8_t command_ref;
342 uint8_t task_codes;
343 uint8_t task_flags;
344 uint8_t execution_codes;
345 uint8_t cdb[MAX_CMDSZ];
346 uint32_t data_length;
347 uint16_t lun;
348 uint8_t initiator_port_name[WWN_SIZE];
349 uint16_t reserved_32[6];
350 uint16_t ox_id;
351 } isp2x;
352 struct {
353 uint16_t entry_hdr;
354 uint8_t fcp_cmnd_len_low;
355 uint8_t fcp_cmnd_len_high:4;
356 uint8_t attr:4;
357 uint32_t exchange_addr;
358#define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
359 struct fcp_hdr fcp_hdr;
360 struct atio7_fcp_cmnd fcp_cmnd;
361 } isp24;
362 struct {
363 uint8_t entry_type;
364 uint8_t entry_count;
365 __le16 attr_n_length;
366#define FCP_CMD_LENGTH_MASK 0x0fff
367#define FCP_CMD_LENGTH_MIN 0x38
368 uint8_t data[56];
369 uint32_t signature;
370#define ATIO_PROCESSED 0xDEADDEAD
371 } raw;
372 } u;
373} __packed;
374
375static inline int fcpcmd_is_corrupted(struct atio *atio)
376{
377 if (atio->entry_type == ATIO_TYPE7 &&
378 (le16_to_cpu(atio->attr_n_length & FCP_CMD_LENGTH_MASK) <
379 FCP_CMD_LENGTH_MIN))
380 return 1;
381 else
382 return 0;
383}
384
385
386static inline void adjust_corrupted_atio(struct atio_from_isp *atio)
387{
388 atio->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENGTH_MIN);
389 atio->u.isp24.fcp_cmnd.add_cdb_len = 0;
390}
391
392static inline int get_datalen_for_atio(struct atio_from_isp *atio)
393{
394 int len = atio->u.isp24.fcp_cmnd.add_cdb_len;
395
396 return (be32_to_cpu(get_unaligned((uint32_t *)
397 &atio->u.isp24.fcp_cmnd.add_cdb[len * 4])));
398}
399
400#define CTIO_TYPE7 0x12
401
402
403
404
405
406
407struct ctio7_to_24xx {
408 uint8_t entry_type;
409 uint8_t entry_count;
410 uint8_t sys_define;
411 uint8_t entry_status;
412 uint32_t handle;
413 uint16_t nport_handle;
414#define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
415 uint16_t timeout;
416 uint16_t dseg_count;
417 uint8_t vp_index;
418 uint8_t add_flags;
419 uint8_t initiator_id[3];
420 uint8_t reserved;
421 uint32_t exchange_addr;
422 union {
423 struct {
424 uint16_t reserved1;
425 __le16 flags;
426 uint32_t residual;
427 __le16 ox_id;
428 uint16_t scsi_status;
429 uint32_t relative_offset;
430 uint32_t reserved2;
431 uint32_t transfer_length;
432 uint32_t reserved3;
433
434 uint32_t dseg_0_address[2];
435
436 uint32_t dseg_0_length;
437 } status0;
438 struct {
439 uint16_t sense_length;
440 __le16 flags;
441 uint32_t residual;
442 __le16 ox_id;
443 uint16_t scsi_status;
444 uint16_t response_len;
445 uint16_t reserved;
446 uint8_t sense_data[24];
447 } status1;
448 } u;
449} __packed;
450
451
452
453
454
455struct ctio7_from_24xx {
456 uint8_t entry_type;
457 uint8_t entry_count;
458 uint8_t sys_define;
459 uint8_t entry_status;
460 uint32_t handle;
461 uint16_t status;
462 uint16_t timeout;
463 uint16_t dseg_count;
464 uint8_t vp_index;
465 uint8_t reserved1[5];
466 uint32_t exchange_address;
467 uint16_t reserved2;
468 uint16_t flags;
469 uint32_t residual;
470 uint16_t ox_id;
471 uint16_t reserved3;
472 uint32_t relative_offset;
473 uint8_t reserved4[24];
474} __packed;
475
476
477#define CTIO7_FLAGS_SEND_STATUS BIT_15
478#define CTIO7_FLAGS_TERMINATE BIT_14
479#define CTIO7_FLAGS_CONFORM_REQ BIT_13
480#define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
481#define CTIO7_FLAGS_STATUS_MODE_0 0
482#define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
483#define CTIO7_FLAGS_STATUS_MODE_2 BIT_7
484#define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
485#define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
486#define CTIO7_FLAGS_DSD_PTR BIT_2
487#define CTIO7_FLAGS_DATA_IN BIT_1
488#define CTIO7_FLAGS_DATA_OUT BIT_0
489
490#define ELS_PLOGI 0x3
491#define ELS_FLOGI 0x4
492#define ELS_LOGO 0x5
493#define ELS_PRLI 0x20
494#define ELS_PRLO 0x21
495#define ELS_TPRLO 0x24
496#define ELS_PDISC 0x50
497#define ELS_ADISC 0x52
498
499
500
501
502struct ctio_crc2_to_fw {
503 uint8_t entry_type;
504#define CTIO_CRC2 0x7A
505 uint8_t entry_count;
506 uint8_t sys_define;
507 uint8_t entry_status;
508
509 uint32_t handle;
510 uint16_t nport_handle;
511 __le16 timeout;
512
513 uint16_t dseg_count;
514 uint8_t vp_index;
515 uint8_t add_flags;
516#define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
517
518 uint8_t initiator_id[3];
519 uint8_t reserved1;
520 uint32_t exchange_addr;
521 uint16_t reserved2;
522 __le16 flags;
523 uint32_t residual;
524 __le16 ox_id;
525 uint16_t scsi_status;
526 __le32 relative_offset;
527 uint32_t reserved5;
528 __le32 transfer_length;
529 uint32_t reserved6;
530 __le32 crc_context_address[2];
531 uint16_t crc_context_len;
532 uint16_t reserved_1;
533} __packed;
534
535
536struct ctio_crc_from_fw {
537 uint8_t entry_type;
538 uint8_t entry_count;
539 uint8_t sys_define;
540 uint8_t entry_status;
541
542 uint32_t handle;
543 uint16_t status;
544 uint16_t timeout;
545 uint16_t dseg_count;
546 uint32_t reserved1;
547 uint16_t state_flags;
548#define CTIO_CRC_SF_DIF_CHOPPED BIT_4
549
550 uint32_t exchange_address;
551 uint16_t reserved2;
552 uint16_t flags;
553 uint32_t resid_xfer_length;
554 uint16_t ox_id;
555 uint8_t reserved3[12];
556 uint16_t runt_guard;
557 uint8_t actual_dif[8];
558 uint8_t expected_dif[8];
559} __packed;
560
561
562
563
564#define ABTS_RECV_24XX 0x54
565#define ABTS_RESP_24XX 0x55
566
567
568
569
570
571
572
573struct abts_recv_from_24xx {
574 uint8_t entry_type;
575 uint8_t entry_count;
576 uint8_t sys_define;
577 uint8_t entry_status;
578 uint8_t reserved_1[6];
579 uint16_t nport_handle;
580 uint8_t reserved_2[2];
581 uint8_t vp_index;
582 uint8_t reserved_3:4;
583 uint8_t sof_type:4;
584 uint32_t exchange_address;
585 struct fcp_hdr_le fcp_hdr_le;
586 uint8_t reserved_4[16];
587 uint32_t exchange_addr_to_abort;
588} __packed;
589
590#define ABTS_PARAM_ABORT_SEQ BIT_0
591
592struct ba_acc_le {
593 uint16_t reserved;
594 uint8_t seq_id_last;
595 uint8_t seq_id_valid;
596#define SEQ_ID_VALID 0x80
597#define SEQ_ID_INVALID 0x00
598 uint16_t rx_id;
599 uint16_t ox_id;
600 uint16_t high_seq_cnt;
601 uint16_t low_seq_cnt;
602} __packed;
603
604struct ba_rjt_le {
605 uint8_t vendor_uniq;
606 uint8_t reason_expl;
607 uint8_t reason_code;
608#define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
609#define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
610 uint8_t reserved;
611} __packed;
612
613
614
615
616
617
618
619struct abts_resp_to_24xx {
620 uint8_t entry_type;
621 uint8_t entry_count;
622 uint8_t sys_define;
623 uint8_t entry_status;
624 uint32_t handle;
625 uint16_t reserved_1;
626 uint16_t nport_handle;
627 uint16_t control_flags;
628#define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
629 uint8_t vp_index;
630 uint8_t reserved_3:4;
631 uint8_t sof_type:4;
632 uint32_t exchange_address;
633 struct fcp_hdr_le fcp_hdr_le;
634 union {
635 struct ba_acc_le ba_acct;
636 struct ba_rjt_le ba_rjt;
637 } __packed payload;
638 uint32_t reserved_4;
639 uint32_t exchange_addr_to_abort;
640} __packed;
641
642
643
644
645
646
647
648
649struct abts_resp_from_24xx_fw {
650 uint8_t entry_type;
651 uint8_t entry_count;
652 uint8_t sys_define;
653 uint8_t entry_status;
654 uint32_t handle;
655 uint16_t compl_status;
656#define ABTS_RESP_COMPL_SUCCESS 0
657#define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
658 uint16_t nport_handle;
659 uint16_t reserved_1;
660 uint8_t reserved_2;
661 uint8_t reserved_3:4;
662 uint8_t sof_type:4;
663 uint32_t exchange_address;
664 struct fcp_hdr_le fcp_hdr_le;
665 uint8_t reserved_4[8];
666 uint32_t error_subcode1;
667#define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
668 uint32_t error_subcode2;
669 uint32_t exchange_addr_to_abort;
670} __packed;
671
672
673
674
675
676struct qla_tgt_mgmt_cmd;
677struct fc_port;
678struct qla_tgt_cmd;
679
680
681
682
683
684
685struct qla_tgt_func_tmpl {
686
687 int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
688 unsigned char *, uint32_t, int, int, int);
689 void (*handle_data)(struct qla_tgt_cmd *);
690 int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, u64, uint16_t,
691 uint32_t);
692 void (*free_cmd)(struct qla_tgt_cmd *);
693 void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
694 void (*free_session)(struct fc_port *);
695
696 int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
697 struct fc_port *);
698 void (*update_sess)(struct fc_port *, port_id_t, uint16_t, bool);
699 struct fc_port *(*find_sess_by_loop_id)(struct scsi_qla_host *,
700 const uint16_t);
701 struct fc_port *(*find_sess_by_s_id)(struct scsi_qla_host *,
702 const uint8_t *);
703 void (*clear_nacl_from_fcport_map)(struct fc_port *);
704 void (*put_sess)(struct fc_port *);
705 void (*shutdown_sess)(struct fc_port *);
706 int (*get_dif_tags)(struct qla_tgt_cmd *cmd, uint16_t *pfw_prot_opts);
707 int (*chk_dif_tags)(uint32_t tag);
708 void (*add_target)(struct scsi_qla_host *);
709 void (*remove_target)(struct scsi_qla_host *);
710};
711
712int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
713
714#include <target/target_core_base.h>
715
716#define QLA_TGT_TIMEOUT 10
717
718#define QLA_TGT_MAX_HW_PENDING_TIME 60
719
720
721#define IMM_NTFY_LIP_RESET 0x000E
722#define IMM_NTFY_LIP_LINK_REINIT 0x000F
723#define IMM_NTFY_IOCB_OVERFLOW 0x0016
724#define IMM_NTFY_ABORT_TASK 0x0020
725#define IMM_NTFY_PORT_LOGOUT 0x0029
726#define IMM_NTFY_PORT_CONFIG 0x002A
727#define IMM_NTFY_GLBL_TPRLO 0x002D
728#define IMM_NTFY_GLBL_LOGO 0x002E
729#define IMM_NTFY_RESOURCE 0x0034
730#define IMM_NTFY_MSG_RX 0x0036
731#define IMM_NTFY_SRR 0x0045
732#define IMM_NTFY_ELS 0x0046
733
734
735#define IMM_NTFY_TASK_MGMT_SHIFT 8
736
737#define QLA_TGT_CLEAR_ACA 0x40
738#define QLA_TGT_TARGET_RESET 0x20
739#define QLA_TGT_LUN_RESET 0x10
740#define QLA_TGT_CLEAR_TS 0x04
741#define QLA_TGT_ABORT_TS 0x02
742#define QLA_TGT_ABORT_ALL_SESS 0xFFFF
743#define QLA_TGT_ABORT_ALL 0xFFFE
744#define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
745#define QLA_TGT_NEXUS_LOSS 0xFFFC
746#define QLA_TGT_ABTS 0xFFFB
747#define QLA_TGT_2G_ABORT_TASK 0xFFFA
748
749
750#define NOTIFY_ACK_RES_COUNT BIT_8
751#define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
752#define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
753
754
755#define QLA_TGT_STATE_NEW 0
756#define QLA_TGT_STATE_NEED_DATA 1
757#define QLA_TGT_STATE_DATA_IN 2
758#define QLA_TGT_STATE_PROCESSED 3
759
760
761#define ATIO_SIMPLE_QUEUE 0
762#define ATIO_HEAD_OF_QUEUE 1
763#define ATIO_ORDERED_QUEUE 2
764#define ATIO_ACA_QUEUE 4
765#define ATIO_UNTAGGED 5
766
767
768#define FC_TM_SUCCESS 0
769#define FC_TM_BAD_FCP_DATA 1
770#define FC_TM_BAD_CMD 2
771#define FC_TM_FCP_DATA_MISMATCH 3
772#define FC_TM_REJECT 4
773#define FC_TM_FAILED 5
774
775#if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
776#define pci_dma_lo32(a) (a & 0xffffffff)
777#define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
778#else
779#define pci_dma_lo32(a) (a & 0xffffffff)
780#define pci_dma_hi32(a) 0
781#endif
782
783#define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
784 (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
785
786struct qla_port_24xx_data {
787 uint8_t port_name[WWN_SIZE];
788 uint16_t loop_id;
789 uint16_t reserved;
790};
791
792struct qla_qpair_hint {
793 struct list_head hint_elem;
794 struct qla_qpair *qpair;
795 u16 cpuid;
796 uint8_t cmd_cnt;
797};
798
799struct qla_tgt {
800 struct scsi_qla_host *vha;
801 struct qla_hw_data *ha;
802 struct btree_head64 lun_qpair_map;
803 struct qla_qpair_hint *qphints;
804
805
806
807
808
809 int atio_irq_cmd_count;
810
811 int sg_tablesize;
812
813
814 unsigned int link_reinit_iocb_pending:1;
815
816
817
818
819
820 int tgt_stop;
821 int tgt_stopped;
822
823
824 int sess_count;
825
826
827 struct list_head del_sess_list;
828
829 spinlock_t sess_work_lock;
830 struct list_head sess_works_list;
831 struct work_struct sess_work;
832
833 struct imm_ntfy_from_isp link_reinit_iocb;
834 wait_queue_head_t waitQ;
835 int notify_ack_expected;
836 int abts_resp_expected;
837 int modify_lun_expected;
838 atomic_t tgt_global_resets_count;
839 struct list_head tgt_list_entry;
840};
841
842struct qla_tgt_sess_op {
843 struct scsi_qla_host *vha;
844 uint32_t chip_reset;
845 struct atio_from_isp atio;
846 struct work_struct work;
847 struct list_head cmd_list;
848 bool aborted;
849 struct rsp_que *rsp;
850};
851
852enum trace_flags {
853 TRC_NEW_CMD = BIT_0,
854 TRC_DO_WORK = BIT_1,
855 TRC_DO_WORK_ERR = BIT_2,
856 TRC_XFR_RDY = BIT_3,
857 TRC_XMIT_DATA = BIT_4,
858 TRC_XMIT_STATUS = BIT_5,
859 TRC_SRR_RSP = BIT_6,
860 TRC_SRR_XRDY = BIT_7,
861 TRC_SRR_TERM = BIT_8,
862 TRC_SRR_CTIO = BIT_9,
863 TRC_FLUSH = BIT_10,
864 TRC_CTIO_ERR = BIT_11,
865 TRC_CTIO_DONE = BIT_12,
866 TRC_CTIO_ABORTED = BIT_13,
867 TRC_CTIO_STRANGE= BIT_14,
868 TRC_CMD_DONE = BIT_15,
869 TRC_CMD_CHK_STOP = BIT_16,
870 TRC_CMD_FREE = BIT_17,
871 TRC_DATA_IN = BIT_18,
872 TRC_ABORT = BIT_19,
873 TRC_DIF_ERR = BIT_20,
874};
875
876struct qla_tgt_cmd {
877
878
879
880 uint8_t cmd_type;
881 uint8_t pad[7];
882 struct se_cmd se_cmd;
883 struct fc_port *sess;
884 struct qla_qpair *qpair;
885 uint32_t reset_count;
886 int state;
887 struct work_struct work;
888
889 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
890
891 spinlock_t cmd_lock;
892
893 unsigned int conf_compl_supported:1;
894 unsigned int sg_mapped:1;
895 unsigned int free_sg:1;
896 unsigned int write_data_transferred:1;
897 unsigned int q_full:1;
898 unsigned int term_exchg:1;
899 unsigned int cmd_sent_to_fw:1;
900 unsigned int cmd_in_wq:1;
901 unsigned int aborted:1;
902 unsigned int data_work:1;
903 unsigned int data_work_free:1;
904
905 struct scatterlist *sg;
906 int sg_cnt;
907 int bufflen;
908 int offset;
909 u64 unpacked_lun;
910 enum dma_data_direction dma_data_direction;
911
912 uint16_t vp_idx;
913 uint16_t loop_id;
914 struct qla_tgt *tgt;
915 struct scsi_qla_host *vha;
916 struct list_head cmd_list;
917
918 struct atio_from_isp atio;
919
920 uint8_t ctx_dsd_alloced;
921
922
923#define DIF_ERR_NONE 0
924#define DIF_ERR_GRD 1
925#define DIF_ERR_REF 2
926#define DIF_ERR_APP 3
927 int8_t dif_err_code;
928 struct scatterlist *prot_sg;
929 uint32_t prot_sg_cnt;
930 uint32_t blk_sz, num_blks;
931 uint8_t scsi_status, sense_key, asc, ascq;
932
933 struct crc_context *ctx;
934 uint8_t *cdb;
935 uint64_t lba;
936 uint16_t a_guard, e_guard, a_app_tag, e_app_tag;
937 uint32_t a_ref_tag, e_ref_tag;
938
939 uint64_t jiffies_at_alloc;
940 uint64_t jiffies_at_free;
941
942 enum trace_flags trc_flags;
943};
944
945struct qla_tgt_sess_work_param {
946 struct list_head sess_works_list_entry;
947
948#define QLA_TGT_SESS_WORK_ABORT 1
949#define QLA_TGT_SESS_WORK_TM 2
950 int type;
951
952 union {
953 struct abts_recv_from_24xx abts;
954 struct imm_ntfy_from_isp tm_iocb;
955 struct atio_from_isp tm_iocb2;
956 };
957};
958
959struct qla_tgt_mgmt_cmd {
960 uint16_t tmr_func;
961 uint8_t fc_tm_rsp;
962 struct fc_port *sess;
963 struct qla_qpair *qpair;
964 struct scsi_qla_host *vha;
965 struct se_cmd se_cmd;
966 struct work_struct free_work;
967 unsigned int flags;
968 uint32_t reset_count;
969#define QLA24XX_MGMT_SEND_NACK 1
970 union {
971 struct atio_from_isp atio;
972 struct imm_ntfy_from_isp imm_ntfy;
973 struct abts_recv_from_24xx abts;
974 } __packed orig_iocb;
975};
976
977struct qla_tgt_prm {
978 struct qla_tgt_cmd *cmd;
979 struct qla_tgt *tgt;
980 void *pkt;
981 struct scatterlist *sg;
982 int seg_cnt;
983 int req_cnt;
984 uint16_t rq_result;
985 unsigned char *sense_buffer;
986 int sense_buffer_len;
987 int residual;
988 int add_status_pkt;
989
990 struct scatterlist *prot_sg;
991 uint16_t prot_seg_cnt;
992 uint16_t tot_dsds;
993};
994
995
996#define IS_SW_RESV_ADDR(_s_id) \
997 ((_s_id.b.domain == 0xff) && ((_s_id.b.area & 0xf0) == 0xf0))
998
999#define QLA_TGT_XMIT_DATA 1
1000#define QLA_TGT_XMIT_STATUS 2
1001#define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
1002
1003
1004extern struct qla_tgt_data qla_target;
1005
1006
1007
1008
1009extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
1010extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
1011extern int qlt_lport_register(void *, u64, u64, u64,
1012 int (*callback)(struct scsi_qla_host *, void *, u64, u64));
1013extern void qlt_lport_deregister(struct scsi_qla_host *);
1014extern void qlt_unreg_sess(struct fc_port *);
1015extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
1016extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int);
1017extern int __init qlt_init(void);
1018extern void qlt_exit(void);
1019extern void qlt_update_vp_map(struct scsi_qla_host *, int);
1020extern void qlt_free_session_done(struct work_struct *);
1021
1022
1023
1024
1025#define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
1026
1027extern int ql2x_ini_mode;
1028
1029static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
1030{
1031 return ha->host->active_mode == MODE_TARGET;
1032}
1033
1034static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
1035{
1036 return ha->host->active_mode == MODE_INITIATOR;
1037}
1038
1039static inline bool qla_dual_mode_enabled(struct scsi_qla_host *ha)
1040{
1041 return (ha->host->active_mode == MODE_DUAL);
1042}
1043
1044static inline uint32_t sid_to_key(const uint8_t *s_id)
1045{
1046 uint32_t key;
1047
1048 key = (((unsigned long)s_id[0] << 16) |
1049 ((unsigned long)s_id[1] << 8) |
1050 (unsigned long)s_id[2]);
1051 return key;
1052}
1053
1054static inline void sid_to_portid(const uint8_t *s_id, port_id_t *p)
1055{
1056 memset(p, 0, sizeof(*p));
1057 p->b.domain = s_id[0];
1058 p->b.area = s_id[1];
1059 p->b.al_pa = s_id[2];
1060}
1061
1062
1063
1064
1065extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, struct rsp_que *,
1066 response_t *);
1067extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
1068extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
1069extern int qlt_abort_cmd(struct qla_tgt_cmd *);
1070extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
1071extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
1072extern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
1073extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
1074extern void qlt_enable_vha(struct scsi_qla_host *);
1075extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
1076extern u8 qlt_rff_id(struct scsi_qla_host *);
1077extern void qlt_init_atio_q_entries(struct scsi_qla_host *);
1078extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *, uint8_t);
1079extern void qlt_24xx_config_rings(struct scsi_qla_host *);
1080extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
1081 struct nvram_24xx *);
1082extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
1083 struct init_cb_24xx *);
1084extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
1085 struct init_cb_81xx *);
1086extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
1087 struct nvram_81xx *);
1088extern int qlt_24xx_process_response_error(struct scsi_qla_host *,
1089 struct sts_entry_24xx *);
1090extern void qlt_modify_vp_config(struct scsi_qla_host *,
1091 struct vp_config_entry_24xx *);
1092extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
1093extern int qlt_mem_alloc(struct qla_hw_data *);
1094extern void qlt_mem_free(struct qla_hw_data *);
1095extern int qlt_stop_phase1(struct qla_tgt *);
1096extern void qlt_stop_phase2(struct qla_tgt *);
1097extern irqreturn_t qla83xx_msix_atio_q(int, void *);
1098extern void qlt_83xx_iospace_config(struct qla_hw_data *);
1099extern int qlt_free_qfull_cmds(struct qla_qpair *);
1100extern void qlt_logo_completion_handler(fc_port_t *, int);
1101extern void qlt_do_generation_tick(struct scsi_qla_host *, int *);
1102
1103void qlt_send_resp_ctio(struct qla_qpair *, struct qla_tgt_cmd *, uint8_t,
1104 uint8_t, uint8_t, uint8_t);
1105extern void qlt_abort_cmd_on_host_reset(struct scsi_qla_host *,
1106 struct qla_tgt_cmd *);
1107
1108#endif
1109