zfcp_def.h 20 KB

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