ibmvfc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
  3. *
  4. * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) IBM Corporation, 2008
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #ifndef _IBMVFC_H
  24. #define _IBMVFC_H
  25. #include <linux/list.h>
  26. #include <linux/types.h>
  27. #include <scsi/viosrp.h>
  28. #define IBMVFC_NAME "ibmvfc"
  29. #define IBMVFC_DRIVER_VERSION "1.0.11"
  30. #define IBMVFC_DRIVER_DATE "(April 12, 2013)"
  31. #define IBMVFC_DEFAULT_TIMEOUT 60
  32. #define IBMVFC_ADISC_CANCEL_TIMEOUT 45
  33. #define IBMVFC_ADISC_TIMEOUT 15
  34. #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
  35. (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
  36. #define IBMVFC_INIT_TIMEOUT 120
  37. #define IBMVFC_ABORT_TIMEOUT 8
  38. #define IBMVFC_ABORT_WAIT_TIMEOUT 40
  39. #define IBMVFC_MAX_REQUESTS_DEFAULT 100
  40. #define IBMVFC_DEBUG 0
  41. #define IBMVFC_MAX_TARGETS 1024
  42. #define IBMVFC_MAX_LUN 0xffffffff
  43. #define IBMVFC_MAX_SECTORS 0xffffu
  44. #define IBMVFC_MAX_DISC_THREADS 4
  45. #define IBMVFC_TGT_MEMPOOL_SZ 64
  46. #define IBMVFC_MAX_CMDS_PER_LUN 64
  47. #define IBMVFC_MAX_HOST_INIT_RETRIES 6
  48. #define IBMVFC_MAX_TGT_INIT_RETRIES 3
  49. #define IBMVFC_DEV_LOSS_TMO (5 * 60)
  50. #define IBMVFC_DEFAULT_LOG_LEVEL 2
  51. #define IBMVFC_MAX_CDB_LEN 16
  52. #define IBMVFC_CLS3_ERROR 0
  53. /*
  54. * Ensure we have resources for ERP and initialization:
  55. * 1 for ERP
  56. * 1 for initialization
  57. * 1 for NPIV Logout
  58. * 2 for BSG passthru
  59. * 2 for each discovery thread
  60. */
  61. #define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
  62. #define IBMVFC_MAD_SUCCESS 0x00
  63. #define IBMVFC_MAD_NOT_SUPPORTED 0xF1
  64. #define IBMVFC_MAD_FAILED 0xF7
  65. #define IBMVFC_MAD_DRIVER_FAILED 0xEE
  66. #define IBMVFC_MAD_CRQ_ERROR 0xEF
  67. enum ibmvfc_crq_valid {
  68. IBMVFC_CRQ_CMD_RSP = 0x80,
  69. IBMVFC_CRQ_INIT_RSP = 0xC0,
  70. IBMVFC_CRQ_XPORT_EVENT = 0xFF,
  71. };
  72. enum ibmvfc_crq_format {
  73. IBMVFC_CRQ_INIT = 0x01,
  74. IBMVFC_CRQ_INIT_COMPLETE = 0x02,
  75. IBMVFC_PARTITION_MIGRATED = 0x06,
  76. };
  77. enum ibmvfc_cmd_status_flags {
  78. IBMVFC_FABRIC_MAPPED = 0x0001,
  79. IBMVFC_VIOS_FAILURE = 0x0002,
  80. IBMVFC_FC_FAILURE = 0x0004,
  81. IBMVFC_FC_SCSI_ERROR = 0x0008,
  82. IBMVFC_HW_EVENT_LOGGED = 0x0010,
  83. IBMVFC_VIOS_LOGGED = 0x0020,
  84. };
  85. enum ibmvfc_fabric_mapped_errors {
  86. IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
  87. IBMVFC_XPORT_FAULT = 0x0002,
  88. IBMVFC_CMD_TIMEOUT = 0x0003,
  89. IBMVFC_ENETDOWN = 0x0004,
  90. IBMVFC_HW_FAILURE = 0x0005,
  91. IBMVFC_LINK_DOWN_ERR = 0x0006,
  92. IBMVFC_LINK_DEAD_ERR = 0x0007,
  93. IBMVFC_UNABLE_TO_REGISTER = 0x0008,
  94. IBMVFC_XPORT_BUSY = 0x000A,
  95. IBMVFC_XPORT_DEAD = 0x000B,
  96. IBMVFC_CONFIG_ERROR = 0x000C,
  97. IBMVFC_NAME_SERVER_FAIL = 0x000D,
  98. IBMVFC_LINK_HALTED = 0x000E,
  99. IBMVFC_XPORT_GENERAL = 0x8000,
  100. };
  101. enum ibmvfc_vios_errors {
  102. IBMVFC_CRQ_FAILURE = 0x0001,
  103. IBMVFC_SW_FAILURE = 0x0002,
  104. IBMVFC_INVALID_PARAMETER = 0x0003,
  105. IBMVFC_MISSING_PARAMETER = 0x0004,
  106. IBMVFC_HOST_IO_BUS = 0x0005,
  107. IBMVFC_TRANS_CANCELLED = 0x0006,
  108. IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
  109. IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
  110. IBMVFC_PLOGI_REQUIRED = 0x0010,
  111. IBMVFC_COMMAND_FAILED = 0x8000,
  112. };
  113. enum ibmvfc_mad_types {
  114. IBMVFC_NPIV_LOGIN = 0x0001,
  115. IBMVFC_DISC_TARGETS = 0x0002,
  116. IBMVFC_PORT_LOGIN = 0x0004,
  117. IBMVFC_PROCESS_LOGIN = 0x0008,
  118. IBMVFC_QUERY_TARGET = 0x0010,
  119. IBMVFC_IMPLICIT_LOGOUT = 0x0040,
  120. IBMVFC_PASSTHRU = 0x0200,
  121. IBMVFC_TMF_MAD = 0x0100,
  122. IBMVFC_NPIV_LOGOUT = 0x0800,
  123. };
  124. struct ibmvfc_mad_common {
  125. __be32 version;
  126. __be32 reserved;
  127. __be32 opcode;
  128. __be16 status;
  129. __be16 length;
  130. __be64 tag;
  131. }__attribute__((packed, aligned (8)));
  132. struct ibmvfc_npiv_login_mad {
  133. struct ibmvfc_mad_common common;
  134. struct srp_direct_buf buffer;
  135. }__attribute__((packed, aligned (8)));
  136. struct ibmvfc_npiv_logout_mad {
  137. struct ibmvfc_mad_common common;
  138. }__attribute__((packed, aligned (8)));
  139. #define IBMVFC_MAX_NAME 256
  140. struct ibmvfc_npiv_login {
  141. __be32 ostype;
  142. #define IBMVFC_OS_LINUX 0x02
  143. __be32 pad;
  144. __be64 max_dma_len;
  145. __be32 max_payload;
  146. __be32 max_response;
  147. __be32 partition_num;
  148. __be32 vfc_frame_version;
  149. __be16 fcp_version;
  150. __be16 flags;
  151. #define IBMVFC_CLIENT_MIGRATED 0x01
  152. #define IBMVFC_FLUSH_ON_HALT 0x02
  153. __be32 max_cmds;
  154. __be64 capabilities;
  155. #define IBMVFC_CAN_MIGRATE 0x01
  156. __be64 node_name;
  157. struct srp_direct_buf async;
  158. u8 partition_name[IBMVFC_MAX_NAME];
  159. u8 device_name[IBMVFC_MAX_NAME];
  160. u8 drc_name[IBMVFC_MAX_NAME];
  161. __be64 reserved2[2];
  162. }__attribute__((packed, aligned (8)));
  163. struct ibmvfc_common_svc_parms {
  164. __be16 fcph_version;
  165. __be16 b2b_credit;
  166. __be16 features;
  167. __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
  168. __be32 ratov;
  169. __be32 edtov;
  170. }__attribute__((packed, aligned (4)));
  171. struct ibmvfc_service_parms {
  172. struct ibmvfc_common_svc_parms common;
  173. u8 port_name[8];
  174. u8 node_name[8];
  175. __be32 class1_parms[4];
  176. __be32 class2_parms[4];
  177. __be32 class3_parms[4];
  178. __be32 obsolete[4];
  179. __be32 vendor_version[4];
  180. __be32 services_avail[2];
  181. __be32 ext_len;
  182. __be32 reserved[30];
  183. __be32 clk_sync_qos[2];
  184. }__attribute__((packed, aligned (4)));
  185. struct ibmvfc_npiv_login_resp {
  186. __be32 version;
  187. __be16 status;
  188. __be16 error;
  189. __be32 flags;
  190. #define IBMVFC_NATIVE_FC 0x01
  191. __be32 reserved;
  192. __be64 capabilities;
  193. #define IBMVFC_CAN_FLUSH_ON_HALT 0x08
  194. #define IBMVFC_CAN_SUPPRESS_ABTS 0x10
  195. __be32 max_cmds;
  196. __be32 scsi_id_sz;
  197. __be64 max_dma_len;
  198. __be64 scsi_id;
  199. __be64 port_name;
  200. __be64 node_name;
  201. __be64 link_speed;
  202. u8 partition_name[IBMVFC_MAX_NAME];
  203. u8 device_name[IBMVFC_MAX_NAME];
  204. u8 port_loc_code[IBMVFC_MAX_NAME];
  205. u8 drc_name[IBMVFC_MAX_NAME];
  206. struct ibmvfc_service_parms service_parms;
  207. __be64 reserved2;
  208. }__attribute__((packed, aligned (8)));
  209. union ibmvfc_npiv_login_data {
  210. struct ibmvfc_npiv_login login;
  211. struct ibmvfc_npiv_login_resp resp;
  212. }__attribute__((packed, aligned (8)));
  213. struct ibmvfc_discover_targets_buf {
  214. __be32 scsi_id[1];
  215. #define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
  216. };
  217. struct ibmvfc_discover_targets {
  218. struct ibmvfc_mad_common common;
  219. struct srp_direct_buf buffer;
  220. __be32 flags;
  221. __be16 status;
  222. __be16 error;
  223. __be32 bufflen;
  224. __be32 num_avail;
  225. __be32 num_written;
  226. __be64 reserved[2];
  227. }__attribute__((packed, aligned (8)));
  228. enum ibmvfc_fc_reason {
  229. IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
  230. IBMVFC_INVALID_VERSION = 0x02,
  231. IBMVFC_LOGICAL_ERROR = 0x03,
  232. IBMVFC_INVALID_CT_IU_SIZE = 0x04,
  233. IBMVFC_LOGICAL_BUSY = 0x05,
  234. IBMVFC_PROTOCOL_ERROR = 0x07,
  235. IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
  236. IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
  237. IBMVFC_SERVER_NOT_AVAIL = 0x0D,
  238. IBMVFC_CMD_IN_PROGRESS = 0x0E,
  239. IBMVFC_VENDOR_SPECIFIC = 0xFF,
  240. };
  241. enum ibmvfc_fc_type {
  242. IBMVFC_FABRIC_REJECT = 0x01,
  243. IBMVFC_PORT_REJECT = 0x02,
  244. IBMVFC_LS_REJECT = 0x03,
  245. IBMVFC_FABRIC_BUSY = 0x04,
  246. IBMVFC_PORT_BUSY = 0x05,
  247. IBMVFC_BASIC_REJECT = 0x06,
  248. };
  249. enum ibmvfc_gs_explain {
  250. IBMVFC_PORT_NAME_NOT_REG = 0x02,
  251. };
  252. struct ibmvfc_port_login {
  253. struct ibmvfc_mad_common common;
  254. __be64 scsi_id;
  255. __be16 reserved;
  256. __be16 fc_service_class;
  257. __be32 blksz;
  258. __be32 hdr_per_blk;
  259. __be16 status;
  260. __be16 error; /* also fc_reason */
  261. __be16 fc_explain;
  262. __be16 fc_type;
  263. __be32 reserved2;
  264. struct ibmvfc_service_parms service_parms;
  265. struct ibmvfc_service_parms service_parms_change;
  266. __be64 reserved3[2];
  267. }__attribute__((packed, aligned (8)));
  268. struct ibmvfc_prli_svc_parms {
  269. u8 type;
  270. #define IBMVFC_SCSI_FCP_TYPE 0x08
  271. u8 type_ext;
  272. __be16 flags;
  273. #define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
  274. #define IBMVFC_PRLI_RESP_PA_VALID 0x4000
  275. #define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
  276. __be32 orig_pa;
  277. __be32 resp_pa;
  278. __be32 service_parms;
  279. #define IBMVFC_PRLI_TASK_RETRY 0x00000200
  280. #define IBMVFC_PRLI_RETRY 0x00000100
  281. #define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
  282. #define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
  283. #define IBMVFC_PRLI_TARGET_FUNC 0x00000010
  284. #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
  285. #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
  286. }__attribute__((packed, aligned (4)));
  287. struct ibmvfc_process_login {
  288. struct ibmvfc_mad_common common;
  289. __be64 scsi_id;
  290. struct ibmvfc_prli_svc_parms parms;
  291. u8 reserved[48];
  292. __be16 status;
  293. __be16 error; /* also fc_reason */
  294. __be32 reserved2;
  295. __be64 reserved3[2];
  296. }__attribute__((packed, aligned (8)));
  297. struct ibmvfc_query_tgt {
  298. struct ibmvfc_mad_common common;
  299. __be64 wwpn;
  300. __be64 scsi_id;
  301. __be16 status;
  302. __be16 error;
  303. __be16 fc_explain;
  304. __be16 fc_type;
  305. __be64 reserved[2];
  306. }__attribute__((packed, aligned (8)));
  307. struct ibmvfc_implicit_logout {
  308. struct ibmvfc_mad_common common;
  309. __be64 old_scsi_id;
  310. __be64 reserved[2];
  311. }__attribute__((packed, aligned (8)));
  312. struct ibmvfc_tmf {
  313. struct ibmvfc_mad_common common;
  314. __be64 scsi_id;
  315. struct scsi_lun lun;
  316. __be32 flags;
  317. #define IBMVFC_TMF_ABORT_TASK 0x02
  318. #define IBMVFC_TMF_ABORT_TASK_SET 0x04
  319. #define IBMVFC_TMF_LUN_RESET 0x10
  320. #define IBMVFC_TMF_TGT_RESET 0x20
  321. #define IBMVFC_TMF_LUA_VALID 0x40
  322. #define IBMVFC_TMF_SUPPRESS_ABTS 0x80
  323. __be32 cancel_key;
  324. __be32 my_cancel_key;
  325. __be32 pad;
  326. __be64 reserved[2];
  327. }__attribute__((packed, aligned (8)));
  328. enum ibmvfc_fcp_rsp_info_codes {
  329. RSP_NO_FAILURE = 0x00,
  330. RSP_TMF_REJECTED = 0x04,
  331. RSP_TMF_FAILED = 0x05,
  332. RSP_TMF_INVALID_LUN = 0x09,
  333. };
  334. struct ibmvfc_fcp_rsp_info {
  335. u8 reserved[3];
  336. u8 rsp_code;
  337. u8 reserved2[4];
  338. }__attribute__((packed, aligned (2)));
  339. enum ibmvfc_fcp_rsp_flags {
  340. FCP_BIDI_RSP = 0x80,
  341. FCP_BIDI_READ_RESID_UNDER = 0x40,
  342. FCP_BIDI_READ_RESID_OVER = 0x20,
  343. FCP_CONF_REQ = 0x10,
  344. FCP_RESID_UNDER = 0x08,
  345. FCP_RESID_OVER = 0x04,
  346. FCP_SNS_LEN_VALID = 0x02,
  347. FCP_RSP_LEN_VALID = 0x01,
  348. };
  349. union ibmvfc_fcp_rsp_data {
  350. struct ibmvfc_fcp_rsp_info info;
  351. u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
  352. }__attribute__((packed, aligned (8)));
  353. struct ibmvfc_fcp_rsp {
  354. __be64 reserved;
  355. __be16 retry_delay_timer;
  356. u8 flags;
  357. u8 scsi_status;
  358. __be32 fcp_resid;
  359. __be32 fcp_sense_len;
  360. __be32 fcp_rsp_len;
  361. union ibmvfc_fcp_rsp_data data;
  362. }__attribute__((packed, aligned (8)));
  363. enum ibmvfc_cmd_flags {
  364. IBMVFC_SCATTERLIST = 0x0001,
  365. IBMVFC_NO_MEM_DESC = 0x0002,
  366. IBMVFC_READ = 0x0004,
  367. IBMVFC_WRITE = 0x0008,
  368. IBMVFC_TMF = 0x0080,
  369. IBMVFC_CLASS_3_ERR = 0x0100,
  370. };
  371. enum ibmvfc_fc_task_attr {
  372. IBMVFC_SIMPLE_TASK = 0x00,
  373. IBMVFC_HEAD_OF_QUEUE = 0x01,
  374. IBMVFC_ORDERED_TASK = 0x02,
  375. IBMVFC_ACA_TASK = 0x04,
  376. };
  377. enum ibmvfc_fc_tmf_flags {
  378. IBMVFC_ABORT_TASK_SET = 0x02,
  379. IBMVFC_LUN_RESET = 0x10,
  380. IBMVFC_TARGET_RESET = 0x20,
  381. };
  382. struct ibmvfc_fcp_cmd_iu {
  383. struct scsi_lun lun;
  384. u8 crn;
  385. u8 pri_task_attr;
  386. u8 tmf_flags;
  387. u8 add_cdb_len;
  388. #define IBMVFC_RDDATA 0x02
  389. #define IBMVFC_WRDATA 0x01
  390. u8 cdb[IBMVFC_MAX_CDB_LEN];
  391. __be32 xfer_len;
  392. }__attribute__((packed, aligned (4)));
  393. struct ibmvfc_cmd {
  394. __be64 task_tag;
  395. __be32 frame_type;
  396. __be32 payload_len;
  397. __be32 resp_len;
  398. __be32 adapter_resid;
  399. __be16 status;
  400. __be16 error;
  401. __be16 flags;
  402. __be16 response_flags;
  403. #define IBMVFC_ADAPTER_RESID_VALID 0x01
  404. __be32 cancel_key;
  405. __be32 exchange_id;
  406. struct srp_direct_buf ext_func;
  407. struct srp_direct_buf ioba;
  408. struct srp_direct_buf resp;
  409. __be64 correlation;
  410. __be64 tgt_scsi_id;
  411. __be64 tag;
  412. __be64 reserved3[2];
  413. struct ibmvfc_fcp_cmd_iu iu;
  414. struct ibmvfc_fcp_rsp rsp;
  415. }__attribute__((packed, aligned (8)));
  416. struct ibmvfc_passthru_fc_iu {
  417. __be32 payload[7];
  418. #define IBMVFC_ADISC 0x52000000
  419. __be32 response[7];
  420. };
  421. struct ibmvfc_passthru_iu {
  422. __be64 task_tag;
  423. __be32 cmd_len;
  424. __be32 rsp_len;
  425. __be16 status;
  426. __be16 error;
  427. __be32 flags;
  428. #define IBMVFC_FC_ELS 0x01
  429. #define IBMVFC_FC_CT_IU 0x02
  430. __be32 cancel_key;
  431. #define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
  432. #define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
  433. __be32 reserved;
  434. struct srp_direct_buf cmd;
  435. struct srp_direct_buf rsp;
  436. __be64 correlation;
  437. __be64 scsi_id;
  438. __be64 tag;
  439. __be64 reserved2[2];
  440. }__attribute__((packed, aligned (8)));
  441. struct ibmvfc_passthru_mad {
  442. struct ibmvfc_mad_common common;
  443. struct srp_direct_buf cmd_ioba;
  444. struct ibmvfc_passthru_iu iu;
  445. struct ibmvfc_passthru_fc_iu fc_iu;
  446. }__attribute__((packed, aligned (8)));
  447. struct ibmvfc_trace_start_entry {
  448. u32 xfer_len;
  449. }__attribute__((packed));
  450. struct ibmvfc_trace_end_entry {
  451. u16 status;
  452. u16 error;
  453. u8 fcp_rsp_flags;
  454. u8 rsp_code;
  455. u8 scsi_status;
  456. u8 reserved;
  457. }__attribute__((packed));
  458. struct ibmvfc_trace_entry {
  459. struct ibmvfc_event *evt;
  460. u32 time;
  461. u32 scsi_id;
  462. u32 lun;
  463. u8 fmt;
  464. u8 op_code;
  465. u8 tmf_flags;
  466. u8 type;
  467. #define IBMVFC_TRC_START 0x00
  468. #define IBMVFC_TRC_END 0xff
  469. union {
  470. struct ibmvfc_trace_start_entry start;
  471. struct ibmvfc_trace_end_entry end;
  472. } u;
  473. }__attribute__((packed, aligned (8)));
  474. enum ibmvfc_crq_formats {
  475. IBMVFC_CMD_FORMAT = 0x01,
  476. IBMVFC_ASYNC_EVENT = 0x02,
  477. IBMVFC_MAD_FORMAT = 0x04,
  478. };
  479. enum ibmvfc_async_event {
  480. IBMVFC_AE_ELS_PLOGI = 0x0001,
  481. IBMVFC_AE_ELS_LOGO = 0x0002,
  482. IBMVFC_AE_ELS_PRLO = 0x0004,
  483. IBMVFC_AE_SCN_NPORT = 0x0008,
  484. IBMVFC_AE_SCN_GROUP = 0x0010,
  485. IBMVFC_AE_SCN_DOMAIN = 0x0020,
  486. IBMVFC_AE_SCN_FABRIC = 0x0040,
  487. IBMVFC_AE_LINK_UP = 0x0080,
  488. IBMVFC_AE_LINK_DOWN = 0x0100,
  489. IBMVFC_AE_LINK_DEAD = 0x0200,
  490. IBMVFC_AE_HALT = 0x0400,
  491. IBMVFC_AE_RESUME = 0x0800,
  492. IBMVFC_AE_ADAPTER_FAILED = 0x1000,
  493. };
  494. struct ibmvfc_async_desc {
  495. const char *desc;
  496. enum ibmvfc_async_event ae;
  497. int log_level;
  498. };
  499. struct ibmvfc_crq {
  500. volatile u8 valid;
  501. volatile u8 format;
  502. u8 reserved[6];
  503. volatile __be64 ioba;
  504. }__attribute__((packed, aligned (8)));
  505. struct ibmvfc_crq_queue {
  506. struct ibmvfc_crq *msgs;
  507. int size, cur;
  508. dma_addr_t msg_token;
  509. };
  510. enum ibmvfc_ae_link_state {
  511. IBMVFC_AE_LS_LINK_UP = 0x01,
  512. IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
  513. IBMVFC_AE_LS_LINK_DOWN = 0x04,
  514. IBMVFC_AE_LS_LINK_DEAD = 0x08,
  515. };
  516. struct ibmvfc_async_crq {
  517. volatile u8 valid;
  518. u8 link_state;
  519. u8 pad[2];
  520. __be32 pad2;
  521. volatile __be64 event;
  522. volatile __be64 scsi_id;
  523. volatile __be64 wwpn;
  524. volatile __be64 node_name;
  525. __be64 reserved;
  526. }__attribute__((packed, aligned (8)));
  527. struct ibmvfc_async_crq_queue {
  528. struct ibmvfc_async_crq *msgs;
  529. int size, cur;
  530. dma_addr_t msg_token;
  531. };
  532. union ibmvfc_iu {
  533. struct ibmvfc_mad_common mad_common;
  534. struct ibmvfc_npiv_login_mad npiv_login;
  535. struct ibmvfc_npiv_logout_mad npiv_logout;
  536. struct ibmvfc_discover_targets discover_targets;
  537. struct ibmvfc_port_login plogi;
  538. struct ibmvfc_process_login prli;
  539. struct ibmvfc_query_tgt query_tgt;
  540. struct ibmvfc_implicit_logout implicit_logout;
  541. struct ibmvfc_tmf tmf;
  542. struct ibmvfc_cmd cmd;
  543. struct ibmvfc_passthru_mad passthru;
  544. }__attribute__((packed, aligned (8)));
  545. enum ibmvfc_target_action {
  546. IBMVFC_TGT_ACTION_NONE = 0,
  547. IBMVFC_TGT_ACTION_INIT,
  548. IBMVFC_TGT_ACTION_INIT_WAIT,
  549. IBMVFC_TGT_ACTION_DEL_RPORT,
  550. IBMVFC_TGT_ACTION_DELETED_RPORT,
  551. };
  552. struct ibmvfc_target {
  553. struct list_head queue;
  554. struct ibmvfc_host *vhost;
  555. u64 scsi_id;
  556. u64 new_scsi_id;
  557. struct fc_rport *rport;
  558. int target_id;
  559. enum ibmvfc_target_action action;
  560. int need_login;
  561. int add_rport;
  562. int init_retries;
  563. int logo_rcvd;
  564. u32 cancel_key;
  565. struct ibmvfc_service_parms service_parms;
  566. struct ibmvfc_service_parms service_parms_change;
  567. struct fc_rport_identifiers ids;
  568. void (*job_step) (struct ibmvfc_target *);
  569. struct timer_list timer;
  570. struct kref kref;
  571. };
  572. /* a unit of work for the hosting partition */
  573. struct ibmvfc_event {
  574. struct list_head queue;
  575. struct ibmvfc_host *vhost;
  576. struct ibmvfc_target *tgt;
  577. struct scsi_cmnd *cmnd;
  578. atomic_t free;
  579. union ibmvfc_iu *xfer_iu;
  580. void (*done) (struct ibmvfc_event *);
  581. struct ibmvfc_crq crq;
  582. union ibmvfc_iu iu;
  583. union ibmvfc_iu *sync_iu;
  584. struct srp_direct_buf *ext_list;
  585. dma_addr_t ext_list_token;
  586. struct completion comp;
  587. struct completion *eh_comp;
  588. struct timer_list timer;
  589. };
  590. /* a pool of event structs for use */
  591. struct ibmvfc_event_pool {
  592. struct ibmvfc_event *events;
  593. u32 size;
  594. union ibmvfc_iu *iu_storage;
  595. dma_addr_t iu_token;
  596. };
  597. enum ibmvfc_host_action {
  598. IBMVFC_HOST_ACTION_NONE = 0,
  599. IBMVFC_HOST_ACTION_RESET,
  600. IBMVFC_HOST_ACTION_REENABLE,
  601. IBMVFC_HOST_ACTION_LOGO,
  602. IBMVFC_HOST_ACTION_LOGO_WAIT,
  603. IBMVFC_HOST_ACTION_INIT,
  604. IBMVFC_HOST_ACTION_INIT_WAIT,
  605. IBMVFC_HOST_ACTION_QUERY,
  606. IBMVFC_HOST_ACTION_QUERY_TGTS,
  607. IBMVFC_HOST_ACTION_TGT_DEL,
  608. IBMVFC_HOST_ACTION_ALLOC_TGTS,
  609. IBMVFC_HOST_ACTION_TGT_INIT,
  610. IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
  611. };
  612. enum ibmvfc_host_state {
  613. IBMVFC_NO_CRQ = 0,
  614. IBMVFC_INITIALIZING,
  615. IBMVFC_ACTIVE,
  616. IBMVFC_HALTED,
  617. IBMVFC_LINK_DOWN,
  618. IBMVFC_LINK_DEAD,
  619. IBMVFC_HOST_OFFLINE,
  620. };
  621. struct ibmvfc_host {
  622. char name[8];
  623. struct list_head queue;
  624. struct Scsi_Host *host;
  625. enum ibmvfc_host_state state;
  626. enum ibmvfc_host_action action;
  627. #define IBMVFC_NUM_TRACE_INDEX_BITS 8
  628. #define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
  629. #define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
  630. struct ibmvfc_trace_entry *trace;
  631. u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
  632. int num_targets;
  633. struct list_head targets;
  634. struct list_head sent;
  635. struct list_head free;
  636. struct device *dev;
  637. struct ibmvfc_event_pool pool;
  638. struct dma_pool *sg_pool;
  639. mempool_t *tgt_pool;
  640. struct ibmvfc_crq_queue crq;
  641. struct ibmvfc_async_crq_queue async_crq;
  642. struct ibmvfc_npiv_login login_info;
  643. union ibmvfc_npiv_login_data *login_buf;
  644. dma_addr_t login_buf_dma;
  645. int disc_buf_sz;
  646. int log_level;
  647. struct ibmvfc_discover_targets_buf *disc_buf;
  648. struct mutex passthru_mutex;
  649. int task_set;
  650. int init_retries;
  651. int discovery_threads;
  652. int abort_threads;
  653. int client_migrated;
  654. int reinit;
  655. int delay_init;
  656. int scan_complete;
  657. int logged_in;
  658. int aborting_passthru;
  659. int events_to_log;
  660. #define IBMVFC_AE_LINKUP 0x0001
  661. #define IBMVFC_AE_LINKDOWN 0x0002
  662. #define IBMVFC_AE_RSCN 0x0004
  663. dma_addr_t disc_buf_dma;
  664. unsigned int partition_number;
  665. char partition_name[97];
  666. void (*job_step) (struct ibmvfc_host *);
  667. struct task_struct *work_thread;
  668. struct tasklet_struct tasklet;
  669. struct work_struct rport_add_work_q;
  670. wait_queue_head_t init_wait_q;
  671. wait_queue_head_t work_wait_q;
  672. };
  673. #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
  674. #define tgt_dbg(t, fmt, ...) \
  675. DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
  676. #define tgt_info(t, fmt, ...) \
  677. dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  678. #define tgt_err(t, fmt, ...) \
  679. dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  680. #define tgt_log(t, level, fmt, ...) \
  681. do { \
  682. if ((t)->vhost->log_level >= level) \
  683. tgt_err(t, fmt, ##__VA_ARGS__); \
  684. } while (0)
  685. #define ibmvfc_dbg(vhost, ...) \
  686. DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
  687. #define ibmvfc_log(vhost, level, ...) \
  688. do { \
  689. if ((vhost)->log_level >= level) \
  690. dev_err((vhost)->dev, ##__VA_ARGS__); \
  691. } while (0)
  692. #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
  693. #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
  694. #ifdef CONFIG_SCSI_IBMVFC_TRACE
  695. #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
  696. #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
  697. #else
  698. #define ibmvfc_create_trace_file(kobj, attr) 0
  699. #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
  700. #endif
  701. #endif