ibmvfc.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
  4. *
  5. * Written By: Brian King <[email protected]>, IBM Corporation
  6. *
  7. * Copyright (C) IBM Corporation, 2008
  8. */
  9. #ifndef _IBMVFC_H
  10. #define _IBMVFC_H
  11. #include <linux/list.h>
  12. #include <linux/types.h>
  13. #include <scsi/viosrp.h>
  14. #define IBMVFC_NAME "ibmvfc"
  15. #define IBMVFC_DRIVER_VERSION "1.0.11"
  16. #define IBMVFC_DRIVER_DATE "(April 12, 2013)"
  17. #define IBMVFC_DEFAULT_TIMEOUT 60
  18. #define IBMVFC_ADISC_CANCEL_TIMEOUT 45
  19. #define IBMVFC_ADISC_TIMEOUT 15
  20. #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
  21. (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
  22. #define IBMVFC_INIT_TIMEOUT 120
  23. #define IBMVFC_ABORT_TIMEOUT 8
  24. #define IBMVFC_ABORT_WAIT_TIMEOUT 40
  25. #define IBMVFC_MAX_REQUESTS_DEFAULT 100
  26. #define IBMVFC_DEBUG 0
  27. #define IBMVFC_MAX_TARGETS 1024
  28. #define IBMVFC_MAX_LUN 0xffffffff
  29. #define IBMVFC_MAX_SECTORS 0xffffu
  30. #define IBMVFC_MAX_DISC_THREADS 4
  31. #define IBMVFC_TGT_MEMPOOL_SZ 64
  32. #define IBMVFC_MAX_CMDS_PER_LUN 64
  33. #define IBMVFC_MAX_HOST_INIT_RETRIES 6
  34. #define IBMVFC_MAX_TGT_INIT_RETRIES 3
  35. #define IBMVFC_DEV_LOSS_TMO (5 * 60)
  36. #define IBMVFC_DEFAULT_LOG_LEVEL 2
  37. #define IBMVFC_MAX_CDB_LEN 16
  38. #define IBMVFC_CLS3_ERROR 0
  39. #define IBMVFC_MQ 1
  40. #define IBMVFC_SCSI_CHANNELS 8
  41. #define IBMVFC_MAX_SCSI_QUEUES 16
  42. #define IBMVFC_SCSI_HW_QUEUES 8
  43. #define IBMVFC_MIG_NO_SUB_TO_CRQ 0
  44. #define IBMVFC_MIG_NO_N_TO_M 0
  45. /*
  46. * Ensure we have resources for ERP and initialization:
  47. * 1 for ERP
  48. * 1 for initialization
  49. * 1 for NPIV Logout
  50. * 2 for BSG passthru
  51. * 2 for each discovery thread
  52. */
  53. #define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
  54. #define IBMVFC_MAD_SUCCESS 0x00
  55. #define IBMVFC_MAD_NOT_SUPPORTED 0xF1
  56. #define IBMVFC_MAD_VERSION_NOT_SUPP 0xF2
  57. #define IBMVFC_MAD_FAILED 0xF7
  58. #define IBMVFC_MAD_DRIVER_FAILED 0xEE
  59. #define IBMVFC_MAD_CRQ_ERROR 0xEF
  60. enum ibmvfc_crq_valid {
  61. IBMVFC_CRQ_CMD_RSP = 0x80,
  62. IBMVFC_CRQ_INIT_RSP = 0xC0,
  63. IBMVFC_CRQ_XPORT_EVENT = 0xFF,
  64. };
  65. enum ibmvfc_crq_init_msg {
  66. IBMVFC_CRQ_INIT = 0x01,
  67. IBMVFC_CRQ_INIT_COMPLETE = 0x02,
  68. };
  69. enum ibmvfc_crq_xport_evts {
  70. IBMVFC_PARTNER_FAILED = 0x01,
  71. IBMVFC_PARTNER_DEREGISTER = 0x02,
  72. IBMVFC_PARTITION_MIGRATED = 0x06,
  73. };
  74. enum ibmvfc_cmd_status_flags {
  75. IBMVFC_FABRIC_MAPPED = 0x0001,
  76. IBMVFC_VIOS_FAILURE = 0x0002,
  77. IBMVFC_FC_FAILURE = 0x0004,
  78. IBMVFC_FC_SCSI_ERROR = 0x0008,
  79. IBMVFC_HW_EVENT_LOGGED = 0x0010,
  80. IBMVFC_VIOS_LOGGED = 0x0020,
  81. };
  82. enum ibmvfc_fabric_mapped_errors {
  83. IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
  84. IBMVFC_XPORT_FAULT = 0x0002,
  85. IBMVFC_CMD_TIMEOUT = 0x0003,
  86. IBMVFC_ENETDOWN = 0x0004,
  87. IBMVFC_HW_FAILURE = 0x0005,
  88. IBMVFC_LINK_DOWN_ERR = 0x0006,
  89. IBMVFC_LINK_DEAD_ERR = 0x0007,
  90. IBMVFC_UNABLE_TO_REGISTER = 0x0008,
  91. IBMVFC_XPORT_BUSY = 0x000A,
  92. IBMVFC_XPORT_DEAD = 0x000B,
  93. IBMVFC_CONFIG_ERROR = 0x000C,
  94. IBMVFC_NAME_SERVER_FAIL = 0x000D,
  95. IBMVFC_LINK_HALTED = 0x000E,
  96. IBMVFC_XPORT_GENERAL = 0x8000,
  97. };
  98. enum ibmvfc_vios_errors {
  99. IBMVFC_CRQ_FAILURE = 0x0001,
  100. IBMVFC_SW_FAILURE = 0x0002,
  101. IBMVFC_INVALID_PARAMETER = 0x0003,
  102. IBMVFC_MISSING_PARAMETER = 0x0004,
  103. IBMVFC_HOST_IO_BUS = 0x0005,
  104. IBMVFC_TRANS_CANCELLED = 0x0006,
  105. IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
  106. IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
  107. IBMVFC_PLOGI_REQUIRED = 0x0010,
  108. IBMVFC_COMMAND_FAILED = 0x8000,
  109. };
  110. enum ibmvfc_mad_types {
  111. IBMVFC_NPIV_LOGIN = 0x0001,
  112. IBMVFC_DISC_TARGETS = 0x0002,
  113. IBMVFC_PORT_LOGIN = 0x0004,
  114. IBMVFC_PROCESS_LOGIN = 0x0008,
  115. IBMVFC_QUERY_TARGET = 0x0010,
  116. IBMVFC_MOVE_LOGIN = 0x0020,
  117. IBMVFC_IMPLICIT_LOGOUT = 0x0040,
  118. IBMVFC_PASSTHRU = 0x0200,
  119. IBMVFC_TMF_MAD = 0x0100,
  120. IBMVFC_NPIV_LOGOUT = 0x0800,
  121. IBMVFC_CHANNEL_ENQUIRY = 0x1000,
  122. IBMVFC_CHANNEL_SETUP = 0x2000,
  123. IBMVFC_CONNECTION_INFO = 0x4000,
  124. };
  125. struct ibmvfc_mad_common {
  126. __be32 version;
  127. __be32 reserved;
  128. __be32 opcode;
  129. __be16 status;
  130. __be16 length;
  131. __be64 tag;
  132. } __packed __aligned(8);
  133. struct ibmvfc_npiv_login_mad {
  134. struct ibmvfc_mad_common common;
  135. struct srp_direct_buf buffer;
  136. } __packed __aligned(8);
  137. struct ibmvfc_npiv_logout_mad {
  138. struct ibmvfc_mad_common common;
  139. } __packed __aligned(8);
  140. #define IBMVFC_MAX_NAME 256
  141. struct ibmvfc_npiv_login {
  142. __be32 ostype;
  143. #define IBMVFC_OS_LINUX 0x02
  144. __be32 pad;
  145. __be64 max_dma_len;
  146. __be32 max_payload;
  147. __be32 max_response;
  148. __be32 partition_num;
  149. __be32 vfc_frame_version;
  150. __be16 fcp_version;
  151. __be16 flags;
  152. #define IBMVFC_CLIENT_MIGRATED 0x01
  153. #define IBMVFC_FLUSH_ON_HALT 0x02
  154. __be32 max_cmds;
  155. __be64 capabilities;
  156. #define IBMVFC_CAN_MIGRATE 0x01
  157. #define IBMVFC_CAN_USE_CHANNELS 0x02
  158. #define IBMVFC_CAN_HANDLE_FPIN 0x04
  159. #define IBMVFC_CAN_USE_MAD_VERSION 0x08
  160. #define IBMVFC_CAN_SEND_VF_WWPN 0x10
  161. __be64 node_name;
  162. struct srp_direct_buf async;
  163. u8 partition_name[IBMVFC_MAX_NAME];
  164. u8 device_name[IBMVFC_MAX_NAME];
  165. u8 drc_name[IBMVFC_MAX_NAME];
  166. __be64 reserved2[2];
  167. } __packed __aligned(8);
  168. struct ibmvfc_common_svc_parms {
  169. __be16 fcph_version;
  170. __be16 b2b_credit;
  171. __be16 features;
  172. __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
  173. __be32 ratov;
  174. __be32 edtov;
  175. } __packed __aligned(4);
  176. struct ibmvfc_service_parms {
  177. struct ibmvfc_common_svc_parms common;
  178. u8 port_name[8];
  179. u8 node_name[8];
  180. __be32 class1_parms[4];
  181. __be32 class2_parms[4];
  182. __be32 class3_parms[4];
  183. __be32 obsolete[4];
  184. __be32 vendor_version[4];
  185. __be32 services_avail[2];
  186. __be32 ext_len;
  187. __be32 reserved[30];
  188. __be32 clk_sync_qos[2];
  189. __be32 reserved2;
  190. } __packed __aligned(4);
  191. struct ibmvfc_npiv_login_resp {
  192. __be32 version;
  193. __be16 status;
  194. __be16 error;
  195. __be32 flags;
  196. #define IBMVFC_NATIVE_FC 0x01
  197. __be32 reserved;
  198. __be64 capabilities;
  199. #define IBMVFC_CAN_FLUSH_ON_HALT 0x08
  200. #define IBMVFC_CAN_SUPPRESS_ABTS 0x10
  201. #define IBMVFC_MAD_VERSION_CAP 0x20
  202. #define IBMVFC_HANDLE_VF_WWPN 0x40
  203. #define IBMVFC_CAN_SUPPORT_CHANNELS 0x80
  204. __be32 max_cmds;
  205. __be32 scsi_id_sz;
  206. __be64 max_dma_len;
  207. __be64 scsi_id;
  208. __be64 port_name;
  209. __be64 node_name;
  210. __be64 link_speed;
  211. u8 partition_name[IBMVFC_MAX_NAME];
  212. u8 device_name[IBMVFC_MAX_NAME];
  213. u8 port_loc_code[IBMVFC_MAX_NAME];
  214. u8 drc_name[IBMVFC_MAX_NAME];
  215. struct ibmvfc_service_parms service_parms;
  216. __be64 reserved2;
  217. } __packed __aligned(8);
  218. union ibmvfc_npiv_login_data {
  219. struct ibmvfc_npiv_login login;
  220. struct ibmvfc_npiv_login_resp resp;
  221. } __packed __aligned(8);
  222. struct ibmvfc_discover_targets_entry {
  223. __be32 scsi_id;
  224. __be32 pad;
  225. __be64 wwpn;
  226. #define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
  227. } __packed __aligned(8);
  228. struct ibmvfc_discover_targets {
  229. struct ibmvfc_mad_common common;
  230. struct srp_direct_buf buffer;
  231. __be32 flags;
  232. #define IBMVFC_DISC_TGT_PORT_ID_WWPN_LIST 0x02
  233. __be16 status;
  234. __be16 error;
  235. __be32 bufflen;
  236. __be32 num_avail;
  237. __be32 num_written;
  238. __be64 reserved[2];
  239. } __packed __aligned(8);
  240. enum ibmvfc_fc_reason {
  241. IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
  242. IBMVFC_INVALID_VERSION = 0x02,
  243. IBMVFC_LOGICAL_ERROR = 0x03,
  244. IBMVFC_INVALID_CT_IU_SIZE = 0x04,
  245. IBMVFC_LOGICAL_BUSY = 0x05,
  246. IBMVFC_PROTOCOL_ERROR = 0x07,
  247. IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
  248. IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
  249. IBMVFC_SERVER_NOT_AVAIL = 0x0D,
  250. IBMVFC_CMD_IN_PROGRESS = 0x0E,
  251. IBMVFC_VENDOR_SPECIFIC = 0xFF,
  252. };
  253. enum ibmvfc_fc_type {
  254. IBMVFC_FABRIC_REJECT = 0x01,
  255. IBMVFC_PORT_REJECT = 0x02,
  256. IBMVFC_LS_REJECT = 0x03,
  257. IBMVFC_FABRIC_BUSY = 0x04,
  258. IBMVFC_PORT_BUSY = 0x05,
  259. IBMVFC_BASIC_REJECT = 0x06,
  260. };
  261. enum ibmvfc_gs_explain {
  262. IBMVFC_PORT_NAME_NOT_REG = 0x02,
  263. };
  264. struct ibmvfc_port_login {
  265. struct ibmvfc_mad_common common;
  266. __be64 scsi_id;
  267. __be16 reserved;
  268. __be16 fc_service_class;
  269. __be32 blksz;
  270. __be32 hdr_per_blk;
  271. __be16 status;
  272. __be16 error; /* also fc_reason */
  273. __be16 fc_explain;
  274. __be16 fc_type;
  275. __be32 reserved2;
  276. struct ibmvfc_service_parms service_parms;
  277. struct ibmvfc_service_parms service_parms_change;
  278. __be64 target_wwpn;
  279. __be64 reserved3[2];
  280. } __packed __aligned(8);
  281. struct ibmvfc_move_login {
  282. struct ibmvfc_mad_common common;
  283. __be64 old_scsi_id;
  284. __be64 new_scsi_id;
  285. __be64 wwpn;
  286. __be64 node_name;
  287. __be32 flags;
  288. #define IBMVFC_MOVE_LOGIN_IMPLICIT_OLD_FAILED 0x01
  289. #define IBMVFC_MOVE_LOGIN_IMPLICIT_NEW_FAILED 0x02
  290. #define IBMVFC_MOVE_LOGIN_PORT_LOGIN_FAILED 0x04
  291. __be32 reserved;
  292. struct ibmvfc_service_parms service_parms;
  293. struct ibmvfc_service_parms service_parms_change;
  294. __be32 reserved2;
  295. __be16 service_class;
  296. __be16 vios_flags;
  297. #define IBMVFC_MOVE_LOGIN_VF_NOT_SENT_ADAPTER 0x01
  298. __be64 reserved3;
  299. } __packed __aligned(8);
  300. struct ibmvfc_prli_svc_parms {
  301. u8 type;
  302. #define IBMVFC_SCSI_FCP_TYPE 0x08
  303. u8 type_ext;
  304. __be16 flags;
  305. #define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
  306. #define IBMVFC_PRLI_RESP_PA_VALID 0x4000
  307. #define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
  308. __be32 orig_pa;
  309. __be32 resp_pa;
  310. __be32 service_parms;
  311. #define IBMVFC_PRLI_TASK_RETRY 0x00000200
  312. #define IBMVFC_PRLI_RETRY 0x00000100
  313. #define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
  314. #define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
  315. #define IBMVFC_PRLI_TARGET_FUNC 0x00000010
  316. #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
  317. #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
  318. } __packed __aligned(4);
  319. struct ibmvfc_process_login {
  320. struct ibmvfc_mad_common common;
  321. __be64 scsi_id;
  322. struct ibmvfc_prli_svc_parms parms;
  323. u8 reserved[48];
  324. __be16 status;
  325. __be16 error; /* also fc_reason */
  326. __be32 reserved2;
  327. __be64 target_wwpn;
  328. __be64 reserved3[2];
  329. } __packed __aligned(8);
  330. struct ibmvfc_query_tgt {
  331. struct ibmvfc_mad_common common;
  332. __be64 wwpn;
  333. __be64 scsi_id;
  334. __be16 status;
  335. __be16 error;
  336. __be16 fc_explain;
  337. __be16 fc_type;
  338. __be64 reserved[2];
  339. } __packed __aligned(8);
  340. struct ibmvfc_implicit_logout {
  341. struct ibmvfc_mad_common common;
  342. __be64 old_scsi_id;
  343. __be64 reserved[2];
  344. } __packed __aligned(8);
  345. struct ibmvfc_tmf {
  346. struct ibmvfc_mad_common common;
  347. __be64 scsi_id;
  348. struct scsi_lun lun;
  349. __be32 flags;
  350. #define IBMVFC_TMF_ABORT_TASK 0x02
  351. #define IBMVFC_TMF_ABORT_TASK_SET 0x04
  352. #define IBMVFC_TMF_LUN_RESET 0x10
  353. #define IBMVFC_TMF_TGT_RESET 0x20
  354. #define IBMVFC_TMF_LUA_VALID 0x40
  355. #define IBMVFC_TMF_SUPPRESS_ABTS 0x80
  356. __be32 cancel_key;
  357. __be32 my_cancel_key;
  358. __be32 pad;
  359. __be64 target_wwpn;
  360. __be64 task_tag;
  361. __be64 reserved[2];
  362. } __packed __aligned(8);
  363. enum ibmvfc_fcp_rsp_info_codes {
  364. RSP_NO_FAILURE = 0x00,
  365. RSP_TMF_REJECTED = 0x04,
  366. RSP_TMF_FAILED = 0x05,
  367. RSP_TMF_INVALID_LUN = 0x09,
  368. };
  369. struct ibmvfc_fcp_rsp_info {
  370. u8 reserved[3];
  371. u8 rsp_code;
  372. u8 reserved2[4];
  373. } __packed __aligned(2);
  374. enum ibmvfc_fcp_rsp_flags {
  375. FCP_BIDI_RSP = 0x80,
  376. FCP_BIDI_READ_RESID_UNDER = 0x40,
  377. FCP_BIDI_READ_RESID_OVER = 0x20,
  378. FCP_CONF_REQ = 0x10,
  379. FCP_RESID_UNDER = 0x08,
  380. FCP_RESID_OVER = 0x04,
  381. FCP_SNS_LEN_VALID = 0x02,
  382. FCP_RSP_LEN_VALID = 0x01,
  383. };
  384. union ibmvfc_fcp_rsp_data {
  385. struct ibmvfc_fcp_rsp_info info;
  386. u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
  387. } __packed __aligned(8);
  388. struct ibmvfc_fcp_rsp {
  389. __be64 reserved;
  390. __be16 retry_delay_timer;
  391. u8 flags;
  392. u8 scsi_status;
  393. __be32 fcp_resid;
  394. __be32 fcp_sense_len;
  395. __be32 fcp_rsp_len;
  396. union ibmvfc_fcp_rsp_data data;
  397. } __packed __aligned(8);
  398. enum ibmvfc_cmd_flags {
  399. IBMVFC_SCATTERLIST = 0x0001,
  400. IBMVFC_NO_MEM_DESC = 0x0002,
  401. IBMVFC_READ = 0x0004,
  402. IBMVFC_WRITE = 0x0008,
  403. IBMVFC_TMF = 0x0080,
  404. IBMVFC_CLASS_3_ERR = 0x0100,
  405. };
  406. enum ibmvfc_fc_task_attr {
  407. IBMVFC_SIMPLE_TASK = 0x00,
  408. IBMVFC_HEAD_OF_QUEUE = 0x01,
  409. IBMVFC_ORDERED_TASK = 0x02,
  410. IBMVFC_ACA_TASK = 0x04,
  411. };
  412. enum ibmvfc_fc_tmf_flags {
  413. IBMVFC_ABORT_TASK_SET = 0x02,
  414. IBMVFC_LUN_RESET = 0x10,
  415. IBMVFC_TARGET_RESET = 0x20,
  416. };
  417. struct ibmvfc_fcp_cmd_iu {
  418. struct scsi_lun lun;
  419. u8 crn;
  420. u8 pri_task_attr;
  421. u8 tmf_flags;
  422. u8 add_cdb_len;
  423. #define IBMVFC_RDDATA 0x02
  424. #define IBMVFC_WRDATA 0x01
  425. u8 cdb[IBMVFC_MAX_CDB_LEN];
  426. __be32 xfer_len;
  427. } __packed __aligned(4);
  428. struct ibmvfc_cmd {
  429. __be64 task_tag;
  430. __be32 frame_type;
  431. __be32 payload_len;
  432. __be32 resp_len;
  433. __be32 adapter_resid;
  434. __be16 status;
  435. __be16 error;
  436. __be16 flags;
  437. __be16 response_flags;
  438. #define IBMVFC_ADAPTER_RESID_VALID 0x01
  439. __be32 cancel_key;
  440. __be32 exchange_id;
  441. struct srp_direct_buf ext_func;
  442. struct srp_direct_buf ioba;
  443. struct srp_direct_buf resp;
  444. __be64 correlation;
  445. __be64 tgt_scsi_id;
  446. __be64 tag;
  447. __be64 target_wwpn;
  448. __be64 reserved3;
  449. union {
  450. struct {
  451. struct ibmvfc_fcp_cmd_iu iu;
  452. struct ibmvfc_fcp_rsp rsp;
  453. } v1;
  454. struct {
  455. __be64 reserved4;
  456. struct ibmvfc_fcp_cmd_iu iu;
  457. struct ibmvfc_fcp_rsp rsp;
  458. } v2;
  459. };
  460. } __packed __aligned(8);
  461. struct ibmvfc_passthru_fc_iu {
  462. __be32 payload[7];
  463. #define IBMVFC_ADISC 0x52000000
  464. __be32 response[7];
  465. };
  466. struct ibmvfc_passthru_iu {
  467. __be64 task_tag;
  468. __be32 cmd_len;
  469. __be32 rsp_len;
  470. __be16 status;
  471. __be16 error;
  472. __be32 flags;
  473. #define IBMVFC_FC_ELS 0x01
  474. #define IBMVFC_FC_CT_IU 0x02
  475. __be32 cancel_key;
  476. #define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
  477. #define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
  478. __be32 reserved;
  479. struct srp_direct_buf cmd;
  480. struct srp_direct_buf rsp;
  481. __be64 correlation;
  482. __be64 scsi_id;
  483. __be64 tag;
  484. __be64 target_wwpn;
  485. __be64 reserved2[2];
  486. } __packed __aligned(8);
  487. struct ibmvfc_passthru_mad {
  488. struct ibmvfc_mad_common common;
  489. struct srp_direct_buf cmd_ioba;
  490. struct ibmvfc_passthru_iu iu;
  491. struct ibmvfc_passthru_fc_iu fc_iu;
  492. } __packed __aligned(8);
  493. struct ibmvfc_channel_enquiry {
  494. struct ibmvfc_mad_common common;
  495. __be32 flags;
  496. #define IBMVFC_NO_CHANNELS_TO_CRQ_SUPPORT 0x01
  497. #define IBMVFC_SUPPORT_VARIABLE_SUBQ_MSG 0x02
  498. #define IBMVFC_NO_N_TO_M_CHANNELS_SUPPORT 0x04
  499. __be32 num_scsi_subq_channels;
  500. __be32 num_nvmeof_subq_channels;
  501. __be32 num_scsi_vas_channels;
  502. __be32 num_nvmeof_vas_channels;
  503. } __packed __aligned(8);
  504. struct ibmvfc_channel_setup_mad {
  505. struct ibmvfc_mad_common common;
  506. struct srp_direct_buf buffer;
  507. } __packed __aligned(8);
  508. #define IBMVFC_MAX_CHANNELS 502
  509. struct ibmvfc_channel_setup {
  510. __be32 flags;
  511. #define IBMVFC_CANCEL_CHANNELS 0x01
  512. #define IBMVFC_USE_BUFFER 0x02
  513. #define IBMVFC_CHANNELS_CANCELED 0x04
  514. __be32 reserved;
  515. __be32 num_scsi_subq_channels;
  516. __be32 num_nvmeof_subq_channels;
  517. __be32 num_scsi_vas_channels;
  518. __be32 num_nvmeof_vas_channels;
  519. struct srp_direct_buf buffer;
  520. __be64 reserved2[5];
  521. __be64 channel_handles[IBMVFC_MAX_CHANNELS];
  522. } __packed __aligned(8);
  523. struct ibmvfc_connection_info {
  524. struct ibmvfc_mad_common common;
  525. __be64 information_bits;
  526. #define IBMVFC_NO_FC_IO_CHANNEL 0x01
  527. #define IBMVFC_NO_PHYP_VAS 0x02
  528. #define IBMVFC_NO_PHYP_SUBQ 0x04
  529. #define IBMVFC_PHYP_DEPRECATED_SUBQ 0x08
  530. #define IBMVFC_PHYP_PRESERVED_SUBQ 0x10
  531. #define IBMVFC_PHYP_FULL_SUBQ 0x20
  532. __be64 reserved[16];
  533. } __packed __aligned(8);
  534. struct ibmvfc_trace_start_entry {
  535. u32 xfer_len;
  536. } __packed;
  537. struct ibmvfc_trace_end_entry {
  538. u16 status;
  539. u16 error;
  540. u8 fcp_rsp_flags;
  541. u8 rsp_code;
  542. u8 scsi_status;
  543. u8 reserved;
  544. } __packed;
  545. struct ibmvfc_trace_entry {
  546. struct ibmvfc_event *evt;
  547. u32 time;
  548. u32 scsi_id;
  549. u32 lun;
  550. u8 fmt;
  551. u8 op_code;
  552. u8 tmf_flags;
  553. u8 type;
  554. #define IBMVFC_TRC_START 0x00
  555. #define IBMVFC_TRC_END 0xff
  556. union {
  557. struct ibmvfc_trace_start_entry start;
  558. struct ibmvfc_trace_end_entry end;
  559. } u;
  560. } __packed __aligned(8);
  561. enum ibmvfc_crq_formats {
  562. IBMVFC_CMD_FORMAT = 0x01,
  563. IBMVFC_ASYNC_EVENT = 0x02,
  564. IBMVFC_MAD_FORMAT = 0x04,
  565. };
  566. enum ibmvfc_async_event {
  567. IBMVFC_AE_ELS_PLOGI = 0x0001,
  568. IBMVFC_AE_ELS_LOGO = 0x0002,
  569. IBMVFC_AE_ELS_PRLO = 0x0004,
  570. IBMVFC_AE_SCN_NPORT = 0x0008,
  571. IBMVFC_AE_SCN_GROUP = 0x0010,
  572. IBMVFC_AE_SCN_DOMAIN = 0x0020,
  573. IBMVFC_AE_SCN_FABRIC = 0x0040,
  574. IBMVFC_AE_LINK_UP = 0x0080,
  575. IBMVFC_AE_LINK_DOWN = 0x0100,
  576. IBMVFC_AE_LINK_DEAD = 0x0200,
  577. IBMVFC_AE_HALT = 0x0400,
  578. IBMVFC_AE_RESUME = 0x0800,
  579. IBMVFC_AE_ADAPTER_FAILED = 0x1000,
  580. IBMVFC_AE_FPIN = 0x2000,
  581. };
  582. struct ibmvfc_async_desc {
  583. const char *desc;
  584. enum ibmvfc_async_event ae;
  585. int log_level;
  586. };
  587. struct ibmvfc_crq {
  588. volatile u8 valid;
  589. volatile u8 format;
  590. u8 reserved[6];
  591. volatile __be64 ioba;
  592. } __packed __aligned(8);
  593. struct ibmvfc_sub_crq {
  594. struct ibmvfc_crq crq;
  595. __be64 reserved[2];
  596. } __packed __aligned(8);
  597. enum ibmvfc_ae_link_state {
  598. IBMVFC_AE_LS_LINK_UP = 0x01,
  599. IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
  600. IBMVFC_AE_LS_LINK_DOWN = 0x04,
  601. IBMVFC_AE_LS_LINK_DEAD = 0x08,
  602. };
  603. enum ibmvfc_ae_fpin_status {
  604. IBMVFC_AE_FPIN_LINK_CONGESTED = 0x1,
  605. IBMVFC_AE_FPIN_PORT_CONGESTED = 0x2,
  606. IBMVFC_AE_FPIN_PORT_CLEARED = 0x3,
  607. IBMVFC_AE_FPIN_PORT_DEGRADED = 0x4,
  608. };
  609. struct ibmvfc_async_crq {
  610. volatile u8 valid;
  611. u8 link_state;
  612. u8 fpin_status;
  613. u8 pad;
  614. __be32 pad2;
  615. volatile __be64 event;
  616. volatile __be64 scsi_id;
  617. volatile __be64 wwpn;
  618. volatile __be64 node_name;
  619. __be64 reserved;
  620. } __packed __aligned(8);
  621. union ibmvfc_iu {
  622. struct ibmvfc_mad_common mad_common;
  623. struct ibmvfc_npiv_login_mad npiv_login;
  624. struct ibmvfc_npiv_logout_mad npiv_logout;
  625. struct ibmvfc_discover_targets discover_targets;
  626. struct ibmvfc_port_login plogi;
  627. struct ibmvfc_process_login prli;
  628. struct ibmvfc_move_login move_login;
  629. struct ibmvfc_query_tgt query_tgt;
  630. struct ibmvfc_implicit_logout implicit_logout;
  631. struct ibmvfc_tmf tmf;
  632. struct ibmvfc_cmd cmd;
  633. struct ibmvfc_passthru_mad passthru;
  634. struct ibmvfc_channel_enquiry channel_enquiry;
  635. struct ibmvfc_channel_setup_mad channel_setup;
  636. struct ibmvfc_connection_info connection_info;
  637. } __packed __aligned(8);
  638. enum ibmvfc_target_action {
  639. IBMVFC_TGT_ACTION_NONE = 0,
  640. IBMVFC_TGT_ACTION_INIT,
  641. IBMVFC_TGT_ACTION_INIT_WAIT,
  642. IBMVFC_TGT_ACTION_LOGOUT_RPORT,
  643. IBMVFC_TGT_ACTION_LOGOUT_RPORT_WAIT,
  644. IBMVFC_TGT_ACTION_DEL_RPORT,
  645. IBMVFC_TGT_ACTION_DELETED_RPORT,
  646. IBMVFC_TGT_ACTION_DEL_AND_LOGOUT_RPORT,
  647. IBMVFC_TGT_ACTION_LOGOUT_DELETED_RPORT,
  648. };
  649. struct ibmvfc_target {
  650. struct list_head queue;
  651. struct ibmvfc_host *vhost;
  652. u64 scsi_id;
  653. u64 wwpn;
  654. u64 new_scsi_id;
  655. struct fc_rport *rport;
  656. int target_id;
  657. enum ibmvfc_target_action action;
  658. int need_login;
  659. int add_rport;
  660. int init_retries;
  661. int logo_rcvd;
  662. int move_login;
  663. u32 cancel_key;
  664. struct ibmvfc_service_parms service_parms;
  665. struct ibmvfc_service_parms service_parms_change;
  666. struct fc_rport_identifiers ids;
  667. void (*job_step) (struct ibmvfc_target *);
  668. struct timer_list timer;
  669. struct kref kref;
  670. };
  671. /* a unit of work for the hosting partition */
  672. struct ibmvfc_event {
  673. struct list_head queue_list;
  674. struct list_head cancel;
  675. struct ibmvfc_host *vhost;
  676. struct ibmvfc_queue *queue;
  677. struct ibmvfc_target *tgt;
  678. struct scsi_cmnd *cmnd;
  679. atomic_t free;
  680. atomic_t active;
  681. union ibmvfc_iu *xfer_iu;
  682. void (*done)(struct ibmvfc_event *evt);
  683. void (*_done)(struct ibmvfc_event *evt);
  684. struct ibmvfc_crq crq;
  685. union ibmvfc_iu iu;
  686. union ibmvfc_iu *sync_iu;
  687. struct srp_direct_buf *ext_list;
  688. dma_addr_t ext_list_token;
  689. struct completion comp;
  690. struct completion *eh_comp;
  691. struct timer_list timer;
  692. u16 hwq;
  693. };
  694. /* a pool of event structs for use */
  695. struct ibmvfc_event_pool {
  696. struct ibmvfc_event *events;
  697. u32 size;
  698. union ibmvfc_iu *iu_storage;
  699. dma_addr_t iu_token;
  700. };
  701. enum ibmvfc_msg_fmt {
  702. IBMVFC_CRQ_FMT = 0,
  703. IBMVFC_ASYNC_FMT,
  704. IBMVFC_SUB_CRQ_FMT,
  705. };
  706. union ibmvfc_msgs {
  707. void *handle;
  708. struct ibmvfc_crq *crq;
  709. struct ibmvfc_async_crq *async;
  710. struct ibmvfc_sub_crq *scrq;
  711. };
  712. struct ibmvfc_queue {
  713. union ibmvfc_msgs msgs;
  714. dma_addr_t msg_token;
  715. enum ibmvfc_msg_fmt fmt;
  716. int size, cur;
  717. spinlock_t _lock;
  718. spinlock_t *q_lock;
  719. struct ibmvfc_host *vhost;
  720. struct ibmvfc_event_pool evt_pool;
  721. struct list_head sent;
  722. struct list_head free;
  723. spinlock_t l_lock;
  724. union ibmvfc_iu cancel_rsp;
  725. /* Sub-CRQ fields */
  726. unsigned long cookie;
  727. unsigned long vios_cookie;
  728. unsigned long hw_irq;
  729. unsigned long irq;
  730. unsigned long hwq_id;
  731. char name[32];
  732. };
  733. struct ibmvfc_scsi_channels {
  734. struct ibmvfc_queue *scrqs;
  735. unsigned int active_queues;
  736. };
  737. enum ibmvfc_host_action {
  738. IBMVFC_HOST_ACTION_NONE = 0,
  739. IBMVFC_HOST_ACTION_RESET,
  740. IBMVFC_HOST_ACTION_REENABLE,
  741. IBMVFC_HOST_ACTION_LOGO,
  742. IBMVFC_HOST_ACTION_LOGO_WAIT,
  743. IBMVFC_HOST_ACTION_INIT,
  744. IBMVFC_HOST_ACTION_INIT_WAIT,
  745. IBMVFC_HOST_ACTION_QUERY,
  746. IBMVFC_HOST_ACTION_QUERY_TGTS,
  747. IBMVFC_HOST_ACTION_TGT_DEL,
  748. IBMVFC_HOST_ACTION_ALLOC_TGTS,
  749. IBMVFC_HOST_ACTION_TGT_INIT,
  750. IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
  751. };
  752. enum ibmvfc_host_state {
  753. IBMVFC_NO_CRQ = 0,
  754. IBMVFC_INITIALIZING,
  755. IBMVFC_ACTIVE,
  756. IBMVFC_HALTED,
  757. IBMVFC_LINK_DOWN,
  758. IBMVFC_LINK_DEAD,
  759. IBMVFC_HOST_OFFLINE,
  760. };
  761. struct ibmvfc_host {
  762. char name[8];
  763. struct list_head queue;
  764. struct Scsi_Host *host;
  765. enum ibmvfc_host_state state;
  766. enum ibmvfc_host_action action;
  767. #define IBMVFC_NUM_TRACE_INDEX_BITS 8
  768. #define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
  769. #define IBMVFC_TRACE_INDEX_MASK (IBMVFC_NUM_TRACE_ENTRIES - 1)
  770. #define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
  771. struct ibmvfc_trace_entry *trace;
  772. atomic_t trace_index;
  773. int num_targets;
  774. struct list_head targets;
  775. struct list_head purge;
  776. struct device *dev;
  777. struct dma_pool *sg_pool;
  778. mempool_t *tgt_pool;
  779. struct ibmvfc_queue crq;
  780. struct ibmvfc_queue async_crq;
  781. struct ibmvfc_scsi_channels scsi_scrqs;
  782. struct ibmvfc_npiv_login login_info;
  783. union ibmvfc_npiv_login_data *login_buf;
  784. dma_addr_t login_buf_dma;
  785. struct ibmvfc_channel_setup *channel_setup_buf;
  786. dma_addr_t channel_setup_dma;
  787. int disc_buf_sz;
  788. int log_level;
  789. struct ibmvfc_discover_targets_entry *disc_buf;
  790. struct mutex passthru_mutex;
  791. int max_vios_scsi_channels;
  792. int task_set;
  793. int init_retries;
  794. int discovery_threads;
  795. int abort_threads;
  796. int client_migrated;
  797. int reinit;
  798. int delay_init;
  799. int scan_complete;
  800. int scan_timeout;
  801. int logged_in;
  802. int mq_enabled;
  803. int using_channels;
  804. int do_enquiry;
  805. int client_scsi_channels;
  806. int aborting_passthru;
  807. int events_to_log;
  808. #define IBMVFC_AE_LINKUP 0x0001
  809. #define IBMVFC_AE_LINKDOWN 0x0002
  810. #define IBMVFC_AE_RSCN 0x0004
  811. dma_addr_t disc_buf_dma;
  812. unsigned int partition_number;
  813. char partition_name[97];
  814. void (*job_step) (struct ibmvfc_host *);
  815. struct task_struct *work_thread;
  816. struct tasklet_struct tasklet;
  817. struct work_struct rport_add_work_q;
  818. wait_queue_head_t init_wait_q;
  819. wait_queue_head_t work_wait_q;
  820. };
  821. #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
  822. #define tgt_dbg(t, fmt, ...) \
  823. DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
  824. #define tgt_info(t, fmt, ...) \
  825. dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  826. #define tgt_err(t, fmt, ...) \
  827. dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  828. #define tgt_log(t, level, fmt, ...) \
  829. do { \
  830. if ((t)->vhost->log_level >= level) \
  831. tgt_err(t, fmt, ##__VA_ARGS__); \
  832. } while (0)
  833. #define ibmvfc_dbg(vhost, ...) \
  834. DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
  835. #define ibmvfc_log(vhost, level, ...) \
  836. do { \
  837. if ((vhost)->log_level >= level) \
  838. dev_err((vhost)->dev, ##__VA_ARGS__); \
  839. } while (0)
  840. #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
  841. #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
  842. #ifdef CONFIG_SCSI_IBMVFC_TRACE
  843. #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
  844. #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
  845. #else
  846. #define ibmvfc_create_trace_file(kobj, attr) 0
  847. #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
  848. #endif
  849. #endif