0001
0002 #ifndef SCSI_TRANSPORT_SAS_H
0003 #define SCSI_TRANSPORT_SAS_H
0004
0005 #include <linux/transport_class.h>
0006 #include <linux/types.h>
0007 #include <linux/mutex.h>
0008 #include <scsi/sas.h>
0009 #include <linux/bsg-lib.h>
0010
0011 struct scsi_transport_template;
0012 struct sas_rphy;
0013 struct request;
0014
0015 #if !IS_ENABLED(CONFIG_SCSI_SAS_ATTRS)
0016 static inline int scsi_is_sas_rphy(const struct device *sdev)
0017 {
0018 return 0;
0019 }
0020 #else
0021 extern int scsi_is_sas_rphy(const struct device *);
0022 #endif
0023
0024 static inline int sas_protocol_ata(enum sas_protocol proto)
0025 {
0026 return ((proto & SAS_PROTOCOL_SATA) ||
0027 (proto & SAS_PROTOCOL_STP))? 1 : 0;
0028 }
0029
0030 enum sas_linkrate {
0031
0032 SAS_LINK_RATE_UNKNOWN = 0,
0033 SAS_PHY_DISABLED = 1,
0034 SAS_PHY_RESET_PROBLEM = 2,
0035 SAS_SATA_SPINUP_HOLD = 3,
0036 SAS_SATA_PORT_SELECTOR = 4,
0037 SAS_PHY_RESET_IN_PROGRESS = 5,
0038 SAS_LINK_RATE_1_5_GBPS = 8,
0039 SAS_LINK_RATE_G1 = SAS_LINK_RATE_1_5_GBPS,
0040 SAS_LINK_RATE_3_0_GBPS = 9,
0041 SAS_LINK_RATE_G2 = SAS_LINK_RATE_3_0_GBPS,
0042 SAS_LINK_RATE_6_0_GBPS = 10,
0043 SAS_LINK_RATE_12_0_GBPS = 11,
0044 SAS_LINK_RATE_22_5_GBPS = 12,
0045
0046
0047
0048 SAS_LINK_RATE_FAILED = 0x10,
0049 SAS_PHY_VIRTUAL = 0x11,
0050 };
0051
0052 struct sas_identify {
0053 enum sas_device_type device_type;
0054 enum sas_protocol initiator_port_protocols;
0055 enum sas_protocol target_port_protocols;
0056 u64 sas_address;
0057 u8 phy_identifier;
0058 };
0059
0060 struct sas_phy {
0061 struct device dev;
0062 int number;
0063 int enabled;
0064
0065
0066 struct sas_identify identify;
0067
0068
0069 enum sas_linkrate negotiated_linkrate;
0070 enum sas_linkrate minimum_linkrate_hw;
0071 enum sas_linkrate minimum_linkrate;
0072 enum sas_linkrate maximum_linkrate_hw;
0073 enum sas_linkrate maximum_linkrate;
0074
0075
0076 u32 invalid_dword_count;
0077 u32 running_disparity_error_count;
0078 u32 loss_of_dword_sync_count;
0079 u32 phy_reset_problem_count;
0080
0081
0082 struct list_head port_siblings;
0083
0084
0085 void *hostdata;
0086 };
0087
0088 #define dev_to_phy(d) \
0089 container_of((d), struct sas_phy, dev)
0090 #define transport_class_to_phy(dev) \
0091 dev_to_phy((dev)->parent)
0092 #define phy_to_shost(phy) \
0093 dev_to_shost((phy)->dev.parent)
0094
0095 struct request_queue;
0096 struct sas_rphy {
0097 struct device dev;
0098 struct sas_identify identify;
0099 struct list_head list;
0100 struct request_queue *q;
0101 u32 scsi_target_id;
0102 };
0103
0104 #define dev_to_rphy(d) \
0105 container_of((d), struct sas_rphy, dev)
0106 #define transport_class_to_rphy(dev) \
0107 dev_to_rphy((dev)->parent)
0108 #define rphy_to_shost(rphy) \
0109 dev_to_shost((rphy)->dev.parent)
0110 #define target_to_rphy(targ) \
0111 dev_to_rphy((targ)->dev.parent)
0112
0113 struct sas_end_device {
0114 struct sas_rphy rphy;
0115
0116 unsigned ready_led_meaning:1;
0117 unsigned tlr_supported:1;
0118 unsigned tlr_enabled:1;
0119
0120 u16 I_T_nexus_loss_timeout;
0121 u16 initiator_response_timeout;
0122 };
0123 #define rphy_to_end_device(r) \
0124 container_of((r), struct sas_end_device, rphy)
0125
0126 struct sas_expander_device {
0127 int level;
0128 int next_port_id;
0129
0130 #define SAS_EXPANDER_VENDOR_ID_LEN 8
0131 char vendor_id[SAS_EXPANDER_VENDOR_ID_LEN+1];
0132 #define SAS_EXPANDER_PRODUCT_ID_LEN 16
0133 char product_id[SAS_EXPANDER_PRODUCT_ID_LEN+1];
0134 #define SAS_EXPANDER_PRODUCT_REV_LEN 4
0135 char product_rev[SAS_EXPANDER_PRODUCT_REV_LEN+1];
0136 #define SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN 8
0137 char component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN+1];
0138 u16 component_id;
0139 u8 component_revision_id;
0140
0141 struct sas_rphy rphy;
0142
0143 };
0144 #define rphy_to_expander_device(r) \
0145 container_of((r), struct sas_expander_device, rphy)
0146
0147 struct sas_port {
0148 struct device dev;
0149
0150 int port_identifier;
0151 int num_phys;
0152
0153 unsigned int is_backlink:1;
0154
0155
0156 struct sas_rphy *rphy;
0157
0158 struct mutex phy_list_mutex;
0159 struct list_head phy_list;
0160 struct list_head del_list;
0161 };
0162
0163 #define dev_to_sas_port(d) \
0164 container_of((d), struct sas_port, dev)
0165 #define transport_class_to_sas_port(dev) \
0166 dev_to_sas_port((dev)->parent)
0167
0168 struct sas_phy_linkrates {
0169 enum sas_linkrate maximum_linkrate;
0170 enum sas_linkrate minimum_linkrate;
0171 };
0172
0173
0174 struct sas_function_template {
0175 int (*get_linkerrors)(struct sas_phy *);
0176 int (*get_enclosure_identifier)(struct sas_rphy *, u64 *);
0177 int (*get_bay_identifier)(struct sas_rphy *);
0178 int (*phy_reset)(struct sas_phy *, int);
0179 int (*phy_enable)(struct sas_phy *, int);
0180 int (*phy_setup)(struct sas_phy *);
0181 void (*phy_release)(struct sas_phy *);
0182 int (*set_phy_speed)(struct sas_phy *, struct sas_phy_linkrates *);
0183 void (*smp_handler)(struct bsg_job *, struct Scsi_Host *,
0184 struct sas_rphy *);
0185 };
0186
0187
0188 void sas_remove_children(struct device *);
0189 extern void sas_remove_host(struct Scsi_Host *);
0190
0191 extern struct sas_phy *sas_phy_alloc(struct device *, int);
0192 extern void sas_phy_free(struct sas_phy *);
0193 extern int sas_phy_add(struct sas_phy *);
0194 extern void sas_phy_delete(struct sas_phy *);
0195 extern int scsi_is_sas_phy(const struct device *);
0196
0197 u64 sas_get_address(struct scsi_device *);
0198 unsigned int sas_tlr_supported(struct scsi_device *);
0199 unsigned int sas_is_tlr_enabled(struct scsi_device *);
0200 void sas_disable_tlr(struct scsi_device *);
0201 void sas_enable_tlr(struct scsi_device *);
0202
0203 extern struct sas_rphy *sas_end_device_alloc(struct sas_port *);
0204 extern struct sas_rphy *sas_expander_alloc(struct sas_port *, enum sas_device_type);
0205 void sas_rphy_free(struct sas_rphy *);
0206 extern int sas_rphy_add(struct sas_rphy *);
0207 extern void sas_rphy_remove(struct sas_rphy *);
0208 extern void sas_rphy_delete(struct sas_rphy *);
0209 extern void sas_rphy_unlink(struct sas_rphy *);
0210
0211 struct sas_port *sas_port_alloc(struct device *, int);
0212 struct sas_port *sas_port_alloc_num(struct device *);
0213 int sas_port_add(struct sas_port *);
0214 void sas_port_free(struct sas_port *);
0215 void sas_port_delete(struct sas_port *);
0216 void sas_port_add_phy(struct sas_port *, struct sas_phy *);
0217 void sas_port_delete_phy(struct sas_port *, struct sas_phy *);
0218 void sas_port_mark_backlink(struct sas_port *);
0219 int scsi_is_sas_port(const struct device *);
0220 struct sas_phy *sas_port_get_phy(struct sas_port *port);
0221 static inline void sas_port_put_phy(struct sas_phy *phy)
0222 {
0223 if (phy)
0224 put_device(&phy->dev);
0225 }
0226
0227 extern struct scsi_transport_template *
0228 sas_attach_transport(struct sas_function_template *);
0229 extern void sas_release_transport(struct scsi_transport_template *);
0230 int sas_read_port_mode_page(struct scsi_device *);
0231
0232 static inline int
0233 scsi_is_sas_expander_device(struct device *dev)
0234 {
0235 struct sas_rphy *rphy;
0236 if (!scsi_is_sas_rphy(dev))
0237 return 0;
0238 rphy = dev_to_rphy(dev);
0239 return rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE ||
0240 rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE;
0241 }
0242
0243 #define scsi_is_sas_phy_local(phy) scsi_is_host_device((phy)->dev.parent)
0244
0245 #endif