zfcp_def.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. /*
  2. *
  3. * linux/drivers/s390/scsi/zfcp_def.h
  4. *
  5. * FCP adapter driver for IBM eServer zSeries
  6. *
  7. * (C) Copyright IBM Corp. 2002, 2004
  8. *
  9. * Author(s): Martin Peschke <mpeschke@de.ibm.com>
  10. * Raimund Schroeder <raimund.schroeder@de.ibm.com>
  11. * Aron Zeh
  12. * Wolfgang Taphorn
  13. * Stefan Bader <stefan.bader@de.ibm.com>
  14. * Heiko Carstens <heiko.carstens@de.ibm.com>
  15. * Andreas Herrmann <aherrman@de.ibm.com>
  16. * Volker Sameske <sameske@de.ibm.com>
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2, or (at your option)
  21. * any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #ifndef ZFCP_DEF_H
  33. #define ZFCP_DEF_H
  34. /*************************** INCLUDES *****************************************/
  35. #include <linux/init.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/miscdevice.h>
  38. #include <linux/major.h>
  39. #include <linux/blkdev.h>
  40. #include <linux/delay.h>
  41. #include <linux/timer.h>
  42. #include <scsi/scsi.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include <scsi/scsi_cmnd.h>
  45. #include <scsi/scsi_device.h>
  46. #include <scsi/scsi_host.h>
  47. #include <scsi/scsi_transport.h>
  48. #include <scsi/scsi_transport_fc.h>
  49. #include "../../fc4/fc.h"
  50. #include "zfcp_fsf.h"
  51. #include <asm/ccwdev.h>
  52. #include <asm/qdio.h>
  53. #include <asm/debug.h>
  54. #include <asm/ebcdic.h>
  55. #include <linux/mempool.h>
  56. #include <linux/syscalls.h>
  57. #include <linux/ioctl.h>
  58. /********************* GENERAL DEFINES *********************************/
  59. /* zfcp version number, it consists of major, minor, and patch-level number */
  60. #define ZFCP_VERSION "4.5.0"
  61. /**
  62. * zfcp_sg_to_address - determine kernel address from struct scatterlist
  63. * @list: struct scatterlist
  64. * Return: kernel address
  65. */
  66. static inline void *
  67. zfcp_sg_to_address(struct scatterlist *list)
  68. {
  69. return (void *) (page_address(list->page) + list->offset);
  70. }
  71. /**
  72. * zfcp_address_to_sg - set up struct scatterlist from kernel address
  73. * @address: kernel address
  74. * @list: struct scatterlist
  75. */
  76. static inline void
  77. zfcp_address_to_sg(void *address, struct scatterlist *list)
  78. {
  79. list->page = virt_to_page(address);
  80. list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
  81. }
  82. /********************* SCSI SPECIFIC DEFINES *********************************/
  83. /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
  84. typedef u32 scsi_id_t;
  85. typedef u32 scsi_lun_t;
  86. #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT (100*HZ)
  87. #define ZFCP_SCSI_ER_TIMEOUT (100*HZ)
  88. /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
  89. /* Adapter Identification Parameters */
  90. #define ZFCP_CONTROL_UNIT_TYPE 0x1731
  91. #define ZFCP_CONTROL_UNIT_MODEL 0x03
  92. #define ZFCP_DEVICE_TYPE 0x1732
  93. #define ZFCP_DEVICE_MODEL 0x03
  94. #define ZFCP_DEVICE_MODEL_PRIV 0x04
  95. /* allow as many chained SBALs as are supported by hardware */
  96. #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
  97. #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
  98. #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
  99. /* DMQ bug workaround: don't use last SBALE */
  100. #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
  101. /* index of last SBALE (with respect to DMQ bug workaround) */
  102. #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
  103. /* max. number of (data buffer) SBALEs in largest SBAL chain */
  104. #define ZFCP_MAX_SBALES_PER_REQ \
  105. (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
  106. /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
  107. /* FIXME(tune): free space should be one max. SBAL chain plus what? */
  108. #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
  109. - (ZFCP_MAX_SBALS_PER_REQ + 4))
  110. #define ZFCP_SBAL_TIMEOUT (5*HZ)
  111. #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
  112. /* queue polling (values in microseconds) */
  113. #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
  114. #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
  115. #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
  116. #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
  117. #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
  118. /********************* FSF SPECIFIC DEFINES *********************************/
  119. #define ZFCP_ULP_INFO_VERSION 26
  120. #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
  121. /* ATTENTION: value must not be used by hardware */
  122. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  123. #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
  124. #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
  125. /* Do 1st retry in 1 second, then double the timeout for each following retry */
  126. #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 100
  127. #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
  128. /* Retry 5 times every 2 second, then every minute */
  129. #define ZFCP_EXCHANGE_PORT_DATA_SHORT_RETRIES 5
  130. #define ZFCP_EXCHANGE_PORT_DATA_SHORT_SLEEP 200
  131. #define ZFCP_EXCHANGE_PORT_DATA_LONG_SLEEP 6000
  132. /* timeout value for "default timer" for fsf requests */
  133. #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
  134. /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
  135. typedef unsigned long long wwn_t;
  136. typedef unsigned long long fcp_lun_t;
  137. /* data length field may be at variable position in FCP-2 FCP_CMND IU */
  138. typedef unsigned int fcp_dl_t;
  139. #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
  140. /* timeout for name-server lookup (in seconds) */
  141. #define ZFCP_NS_GID_PN_TIMEOUT 10
  142. /* largest SCSI command we can process */
  143. /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
  144. #define ZFCP_MAX_SCSI_CMND_LENGTH 255
  145. /* maximum number of commands in LUN queue (tagged queueing) */
  146. #define ZFCP_CMND_PER_LUN 32
  147. /* task attribute values in FCP-2 FCP_CMND IU */
  148. #define SIMPLE_Q 0
  149. #define HEAD_OF_Q 1
  150. #define ORDERED_Q 2
  151. #define ACA_Q 4
  152. #define UNTAGGED 5
  153. /* task management flags in FCP-2 FCP_CMND IU */
  154. #define FCP_CLEAR_ACA 0x40
  155. #define FCP_TARGET_RESET 0x20
  156. #define FCP_LOGICAL_UNIT_RESET 0x10
  157. #define FCP_CLEAR_TASK_SET 0x04
  158. #define FCP_ABORT_TASK_SET 0x02
  159. #define FCP_CDB_LENGTH 16
  160. #define ZFCP_DID_MASK 0x00FFFFFF
  161. /* FCP(-2) FCP_CMND IU */
  162. struct fcp_cmnd_iu {
  163. fcp_lun_t fcp_lun; /* FCP logical unit number */
  164. u8 crn; /* command reference number */
  165. u8 reserved0:5; /* reserved */
  166. u8 task_attribute:3; /* task attribute */
  167. u8 task_management_flags; /* task management flags */
  168. u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
  169. u8 rddata:1; /* read data */
  170. u8 wddata:1; /* write data */
  171. u8 fcp_cdb[FCP_CDB_LENGTH];
  172. } __attribute__((packed));
  173. /* FCP(-2) FCP_RSP IU */
  174. struct fcp_rsp_iu {
  175. u8 reserved0[10];
  176. union {
  177. struct {
  178. u8 reserved1:3;
  179. u8 fcp_conf_req:1;
  180. u8 fcp_resid_under:1;
  181. u8 fcp_resid_over:1;
  182. u8 fcp_sns_len_valid:1;
  183. u8 fcp_rsp_len_valid:1;
  184. } bits;
  185. u8 value;
  186. } validity;
  187. u8 scsi_status;
  188. u32 fcp_resid;
  189. u32 fcp_sns_len;
  190. u32 fcp_rsp_len;
  191. } __attribute__((packed));
  192. #define RSP_CODE_GOOD 0
  193. #define RSP_CODE_LENGTH_MISMATCH 1
  194. #define RSP_CODE_FIELD_INVALID 2
  195. #define RSP_CODE_RO_MISMATCH 3
  196. #define RSP_CODE_TASKMAN_UNSUPP 4
  197. #define RSP_CODE_TASKMAN_FAILED 5
  198. /* see fc-fs */
  199. #define LS_FAN 0x60000000
  200. #define LS_RSCN 0x61040000
  201. struct fcp_rscn_head {
  202. u8 command;
  203. u8 page_length; /* always 0x04 */
  204. u16 payload_len;
  205. } __attribute__((packed));
  206. struct fcp_rscn_element {
  207. u8 reserved:2;
  208. u8 event_qual:4;
  209. u8 addr_format:2;
  210. u32 nport_did:24;
  211. } __attribute__((packed));
  212. #define ZFCP_PORT_ADDRESS 0x0
  213. #define ZFCP_AREA_ADDRESS 0x1
  214. #define ZFCP_DOMAIN_ADDRESS 0x2
  215. #define ZFCP_FABRIC_ADDRESS 0x3
  216. #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
  217. #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
  218. #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
  219. #define ZFCP_PORTS_RANGE_FABRIC 0x000000
  220. #define ZFCP_NO_PORTS_PER_AREA 0x100
  221. #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
  222. #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
  223. struct fcp_fan {
  224. u32 command;
  225. u32 fport_did;
  226. wwn_t fport_wwpn;
  227. wwn_t fport_wwname;
  228. } __attribute__((packed));
  229. /* see fc-ph */
  230. struct fcp_logo {
  231. u32 command;
  232. u32 nport_did;
  233. wwn_t nport_wwpn;
  234. } __attribute__((packed));
  235. /*
  236. * DBF stuff
  237. */
  238. #define ZFCP_DBF_TAG_SIZE 4
  239. struct zfcp_dbf_dump {
  240. u8 tag[ZFCP_DBF_TAG_SIZE];
  241. u32 total_size; /* size of total dump data */
  242. u32 offset; /* how much data has being already dumped */
  243. u32 size; /* how much data comes with this record */
  244. u8 data[]; /* dump data */
  245. } __attribute__ ((packed));
  246. /* FIXME: to be inflated when reworking the erp dbf */
  247. struct zfcp_erp_dbf_record {
  248. u8 dummy[16];
  249. } __attribute__ ((packed));
  250. struct zfcp_hba_dbf_record_response {
  251. u32 fsf_command;
  252. u64 fsf_reqid;
  253. u32 fsf_seqno;
  254. u64 fsf_issued;
  255. u32 fsf_prot_status;
  256. u32 fsf_status;
  257. u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  258. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  259. u32 fsf_req_status;
  260. u8 sbal_first;
  261. u8 sbal_curr;
  262. u8 sbal_last;
  263. u8 pool;
  264. u64 erp_action;
  265. union {
  266. struct {
  267. u64 scsi_cmnd;
  268. u64 scsi_serial;
  269. } send_fcp;
  270. struct {
  271. u64 wwpn;
  272. u32 d_id;
  273. u32 port_handle;
  274. } port;
  275. struct {
  276. u64 wwpn;
  277. u64 fcp_lun;
  278. u32 port_handle;
  279. u32 lun_handle;
  280. } unit;
  281. struct {
  282. u32 d_id;
  283. u8 ls_code;
  284. } send_els;
  285. } data;
  286. } __attribute__ ((packed));
  287. struct zfcp_hba_dbf_record_status {
  288. u8 failed;
  289. u32 status_type;
  290. u32 status_subtype;
  291. struct fsf_queue_designator
  292. queue_designator;
  293. u32 payload_size;
  294. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  295. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  296. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  297. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  298. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  299. } __attribute__ ((packed));
  300. struct zfcp_hba_dbf_record_qdio {
  301. u32 status;
  302. u32 qdio_error;
  303. u32 siga_error;
  304. u8 sbal_index;
  305. u8 sbal_count;
  306. } __attribute__ ((packed));
  307. struct zfcp_hba_dbf_record {
  308. u8 tag[ZFCP_DBF_TAG_SIZE];
  309. u8 tag2[ZFCP_DBF_TAG_SIZE];
  310. union {
  311. struct zfcp_hba_dbf_record_response response;
  312. struct zfcp_hba_dbf_record_status status;
  313. struct zfcp_hba_dbf_record_qdio qdio;
  314. } type;
  315. } __attribute__ ((packed));
  316. struct zfcp_san_dbf_record_ct {
  317. union {
  318. struct {
  319. u16 cmd_req_code;
  320. u8 revision;
  321. u8 gs_type;
  322. u8 gs_subtype;
  323. u8 options;
  324. u16 max_res_size;
  325. } request;
  326. struct {
  327. u16 cmd_rsp_code;
  328. u8 revision;
  329. u8 reason_code;
  330. u8 reason_code_expl;
  331. u8 vendor_unique;
  332. } response;
  333. } type;
  334. u32 payload_size;
  335. #define ZFCP_DBF_CT_PAYLOAD 24
  336. u8 payload[ZFCP_DBF_CT_PAYLOAD];
  337. } __attribute__ ((packed));
  338. struct zfcp_san_dbf_record_els {
  339. u8 ls_code;
  340. u32 payload_size;
  341. #define ZFCP_DBF_ELS_PAYLOAD 32
  342. #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
  343. u8 payload[ZFCP_DBF_ELS_PAYLOAD];
  344. } __attribute__ ((packed));
  345. struct zfcp_san_dbf_record {
  346. u8 tag[ZFCP_DBF_TAG_SIZE];
  347. u64 fsf_reqid;
  348. u32 fsf_seqno;
  349. u32 s_id;
  350. u32 d_id;
  351. union {
  352. struct zfcp_san_dbf_record_ct ct;
  353. struct zfcp_san_dbf_record_els els;
  354. } type;
  355. } __attribute__ ((packed));
  356. struct zfcp_scsi_dbf_record {
  357. u8 tag[ZFCP_DBF_TAG_SIZE];
  358. u8 tag2[ZFCP_DBF_TAG_SIZE];
  359. u32 scsi_id;
  360. u32 scsi_lun;
  361. u32 scsi_result;
  362. u64 scsi_cmnd;
  363. u64 scsi_serial;
  364. #define ZFCP_DBF_SCSI_OPCODE 16
  365. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  366. u8 scsi_retries;
  367. u8 scsi_allowed;
  368. u64 fsf_reqid;
  369. u32 fsf_seqno;
  370. u64 fsf_issued;
  371. union {
  372. struct {
  373. u64 fsf_reqid;
  374. u32 fsf_seqno;
  375. u64 fsf_issued;
  376. } new_fsf_req;
  377. struct {
  378. u8 rsp_validity;
  379. u8 rsp_scsi_status;
  380. u32 rsp_resid;
  381. u8 rsp_code;
  382. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  383. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  384. u32 sns_info_len;
  385. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  386. } fcp;
  387. } type;
  388. } __attribute__ ((packed));
  389. /*
  390. * FC-FS stuff
  391. */
  392. #define R_A_TOV 10 /* seconds */
  393. #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
  394. #define ZFCP_LS_RLS 0x0f
  395. #define ZFCP_LS_ADISC 0x52
  396. #define ZFCP_LS_RPS 0x56
  397. #define ZFCP_LS_RSCN 0x61
  398. #define ZFCP_LS_RNID 0x78
  399. struct zfcp_ls_rjt_par {
  400. u8 action;
  401. u8 reason_code;
  402. u8 reason_expl;
  403. u8 vendor_unique;
  404. } __attribute__ ((packed));
  405. struct zfcp_ls_adisc {
  406. u8 code;
  407. u8 field[3];
  408. u32 hard_nport_id;
  409. u64 wwpn;
  410. u64 wwnn;
  411. u32 nport_id;
  412. } __attribute__ ((packed));
  413. struct zfcp_ls_adisc_acc {
  414. u8 code;
  415. u8 field[3];
  416. u32 hard_nport_id;
  417. u64 wwpn;
  418. u64 wwnn;
  419. u32 nport_id;
  420. } __attribute__ ((packed));
  421. struct zfcp_rc_entry {
  422. u8 code;
  423. const char *description;
  424. };
  425. /*
  426. * FC-GS-2 stuff
  427. */
  428. #define ZFCP_CT_REVISION 0x01
  429. #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
  430. #define ZFCP_CT_NAME_SERVER 0x02
  431. #define ZFCP_CT_SYNCHRONOUS 0x00
  432. #define ZFCP_CT_GID_PN 0x0121
  433. #define ZFCP_CT_MAX_SIZE 0x1020
  434. #define ZFCP_CT_ACCEPT 0x8002
  435. #define ZFCP_CT_REJECT 0x8001
  436. /*
  437. * FC-GS-4 stuff
  438. */
  439. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  440. /******************** LOGGING MACROS AND DEFINES *****************************/
  441. /*
  442. * Logging may be applied on certain kinds of driver operations
  443. * independently. Additionally, different log-levels are supported for
  444. * each of these areas.
  445. */
  446. #define ZFCP_NAME "zfcp"
  447. /* read-only LUN sharing switch initial value */
  448. #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
  449. /* independent log areas */
  450. #define ZFCP_LOG_AREA_OTHER 0
  451. #define ZFCP_LOG_AREA_SCSI 1
  452. #define ZFCP_LOG_AREA_FSF 2
  453. #define ZFCP_LOG_AREA_CONFIG 3
  454. #define ZFCP_LOG_AREA_CIO 4
  455. #define ZFCP_LOG_AREA_QDIO 5
  456. #define ZFCP_LOG_AREA_ERP 6
  457. #define ZFCP_LOG_AREA_FC 7
  458. /* log level values*/
  459. #define ZFCP_LOG_LEVEL_NORMAL 0
  460. #define ZFCP_LOG_LEVEL_INFO 1
  461. #define ZFCP_LOG_LEVEL_DEBUG 2
  462. #define ZFCP_LOG_LEVEL_TRACE 3
  463. /*
  464. * this allows removal of logging code by the preprocessor
  465. * (the most detailed log level still to be compiled in is specified,
  466. * higher log levels are removed)
  467. */
  468. #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
  469. /* get "loglevel" nibble assignment */
  470. #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
  471. ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
  472. /* set "loglevel" nibble */
  473. #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
  474. (value << (zfcp_lognibble << 2))
  475. /* all log-level defaults are combined to generate initial log-level */
  476. #define ZFCP_LOG_LEVEL_DEFAULTS \
  477. (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
  478. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
  479. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
  480. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
  481. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
  482. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
  483. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
  484. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
  485. /* check whether we have the right level for logging */
  486. #define ZFCP_LOG_CHECK(level) \
  487. ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
  488. /* logging routine for zfcp */
  489. #define _ZFCP_LOG(fmt, args...) \
  490. printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
  491. __LINE__ , ##args)
  492. #define ZFCP_LOG(level, fmt, args...) \
  493. do { \
  494. if (ZFCP_LOG_CHECK(level)) \
  495. _ZFCP_LOG(fmt, ##args); \
  496. } while (0)
  497. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
  498. # define ZFCP_LOG_NORMAL(fmt, args...)
  499. #else
  500. # define ZFCP_LOG_NORMAL(fmt, args...) \
  501. do { \
  502. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
  503. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  504. } while (0)
  505. #endif
  506. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
  507. # define ZFCP_LOG_INFO(fmt, args...)
  508. #else
  509. # define ZFCP_LOG_INFO(fmt, args...) \
  510. do { \
  511. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
  512. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  513. } while (0)
  514. #endif
  515. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
  516. # define ZFCP_LOG_DEBUG(fmt, args...)
  517. #else
  518. # define ZFCP_LOG_DEBUG(fmt, args...) \
  519. ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
  520. #endif
  521. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
  522. # define ZFCP_LOG_TRACE(fmt, args...)
  523. #else
  524. # define ZFCP_LOG_TRACE(fmt, args...) \
  525. ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
  526. #endif
  527. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  528. /*
  529. * Note, the leftmost status byte is common among adapter, port
  530. * and unit
  531. */
  532. #define ZFCP_COMMON_FLAGS 0xfff00000
  533. #define ZFCP_SPECIFIC_FLAGS 0x000fffff
  534. /* common status bits */
  535. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  536. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  537. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  538. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  539. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  540. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  541. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  542. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  543. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  544. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  545. /* adapter status */
  546. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  547. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  548. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  549. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  550. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  551. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  552. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  553. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  554. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  555. #define ZFCP_STATUS_ADAPTER_SCSI_UP \
  556. (ZFCP_STATUS_COMMON_UNBLOCKED | \
  557. ZFCP_STATUS_ADAPTER_REGISTERED)
  558. /* FC-PH/FC-GS well-known address identifiers for generic services */
  559. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  560. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  561. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  562. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  563. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  564. /* remote port status */
  565. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  566. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  567. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  568. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  569. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  570. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  571. #define ZFCP_STATUS_PORT_ACCESS_DENIED 0x00000040
  572. /* for ports with well known addresses */
  573. #define ZFCP_STATUS_PORT_WKA \
  574. (ZFCP_STATUS_PORT_NO_WWPN | \
  575. ZFCP_STATUS_PORT_NO_SCSI_ID)
  576. /* logical unit status */
  577. #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
  578. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  579. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  580. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  581. /* FSF request status (this does not have a common part) */
  582. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  583. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  584. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  585. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  586. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  587. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  588. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  589. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  590. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  591. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  592. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  593. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  594. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  595. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  596. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  597. #define ZFCP_MAX_ERPS 3
  598. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  599. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  600. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  601. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  602. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  603. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  604. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  605. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  606. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  607. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  608. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  609. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  610. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  611. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  612. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  613. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  614. /* Ordered by escalation level (necessary for proper erp-code operation) */
  615. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  616. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  617. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  618. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  619. #define ZFCP_ERP_ACTION_RUNNING 0x1
  620. #define ZFCP_ERP_ACTION_READY 0x2
  621. #define ZFCP_ERP_SUCCEEDED 0x0
  622. #define ZFCP_ERP_FAILED 0x1
  623. #define ZFCP_ERP_CONTINUES 0x2
  624. #define ZFCP_ERP_EXIT 0x3
  625. #define ZFCP_ERP_DISMISSED 0x4
  626. #define ZFCP_ERP_NOMEM 0x5
  627. /******************** CFDC SPECIFIC STUFF *****************************/
  628. /* Firewall data channel sense data record */
  629. struct zfcp_cfdc_sense_data {
  630. u32 signature; /* Request signature */
  631. u32 devno; /* FCP adapter device number */
  632. u32 command; /* Command code */
  633. u32 fsf_status; /* FSF request status and status qualifier */
  634. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  635. u8 payloads[256]; /* Access conflicts list */
  636. u8 control_file[0]; /* Access control table */
  637. };
  638. #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
  639. #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
  640. #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
  641. #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
  642. #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
  643. #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
  644. #define ZFCP_CFDC_DOWNLOAD 0x00000001
  645. #define ZFCP_CFDC_UPLOAD 0x00000002
  646. #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
  647. #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
  648. #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
  649. #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
  650. #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
  651. /************************* STRUCTURE DEFINITIONS *****************************/
  652. struct zfcp_fsf_req;
  653. /* holds various memory pools of an adapter */
  654. struct zfcp_adapter_mempool {
  655. mempool_t *fsf_req_erp;
  656. mempool_t *fsf_req_scsi;
  657. mempool_t *fsf_req_abort;
  658. mempool_t *fsf_req_status_read;
  659. mempool_t *data_status_read;
  660. mempool_t *data_gid_pn;
  661. };
  662. /*
  663. * header for CT_IU
  664. */
  665. struct ct_hdr {
  666. u8 revision; // 0x01
  667. u8 in_id[3]; // 0x00
  668. u8 gs_type; // 0xFC Directory Service
  669. u8 gs_subtype; // 0x02 Name Server
  670. u8 options; // 0x00 single bidirectional exchange
  671. u8 reserved0;
  672. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  673. u16 max_res_size; // <= (4096 - 16) / 4
  674. u8 reserved1;
  675. u8 reason_code;
  676. u8 reason_code_expl;
  677. u8 vendor_unique;
  678. } __attribute__ ((packed));
  679. /* nameserver request CT_IU -- for requests where
  680. * a port name is required */
  681. struct ct_iu_gid_pn_req {
  682. struct ct_hdr header;
  683. wwn_t wwpn;
  684. } __attribute__ ((packed));
  685. /* FS_ACC IU and data unit for GID_PN nameserver request */
  686. struct ct_iu_gid_pn_resp {
  687. struct ct_hdr header;
  688. u32 d_id;
  689. } __attribute__ ((packed));
  690. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  691. /**
  692. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  693. * @port: port where the request is sent to
  694. * @req: scatter-gather list for request
  695. * @resp: scatter-gather list for response
  696. * @req_count: number of elements in request scatter-gather list
  697. * @resp_count: number of elements in response scatter-gather list
  698. * @handler: handler function (called for response to the request)
  699. * @handler_data: data passed to handler function
  700. * @pool: pointer to memory pool for ct request structure
  701. * @timeout: FSF timeout for this request
  702. * @timer: timer (e.g. for request initiated by erp)
  703. * @completion: completion for synchronization purposes
  704. * @status: used to pass error status to calling function
  705. */
  706. struct zfcp_send_ct {
  707. struct zfcp_port *port;
  708. struct scatterlist *req;
  709. struct scatterlist *resp;
  710. unsigned int req_count;
  711. unsigned int resp_count;
  712. zfcp_send_ct_handler_t handler;
  713. unsigned long handler_data;
  714. mempool_t *pool;
  715. int timeout;
  716. struct timer_list *timer;
  717. struct completion *completion;
  718. int status;
  719. };
  720. /* used for name server requests in error recovery */
  721. struct zfcp_gid_pn_data {
  722. struct zfcp_send_ct ct;
  723. struct scatterlist req;
  724. struct scatterlist resp;
  725. struct ct_iu_gid_pn_req ct_iu_req;
  726. struct ct_iu_gid_pn_resp ct_iu_resp;
  727. struct zfcp_port *port;
  728. };
  729. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  730. /**
  731. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  732. * @adapter: adapter where request is sent from
  733. * @port: port where ELS is destinated (port reference count has to be increased)
  734. * @d_id: destiniation id of port where request is sent to
  735. * @req: scatter-gather list for request
  736. * @resp: scatter-gather list for response
  737. * @req_count: number of elements in request scatter-gather list
  738. * @resp_count: number of elements in response scatter-gather list
  739. * @handler: handler function (called for response to the request)
  740. * @handler_data: data passed to handler function
  741. * @timer: timer (e.g. for request initiated by erp)
  742. * @completion: completion for synchronization purposes
  743. * @ls_code: hex code of ELS command
  744. * @status: used to pass error status to calling function
  745. */
  746. struct zfcp_send_els {
  747. struct zfcp_adapter *adapter;
  748. struct zfcp_port *port;
  749. u32 d_id;
  750. struct scatterlist *req;
  751. struct scatterlist *resp;
  752. unsigned int req_count;
  753. unsigned int resp_count;
  754. zfcp_send_els_handler_t handler;
  755. unsigned long handler_data;
  756. struct timer_list *timer;
  757. struct completion *completion;
  758. int ls_code;
  759. int status;
  760. };
  761. struct zfcp_qdio_queue {
  762. struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  763. u8 free_index; /* index of next free bfr
  764. in queue (free_count>0) */
  765. atomic_t free_count; /* number of free buffers
  766. in queue */
  767. rwlock_t queue_lock; /* lock for operations on queue */
  768. int distance_from_int; /* SBALs used since PCI indication
  769. was last set */
  770. };
  771. struct zfcp_erp_action {
  772. struct list_head list;
  773. int action; /* requested action code */
  774. struct zfcp_adapter *adapter; /* device which should be recovered */
  775. struct zfcp_port *port;
  776. struct zfcp_unit *unit;
  777. volatile u32 status; /* recovery status */
  778. u32 step; /* active step of this erp action */
  779. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  780. for this action */
  781. struct timer_list timer;
  782. };
  783. struct zfcp_adapter {
  784. struct list_head list; /* list of adapters */
  785. atomic_t refcount; /* reference count */
  786. wait_queue_head_t remove_wq; /* can be used to wait for
  787. refcount drop to zero */
  788. wwn_t peer_wwnn; /* P2P peer WWNN */
  789. wwn_t peer_wwpn; /* P2P peer WWPN */
  790. u32 peer_d_id; /* P2P peer D_ID */
  791. wwn_t physical_wwpn; /* WWPN of physical port */
  792. u32 physical_s_id; /* local FC port ID */
  793. struct ccw_device *ccw_device; /* S/390 ccw device */
  794. u8 fc_service_class;
  795. u32 hydra_version; /* Hydra version */
  796. u32 fsf_lic_version;
  797. u32 adapter_features; /* FCP channel features */
  798. u32 connection_features; /* host connection features */
  799. u32 hardware_version; /* of FCP channel */
  800. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  801. unsigned short scsi_host_no; /* Assigned host number */
  802. unsigned char name[9];
  803. struct list_head port_list_head; /* remote port list */
  804. struct list_head port_remove_lh; /* head of ports to be
  805. removed */
  806. u32 ports; /* number of remote ports */
  807. struct timer_list scsi_er_timer; /* SCSI err recovery watch */
  808. struct list_head fsf_req_list_head; /* head of FSF req list */
  809. spinlock_t fsf_req_list_lock; /* lock for ops on list of
  810. FSF requests */
  811. atomic_t fsf_reqs_active; /* # active FSF reqs */
  812. struct zfcp_qdio_queue request_queue; /* request queue */
  813. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  814. wait_queue_head_t request_wq; /* can be used to wait for
  815. more avaliable SBALs */
  816. struct zfcp_qdio_queue response_queue; /* response queue */
  817. rwlock_t abort_lock; /* Protects against SCSI
  818. stack abort/command
  819. completion races */
  820. u16 status_read_failed; /* # failed status reads */
  821. atomic_t status; /* status of this adapter */
  822. struct list_head erp_ready_head; /* error recovery for this
  823. adapter/devices */
  824. struct list_head erp_running_head;
  825. rwlock_t erp_lock;
  826. struct semaphore erp_ready_sem;
  827. wait_queue_head_t erp_thread_wqh;
  828. wait_queue_head_t erp_done_wqh;
  829. struct zfcp_erp_action erp_action; /* pending error recovery */
  830. atomic_t erp_counter;
  831. u32 erp_total_count; /* total nr of enqueued erp
  832. actions */
  833. u32 erp_low_mem_count; /* nr of erp actions waiting
  834. for memory */
  835. struct zfcp_port *nameserver_port; /* adapter's nameserver */
  836. debug_info_t *erp_dbf;
  837. debug_info_t *hba_dbf;
  838. debug_info_t *san_dbf; /* debug feature areas */
  839. debug_info_t *scsi_dbf;
  840. spinlock_t erp_dbf_lock;
  841. spinlock_t hba_dbf_lock;
  842. spinlock_t san_dbf_lock;
  843. spinlock_t scsi_dbf_lock;
  844. struct zfcp_erp_dbf_record erp_dbf_buf;
  845. struct zfcp_hba_dbf_record hba_dbf_buf;
  846. struct zfcp_san_dbf_record san_dbf_buf;
  847. struct zfcp_scsi_dbf_record scsi_dbf_buf;
  848. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  849. struct qdio_initialize qdio_init_data; /* for qdio_establish */
  850. struct device generic_services; /* directory for WKA ports */
  851. struct fc_host_statistics *fc_stats;
  852. struct fsf_qtcb_bottom_port *stats_reset_data;
  853. unsigned long stats_reset;
  854. };
  855. /*
  856. * the struct device sysfs_device must be at the beginning of this structure.
  857. * pointer to struct device is used to free port structure in release function
  858. * of the device. don't change!
  859. */
  860. struct zfcp_port {
  861. struct device sysfs_device; /* sysfs device */
  862. struct fc_rport *rport; /* rport of fc transport class */
  863. struct list_head list; /* list of remote ports */
  864. atomic_t refcount; /* reference count */
  865. wait_queue_head_t remove_wq; /* can be used to wait for
  866. refcount drop to zero */
  867. struct zfcp_adapter *adapter; /* adapter used to access port */
  868. struct list_head unit_list_head; /* head of logical unit list */
  869. struct list_head unit_remove_lh; /* head of luns to be removed
  870. list */
  871. u32 units; /* # of logical units in list */
  872. atomic_t status; /* status of this remote port */
  873. wwn_t wwnn; /* WWNN if known */
  874. wwn_t wwpn; /* WWPN */
  875. u32 d_id; /* D_ID */
  876. u32 handle; /* handle assigned by FSF */
  877. struct zfcp_erp_action erp_action; /* pending error recovery */
  878. atomic_t erp_counter;
  879. };
  880. /* the struct device sysfs_device must be at the beginning of this structure.
  881. * pointer to struct device is used to free unit structure in release function
  882. * of the device. don't change!
  883. */
  884. struct zfcp_unit {
  885. struct device sysfs_device; /* sysfs device */
  886. struct list_head list; /* list of logical units */
  887. atomic_t refcount; /* reference count */
  888. wait_queue_head_t remove_wq; /* can be used to wait for
  889. refcount drop to zero */
  890. struct zfcp_port *port; /* remote port of unit */
  891. atomic_t status; /* status of this logical unit */
  892. scsi_lun_t scsi_lun; /* own SCSI LUN */
  893. fcp_lun_t fcp_lun; /* own FCP_LUN */
  894. u32 handle; /* handle assigned by FSF */
  895. struct scsi_device *device; /* scsi device struct pointer */
  896. struct zfcp_erp_action erp_action; /* pending error recovery */
  897. atomic_t erp_counter;
  898. };
  899. /* FSF request */
  900. struct zfcp_fsf_req {
  901. struct list_head list; /* list of FSF requests */
  902. struct zfcp_adapter *adapter; /* adapter request belongs to */
  903. u8 sbal_number; /* nr of SBALs free for use */
  904. u8 sbal_first; /* first SBAL for this request */
  905. u8 sbal_last; /* last possible SBAL for
  906. this reuest */
  907. u8 sbal_curr; /* current SBAL during creation
  908. of request */
  909. u8 sbale_curr; /* current SBALE during creation
  910. of request */
  911. wait_queue_head_t completion_wq; /* can be used by a routine
  912. to wait for completion */
  913. volatile u32 status; /* status of this request */
  914. u32 fsf_command; /* FSF Command copy */
  915. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  916. u32 seq_no; /* Sequence number of request */
  917. unsigned long data; /* private data of request */
  918. struct zfcp_erp_action *erp_action; /* used if this request is
  919. issued on behalf of erp */
  920. mempool_t *pool; /* used if request was alloacted
  921. from emergency pool */
  922. unsigned long long issued; /* request sent time (STCK) */
  923. struct zfcp_unit *unit;
  924. };
  925. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  926. /* driver data */
  927. struct zfcp_data {
  928. struct scsi_host_template scsi_host_template;
  929. atomic_t status; /* Module status flags */
  930. struct list_head adapter_list_head; /* head of adapter list */
  931. struct list_head adapter_remove_lh; /* head of adapters to be
  932. removed */
  933. rwlock_t status_read_lock; /* for status read thread */
  934. struct list_head status_read_receive_head;
  935. struct list_head status_read_send_head;
  936. struct semaphore status_read_sema;
  937. wait_queue_head_t status_read_thread_wqh;
  938. u32 adapters; /* # of adapters in list */
  939. rwlock_t config_lock; /* serialises changes
  940. to adapter/port/unit
  941. lists */
  942. struct semaphore config_sema; /* serialises configuration
  943. changes */
  944. atomic_t loglevel; /* current loglevel */
  945. char init_busid[BUS_ID_SIZE];
  946. wwn_t init_wwpn;
  947. fcp_lun_t init_fcp_lun;
  948. char *driver_version;
  949. };
  950. /**
  951. * struct zfcp_sg_list - struct describing a scatter-gather list
  952. * @sg: pointer to array of (struct scatterlist)
  953. * @count: number of elements in scatter-gather list
  954. */
  955. struct zfcp_sg_list {
  956. struct scatterlist *sg;
  957. unsigned int count;
  958. };
  959. /* number of elements for various memory pools */
  960. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  961. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  962. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  963. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  964. #define ZFCP_POOL_DATA_GID_PN_NR 1
  965. /* struct used by memory pools for fsf_requests */
  966. struct zfcp_fsf_req_pool_element {
  967. struct zfcp_fsf_req fsf_req;
  968. struct fsf_qtcb qtcb;
  969. };
  970. /********************** ZFCP SPECIFIC DEFINES ********************************/
  971. #define ZFCP_FSFREQ_CLEANUP_TIMEOUT HZ/10
  972. #define ZFCP_KNOWN 0x00000001
  973. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  974. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  975. #define ZFCP_REQ_NO_QTCB 0x00000008
  976. #define ZFCP_SET 0x00000100
  977. #define ZFCP_CLEAR 0x00000200
  978. #define ZFCP_INTERRUPTIBLE 1
  979. #define ZFCP_UNINTERRUPTIBLE 0
  980. #ifndef atomic_test_mask
  981. #define atomic_test_mask(mask, target) \
  982. ((atomic_read(target) & mask) == mask)
  983. #endif
  984. extern void _zfcp_hex_dump(char *, int);
  985. #define ZFCP_HEX_DUMP(level, addr, count) \
  986. if (ZFCP_LOG_CHECK(level)) { \
  987. _zfcp_hex_dump(addr, count); \
  988. }
  989. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  990. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  991. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  992. /*
  993. * functions needed for reference/usage counting
  994. */
  995. static inline void
  996. zfcp_unit_get(struct zfcp_unit *unit)
  997. {
  998. atomic_inc(&unit->refcount);
  999. }
  1000. static inline void
  1001. zfcp_unit_put(struct zfcp_unit *unit)
  1002. {
  1003. if (atomic_dec_return(&unit->refcount) == 0)
  1004. wake_up(&unit->remove_wq);
  1005. }
  1006. static inline void
  1007. zfcp_unit_wait(struct zfcp_unit *unit)
  1008. {
  1009. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  1010. }
  1011. static inline void
  1012. zfcp_port_get(struct zfcp_port *port)
  1013. {
  1014. atomic_inc(&port->refcount);
  1015. }
  1016. static inline void
  1017. zfcp_port_put(struct zfcp_port *port)
  1018. {
  1019. if (atomic_dec_return(&port->refcount) == 0)
  1020. wake_up(&port->remove_wq);
  1021. }
  1022. static inline void
  1023. zfcp_port_wait(struct zfcp_port *port)
  1024. {
  1025. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  1026. }
  1027. static inline void
  1028. zfcp_adapter_get(struct zfcp_adapter *adapter)
  1029. {
  1030. atomic_inc(&adapter->refcount);
  1031. }
  1032. static inline void
  1033. zfcp_adapter_put(struct zfcp_adapter *adapter)
  1034. {
  1035. if (atomic_dec_return(&adapter->refcount) == 0)
  1036. wake_up(&adapter->remove_wq);
  1037. }
  1038. static inline void
  1039. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  1040. {
  1041. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  1042. }
  1043. #endif /* ZFCP_DEF_H */