scsi_transport_sas.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef SCSI_TRANSPORT_SAS_H
  2. #define SCSI_TRANSPORT_SAS_H
  3. #include <linux/transport_class.h>
  4. #include <linux/types.h>
  5. struct scsi_transport_template;
  6. struct sas_rphy;
  7. enum sas_device_type {
  8. SAS_PHY_UNUSED,
  9. SAS_END_DEVICE,
  10. SAS_EDGE_EXPANDER_DEVICE,
  11. SAS_FANOUT_EXPANDER_DEVICE,
  12. };
  13. enum sas_protocol {
  14. SAS_PROTOCOL_SATA = 0x01,
  15. SAS_PROTOCOL_SMP = 0x02,
  16. SAS_PROTOCOL_STP = 0x04,
  17. SAS_PROTOCOL_SSP = 0x08,
  18. };
  19. enum sas_linkrate {
  20. SAS_LINK_RATE_UNKNOWN,
  21. SAS_PHY_DISABLED,
  22. SAS_LINK_RATE_FAILED,
  23. SAS_SATA_SPINUP_HOLD,
  24. SAS_SATA_PORT_SELECTOR,
  25. SAS_LINK_RATE_1_5_GBPS,
  26. SAS_LINK_RATE_3_0_GBPS,
  27. SAS_LINK_RATE_6_0_GBPS,
  28. SAS_LINK_VIRTUAL,
  29. };
  30. struct sas_identify {
  31. enum sas_device_type device_type;
  32. enum sas_protocol initiator_port_protocols;
  33. enum sas_protocol target_port_protocols;
  34. u64 sas_address;
  35. u8 phy_identifier;
  36. };
  37. struct sas_phy {
  38. struct device dev;
  39. int number;
  40. /* phy identification */
  41. struct sas_identify identify;
  42. /* phy attributes */
  43. enum sas_linkrate negotiated_linkrate;
  44. enum sas_linkrate minimum_linkrate_hw;
  45. enum sas_linkrate minimum_linkrate;
  46. enum sas_linkrate maximum_linkrate_hw;
  47. enum sas_linkrate maximum_linkrate;
  48. u8 port_identifier;
  49. /* internal state */
  50. unsigned int local_attached : 1;
  51. /* link error statistics */
  52. u32 invalid_dword_count;
  53. u32 running_disparity_error_count;
  54. u32 loss_of_dword_sync_count;
  55. u32 phy_reset_problem_count;
  56. /* the other end of the link */
  57. struct sas_rphy *rphy;
  58. };
  59. #define dev_to_phy(d) \
  60. container_of((d), struct sas_phy, dev)
  61. #define transport_class_to_phy(cdev) \
  62. dev_to_phy((cdev)->dev)
  63. #define phy_to_shost(phy) \
  64. dev_to_shost((phy)->dev.parent)
  65. struct sas_rphy {
  66. struct device dev;
  67. struct sas_identify identify;
  68. struct list_head list;
  69. u32 scsi_target_id;
  70. /* temporary expedient: mark the rphy as being contained
  71. * within a type specific rphy
  72. * FIXME: pull this out when everything uses the containers */
  73. unsigned contained:1;
  74. };
  75. #define dev_to_rphy(d) \
  76. container_of((d), struct sas_rphy, dev)
  77. #define transport_class_to_rphy(cdev) \
  78. dev_to_rphy((cdev)->dev)
  79. #define rphy_to_shost(rphy) \
  80. dev_to_shost((rphy)->dev.parent)
  81. #define target_to_rphy(targ) \
  82. dev_to_rphy((targ)->dev.parent)
  83. struct sas_end_device {
  84. struct sas_rphy rphy;
  85. /* flags */
  86. unsigned ready_led_meaning:1;
  87. /* parameters */
  88. u16 I_T_nexus_loss_timeout;
  89. u16 initiator_response_timeout;
  90. };
  91. #define rphy_to_end_device(r) \
  92. container_of((r), struct sas_end_device, rphy)
  93. struct sas_expander_device {
  94. int level;
  95. #define SAS_EXPANDER_VENDOR_ID_LEN 8
  96. char vendor_id[SAS_EXPANDER_VENDOR_ID_LEN+1];
  97. #define SAS_EXPANDER_PRODUCT_ID_LEN 16
  98. char product_id[SAS_EXPANDER_PRODUCT_ID_LEN+1];
  99. #define SAS_EXPANDER_PRODUCT_REV_LEN 4
  100. char product_rev[SAS_EXPANDER_PRODUCT_REV_LEN+1];
  101. #define SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN 8
  102. char component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN+1];
  103. u16 component_id;
  104. u8 component_revision_id;
  105. struct sas_rphy rphy;
  106. };
  107. #define rphy_to_expander_device(r) \
  108. container_of((r), struct sas_expander_device, rphy)
  109. /* The functions by which the transport class and the driver communicate */
  110. struct sas_function_template {
  111. int (*get_linkerrors)(struct sas_phy *);
  112. int (*get_enclosure_identifier)(struct sas_rphy *, u64 *);
  113. int (*get_bay_identifier)(struct sas_rphy *);
  114. int (*phy_reset)(struct sas_phy *, int);
  115. };
  116. extern void sas_remove_host(struct Scsi_Host *);
  117. extern struct sas_phy *sas_phy_alloc(struct device *, int);
  118. extern void sas_phy_free(struct sas_phy *);
  119. extern int sas_phy_add(struct sas_phy *);
  120. extern void sas_phy_delete(struct sas_phy *);
  121. extern int scsi_is_sas_phy(const struct device *);
  122. extern struct sas_rphy *sas_rphy_alloc(struct sas_phy *);
  123. extern struct sas_rphy *sas_end_device_alloc(struct sas_phy *);
  124. extern struct sas_rphy *sas_expander_alloc(struct sas_phy *, enum sas_device_type);
  125. void sas_rphy_free(struct sas_rphy *);
  126. extern int sas_rphy_add(struct sas_rphy *);
  127. extern void sas_rphy_delete(struct sas_rphy *);
  128. extern int scsi_is_sas_rphy(const struct device *);
  129. extern struct scsi_transport_template *
  130. sas_attach_transport(struct sas_function_template *);
  131. extern void sas_release_transport(struct scsi_transport_template *);
  132. int sas_read_port_mode_page(struct scsi_device *);
  133. static inline int
  134. scsi_is_sas_expander_device(struct device *dev)
  135. {
  136. struct sas_rphy *rphy;
  137. if (!scsi_is_sas_rphy(dev))
  138. return 0;
  139. rphy = dev_to_rphy(dev);
  140. return rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE ||
  141. rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE;
  142. }
  143. #endif /* SCSI_TRANSPORT_SAS_H */