Commit | Line | Data |
---|---|---|
8482e118 | 1 | /* |
fa90c54f AV |
2 | * QLogic Fibre Channel HBA Driver |
3 | * Copyright (c) 2003-2005 QLogic Corporation | |
8482e118 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
8482e118 | 6 | */ |
7 | #include "qla_def.h" | |
8 | ||
7aaef27b | 9 | #include <linux/vmalloc.h> |
8482e118 | 10 | |
11 | /* SYSFS attributes --------------------------------------------------------- */ | |
12 | ||
13 | static ssize_t | |
14 | qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off, | |
15 | size_t count) | |
16 | { | |
17 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
18 | struct device, kobj))); | |
19 | ||
20 | if (ha->fw_dump_reading == 0) | |
21 | return 0; | |
22 | if (off > ha->fw_dump_buffer_len) | |
23 | return 0; | |
24 | if (off + count > ha->fw_dump_buffer_len) | |
25 | count = ha->fw_dump_buffer_len - off; | |
26 | ||
27 | memcpy(buf, &ha->fw_dump_buffer[off], count); | |
28 | ||
29 | return (count); | |
30 | } | |
31 | ||
32 | static ssize_t | |
33 | qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off, | |
34 | size_t count) | |
35 | { | |
36 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
37 | struct device, kobj))); | |
38 | int reading; | |
39 | uint32_t dump_size; | |
40 | ||
41 | if (off != 0) | |
42 | return (0); | |
43 | ||
44 | reading = simple_strtol(buf, NULL, 10); | |
45 | switch (reading) { | |
46 | case 0: | |
47 | if (ha->fw_dump_reading == 1) { | |
48 | qla_printk(KERN_INFO, ha, | |
49 | "Firmware dump cleared on (%ld).\n", | |
50 | ha->host_no); | |
51 | ||
52 | vfree(ha->fw_dump_buffer); | |
044cc6c8 | 53 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
fca29703 AV |
54 | free_pages((unsigned long)ha->fw_dump, |
55 | ha->fw_dump_order); | |
8482e118 | 56 | |
57 | ha->fw_dump_reading = 0; | |
58 | ha->fw_dump_buffer = NULL; | |
59 | ha->fw_dump = NULL; | |
fca29703 | 60 | ha->fw_dumped = 0; |
8482e118 | 61 | } |
62 | break; | |
63 | case 1: | |
fca29703 | 64 | if ((ha->fw_dump || ha->fw_dumped) && !ha->fw_dump_reading) { |
8482e118 | 65 | ha->fw_dump_reading = 1; |
66 | ||
044cc6c8 | 67 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
fca29703 AV |
68 | dump_size = FW_DUMP_SIZE_24XX; |
69 | else { | |
70 | dump_size = FW_DUMP_SIZE_1M; | |
71 | if (ha->fw_memory_size < 0x20000) | |
72 | dump_size = FW_DUMP_SIZE_128K; | |
73 | else if (ha->fw_memory_size < 0x80000) | |
74 | dump_size = FW_DUMP_SIZE_512K; | |
75 | } | |
8482e118 | 76 | ha->fw_dump_buffer = (char *)vmalloc(dump_size); |
77 | if (ha->fw_dump_buffer == NULL) { | |
78 | qla_printk(KERN_WARNING, ha, | |
79 | "Unable to allocate memory for firmware " | |
80 | "dump buffer (%d).\n", dump_size); | |
81 | ||
82 | ha->fw_dump_reading = 0; | |
83 | return (count); | |
84 | } | |
85 | qla_printk(KERN_INFO, ha, | |
86 | "Firmware dump ready for read on (%ld).\n", | |
87 | ha->host_no); | |
88 | memset(ha->fw_dump_buffer, 0, dump_size); | |
abbd8870 | 89 | ha->isp_ops.ascii_fw_dump(ha); |
8482e118 | 90 | ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer); |
91 | } | |
92 | break; | |
93 | } | |
94 | return (count); | |
95 | } | |
96 | ||
97 | static struct bin_attribute sysfs_fw_dump_attr = { | |
98 | .attr = { | |
99 | .name = "fw_dump", | |
100 | .mode = S_IRUSR | S_IWUSR, | |
101 | .owner = THIS_MODULE, | |
102 | }, | |
103 | .size = 0, | |
104 | .read = qla2x00_sysfs_read_fw_dump, | |
105 | .write = qla2x00_sysfs_write_fw_dump, | |
106 | }; | |
107 | ||
108 | static ssize_t | |
109 | qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off, | |
110 | size_t count) | |
111 | { | |
112 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
113 | struct device, kobj))); | |
8482e118 | 114 | unsigned long flags; |
8482e118 | 115 | |
1b3f6365 | 116 | if (!capable(CAP_SYS_ADMIN) || off != 0) |
8482e118 | 117 | return 0; |
118 | ||
119 | /* Read NVRAM. */ | |
120 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
459c5378 AV |
121 | ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base, |
122 | ha->nvram_size); | |
8482e118 | 123 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
124 | ||
1b3f6365 | 125 | return ha->nvram_size; |
8482e118 | 126 | } |
127 | ||
128 | static ssize_t | |
129 | qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off, | |
130 | size_t count) | |
131 | { | |
132 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
133 | struct device, kobj))); | |
8482e118 | 134 | unsigned long flags; |
135 | uint16_t cnt; | |
8482e118 | 136 | |
459c5378 | 137 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size) |
8482e118 | 138 | return 0; |
139 | ||
140 | /* Checksum NVRAM. */ | |
044cc6c8 | 141 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
459c5378 AV |
142 | uint32_t *iter; |
143 | uint32_t chksum; | |
144 | ||
145 | iter = (uint32_t *)buf; | |
146 | chksum = 0; | |
147 | for (cnt = 0; cnt < ((count >> 2) - 1); cnt++) | |
148 | chksum += le32_to_cpu(*iter++); | |
149 | chksum = ~chksum + 1; | |
150 | *iter = cpu_to_le32(chksum); | |
151 | } else { | |
152 | uint8_t *iter; | |
153 | uint8_t chksum; | |
154 | ||
155 | iter = (uint8_t *)buf; | |
156 | chksum = 0; | |
157 | for (cnt = 0; cnt < count - 1; cnt++) | |
158 | chksum += *iter++; | |
159 | chksum = ~chksum + 1; | |
160 | *iter = chksum; | |
161 | } | |
8482e118 | 162 | |
163 | /* Write NVRAM. */ | |
164 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
459c5378 | 165 | ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count); |
8482e118 | 166 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
167 | ||
168 | return (count); | |
169 | } | |
170 | ||
171 | static struct bin_attribute sysfs_nvram_attr = { | |
172 | .attr = { | |
173 | .name = "nvram", | |
174 | .mode = S_IRUSR | S_IWUSR, | |
175 | .owner = THIS_MODULE, | |
176 | }, | |
1b3f6365 | 177 | .size = 512, |
8482e118 | 178 | .read = qla2x00_sysfs_read_nvram, |
179 | .write = qla2x00_sysfs_write_nvram, | |
180 | }; | |
181 | ||
854165f4 | 182 | static ssize_t |
183 | qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off, | |
184 | size_t count) | |
185 | { | |
186 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
187 | struct device, kobj))); | |
188 | ||
189 | if (ha->optrom_state != QLA_SREADING) | |
190 | return 0; | |
191 | if (off > ha->optrom_size) | |
192 | return 0; | |
193 | if (off + count > ha->optrom_size) | |
194 | count = ha->optrom_size - off; | |
195 | ||
196 | memcpy(buf, &ha->optrom_buffer[off], count); | |
197 | ||
198 | return count; | |
199 | } | |
200 | ||
201 | static ssize_t | |
202 | qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off, | |
203 | size_t count) | |
204 | { | |
205 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
206 | struct device, kobj))); | |
207 | ||
208 | if (ha->optrom_state != QLA_SWRITING) | |
209 | return -EINVAL; | |
210 | if (off > ha->optrom_size) | |
211 | return -ERANGE; | |
212 | if (off + count > ha->optrom_size) | |
213 | count = ha->optrom_size - off; | |
214 | ||
215 | memcpy(&ha->optrom_buffer[off], buf, count); | |
216 | ||
217 | return count; | |
218 | } | |
219 | ||
220 | static struct bin_attribute sysfs_optrom_attr = { | |
221 | .attr = { | |
222 | .name = "optrom", | |
223 | .mode = S_IRUSR | S_IWUSR, | |
224 | .owner = THIS_MODULE, | |
225 | }, | |
226 | .size = OPTROM_SIZE_24XX, | |
227 | .read = qla2x00_sysfs_read_optrom, | |
228 | .write = qla2x00_sysfs_write_optrom, | |
229 | }; | |
230 | ||
231 | static ssize_t | |
232 | qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off, | |
233 | size_t count) | |
234 | { | |
235 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
236 | struct device, kobj))); | |
237 | int val; | |
238 | ||
239 | if (off) | |
240 | return 0; | |
241 | ||
242 | if (sscanf(buf, "%d", &val) != 1) | |
243 | return -EINVAL; | |
244 | ||
245 | switch (val) { | |
246 | case 0: | |
247 | if (ha->optrom_state != QLA_SREADING && | |
248 | ha->optrom_state != QLA_SWRITING) | |
249 | break; | |
250 | ||
251 | ha->optrom_state = QLA_SWAITING; | |
252 | vfree(ha->optrom_buffer); | |
253 | ha->optrom_buffer = NULL; | |
254 | break; | |
255 | case 1: | |
256 | if (ha->optrom_state != QLA_SWAITING) | |
257 | break; | |
258 | ||
259 | ha->optrom_state = QLA_SREADING; | |
260 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); | |
261 | if (ha->optrom_buffer == NULL) { | |
262 | qla_printk(KERN_WARNING, ha, | |
263 | "Unable to allocate memory for optrom retrieval " | |
264 | "(%x).\n", ha->optrom_size); | |
265 | ||
266 | ha->optrom_state = QLA_SWAITING; | |
267 | return count; | |
268 | } | |
269 | ||
270 | memset(ha->optrom_buffer, 0, ha->optrom_size); | |
271 | ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0, | |
272 | ha->optrom_size); | |
273 | break; | |
274 | case 2: | |
275 | if (ha->optrom_state != QLA_SWAITING) | |
276 | break; | |
277 | ||
278 | ha->optrom_state = QLA_SWRITING; | |
279 | ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size); | |
280 | if (ha->optrom_buffer == NULL) { | |
281 | qla_printk(KERN_WARNING, ha, | |
282 | "Unable to allocate memory for optrom update " | |
283 | "(%x).\n", ha->optrom_size); | |
284 | ||
285 | ha->optrom_state = QLA_SWAITING; | |
286 | return count; | |
287 | } | |
288 | memset(ha->optrom_buffer, 0, ha->optrom_size); | |
289 | break; | |
290 | case 3: | |
291 | if (ha->optrom_state != QLA_SWRITING) | |
292 | break; | |
293 | ||
294 | ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0, | |
295 | ha->optrom_size); | |
296 | break; | |
297 | } | |
298 | return count; | |
299 | } | |
300 | ||
301 | static struct bin_attribute sysfs_optrom_ctl_attr = { | |
302 | .attr = { | |
303 | .name = "optrom_ctl", | |
304 | .mode = S_IWUSR, | |
305 | .owner = THIS_MODULE, | |
306 | }, | |
307 | .size = 0, | |
308 | .write = qla2x00_sysfs_write_optrom_ctl, | |
309 | }; | |
310 | ||
6f641790 | 311 | static ssize_t |
312 | qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off, | |
313 | size_t count) | |
314 | { | |
315 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
316 | struct device, kobj))); | |
317 | unsigned long flags; | |
318 | ||
319 | if (!capable(CAP_SYS_ADMIN) || off != 0) | |
320 | return 0; | |
321 | ||
322 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) | |
323 | return -ENOTSUPP; | |
324 | ||
325 | /* Read NVRAM. */ | |
326 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
327 | ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size); | |
328 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
329 | ||
330 | return ha->vpd_size; | |
331 | } | |
332 | ||
333 | static ssize_t | |
334 | qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off, | |
335 | size_t count) | |
336 | { | |
337 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, | |
338 | struct device, kobj))); | |
339 | unsigned long flags; | |
340 | ||
341 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size) | |
342 | return 0; | |
343 | ||
344 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) | |
345 | return -ENOTSUPP; | |
346 | ||
347 | /* Write NVRAM. */ | |
348 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
349 | ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count); | |
350 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
351 | ||
352 | return count; | |
353 | } | |
354 | ||
355 | static struct bin_attribute sysfs_vpd_attr = { | |
356 | .attr = { | |
357 | .name = "vpd", | |
358 | .mode = S_IRUSR | S_IWUSR, | |
359 | .owner = THIS_MODULE, | |
360 | }, | |
361 | .size = 0, | |
362 | .read = qla2x00_sysfs_read_vpd, | |
363 | .write = qla2x00_sysfs_write_vpd, | |
364 | }; | |
365 | ||
8482e118 | 366 | void |
367 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) | |
368 | { | |
369 | struct Scsi_Host *host = ha->host; | |
370 | ||
371 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr); | |
372 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); | |
854165f4 | 373 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); |
374 | sysfs_create_bin_file(&host->shost_gendev.kobj, | |
375 | &sysfs_optrom_ctl_attr); | |
6f641790 | 376 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr); |
8482e118 | 377 | } |
378 | ||
379 | void | |
380 | qla2x00_free_sysfs_attr(scsi_qla_host_t *ha) | |
381 | { | |
382 | struct Scsi_Host *host = ha->host; | |
383 | ||
384 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr); | |
385 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); | |
854165f4 | 386 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); |
387 | sysfs_remove_bin_file(&host->shost_gendev.kobj, | |
388 | &sysfs_optrom_ctl_attr); | |
6f641790 | 389 | sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr); |
f6df144c | 390 | |
391 | if (ha->beacon_blink_led == 1) | |
392 | ha->isp_ops.beacon_off(ha); | |
8482e118 | 393 | } |
394 | ||
afb046e2 AV |
395 | /* Scsi_Host attributes. */ |
396 | ||
397 | static ssize_t | |
398 | qla2x00_drvr_version_show(struct class_device *cdev, char *buf) | |
399 | { | |
400 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); | |
401 | } | |
402 | ||
403 | static ssize_t | |
404 | qla2x00_fw_version_show(struct class_device *cdev, char *buf) | |
405 | { | |
406 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
407 | char fw_str[30]; | |
408 | ||
409 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
410 | ha->isp_ops.fw_version_str(ha, fw_str)); | |
411 | } | |
412 | ||
413 | static ssize_t | |
414 | qla2x00_serial_num_show(struct class_device *cdev, char *buf) | |
415 | { | |
416 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
417 | uint32_t sn; | |
418 | ||
419 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; | |
420 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, | |
421 | sn % 100000); | |
422 | } | |
423 | ||
424 | static ssize_t | |
425 | qla2x00_isp_name_show(struct class_device *cdev, char *buf) | |
426 | { | |
427 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
5433383e | 428 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device); |
afb046e2 AV |
429 | } |
430 | ||
431 | static ssize_t | |
432 | qla2x00_isp_id_show(struct class_device *cdev, char *buf) | |
433 | { | |
434 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
435 | return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n", | |
436 | ha->product_id[0], ha->product_id[1], ha->product_id[2], | |
437 | ha->product_id[3]); | |
438 | } | |
439 | ||
440 | static ssize_t | |
441 | qla2x00_model_name_show(struct class_device *cdev, char *buf) | |
442 | { | |
443 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
444 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number); | |
445 | } | |
446 | ||
447 | static ssize_t | |
448 | qla2x00_model_desc_show(struct class_device *cdev, char *buf) | |
449 | { | |
450 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
451 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
452 | ha->model_desc ? ha->model_desc: ""); | |
453 | } | |
454 | ||
455 | static ssize_t | |
456 | qla2x00_pci_info_show(struct class_device *cdev, char *buf) | |
457 | { | |
458 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
459 | char pci_info[30]; | |
460 | ||
461 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
462 | ha->isp_ops.pci_info_str(ha, pci_info)); | |
463 | } | |
464 | ||
465 | static ssize_t | |
466 | qla2x00_state_show(struct class_device *cdev, char *buf) | |
467 | { | |
468 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
469 | int len = 0; | |
470 | ||
471 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || | |
472 | atomic_read(&ha->loop_state) == LOOP_DEAD) | |
473 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); | |
474 | else if (atomic_read(&ha->loop_state) != LOOP_READY || | |
475 | test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) || | |
476 | test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) | |
477 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); | |
478 | else { | |
479 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); | |
480 | ||
481 | switch (ha->current_topology) { | |
482 | case ISP_CFG_NL: | |
483 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
484 | break; | |
485 | case ISP_CFG_FL: | |
486 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); | |
487 | break; | |
488 | case ISP_CFG_N: | |
489 | len += snprintf(buf + len, PAGE_SIZE-len, | |
490 | "N_Port to N_Port\n"); | |
491 | break; | |
492 | case ISP_CFG_F: | |
493 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); | |
494 | break; | |
495 | default: | |
496 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
497 | break; | |
498 | } | |
499 | } | |
500 | return len; | |
501 | } | |
502 | ||
4fdfefe5 AV |
503 | static ssize_t |
504 | qla2x00_zio_show(struct class_device *cdev, char *buf) | |
505 | { | |
506 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
507 | int len = 0; | |
508 | ||
509 | switch (ha->zio_mode) { | |
510 | case QLA_ZIO_MODE_5: | |
511 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n"); | |
512 | break; | |
513 | case QLA_ZIO_MODE_6: | |
514 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); | |
515 | break; | |
516 | case QLA_ZIO_DISABLED: | |
517 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
518 | break; | |
519 | } | |
520 | return len; | |
521 | } | |
522 | ||
523 | static ssize_t | |
524 | qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count) | |
525 | { | |
526 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
527 | int val = 0; | |
528 | uint16_t zio_mode; | |
529 | ||
530 | if (sscanf(buf, "%d", &val) != 1) | |
531 | return -EINVAL; | |
532 | ||
533 | switch (val) { | |
534 | case 1: | |
535 | zio_mode = QLA_ZIO_MODE_5; | |
536 | break; | |
537 | case 2: | |
538 | zio_mode = QLA_ZIO_MODE_6; | |
539 | break; | |
540 | default: | |
541 | zio_mode = QLA_ZIO_DISABLED; | |
542 | break; | |
543 | } | |
544 | ||
545 | /* Update per-hba values and queue a reset. */ | |
546 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { | |
547 | ha->zio_mode = zio_mode; | |
548 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
549 | } | |
550 | return strlen(buf); | |
551 | } | |
552 | ||
553 | static ssize_t | |
554 | qla2x00_zio_timer_show(struct class_device *cdev, char *buf) | |
555 | { | |
556 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
557 | ||
558 | return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100); | |
559 | } | |
560 | ||
561 | static ssize_t | |
562 | qla2x00_zio_timer_store(struct class_device *cdev, const char *buf, | |
563 | size_t count) | |
564 | { | |
565 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
566 | int val = 0; | |
567 | uint16_t zio_timer; | |
568 | ||
569 | if (sscanf(buf, "%d", &val) != 1) | |
570 | return -EINVAL; | |
571 | if (val > 25500 || val < 100) | |
572 | return -ERANGE; | |
573 | ||
574 | zio_timer = (uint16_t)(val / 100); | |
575 | ha->zio_timer = zio_timer; | |
576 | ||
577 | return strlen(buf); | |
578 | } | |
579 | ||
f6df144c | 580 | static ssize_t |
581 | qla2x00_beacon_show(struct class_device *cdev, char *buf) | |
582 | { | |
583 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
584 | int len = 0; | |
585 | ||
586 | if (ha->beacon_blink_led) | |
587 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); | |
588 | else | |
589 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
590 | return len; | |
591 | } | |
592 | ||
593 | static ssize_t | |
594 | qla2x00_beacon_store(struct class_device *cdev, const char *buf, | |
595 | size_t count) | |
596 | { | |
597 | scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev)); | |
598 | int val = 0; | |
599 | int rval; | |
600 | ||
601 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | |
602 | return -EPERM; | |
603 | ||
604 | if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) { | |
605 | qla_printk(KERN_WARNING, ha, | |
606 | "Abort ISP active -- ignoring beacon request.\n"); | |
607 | return -EBUSY; | |
608 | } | |
609 | ||
610 | if (sscanf(buf, "%d", &val) != 1) | |
611 | return -EINVAL; | |
612 | ||
613 | if (val) | |
614 | rval = ha->isp_ops.beacon_on(ha); | |
615 | else | |
616 | rval = ha->isp_ops.beacon_off(ha); | |
617 | ||
618 | if (rval != QLA_SUCCESS) | |
619 | count = 0; | |
620 | ||
621 | return count; | |
622 | } | |
623 | ||
afb046e2 AV |
624 | static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, |
625 | NULL); | |
626 | static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); | |
627 | static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); | |
628 | static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); | |
629 | static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); | |
630 | static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); | |
631 | static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); | |
632 | static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); | |
633 | static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL); | |
4fdfefe5 AV |
634 | static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, |
635 | qla2x00_zio_store); | |
636 | static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, | |
637 | qla2x00_zio_timer_store); | |
f6df144c | 638 | static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, |
639 | qla2x00_beacon_store); | |
afb046e2 AV |
640 | |
641 | struct class_device_attribute *qla2x00_host_attrs[] = { | |
642 | &class_device_attr_driver_version, | |
643 | &class_device_attr_fw_version, | |
644 | &class_device_attr_serial_num, | |
645 | &class_device_attr_isp_name, | |
646 | &class_device_attr_isp_id, | |
647 | &class_device_attr_model_name, | |
648 | &class_device_attr_model_desc, | |
649 | &class_device_attr_pci_info, | |
650 | &class_device_attr_state, | |
4fdfefe5 AV |
651 | &class_device_attr_zio, |
652 | &class_device_attr_zio_timer, | |
f6df144c | 653 | &class_device_attr_beacon, |
afb046e2 AV |
654 | NULL, |
655 | }; | |
656 | ||
8482e118 | 657 | /* Host attributes. */ |
658 | ||
659 | static void | |
660 | qla2x00_get_host_port_id(struct Scsi_Host *shost) | |
661 | { | |
662 | scsi_qla_host_t *ha = to_qla_host(shost); | |
663 | ||
664 | fc_host_port_id(shost) = ha->d_id.b.domain << 16 | | |
665 | ha->d_id.b.area << 8 | ha->d_id.b.al_pa; | |
666 | } | |
667 | ||
04414013 | 668 | static void |
669 | qla2x00_get_host_speed(struct Scsi_Host *shost) | |
670 | { | |
671 | scsi_qla_host_t *ha = to_qla_host(shost); | |
672 | uint32_t speed = 0; | |
673 | ||
674 | switch (ha->link_data_rate) { | |
675 | case LDR_1GB: | |
676 | speed = 1; | |
677 | break; | |
678 | case LDR_2GB: | |
679 | speed = 2; | |
680 | break; | |
681 | case LDR_4GB: | |
682 | speed = 4; | |
683 | break; | |
684 | } | |
685 | fc_host_speed(shost) = speed; | |
686 | } | |
687 | ||
8d067623 | 688 | static void |
689 | qla2x00_get_host_port_type(struct Scsi_Host *shost) | |
690 | { | |
691 | scsi_qla_host_t *ha = to_qla_host(shost); | |
692 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; | |
693 | ||
694 | switch (ha->current_topology) { | |
695 | case ISP_CFG_NL: | |
696 | port_type = FC_PORTTYPE_LPORT; | |
697 | break; | |
698 | case ISP_CFG_FL: | |
699 | port_type = FC_PORTTYPE_NLPORT; | |
700 | break; | |
701 | case ISP_CFG_N: | |
702 | port_type = FC_PORTTYPE_PTP; | |
703 | break; | |
704 | case ISP_CFG_F: | |
705 | port_type = FC_PORTTYPE_NPORT; | |
706 | break; | |
707 | } | |
708 | fc_host_port_type(shost) = port_type; | |
709 | } | |
710 | ||
8482e118 | 711 | static void |
712 | qla2x00_get_starget_node_name(struct scsi_target *starget) | |
713 | { | |
714 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
715 | scsi_qla_host_t *ha = to_qla_host(host); | |
bdf79621 | 716 | fc_port_t *fcport; |
f8b02a85 | 717 | u64 node_name = 0; |
8482e118 | 718 | |
bdf79621 | 719 | list_for_each_entry(fcport, &ha->fcports, list) { |
720 | if (starget->id == fcport->os_target_id) { | |
f8b02a85 | 721 | node_name = wwn_to_u64(fcport->node_name); |
bdf79621 | 722 | break; |
723 | } | |
724 | } | |
725 | ||
f8b02a85 | 726 | fc_starget_node_name(starget) = node_name; |
8482e118 | 727 | } |
728 | ||
729 | static void | |
730 | qla2x00_get_starget_port_name(struct scsi_target *starget) | |
731 | { | |
732 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
733 | scsi_qla_host_t *ha = to_qla_host(host); | |
bdf79621 | 734 | fc_port_t *fcport; |
f8b02a85 | 735 | u64 port_name = 0; |
8482e118 | 736 | |
bdf79621 | 737 | list_for_each_entry(fcport, &ha->fcports, list) { |
738 | if (starget->id == fcport->os_target_id) { | |
f8b02a85 | 739 | port_name = wwn_to_u64(fcport->port_name); |
bdf79621 | 740 | break; |
741 | } | |
742 | } | |
743 | ||
f8b02a85 | 744 | fc_starget_port_name(starget) = port_name; |
8482e118 | 745 | } |
746 | ||
747 | static void | |
748 | qla2x00_get_starget_port_id(struct scsi_target *starget) | |
749 | { | |
750 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
751 | scsi_qla_host_t *ha = to_qla_host(host); | |
bdf79621 | 752 | fc_port_t *fcport; |
753 | uint32_t port_id = ~0U; | |
754 | ||
755 | list_for_each_entry(fcport, &ha->fcports, list) { | |
756 | if (starget->id == fcport->os_target_id) { | |
757 | port_id = fcport->d_id.b.domain << 16 | | |
758 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; | |
759 | break; | |
760 | } | |
761 | } | |
8482e118 | 762 | |
8482e118 | 763 | fc_starget_port_id(starget) = port_id; |
764 | } | |
765 | ||
766 | static void | |
767 | qla2x00_get_rport_loss_tmo(struct fc_rport *rport) | |
768 | { | |
bdf79621 | 769 | struct Scsi_Host *host = rport_to_shost(rport); |
770 | scsi_qla_host_t *ha = to_qla_host(host); | |
8482e118 | 771 | |
772 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; | |
773 | } | |
774 | ||
775 | static void | |
776 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
777 | { | |
bdf79621 | 778 | struct Scsi_Host *host = rport_to_shost(rport); |
779 | scsi_qla_host_t *ha = to_qla_host(host); | |
8482e118 | 780 | |
781 | if (timeout) | |
782 | ha->port_down_retry_count = timeout; | |
783 | else | |
784 | ha->port_down_retry_count = 1; | |
785 | ||
786 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; | |
787 | } | |
788 | ||
91ca7b01 AV |
789 | static int |
790 | qla2x00_issue_lip(struct Scsi_Host *shost) | |
791 | { | |
792 | scsi_qla_host_t *ha = to_qla_host(shost); | |
793 | ||
794 | set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags); | |
795 | return 0; | |
796 | } | |
797 | ||
392e2f65 | 798 | static struct fc_host_statistics * |
799 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) | |
800 | { | |
801 | scsi_qla_host_t *ha = to_qla_host(shost); | |
802 | int rval; | |
803 | uint16_t mb_stat[1]; | |
804 | link_stat_t stat_buf; | |
805 | struct fc_host_statistics *pfc_host_stat; | |
806 | ||
807 | pfc_host_stat = &ha->fc_host_stat; | |
808 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); | |
809 | ||
044cc6c8 | 810 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
392e2f65 | 811 | rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf, |
812 | sizeof(stat_buf) / 4, mb_stat); | |
813 | } else { | |
814 | rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf, | |
815 | mb_stat); | |
816 | } | |
817 | if (rval != 0) { | |
818 | qla_printk(KERN_WARNING, ha, | |
819 | "Unable to retrieve host statistics (%d).\n", mb_stat[0]); | |
820 | return pfc_host_stat; | |
821 | } | |
822 | ||
823 | pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt; | |
824 | pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt; | |
825 | pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt; | |
826 | pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt; | |
827 | pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt; | |
828 | pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt; | |
829 | ||
830 | return pfc_host_stat; | |
831 | } | |
832 | ||
1c97a12a | 833 | struct fc_function_template qla2xxx_transport_functions = { |
8482e118 | 834 | |
835 | .show_host_node_name = 1, | |
836 | .show_host_port_name = 1, | |
ad3e0eda AV |
837 | .show_host_supported_classes = 1, |
838 | ||
8482e118 | 839 | .get_host_port_id = qla2x00_get_host_port_id, |
840 | .show_host_port_id = 1, | |
04414013 | 841 | .get_host_speed = qla2x00_get_host_speed, |
842 | .show_host_speed = 1, | |
8d067623 | 843 | .get_host_port_type = qla2x00_get_host_port_type, |
844 | .show_host_port_type = 1, | |
8482e118 | 845 | |
bdf79621 | 846 | .dd_fcrport_size = sizeof(struct fc_port *), |
ad3e0eda | 847 | .show_rport_supported_classes = 1, |
8482e118 | 848 | |
849 | .get_starget_node_name = qla2x00_get_starget_node_name, | |
850 | .show_starget_node_name = 1, | |
851 | .get_starget_port_name = qla2x00_get_starget_port_name, | |
852 | .show_starget_port_name = 1, | |
853 | .get_starget_port_id = qla2x00_get_starget_port_id, | |
854 | .show_starget_port_id = 1, | |
855 | ||
856 | .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo, | |
857 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, | |
858 | .show_rport_dev_loss_tmo = 1, | |
859 | ||
91ca7b01 | 860 | .issue_fc_host_lip = qla2x00_issue_lip, |
392e2f65 | 861 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
8482e118 | 862 | }; |
863 | ||
8482e118 | 864 | void |
865 | qla2x00_init_host_attr(scsi_qla_host_t *ha) | |
866 | { | |
dad9c8c1 | 867 | fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name); |
868 | fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name); | |
ad3e0eda | 869 | fc_host_supported_classes(ha->host) = FC_COS_CLASS3; |
8482e118 | 870 | } |