zfcp_def.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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_GID_PN 0x0121
  236. #define ZFCP_CT_MAX_SIZE 0x1020
  237. #define ZFCP_CT_ACCEPT 0x8002
  238. #define ZFCP_CT_REJECT 0x8001
  239. /*
  240. * FC-GS-4 stuff
  241. */
  242. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  243. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  244. /*
  245. * Note, the leftmost status byte is common among adapter, port
  246. * and unit
  247. */
  248. #define ZFCP_COMMON_FLAGS 0xfff00000
  249. /* common status bits */
  250. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  251. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  252. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  253. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  254. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  255. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  256. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  257. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  258. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  259. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  260. /* adapter status */
  261. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  262. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  263. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  264. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  265. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  266. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  267. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  268. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  269. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  270. /* FC-PH/FC-GS well-known address identifiers for generic services */
  271. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  272. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  273. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  274. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  275. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  276. /* remote port status */
  277. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  278. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  279. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  280. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  281. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  282. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  283. /* for ports with well known addresses */
  284. #define ZFCP_STATUS_PORT_WKA \
  285. (ZFCP_STATUS_PORT_NO_WWPN | \
  286. ZFCP_STATUS_PORT_NO_SCSI_ID)
  287. /* logical unit status */
  288. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  289. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  290. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  291. #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
  292. #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
  293. /* FSF request status (this does not have a common part) */
  294. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  295. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  296. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  297. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  298. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  299. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  300. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  301. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  302. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  303. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  304. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  305. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  306. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  307. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  308. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  309. #define ZFCP_MAX_ERPS 3
  310. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  311. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  312. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  313. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  314. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  315. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  316. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  317. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  318. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  319. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  320. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  321. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  322. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  323. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  324. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  325. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  326. /* Ordered by escalation level (necessary for proper erp-code operation) */
  327. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  328. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  329. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  330. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  331. #define ZFCP_ERP_ACTION_RUNNING 0x1
  332. #define ZFCP_ERP_ACTION_READY 0x2
  333. #define ZFCP_ERP_SUCCEEDED 0x0
  334. #define ZFCP_ERP_FAILED 0x1
  335. #define ZFCP_ERP_CONTINUES 0x2
  336. #define ZFCP_ERP_EXIT 0x3
  337. #define ZFCP_ERP_DISMISSED 0x4
  338. #define ZFCP_ERP_NOMEM 0x5
  339. /************************* STRUCTURE DEFINITIONS *****************************/
  340. struct zfcp_fsf_req;
  341. /* holds various memory pools of an adapter */
  342. struct zfcp_adapter_mempool {
  343. mempool_t *fsf_req_erp;
  344. mempool_t *fsf_req_scsi;
  345. mempool_t *fsf_req_abort;
  346. mempool_t *fsf_req_status_read;
  347. mempool_t *data_status_read;
  348. mempool_t *data_gid_pn;
  349. };
  350. /*
  351. * header for CT_IU
  352. */
  353. struct ct_hdr {
  354. u8 revision; // 0x01
  355. u8 in_id[3]; // 0x00
  356. u8 gs_type; // 0xFC Directory Service
  357. u8 gs_subtype; // 0x02 Name Server
  358. u8 options; // 0x00 single bidirectional exchange
  359. u8 reserved0;
  360. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  361. u16 max_res_size; // <= (4096 - 16) / 4
  362. u8 reserved1;
  363. u8 reason_code;
  364. u8 reason_code_expl;
  365. u8 vendor_unique;
  366. } __attribute__ ((packed));
  367. /* nameserver request CT_IU -- for requests where
  368. * a port name is required */
  369. struct ct_iu_gid_pn_req {
  370. struct ct_hdr header;
  371. wwn_t wwpn;
  372. } __attribute__ ((packed));
  373. /* FS_ACC IU and data unit for GID_PN nameserver request */
  374. struct ct_iu_gid_pn_resp {
  375. struct ct_hdr header;
  376. u32 d_id;
  377. } __attribute__ ((packed));
  378. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  379. /**
  380. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  381. * @port: port where the request is sent to
  382. * @req: scatter-gather list for request
  383. * @resp: scatter-gather list for response
  384. * @req_count: number of elements in request scatter-gather list
  385. * @resp_count: number of elements in response scatter-gather list
  386. * @handler: handler function (called for response to the request)
  387. * @handler_data: data passed to handler function
  388. * @timeout: FSF timeout for this request
  389. * @completion: completion for synchronization purposes
  390. * @status: used to pass error status to calling function
  391. */
  392. struct zfcp_send_ct {
  393. struct zfcp_port *port;
  394. struct scatterlist *req;
  395. struct scatterlist *resp;
  396. unsigned int req_count;
  397. unsigned int resp_count;
  398. zfcp_send_ct_handler_t handler;
  399. unsigned long handler_data;
  400. int timeout;
  401. struct completion *completion;
  402. int status;
  403. };
  404. /* used for name server requests in error recovery */
  405. struct zfcp_gid_pn_data {
  406. struct zfcp_send_ct ct;
  407. struct scatterlist req;
  408. struct scatterlist resp;
  409. struct ct_iu_gid_pn_req ct_iu_req;
  410. struct ct_iu_gid_pn_resp ct_iu_resp;
  411. struct zfcp_port *port;
  412. };
  413. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  414. /**
  415. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  416. * @adapter: adapter where request is sent from
  417. * @port: port where ELS is destinated (port reference count has to be increased)
  418. * @d_id: destiniation id of port where request is sent to
  419. * @req: scatter-gather list for request
  420. * @resp: scatter-gather list for response
  421. * @req_count: number of elements in request scatter-gather list
  422. * @resp_count: number of elements in response scatter-gather list
  423. * @handler: handler function (called for response to the request)
  424. * @handler_data: data passed to handler function
  425. * @completion: completion for synchronization purposes
  426. * @ls_code: hex code of ELS command
  427. * @status: used to pass error status to calling function
  428. */
  429. struct zfcp_send_els {
  430. struct zfcp_adapter *adapter;
  431. struct zfcp_port *port;
  432. u32 d_id;
  433. struct scatterlist *req;
  434. struct scatterlist *resp;
  435. unsigned int req_count;
  436. unsigned int resp_count;
  437. zfcp_send_els_handler_t handler;
  438. unsigned long handler_data;
  439. struct completion *completion;
  440. int ls_code;
  441. int status;
  442. };
  443. struct zfcp_qdio_queue {
  444. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  445. u8 first; /* index of next free bfr
  446. in queue (free_count>0) */
  447. atomic_t count; /* number of free buffers
  448. in queue */
  449. rwlock_t lock; /* lock for operations on queue */
  450. int pci_batch; /* SBALs since PCI indication
  451. was last set */
  452. };
  453. struct zfcp_erp_action {
  454. struct list_head list;
  455. int action; /* requested action code */
  456. struct zfcp_adapter *adapter; /* device which should be recovered */
  457. struct zfcp_port *port;
  458. struct zfcp_unit *unit;
  459. volatile u32 status; /* recovery status */
  460. u32 step; /* active step of this erp action */
  461. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  462. for this action */
  463. struct timer_list timer;
  464. };
  465. struct fsf_latency_record {
  466. u32 min;
  467. u32 max;
  468. u64 sum;
  469. };
  470. struct latency_cont {
  471. struct fsf_latency_record channel;
  472. struct fsf_latency_record fabric;
  473. u64 counter;
  474. };
  475. struct zfcp_latencies {
  476. struct latency_cont read;
  477. struct latency_cont write;
  478. struct latency_cont cmd;
  479. spinlock_t lock;
  480. };
  481. struct zfcp_adapter {
  482. struct list_head list; /* list of adapters */
  483. atomic_t refcount; /* reference count */
  484. wait_queue_head_t remove_wq; /* can be used to wait for
  485. refcount drop to zero */
  486. wwn_t peer_wwnn; /* P2P peer WWNN */
  487. wwn_t peer_wwpn; /* P2P peer WWPN */
  488. u32 peer_d_id; /* P2P peer D_ID */
  489. struct ccw_device *ccw_device; /* S/390 ccw device */
  490. u32 hydra_version; /* Hydra version */
  491. u32 fsf_lic_version;
  492. u32 adapter_features; /* FCP channel features */
  493. u32 connection_features; /* host connection features */
  494. u32 hardware_version; /* of FCP channel */
  495. u16 timer_ticks; /* time int for a tick */
  496. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  497. struct list_head port_list_head; /* remote port list */
  498. struct list_head port_remove_lh; /* head of ports to be
  499. removed */
  500. u32 ports; /* number of remote ports */
  501. unsigned long req_no; /* unique FSF req number */
  502. struct list_head *req_list; /* list of pending reqs */
  503. spinlock_t req_list_lock; /* request list lock */
  504. struct zfcp_qdio_queue req_q; /* request queue */
  505. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  506. wait_queue_head_t request_wq; /* can be used to wait for
  507. more avaliable SBALs */
  508. struct zfcp_qdio_queue resp_q; /* response queue */
  509. rwlock_t abort_lock; /* Protects against SCSI
  510. stack abort/command
  511. completion races */
  512. atomic_t stat_miss; /* # missing status reads*/
  513. struct work_struct stat_work;
  514. atomic_t status; /* status of this adapter */
  515. struct list_head erp_ready_head; /* error recovery for this
  516. adapter/devices */
  517. struct list_head erp_running_head;
  518. rwlock_t erp_lock;
  519. struct semaphore erp_ready_sem;
  520. wait_queue_head_t erp_thread_wqh;
  521. wait_queue_head_t erp_done_wqh;
  522. struct zfcp_erp_action erp_action; /* pending error recovery */
  523. atomic_t erp_counter;
  524. u32 erp_total_count; /* total nr of enqueued erp
  525. actions */
  526. u32 erp_low_mem_count; /* nr of erp actions waiting
  527. for memory */
  528. struct zfcp_port *nameserver_port; /* adapter's nameserver */
  529. debug_info_t *rec_dbf;
  530. debug_info_t *hba_dbf;
  531. debug_info_t *san_dbf; /* debug feature areas */
  532. debug_info_t *scsi_dbf;
  533. spinlock_t rec_dbf_lock;
  534. spinlock_t hba_dbf_lock;
  535. spinlock_t san_dbf_lock;
  536. spinlock_t scsi_dbf_lock;
  537. struct zfcp_rec_dbf_record rec_dbf_buf;
  538. struct zfcp_hba_dbf_record hba_dbf_buf;
  539. struct zfcp_san_dbf_record san_dbf_buf;
  540. struct zfcp_scsi_dbf_record scsi_dbf_buf;
  541. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  542. struct qdio_initialize qdio_init_data; /* for qdio_establish */
  543. struct device generic_services; /* directory for WKA ports */
  544. struct fc_host_statistics *fc_stats;
  545. struct fsf_qtcb_bottom_port *stats_reset_data;
  546. unsigned long stats_reset;
  547. };
  548. /*
  549. * the struct device sysfs_device must be at the beginning of this structure.
  550. * pointer to struct device is used to free port structure in release function
  551. * of the device. don't change!
  552. */
  553. struct zfcp_port {
  554. struct device sysfs_device; /* sysfs device */
  555. struct fc_rport *rport; /* rport of fc transport class */
  556. struct list_head list; /* list of remote ports */
  557. atomic_t refcount; /* reference count */
  558. wait_queue_head_t remove_wq; /* can be used to wait for
  559. refcount drop to zero */
  560. struct zfcp_adapter *adapter; /* adapter used to access port */
  561. struct list_head unit_list_head; /* head of logical unit list */
  562. struct list_head unit_remove_lh; /* head of luns to be removed
  563. list */
  564. u32 units; /* # of logical units in list */
  565. atomic_t status; /* status of this remote port */
  566. wwn_t wwnn; /* WWNN if known */
  567. wwn_t wwpn; /* WWPN */
  568. u32 d_id; /* D_ID */
  569. u32 handle; /* handle assigned by FSF */
  570. struct zfcp_erp_action erp_action; /* pending error recovery */
  571. atomic_t erp_counter;
  572. u32 maxframe_size;
  573. u32 supported_classes;
  574. };
  575. /* the struct device sysfs_device must be at the beginning of this structure.
  576. * pointer to struct device is used to free unit structure in release function
  577. * of the device. don't change!
  578. */
  579. struct zfcp_unit {
  580. struct device sysfs_device; /* sysfs device */
  581. struct list_head list; /* list of logical units */
  582. atomic_t refcount; /* reference count */
  583. wait_queue_head_t remove_wq; /* can be used to wait for
  584. refcount drop to zero */
  585. struct zfcp_port *port; /* remote port of unit */
  586. atomic_t status; /* status of this logical unit */
  587. unsigned int scsi_lun; /* own SCSI LUN */
  588. fcp_lun_t fcp_lun; /* own FCP_LUN */
  589. u32 handle; /* handle assigned by FSF */
  590. struct scsi_device *device; /* scsi device struct pointer */
  591. struct zfcp_erp_action erp_action; /* pending error recovery */
  592. atomic_t erp_counter;
  593. struct zfcp_latencies latencies;
  594. };
  595. /* FSF request */
  596. struct zfcp_fsf_req {
  597. struct list_head list; /* list of FSF requests */
  598. unsigned long req_id; /* unique request ID */
  599. struct zfcp_adapter *adapter; /* adapter request belongs to */
  600. u8 sbal_number; /* nr of SBALs free for use */
  601. u8 sbal_first; /* first SBAL for this request */
  602. u8 sbal_last; /* last SBAL for this request */
  603. u8 sbal_limit; /* last possible SBAL for
  604. this reuest */
  605. u8 sbale_curr; /* current SBALE during creation
  606. of request */
  607. u8 sbal_response; /* SBAL used in interrupt */
  608. wait_queue_head_t completion_wq; /* can be used by a routine
  609. to wait for completion */
  610. volatile u32 status; /* status of this request */
  611. u32 fsf_command; /* FSF Command copy */
  612. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  613. u32 seq_no; /* Sequence number of request */
  614. unsigned long data; /* private data of request */
  615. struct timer_list timer; /* used for erp or scsi er */
  616. struct zfcp_erp_action *erp_action; /* used if this request is
  617. issued on behalf of erp */
  618. mempool_t *pool; /* used if request was alloacted
  619. from emergency pool */
  620. unsigned long long issued; /* request sent time (STCK) */
  621. struct zfcp_unit *unit;
  622. };
  623. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  624. /* driver data */
  625. struct zfcp_data {
  626. struct scsi_host_template scsi_host_template;
  627. struct scsi_transport_template *scsi_transport_template;
  628. atomic_t status; /* Module status flags */
  629. struct list_head adapter_list_head; /* head of adapter list */
  630. struct list_head adapter_remove_lh; /* head of adapters to be
  631. removed */
  632. u32 adapters; /* # of adapters in list */
  633. rwlock_t config_lock; /* serialises changes
  634. to adapter/port/unit
  635. lists */
  636. struct semaphore config_sema; /* serialises configuration
  637. changes */
  638. atomic_t loglevel; /* current loglevel */
  639. char init_busid[BUS_ID_SIZE];
  640. wwn_t init_wwpn;
  641. fcp_lun_t init_fcp_lun;
  642. struct kmem_cache *fsf_req_qtcb_cache;
  643. struct kmem_cache *sr_buffer_cache;
  644. struct kmem_cache *gid_pn_cache;
  645. };
  646. /* number of elements for various memory pools */
  647. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  648. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  649. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  650. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  651. #define ZFCP_POOL_DATA_GID_PN_NR 1
  652. /* struct used by memory pools for fsf_requests */
  653. struct zfcp_fsf_req_qtcb {
  654. struct zfcp_fsf_req fsf_req;
  655. struct fsf_qtcb qtcb;
  656. };
  657. /********************** ZFCP SPECIFIC DEFINES ********************************/
  658. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  659. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  660. #define ZFCP_REQ_NO_QTCB 0x00000008
  661. #define ZFCP_SET 0x00000100
  662. #define ZFCP_CLEAR 0x00000200
  663. #ifndef atomic_test_mask
  664. #define atomic_test_mask(mask, target) \
  665. ((atomic_read(target) & mask) == mask)
  666. #endif
  667. extern void _zfcp_hex_dump(char *, int);
  668. #define ZFCP_HEX_DUMP(level, addr, count) \
  669. if (ZFCP_LOG_CHECK(level)) { \
  670. _zfcp_hex_dump(addr, count); \
  671. }
  672. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  673. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  674. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  675. /*
  676. * Helper functions for request ID management.
  677. */
  678. static inline int zfcp_reqlist_hash(unsigned long req_id)
  679. {
  680. return req_id % REQUEST_LIST_SIZE;
  681. }
  682. static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
  683. struct zfcp_fsf_req *fsf_req)
  684. {
  685. unsigned int idx;
  686. idx = zfcp_reqlist_hash(fsf_req->req_id);
  687. list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
  688. }
  689. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  690. struct zfcp_fsf_req *fsf_req)
  691. {
  692. list_del(&fsf_req->list);
  693. }
  694. static inline struct zfcp_fsf_req *
  695. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  696. {
  697. struct zfcp_fsf_req *request;
  698. unsigned int idx;
  699. idx = zfcp_reqlist_hash(req_id);
  700. list_for_each_entry(request, &adapter->req_list[idx], list)
  701. if (request->req_id == req_id)
  702. return request;
  703. return NULL;
  704. }
  705. static inline struct zfcp_fsf_req *
  706. zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
  707. {
  708. struct zfcp_fsf_req *request;
  709. unsigned int idx;
  710. for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
  711. list_for_each_entry(request, &adapter->req_list[idx], list)
  712. if (request == req)
  713. return request;
  714. }
  715. return NULL;
  716. }
  717. /*
  718. * functions needed for reference/usage counting
  719. */
  720. static inline void
  721. zfcp_unit_get(struct zfcp_unit *unit)
  722. {
  723. atomic_inc(&unit->refcount);
  724. }
  725. static inline void
  726. zfcp_unit_put(struct zfcp_unit *unit)
  727. {
  728. if (atomic_dec_return(&unit->refcount) == 0)
  729. wake_up(&unit->remove_wq);
  730. }
  731. static inline void
  732. zfcp_unit_wait(struct zfcp_unit *unit)
  733. {
  734. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  735. }
  736. static inline void
  737. zfcp_port_get(struct zfcp_port *port)
  738. {
  739. atomic_inc(&port->refcount);
  740. }
  741. static inline void
  742. zfcp_port_put(struct zfcp_port *port)
  743. {
  744. if (atomic_dec_return(&port->refcount) == 0)
  745. wake_up(&port->remove_wq);
  746. }
  747. static inline void
  748. zfcp_port_wait(struct zfcp_port *port)
  749. {
  750. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  751. }
  752. static inline void
  753. zfcp_adapter_get(struct zfcp_adapter *adapter)
  754. {
  755. atomic_inc(&adapter->refcount);
  756. }
  757. static inline void
  758. zfcp_adapter_put(struct zfcp_adapter *adapter)
  759. {
  760. if (atomic_dec_return(&adapter->refcount) == 0)
  761. wake_up(&adapter->remove_wq);
  762. }
  763. static inline void
  764. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  765. {
  766. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  767. }
  768. #endif /* ZFCP_DEF_H */