zfcp_def.h 27 KB

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