[SCSI] qla2xxx: Export negotiated fabric-parameters for application support.
[deliverable/linux.git] / drivers / scsi / qla2xxx / qla_attr.c
CommitLineData
8482e118 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
01e58d8e 3 * Copyright (c) 2003-2008 QLogic Corporation
8482e118 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
8482e118 6 */
7#include "qla_def.h"
8
2c3dfe3f 9#include <linux/kthread.h>
7aaef27b 10#include <linux/vmalloc.h>
00eabe7c 11#include <linux/delay.h>
8482e118 12
a824ebb3 13static int qla24xx_vport_disable(struct fc_vport *, bool);
2c3dfe3f 14
8482e118 15/* SYSFS attributes --------------------------------------------------------- */
16
17static ssize_t
91a69029
ZR
18qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
19 struct bin_attribute *bin_attr,
20 char *buf, loff_t off, size_t count)
8482e118 21{
7b867cf7 22 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 23 struct device, kobj)));
7b867cf7 24 struct qla_hw_data *ha = vha->hw;
8482e118 25
26 if (ha->fw_dump_reading == 0)
27 return 0;
8482e118 28
b3dc9088
AM
29 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
30 ha->fw_dump_len);
8482e118 31}
32
33static ssize_t
91a69029
ZR
34qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
35 struct bin_attribute *bin_attr,
36 char *buf, loff_t off, size_t count)
8482e118 37{
7b867cf7 38 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 39 struct device, kobj)));
7b867cf7 40 struct qla_hw_data *ha = vha->hw;
8482e118 41 int reading;
8482e118 42
43 if (off != 0)
44 return (0);
45
46 reading = simple_strtol(buf, NULL, 10);
47 switch (reading) {
48 case 0:
a7a167bf
AV
49 if (!ha->fw_dump_reading)
50 break;
8482e118 51
a7a167bf 52 qla_printk(KERN_INFO, ha,
7b867cf7 53 "Firmware dump cleared on (%ld).\n", vha->host_no);
a7a167bf
AV
54
55 ha->fw_dump_reading = 0;
56 ha->fw_dumped = 0;
8482e118 57 break;
58 case 1:
d4e3e04d 59 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e118 60 ha->fw_dump_reading = 1;
61
8482e118 62 qla_printk(KERN_INFO, ha,
a7a167bf 63 "Raw firmware dump ready for read on (%ld).\n",
7b867cf7 64 vha->host_no);
8482e118 65 }
66 break;
a7a167bf 67 case 2:
7b867cf7 68 qla2x00_alloc_fw_dump(vha);
a7a167bf 69 break;
68af0811 70 case 3:
7b867cf7 71 qla2x00_system_error(vha);
68af0811 72 break;
8482e118 73 }
74 return (count);
75}
76
77static struct bin_attribute sysfs_fw_dump_attr = {
78 .attr = {
79 .name = "fw_dump",
80 .mode = S_IRUSR | S_IWUSR,
8482e118 81 },
82 .size = 0,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
85};
86
87static ssize_t
91a69029
ZR
88qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
8482e118 91{
7b867cf7 92 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 93 struct device, kobj)));
7b867cf7 94 struct qla_hw_data *ha = vha->hw;
8482e118 95
b3dc9088 96 if (!capable(CAP_SYS_ADMIN))
8482e118 97 return 0;
98
6749ce36 99 if (IS_NOCACHE_VPD_TYPE(ha))
8f979751 100 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
6749ce36 101 ha->nvram_size);
b3dc9088
AM
102 return memory_read_from_buffer(buf, count, &off, ha->nvram,
103 ha->nvram_size);
8482e118 104}
105
106static ssize_t
91a69029
ZR
107qla2x00_sysfs_write_nvram(struct kobject *kobj,
108 struct bin_attribute *bin_attr,
109 char *buf, loff_t off, size_t count)
8482e118 110{
7b867cf7 111 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 112 struct device, kobj)));
7b867cf7 113 struct qla_hw_data *ha = vha->hw;
8482e118 114 uint16_t cnt;
8482e118 115
3d79038f
AV
116 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
117 !ha->isp_ops->write_nvram)
8482e118 118 return 0;
119
120 /* Checksum NVRAM. */
e428924c 121 if (IS_FWI2_CAPABLE(ha)) {
459c5378
AV
122 uint32_t *iter;
123 uint32_t chksum;
124
125 iter = (uint32_t *)buf;
126 chksum = 0;
127 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
128 chksum += le32_to_cpu(*iter++);
129 chksum = ~chksum + 1;
130 *iter = cpu_to_le32(chksum);
131 } else {
132 uint8_t *iter;
133 uint8_t chksum;
134
135 iter = (uint8_t *)buf;
136 chksum = 0;
137 for (cnt = 0; cnt < count - 1; cnt++)
138 chksum += *iter++;
139 chksum = ~chksum + 1;
140 *iter = chksum;
141 }
8482e118 142
2533cf67
LC
143 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
144 qla_printk(KERN_WARNING, ha,
145 "HBA not online, failing NVRAM update.\n");
146 return -EAGAIN;
147 }
148
8482e118 149 /* Write NVRAM. */
7b867cf7
AC
150 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
151 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
281afe19 152 count);
8482e118 153
2533cf67 154 /* NVRAM settings take effect immediately. */
7b867cf7 155 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2533cf67
LC
156 qla2xxx_wake_dpc(vha);
157 qla2x00_wait_for_chip_reset(vha);
26b8d348 158
8482e118 159 return (count);
160}
161
162static struct bin_attribute sysfs_nvram_attr = {
163 .attr = {
164 .name = "nvram",
165 .mode = S_IRUSR | S_IWUSR,
8482e118 166 },
1b3f6365 167 .size = 512,
8482e118 168 .read = qla2x00_sysfs_read_nvram,
169 .write = qla2x00_sysfs_write_nvram,
170};
171
854165f4 172static ssize_t
91a69029
ZR
173qla2x00_sysfs_read_optrom(struct kobject *kobj,
174 struct bin_attribute *bin_attr,
175 char *buf, loff_t off, size_t count)
854165f4 176{
7b867cf7 177 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 178 struct device, kobj)));
7b867cf7 179 struct qla_hw_data *ha = vha->hw;
854165f4 180
181 if (ha->optrom_state != QLA_SREADING)
182 return 0;
854165f4 183
b3dc9088
AM
184 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
185 ha->optrom_region_size);
854165f4 186}
187
188static ssize_t
91a69029
ZR
189qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
854165f4 192{
7b867cf7 193 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 194 struct device, kobj)));
7b867cf7 195 struct qla_hw_data *ha = vha->hw;
854165f4 196
197 if (ha->optrom_state != QLA_SWRITING)
198 return -EINVAL;
b7cc176c 199 if (off > ha->optrom_region_size)
854165f4 200 return -ERANGE;
b7cc176c
JC
201 if (off + count > ha->optrom_region_size)
202 count = ha->optrom_region_size - off;
854165f4 203
204 memcpy(&ha->optrom_buffer[off], buf, count);
205
206 return count;
207}
208
209static struct bin_attribute sysfs_optrom_attr = {
210 .attr = {
211 .name = "optrom",
212 .mode = S_IRUSR | S_IWUSR,
854165f4 213 },
c3a2f0df 214 .size = 0,
854165f4 215 .read = qla2x00_sysfs_read_optrom,
216 .write = qla2x00_sysfs_write_optrom,
217};
218
219static ssize_t
91a69029
ZR
220qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
221 struct bin_attribute *bin_attr,
222 char *buf, loff_t off, size_t count)
854165f4 223{
7b867cf7 224 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 225 struct device, kobj)));
7b867cf7
AC
226 struct qla_hw_data *ha = vha->hw;
227
b7cc176c
JC
228 uint32_t start = 0;
229 uint32_t size = ha->optrom_size;
230 int val, valid;
854165f4 231
232 if (off)
233 return 0;
234
b7cc176c
JC
235 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
236 return -EINVAL;
237 if (start > ha->optrom_size)
854165f4 238 return -EINVAL;
239
240 switch (val) {
241 case 0:
242 if (ha->optrom_state != QLA_SREADING &&
243 ha->optrom_state != QLA_SWRITING)
244 break;
245
246 ha->optrom_state = QLA_SWAITING;
b7cc176c
JC
247
248 DEBUG2(qla_printk(KERN_INFO, ha,
249 "Freeing flash region allocation -- 0x%x bytes.\n",
250 ha->optrom_region_size));
251
854165f4 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
b7cc176c
JC
259 ha->optrom_region_start = start;
260 ha->optrom_region_size = start + size > ha->optrom_size ?
261 ha->optrom_size - start : size;
262
854165f4 263 ha->optrom_state = QLA_SREADING;
b7cc176c 264 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4 265 if (ha->optrom_buffer == NULL) {
266 qla_printk(KERN_WARNING, ha,
267 "Unable to allocate memory for optrom retrieval "
b7cc176c 268 "(%x).\n", ha->optrom_region_size);
854165f4 269
270 ha->optrom_state = QLA_SWAITING;
271 return count;
272 }
273
b7cc176c
JC
274 DEBUG2(qla_printk(KERN_INFO, ha,
275 "Reading flash region -- 0x%x/0x%x.\n",
276 ha->optrom_region_start, ha->optrom_region_size));
277
278 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
7b867cf7 279 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
b7cc176c 280 ha->optrom_region_start, ha->optrom_region_size);
854165f4 281 break;
282 case 2:
283 if (ha->optrom_state != QLA_SWAITING)
284 break;
285
b7cc176c
JC
286 /*
287 * We need to be more restrictive on which FLASH regions are
288 * allowed to be updated via user-space. Regions accessible
289 * via this method include:
290 *
291 * ISP21xx/ISP22xx/ISP23xx type boards:
292 *
293 * 0x000000 -> 0x020000 -- Boot code.
294 *
295 * ISP2322/ISP24xx type boards:
296 *
297 * 0x000000 -> 0x07ffff -- Boot code.
298 * 0x080000 -> 0x0fffff -- Firmware.
299 *
300 * ISP25xx type boards:
301 *
302 * 0x000000 -> 0x07ffff -- Boot code.
303 * 0x080000 -> 0x0fffff -- Firmware.
304 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
305 */
306 valid = 0;
307 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
308 valid = 1;
c00d8994
AV
309 else if (start == (ha->flt_region_boot * 4) ||
310 start == (ha->flt_region_fw * 4))
b7cc176c 311 valid = 1;
6431c5dc 312 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
b7cc176c
JC
313 valid = 1;
314 if (!valid) {
315 qla_printk(KERN_WARNING, ha,
316 "Invalid start region 0x%x/0x%x.\n", start, size);
317 return -EINVAL;
318 }
319
320 ha->optrom_region_start = start;
321 ha->optrom_region_size = start + size > ha->optrom_size ?
322 ha->optrom_size - start : size;
323
854165f4 324 ha->optrom_state = QLA_SWRITING;
b7cc176c 325 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4 326 if (ha->optrom_buffer == NULL) {
327 qla_printk(KERN_WARNING, ha,
328 "Unable to allocate memory for optrom update "
b7cc176c 329 "(%x).\n", ha->optrom_region_size);
854165f4 330
331 ha->optrom_state = QLA_SWAITING;
332 return count;
333 }
b7cc176c
JC
334
335 DEBUG2(qla_printk(KERN_INFO, ha,
336 "Staging flash region write -- 0x%x/0x%x.\n",
337 ha->optrom_region_start, ha->optrom_region_size));
338
339 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
854165f4 340 break;
341 case 3:
342 if (ha->optrom_state != QLA_SWRITING)
343 break;
344
2533cf67
LC
345 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
346 qla_printk(KERN_WARNING, ha,
347 "HBA not online, failing flash update.\n");
348 return -EAGAIN;
349 }
350
b7cc176c
JC
351 DEBUG2(qla_printk(KERN_INFO, ha,
352 "Writing flash region -- 0x%x/0x%x.\n",
353 ha->optrom_region_start, ha->optrom_region_size));
354
7b867cf7 355 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
b7cc176c 356 ha->optrom_region_start, ha->optrom_region_size);
854165f4 357 break;
b7cc176c
JC
358 default:
359 count = -EINVAL;
854165f4 360 }
361 return count;
362}
363
364static struct bin_attribute sysfs_optrom_ctl_attr = {
365 .attr = {
366 .name = "optrom_ctl",
367 .mode = S_IWUSR,
854165f4 368 },
369 .size = 0,
370 .write = qla2x00_sysfs_write_optrom_ctl,
371};
372
6f641790 373static ssize_t
91a69029
ZR
374qla2x00_sysfs_read_vpd(struct kobject *kobj,
375 struct bin_attribute *bin_attr,
376 char *buf, loff_t off, size_t count)
6f641790 377{
7b867cf7 378 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 379 struct device, kobj)));
7b867cf7 380 struct qla_hw_data *ha = vha->hw;
6f641790 381
b3dc9088 382 if (!capable(CAP_SYS_ADMIN))
6f641790 383 return 0;
384
6749ce36
AV
385 if (IS_NOCACHE_VPD_TYPE(ha))
386 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
387 ha->vpd_size);
b3dc9088 388 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
6f641790 389}
390
391static ssize_t
91a69029
ZR
392qla2x00_sysfs_write_vpd(struct kobject *kobj,
393 struct bin_attribute *bin_attr,
394 char *buf, loff_t off, size_t count)
6f641790 395{
7b867cf7 396 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 397 struct device, kobj)));
7b867cf7 398 struct qla_hw_data *ha = vha->hw;
d0c3eefa 399 uint8_t *tmp_data;
6f641790 400
3d79038f
AV
401 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
402 !ha->isp_ops->write_nvram)
6f641790 403 return 0;
404
2533cf67
LC
405 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
406 qla_printk(KERN_WARNING, ha,
407 "HBA not online, failing VPD update.\n");
408 return -EAGAIN;
409 }
410
6f641790 411 /* Write NVRAM. */
7b867cf7
AC
412 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
413 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
6f641790 414
d0c3eefa
LC
415 /* Update flash version information for 4Gb & above. */
416 if (!IS_FWI2_CAPABLE(ha))
417 goto done;
418
419 tmp_data = vmalloc(256);
420 if (!tmp_data) {
421 qla_printk(KERN_WARNING, ha,
422 "Unable to allocate memory for VPD information update.\n");
423 goto done;
424 }
425 ha->isp_ops->get_flash_version(vha, tmp_data);
426 vfree(tmp_data);
427done:
6f641790 428 return count;
429}
430
431static struct bin_attribute sysfs_vpd_attr = {
432 .attr = {
433 .name = "vpd",
434 .mode = S_IRUSR | S_IWUSR,
6f641790 435 },
436 .size = 0,
437 .read = qla2x00_sysfs_read_vpd,
438 .write = qla2x00_sysfs_write_vpd,
439};
440
88729e53 441static ssize_t
91a69029
ZR
442qla2x00_sysfs_read_sfp(struct kobject *kobj,
443 struct bin_attribute *bin_attr,
444 char *buf, loff_t off, size_t count)
88729e53 445{
7b867cf7 446 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
88729e53 447 struct device, kobj)));
7b867cf7 448 struct qla_hw_data *ha = vha->hw;
88729e53
AV
449 uint16_t iter, addr, offset;
450 int rval;
451
452 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
453 return 0;
454
e8711085
AV
455 if (ha->sfp_data)
456 goto do_read;
457
458 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
459 &ha->sfp_data_dma);
460 if (!ha->sfp_data) {
461 qla_printk(KERN_WARNING, ha,
462 "Unable to allocate memory for SFP read-data.\n");
463 return 0;
464 }
465
466do_read:
467 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
88729e53
AV
468 addr = 0xa0;
469 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
470 iter++, offset += SFP_BLOCK_SIZE) {
471 if (iter == 4) {
472 /* Skip to next device address. */
473 addr = 0xa2;
474 offset = 0;
475 }
476
7b867cf7 477 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
88729e53
AV
478 SFP_BLOCK_SIZE);
479 if (rval != QLA_SUCCESS) {
480 qla_printk(KERN_WARNING, ha,
481 "Unable to read SFP data (%x/%x/%x).\n", rval,
482 addr, offset);
483 count = 0;
484 break;
485 }
486 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
487 buf += SFP_BLOCK_SIZE;
488 }
489
490 return count;
491}
492
493static struct bin_attribute sysfs_sfp_attr = {
494 .attr = {
495 .name = "sfp",
496 .mode = S_IRUSR | S_IWUSR,
88729e53
AV
497 },
498 .size = SFP_DEV_SIZE * 2,
499 .read = qla2x00_sysfs_read_sfp,
500};
501
6e181be5
LC
502static ssize_t
503qla2x00_sysfs_write_reset(struct kobject *kobj,
504 struct bin_attribute *bin_attr,
505 char *buf, loff_t off, size_t count)
506{
507 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
508 struct device, kobj)));
509 struct qla_hw_data *ha = vha->hw;
510 int type;
511
512 if (off != 0)
513 return 0;
514
515 type = simple_strtol(buf, NULL, 10);
516 switch (type) {
517 case 0x2025c:
518 qla_printk(KERN_INFO, ha,
519 "Issuing ISP reset on (%ld).\n", vha->host_no);
520
521 scsi_block_requests(vha->host);
522 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
523 qla2xxx_wake_dpc(vha);
524 qla2x00_wait_for_chip_reset(vha);
525 scsi_unblock_requests(vha->host);
526 break;
527 case 0x2025d:
528 if (!IS_QLA81XX(ha))
529 break;
530
531 qla_printk(KERN_INFO, ha,
532 "Issuing MPI reset on (%ld).\n", vha->host_no);
533
534 /* Make sure FC side is not in reset */
535 qla2x00_wait_for_hba_online(vha);
536
537 /* Issue MPI reset */
538 scsi_block_requests(vha->host);
539 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
540 qla_printk(KERN_WARNING, ha,
541 "MPI reset failed on (%ld).\n", vha->host_no);
542 scsi_unblock_requests(vha->host);
543 break;
544 }
545 return count;
546}
547
548static struct bin_attribute sysfs_reset_attr = {
549 .attr = {
550 .name = "reset",
551 .mode = S_IWUSR,
552 },
553 .size = 0,
554 .write = qla2x00_sysfs_write_reset,
555};
556
ad0ecd61
JC
557static ssize_t
558qla2x00_sysfs_write_edc(struct kobject *kobj,
559 struct bin_attribute *bin_attr,
560 char *buf, loff_t off, size_t count)
561{
562 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
563 struct device, kobj)));
564 struct qla_hw_data *ha = vha->hw;
565 uint16_t dev, adr, opt, len;
566 int rval;
567
568 ha->edc_data_len = 0;
569
570 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
571 return 0;
572
573 if (!ha->edc_data) {
574 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
575 &ha->edc_data_dma);
576 if (!ha->edc_data) {
577 DEBUG2(qla_printk(KERN_INFO, ha,
578 "Unable to allocate memory for EDC write.\n"));
579 return 0;
580 }
581 }
582
583 dev = le16_to_cpup((void *)&buf[0]);
584 adr = le16_to_cpup((void *)&buf[2]);
585 opt = le16_to_cpup((void *)&buf[4]);
586 len = le16_to_cpup((void *)&buf[6]);
587
588 if (!(opt & BIT_0))
589 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
590 return -EINVAL;
591
592 memcpy(ha->edc_data, &buf[8], len);
593
594 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
595 ha->edc_data, len, opt);
596 if (rval != QLA_SUCCESS) {
597 DEBUG2(qla_printk(KERN_INFO, ha,
598 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
599 rval, dev, adr, opt, len, *buf));
600 return 0;
601 }
602
603 return count;
604}
605
606static struct bin_attribute sysfs_edc_attr = {
607 .attr = {
608 .name = "edc",
609 .mode = S_IWUSR,
610 },
611 .size = 0,
612 .write = qla2x00_sysfs_write_edc,
613};
614
615static ssize_t
616qla2x00_sysfs_write_edc_status(struct kobject *kobj,
617 struct bin_attribute *bin_attr,
618 char *buf, loff_t off, size_t count)
619{
620 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
621 struct device, kobj)));
622 struct qla_hw_data *ha = vha->hw;
623 uint16_t dev, adr, opt, len;
624 int rval;
625
626 ha->edc_data_len = 0;
627
628 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
629 return 0;
630
631 if (!ha->edc_data) {
632 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
633 &ha->edc_data_dma);
634 if (!ha->edc_data) {
635 DEBUG2(qla_printk(KERN_INFO, ha,
636 "Unable to allocate memory for EDC status.\n"));
637 return 0;
638 }
639 }
640
641 dev = le16_to_cpup((void *)&buf[0]);
642 adr = le16_to_cpup((void *)&buf[2]);
643 opt = le16_to_cpup((void *)&buf[4]);
644 len = le16_to_cpup((void *)&buf[6]);
645
646 if (!(opt & BIT_0))
647 if (len == 0 || len > DMA_POOL_SIZE)
648 return -EINVAL;
649
650 memset(ha->edc_data, 0, len);
651 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
652 ha->edc_data, len, opt);
653 if (rval != QLA_SUCCESS) {
654 DEBUG2(qla_printk(KERN_INFO, ha,
655 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
656 rval, dev, adr, opt, len));
657 return 0;
658 }
659
660 ha->edc_data_len = len;
661
662 return count;
663}
664
665static ssize_t
666qla2x00_sysfs_read_edc_status(struct kobject *kobj,
667 struct bin_attribute *bin_attr,
668 char *buf, loff_t off, size_t count)
669{
670 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
671 struct device, kobj)));
672 struct qla_hw_data *ha = vha->hw;
673
674 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
675 return 0;
676
677 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
678 return -EINVAL;
679
680 memcpy(buf, ha->edc_data, ha->edc_data_len);
681
682 return ha->edc_data_len;
683}
684
685static struct bin_attribute sysfs_edc_status_attr = {
686 .attr = {
687 .name = "edc_status",
688 .mode = S_IRUSR | S_IWUSR,
689 },
690 .size = 0,
691 .write = qla2x00_sysfs_write_edc_status,
692 .read = qla2x00_sysfs_read_edc_status,
693};
694
f1663ad5
AV
695static struct sysfs_entry {
696 char *name;
697 struct bin_attribute *attr;
698 int is4GBp_only;
699} bin_file_entries[] = {
700 { "fw_dump", &sysfs_fw_dump_attr, },
701 { "nvram", &sysfs_nvram_attr, },
702 { "optrom", &sysfs_optrom_attr, },
703 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
704 { "vpd", &sysfs_vpd_attr, 1 },
705 { "sfp", &sysfs_sfp_attr, 1 },
6e181be5 706 { "reset", &sysfs_reset_attr, },
ad0ecd61
JC
707 { "edc", &sysfs_edc_attr, 2 },
708 { "edc_status", &sysfs_edc_status_attr, 2 },
46ddab7b 709 { NULL },
f1663ad5
AV
710};
711
8482e118 712void
7b867cf7 713qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e118 714{
7b867cf7 715 struct Scsi_Host *host = vha->host;
f1663ad5
AV
716 struct sysfs_entry *iter;
717 int ret;
8482e118 718
f1663ad5 719 for (iter = bin_file_entries; iter->name; iter++) {
7b867cf7 720 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
f1663ad5 721 continue;
ad0ecd61
JC
722 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
723 continue;
f1663ad5
AV
724
725 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
726 iter->attr);
727 if (ret)
7b867cf7 728 qla_printk(KERN_INFO, vha->hw,
f1663ad5
AV
729 "Unable to create sysfs %s binary attribute "
730 "(%d).\n", iter->name, ret);
7914d004 731 }
8482e118 732}
733
734void
7b867cf7 735qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e118 736{
7b867cf7 737 struct Scsi_Host *host = vha->host;
f1663ad5 738 struct sysfs_entry *iter;
7b867cf7 739 struct qla_hw_data *ha = vha->hw;
f1663ad5
AV
740
741 for (iter = bin_file_entries; iter->name; iter++) {
e428924c 742 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
f1663ad5 743 continue;
ad0ecd61
JC
744 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
745 continue;
8482e118 746
88729e53 747 sysfs_remove_bin_file(&host->shost_gendev.kobj,
f1663ad5 748 iter->attr);
7914d004 749 }
f6df144c 750
751 if (ha->beacon_blink_led == 1)
7b867cf7 752 ha->isp_ops->beacon_off(vha);
8482e118 753}
754
afb046e2
AV
755/* Scsi_Host attributes. */
756
757static ssize_t
ee959b00
TJ
758qla2x00_drvr_version_show(struct device *dev,
759 struct device_attribute *attr, char *buf)
afb046e2
AV
760{
761 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
762}
763
764static ssize_t
ee959b00
TJ
765qla2x00_fw_version_show(struct device *dev,
766 struct device_attribute *attr, char *buf)
afb046e2 767{
7b867cf7
AC
768 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
769 struct qla_hw_data *ha = vha->hw;
770 char fw_str[128];
afb046e2
AV
771
772 return snprintf(buf, PAGE_SIZE, "%s\n",
7b867cf7 773 ha->isp_ops->fw_version_str(vha, fw_str));
afb046e2
AV
774}
775
776static ssize_t
ee959b00
TJ
777qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
778 char *buf)
afb046e2 779{
7b867cf7
AC
780 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
781 struct qla_hw_data *ha = vha->hw;
afb046e2
AV
782 uint32_t sn;
783
1ee27146 784 if (IS_FWI2_CAPABLE(ha)) {
7b867cf7 785 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
1ee27146
JC
786 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
787 }
8b7afc2a 788
afb046e2
AV
789 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
790 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
791 sn % 100000);
792}
793
794static ssize_t
ee959b00
TJ
795qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
796 char *buf)
afb046e2 797{
7b867cf7
AC
798 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
799 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
afb046e2
AV
800}
801
802static ssize_t
ee959b00
TJ
803qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
804 char *buf)
afb046e2 805{
7b867cf7
AC
806 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
807 struct qla_hw_data *ha = vha->hw;
afb046e2
AV
808 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
809 ha->product_id[0], ha->product_id[1], ha->product_id[2],
810 ha->product_id[3]);
811}
812
813static ssize_t
ee959b00
TJ
814qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
815 char *buf)
afb046e2 816{
7b867cf7
AC
817 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
818 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
afb046e2
AV
819}
820
821static ssize_t
ee959b00
TJ
822qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
823 char *buf)
afb046e2 824{
7b867cf7 825 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
afb046e2 826 return snprintf(buf, PAGE_SIZE, "%s\n",
7b867cf7 827 vha->hw->model_desc ? vha->hw->model_desc : "");
afb046e2
AV
828}
829
830static ssize_t
ee959b00
TJ
831qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
832 char *buf)
afb046e2 833{
7b867cf7 834 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
afb046e2
AV
835 char pci_info[30];
836
837 return snprintf(buf, PAGE_SIZE, "%s\n",
7b867cf7 838 vha->hw->isp_ops->pci_info_str(vha, pci_info));
afb046e2
AV
839}
840
841static ssize_t
bbd1ae41
HR
842qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
843 char *buf)
afb046e2 844{
7b867cf7
AC
845 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
846 struct qla_hw_data *ha = vha->hw;
afb046e2
AV
847 int len = 0;
848
7b867cf7
AC
849 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
850 atomic_read(&vha->loop_state) == LOOP_DEAD)
afb046e2 851 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
7b867cf7
AC
852 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
853 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
854 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
afb046e2
AV
855 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
856 else {
857 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
858
859 switch (ha->current_topology) {
860 case ISP_CFG_NL:
861 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
862 break;
863 case ISP_CFG_FL:
864 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
865 break;
866 case ISP_CFG_N:
867 len += snprintf(buf + len, PAGE_SIZE-len,
868 "N_Port to N_Port\n");
869 break;
870 case ISP_CFG_F:
871 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
872 break;
873 default:
874 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
875 break;
876 }
877 }
878 return len;
879}
880
4fdfefe5 881static ssize_t
ee959b00
TJ
882qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
883 char *buf)
4fdfefe5 884{
7b867cf7 885 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
886 int len = 0;
887
7b867cf7 888 switch (vha->hw->zio_mode) {
4fdfefe5
AV
889 case QLA_ZIO_MODE_6:
890 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
891 break;
892 case QLA_ZIO_DISABLED:
893 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
894 break;
895 }
896 return len;
897}
898
899static ssize_t
ee959b00
TJ
900qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
901 const char *buf, size_t count)
4fdfefe5 902{
7b867cf7
AC
903 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
904 struct qla_hw_data *ha = vha->hw;
4fdfefe5
AV
905 int val = 0;
906 uint16_t zio_mode;
907
4a59f71d 908 if (!IS_ZIO_SUPPORTED(ha))
909 return -ENOTSUPP;
910
4fdfefe5
AV
911 if (sscanf(buf, "%d", &val) != 1)
912 return -EINVAL;
913
4a59f71d 914 if (val)
4fdfefe5 915 zio_mode = QLA_ZIO_MODE_6;
4a59f71d 916 else
4fdfefe5 917 zio_mode = QLA_ZIO_DISABLED;
4fdfefe5
AV
918
919 /* Update per-hba values and queue a reset. */
920 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
921 ha->zio_mode = zio_mode;
7b867cf7 922 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4fdfefe5
AV
923 }
924 return strlen(buf);
925}
926
927static ssize_t
ee959b00
TJ
928qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
929 char *buf)
4fdfefe5 930{
7b867cf7 931 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5 932
7b867cf7 933 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
4fdfefe5
AV
934}
935
936static ssize_t
ee959b00
TJ
937qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
938 const char *buf, size_t count)
4fdfefe5 939{
7b867cf7 940 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
941 int val = 0;
942 uint16_t zio_timer;
943
944 if (sscanf(buf, "%d", &val) != 1)
945 return -EINVAL;
946 if (val > 25500 || val < 100)
947 return -ERANGE;
948
949 zio_timer = (uint16_t)(val / 100);
7b867cf7 950 vha->hw->zio_timer = zio_timer;
4fdfefe5
AV
951
952 return strlen(buf);
953}
954
f6df144c 955static ssize_t
ee959b00
TJ
956qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
957 char *buf)
f6df144c 958{
7b867cf7 959 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
f6df144c 960 int len = 0;
961
7b867cf7 962 if (vha->hw->beacon_blink_led)
f6df144c 963 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
964 else
965 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
966 return len;
967}
968
969static ssize_t
ee959b00
TJ
970qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
971 const char *buf, size_t count)
f6df144c 972{
7b867cf7
AC
973 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
974 struct qla_hw_data *ha = vha->hw;
f6df144c 975 int val = 0;
976 int rval;
977
978 if (IS_QLA2100(ha) || IS_QLA2200(ha))
979 return -EPERM;
980
7b867cf7 981 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
f6df144c 982 qla_printk(KERN_WARNING, ha,
983 "Abort ISP active -- ignoring beacon request.\n");
984 return -EBUSY;
985 }
986
987 if (sscanf(buf, "%d", &val) != 1)
988 return -EINVAL;
989
990 if (val)
7b867cf7 991 rval = ha->isp_ops->beacon_on(vha);
f6df144c 992 else
7b867cf7 993 rval = ha->isp_ops->beacon_off(vha);
f6df144c 994
995 if (rval != QLA_SUCCESS)
996 count = 0;
997
998 return count;
999}
1000
30c47662 1001static ssize_t
ee959b00
TJ
1002qla2x00_optrom_bios_version_show(struct device *dev,
1003 struct device_attribute *attr, char *buf)
30c47662 1004{
7b867cf7
AC
1005 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1006 struct qla_hw_data *ha = vha->hw;
30c47662
AV
1007 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1008 ha->bios_revision[0]);
1009}
1010
1011static ssize_t
ee959b00
TJ
1012qla2x00_optrom_efi_version_show(struct device *dev,
1013 struct device_attribute *attr, char *buf)
30c47662 1014{
7b867cf7
AC
1015 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1016 struct qla_hw_data *ha = vha->hw;
30c47662
AV
1017 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1018 ha->efi_revision[0]);
1019}
1020
1021static ssize_t
ee959b00
TJ
1022qla2x00_optrom_fcode_version_show(struct device *dev,
1023 struct device_attribute *attr, char *buf)
30c47662 1024{
7b867cf7
AC
1025 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1026 struct qla_hw_data *ha = vha->hw;
30c47662
AV
1027 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1028 ha->fcode_revision[0]);
1029}
1030
1031static ssize_t
ee959b00
TJ
1032qla2x00_optrom_fw_version_show(struct device *dev,
1033 struct device_attribute *attr, char *buf)
30c47662 1034{
7b867cf7
AC
1035 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1036 struct qla_hw_data *ha = vha->hw;
30c47662
AV
1037 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1038 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1039 ha->fw_revision[3]);
1040}
1041
e5f5f6f7
HZ
1042static ssize_t
1043qla2x00_total_isp_aborts_show(struct device *dev,
1044 struct device_attribute *attr, char *buf)
1045{
7b867cf7
AC
1046 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1047 struct qla_hw_data *ha = vha->hw;
e5f5f6f7
HZ
1048 return snprintf(buf, PAGE_SIZE, "%d\n",
1049 ha->qla_stats.total_isp_aborts);
1050}
1051
3a03eb79
AV
1052static ssize_t
1053qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1054 char *buf)
1055{
1056 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1057 struct qla_hw_data *ha = vha->hw;
1058
1059 if (!IS_QLA81XX(ha))
1060 return snprintf(buf, PAGE_SIZE, "\n");
1061
55a96158 1062 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
3a03eb79 1063 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
55a96158
AV
1064 ha->mpi_capabilities);
1065}
1066
1067static ssize_t
1068qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1069 char *buf)
1070{
1071 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1072 struct qla_hw_data *ha = vha->hw;
1073
1074 if (!IS_QLA81XX(ha))
1075 return snprintf(buf, PAGE_SIZE, "\n");
1076
1077 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1078 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
3a03eb79
AV
1079}
1080
fbcbb5d0
LC
1081static ssize_t
1082qla2x00_flash_block_size_show(struct device *dev,
1083 struct device_attribute *attr, char *buf)
1084{
1085 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1086 struct qla_hw_data *ha = vha->hw;
1087
1088 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1089}
1090
bad7001c
AV
1091static ssize_t
1092qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
1094{
1095 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1096
1097 if (!IS_QLA81XX(vha->hw))
1098 return snprintf(buf, PAGE_SIZE, "\n");
1099
1100 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1101}
1102
1103static ssize_t
1104qla2x00_vn_port_mac_address_show(struct device *dev,
1105 struct device_attribute *attr, char *buf)
1106{
1107 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1108
1109 if (!IS_QLA81XX(vha->hw))
1110 return snprintf(buf, PAGE_SIZE, "\n");
1111
1112 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1113 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1114 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1115 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1116}
1117
7f774025
AV
1118static ssize_t
1119qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1120 char *buf)
1121{
1122 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1123
1124 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1125}
1126
ee959b00
TJ
1127static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1128static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1129static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1130static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1131static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1132static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1133static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1134static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
bbd1ae41 1135static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
ee959b00
TJ
1136static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1137static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1138 qla2x00_zio_timer_store);
1139static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1140 qla2x00_beacon_store);
1141static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1142 qla2x00_optrom_bios_version_show, NULL);
1143static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1144 qla2x00_optrom_efi_version_show, NULL);
1145static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1146 qla2x00_optrom_fcode_version_show, NULL);
1147static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1148 NULL);
e5f5f6f7
HZ
1149static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1150 NULL);
3a03eb79 1151static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
55a96158 1152static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
fbcbb5d0
LC
1153static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1154 NULL);
bad7001c
AV
1155static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1156static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1157 qla2x00_vn_port_mac_address_show, NULL);
7f774025 1158static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
ee959b00
TJ
1159
1160struct device_attribute *qla2x00_host_attrs[] = {
1161 &dev_attr_driver_version,
1162 &dev_attr_fw_version,
1163 &dev_attr_serial_num,
1164 &dev_attr_isp_name,
1165 &dev_attr_isp_id,
1166 &dev_attr_model_name,
1167 &dev_attr_model_desc,
1168 &dev_attr_pci_info,
bbd1ae41 1169 &dev_attr_link_state,
ee959b00
TJ
1170 &dev_attr_zio,
1171 &dev_attr_zio_timer,
1172 &dev_attr_beacon,
1173 &dev_attr_optrom_bios_version,
1174 &dev_attr_optrom_efi_version,
1175 &dev_attr_optrom_fcode_version,
1176 &dev_attr_optrom_fw_version,
e5f5f6f7 1177 &dev_attr_total_isp_aborts,
3a03eb79 1178 &dev_attr_mpi_version,
55a96158 1179 &dev_attr_phy_version,
fbcbb5d0 1180 &dev_attr_flash_block_size,
bad7001c
AV
1181 &dev_attr_vlan_id,
1182 &dev_attr_vn_port_mac_address,
7f774025 1183 &dev_attr_fabric_param,
afb046e2
AV
1184 NULL,
1185};
1186
8482e118 1187/* Host attributes. */
1188
1189static void
1190qla2x00_get_host_port_id(struct Scsi_Host *shost)
1191{
7b867cf7 1192 scsi_qla_host_t *vha = shost_priv(shost);
8482e118 1193
7b867cf7
AC
1194 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1195 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e118 1196}
1197
04414013 1198static void
1199qla2x00_get_host_speed(struct Scsi_Host *shost)
1200{
7b867cf7
AC
1201 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1202 (shost_priv(shost)))->hw;
2ae2b370 1203 u32 speed = FC_PORTSPEED_UNKNOWN;
04414013 1204
1205 switch (ha->link_data_rate) {
d8b45213 1206 case PORT_SPEED_1GB:
2ae2b370 1207 speed = FC_PORTSPEED_1GBIT;
04414013 1208 break;
d8b45213 1209 case PORT_SPEED_2GB:
2ae2b370 1210 speed = FC_PORTSPEED_2GBIT;
04414013 1211 break;
d8b45213 1212 case PORT_SPEED_4GB:
2ae2b370 1213 speed = FC_PORTSPEED_4GBIT;
04414013 1214 break;
da4541b6 1215 case PORT_SPEED_8GB:
2ae2b370 1216 speed = FC_PORTSPEED_8GBIT;
da4541b6 1217 break;
3a03eb79
AV
1218 case PORT_SPEED_10GB:
1219 speed = FC_PORTSPEED_10GBIT;
1220 break;
04414013 1221 }
1222 fc_host_speed(shost) = speed;
1223}
1224
8d067623 1225static void
1226qla2x00_get_host_port_type(struct Scsi_Host *shost)
1227{
7b867cf7 1228 scsi_qla_host_t *vha = shost_priv(shost);
8d067623 1229 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1230
7b867cf7 1231 if (vha->vp_idx) {
2f2fa13d
SS
1232 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1233 return;
1234 }
7b867cf7 1235 switch (vha->hw->current_topology) {
8d067623 1236 case ISP_CFG_NL:
1237 port_type = FC_PORTTYPE_LPORT;
1238 break;
1239 case ISP_CFG_FL:
1240 port_type = FC_PORTTYPE_NLPORT;
1241 break;
1242 case ISP_CFG_N:
1243 port_type = FC_PORTTYPE_PTP;
1244 break;
1245 case ISP_CFG_F:
1246 port_type = FC_PORTTYPE_NPORT;
1247 break;
1248 }
1249 fc_host_port_type(shost) = port_type;
1250}
1251
8482e118 1252static void
1253qla2x00_get_starget_node_name(struct scsi_target *starget)
1254{
1255 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 1256 scsi_qla_host_t *vha = shost_priv(host);
bdf79621 1257 fc_port_t *fcport;
f8b02a85 1258 u64 node_name = 0;
8482e118 1259
7b867cf7 1260 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
1261 if (fcport->rport &&
1262 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 1263 node_name = wwn_to_u64(fcport->node_name);
bdf79621 1264 break;
1265 }
1266 }
1267
f8b02a85 1268 fc_starget_node_name(starget) = node_name;
8482e118 1269}
1270
1271static void
1272qla2x00_get_starget_port_name(struct scsi_target *starget)
1273{
1274 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 1275 scsi_qla_host_t *vha = shost_priv(host);
bdf79621 1276 fc_port_t *fcport;
f8b02a85 1277 u64 port_name = 0;
8482e118 1278
7b867cf7 1279 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
1280 if (fcport->rport &&
1281 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 1282 port_name = wwn_to_u64(fcport->port_name);
bdf79621 1283 break;
1284 }
1285 }
1286
f8b02a85 1287 fc_starget_port_name(starget) = port_name;
8482e118 1288}
1289
1290static void
1291qla2x00_get_starget_port_id(struct scsi_target *starget)
1292{
1293 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 1294 scsi_qla_host_t *vha = shost_priv(host);
bdf79621 1295 fc_port_t *fcport;
1296 uint32_t port_id = ~0U;
1297
7b867cf7 1298 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
1299 if (fcport->rport &&
1300 starget->id == fcport->rport->scsi_target_id) {
bdf79621 1301 port_id = fcport->d_id.b.domain << 16 |
1302 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1303 break;
1304 }
1305 }
8482e118 1306
8482e118 1307 fc_starget_port_id(starget) = port_id;
1308}
1309
8482e118 1310static void
1311qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1312{
8482e118 1313 if (timeout)
85821c90 1314 rport->dev_loss_tmo = timeout;
8482e118 1315 else
85821c90 1316 rport->dev_loss_tmo = 1;
8482e118 1317}
1318
5f3a9a20
SJ
1319static void
1320qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1321{
1322 struct Scsi_Host *host = rport_to_shost(rport);
1323 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1324
3c01b4f9
SJ
1325 if (!fcport)
1326 return;
1327
b9b12f73
SJ
1328 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev)))
1329 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1330 else
1331 qla2x00_abort_fcport_cmds(fcport);
5f3a9a20
SJ
1332
1333 /*
1334 * Transport has effectively 'deleted' the rport, clear
1335 * all local references.
1336 */
1337 spin_lock_irq(host->host_lock);
1338 fcport->rport = NULL;
1339 *((fc_port_t **)rport->dd_data) = NULL;
1340 spin_unlock_irq(host->host_lock);
1341}
1342
1343static void
1344qla2x00_terminate_rport_io(struct fc_rport *rport)
1345{
1346 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1347
3c01b4f9
SJ
1348 if (!fcport)
1349 return;
1350
b9b12f73
SJ
1351 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1352 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1353 return;
1354 }
6390d1f3
AV
1355 /*
1356 * At this point all fcport's software-states are cleared. Perform any
1357 * final cleanup of firmware resources (PCBs and XCBs).
1358 */
be67e653 1359 if (fcport->loop_id != FC_NO_LOOP_ID)
7b867cf7
AC
1360 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1361 fcport->loop_id, fcport->d_id.b.domain,
1362 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6390d1f3 1363
5f3a9a20 1364 qla2x00_abort_fcport_cmds(fcport);
5f3a9a20
SJ
1365}
1366
91ca7b01
AV
1367static int
1368qla2x00_issue_lip(struct Scsi_Host *shost)
1369{
7b867cf7 1370 scsi_qla_host_t *vha = shost_priv(shost);
91ca7b01 1371
7b867cf7 1372 qla2x00_loop_reset(vha);
91ca7b01
AV
1373 return 0;
1374}
1375
392e2f65 1376static struct fc_host_statistics *
1377qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1378{
7b867cf7
AC
1379 scsi_qla_host_t *vha = shost_priv(shost);
1380 struct qla_hw_data *ha = vha->hw;
1381 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
392e2f65 1382 int rval;
43ef0580
AV
1383 struct link_statistics *stats;
1384 dma_addr_t stats_dma;
392e2f65 1385 struct fc_host_statistics *pfc_host_stat;
1386
1387 pfc_host_stat = &ha->fc_host_stat;
1388 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1389
43ef0580
AV
1390 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1391 if (stats == NULL) {
1392 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
7b867cf7 1393 __func__, base_vha->host_no));
43ef0580
AV
1394 goto done;
1395 }
1396 memset(stats, 0, DMA_POOL_SIZE);
1397
1398 rval = QLA_FUNCTION_FAILED;
e428924c 1399 if (IS_FWI2_CAPABLE(ha)) {
7b867cf7
AC
1400 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1401 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1402 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1403 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
178779a6
AV
1404 !ha->dpc_active) {
1405 /* Must be in a 'READY' state for statistics retrieval. */
7b867cf7
AC
1406 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1407 stats, stats_dma);
392e2f65 1408 }
178779a6
AV
1409
1410 if (rval != QLA_SUCCESS)
43ef0580
AV
1411 goto done_free;
1412
1413 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1414 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1415 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1416 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1417 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1418 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1419 if (IS_FWI2_CAPABLE(ha)) {
032d8dd7 1420 pfc_host_stat->lip_count = stats->lip_cnt;
43ef0580
AV
1421 pfc_host_stat->tx_frames = stats->tx_frames;
1422 pfc_host_stat->rx_frames = stats->rx_frames;
1423 pfc_host_stat->dumped_frames = stats->dumped_frames;
1424 pfc_host_stat->nos_count = stats->nos_rcvd;
1425 }
49fd462a
HZ
1426 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1427 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
392e2f65 1428
43ef0580
AV
1429done_free:
1430 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
178779a6 1431done:
392e2f65 1432 return pfc_host_stat;
1433}
1434
1620f7c2
AV
1435static void
1436qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1437{
7b867cf7 1438 scsi_qla_host_t *vha = shost_priv(shost);
1620f7c2 1439
7b867cf7 1440 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
1620f7c2
AV
1441}
1442
a740a3f0
AV
1443static void
1444qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1445{
7b867cf7 1446 scsi_qla_host_t *vha = shost_priv(shost);
a740a3f0 1447
7b867cf7 1448 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
a740a3f0
AV
1449}
1450
90991c85
AV
1451static void
1452qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1453{
7b867cf7 1454 scsi_qla_host_t *vha = shost_priv(shost);
90991c85
AV
1455 u64 node_name;
1456
7b867cf7
AC
1457 if (vha->device_flags & SWITCH_FOUND)
1458 node_name = wwn_to_u64(vha->fabric_node_name);
90991c85 1459 else
7b867cf7 1460 node_name = wwn_to_u64(vha->node_name);
90991c85
AV
1461
1462 fc_host_fabric_name(shost) = node_name;
1463}
1464
7047fcdd
AV
1465static void
1466qla2x00_get_host_port_state(struct Scsi_Host *shost)
1467{
7b867cf7
AC
1468 scsi_qla_host_t *vha = shost_priv(shost);
1469 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
7047fcdd 1470
7b867cf7 1471 if (!base_vha->flags.online)
7047fcdd 1472 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
7b867cf7 1473 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
7047fcdd
AV
1474 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1475 else
1476 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1477}
1478
2c3dfe3f
SJ
1479static int
1480qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1481{
1482 int ret = 0;
2afa19a9 1483 uint8_t qos = 0;
7b867cf7
AC
1484 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1485 scsi_qla_host_t *vha = NULL;
73208dfd 1486 struct qla_hw_data *ha = base_vha->hw;
2afa19a9
AC
1487 uint16_t options = 0;
1488 int cnt;
2c3dfe3f
SJ
1489
1490 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1491 if (ret) {
1492 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1493 "status %x\n", ret));
1494 return (ret);
1495 }
1496
1497 vha = qla24xx_create_vhost(fc_vport);
1498 if (vha == NULL) {
1499 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1500 vha));
1501 return FC_VPORT_FAILED;
1502 }
1503 if (disable) {
1504 atomic_set(&vha->vp_state, VP_OFFLINE);
1505 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1506 } else
1507 atomic_set(&vha->vp_state, VP_FAILED);
1508
1509 /* ready to create vport */
7b867cf7
AC
1510 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1511 vha->vp_idx);
2c3dfe3f
SJ
1512
1513 /* initialized vport states */
1514 atomic_set(&vha->loop_state, LOOP_DOWN);
1515 vha->vp_err_state= VP_ERR_PORTDWN;
1516 vha->vp_prev_err_state= VP_ERR_UNKWN;
1517 /* Check if physical ha port is Up */
7b867cf7
AC
1518 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1519 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
2c3dfe3f
SJ
1520 /* Don't retry or attempt login of this virtual port */
1521 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
7b867cf7 1522 base_vha->host_no));
2c3dfe3f
SJ
1523 atomic_set(&vha->loop_state, LOOP_DEAD);
1524 if (!disable)
1525 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1526 }
1527
1528 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1529 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1530 vha->host_no, vha->vp_idx));
1531 goto vport_create_failed_2;
1532 }
1533
1534 /* initialize attributes */
1535 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1536 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1537 fc_host_supported_classes(vha->host) =
7b867cf7 1538 fc_host_supported_classes(base_vha->host);
2c3dfe3f 1539 fc_host_supported_speeds(vha->host) =
7b867cf7 1540 fc_host_supported_speeds(base_vha->host);
2c3dfe3f
SJ
1541
1542 qla24xx_vport_disable(fc_vport, disable);
1543
2afa19a9 1544 ret = 0;
68ca949c 1545 if (ha->cur_vport_count <= ha->flex_port_count || ql2xmultique_tag
2afa19a9
AC
1546 || ha->max_req_queues == 1 || !ha->npiv_info)
1547 goto vport_queue;
1548 /* Create a request queue in QoS mode for the vport */
1549 for (cnt = ha->flex_port_count; cnt < ha->nvram_npiv_size; cnt++) {
1550 if (ha->npiv_info[cnt].port_name == vha->port_name &&
1551 ha->npiv_info[cnt].node_name == vha->node_name) {
1552 qos = ha->npiv_info[cnt].q_qos;
1553 break;
73208dfd 1554 }
2afa19a9
AC
1555 }
1556 if (qos) {
1557 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1558 qos);
1559 if (!ret)
1560 qla_printk(KERN_WARNING, ha,
1561 "Can't create request queue for vp_idx:%d\n",
1562 vha->vp_idx);
1563 else
1564 DEBUG2(qla_printk(KERN_INFO, ha,
1565 "Request Que:%d created for vp_idx:%d\n",
1566 ret, vha->vp_idx));
73208dfd
AC
1567 }
1568
2afa19a9
AC
1569vport_queue:
1570 vha->req = ha->req_q_map[ret];
2c3dfe3f 1571 return 0;
2afa19a9 1572
2c3dfe3f
SJ
1573vport_create_failed_2:
1574 qla24xx_disable_vp(vha);
1575 qla24xx_deallocate_vp_id(vha);
2c3dfe3f
SJ
1576 scsi_host_put(vha->host);
1577 return FC_VPORT_FAILED;
1578}
1579
a824ebb3 1580static int
2c3dfe3f
SJ
1581qla24xx_vport_delete(struct fc_vport *fc_vport)
1582{
2c3dfe3f 1583 scsi_qla_host_t *vha = fc_vport->dd_data;
7b867cf7 1584 fc_port_t *fcport, *tfcport;
73208dfd
AC
1585 struct qla_hw_data *ha = vha->hw;
1586 uint16_t id = vha->vp_idx;
c9c5ced9
AV
1587
1588 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
7b867cf7 1589 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
c9c5ced9 1590 msleep(1000);
2c3dfe3f
SJ
1591
1592 qla24xx_disable_vp(vha);
2c3dfe3f 1593
7b867cf7
AC
1594 fc_remove_host(vha->host);
1595
1596 scsi_remove_host(vha->host);
1597
1598 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1599 list_del(&fcport->list);
1600 kfree(fcport);
1601 fcport = NULL;
1602 }
1603
1604 qla24xx_deallocate_vp_id(vha);
2c3dfe3f
SJ
1605
1606 if (vha->timer_active) {
1607 qla2x00_vp_stop_timer(vha);
1608 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1609 "has stopped\n",
1610 vha->host_no, vha->vp_idx, vha));
1611 }
1612
68ca949c 1613 if (vha->req->id && !ql2xmultique_tag) {
2afa19a9 1614 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
cf5a1631
AC
1615 qla_printk(KERN_WARNING, ha,
1616 "Queue delete failed.\n");
1617 }
1618
2c3dfe3f 1619 scsi_host_put(vha->host);
73208dfd 1620 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
2c3dfe3f
SJ
1621 return 0;
1622}
1623
a824ebb3 1624static int
2c3dfe3f
SJ
1625qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1626{
1627 scsi_qla_host_t *vha = fc_vport->dd_data;
1628
1629 if (disable)
1630 qla24xx_disable_vp(vha);
1631 else
1632 qla24xx_enable_vp(vha);
1633
1634 return 0;
1635}
1636
1c97a12a 1637struct fc_function_template qla2xxx_transport_functions = {
8482e118 1638
1639 .show_host_node_name = 1,
1640 .show_host_port_name = 1,
ad3e0eda 1641 .show_host_supported_classes = 1,
2ae2b370 1642 .show_host_supported_speeds = 1,
ad3e0eda 1643
8482e118 1644 .get_host_port_id = qla2x00_get_host_port_id,
1645 .show_host_port_id = 1,
04414013 1646 .get_host_speed = qla2x00_get_host_speed,
1647 .show_host_speed = 1,
8d067623 1648 .get_host_port_type = qla2x00_get_host_port_type,
1649 .show_host_port_type = 1,
1620f7c2
AV
1650 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1651 .show_host_symbolic_name = 1,
a740a3f0
AV
1652 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1653 .show_host_system_hostname = 1,
90991c85
AV
1654 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1655 .show_host_fabric_name = 1,
7047fcdd
AV
1656 .get_host_port_state = qla2x00_get_host_port_state,
1657 .show_host_port_state = 1,
8482e118 1658
bdf79621 1659 .dd_fcrport_size = sizeof(struct fc_port *),
ad3e0eda 1660 .show_rport_supported_classes = 1,
8482e118 1661
1662 .get_starget_node_name = qla2x00_get_starget_node_name,
1663 .show_starget_node_name = 1,
1664 .get_starget_port_name = qla2x00_get_starget_port_name,
1665 .show_starget_port_name = 1,
1666 .get_starget_port_id = qla2x00_get_starget_port_id,
1667 .show_starget_port_id = 1,
1668
8482e118 1669 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1670 .show_rport_dev_loss_tmo = 1,
1671
91ca7b01 1672 .issue_fc_host_lip = qla2x00_issue_lip,
5f3a9a20
SJ
1673 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1674 .terminate_rport_io = qla2x00_terminate_rport_io,
392e2f65 1675 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2c3dfe3f
SJ
1676
1677 .vport_create = qla24xx_vport_create,
1678 .vport_disable = qla24xx_vport_disable,
1679 .vport_delete = qla24xx_vport_delete,
1680};
1681
1682struct fc_function_template qla2xxx_transport_vport_functions = {
1683
1684 .show_host_node_name = 1,
1685 .show_host_port_name = 1,
1686 .show_host_supported_classes = 1,
1687
1688 .get_host_port_id = qla2x00_get_host_port_id,
1689 .show_host_port_id = 1,
1690 .get_host_speed = qla2x00_get_host_speed,
1691 .show_host_speed = 1,
1692 .get_host_port_type = qla2x00_get_host_port_type,
1693 .show_host_port_type = 1,
1694 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1695 .show_host_symbolic_name = 1,
1696 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1697 .show_host_system_hostname = 1,
1698 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1699 .show_host_fabric_name = 1,
1700 .get_host_port_state = qla2x00_get_host_port_state,
1701 .show_host_port_state = 1,
1702
1703 .dd_fcrport_size = sizeof(struct fc_port *),
1704 .show_rport_supported_classes = 1,
1705
1706 .get_starget_node_name = qla2x00_get_starget_node_name,
1707 .show_starget_node_name = 1,
1708 .get_starget_port_name = qla2x00_get_starget_port_name,
1709 .show_starget_port_name = 1,
1710 .get_starget_port_id = qla2x00_get_starget_port_id,
1711 .show_starget_port_id = 1,
1712
2c3dfe3f
SJ
1713 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1714 .show_rport_dev_loss_tmo = 1,
1715
1716 .issue_fc_host_lip = qla2x00_issue_lip,
5f3a9a20
SJ
1717 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1718 .terminate_rport_io = qla2x00_terminate_rport_io,
2c3dfe3f 1719 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e118 1720};
1721
8482e118 1722void
7b867cf7 1723qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e118 1724{
7b867cf7 1725 struct qla_hw_data *ha = vha->hw;
2ae2b370
AV
1726 u32 speed = FC_PORTSPEED_UNKNOWN;
1727
7b867cf7
AC
1728 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1729 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1730 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1731 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1732 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
2ae2b370 1733
3a03eb79
AV
1734 if (IS_QLA81XX(ha))
1735 speed = FC_PORTSPEED_10GBIT;
1736 else if (IS_QLA25XX(ha))
2ae2b370
AV
1737 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1738 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
4d4df193 1739 else if (IS_QLA24XX_TYPE(ha))
2ae2b370
AV
1740 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1741 FC_PORTSPEED_1GBIT;
1742 else if (IS_QLA23XX(ha))
1743 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1744 else
1745 speed = FC_PORTSPEED_1GBIT;
7b867cf7 1746 fc_host_supported_speeds(vha->host) = speed;
8482e118 1747}
This page took 0.778135 seconds and 5 git commands to generate.