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