ibmvfc.h 19 KB

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