zfcp_def.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*
  2. * zfcp device driver
  3. *
  4. * Global definitions for the zfcp device driver.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #ifndef ZFCP_DEF_H
  9. #define ZFCP_DEF_H
  10. /*************************** INCLUDES *****************************************/
  11. #include <linux/init.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/major.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/delay.h>
  16. #include <linux/timer.h>
  17. #include <linux/slab.h>
  18. #include <linux/mempool.h>
  19. #include <linux/syscalls.h>
  20. #include <linux/scatterlist.h>
  21. #include <linux/ioctl.h>
  22. #include <scsi/scsi.h>
  23. #include <scsi/scsi_tcq.h>
  24. #include <scsi/scsi_cmnd.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include <asm/ccwdev.h>
  30. #include <asm/qdio.h>
  31. #include <asm/debug.h>
  32. #include <asm/ebcdic.h>
  33. #include "zfcp_dbf.h"
  34. #include "zfcp_fsf.h"
  35. /********************* GENERAL DEFINES *********************************/
  36. /**
  37. * zfcp_sg_to_address - determine kernel address from struct scatterlist
  38. * @list: struct scatterlist
  39. * Return: kernel address
  40. */
  41. static inline void *
  42. zfcp_sg_to_address(struct scatterlist *list)
  43. {
  44. return sg_virt(list);
  45. }
  46. /**
  47. * zfcp_address_to_sg - set up struct scatterlist from kernel address
  48. * @address: kernel address
  49. * @list: struct scatterlist
  50. * @size: buffer size
  51. */
  52. static inline void
  53. zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
  54. {
  55. sg_set_buf(list, address, size);
  56. }
  57. #define REQUEST_LIST_SIZE 128
  58. /********************* SCSI SPECIFIC DEFINES *********************************/
  59. #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
  60. /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
  61. /* Adapter Identification Parameters */
  62. #define ZFCP_CONTROL_UNIT_TYPE 0x1731
  63. #define ZFCP_CONTROL_UNIT_MODEL 0x03
  64. #define ZFCP_DEVICE_TYPE 0x1732
  65. #define ZFCP_DEVICE_MODEL 0x03
  66. #define ZFCP_DEVICE_MODEL_PRIV 0x04
  67. /* allow as many chained SBALs as are supported by hardware */
  68. #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
  69. #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
  70. #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
  71. /* DMQ bug workaround: don't use last SBALE */
  72. #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
  73. /* index of last SBALE (with respect to DMQ bug workaround) */
  74. #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
  75. /* max. number of (data buffer) SBALEs in largest SBAL chain */
  76. #define ZFCP_MAX_SBALES_PER_REQ \
  77. (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
  78. /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
  79. #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
  80. /* max. number of (data buffer) SBALEs in largest SBAL chain
  81. multiplied with number of sectors per 4k block */
  82. #define ZFCP_SBAL_TIMEOUT (5*HZ)
  83. #define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
  84. #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
  85. /********************* FSF SPECIFIC DEFINES *********************************/
  86. #define ZFCP_ULP_INFO_VERSION 26
  87. #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
  88. /* ATTENTION: value must not be used by hardware */
  89. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  90. #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
  91. /* Do 1st retry in 1 second, then double the timeout for each following retry */
  92. #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
  93. #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
  94. /* timeout value for "default timer" for fsf requests */
  95. #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
  96. /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
  97. typedef unsigned long long wwn_t;
  98. typedef unsigned long long fcp_lun_t;
  99. /* data length field may be at variable position in FCP-2 FCP_CMND IU */
  100. typedef unsigned int fcp_dl_t;
  101. #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
  102. /* timeout for name-server lookup (in seconds) */
  103. #define ZFCP_NS_GID_PN_TIMEOUT 10
  104. /* largest SCSI command we can process */
  105. /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
  106. #define ZFCP_MAX_SCSI_CMND_LENGTH 255
  107. /* maximum number of commands in LUN queue (tagged queueing) */
  108. #define ZFCP_CMND_PER_LUN 32
  109. /* task attribute values in FCP-2 FCP_CMND IU */
  110. #define SIMPLE_Q 0
  111. #define HEAD_OF_Q 1
  112. #define ORDERED_Q 2
  113. #define ACA_Q 4
  114. #define UNTAGGED 5
  115. /* task management flags in FCP-2 FCP_CMND IU */
  116. #define FCP_CLEAR_ACA 0x40
  117. #define FCP_TARGET_RESET 0x20
  118. #define FCP_LOGICAL_UNIT_RESET 0x10
  119. #define FCP_CLEAR_TASK_SET 0x04
  120. #define FCP_ABORT_TASK_SET 0x02
  121. #define FCP_CDB_LENGTH 16
  122. #define ZFCP_DID_MASK 0x00FFFFFF
  123. /* FCP(-2) FCP_CMND IU */
  124. struct fcp_cmnd_iu {
  125. fcp_lun_t fcp_lun; /* FCP logical unit number */
  126. u8 crn; /* command reference number */
  127. u8 reserved0:5; /* reserved */
  128. u8 task_attribute:3; /* task attribute */
  129. u8 task_management_flags; /* task management flags */
  130. u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
  131. u8 rddata:1; /* read data */
  132. u8 wddata:1; /* write data */
  133. u8 fcp_cdb[FCP_CDB_LENGTH];
  134. } __attribute__((packed));
  135. /* FCP(-2) FCP_RSP IU */
  136. struct fcp_rsp_iu {
  137. u8 reserved0[10];
  138. union {
  139. struct {
  140. u8 reserved1:3;
  141. u8 fcp_conf_req:1;
  142. u8 fcp_resid_under:1;
  143. u8 fcp_resid_over:1;
  144. u8 fcp_sns_len_valid:1;
  145. u8 fcp_rsp_len_valid:1;
  146. } bits;
  147. u8 value;
  148. } validity;
  149. u8 scsi_status;
  150. u32 fcp_resid;
  151. u32 fcp_sns_len;
  152. u32 fcp_rsp_len;
  153. } __attribute__((packed));
  154. #define RSP_CODE_GOOD 0
  155. #define RSP_CODE_LENGTH_MISMATCH 1
  156. #define RSP_CODE_FIELD_INVALID 2
  157. #define RSP_CODE_RO_MISMATCH 3
  158. #define RSP_CODE_TASKMAN_UNSUPP 4
  159. #define RSP_CODE_TASKMAN_FAILED 5
  160. /* see fc-fs */
  161. #define LS_RSCN 0x61
  162. #define LS_LOGO 0x05
  163. #define LS_PLOGI 0x03
  164. struct fcp_rscn_head {
  165. u8 command;
  166. u8 page_length; /* always 0x04 */
  167. u16 payload_len;
  168. } __attribute__((packed));
  169. struct fcp_rscn_element {
  170. u8 reserved:2;
  171. u8 event_qual:4;
  172. u8 addr_format:2;
  173. u32 nport_did:24;
  174. } __attribute__((packed));
  175. #define ZFCP_PORT_ADDRESS 0x0
  176. #define ZFCP_AREA_ADDRESS 0x1
  177. #define ZFCP_DOMAIN_ADDRESS 0x2
  178. #define ZFCP_FABRIC_ADDRESS 0x3
  179. #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
  180. #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
  181. #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
  182. #define ZFCP_PORTS_RANGE_FABRIC 0x000000
  183. #define ZFCP_NO_PORTS_PER_AREA 0x100
  184. #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
  185. #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
  186. /* see fc-ph */
  187. struct fcp_logo {
  188. u32 command;
  189. u32 nport_did;
  190. wwn_t nport_wwpn;
  191. } __attribute__((packed));
  192. /*
  193. * FC-FS stuff
  194. */
  195. #define R_A_TOV 10 /* seconds */
  196. #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
  197. #define ZFCP_LS_RLS 0x0f
  198. #define ZFCP_LS_ADISC 0x52
  199. #define ZFCP_LS_RPS 0x56
  200. #define ZFCP_LS_RSCN 0x61
  201. #define ZFCP_LS_RNID 0x78
  202. struct zfcp_ls_rjt_par {
  203. u8 action;
  204. u8 reason_code;
  205. u8 reason_expl;
  206. u8 vendor_unique;
  207. } __attribute__ ((packed));
  208. struct zfcp_ls_adisc {
  209. u8 code;
  210. u8 field[3];
  211. u32 hard_nport_id;
  212. u64 wwpn;
  213. u64 wwnn;
  214. u32 nport_id;
  215. } __attribute__ ((packed));
  216. struct zfcp_ls_adisc_acc {
  217. u8 code;
  218. u8 field[3];
  219. u32 hard_nport_id;
  220. u64 wwpn;
  221. u64 wwnn;
  222. u32 nport_id;
  223. } __attribute__ ((packed));
  224. struct zfcp_rc_entry {
  225. u8 code;
  226. const char *description;
  227. };
  228. /*
  229. * FC-GS-2 stuff
  230. */
  231. #define ZFCP_CT_REVISION 0x01
  232. #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
  233. #define ZFCP_CT_NAME_SERVER 0x02
  234. #define ZFCP_CT_SYNCHRONOUS 0x00
  235. #define ZFCP_CT_SCSI_FCP 0x08
  236. #define ZFCP_CT_UNABLE_TO_PERFORM_CMD 0x09
  237. #define ZFCP_CT_GID_PN 0x0121
  238. #define ZFCP_CT_GPN_FT 0x0172
  239. #define ZFCP_CT_MAX_SIZE 0x1020
  240. #define ZFCP_CT_ACCEPT 0x8002
  241. #define ZFCP_CT_REJECT 0x8001
  242. /*
  243. * FC-GS-4 stuff
  244. */
  245. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  246. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  247. /*
  248. * Note, the leftmost status byte is common among adapter, port
  249. * and unit
  250. */
  251. #define ZFCP_COMMON_FLAGS 0xfff00000
  252. /* common status bits */
  253. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  254. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  255. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  256. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  257. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  258. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  259. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  260. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  261. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  262. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  263. #define ZFCP_STATUS_COMMON_NOESC 0x00200000
  264. /* adapter status */
  265. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  266. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  267. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  268. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  269. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  270. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  271. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  272. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  273. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  274. /* FC-PH/FC-GS well-known address identifiers for generic services */
  275. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  276. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  277. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  278. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  279. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  280. /* remote port status */
  281. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  282. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  283. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  284. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  285. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  286. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  287. /* for ports with well known addresses */
  288. #define ZFCP_STATUS_PORT_WKA \
  289. (ZFCP_STATUS_PORT_NO_WWPN | \
  290. ZFCP_STATUS_PORT_NO_SCSI_ID)
  291. /* logical unit status */
  292. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  293. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  294. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  295. #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
  296. #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
  297. /* FSF request status (this does not have a common part) */
  298. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  299. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  300. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  301. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  302. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  303. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  304. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  305. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  306. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  307. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  308. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  309. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  310. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  311. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  312. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  313. #define ZFCP_MAX_ERPS 3
  314. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  315. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  316. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  317. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  318. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  319. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  320. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  321. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  322. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  323. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  324. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  325. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  326. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  327. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  328. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  329. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  330. /* Ordered by escalation level (necessary for proper erp-code operation) */
  331. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  332. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  333. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  334. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  335. #define ZFCP_ERP_ACTION_RUNNING 0x1
  336. #define ZFCP_ERP_ACTION_READY 0x2
  337. #define ZFCP_ERP_SUCCEEDED 0x0
  338. #define ZFCP_ERP_FAILED 0x1
  339. #define ZFCP_ERP_CONTINUES 0x2
  340. #define ZFCP_ERP_EXIT 0x3
  341. #define ZFCP_ERP_DISMISSED 0x4
  342. #define ZFCP_ERP_NOMEM 0x5
  343. /************************* STRUCTURE DEFINITIONS *****************************/
  344. struct zfcp_fsf_req;
  345. /* holds various memory pools of an adapter */
  346. struct zfcp_adapter_mempool {
  347. mempool_t *fsf_req_erp;
  348. mempool_t *fsf_req_scsi;
  349. mempool_t *fsf_req_abort;
  350. mempool_t *fsf_req_status_read;
  351. mempool_t *data_status_read;
  352. mempool_t *data_gid_pn;
  353. };
  354. /*
  355. * header for CT_IU
  356. */
  357. struct ct_hdr {
  358. u8 revision; // 0x01
  359. u8 in_id[3]; // 0x00
  360. u8 gs_type; // 0xFC Directory Service
  361. u8 gs_subtype; // 0x02 Name Server
  362. u8 options; // 0x00 single bidirectional exchange
  363. u8 reserved0;
  364. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  365. u16 max_res_size; // <= (4096 - 16) / 4
  366. u8 reserved1;
  367. u8 reason_code;
  368. u8 reason_code_expl;
  369. u8 vendor_unique;
  370. } __attribute__ ((packed));
  371. /* nameserver request CT_IU -- for requests where
  372. * a port name is required */
  373. struct ct_iu_gid_pn_req {
  374. struct ct_hdr header;
  375. wwn_t wwpn;
  376. } __attribute__ ((packed));
  377. /* FS_ACC IU and data unit for GID_PN nameserver request */
  378. struct ct_iu_gid_pn_resp {
  379. struct ct_hdr header;
  380. u32 d_id;
  381. } __attribute__ ((packed));
  382. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  383. /**
  384. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  385. * @port: port where the request is sent to
  386. * @req: scatter-gather list for request
  387. * @resp: scatter-gather list for response
  388. * @req_count: number of elements in request scatter-gather list
  389. * @resp_count: number of elements in response scatter-gather list
  390. * @handler: handler function (called for response to the request)
  391. * @handler_data: data passed to handler function
  392. * @timeout: FSF timeout for this request
  393. * @completion: completion for synchronization purposes
  394. * @status: used to pass error status to calling function
  395. */
  396. struct zfcp_send_ct {
  397. struct zfcp_port *port;
  398. struct scatterlist *req;
  399. struct scatterlist *resp;
  400. unsigned int req_count;
  401. unsigned int resp_count;
  402. zfcp_send_ct_handler_t handler;
  403. unsigned long handler_data;
  404. int timeout;
  405. struct completion *completion;
  406. int status;
  407. };
  408. /* used for name server requests in error recovery */
  409. struct zfcp_gid_pn_data {
  410. struct zfcp_send_ct ct;
  411. struct scatterlist req;
  412. struct scatterlist resp;
  413. struct ct_iu_gid_pn_req ct_iu_req;
  414. struct ct_iu_gid_pn_resp ct_iu_resp;
  415. struct zfcp_port *port;
  416. };
  417. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  418. /**
  419. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  420. * @adapter: adapter where request is sent from
  421. * @port: port where ELS is destinated (port reference count has to be increased)
  422. * @d_id: destiniation id of port where request is sent to
  423. * @req: scatter-gather list for request
  424. * @resp: scatter-gather list for response
  425. * @req_count: number of elements in request scatter-gather list
  426. * @resp_count: number of elements in response scatter-gather list
  427. * @handler: handler function (called for response to the request)
  428. * @handler_data: data passed to handler function
  429. * @completion: completion for synchronization purposes
  430. * @ls_code: hex code of ELS command
  431. * @status: used to pass error status to calling function
  432. */
  433. struct zfcp_send_els {
  434. struct zfcp_adapter *adapter;
  435. struct zfcp_port *port;
  436. u32 d_id;
  437. struct scatterlist *req;
  438. struct scatterlist *resp;
  439. unsigned int req_count;
  440. unsigned int resp_count;
  441. zfcp_send_els_handler_t handler;
  442. unsigned long handler_data;
  443. struct completion *completion;
  444. int ls_code;
  445. int status;
  446. };
  447. struct zfcp_qdio_queue {
  448. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  449. u8 first; /* index of next free bfr
  450. in queue (free_count>0) */
  451. atomic_t count; /* number of free buffers
  452. in queue */
  453. rwlock_t lock; /* lock for operations on queue */
  454. int pci_batch; /* SBALs since PCI indication
  455. was last set */
  456. };
  457. struct zfcp_erp_action {
  458. struct list_head list;
  459. int action; /* requested action code */
  460. struct zfcp_adapter *adapter; /* device which should be recovered */
  461. struct zfcp_port *port;
  462. struct zfcp_unit *unit;
  463. volatile u32 status; /* recovery status */
  464. u32 step; /* active step of this erp action */
  465. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  466. for this action */
  467. struct timer_list timer;
  468. };
  469. struct fsf_latency_record {
  470. u32 min;
  471. u32 max;
  472. u64 sum;
  473. };
  474. struct latency_cont {
  475. struct fsf_latency_record channel;
  476. struct fsf_latency_record fabric;
  477. u64 counter;
  478. };
  479. struct zfcp_latencies {
  480. struct latency_cont read;
  481. struct latency_cont write;
  482. struct latency_cont cmd;
  483. spinlock_t lock;
  484. };
  485. struct zfcp_adapter {
  486. struct list_head list; /* list of adapters */
  487. atomic_t refcount; /* reference count */
  488. wait_queue_head_t remove_wq; /* can be used to wait for
  489. refcount drop to zero */
  490. wwn_t peer_wwnn; /* P2P peer WWNN */
  491. wwn_t peer_wwpn; /* P2P peer WWPN */
  492. u32 peer_d_id; /* P2P peer D_ID */
  493. struct ccw_device *ccw_device; /* S/390 ccw device */
  494. u32 hydra_version; /* Hydra version */
  495. u32 fsf_lic_version;
  496. u32 adapter_features; /* FCP channel features */
  497. u32 connection_features; /* host connection features */
  498. u32 hardware_version; /* of FCP channel */
  499. u16 timer_ticks; /* time int for a tick */
  500. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  501. struct list_head port_list_head; /* remote port list */
  502. struct list_head port_remove_lh; /* head of ports to be
  503. removed */
  504. u32 ports; /* number of remote ports */
  505. unsigned long req_no; /* unique FSF req number */
  506. struct list_head *req_list; /* list of pending reqs */
  507. spinlock_t req_list_lock; /* request list lock */
  508. struct zfcp_qdio_queue req_q; /* request queue */
  509. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  510. wait_queue_head_t request_wq; /* can be used to wait for
  511. more avaliable SBALs */
  512. struct zfcp_qdio_queue resp_q; /* response queue */
  513. rwlock_t abort_lock; /* Protects against SCSI
  514. stack abort/command
  515. completion races */
  516. atomic_t stat_miss; /* # missing status reads*/
  517. struct work_struct stat_work;
  518. atomic_t status; /* status of this adapter */
  519. struct list_head erp_ready_head; /* error recovery for this
  520. adapter/devices */
  521. struct list_head erp_running_head;
  522. rwlock_t erp_lock;
  523. struct semaphore erp_ready_sem;
  524. wait_queue_head_t erp_thread_wqh;
  525. wait_queue_head_t erp_done_wqh;
  526. struct zfcp_erp_action erp_action; /* pending error recovery */
  527. atomic_t erp_counter;
  528. u32 erp_total_count; /* total nr of enqueued erp
  529. actions */
  530. u32 erp_low_mem_count; /* nr of erp actions waiting
  531. for memory */
  532. struct zfcp_port *nameserver_port; /* adapter's nameserver */
  533. debug_info_t *rec_dbf;
  534. debug_info_t *hba_dbf;
  535. debug_info_t *san_dbf; /* debug feature areas */
  536. debug_info_t *scsi_dbf;
  537. spinlock_t rec_dbf_lock;
  538. spinlock_t hba_dbf_lock;
  539. spinlock_t san_dbf_lock;
  540. spinlock_t scsi_dbf_lock;
  541. struct zfcp_rec_dbf_record rec_dbf_buf;
  542. struct zfcp_hba_dbf_record hba_dbf_buf;
  543. struct zfcp_san_dbf_record san_dbf_buf;
  544. struct zfcp_scsi_dbf_record scsi_dbf_buf;
  545. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  546. struct qdio_initialize qdio_init_data; /* for qdio_establish */
  547. struct device generic_services; /* directory for WKA ports */
  548. struct fc_host_statistics *fc_stats;
  549. struct fsf_qtcb_bottom_port *stats_reset_data;
  550. unsigned long stats_reset;
  551. struct work_struct scan_work;
  552. };
  553. /*
  554. * the struct device sysfs_device must be at the beginning of this structure.
  555. * pointer to struct device is used to free port structure in release function
  556. * of the device. don't change!
  557. */
  558. struct zfcp_port {
  559. struct device sysfs_device; /* sysfs device */
  560. struct fc_rport *rport; /* rport of fc transport class */
  561. struct list_head list; /* list of remote ports */
  562. atomic_t refcount; /* reference count */
  563. wait_queue_head_t remove_wq; /* can be used to wait for
  564. refcount drop to zero */
  565. struct zfcp_adapter *adapter; /* adapter used to access port */
  566. struct list_head unit_list_head; /* head of logical unit list */
  567. struct list_head unit_remove_lh; /* head of luns to be removed
  568. list */
  569. u32 units; /* # of logical units in list */
  570. atomic_t status; /* status of this remote port */
  571. wwn_t wwnn; /* WWNN if known */
  572. wwn_t wwpn; /* WWPN */
  573. u32 d_id; /* D_ID */
  574. u32 handle; /* handle assigned by FSF */
  575. struct zfcp_erp_action erp_action; /* pending error recovery */
  576. atomic_t erp_counter;
  577. u32 maxframe_size;
  578. u32 supported_classes;
  579. };
  580. /* the struct device sysfs_device must be at the beginning of this structure.
  581. * pointer to struct device is used to free unit structure in release function
  582. * of the device. don't change!
  583. */
  584. struct zfcp_unit {
  585. struct device sysfs_device; /* sysfs device */
  586. struct list_head list; /* list of logical units */
  587. atomic_t refcount; /* reference count */
  588. wait_queue_head_t remove_wq; /* can be used to wait for
  589. refcount drop to zero */
  590. struct zfcp_port *port; /* remote port of unit */
  591. atomic_t status; /* status of this logical unit */
  592. unsigned int scsi_lun; /* own SCSI LUN */
  593. fcp_lun_t fcp_lun; /* own FCP_LUN */
  594. u32 handle; /* handle assigned by FSF */
  595. struct scsi_device *device; /* scsi device struct pointer */
  596. struct zfcp_erp_action erp_action; /* pending error recovery */
  597. atomic_t erp_counter;
  598. struct zfcp_latencies latencies;
  599. };
  600. /* FSF request */
  601. struct zfcp_fsf_req {
  602. struct list_head list; /* list of FSF requests */
  603. unsigned long req_id; /* unique request ID */
  604. struct zfcp_adapter *adapter; /* adapter request belongs to */
  605. u8 sbal_number; /* nr of SBALs free for use */
  606. u8 sbal_first; /* first SBAL for this request */
  607. u8 sbal_last; /* last SBAL for this request */
  608. u8 sbal_limit; /* last possible SBAL for
  609. this reuest */
  610. u8 sbale_curr; /* current SBALE during creation
  611. of request */
  612. u8 sbal_response; /* SBAL used in interrupt */
  613. wait_queue_head_t completion_wq; /* can be used by a routine
  614. to wait for completion */
  615. volatile u32 status; /* status of this request */
  616. u32 fsf_command; /* FSF Command copy */
  617. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  618. u32 seq_no; /* Sequence number of request */
  619. unsigned long data; /* private data of request */
  620. struct timer_list timer; /* used for erp or scsi er */
  621. struct zfcp_erp_action *erp_action; /* used if this request is
  622. issued on behalf of erp */
  623. mempool_t *pool; /* used if request was alloacted
  624. from emergency pool */
  625. unsigned long long issued; /* request sent time (STCK) */
  626. struct zfcp_unit *unit;
  627. };
  628. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  629. /* driver data */
  630. struct zfcp_data {
  631. struct scsi_host_template scsi_host_template;
  632. struct scsi_transport_template *scsi_transport_template;
  633. atomic_t status; /* Module status flags */
  634. struct list_head adapter_list_head; /* head of adapter list */
  635. struct list_head adapter_remove_lh; /* head of adapters to be
  636. removed */
  637. u32 adapters; /* # of adapters in list */
  638. rwlock_t config_lock; /* serialises changes
  639. to adapter/port/unit
  640. lists */
  641. struct semaphore config_sema; /* serialises configuration
  642. changes */
  643. atomic_t loglevel; /* current loglevel */
  644. char init_busid[BUS_ID_SIZE];
  645. wwn_t init_wwpn;
  646. fcp_lun_t init_fcp_lun;
  647. struct kmem_cache *fsf_req_qtcb_cache;
  648. struct kmem_cache *sr_buffer_cache;
  649. struct kmem_cache *gid_pn_cache;
  650. };
  651. /* number of elements for various memory pools */
  652. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  653. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  654. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  655. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  656. #define ZFCP_POOL_DATA_GID_PN_NR 1
  657. /* struct used by memory pools for fsf_requests */
  658. struct zfcp_fsf_req_qtcb {
  659. struct zfcp_fsf_req fsf_req;
  660. struct fsf_qtcb qtcb;
  661. };
  662. /********************** ZFCP SPECIFIC DEFINES ********************************/
  663. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  664. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  665. #define ZFCP_REQ_NO_QTCB 0x00000008
  666. #define ZFCP_SET 0x00000100
  667. #define ZFCP_CLEAR 0x00000200
  668. #ifndef atomic_test_mask
  669. #define atomic_test_mask(mask, target) \
  670. ((atomic_read(target) & mask) == mask)
  671. #endif
  672. extern void _zfcp_hex_dump(char *, int);
  673. #define ZFCP_HEX_DUMP(level, addr, count) \
  674. if (ZFCP_LOG_CHECK(level)) { \
  675. _zfcp_hex_dump(addr, count); \
  676. }
  677. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  678. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  679. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  680. /*
  681. * Helper functions for request ID management.
  682. */
  683. static inline int zfcp_reqlist_hash(unsigned long req_id)
  684. {
  685. return req_id % REQUEST_LIST_SIZE;
  686. }
  687. static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
  688. struct zfcp_fsf_req *fsf_req)
  689. {
  690. unsigned int idx;
  691. idx = zfcp_reqlist_hash(fsf_req->req_id);
  692. list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
  693. }
  694. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  695. struct zfcp_fsf_req *fsf_req)
  696. {
  697. list_del(&fsf_req->list);
  698. }
  699. static inline struct zfcp_fsf_req *
  700. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  701. {
  702. struct zfcp_fsf_req *request;
  703. unsigned int idx;
  704. idx = zfcp_reqlist_hash(req_id);
  705. list_for_each_entry(request, &adapter->req_list[idx], list)
  706. if (request->req_id == req_id)
  707. return request;
  708. return NULL;
  709. }
  710. static inline struct zfcp_fsf_req *
  711. zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
  712. {
  713. struct zfcp_fsf_req *request;
  714. unsigned int idx;
  715. for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
  716. list_for_each_entry(request, &adapter->req_list[idx], list)
  717. if (request == req)
  718. return request;
  719. }
  720. return NULL;
  721. }
  722. /*
  723. * functions needed for reference/usage counting
  724. */
  725. static inline void
  726. zfcp_unit_get(struct zfcp_unit *unit)
  727. {
  728. atomic_inc(&unit->refcount);
  729. }
  730. static inline void
  731. zfcp_unit_put(struct zfcp_unit *unit)
  732. {
  733. if (atomic_dec_return(&unit->refcount) == 0)
  734. wake_up(&unit->remove_wq);
  735. }
  736. static inline void
  737. zfcp_unit_wait(struct zfcp_unit *unit)
  738. {
  739. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  740. }
  741. static inline void
  742. zfcp_port_get(struct zfcp_port *port)
  743. {
  744. atomic_inc(&port->refcount);
  745. }
  746. static inline void
  747. zfcp_port_put(struct zfcp_port *port)
  748. {
  749. if (atomic_dec_return(&port->refcount) == 0)
  750. wake_up(&port->remove_wq);
  751. }
  752. static inline void
  753. zfcp_port_wait(struct zfcp_port *port)
  754. {
  755. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  756. }
  757. static inline void
  758. zfcp_adapter_get(struct zfcp_adapter *adapter)
  759. {
  760. atomic_inc(&adapter->refcount);
  761. }
  762. static inline void
  763. zfcp_adapter_put(struct zfcp_adapter *adapter)
  764. {
  765. if (atomic_dec_return(&adapter->refcount) == 0)
  766. wake_up(&adapter->remove_wq);
  767. }
  768. static inline void
  769. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  770. {
  771. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  772. }
  773. #endif /* ZFCP_DEF_H */