scsi_transport_sas.h 6.5 KB

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