zfcp_def.h 23 KB

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