scsi_transport_sas.h 5.2 KB

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