[SCSI] qla2xxx: Correct locking during NVRAM manipulation.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / qla2xxx / qla_attr.c
CommitLineData
8482e118 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
01e58d8e 3 * Copyright (c) 2003-2008 QLogic Corporation
8482e118 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
8482e118
AV
6 */
7#include "qla_def.h"
8
2c3dfe3f 9#include <linux/kthread.h>
7aaef27b 10#include <linux/vmalloc.h>
8482e118 11
a824ebb3 12static int qla24xx_vport_disable(struct fc_vport *, bool);
2c3dfe3f 13
8482e118
AV
14/* SYSFS attributes --------------------------------------------------------- */
15
16static ssize_t
91a69029
ZR
17qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
18 struct bin_attribute *bin_attr,
19 char *buf, loff_t off, size_t count)
8482e118 20{
f363b943 21 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 22 struct device, kobj)));
a7a167bf 23 char *rbuf = (char *)ha->fw_dump;
8482e118
AV
24
25 if (ha->fw_dump_reading == 0)
26 return 0;
a7a167bf
AV
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;
8482e118 31
a7a167bf 32 memcpy(buf, &rbuf[off], count);
8482e118
AV
33
34 return (count);
35}
36
37static ssize_t
91a69029
ZR
38qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
39 struct bin_attribute *bin_attr,
40 char *buf, loff_t off, size_t count)
8482e118 41{
f363b943 42 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e118
AV
43 struct device, kobj)));
44 int reading;
8482e118
AV
45
46 if (off != 0)
47 return (0);
48
49 reading = simple_strtol(buf, NULL, 10);
50 switch (reading) {
51 case 0:
a7a167bf
AV
52 if (!ha->fw_dump_reading)
53 break;
8482e118 54
a7a167bf
AV
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;
8482e118
AV
60 break;
61 case 1:
d4e3e04d 62 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e118
AV
63 ha->fw_dump_reading = 1;
64
8482e118 65 qla_printk(KERN_INFO, ha,
a7a167bf 66 "Raw firmware dump ready for read on (%ld).\n",
8482e118 67 ha->host_no);
8482e118
AV
68 }
69 break;
a7a167bf
AV
70 case 2:
71 qla2x00_alloc_fw_dump(ha);
72 break;
68af0811
AV
73 case 3:
74 qla2x00_system_error(ha);
75 break;
8482e118
AV
76 }
77 return (count);
78}
79
80static struct bin_attribute sysfs_fw_dump_attr = {
81 .attr = {
82 .name = "fw_dump",
83 .mode = S_IRUSR | S_IWUSR,
8482e118
AV
84 },
85 .size = 0,
86 .read = qla2x00_sysfs_read_fw_dump,
87 .write = qla2x00_sysfs_write_fw_dump,
88};
89
90static ssize_t
91a69029
ZR
91qla2x00_sysfs_read_nvram(struct kobject *kobj,
92 struct bin_attribute *bin_attr,
93 char *buf, loff_t off, size_t count)
8482e118 94{
f363b943 95 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 96 struct device, kobj)));
281afe19
SJ
97 int size = ha->nvram_size;
98 char *nvram_cache = ha->nvram;
8482e118 99
281afe19 100 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
8482e118 101 return 0;
281afe19
SJ
102 if (off + count > size) {
103 size -= off;
104 count = size;
105 }
8482e118 106
281afe19
SJ
107 /* Read NVRAM data from cache. */
108 memcpy(buf, &nvram_cache[off], count);
8482e118 109
281afe19 110 return count;
8482e118
AV
111}
112
113static ssize_t
91a69029
ZR
114qla2x00_sysfs_write_nvram(struct kobject *kobj,
115 struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
8482e118 117{
f363b943 118 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e118 119 struct device, kobj)));
8482e118 120 uint16_t cnt;
8482e118 121
459c5378 122 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e118
AV
123 return 0;
124
125 /* Checksum NVRAM. */
e428924c 126 if (IS_FWI2_CAPABLE(ha)) {
459c5378
AV
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 }
8482e118
AV
147
148 /* Write NVRAM. */
fd34f556 149 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
c45bcc8e 150 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
281afe19 151 count);
8482e118 152
26b8d348
AV
153 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
154
8482e118
AV
155 return (count);
156}
157
158static struct bin_attribute sysfs_nvram_attr = {
159 .attr = {
160 .name = "nvram",
161 .mode = S_IRUSR | S_IWUSR,
8482e118 162 },
1b3f6365 163 .size = 512,
8482e118
AV
164 .read = qla2x00_sysfs_read_nvram,
165 .write = qla2x00_sysfs_write_nvram,
166};
167
854165f4 168static ssize_t
91a69029
ZR
169qla2x00_sysfs_read_optrom(struct kobject *kobj,
170 struct bin_attribute *bin_attr,
171 char *buf, loff_t off, size_t count)
854165f4 172{
f363b943 173 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
854165f4
AV
174 struct device, kobj)));
175
176 if (ha->optrom_state != QLA_SREADING)
177 return 0;
b7cc176c 178 if (off > ha->optrom_region_size)
854165f4 179 return 0;
b7cc176c
JC
180 if (off + count > ha->optrom_region_size)
181 count = ha->optrom_region_size - off;
854165f4
AV
182
183 memcpy(buf, &ha->optrom_buffer[off], count);
184
185 return count;
186}
187
188static ssize_t
91a69029
ZR
189qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
854165f4 192{
f363b943 193 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
854165f4
AV
194 struct device, kobj)));
195
196 if (ha->optrom_state != QLA_SWRITING)
197 return -EINVAL;
b7cc176c 198 if (off > ha->optrom_region_size)
854165f4 199 return -ERANGE;
b7cc176c
JC
200 if (off + count > ha->optrom_region_size)
201 count = ha->optrom_region_size - off;
854165f4
AV
202
203 memcpy(&ha->optrom_buffer[off], buf, count);
204
205 return count;
206}
207
208static struct bin_attribute sysfs_optrom_attr = {
209 .attr = {
210 .name = "optrom",
211 .mode = S_IRUSR | S_IWUSR,
854165f4 212 },
c3a2f0df 213 .size = 0,
854165f4
AV
214 .read = qla2x00_sysfs_read_optrom,
215 .write = qla2x00_sysfs_write_optrom,
216};
217
218static ssize_t
91a69029
ZR
219qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
220 struct bin_attribute *bin_attr,
221 char *buf, loff_t off, size_t count)
854165f4 222{
f363b943 223 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
854165f4 224 struct device, kobj)));
b7cc176c
JC
225 uint32_t start = 0;
226 uint32_t size = ha->optrom_size;
227 int val, valid;
854165f4
AV
228
229 if (off)
230 return 0;
231
b7cc176c
JC
232 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
233 return -EINVAL;
234 if (start > ha->optrom_size)
854165f4
AV
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;
b7cc176c
JC
244
245 DEBUG2(qla_printk(KERN_INFO, ha,
246 "Freeing flash region allocation -- 0x%x bytes.\n",
247 ha->optrom_region_size));
248
854165f4
AV
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
b7cc176c
JC
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
854165f4 266 ha->optrom_state = QLA_SREADING;
b7cc176c 267 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4
AV
268 if (ha->optrom_buffer == NULL) {
269 qla_printk(KERN_WARNING, ha,
270 "Unable to allocate memory for optrom retrieval "
b7cc176c 271 "(%x).\n", ha->optrom_region_size);
854165f4
AV
272
273 ha->optrom_state = QLA_SWAITING;
274 return count;
275 }
276
b7cc176c
JC
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);
854165f4
AV
284 break;
285 case 2:
286 if (ha->optrom_state != QLA_SWAITING)
287 break;
288
b7cc176c
JC
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
854165f4 327 ha->optrom_state = QLA_SWRITING;
b7cc176c 328 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
854165f4
AV
329 if (ha->optrom_buffer == NULL) {
330 qla_printk(KERN_WARNING, ha,
331 "Unable to allocate memory for optrom update "
b7cc176c 332 "(%x).\n", ha->optrom_region_size);
854165f4
AV
333
334 ha->optrom_state = QLA_SWAITING;
335 return count;
336 }
b7cc176c
JC
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);
854165f4
AV
343 break;
344 case 3:
345 if (ha->optrom_state != QLA_SWRITING)
346 break;
347
b7cc176c
JC
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);
854165f4 354 break;
b7cc176c
JC
355 default:
356 count = -EINVAL;
854165f4
AV
357 }
358 return count;
359}
360
361static struct bin_attribute sysfs_optrom_ctl_attr = {
362 .attr = {
363 .name = "optrom_ctl",
364 .mode = S_IWUSR,
854165f4
AV
365 },
366 .size = 0,
367 .write = qla2x00_sysfs_write_optrom_ctl,
368};
369
6f641790 370static ssize_t
91a69029
ZR
371qla2x00_sysfs_read_vpd(struct kobject *kobj,
372 struct bin_attribute *bin_attr,
373 char *buf, loff_t off, size_t count)
6f641790 374{
f363b943 375 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 376 struct device, kobj)));
281afe19
SJ
377 int size = ha->vpd_size;
378 char *vpd_cache = ha->vpd;
6f641790 379
281afe19 380 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
6f641790 381 return 0;
281afe19
SJ
382 if (off + count > size) {
383 size -= off;
384 count = size;
385 }
6f641790 386
281afe19
SJ
387 /* Read NVRAM data from cache. */
388 memcpy(buf, &vpd_cache[off], count);
6f641790 389
281afe19 390 return count;
6f641790
AV
391}
392
393static ssize_t
91a69029
ZR
394qla2x00_sysfs_write_vpd(struct kobject *kobj,
395 struct bin_attribute *bin_attr,
396 char *buf, loff_t off, size_t count)
6f641790 397{
f363b943 398 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
6f641790 399 struct device, kobj)));
6f641790
AV
400
401 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
402 return 0;
403
6f641790 404 /* Write NVRAM. */
fd34f556 405 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
281afe19 406 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
6f641790
AV
407
408 return count;
409}
410
411static struct bin_attribute sysfs_vpd_attr = {
412 .attr = {
413 .name = "vpd",
414 .mode = S_IRUSR | S_IWUSR,
6f641790
AV
415 },
416 .size = 0,
417 .read = qla2x00_sysfs_read_vpd,
418 .write = qla2x00_sysfs_write_vpd,
419};
420
88729e53 421static ssize_t
91a69029
ZR
422qla2x00_sysfs_read_sfp(struct kobject *kobj,
423 struct bin_attribute *bin_attr,
424 char *buf, loff_t off, size_t count)
88729e53 425{
f363b943 426 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
88729e53
AV
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
e8711085
AV
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
445do_read:
446 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
88729e53
AV
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
472static struct bin_attribute sysfs_sfp_attr = {
473 .attr = {
474 .name = "sfp",
475 .mode = S_IRUSR | S_IWUSR,
88729e53
AV
476 },
477 .size = SFP_DEV_SIZE * 2,
478 .read = qla2x00_sysfs_read_sfp,
479};
480
f1663ad5
AV
481static 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 },
46ddab7b 492 { NULL },
f1663ad5
AV
493};
494
8482e118
AV
495void
496qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
497{
498 struct Scsi_Host *host = ha->host;
f1663ad5
AV
499 struct sysfs_entry *iter;
500 int ret;
8482e118 501
f1663ad5 502 for (iter = bin_file_entries; iter->name; iter++) {
e428924c 503 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
f1663ad5
AV
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);
7914d004 512 }
8482e118
AV
513}
514
515void
516qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
517{
518 struct Scsi_Host *host = ha->host;
f1663ad5
AV
519 struct sysfs_entry *iter;
520
521 for (iter = bin_file_entries; iter->name; iter++) {
e428924c 522 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
f1663ad5 523 continue;
8482e118 524
88729e53 525 sysfs_remove_bin_file(&host->shost_gendev.kobj,
f1663ad5 526 iter->attr);
7914d004 527 }
f6df144c
AV
528
529 if (ha->beacon_blink_led == 1)
fd34f556 530 ha->isp_ops->beacon_off(ha);
8482e118
AV
531}
532
afb046e2
AV
533/* Scsi_Host attributes. */
534
535static ssize_t
ee959b00
TJ
536qla2x00_drvr_version_show(struct device *dev,
537 struct device_attribute *attr, char *buf)
afb046e2
AV
538{
539 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
540}
541
542static ssize_t
ee959b00
TJ
543qla2x00_fw_version_show(struct device *dev,
544 struct device_attribute *attr, char *buf)
afb046e2 545{
ee959b00 546 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
547 char fw_str[30];
548
549 return snprintf(buf, PAGE_SIZE, "%s\n",
fd34f556 550 ha->isp_ops->fw_version_str(ha, fw_str));
afb046e2
AV
551}
552
553static ssize_t
ee959b00
TJ
554qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
555 char *buf)
afb046e2 556{
ee959b00 557 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
558 uint32_t sn;
559
8b7afc2a
AV
560 if (IS_FWI2_CAPABLE(ha))
561 return snprintf(buf, PAGE_SIZE, "\n");
562
afb046e2
AV
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
568static ssize_t
ee959b00
TJ
569qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
570 char *buf)
afb046e2 571{
ee959b00 572 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
5433383e 573 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
afb046e2
AV
574}
575
576static ssize_t
ee959b00
TJ
577qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
578 char *buf)
afb046e2 579{
ee959b00 580 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
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
586static ssize_t
ee959b00
TJ
587qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
588 char *buf)
afb046e2 589{
ee959b00 590 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
591 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
592}
593
594static ssize_t
ee959b00
TJ
595qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
596 char *buf)
afb046e2 597{
ee959b00 598 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
599 return snprintf(buf, PAGE_SIZE, "%s\n",
600 ha->model_desc ? ha->model_desc: "");
601}
602
603static ssize_t
ee959b00
TJ
604qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
605 char *buf)
afb046e2 606{
ee959b00 607 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
608 char pci_info[30];
609
610 return snprintf(buf, PAGE_SIZE, "%s\n",
fd34f556 611 ha->isp_ops->pci_info_str(ha, pci_info));
afb046e2
AV
612}
613
614static ssize_t
bbd1ae41
HR
615qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
616 char *buf)
afb046e2 617{
ee959b00 618 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
afb046e2
AV
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
4fdfefe5 653static ssize_t
ee959b00
TJ
654qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
655 char *buf)
4fdfefe5 656{
ee959b00 657 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
658 int len = 0;
659
660 switch (ha->zio_mode) {
4fdfefe5
AV
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
671static ssize_t
ee959b00
TJ
672qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
673 const char *buf, size_t count)
4fdfefe5 674{
ee959b00 675 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
676 int val = 0;
677 uint16_t zio_mode;
678
4a59f71d
AV
679 if (!IS_ZIO_SUPPORTED(ha))
680 return -ENOTSUPP;
681
4fdfefe5
AV
682 if (sscanf(buf, "%d", &val) != 1)
683 return -EINVAL;
684
4a59f71d 685 if (val)
4fdfefe5 686 zio_mode = QLA_ZIO_MODE_6;
4a59f71d 687 else
4fdfefe5 688 zio_mode = QLA_ZIO_DISABLED;
4fdfefe5
AV
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
698static ssize_t
ee959b00
TJ
699qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
700 char *buf)
4fdfefe5 701{
ee959b00 702 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
703
704 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
705}
706
707static ssize_t
ee959b00
TJ
708qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
709 const char *buf, size_t count)
4fdfefe5 710{
ee959b00 711 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
4fdfefe5
AV
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
f6df144c 726static ssize_t
ee959b00
TJ
727qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
728 char *buf)
f6df144c 729{
ee959b00 730 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
f6df144c
AV
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
740static ssize_t
ee959b00
TJ
741qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
742 const char *buf, size_t count)
f6df144c 743{
ee959b00 744 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
f6df144c
AV
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)
fd34f556 761 rval = ha->isp_ops->beacon_on(ha);
f6df144c 762 else
fd34f556 763 rval = ha->isp_ops->beacon_off(ha);
f6df144c
AV
764
765 if (rval != QLA_SUCCESS)
766 count = 0;
767
768 return count;
769}
770
30c47662 771static ssize_t
ee959b00
TJ
772qla2x00_optrom_bios_version_show(struct device *dev,
773 struct device_attribute *attr, char *buf)
30c47662 774{
ee959b00 775 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
30c47662
AV
776
777 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
778 ha->bios_revision[0]);
779}
780
781static ssize_t
ee959b00
TJ
782qla2x00_optrom_efi_version_show(struct device *dev,
783 struct device_attribute *attr, char *buf)
30c47662 784{
ee959b00 785 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
30c47662
AV
786
787 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
788 ha->efi_revision[0]);
789}
790
791static ssize_t
ee959b00
TJ
792qla2x00_optrom_fcode_version_show(struct device *dev,
793 struct device_attribute *attr, char *buf)
30c47662 794{
ee959b00 795 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
30c47662
AV
796
797 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
798 ha->fcode_revision[0]);
799}
800
801static ssize_t
ee959b00
TJ
802qla2x00_optrom_fw_version_show(struct device *dev,
803 struct device_attribute *attr, char *buf)
30c47662 804{
ee959b00 805 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
30c47662
AV
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
ee959b00
TJ
812static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
813static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
814static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
815static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
816static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
817static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
818static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
819static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
bbd1ae41 820static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
ee959b00
TJ
821static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
822static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
823 qla2x00_zio_timer_store);
824static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
825 qla2x00_beacon_store);
826static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
827 qla2x00_optrom_bios_version_show, NULL);
828static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
829 qla2x00_optrom_efi_version_show, NULL);
830static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
831 qla2x00_optrom_fcode_version_show, NULL);
832static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
833 NULL);
834
835struct device_attribute *qla2x00_host_attrs[] = {
836 &dev_attr_driver_version,
837 &dev_attr_fw_version,
838 &dev_attr_serial_num,
839 &dev_attr_isp_name,
840 &dev_attr_isp_id,
841 &dev_attr_model_name,
842 &dev_attr_model_desc,
843 &dev_attr_pci_info,
bbd1ae41 844 &dev_attr_link_state,
ee959b00
TJ
845 &dev_attr_zio,
846 &dev_attr_zio_timer,
847 &dev_attr_beacon,
848 &dev_attr_optrom_bios_version,
849 &dev_attr_optrom_efi_version,
850 &dev_attr_optrom_fcode_version,
851 &dev_attr_optrom_fw_version,
afb046e2
AV
852 NULL,
853};
854
8482e118
AV
855/* Host attributes. */
856
857static void
858qla2x00_get_host_port_id(struct Scsi_Host *shost)
859{
f363b943 860 scsi_qla_host_t *ha = shost_priv(shost);
8482e118
AV
861
862 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
863 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
864}
865
04414013
AV
866static void
867qla2x00_get_host_speed(struct Scsi_Host *shost)
868{
da4541b6 869 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
2ae2b370 870 u32 speed = FC_PORTSPEED_UNKNOWN;
04414013
AV
871
872 switch (ha->link_data_rate) {
d8b45213 873 case PORT_SPEED_1GB:
2ae2b370 874 speed = FC_PORTSPEED_1GBIT;
04414013 875 break;
d8b45213 876 case PORT_SPEED_2GB:
2ae2b370 877 speed = FC_PORTSPEED_2GBIT;
04414013 878 break;
d8b45213 879 case PORT_SPEED_4GB:
2ae2b370 880 speed = FC_PORTSPEED_4GBIT;
04414013 881 break;
da4541b6 882 case PORT_SPEED_8GB:
2ae2b370 883 speed = FC_PORTSPEED_8GBIT;
da4541b6 884 break;
04414013
AV
885 }
886 fc_host_speed(shost) = speed;
887}
888
8d067623
AV
889static void
890qla2x00_get_host_port_type(struct Scsi_Host *shost)
891{
2f2fa13d 892 scsi_qla_host_t *ha = shost_priv(shost);
8d067623
AV
893 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
894
2f2fa13d
SS
895 if (ha->parent) {
896 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
897 return;
898 }
8d067623
AV
899 switch (ha->current_topology) {
900 case ISP_CFG_NL:
901 port_type = FC_PORTTYPE_LPORT;
902 break;
903 case ISP_CFG_FL:
904 port_type = FC_PORTTYPE_NLPORT;
905 break;
906 case ISP_CFG_N:
907 port_type = FC_PORTTYPE_PTP;
908 break;
909 case ISP_CFG_F:
910 port_type = FC_PORTTYPE_NPORT;
911 break;
912 }
913 fc_host_port_type(shost) = port_type;
914}
915
8482e118
AV
916static void
917qla2x00_get_starget_node_name(struct scsi_target *starget)
918{
919 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
f363b943 920 scsi_qla_host_t *ha = shost_priv(host);
bdf79621 921 fc_port_t *fcport;
f8b02a85 922 u64 node_name = 0;
8482e118 923
bdf79621 924 list_for_each_entry(fcport, &ha->fcports, list) {
5ab5a4dd
AV
925 if (fcport->rport &&
926 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 927 node_name = wwn_to_u64(fcport->node_name);
bdf79621
AV
928 break;
929 }
930 }
931
f8b02a85 932 fc_starget_node_name(starget) = node_name;
8482e118
AV
933}
934
935static void
936qla2x00_get_starget_port_name(struct scsi_target *starget)
937{
938 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
f363b943 939 scsi_qla_host_t *ha = shost_priv(host);
bdf79621 940 fc_port_t *fcport;
f8b02a85 941 u64 port_name = 0;
8482e118 942
bdf79621 943 list_for_each_entry(fcport, &ha->fcports, list) {
5ab5a4dd
AV
944 if (fcport->rport &&
945 starget->id == fcport->rport->scsi_target_id) {
f8b02a85 946 port_name = wwn_to_u64(fcport->port_name);
bdf79621
AV
947 break;
948 }
949 }
950
f8b02a85 951 fc_starget_port_name(starget) = port_name;
8482e118
AV
952}
953
954static void
955qla2x00_get_starget_port_id(struct scsi_target *starget)
956{
957 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
f363b943 958 scsi_qla_host_t *ha = shost_priv(host);
bdf79621
AV
959 fc_port_t *fcport;
960 uint32_t port_id = ~0U;
961
962 list_for_each_entry(fcport, &ha->fcports, list) {
5ab5a4dd
AV
963 if (fcport->rport &&
964 starget->id == fcport->rport->scsi_target_id) {
bdf79621
AV
965 port_id = fcport->d_id.b.domain << 16 |
966 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
967 break;
968 }
969 }
8482e118 970
8482e118
AV
971 fc_starget_port_id(starget) = port_id;
972}
973
974static void
975qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
976{
bdf79621 977 struct Scsi_Host *host = rport_to_shost(rport);
f363b943 978 scsi_qla_host_t *ha = shost_priv(host);
8482e118
AV
979
980 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
981}
982
983static void
984qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
985{
bdf79621 986 struct Scsi_Host *host = rport_to_shost(rport);
f363b943 987 scsi_qla_host_t *ha = shost_priv(host);
8482e118
AV
988
989 if (timeout)
990 ha->port_down_retry_count = timeout;
991 else
992 ha->port_down_retry_count = 1;
993
994 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
995}
996
91ca7b01
AV
997static int
998qla2x00_issue_lip(struct Scsi_Host *shost)
999{
f363b943 1000 scsi_qla_host_t *ha = shost_priv(shost);
91ca7b01 1001
a4722cf2 1002 qla2x00_loop_reset(ha);
91ca7b01
AV
1003 return 0;
1004}
1005
392e2f65
AV
1006static struct fc_host_statistics *
1007qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1008{
da4541b6 1009 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
392e2f65 1010 int rval;
43ef0580
AV
1011 struct link_statistics *stats;
1012 dma_addr_t stats_dma;
392e2f65
AV
1013 struct fc_host_statistics *pfc_host_stat;
1014
1015 pfc_host_stat = &ha->fc_host_stat;
1016 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1017
43ef0580
AV
1018 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1019 if (stats == NULL) {
1020 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1021 __func__, ha->host_no));
1022 goto done;
1023 }
1024 memset(stats, 0, DMA_POOL_SIZE);
1025
1026 rval = QLA_FUNCTION_FAILED;
e428924c 1027 if (IS_FWI2_CAPABLE(ha)) {
43ef0580 1028 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
178779a6
AV
1029 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1030 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1031 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1032 !ha->dpc_active) {
1033 /* Must be in a 'READY' state for statistics retrieval. */
43ef0580
AV
1034 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1035 stats_dma);
392e2f65 1036 }
178779a6
AV
1037
1038 if (rval != QLA_SUCCESS)
43ef0580
AV
1039 goto done_free;
1040
1041 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1042 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1043 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1044 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1045 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1046 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1047 if (IS_FWI2_CAPABLE(ha)) {
1048 pfc_host_stat->tx_frames = stats->tx_frames;
1049 pfc_host_stat->rx_frames = stats->rx_frames;
1050 pfc_host_stat->dumped_frames = stats->dumped_frames;
1051 pfc_host_stat->nos_count = stats->nos_rcvd;
1052 }
392e2f65 1053
43ef0580
AV
1054done_free:
1055 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
178779a6 1056done:
392e2f65
AV
1057 return pfc_host_stat;
1058}
1059
1620f7c2
AV
1060static void
1061qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1062{
f363b943 1063 scsi_qla_host_t *ha = shost_priv(shost);
1620f7c2
AV
1064
1065 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1066}
1067
a740a3f0
AV
1068static void
1069qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1070{
f363b943 1071 scsi_qla_host_t *ha = shost_priv(shost);
a740a3f0
AV
1072
1073 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1074}
1075
90991c85
AV
1076static void
1077qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1078{
f363b943 1079 scsi_qla_host_t *ha = shost_priv(shost);
90991c85
AV
1080 u64 node_name;
1081
1082 if (ha->device_flags & SWITCH_FOUND)
1083 node_name = wwn_to_u64(ha->fabric_node_name);
1084 else
1085 node_name = wwn_to_u64(ha->node_name);
1086
1087 fc_host_fabric_name(shost) = node_name;
1088}
1089
7047fcdd
AV
1090static void
1091qla2x00_get_host_port_state(struct Scsi_Host *shost)
1092{
da4541b6 1093 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
7047fcdd
AV
1094
1095 if (!ha->flags.online)
1096 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1097 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1098 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1099 else
1100 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1101}
1102
2c3dfe3f
SJ
1103static int
1104qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1105{
1106 int ret = 0;
f363b943 1107 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
2c3dfe3f
SJ
1108 scsi_qla_host_t *vha;
1109
1110 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1111 if (ret) {
1112 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1113 "status %x\n", ret));
1114 return (ret);
1115 }
1116
1117 vha = qla24xx_create_vhost(fc_vport);
1118 if (vha == NULL) {
1119 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1120 vha));
1121 return FC_VPORT_FAILED;
1122 }
1123 if (disable) {
1124 atomic_set(&vha->vp_state, VP_OFFLINE);
1125 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1126 } else
1127 atomic_set(&vha->vp_state, VP_FAILED);
1128
1129 /* ready to create vport */
1130 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1131
1132 /* initialized vport states */
1133 atomic_set(&vha->loop_state, LOOP_DOWN);
1134 vha->vp_err_state= VP_ERR_PORTDWN;
1135 vha->vp_prev_err_state= VP_ERR_UNKWN;
1136 /* Check if physical ha port is Up */
1137 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1138 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1139 /* Don't retry or attempt login of this virtual port */
1140 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1141 vha->host_no));
1142 atomic_set(&vha->loop_state, LOOP_DEAD);
1143 if (!disable)
1144 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1145 }
1146
1147 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1148 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1149 vha->host_no, vha->vp_idx));
1150 goto vport_create_failed_2;
1151 }
1152
1153 /* initialize attributes */
1154 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1155 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1156 fc_host_supported_classes(vha->host) =
1157 fc_host_supported_classes(ha->host);
1158 fc_host_supported_speeds(vha->host) =
1159 fc_host_supported_speeds(ha->host);
1160
1161 qla24xx_vport_disable(fc_vport, disable);
1162
1163 return 0;
1164vport_create_failed_2:
1165 qla24xx_disable_vp(vha);
1166 qla24xx_deallocate_vp_id(vha);
1167 kfree(vha->port_name);
1168 kfree(vha->node_name);
1169 scsi_host_put(vha->host);
1170 return FC_VPORT_FAILED;
1171}
1172
a824ebb3 1173static int
2c3dfe3f
SJ
1174qla24xx_vport_delete(struct fc_vport *fc_vport)
1175{
f363b943 1176 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
2c3dfe3f
SJ
1177 scsi_qla_host_t *vha = fc_vport->dd_data;
1178
1179 qla24xx_disable_vp(vha);
1180 qla24xx_deallocate_vp_id(vha);
1181
6c2f527c 1182 mutex_lock(&ha->vport_lock);
2c3dfe3f 1183 ha->cur_vport_count--;
eb66dc60 1184 clear_bit(vha->vp_idx, ha->vp_idx_map);
6c2f527c 1185 mutex_unlock(&ha->vport_lock);
2c3dfe3f
SJ
1186
1187 kfree(vha->node_name);
1188 kfree(vha->port_name);
1189
1190 if (vha->timer_active) {
1191 qla2x00_vp_stop_timer(vha);
1192 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1193 "has stopped\n",
1194 vha->host_no, vha->vp_idx, vha));
1195 }
1196
1197 fc_remove_host(vha->host);
1198
1199 scsi_remove_host(vha->host);
1200
1201 scsi_host_put(vha->host);
1202
1203 return 0;
1204}
1205
a824ebb3 1206static int
2c3dfe3f
SJ
1207qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1208{
1209 scsi_qla_host_t *vha = fc_vport->dd_data;
1210
1211 if (disable)
1212 qla24xx_disable_vp(vha);
1213 else
1214 qla24xx_enable_vp(vha);
1215
1216 return 0;
1217}
1218
1c97a12a 1219struct fc_function_template qla2xxx_transport_functions = {
8482e118
AV
1220
1221 .show_host_node_name = 1,
1222 .show_host_port_name = 1,
ad3e0eda 1223 .show_host_supported_classes = 1,
2ae2b370 1224 .show_host_supported_speeds = 1,
ad3e0eda 1225
8482e118
AV
1226 .get_host_port_id = qla2x00_get_host_port_id,
1227 .show_host_port_id = 1,
04414013
AV
1228 .get_host_speed = qla2x00_get_host_speed,
1229 .show_host_speed = 1,
8d067623
AV
1230 .get_host_port_type = qla2x00_get_host_port_type,
1231 .show_host_port_type = 1,
1620f7c2
AV
1232 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1233 .show_host_symbolic_name = 1,
a740a3f0
AV
1234 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1235 .show_host_system_hostname = 1,
90991c85
AV
1236 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1237 .show_host_fabric_name = 1,
7047fcdd
AV
1238 .get_host_port_state = qla2x00_get_host_port_state,
1239 .show_host_port_state = 1,
8482e118 1240
bdf79621 1241 .dd_fcrport_size = sizeof(struct fc_port *),
ad3e0eda 1242 .show_rport_supported_classes = 1,
8482e118
AV
1243
1244 .get_starget_node_name = qla2x00_get_starget_node_name,
1245 .show_starget_node_name = 1,
1246 .get_starget_port_name = qla2x00_get_starget_port_name,
1247 .show_starget_port_name = 1,
1248 .get_starget_port_id = qla2x00_get_starget_port_id,
1249 .show_starget_port_id = 1,
1250
1251 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1252 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1253 .show_rport_dev_loss_tmo = 1,
1254
91ca7b01 1255 .issue_fc_host_lip = qla2x00_issue_lip,
392e2f65 1256 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2c3dfe3f
SJ
1257
1258 .vport_create = qla24xx_vport_create,
1259 .vport_disable = qla24xx_vport_disable,
1260 .vport_delete = qla24xx_vport_delete,
1261};
1262
1263struct fc_function_template qla2xxx_transport_vport_functions = {
1264
1265 .show_host_node_name = 1,
1266 .show_host_port_name = 1,
1267 .show_host_supported_classes = 1,
1268
1269 .get_host_port_id = qla2x00_get_host_port_id,
1270 .show_host_port_id = 1,
1271 .get_host_speed = qla2x00_get_host_speed,
1272 .show_host_speed = 1,
1273 .get_host_port_type = qla2x00_get_host_port_type,
1274 .show_host_port_type = 1,
1275 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1276 .show_host_symbolic_name = 1,
1277 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1278 .show_host_system_hostname = 1,
1279 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1280 .show_host_fabric_name = 1,
1281 .get_host_port_state = qla2x00_get_host_port_state,
1282 .show_host_port_state = 1,
1283
1284 .dd_fcrport_size = sizeof(struct fc_port *),
1285 .show_rport_supported_classes = 1,
1286
1287 .get_starget_node_name = qla2x00_get_starget_node_name,
1288 .show_starget_node_name = 1,
1289 .get_starget_port_name = qla2x00_get_starget_port_name,
1290 .show_starget_port_name = 1,
1291 .get_starget_port_id = qla2x00_get_starget_port_id,
1292 .show_starget_port_id = 1,
1293
1294 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1295 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1296 .show_rport_dev_loss_tmo = 1,
1297
1298 .issue_fc_host_lip = qla2x00_issue_lip,
1299 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e118
AV
1300};
1301
8482e118
AV
1302void
1303qla2x00_init_host_attr(scsi_qla_host_t *ha)
1304{
2ae2b370
AV
1305 u32 speed = FC_PORTSPEED_UNKNOWN;
1306
dad9c8c1
AV
1307 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1308 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
ad3e0eda 1309 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
4d0ea247 1310 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
2c3dfe3f 1311 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
2ae2b370
AV
1312
1313 if (IS_QLA25XX(ha))
1314 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1315 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
4d4df193 1316 else if (IS_QLA24XX_TYPE(ha))
2ae2b370
AV
1317 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1318 FC_PORTSPEED_1GBIT;
1319 else if (IS_QLA23XX(ha))
1320 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1321 else
1322 speed = FC_PORTSPEED_1GBIT;
1323 fc_host_supported_speeds(ha->host) = speed;
8482e118 1324}