zfcp_def.h 20 KB

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