scsi_transport_sas.h 6.3 KB

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