[SCSI] qla2xxx: use memory_read_from_buffer()
[safe/jmp/linux-2.6] / drivers / scsi / qla2xxx / qla_attr.c
1 /*
2  * QLogic Fibre Channel HBA Driver
3  * Copyright (c)  2003-2008 QLogic Corporation
4  *
5  * See LICENSE.qla2xxx for copyright and licensing details.
6  */
7 #include "qla_def.h"
8
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11
12 static int qla24xx_vport_disable(struct fc_vport *, bool);
13
14 /* SYSFS attributes --------------------------------------------------------- */
15
16 static ssize_t
17 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
18                            struct bin_attribute *bin_attr,
19                            char *buf, loff_t off, size_t count)
20 {
21         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
22             struct device, kobj)));
23
24         if (ha->fw_dump_reading == 0)
25                 return 0;
26
27         return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
28                                         ha->fw_dump_len);
29 }
30
31 static ssize_t
32 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
33                             struct bin_attribute *bin_attr,
34                             char *buf, loff_t off, size_t count)
35 {
36         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
37             struct device, kobj)));
38         int reading;
39
40         if (off != 0)
41                 return (0);
42
43         reading = simple_strtol(buf, NULL, 10);
44         switch (reading) {
45         case 0:
46                 if (!ha->fw_dump_reading)
47                         break;
48
49                 qla_printk(KERN_INFO, ha,
50                     "Firmware dump cleared on (%ld).\n", ha->host_no);
51
52                 ha->fw_dump_reading = 0;
53                 ha->fw_dumped = 0;
54                 break;
55         case 1:
56                 if (ha->fw_dumped && !ha->fw_dump_reading) {
57                         ha->fw_dump_reading = 1;
58
59                         qla_printk(KERN_INFO, ha,
60                             "Raw firmware dump ready for read on (%ld).\n",
61                             ha->host_no);
62                 }
63                 break;
64         case 2:
65                 qla2x00_alloc_fw_dump(ha);
66                 break;
67         case 3:
68                 qla2x00_system_error(ha);
69                 break;
70         }
71         return (count);
72 }
73
74 static struct bin_attribute sysfs_fw_dump_attr = {
75         .attr = {
76                 .name = "fw_dump",
77                 .mode = S_IRUSR | S_IWUSR,
78         },
79         .size = 0,
80         .read = qla2x00_sysfs_read_fw_dump,
81         .write = qla2x00_sysfs_write_fw_dump,
82 };
83
84 static ssize_t
85 qla2x00_sysfs_read_nvram(struct kobject *kobj,
86                          struct bin_attribute *bin_attr,
87                          char *buf, loff_t off, size_t count)
88 {
89         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
90             struct device, kobj)));
91
92         if (!capable(CAP_SYS_ADMIN))
93                 return 0;
94
95         /* Read NVRAM data from cache. */
96         return memory_read_from_buffer(buf, count, &off, ha->nvram,
97                                         ha->nvram_size);
98 }
99
100 static ssize_t
101 qla2x00_sysfs_write_nvram(struct kobject *kobj,
102                           struct bin_attribute *bin_attr,
103                           char *buf, loff_t off, size_t count)
104 {
105         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
106             struct device, kobj)));
107         uint16_t        cnt;
108
109         if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
110                 return 0;
111
112         /* Checksum NVRAM. */
113         if (IS_FWI2_CAPABLE(ha)) {
114                 uint32_t *iter;
115                 uint32_t chksum;
116
117                 iter = (uint32_t *)buf;
118                 chksum = 0;
119                 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
120                         chksum += le32_to_cpu(*iter++);
121                 chksum = ~chksum + 1;
122                 *iter = cpu_to_le32(chksum);
123         } else {
124                 uint8_t *iter;
125                 uint8_t chksum;
126
127                 iter = (uint8_t *)buf;
128                 chksum = 0;
129                 for (cnt = 0; cnt < count - 1; cnt++)
130                         chksum += *iter++;
131                 chksum = ~chksum + 1;
132                 *iter = chksum;
133         }
134
135         /* Write NVRAM. */
136         ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
137         ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
138             count);
139
140         set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
141
142         return (count);
143 }
144
145 static struct bin_attribute sysfs_nvram_attr = {
146         .attr = {
147                 .name = "nvram",
148                 .mode = S_IRUSR | S_IWUSR,
149         },
150         .size = 512,
151         .read = qla2x00_sysfs_read_nvram,
152         .write = qla2x00_sysfs_write_nvram,
153 };
154
155 static ssize_t
156 qla2x00_sysfs_read_optrom(struct kobject *kobj,
157                           struct bin_attribute *bin_attr,
158                           char *buf, loff_t off, size_t count)
159 {
160         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
161             struct device, kobj)));
162
163         if (ha->optrom_state != QLA_SREADING)
164                 return 0;
165
166         return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
167                                         ha->optrom_region_size);
168 }
169
170 static ssize_t
171 qla2x00_sysfs_write_optrom(struct kobject *kobj,
172                            struct bin_attribute *bin_attr,
173                            char *buf, loff_t off, size_t count)
174 {
175         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
176             struct device, kobj)));
177
178         if (ha->optrom_state != QLA_SWRITING)
179                 return -EINVAL;
180         if (off > ha->optrom_region_size)
181                 return -ERANGE;
182         if (off + count > ha->optrom_region_size)
183                 count = ha->optrom_region_size - off;
184
185         memcpy(&ha->optrom_buffer[off], buf, count);
186
187         return count;
188 }
189
190 static struct bin_attribute sysfs_optrom_attr = {
191         .attr = {
192                 .name = "optrom",
193                 .mode = S_IRUSR | S_IWUSR,
194         },
195         .size = 0,
196         .read = qla2x00_sysfs_read_optrom,
197         .write = qla2x00_sysfs_write_optrom,
198 };
199
200 static ssize_t
201 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
202                                struct bin_attribute *bin_attr,
203                                char *buf, loff_t off, size_t count)
204 {
205         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
206             struct device, kobj)));
207         uint32_t start = 0;
208         uint32_t size = ha->optrom_size;
209         int val, valid;
210
211         if (off)
212                 return 0;
213
214         if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
215                 return -EINVAL;
216         if (start > ha->optrom_size)
217                 return -EINVAL;
218
219         switch (val) {
220         case 0:
221                 if (ha->optrom_state != QLA_SREADING &&
222                     ha->optrom_state != QLA_SWRITING)
223                         break;
224
225                 ha->optrom_state = QLA_SWAITING;
226
227                 DEBUG2(qla_printk(KERN_INFO, ha,
228                     "Freeing flash region allocation -- 0x%x bytes.\n",
229                     ha->optrom_region_size));
230
231                 vfree(ha->optrom_buffer);
232                 ha->optrom_buffer = NULL;
233                 break;
234         case 1:
235                 if (ha->optrom_state != QLA_SWAITING)
236                         break;
237
238                 if (start & 0xfff) {
239                         qla_printk(KERN_WARNING, ha,
240                             "Invalid start region 0x%x/0x%x.\n", start, size);
241                         return -EINVAL;
242                 }
243
244                 ha->optrom_region_start = start;
245                 ha->optrom_region_size = start + size > ha->optrom_size ?
246                     ha->optrom_size - start : size;
247
248                 ha->optrom_state = QLA_SREADING;
249                 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
250                 if (ha->optrom_buffer == NULL) {
251                         qla_printk(KERN_WARNING, ha,
252                             "Unable to allocate memory for optrom retrieval "
253                             "(%x).\n", ha->optrom_region_size);
254
255                         ha->optrom_state = QLA_SWAITING;
256                         return count;
257                 }
258
259                 DEBUG2(qla_printk(KERN_INFO, ha,
260                     "Reading flash region -- 0x%x/0x%x.\n",
261                     ha->optrom_region_start, ha->optrom_region_size));
262
263                 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
264                 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
265                     ha->optrom_region_start, ha->optrom_region_size);
266                 break;
267         case 2:
268                 if (ha->optrom_state != QLA_SWAITING)
269                         break;
270
271                 /*
272                  * We need to be more restrictive on which FLASH regions are
273                  * allowed to be updated via user-space.  Regions accessible
274                  * via this method include:
275                  *
276                  * ISP21xx/ISP22xx/ISP23xx type boards:
277                  *
278                  *      0x000000 -> 0x020000 -- Boot code.
279                  *
280                  * ISP2322/ISP24xx type boards:
281                  *
282                  *      0x000000 -> 0x07ffff -- Boot code.
283                  *      0x080000 -> 0x0fffff -- Firmware.
284                  *
285                  * ISP25xx type boards:
286                  *
287                  *      0x000000 -> 0x07ffff -- Boot code.
288                  *      0x080000 -> 0x0fffff -- Firmware.
289                  *      0x120000 -> 0x12ffff -- VPD and HBA parameters.
290                  */
291                 valid = 0;
292                 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
293                         valid = 1;
294                 else if (start == (FA_BOOT_CODE_ADDR*4) ||
295                     start == (FA_RISC_CODE_ADDR*4))
296                         valid = 1;
297                 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
298                     valid = 1;
299                 if (!valid) {
300                         qla_printk(KERN_WARNING, ha,
301                             "Invalid start region 0x%x/0x%x.\n", start, size);
302                         return -EINVAL;
303                 }
304
305                 ha->optrom_region_start = start;
306                 ha->optrom_region_size = start + size > ha->optrom_size ?
307                     ha->optrom_size - start : size;
308
309                 ha->optrom_state = QLA_SWRITING;
310                 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
311                 if (ha->optrom_buffer == NULL) {
312                         qla_printk(KERN_WARNING, ha,
313                             "Unable to allocate memory for optrom update "
314                             "(%x).\n", ha->optrom_region_size);
315
316                         ha->optrom_state = QLA_SWAITING;
317                         return count;
318                 }
319
320                 DEBUG2(qla_printk(KERN_INFO, ha,
321                     "Staging flash region write -- 0x%x/0x%x.\n",
322                     ha->optrom_region_start, ha->optrom_region_size));
323
324                 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
325                 break;
326         case 3:
327                 if (ha->optrom_state != QLA_SWRITING)
328                         break;
329
330                 DEBUG2(qla_printk(KERN_INFO, ha,
331                     "Writing flash region -- 0x%x/0x%x.\n",
332                     ha->optrom_region_start, ha->optrom_region_size));
333
334                 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
335                     ha->optrom_region_start, ha->optrom_region_size);
336                 break;
337         default:
338                 count = -EINVAL;
339         }
340         return count;
341 }
342
343 static struct bin_attribute sysfs_optrom_ctl_attr = {
344         .attr = {
345                 .name = "optrom_ctl",
346                 .mode = S_IWUSR,
347         },
348         .size = 0,
349         .write = qla2x00_sysfs_write_optrom_ctl,
350 };
351
352 static ssize_t
353 qla2x00_sysfs_read_vpd(struct kobject *kobj,
354                        struct bin_attribute *bin_attr,
355                        char *buf, loff_t off, size_t count)
356 {
357         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
358             struct device, kobj)));
359
360         if (!capable(CAP_SYS_ADMIN))
361                 return 0;
362
363         /* Read NVRAM data from cache. */
364         return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
365 }
366
367 static ssize_t
368 qla2x00_sysfs_write_vpd(struct kobject *kobj,
369                         struct bin_attribute *bin_attr,
370                         char *buf, loff_t off, size_t count)
371 {
372         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
373             struct device, kobj)));
374
375         if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
376                 return 0;
377
378         /* Write NVRAM. */
379         ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
380         ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
381
382         return count;
383 }
384
385 static struct bin_attribute sysfs_vpd_attr = {
386         .attr = {
387                 .name = "vpd",
388                 .mode = S_IRUSR | S_IWUSR,
389         },
390         .size = 0,
391         .read = qla2x00_sysfs_read_vpd,
392         .write = qla2x00_sysfs_write_vpd,
393 };
394
395 static ssize_t
396 qla2x00_sysfs_read_sfp(struct kobject *kobj,
397                        struct bin_attribute *bin_attr,
398                        char *buf, loff_t off, size_t count)
399 {
400         struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
401             struct device, kobj)));
402         uint16_t iter, addr, offset;
403         int rval;
404
405         if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
406                 return 0;
407
408         if (ha->sfp_data)
409                 goto do_read;
410
411         ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
412             &ha->sfp_data_dma);
413         if (!ha->sfp_data) {
414                 qla_printk(KERN_WARNING, ha,
415                     "Unable to allocate memory for SFP read-data.\n");
416                 return 0;
417         }
418
419 do_read:
420         memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
421         addr = 0xa0;
422         for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
423             iter++, offset += SFP_BLOCK_SIZE) {
424                 if (iter == 4) {
425                         /* Skip to next device address. */
426                         addr = 0xa2;
427                         offset = 0;
428                 }
429
430                 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
431                     SFP_BLOCK_SIZE);
432                 if (rval != QLA_SUCCESS) {
433                         qla_printk(KERN_WARNING, ha,
434                             "Unable to read SFP data (%x/%x/%x).\n", rval,
435                             addr, offset);
436                         count = 0;
437                         break;
438                 }
439                 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
440                 buf += SFP_BLOCK_SIZE;
441         }
442
443         return count;
444 }
445
446 static struct bin_attribute sysfs_sfp_attr = {
447         .attr = {
448                 .name = "sfp",
449                 .mode = S_IRUSR | S_IWUSR,
450         },
451         .size = SFP_DEV_SIZE * 2,
452         .read = qla2x00_sysfs_read_sfp,
453 };
454
455 static struct sysfs_entry {
456         char *name;
457         struct bin_attribute *attr;
458         int is4GBp_only;
459 } bin_file_entries[] = {
460         { "fw_dump", &sysfs_fw_dump_attr, },
461         { "nvram", &sysfs_nvram_attr, },
462         { "optrom", &sysfs_optrom_attr, },
463         { "optrom_ctl", &sysfs_optrom_ctl_attr, },
464         { "vpd", &sysfs_vpd_attr, 1 },
465         { "sfp", &sysfs_sfp_attr, 1 },
466         { NULL },
467 };
468
469 void
470 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
471 {
472         struct Scsi_Host *host = ha->host;
473         struct sysfs_entry *iter;
474         int ret;
475
476         for (iter = bin_file_entries; iter->name; iter++) {
477                 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
478                         continue;
479
480                 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
481                     iter->attr);
482                 if (ret)
483                         qla_printk(KERN_INFO, ha,
484                             "Unable to create sysfs %s binary attribute "
485                             "(%d).\n", iter->name, ret);
486         }
487 }
488
489 void
490 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
491 {
492         struct Scsi_Host *host = ha->host;
493         struct sysfs_entry *iter;
494
495         for (iter = bin_file_entries; iter->name; iter++) {
496                 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
497                         continue;
498
499                 sysfs_remove_bin_file(&host->shost_gendev.kobj,
500                     iter->attr);
501         }
502
503         if (ha->beacon_blink_led == 1)
504                 ha->isp_ops->beacon_off(ha);
505 }
506
507 /* Scsi_Host attributes. */
508
509 static ssize_t
510 qla2x00_drvr_version_show(struct device *dev,
511                           struct device_attribute *attr, char *buf)
512 {
513         return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
514 }
515
516 static ssize_t
517 qla2x00_fw_version_show(struct device *dev,
518                         struct device_attribute *attr, char *buf)
519 {
520         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
521         char fw_str[30];
522
523         return snprintf(buf, PAGE_SIZE, "%s\n",
524             ha->isp_ops->fw_version_str(ha, fw_str));
525 }
526
527 static ssize_t
528 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
529                         char *buf)
530 {
531         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
532         uint32_t sn;
533
534         if (IS_FWI2_CAPABLE(ha)) {
535                 qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
536                 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
537         }
538
539         sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
540         return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
541             sn % 100000);
542 }
543
544 static ssize_t
545 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
546                       char *buf)
547 {
548         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
549         return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
550 }
551
552 static ssize_t
553 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
554                     char *buf)
555 {
556         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
557         return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
558             ha->product_id[0], ha->product_id[1], ha->product_id[2],
559             ha->product_id[3]);
560 }
561
562 static ssize_t
563 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
564                         char *buf)
565 {
566         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
567         return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
568 }
569
570 static ssize_t
571 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
572                         char *buf)
573 {
574         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
575         return snprintf(buf, PAGE_SIZE, "%s\n",
576             ha->model_desc ? ha->model_desc: "");
577 }
578
579 static ssize_t
580 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
581                       char *buf)
582 {
583         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
584         char pci_info[30];
585
586         return snprintf(buf, PAGE_SIZE, "%s\n",
587             ha->isp_ops->pci_info_str(ha, pci_info));
588 }
589
590 static ssize_t
591 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
592                         char *buf)
593 {
594         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
595         int len = 0;
596
597         if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
598             atomic_read(&ha->loop_state) == LOOP_DEAD)
599                 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
600         else if (atomic_read(&ha->loop_state) != LOOP_READY ||
601             test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
602             test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
603                 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
604         else {
605                 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
606
607                 switch (ha->current_topology) {
608                 case ISP_CFG_NL:
609                         len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
610                         break;
611                 case ISP_CFG_FL:
612                         len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
613                         break;
614                 case ISP_CFG_N:
615                         len += snprintf(buf + len, PAGE_SIZE-len,
616                             "N_Port to N_Port\n");
617                         break;
618                 case ISP_CFG_F:
619                         len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
620                         break;
621                 default:
622                         len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
623                         break;
624                 }
625         }
626         return len;
627 }
628
629 static ssize_t
630 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
631                  char *buf)
632 {
633         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
634         int len = 0;
635
636         switch (ha->zio_mode) {
637         case QLA_ZIO_MODE_6:
638                 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
639                 break;
640         case QLA_ZIO_DISABLED:
641                 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
642                 break;
643         }
644         return len;
645 }
646
647 static ssize_t
648 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
649                   const char *buf, size_t count)
650 {
651         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
652         int val = 0;
653         uint16_t zio_mode;
654
655         if (!IS_ZIO_SUPPORTED(ha))
656                 return -ENOTSUPP;
657
658         if (sscanf(buf, "%d", &val) != 1)
659                 return -EINVAL;
660
661         if (val)
662                 zio_mode = QLA_ZIO_MODE_6;
663         else
664                 zio_mode = QLA_ZIO_DISABLED;
665
666         /* Update per-hba values and queue a reset. */
667         if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
668                 ha->zio_mode = zio_mode;
669                 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
670         }
671         return strlen(buf);
672 }
673
674 static ssize_t
675 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
676                        char *buf)
677 {
678         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
679
680         return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
681 }
682
683 static ssize_t
684 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
685                         const char *buf, size_t count)
686 {
687         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
688         int val = 0;
689         uint16_t zio_timer;
690
691         if (sscanf(buf, "%d", &val) != 1)
692                 return -EINVAL;
693         if (val > 25500 || val < 100)
694                 return -ERANGE;
695
696         zio_timer = (uint16_t)(val / 100);
697         ha->zio_timer = zio_timer;
698
699         return strlen(buf);
700 }
701
702 static ssize_t
703 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
704                     char *buf)
705 {
706         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
707         int len = 0;
708
709         if (ha->beacon_blink_led)
710                 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
711         else
712                 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
713         return len;
714 }
715
716 static ssize_t
717 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
718                      const char *buf, size_t count)
719 {
720         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
721         int val = 0;
722         int rval;
723
724         if (IS_QLA2100(ha) || IS_QLA2200(ha))
725                 return -EPERM;
726
727         if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
728                 qla_printk(KERN_WARNING, ha,
729                     "Abort ISP active -- ignoring beacon request.\n");
730                 return -EBUSY;
731         }
732
733         if (sscanf(buf, "%d", &val) != 1)
734                 return -EINVAL;
735
736         if (val)
737                 rval = ha->isp_ops->beacon_on(ha);
738         else
739                 rval = ha->isp_ops->beacon_off(ha);
740
741         if (rval != QLA_SUCCESS)
742                 count = 0;
743
744         return count;
745 }
746
747 static ssize_t
748 qla2x00_optrom_bios_version_show(struct device *dev,
749                                  struct device_attribute *attr, char *buf)
750 {
751         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
752
753         return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
754             ha->bios_revision[0]);
755 }
756
757 static ssize_t
758 qla2x00_optrom_efi_version_show(struct device *dev,
759                                 struct device_attribute *attr, char *buf)
760 {
761         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
762
763         return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
764             ha->efi_revision[0]);
765 }
766
767 static ssize_t
768 qla2x00_optrom_fcode_version_show(struct device *dev,
769                                   struct device_attribute *attr, char *buf)
770 {
771         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
772
773         return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
774             ha->fcode_revision[0]);
775 }
776
777 static ssize_t
778 qla2x00_optrom_fw_version_show(struct device *dev,
779                                struct device_attribute *attr, char *buf)
780 {
781         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
782
783         return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
784             ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
785             ha->fw_revision[3]);
786 }
787
788 static ssize_t
789 qla2x00_total_isp_aborts_show(struct device *dev,
790                               struct device_attribute *attr, char *buf)
791 {
792         scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
793
794         return snprintf(buf, PAGE_SIZE, "%d\n",
795             ha->qla_stats.total_isp_aborts);
796 }
797
798 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
799 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
800 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
801 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
802 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
803 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
804 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
805 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
806 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
807 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
808 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
809                    qla2x00_zio_timer_store);
810 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
811                    qla2x00_beacon_store);
812 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
813                    qla2x00_optrom_bios_version_show, NULL);
814 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
815                    qla2x00_optrom_efi_version_show, NULL);
816 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
817                    qla2x00_optrom_fcode_version_show, NULL);
818 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
819                    NULL);
820 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
821                    NULL);
822
823 struct device_attribute *qla2x00_host_attrs[] = {
824         &dev_attr_driver_version,
825         &dev_attr_fw_version,
826         &dev_attr_serial_num,
827         &dev_attr_isp_name,
828         &dev_attr_isp_id,
829         &dev_attr_model_name,
830         &dev_attr_model_desc,
831         &dev_attr_pci_info,
832         &dev_attr_link_state,
833         &dev_attr_zio,
834         &dev_attr_zio_timer,
835         &dev_attr_beacon,
836         &dev_attr_optrom_bios_version,
837         &dev_attr_optrom_efi_version,
838         &dev_attr_optrom_fcode_version,
839         &dev_attr_optrom_fw_version,
840         &dev_attr_total_isp_aborts,
841         NULL,
842 };
843
844 /* Host attributes. */
845
846 static void
847 qla2x00_get_host_port_id(struct Scsi_Host *shost)
848 {
849         scsi_qla_host_t *ha = shost_priv(shost);
850
851         fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
852             ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
853 }
854
855 static void
856 qla2x00_get_host_speed(struct Scsi_Host *shost)
857 {
858         scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
859         u32 speed = FC_PORTSPEED_UNKNOWN;
860
861         switch (ha->link_data_rate) {
862         case PORT_SPEED_1GB:
863                 speed = FC_PORTSPEED_1GBIT;
864                 break;
865         case PORT_SPEED_2GB:
866                 speed = FC_PORTSPEED_2GBIT;
867                 break;
868         case PORT_SPEED_4GB:
869                 speed = FC_PORTSPEED_4GBIT;
870                 break;
871         case PORT_SPEED_8GB:
872                 speed = FC_PORTSPEED_8GBIT;
873                 break;
874         }
875         fc_host_speed(shost) = speed;
876 }
877
878 static void
879 qla2x00_get_host_port_type(struct Scsi_Host *shost)
880 {
881         scsi_qla_host_t *ha = shost_priv(shost);
882         uint32_t port_type = FC_PORTTYPE_UNKNOWN;
883
884         if (ha->parent) {
885                 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
886                 return;
887         }
888         switch (ha->current_topology) {
889         case ISP_CFG_NL:
890                 port_type = FC_PORTTYPE_LPORT;
891                 break;
892         case ISP_CFG_FL:
893                 port_type = FC_PORTTYPE_NLPORT;
894                 break;
895         case ISP_CFG_N:
896                 port_type = FC_PORTTYPE_PTP;
897                 break;
898         case ISP_CFG_F:
899                 port_type = FC_PORTTYPE_NPORT;
900                 break;
901         }
902         fc_host_port_type(shost) = port_type;
903 }
904
905 static void
906 qla2x00_get_starget_node_name(struct scsi_target *starget)
907 {
908         struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
909         scsi_qla_host_t *ha = shost_priv(host);
910         fc_port_t *fcport;
911         u64 node_name = 0;
912
913         list_for_each_entry(fcport, &ha->fcports, list) {
914                 if (fcport->rport &&
915                     starget->id == fcport->rport->scsi_target_id) {
916                         node_name = wwn_to_u64(fcport->node_name);
917                         break;
918                 }
919         }
920
921         fc_starget_node_name(starget) = node_name;
922 }
923
924 static void
925 qla2x00_get_starget_port_name(struct scsi_target *starget)
926 {
927         struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
928         scsi_qla_host_t *ha = shost_priv(host);
929         fc_port_t *fcport;
930         u64 port_name = 0;
931
932         list_for_each_entry(fcport, &ha->fcports, list) {
933                 if (fcport->rport &&
934                     starget->id == fcport->rport->scsi_target_id) {
935                         port_name = wwn_to_u64(fcport->port_name);
936                         break;
937                 }
938         }
939
940         fc_starget_port_name(starget) = port_name;
941 }
942
943 static void
944 qla2x00_get_starget_port_id(struct scsi_target *starget)
945 {
946         struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
947         scsi_qla_host_t *ha = shost_priv(host);
948         fc_port_t *fcport;
949         uint32_t port_id = ~0U;
950
951         list_for_each_entry(fcport, &ha->fcports, list) {
952                 if (fcport->rport &&
953                     starget->id == fcport->rport->scsi_target_id) {
954                         port_id = fcport->d_id.b.domain << 16 |
955                             fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
956                         break;
957                 }
958         }
959
960         fc_starget_port_id(starget) = port_id;
961 }
962
963 static void
964 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
965 {
966         if (timeout)
967                 rport->dev_loss_tmo = timeout;
968         else
969                 rport->dev_loss_tmo = 1;
970 }
971
972 static void
973 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
974 {
975         struct Scsi_Host *host = rport_to_shost(rport);
976         fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
977
978         qla2x00_abort_fcport_cmds(fcport);
979
980         /*
981          * Transport has effectively 'deleted' the rport, clear
982          * all local references.
983          */
984         spin_lock_irq(host->host_lock);
985         fcport->rport = NULL;
986         *((fc_port_t **)rport->dd_data) = NULL;
987         spin_unlock_irq(host->host_lock);
988 }
989
990 static void
991 qla2x00_terminate_rport_io(struct fc_rport *rport)
992 {
993         fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
994
995         qla2x00_abort_fcport_cmds(fcport);
996         scsi_target_unblock(&rport->dev);
997 }
998
999 static int
1000 qla2x00_issue_lip(struct Scsi_Host *shost)
1001 {
1002         scsi_qla_host_t *ha = shost_priv(shost);
1003
1004         qla2x00_loop_reset(ha);
1005         return 0;
1006 }
1007
1008 static struct fc_host_statistics *
1009 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1010 {
1011         scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1012         int rval;
1013         struct link_statistics *stats;
1014         dma_addr_t stats_dma;
1015         struct fc_host_statistics *pfc_host_stat;
1016
1017         pfc_host_stat = &ha->fc_host_stat;
1018         memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1019
1020         stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1021         if (stats == NULL) {
1022                 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1023                     __func__, ha->host_no));
1024                 goto done;
1025         }
1026         memset(stats, 0, DMA_POOL_SIZE);
1027
1028         rval = QLA_FUNCTION_FAILED;
1029         if (IS_FWI2_CAPABLE(ha)) {
1030                 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
1031         } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1032                     !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1033                     !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1034                     !ha->dpc_active) {
1035                 /* Must be in a 'READY' state for statistics retrieval. */
1036                 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1037                     stats_dma);
1038         }
1039
1040         if (rval != QLA_SUCCESS)
1041                 goto done_free;
1042
1043         pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1044         pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1045         pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1046         pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1047         pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1048         pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1049         if (IS_FWI2_CAPABLE(ha)) {
1050                 pfc_host_stat->lip_count = stats->lip_cnt;
1051                 pfc_host_stat->tx_frames = stats->tx_frames;
1052                 pfc_host_stat->rx_frames = stats->rx_frames;
1053                 pfc_host_stat->dumped_frames = stats->dumped_frames;
1054                 pfc_host_stat->nos_count = stats->nos_rcvd;
1055         }
1056
1057 done_free:
1058         dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1059 done:
1060         return pfc_host_stat;
1061 }
1062
1063 static void
1064 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1065 {
1066         scsi_qla_host_t *ha = shost_priv(shost);
1067
1068         qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1069 }
1070
1071 static void
1072 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1073 {
1074         scsi_qla_host_t *ha = shost_priv(shost);
1075
1076         set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1077 }
1078
1079 static void
1080 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1081 {
1082         scsi_qla_host_t *ha = shost_priv(shost);
1083         u64 node_name;
1084
1085         if (ha->device_flags & SWITCH_FOUND)
1086                 node_name = wwn_to_u64(ha->fabric_node_name);
1087         else
1088                 node_name = wwn_to_u64(ha->node_name);
1089
1090         fc_host_fabric_name(shost) = node_name;
1091 }
1092
1093 static void
1094 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1095 {
1096         scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1097
1098         if (!ha->flags.online)
1099                 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1100         else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1101                 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1102         else
1103                 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1104 }
1105
1106 static int
1107 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1108 {
1109         int     ret = 0;
1110         scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1111         scsi_qla_host_t *vha;
1112
1113         ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1114         if (ret) {
1115                 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1116                     "status %x\n", ret));
1117                 return (ret);
1118         }
1119
1120         vha = qla24xx_create_vhost(fc_vport);
1121         if (vha == NULL) {
1122                 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1123                     vha));
1124                 return FC_VPORT_FAILED;
1125         }
1126         if (disable) {
1127                 atomic_set(&vha->vp_state, VP_OFFLINE);
1128                 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1129         } else
1130                 atomic_set(&vha->vp_state, VP_FAILED);
1131
1132         /* ready to create vport */
1133         qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1134
1135         /* initialized vport states */
1136         atomic_set(&vha->loop_state, LOOP_DOWN);
1137         vha->vp_err_state=  VP_ERR_PORTDWN;
1138         vha->vp_prev_err_state=  VP_ERR_UNKWN;
1139         /* Check if physical ha port is Up */
1140         if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1141             atomic_read(&ha->loop_state) == LOOP_DEAD) {
1142                 /* Don't retry or attempt login of this virtual port */
1143                 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1144                     vha->host_no));
1145                 atomic_set(&vha->loop_state, LOOP_DEAD);
1146                 if (!disable)
1147                         fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1148         }
1149
1150         if (scsi_add_host(vha->host, &fc_vport->dev)) {
1151                 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1152                         vha->host_no, vha->vp_idx));
1153                 goto vport_create_failed_2;
1154         }
1155
1156         /* initialize attributes */
1157         fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1158         fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1159         fc_host_supported_classes(vha->host) =
1160                 fc_host_supported_classes(ha->host);
1161         fc_host_supported_speeds(vha->host) =
1162                 fc_host_supported_speeds(ha->host);
1163
1164         qla24xx_vport_disable(fc_vport, disable);
1165
1166         return 0;
1167 vport_create_failed_2:
1168         qla24xx_disable_vp(vha);
1169         qla24xx_deallocate_vp_id(vha);
1170         kfree(vha->port_name);
1171         kfree(vha->node_name);
1172         scsi_host_put(vha->host);
1173         return FC_VPORT_FAILED;
1174 }
1175
1176 static int
1177 qla24xx_vport_delete(struct fc_vport *fc_vport)
1178 {
1179         scsi_qla_host_t *vha = fc_vport->dd_data;
1180
1181         qla24xx_disable_vp(vha);
1182         qla24xx_deallocate_vp_id(vha);
1183
1184         kfree(vha->node_name);
1185         kfree(vha->port_name);
1186
1187         if (vha->timer_active) {
1188                 qla2x00_vp_stop_timer(vha);
1189                 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1190                     "has stopped\n",
1191                     vha->host_no, vha->vp_idx, vha));
1192         }
1193
1194         fc_remove_host(vha->host);
1195
1196         scsi_remove_host(vha->host);
1197
1198         scsi_host_put(vha->host);
1199
1200         return 0;
1201 }
1202
1203 static int
1204 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1205 {
1206         scsi_qla_host_t *vha = fc_vport->dd_data;
1207
1208         if (disable)
1209                 qla24xx_disable_vp(vha);
1210         else
1211                 qla24xx_enable_vp(vha);
1212
1213         return 0;
1214 }
1215
1216 struct fc_function_template qla2xxx_transport_functions = {
1217
1218         .show_host_node_name = 1,
1219         .show_host_port_name = 1,
1220         .show_host_supported_classes = 1,
1221         .show_host_supported_speeds = 1,
1222
1223         .get_host_port_id = qla2x00_get_host_port_id,
1224         .show_host_port_id = 1,
1225         .get_host_speed = qla2x00_get_host_speed,
1226         .show_host_speed = 1,
1227         .get_host_port_type = qla2x00_get_host_port_type,
1228         .show_host_port_type = 1,
1229         .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1230         .show_host_symbolic_name = 1,
1231         .set_host_system_hostname = qla2x00_set_host_system_hostname,
1232         .show_host_system_hostname = 1,
1233         .get_host_fabric_name = qla2x00_get_host_fabric_name,
1234         .show_host_fabric_name = 1,
1235         .get_host_port_state = qla2x00_get_host_port_state,
1236         .show_host_port_state = 1,
1237
1238         .dd_fcrport_size = sizeof(struct fc_port *),
1239         .show_rport_supported_classes = 1,
1240
1241         .get_starget_node_name = qla2x00_get_starget_node_name,
1242         .show_starget_node_name = 1,
1243         .get_starget_port_name = qla2x00_get_starget_port_name,
1244         .show_starget_port_name = 1,
1245         .get_starget_port_id  = qla2x00_get_starget_port_id,
1246         .show_starget_port_id = 1,
1247
1248         .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1249         .show_rport_dev_loss_tmo = 1,
1250
1251         .issue_fc_host_lip = qla2x00_issue_lip,
1252         .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1253         .terminate_rport_io = qla2x00_terminate_rport_io,
1254         .get_fc_host_stats = qla2x00_get_fc_host_stats,
1255
1256         .vport_create = qla24xx_vport_create,
1257         .vport_disable = qla24xx_vport_disable,
1258         .vport_delete = qla24xx_vport_delete,
1259 };
1260
1261 struct fc_function_template qla2xxx_transport_vport_functions = {
1262
1263         .show_host_node_name = 1,
1264         .show_host_port_name = 1,
1265         .show_host_supported_classes = 1,
1266
1267         .get_host_port_id = qla2x00_get_host_port_id,
1268         .show_host_port_id = 1,
1269         .get_host_speed = qla2x00_get_host_speed,
1270         .show_host_speed = 1,
1271         .get_host_port_type = qla2x00_get_host_port_type,
1272         .show_host_port_type = 1,
1273         .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1274         .show_host_symbolic_name = 1,
1275         .set_host_system_hostname = qla2x00_set_host_system_hostname,
1276         .show_host_system_hostname = 1,
1277         .get_host_fabric_name = qla2x00_get_host_fabric_name,
1278         .show_host_fabric_name = 1,
1279         .get_host_port_state = qla2x00_get_host_port_state,
1280         .show_host_port_state = 1,
1281
1282         .dd_fcrport_size = sizeof(struct fc_port *),
1283         .show_rport_supported_classes = 1,
1284
1285         .get_starget_node_name = qla2x00_get_starget_node_name,
1286         .show_starget_node_name = 1,
1287         .get_starget_port_name = qla2x00_get_starget_port_name,
1288         .show_starget_port_name = 1,
1289         .get_starget_port_id  = qla2x00_get_starget_port_id,
1290         .show_starget_port_id = 1,
1291
1292         .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1293         .show_rport_dev_loss_tmo = 1,
1294
1295         .issue_fc_host_lip = qla2x00_issue_lip,
1296         .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1297         .terminate_rport_io = qla2x00_terminate_rport_io,
1298         .get_fc_host_stats = qla2x00_get_fc_host_stats,
1299 };
1300
1301 void
1302 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1303 {
1304         u32 speed = FC_PORTSPEED_UNKNOWN;
1305
1306         fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1307         fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1308         fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1309         fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
1310         fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
1311
1312         if (IS_QLA25XX(ha))
1313                 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1314                     FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1315         else if (IS_QLA24XX_TYPE(ha))
1316                 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1317                     FC_PORTSPEED_1GBIT;
1318         else if (IS_QLA23XX(ha))
1319                 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1320         else
1321                 speed = FC_PORTSPEED_1GBIT;
1322         fc_host_supported_speeds(ha->host) = speed;
1323 }