[SCSI] qla2xxx: Export flash-block-size for application support.
[linux-2.6/mini2440.git] / drivers / scsi / qla2xxx / qla_attr.c
blobc017dba900393f67f3e6bdc984b2724c0962d3f5
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
13 static int qla24xx_vport_disable(struct fc_vport *, bool);
15 /* SYSFS attributes --------------------------------------------------------- */
17 static ssize_t
18 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
19 struct bin_attribute *bin_attr,
20 char *buf, loff_t off, size_t count)
22 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
23 struct device, kobj)));
24 struct qla_hw_data *ha = vha->hw;
26 if (ha->fw_dump_reading == 0)
27 return 0;
29 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
30 ha->fw_dump_len);
33 static ssize_t
34 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
35 struct bin_attribute *bin_attr,
36 char *buf, loff_t off, size_t count)
38 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
39 struct device, kobj)));
40 struct qla_hw_data *ha = vha->hw;
41 int reading;
43 if (off != 0)
44 return (0);
46 reading = simple_strtol(buf, NULL, 10);
47 switch (reading) {
48 case 0:
49 if (!ha->fw_dump_reading)
50 break;
52 qla_printk(KERN_INFO, ha,
53 "Firmware dump cleared on (%ld).\n", vha->host_no);
55 ha->fw_dump_reading = 0;
56 ha->fw_dumped = 0;
57 break;
58 case 1:
59 if (ha->fw_dumped && !ha->fw_dump_reading) {
60 ha->fw_dump_reading = 1;
62 qla_printk(KERN_INFO, ha,
63 "Raw firmware dump ready for read on (%ld).\n",
64 vha->host_no);
66 break;
67 case 2:
68 qla2x00_alloc_fw_dump(vha);
69 break;
70 case 3:
71 qla2x00_system_error(vha);
72 break;
74 return (count);
77 static struct bin_attribute sysfs_fw_dump_attr = {
78 .attr = {
79 .name = "fw_dump",
80 .mode = S_IRUSR | S_IWUSR,
82 .size = 0,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
87 static ssize_t
88 qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
92 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
93 struct device, kobj)));
94 struct qla_hw_data *ha = vha->hw;
96 if (!capable(CAP_SYS_ADMIN))
97 return 0;
99 /* Read NVRAM data from cache. */
100 return memory_read_from_buffer(buf, count, &off, ha->nvram,
101 ha->nvram_size);
104 static ssize_t
105 qla2x00_sysfs_write_nvram(struct kobject *kobj,
106 struct bin_attribute *bin_attr,
107 char *buf, loff_t off, size_t count)
109 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
110 struct device, kobj)));
111 struct qla_hw_data *ha = vha->hw;
112 uint16_t cnt;
114 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
115 return 0;
117 /* Checksum NVRAM. */
118 if (IS_FWI2_CAPABLE(ha)) {
119 uint32_t *iter;
120 uint32_t chksum;
122 iter = (uint32_t *)buf;
123 chksum = 0;
124 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
125 chksum += le32_to_cpu(*iter++);
126 chksum = ~chksum + 1;
127 *iter = cpu_to_le32(chksum);
128 } else {
129 uint8_t *iter;
130 uint8_t chksum;
132 iter = (uint8_t *)buf;
133 chksum = 0;
134 for (cnt = 0; cnt < count - 1; cnt++)
135 chksum += *iter++;
136 chksum = ~chksum + 1;
137 *iter = chksum;
140 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
141 qla_printk(KERN_WARNING, ha,
142 "HBA not online, failing NVRAM update.\n");
143 return -EAGAIN;
146 /* Write NVRAM. */
147 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
148 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
149 count);
151 /* NVRAM settings take effect immediately. */
152 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
153 qla2xxx_wake_dpc(vha);
154 qla2x00_wait_for_chip_reset(vha);
156 return (count);
159 static struct bin_attribute sysfs_nvram_attr = {
160 .attr = {
161 .name = "nvram",
162 .mode = S_IRUSR | S_IWUSR,
164 .size = 512,
165 .read = qla2x00_sysfs_read_nvram,
166 .write = qla2x00_sysfs_write_nvram,
169 static ssize_t
170 qla2x00_sysfs_read_optrom(struct kobject *kobj,
171 struct bin_attribute *bin_attr,
172 char *buf, loff_t off, size_t count)
174 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
175 struct device, kobj)));
176 struct qla_hw_data *ha = vha->hw;
178 if (ha->optrom_state != QLA_SREADING)
179 return 0;
181 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
182 ha->optrom_region_size);
185 static ssize_t
186 qla2x00_sysfs_write_optrom(struct kobject *kobj,
187 struct bin_attribute *bin_attr,
188 char *buf, loff_t off, size_t count)
190 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
191 struct device, kobj)));
192 struct qla_hw_data *ha = vha->hw;
194 if (ha->optrom_state != QLA_SWRITING)
195 return -EINVAL;
196 if (off > ha->optrom_region_size)
197 return -ERANGE;
198 if (off + count > ha->optrom_region_size)
199 count = ha->optrom_region_size - off;
201 memcpy(&ha->optrom_buffer[off], buf, count);
203 return count;
206 static struct bin_attribute sysfs_optrom_attr = {
207 .attr = {
208 .name = "optrom",
209 .mode = S_IRUSR | S_IWUSR,
211 .size = 0,
212 .read = qla2x00_sysfs_read_optrom,
213 .write = qla2x00_sysfs_write_optrom,
216 static ssize_t
217 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
218 struct bin_attribute *bin_attr,
219 char *buf, loff_t off, size_t count)
221 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
222 struct device, kobj)));
223 struct qla_hw_data *ha = vha->hw;
225 uint32_t start = 0;
226 uint32_t size = ha->optrom_size;
227 int val, valid;
229 if (off)
230 return 0;
232 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
233 return -EINVAL;
234 if (start > ha->optrom_size)
235 return -EINVAL;
237 switch (val) {
238 case 0:
239 if (ha->optrom_state != QLA_SREADING &&
240 ha->optrom_state != QLA_SWRITING)
241 break;
243 ha->optrom_state = QLA_SWAITING;
245 DEBUG2(qla_printk(KERN_INFO, ha,
246 "Freeing flash region allocation -- 0x%x bytes.\n",
247 ha->optrom_region_size));
249 vfree(ha->optrom_buffer);
250 ha->optrom_buffer = NULL;
251 break;
252 case 1:
253 if (ha->optrom_state != QLA_SWAITING)
254 break;
256 ha->optrom_region_start = start;
257 ha->optrom_region_size = start + size > ha->optrom_size ?
258 ha->optrom_size - start : size;
260 ha->optrom_state = QLA_SREADING;
261 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
262 if (ha->optrom_buffer == NULL) {
263 qla_printk(KERN_WARNING, ha,
264 "Unable to allocate memory for optrom retrieval "
265 "(%x).\n", ha->optrom_region_size);
267 ha->optrom_state = QLA_SWAITING;
268 return count;
271 DEBUG2(qla_printk(KERN_INFO, ha,
272 "Reading flash region -- 0x%x/0x%x.\n",
273 ha->optrom_region_start, ha->optrom_region_size));
275 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
276 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
277 ha->optrom_region_start, ha->optrom_region_size);
278 break;
279 case 2:
280 if (ha->optrom_state != QLA_SWAITING)
281 break;
284 * We need to be more restrictive on which FLASH regions are
285 * allowed to be updated via user-space. Regions accessible
286 * via this method include:
288 * ISP21xx/ISP22xx/ISP23xx type boards:
290 * 0x000000 -> 0x020000 -- Boot code.
292 * ISP2322/ISP24xx type boards:
294 * 0x000000 -> 0x07ffff -- Boot code.
295 * 0x080000 -> 0x0fffff -- Firmware.
297 * ISP25xx type boards:
299 * 0x000000 -> 0x07ffff -- Boot code.
300 * 0x080000 -> 0x0fffff -- Firmware.
301 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
303 valid = 0;
304 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
305 valid = 1;
306 else if (start == (ha->flt_region_boot * 4) ||
307 start == (ha->flt_region_fw * 4))
308 valid = 1;
309 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
310 valid = 1;
311 if (!valid) {
312 qla_printk(KERN_WARNING, ha,
313 "Invalid start region 0x%x/0x%x.\n", start, size);
314 return -EINVAL;
317 ha->optrom_region_start = start;
318 ha->optrom_region_size = start + size > ha->optrom_size ?
319 ha->optrom_size - start : size;
321 ha->optrom_state = QLA_SWRITING;
322 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
323 if (ha->optrom_buffer == NULL) {
324 qla_printk(KERN_WARNING, ha,
325 "Unable to allocate memory for optrom update "
326 "(%x).\n", ha->optrom_region_size);
328 ha->optrom_state = QLA_SWAITING;
329 return count;
332 DEBUG2(qla_printk(KERN_INFO, ha,
333 "Staging flash region write -- 0x%x/0x%x.\n",
334 ha->optrom_region_start, ha->optrom_region_size));
336 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
337 break;
338 case 3:
339 if (ha->optrom_state != QLA_SWRITING)
340 break;
342 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
343 qla_printk(KERN_WARNING, ha,
344 "HBA not online, failing flash update.\n");
345 return -EAGAIN;
348 DEBUG2(qla_printk(KERN_INFO, ha,
349 "Writing flash region -- 0x%x/0x%x.\n",
350 ha->optrom_region_start, ha->optrom_region_size));
352 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
353 ha->optrom_region_start, ha->optrom_region_size);
354 break;
355 default:
356 count = -EINVAL;
358 return count;
361 static struct bin_attribute sysfs_optrom_ctl_attr = {
362 .attr = {
363 .name = "optrom_ctl",
364 .mode = S_IWUSR,
366 .size = 0,
367 .write = qla2x00_sysfs_write_optrom_ctl,
370 static ssize_t
371 qla2x00_sysfs_read_vpd(struct kobject *kobj,
372 struct bin_attribute *bin_attr,
373 char *buf, loff_t off, size_t count)
375 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
376 struct device, kobj)));
377 struct qla_hw_data *ha = vha->hw;
379 if (!capable(CAP_SYS_ADMIN))
380 return 0;
382 /* Read NVRAM data from cache. */
383 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
386 static ssize_t
387 qla2x00_sysfs_write_vpd(struct kobject *kobj,
388 struct bin_attribute *bin_attr,
389 char *buf, loff_t off, size_t count)
391 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
392 struct device, kobj)));
393 struct qla_hw_data *ha = vha->hw;
394 uint8_t *tmp_data;
396 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
397 return 0;
399 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
400 qla_printk(KERN_WARNING, ha,
401 "HBA not online, failing VPD update.\n");
402 return -EAGAIN;
405 /* Write NVRAM. */
406 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
407 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
409 /* Update flash version information for 4Gb & above. */
410 if (!IS_FWI2_CAPABLE(ha))
411 goto done;
413 tmp_data = vmalloc(256);
414 if (!tmp_data) {
415 qla_printk(KERN_WARNING, ha,
416 "Unable to allocate memory for VPD information update.\n");
417 goto done;
419 ha->isp_ops->get_flash_version(vha, tmp_data);
420 vfree(tmp_data);
421 done:
422 return count;
425 static struct bin_attribute sysfs_vpd_attr = {
426 .attr = {
427 .name = "vpd",
428 .mode = S_IRUSR | S_IWUSR,
430 .size = 0,
431 .read = qla2x00_sysfs_read_vpd,
432 .write = qla2x00_sysfs_write_vpd,
435 static ssize_t
436 qla2x00_sysfs_read_sfp(struct kobject *kobj,
437 struct bin_attribute *bin_attr,
438 char *buf, loff_t off, size_t count)
440 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
441 struct device, kobj)));
442 struct qla_hw_data *ha = vha->hw;
443 uint16_t iter, addr, offset;
444 int rval;
446 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
447 return 0;
449 if (ha->sfp_data)
450 goto do_read;
452 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
453 &ha->sfp_data_dma);
454 if (!ha->sfp_data) {
455 qla_printk(KERN_WARNING, ha,
456 "Unable to allocate memory for SFP read-data.\n");
457 return 0;
460 do_read:
461 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
462 addr = 0xa0;
463 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
464 iter++, offset += SFP_BLOCK_SIZE) {
465 if (iter == 4) {
466 /* Skip to next device address. */
467 addr = 0xa2;
468 offset = 0;
471 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
472 SFP_BLOCK_SIZE);
473 if (rval != QLA_SUCCESS) {
474 qla_printk(KERN_WARNING, ha,
475 "Unable to read SFP data (%x/%x/%x).\n", rval,
476 addr, offset);
477 count = 0;
478 break;
480 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
481 buf += SFP_BLOCK_SIZE;
484 return count;
487 static struct bin_attribute sysfs_sfp_attr = {
488 .attr = {
489 .name = "sfp",
490 .mode = S_IRUSR | S_IWUSR,
492 .size = SFP_DEV_SIZE * 2,
493 .read = qla2x00_sysfs_read_sfp,
496 static ssize_t
497 qla2x00_sysfs_write_reset(struct kobject *kobj,
498 struct bin_attribute *bin_attr,
499 char *buf, loff_t off, size_t count)
501 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
502 struct device, kobj)));
503 struct qla_hw_data *ha = vha->hw;
504 int type;
506 if (off != 0)
507 return 0;
509 type = simple_strtol(buf, NULL, 10);
510 switch (type) {
511 case 0x2025c:
512 qla_printk(KERN_INFO, ha,
513 "Issuing ISP reset on (%ld).\n", vha->host_no);
515 scsi_block_requests(vha->host);
516 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
517 qla2xxx_wake_dpc(vha);
518 qla2x00_wait_for_chip_reset(vha);
519 scsi_unblock_requests(vha->host);
520 break;
521 case 0x2025d:
522 if (!IS_QLA81XX(ha))
523 break;
525 qla_printk(KERN_INFO, ha,
526 "Issuing MPI reset on (%ld).\n", vha->host_no);
528 /* Make sure FC side is not in reset */
529 qla2x00_wait_for_hba_online(vha);
531 /* Issue MPI reset */
532 scsi_block_requests(vha->host);
533 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
534 qla_printk(KERN_WARNING, ha,
535 "MPI reset failed on (%ld).\n", vha->host_no);
536 scsi_unblock_requests(vha->host);
537 break;
539 return count;
542 static struct bin_attribute sysfs_reset_attr = {
543 .attr = {
544 .name = "reset",
545 .mode = S_IWUSR,
547 .size = 0,
548 .write = qla2x00_sysfs_write_reset,
551 static struct sysfs_entry {
552 char *name;
553 struct bin_attribute *attr;
554 int is4GBp_only;
555 } bin_file_entries[] = {
556 { "fw_dump", &sysfs_fw_dump_attr, },
557 { "nvram", &sysfs_nvram_attr, },
558 { "optrom", &sysfs_optrom_attr, },
559 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
560 { "vpd", &sysfs_vpd_attr, 1 },
561 { "sfp", &sysfs_sfp_attr, 1 },
562 { "reset", &sysfs_reset_attr, },
563 { NULL },
566 void
567 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
569 struct Scsi_Host *host = vha->host;
570 struct sysfs_entry *iter;
571 int ret;
573 for (iter = bin_file_entries; iter->name; iter++) {
574 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
575 continue;
577 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
578 iter->attr);
579 if (ret)
580 qla_printk(KERN_INFO, vha->hw,
581 "Unable to create sysfs %s binary attribute "
582 "(%d).\n", iter->name, ret);
586 void
587 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
589 struct Scsi_Host *host = vha->host;
590 struct sysfs_entry *iter;
591 struct qla_hw_data *ha = vha->hw;
593 for (iter = bin_file_entries; iter->name; iter++) {
594 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
595 continue;
597 sysfs_remove_bin_file(&host->shost_gendev.kobj,
598 iter->attr);
601 if (ha->beacon_blink_led == 1)
602 ha->isp_ops->beacon_off(vha);
605 /* Scsi_Host attributes. */
607 static ssize_t
608 qla2x00_drvr_version_show(struct device *dev,
609 struct device_attribute *attr, char *buf)
611 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
614 static ssize_t
615 qla2x00_fw_version_show(struct device *dev,
616 struct device_attribute *attr, char *buf)
618 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
619 struct qla_hw_data *ha = vha->hw;
620 char fw_str[128];
622 return snprintf(buf, PAGE_SIZE, "%s\n",
623 ha->isp_ops->fw_version_str(vha, fw_str));
626 static ssize_t
627 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
628 char *buf)
630 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
631 struct qla_hw_data *ha = vha->hw;
632 uint32_t sn;
634 if (IS_FWI2_CAPABLE(ha)) {
635 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
636 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
639 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
640 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
641 sn % 100000);
644 static ssize_t
645 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
646 char *buf)
648 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
649 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
652 static ssize_t
653 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
654 char *buf)
656 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
657 struct qla_hw_data *ha = vha->hw;
658 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
659 ha->product_id[0], ha->product_id[1], ha->product_id[2],
660 ha->product_id[3]);
663 static ssize_t
664 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
665 char *buf)
667 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
668 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
671 static ssize_t
672 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
673 char *buf)
675 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
676 return snprintf(buf, PAGE_SIZE, "%s\n",
677 vha->hw->model_desc ? vha->hw->model_desc : "");
680 static ssize_t
681 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
682 char *buf)
684 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
685 char pci_info[30];
687 return snprintf(buf, PAGE_SIZE, "%s\n",
688 vha->hw->isp_ops->pci_info_str(vha, pci_info));
691 static ssize_t
692 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
693 char *buf)
695 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
696 struct qla_hw_data *ha = vha->hw;
697 int len = 0;
699 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
700 atomic_read(&vha->loop_state) == LOOP_DEAD)
701 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
702 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
703 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
704 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
705 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
706 else {
707 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
709 switch (ha->current_topology) {
710 case ISP_CFG_NL:
711 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
712 break;
713 case ISP_CFG_FL:
714 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
715 break;
716 case ISP_CFG_N:
717 len += snprintf(buf + len, PAGE_SIZE-len,
718 "N_Port to N_Port\n");
719 break;
720 case ISP_CFG_F:
721 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
722 break;
723 default:
724 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
725 break;
728 return len;
731 static ssize_t
732 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
733 char *buf)
735 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
736 int len = 0;
738 switch (vha->hw->zio_mode) {
739 case QLA_ZIO_MODE_6:
740 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
741 break;
742 case QLA_ZIO_DISABLED:
743 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
744 break;
746 return len;
749 static ssize_t
750 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
751 const char *buf, size_t count)
753 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
754 struct qla_hw_data *ha = vha->hw;
755 int val = 0;
756 uint16_t zio_mode;
758 if (!IS_ZIO_SUPPORTED(ha))
759 return -ENOTSUPP;
761 if (sscanf(buf, "%d", &val) != 1)
762 return -EINVAL;
764 if (val)
765 zio_mode = QLA_ZIO_MODE_6;
766 else
767 zio_mode = QLA_ZIO_DISABLED;
769 /* Update per-hba values and queue a reset. */
770 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
771 ha->zio_mode = zio_mode;
772 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
774 return strlen(buf);
777 static ssize_t
778 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
779 char *buf)
781 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
783 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
786 static ssize_t
787 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
788 const char *buf, size_t count)
790 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
791 int val = 0;
792 uint16_t zio_timer;
794 if (sscanf(buf, "%d", &val) != 1)
795 return -EINVAL;
796 if (val > 25500 || val < 100)
797 return -ERANGE;
799 zio_timer = (uint16_t)(val / 100);
800 vha->hw->zio_timer = zio_timer;
802 return strlen(buf);
805 static ssize_t
806 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
807 char *buf)
809 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
810 int len = 0;
812 if (vha->hw->beacon_blink_led)
813 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
814 else
815 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
816 return len;
819 static ssize_t
820 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
821 const char *buf, size_t count)
823 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
824 struct qla_hw_data *ha = vha->hw;
825 int val = 0;
826 int rval;
828 if (IS_QLA2100(ha) || IS_QLA2200(ha))
829 return -EPERM;
831 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
832 qla_printk(KERN_WARNING, ha,
833 "Abort ISP active -- ignoring beacon request.\n");
834 return -EBUSY;
837 if (sscanf(buf, "%d", &val) != 1)
838 return -EINVAL;
840 if (val)
841 rval = ha->isp_ops->beacon_on(vha);
842 else
843 rval = ha->isp_ops->beacon_off(vha);
845 if (rval != QLA_SUCCESS)
846 count = 0;
848 return count;
851 static ssize_t
852 qla2x00_optrom_bios_version_show(struct device *dev,
853 struct device_attribute *attr, char *buf)
855 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
856 struct qla_hw_data *ha = vha->hw;
857 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
858 ha->bios_revision[0]);
861 static ssize_t
862 qla2x00_optrom_efi_version_show(struct device *dev,
863 struct device_attribute *attr, char *buf)
865 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
866 struct qla_hw_data *ha = vha->hw;
867 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
868 ha->efi_revision[0]);
871 static ssize_t
872 qla2x00_optrom_fcode_version_show(struct device *dev,
873 struct device_attribute *attr, char *buf)
875 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
876 struct qla_hw_data *ha = vha->hw;
877 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
878 ha->fcode_revision[0]);
881 static ssize_t
882 qla2x00_optrom_fw_version_show(struct device *dev,
883 struct device_attribute *attr, char *buf)
885 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
886 struct qla_hw_data *ha = vha->hw;
887 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
888 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
889 ha->fw_revision[3]);
892 static ssize_t
893 qla2x00_total_isp_aborts_show(struct device *dev,
894 struct device_attribute *attr, char *buf)
896 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
897 struct qla_hw_data *ha = vha->hw;
898 return snprintf(buf, PAGE_SIZE, "%d\n",
899 ha->qla_stats.total_isp_aborts);
902 static ssize_t
903 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
904 char *buf)
906 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
907 struct qla_hw_data *ha = vha->hw;
909 if (!IS_QLA81XX(ha))
910 return snprintf(buf, PAGE_SIZE, "\n");
912 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
913 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
914 ha->mpi_capabilities);
917 static ssize_t
918 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
919 char *buf)
921 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
922 struct qla_hw_data *ha = vha->hw;
924 if (!IS_QLA81XX(ha))
925 return snprintf(buf, PAGE_SIZE, "\n");
927 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
928 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
931 static ssize_t
932 qla2x00_flash_block_size_show(struct device *dev,
933 struct device_attribute *attr, char *buf)
935 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
936 struct qla_hw_data *ha = vha->hw;
938 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
941 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
942 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
943 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
944 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
945 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
946 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
947 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
948 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
949 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
950 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
951 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
952 qla2x00_zio_timer_store);
953 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
954 qla2x00_beacon_store);
955 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
956 qla2x00_optrom_bios_version_show, NULL);
957 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
958 qla2x00_optrom_efi_version_show, NULL);
959 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
960 qla2x00_optrom_fcode_version_show, NULL);
961 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
962 NULL);
963 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
964 NULL);
965 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
966 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
967 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
968 NULL);
970 struct device_attribute *qla2x00_host_attrs[] = {
971 &dev_attr_driver_version,
972 &dev_attr_fw_version,
973 &dev_attr_serial_num,
974 &dev_attr_isp_name,
975 &dev_attr_isp_id,
976 &dev_attr_model_name,
977 &dev_attr_model_desc,
978 &dev_attr_pci_info,
979 &dev_attr_link_state,
980 &dev_attr_zio,
981 &dev_attr_zio_timer,
982 &dev_attr_beacon,
983 &dev_attr_optrom_bios_version,
984 &dev_attr_optrom_efi_version,
985 &dev_attr_optrom_fcode_version,
986 &dev_attr_optrom_fw_version,
987 &dev_attr_total_isp_aborts,
988 &dev_attr_mpi_version,
989 &dev_attr_phy_version,
990 &dev_attr_flash_block_size,
991 NULL,
994 /* Host attributes. */
996 static void
997 qla2x00_get_host_port_id(struct Scsi_Host *shost)
999 scsi_qla_host_t *vha = shost_priv(shost);
1001 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1002 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
1005 static void
1006 qla2x00_get_host_speed(struct Scsi_Host *shost)
1008 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1009 (shost_priv(shost)))->hw;
1010 u32 speed = FC_PORTSPEED_UNKNOWN;
1012 switch (ha->link_data_rate) {
1013 case PORT_SPEED_1GB:
1014 speed = FC_PORTSPEED_1GBIT;
1015 break;
1016 case PORT_SPEED_2GB:
1017 speed = FC_PORTSPEED_2GBIT;
1018 break;
1019 case PORT_SPEED_4GB:
1020 speed = FC_PORTSPEED_4GBIT;
1021 break;
1022 case PORT_SPEED_8GB:
1023 speed = FC_PORTSPEED_8GBIT;
1024 break;
1025 case PORT_SPEED_10GB:
1026 speed = FC_PORTSPEED_10GBIT;
1027 break;
1029 fc_host_speed(shost) = speed;
1032 static void
1033 qla2x00_get_host_port_type(struct Scsi_Host *shost)
1035 scsi_qla_host_t *vha = shost_priv(shost);
1036 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1038 if (vha->vp_idx) {
1039 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1040 return;
1042 switch (vha->hw->current_topology) {
1043 case ISP_CFG_NL:
1044 port_type = FC_PORTTYPE_LPORT;
1045 break;
1046 case ISP_CFG_FL:
1047 port_type = FC_PORTTYPE_NLPORT;
1048 break;
1049 case ISP_CFG_N:
1050 port_type = FC_PORTTYPE_PTP;
1051 break;
1052 case ISP_CFG_F:
1053 port_type = FC_PORTTYPE_NPORT;
1054 break;
1056 fc_host_port_type(shost) = port_type;
1059 static void
1060 qla2x00_get_starget_node_name(struct scsi_target *starget)
1062 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1063 scsi_qla_host_t *vha = shost_priv(host);
1064 fc_port_t *fcport;
1065 u64 node_name = 0;
1067 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1068 if (fcport->rport &&
1069 starget->id == fcport->rport->scsi_target_id) {
1070 node_name = wwn_to_u64(fcport->node_name);
1071 break;
1075 fc_starget_node_name(starget) = node_name;
1078 static void
1079 qla2x00_get_starget_port_name(struct scsi_target *starget)
1081 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1082 scsi_qla_host_t *vha = shost_priv(host);
1083 fc_port_t *fcport;
1084 u64 port_name = 0;
1086 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1087 if (fcport->rport &&
1088 starget->id == fcport->rport->scsi_target_id) {
1089 port_name = wwn_to_u64(fcport->port_name);
1090 break;
1094 fc_starget_port_name(starget) = port_name;
1097 static void
1098 qla2x00_get_starget_port_id(struct scsi_target *starget)
1100 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1101 scsi_qla_host_t *vha = shost_priv(host);
1102 fc_port_t *fcport;
1103 uint32_t port_id = ~0U;
1105 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1106 if (fcport->rport &&
1107 starget->id == fcport->rport->scsi_target_id) {
1108 port_id = fcport->d_id.b.domain << 16 |
1109 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1110 break;
1114 fc_starget_port_id(starget) = port_id;
1117 static void
1118 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1120 if (timeout)
1121 rport->dev_loss_tmo = timeout;
1122 else
1123 rport->dev_loss_tmo = 1;
1126 static void
1127 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1129 struct Scsi_Host *host = rport_to_shost(rport);
1130 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1132 if (!fcport)
1133 return;
1135 qla2x00_abort_fcport_cmds(fcport);
1138 * Transport has effectively 'deleted' the rport, clear
1139 * all local references.
1141 spin_lock_irq(host->host_lock);
1142 fcport->rport = NULL;
1143 *((fc_port_t **)rport->dd_data) = NULL;
1144 spin_unlock_irq(host->host_lock);
1147 static void
1148 qla2x00_terminate_rport_io(struct fc_rport *rport)
1150 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1152 if (!fcport)
1153 return;
1156 * At this point all fcport's software-states are cleared. Perform any
1157 * final cleanup of firmware resources (PCBs and XCBs).
1159 if (fcport->loop_id != FC_NO_LOOP_ID)
1160 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1161 fcport->loop_id, fcport->d_id.b.domain,
1162 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1164 qla2x00_abort_fcport_cmds(fcport);
1167 static int
1168 qla2x00_issue_lip(struct Scsi_Host *shost)
1170 scsi_qla_host_t *vha = shost_priv(shost);
1172 qla2x00_loop_reset(vha);
1173 return 0;
1176 static struct fc_host_statistics *
1177 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1179 scsi_qla_host_t *vha = shost_priv(shost);
1180 struct qla_hw_data *ha = vha->hw;
1181 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1182 int rval;
1183 struct link_statistics *stats;
1184 dma_addr_t stats_dma;
1185 struct fc_host_statistics *pfc_host_stat;
1187 pfc_host_stat = &ha->fc_host_stat;
1188 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1190 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1191 if (stats == NULL) {
1192 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1193 __func__, base_vha->host_no));
1194 goto done;
1196 memset(stats, 0, DMA_POOL_SIZE);
1198 rval = QLA_FUNCTION_FAILED;
1199 if (IS_FWI2_CAPABLE(ha)) {
1200 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1201 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1202 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1203 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1204 !ha->dpc_active) {
1205 /* Must be in a 'READY' state for statistics retrieval. */
1206 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1207 stats, stats_dma);
1210 if (rval != QLA_SUCCESS)
1211 goto done_free;
1213 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1214 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1215 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1216 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1217 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1218 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1219 if (IS_FWI2_CAPABLE(ha)) {
1220 pfc_host_stat->lip_count = stats->lip_cnt;
1221 pfc_host_stat->tx_frames = stats->tx_frames;
1222 pfc_host_stat->rx_frames = stats->rx_frames;
1223 pfc_host_stat->dumped_frames = stats->dumped_frames;
1224 pfc_host_stat->nos_count = stats->nos_rcvd;
1226 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1227 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
1229 done_free:
1230 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1231 done:
1232 return pfc_host_stat;
1235 static void
1236 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1238 scsi_qla_host_t *vha = shost_priv(shost);
1240 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
1243 static void
1244 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1246 scsi_qla_host_t *vha = shost_priv(shost);
1248 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1251 static void
1252 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1254 scsi_qla_host_t *vha = shost_priv(shost);
1255 u64 node_name;
1257 if (vha->device_flags & SWITCH_FOUND)
1258 node_name = wwn_to_u64(vha->fabric_node_name);
1259 else
1260 node_name = wwn_to_u64(vha->node_name);
1262 fc_host_fabric_name(shost) = node_name;
1265 static void
1266 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1268 scsi_qla_host_t *vha = shost_priv(shost);
1269 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
1271 if (!base_vha->flags.online)
1272 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1273 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
1274 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1275 else
1276 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1279 static int
1280 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1282 int ret = 0;
1283 int cnt = 0;
1284 uint8_t qos = QLA_DEFAULT_QUE_QOS;
1285 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1286 scsi_qla_host_t *vha = NULL;
1287 struct qla_hw_data *ha = base_vha->hw;
1289 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1290 if (ret) {
1291 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1292 "status %x\n", ret));
1293 return (ret);
1296 vha = qla24xx_create_vhost(fc_vport);
1297 if (vha == NULL) {
1298 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1299 vha));
1300 return FC_VPORT_FAILED;
1302 if (disable) {
1303 atomic_set(&vha->vp_state, VP_OFFLINE);
1304 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1305 } else
1306 atomic_set(&vha->vp_state, VP_FAILED);
1308 /* ready to create vport */
1309 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1310 vha->vp_idx);
1312 /* initialized vport states */
1313 atomic_set(&vha->loop_state, LOOP_DOWN);
1314 vha->vp_err_state= VP_ERR_PORTDWN;
1315 vha->vp_prev_err_state= VP_ERR_UNKWN;
1316 /* Check if physical ha port is Up */
1317 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1318 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1319 /* Don't retry or attempt login of this virtual port */
1320 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1321 base_vha->host_no));
1322 atomic_set(&vha->loop_state, LOOP_DEAD);
1323 if (!disable)
1324 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1327 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1328 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1329 vha->host_no, vha->vp_idx));
1330 goto vport_create_failed_2;
1333 /* initialize attributes */
1334 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1335 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1336 fc_host_supported_classes(vha->host) =
1337 fc_host_supported_classes(base_vha->host);
1338 fc_host_supported_speeds(vha->host) =
1339 fc_host_supported_speeds(base_vha->host);
1341 qla24xx_vport_disable(fc_vport, disable);
1343 /* Create a queue pair for the vport */
1344 if (ha->mqenable) {
1345 if (ha->npiv_info) {
1346 for (; cnt < ha->nvram_npiv_size; cnt++) {
1347 if (ha->npiv_info[cnt].port_name ==
1348 vha->port_name &&
1349 ha->npiv_info[cnt].node_name ==
1350 vha->node_name) {
1351 qos = ha->npiv_info[cnt].q_qos;
1352 break;
1356 qla25xx_create_queues(vha, qos);
1359 return 0;
1360 vport_create_failed_2:
1361 qla24xx_disable_vp(vha);
1362 qla24xx_deallocate_vp_id(vha);
1363 scsi_host_put(vha->host);
1364 return FC_VPORT_FAILED;
1367 static int
1368 qla24xx_vport_delete(struct fc_vport *fc_vport)
1370 scsi_qla_host_t *vha = fc_vport->dd_data;
1371 fc_port_t *fcport, *tfcport;
1372 struct qla_hw_data *ha = vha->hw;
1373 uint16_t id = vha->vp_idx;
1375 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1376 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
1377 msleep(1000);
1379 qla24xx_disable_vp(vha);
1381 fc_remove_host(vha->host);
1383 scsi_remove_host(vha->host);
1385 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1386 list_del(&fcport->list);
1387 kfree(fcport);
1388 fcport = NULL;
1391 qla24xx_deallocate_vp_id(vha);
1393 if (vha->timer_active) {
1394 qla2x00_vp_stop_timer(vha);
1395 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1396 "has stopped\n",
1397 vha->host_no, vha->vp_idx, vha));
1400 if (ha->mqenable) {
1401 if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
1402 qla_printk(KERN_WARNING, ha,
1403 "Queue delete failed.\n");
1406 scsi_host_put(vha->host);
1407 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
1408 return 0;
1411 static int
1412 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1414 scsi_qla_host_t *vha = fc_vport->dd_data;
1416 if (disable)
1417 qla24xx_disable_vp(vha);
1418 else
1419 qla24xx_enable_vp(vha);
1421 return 0;
1424 struct fc_function_template qla2xxx_transport_functions = {
1426 .show_host_node_name = 1,
1427 .show_host_port_name = 1,
1428 .show_host_supported_classes = 1,
1429 .show_host_supported_speeds = 1,
1431 .get_host_port_id = qla2x00_get_host_port_id,
1432 .show_host_port_id = 1,
1433 .get_host_speed = qla2x00_get_host_speed,
1434 .show_host_speed = 1,
1435 .get_host_port_type = qla2x00_get_host_port_type,
1436 .show_host_port_type = 1,
1437 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1438 .show_host_symbolic_name = 1,
1439 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1440 .show_host_system_hostname = 1,
1441 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1442 .show_host_fabric_name = 1,
1443 .get_host_port_state = qla2x00_get_host_port_state,
1444 .show_host_port_state = 1,
1446 .dd_fcrport_size = sizeof(struct fc_port *),
1447 .show_rport_supported_classes = 1,
1449 .get_starget_node_name = qla2x00_get_starget_node_name,
1450 .show_starget_node_name = 1,
1451 .get_starget_port_name = qla2x00_get_starget_port_name,
1452 .show_starget_port_name = 1,
1453 .get_starget_port_id = qla2x00_get_starget_port_id,
1454 .show_starget_port_id = 1,
1456 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1457 .show_rport_dev_loss_tmo = 1,
1459 .issue_fc_host_lip = qla2x00_issue_lip,
1460 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1461 .terminate_rport_io = qla2x00_terminate_rport_io,
1462 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1464 .vport_create = qla24xx_vport_create,
1465 .vport_disable = qla24xx_vport_disable,
1466 .vport_delete = qla24xx_vport_delete,
1469 struct fc_function_template qla2xxx_transport_vport_functions = {
1471 .show_host_node_name = 1,
1472 .show_host_port_name = 1,
1473 .show_host_supported_classes = 1,
1475 .get_host_port_id = qla2x00_get_host_port_id,
1476 .show_host_port_id = 1,
1477 .get_host_speed = qla2x00_get_host_speed,
1478 .show_host_speed = 1,
1479 .get_host_port_type = qla2x00_get_host_port_type,
1480 .show_host_port_type = 1,
1481 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1482 .show_host_symbolic_name = 1,
1483 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1484 .show_host_system_hostname = 1,
1485 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1486 .show_host_fabric_name = 1,
1487 .get_host_port_state = qla2x00_get_host_port_state,
1488 .show_host_port_state = 1,
1490 .dd_fcrport_size = sizeof(struct fc_port *),
1491 .show_rport_supported_classes = 1,
1493 .get_starget_node_name = qla2x00_get_starget_node_name,
1494 .show_starget_node_name = 1,
1495 .get_starget_port_name = qla2x00_get_starget_port_name,
1496 .show_starget_port_name = 1,
1497 .get_starget_port_id = qla2x00_get_starget_port_id,
1498 .show_starget_port_id = 1,
1500 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1501 .show_rport_dev_loss_tmo = 1,
1503 .issue_fc_host_lip = qla2x00_issue_lip,
1504 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1505 .terminate_rport_io = qla2x00_terminate_rport_io,
1506 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1509 void
1510 qla2x00_init_host_attr(scsi_qla_host_t *vha)
1512 struct qla_hw_data *ha = vha->hw;
1513 u32 speed = FC_PORTSPEED_UNKNOWN;
1515 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1516 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1517 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1518 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1519 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
1521 if (IS_QLA81XX(ha))
1522 speed = FC_PORTSPEED_10GBIT;
1523 else if (IS_QLA25XX(ha))
1524 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1525 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1526 else if (IS_QLA24XX_TYPE(ha))
1527 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1528 FC_PORTSPEED_1GBIT;
1529 else if (IS_QLA23XX(ha))
1530 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1531 else
1532 speed = FC_PORTSPEED_1GBIT;
1533 fc_host_supported_speeds(vha->host) = speed;