qla_target.h 29 KB

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