zfcp_def.h 24 KB

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