zfcp_def.h 21 KB

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