sas.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. SAS_PROTOCOL_STP_ALL = SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA,
  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. enum sas_gpio_reg_type {
  177. SAS_GPIO_REG_CFG = 0,
  178. SAS_GPIO_REG_RX = 1,
  179. SAS_GPIO_REG_RX_GP = 2,
  180. SAS_GPIO_REG_TX = 3,
  181. SAS_GPIO_REG_TX_GP = 4,
  182. };
  183. struct dev_to_host_fis {
  184. u8 fis_type; /* 0x34 */
  185. u8 flags;
  186. u8 status;
  187. u8 error;
  188. u8 lbal;
  189. union { u8 lbam; u8 byte_count_low; };
  190. union { u8 lbah; u8 byte_count_high; };
  191. u8 device;
  192. u8 lbal_exp;
  193. u8 lbam_exp;
  194. u8 lbah_exp;
  195. u8 _r_a;
  196. union { u8 sector_count; u8 interrupt_reason; };
  197. u8 sector_count_exp;
  198. u8 _r_b;
  199. u8 _r_c;
  200. u32 _r_d;
  201. } __attribute__ ((packed));
  202. struct host_to_dev_fis {
  203. u8 fis_type; /* 0x27 */
  204. u8 flags;
  205. u8 command;
  206. u8 features;
  207. u8 lbal;
  208. union { u8 lbam; u8 byte_count_low; };
  209. union { u8 lbah; u8 byte_count_high; };
  210. u8 device;
  211. u8 lbal_exp;
  212. u8 lbam_exp;
  213. u8 lbah_exp;
  214. u8 features_exp;
  215. union { u8 sector_count; u8 interrupt_reason; };
  216. u8 sector_count_exp;
  217. u8 _r_a;
  218. u8 control;
  219. u32 _r_b;
  220. } __attribute__ ((packed));
  221. /* Prefer to have code clarity over header file clarity.
  222. */
  223. #ifdef __LITTLE_ENDIAN_BITFIELD
  224. struct sas_identify_frame {
  225. /* Byte 0 */
  226. u8 frame_type:4;
  227. u8 dev_type:3;
  228. u8 _un0:1;
  229. /* Byte 1 */
  230. u8 _un1;
  231. /* Byte 2 */
  232. union {
  233. struct {
  234. u8 _un20:1;
  235. u8 smp_iport:1;
  236. u8 stp_iport:1;
  237. u8 ssp_iport:1;
  238. u8 _un247:4;
  239. };
  240. u8 initiator_bits;
  241. };
  242. /* Byte 3 */
  243. union {
  244. struct {
  245. u8 _un30:1;
  246. u8 smp_tport:1;
  247. u8 stp_tport:1;
  248. u8 ssp_tport:1;
  249. u8 _un347:4;
  250. };
  251. u8 target_bits;
  252. };
  253. /* Byte 4 - 11 */
  254. u8 _un4_11[8];
  255. /* Byte 12 - 19 */
  256. u8 sas_addr[SAS_ADDR_SIZE];
  257. /* Byte 20 */
  258. u8 phy_id;
  259. u8 _un21_27[7];
  260. __be32 crc;
  261. } __attribute__ ((packed));
  262. struct ssp_frame_hdr {
  263. u8 frame_type;
  264. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  265. u8 _r_a;
  266. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  267. __be16 _r_b;
  268. u8 changing_data_ptr:1;
  269. u8 retransmit:1;
  270. u8 retry_data_frames:1;
  271. u8 _r_c:5;
  272. u8 num_fill_bytes:2;
  273. u8 _r_d:6;
  274. u32 _r_e;
  275. __be16 tag;
  276. __be16 tptt;
  277. __be32 data_offs;
  278. } __attribute__ ((packed));
  279. struct ssp_response_iu {
  280. u8 _r_a[10];
  281. u8 datapres:2;
  282. u8 _r_b:6;
  283. u8 status;
  284. u32 _r_c;
  285. __be32 sense_data_len;
  286. __be32 response_data_len;
  287. u8 resp_data[0];
  288. u8 sense_data[0];
  289. } __attribute__ ((packed));
  290. /* ---------- SMP ---------- */
  291. struct report_general_resp {
  292. __be16 change_count;
  293. __be16 route_indexes;
  294. u8 _r_a;
  295. u8 num_phys;
  296. u8 conf_route_table:1;
  297. u8 configuring:1;
  298. u8 config_others:1;
  299. u8 orej_retry_supp:1;
  300. u8 stp_cont_awt:1;
  301. u8 self_config:1;
  302. u8 zone_config:1;
  303. u8 t2t_supp:1;
  304. u8 _r_c;
  305. u8 enclosure_logical_id[8];
  306. u8 _r_d[12];
  307. } __attribute__ ((packed));
  308. struct discover_resp {
  309. u8 _r_a[5];
  310. u8 phy_id;
  311. __be16 _r_b;
  312. u8 _r_c:4;
  313. u8 attached_dev_type:3;
  314. u8 _r_d:1;
  315. u8 linkrate:4;
  316. u8 _r_e:4;
  317. u8 attached_sata_host:1;
  318. u8 iproto:3;
  319. u8 _r_f:4;
  320. u8 attached_sata_dev:1;
  321. u8 tproto:3;
  322. u8 _r_g:3;
  323. u8 attached_sata_ps:1;
  324. u8 sas_addr[8];
  325. u8 attached_sas_addr[8];
  326. u8 attached_phy_id;
  327. u8 _r_h[7];
  328. u8 hmin_linkrate:4;
  329. u8 pmin_linkrate:4;
  330. u8 hmax_linkrate:4;
  331. u8 pmax_linkrate:4;
  332. u8 change_count;
  333. u8 pptv:4;
  334. u8 _r_i:3;
  335. u8 virtual:1;
  336. u8 routing_attr:4;
  337. u8 _r_j:4;
  338. u8 conn_type;
  339. u8 conn_el_index;
  340. u8 conn_phy_link;
  341. u8 _r_k[8];
  342. } __attribute__ ((packed));
  343. struct report_phy_sata_resp {
  344. u8 _r_a[5];
  345. u8 phy_id;
  346. u8 _r_b;
  347. u8 affil_valid:1;
  348. u8 affil_supp:1;
  349. u8 _r_c:6;
  350. u32 _r_d;
  351. u8 stp_sas_addr[8];
  352. struct dev_to_host_fis fis;
  353. u32 _r_e;
  354. u8 affil_stp_ini_addr[8];
  355. __be32 crc;
  356. } __attribute__ ((packed));
  357. struct smp_resp {
  358. u8 frame_type;
  359. u8 function;
  360. u8 result;
  361. u8 reserved;
  362. union {
  363. struct report_general_resp rg;
  364. struct discover_resp disc;
  365. struct report_phy_sata_resp rps;
  366. };
  367. } __attribute__ ((packed));
  368. #elif defined(__BIG_ENDIAN_BITFIELD)
  369. struct sas_identify_frame {
  370. /* Byte 0 */
  371. u8 _un0:1;
  372. u8 dev_type:3;
  373. u8 frame_type:4;
  374. /* Byte 1 */
  375. u8 _un1;
  376. /* Byte 2 */
  377. union {
  378. struct {
  379. u8 _un247:4;
  380. u8 ssp_iport:1;
  381. u8 stp_iport:1;
  382. u8 smp_iport:1;
  383. u8 _un20:1;
  384. };
  385. u8 initiator_bits;
  386. };
  387. /* Byte 3 */
  388. union {
  389. struct {
  390. u8 _un347:4;
  391. u8 ssp_tport:1;
  392. u8 stp_tport:1;
  393. u8 smp_tport:1;
  394. u8 _un30:1;
  395. };
  396. u8 target_bits;
  397. };
  398. /* Byte 4 - 11 */
  399. u8 _un4_11[8];
  400. /* Byte 12 - 19 */
  401. u8 sas_addr[SAS_ADDR_SIZE];
  402. /* Byte 20 */
  403. u8 phy_id;
  404. u8 _un21_27[7];
  405. __be32 crc;
  406. } __attribute__ ((packed));
  407. struct ssp_frame_hdr {
  408. u8 frame_type;
  409. u8 hashed_dest_addr[HASHED_SAS_ADDR_SIZE];
  410. u8 _r_a;
  411. u8 hashed_src_addr[HASHED_SAS_ADDR_SIZE];
  412. __be16 _r_b;
  413. u8 _r_c:5;
  414. u8 retry_data_frames:1;
  415. u8 retransmit:1;
  416. u8 changing_data_ptr:1;
  417. u8 _r_d:6;
  418. u8 num_fill_bytes:2;
  419. u32 _r_e;
  420. __be16 tag;
  421. __be16 tptt;
  422. __be32 data_offs;
  423. } __attribute__ ((packed));
  424. struct ssp_response_iu {
  425. u8 _r_a[10];
  426. u8 _r_b:6;
  427. u8 datapres:2;
  428. u8 status;
  429. u32 _r_c;
  430. __be32 sense_data_len;
  431. __be32 response_data_len;
  432. u8 resp_data[0];
  433. u8 sense_data[0];
  434. } __attribute__ ((packed));
  435. /* ---------- SMP ---------- */
  436. struct report_general_resp {
  437. __be16 change_count;
  438. __be16 route_indexes;
  439. u8 _r_a;
  440. u8 num_phys;
  441. u8 t2t_supp:1;
  442. u8 zone_config:1;
  443. u8 self_config:1;
  444. u8 stp_cont_awt:1;
  445. u8 orej_retry_supp:1;
  446. u8 config_others:1;
  447. u8 configuring:1;
  448. u8 conf_route_table:1;
  449. u8 _r_c;
  450. u8 enclosure_logical_id[8];
  451. u8 _r_d[12];
  452. } __attribute__ ((packed));
  453. struct discover_resp {
  454. u8 _r_a[5];
  455. u8 phy_id;
  456. __be16 _r_b;
  457. u8 _r_d:1;
  458. u8 attached_dev_type:3;
  459. u8 _r_c:4;
  460. u8 _r_e:4;
  461. u8 linkrate:4;
  462. u8 _r_f:4;
  463. u8 iproto:3;
  464. u8 attached_sata_host:1;
  465. u8 attached_sata_ps:1;
  466. u8 _r_g:3;
  467. u8 tproto:3;
  468. u8 attached_sata_dev:1;
  469. u8 sas_addr[8];
  470. u8 attached_sas_addr[8];
  471. u8 attached_phy_id;
  472. u8 _r_h[7];
  473. u8 pmin_linkrate:4;
  474. u8 hmin_linkrate:4;
  475. u8 pmax_linkrate:4;
  476. u8 hmax_linkrate:4;
  477. u8 change_count;
  478. u8 virtual:1;
  479. u8 _r_i:3;
  480. u8 pptv:4;
  481. u8 _r_j:4;
  482. u8 routing_attr:4;
  483. u8 conn_type;
  484. u8 conn_el_index;
  485. u8 conn_phy_link;
  486. u8 _r_k[8];
  487. } __attribute__ ((packed));
  488. struct report_phy_sata_resp {
  489. u8 _r_a[5];
  490. u8 phy_id;
  491. u8 _r_b;
  492. u8 _r_c:6;
  493. u8 affil_supp:1;
  494. u8 affil_valid:1;
  495. u32 _r_d;
  496. u8 stp_sas_addr[8];
  497. struct dev_to_host_fis fis;
  498. u32 _r_e;
  499. u8 affil_stp_ini_addr[8];
  500. __be32 crc;
  501. } __attribute__ ((packed));
  502. struct smp_resp {
  503. u8 frame_type;
  504. u8 function;
  505. u8 result;
  506. u8 reserved;
  507. union {
  508. struct report_general_resp rg;
  509. struct discover_resp disc;
  510. struct report_phy_sata_resp rps;
  511. };
  512. } __attribute__ ((packed));
  513. #else
  514. #error "Bitfield order not defined!"
  515. #endif
  516. #endif /* _SAS_H_ */