zfcp_def.h 37 KB

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