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