qla_target.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /*
  2. * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
  3. * Copyright (C) 2004 - 2005 Leonid Stoljar
  4. * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
  5. * Copyright (C) 2007 - 2010 ID7 Ltd.
  6. *
  7. * Forward port and refactoring to modern qla2xxx and target/configfs
  8. *
  9. * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org>
  10. *
  11. * Additional file for the target driver support.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. /*
  24. * This is the global def file that is useful for including from the
  25. * target portion.
  26. */
  27. #ifndef __QLA_TARGET_H
  28. #define __QLA_TARGET_H
  29. #include "qla_def.h"
  30. /*
  31. * Must be changed on any change in any initiator visible interfaces or
  32. * data in the target add-on
  33. */
  34. #define QLA2XXX_TARGET_MAGIC 269
  35. /*
  36. * Must be changed on any change in any target visible interfaces or
  37. * data in the initiator
  38. */
  39. #define QLA2XXX_INITIATOR_MAGIC 57222
  40. #define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive"
  41. #define QLA2XXX_INI_MODE_STR_DISABLED "disabled"
  42. #define QLA2XXX_INI_MODE_STR_ENABLED "enabled"
  43. #define QLA2XXX_INI_MODE_EXCLUSIVE 0
  44. #define QLA2XXX_INI_MODE_DISABLED 1
  45. #define QLA2XXX_INI_MODE_ENABLED 2
  46. #define QLA2XXX_COMMAND_COUNT_INIT 250
  47. #define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
  48. /*
  49. * Used to mark which completion handles (for RIO Status's) are for CTIO's
  50. * vs. regular (non-target) info. This is checked for in
  51. * qla2x00_process_response_queue() to see if a handle coming back in a
  52. * multi-complete should come to the tgt driver or be handled there by qla2xxx
  53. */
  54. #define CTIO_COMPLETION_HANDLE_MARK BIT_29
  55. #if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
  56. #error "CTIO_COMPLETION_HANDLE_MARK not larger than "
  57. "DEFAULT_OUTSTANDING_COMMANDS"
  58. #endif
  59. #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
  60. /* Used to mark CTIO as intermediate */
  61. #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
  62. #ifndef OF_SS_MODE_0
  63. /*
  64. * ISP target entries - Flags bit definitions.
  65. */
  66. #define OF_SS_MODE_0 0
  67. #define OF_SS_MODE_1 1
  68. #define OF_SS_MODE_2 2
  69. #define OF_SS_MODE_3 3
  70. #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */
  71. #define OF_DATA_IN BIT_6 /* Data in to initiator */
  72. /* (data from target to initiator) */
  73. #define OF_DATA_OUT BIT_7 /* Data out from initiator */
  74. /* (data from initiator to target) */
  75. #define OF_NO_DATA (BIT_7 | BIT_6)
  76. #define OF_INC_RC BIT_8 /* Increment command resource count */
  77. #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */
  78. #define OF_CONF_REQ BIT_13 /* Confirmation Requested */
  79. #define OF_TERM_EXCH BIT_14 /* Terminate exchange */
  80. #define OF_SSTS BIT_15 /* Send SCSI status */
  81. #endif
  82. #ifndef QLA_TGT_DATASEGS_PER_CMD32
  83. #define QLA_TGT_DATASEGS_PER_CMD32 3
  84. #define QLA_TGT_DATASEGS_PER_CONT32 7
  85. #define QLA_TGT_MAX_SG32(ql) \
  86. (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
  87. QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
  88. #define QLA_TGT_DATASEGS_PER_CMD64 2
  89. #define QLA_TGT_DATASEGS_PER_CONT64 5
  90. #define QLA_TGT_MAX_SG64(ql) \
  91. (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
  92. QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
  93. #endif
  94. #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
  95. #define QLA_TGT_DATASEGS_PER_CMD_24XX 1
  96. #define QLA_TGT_DATASEGS_PER_CONT_24XX 5
  97. #define QLA_TGT_MAX_SG_24XX(ql) \
  98. (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
  99. QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
  100. #endif
  101. #endif
  102. #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
  103. ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
  104. : (uint16_t)(iocb)->u.isp2x.target.id.standard)
  105. #ifndef IMMED_NOTIFY_TYPE
  106. #define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */
  107. /*
  108. * ISP queue - immediate notify entry structure definition.
  109. * This is sent by the ISP to the Target driver.
  110. * This IOCB would have report of events sent by the
  111. * initiator, that needs to be handled by the target
  112. * driver immediately.
  113. */
  114. struct imm_ntfy_from_isp {
  115. uint8_t entry_type; /* Entry type. */
  116. uint8_t entry_count; /* Entry count. */
  117. uint8_t sys_define; /* System defined. */
  118. uint8_t entry_status; /* Entry Status. */
  119. union {
  120. struct {
  121. uint32_t sys_define_2; /* System defined. */
  122. target_id_t target;
  123. uint16_t lun;
  124. uint8_t target_id;
  125. uint8_t reserved_1;
  126. uint16_t status_modifier;
  127. uint16_t status;
  128. uint16_t task_flags;
  129. uint16_t seq_id;
  130. uint16_t srr_rx_id;
  131. uint32_t srr_rel_offs;
  132. uint16_t srr_ui;
  133. #define SRR_IU_DATA_IN 0x1
  134. #define SRR_IU_DATA_OUT 0x5
  135. #define SRR_IU_STATUS 0x7
  136. uint16_t srr_ox_id;
  137. uint8_t reserved_2[28];
  138. } isp2x;
  139. struct {
  140. uint32_t reserved;
  141. uint16_t nport_handle;
  142. uint16_t reserved_2;
  143. uint16_t flags;
  144. #define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1
  145. #define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0
  146. uint16_t srr_rx_id;
  147. uint16_t status;
  148. uint8_t status_subcode;
  149. uint8_t fw_handle;
  150. uint32_t exchange_address;
  151. uint32_t srr_rel_offs;
  152. uint16_t srr_ui;
  153. uint16_t srr_ox_id;
  154. uint8_t reserved_4[19];
  155. uint8_t vp_index;
  156. uint32_t reserved_5;
  157. uint8_t port_id[3];
  158. uint8_t reserved_6;
  159. } isp24;
  160. } u;
  161. uint16_t reserved_7;
  162. uint16_t ox_id;
  163. } __packed;
  164. #endif
  165. #ifndef NOTIFY_ACK_TYPE
  166. #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
  167. /*
  168. * ISP queue - notify acknowledge entry structure definition.
  169. * This is sent to the ISP from the target driver.
  170. */
  171. struct nack_to_isp {
  172. uint8_t entry_type; /* Entry type. */
  173. uint8_t entry_count; /* Entry count. */
  174. uint8_t sys_define; /* System defined. */
  175. uint8_t entry_status; /* Entry Status. */
  176. union {
  177. struct {
  178. uint32_t sys_define_2; /* System defined. */
  179. target_id_t target;
  180. uint8_t target_id;
  181. uint8_t reserved_1;
  182. uint16_t flags;
  183. uint16_t resp_code;
  184. uint16_t status;
  185. uint16_t task_flags;
  186. uint16_t seq_id;
  187. uint16_t srr_rx_id;
  188. uint32_t srr_rel_offs;
  189. uint16_t srr_ui;
  190. uint16_t srr_flags;
  191. uint16_t srr_reject_code;
  192. uint8_t srr_reject_vendor_uniq;
  193. uint8_t srr_reject_code_expl;
  194. uint8_t reserved_2[24];
  195. } isp2x;
  196. struct {
  197. uint32_t handle;
  198. uint16_t nport_handle;
  199. uint16_t reserved_1;
  200. uint16_t flags;
  201. uint16_t srr_rx_id;
  202. uint16_t status;
  203. uint8_t status_subcode;
  204. uint8_t fw_handle;
  205. uint32_t exchange_address;
  206. uint32_t srr_rel_offs;
  207. uint16_t srr_ui;
  208. uint16_t srr_flags;
  209. uint8_t reserved_4[19];
  210. uint8_t vp_index;
  211. uint8_t srr_reject_vendor_uniq;
  212. uint8_t srr_reject_code_expl;
  213. uint8_t srr_reject_code;
  214. uint8_t reserved_5[5];
  215. } isp24;
  216. } u;
  217. uint8_t reserved[2];
  218. uint16_t ox_id;
  219. } __packed;
  220. #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
  221. #define NOTIFY_ACK_SRR_FLAGS_REJECT 1
  222. #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
  223. #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
  224. #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
  225. #define NOTIFY_ACK_SUCCESS 0x01
  226. #endif
  227. #ifndef ACCEPT_TGT_IO_TYPE
  228. #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
  229. #endif
  230. #ifndef CONTINUE_TGT_IO_TYPE
  231. #define CONTINUE_TGT_IO_TYPE 0x17
  232. /*
  233. * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
  234. * This structure is sent to the ISP 2xxx from target driver.
  235. */
  236. struct ctio_to_2xxx {
  237. uint8_t entry_type; /* Entry type. */
  238. uint8_t entry_count; /* Entry count. */
  239. uint8_t sys_define; /* System defined. */
  240. uint8_t entry_status; /* Entry Status. */
  241. uint32_t handle; /* System defined handle */
  242. target_id_t target;
  243. uint16_t rx_id;
  244. uint16_t flags;
  245. uint16_t status;
  246. uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */
  247. uint16_t dseg_count; /* Data segment count. */
  248. uint32_t relative_offset;
  249. uint32_t residual;
  250. uint16_t reserved_1[3];
  251. uint16_t scsi_status;
  252. uint32_t transfer_length;
  253. uint32_t dseg_0_address; /* Data segment 0 address. */
  254. uint32_t dseg_0_length; /* Data segment 0 length. */
  255. uint32_t dseg_1_address; /* Data segment 1 address. */
  256. uint32_t dseg_1_length; /* Data segment 1 length. */
  257. uint32_t dseg_2_address; /* Data segment 2 address. */
  258. uint32_t dseg_2_length; /* Data segment 2 length. */
  259. } __packed;
  260. #define ATIO_PATH_INVALID 0x07
  261. #define ATIO_CANT_PROV_CAP 0x16
  262. #define ATIO_CDB_VALID 0x3D
  263. #define ATIO_EXEC_READ BIT_1
  264. #define ATIO_EXEC_WRITE BIT_0
  265. #endif
  266. #ifndef CTIO_A64_TYPE
  267. #define CTIO_A64_TYPE 0x1F
  268. #define CTIO_SUCCESS 0x01
  269. #define CTIO_ABORTED 0x02
  270. #define CTIO_INVALID_RX_ID 0x08
  271. #define CTIO_TIMEOUT 0x0B
  272. #define CTIO_LIP_RESET 0x0E
  273. #define CTIO_TARGET_RESET 0x17
  274. #define CTIO_PORT_UNAVAILABLE 0x28
  275. #define CTIO_PORT_LOGGED_OUT 0x29
  276. #define CTIO_PORT_CONF_CHANGED 0x2A
  277. #define CTIO_SRR_RECEIVED 0x45
  278. #endif
  279. #ifndef CTIO_RET_TYPE
  280. #define CTIO_RET_TYPE 0x17 /* CTIO return entry */
  281. #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
  282. struct fcp_hdr {
  283. uint8_t r_ctl;
  284. uint8_t d_id[3];
  285. uint8_t cs_ctl;
  286. uint8_t s_id[3];
  287. uint8_t type;
  288. uint8_t f_ctl[3];
  289. uint8_t seq_id;
  290. uint8_t df_ctl;
  291. uint16_t seq_cnt;
  292. uint16_t ox_id;
  293. uint16_t rx_id;
  294. uint32_t parameter;
  295. } __packed;
  296. struct fcp_hdr_le {
  297. uint8_t d_id[3];
  298. uint8_t r_ctl;
  299. uint8_t s_id[3];
  300. uint8_t cs_ctl;
  301. uint8_t f_ctl[3];
  302. uint8_t type;
  303. uint16_t seq_cnt;
  304. uint8_t df_ctl;
  305. uint8_t seq_id;
  306. uint16_t rx_id;
  307. uint16_t ox_id;
  308. uint32_t parameter;
  309. } __packed;
  310. #define F_CTL_EXCH_CONTEXT_RESP BIT_23
  311. #define F_CTL_SEQ_CONTEXT_RESIP BIT_22
  312. #define F_CTL_LAST_SEQ BIT_20
  313. #define F_CTL_END_SEQ BIT_19
  314. #define F_CTL_SEQ_INITIATIVE BIT_16
  315. #define R_CTL_BASIC_LINK_SERV 0x80
  316. #define R_CTL_B_ACC 0x4
  317. #define R_CTL_B_RJT 0x5
  318. struct atio7_fcp_cmnd {
  319. uint64_t lun;
  320. uint8_t cmnd_ref;
  321. uint8_t task_attr:3;
  322. uint8_t reserved:5;
  323. uint8_t task_mgmt_flags;
  324. #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
  325. #define FCP_CMND_TASK_MGMT_TARGET_RESET 5
  326. #define FCP_CMND_TASK_MGMT_LU_RESET 4
  327. #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
  328. #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
  329. uint8_t wrdata:1;
  330. uint8_t rddata:1;
  331. uint8_t add_cdb_len:6;
  332. uint8_t cdb[16];
  333. /*
  334. * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
  335. * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
  336. * BUILD_BUG_ON in qlt_init().
  337. */
  338. uint8_t add_cdb[4];
  339. /* uint32_t data_length; */
  340. } __packed;
  341. /*
  342. * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
  343. * This is sent from the ISP to the target driver.
  344. */
  345. struct atio_from_isp {
  346. union {
  347. struct {
  348. uint16_t entry_hdr;
  349. uint8_t sys_define; /* System defined. */
  350. uint8_t entry_status; /* Entry Status. */
  351. uint32_t sys_define_2; /* System defined. */
  352. target_id_t target;
  353. uint16_t rx_id;
  354. uint16_t flags;
  355. uint16_t status;
  356. uint8_t command_ref;
  357. uint8_t task_codes;
  358. uint8_t task_flags;
  359. uint8_t execution_codes;
  360. uint8_t cdb[MAX_CMDSZ];
  361. uint32_t data_length;
  362. uint16_t lun;
  363. uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */
  364. uint16_t reserved_32[6];
  365. uint16_t ox_id;
  366. } isp2x;
  367. struct {
  368. uint16_t entry_hdr;
  369. uint8_t fcp_cmnd_len_low;
  370. uint8_t fcp_cmnd_len_high:4;
  371. uint8_t attr:4;
  372. uint32_t exchange_addr;
  373. #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
  374. struct fcp_hdr fcp_hdr;
  375. struct atio7_fcp_cmnd fcp_cmnd;
  376. } isp24;
  377. struct {
  378. uint8_t entry_type; /* Entry type. */
  379. uint8_t entry_count; /* Entry count. */
  380. uint8_t data[58];
  381. uint32_t signature;
  382. #define ATIO_PROCESSED 0xDEADDEAD /* Signature */
  383. } raw;
  384. } u;
  385. } __packed;
  386. #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
  387. /*
  388. * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
  389. * This structure is sent to the ISP 24xx from the target driver.
  390. */
  391. struct ctio7_to_24xx {
  392. uint8_t entry_type; /* Entry type. */
  393. uint8_t entry_count; /* Entry count. */
  394. uint8_t sys_define; /* System defined. */
  395. uint8_t entry_status; /* Entry Status. */
  396. uint32_t handle; /* System defined handle */
  397. uint16_t nport_handle;
  398. #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
  399. uint16_t timeout;
  400. uint16_t dseg_count; /* Data segment count. */
  401. uint8_t vp_index;
  402. uint8_t add_flags;
  403. uint8_t initiator_id[3];
  404. uint8_t reserved;
  405. uint32_t exchange_addr;
  406. union {
  407. struct {
  408. uint16_t reserved1;
  409. uint16_t flags;
  410. uint32_t residual;
  411. uint16_t ox_id;
  412. uint16_t scsi_status;
  413. uint32_t relative_offset;
  414. uint32_t reserved2;
  415. uint32_t transfer_length;
  416. uint32_t reserved3;
  417. /* Data segment 0 address. */
  418. uint32_t dseg_0_address[2];
  419. /* Data segment 0 length. */
  420. uint32_t dseg_0_length;
  421. } status0;
  422. struct {
  423. uint16_t sense_length;
  424. uint16_t flags;
  425. uint32_t residual;
  426. uint16_t ox_id;
  427. uint16_t scsi_status;
  428. uint16_t response_len;
  429. uint16_t reserved;
  430. uint8_t sense_data[24];
  431. } status1;
  432. } u;
  433. } __packed;
  434. /*
  435. * ISP queue - CTIO type 7 from ISP 24xx to target driver
  436. * returned entry structure.
  437. */
  438. struct ctio7_from_24xx {
  439. uint8_t entry_type; /* Entry type. */
  440. uint8_t entry_count; /* Entry count. */
  441. uint8_t sys_define; /* System defined. */
  442. uint8_t entry_status; /* Entry Status. */
  443. uint32_t handle; /* System defined handle */
  444. uint16_t status;
  445. uint16_t timeout;
  446. uint16_t dseg_count; /* Data segment count. */
  447. uint8_t vp_index;
  448. uint8_t reserved1[5];
  449. uint32_t exchange_address;
  450. uint16_t reserved2;
  451. uint16_t flags;
  452. uint32_t residual;
  453. uint16_t ox_id;
  454. uint16_t reserved3;
  455. uint32_t relative_offset;
  456. uint8_t reserved4[24];
  457. } __packed;
  458. /* CTIO7 flags values */
  459. #define CTIO7_FLAGS_SEND_STATUS BIT_15
  460. #define CTIO7_FLAGS_TERMINATE BIT_14
  461. #define CTIO7_FLAGS_CONFORM_REQ BIT_13
  462. #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
  463. #define CTIO7_FLAGS_STATUS_MODE_0 0
  464. #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
  465. #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
  466. #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
  467. #define CTIO7_FLAGS_DSD_PTR BIT_2
  468. #define CTIO7_FLAGS_DATA_IN BIT_1
  469. #define CTIO7_FLAGS_DATA_OUT BIT_0
  470. #define ELS_PLOGI 0x3
  471. #define ELS_FLOGI 0x4
  472. #define ELS_LOGO 0x5
  473. #define ELS_PRLI 0x20
  474. #define ELS_PRLO 0x21
  475. #define ELS_TPRLO 0x24
  476. #define ELS_PDISC 0x50
  477. #define ELS_ADISC 0x52
  478. /*
  479. * ISP queue - ABTS received/response entries structure definition for 24xx.
  480. */
  481. #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
  482. #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
  483. /*
  484. * ISP queue - ABTS received IOCB entry structure definition for 24xx.
  485. * The ABTS BLS received from the wire is sent to the
  486. * target driver by the ISP 24xx.
  487. * The IOCB is placed on the response queue.
  488. */
  489. struct abts_recv_from_24xx {
  490. uint8_t entry_type; /* Entry type. */
  491. uint8_t entry_count; /* Entry count. */
  492. uint8_t sys_define; /* System defined. */
  493. uint8_t entry_status; /* Entry Status. */
  494. uint8_t reserved_1[6];
  495. uint16_t nport_handle;
  496. uint8_t reserved_2[2];
  497. uint8_t vp_index;
  498. uint8_t reserved_3:4;
  499. uint8_t sof_type:4;
  500. uint32_t exchange_address;
  501. struct fcp_hdr_le fcp_hdr_le;
  502. uint8_t reserved_4[16];
  503. uint32_t exchange_addr_to_abort;
  504. } __packed;
  505. #define ABTS_PARAM_ABORT_SEQ BIT_0
  506. struct ba_acc_le {
  507. uint16_t reserved;
  508. uint8_t seq_id_last;
  509. uint8_t seq_id_valid;
  510. #define SEQ_ID_VALID 0x80
  511. #define SEQ_ID_INVALID 0x00
  512. uint16_t rx_id;
  513. uint16_t ox_id;
  514. uint16_t high_seq_cnt;
  515. uint16_t low_seq_cnt;
  516. } __packed;
  517. struct ba_rjt_le {
  518. uint8_t vendor_uniq;
  519. uint8_t reason_expl;
  520. uint8_t reason_code;
  521. #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
  522. #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
  523. uint8_t reserved;
  524. } __packed;
  525. /*
  526. * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
  527. * The ABTS response to the ABTS received is sent by the
  528. * target driver to the ISP 24xx.
  529. * The IOCB is placed on the request queue.
  530. */
  531. struct abts_resp_to_24xx {
  532. uint8_t entry_type; /* Entry type. */
  533. uint8_t entry_count; /* Entry count. */
  534. uint8_t sys_define; /* System defined. */
  535. uint8_t entry_status; /* Entry Status. */
  536. uint32_t handle;
  537. uint16_t reserved_1;
  538. uint16_t nport_handle;
  539. uint16_t control_flags;
  540. #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
  541. uint8_t vp_index;
  542. uint8_t reserved_3:4;
  543. uint8_t sof_type:4;
  544. uint32_t exchange_address;
  545. struct fcp_hdr_le fcp_hdr_le;
  546. union {
  547. struct ba_acc_le ba_acct;
  548. struct ba_rjt_le ba_rjt;
  549. } __packed payload;
  550. uint32_t reserved_4;
  551. uint32_t exchange_addr_to_abort;
  552. } __packed;
  553. /*
  554. * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
  555. * The ABTS response with completion status to the ABTS response
  556. * (sent by the target driver to the ISP 24xx) is sent by the
  557. * ISP24xx firmware to the target driver.
  558. * The IOCB is placed on the response queue.
  559. */
  560. struct abts_resp_from_24xx_fw {
  561. uint8_t entry_type; /* Entry type. */
  562. uint8_t entry_count; /* Entry count. */
  563. uint8_t sys_define; /* System defined. */
  564. uint8_t entry_status; /* Entry Status. */
  565. uint32_t handle;
  566. uint16_t compl_status;
  567. #define ABTS_RESP_COMPL_SUCCESS 0
  568. #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
  569. uint16_t nport_handle;
  570. uint16_t reserved_1;
  571. uint8_t reserved_2;
  572. uint8_t reserved_3:4;
  573. uint8_t sof_type:4;
  574. uint32_t exchange_address;
  575. struct fcp_hdr_le fcp_hdr_le;
  576. uint8_t reserved_4[8];
  577. uint32_t error_subcode1;
  578. #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
  579. uint32_t error_subcode2;
  580. uint32_t exchange_addr_to_abort;
  581. } __packed;
  582. /********************************************************************\
  583. * Type Definitions used by initiator & target halves
  584. \********************************************************************/
  585. struct qla_tgt_mgmt_cmd;
  586. struct qla_tgt_sess;
  587. /*
  588. * This structure provides a template of function calls that the
  589. * target driver (from within qla_target.c) can issue to the
  590. * target module (tcm_qla2xxx).
  591. */
  592. struct qla_tgt_func_tmpl {
  593. int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
  594. unsigned char *, uint32_t, int, int, int);
  595. void (*handle_data)(struct qla_tgt_cmd *);
  596. int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t,
  597. uint32_t);
  598. void (*free_cmd)(struct qla_tgt_cmd *);
  599. void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
  600. void (*free_session)(struct qla_tgt_sess *);
  601. int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
  602. void *, uint8_t *, uint16_t);
  603. void (*update_sess)(struct qla_tgt_sess *, port_id_t, uint16_t, bool);
  604. struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *,
  605. const uint16_t);
  606. struct qla_tgt_sess *(*find_sess_by_s_id)(struct scsi_qla_host *,
  607. const uint8_t *);
  608. void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *);
  609. void (*put_sess)(struct qla_tgt_sess *);
  610. void (*shutdown_sess)(struct qla_tgt_sess *);
  611. };
  612. int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
  613. #include <target/target_core_base.h>
  614. #define QLA_TGT_TIMEOUT 10 /* in seconds */
  615. #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
  616. /* Immediate notify status constants */
  617. #define IMM_NTFY_LIP_RESET 0x000E
  618. #define IMM_NTFY_LIP_LINK_REINIT 0x000F
  619. #define IMM_NTFY_IOCB_OVERFLOW 0x0016
  620. #define IMM_NTFY_ABORT_TASK 0x0020
  621. #define IMM_NTFY_PORT_LOGOUT 0x0029
  622. #define IMM_NTFY_PORT_CONFIG 0x002A
  623. #define IMM_NTFY_GLBL_TPRLO 0x002D
  624. #define IMM_NTFY_GLBL_LOGO 0x002E
  625. #define IMM_NTFY_RESOURCE 0x0034
  626. #define IMM_NTFY_MSG_RX 0x0036
  627. #define IMM_NTFY_SRR 0x0045
  628. #define IMM_NTFY_ELS 0x0046
  629. /* Immediate notify task flags */
  630. #define IMM_NTFY_TASK_MGMT_SHIFT 8
  631. #define QLA_TGT_CLEAR_ACA 0x40
  632. #define QLA_TGT_TARGET_RESET 0x20
  633. #define QLA_TGT_LUN_RESET 0x10
  634. #define QLA_TGT_CLEAR_TS 0x04
  635. #define QLA_TGT_ABORT_TS 0x02
  636. #define QLA_TGT_ABORT_ALL_SESS 0xFFFF
  637. #define QLA_TGT_ABORT_ALL 0xFFFE
  638. #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
  639. #define QLA_TGT_NEXUS_LOSS 0xFFFC
  640. /* Notify Acknowledge flags */
  641. #define NOTIFY_ACK_RES_COUNT BIT_8
  642. #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
  643. #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
  644. /* Command's states */
  645. #define QLA_TGT_STATE_NEW 0 /* New command + target processing */
  646. #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
  647. #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
  648. #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
  649. #define QLA_TGT_STATE_ABORTED 4 /* Command aborted */
  650. /* Special handles */
  651. #define QLA_TGT_NULL_HANDLE 0
  652. #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
  653. /* ATIO task_codes field */
  654. #define ATIO_SIMPLE_QUEUE 0
  655. #define ATIO_HEAD_OF_QUEUE 1
  656. #define ATIO_ORDERED_QUEUE 2
  657. #define ATIO_ACA_QUEUE 4
  658. #define ATIO_UNTAGGED 5
  659. /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
  660. #define FC_TM_SUCCESS 0
  661. #define FC_TM_BAD_FCP_DATA 1
  662. #define FC_TM_BAD_CMD 2
  663. #define FC_TM_FCP_DATA_MISMATCH 3
  664. #define FC_TM_REJECT 4
  665. #define FC_TM_FAILED 5
  666. /*
  667. * Error code of qlt_pre_xmit_response() meaning that cmd's exchange was
  668. * terminated, so no more actions is needed and success should be returned
  669. * to target.
  670. */
  671. #define QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED 0x1717
  672. #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
  673. #define pci_dma_lo32(a) (a & 0xffffffff)
  674. #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
  675. #else
  676. #define pci_dma_lo32(a) (a & 0xffffffff)
  677. #define pci_dma_hi32(a) 0
  678. #endif
  679. #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
  680. (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
  681. struct qla_port_24xx_data {
  682. uint8_t port_name[WWN_SIZE];
  683. uint16_t loop_id;
  684. uint16_t reserved;
  685. };
  686. struct qla_tgt {
  687. struct scsi_qla_host *vha;
  688. struct qla_hw_data *ha;
  689. /*
  690. * To sync between IRQ handlers and qlt_target_release(). Needed,
  691. * because req_pkt() can drop/reaquire HW lock inside. Protected by
  692. * HW lock.
  693. */
  694. int irq_cmd_count;
  695. int datasegs_per_cmd, datasegs_per_cont, sg_tablesize;
  696. /* Target's flags, serialized by pha->hardware_lock */
  697. unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addr enabled */
  698. unsigned int link_reinit_iocb_pending:1;
  699. /*
  700. * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
  701. * OR hardware_lock for reading.
  702. */
  703. int tgt_stop; /* the target mode driver is being stopped */
  704. int tgt_stopped; /* the target mode driver has been stopped */
  705. /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
  706. int sess_count;
  707. /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
  708. struct list_head sess_list;
  709. /* Protected by hardware_lock */
  710. struct list_head del_sess_list;
  711. struct delayed_work sess_del_work;
  712. spinlock_t sess_work_lock;
  713. struct list_head sess_works_list;
  714. struct work_struct sess_work;
  715. struct imm_ntfy_from_isp link_reinit_iocb;
  716. wait_queue_head_t waitQ;
  717. int notify_ack_expected;
  718. int abts_resp_expected;
  719. int modify_lun_expected;
  720. int ctio_srr_id;
  721. int imm_srr_id;
  722. spinlock_t srr_lock;
  723. struct list_head srr_ctio_list;
  724. struct list_head srr_imm_list;
  725. struct work_struct srr_work;
  726. atomic_t tgt_global_resets_count;
  727. struct list_head tgt_list_entry;
  728. };
  729. /*
  730. * Equivilant to IT Nexus (Initiator-Target)
  731. */
  732. struct qla_tgt_sess {
  733. uint16_t loop_id;
  734. port_id_t s_id;
  735. unsigned int conf_compl_supported:1;
  736. unsigned int deleted:1;
  737. unsigned int local:1;
  738. struct se_session *se_sess;
  739. struct scsi_qla_host *vha;
  740. struct qla_tgt *tgt;
  741. struct list_head sess_list_entry;
  742. unsigned long expires;
  743. struct list_head del_list_entry;
  744. uint8_t port_name[WWN_SIZE];
  745. struct work_struct free_work;
  746. };
  747. struct qla_tgt_cmd {
  748. struct qla_tgt_sess *sess;
  749. int state;
  750. struct se_cmd se_cmd;
  751. struct work_struct free_work;
  752. struct work_struct work;
  753. /* Sense buffer that will be mapped into outgoing status */
  754. unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
  755. /* to save extra sess dereferences */
  756. unsigned int conf_compl_supported:1;
  757. unsigned int sg_mapped:1;
  758. unsigned int free_sg:1;
  759. unsigned int aborted:1; /* Needed in case of SRR */
  760. unsigned int write_data_transferred:1;
  761. struct scatterlist *sg; /* cmd data buffer SG vector */
  762. int sg_cnt; /* SG segments count */
  763. int bufflen; /* cmd buffer length */
  764. int offset;
  765. uint32_t tag;
  766. uint32_t unpacked_lun;
  767. enum dma_data_direction dma_data_direction;
  768. uint16_t loop_id; /* to save extra sess dereferences */
  769. struct qla_tgt *tgt; /* to save extra sess dereferences */
  770. struct scsi_qla_host *vha;
  771. struct list_head cmd_list;
  772. struct atio_from_isp atio;
  773. };
  774. struct qla_tgt_sess_work_param {
  775. struct list_head sess_works_list_entry;
  776. #define QLA_TGT_SESS_WORK_ABORT 1
  777. #define QLA_TGT_SESS_WORK_TM 2
  778. int type;
  779. union {
  780. struct abts_recv_from_24xx abts;
  781. struct imm_ntfy_from_isp tm_iocb;
  782. struct atio_from_isp tm_iocb2;
  783. };
  784. };
  785. struct qla_tgt_mgmt_cmd {
  786. uint8_t tmr_func;
  787. uint8_t fc_tm_rsp;
  788. struct qla_tgt_sess *sess;
  789. struct se_cmd se_cmd;
  790. struct work_struct free_work;
  791. unsigned int flags;
  792. #define QLA24XX_MGMT_SEND_NACK 1
  793. union {
  794. struct atio_from_isp atio;
  795. struct imm_ntfy_from_isp imm_ntfy;
  796. struct abts_recv_from_24xx abts;
  797. } __packed orig_iocb;
  798. };
  799. struct qla_tgt_prm {
  800. struct qla_tgt_cmd *cmd;
  801. struct qla_tgt *tgt;
  802. void *pkt;
  803. struct scatterlist *sg; /* cmd data buffer SG vector */
  804. int seg_cnt;
  805. int req_cnt;
  806. uint16_t rq_result;
  807. uint16_t scsi_status;
  808. unsigned char *sense_buffer;
  809. int sense_buffer_len;
  810. int residual;
  811. int add_status_pkt;
  812. };
  813. struct qla_tgt_srr_imm {
  814. struct list_head srr_list_entry;
  815. int srr_id;
  816. struct imm_ntfy_from_isp imm_ntfy;
  817. };
  818. struct qla_tgt_srr_ctio {
  819. struct list_head srr_list_entry;
  820. int srr_id;
  821. struct qla_tgt_cmd *cmd;
  822. };
  823. #define QLA_TGT_XMIT_DATA 1
  824. #define QLA_TGT_XMIT_STATUS 2
  825. #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
  826. extern struct qla_tgt_data qla_target;
  827. /*
  828. * Internal function prototypes
  829. */
  830. void qlt_disable_vha(struct scsi_qla_host *);
  831. /*
  832. * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
  833. */
  834. extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
  835. extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
  836. extern int qlt_lport_register(struct qla_tgt_func_tmpl *, u64,
  837. int (*callback)(struct scsi_qla_host *), void *);
  838. extern void qlt_lport_deregister(struct scsi_qla_host *);
  839. extern void qlt_unreg_sess(struct qla_tgt_sess *);
  840. extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
  841. extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *);
  842. extern void qlt_set_mode(struct scsi_qla_host *ha);
  843. extern void qlt_clear_mode(struct scsi_qla_host *ha);
  844. extern int __init qlt_init(void);
  845. extern void qlt_exit(void);
  846. extern void qlt_update_vp_map(struct scsi_qla_host *, int);
  847. /*
  848. * This macro is used during early initializations when host->active_mode
  849. * is not set. Right now, ha value is ignored.
  850. */
  851. #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
  852. extern int ql2x_ini_mode;
  853. static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
  854. {
  855. return ha->host->active_mode & MODE_TARGET;
  856. }
  857. static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
  858. {
  859. return ha->host->active_mode & MODE_INITIATOR;
  860. }
  861. static inline void qla_reverse_ini_mode(struct scsi_qla_host *ha)
  862. {
  863. if (ha->host->active_mode & MODE_INITIATOR)
  864. ha->host->active_mode &= ~MODE_INITIATOR;
  865. else
  866. ha->host->active_mode |= MODE_INITIATOR;
  867. }
  868. /*
  869. * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
  870. */
  871. extern void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *,
  872. struct atio_from_isp *);
  873. extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, response_t *);
  874. extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
  875. extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
  876. extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
  877. extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
  878. extern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
  879. extern void qlt_ctio_completion(struct scsi_qla_host *, uint32_t);
  880. extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
  881. extern void qlt_enable_vha(struct scsi_qla_host *);
  882. extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
  883. extern void qlt_rff_id(struct scsi_qla_host *, struct ct_sns_req *);
  884. extern void qlt_init_atio_q_entries(struct scsi_qla_host *);
  885. extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *);
  886. extern void qlt_24xx_config_rings(struct scsi_qla_host *);
  887. extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
  888. struct nvram_24xx *);
  889. extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
  890. struct init_cb_24xx *);
  891. extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
  892. struct init_cb_81xx *);
  893. extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
  894. struct nvram_81xx *);
  895. extern int qlt_24xx_process_response_error(struct scsi_qla_host *,
  896. struct sts_entry_24xx *);
  897. extern void qlt_modify_vp_config(struct scsi_qla_host *,
  898. struct vp_config_entry_24xx *);
  899. extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
  900. extern int qlt_mem_alloc(struct qla_hw_data *);
  901. extern void qlt_mem_free(struct qla_hw_data *);
  902. extern void qlt_stop_phase1(struct qla_tgt *);
  903. extern void qlt_stop_phase2(struct qla_tgt *);
  904. extern irqreturn_t qla83xx_msix_atio_q(int, void *);
  905. extern void qlt_83xx_iospace_config(struct qla_hw_data *);
  906. #endif /* __QLA_TARGET_H */