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