sas.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * SAS structures and definitions header file
  3. *
  4. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  5. * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
  6. *
  7. * This file is licensed under GPLv2.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. * USA
  23. *
  24. */
  25. #ifndef _SAS_H_
  26. #define _SAS_H_
  27. #include <linux/types.h>
  28. #include <asm/byteorder.h>
  29. #define SAS_ADDR_SIZE 8
  30. #define HASHED_SAS_ADDR_SIZE 3
  31. #define SAS_ADDR(_sa) ((unsigned long long) be64_to_cpu(*(__be64 *)(_sa)))
  32. #define SMP_REQUEST 0x40
  33. #define SMP_RESPONSE 0x41
  34. #define SSP_DATA 0x01
  35. #define SSP_XFER_RDY 0x05
  36. #define SSP_COMMAND 0x06
  37. #define SSP_RESPONSE 0x07
  38. #define SSP_TASK 0x16
  39. #define SMP_REPORT_GENERAL 0x00
  40. #define SMP_REPORT_MANUF_INFO 0x01
  41. #define SMP_READ_GPIO_REG 0x02
  42. #define SMP_DISCOVER 0x10
  43. #define SMP_REPORT_PHY_ERR_LOG 0x11
  44. #define SMP_REPORT_PHY_SATA 0x12
  45. #define SMP_REPORT_ROUTE_INFO 0x13
  46. #define SMP_WRITE_GPIO_REG 0x82
  47. #define SMP_CONF_ROUTE_INFO 0x90
  48. #define SMP_PHY_CONTROL 0x91
  49. #define SMP_PHY_TEST_FUNCTION 0x92
  50. #define SMP_RESP_FUNC_ACC 0x00
  51. #define SMP_RESP_FUNC_UNK 0x01
  52. #define SMP_RESP_FUNC_FAILED 0x02
  53. #define SMP_RESP_INV_FRM_LEN 0x03
  54. #define SMP_RESP_NO_PHY 0x10
  55. #define SMP_RESP_NO_INDEX 0x11
  56. #define SMP_RESP_PHY_NO_SATA 0x12
  57. #define SMP_RESP_PHY_UNK_OP 0x13
  58. #define SMP_RESP_PHY_UNK_TESTF 0x14
  59. #define SMP_RESP_PHY_TEST_INPROG 0x15
  60. #define SMP_RESP_PHY_VACANT 0x16
  61. /* SAM TMFs */
  62. #define TMF_ABORT_TASK 0x01
  63. #define TMF_ABORT_TASK_SET 0x02
  64. #define TMF_CLEAR_TASK_SET 0x04
  65. #define TMF_LU_RESET 0x08
  66. #define TMF_CLEAR_ACA 0x40
  67. #define TMF_QUERY_TASK 0x80
  68. /* SAS TMF responses */
  69. #define TMF_RESP_FUNC_COMPLETE 0x00
  70. #define TMF_RESP_INVALID_FRAME 0x02
  71. #define TMF_RESP_FUNC_ESUPP 0x04
  72. #define TMF_RESP_FUNC_FAILED 0x05
  73. #define TMF_RESP_FUNC_SUCC 0x08
  74. #define TMF_RESP_NO_LUN 0x09
  75. #define TMF_RESP_OVERLAPPED_TAG 0x0A
  76. enum sas_oob_mode {
  77. OOB_NOT_CONNECTED,
  78. SATA_OOB_MODE,
  79. SAS_OOB_MODE
  80. };
  81. /* See sas_discover.c if you plan on changing these.
  82. */
  83. enum sas_dev_type {
  84. NO_DEVICE = 0, /* protocol */
  85. SAS_END_DEV = 1, /* protocol */
  86. EDGE_DEV = 2, /* protocol */
  87. FANOUT_DEV = 3, /* protocol */
  88. SAS_HA = 4,
  89. SATA_DEV = 5,
  90. SATA_PM = 7,
  91. SATA_PM_PORT= 8,
  92. };
  93. enum sas_protocol {
  94. SAS_PROTOCOL_SATA = 0x01,
  95. SAS_PROTOCOL_SMP = 0x02,
  96. SAS_PROTOCOL_STP = 0x04,
  97. SAS_PROTOCOL_SSP = 0x08,
  98. SAS_PROTOCOL_ALL = 0x0E,
  99. };
  100. /* From the spec; local phys only */
  101. enum phy_func {
  102. PHY_FUNC_NOP,
  103. PHY_FUNC_LINK_RESET, /* Enables the phy */
  104. PHY_FUNC_HARD_RESET,
  105. PHY_FUNC_DISABLE,
  106. PHY_FUNC_CLEAR_ERROR_LOG = 5,
  107. PHY_FUNC_CLEAR_AFFIL,
  108. PHY_FUNC_TX_SATA_PS_SIGNAL,
  109. PHY_FUNC_RELEASE_SPINUP_HOLD = 0x10, /* LOCAL PORT ONLY! */
  110. PHY_FUNC_SET_LINK_RATE,
  111. };
  112. /* SAS LLDD would need to report only _very_few_ of those, like BROADCAST.
  113. * Most of those are here for completeness.
  114. */
  115. enum sas_prim {
  116. SAS_PRIM_AIP_NORMAL = 1,
  117. SAS_PRIM_AIP_R0 = 2,
  118. SAS_PRIM_AIP_R1 = 3,
  119. SAS_PRIM_AIP_R2 = 4,
  120. SAS_PRIM_AIP_WC = 5,
  121. SAS_PRIM_AIP_WD = 6,
  122. SAS_PRIM_AIP_WP = 7,
  123. SAS_PRIM_AIP_RWP = 8,
  124. SAS_PRIM_BC_CH = 9,
  125. SAS_PRIM_BC_RCH0 = 10,
  126. SAS_PRIM_BC_RCH1 = 11,
  127. SAS_PRIM_BC_R0 = 12,
  128. SAS_PRIM_BC_R1 = 13,
  129. SAS_PRIM_BC_R2 = 14,
  130. SAS_PRIM_BC_R3 = 15,
  131. SAS_PRIM_BC_R4 = 16,
  132. SAS_PRIM_NOTIFY_ENSP= 17,
  133. SAS_PRIM_NOTIFY_R0 = 18,
  134. SAS_PRIM_NOTIFY_R1 = 19,
  135. SAS_PRIM_NOTIFY_R2 = 20,
  136. SAS_PRIM_CLOSE_CLAF = 21,
  137. SAS_PRIM_CLOSE_NORM = 22,
  138. SAS_PRIM_CLOSE_R0 = 23,
  139. SAS_PRIM_CLOSE_R1 = 24,
  140. SAS_PRIM_OPEN_RTRY = 25,
  141. SAS_PRIM_OPEN_RJCT = 26,
  142. SAS_PRIM_OPEN_ACPT = 27,
  143. SAS_PRIM_DONE = 28,
  144. SAS_PRIM_BREAK = 29,
  145. SATA_PRIM_DMAT = 33,
  146. SATA_PRIM_PMNAK = 34,
  147. SATA_PRIM_PMACK = 35,
  148. SATA_PRIM_PMREQ_S = 36,
  149. SATA_PRIM_PMREQ_P = 37,
  150. SATA_SATA_R_ERR = 38,
  151. };
  152. enum sas_open_rej_reason {
  153. /* Abandon open */
  154. SAS_OREJ_UNKNOWN = 0,
  155. SAS_OREJ_BAD_DEST = 1,
  156. SAS_OREJ_CONN_RATE = 2,
  157. SAS_OREJ_EPROTO = 3,
  158. SAS_OREJ_RESV_AB0 = 4,
  159. SAS_OREJ_RESV_AB1 = 5,
  160. SAS_OREJ_RESV_AB2 = 6,
  161. SAS_OREJ_RESV_AB3 = 7,
  162. SAS_OREJ_WRONG_DEST= 8,
  163. SAS_OREJ_STP_NORES = 9,
  164. /* Retry open */
  165. SAS_OREJ_NO_DEST = 10,
  166. SAS_OREJ_PATH_BLOCKED = 11,
  167. SAS_OREJ_RSVD_CONT0 = 12,
  168. SAS_OREJ_RSVD_CONT1 = 13,
  169. SAS_OREJ_RSVD_INIT0 = 14,
  170. SAS_OREJ_RSVD_INIT1 = 15,
  171. SAS_OREJ_RSVD_STOP0 = 16,
  172. SAS_OREJ_RSVD_STOP1 = 17,
  173. SAS_OREJ_RSVD_RETRY = 18,
  174. };
  175. struct dev_to_host_fis {
  176. u8 fis_type; /* 0x34 */
  177. u8 flags;
  178. u8 status;
  179. u8 error;
  180. u8 lbal;
  181. union { u8 lbam; u8 byte_count_low; };
  182. union { u8 lbah; u8 byte_count_high; };
  183. u8 device;
  184. u8 lbal_exp;
  185. u8 lbam_exp;
  186. u8 lbah_exp;
  187. u8 _r_a;
  188. union { u8 sector_count; u8 interrupt_reason; };
  189. u8 sector_count_exp;
  190. u8 _r_b;
  191. u8 _r_c;
  192. u32 _r_d;
  193. } __attribute__ ((packed));
  194. struct host_to_dev_fis {
  195. u8 fis_type; /* 0x27 */
  196. u8 flags;
  197. u8 command;
  198. u8 features;
  199. u8 lbal;
  200. union { u8 lbam; u8 byte_count_low; };
  201. union { u8 lbah; u8 byte_count_high; };
  202. u8 device;
  203. u8 lbal_exp;
  204. u8 lbam_exp;
  205. u8 lbah_exp;
  206. u8 features_exp;
  207. union { u8 sector_count; u8 interrupt_reason; };
  208. u8 sector_count_exp;
  209. u8 _r_a;
  210. u8 control;
  211. u32 _r_b;
  212. } __attribute__ ((packed));
  213. /* Prefer to have code clarity over header file clarity.
  214. */
  215. #ifdef __LITTLE_ENDIAN_BITFIELD
  216. struct sas_identify_frame {
  217. /* Byte 0 */
  218. u8 frame_type:4;
  219. u8 dev_type:3;
  220. u8 _un0:1;
  221. /* Byte 1 */
  222. u8 _un1;
  223. /* Byte 2 */
  224. union {
  225. struct {
  226. u8 _un20:1;
  227. u8 smp_iport:1;
  228. u8 stp_iport:1;
  229. u8 ssp_iport:1;
  230. u8 _un247:4;
  231. };
  232. u8 initiator_bits;
  233. };
  234. /* Byte 3 */
  235. union {
  236. struct {
  237. u8 _un30:1;
  238. u8 smp_tport:1;
  239. u8 stp_tport:1;
  240. u8 ssp_tport:1;
  241. u8 _un347:4;
  242. };
  243. u8 target_bits;
  244. };
  245. /* Byte 4 - 11 */
  246. u8 _un4_11[8];
  247. /* Byte 12 - 19 */
  248. u8 sas_addr[SAS_ADDR_SIZE];
  249. /* Byte 20 */
  250. u8 phy_id;
  251. u8 _un21_27[7];
  252. __be32 crc;
  253. } __attribute__ ((packed));
  254. struct ssp_frame_hdr {
  255. u8 frame_type;
  256. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  257. u8 _r_a;
  258. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  259. __be16 _r_b;
  260. u8 changing_data_ptr:1;
  261. u8 retransmit:1;
  262. u8 retry_data_frames:1;
  263. u8 _r_c:5;
  264. u8 num_fill_bytes:2;
  265. u8 _r_d:6;
  266. u32 _r_e;
  267. __be16 tag;
  268. __be16 tptt;
  269. __be32 data_offs;
  270. } __attribute__ ((packed));
  271. struct ssp_response_iu {
  272. u8 _r_a[10];
  273. u8 datapres:2;
  274. u8 _r_b:6;
  275. u8 status;
  276. u32 _r_c;
  277. __be32 sense_data_len;
  278. __be32 response_data_len;
  279. u8 resp_data[0];
  280. u8 sense_data[0];
  281. } __attribute__ ((packed));
  282. /* ---------- SMP ---------- */
  283. struct report_general_resp {
  284. __be16 change_count;
  285. __be16 route_indexes;
  286. u8 _r_a;
  287. u8 num_phys;
  288. u8 conf_route_table:1;
  289. u8 configuring:1;
  290. u8 _r_b:6;
  291. u8 _r_c;
  292. u8 enclosure_logical_id[8];
  293. u8 _r_d[12];
  294. } __attribute__ ((packed));
  295. struct discover_resp {
  296. u8 _r_a[5];
  297. u8 phy_id;
  298. __be16 _r_b;
  299. u8 _r_c:4;
  300. u8 attached_dev_type:3;
  301. u8 _r_d:1;
  302. u8 linkrate:4;
  303. u8 _r_e:4;
  304. u8 attached_sata_host:1;
  305. u8 iproto:3;
  306. u8 _r_f:4;
  307. u8 attached_sata_dev:1;
  308. u8 tproto:3;
  309. u8 _r_g:3;
  310. u8 attached_sata_ps:1;
  311. u8 sas_addr[8];
  312. u8 attached_sas_addr[8];
  313. u8 attached_phy_id;
  314. u8 _r_h[7];
  315. u8 hmin_linkrate:4;
  316. u8 pmin_linkrate:4;
  317. u8 hmax_linkrate:4;
  318. u8 pmax_linkrate:4;
  319. u8 change_count;
  320. u8 pptv:4;
  321. u8 _r_i:3;
  322. u8 virtual:1;
  323. u8 routing_attr:4;
  324. u8 _r_j:4;
  325. u8 conn_type;
  326. u8 conn_el_index;
  327. u8 conn_phy_link;
  328. u8 _r_k[8];
  329. } __attribute__ ((packed));
  330. struct report_phy_sata_resp {
  331. u8 _r_a[5];
  332. u8 phy_id;
  333. u8 _r_b;
  334. u8 affil_valid:1;
  335. u8 affil_supp:1;
  336. u8 _r_c:6;
  337. u32 _r_d;
  338. u8 stp_sas_addr[8];
  339. struct dev_to_host_fis fis;
  340. u32 _r_e;
  341. u8 affil_stp_ini_addr[8];
  342. __be32 crc;
  343. } __attribute__ ((packed));
  344. struct smp_resp {
  345. u8 frame_type;
  346. u8 function;
  347. u8 result;
  348. u8 reserved;
  349. union {
  350. struct report_general_resp rg;
  351. struct discover_resp disc;
  352. struct report_phy_sata_resp rps;
  353. };
  354. } __attribute__ ((packed));
  355. #elif defined(__BIG_ENDIAN_BITFIELD)
  356. struct sas_identify_frame {
  357. /* Byte 0 */
  358. u8 _un0:1;
  359. u8 dev_type:3;
  360. u8 frame_type:4;
  361. /* Byte 1 */
  362. u8 _un1;
  363. /* Byte 2 */
  364. union {
  365. struct {
  366. u8 _un247:4;
  367. u8 ssp_iport:1;
  368. u8 stp_iport:1;
  369. u8 smp_iport:1;
  370. u8 _un20:1;
  371. };
  372. u8 initiator_bits;
  373. };
  374. /* Byte 3 */
  375. union {
  376. struct {
  377. u8 _un347:4;
  378. u8 ssp_tport:1;
  379. u8 stp_tport:1;
  380. u8 smp_tport:1;
  381. u8 _un30:1;
  382. };
  383. u8 target_bits;
  384. };
  385. /* Byte 4 - 11 */
  386. u8 _un4_11[8];
  387. /* Byte 12 - 19 */
  388. u8 sas_addr[SAS_ADDR_SIZE];
  389. /* Byte 20 */
  390. u8 phy_id;
  391. u8 _un21_27[7];
  392. __be32 crc;
  393. } __attribute__ ((packed));
  394. struct ssp_frame_hdr {
  395. u8 frame_type;
  396. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  397. u8 _r_a;
  398. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  399. __be16 _r_b;
  400. u8 _r_c:5;
  401. u8 retry_data_frames:1;
  402. u8 retransmit:1;
  403. u8 changing_data_ptr:1;
  404. u8 _r_d:6;
  405. u8 num_fill_bytes:2;
  406. u32 _r_e;
  407. __be16 tag;
  408. __be16 tptt;
  409. __be32 data_offs;
  410. } __attribute__ ((packed));
  411. struct ssp_response_iu {
  412. u8 _r_a[10];
  413. u8 _r_b:6;
  414. u8 datapres:2;
  415. u8 status;
  416. u32 _r_c;
  417. __be32 sense_data_len;
  418. __be32 response_data_len;
  419. u8 resp_data[0];
  420. u8 sense_data[0];
  421. } __attribute__ ((packed));
  422. /* ---------- SMP ---------- */
  423. struct report_general_resp {
  424. __be16 change_count;
  425. __be16 route_indexes;
  426. u8 _r_a;
  427. u8 num_phys;
  428. u8 _r_b:6;
  429. u8 configuring:1;
  430. u8 conf_route_table:1;
  431. u8 _r_c;
  432. u8 enclosure_logical_id[8];
  433. u8 _r_d[12];
  434. } __attribute__ ((packed));
  435. struct discover_resp {
  436. u8 _r_a[5];
  437. u8 phy_id;
  438. __be16 _r_b;
  439. u8 _r_d:1;
  440. u8 attached_dev_type:3;
  441. u8 _r_c:4;
  442. u8 _r_e:4;
  443. u8 linkrate:4;
  444. u8 _r_f:4;
  445. u8 iproto:3;
  446. u8 attached_sata_host:1;
  447. u8 attached_sata_ps:1;
  448. u8 _r_g:3;
  449. u8 tproto:3;
  450. u8 attached_sata_dev:1;
  451. u8 sas_addr[8];
  452. u8 attached_sas_addr[8];
  453. u8 attached_phy_id;
  454. u8 _r_h[7];
  455. u8 pmin_linkrate:4;
  456. u8 hmin_linkrate:4;
  457. u8 pmax_linkrate:4;
  458. u8 hmax_linkrate:4;
  459. u8 change_count;
  460. u8 virtual:1;
  461. u8 _r_i:3;
  462. u8 pptv:4;
  463. u8 _r_j:4;
  464. u8 routing_attr:4;
  465. u8 conn_type;
  466. u8 conn_el_index;
  467. u8 conn_phy_link;
  468. u8 _r_k[8];
  469. } __attribute__ ((packed));
  470. struct report_phy_sata_resp {
  471. u8 _r_a[5];
  472. u8 phy_id;
  473. u8 _r_b;
  474. u8 _r_c:6;
  475. u8 affil_supp:1;
  476. u8 affil_valid:1;
  477. u32 _r_d;
  478. u8 stp_sas_addr[8];
  479. struct dev_to_host_fis fis;
  480. u32 _r_e;
  481. u8 affil_stp_ini_addr[8];
  482. __be32 crc;
  483. } __attribute__ ((packed));
  484. struct smp_resp {
  485. u8 frame_type;
  486. u8 function;
  487. u8 result;
  488. u8 reserved;
  489. union {
  490. struct report_general_resp rg;
  491. struct discover_resp disc;
  492. struct report_phy_sata_resp rps;
  493. };
  494. } __attribute__ ((packed));
  495. #else
  496. #error "Bitfield order not defined!"
  497. #endif
  498. #endif /* _SAS_H_ */