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. /* Partly from IDENTIFY address frame. */
  94. enum sas_proto {
  95. SATA_PROTO = 1,
  96. SAS_PROTO_SMP = 2, /* protocol */
  97. SAS_PROTO_STP = 4, /* protocol */
  98. SAS_PROTO_SSP = 8, /* protocol */
  99. SAS_PROTO_ALL = 0xE,
  100. };
  101. /* From the spec; local phys only */
  102. enum phy_func {
  103. PHY_FUNC_NOP,
  104. PHY_FUNC_LINK_RESET, /* Enables the phy */
  105. PHY_FUNC_HARD_RESET,
  106. PHY_FUNC_DISABLE,
  107. PHY_FUNC_CLEAR_ERROR_LOG = 5,
  108. PHY_FUNC_CLEAR_AFFIL,
  109. PHY_FUNC_TX_SATA_PS_SIGNAL,
  110. PHY_FUNC_RELEASE_SPINUP_HOLD = 0x10, /* LOCAL PORT ONLY! */
  111. PHY_FUNC_SET_LINK_RATE,
  112. };
  113. /* SAS LLDD would need to report only _very_few_ of those, like BROADCAST.
  114. * Most of those are here for completeness.
  115. */
  116. enum sas_prim {
  117. SAS_PRIM_AIP_NORMAL = 1,
  118. SAS_PRIM_AIP_R0 = 2,
  119. SAS_PRIM_AIP_R1 = 3,
  120. SAS_PRIM_AIP_R2 = 4,
  121. SAS_PRIM_AIP_WC = 5,
  122. SAS_PRIM_AIP_WD = 6,
  123. SAS_PRIM_AIP_WP = 7,
  124. SAS_PRIM_AIP_RWP = 8,
  125. SAS_PRIM_BC_CH = 9,
  126. SAS_PRIM_BC_RCH0 = 10,
  127. SAS_PRIM_BC_RCH1 = 11,
  128. SAS_PRIM_BC_R0 = 12,
  129. SAS_PRIM_BC_R1 = 13,
  130. SAS_PRIM_BC_R2 = 14,
  131. SAS_PRIM_BC_R3 = 15,
  132. SAS_PRIM_BC_R4 = 16,
  133. SAS_PRIM_NOTIFY_ENSP= 17,
  134. SAS_PRIM_NOTIFY_R0 = 18,
  135. SAS_PRIM_NOTIFY_R1 = 19,
  136. SAS_PRIM_NOTIFY_R2 = 20,
  137. SAS_PRIM_CLOSE_CLAF = 21,
  138. SAS_PRIM_CLOSE_NORM = 22,
  139. SAS_PRIM_CLOSE_R0 = 23,
  140. SAS_PRIM_CLOSE_R1 = 24,
  141. SAS_PRIM_OPEN_RTRY = 25,
  142. SAS_PRIM_OPEN_RJCT = 26,
  143. SAS_PRIM_OPEN_ACPT = 27,
  144. SAS_PRIM_DONE = 28,
  145. SAS_PRIM_BREAK = 29,
  146. SATA_PRIM_DMAT = 33,
  147. SATA_PRIM_PMNAK = 34,
  148. SATA_PRIM_PMACK = 35,
  149. SATA_PRIM_PMREQ_S = 36,
  150. SATA_PRIM_PMREQ_P = 37,
  151. SATA_SATA_R_ERR = 38,
  152. };
  153. enum sas_open_rej_reason {
  154. /* Abandon open */
  155. SAS_OREJ_UNKNOWN = 0,
  156. SAS_OREJ_BAD_DEST = 1,
  157. SAS_OREJ_CONN_RATE = 2,
  158. SAS_OREJ_EPROTO = 3,
  159. SAS_OREJ_RESV_AB0 = 4,
  160. SAS_OREJ_RESV_AB1 = 5,
  161. SAS_OREJ_RESV_AB2 = 6,
  162. SAS_OREJ_RESV_AB3 = 7,
  163. SAS_OREJ_WRONG_DEST= 8,
  164. SAS_OREJ_STP_NORES = 9,
  165. /* Retry open */
  166. SAS_OREJ_NO_DEST = 10,
  167. SAS_OREJ_PATH_BLOCKED = 11,
  168. SAS_OREJ_RSVD_CONT0 = 12,
  169. SAS_OREJ_RSVD_CONT1 = 13,
  170. SAS_OREJ_RSVD_INIT0 = 14,
  171. SAS_OREJ_RSVD_INIT1 = 15,
  172. SAS_OREJ_RSVD_STOP0 = 16,
  173. SAS_OREJ_RSVD_STOP1 = 17,
  174. SAS_OREJ_RSVD_RETRY = 18,
  175. };
  176. struct dev_to_host_fis {
  177. u8 fis_type; /* 0x34 */
  178. u8 flags;
  179. u8 status;
  180. u8 error;
  181. u8 lbal;
  182. union { u8 lbam; u8 byte_count_low; };
  183. union { u8 lbah; u8 byte_count_high; };
  184. u8 device;
  185. u8 lbal_exp;
  186. u8 lbam_exp;
  187. u8 lbah_exp;
  188. u8 _r_a;
  189. union { u8 sector_count; u8 interrupt_reason; };
  190. u8 sector_count_exp;
  191. u8 _r_b;
  192. u8 _r_c;
  193. u32 _r_d;
  194. } __attribute__ ((packed));
  195. struct host_to_dev_fis {
  196. u8 fis_type; /* 0x27 */
  197. u8 flags;
  198. u8 command;
  199. u8 features;
  200. u8 lbal;
  201. union { u8 lbam; u8 byte_count_low; };
  202. union { u8 lbah; u8 byte_count_high; };
  203. u8 device;
  204. u8 lbal_exp;
  205. u8 lbam_exp;
  206. u8 lbah_exp;
  207. u8 features_exp;
  208. union { u8 sector_count; u8 interrupt_reason; };
  209. u8 sector_count_exp;
  210. u8 _r_a;
  211. u8 control;
  212. u32 _r_b;
  213. } __attribute__ ((packed));
  214. /* Prefer to have code clarity over header file clarity.
  215. */
  216. #ifdef __LITTLE_ENDIAN_BITFIELD
  217. struct sas_identify_frame {
  218. /* Byte 0 */
  219. u8 frame_type:4;
  220. u8 dev_type:3;
  221. u8 _un0:1;
  222. /* Byte 1 */
  223. u8 _un1;
  224. /* Byte 2 */
  225. union {
  226. struct {
  227. u8 _un20:1;
  228. u8 smp_iport:1;
  229. u8 stp_iport:1;
  230. u8 ssp_iport:1;
  231. u8 _un247:4;
  232. };
  233. u8 initiator_bits;
  234. };
  235. /* Byte 3 */
  236. union {
  237. struct {
  238. u8 _un30:1;
  239. u8 smp_tport:1;
  240. u8 stp_tport:1;
  241. u8 ssp_tport:1;
  242. u8 _un347:4;
  243. };
  244. u8 target_bits;
  245. };
  246. /* Byte 4 - 11 */
  247. u8 _un4_11[8];
  248. /* Byte 12 - 19 */
  249. u8 sas_addr[SAS_ADDR_SIZE];
  250. /* Byte 20 */
  251. u8 phy_id;
  252. u8 _un21_27[7];
  253. __be32 crc;
  254. } __attribute__ ((packed));
  255. struct ssp_frame_hdr {
  256. u8 frame_type;
  257. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  258. u8 _r_a;
  259. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  260. __be16 _r_b;
  261. u8 changing_data_ptr:1;
  262. u8 retransmit:1;
  263. u8 retry_data_frames:1;
  264. u8 _r_c:5;
  265. u8 num_fill_bytes:2;
  266. u8 _r_d:6;
  267. u32 _r_e;
  268. __be16 tag;
  269. __be16 tptt;
  270. __be32 data_offs;
  271. } __attribute__ ((packed));
  272. struct ssp_response_iu {
  273. u8 _r_a[10];
  274. u8 datapres:2;
  275. u8 _r_b:6;
  276. u8 status;
  277. u32 _r_c;
  278. __be32 sense_data_len;
  279. __be32 response_data_len;
  280. u8 resp_data[0];
  281. u8 sense_data[0];
  282. } __attribute__ ((packed));
  283. /* ---------- SMP ---------- */
  284. struct report_general_resp {
  285. __be16 change_count;
  286. __be16 route_indexes;
  287. u8 _r_a;
  288. u8 num_phys;
  289. u8 conf_route_table:1;
  290. u8 configuring:1;
  291. u8 _r_b:6;
  292. u8 _r_c;
  293. u8 enclosure_logical_id[8];
  294. u8 _r_d[12];
  295. } __attribute__ ((packed));
  296. struct discover_resp {
  297. u8 _r_a[5];
  298. u8 phy_id;
  299. __be16 _r_b;
  300. u8 _r_c:4;
  301. u8 attached_dev_type:3;
  302. u8 _r_d:1;
  303. u8 linkrate:4;
  304. u8 _r_e:4;
  305. u8 attached_sata_host:1;
  306. u8 iproto:3;
  307. u8 _r_f:4;
  308. u8 attached_sata_dev:1;
  309. u8 tproto:3;
  310. u8 _r_g:3;
  311. u8 attached_sata_ps:1;
  312. u8 sas_addr[8];
  313. u8 attached_sas_addr[8];
  314. u8 attached_phy_id;
  315. u8 _r_h[7];
  316. u8 hmin_linkrate:4;
  317. u8 pmin_linkrate:4;
  318. u8 hmax_linkrate:4;
  319. u8 pmax_linkrate:4;
  320. u8 change_count;
  321. u8 pptv:4;
  322. u8 _r_i:3;
  323. u8 virtual:1;
  324. u8 routing_attr:4;
  325. u8 _r_j:4;
  326. u8 conn_type;
  327. u8 conn_el_index;
  328. u8 conn_phy_link;
  329. u8 _r_k[8];
  330. } __attribute__ ((packed));
  331. struct report_phy_sata_resp {
  332. u8 _r_a[5];
  333. u8 phy_id;
  334. u8 _r_b;
  335. u8 affil_valid:1;
  336. u8 affil_supp:1;
  337. u8 _r_c:6;
  338. u32 _r_d;
  339. u8 stp_sas_addr[8];
  340. struct dev_to_host_fis fis;
  341. u32 _r_e;
  342. u8 affil_stp_ini_addr[8];
  343. __be32 crc;
  344. } __attribute__ ((packed));
  345. struct smp_resp {
  346. u8 frame_type;
  347. u8 function;
  348. u8 result;
  349. u8 reserved;
  350. union {
  351. struct report_general_resp rg;
  352. struct discover_resp disc;
  353. struct report_phy_sata_resp rps;
  354. };
  355. } __attribute__ ((packed));
  356. #elif defined(__BIG_ENDIAN_BITFIELD)
  357. struct sas_identify_frame {
  358. /* Byte 0 */
  359. u8 _un0:1;
  360. u8 dev_type:3;
  361. u8 frame_type:4;
  362. /* Byte 1 */
  363. u8 _un1;
  364. /* Byte 2 */
  365. union {
  366. struct {
  367. u8 _un247:4;
  368. u8 ssp_iport:1;
  369. u8 stp_iport:1;
  370. u8 smp_iport:1;
  371. u8 _un20:1;
  372. };
  373. u8 initiator_bits;
  374. };
  375. /* Byte 3 */
  376. union {
  377. struct {
  378. u8 _un347:4;
  379. u8 ssp_tport:1;
  380. u8 stp_tport:1;
  381. u8 smp_tport:1;
  382. u8 _un30:1;
  383. };
  384. u8 target_bits;
  385. };
  386. /* Byte 4 - 11 */
  387. u8 _un4_11[8];
  388. /* Byte 12 - 19 */
  389. u8 sas_addr[SAS_ADDR_SIZE];
  390. /* Byte 20 */
  391. u8 phy_id;
  392. u8 _un21_27[7];
  393. __be32 crc;
  394. } __attribute__ ((packed));
  395. struct ssp_frame_hdr {
  396. u8 frame_type;
  397. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  398. u8 _r_a;
  399. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  400. __be16 _r_b;
  401. u8 _r_c:5;
  402. u8 retry_data_frames:1;
  403. u8 retransmit:1;
  404. u8 changing_data_ptr:1;
  405. u8 _r_d:6;
  406. u8 num_fill_bytes:2;
  407. u32 _r_e;
  408. __be16 tag;
  409. __be16 tptt;
  410. __be32 data_offs;
  411. } __attribute__ ((packed));
  412. struct ssp_response_iu {
  413. u8 _r_a[10];
  414. u8 _r_b:6;
  415. u8 datapres:2;
  416. u8 status;
  417. u32 _r_c;
  418. __be32 sense_data_len;
  419. __be32 response_data_len;
  420. u8 resp_data[0];
  421. u8 sense_data[0];
  422. } __attribute__ ((packed));
  423. /* ---------- SMP ---------- */
  424. struct report_general_resp {
  425. __be16 change_count;
  426. __be16 route_indexes;
  427. u8 _r_a;
  428. u8 num_phys;
  429. u8 _r_b:6;
  430. u8 configuring:1;
  431. u8 conf_route_table:1;
  432. u8 _r_c;
  433. u8 enclosure_logical_id[8];
  434. u8 _r_d[12];
  435. } __attribute__ ((packed));
  436. struct discover_resp {
  437. u8 _r_a[5];
  438. u8 phy_id;
  439. __be16 _r_b;
  440. u8 _r_d:1;
  441. u8 attached_dev_type:3;
  442. u8 _r_c:4;
  443. u8 _r_e:4;
  444. u8 linkrate:4;
  445. u8 _r_f:4;
  446. u8 iproto:3;
  447. u8 attached_sata_host:1;
  448. u8 attached_sata_ps:1;
  449. u8 _r_g:3;
  450. u8 tproto:3;
  451. u8 attached_sata_dev:1;
  452. u8 sas_addr[8];
  453. u8 attached_sas_addr[8];
  454. u8 attached_phy_id;
  455. u8 _r_h[7];
  456. u8 pmin_linkrate:4;
  457. u8 hmin_linkrate:4;
  458. u8 pmax_linkrate:4;
  459. u8 hmax_linkrate:4;
  460. u8 change_count;
  461. u8 virtual:1;
  462. u8 _r_i:3;
  463. u8 pptv:4;
  464. u8 _r_j:4;
  465. u8 routing_attr:4;
  466. u8 conn_type;
  467. u8 conn_el_index;
  468. u8 conn_phy_link;
  469. u8 _r_k[8];
  470. } __attribute__ ((packed));
  471. struct report_phy_sata_resp {
  472. u8 _r_a[5];
  473. u8 phy_id;
  474. u8 _r_b;
  475. u8 _r_c:6;
  476. u8 affil_supp:1;
  477. u8 affil_valid:1;
  478. u32 _r_d;
  479. u8 stp_sas_addr[8];
  480. struct dev_to_host_fis fis;
  481. u32 _r_e;
  482. u8 affil_stp_ini_addr[8];
  483. __be32 crc;
  484. } __attribute__ ((packed));
  485. struct smp_resp {
  486. u8 frame_type;
  487. u8 function;
  488. u8 result;
  489. u8 reserved;
  490. union {
  491. struct report_general_resp rg;
  492. struct discover_resp disc;
  493. struct report_phy_sata_resp rps;
  494. };
  495. } __attribute__ ((packed));
  496. #else
  497. #error "Bitfield order not defined!"
  498. #endif
  499. #endif /* _SAS_H_ */