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