scsi_transport_sas.h 6.8 KB

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