scsi_transport_sas.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #ifndef SCSI_TRANSPORT_SAS_H
  2. #define SCSI_TRANSPORT_SAS_H
  3. #include <linux/transport_class.h>
  4. #include <linux/types.h>
  5. #include <linux/mutex.h>
  6. #include <scsi/sas.h>
  7. #include <linux/bsg-lib.h>
  8. struct scsi_transport_template;
  9. struct sas_rphy;
  10. struct request;
  11. #if !IS_ENABLED(CONFIG_SCSI_SAS_ATTRS)
  12. static inline int scsi_is_sas_rphy(const struct device *sdev)
  13. {
  14. return 0;
  15. }
  16. #else
  17. extern int scsi_is_sas_rphy(const struct device *);
  18. #endif
  19. static inline int sas_protocol_ata(enum sas_protocol proto)
  20. {
  21. return ((proto & SAS_PROTOCOL_SATA) ||
  22. (proto & SAS_PROTOCOL_STP))? 1 : 0;
  23. }
  24. enum sas_linkrate {
  25. /* These Values are defined in the SAS standard */
  26. SAS_LINK_RATE_UNKNOWN = 0,
  27. SAS_PHY_DISABLED = 1,
  28. SAS_PHY_RESET_PROBLEM = 2,
  29. SAS_SATA_SPINUP_HOLD = 3,
  30. SAS_SATA_PORT_SELECTOR = 4,
  31. SAS_PHY_RESET_IN_PROGRESS = 5,
  32. SAS_LINK_RATE_1_5_GBPS = 8,
  33. SAS_LINK_RATE_G1 = SAS_LINK_RATE_1_5_GBPS,
  34. SAS_LINK_RATE_3_0_GBPS = 9,
  35. SAS_LINK_RATE_G2 = SAS_LINK_RATE_3_0_GBPS,
  36. SAS_LINK_RATE_6_0_GBPS = 10,
  37. SAS_LINK_RATE_12_0_GBPS = 11,
  38. /* These are virtual to the transport class and may never
  39. * be signalled normally since the standard defined field
  40. * is only 4 bits */
  41. SAS_LINK_RATE_FAILED = 0x10,
  42. SAS_PHY_VIRTUAL = 0x11,
  43. };
  44. struct sas_identify {
  45. enum sas_device_type device_type;
  46. enum sas_protocol initiator_port_protocols;
  47. enum sas_protocol target_port_protocols;
  48. u64 sas_address;
  49. u8 phy_identifier;
  50. };
  51. struct sas_phy {
  52. struct device dev;
  53. int number;
  54. int enabled;
  55. /* phy identification */
  56. struct sas_identify identify;
  57. /* phy attributes */
  58. enum sas_linkrate negotiated_linkrate;
  59. enum sas_linkrate minimum_linkrate_hw;
  60. enum sas_linkrate minimum_linkrate;
  61. enum sas_linkrate maximum_linkrate_hw;
  62. enum sas_linkrate maximum_linkrate;
  63. /* link error statistics */
  64. u32 invalid_dword_count;
  65. u32 running_disparity_error_count;
  66. u32 loss_of_dword_sync_count;
  67. u32 phy_reset_problem_count;
  68. /* for the list of phys belonging to a port */
  69. struct list_head port_siblings;
  70. /* available to the lldd */
  71. void *hostdata;
  72. };
  73. #define dev_to_phy(d) \
  74. container_of((d), struct sas_phy, dev)
  75. #define transport_class_to_phy(dev) \
  76. dev_to_phy((dev)->parent)
  77. #define phy_to_shost(phy) \
  78. dev_to_shost((phy)->dev.parent)
  79. struct request_queue;
  80. struct sas_rphy {
  81. struct device dev;
  82. struct sas_identify identify;
  83. struct list_head list;
  84. struct request_queue *q;
  85. u32 scsi_target_id;
  86. };
  87. #define dev_to_rphy(d) \
  88. container_of((d), struct sas_rphy, dev)
  89. #define transport_class_to_rphy(dev) \
  90. dev_to_rphy((dev)->parent)
  91. #define rphy_to_shost(rphy) \
  92. dev_to_shost((rphy)->dev.parent)
  93. #define target_to_rphy(targ) \
  94. dev_to_rphy((targ)->dev.parent)
  95. struct sas_end_device {
  96. struct sas_rphy rphy;
  97. /* flags */
  98. unsigned ready_led_meaning:1;
  99. unsigned tlr_supported:1;
  100. unsigned tlr_enabled:1;
  101. /* parameters */
  102. u16 I_T_nexus_loss_timeout;
  103. u16 initiator_response_timeout;
  104. };
  105. #define rphy_to_end_device(r) \
  106. container_of((r), struct sas_end_device, rphy)
  107. struct sas_expander_device {
  108. int level;
  109. int next_port_id;
  110. #define SAS_EXPANDER_VENDOR_ID_LEN 8
  111. char vendor_id[SAS_EXPANDER_VENDOR_ID_LEN+1];
  112. #define SAS_EXPANDER_PRODUCT_ID_LEN 16
  113. char product_id[SAS_EXPANDER_PRODUCT_ID_LEN+1];
  114. #define SAS_EXPANDER_PRODUCT_REV_LEN 4
  115. char product_rev[SAS_EXPANDER_PRODUCT_REV_LEN+1];
  116. #define SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN 8
  117. char component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN+1];
  118. u16 component_id;
  119. u8 component_revision_id;
  120. struct sas_rphy rphy;
  121. };
  122. #define rphy_to_expander_device(r) \
  123. container_of((r), struct sas_expander_device, rphy)
  124. struct sas_port {
  125. struct device dev;
  126. int port_identifier;
  127. int num_phys;
  128. /* port flags */
  129. unsigned int is_backlink:1;
  130. /* the other end of the link */
  131. struct sas_rphy *rphy;
  132. struct mutex phy_list_mutex;
  133. struct list_head phy_list;
  134. };
  135. #define dev_to_sas_port(d) \
  136. container_of((d), struct sas_port, dev)
  137. #define transport_class_to_sas_port(dev) \
  138. dev_to_sas_port((dev)->parent)
  139. struct sas_phy_linkrates {
  140. enum sas_linkrate maximum_linkrate;
  141. enum sas_linkrate minimum_linkrate;
  142. };
  143. /* The functions by which the transport class and the driver communicate */
  144. struct sas_function_template {
  145. int (*get_linkerrors)(struct sas_phy *);
  146. int (*get_enclosure_identifier)(struct sas_rphy *, u64 *);
  147. int (*get_bay_identifier)(struct sas_rphy *);
  148. int (*phy_reset)(struct sas_phy *, int);
  149. int (*phy_enable)(struct sas_phy *, int);
  150. int (*phy_setup)(struct sas_phy *);
  151. void (*phy_release)(struct sas_phy *);
  152. int (*set_phy_speed)(struct sas_phy *, struct sas_phy_linkrates *);
  153. void (*smp_handler)(struct bsg_job *, struct Scsi_Host *,
  154. struct sas_rphy *);
  155. };
  156. void sas_remove_children(struct device *);
  157. extern void sas_remove_host(struct Scsi_Host *);
  158. extern struct sas_phy *sas_phy_alloc(struct device *, int);
  159. extern void sas_phy_free(struct sas_phy *);
  160. extern int sas_phy_add(struct sas_phy *);
  161. extern void sas_phy_delete(struct sas_phy *);
  162. extern int scsi_is_sas_phy(const struct device *);
  163. u64 sas_get_address(struct scsi_device *);
  164. unsigned int sas_tlr_supported(struct scsi_device *);
  165. unsigned int sas_is_tlr_enabled(struct scsi_device *);
  166. void sas_disable_tlr(struct scsi_device *);
  167. void sas_enable_tlr(struct scsi_device *);
  168. extern struct sas_rphy *sas_end_device_alloc(struct sas_port *);
  169. extern struct sas_rphy *sas_expander_alloc(struct sas_port *, enum sas_device_type);
  170. void sas_rphy_free(struct sas_rphy *);
  171. extern int sas_rphy_add(struct sas_rphy *);
  172. extern void sas_rphy_remove(struct sas_rphy *);
  173. extern void sas_rphy_delete(struct sas_rphy *);
  174. extern void sas_rphy_unlink(struct sas_rphy *);
  175. struct sas_port *sas_port_alloc(struct device *, int);
  176. struct sas_port *sas_port_alloc_num(struct device *);
  177. int sas_port_add(struct sas_port *);
  178. void sas_port_free(struct sas_port *);
  179. void sas_port_delete(struct sas_port *);
  180. void sas_port_add_phy(struct sas_port *, struct sas_phy *);
  181. void sas_port_delete_phy(struct sas_port *, struct sas_phy *);
  182. void sas_port_mark_backlink(struct sas_port *);
  183. int scsi_is_sas_port(const struct device *);
  184. struct sas_phy *sas_port_get_phy(struct sas_port *port);
  185. static inline void sas_port_put_phy(struct sas_phy *phy)
  186. {
  187. if (phy)
  188. put_device(&phy->dev);
  189. }
  190. extern struct scsi_transport_template *
  191. sas_attach_transport(struct sas_function_template *);
  192. extern void sas_release_transport(struct scsi_transport_template *);
  193. int sas_read_port_mode_page(struct scsi_device *);
  194. static inline int
  195. scsi_is_sas_expander_device(struct device *dev)
  196. {
  197. struct sas_rphy *rphy;
  198. if (!scsi_is_sas_rphy(dev))
  199. return 0;
  200. rphy = dev_to_rphy(dev);
  201. return rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE ||
  202. rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE;
  203. }
  204. #define scsi_is_sas_phy_local(phy) scsi_is_host_device((phy)->dev.parent)
  205. #endif /* SCSI_TRANSPORT_SAS_H */