diff options
author | Dan Williams <dan.j.williams@intel.com> | 2011-09-02 00:18:20 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2011-09-22 06:59:09 -0400 |
commit | 8ec6552f4a77d15f446b00aed364e3c12d38aa6c (patch) | |
tree | efaa0dfc6479d28a14e5e778e8eb246ff94c360f | |
parent | 9c224ac21506d29f5a6ff4df0c4cc9f97484fa25 (diff) |
[SCSI] libsas: sgpio write support
Add SFF-8485 v0.7 / SAS-1 smp-write-gpio register support to libsas.
Defer SAS-2 support unless/until it defines an sgpio interface.
Minimum implementation needed to get the lights blinking.
try_test_sas_gpio_gp_bit() provides a common method to parse the
incoming write data (raw bitstream), and the to_sas_gpio_gp_bit() helper
routine can be used as a basis for the set/clear operations for the
'read' implementation. Host implementations parse as many bits
(ODx.[012]) as are locally supported and report the number of registers
successfully written. If the submitted data overruns the internal
number of registers available report the write as a success with the
number of bytes remaining reported in ->resid_len.
Example (assuming an active backplane) set the "identify" pattern for
the first 21 devices:
smp_write_gpio --count=2 --data=92,49,24,92,24,92,49,24 -t 4 --index=1 /dev/bsg/sas_hostX
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | drivers/scsi/libsas/sas_host_smp.c | 103 | ||||
-rw-r--r-- | include/scsi/libsas.h | 11 | ||||
-rw-r--r-- | include/scsi/sas.h | 8 |
3 files changed, 120 insertions, 2 deletions
diff --git a/drivers/scsi/libsas/sas_host_smp.c b/drivers/scsi/libsas/sas_host_smp.c index 04ad8dd1a74c..e1aa17840c5b 100644 --- a/drivers/scsi/libsas/sas_host_smp.c +++ b/drivers/scsi/libsas/sas_host_smp.c | |||
@@ -51,6 +51,91 @@ static void sas_host_smp_discover(struct sas_ha_struct *sas_ha, u8 *resp_data, | |||
51 | resp_data[15] = rphy->identify.target_port_protocols; | 51 | resp_data[15] = rphy->identify.target_port_protocols; |
52 | } | 52 | } |
53 | 53 | ||
54 | /** | ||
55 | * to_sas_gpio_gp_bit - given the gpio frame data find the byte/bit position of 'od' | ||
56 | * @od: od bit to find | ||
57 | * @data: incoming bitstream (from frame) | ||
58 | * @index: requested data register index (from frame) | ||
59 | * @count: total number of registers in the bitstream (from frame) | ||
60 | * @bit: bit position of 'od' in the returned byte | ||
61 | * | ||
62 | * returns NULL if 'od' is not in 'data' | ||
63 | * | ||
64 | * From SFF-8485 v0.7: | ||
65 | * "In GPIO_TX[1], bit 0 of byte 3 contains the first bit (i.e., OD0.0) | ||
66 | * and bit 7 of byte 0 contains the 32nd bit (i.e., OD10.1). | ||
67 | * | ||
68 | * In GPIO_TX[2], bit 0 of byte 3 contains the 33rd bit (i.e., OD10.2) | ||
69 | * and bit 7 of byte 0 contains the 64th bit (i.e., OD21.0)." | ||
70 | * | ||
71 | * The general-purpose (raw-bitstream) RX registers have the same layout | ||
72 | * although 'od' is renamed 'id' for 'input data'. | ||
73 | * | ||
74 | * SFF-8489 defines the behavior of the LEDs in response to the 'od' values. | ||
75 | */ | ||
76 | static u8 *to_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count, u8 *bit) | ||
77 | { | ||
78 | unsigned int reg; | ||
79 | u8 byte; | ||
80 | |||
81 | /* gp registers start at index 1 */ | ||
82 | if (index == 0) | ||
83 | return NULL; | ||
84 | |||
85 | index--; /* make index 0-based */ | ||
86 | if (od < index * 32) | ||
87 | return NULL; | ||
88 | |||
89 | od -= index * 32; | ||
90 | reg = od >> 5; | ||
91 | |||
92 | if (reg >= count) | ||
93 | return NULL; | ||
94 | |||
95 | od &= (1 << 5) - 1; | ||
96 | byte = 3 - (od >> 3); | ||
97 | *bit = od & ((1 << 3) - 1); | ||
98 | |||
99 | return &data[reg * 4 + byte]; | ||
100 | } | ||
101 | |||
102 | int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count) | ||
103 | { | ||
104 | u8 *byte; | ||
105 | u8 bit; | ||
106 | |||
107 | byte = to_sas_gpio_gp_bit(od, data, index, count, &bit); | ||
108 | if (!byte) | ||
109 | return -1; | ||
110 | |||
111 | return (*byte >> bit) & 1; | ||
112 | } | ||
113 | EXPORT_SYMBOL(try_test_sas_gpio_gp_bit); | ||
114 | |||
115 | static int sas_host_smp_write_gpio(struct sas_ha_struct *sas_ha, u8 *resp_data, | ||
116 | u8 reg_type, u8 reg_index, u8 reg_count, | ||
117 | u8 *req_data) | ||
118 | { | ||
119 | struct sas_internal *i = to_sas_internal(sas_ha->core.shost->transportt); | ||
120 | int written; | ||
121 | |||
122 | if (i->dft->lldd_write_gpio == NULL) { | ||
123 | resp_data[2] = SMP_RESP_FUNC_UNK; | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | written = i->dft->lldd_write_gpio(sas_ha, reg_type, reg_index, | ||
128 | reg_count, req_data); | ||
129 | |||
130 | if (written < 0) { | ||
131 | resp_data[2] = SMP_RESP_FUNC_FAILED; | ||
132 | written = 0; | ||
133 | } else | ||
134 | resp_data[2] = SMP_RESP_FUNC_ACC; | ||
135 | |||
136 | return written; | ||
137 | } | ||
138 | |||
54 | static void sas_report_phy_sata(struct sas_ha_struct *sas_ha, u8 *resp_data, | 139 | static void sas_report_phy_sata(struct sas_ha_struct *sas_ha, u8 *resp_data, |
55 | u8 phy_id) | 140 | u8 phy_id) |
56 | { | 141 | { |
@@ -230,9 +315,23 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, | |||
230 | /* Can't implement; hosts have no routes */ | 315 | /* Can't implement; hosts have no routes */ |
231 | break; | 316 | break; |
232 | 317 | ||
233 | case SMP_WRITE_GPIO_REG: | 318 | case SMP_WRITE_GPIO_REG: { |
234 | /* FIXME: need GPIO support in the transport class */ | 319 | /* SFF-8485 v0.7 */ |
320 | const int base_frame_size = 11; | ||
321 | int to_write = req_data[4]; | ||
322 | |||
323 | if (blk_rq_bytes(req) < base_frame_size + to_write * 4 || | ||
324 | req->resid_len < base_frame_size + to_write * 4) { | ||
325 | resp_data[2] = SMP_RESP_INV_FRM_LEN; | ||
326 | break; | ||
327 | } | ||
328 | |||
329 | to_write = sas_host_smp_write_gpio(sas_ha, resp_data, req_data[2], | ||
330 | req_data[3], to_write, &req_data[8]); | ||
331 | req->resid_len -= base_frame_size + to_write * 4; | ||
332 | rsp->resid_len -= 8; | ||
235 | break; | 333 | break; |
334 | } | ||
236 | 335 | ||
237 | case SMP_CONF_ROUTE_INFO: | 336 | case SMP_CONF_ROUTE_INFO: |
238 | /* Can't implement; hosts have no routes */ | 337 | /* Can't implement; hosts have no routes */ |
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 2517254b8403..af0a1deac930 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h | |||
@@ -405,6 +405,13 @@ static inline void sas_phy_disconnected(struct asd_sas_phy *phy) | |||
405 | phy->linkrate = SAS_LINK_RATE_UNKNOWN; | 405 | phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
406 | } | 406 | } |
407 | 407 | ||
408 | static inline unsigned int to_sas_gpio_od(int device, int bit) | ||
409 | { | ||
410 | return 3 * device + bit; | ||
411 | } | ||
412 | |||
413 | int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count); | ||
414 | |||
408 | /* ---------- Tasks ---------- */ | 415 | /* ---------- Tasks ---------- */ |
409 | /* | 416 | /* |
410 | service_response | SAS_TASK_COMPLETE | SAS_TASK_UNDELIVERED | | 417 | service_response | SAS_TASK_COMPLETE | SAS_TASK_UNDELIVERED | |
@@ -592,6 +599,10 @@ struct sas_domain_function_template { | |||
592 | 599 | ||
593 | /* Phy management */ | 600 | /* Phy management */ |
594 | int (*lldd_control_phy)(struct asd_sas_phy *, enum phy_func, void *); | 601 | int (*lldd_control_phy)(struct asd_sas_phy *, enum phy_func, void *); |
602 | |||
603 | /* GPIO support */ | ||
604 | int (*lldd_write_gpio)(struct sas_ha_struct *, u8 reg_type, | ||
605 | u8 reg_index, u8 reg_count, u8 *write_data); | ||
595 | }; | 606 | }; |
596 | 607 | ||
597 | extern int sas_register_ha(struct sas_ha_struct *); | 608 | extern int sas_register_ha(struct sas_ha_struct *); |
diff --git a/include/scsi/sas.h b/include/scsi/sas.h index e9fd02281381..a3001add0c66 100644 --- a/include/scsi/sas.h +++ b/include/scsi/sas.h | |||
@@ -195,6 +195,14 @@ enum sas_open_rej_reason { | |||
195 | SAS_OREJ_RSVD_RETRY = 18, | 195 | SAS_OREJ_RSVD_RETRY = 18, |
196 | }; | 196 | }; |
197 | 197 | ||
198 | enum sas_gpio_reg_type { | ||
199 | SAS_GPIO_REG_CFG = 0, | ||
200 | SAS_GPIO_REG_RX = 1, | ||
201 | SAS_GPIO_REG_RX_GP = 2, | ||
202 | SAS_GPIO_REG_TX = 3, | ||
203 | SAS_GPIO_REG_TX_GP = 4, | ||
204 | }; | ||
205 | |||
198 | struct dev_to_host_fis { | 206 | struct dev_to_host_fis { |
199 | u8 fis_type; /* 0x34 */ | 207 | u8 fis_type; /* 0x34 */ |
200 | u8 flags; | 208 | u8 flags; |