ibmvfc.h 18 KB

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