zfcp_def.h 20 KB

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