]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/scsi/qla2xxx/qla_attr.c
scsi: scsi_transport_fc: Declare wwn_to_u64() argument const
[mirror_ubuntu-jammy-kernel.git] / drivers / scsi / qla2xxx / qla_attr.c
CommitLineData
8482e118 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
bd21eaf9 3 * Copyright (c) 2003-2014 QLogic Corporation
8482e118 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
8482e118
AV
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
AV
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
81178772 29 if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
8482e118 30 return 0;
8482e118 31
a6b95d1c 32 mutex_lock(&ha->optrom_mutex);
7ec0effd 33 if (IS_P3P_TYPE(ha)) {
08de2844
GM
34 if (off < ha->md_template_size) {
35 rval = memory_read_from_buffer(buf, count,
36 &off, ha->md_tmplt_hdr, ha->md_template_size);
a6b95d1c
QT
37 } else {
38 off -= ha->md_template_size;
39 rval = memory_read_from_buffer(buf, count,
40 &off, ha->md_dump, ha->md_dump_size);
08de2844 41 }
a6b95d1c
QT
42 } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
43 rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
81178772 44 MCTP_DUMP_SIZE);
a6b95d1c
QT
45 } else if (ha->fw_dump_reading) {
46 rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
b3dc9088 47 ha->fw_dump_len);
a6b95d1c
QT
48 } else {
49 rval = 0;
50 }
51 mutex_unlock(&ha->optrom_mutex);
52 return rval;
8482e118
AV
53}
54
55static ssize_t
2c3c8bea 56qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
91a69029
ZR
57 struct bin_attribute *bin_attr,
58 char *buf, loff_t off, size_t count)
8482e118 59{
7b867cf7 60 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 61 struct device, kobj)));
7b867cf7 62 struct qla_hw_data *ha = vha->hw;
8482e118 63 int reading;
8482e118
AV
64
65 if (off != 0)
66 return (0);
67
68 reading = simple_strtol(buf, NULL, 10);
69 switch (reading) {
70 case 0:
a7a167bf
AV
71 if (!ha->fw_dump_reading)
72 break;
8482e118 73
7c3df132 74 ql_log(ql_log_info, vha, 0x705d,
7b867cf7 75 "Firmware dump cleared on (%ld).\n", vha->host_no);
a7a167bf 76
7ec0effd 77 if (IS_P3P_TYPE(ha)) {
08de2844
GM
78 qla82xx_md_free(vha);
79 qla82xx_md_prep(vha);
80 }
a7a167bf
AV
81 ha->fw_dump_reading = 0;
82 ha->fw_dumped = 0;
8482e118
AV
83 break;
84 case 1:
d4e3e04d 85 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e118
AV
86 ha->fw_dump_reading = 1;
87
7c3df132 88 ql_log(ql_log_info, vha, 0x705e,
a7a167bf 89 "Raw firmware dump ready for read on (%ld).\n",
7b867cf7 90 vha->host_no);
8482e118
AV
91 }
92 break;
a7a167bf 93 case 2:
7b867cf7 94 qla2x00_alloc_fw_dump(vha);
a7a167bf 95 break;
68af0811 96 case 3:
08de2844
GM
97 if (IS_QLA82XX(ha)) {
98 qla82xx_idc_lock(ha);
99 qla82xx_set_reset_owner(vha);
100 qla82xx_idc_unlock(ha);
7ec0effd
AD
101 } else if (IS_QLA8044(ha)) {
102 qla8044_idc_lock(ha);
103 qla82xx_set_reset_owner(vha);
104 qla8044_idc_unlock(ha);
08de2844
GM
105 } else
106 qla2x00_system_error(vha);
107 break;
108 case 4:
7ec0effd 109 if (IS_P3P_TYPE(ha)) {
08de2844
GM
110 if (ha->md_tmplt_hdr)
111 ql_dbg(ql_dbg_user, vha, 0x705b,
112 "MiniDump supported with this firmware.\n");
113 else
114 ql_dbg(ql_dbg_user, vha, 0x709d,
115 "MiniDump not supported with this firmware.\n");
116 }
117 break;
118 case 5:
7ec0effd 119 if (IS_P3P_TYPE(ha))
08de2844 120 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
68af0811 121 break;
81178772
SK
122 case 6:
123 if (!ha->mctp_dump_reading)
124 break;
125 ql_log(ql_log_info, vha, 0x70c1,
126 "MCTP dump cleared on (%ld).\n", vha->host_no);
127 ha->mctp_dump_reading = 0;
128 ha->mctp_dumped = 0;
129 break;
130 case 7:
131 if (ha->mctp_dumped && !ha->mctp_dump_reading) {
132 ha->mctp_dump_reading = 1;
133 ql_log(ql_log_info, vha, 0x70c2,
134 "Raw mctp dump ready for read on (%ld).\n",
135 vha->host_no);
136 }
137 break;
8482e118 138 }
71dfe9e7 139 return count;
8482e118
AV
140}
141
142static struct bin_attribute sysfs_fw_dump_attr = {
143 .attr = {
144 .name = "fw_dump",
145 .mode = S_IRUSR | S_IWUSR,
8482e118
AV
146 },
147 .size = 0,
148 .read = qla2x00_sysfs_read_fw_dump,
149 .write = qla2x00_sysfs_write_fw_dump,
150};
151
152static ssize_t
2c3c8bea 153qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
91a69029
ZR
154 struct bin_attribute *bin_attr,
155 char *buf, loff_t off, size_t count)
8482e118 156{
7b867cf7 157 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 158 struct device, kobj)));
7b867cf7 159 struct qla_hw_data *ha = vha->hw;
5fa8774c
JC
160 uint32_t faddr;
161 struct active_regions active_regions = { };
8482e118 162
b3dc9088 163 if (!capable(CAP_SYS_ADMIN))
8482e118
AV
164 return 0;
165
b6faaaf7
QT
166 mutex_lock(&ha->optrom_mutex);
167 if (qla2x00_chip_is_down(vha)) {
168 mutex_unlock(&ha->optrom_mutex);
169 return -EAGAIN;
170 }
171
5fa8774c
JC
172 if (!IS_NOCACHE_VPD_TYPE(ha)) {
173 mutex_unlock(&ha->optrom_mutex);
174 goto skip;
175 }
176
177 faddr = ha->flt_region_nvram;
178 if (IS_QLA28XX(ha)) {
179 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
180 faddr = ha->flt_region_nvram_sec;
181 }
182 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
183
b6faaaf7
QT
184 mutex_unlock(&ha->optrom_mutex);
185
5fa8774c 186skip:
b3dc9088
AM
187 return memory_read_from_buffer(buf, count, &off, ha->nvram,
188 ha->nvram_size);
8482e118
AV
189}
190
191static ssize_t
2c3c8bea 192qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
91a69029
ZR
193 struct bin_attribute *bin_attr,
194 char *buf, loff_t off, size_t count)
8482e118 195{
7b867cf7 196 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 197 struct device, kobj)));
7b867cf7 198 struct qla_hw_data *ha = vha->hw;
8482e118 199 uint16_t cnt;
8482e118 200
3d79038f
AV
201 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
202 !ha->isp_ops->write_nvram)
b668ae37 203 return -EINVAL;
8482e118
AV
204
205 /* Checksum NVRAM. */
e428924c 206 if (IS_FWI2_CAPABLE(ha)) {
459c5378
AV
207 uint32_t *iter;
208 uint32_t chksum;
209
210 iter = (uint32_t *)buf;
211 chksum = 0;
da08ef5c
JC
212 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
213 chksum += le32_to_cpu(*iter);
459c5378
AV
214 chksum = ~chksum + 1;
215 *iter = cpu_to_le32(chksum);
216 } else {
217 uint8_t *iter;
218 uint8_t chksum;
219
220 iter = (uint8_t *)buf;
221 chksum = 0;
222 for (cnt = 0; cnt < count - 1; cnt++)
223 chksum += *iter++;
224 chksum = ~chksum + 1;
225 *iter = chksum;
226 }
8482e118 227
2533cf67 228 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
7c3df132 229 ql_log(ql_log_warn, vha, 0x705f,
2533cf67
LC
230 "HBA not online, failing NVRAM update.\n");
231 return -EAGAIN;
232 }
233
b6faaaf7
QT
234 mutex_lock(&ha->optrom_mutex);
235 if (qla2x00_chip_is_down(vha)) {
109a5987 236 mutex_unlock(&ha->optrom_mutex);
b6faaaf7
QT
237 return -EAGAIN;
238 }
239
8482e118 240 /* Write NVRAM. */
3695310e
JC
241 ha->isp_ops->write_nvram(vha, buf, ha->nvram_base, count);
242 ha->isp_ops->read_nvram(vha, ha->nvram, ha->nvram_base,
243 count);
b6faaaf7 244 mutex_unlock(&ha->optrom_mutex);
8482e118 245
7c3df132
SK
246 ql_dbg(ql_dbg_user, vha, 0x7060,
247 "Setting ISP_ABORT_NEEDED\n");
2533cf67 248 /* NVRAM settings take effect immediately. */
7b867cf7 249 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2533cf67
LC
250 qla2xxx_wake_dpc(vha);
251 qla2x00_wait_for_chip_reset(vha);
26b8d348 252
b668ae37 253 return count;
8482e118
AV
254}
255
256static struct bin_attribute sysfs_nvram_attr = {
257 .attr = {
258 .name = "nvram",
259 .mode = S_IRUSR | S_IWUSR,
8482e118 260 },
1b3f6365 261 .size = 512,
8482e118
AV
262 .read = qla2x00_sysfs_read_nvram,
263 .write = qla2x00_sysfs_write_nvram,
264};
265
854165f4 266static ssize_t
2c3c8bea 267qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
91a69029
ZR
268 struct bin_attribute *bin_attr,
269 char *buf, loff_t off, size_t count)
854165f4 270{
7b867cf7 271 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 272 struct device, kobj)));
7b867cf7 273 struct qla_hw_data *ha = vha->hw;
7a8ab9c8 274 ssize_t rval = 0;
854165f4 275
c7702b8c
MG
276 mutex_lock(&ha->optrom_mutex);
277
854165f4 278 if (ha->optrom_state != QLA_SREADING)
c7702b8c 279 goto out;
854165f4 280
7a8ab9c8
CD
281 rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
282 ha->optrom_region_size);
c7702b8c
MG
283
284out:
7a8ab9c8
CD
285 mutex_unlock(&ha->optrom_mutex);
286
287 return rval;
854165f4
AV
288}
289
290static ssize_t
2c3c8bea 291qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
91a69029
ZR
292 struct bin_attribute *bin_attr,
293 char *buf, loff_t off, size_t count)
854165f4 294{
7b867cf7 295 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 296 struct device, kobj)));
7b867cf7 297 struct qla_hw_data *ha = vha->hw;
854165f4 298
c7702b8c
MG
299 mutex_lock(&ha->optrom_mutex);
300
301 if (ha->optrom_state != QLA_SWRITING) {
302 mutex_unlock(&ha->optrom_mutex);
854165f4 303 return -EINVAL;
c7702b8c
MG
304 }
305 if (off > ha->optrom_region_size) {
306 mutex_unlock(&ha->optrom_mutex);
854165f4 307 return -ERANGE;
c7702b8c 308 }
b7cc176c
JC
309 if (off + count > ha->optrom_region_size)
310 count = ha->optrom_region_size - off;
854165f4
AV
311
312 memcpy(&ha->optrom_buffer[off], buf, count);
7a8ab9c8 313 mutex_unlock(&ha->optrom_mutex);
854165f4
AV
314
315 return count;
316}
317
318static struct bin_attribute sysfs_optrom_attr = {
319 .attr = {
320 .name = "optrom",
321 .mode = S_IRUSR | S_IWUSR,
854165f4 322 },
c3a2f0df 323 .size = 0,
854165f4
AV
324 .read = qla2x00_sysfs_read_optrom,
325 .write = qla2x00_sysfs_write_optrom,
326};
327
328static ssize_t
2c3c8bea 329qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
91a69029
ZR
330 struct bin_attribute *bin_attr,
331 char *buf, loff_t off, size_t count)
854165f4 332{
7b867cf7 333 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 334 struct device, kobj)));
7b867cf7 335 struct qla_hw_data *ha = vha->hw;
b7cc176c
JC
336 uint32_t start = 0;
337 uint32_t size = ha->optrom_size;
338 int val, valid;
7a8ab9c8 339 ssize_t rval = count;
854165f4
AV
340
341 if (off)
b668ae37 342 return -EINVAL;
854165f4 343
85880801 344 if (unlikely(pci_channel_offline(ha->pdev)))
b668ae37 345 return -EAGAIN;
85880801 346
b7cc176c
JC
347 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
348 return -EINVAL;
349 if (start > ha->optrom_size)
854165f4 350 return -EINVAL;
e6f77540
DC
351 if (size > ha->optrom_size - start)
352 size = ha->optrom_size - start;
854165f4 353
7a8ab9c8 354 mutex_lock(&ha->optrom_mutex);
b6faaaf7
QT
355 if (qla2x00_chip_is_down(vha)) {
356 mutex_unlock(&ha->optrom_mutex);
357 return -EAGAIN;
358 }
854165f4
AV
359 switch (val) {
360 case 0:
361 if (ha->optrom_state != QLA_SREADING &&
7a8ab9c8
CD
362 ha->optrom_state != QLA_SWRITING) {
363 rval = -EINVAL;
364 goto out;
365 }
854165f4 366 ha->optrom_state = QLA_SWAITING;
b7cc176c 367
7c3df132 368 ql_dbg(ql_dbg_user, vha, 0x7061,
b7cc176c 369 "Freeing flash region allocation -- 0x%x bytes.\n",
7c3df132 370 ha->optrom_region_size);
b7cc176c 371
854165f4
AV
372 vfree(ha->optrom_buffer);
373 ha->optrom_buffer = NULL;
374 break;
375 case 1:
7a8ab9c8
CD
376 if (ha->optrom_state != QLA_SWAITING) {
377 rval = -EINVAL;
378 goto out;
379 }
854165f4 380
b7cc176c 381 ha->optrom_region_start = start;
5cbdae10 382 ha->optrom_region_size = size;
b7cc176c 383
854165f4 384 ha->optrom_state = QLA_SREADING;
b7cc176c 385 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4 386 if (ha->optrom_buffer == NULL) {
7c3df132 387 ql_log(ql_log_warn, vha, 0x7062,
854165f4 388 "Unable to allocate memory for optrom retrieval "
b7cc176c 389 "(%x).\n", ha->optrom_region_size);
854165f4
AV
390
391 ha->optrom_state = QLA_SWAITING;
7a8ab9c8
CD
392 rval = -ENOMEM;
393 goto out;
854165f4
AV
394 }
395
86fbee86 396 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
7c3df132
SK
397 ql_log(ql_log_warn, vha, 0x7063,
398 "HBA not online, failing NVRAM update.\n");
7a8ab9c8
CD
399 rval = -EAGAIN;
400 goto out;
86fbee86
LC
401 }
402
7c3df132 403 ql_dbg(ql_dbg_user, vha, 0x7064,
b7cc176c 404 "Reading flash region -- 0x%x/0x%x.\n",
7c3df132 405 ha->optrom_region_start, ha->optrom_region_size);
b7cc176c
JC
406
407 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
7b867cf7 408 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
b7cc176c 409 ha->optrom_region_start, ha->optrom_region_size);
854165f4
AV
410 break;
411 case 2:
7a8ab9c8
CD
412 if (ha->optrom_state != QLA_SWAITING) {
413 rval = -EINVAL;
414 goto out;
415 }
854165f4 416
b7cc176c
JC
417 /*
418 * We need to be more restrictive on which FLASH regions are
419 * allowed to be updated via user-space. Regions accessible
420 * via this method include:
421 *
422 * ISP21xx/ISP22xx/ISP23xx type boards:
423 *
424 * 0x000000 -> 0x020000 -- Boot code.
425 *
426 * ISP2322/ISP24xx type boards:
427 *
428 * 0x000000 -> 0x07ffff -- Boot code.
429 * 0x080000 -> 0x0fffff -- Firmware.
430 *
431 * ISP25xx type boards:
432 *
433 * 0x000000 -> 0x07ffff -- Boot code.
434 * 0x080000 -> 0x0fffff -- Firmware.
435 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
e81d1bcb
AV
436 *
437 * > ISP25xx type boards:
438 *
439 * None -- should go through BSG.
b7cc176c
JC
440 */
441 valid = 0;
442 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
443 valid = 1;
c00d8994
AV
444 else if (start == (ha->flt_region_boot * 4) ||
445 start == (ha->flt_region_fw * 4))
b7cc176c 446 valid = 1;
e81d1bcb 447 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
a9083016 448 valid = 1;
b7cc176c 449 if (!valid) {
7c3df132 450 ql_log(ql_log_warn, vha, 0x7065,
b7cc176c 451 "Invalid start region 0x%x/0x%x.\n", start, size);
7a8ab9c8
CD
452 rval = -EINVAL;
453 goto out;
b7cc176c
JC
454 }
455
456 ha->optrom_region_start = start;
5cbdae10 457 ha->optrom_region_size = size;
b7cc176c 458
854165f4 459 ha->optrom_state = QLA_SWRITING;
b7cc176c 460 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4 461 if (ha->optrom_buffer == NULL) {
7c3df132 462 ql_log(ql_log_warn, vha, 0x7066,
854165f4 463 "Unable to allocate memory for optrom update "
7c3df132 464 "(%x)\n", ha->optrom_region_size);
854165f4
AV
465
466 ha->optrom_state = QLA_SWAITING;
7a8ab9c8
CD
467 rval = -ENOMEM;
468 goto out;
854165f4 469 }
b7cc176c 470
7c3df132 471 ql_dbg(ql_dbg_user, vha, 0x7067,
b7cc176c 472 "Staging flash region write -- 0x%x/0x%x.\n",
7c3df132 473 ha->optrom_region_start, ha->optrom_region_size);
b7cc176c
JC
474
475 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
854165f4
AV
476 break;
477 case 3:
7a8ab9c8
CD
478 if (ha->optrom_state != QLA_SWRITING) {
479 rval = -EINVAL;
480 goto out;
481 }
854165f4 482
2533cf67 483 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
7c3df132 484 ql_log(ql_log_warn, vha, 0x7068,
2533cf67 485 "HBA not online, failing flash update.\n");
7a8ab9c8
CD
486 rval = -EAGAIN;
487 goto out;
2533cf67
LC
488 }
489
7c3df132 490 ql_dbg(ql_dbg_user, vha, 0x7069,
b7cc176c 491 "Writing flash region -- 0x%x/0x%x.\n",
7c3df132 492 ha->optrom_region_start, ha->optrom_region_size);
b7cc176c 493
7b867cf7 494 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
b7cc176c 495 ha->optrom_region_start, ha->optrom_region_size);
854165f4 496 break;
b7cc176c 497 default:
7a8ab9c8 498 rval = -EINVAL;
854165f4 499 }
7a8ab9c8
CD
500
501out:
502 mutex_unlock(&ha->optrom_mutex);
503 return rval;
854165f4
AV
504}
505
506static struct bin_attribute sysfs_optrom_ctl_attr = {
507 .attr = {
508 .name = "optrom_ctl",
509 .mode = S_IWUSR,
854165f4
AV
510 },
511 .size = 0,
512 .write = qla2x00_sysfs_write_optrom_ctl,
513};
514
6f641790 515static ssize_t
2c3c8bea 516qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
91a69029
ZR
517 struct bin_attribute *bin_attr,
518 char *buf, loff_t off, size_t count)
6f641790 519{
7b867cf7 520 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 521 struct device, kobj)));
7b867cf7 522 struct qla_hw_data *ha = vha->hw;
4243c115 523 uint32_t faddr;
5fa8774c 524 struct active_regions active_regions = { };
6f641790 525
85880801 526 if (unlikely(pci_channel_offline(ha->pdev)))
b668ae37 527 return -EAGAIN;
85880801 528
b3dc9088 529 if (!capable(CAP_SYS_ADMIN))
b668ae37 530 return -EINVAL;
6f641790 531
3695310e
JC
532 if (IS_NOCACHE_VPD_TYPE(ha))
533 goto skip;
4243c115 534
3695310e 535 faddr = ha->flt_region_vpd << 2;
4243c115 536
5fa8774c
JC
537 if (IS_QLA28XX(ha)) {
538 qla28xx_get_aux_images(vha, &active_regions);
539 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
540 faddr = ha->flt_region_vpd_sec << 2;
541
542 ql_dbg(ql_dbg_init, vha, 0x7070,
543 "Loading %s nvram image.\n",
544 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
545 "primary" : "secondary");
546 }
3695310e
JC
547
548 mutex_lock(&ha->optrom_mutex);
549 if (qla2x00_chip_is_down(vha)) {
b6faaaf7 550 mutex_unlock(&ha->optrom_mutex);
3695310e 551 return -EAGAIN;
4243c115 552 }
3695310e
JC
553
554 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
555 mutex_unlock(&ha->optrom_mutex);
5fa8774c
JC
556
557 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
3695310e 558skip:
b3dc9088 559 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
6f641790
AV
560}
561
562static ssize_t
2c3c8bea 563qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
91a69029
ZR
564 struct bin_attribute *bin_attr,
565 char *buf, loff_t off, size_t count)
6f641790 566{
7b867cf7 567 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 568 struct device, kobj)));
7b867cf7 569 struct qla_hw_data *ha = vha->hw;
d0c3eefa 570 uint8_t *tmp_data;
6f641790 571
85880801
AV
572 if (unlikely(pci_channel_offline(ha->pdev)))
573 return 0;
574
b726d99d
QT
575 if (qla2x00_chip_is_down(vha))
576 return 0;
577
3d79038f
AV
578 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
579 !ha->isp_ops->write_nvram)
6f641790
AV
580 return 0;
581
2533cf67 582 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
7c3df132 583 ql_log(ql_log_warn, vha, 0x706a,
2533cf67
LC
584 "HBA not online, failing VPD update.\n");
585 return -EAGAIN;
586 }
587
b6faaaf7
QT
588 mutex_lock(&ha->optrom_mutex);
589 if (qla2x00_chip_is_down(vha)) {
590 mutex_unlock(&ha->optrom_mutex);
591 return -EAGAIN;
592 }
593
6f641790 594 /* Write NVRAM. */
3695310e
JC
595 ha->isp_ops->write_nvram(vha, buf, ha->vpd_base, count);
596 ha->isp_ops->read_nvram(vha, ha->vpd, ha->vpd_base, count);
6f641790 597
d0c3eefa 598 /* Update flash version information for 4Gb & above. */
b6faaaf7
QT
599 if (!IS_FWI2_CAPABLE(ha)) {
600 mutex_unlock(&ha->optrom_mutex);
b668ae37 601 return -EINVAL;
b6faaaf7 602 }
d0c3eefa
LC
603
604 tmp_data = vmalloc(256);
605 if (!tmp_data) {
b6faaaf7 606 mutex_unlock(&ha->optrom_mutex);
7c3df132 607 ql_log(ql_log_warn, vha, 0x706b,
d0c3eefa 608 "Unable to allocate memory for VPD information update.\n");
b668ae37 609 return -ENOMEM;
d0c3eefa
LC
610 }
611 ha->isp_ops->get_flash_version(vha, tmp_data);
612 vfree(tmp_data);
b668ae37 613
b6faaaf7
QT
614 mutex_unlock(&ha->optrom_mutex);
615
6f641790
AV
616 return count;
617}
618
619static struct bin_attribute sysfs_vpd_attr = {
620 .attr = {
621 .name = "vpd",
622 .mode = S_IRUSR | S_IWUSR,
6f641790
AV
623 },
624 .size = 0,
625 .read = qla2x00_sysfs_read_vpd,
626 .write = qla2x00_sysfs_write_vpd,
627};
628
88729e53 629static ssize_t
2c3c8bea 630qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
91a69029
ZR
631 struct bin_attribute *bin_attr,
632 char *buf, loff_t off, size_t count)
88729e53 633{
7b867cf7 634 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
88729e53 635 struct device, kobj)));
88729e53
AV
636 int rval;
637
e4e3a2ce 638 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
88729e53
AV
639 return 0;
640
b6faaaf7
QT
641 mutex_lock(&vha->hw->optrom_mutex);
642 if (qla2x00_chip_is_down(vha)) {
643 mutex_unlock(&vha->hw->optrom_mutex);
e8711085 644 return 0;
b6faaaf7 645 }
7c3df132 646
e4e3a2ce 647 rval = qla2x00_read_sfp_dev(vha, buf, count);
b6faaaf7
QT
648 mutex_unlock(&vha->hw->optrom_mutex);
649
e4e3a2ce
QT
650 if (rval)
651 return -EIO;
88729e53
AV
652
653 return count;
654}
655
656static struct bin_attribute sysfs_sfp_attr = {
657 .attr = {
658 .name = "sfp",
659 .mode = S_IRUSR | S_IWUSR,
88729e53 660 },
e4e3a2ce 661 .size = SFP_DEV_SIZE,
88729e53
AV
662 .read = qla2x00_sysfs_read_sfp,
663};
664
6e181be5 665static ssize_t
2c3c8bea 666qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
6e181be5
LC
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;
a9083016 673 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6e181be5 674 int type;
7d613ac6 675 uint32_t idc_control;
8c2cf7d4 676 uint8_t *tmp_data = NULL;
6e181be5 677 if (off != 0)
b668ae37 678 return -EINVAL;
6e181be5
LC
679
680 type = simple_strtol(buf, NULL, 10);
681 switch (type) {
682 case 0x2025c:
7c3df132
SK
683 ql_log(ql_log_info, vha, 0x706e,
684 "Issuing ISP reset.\n");
6e181be5
LC
685
686 scsi_block_requests(vha->host);
08de2844 687 if (IS_QLA82XX(ha)) {
b6d0d9d5 688 ha->flags.isp82xx_no_md_cap = 1;
08de2844
GM
689 qla82xx_idc_lock(ha);
690 qla82xx_set_reset_owner(vha);
691 qla82xx_idc_unlock(ha);
7ec0effd
AD
692 } else if (IS_QLA8044(ha)) {
693 qla8044_idc_lock(ha);
694 idc_control = qla8044_rd_reg(ha,
695 QLA8044_IDC_DRV_CTRL);
696 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
697 (idc_control | GRACEFUL_RESET_BIT1));
698 qla82xx_set_reset_owner(vha);
699 qla8044_idc_unlock(ha);
700 } else {
701 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
702 qla2xxx_wake_dpc(vha);
08de2844 703 }
6e181be5
LC
704 qla2x00_wait_for_chip_reset(vha);
705 scsi_unblock_requests(vha->host);
706 break;
707 case 0x2025d:
7d613ac6 708 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
b668ae37 709 return -EPERM;
6e181be5 710
7c3df132
SK
711 ql_log(ql_log_info, vha, 0x706f,
712 "Issuing MPI reset.\n");
6e181be5 713
ecc89f25 714 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
7d613ac6
SV
715 uint32_t idc_control;
716
717 qla83xx_idc_lock(vha, 0);
718 __qla83xx_get_idc_control(vha, &idc_control);
719 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
720 __qla83xx_set_idc_control(vha, idc_control);
721 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
722 QLA8XXX_DEV_NEED_RESET);
723 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
724 qla83xx_idc_unlock(vha, 0);
725 break;
726 } else {
727 /* Make sure FC side is not in reset */
728 qla2x00_wait_for_hba_online(vha);
729
730 /* Issue MPI reset */
731 scsi_block_requests(vha->host);
732 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
733 ql_log(ql_log_warn, vha, 0x7070,
734 "MPI reset failed.\n");
735 scsi_unblock_requests(vha->host);
736 break;
737 }
a9083016 738 case 0x2025e:
7ec0effd 739 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
7c3df132 740 ql_log(ql_log_info, vha, 0x7071,
5a68a1c2 741 "FCoE ctx reset not supported.\n");
b668ae37 742 return -EPERM;
a9083016
GM
743 }
744
7c3df132
SK
745 ql_log(ql_log_info, vha, 0x7072,
746 "Issuing FCoE ctx reset.\n");
a9083016
GM
747 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
748 qla2xxx_wake_dpc(vha);
749 qla2x00_wait_for_fcoe_ctx_reset(vha);
750 break;
7d613ac6
SV
751 case 0x2025f:
752 if (!IS_QLA8031(ha))
753 return -EPERM;
754 ql_log(ql_log_info, vha, 0x70bc,
755 "Disabling Reset by IDC control\n");
756 qla83xx_idc_lock(vha, 0);
757 __qla83xx_get_idc_control(vha, &idc_control);
758 idc_control |= QLA83XX_IDC_RESET_DISABLED;
759 __qla83xx_set_idc_control(vha, idc_control);
760 qla83xx_idc_unlock(vha, 0);
761 break;
762 case 0x20260:
763 if (!IS_QLA8031(ha))
764 return -EPERM;
765 ql_log(ql_log_info, vha, 0x70bd,
766 "Enabling Reset by IDC control\n");
767 qla83xx_idc_lock(vha, 0);
768 __qla83xx_get_idc_control(vha, &idc_control);
769 idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
770 __qla83xx_set_idc_control(vha, idc_control);
771 qla83xx_idc_unlock(vha, 0);
772 break;
8c2cf7d4
SC
773 case 0x20261:
774 ql_dbg(ql_dbg_user, vha, 0x70e0,
775 "Updating cache versions without reset ");
776
777 tmp_data = vmalloc(256);
778 if (!tmp_data) {
779 ql_log(ql_log_warn, vha, 0x70e1,
780 "Unable to allocate memory for VPD information update.\n");
781 return -ENOMEM;
782 }
783 ha->isp_ops->get_flash_version(vha, tmp_data);
784 vfree(tmp_data);
785 break;
6e181be5
LC
786 }
787 return count;
788}
789
790static struct bin_attribute sysfs_reset_attr = {
791 .attr = {
792 .name = "reset",
793 .mode = S_IWUSR,
794 },
795 .size = 0,
796 .write = qla2x00_sysfs_write_reset,
797};
798
6eb54715
HM
799static ssize_t
800qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
801 struct bin_attribute *bin_attr,
802 char *buf, loff_t off, size_t count)
803{
804 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
805 struct device, kobj)));
806 int type;
6eb54715
HM
807 port_id_t did;
808
22ebde16
QT
809 if (!capable(CAP_SYS_ADMIN))
810 return 0;
811
812 if (unlikely(pci_channel_offline(vha->hw->pdev)))
813 return 0;
814
815 if (qla2x00_chip_is_down(vha))
816 return 0;
817
6eb54715
HM
818 type = simple_strtol(buf, NULL, 10);
819
820 did.b.domain = (type & 0x00ff0000) >> 16;
821 did.b.area = (type & 0x0000ff00) >> 8;
822 did.b.al_pa = (type & 0x000000ff);
823
83548fe2 824 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
6eb54715
HM
825 did.b.domain, did.b.area, did.b.al_pa);
826
827 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
828
91f42b33 829 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
6eb54715
HM
830 return count;
831}
832
833static struct bin_attribute sysfs_issue_logo_attr = {
834 .attr = {
835 .name = "issue_logo",
836 .mode = S_IWUSR,
837 },
838 .size = 0,
839 .write = qla2x00_issue_logo,
840};
841
ce0423f4 842static ssize_t
2c3c8bea 843qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
ce0423f4
AV
844 struct bin_attribute *bin_attr,
845 char *buf, loff_t off, size_t count)
846{
847 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
848 struct device, kobj)));
849 struct qla_hw_data *ha = vha->hw;
850 int rval;
851 uint16_t actual_size;
852
853 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
854 return 0;
855
22ebde16
QT
856 if (unlikely(pci_channel_offline(ha->pdev)))
857 return 0;
b6faaaf7
QT
858 mutex_lock(&vha->hw->optrom_mutex);
859 if (qla2x00_chip_is_down(vha)) {
860 mutex_unlock(&vha->hw->optrom_mutex);
22ebde16 861 return 0;
b6faaaf7 862 }
22ebde16 863
ce0423f4
AV
864 if (ha->xgmac_data)
865 goto do_read;
866
867 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
868 &ha->xgmac_data_dma, GFP_KERNEL);
869 if (!ha->xgmac_data) {
b6faaaf7 870 mutex_unlock(&vha->hw->optrom_mutex);
7c3df132 871 ql_log(ql_log_warn, vha, 0x7076,
ce0423f4
AV
872 "Unable to allocate memory for XGMAC read-data.\n");
873 return 0;
874 }
875
876do_read:
877 actual_size = 0;
878 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
879
880 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
881 XGMAC_DATA_SIZE, &actual_size);
b6faaaf7
QT
882
883 mutex_unlock(&vha->hw->optrom_mutex);
ce0423f4 884 if (rval != QLA_SUCCESS) {
7c3df132 885 ql_log(ql_log_warn, vha, 0x7077,
ce0423f4
AV
886 "Unable to read XGMAC data (%x).\n", rval);
887 count = 0;
888 }
889
890 count = actual_size > count ? count: actual_size;
891 memcpy(buf, ha->xgmac_data, count);
892
893 return count;
894}
895
896static struct bin_attribute sysfs_xgmac_stats_attr = {
897 .attr = {
898 .name = "xgmac_stats",
899 .mode = S_IRUSR,
900 },
901 .size = 0,
902 .read = qla2x00_sysfs_read_xgmac_stats,
903};
904
11bbc1d8 905static ssize_t
2c3c8bea 906qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
11bbc1d8
AV
907 struct bin_attribute *bin_attr,
908 char *buf, loff_t off, size_t count)
909{
910 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
911 struct device, kobj)));
912 struct qla_hw_data *ha = vha->hw;
913 int rval;
11bbc1d8
AV
914
915 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
916 return 0;
917
918 if (ha->dcbx_tlv)
919 goto do_read;
b6faaaf7
QT
920 mutex_lock(&vha->hw->optrom_mutex);
921 if (qla2x00_chip_is_down(vha)) {
922 mutex_unlock(&vha->hw->optrom_mutex);
22ebde16 923 return 0;
b6faaaf7 924 }
22ebde16 925
11bbc1d8
AV
926 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
927 &ha->dcbx_tlv_dma, GFP_KERNEL);
928 if (!ha->dcbx_tlv) {
b6faaaf7 929 mutex_unlock(&vha->hw->optrom_mutex);
7c3df132 930 ql_log(ql_log_warn, vha, 0x7078,
11bbc1d8 931 "Unable to allocate memory for DCBX TLV read-data.\n");
b668ae37 932 return -ENOMEM;
11bbc1d8
AV
933 }
934
935do_read:
11bbc1d8
AV
936 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
937
938 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
939 DCBX_TLV_DATA_SIZE);
b6faaaf7
QT
940
941 mutex_unlock(&vha->hw->optrom_mutex);
942
11bbc1d8 943 if (rval != QLA_SUCCESS) {
7c3df132
SK
944 ql_log(ql_log_warn, vha, 0x7079,
945 "Unable to read DCBX TLV (%x).\n", rval);
b668ae37 946 return -EIO;
11bbc1d8
AV
947 }
948
949 memcpy(buf, ha->dcbx_tlv, count);
950
951 return count;
952}
953
954static struct bin_attribute sysfs_dcbx_tlv_attr = {
955 .attr = {
956 .name = "dcbx_tlv",
957 .mode = S_IRUSR,
958 },
959 .size = 0,
960 .read = qla2x00_sysfs_read_dcbx_tlv,
961};
962
f1663ad5
AV
963static struct sysfs_entry {
964 char *name;
965 struct bin_attribute *attr;
3695310e 966 int type;
f1663ad5
AV
967} bin_file_entries[] = {
968 { "fw_dump", &sysfs_fw_dump_attr, },
969 { "nvram", &sysfs_nvram_attr, },
970 { "optrom", &sysfs_optrom_attr, },
971 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
972 { "vpd", &sysfs_vpd_attr, 1 },
973 { "sfp", &sysfs_sfp_attr, 1 },
6e181be5 974 { "reset", &sysfs_reset_attr, },
6eb54715 975 { "issue_logo", &sysfs_issue_logo_attr, },
ce0423f4 976 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
11bbc1d8 977 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
46ddab7b 978 { NULL },
f1663ad5
AV
979};
980
8482e118 981void
7b867cf7 982qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e118 983{
7b867cf7 984 struct Scsi_Host *host = vha->host;
f1663ad5
AV
985 struct sysfs_entry *iter;
986 int ret;
8482e118 987
f1663ad5 988 for (iter = bin_file_entries; iter->name; iter++) {
3695310e 989 if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
f1663ad5 990 continue;
3695310e 991 if (iter->type == 2 && !IS_QLA25XX(vha->hw))
ad0ecd61 992 continue;
3695310e 993 if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
ce0423f4 994 continue;
f1663ad5
AV
995
996 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
997 iter->attr);
998 if (ret)
7c3df132
SK
999 ql_log(ql_log_warn, vha, 0x00f3,
1000 "Unable to create sysfs %s binary attribute (%d).\n",
1001 iter->name, ret);
1002 else
1003 ql_dbg(ql_dbg_init, vha, 0x00f4,
0bf0efa1 1004 "Successfully created sysfs %s binary attribute.\n",
7c3df132 1005 iter->name);
7914d004 1006 }
8482e118
AV
1007}
1008
1009void
fe1b806f 1010qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
8482e118 1011{
7b867cf7 1012 struct Scsi_Host *host = vha->host;
f1663ad5 1013 struct sysfs_entry *iter;
7b867cf7 1014 struct qla_hw_data *ha = vha->hw;
f1663ad5
AV
1015
1016 for (iter = bin_file_entries; iter->name; iter++) {
3695310e 1017 if (iter->type && !IS_FWI2_CAPABLE(ha))
f1663ad5 1018 continue;
3695310e 1019 if (iter->type == 2 && !IS_QLA25XX(ha))
ad0ecd61 1020 continue;
3695310e 1021 if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
ce0423f4 1022 continue;
3695310e
JC
1023 if (iter->type == 0x27 &&
1024 (!IS_QLA27XX(ha) || !IS_QLA28XX(ha)))
7473952e 1025 continue;
8482e118 1026
88729e53 1027 sysfs_remove_bin_file(&host->shost_gendev.kobj,
f1663ad5 1028 iter->attr);
7914d004 1029 }
f6df144c 1030
fe1b806f 1031 if (stop_beacon && ha->beacon_blink_led == 1)
7b867cf7 1032 ha->isp_ops->beacon_off(vha);
8482e118
AV
1033}
1034
afb046e2
AV
1035/* Scsi_Host attributes. */
1036
1037static ssize_t
50b81275 1038qla2x00_driver_version_show(struct device *dev,
ee959b00 1039 struct device_attribute *attr, char *buf)
afb046e2 1040{
15904d76 1041 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
afb046e2
AV
1042}
1043
1044static ssize_t
ee959b00
TJ
1045qla2x00_fw_version_show(struct device *dev,
1046 struct device_attribute *attr, char *buf)
afb046e2 1047{
7b867cf7
AC
1048 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1049 struct qla_hw_data *ha = vha->hw;
1050 char fw_str[128];
afb046e2 1051
15904d76 1052 return scnprintf(buf, PAGE_SIZE, "%s\n",
df57caba 1053 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
afb046e2
AV
1054}
1055
1056static ssize_t
ee959b00
TJ
1057qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1058 char *buf)
afb046e2 1059{
7b867cf7
AC
1060 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1061 struct qla_hw_data *ha = vha->hw;
afb046e2
AV
1062 uint32_t sn;
1063
8ae6d9c7 1064 if (IS_QLAFX00(vha->hw)) {
15904d76 1065 return scnprintf(buf, PAGE_SIZE, "%s\n",
8ae6d9c7
GM
1066 vha->hw->mr.serial_num);
1067 } else if (IS_FWI2_CAPABLE(ha)) {
ad5fa025
JC
1068 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1069 return strlen(strcat(buf, "\n"));
1ee27146 1070 }
8b7afc2a 1071
afb046e2 1072 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
15904d76 1073 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
afb046e2
AV
1074 sn % 100000);
1075}
1076
1077static ssize_t
ee959b00
TJ
1078qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1079 char *buf)
afb046e2 1080{
7b867cf7 1081 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
15904d76 1082 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
afb046e2
AV
1083}
1084
1085static ssize_t
ee959b00
TJ
1086qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1087 char *buf)
afb046e2 1088{
7b867cf7
AC
1089 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1090 struct qla_hw_data *ha = vha->hw;
8ae6d9c7
GM
1091
1092 if (IS_QLAFX00(vha->hw))
15904d76 1093 return scnprintf(buf, PAGE_SIZE, "%s\n",
8ae6d9c7
GM
1094 vha->hw->mr.hw_version);
1095
15904d76 1096 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
afb046e2
AV
1097 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1098 ha->product_id[3]);
1099}
1100
1101static ssize_t
ee959b00
TJ
1102qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1103 char *buf)
afb046e2 1104{
7b867cf7 1105 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
8ae6d9c7 1106
15904d76 1107 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
afb046e2
AV
1108}
1109
1110static ssize_t
ee959b00
TJ
1111qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1112 char *buf)
afb046e2 1113{
7b867cf7 1114 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
82e6afd4 1115 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
afb046e2
AV
1116}
1117
1118static ssize_t
ee959b00
TJ
1119qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1120 char *buf)
afb046e2 1121{
7b867cf7 1122 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
afb046e2
AV
1123 char pci_info[30];
1124
15904d76 1125 return scnprintf(buf, PAGE_SIZE, "%s\n",
7b867cf7 1126 vha->hw->isp_ops->pci_info_str(vha, pci_info));
afb046e2
AV
1127}
1128
1129static ssize_t
bbd1ae41
HR
1130qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1131 char *buf)
afb046e2 1132{
7b867cf7
AC
1133 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1134 struct qla_hw_data *ha = vha->hw;
afb046e2
AV
1135 int len = 0;
1136
7b867cf7 1137 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
62542f4b
AV
1138 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1139 vha->device_flags & DFLG_NO_CABLE)
15904d76 1140 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
7b867cf7 1141 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
22ebde16 1142 qla2x00_chip_is_down(vha))
15904d76 1143 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
afb046e2 1144 else {
15904d76 1145 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
afb046e2
AV
1146
1147 switch (ha->current_topology) {
1148 case ISP_CFG_NL:
15904d76 1149 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
afb046e2
AV
1150 break;
1151 case ISP_CFG_FL:
15904d76 1152 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
afb046e2
AV
1153 break;
1154 case ISP_CFG_N:
15904d76 1155 len += scnprintf(buf + len, PAGE_SIZE-len,
afb046e2
AV
1156 "N_Port to N_Port\n");
1157 break;
1158 case ISP_CFG_F:
15904d76 1159 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
afb046e2
AV
1160 break;
1161 default:
15904d76 1162 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
afb046e2
AV
1163 break;
1164 }
1165 }
1166 return len;
1167}
1168
4fdfefe5 1169static ssize_t
ee959b00
TJ
1170qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1171 char *buf)
4fdfefe5 1172{
7b867cf7 1173 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
1174 int len = 0;
1175
7b867cf7 1176 switch (vha->hw->zio_mode) {
4fdfefe5 1177 case QLA_ZIO_MODE_6:
15904d76 1178 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
4fdfefe5
AV
1179 break;
1180 case QLA_ZIO_DISABLED:
15904d76 1181 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
4fdfefe5
AV
1182 break;
1183 }
1184 return len;
1185}
1186
1187static ssize_t
ee959b00
TJ
1188qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1189 const char *buf, size_t count)
4fdfefe5 1190{
7b867cf7
AC
1191 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1192 struct qla_hw_data *ha = vha->hw;
4fdfefe5
AV
1193 int val = 0;
1194 uint16_t zio_mode;
1195
4a59f71d
AV
1196 if (!IS_ZIO_SUPPORTED(ha))
1197 return -ENOTSUPP;
1198
4fdfefe5
AV
1199 if (sscanf(buf, "%d", &val) != 1)
1200 return -EINVAL;
1201
4a59f71d 1202 if (val)
4fdfefe5 1203 zio_mode = QLA_ZIO_MODE_6;
4a59f71d 1204 else
4fdfefe5 1205 zio_mode = QLA_ZIO_DISABLED;
4fdfefe5
AV
1206
1207 /* Update per-hba values and queue a reset. */
1208 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1209 ha->zio_mode = zio_mode;
7b867cf7 1210 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4fdfefe5
AV
1211 }
1212 return strlen(buf);
1213}
1214
1215static ssize_t
ee959b00
TJ
1216qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1217 char *buf)
4fdfefe5 1218{
7b867cf7 1219 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5 1220
15904d76 1221 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
4fdfefe5
AV
1222}
1223
1224static ssize_t
ee959b00
TJ
1225qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1226 const char *buf, size_t count)
4fdfefe5 1227{
7b867cf7 1228 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
1229 int val = 0;
1230 uint16_t zio_timer;
1231
1232 if (sscanf(buf, "%d", &val) != 1)
1233 return -EINVAL;
1234 if (val > 25500 || val < 100)
1235 return -ERANGE;
1236
1237 zio_timer = (uint16_t)(val / 100);
7b867cf7 1238 vha->hw->zio_timer = zio_timer;
4fdfefe5
AV
1239
1240 return strlen(buf);
1241}
1242
8b4673ba
QT
1243static ssize_t
1244qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1245 char *buf)
1246{
1247 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1248
1249 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1250 vha->hw->last_zio_threshold);
1251}
1252
1253static ssize_t
1254qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1255 const char *buf, size_t count)
1256{
1257 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1258 int val = 0;
1259
1260 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1261 return -EINVAL;
1262 if (sscanf(buf, "%d", &val) != 1)
1263 return -EINVAL;
1703659d 1264 if (val < 0 || val > 256)
8b4673ba
QT
1265 return -ERANGE;
1266
1267 atomic_set(&vha->hw->zio_threshold, val);
1268 return strlen(buf);
1269}
1270
f6df144c 1271static ssize_t
ee959b00
TJ
1272qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1273 char *buf)
f6df144c 1274{
7b867cf7 1275 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
f6df144c
AV
1276 int len = 0;
1277
7b867cf7 1278 if (vha->hw->beacon_blink_led)
15904d76 1279 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
f6df144c 1280 else
15904d76 1281 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
f6df144c
AV
1282 return len;
1283}
1284
1285static ssize_t
ee959b00
TJ
1286qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1287 const char *buf, size_t count)
f6df144c 1288{
7b867cf7
AC
1289 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1290 struct qla_hw_data *ha = vha->hw;
f6df144c
AV
1291 int val = 0;
1292 int rval;
1293
1294 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1295 return -EPERM;
1296
b6faaaf7
QT
1297 if (sscanf(buf, "%d", &val) != 1)
1298 return -EINVAL;
1299
1300 mutex_lock(&vha->hw->optrom_mutex);
22ebde16 1301 if (qla2x00_chip_is_down(vha)) {
b6faaaf7 1302 mutex_unlock(&vha->hw->optrom_mutex);
7c3df132 1303 ql_log(ql_log_warn, vha, 0x707a,
f6df144c
AV
1304 "Abort ISP active -- ignoring beacon request.\n");
1305 return -EBUSY;
1306 }
1307
f6df144c 1308 if (val)
7b867cf7 1309 rval = ha->isp_ops->beacon_on(vha);
f6df144c 1310 else
7b867cf7 1311 rval = ha->isp_ops->beacon_off(vha);
f6df144c
AV
1312
1313 if (rval != QLA_SUCCESS)
1314 count = 0;
1315
b6faaaf7
QT
1316 mutex_unlock(&vha->hw->optrom_mutex);
1317
f6df144c
AV
1318 return count;
1319}
1320
30c47662 1321static ssize_t
ee959b00
TJ
1322qla2x00_optrom_bios_version_show(struct device *dev,
1323 struct device_attribute *attr, char *buf)
30c47662 1324{
7b867cf7
AC
1325 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1326 struct qla_hw_data *ha = vha->hw;
15904d76 1327 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
30c47662
AV
1328 ha->bios_revision[0]);
1329}
1330
1331static ssize_t
ee959b00
TJ
1332qla2x00_optrom_efi_version_show(struct device *dev,
1333 struct device_attribute *attr, char *buf)
30c47662 1334{
7b867cf7
AC
1335 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1336 struct qla_hw_data *ha = vha->hw;
15904d76 1337 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
30c47662
AV
1338 ha->efi_revision[0]);
1339}
1340
1341static ssize_t
ee959b00
TJ
1342qla2x00_optrom_fcode_version_show(struct device *dev,
1343 struct device_attribute *attr, char *buf)
30c47662 1344{
7b867cf7
AC
1345 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1346 struct qla_hw_data *ha = vha->hw;
15904d76 1347 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
30c47662
AV
1348 ha->fcode_revision[0]);
1349}
1350
1351static ssize_t
ee959b00
TJ
1352qla2x00_optrom_fw_version_show(struct device *dev,
1353 struct device_attribute *attr, char *buf)
30c47662 1354{
7b867cf7
AC
1355 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1356 struct qla_hw_data *ha = vha->hw;
15904d76 1357 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
30c47662
AV
1358 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1359 ha->fw_revision[3]);
1360}
1361
0f2d962f
MI
1362static ssize_t
1363qla2x00_optrom_gold_fw_version_show(struct device *dev,
1364 struct device_attribute *attr, char *buf)
1365{
1366 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1367 struct qla_hw_data *ha = vha->hw;
1368
ecc89f25
JC
1369 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1370 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
15904d76 1371 return scnprintf(buf, PAGE_SIZE, "\n");
0f2d962f 1372
15904d76 1373 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
0f2d962f
MI
1374 ha->gold_fw_version[0], ha->gold_fw_version[1],
1375 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1376}
1377
e5f5f6f7
HZ
1378static ssize_t
1379qla2x00_total_isp_aborts_show(struct device *dev,
1380 struct device_attribute *attr, char *buf)
1381{
7b867cf7 1382 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
15904d76 1383 return scnprintf(buf, PAGE_SIZE, "%d\n",
2be21fa2 1384 vha->qla_stats.total_isp_aborts);
e5f5f6f7
HZ
1385}
1386
9a069e19
GM
1387static ssize_t
1388qla24xx_84xx_fw_version_show(struct device *dev,
1389 struct device_attribute *attr, char *buf)
1390{
1391 int rval = QLA_SUCCESS;
3695310e 1392 uint16_t status[2] = { 0 };
9a069e19
GM
1393 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1394 struct qla_hw_data *ha = vha->hw;
1395
0b9dae6a 1396 if (!IS_QLA84XX(ha))
15904d76 1397 return scnprintf(buf, PAGE_SIZE, "\n");
0b9dae6a 1398
3695310e 1399 if (!ha->cs84xx->op_fw_version) {
0b9dae6a 1400 rval = qla84xx_verify_chip(vha, status);
9a069e19 1401
3695310e
JC
1402 if (!rval && !status[0])
1403 return scnprintf(buf, PAGE_SIZE, "%u\n",
1404 (uint32_t)ha->cs84xx->op_fw_version);
1405 }
9a069e19 1406
15904d76 1407 return scnprintf(buf, PAGE_SIZE, "\n");
9a069e19
GM
1408}
1409
2a3192a3
JC
1410static ssize_t
1411qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1412 char *buf)
1413{
1414 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1415 struct qla_hw_data *ha = vha->hw;
1416
1417 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1418 return scnprintf(buf, PAGE_SIZE, "\n");
1419
1420 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1421 ha->serdes_version[0], ha->serdes_version[1],
1422 ha->serdes_version[2]);
1423}
1424
3a03eb79
AV
1425static ssize_t
1426qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1427 char *buf)
1428{
1429 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1430 struct qla_hw_data *ha = vha->hw;
1431
03aa868c 1432 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
ecc89f25 1433 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
15904d76 1434 return scnprintf(buf, PAGE_SIZE, "\n");
3a03eb79 1435
15904d76 1436 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
3a03eb79 1437 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
55a96158
AV
1438 ha->mpi_capabilities);
1439}
1440
1441static ssize_t
1442qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1443 char *buf)
1444{
1445 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1446 struct qla_hw_data *ha = vha->hw;
1447
f863f603 1448 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
15904d76 1449 return scnprintf(buf, PAGE_SIZE, "\n");
55a96158 1450
15904d76 1451 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
55a96158 1452 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
3a03eb79
AV
1453}
1454
fbcbb5d0
LC
1455static ssize_t
1456qla2x00_flash_block_size_show(struct device *dev,
1457 struct device_attribute *attr, char *buf)
1458{
1459 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1460 struct qla_hw_data *ha = vha->hw;
1461
15904d76 1462 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
fbcbb5d0
LC
1463}
1464
bad7001c
AV
1465static ssize_t
1466qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1467 char *buf)
1468{
1469 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1470
6246b8a1 1471 if (!IS_CNA_CAPABLE(vha->hw))
15904d76 1472 return scnprintf(buf, PAGE_SIZE, "\n");
bad7001c 1473
15904d76 1474 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
bad7001c
AV
1475}
1476
1477static ssize_t
1478qla2x00_vn_port_mac_address_show(struct device *dev,
1479 struct device_attribute *attr, char *buf)
1480{
1481 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1482
6246b8a1 1483 if (!IS_CNA_CAPABLE(vha->hw))
15904d76 1484 return scnprintf(buf, PAGE_SIZE, "\n");
bad7001c 1485
15904d76 1486 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
bad7001c
AV
1487}
1488
7f774025
AV
1489static ssize_t
1490qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1491 char *buf)
1492{
1493 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1494
15904d76 1495 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
7f774025
AV
1496}
1497
794a5691
AV
1498static ssize_t
1499qla2x00_thermal_temp_show(struct device *dev,
1500 struct device_attribute *attr, char *buf)
1501{
1502 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
fe52f6e1 1503 uint16_t temp = 0;
b6faaaf7 1504 int rc;
794a5691 1505
b6faaaf7 1506 mutex_lock(&vha->hw->optrom_mutex);
22ebde16 1507 if (qla2x00_chip_is_down(vha)) {
b6faaaf7 1508 mutex_unlock(&vha->hw->optrom_mutex);
fe52f6e1
JC
1509 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1510 goto done;
1511 }
1512
1513 if (vha->hw->flags.eeh_busy) {
b6faaaf7 1514 mutex_unlock(&vha->hw->optrom_mutex);
fe52f6e1
JC
1515 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1516 goto done;
1517 }
1518
b6faaaf7
QT
1519 rc = qla2x00_get_thermal_temp(vha, &temp);
1520 mutex_unlock(&vha->hw->optrom_mutex);
1521 if (rc == QLA_SUCCESS)
15904d76 1522 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
794a5691 1523
fe52f6e1 1524done:
15904d76 1525 return scnprintf(buf, PAGE_SIZE, "\n");
794a5691
AV
1526}
1527
656e8912
AV
1528static ssize_t
1529qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1530 char *buf)
1531{
1532 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
85880801 1533 int rval = QLA_FUNCTION_FAILED;
b5a340dd 1534 uint16_t state[6];
8ae6d9c7
GM
1535 uint32_t pstate;
1536
1537 if (IS_QLAFX00(vha->hw)) {
1538 pstate = qlafx00_fw_state_show(dev, attr, buf);
15904d76 1539 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
8ae6d9c7 1540 }
656e8912 1541
b6faaaf7
QT
1542 mutex_lock(&vha->hw->optrom_mutex);
1543 if (qla2x00_chip_is_down(vha)) {
1544 mutex_unlock(&vha->hw->optrom_mutex);
7c3df132
SK
1545 ql_log(ql_log_warn, vha, 0x707c,
1546 "ISP reset active.\n");
b6faaaf7
QT
1547 goto out;
1548 } else if (vha->hw->flags.eeh_busy) {
1549 mutex_unlock(&vha->hw->optrom_mutex);
1550 goto out;
1551 }
1552
1553 rval = qla2x00_get_firmware_state(vha, state);
1554 mutex_unlock(&vha->hw->optrom_mutex);
1555out:
1556 if (rval != QLA_SUCCESS) {
656e8912 1557 memset(state, -1, sizeof(state));
b6faaaf7
QT
1558 rval = qla2x00_get_firmware_state(vha, state);
1559 }
656e8912 1560
b5a340dd
JC
1561 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1562 state[0], state[1], state[2], state[3], state[4], state[5]);
656e8912
AV
1563}
1564
a9b6f722
SK
1565static ssize_t
1566qla2x00_diag_requests_show(struct device *dev,
1567 struct device_attribute *attr, char *buf)
1568{
1569 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1570
1571 if (!IS_BIDI_CAPABLE(vha->hw))
15904d76 1572 return scnprintf(buf, PAGE_SIZE, "\n");
a9b6f722 1573
15904d76 1574 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
a9b6f722
SK
1575}
1576
1577static ssize_t
1578qla2x00_diag_megabytes_show(struct device *dev,
1579 struct device_attribute *attr, char *buf)
1580{
1581 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1582
1583 if (!IS_BIDI_CAPABLE(vha->hw))
15904d76 1584 return scnprintf(buf, PAGE_SIZE, "\n");
a9b6f722 1585
15904d76 1586 return scnprintf(buf, PAGE_SIZE, "%llu\n",
a9b6f722
SK
1587 vha->bidi_stats.transfer_bytes >> 20);
1588}
1589
40129a4c
HZ
1590static ssize_t
1591qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1592 char *buf)
1593{
1594 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1595 struct qla_hw_data *ha = vha->hw;
1596 uint32_t size;
1597
1598 if (!ha->fw_dumped)
1599 size = 0;
cf3af76b 1600 else if (IS_P3P_TYPE(ha))
40129a4c
HZ
1601 size = ha->md_template_size + ha->md_dump_size;
1602 else
1603 size = ha->fw_dump_len;
1604
15904d76 1605 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
40129a4c
HZ
1606}
1607
a1b23c5a
CD
1608static ssize_t
1609qla2x00_allow_cna_fw_dump_show(struct device *dev,
1610 struct device_attribute *attr, char *buf)
1611{
1612 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1613
1614 if (!IS_P3P_TYPE(vha->hw))
1615 return scnprintf(buf, PAGE_SIZE, "\n");
1616 else
1617 return scnprintf(buf, PAGE_SIZE, "%s\n",
1618 vha->hw->allow_cna_fw_dump ? "true" : "false");
1619}
1620
1621static ssize_t
1622qla2x00_allow_cna_fw_dump_store(struct device *dev,
1623 struct device_attribute *attr, const char *buf, size_t count)
1624{
1625 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1626 int val = 0;
1627
1628 if (!IS_P3P_TYPE(vha->hw))
1629 return -EINVAL;
1630
1631 if (sscanf(buf, "%d", &val) != 1)
1632 return -EINVAL;
1633
1634 vha->hw->allow_cna_fw_dump = val != 0;
1635
1636 return strlen(buf);
1637}
1638
03aa868c
SC
1639static ssize_t
1640qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1641 char *buf)
1642{
1643 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1644 struct qla_hw_data *ha = vha->hw;
1645
ecc89f25 1646 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
03aa868c
SC
1647 return scnprintf(buf, PAGE_SIZE, "\n");
1648
1649 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1650 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1651}
1652
92d4408e 1653static ssize_t
72a92df2
JC
1654qla2x00_min_supported_speed_show(struct device *dev,
1655 struct device_attribute *attr, char *buf)
92d4408e
SC
1656{
1657 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1658 struct qla_hw_data *ha = vha->hw;
1659
ecc89f25 1660 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
92d4408e
SC
1661 return scnprintf(buf, PAGE_SIZE, "\n");
1662
1663 return scnprintf(buf, PAGE_SIZE, "%s\n",
72a92df2
JC
1664 ha->min_supported_speed == 6 ? "64Gps" :
1665 ha->min_supported_speed == 5 ? "32Gps" :
1666 ha->min_supported_speed == 4 ? "16Gps" :
1667 ha->min_supported_speed == 3 ? "8Gps" :
1668 ha->min_supported_speed == 2 ? "4Gps" :
1669 ha->min_supported_speed != 0 ? "unknown" : "");
92d4408e
SC
1670}
1671
1672static ssize_t
72a92df2
JC
1673qla2x00_max_supported_speed_show(struct device *dev,
1674 struct device_attribute *attr, char *buf)
92d4408e
SC
1675{
1676 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1677 struct qla_hw_data *ha = vha->hw;
1678
ecc89f25 1679 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
92d4408e
SC
1680 return scnprintf(buf, PAGE_SIZE, "\n");
1681
1682 return scnprintf(buf, PAGE_SIZE, "%s\n",
72a92df2
JC
1683 ha->max_supported_speed == 2 ? "64Gps" :
1684 ha->max_supported_speed == 1 ? "32Gps" :
1685 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
92d4408e
SC
1686}
1687
4910b524
AG
1688static ssize_t
1689qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1690 const char *buf, size_t count)
1691{
1692 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1693 ulong type, speed;
1694 int oldspeed, rval;
1695 int mode = QLA_SET_DATA_RATE_LR;
1696 struct qla_hw_data *ha = vha->hw;
1697
ecc89f25 1698 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
4910b524
AG
1699 ql_log(ql_log_warn, vha, 0x70d8,
1700 "Speed setting not supported \n");
1701 return -EINVAL;
1702 }
1703
1704 rval = kstrtol(buf, 10, &type);
b8870ec6
DC
1705 if (rval)
1706 return rval;
4910b524
AG
1707 speed = type;
1708 if (type == 40 || type == 80 || type == 160 ||
1709 type == 320) {
1710 ql_dbg(ql_dbg_user, vha, 0x70d9,
1711 "Setting will be affected after a loss of sync\n");
1712 type = type/10;
1713 mode = QLA_SET_DATA_RATE_NOLR;
1714 }
1715
1716 oldspeed = ha->set_data_rate;
1717
1718 switch (type) {
1719 case 0:
1720 ha->set_data_rate = PORT_SPEED_AUTO;
1721 break;
1722 case 4:
1723 ha->set_data_rate = PORT_SPEED_4GB;
1724 break;
1725 case 8:
1726 ha->set_data_rate = PORT_SPEED_8GB;
1727 break;
1728 case 16:
1729 ha->set_data_rate = PORT_SPEED_16GB;
1730 break;
1731 case 32:
1732 ha->set_data_rate = PORT_SPEED_32GB;
1733 break;
1734 default:
1735 ql_log(ql_log_warn, vha, 0x1199,
1736 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1737 speed);
1738 ha->set_data_rate = PORT_SPEED_AUTO;
1739 }
1740
1741 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1742 return -EINVAL;
1743
1744 ql_log(ql_log_info, vha, 0x70da,
1745 "Setting speed to %lx Gbps \n", type);
1746
1747 rval = qla2x00_set_data_rate(vha, mode);
1748 if (rval != QLA_SUCCESS)
1749 return -EIO;
1750
1751 return strlen(buf);
1752}
1753
1754static ssize_t
1755qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1756 char *buf)
1757{
1758 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1759 struct qla_hw_data *ha = vha->hw;
1760 ssize_t rval;
1761 char *spd[7] = {"0", "0", "0", "4", "8", "16", "32"};
1762
1763 rval = qla2x00_get_data_rate(vha);
1764 if (rval != QLA_SUCCESS) {
1765 ql_log(ql_log_warn, vha, 0x70db,
1766 "Unable to get port speed rval:%zd\n", rval);
1767 return -EINVAL;
1768 }
1769
1770 ql_log(ql_log_info, vha, 0x70d6,
1771 "port speed:%d\n", ha->link_data_rate);
1772
1773 return scnprintf(buf, PAGE_SIZE, "%s\n", spd[ha->link_data_rate]);
1774}
1775
0645cb83
QT
1776/* ----- */
1777
1778static ssize_t
1779qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1780{
1781 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1782 int len = 0;
1783
1784 len += scnprintf(buf + len, PAGE_SIZE-len,
1785 "Supported options: enabled | disabled | dual | exclusive\n");
1786
1787 /* --- */
1788 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1789
1790 switch (vha->qlini_mode) {
1791 case QLA2XXX_INI_MODE_EXCLUSIVE:
1792 len += scnprintf(buf + len, PAGE_SIZE-len,
1793 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1794 break;
1795 case QLA2XXX_INI_MODE_DISABLED:
1796 len += scnprintf(buf + len, PAGE_SIZE-len,
1797 QLA2XXX_INI_MODE_STR_DISABLED);
1798 break;
1799 case QLA2XXX_INI_MODE_ENABLED:
1800 len += scnprintf(buf + len, PAGE_SIZE-len,
1801 QLA2XXX_INI_MODE_STR_ENABLED);
1802 break;
1803 case QLA2XXX_INI_MODE_DUAL:
1804 len += scnprintf(buf + len, PAGE_SIZE-len,
1805 QLA2XXX_INI_MODE_STR_DUAL);
1806 break;
1807 }
1808 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1809
1810 return len;
1811}
1812
1813static char *mode_to_str[] = {
1814 "exclusive",
1815 "disabled",
1816 "enabled",
1817 "dual",
1818};
1819
1820#define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1821static int qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1822{
1823 int rc = 0;
1824 enum {
1825 NO_ACTION,
1826 MODE_CHANGE_ACCEPT,
1827 MODE_CHANGE_NO_ACTION,
1828 TARGET_STILL_ACTIVE,
1829 };
1830 int action = NO_ACTION;
1831 int set_mode = 0;
1832 u8 eo_toggle = 0; /* exchange offload flipped */
1833
1834 switch (vha->qlini_mode) {
1835 case QLA2XXX_INI_MODE_DISABLED:
1836 switch (op) {
1837 case QLA2XXX_INI_MODE_DISABLED:
1838 if (qla_tgt_mode_enabled(vha)) {
1839 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1840 vha->hw->flags.exchoffld_enabled)
1841 eo_toggle = 1;
1842 if (((vha->ql2xexchoffld !=
1843 vha->u_ql2xexchoffld) &&
1844 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1845 eo_toggle) {
1846 /*
1847 * The number of exchange to be offload
1848 * was tweaked or offload option was
1849 * flipped
1850 */
1851 action = MODE_CHANGE_ACCEPT;
1852 } else {
1853 action = MODE_CHANGE_NO_ACTION;
1854 }
1855 } else {
1856 action = MODE_CHANGE_NO_ACTION;
1857 }
1858 break;
1859 case QLA2XXX_INI_MODE_EXCLUSIVE:
1860 if (qla_tgt_mode_enabled(vha)) {
1861 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1862 vha->hw->flags.exchoffld_enabled)
1863 eo_toggle = 1;
1864 if (((vha->ql2xexchoffld !=
1865 vha->u_ql2xexchoffld) &&
1866 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1867 eo_toggle) {
1868 /*
1869 * The number of exchange to be offload
1870 * was tweaked or offload option was
1871 * flipped
1872 */
1873 action = MODE_CHANGE_ACCEPT;
1874 } else {
1875 action = MODE_CHANGE_NO_ACTION;
1876 }
1877 } else {
1878 action = MODE_CHANGE_ACCEPT;
1879 }
1880 break;
1881 case QLA2XXX_INI_MODE_DUAL:
1882 action = MODE_CHANGE_ACCEPT;
1883 /* active_mode is target only, reset it to dual */
1884 if (qla_tgt_mode_enabled(vha)) {
1885 set_mode = 1;
1886 action = MODE_CHANGE_ACCEPT;
1887 } else {
1888 action = MODE_CHANGE_NO_ACTION;
1889 }
1890 break;
1891
1892 case QLA2XXX_INI_MODE_ENABLED:
1893 if (qla_tgt_mode_enabled(vha))
1894 action = TARGET_STILL_ACTIVE;
1895 else {
1896 action = MODE_CHANGE_ACCEPT;
1897 set_mode = 1;
1898 }
1899 break;
1900 }
1901 break;
1902
1903 case QLA2XXX_INI_MODE_EXCLUSIVE:
1904 switch (op) {
1905 case QLA2XXX_INI_MODE_EXCLUSIVE:
1906 if (qla_tgt_mode_enabled(vha)) {
1907 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1908 vha->hw->flags.exchoffld_enabled)
1909 eo_toggle = 1;
1910 if (((vha->ql2xexchoffld !=
1911 vha->u_ql2xexchoffld) &&
1912 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1913 eo_toggle)
1914 /*
1915 * The number of exchange to be offload
1916 * was tweaked or offload option was
1917 * flipped
1918 */
1919 action = MODE_CHANGE_ACCEPT;
1920 else
1921 action = NO_ACTION;
1922 } else
1923 action = NO_ACTION;
1924
1925 break;
1926
1927 case QLA2XXX_INI_MODE_DISABLED:
1928 if (qla_tgt_mode_enabled(vha)) {
1929 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1930 vha->hw->flags.exchoffld_enabled)
1931 eo_toggle = 1;
1932 if (((vha->ql2xexchoffld !=
1933 vha->u_ql2xexchoffld) &&
1934 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1935 eo_toggle)
1936 action = MODE_CHANGE_ACCEPT;
1937 else
1938 action = MODE_CHANGE_NO_ACTION;
1939 } else
1940 action = MODE_CHANGE_NO_ACTION;
1941 break;
1942
1943 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
1944 if (qla_tgt_mode_enabled(vha)) {
1945 action = MODE_CHANGE_ACCEPT;
1946 set_mode = 1;
1947 } else
1948 action = MODE_CHANGE_ACCEPT;
1949 break;
1950
1951 case QLA2XXX_INI_MODE_ENABLED:
1952 if (qla_tgt_mode_enabled(vha))
1953 action = TARGET_STILL_ACTIVE;
1954 else {
1955 if (vha->hw->flags.fw_started)
1956 action = MODE_CHANGE_NO_ACTION;
1957 else
1958 action = MODE_CHANGE_ACCEPT;
1959 }
1960 break;
1961 }
1962 break;
1963
1964 case QLA2XXX_INI_MODE_ENABLED:
1965 switch (op) {
1966 case QLA2XXX_INI_MODE_ENABLED:
1967 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
1968 vha->hw->flags.exchoffld_enabled)
1969 eo_toggle = 1;
1970 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
1971 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
1972 eo_toggle)
1973 action = MODE_CHANGE_ACCEPT;
1974 else
1975 action = NO_ACTION;
1976 break;
1977 case QLA2XXX_INI_MODE_DUAL:
1978 case QLA2XXX_INI_MODE_DISABLED:
1979 action = MODE_CHANGE_ACCEPT;
1980 break;
1981 default:
1982 action = MODE_CHANGE_NO_ACTION;
1983 break;
1984 }
1985 break;
1986
1987 case QLA2XXX_INI_MODE_DUAL:
1988 switch (op) {
1989 case QLA2XXX_INI_MODE_DUAL:
1990 if (qla_tgt_mode_enabled(vha) ||
1991 qla_dual_mode_enabled(vha)) {
1992 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
1993 vha->u_ql2xiniexchg) !=
1994 vha->hw->flags.exchoffld_enabled)
1995 eo_toggle = 1;
1996
1997 if ((((vha->ql2xexchoffld +
1998 vha->ql2xiniexchg) !=
1999 (vha->u_ql2xiniexchg +
2000 vha->u_ql2xexchoffld)) &&
2001 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2002 vha->u_ql2xexchoffld)) || eo_toggle)
2003 action = MODE_CHANGE_ACCEPT;
2004 else
2005 action = NO_ACTION;
2006 } else {
2007 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2008 vha->u_ql2xiniexchg) !=
2009 vha->hw->flags.exchoffld_enabled)
2010 eo_toggle = 1;
2011
2012 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2013 != (vha->u_ql2xiniexchg +
2014 vha->u_ql2xexchoffld)) &&
2015 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2016 vha->u_ql2xexchoffld)) || eo_toggle)
2017 action = MODE_CHANGE_NO_ACTION;
2018 else
2019 action = NO_ACTION;
2020 }
2021 break;
2022
2023 case QLA2XXX_INI_MODE_DISABLED:
2024 if (qla_tgt_mode_enabled(vha) ||
2025 qla_dual_mode_enabled(vha)) {
2026 /* turning off initiator mode */
2027 set_mode = 1;
2028 action = MODE_CHANGE_ACCEPT;
2029 } else {
2030 action = MODE_CHANGE_NO_ACTION;
2031 }
2032 break;
2033
2034 case QLA2XXX_INI_MODE_EXCLUSIVE:
2035 if (qla_tgt_mode_enabled(vha) ||
2036 qla_dual_mode_enabled(vha)) {
2037 set_mode = 1;
2038 action = MODE_CHANGE_ACCEPT;
2039 } else {
2040 action = MODE_CHANGE_ACCEPT;
2041 }
2042 break;
2043
2044 case QLA2XXX_INI_MODE_ENABLED:
2045 if (qla_tgt_mode_enabled(vha) ||
2046 qla_dual_mode_enabled(vha)) {
2047 action = TARGET_STILL_ACTIVE;
2048 } else {
2049 action = MODE_CHANGE_ACCEPT;
2050 }
2051 }
2052 break;
2053 }
2054
2055 switch (action) {
2056 case MODE_CHANGE_ACCEPT:
2057 ql_log(ql_log_warn, vha, 0xffff,
2058 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2059 mode_to_str[vha->qlini_mode], mode_to_str[op],
2060 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2061 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2062
2063 vha->qlini_mode = op;
2064 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2065 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2066 if (set_mode)
2067 qlt_set_mode(vha);
2068 vha->flags.online = 1;
2069 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2070 break;
2071
2072 case MODE_CHANGE_NO_ACTION:
2073 ql_log(ql_log_warn, vha, 0xffff,
2074 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2075 mode_to_str[vha->qlini_mode], mode_to_str[op],
2076 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2077 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2078 vha->qlini_mode = op;
2079 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2080 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2081 break;
2082
2083 case TARGET_STILL_ACTIVE:
2084 ql_log(ql_log_warn, vha, 0xffff,
2085 "Target Mode is active. Unable to change Mode.\n");
2086 break;
2087
2088 case NO_ACTION:
2089 default:
2090 ql_log(ql_log_warn, vha, 0xffff,
2091 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2092 vha->qlini_mode, op,
2093 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2094 break;
2095 }
2096
2097 return rc;
2098}
2099
2100static ssize_t
2101qlini_mode_store(struct device *dev, struct device_attribute *attr,
2102 const char *buf, size_t count)
2103{
2104 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2105 int ini;
2106
2107 if (!buf)
2108 return -EINVAL;
2109
2110 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2111 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2112 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2113 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2114 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2115 ini = QLA2XXX_INI_MODE_DISABLED;
2116 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2117 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2118 ini = QLA2XXX_INI_MODE_ENABLED;
2119 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2120 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2121 ini = QLA2XXX_INI_MODE_DUAL;
2122 else
2123 return -EINVAL;
2124
2125 qla_set_ini_mode(vha, ini);
2126 return strlen(buf);
2127}
2128
2129static ssize_t
2130ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2131 char *buf)
2132{
2133 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2134 int len = 0;
2135
2136 len += scnprintf(buf + len, PAGE_SIZE-len,
2137 "target exchange: new %d : current: %d\n\n",
2138 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2139
2140 len += scnprintf(buf + len, PAGE_SIZE-len,
2141 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2142 vha->host_no);
2143
2144 return len;
2145}
2146
2147static ssize_t
2148ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2149 const char *buf, size_t count)
2150{
2151 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2152 int val = 0;
2153
2154 if (sscanf(buf, "%d", &val) != 1)
2155 return -EINVAL;
2156
2157 if (val > FW_MAX_EXCHANGES_CNT)
2158 val = FW_MAX_EXCHANGES_CNT;
2159 else if (val < 0)
2160 val = 0;
2161
2162 vha->u_ql2xexchoffld = val;
2163 return strlen(buf);
2164}
2165
2166static ssize_t
2167ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2168 char *buf)
2169{
2170 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2171 int len = 0;
2172
2173 len += scnprintf(buf + len, PAGE_SIZE-len,
2174 "target exchange: new %d : current: %d\n\n",
2175 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2176
2177 len += scnprintf(buf + len, PAGE_SIZE-len,
2178 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2179 vha->host_no);
2180
2181 return len;
2182}
2183
2184static ssize_t
2185ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2186 const char *buf, size_t count)
2187{
2188 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2189 int val = 0;
2190
2191 if (sscanf(buf, "%d", &val) != 1)
2192 return -EINVAL;
2193
2194 if (val > FW_MAX_EXCHANGES_CNT)
2195 val = FW_MAX_EXCHANGES_CNT;
2196 else if (val < 0)
2197 val = 0;
2198
2199 vha->u_ql2xiniexchg = val;
2200 return strlen(buf);
2201}
2202
50b81275
GM
2203static ssize_t
2204qla2x00_dif_bundle_statistics_show(struct device *dev,
2205 struct device_attribute *attr, char *buf)
2206{
2207 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2208 struct qla_hw_data *ha = vha->hw;
2209
2210 return scnprintf(buf, PAGE_SIZE,
2211 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2212 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2213 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2214 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2215}
2216
df617ffb
JC
2217static ssize_t
2218qla2x00_fw_attr_show(struct device *dev,
2219 struct device_attribute *attr, char *buf)
2220{
2221 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2222 struct qla_hw_data *ha = vha->hw;
2223
ecc89f25 2224 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
df617ffb
JC
2225 return scnprintf(buf, PAGE_SIZE, "\n");
2226
2227 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2228 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2229 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2230 (uint64_t)ha->fw_attributes_h << 16 |
2231 (uint64_t)ha->fw_attributes);
2232}
2233
2234static ssize_t
2235qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2236 char *buf)
2237{
2238 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2239
2240 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2241}
2242
50b81275 2243static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
ee959b00
TJ
2244static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2245static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2246static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2247static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2248static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2249static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2250static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
bbd1ae41 2251static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
ee959b00
TJ
2252static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2253static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2254 qla2x00_zio_timer_store);
2255static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2256 qla2x00_beacon_store);
2257static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2258 qla2x00_optrom_bios_version_show, NULL);
2259static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2260 qla2x00_optrom_efi_version_show, NULL);
2261static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2262 qla2x00_optrom_fcode_version_show, NULL);
2263static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2264 NULL);
0f2d962f
MI
2265static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2266 qla2x00_optrom_gold_fw_version_show, NULL);
9a069e19
GM
2267static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2268 NULL);
e5f5f6f7
HZ
2269static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2270 NULL);
2a3192a3 2271static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
3a03eb79 2272static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
55a96158 2273static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
fbcbb5d0
LC
2274static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2275 NULL);
bad7001c
AV
2276static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2277static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2278 qla2x00_vn_port_mac_address_show, NULL);
7f774025 2279static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
656e8912 2280static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
794a5691 2281static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
a9b6f722
SK
2282static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2283static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
40129a4c 2284static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
a1b23c5a
CD
2285static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2286 qla2x00_allow_cna_fw_dump_show,
2287 qla2x00_allow_cna_fw_dump_store);
03aa868c 2288static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
72a92df2
JC
2289static DEVICE_ATTR(min_supported_speed, 0444,
2290 qla2x00_min_supported_speed_show, NULL);
2291static DEVICE_ATTR(max_supported_speed, 0444,
2292 qla2x00_max_supported_speed_show, NULL);
8b4673ba
QT
2293static DEVICE_ATTR(zio_threshold, 0644,
2294 qla_zio_threshold_show,
2295 qla_zio_threshold_store);
0645cb83
QT
2296static DEVICE_ATTR_RW(qlini_mode);
2297static DEVICE_ATTR_RW(ql2xexchoffld);
2298static DEVICE_ATTR_RW(ql2xiniexchg);
50b81275
GM
2299static DEVICE_ATTR(dif_bundle_statistics, 0444,
2300 qla2x00_dif_bundle_statistics_show, NULL);
4910b524
AG
2301static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2302 qla2x00_port_speed_store);
df617ffb
JC
2303static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2304static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
0645cb83 2305
ee959b00
TJ
2306
2307struct device_attribute *qla2x00_host_attrs[] = {
2308 &dev_attr_driver_version,
2309 &dev_attr_fw_version,
2310 &dev_attr_serial_num,
2311 &dev_attr_isp_name,
2312 &dev_attr_isp_id,
2313 &dev_attr_model_name,
2314 &dev_attr_model_desc,
2315 &dev_attr_pci_info,
bbd1ae41 2316 &dev_attr_link_state,
ee959b00
TJ
2317 &dev_attr_zio,
2318 &dev_attr_zio_timer,
2319 &dev_attr_beacon,
2320 &dev_attr_optrom_bios_version,
2321 &dev_attr_optrom_efi_version,
2322 &dev_attr_optrom_fcode_version,
2323 &dev_attr_optrom_fw_version,
9a069e19 2324 &dev_attr_84xx_fw_version,
e5f5f6f7 2325 &dev_attr_total_isp_aborts,
2a3192a3 2326 &dev_attr_serdes_version,
3a03eb79 2327 &dev_attr_mpi_version,
55a96158 2328 &dev_attr_phy_version,
fbcbb5d0 2329 &dev_attr_flash_block_size,
bad7001c
AV
2330 &dev_attr_vlan_id,
2331 &dev_attr_vn_port_mac_address,
7f774025 2332 &dev_attr_fabric_param,
656e8912 2333 &dev_attr_fw_state,
0f2d962f 2334 &dev_attr_optrom_gold_fw_version,
794a5691 2335 &dev_attr_thermal_temp,
a9b6f722
SK
2336 &dev_attr_diag_requests,
2337 &dev_attr_diag_megabytes,
40129a4c 2338 &dev_attr_fw_dump_size,
a1b23c5a 2339 &dev_attr_allow_cna_fw_dump,
03aa868c 2340 &dev_attr_pep_version,
72a92df2
JC
2341 &dev_attr_min_supported_speed,
2342 &dev_attr_max_supported_speed,
8b4673ba 2343 &dev_attr_zio_threshold,
50b81275 2344 &dev_attr_dif_bundle_statistics,
4910b524 2345 &dev_attr_port_speed,
df617ffb
JC
2346 &dev_attr_port_no,
2347 &dev_attr_fw_attr,
0645cb83
QT
2348 NULL, /* reserve for qlini_mode */
2349 NULL, /* reserve for ql2xiniexchg */
2350 NULL, /* reserve for ql2xexchoffld */
afb046e2
AV
2351 NULL,
2352};
2353
0645cb83
QT
2354void qla_insert_tgt_attrs(void)
2355{
2356 struct device_attribute **attr;
2357
2358 /* advance to empty slot */
2359 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2360 continue;
2361
2362 *attr = &dev_attr_qlini_mode;
2363 attr++;
2364 *attr = &dev_attr_ql2xiniexchg;
2365 attr++;
2366 *attr = &dev_attr_ql2xexchoffld;
2367}
2368
8482e118
AV
2369/* Host attributes. */
2370
2371static void
2372qla2x00_get_host_port_id(struct Scsi_Host *shost)
2373{
7b867cf7 2374 scsi_qla_host_t *vha = shost_priv(shost);
8482e118 2375
7b867cf7
AC
2376 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2377 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e118
AV
2378}
2379
04414013
AV
2380static void
2381qla2x00_get_host_speed(struct Scsi_Host *shost)
2382{
2a3192a3
JC
2383 scsi_qla_host_t *vha = shost_priv(shost);
2384 u32 speed;
04414013 2385
2a3192a3 2386 if (IS_QLAFX00(vha->hw)) {
8ae6d9c7
GM
2387 qlafx00_get_host_speed(shost);
2388 return;
2389 }
2390
2a3192a3 2391 switch (vha->hw->link_data_rate) {
d8b45213 2392 case PORT_SPEED_1GB:
2ae2b370 2393 speed = FC_PORTSPEED_1GBIT;
04414013 2394 break;
d8b45213 2395 case PORT_SPEED_2GB:
2ae2b370 2396 speed = FC_PORTSPEED_2GBIT;
04414013 2397 break;
d8b45213 2398 case PORT_SPEED_4GB:
2ae2b370 2399 speed = FC_PORTSPEED_4GBIT;
04414013 2400 break;
da4541b6 2401 case PORT_SPEED_8GB:
2ae2b370 2402 speed = FC_PORTSPEED_8GBIT;
da4541b6 2403 break;
3a03eb79
AV
2404 case PORT_SPEED_10GB:
2405 speed = FC_PORTSPEED_10GBIT;
2406 break;
6246b8a1
GM
2407 case PORT_SPEED_16GB:
2408 speed = FC_PORTSPEED_16GBIT;
2409 break;
f73cb695
CD
2410 case PORT_SPEED_32GB:
2411 speed = FC_PORTSPEED_32GBIT;
2412 break;
ecc89f25
JC
2413 case PORT_SPEED_64GB:
2414 speed = FC_PORTSPEED_64GBIT;
2415 break;
2a3192a3
JC
2416 default:
2417 speed = FC_PORTSPEED_UNKNOWN;
2418 break;
04414013 2419 }
2a3192a3 2420
04414013
AV
2421 fc_host_speed(shost) = speed;
2422}
2423
8d067623
AV
2424static void
2425qla2x00_get_host_port_type(struct Scsi_Host *shost)
2426{
7b867cf7 2427 scsi_qla_host_t *vha = shost_priv(shost);
2a3192a3 2428 uint32_t port_type;
8d067623 2429
7b867cf7 2430 if (vha->vp_idx) {
2f2fa13d
SS
2431 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2432 return;
2433 }
7b867cf7 2434 switch (vha->hw->current_topology) {
8d067623
AV
2435 case ISP_CFG_NL:
2436 port_type = FC_PORTTYPE_LPORT;
2437 break;
2438 case ISP_CFG_FL:
2439 port_type = FC_PORTTYPE_NLPORT;
2440 break;
2441 case ISP_CFG_N:
2442 port_type = FC_PORTTYPE_PTP;
2443 break;
2444 case ISP_CFG_F:
2445 port_type = FC_PORTTYPE_NPORT;
2446 break;
2a3192a3
JC
2447 default:
2448 port_type = FC_PORTTYPE_UNKNOWN;
2449 break;
8d067623 2450 }
2a3192a3 2451
8d067623
AV
2452 fc_host_port_type(shost) = port_type;
2453}
2454
8482e118
AV
2455static void
2456qla2x00_get_starget_node_name(struct scsi_target *starget)
2457{
2458 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 2459 scsi_qla_host_t *vha = shost_priv(host);
bdf79621 2460 fc_port_t *fcport;
f8b02a85 2461 u64 node_name = 0;
8482e118 2462
7b867cf7 2463 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
2464 if (fcport->rport &&
2465 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 2466 node_name = wwn_to_u64(fcport->node_name);
bdf79621
AV
2467 break;
2468 }
2469 }
2470
f8b02a85 2471 fc_starget_node_name(starget) = node_name;
8482e118
AV
2472}
2473
2474static void
2475qla2x00_get_starget_port_name(struct scsi_target *starget)
2476{
2477 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 2478 scsi_qla_host_t *vha = shost_priv(host);
bdf79621 2479 fc_port_t *fcport;
f8b02a85 2480 u64 port_name = 0;
8482e118 2481
7b867cf7 2482 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
2483 if (fcport->rport &&
2484 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 2485 port_name = wwn_to_u64(fcport->port_name);
bdf79621
AV
2486 break;
2487 }
2488 }
2489
f8b02a85 2490 fc_starget_port_name(starget) = port_name;
8482e118
AV
2491}
2492
2493static void
2494qla2x00_get_starget_port_id(struct scsi_target *starget)
2495{
2496 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
7b867cf7 2497 scsi_qla_host_t *vha = shost_priv(host);
bdf79621
AV
2498 fc_port_t *fcport;
2499 uint32_t port_id = ~0U;
2500
7b867cf7 2501 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5ab5a4dd
AV
2502 if (fcport->rport &&
2503 starget->id == fcport->rport->scsi_target_id) {
bdf79621
AV
2504 port_id = fcport->d_id.b.domain << 16 |
2505 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2506 break;
2507 }
2508 }
8482e118 2509
8482e118
AV
2510 fc_starget_port_id(starget) = port_id;
2511}
2512
2a3192a3 2513static inline void
8482e118
AV
2514qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2515{
2a3192a3 2516 rport->dev_loss_tmo = timeout ? timeout : 1;
8482e118
AV
2517}
2518
5f3a9a20
SJ
2519static void
2520qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2521{
2522 struct Scsi_Host *host = rport_to_shost(rport);
2523 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
044d78e1 2524 unsigned long flags;
5f3a9a20 2525
3c01b4f9
SJ
2526 if (!fcport)
2527 return;
2528
38170fa8
GM
2529 /* Now that the rport has been deleted, set the fcport state to
2530 FCS_DEVICE_DEAD */
ec426e10 2531 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
38170fa8 2532
5f3a9a20
SJ
2533 /*
2534 * Transport has effectively 'deleted' the rport, clear
2535 * all local references.
2536 */
044d78e1 2537 spin_lock_irqsave(host->host_lock, flags);
3fadb80b 2538 fcport->rport = fcport->drport = NULL;
5f3a9a20 2539 *((fc_port_t **)rport->dd_data) = NULL;
044d78e1 2540 spin_unlock_irqrestore(host->host_lock, flags);
3fadb80b
GM
2541
2542 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2543 return;
2544
2545 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2546 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2547 return;
2548 }
5f3a9a20
SJ
2549}
2550
2551static void
2552qla2x00_terminate_rport_io(struct fc_rport *rport)
2553{
2554 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2555
3c01b4f9
SJ
2556 if (!fcport)
2557 return;
2558
a465537a
SC
2559 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2560 return;
2561
85880801
AV
2562 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2563 return;
2564
b9b12f73
SJ
2565 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2566 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2567 return;
2568 }
6390d1f3
AV
2569 /*
2570 * At this point all fcport's software-states are cleared. Perform any
2571 * final cleanup of firmware resources (PCBs and XCBs).
2572 */
220d36b4 2573 if (fcport->loop_id != FC_NO_LOOP_ID) {
af11f64d
AV
2574 if (IS_FWI2_CAPABLE(fcport->vha->hw))
2575 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2576 fcport->loop_id, fcport->d_id.b.domain,
2577 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2578 else
2579 qla2x00_port_logout(fcport->vha, fcport);
2580 }
5f3a9a20
SJ
2581}
2582
91ca7b01
AV
2583static int
2584qla2x00_issue_lip(struct Scsi_Host *shost)
2585{
7b867cf7 2586 scsi_qla_host_t *vha = shost_priv(shost);
91ca7b01 2587
8ae6d9c7
GM
2588 if (IS_QLAFX00(vha->hw))
2589 return 0;
2590
7b867cf7 2591 qla2x00_loop_reset(vha);
91ca7b01
AV
2592 return 0;
2593}
2594
392e2f65
AV
2595static struct fc_host_statistics *
2596qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2597{
7b867cf7
AC
2598 scsi_qla_host_t *vha = shost_priv(shost);
2599 struct qla_hw_data *ha = vha->hw;
2600 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
392e2f65 2601 int rval;
43ef0580
AV
2602 struct link_statistics *stats;
2603 dma_addr_t stats_dma;
fc90adaf 2604 struct fc_host_statistics *p = &vha->fc_host_stat;
392e2f65 2605
fc90adaf 2606 memset(p, -1, sizeof(*p));
392e2f65 2607
8ae6d9c7
GM
2608 if (IS_QLAFX00(vha->hw))
2609 goto done;
2610
85880801
AV
2611 if (test_bit(UNLOADING, &vha->dpc_flags))
2612 goto done;
2613
2614 if (unlikely(pci_channel_offline(ha->pdev)))
2615 goto done;
2616
22ebde16 2617 if (qla2x00_chip_is_down(vha))
8fbfe2d2
CD
2618 goto done;
2619
750afb08
LC
2620 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2621 GFP_KERNEL);
c6dc9905 2622 if (!stats) {
7c3df132
SK
2623 ql_log(ql_log_warn, vha, 0x707d,
2624 "Failed to allocate memory for stats.\n");
43ef0580
AV
2625 goto done;
2626 }
43ef0580
AV
2627
2628 rval = QLA_FUNCTION_FAILED;
e428924c 2629 if (IS_FWI2_CAPABLE(ha)) {
c6dc9905 2630 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
7b867cf7 2631 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
8fbfe2d2 2632 !ha->dpc_active) {
178779a6 2633 /* Must be in a 'READY' state for statistics retrieval. */
7b867cf7
AC
2634 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2635 stats, stats_dma);
392e2f65 2636 }
178779a6
AV
2637
2638 if (rval != QLA_SUCCESS)
43ef0580
AV
2639 goto done_free;
2640
fc90adaf
JC
2641 p->link_failure_count = stats->link_fail_cnt;
2642 p->loss_of_sync_count = stats->loss_sync_cnt;
2643 p->loss_of_signal_count = stats->loss_sig_cnt;
2644 p->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
2645 p->invalid_tx_word_count = stats->inval_xmit_word_cnt;
2646 p->invalid_crc_count = stats->inval_crc_cnt;
43ef0580 2647 if (IS_FWI2_CAPABLE(ha)) {
fc90adaf
JC
2648 p->lip_count = stats->lip_cnt;
2649 p->tx_frames = stats->tx_frames;
2650 p->rx_frames = stats->rx_frames;
2651 p->dumped_frames = stats->discarded_frames;
2652 p->nos_count = stats->nos_rcvd;
2653 p->error_frames =
fabbb8df 2654 stats->dropped_frames + stats->discarded_frames;
fc90adaf
JC
2655 p->rx_words = vha->qla_stats.input_bytes;
2656 p->tx_words = vha->qla_stats.output_bytes;
43ef0580 2657 }
fc90adaf
JC
2658 p->fcp_control_requests = vha->qla_stats.control_requests;
2659 p->fcp_input_requests = vha->qla_stats.input_requests;
2660 p->fcp_output_requests = vha->qla_stats.output_requests;
2661 p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
2662 p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
2663 p->seconds_since_last_reset =
fabbb8df 2664 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
fc90adaf 2665 do_div(p->seconds_since_last_reset, HZ);
392e2f65 2666
43ef0580 2667done_free:
243de676
HZ
2668 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2669 stats, stats_dma);
178779a6 2670done:
fc90adaf 2671 return p;
392e2f65
AV
2672}
2673
fabbb8df
JC
2674static void
2675qla2x00_reset_host_stats(struct Scsi_Host *shost)
2676{
2677 scsi_qla_host_t *vha = shost_priv(shost);
c6dc9905
JC
2678 struct qla_hw_data *ha = vha->hw;
2679 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2680 struct link_statistics *stats;
2681 dma_addr_t stats_dma;
fabbb8df 2682
fc90adaf 2683 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
fabbb8df
JC
2684 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2685
2686 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
c6dc9905
JC
2687
2688 if (IS_FWI2_CAPABLE(ha)) {
2689 stats = dma_alloc_coherent(&ha->pdev->dev,
2690 sizeof(*stats), &stats_dma, GFP_KERNEL);
2691 if (!stats) {
2692 ql_log(ql_log_warn, vha, 0x70d7,
2693 "Failed to allocate memory for stats.\n");
2694 return;
2695 }
2696
2697 /* reset firmware statistics */
2698 qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2699
2700 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2701 stats, stats_dma);
2702 }
fabbb8df
JC
2703}
2704
1620f7c2
AV
2705static void
2706qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2707{
7b867cf7 2708 scsi_qla_host_t *vha = shost_priv(shost);
1620f7c2 2709
df57caba
HM
2710 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2711 sizeof(fc_host_symbolic_name(shost)));
1620f7c2
AV
2712}
2713
a740a3f0
AV
2714static void
2715qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2716{
7b867cf7 2717 scsi_qla_host_t *vha = shost_priv(shost);
a740a3f0 2718
7b867cf7 2719 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
a740a3f0
AV
2720}
2721
90991c85
AV
2722static void
2723qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2724{
7b867cf7 2725 scsi_qla_host_t *vha = shost_priv(shost);
35e0cbd4
GM
2726 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
2727 0xFF, 0xFF, 0xFF, 0xFF};
2728 u64 fabric_name = wwn_to_u64(node_name);
90991c85 2729
7b867cf7 2730 if (vha->device_flags & SWITCH_FOUND)
35e0cbd4 2731 fabric_name = wwn_to_u64(vha->fabric_node_name);
90991c85 2732
35e0cbd4 2733 fc_host_fabric_name(shost) = fabric_name;
90991c85
AV
2734}
2735
7047fcdd
AV
2736static void
2737qla2x00_get_host_port_state(struct Scsi_Host *shost)
2738{
7b867cf7
AC
2739 scsi_qla_host_t *vha = shost_priv(shost);
2740 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
7047fcdd 2741
49e85c23 2742 if (!base_vha->flags.online) {
7047fcdd 2743 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
49e85c23
SK
2744 return;
2745 }
2746
2747 switch (atomic_read(&base_vha->loop_state)) {
2748 case LOOP_UPDATE:
2749 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2750 break;
2751 case LOOP_DOWN:
2752 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2753 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2754 else
2755 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2756 break;
2757 case LOOP_DEAD:
2758 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2759 break;
2760 case LOOP_READY:
7047fcdd 2761 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
49e85c23
SK
2762 break;
2763 default:
2764 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2765 break;
2766 }
7047fcdd
AV
2767}
2768
2c3dfe3f
SJ
2769static int
2770qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2771{
2772 int ret = 0;
2afa19a9 2773 uint8_t qos = 0;
7b867cf7
AC
2774 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2775 scsi_qla_host_t *vha = NULL;
73208dfd 2776 struct qla_hw_data *ha = base_vha->hw;
2afa19a9 2777 int cnt;
59e0b8b0 2778 struct req_que *req = ha->req_q_map[0];
d7459527 2779 struct qla_qpair *qpair;
2c3dfe3f
SJ
2780
2781 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2782 if (ret) {
7c3df132
SK
2783 ql_log(ql_log_warn, vha, 0x707e,
2784 "Vport sanity check failed, status %x\n", ret);
2c3dfe3f
SJ
2785 return (ret);
2786 }
2787
2788 vha = qla24xx_create_vhost(fc_vport);
2789 if (vha == NULL) {
7c3df132 2790 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
2c3dfe3f
SJ
2791 return FC_VPORT_FAILED;
2792 }
2793 if (disable) {
2794 atomic_set(&vha->vp_state, VP_OFFLINE);
2795 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
2796 } else
2797 atomic_set(&vha->vp_state, VP_FAILED);
2798
2799 /* ready to create vport */
7c3df132
SK
2800 ql_log(ql_log_info, vha, 0x7080,
2801 "VP entry id %d assigned.\n", vha->vp_idx);
2c3dfe3f
SJ
2802
2803 /* initialized vport states */
2804 atomic_set(&vha->loop_state, LOOP_DOWN);
2805 vha->vp_err_state= VP_ERR_PORTDWN;
2806 vha->vp_prev_err_state= VP_ERR_UNKWN;
2807 /* Check if physical ha port is Up */
7b867cf7
AC
2808 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
2809 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
2c3dfe3f 2810 /* Don't retry or attempt login of this virtual port */
7c3df132
SK
2811 ql_dbg(ql_dbg_user, vha, 0x7081,
2812 "Vport loop state is not UP.\n");
2c3dfe3f
SJ
2813 atomic_set(&vha->loop_state, LOOP_DEAD);
2814 if (!disable)
2815 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
2816 }
2817
e02587d7 2818 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
bad75002 2819 if (ha->fw_attributes & BIT_4) {
9e522cd8 2820 int prot = 0, guard;
bad75002 2821 vha->flags.difdix_supported = 1;
7c3df132
SK
2822 ql_dbg(ql_dbg_user, vha, 0x7082,
2823 "Registered for DIF/DIX type 1 and 3 protection.\n");
8cb2049c
AE
2824 if (ql2xenabledif == 1)
2825 prot = SHOST_DIX_TYPE0_PROTECTION;
bad75002 2826 scsi_host_set_prot(vha->host,
8cb2049c 2827 prot | SHOST_DIF_TYPE1_PROTECTION
0c470874 2828 | SHOST_DIF_TYPE2_PROTECTION
bad75002
AE
2829 | SHOST_DIF_TYPE3_PROTECTION
2830 | SHOST_DIX_TYPE1_PROTECTION
0c470874 2831 | SHOST_DIX_TYPE2_PROTECTION
bad75002 2832 | SHOST_DIX_TYPE3_PROTECTION);
9e522cd8
AE
2833
2834 guard = SHOST_DIX_GUARD_CRC;
2835
2836 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2837 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2838 guard |= SHOST_DIX_GUARD_IP;
2839
2840 scsi_host_set_guard(vha->host, guard);
bad75002
AE
2841 } else
2842 vha->flags.difdix_supported = 0;
2843 }
2844
d139b9bd
JB
2845 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
2846 &ha->pdev->dev)) {
7c3df132
SK
2847 ql_dbg(ql_dbg_user, vha, 0x7083,
2848 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
2c3dfe3f
SJ
2849 goto vport_create_failed_2;
2850 }
2851
2852 /* initialize attributes */
d2b5f10e 2853 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
2c3dfe3f
SJ
2854 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2855 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2856 fc_host_supported_classes(vha->host) =
7b867cf7 2857 fc_host_supported_classes(base_vha->host);
2c3dfe3f 2858 fc_host_supported_speeds(vha->host) =
7b867cf7 2859 fc_host_supported_speeds(base_vha->host);
2c3dfe3f 2860
2d70c103 2861 qlt_vport_create(vha, ha);
2c3dfe3f
SJ
2862 qla24xx_vport_disable(fc_vport, disable);
2863
d7459527 2864 if (!ql2xmqsupport || !ha->npiv_info)
2afa19a9 2865 goto vport_queue;
d7459527 2866
2afa19a9 2867 /* Create a request queue in QoS mode for the vport */
40859ae5
AC
2868 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
2869 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
2870 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
59e0b8b0 2871 8) == 0) {
2afa19a9
AC
2872 qos = ha->npiv_info[cnt].q_qos;
2873 break;
73208dfd 2874 }
2afa19a9 2875 }
6246b8a1 2876
2afa19a9 2877 if (qos) {
82de802a 2878 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
d7459527 2879 if (!qpair)
7c3df132 2880 ql_log(ql_log_warn, vha, 0x7084,
d7459527 2881 "Can't create qpair for VP[%d]\n",
7c3df132 2882 vha->vp_idx);
59e0b8b0 2883 else {
7c3df132 2884 ql_dbg(ql_dbg_multiq, vha, 0xc001,
d7459527
MH
2885 "Queue pair: %d Qos: %d) created for VP[%d]\n",
2886 qpair->id, qos, vha->vp_idx);
7c3df132 2887 ql_dbg(ql_dbg_user, vha, 0x7085,
d7459527
MH
2888 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
2889 qpair->id, qos, vha->vp_idx);
2890 req = qpair->req;
2891 vha->qpair = qpair;
59e0b8b0 2892 }
73208dfd
AC
2893 }
2894
2afa19a9 2895vport_queue:
59e0b8b0 2896 vha->req = req;
2c3dfe3f 2897 return 0;
2afa19a9 2898
2c3dfe3f
SJ
2899vport_create_failed_2:
2900 qla24xx_disable_vp(vha);
2901 qla24xx_deallocate_vp_id(vha);
2c3dfe3f
SJ
2902 scsi_host_put(vha->host);
2903 return FC_VPORT_FAILED;
2904}
2905
a824ebb3 2906static int
2c3dfe3f
SJ
2907qla24xx_vport_delete(struct fc_vport *fc_vport)
2908{
2c3dfe3f 2909 scsi_qla_host_t *vha = fc_vport->dd_data;
73208dfd
AC
2910 struct qla_hw_data *ha = vha->hw;
2911 uint16_t id = vha->vp_idx;
c9c5ced9
AV
2912
2913 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
7b867cf7 2914 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
c9c5ced9 2915 msleep(1000);
2c3dfe3f 2916
835aa4f2
GM
2917 qla_nvme_delete(vha);
2918
2c3dfe3f 2919 qla24xx_disable_vp(vha);
efa93f48 2920 qla2x00_wait_for_sess_deletion(vha);
2c3dfe3f 2921
feafb7b1
AE
2922 vha->flags.delete_progress = 1;
2923
0e8cd71c
SK
2924 qlt_remove_target(ha, vha);
2925
7b867cf7
AC
2926 fc_remove_host(vha->host);
2927
2928 scsi_remove_host(vha->host);
2929
9f40682e
AE
2930 /* Allow timer to run to drain queued items, when removing vp */
2931 qla24xx_deallocate_vp_id(vha);
2932
feafb7b1
AE
2933 if (vha->timer_active) {
2934 qla2x00_vp_stop_timer(vha);
7c3df132
SK
2935 ql_dbg(ql_dbg_user, vha, 0x7086,
2936 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
feafb7b1 2937 }
7b867cf7 2938
feafb7b1
AE
2939 qla2x00_free_fcports(vha);
2940
0d6e61bc
AV
2941 mutex_lock(&ha->vport_lock);
2942 ha->cur_vport_count--;
2943 clear_bit(vha->vp_idx, ha->vp_idx_map);
2944 mutex_unlock(&ha->vport_lock);
2945
726b8548
QT
2946 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
2947 vha->gnl.ldma);
2948
a4239945
QT
2949 vfree(vha->scan.l);
2950
c4a9b538 2951 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
d7459527 2952 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
7c3df132 2953 ql_log(ql_log_warn, vha, 0x7087,
d7459527 2954 "Queue Pair delete failed.\n");
cf5a1631
AC
2955 }
2956
7c3df132 2957 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
cfb0919c 2958 scsi_host_put(vha->host);
2c3dfe3f
SJ
2959 return 0;
2960}
2961
a824ebb3 2962static int
2c3dfe3f
SJ
2963qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
2964{
2965 scsi_qla_host_t *vha = fc_vport->dd_data;
2966
2967 if (disable)
2968 qla24xx_disable_vp(vha);
2969 else
2970 qla24xx_enable_vp(vha);
2971
2972 return 0;
2973}
2974
1c97a12a 2975struct fc_function_template qla2xxx_transport_functions = {
8482e118
AV
2976
2977 .show_host_node_name = 1,
2978 .show_host_port_name = 1,
ad3e0eda 2979 .show_host_supported_classes = 1,
2ae2b370 2980 .show_host_supported_speeds = 1,
ad3e0eda 2981
8482e118
AV
2982 .get_host_port_id = qla2x00_get_host_port_id,
2983 .show_host_port_id = 1,
04414013
AV
2984 .get_host_speed = qla2x00_get_host_speed,
2985 .show_host_speed = 1,
8d067623
AV
2986 .get_host_port_type = qla2x00_get_host_port_type,
2987 .show_host_port_type = 1,
1620f7c2
AV
2988 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2989 .show_host_symbolic_name = 1,
a740a3f0
AV
2990 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2991 .show_host_system_hostname = 1,
90991c85
AV
2992 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2993 .show_host_fabric_name = 1,
7047fcdd
AV
2994 .get_host_port_state = qla2x00_get_host_port_state,
2995 .show_host_port_state = 1,
8482e118 2996
bdf79621 2997 .dd_fcrport_size = sizeof(struct fc_port *),
ad3e0eda 2998 .show_rport_supported_classes = 1,
8482e118
AV
2999
3000 .get_starget_node_name = qla2x00_get_starget_node_name,
3001 .show_starget_node_name = 1,
3002 .get_starget_port_name = qla2x00_get_starget_port_name,
3003 .show_starget_port_name = 1,
3004 .get_starget_port_id = qla2x00_get_starget_port_id,
3005 .show_starget_port_id = 1,
3006
8482e118
AV
3007 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3008 .show_rport_dev_loss_tmo = 1,
3009
91ca7b01 3010 .issue_fc_host_lip = qla2x00_issue_lip,
5f3a9a20
SJ
3011 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3012 .terminate_rport_io = qla2x00_terminate_rport_io,
392e2f65 3013 .get_fc_host_stats = qla2x00_get_fc_host_stats,
fabbb8df 3014 .reset_fc_host_stats = qla2x00_reset_host_stats,
2c3dfe3f
SJ
3015
3016 .vport_create = qla24xx_vport_create,
3017 .vport_disable = qla24xx_vport_disable,
3018 .vport_delete = qla24xx_vport_delete,
9a069e19
GM
3019 .bsg_request = qla24xx_bsg_request,
3020 .bsg_timeout = qla24xx_bsg_timeout,
2c3dfe3f
SJ
3021};
3022
3023struct fc_function_template qla2xxx_transport_vport_functions = {
3024
3025 .show_host_node_name = 1,
3026 .show_host_port_name = 1,
3027 .show_host_supported_classes = 1,
3028
3029 .get_host_port_id = qla2x00_get_host_port_id,
3030 .show_host_port_id = 1,
3031 .get_host_speed = qla2x00_get_host_speed,
3032 .show_host_speed = 1,
3033 .get_host_port_type = qla2x00_get_host_port_type,
3034 .show_host_port_type = 1,
3035 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3036 .show_host_symbolic_name = 1,
3037 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3038 .show_host_system_hostname = 1,
3039 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3040 .show_host_fabric_name = 1,
3041 .get_host_port_state = qla2x00_get_host_port_state,
3042 .show_host_port_state = 1,
3043
3044 .dd_fcrport_size = sizeof(struct fc_port *),
3045 .show_rport_supported_classes = 1,
3046
3047 .get_starget_node_name = qla2x00_get_starget_node_name,
3048 .show_starget_node_name = 1,
3049 .get_starget_port_name = qla2x00_get_starget_port_name,
3050 .show_starget_port_name = 1,
3051 .get_starget_port_id = qla2x00_get_starget_port_id,
3052 .show_starget_port_id = 1,
3053
2c3dfe3f
SJ
3054 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3055 .show_rport_dev_loss_tmo = 1,
3056
3057 .issue_fc_host_lip = qla2x00_issue_lip,
5f3a9a20
SJ
3058 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3059 .terminate_rport_io = qla2x00_terminate_rport_io,
2c3dfe3f 3060 .get_fc_host_stats = qla2x00_get_fc_host_stats,
fabbb8df
JC
3061 .reset_fc_host_stats = qla2x00_reset_host_stats,
3062
9a069e19
GM
3063 .bsg_request = qla24xx_bsg_request,
3064 .bsg_timeout = qla24xx_bsg_timeout,
8482e118
AV
3065};
3066
8482e118 3067void
7b867cf7 3068qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e118 3069{
7b867cf7 3070 struct qla_hw_data *ha = vha->hw;
72a92df2 3071 u32 speeds = FC_PORTSPEED_UNKNOWN;
2ae2b370 3072
d2b5f10e 3073 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
7b867cf7
AC
3074 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3075 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
7c3f8fd1 3076 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
2d70c103 3077 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
7b867cf7
AC
3078 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3079 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
2ae2b370 3080
6246b8a1 3081 if (IS_CNA_CAPABLE(ha))
72a92df2
JC
3082 speeds = FC_PORTSPEED_10GBIT;
3083 else if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
3084 if (ha->max_supported_speed == 2) {
3085 if (ha->min_supported_speed <= 6)
3086 speeds |= FC_PORTSPEED_64GBIT;
3087 }
3088 if (ha->max_supported_speed == 2 ||
3089 ha->max_supported_speed == 1) {
3090 if (ha->min_supported_speed <= 5)
3091 speeds |= FC_PORTSPEED_32GBIT;
3092 }
3093 if (ha->max_supported_speed == 2 ||
3094 ha->max_supported_speed == 1 ||
3095 ha->max_supported_speed == 0) {
3096 if (ha->min_supported_speed <= 4)
3097 speeds |= FC_PORTSPEED_16GBIT;
3098 }
3099 if (ha->max_supported_speed == 1 ||
3100 ha->max_supported_speed == 0) {
3101 if (ha->min_supported_speed <= 3)
3102 speeds |= FC_PORTSPEED_8GBIT;
3103 }
3104 if (ha->max_supported_speed == 0) {
3105 if (ha->min_supported_speed <= 2)
3106 speeds |= FC_PORTSPEED_4GBIT;
3107 }
3108 } else if (IS_QLA2031(ha))
3109 speeds = FC_PORTSPEED_16GBIT|FC_PORTSPEED_8GBIT|
3110 FC_PORTSPEED_4GBIT;
3111 else if (IS_QLA25XX(ha) || IS_QLAFX00(ha))
3112 speeds = FC_PORTSPEED_8GBIT|FC_PORTSPEED_4GBIT|
3113 FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
4d4df193 3114 else if (IS_QLA24XX_TYPE(ha))
72a92df2
JC
3115 speeds = FC_PORTSPEED_4GBIT|FC_PORTSPEED_2GBIT|
3116 FC_PORTSPEED_1GBIT;
2ae2b370 3117 else if (IS_QLA23XX(ha))
72a92df2 3118 speeds = FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
2ae2b370 3119 else
72a92df2
JC
3120 speeds = FC_PORTSPEED_1GBIT;
3121
3122 fc_host_supported_speeds(vha->host) = speeds;
8482e118 3123}