Commit | Line | Data |
---|---|---|
dbf9bfe6 | 1 | /* |
e5742101 | 2 | * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver |
dbf9bfe6 | 3 | * |
4 | * Copyright (c) 2008-2009 USI Co., Ltd. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions, and the following disclaimer, | |
12 | * without modification. | |
13 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
14 | * substantially similar to the "NO WARRANTY" disclaimer below | |
15 | * ("Disclaimer") and any redistribution must be conditioned upon | |
16 | * including a substantially similar Disclaimer requirement for further | |
17 | * binary redistribution. | |
18 | * 3. Neither the names of the above-listed copyright holders nor the names | |
19 | * of any contributors may be used to endorse or promote products derived | |
20 | * from this software without specific prior written permission. | |
21 | * | |
22 | * Alternatively, this software may be distributed under the terms of the | |
23 | * GNU General Public License ("GPL") version 2 as published by the Free | |
24 | * Software Foundation. | |
25 | * | |
26 | * NO WARRANTY | |
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
31 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
36 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
37 | * POSSIBILITY OF SUCH DAMAGES. | |
38 | * | |
39 | */ | |
40 | #include <linux/firmware.h> | |
5a0e3ad6 | 41 | #include <linux/slab.h> |
dbf9bfe6 | 42 | #include "pm8001_sas.h" |
43 | #include "pm8001_ctl.h" | |
44 | ||
45 | /* scsi host attributes */ | |
46 | ||
47 | /** | |
48 | * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number | |
49 | * @cdev: pointer to embedded class device | |
50 | * @buf: the buffer returned | |
51 | * | |
52 | * A sysfs 'read-only' shost attribute. | |
53 | */ | |
54 | static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev, | |
55 | struct device_attribute *attr, char *buf) | |
56 | { | |
57 | struct Scsi_Host *shost = class_to_shost(cdev); | |
58 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
59 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
60 | ||
e5742101 S |
61 | if (pm8001_ha->chip_id == chip_8001) { |
62 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
63 | pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev); | |
64 | } else { | |
65 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
66 | pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev); | |
67 | } | |
dbf9bfe6 | 68 | } |
69 | static | |
70 | DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL); | |
71 | ||
72 | /** | |
73 | * pm8001_ctl_fw_version_show - firmware version | |
74 | * @cdev: pointer to embedded class device | |
75 | * @buf: the buffer returned | |
76 | * | |
77 | * A sysfs 'read-only' shost attribute. | |
78 | */ | |
79 | static ssize_t pm8001_ctl_fw_version_show(struct device *cdev, | |
80 | struct device_attribute *attr, char *buf) | |
81 | { | |
82 | struct Scsi_Host *shost = class_to_shost(cdev); | |
83 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
84 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
85 | ||
e5742101 S |
86 | if (pm8001_ha->chip_id == chip_8001) { |
87 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n", | |
88 | (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 24), | |
89 | (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 16), | |
90 | (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 8), | |
91 | (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev)); | |
92 | } else { | |
93 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n", | |
94 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 24), | |
95 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 16), | |
96 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 8), | |
97 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev)); | |
98 | } | |
dbf9bfe6 | 99 | } |
100 | static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL); | |
24fff017 V |
101 | |
102 | /** | |
103 | * pm8001_ctl_ila_version_show - ila version | |
104 | * @cdev: pointer to embedded class device | |
105 | * @buf: the buffer returned | |
106 | * | |
107 | * A sysfs 'read-only' shost attribute. | |
108 | */ | |
109 | static ssize_t pm8001_ctl_ila_version_show(struct device *cdev, | |
110 | struct device_attribute *attr, char *buf) | |
111 | { | |
112 | struct Scsi_Host *shost = class_to_shost(cdev); | |
113 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
114 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
115 | ||
116 | if (pm8001_ha->chip_id != chip_8001) { | |
117 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n", | |
118 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 24), | |
119 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 16), | |
120 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 8), | |
121 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version)); | |
122 | } | |
123 | return 0; | |
124 | } | |
125 | static DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL); | |
126 | ||
127 | /** | |
128 | * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number | |
129 | * @cdev: pointer to embedded class device | |
130 | * @buf: the buffer returned | |
131 | * | |
132 | * A sysfs 'read-only' shost attribute. | |
133 | */ | |
134 | static ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev, | |
135 | struct device_attribute *attr, char *buf) | |
136 | { | |
137 | struct Scsi_Host *shost = class_to_shost(cdev); | |
138 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
139 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
140 | ||
141 | if (pm8001_ha->chip_id != chip_8001) { | |
142 | return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n", | |
143 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 24), | |
144 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 16), | |
145 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 8), | |
146 | (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version)); | |
147 | } | |
148 | return 0; | |
149 | } | |
150 | static | |
151 | DEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL); | |
152 | ||
dbf9bfe6 | 153 | /** |
154 | * pm8001_ctl_max_out_io_show - max outstanding io supported | |
155 | * @cdev: pointer to embedded class device | |
156 | * @buf: the buffer returned | |
157 | * | |
158 | * A sysfs 'read-only' shost attribute. | |
159 | */ | |
160 | static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev, | |
161 | struct device_attribute *attr, char *buf) | |
162 | { | |
163 | struct Scsi_Host *shost = class_to_shost(cdev); | |
164 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
165 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
166 | ||
e5742101 S |
167 | if (pm8001_ha->chip_id == chip_8001) { |
168 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
169 | pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io); | |
170 | } else { | |
171 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
172 | pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io); | |
173 | } | |
dbf9bfe6 | 174 | } |
175 | static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL); | |
176 | /** | |
177 | * pm8001_ctl_max_devices_show - max devices support | |
178 | * @cdev: pointer to embedded class device | |
179 | * @buf: the buffer returned | |
180 | * | |
181 | * A sysfs 'read-only' shost attribute. | |
182 | */ | |
183 | static ssize_t pm8001_ctl_max_devices_show(struct device *cdev, | |
184 | struct device_attribute *attr, char *buf) | |
185 | { | |
186 | struct Scsi_Host *shost = class_to_shost(cdev); | |
187 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
188 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
189 | ||
e5742101 S |
190 | if (pm8001_ha->chip_id == chip_8001) { |
191 | return snprintf(buf, PAGE_SIZE, "%04d\n", | |
192 | (u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16) | |
193 | ); | |
194 | } else { | |
195 | return snprintf(buf, PAGE_SIZE, "%04d\n", | |
196 | (u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16) | |
197 | ); | |
198 | } | |
dbf9bfe6 | 199 | } |
200 | static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL); | |
201 | /** | |
202 | * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no | |
203 | * hardware limitation | |
204 | * @cdev: pointer to embedded class device | |
205 | * @buf: the buffer returned | |
206 | * | |
207 | * A sysfs 'read-only' shost attribute. | |
208 | */ | |
209 | static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev, | |
210 | struct device_attribute *attr, char *buf) | |
211 | { | |
212 | struct Scsi_Host *shost = class_to_shost(cdev); | |
213 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
214 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
215 | ||
e5742101 S |
216 | if (pm8001_ha->chip_id == chip_8001) { |
217 | return snprintf(buf, PAGE_SIZE, "%04d\n", | |
218 | pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF | |
219 | ); | |
220 | } else { | |
221 | return snprintf(buf, PAGE_SIZE, "%04d\n", | |
222 | pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF | |
223 | ); | |
224 | } | |
dbf9bfe6 | 225 | } |
226 | static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL); | |
227 | ||
228 | #define SAS_1_0 0x1 | |
229 | #define SAS_1_1 0x2 | |
230 | #define SAS_2_0 0x4 | |
231 | ||
232 | static ssize_t | |
233 | show_sas_spec_support_status(unsigned int mode, char *buf) | |
234 | { | |
235 | ssize_t len = 0; | |
236 | ||
237 | if (mode & SAS_1_1) | |
238 | len = sprintf(buf, "%s", "SAS1.1"); | |
239 | if (mode & SAS_2_0) | |
240 | len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0"); | |
241 | len += sprintf(buf + len, "\n"); | |
242 | ||
243 | return len; | |
244 | } | |
245 | ||
246 | /** | |
247 | * pm8001_ctl_sas_spec_support_show - sas spec supported | |
248 | * @cdev: pointer to embedded class device | |
249 | * @buf: the buffer returned | |
250 | * | |
251 | * A sysfs 'read-only' shost attribute. | |
252 | */ | |
253 | static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev, | |
254 | struct device_attribute *attr, char *buf) | |
255 | { | |
256 | unsigned int mode; | |
257 | struct Scsi_Host *shost = class_to_shost(cdev); | |
258 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
259 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
e5742101 S |
260 | /* fe000000 means supports SAS2.1 */ |
261 | if (pm8001_ha->chip_id == chip_8001) | |
262 | mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag & | |
263 | 0xfe000000)>>25; | |
264 | else | |
265 | /* fe000000 means supports SAS2.1 */ | |
266 | mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag & | |
267 | 0xfe000000)>>25; | |
dbf9bfe6 | 268 | return show_sas_spec_support_status(mode, buf); |
269 | } | |
270 | static DEVICE_ATTR(sas_spec_support, S_IRUGO, | |
271 | pm8001_ctl_sas_spec_support_show, NULL); | |
272 | ||
273 | /** | |
274 | * pm8001_ctl_sas_address_show - sas address | |
275 | * @cdev: pointer to embedded class device | |
276 | * @buf: the buffer returned | |
277 | * | |
278 | * This is the controller sas address | |
279 | * | |
280 | * A sysfs 'read-only' shost attribute. | |
281 | */ | |
282 | static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev, | |
283 | struct device_attribute *attr, char *buf) | |
284 | { | |
285 | struct Scsi_Host *shost = class_to_shost(cdev); | |
286 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
287 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
288 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", | |
289 | be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr)); | |
290 | } | |
291 | static DEVICE_ATTR(host_sas_address, S_IRUGO, | |
292 | pm8001_ctl_host_sas_address_show, NULL); | |
293 | ||
294 | /** | |
295 | * pm8001_ctl_logging_level_show - logging level | |
296 | * @cdev: pointer to embedded class device | |
297 | * @buf: the buffer returned | |
298 | * | |
299 | * A sysfs 'read/write' shost attribute. | |
300 | */ | |
301 | static ssize_t pm8001_ctl_logging_level_show(struct device *cdev, | |
302 | struct device_attribute *attr, char *buf) | |
303 | { | |
304 | struct Scsi_Host *shost = class_to_shost(cdev); | |
305 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
306 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
307 | ||
308 | return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level); | |
309 | } | |
310 | static ssize_t pm8001_ctl_logging_level_store(struct device *cdev, | |
311 | struct device_attribute *attr, const char *buf, size_t count) | |
312 | { | |
313 | struct Scsi_Host *shost = class_to_shost(cdev); | |
314 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
315 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
316 | int val = 0; | |
317 | ||
318 | if (sscanf(buf, "%x", &val) != 1) | |
319 | return -EINVAL; | |
320 | ||
321 | pm8001_ha->logging_level = val; | |
322 | return strlen(buf); | |
323 | } | |
324 | ||
325 | static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, | |
326 | pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store); | |
327 | /** | |
328 | * pm8001_ctl_aap_log_show - aap1 event log | |
329 | * @cdev: pointer to embedded class device | |
330 | * @buf: the buffer returned | |
331 | * | |
332 | * A sysfs 'read-only' shost attribute. | |
333 | */ | |
334 | static ssize_t pm8001_ctl_aap_log_show(struct device *cdev, | |
335 | struct device_attribute *attr, char *buf) | |
336 | { | |
337 | struct Scsi_Host *shost = class_to_shost(cdev); | |
338 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
339 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
340 | int i; | |
341 | #define AAP1_MEMMAP(r, c) \ | |
342 | (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \ | |
343 | + (c))) | |
344 | ||
345 | char *str = buf; | |
346 | int max = 2; | |
347 | for (i = 0; i < max; i++) { | |
348 | str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x" | |
349 | "0x%08x 0x%08x\n", | |
350 | AAP1_MEMMAP(i, 0), | |
351 | AAP1_MEMMAP(i, 4), | |
352 | AAP1_MEMMAP(i, 8), | |
353 | AAP1_MEMMAP(i, 12), | |
354 | AAP1_MEMMAP(i, 16), | |
355 | AAP1_MEMMAP(i, 20), | |
356 | AAP1_MEMMAP(i, 24), | |
357 | AAP1_MEMMAP(i, 28)); | |
358 | } | |
359 | ||
360 | return str - buf; | |
361 | } | |
362 | static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL); | |
d078b511 AKS |
363 | /** |
364 | * pm8001_ctl_ib_queue_log_show - Out bound Queue log | |
365 | * @cdev:pointer to embedded class device | |
366 | * @buf: the buffer returned | |
367 | * A sysfs 'read-only' shost attribute. | |
368 | */ | |
369 | static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev, | |
370 | struct device_attribute *attr, char *buf) | |
371 | { | |
372 | struct Scsi_Host *shost = class_to_shost(cdev); | |
373 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
374 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
375 | int offset; | |
376 | char *str = buf; | |
377 | int start = 0; | |
859b5d10 V |
378 | #define IB_MEMMAP(c) \ |
379 | (*(u32 *)((u8 *)pm8001_ha-> \ | |
380 | memoryMap.region[IB].virt_ptr + \ | |
d078b511 AKS |
381 | pm8001_ha->evtlog_ib_offset + (c))) |
382 | ||
383 | for (offset = 0; offset < IB_OB_READ_TIMES; offset++) { | |
859b5d10 | 384 | str += sprintf(str, "0x%08x\n", IB_MEMMAP(start)); |
d078b511 AKS |
385 | start = start + 4; |
386 | } | |
387 | pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET; | |
859b5d10 | 388 | if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0) |
d078b511 AKS |
389 | pm8001_ha->evtlog_ib_offset = 0; |
390 | ||
391 | return str - buf; | |
392 | } | |
393 | ||
394 | static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL); | |
395 | /** | |
396 | * pm8001_ctl_ob_queue_log_show - Out bound Queue log | |
397 | * @cdev:pointer to embedded class device | |
398 | * @buf: the buffer returned | |
399 | * A sysfs 'read-only' shost attribute. | |
400 | */ | |
401 | ||
402 | static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev, | |
403 | struct device_attribute *attr, char *buf) | |
404 | { | |
405 | struct Scsi_Host *shost = class_to_shost(cdev); | |
406 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
407 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
408 | int offset; | |
409 | char *str = buf; | |
410 | int start = 0; | |
859b5d10 V |
411 | #define OB_MEMMAP(c) \ |
412 | (*(u32 *)((u8 *)pm8001_ha-> \ | |
413 | memoryMap.region[OB].virt_ptr + \ | |
d078b511 AKS |
414 | pm8001_ha->evtlog_ob_offset + (c))) |
415 | ||
416 | for (offset = 0; offset < IB_OB_READ_TIMES; offset++) { | |
859b5d10 | 417 | str += sprintf(str, "0x%08x\n", OB_MEMMAP(start)); |
d078b511 AKS |
418 | start = start + 4; |
419 | } | |
420 | pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET; | |
859b5d10 | 421 | if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0) |
d078b511 AKS |
422 | pm8001_ha->evtlog_ob_offset = 0; |
423 | ||
424 | return str - buf; | |
425 | } | |
426 | static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL); | |
966fdcff AKS |
427 | /** |
428 | * pm8001_ctl_bios_version_show - Bios version Display | |
429 | * @cdev:pointer to embedded class device | |
430 | * @buf:the buffer returned | |
431 | * A sysfs 'read-only' shost attribute. | |
432 | */ | |
433 | static ssize_t pm8001_ctl_bios_version_show(struct device *cdev, | |
434 | struct device_attribute *attr, char *buf) | |
435 | { | |
436 | struct Scsi_Host *shost = class_to_shost(cdev); | |
437 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
438 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
439 | char *str = buf; | |
966fdcff AKS |
440 | int bios_index; |
441 | DECLARE_COMPLETION_ONSTACK(completion); | |
442 | struct pm8001_ioctl_payload payload; | |
443 | ||
444 | pm8001_ha->nvmd_completion = &completion; | |
445 | payload.minor_function = 7; | |
446 | payload.offset = 0; | |
447 | payload.length = 4096; | |
448 | payload.func_specific = kzalloc(4096, GFP_KERNEL); | |
b42939aa ST |
449 | if (!payload.func_specific) |
450 | return -ENOMEM; | |
5b4ce882 TH |
451 | if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) { |
452 | kfree(payload.func_specific); | |
453 | return -ENOMEM; | |
454 | } | |
966fdcff | 455 | wait_for_completion(&completion); |
966fdcff AKS |
456 | for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT; |
457 | bios_index++) | |
458 | str += sprintf(str, "%c", | |
9e032845 | 459 | *(payload.func_specific+bios_index)); |
b42939aa | 460 | kfree(payload.func_specific); |
966fdcff AKS |
461 | return str - buf; |
462 | } | |
463 | static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL); | |
dbf9bfe6 | 464 | /** |
465 | * pm8001_ctl_aap_log_show - IOP event log | |
466 | * @cdev: pointer to embedded class device | |
467 | * @buf: the buffer returned | |
468 | * | |
469 | * A sysfs 'read-only' shost attribute. | |
470 | */ | |
471 | static ssize_t pm8001_ctl_iop_log_show(struct device *cdev, | |
472 | struct device_attribute *attr, char *buf) | |
473 | { | |
474 | struct Scsi_Host *shost = class_to_shost(cdev); | |
475 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
476 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
477 | #define IOP_MEMMAP(r, c) \ | |
478 | (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \ | |
479 | + (c))) | |
480 | int i; | |
481 | char *str = buf; | |
482 | int max = 2; | |
483 | for (i = 0; i < max; i++) { | |
484 | str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x" | |
485 | "0x%08x 0x%08x\n", | |
486 | IOP_MEMMAP(i, 0), | |
487 | IOP_MEMMAP(i, 4), | |
488 | IOP_MEMMAP(i, 8), | |
489 | IOP_MEMMAP(i, 12), | |
490 | IOP_MEMMAP(i, 16), | |
491 | IOP_MEMMAP(i, 20), | |
492 | IOP_MEMMAP(i, 24), | |
493 | IOP_MEMMAP(i, 28)); | |
494 | } | |
495 | ||
496 | return str - buf; | |
497 | } | |
498 | static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL); | |
499 | ||
d078b511 AKS |
500 | /** |
501 | ** pm8001_ctl_fatal_log_show - fatal error logging | |
502 | ** @cdev:pointer to embedded class device | |
503 | ** @buf: the buffer returned | |
504 | ** | |
505 | ** A sysfs 'read-only' shost attribute. | |
506 | **/ | |
507 | ||
508 | static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev, | |
509 | struct device_attribute *attr, char *buf) | |
510 | { | |
cf370066 | 511 | ssize_t count; |
d078b511 AKS |
512 | |
513 | count = pm80xx_get_fatal_dump(cdev, attr, buf); | |
514 | return count; | |
515 | } | |
516 | ||
517 | static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL); | |
518 | ||
519 | ||
520 | /** | |
521 | ** pm8001_ctl_gsm_log_show - gsm dump collection | |
522 | ** @cdev:pointer to embedded class device | |
523 | ** @buf: the buffer returned | |
524 | **A sysfs 'read-only' shost attribute. | |
525 | **/ | |
526 | static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev, | |
527 | struct device_attribute *attr, char *buf) | |
528 | { | |
cf370066 | 529 | ssize_t count; |
d078b511 AKS |
530 | |
531 | count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf); | |
532 | return count; | |
533 | } | |
534 | ||
535 | static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL); | |
536 | ||
dbf9bfe6 | 537 | #define FLASH_CMD_NONE 0x00 |
538 | #define FLASH_CMD_UPDATE 0x01 | |
539 | #define FLASH_CMD_SET_NVMD 0x02 | |
540 | ||
541 | struct flash_command { | |
542 | u8 command[8]; | |
543 | int code; | |
544 | }; | |
545 | ||
546 | static struct flash_command flash_command_table[] = | |
547 | { | |
548 | {"set_nvmd", FLASH_CMD_SET_NVMD}, | |
549 | {"update", FLASH_CMD_UPDATE}, | |
550 | {"", FLASH_CMD_NONE} /* Last entry should be NULL. */ | |
551 | }; | |
552 | ||
553 | struct error_fw { | |
554 | char *reason; | |
555 | int err_code; | |
556 | }; | |
557 | ||
558 | static struct error_fw flash_error_table[] = | |
559 | { | |
560 | {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE}, | |
561 | {"image header mismatch", FLASH_UPDATE_HDR_ERR}, | |
562 | {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR}, | |
563 | {"image CRC Error", FLASH_UPDATE_CRC_ERR}, | |
564 | {"image length Error.", FLASH_UPDATE_LENGTH_ERR}, | |
565 | {"Failed to program flash chip", FLASH_UPDATE_HW_ERR}, | |
566 | {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED}, | |
567 | {"Flash update disabled.", FLASH_UPDATE_DISABLED}, | |
568 | {"Flash in progress", FLASH_IN_PROGRESS}, | |
569 | {"Image file size Error", FAIL_FILE_SIZE}, | |
570 | {"Input parameter error", FAIL_PARAMETERS}, | |
571 | {"Out of memory", FAIL_OUT_MEMORY}, | |
572 | {"OK", 0} /* Last entry err_code = 0. */ | |
573 | }; | |
574 | ||
575 | static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha) | |
576 | { | |
577 | struct pm8001_ioctl_payload *payload; | |
578 | DECLARE_COMPLETION_ONSTACK(completion); | |
6f8f31c7 TH |
579 | u8 *ioctlbuffer; |
580 | u32 ret; | |
581 | u32 length = 1024 * 5 + sizeof(*payload) - 1; | |
582 | ||
583 | if (pm8001_ha->fw_image->size > 4096) { | |
584 | pm8001_ha->fw_status = FAIL_FILE_SIZE; | |
585 | return -EFAULT; | |
586 | } | |
dbf9bfe6 | 587 | |
dbf9bfe6 | 588 | ioctlbuffer = kzalloc(length, GFP_KERNEL); |
6f8f31c7 TH |
589 | if (!ioctlbuffer) { |
590 | pm8001_ha->fw_status = FAIL_OUT_MEMORY; | |
dbf9bfe6 | 591 | return -ENOMEM; |
dbf9bfe6 | 592 | } |
593 | payload = (struct pm8001_ioctl_payload *)ioctlbuffer; | |
1c75a679 | 594 | memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data, |
dbf9bfe6 | 595 | pm8001_ha->fw_image->size); |
596 | payload->length = pm8001_ha->fw_image->size; | |
597 | payload->id = 0; | |
1c75a679 | 598 | payload->minor_function = 0x1; |
dbf9bfe6 | 599 | pm8001_ha->nvmd_completion = &completion; |
600 | ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload); | |
6f8f31c7 TH |
601 | if (ret) { |
602 | pm8001_ha->fw_status = FAIL_OUT_MEMORY; | |
603 | goto out; | |
604 | } | |
dbf9bfe6 | 605 | wait_for_completion(&completion); |
606 | out: | |
607 | kfree(ioctlbuffer); | |
608 | return ret; | |
609 | } | |
610 | ||
611 | static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha) | |
612 | { | |
613 | struct pm8001_ioctl_payload *payload; | |
614 | DECLARE_COMPLETION_ONSTACK(completion); | |
6f8f31c7 | 615 | u8 *ioctlbuffer; |
dbf9bfe6 | 616 | struct fw_control_info *fwControl; |
dbf9bfe6 | 617 | u32 partitionSize, partitionSizeTmp; |
6f8f31c7 | 618 | u32 loopNumber, loopcount; |
dbf9bfe6 | 619 | struct pm8001_fw_image_header *image_hdr; |
6f8f31c7 TH |
620 | u32 sizeRead = 0; |
621 | u32 ret = 0; | |
622 | u32 length = 1024 * 16 + sizeof(*payload) - 1; | |
dbf9bfe6 | 623 | |
6f8f31c7 TH |
624 | if (pm8001_ha->fw_image->size < 28) { |
625 | pm8001_ha->fw_status = FAIL_FILE_SIZE; | |
626 | return -EFAULT; | |
627 | } | |
dbf9bfe6 | 628 | ioctlbuffer = kzalloc(length, GFP_KERNEL); |
6f8f31c7 TH |
629 | if (!ioctlbuffer) { |
630 | pm8001_ha->fw_status = FAIL_OUT_MEMORY; | |
dbf9bfe6 | 631 | return -ENOMEM; |
dbf9bfe6 | 632 | } |
6f8f31c7 | 633 | image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data; |
dbf9bfe6 | 634 | while (sizeRead < pm8001_ha->fw_image->size) { |
635 | partitionSizeTmp = | |
636 | *(u32 *)((u8 *)&image_hdr->image_length + sizeRead); | |
637 | partitionSize = be32_to_cpu(partitionSizeTmp); | |
5bd355ee TH |
638 | loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN, |
639 | IOCTL_BUF_SIZE); | |
dbf9bfe6 | 640 | for (loopNumber = 0; loopNumber < loopcount; loopNumber++) { |
641 | payload = (struct pm8001_ioctl_payload *)ioctlbuffer; | |
642 | payload->length = 1024*16; | |
643 | payload->id = 0; | |
644 | fwControl = | |
1c75a679 | 645 | (struct fw_control_info *)&payload->func_specific; |
dbf9bfe6 | 646 | fwControl->len = IOCTL_BUF_SIZE; /* IN */ |
647 | fwControl->size = partitionSize + HEADER_LEN;/* IN */ | |
648 | fwControl->retcode = 0;/* OUT */ | |
649 | fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */ | |
650 | ||
651 | /* for the last chunk of data in case file size is not even with | |
652 | 4k, load only the rest*/ | |
653 | if (((loopcount-loopNumber) == 1) && | |
654 | ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) { | |
655 | fwControl->len = | |
656 | (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE; | |
657 | memcpy((u8 *)fwControl->buffer, | |
658 | (u8 *)pm8001_ha->fw_image->data + sizeRead, | |
659 | (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE); | |
660 | sizeRead += | |
661 | (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE; | |
662 | } else { | |
663 | memcpy((u8 *)fwControl->buffer, | |
664 | (u8 *)pm8001_ha->fw_image->data + sizeRead, | |
665 | IOCTL_BUF_SIZE); | |
666 | sizeRead += IOCTL_BUF_SIZE; | |
667 | } | |
668 | ||
669 | pm8001_ha->nvmd_completion = &completion; | |
670 | ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload); | |
6f8f31c7 TH |
671 | if (ret) { |
672 | pm8001_ha->fw_status = FAIL_OUT_MEMORY; | |
673 | goto out; | |
674 | } | |
dbf9bfe6 | 675 | wait_for_completion(&completion); |
31d05e5b | 676 | if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) { |
6f8f31c7 TH |
677 | pm8001_ha->fw_status = fwControl->retcode; |
678 | ret = -EFAULT; | |
679 | goto out; | |
680 | } | |
dbf9bfe6 | 681 | } |
682 | } | |
dbf9bfe6 | 683 | out: |
684 | kfree(ioctlbuffer); | |
685 | return ret; | |
686 | } | |
687 | static ssize_t pm8001_store_update_fw(struct device *cdev, | |
688 | struct device_attribute *attr, | |
689 | const char *buf, size_t count) | |
690 | { | |
691 | struct Scsi_Host *shost = class_to_shost(cdev); | |
692 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
693 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
694 | char *cmd_ptr, *filename_ptr; | |
695 | int res, i; | |
696 | int flash_command = FLASH_CMD_NONE; | |
6f8f31c7 TH |
697 | int ret; |
698 | ||
dbf9bfe6 | 699 | if (!capable(CAP_SYS_ADMIN)) |
700 | return -EACCES; | |
701 | ||
6f8f31c7 TH |
702 | /* this test protects us from running two flash processes at once, |
703 | * so we should start with this test */ | |
704 | if (pm8001_ha->fw_status == FLASH_IN_PROGRESS) | |
705 | return -EINPROGRESS; | |
706 | pm8001_ha->fw_status = FLASH_IN_PROGRESS; | |
dbf9bfe6 | 707 | |
6396bb22 | 708 | cmd_ptr = kcalloc(count, 2, GFP_KERNEL); |
dbf9bfe6 | 709 | if (!cmd_ptr) { |
6f8f31c7 TH |
710 | pm8001_ha->fw_status = FAIL_OUT_MEMORY; |
711 | return -ENOMEM; | |
dbf9bfe6 | 712 | } |
713 | ||
714 | filename_ptr = cmd_ptr + count; | |
715 | res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr); | |
716 | if (res != 2) { | |
6f8f31c7 TH |
717 | pm8001_ha->fw_status = FAIL_PARAMETERS; |
718 | ret = -EINVAL; | |
719 | goto out; | |
dbf9bfe6 | 720 | } |
721 | ||
722 | for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) { | |
723 | if (!memcmp(flash_command_table[i].command, | |
724 | cmd_ptr, strlen(cmd_ptr))) { | |
725 | flash_command = flash_command_table[i].code; | |
726 | break; | |
727 | } | |
728 | } | |
729 | if (flash_command == FLASH_CMD_NONE) { | |
6f8f31c7 TH |
730 | pm8001_ha->fw_status = FAIL_PARAMETERS; |
731 | ret = -EINVAL; | |
732 | goto out; | |
dbf9bfe6 | 733 | } |
734 | ||
6f8f31c7 | 735 | ret = request_firmware(&pm8001_ha->fw_image, |
dbf9bfe6 | 736 | filename_ptr, |
737 | pm8001_ha->dev); | |
738 | ||
6f8f31c7 | 739 | if (ret) { |
dbf9bfe6 | 740 | PM8001_FAIL_DBG(pm8001_ha, |
6f8f31c7 TH |
741 | pm8001_printk( |
742 | "Failed to load firmware image file %s, error %d\n", | |
743 | filename_ptr, ret)); | |
744 | pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE; | |
745 | goto out; | |
dbf9bfe6 | 746 | } |
747 | ||
6f8f31c7 TH |
748 | if (FLASH_CMD_UPDATE == flash_command) |
749 | ret = pm8001_update_flash(pm8001_ha); | |
750 | else | |
751 | ret = pm8001_set_nvmd(pm8001_ha); | |
752 | ||
dbf9bfe6 | 753 | release_firmware(pm8001_ha->fw_image); |
dbf9bfe6 | 754 | out: |
6f8f31c7 | 755 | kfree(cmd_ptr); |
dbf9bfe6 | 756 | |
6f8f31c7 TH |
757 | if (ret) |
758 | return ret; | |
759 | ||
760 | pm8001_ha->fw_status = FLASH_OK; | |
761 | return count; | |
dbf9bfe6 | 762 | } |
763 | ||
764 | static ssize_t pm8001_show_update_fw(struct device *cdev, | |
765 | struct device_attribute *attr, char *buf) | |
766 | { | |
767 | int i; | |
768 | struct Scsi_Host *shost = class_to_shost(cdev); | |
769 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); | |
770 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; | |
771 | ||
772 | for (i = 0; flash_error_table[i].err_code != 0; i++) { | |
773 | if (flash_error_table[i].err_code == pm8001_ha->fw_status) | |
774 | break; | |
775 | } | |
776 | if (pm8001_ha->fw_status != FLASH_IN_PROGRESS) | |
777 | pm8001_ha->fw_status = FLASH_OK; | |
778 | ||
779 | return snprintf(buf, PAGE_SIZE, "status=%x %s\n", | |
780 | flash_error_table[i].err_code, | |
781 | flash_error_table[i].reason); | |
782 | } | |
783 | ||
332e2b4f | 784 | static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP, |
dbf9bfe6 | 785 | pm8001_show_update_fw, pm8001_store_update_fw); |
786 | struct device_attribute *pm8001_host_attrs[] = { | |
787 | &dev_attr_interface_rev, | |
788 | &dev_attr_fw_version, | |
789 | &dev_attr_update_fw, | |
790 | &dev_attr_aap_log, | |
791 | &dev_attr_iop_log, | |
d078b511 AKS |
792 | &dev_attr_fatal_log, |
793 | &dev_attr_gsm_log, | |
dbf9bfe6 | 794 | &dev_attr_max_out_io, |
795 | &dev_attr_max_devices, | |
796 | &dev_attr_max_sg_list, | |
797 | &dev_attr_sas_spec_support, | |
798 | &dev_attr_logging_level, | |
799 | &dev_attr_host_sas_address, | |
966fdcff | 800 | &dev_attr_bios_version, |
d078b511 AKS |
801 | &dev_attr_ib_log, |
802 | &dev_attr_ob_log, | |
24fff017 V |
803 | &dev_attr_ila_version, |
804 | &dev_attr_inc_fw_ver, | |
dbf9bfe6 | 805 | NULL, |
806 | }; | |
807 |