4 * Copyright (C) 2004-2006 Vladislav Bolkhovitin <vst@vlnb.net>
6 * Nathaniel Clark <nate@misrule.us>
8 * Significant modification 2006 by Nathaniel Clark <nate@misrule.us>
10 * Qlogic 2x00 SCSI target driver.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, version 2
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
26 /* Sneaky hack to skip redefinitions from qla_dbg.h */
29 #include "qla2x_tgt_def.h"
31 /* Version numbers, the same as for the kernel */
32 #define Q2T_VERSION(a,b,c,d) (((a) << 030) + ((b) << 020) + (c) << 010 + (d))
33 #define Q2T_VERSION_CODE Q2T_VERSION(0,9,5,0)
34 #define Q2T_VERSION_STRING "0.9.5-pre2"
36 #define Q2T_MAX_CDB_LEN 16
37 #define Q2T_TIMEOUT 10 /* in seconds */
39 /* Immediate notify status constants */
40 #define IMM_NTFY_LIP_RESET 0x000E
41 #define IMM_NTFY_IOCB_OVERFLOW 0x0016
42 #define IMM_NTFY_ABORT_TASK 0x0020
43 #define IMM_NTFY_PORT_LOGOUT 0x0029
44 #define IMM_NTFY_PORT_CONFIG 0x002A
45 #define IMM_NTFY_GLBL_TPRLO 0x002D
46 #define IMM_NTFY_GLBL_LOGO 0x002E
47 #define IMM_NTFY_RESOURCE 0x0034
48 #define IMM_NTFY_MSG_RX 0x0036
50 /* Immediate notify task flags */
51 #define IMM_NTFY_CLEAR_ACA 0x4000
52 #define IMM_NTFY_TARGET_RESET 0x2000
53 #define IMM_NTFY_LUN_RESET 0x1000
54 #define IMM_NTFY_CLEAR_TS 0x0400
55 #define IMM_NTFY_ABORT_TS 0x0200
57 /* Notify Acknowledge flags */
58 #define NOTIFY_ACK_RES_COUNT BIT_8
59 #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
60 #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
62 /* Command's states */
63 #define Q2T_STATE_NEW 0 /* New command and SCST processes it */
64 #define Q2T_STATE_PROCESSED 1 /* SCST done processing */
65 #define Q2T_STATE_NEED_DATA 2 /* SCST needs data to process */
66 #define Q2T_STATE_DATA_IN 3 /* Data arrived and SCST processes it */
67 #define Q2T_STATE_ABORTED 4 /* Command aborted */
70 #define Q2T_NULL_HANDLE 0
71 #define Q2T_SKIP_HANDLE (0xFFFFFFFE & ~CTIO_COMPLETION_HANDLE_MARK)
72 #define Q2T_BUSY_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
73 #define Q2T_DISABLE_LUN_STATUS_NOT_SET -1
75 /* ATIO task_codes fields */
76 #define ATIO_SIMPLE_QUEUE 0
77 #define ATIO_HEAD_OF_QUEUE 1
78 #define ATIO_ORDERED_QUEUE 2
79 #define ATIO_ACA_QUEUE 4
80 #define ATIO_UNTAGGED 5
82 /* TM failed response code, see FCP */
83 #define FC_TM_FAILED 0x5
85 #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
86 #define pci_dma_lo32(a) (a & 0xffffffff)
87 #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
89 #define pci_dma_lo32(a) (a & 0xffffffff)
90 #define pci_dma_hi32(a) 0
94 * Equivilant to IT Nexus (Initiator-Target)
98 struct list_head list;
99 struct scst_session *scst_sess;
106 struct q2t_sess *sess;
107 struct scst_cmd *scst_cmd;
110 dma_addr_t dma_handle;
116 struct scst_tgt *scst_tgt;
119 int datasegs_per_cmd, datasegs_per_cont;
120 /* Target's flags, serialized by ha->hardware_lock */
121 unsigned int tgt_shutdown:1; /* The driver is being released */
122 unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addressing anables */
123 wait_queue_head_t waitQ;
124 int notify_ack_expected;
125 volatile int modify_lun_expected;
126 volatile int disable_lun_status;
127 atomic_t sess_count; /* count sessions refing q2t_tgt */
128 struct list_head sess_list;
133 struct q2t_sess *sess;
134 notify_entry_t notify_entry;
143 struct scatterlist *sg;
145 scst_data_direction data_direction;
147 uint16_t scsi_status;
148 unsigned char *sense_buffer;
149 unsigned int sense_buffer_len;
152 ctio_common_entry_t *pkt;
155 /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */
156 static inline struct q2t_sess *q2t_find_sess_by_lid(struct q2t_tgt *tgt,
159 struct q2t_sess *sess, *sess_tmp;
161 list_for_each_entry_safe(sess, sess_tmp, &tgt->sess_list, list) {
162 if (lid == (sess->loop_id))
169 #endif /* __QLA2X00T_H */