Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Global definitions for the zfcp device driver. |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 5 | * |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2009 |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #ifndef ZFCP_DEF_H |
| 10 | #define ZFCP_DEF_H |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /*************************** INCLUDES *****************************************/ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/major.h> |
| 17 | #include <linux/blkdev.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/timer.h> |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 20 | #include <linux/slab.h> |
| 21 | #include <linux/mempool.h> |
| 22 | #include <linux/syscalls.h> |
FUJITA Tomonori | f134637 | 2007-07-30 23:01:32 +0900 | [diff] [blame] | 23 | #include <linux/scatterlist.h> |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 24 | #include <linux/ioctl.h> |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 25 | #include <scsi/fc/fc_fs.h> |
| 26 | #include <scsi/fc/fc_gs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_tcq.h> |
| 29 | #include <scsi/scsi_cmnd.h> |
| 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_transport.h> |
| 33 | #include <scsi/scsi_transport_fc.h> |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 34 | #include <scsi/scsi_bsg_fc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/ccwdev.h> |
| 36 | #include <asm/qdio.h> |
| 37 | #include <asm/debug.h> |
| 38 | #include <asm/ebcdic.h> |
Christof Schmitt | bd43a42 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 39 | #include <asm/sysinfo.h> |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 40 | #include "zfcp_fsf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /********************* GENERAL DEFINES *********************************/ |
| 43 | |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 44 | #define REQUEST_LIST_SIZE 128 |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /********************* SCSI SPECIFIC DEFINES *********************************/ |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 47 | #define ZFCP_SCSI_ER_TIMEOUT (10*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /********************* CIO/QDIO SPECIFIC DEFINES *****************************/ |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* DMQ bug workaround: don't use last SBALE */ |
| 52 | #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1) |
| 53 | |
| 54 | /* index of last SBALE (with respect to DMQ bug workaround) */ |
| 55 | #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1) |
| 56 | |
| 57 | /* max. number of (data buffer) SBALEs in largest SBAL chain */ |
| 58 | #define ZFCP_MAX_SBALES_PER_REQ \ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 59 | (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */ |
| 61 | |
Swen Schillig | 8d1a006 | 2006-10-12 11:43:44 +0200 | [diff] [blame] | 62 | #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8) |
| 63 | /* max. number of (data buffer) SBALEs in largest SBAL chain |
| 64 | multiplied with number of sectors per 4k block */ |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /********************* FSF SPECIFIC DEFINES *********************************/ |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* ATTENTION: value must not be used by hardware */ |
| 69 | #define FSF_QTCB_UNSOLICITED_STATUS 0x6305 |
Andreas Herrmann | 22753fa | 2005-06-13 13:15:15 +0200 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* timeout value for "default timer" for fsf requests */ |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 72 | #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/ |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* task attribute values in FCP-2 FCP_CMND IU */ |
| 77 | #define SIMPLE_Q 0 |
| 78 | #define HEAD_OF_Q 1 |
| 79 | #define ORDERED_Q 2 |
| 80 | #define ACA_Q 4 |
| 81 | #define UNTAGGED 5 |
| 82 | |
| 83 | /* task management flags in FCP-2 FCP_CMND IU */ |
| 84 | #define FCP_CLEAR_ACA 0x40 |
| 85 | #define FCP_TARGET_RESET 0x20 |
| 86 | #define FCP_LOGICAL_UNIT_RESET 0x10 |
| 87 | #define FCP_CLEAR_TASK_SET 0x04 |
| 88 | #define FCP_ABORT_TASK_SET 0x02 |
| 89 | |
| 90 | #define FCP_CDB_LENGTH 16 |
| 91 | |
| 92 | #define ZFCP_DID_MASK 0x00FFFFFF |
| 93 | |
| 94 | /* FCP(-2) FCP_CMND IU */ |
| 95 | struct fcp_cmnd_iu { |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 96 | u64 fcp_lun; /* FCP logical unit number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | u8 crn; /* command reference number */ |
| 98 | u8 reserved0:5; /* reserved */ |
| 99 | u8 task_attribute:3; /* task attribute */ |
| 100 | u8 task_management_flags; /* task management flags */ |
| 101 | u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */ |
| 102 | u8 rddata:1; /* read data */ |
| 103 | u8 wddata:1; /* write data */ |
| 104 | u8 fcp_cdb[FCP_CDB_LENGTH]; |
| 105 | } __attribute__((packed)); |
| 106 | |
| 107 | /* FCP(-2) FCP_RSP IU */ |
| 108 | struct fcp_rsp_iu { |
| 109 | u8 reserved0[10]; |
| 110 | union { |
| 111 | struct { |
| 112 | u8 reserved1:3; |
| 113 | u8 fcp_conf_req:1; |
| 114 | u8 fcp_resid_under:1; |
| 115 | u8 fcp_resid_over:1; |
| 116 | u8 fcp_sns_len_valid:1; |
| 117 | u8 fcp_rsp_len_valid:1; |
| 118 | } bits; |
| 119 | u8 value; |
| 120 | } validity; |
| 121 | u8 scsi_status; |
| 122 | u32 fcp_resid; |
| 123 | u32 fcp_sns_len; |
| 124 | u32 fcp_rsp_len; |
| 125 | } __attribute__((packed)); |
| 126 | |
| 127 | |
| 128 | #define RSP_CODE_GOOD 0 |
| 129 | #define RSP_CODE_LENGTH_MISMATCH 1 |
| 130 | #define RSP_CODE_FIELD_INVALID 2 |
| 131 | #define RSP_CODE_RO_MISMATCH 3 |
| 132 | #define RSP_CODE_TASKMAN_UNSUPP 4 |
| 133 | #define RSP_CODE_TASKMAN_FAILED 5 |
| 134 | |
| 135 | /* see fc-fs */ |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 136 | #define LS_RSCN 0x61 |
| 137 | #define LS_LOGO 0x05 |
| 138 | #define LS_PLOGI 0x03 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | struct fcp_rscn_head { |
| 141 | u8 command; |
| 142 | u8 page_length; /* always 0x04 */ |
| 143 | u16 payload_len; |
| 144 | } __attribute__((packed)); |
| 145 | |
| 146 | struct fcp_rscn_element { |
| 147 | u8 reserved:2; |
| 148 | u8 event_qual:4; |
| 149 | u8 addr_format:2; |
| 150 | u32 nport_did:24; |
| 151 | } __attribute__((packed)); |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* see fc-ph */ |
| 154 | struct fcp_logo { |
| 155 | u32 command; |
| 156 | u32 nport_did; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 157 | u64 nport_wwpn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } __attribute__((packed)); |
| 159 | |
| 160 | /* |
| 161 | * FC-FS stuff |
| 162 | */ |
| 163 | #define R_A_TOV 10 /* seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | #define ZFCP_LS_RLS 0x0f |
| 166 | #define ZFCP_LS_ADISC 0x52 |
| 167 | #define ZFCP_LS_RPS 0x56 |
| 168 | #define ZFCP_LS_RSCN 0x61 |
| 169 | #define ZFCP_LS_RNID 0x78 |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | struct zfcp_ls_adisc { |
| 172 | u8 code; |
| 173 | u8 field[3]; |
| 174 | u32 hard_nport_id; |
| 175 | u64 wwpn; |
| 176 | u64 wwnn; |
| 177 | u32 nport_id; |
| 178 | } __attribute__ ((packed)); |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* |
| 181 | * FC-GS-2 stuff |
| 182 | */ |
| 183 | #define ZFCP_CT_REVISION 0x01 |
| 184 | #define ZFCP_CT_DIRECTORY_SERVICE 0xFC |
| 185 | #define ZFCP_CT_NAME_SERVER 0x02 |
| 186 | #define ZFCP_CT_SYNCHRONOUS 0x00 |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 187 | #define ZFCP_CT_SCSI_FCP 0x08 |
| 188 | #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #define ZFCP_CT_GID_PN 0x0121 |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 190 | #define ZFCP_CT_GPN_FT 0x0172 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #define ZFCP_CT_ACCEPT 0x8002 |
| 192 | #define ZFCP_CT_REJECT 0x8001 |
| 193 | |
| 194 | /* |
| 195 | * FC-GS-4 stuff |
| 196 | */ |
| 197 | #define ZFCP_CT_TIMEOUT (3 * R_A_TOV) |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/ |
| 200 | |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 201 | /* |
| 202 | * Note, the leftmost status byte is common among adapter, port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * and unit |
| 204 | */ |
| 205 | #define ZFCP_COMMON_FLAGS 0xfff00000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* common status bits */ |
| 208 | #define ZFCP_STATUS_COMMON_REMOVE 0x80000000 |
| 209 | #define ZFCP_STATUS_COMMON_RUNNING 0x40000000 |
| 210 | #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000 |
| 211 | #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | #define ZFCP_STATUS_COMMON_OPEN 0x04000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000 |
| 214 | #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000 |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 215 | #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000 |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 216 | #define ZFCP_STATUS_COMMON_NOESC 0x00200000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | /* adapter status */ |
| 219 | #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008 |
| 221 | #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100 |
| 223 | #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200 |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /* FC-PH/FC-GS well-known address identifiers for generic services */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 226 | #define ZFCP_DID_WKA 0xFFFFF0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /* remote port status */ |
| 229 | #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001 |
Christof Schmitt | 14e242e | 2009-08-18 15:43:11 +0200 | [diff] [blame] | 230 | #define ZFCP_STATUS_PORT_LINK_TEST 0x00000002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 232 | /* well known address (WKA) port status*/ |
| 233 | enum zfcp_wka_status { |
| 234 | ZFCP_WKA_PORT_OFFLINE, |
| 235 | ZFCP_WKA_PORT_CLOSING, |
| 236 | ZFCP_WKA_PORT_OPENING, |
| 237 | ZFCP_WKA_PORT_ONLINE, |
| 238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | /* logical unit status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | #define ZFCP_STATUS_UNIT_SHARED 0x00000004 |
| 242 | #define ZFCP_STATUS_UNIT_READONLY 0x00000008 |
| 243 | |
| 244 | /* FSF request status (this does not have a common part) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008 |
| 247 | #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040 |
| 249 | #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080 |
| 250 | #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100 |
| 251 | #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200 |
| 252 | #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400 |
| 253 | #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800 |
| 254 | #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000 |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /************************* STRUCTURE DEFINITIONS *****************************/ |
| 257 | |
| 258 | struct zfcp_fsf_req; |
| 259 | |
| 260 | /* holds various memory pools of an adapter */ |
| 261 | struct zfcp_adapter_mempool { |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 262 | mempool_t *erp_req; |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 263 | mempool_t *gid_pn_req; |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 264 | mempool_t *scsi_req; |
| 265 | mempool_t *scsi_abort; |
| 266 | mempool_t *status_read_req; |
| 267 | mempool_t *status_read_data; |
| 268 | mempool_t *gid_pn_data; |
| 269 | mempool_t *qtcb_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /* |
| 273 | * header for CT_IU |
| 274 | */ |
| 275 | struct ct_hdr { |
| 276 | u8 revision; // 0x01 |
| 277 | u8 in_id[3]; // 0x00 |
| 278 | u8 gs_type; // 0xFC Directory Service |
| 279 | u8 gs_subtype; // 0x02 Name Server |
| 280 | u8 options; // 0x00 single bidirectional exchange |
| 281 | u8 reserved0; |
| 282 | u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT |
| 283 | u16 max_res_size; // <= (4096 - 16) / 4 |
| 284 | u8 reserved1; |
| 285 | u8 reason_code; |
| 286 | u8 reason_code_expl; |
| 287 | u8 vendor_unique; |
| 288 | } __attribute__ ((packed)); |
| 289 | |
| 290 | /* nameserver request CT_IU -- for requests where |
| 291 | * a port name is required */ |
| 292 | struct ct_iu_gid_pn_req { |
| 293 | struct ct_hdr header; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 294 | u64 wwpn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } __attribute__ ((packed)); |
| 296 | |
| 297 | /* FS_ACC IU and data unit for GID_PN nameserver request */ |
| 298 | struct ct_iu_gid_pn_resp { |
| 299 | struct ct_hdr header; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 300 | u32 d_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } __attribute__ ((packed)); |
| 302 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 303 | struct ct_iu_gpn_ft_req { |
| 304 | struct ct_hdr header; |
| 305 | u8 flags; |
| 306 | u8 domain_id_scope; |
| 307 | u8 area_id_scope; |
| 308 | u8 fc4_type; |
| 309 | } __attribute__ ((packed)); |
| 310 | |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /** |
| 313 | * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 314 | * @wka_port: port where the request is sent to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | * @req: scatter-gather list for request |
| 316 | * @resp: scatter-gather list for response |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | * @handler: handler function (called for response to the request) |
| 318 | * @handler_data: data passed to handler function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * @completion: completion for synchronization purposes |
| 320 | * @status: used to pass error status to calling function |
| 321 | */ |
| 322 | struct zfcp_send_ct { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 323 | struct zfcp_wka_port *wka_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | struct scatterlist *req; |
| 325 | struct scatterlist *resp; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 326 | void (*handler)(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | unsigned long handler_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | struct completion *completion; |
| 329 | int status; |
| 330 | }; |
| 331 | |
| 332 | /* used for name server requests in error recovery */ |
| 333 | struct zfcp_gid_pn_data { |
| 334 | struct zfcp_send_ct ct; |
| 335 | struct scatterlist req; |
| 336 | struct scatterlist resp; |
| 337 | struct ct_iu_gid_pn_req ct_iu_req; |
| 338 | struct ct_iu_gid_pn_resp ct_iu_resp; |
| 339 | struct zfcp_port *port; |
| 340 | }; |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /** |
| 343 | * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els |
| 344 | * @adapter: adapter where request is sent from |
Andreas Herrmann | 64b29a13 | 2005-06-13 13:18:56 +0200 | [diff] [blame] | 345 | * @port: port where ELS is destinated (port reference count has to be increased) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | * @d_id: destiniation id of port where request is sent to |
| 347 | * @req: scatter-gather list for request |
| 348 | * @resp: scatter-gather list for response |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | * @handler: handler function (called for response to the request) |
| 350 | * @handler_data: data passed to handler function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | * @completion: completion for synchronization purposes |
| 352 | * @ls_code: hex code of ELS command |
| 353 | * @status: used to pass error status to calling function |
| 354 | */ |
| 355 | struct zfcp_send_els { |
| 356 | struct zfcp_adapter *adapter; |
Andreas Herrmann | 64b29a13 | 2005-06-13 13:18:56 +0200 | [diff] [blame] | 357 | struct zfcp_port *port; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 358 | u32 d_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | struct scatterlist *req; |
| 360 | struct scatterlist *resp; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 361 | void (*handler)(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | unsigned long handler_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | struct completion *completion; |
| 364 | int ls_code; |
| 365 | int status; |
| 366 | }; |
| 367 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 368 | struct zfcp_wka_port { |
| 369 | struct zfcp_adapter *adapter; |
| 370 | wait_queue_head_t completion_wq; |
| 371 | enum zfcp_wka_status status; |
| 372 | atomic_t refcount; |
| 373 | u32 d_id; |
| 374 | u32 handle; |
| 375 | struct mutex mutex; |
| 376 | struct delayed_work work; |
| 377 | }; |
| 378 | |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 379 | struct zfcp_wka_ports { |
| 380 | struct zfcp_wka_port ms; /* management service */ |
| 381 | struct zfcp_wka_port ts; /* time service */ |
| 382 | struct zfcp_wka_port ds; /* directory service */ |
| 383 | struct zfcp_wka_port as; /* alias service */ |
| 384 | struct zfcp_wka_port ks; /* key distribution service */ |
| 385 | }; |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | struct zfcp_qdio_queue { |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 388 | struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; |
| 389 | u8 first; /* index of next free bfr in queue */ |
| 390 | atomic_t count; /* number of free buffers in queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | struct zfcp_erp_action { |
| 394 | struct list_head list; |
| 395 | int action; /* requested action code */ |
| 396 | struct zfcp_adapter *adapter; /* device which should be recovered */ |
| 397 | struct zfcp_port *port; |
| 398 | struct zfcp_unit *unit; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 399 | u32 status; /* recovery status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | u32 step; /* active step of this erp action */ |
| 401 | struct zfcp_fsf_req *fsf_req; /* fsf request currently pending |
| 402 | for this action */ |
| 403 | struct timer_list timer; |
| 404 | }; |
| 405 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 406 | struct fsf_latency_record { |
| 407 | u32 min; |
| 408 | u32 max; |
| 409 | u64 sum; |
| 410 | }; |
| 411 | |
| 412 | struct latency_cont { |
| 413 | struct fsf_latency_record channel; |
| 414 | struct fsf_latency_record fabric; |
| 415 | u64 counter; |
| 416 | }; |
| 417 | |
| 418 | struct zfcp_latencies { |
| 419 | struct latency_cont read; |
| 420 | struct latency_cont write; |
| 421 | struct latency_cont cmd; |
| 422 | spinlock_t lock; |
| 423 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 425 | /** struct zfcp_qdio - basic QDIO data structure |
| 426 | * @resp_q: response queue |
| 427 | * @req_q: request queue |
| 428 | * @stat_lock: lock to protect req_q_util and req_q_time |
| 429 | * @req_q_lock; lock to serialize access to request queue |
| 430 | * @req_q_time: time of last fill level change |
| 431 | * @req_q_util: used for accounting |
| 432 | * @req_q_full: queue full incidents |
| 433 | * @req_q_wq: used to wait for SBAL availability |
| 434 | * @adapter: adapter used in conjunction with this QDIO structure |
| 435 | */ |
| 436 | struct zfcp_qdio { |
| 437 | struct zfcp_qdio_queue resp_q; |
| 438 | struct zfcp_qdio_queue req_q; |
| 439 | spinlock_t stat_lock; |
| 440 | spinlock_t req_q_lock; |
Heiko Carstens | 41e05a1 | 2009-08-18 15:43:32 +0200 | [diff] [blame] | 441 | unsigned long long req_q_time; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 442 | u64 req_q_util; |
| 443 | atomic_t req_q_full; |
| 444 | wait_queue_head_t req_q_wq; |
| 445 | struct zfcp_adapter *adapter; |
| 446 | }; |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | struct zfcp_adapter { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | atomic_t refcount; /* reference count */ |
| 450 | wait_queue_head_t remove_wq; /* can be used to wait for |
| 451 | refcount drop to zero */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 452 | u64 peer_wwnn; /* P2P peer WWNN */ |
| 453 | u64 peer_wwpn; /* P2P peer WWPN */ |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 454 | u32 peer_d_id; /* P2P peer D_ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | struct ccw_device *ccw_device; /* S/390 ccw device */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 456 | struct zfcp_qdio *qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | u32 hydra_version; /* Hydra version */ |
| 458 | u32 fsf_lic_version; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 459 | u32 adapter_features; /* FCP channel features */ |
| 460 | u32 connection_features; /* host connection features */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | u32 hardware_version; /* of FCP channel */ |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 462 | u16 timer_ticks; /* time int for a tick */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | struct Scsi_Host *scsi_host; /* Pointer to mid-layer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | struct list_head port_list_head; /* remote port list */ |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 465 | unsigned long req_no; /* unique FSF req number */ |
| 466 | struct list_head *req_list; /* list of pending reqs */ |
| 467 | spinlock_t req_list_lock; /* request list lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | u32 fsf_req_seq_no; /* FSF cmnd seq number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | rwlock_t abort_lock; /* Protects against SCSI |
| 470 | stack abort/command |
| 471 | completion races */ |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 472 | atomic_t stat_miss; /* # missing status reads*/ |
| 473 | struct work_struct stat_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | atomic_t status; /* status of this adapter */ |
| 475 | struct list_head erp_ready_head; /* error recovery for this |
| 476 | adapter/devices */ |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame] | 477 | wait_queue_head_t erp_ready_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | struct list_head erp_running_head; |
| 479 | rwlock_t erp_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | wait_queue_head_t erp_done_wqh; |
| 481 | struct zfcp_erp_action erp_action; /* pending error recovery */ |
| 482 | atomic_t erp_counter; |
| 483 | u32 erp_total_count; /* total nr of enqueued erp |
| 484 | actions */ |
| 485 | u32 erp_low_mem_count; /* nr of erp actions waiting |
| 486 | for memory */ |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame] | 487 | struct task_struct *erp_thread; |
Sven Schuetz | 9d544f2 | 2009-04-06 18:31:47 +0200 | [diff] [blame] | 488 | struct zfcp_wka_ports *gs; /* generic services */ |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 489 | struct zfcp_dbf *dbf; /* debug traces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | struct zfcp_adapter_mempool pool; /* Adapter memory pools */ |
Andreas Herrmann | f6cd94b | 2006-01-05 09:59:34 +0100 | [diff] [blame] | 491 | struct fc_host_statistics *fc_stats; |
| 492 | struct fsf_qtcb_bottom_port *stats_reset_data; |
| 493 | unsigned long stats_reset; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 494 | struct work_struct scan_work; |
Christof Schmitt | bd43a42 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 495 | struct service_level service_level; |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 496 | struct workqueue_struct *work_queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | }; |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | struct zfcp_port { |
| 500 | struct device sysfs_device; /* sysfs device */ |
Andreas Herrmann | 3859f6a | 2005-08-27 11:07:54 -0700 | [diff] [blame] | 501 | struct fc_rport *rport; /* rport of fc transport class */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | struct list_head list; /* list of remote ports */ |
| 503 | atomic_t refcount; /* reference count */ |
| 504 | wait_queue_head_t remove_wq; /* can be used to wait for |
| 505 | refcount drop to zero */ |
| 506 | struct zfcp_adapter *adapter; /* adapter used to access port */ |
| 507 | struct list_head unit_list_head; /* head of logical unit list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | atomic_t status; /* status of this remote port */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 509 | u64 wwnn; /* WWNN if known */ |
| 510 | u64 wwpn; /* WWPN */ |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 511 | u32 d_id; /* D_ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | u32 handle; /* handle assigned by FSF */ |
| 513 | struct zfcp_erp_action erp_action; /* pending error recovery */ |
| 514 | atomic_t erp_counter; |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 515 | u32 maxframe_size; |
| 516 | u32 supported_classes; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 517 | struct work_struct gid_pn_work; |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 518 | struct work_struct test_link_work; |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 519 | struct work_struct rport_work; |
| 520 | enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | }; |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | struct zfcp_unit { |
| 524 | struct device sysfs_device; /* sysfs device */ |
| 525 | struct list_head list; /* list of logical units */ |
| 526 | atomic_t refcount; /* reference count */ |
| 527 | wait_queue_head_t remove_wq; /* can be used to wait for |
| 528 | refcount drop to zero */ |
| 529 | struct zfcp_port *port; /* remote port of unit */ |
| 530 | atomic_t status; /* status of this logical unit */ |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 531 | u64 fcp_lun; /* own FCP_LUN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | u32 handle; /* handle assigned by FSF */ |
| 533 | struct scsi_device *device; /* scsi device struct pointer */ |
| 534 | struct zfcp_erp_action erp_action; /* pending error recovery */ |
| 535 | atomic_t erp_counter; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 536 | struct zfcp_latencies latencies; |
Swen Schillig | 92d5193 | 2009-04-17 15:08:04 +0200 | [diff] [blame] | 537 | struct work_struct scsi_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | }; |
| 539 | |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 540 | /** |
| 541 | * struct zfcp_queue_req - queue related values for a request |
| 542 | * @sbal_number: number of free SBALs |
| 543 | * @sbal_first: first SBAL for this request |
| 544 | * @sbal_last: last SBAL for this request |
| 545 | * @sbal_limit: last possible SBAL for this request |
| 546 | * @sbale_curr: current SBALE at creation of this request |
| 547 | * @sbal_response: SBAL used in interrupt |
| 548 | * @qdio_outb_usage: usage of outbound queue |
| 549 | * @qdio_inb_usage: usage of inbound queue |
| 550 | */ |
| 551 | struct zfcp_queue_req { |
| 552 | u8 sbal_number; |
| 553 | u8 sbal_first; |
| 554 | u8 sbal_last; |
| 555 | u8 sbal_limit; |
| 556 | u8 sbale_curr; |
| 557 | u8 sbal_response; |
| 558 | u16 qdio_outb_usage; |
| 559 | u16 qdio_inb_usage; |
| 560 | }; |
| 561 | |
| 562 | /** |
| 563 | * struct zfcp_fsf_req - basic FSF request structure |
| 564 | * @list: list of FSF requests |
| 565 | * @req_id: unique request ID |
| 566 | * @adapter: adapter this request belongs to |
| 567 | * @queue_req: queue related values |
| 568 | * @completion: used to signal the completion of the request |
| 569 | * @status: status of the request |
| 570 | * @fsf_command: FSF command issued |
| 571 | * @qtcb: associated QTCB |
| 572 | * @seq_no: sequence number of this request |
| 573 | * @data: private data |
| 574 | * @timer: timer data of this request |
| 575 | * @erp_action: reference to erp action if request issued on behalf of ERP |
| 576 | * @pool: reference to memory pool if used for this request |
| 577 | * @issued: time when request was send (STCK) |
| 578 | * @unit: reference to unit if this request is a SCSI request |
| 579 | * @handler: handler which should be called to process response |
| 580 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | struct zfcp_fsf_req { |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 582 | struct list_head list; |
| 583 | unsigned long req_id; |
| 584 | struct zfcp_adapter *adapter; |
| 585 | struct zfcp_queue_req queue_req; |
| 586 | struct completion completion; |
| 587 | u32 status; |
| 588 | u32 fsf_command; |
| 589 | struct fsf_qtcb *qtcb; |
| 590 | u32 seq_no; |
| 591 | void *data; |
| 592 | struct timer_list timer; |
| 593 | struct zfcp_erp_action *erp_action; |
| 594 | mempool_t *pool; |
| 595 | unsigned long long issued; |
| 596 | struct zfcp_unit *unit; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 597 | void (*handler)(struct zfcp_fsf_req *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* driver data */ |
| 601 | struct zfcp_data { |
| 602 | struct scsi_host_template scsi_host_template; |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 603 | struct scsi_transport_template *scsi_transport_template; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | rwlock_t config_lock; /* serialises changes |
| 605 | to adapter/port/unit |
| 606 | lists */ |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 607 | struct mutex config_mutex; |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 608 | struct kmem_cache *gpn_ft_cache; |
| 609 | struct kmem_cache *qtcb_cache; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 610 | struct kmem_cache *sr_buffer_cache; |
| 611 | struct kmem_cache *gid_pn_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | }; |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /********************** ZFCP SPECIFIC DEFINES ********************************/ |
| 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | #define ZFCP_SET 0x00000100 |
| 617 | #define ZFCP_CLEAR 0x00000200 |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | /* |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 620 | * Helper functions for request ID management. |
| 621 | */ |
| 622 | static inline int zfcp_reqlist_hash(unsigned long req_id) |
| 623 | { |
| 624 | return req_id % REQUEST_LIST_SIZE; |
| 625 | } |
| 626 | |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 627 | static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter, |
| 628 | struct zfcp_fsf_req *fsf_req) |
| 629 | { |
| 630 | list_del(&fsf_req->list); |
| 631 | } |
| 632 | |
| 633 | static inline struct zfcp_fsf_req * |
| 634 | zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id) |
| 635 | { |
| 636 | struct zfcp_fsf_req *request; |
| 637 | unsigned int idx; |
| 638 | |
| 639 | idx = zfcp_reqlist_hash(req_id); |
| 640 | list_for_each_entry(request, &adapter->req_list[idx], list) |
| 641 | if (request->req_id == req_id) |
| 642 | return request; |
| 643 | return NULL; |
| 644 | } |
| 645 | |
Heiko Carstens | d1ad09d | 2007-12-20 12:30:22 +0100 | [diff] [blame] | 646 | static inline struct zfcp_fsf_req * |
| 647 | zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req) |
| 648 | { |
| 649 | struct zfcp_fsf_req *request; |
| 650 | unsigned int idx; |
| 651 | |
| 652 | for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) { |
| 653 | list_for_each_entry(request, &adapter->req_list[idx], list) |
| 654 | if (request == req) |
| 655 | return request; |
| 656 | } |
| 657 | return NULL; |
| 658 | } |
| 659 | |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 660 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | * functions needed for reference/usage counting |
| 662 | */ |
| 663 | |
| 664 | static inline void |
| 665 | zfcp_unit_get(struct zfcp_unit *unit) |
| 666 | { |
| 667 | atomic_inc(&unit->refcount); |
| 668 | } |
| 669 | |
| 670 | static inline void |
| 671 | zfcp_unit_put(struct zfcp_unit *unit) |
| 672 | { |
| 673 | if (atomic_dec_return(&unit->refcount) == 0) |
| 674 | wake_up(&unit->remove_wq); |
| 675 | } |
| 676 | |
| 677 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | zfcp_port_get(struct zfcp_port *port) |
| 679 | { |
| 680 | atomic_inc(&port->refcount); |
| 681 | } |
| 682 | |
| 683 | static inline void |
| 684 | zfcp_port_put(struct zfcp_port *port) |
| 685 | { |
| 686 | if (atomic_dec_return(&port->refcount) == 0) |
| 687 | wake_up(&port->remove_wq); |
| 688 | } |
| 689 | |
| 690 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | zfcp_adapter_get(struct zfcp_adapter *adapter) |
| 692 | { |
| 693 | atomic_inc(&adapter->refcount); |
| 694 | } |
| 695 | |
| 696 | static inline void |
| 697 | zfcp_adapter_put(struct zfcp_adapter *adapter) |
| 698 | { |
| 699 | if (atomic_dec_return(&adapter->refcount) == 0) |
| 700 | wake_up(&adapter->remove_wq); |
| 701 | } |
| 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | #endif /* ZFCP_DEF_H */ |