ibmvfc.h 19 KB

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