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