zfcp_def.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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. /* FIXME: to be inflated when reworking the erp dbf */
  229. struct zfcp_erp_dbf_record {
  230. u8 dummy[16];
  231. } __attribute__ ((packed));
  232. struct zfcp_rec_dbf_record {
  233. u8 id;
  234. u8 id2;
  235. union {
  236. } u;
  237. } __attribute__ ((packed));
  238. struct zfcp_hba_dbf_record_response {
  239. u32 fsf_command;
  240. u64 fsf_reqid;
  241. u32 fsf_seqno;
  242. u64 fsf_issued;
  243. u32 fsf_prot_status;
  244. u32 fsf_status;
  245. u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  246. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  247. u32 fsf_req_status;
  248. u8 sbal_first;
  249. u8 sbal_curr;
  250. u8 sbal_last;
  251. u8 pool;
  252. u64 erp_action;
  253. union {
  254. struct {
  255. u64 scsi_cmnd;
  256. u64 scsi_serial;
  257. } send_fcp;
  258. struct {
  259. u64 wwpn;
  260. u32 d_id;
  261. u32 port_handle;
  262. } port;
  263. struct {
  264. u64 wwpn;
  265. u64 fcp_lun;
  266. u32 port_handle;
  267. u32 lun_handle;
  268. } unit;
  269. struct {
  270. u32 d_id;
  271. u8 ls_code;
  272. } send_els;
  273. } data;
  274. } __attribute__ ((packed));
  275. struct zfcp_hba_dbf_record_status {
  276. u8 failed;
  277. u32 status_type;
  278. u32 status_subtype;
  279. struct fsf_queue_designator
  280. queue_designator;
  281. u32 payload_size;
  282. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  283. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  284. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  285. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  286. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  287. } __attribute__ ((packed));
  288. struct zfcp_hba_dbf_record_qdio {
  289. u32 status;
  290. u32 qdio_error;
  291. u32 siga_error;
  292. u8 sbal_index;
  293. u8 sbal_count;
  294. } __attribute__ ((packed));
  295. struct zfcp_hba_dbf_record {
  296. u8 tag[ZFCP_DBF_TAG_SIZE];
  297. u8 tag2[ZFCP_DBF_TAG_SIZE];
  298. union {
  299. struct zfcp_hba_dbf_record_response response;
  300. struct zfcp_hba_dbf_record_status status;
  301. struct zfcp_hba_dbf_record_qdio qdio;
  302. } type;
  303. } __attribute__ ((packed));
  304. struct zfcp_san_dbf_record_ct {
  305. union {
  306. struct {
  307. u16 cmd_req_code;
  308. u8 revision;
  309. u8 gs_type;
  310. u8 gs_subtype;
  311. u8 options;
  312. u16 max_res_size;
  313. } request;
  314. struct {
  315. u16 cmd_rsp_code;
  316. u8 revision;
  317. u8 reason_code;
  318. u8 reason_code_expl;
  319. u8 vendor_unique;
  320. } response;
  321. } type;
  322. u32 payload_size;
  323. #define ZFCP_DBF_CT_PAYLOAD 24
  324. u8 payload[ZFCP_DBF_CT_PAYLOAD];
  325. } __attribute__ ((packed));
  326. struct zfcp_san_dbf_record_els {
  327. u8 ls_code;
  328. u32 payload_size;
  329. #define ZFCP_DBF_ELS_PAYLOAD 32
  330. #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
  331. u8 payload[ZFCP_DBF_ELS_PAYLOAD];
  332. } __attribute__ ((packed));
  333. struct zfcp_san_dbf_record {
  334. u8 tag[ZFCP_DBF_TAG_SIZE];
  335. u64 fsf_reqid;
  336. u32 fsf_seqno;
  337. u32 s_id;
  338. u32 d_id;
  339. union {
  340. struct zfcp_san_dbf_record_ct ct;
  341. struct zfcp_san_dbf_record_els els;
  342. } type;
  343. } __attribute__ ((packed));
  344. struct zfcp_scsi_dbf_record {
  345. u8 tag[ZFCP_DBF_TAG_SIZE];
  346. u8 tag2[ZFCP_DBF_TAG_SIZE];
  347. u32 scsi_id;
  348. u32 scsi_lun;
  349. u32 scsi_result;
  350. u64 scsi_cmnd;
  351. u64 scsi_serial;
  352. #define ZFCP_DBF_SCSI_OPCODE 16
  353. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  354. u8 scsi_retries;
  355. u8 scsi_allowed;
  356. u64 fsf_reqid;
  357. u32 fsf_seqno;
  358. u64 fsf_issued;
  359. union {
  360. u64 old_fsf_reqid;
  361. struct {
  362. u8 rsp_validity;
  363. u8 rsp_scsi_status;
  364. u32 rsp_resid;
  365. u8 rsp_code;
  366. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  367. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  368. u32 sns_info_len;
  369. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  370. } fcp;
  371. } type;
  372. } __attribute__ ((packed));
  373. /*
  374. * FC-FS stuff
  375. */
  376. #define R_A_TOV 10 /* seconds */
  377. #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
  378. #define ZFCP_LS_RLS 0x0f
  379. #define ZFCP_LS_ADISC 0x52
  380. #define ZFCP_LS_RPS 0x56
  381. #define ZFCP_LS_RSCN 0x61
  382. #define ZFCP_LS_RNID 0x78
  383. struct zfcp_ls_rjt_par {
  384. u8 action;
  385. u8 reason_code;
  386. u8 reason_expl;
  387. u8 vendor_unique;
  388. } __attribute__ ((packed));
  389. struct zfcp_ls_adisc {
  390. u8 code;
  391. u8 field[3];
  392. u32 hard_nport_id;
  393. u64 wwpn;
  394. u64 wwnn;
  395. u32 nport_id;
  396. } __attribute__ ((packed));
  397. struct zfcp_ls_adisc_acc {
  398. u8 code;
  399. u8 field[3];
  400. u32 hard_nport_id;
  401. u64 wwpn;
  402. u64 wwnn;
  403. u32 nport_id;
  404. } __attribute__ ((packed));
  405. struct zfcp_rc_entry {
  406. u8 code;
  407. const char *description;
  408. };
  409. /*
  410. * FC-GS-2 stuff
  411. */
  412. #define ZFCP_CT_REVISION 0x01
  413. #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
  414. #define ZFCP_CT_NAME_SERVER 0x02
  415. #define ZFCP_CT_SYNCHRONOUS 0x00
  416. #define ZFCP_CT_GID_PN 0x0121
  417. #define ZFCP_CT_MAX_SIZE 0x1020
  418. #define ZFCP_CT_ACCEPT 0x8002
  419. #define ZFCP_CT_REJECT 0x8001
  420. /*
  421. * FC-GS-4 stuff
  422. */
  423. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  424. /******************** LOGGING MACROS AND DEFINES *****************************/
  425. /*
  426. * Logging may be applied on certain kinds of driver operations
  427. * independently. Additionally, different log-levels are supported for
  428. * each of these areas.
  429. */
  430. #define ZFCP_NAME "zfcp"
  431. /* independent log areas */
  432. #define ZFCP_LOG_AREA_OTHER 0
  433. #define ZFCP_LOG_AREA_SCSI 1
  434. #define ZFCP_LOG_AREA_FSF 2
  435. #define ZFCP_LOG_AREA_CONFIG 3
  436. #define ZFCP_LOG_AREA_CIO 4
  437. #define ZFCP_LOG_AREA_QDIO 5
  438. #define ZFCP_LOG_AREA_ERP 6
  439. #define ZFCP_LOG_AREA_FC 7
  440. /* log level values*/
  441. #define ZFCP_LOG_LEVEL_NORMAL 0
  442. #define ZFCP_LOG_LEVEL_INFO 1
  443. #define ZFCP_LOG_LEVEL_DEBUG 2
  444. #define ZFCP_LOG_LEVEL_TRACE 3
  445. /*
  446. * this allows removal of logging code by the preprocessor
  447. * (the most detailed log level still to be compiled in is specified,
  448. * higher log levels are removed)
  449. */
  450. #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
  451. /* get "loglevel" nibble assignment */
  452. #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
  453. ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
  454. /* set "loglevel" nibble */
  455. #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
  456. (value << (zfcp_lognibble << 2))
  457. /* all log-level defaults are combined to generate initial log-level */
  458. #define ZFCP_LOG_LEVEL_DEFAULTS \
  459. (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
  460. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
  461. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
  462. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
  463. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
  464. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
  465. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
  466. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
  467. /* check whether we have the right level for logging */
  468. #define ZFCP_LOG_CHECK(level) \
  469. ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
  470. /* logging routine for zfcp */
  471. #define _ZFCP_LOG(fmt, args...) \
  472. printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
  473. __LINE__ , ##args)
  474. #define ZFCP_LOG(level, fmt, args...) \
  475. do { \
  476. if (ZFCP_LOG_CHECK(level)) \
  477. _ZFCP_LOG(fmt, ##args); \
  478. } while (0)
  479. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
  480. # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
  481. #else
  482. # define ZFCP_LOG_NORMAL(fmt, args...) \
  483. do { \
  484. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
  485. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  486. } while (0)
  487. #endif
  488. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
  489. # define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
  490. #else
  491. # define ZFCP_LOG_INFO(fmt, args...) \
  492. do { \
  493. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
  494. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  495. } while (0)
  496. #endif
  497. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
  498. # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
  499. #else
  500. # define ZFCP_LOG_DEBUG(fmt, args...) \
  501. ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
  502. #endif
  503. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
  504. # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
  505. #else
  506. # define ZFCP_LOG_TRACE(fmt, args...) \
  507. ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
  508. #endif
  509. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  510. /*
  511. * Note, the leftmost status byte is common among adapter, port
  512. * and unit
  513. */
  514. #define ZFCP_COMMON_FLAGS 0xfff00000
  515. /* common status bits */
  516. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  517. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  518. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  519. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  520. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  521. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  522. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  523. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  524. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  525. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  526. /* adapter status */
  527. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  528. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  529. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  530. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  531. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  532. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  533. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  534. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  535. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  536. /* FC-PH/FC-GS well-known address identifiers for generic services */
  537. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  538. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  539. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  540. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  541. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  542. /* remote port status */
  543. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  544. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  545. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  546. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  547. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  548. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  549. /* for ports with well known addresses */
  550. #define ZFCP_STATUS_PORT_WKA \
  551. (ZFCP_STATUS_PORT_NO_WWPN | \
  552. ZFCP_STATUS_PORT_NO_SCSI_ID)
  553. /* logical unit status */
  554. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  555. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  556. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  557. #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
  558. #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
  559. /* FSF request status (this does not have a common part) */
  560. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  561. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  562. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  563. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  564. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  565. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  566. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  567. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  568. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  569. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  570. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  571. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  572. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  573. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  574. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  575. #define ZFCP_MAX_ERPS 3
  576. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  577. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  578. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  579. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  580. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  581. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  582. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  583. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  584. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  585. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  586. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  587. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  588. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  589. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  590. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  591. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  592. /* Ordered by escalation level (necessary for proper erp-code operation) */
  593. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  594. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  595. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  596. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  597. #define ZFCP_ERP_ACTION_RUNNING 0x1
  598. #define ZFCP_ERP_ACTION_READY 0x2
  599. #define ZFCP_ERP_SUCCEEDED 0x0
  600. #define ZFCP_ERP_FAILED 0x1
  601. #define ZFCP_ERP_CONTINUES 0x2
  602. #define ZFCP_ERP_EXIT 0x3
  603. #define ZFCP_ERP_DISMISSED 0x4
  604. #define ZFCP_ERP_NOMEM 0x5
  605. /******************** CFDC SPECIFIC STUFF *****************************/
  606. /* Firewall data channel sense data record */
  607. struct zfcp_cfdc_sense_data {
  608. u32 signature; /* Request signature */
  609. u32 devno; /* FCP adapter device number */
  610. u32 command; /* Command code */
  611. u32 fsf_status; /* FSF request status and status qualifier */
  612. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  613. u8 payloads[256]; /* Access conflicts list */
  614. u8 control_file[0]; /* Access control table */
  615. };
  616. #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
  617. #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
  618. #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
  619. #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
  620. #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
  621. #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
  622. #define ZFCP_CFDC_DOWNLOAD 0x00000001
  623. #define ZFCP_CFDC_UPLOAD 0x00000002
  624. #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
  625. #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
  626. #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
  627. #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
  628. #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
  629. /************************* STRUCTURE DEFINITIONS *****************************/
  630. struct zfcp_fsf_req;
  631. /* holds various memory pools of an adapter */
  632. struct zfcp_adapter_mempool {
  633. mempool_t *fsf_req_erp;
  634. mempool_t *fsf_req_scsi;
  635. mempool_t *fsf_req_abort;
  636. mempool_t *fsf_req_status_read;
  637. mempool_t *data_status_read;
  638. mempool_t *data_gid_pn;
  639. };
  640. /*
  641. * header for CT_IU
  642. */
  643. struct ct_hdr {
  644. u8 revision; // 0x01
  645. u8 in_id[3]; // 0x00
  646. u8 gs_type; // 0xFC Directory Service
  647. u8 gs_subtype; // 0x02 Name Server
  648. u8 options; // 0x00 single bidirectional exchange
  649. u8 reserved0;
  650. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  651. u16 max_res_size; // <= (4096 - 16) / 4
  652. u8 reserved1;
  653. u8 reason_code;
  654. u8 reason_code_expl;
  655. u8 vendor_unique;
  656. } __attribute__ ((packed));
  657. /* nameserver request CT_IU -- for requests where
  658. * a port name is required */
  659. struct ct_iu_gid_pn_req {
  660. struct ct_hdr header;
  661. wwn_t wwpn;
  662. } __attribute__ ((packed));
  663. /* FS_ACC IU and data unit for GID_PN nameserver request */
  664. struct ct_iu_gid_pn_resp {
  665. struct ct_hdr header;
  666. u32 d_id;
  667. } __attribute__ ((packed));
  668. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  669. /**
  670. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  671. * @port: port where the request is sent to
  672. * @req: scatter-gather list for request
  673. * @resp: scatter-gather list for response
  674. * @req_count: number of elements in request scatter-gather list
  675. * @resp_count: number of elements in response scatter-gather list
  676. * @handler: handler function (called for response to the request)
  677. * @handler_data: data passed to handler function
  678. * @pool: pointer to memory pool for ct request structure
  679. * @timeout: FSF timeout for this request
  680. * @completion: completion for synchronization purposes
  681. * @status: used to pass error status to calling function
  682. */
  683. struct zfcp_send_ct {
  684. struct zfcp_port *port;
  685. struct scatterlist *req;
  686. struct scatterlist *resp;
  687. unsigned int req_count;
  688. unsigned int resp_count;
  689. zfcp_send_ct_handler_t handler;
  690. unsigned long handler_data;
  691. mempool_t *pool;
  692. int timeout;
  693. struct completion *completion;
  694. int status;
  695. };
  696. /* used for name server requests in error recovery */
  697. struct zfcp_gid_pn_data {
  698. struct zfcp_send_ct ct;
  699. struct scatterlist req;
  700. struct scatterlist resp;
  701. struct ct_iu_gid_pn_req ct_iu_req;
  702. struct ct_iu_gid_pn_resp ct_iu_resp;
  703. struct zfcp_port *port;
  704. };
  705. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  706. /**
  707. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  708. * @adapter: adapter where request is sent from
  709. * @port: port where ELS is destinated (port reference count has to be increased)
  710. * @d_id: destiniation id of port where request is sent to
  711. * @req: scatter-gather list for request
  712. * @resp: scatter-gather list for response
  713. * @req_count: number of elements in request scatter-gather list
  714. * @resp_count: number of elements in response scatter-gather list
  715. * @handler: handler function (called for response to the request)
  716. * @handler_data: data passed to handler function
  717. * @completion: completion for synchronization purposes
  718. * @ls_code: hex code of ELS command
  719. * @status: used to pass error status to calling function
  720. */
  721. struct zfcp_send_els {
  722. struct zfcp_adapter *adapter;
  723. struct zfcp_port *port;
  724. u32 d_id;
  725. struct scatterlist *req;
  726. struct scatterlist *resp;
  727. unsigned int req_count;
  728. unsigned int resp_count;
  729. zfcp_send_els_handler_t handler;
  730. unsigned long handler_data;
  731. struct completion *completion;
  732. int ls_code;
  733. int status;
  734. };
  735. struct zfcp_qdio_queue {
  736. struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  737. u8 free_index; /* index of next free bfr
  738. in queue (free_count>0) */
  739. atomic_t free_count; /* number of free buffers
  740. in queue */
  741. rwlock_t queue_lock; /* lock for operations on queue */
  742. int distance_from_int; /* SBALs used since PCI indication
  743. was last set */
  744. };
  745. struct zfcp_erp_action {
  746. struct list_head list;
  747. int action; /* requested action code */
  748. struct zfcp_adapter *adapter; /* device which should be recovered */
  749. struct zfcp_port *port;
  750. struct zfcp_unit *unit;
  751. volatile u32 status; /* recovery status */
  752. u32 step; /* active step of this erp action */
  753. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  754. for this action */
  755. struct timer_list timer;
  756. };
  757. struct zfcp_adapter {
  758. struct list_head list; /* list of adapters */
  759. atomic_t refcount; /* reference count */
  760. wait_queue_head_t remove_wq; /* can be used to wait for
  761. refcount drop to zero */
  762. wwn_t peer_wwnn; /* P2P peer WWNN */
  763. wwn_t peer_wwpn; /* P2P peer WWPN */
  764. u32 peer_d_id; /* P2P peer D_ID */
  765. struct ccw_device *ccw_device; /* S/390 ccw device */
  766. u32 hydra_version; /* Hydra version */
  767. u32 fsf_lic_version;
  768. u32 adapter_features; /* FCP channel features */
  769. u32 connection_features; /* host connection features */
  770. u32 hardware_version; /* of FCP channel */
  771. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  772. struct list_head port_list_head; /* remote port list */
  773. struct list_head port_remove_lh; /* head of ports to be
  774. removed */
  775. u32 ports; /* number of remote ports */
  776. atomic_t reqs_active; /* # active FSF reqs */
  777. unsigned long req_no; /* unique FSF req number */
  778. struct list_head *req_list; /* list of pending reqs */
  779. spinlock_t req_list_lock; /* request list lock */
  780. struct zfcp_qdio_queue request_queue; /* request queue */
  781. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  782. wait_queue_head_t request_wq; /* can be used to wait for
  783. more avaliable SBALs */
  784. struct zfcp_qdio_queue response_queue; /* response queue */
  785. rwlock_t abort_lock; /* Protects against SCSI
  786. stack abort/command
  787. completion races */
  788. u16 status_read_failed; /* # failed status reads */
  789. atomic_t status; /* status of this adapter */
  790. struct list_head erp_ready_head; /* error recovery for this
  791. adapter/devices */
  792. struct list_head erp_running_head;
  793. rwlock_t erp_lock;
  794. struct semaphore erp_ready_sem;
  795. wait_queue_head_t erp_thread_wqh;
  796. wait_queue_head_t erp_done_wqh;
  797. struct zfcp_erp_action erp_action; /* pending error recovery */
  798. atomic_t erp_counter;
  799. u32 erp_total_count; /* total nr of enqueued erp
  800. actions */
  801. u32 erp_low_mem_count; /* nr of erp actions waiting
  802. for memory */
  803. struct zfcp_port *nameserver_port; /* adapter's nameserver */
  804. debug_info_t *erp_dbf;
  805. debug_info_t *rec_dbf;
  806. debug_info_t *hba_dbf;
  807. debug_info_t *san_dbf; /* debug feature areas */
  808. debug_info_t *scsi_dbf;
  809. spinlock_t erp_dbf_lock;
  810. spinlock_t rec_dbf_lock;
  811. spinlock_t hba_dbf_lock;
  812. spinlock_t san_dbf_lock;
  813. spinlock_t scsi_dbf_lock;
  814. struct zfcp_erp_dbf_record erp_dbf_buf;
  815. struct zfcp_rec_dbf_record rec_dbf_buf;
  816. struct zfcp_hba_dbf_record hba_dbf_buf;
  817. struct zfcp_san_dbf_record san_dbf_buf;
  818. struct zfcp_scsi_dbf_record scsi_dbf_buf;
  819. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  820. struct qdio_initialize qdio_init_data; /* for qdio_establish */
  821. struct device generic_services; /* directory for WKA ports */
  822. struct fc_host_statistics *fc_stats;
  823. struct fsf_qtcb_bottom_port *stats_reset_data;
  824. unsigned long stats_reset;
  825. };
  826. /*
  827. * the struct device sysfs_device must be at the beginning of this structure.
  828. * pointer to struct device is used to free port structure in release function
  829. * of the device. don't change!
  830. */
  831. struct zfcp_port {
  832. struct device sysfs_device; /* sysfs device */
  833. struct fc_rport *rport; /* rport of fc transport class */
  834. struct list_head list; /* list of remote ports */
  835. atomic_t refcount; /* reference count */
  836. wait_queue_head_t remove_wq; /* can be used to wait for
  837. refcount drop to zero */
  838. struct zfcp_adapter *adapter; /* adapter used to access port */
  839. struct list_head unit_list_head; /* head of logical unit list */
  840. struct list_head unit_remove_lh; /* head of luns to be removed
  841. list */
  842. u32 units; /* # of logical units in list */
  843. atomic_t status; /* status of this remote port */
  844. wwn_t wwnn; /* WWNN if known */
  845. wwn_t wwpn; /* WWPN */
  846. u32 d_id; /* D_ID */
  847. u32 handle; /* handle assigned by FSF */
  848. struct zfcp_erp_action erp_action; /* pending error recovery */
  849. atomic_t erp_counter;
  850. u32 maxframe_size;
  851. u32 supported_classes;
  852. };
  853. /* the struct device sysfs_device must be at the beginning of this structure.
  854. * pointer to struct device is used to free unit structure in release function
  855. * of the device. don't change!
  856. */
  857. struct zfcp_unit {
  858. struct device sysfs_device; /* sysfs device */
  859. struct list_head list; /* list of logical units */
  860. atomic_t refcount; /* reference count */
  861. wait_queue_head_t remove_wq; /* can be used to wait for
  862. refcount drop to zero */
  863. struct zfcp_port *port; /* remote port of unit */
  864. atomic_t status; /* status of this logical unit */
  865. unsigned int scsi_lun; /* own SCSI LUN */
  866. fcp_lun_t fcp_lun; /* own FCP_LUN */
  867. u32 handle; /* handle assigned by FSF */
  868. struct scsi_device *device; /* scsi device struct pointer */
  869. struct zfcp_erp_action erp_action; /* pending error recovery */
  870. atomic_t erp_counter;
  871. };
  872. /* FSF request */
  873. struct zfcp_fsf_req {
  874. struct list_head list; /* list of FSF requests */
  875. unsigned long req_id; /* unique request ID */
  876. struct zfcp_adapter *adapter; /* adapter request belongs to */
  877. u8 sbal_number; /* nr of SBALs free for use */
  878. u8 sbal_first; /* first SBAL for this request */
  879. u8 sbal_last; /* last possible SBAL for
  880. this reuest */
  881. u8 sbal_curr; /* current SBAL during creation
  882. of request */
  883. u8 sbale_curr; /* current SBALE during creation
  884. of request */
  885. wait_queue_head_t completion_wq; /* can be used by a routine
  886. to wait for completion */
  887. volatile u32 status; /* status of this request */
  888. u32 fsf_command; /* FSF Command copy */
  889. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  890. u32 seq_no; /* Sequence number of request */
  891. unsigned long data; /* private data of request */
  892. struct timer_list timer; /* used for erp or scsi er */
  893. struct zfcp_erp_action *erp_action; /* used if this request is
  894. issued on behalf of erp */
  895. mempool_t *pool; /* used if request was alloacted
  896. from emergency pool */
  897. unsigned long long issued; /* request sent time (STCK) */
  898. struct zfcp_unit *unit;
  899. };
  900. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  901. /* driver data */
  902. struct zfcp_data {
  903. struct scsi_host_template scsi_host_template;
  904. struct scsi_transport_template *scsi_transport_template;
  905. atomic_t status; /* Module status flags */
  906. struct list_head adapter_list_head; /* head of adapter list */
  907. struct list_head adapter_remove_lh; /* head of adapters to be
  908. removed */
  909. u32 adapters; /* # of adapters in list */
  910. rwlock_t config_lock; /* serialises changes
  911. to adapter/port/unit
  912. lists */
  913. struct semaphore config_sema; /* serialises configuration
  914. changes */
  915. atomic_t loglevel; /* current loglevel */
  916. char init_busid[BUS_ID_SIZE];
  917. wwn_t init_wwpn;
  918. fcp_lun_t init_fcp_lun;
  919. char *driver_version;
  920. struct kmem_cache *fsf_req_qtcb_cache;
  921. struct kmem_cache *sr_buffer_cache;
  922. struct kmem_cache *gid_pn_cache;
  923. };
  924. /**
  925. * struct zfcp_sg_list - struct describing a scatter-gather list
  926. * @sg: pointer to array of (struct scatterlist)
  927. * @count: number of elements in scatter-gather list
  928. */
  929. struct zfcp_sg_list {
  930. struct scatterlist *sg;
  931. unsigned int count;
  932. };
  933. /* number of elements for various memory pools */
  934. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  935. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  936. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  937. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  938. #define ZFCP_POOL_DATA_GID_PN_NR 1
  939. /* struct used by memory pools for fsf_requests */
  940. struct zfcp_fsf_req_qtcb {
  941. struct zfcp_fsf_req fsf_req;
  942. struct fsf_qtcb qtcb;
  943. };
  944. /********************** ZFCP SPECIFIC DEFINES ********************************/
  945. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  946. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  947. #define ZFCP_REQ_NO_QTCB 0x00000008
  948. #define ZFCP_SET 0x00000100
  949. #define ZFCP_CLEAR 0x00000200
  950. #ifndef atomic_test_mask
  951. #define atomic_test_mask(mask, target) \
  952. ((atomic_read(target) & mask) == mask)
  953. #endif
  954. extern void _zfcp_hex_dump(char *, int);
  955. #define ZFCP_HEX_DUMP(level, addr, count) \
  956. if (ZFCP_LOG_CHECK(level)) { \
  957. _zfcp_hex_dump(addr, count); \
  958. }
  959. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  960. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  961. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  962. /*
  963. * Helper functions for request ID management.
  964. */
  965. static inline int zfcp_reqlist_hash(unsigned long req_id)
  966. {
  967. return req_id % REQUEST_LIST_SIZE;
  968. }
  969. static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
  970. struct zfcp_fsf_req *fsf_req)
  971. {
  972. unsigned int idx;
  973. idx = zfcp_reqlist_hash(fsf_req->req_id);
  974. list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
  975. }
  976. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  977. struct zfcp_fsf_req *fsf_req)
  978. {
  979. list_del(&fsf_req->list);
  980. }
  981. static inline struct zfcp_fsf_req *
  982. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  983. {
  984. struct zfcp_fsf_req *request;
  985. unsigned int idx;
  986. idx = zfcp_reqlist_hash(req_id);
  987. list_for_each_entry(request, &adapter->req_list[idx], list)
  988. if (request->req_id == req_id)
  989. return request;
  990. return NULL;
  991. }
  992. static inline struct zfcp_fsf_req *
  993. zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
  994. {
  995. struct zfcp_fsf_req *request;
  996. unsigned int idx;
  997. for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
  998. list_for_each_entry(request, &adapter->req_list[idx], list)
  999. if (request == req)
  1000. return request;
  1001. }
  1002. return NULL;
  1003. }
  1004. /*
  1005. * functions needed for reference/usage counting
  1006. */
  1007. static inline void
  1008. zfcp_unit_get(struct zfcp_unit *unit)
  1009. {
  1010. atomic_inc(&unit->refcount);
  1011. }
  1012. static inline void
  1013. zfcp_unit_put(struct zfcp_unit *unit)
  1014. {
  1015. if (atomic_dec_return(&unit->refcount) == 0)
  1016. wake_up(&unit->remove_wq);
  1017. }
  1018. static inline void
  1019. zfcp_unit_wait(struct zfcp_unit *unit)
  1020. {
  1021. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  1022. }
  1023. static inline void
  1024. zfcp_port_get(struct zfcp_port *port)
  1025. {
  1026. atomic_inc(&port->refcount);
  1027. }
  1028. static inline void
  1029. zfcp_port_put(struct zfcp_port *port)
  1030. {
  1031. if (atomic_dec_return(&port->refcount) == 0)
  1032. wake_up(&port->remove_wq);
  1033. }
  1034. static inline void
  1035. zfcp_port_wait(struct zfcp_port *port)
  1036. {
  1037. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  1038. }
  1039. static inline void
  1040. zfcp_adapter_get(struct zfcp_adapter *adapter)
  1041. {
  1042. atomic_inc(&adapter->refcount);
  1043. }
  1044. static inline void
  1045. zfcp_adapter_put(struct zfcp_adapter *adapter)
  1046. {
  1047. if (atomic_dec_return(&adapter->refcount) == 0)
  1048. wake_up(&adapter->remove_wq);
  1049. }
  1050. static inline void
  1051. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  1052. {
  1053. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  1054. }
  1055. #endif /* ZFCP_DEF_H */