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