zfcp_def.h 37 KB

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