Commit | Line | Data |
---|---|---|
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 | 6 | */ |
7 | #include "qla_def.h" | |
8 | ||
2c3dfe3f | 9 | #include <linux/kthread.h> |
7aaef27b | 10 | #include <linux/vmalloc.h> |
8482e118 | 11 | |
a824ebb3 | 12 | static int qla24xx_vport_disable(struct fc_vport *, bool); |
2c3dfe3f | 13 | |
8482e118 | 14 | /* SYSFS attributes --------------------------------------------------------- */ |
15 | ||
16 | static ssize_t | |
91a69029 ZR |
17 | qla2x00_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))); |
23 | ||
24 | if (ha->fw_dump_reading == 0) | |
25 | return 0; | |
8482e118 | 26 | |
b3dc9088 AM |
27 | return memory_read_from_buffer(buf, count, &off, ha->fw_dump, |
28 | ha->fw_dump_len); | |
8482e118 | 29 | } |
30 | ||
31 | static ssize_t | |
91a69029 ZR |
32 | qla2x00_sysfs_write_fw_dump(struct kobject *kobj, |
33 | struct bin_attribute *bin_attr, | |
34 | char *buf, loff_t off, size_t count) | |
8482e118 | 35 | { |
f363b943 | 36 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 37 | struct device, kobj))); |
38 | int reading; | |
8482e118 | 39 | |
40 | if (off != 0) | |
41 | return (0); | |
42 | ||
43 | reading = simple_strtol(buf, NULL, 10); | |
44 | switch (reading) { | |
45 | case 0: | |
a7a167bf AV |
46 | if (!ha->fw_dump_reading) |
47 | break; | |
8482e118 | 48 | |
a7a167bf AV |
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; | |
8482e118 | 54 | break; |
55 | case 1: | |
d4e3e04d | 56 | if (ha->fw_dumped && !ha->fw_dump_reading) { |
8482e118 | 57 | ha->fw_dump_reading = 1; |
58 | ||
8482e118 | 59 | qla_printk(KERN_INFO, ha, |
a7a167bf | 60 | "Raw firmware dump ready for read on (%ld).\n", |
8482e118 | 61 | ha->host_no); |
8482e118 | 62 | } |
63 | break; | |
a7a167bf AV |
64 | case 2: |
65 | qla2x00_alloc_fw_dump(ha); | |
66 | break; | |
68af0811 AV |
67 | case 3: |
68 | qla2x00_system_error(ha); | |
69 | break; | |
8482e118 | 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, | |
8482e118 | 78 | }, |
79 | .size = 0, | |
80 | .read = qla2x00_sysfs_read_fw_dump, | |
81 | .write = qla2x00_sysfs_write_fw_dump, | |
82 | }; | |
83 | ||
84 | static ssize_t | |
91a69029 ZR |
85 | qla2x00_sysfs_read_nvram(struct kobject *kobj, |
86 | struct bin_attribute *bin_attr, | |
87 | char *buf, loff_t off, size_t count) | |
8482e118 | 88 | { |
f363b943 | 89 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 90 | struct device, kobj))); |
8482e118 | 91 | |
b3dc9088 | 92 | if (!capable(CAP_SYS_ADMIN)) |
8482e118 | 93 | return 0; |
94 | ||
281afe19 | 95 | /* Read NVRAM data from cache. */ |
b3dc9088 AM |
96 | return memory_read_from_buffer(buf, count, &off, ha->nvram, |
97 | ha->nvram_size); | |
8482e118 | 98 | } |
99 | ||
100 | static ssize_t | |
91a69029 ZR |
101 | qla2x00_sysfs_write_nvram(struct kobject *kobj, |
102 | struct bin_attribute *bin_attr, | |
103 | char *buf, loff_t off, size_t count) | |
8482e118 | 104 | { |
f363b943 | 105 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 106 | struct device, kobj))); |
8482e118 | 107 | uint16_t cnt; |
8482e118 | 108 | |
459c5378 | 109 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size) |
8482e118 | 110 | return 0; |
111 | ||
112 | /* Checksum NVRAM. */ | |
e428924c | 113 | if (IS_FWI2_CAPABLE(ha)) { |
459c5378 AV |
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 | } | |
8482e118 | 134 | |
135 | /* Write NVRAM. */ | |
fd34f556 | 136 | ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count); |
c45bcc8e | 137 | ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base, |
281afe19 | 138 | count); |
8482e118 | 139 | |
26b8d348 AV |
140 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
141 | ||
8482e118 | 142 | return (count); |
143 | } | |
144 | ||
145 | static struct bin_attribute sysfs_nvram_attr = { | |
146 | .attr = { | |
147 | .name = "nvram", | |
148 | .mode = S_IRUSR | S_IWUSR, | |
8482e118 | 149 | }, |
1b3f6365 | 150 | .size = 512, |
8482e118 | 151 | .read = qla2x00_sysfs_read_nvram, |
152 | .write = qla2x00_sysfs_write_nvram, | |
153 | }; | |
154 | ||
854165f4 | 155 | static ssize_t |
91a69029 ZR |
156 | qla2x00_sysfs_read_optrom(struct kobject *kobj, |
157 | struct bin_attribute *bin_attr, | |
158 | char *buf, loff_t off, size_t count) | |
854165f4 | 159 | { |
f363b943 | 160 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 161 | struct device, kobj))); |
162 | ||
163 | if (ha->optrom_state != QLA_SREADING) | |
164 | return 0; | |
854165f4 | 165 | |
b3dc9088 AM |
166 | return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer, |
167 | ha->optrom_region_size); | |
854165f4 | 168 | } |
169 | ||
170 | static ssize_t | |
91a69029 ZR |
171 | qla2x00_sysfs_write_optrom(struct kobject *kobj, |
172 | struct bin_attribute *bin_attr, | |
173 | char *buf, loff_t off, size_t count) | |
854165f4 | 174 | { |
f363b943 | 175 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 176 | struct device, kobj))); |
177 | ||
178 | if (ha->optrom_state != QLA_SWRITING) | |
179 | return -EINVAL; | |
b7cc176c | 180 | if (off > ha->optrom_region_size) |
854165f4 | 181 | return -ERANGE; |
b7cc176c JC |
182 | if (off + count > ha->optrom_region_size) |
183 | count = ha->optrom_region_size - off; | |
854165f4 | 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, | |
854165f4 | 194 | }, |
c3a2f0df | 195 | .size = 0, |
854165f4 | 196 | .read = qla2x00_sysfs_read_optrom, |
197 | .write = qla2x00_sysfs_write_optrom, | |
198 | }; | |
199 | ||
200 | static ssize_t | |
91a69029 ZR |
201 | qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, |
202 | struct bin_attribute *bin_attr, | |
203 | char *buf, loff_t off, size_t count) | |
854165f4 | 204 | { |
f363b943 | 205 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 206 | struct device, kobj))); |
b7cc176c JC |
207 | uint32_t start = 0; |
208 | uint32_t size = ha->optrom_size; | |
209 | int val, valid; | |
854165f4 | 210 | |
211 | if (off) | |
212 | return 0; | |
213 | ||
b7cc176c JC |
214 | if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1) |
215 | return -EINVAL; | |
216 | if (start > ha->optrom_size) | |
854165f4 | 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; | |
b7cc176c JC |
226 | |
227 | DEBUG2(qla_printk(KERN_INFO, ha, | |
228 | "Freeing flash region allocation -- 0x%x bytes.\n", | |
229 | ha->optrom_region_size)); | |
230 | ||
854165f4 | 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 | ||
b7cc176c JC |
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 | ||
854165f4 | 248 | ha->optrom_state = QLA_SREADING; |
b7cc176c | 249 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
854165f4 | 250 | if (ha->optrom_buffer == NULL) { |
251 | qla_printk(KERN_WARNING, ha, | |
252 | "Unable to allocate memory for optrom retrieval " | |
b7cc176c | 253 | "(%x).\n", ha->optrom_region_size); |
854165f4 | 254 | |
255 | ha->optrom_state = QLA_SWAITING; | |
256 | return count; | |
257 | } | |
258 | ||
b7cc176c JC |
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); | |
854165f4 | 266 | break; |
267 | case 2: | |
268 | if (ha->optrom_state != QLA_SWAITING) | |
269 | break; | |
270 | ||
b7cc176c JC |
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 | ||
854165f4 | 309 | ha->optrom_state = QLA_SWRITING; |
b7cc176c | 310 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
854165f4 | 311 | if (ha->optrom_buffer == NULL) { |
312 | qla_printk(KERN_WARNING, ha, | |
313 | "Unable to allocate memory for optrom update " | |
b7cc176c | 314 | "(%x).\n", ha->optrom_region_size); |
854165f4 | 315 | |
316 | ha->optrom_state = QLA_SWAITING; | |
317 | return count; | |
318 | } | |
b7cc176c JC |
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); | |
854165f4 | 325 | break; |
326 | case 3: | |
327 | if (ha->optrom_state != QLA_SWRITING) | |
328 | break; | |
329 | ||
b7cc176c JC |
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); | |
854165f4 | 336 | break; |
b7cc176c JC |
337 | default: |
338 | count = -EINVAL; | |
854165f4 | 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, | |
854165f4 | 347 | }, |
348 | .size = 0, | |
349 | .write = qla2x00_sysfs_write_optrom_ctl, | |
350 | }; | |
351 | ||
6f641790 | 352 | static ssize_t |
91a69029 ZR |
353 | qla2x00_sysfs_read_vpd(struct kobject *kobj, |
354 | struct bin_attribute *bin_attr, | |
355 | char *buf, loff_t off, size_t count) | |
6f641790 | 356 | { |
f363b943 | 357 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
6f641790 | 358 | struct device, kobj))); |
6f641790 | 359 | |
b3dc9088 | 360 | if (!capable(CAP_SYS_ADMIN)) |
6f641790 | 361 | return 0; |
362 | ||
281afe19 | 363 | /* Read NVRAM data from cache. */ |
b3dc9088 | 364 | return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size); |
6f641790 | 365 | } |
366 | ||
367 | static ssize_t | |
91a69029 ZR |
368 | qla2x00_sysfs_write_vpd(struct kobject *kobj, |
369 | struct bin_attribute *bin_attr, | |
370 | char *buf, loff_t off, size_t count) | |
6f641790 | 371 | { |
f363b943 | 372 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
6f641790 | 373 | struct device, kobj))); |
6f641790 | 374 | |
375 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size) | |
376 | return 0; | |
377 | ||
6f641790 | 378 | /* Write NVRAM. */ |
fd34f556 | 379 | ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count); |
281afe19 | 380 | ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count); |
6f641790 | 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, | |
6f641790 | 389 | }, |
390 | .size = 0, | |
391 | .read = qla2x00_sysfs_read_vpd, | |
392 | .write = qla2x00_sysfs_write_vpd, | |
393 | }; | |
394 | ||
88729e53 | 395 | static ssize_t |
91a69029 ZR |
396 | qla2x00_sysfs_read_sfp(struct kobject *kobj, |
397 | struct bin_attribute *bin_attr, | |
398 | char *buf, loff_t off, size_t count) | |
88729e53 | 399 | { |
f363b943 | 400 | struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj, |
88729e53 AV |
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 | ||
e8711085 AV |
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); | |
88729e53 AV |
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, | |
88729e53 AV |
450 | }, |
451 | .size = SFP_DEV_SIZE * 2, | |
452 | .read = qla2x00_sysfs_read_sfp, | |
453 | }; | |
454 | ||
f1663ad5 AV |
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 }, | |
46ddab7b | 466 | { NULL }, |
f1663ad5 AV |
467 | }; |
468 | ||
8482e118 | 469 | void |
470 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) | |
471 | { | |
472 | struct Scsi_Host *host = ha->host; | |
f1663ad5 AV |
473 | struct sysfs_entry *iter; |
474 | int ret; | |
8482e118 | 475 | |
f1663ad5 | 476 | for (iter = bin_file_entries; iter->name; iter++) { |
e428924c | 477 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
f1663ad5 AV |
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); | |
7914d004 | 486 | } |
8482e118 | 487 | } |
488 | ||
489 | void | |
490 | qla2x00_free_sysfs_attr(scsi_qla_host_t *ha) | |
491 | { | |
492 | struct Scsi_Host *host = ha->host; | |
f1663ad5 AV |
493 | struct sysfs_entry *iter; |
494 | ||
495 | for (iter = bin_file_entries; iter->name; iter++) { | |
e428924c | 496 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
f1663ad5 | 497 | continue; |
8482e118 | 498 | |
88729e53 | 499 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
f1663ad5 | 500 | iter->attr); |
7914d004 | 501 | } |
f6df144c | 502 | |
503 | if (ha->beacon_blink_led == 1) | |
fd34f556 | 504 | ha->isp_ops->beacon_off(ha); |
8482e118 | 505 | } |
506 | ||
afb046e2 AV |
507 | /* Scsi_Host attributes. */ |
508 | ||
509 | static ssize_t | |
ee959b00 TJ |
510 | qla2x00_drvr_version_show(struct device *dev, |
511 | struct device_attribute *attr, char *buf) | |
afb046e2 AV |
512 | { |
513 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); | |
514 | } | |
515 | ||
516 | static ssize_t | |
ee959b00 TJ |
517 | qla2x00_fw_version_show(struct device *dev, |
518 | struct device_attribute *attr, char *buf) | |
afb046e2 | 519 | { |
ee959b00 | 520 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
521 | char fw_str[30]; |
522 | ||
523 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
fd34f556 | 524 | ha->isp_ops->fw_version_str(ha, fw_str)); |
afb046e2 AV |
525 | } |
526 | ||
527 | static ssize_t | |
ee959b00 TJ |
528 | qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr, |
529 | char *buf) | |
afb046e2 | 530 | { |
ee959b00 | 531 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
532 | uint32_t sn; |
533 | ||
1ee27146 JC |
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 | } | |
8b7afc2a | 538 | |
afb046e2 AV |
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 | |
ee959b00 TJ |
545 | qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr, |
546 | char *buf) | |
afb046e2 | 547 | { |
ee959b00 | 548 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
5433383e | 549 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device); |
afb046e2 AV |
550 | } |
551 | ||
552 | static ssize_t | |
ee959b00 TJ |
553 | qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr, |
554 | char *buf) | |
afb046e2 | 555 | { |
ee959b00 | 556 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
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 | |
ee959b00 TJ |
563 | qla2x00_model_name_show(struct device *dev, struct device_attribute *attr, |
564 | char *buf) | |
afb046e2 | 565 | { |
ee959b00 | 566 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
567 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number); |
568 | } | |
569 | ||
570 | static ssize_t | |
ee959b00 TJ |
571 | qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr, |
572 | char *buf) | |
afb046e2 | 573 | { |
ee959b00 | 574 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
575 | return snprintf(buf, PAGE_SIZE, "%s\n", |
576 | ha->model_desc ? ha->model_desc: ""); | |
577 | } | |
578 | ||
579 | static ssize_t | |
ee959b00 TJ |
580 | qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr, |
581 | char *buf) | |
afb046e2 | 582 | { |
ee959b00 | 583 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
584 | char pci_info[30]; |
585 | ||
586 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
fd34f556 | 587 | ha->isp_ops->pci_info_str(ha, pci_info)); |
afb046e2 AV |
588 | } |
589 | ||
590 | static ssize_t | |
bbd1ae41 HR |
591 | qla2x00_link_state_show(struct device *dev, struct device_attribute *attr, |
592 | char *buf) | |
afb046e2 | 593 | { |
ee959b00 | 594 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
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 | ||
4fdfefe5 | 629 | static ssize_t |
ee959b00 TJ |
630 | qla2x00_zio_show(struct device *dev, struct device_attribute *attr, |
631 | char *buf) | |
4fdfefe5 | 632 | { |
ee959b00 | 633 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
634 | int len = 0; |
635 | ||
636 | switch (ha->zio_mode) { | |
4fdfefe5 AV |
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 | |
ee959b00 TJ |
648 | qla2x00_zio_store(struct device *dev, struct device_attribute *attr, |
649 | const char *buf, size_t count) | |
4fdfefe5 | 650 | { |
ee959b00 | 651 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
652 | int val = 0; |
653 | uint16_t zio_mode; | |
654 | ||
4a59f71d | 655 | if (!IS_ZIO_SUPPORTED(ha)) |
656 | return -ENOTSUPP; | |
657 | ||
4fdfefe5 AV |
658 | if (sscanf(buf, "%d", &val) != 1) |
659 | return -EINVAL; | |
660 | ||
4a59f71d | 661 | if (val) |
4fdfefe5 | 662 | zio_mode = QLA_ZIO_MODE_6; |
4a59f71d | 663 | else |
4fdfefe5 | 664 | zio_mode = QLA_ZIO_DISABLED; |
4fdfefe5 AV |
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 | |
ee959b00 TJ |
675 | qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr, |
676 | char *buf) | |
4fdfefe5 | 677 | { |
ee959b00 | 678 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
679 | |
680 | return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100); | |
681 | } | |
682 | ||
683 | static ssize_t | |
ee959b00 TJ |
684 | qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr, |
685 | const char *buf, size_t count) | |
4fdfefe5 | 686 | { |
ee959b00 | 687 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
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 | ||
f6df144c | 702 | static ssize_t |
ee959b00 TJ |
703 | qla2x00_beacon_show(struct device *dev, struct device_attribute *attr, |
704 | char *buf) | |
f6df144c | 705 | { |
ee959b00 | 706 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
f6df144c | 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 | |
ee959b00 TJ |
717 | qla2x00_beacon_store(struct device *dev, struct device_attribute *attr, |
718 | const char *buf, size_t count) | |
f6df144c | 719 | { |
ee959b00 | 720 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
f6df144c | 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) | |
fd34f556 | 737 | rval = ha->isp_ops->beacon_on(ha); |
f6df144c | 738 | else |
fd34f556 | 739 | rval = ha->isp_ops->beacon_off(ha); |
f6df144c | 740 | |
741 | if (rval != QLA_SUCCESS) | |
742 | count = 0; | |
743 | ||
744 | return count; | |
745 | } | |
746 | ||
30c47662 | 747 | static ssize_t |
ee959b00 TJ |
748 | qla2x00_optrom_bios_version_show(struct device *dev, |
749 | struct device_attribute *attr, char *buf) | |
30c47662 | 750 | { |
ee959b00 | 751 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
30c47662 AV |
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 | |
ee959b00 TJ |
758 | qla2x00_optrom_efi_version_show(struct device *dev, |
759 | struct device_attribute *attr, char *buf) | |
30c47662 | 760 | { |
ee959b00 | 761 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
30c47662 AV |
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 | |
ee959b00 TJ |
768 | qla2x00_optrom_fcode_version_show(struct device *dev, |
769 | struct device_attribute *attr, char *buf) | |
30c47662 | 770 | { |
ee959b00 | 771 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
30c47662 AV |
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 | |
ee959b00 TJ |
778 | qla2x00_optrom_fw_version_show(struct device *dev, |
779 | struct device_attribute *attr, char *buf) | |
30c47662 | 780 | { |
ee959b00 | 781 | scsi_qla_host_t *ha = shost_priv(class_to_shost(dev)); |
30c47662 AV |
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 | ||
e5f5f6f7 HZ |
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 | ||
ee959b00 TJ |
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); | |
bbd1ae41 | 806 | static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL); |
ee959b00 TJ |
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); | |
e5f5f6f7 HZ |
820 | static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show, |
821 | NULL); | |
ee959b00 TJ |
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, | |
bbd1ae41 | 832 | &dev_attr_link_state, |
ee959b00 TJ |
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, | |
e5f5f6f7 | 840 | &dev_attr_total_isp_aborts, |
afb046e2 AV |
841 | NULL, |
842 | }; | |
843 | ||
8482e118 | 844 | /* Host attributes. */ |
845 | ||
846 | static void | |
847 | qla2x00_get_host_port_id(struct Scsi_Host *shost) | |
848 | { | |
f363b943 | 849 | scsi_qla_host_t *ha = shost_priv(shost); |
8482e118 | 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 | ||
04414013 | 855 | static void |
856 | qla2x00_get_host_speed(struct Scsi_Host *shost) | |
857 | { | |
da4541b6 | 858 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
2ae2b370 | 859 | u32 speed = FC_PORTSPEED_UNKNOWN; |
04414013 | 860 | |
861 | switch (ha->link_data_rate) { | |
d8b45213 | 862 | case PORT_SPEED_1GB: |
2ae2b370 | 863 | speed = FC_PORTSPEED_1GBIT; |
04414013 | 864 | break; |
d8b45213 | 865 | case PORT_SPEED_2GB: |
2ae2b370 | 866 | speed = FC_PORTSPEED_2GBIT; |
04414013 | 867 | break; |
d8b45213 | 868 | case PORT_SPEED_4GB: |
2ae2b370 | 869 | speed = FC_PORTSPEED_4GBIT; |
04414013 | 870 | break; |
da4541b6 | 871 | case PORT_SPEED_8GB: |
2ae2b370 | 872 | speed = FC_PORTSPEED_8GBIT; |
da4541b6 | 873 | break; |
04414013 | 874 | } |
875 | fc_host_speed(shost) = speed; | |
876 | } | |
877 | ||
8d067623 | 878 | static void |
879 | qla2x00_get_host_port_type(struct Scsi_Host *shost) | |
880 | { | |
2f2fa13d | 881 | scsi_qla_host_t *ha = shost_priv(shost); |
8d067623 | 882 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
883 | ||
2f2fa13d SS |
884 | if (ha->parent) { |
885 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
886 | return; | |
887 | } | |
8d067623 | 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 | ||
8482e118 | 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); | |
f363b943 | 909 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 | 910 | fc_port_t *fcport; |
f8b02a85 | 911 | u64 node_name = 0; |
8482e118 | 912 | |
bdf79621 | 913 | list_for_each_entry(fcport, &ha->fcports, list) { |
5ab5a4dd AV |
914 | if (fcport->rport && |
915 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 916 | node_name = wwn_to_u64(fcport->node_name); |
bdf79621 | 917 | break; |
918 | } | |
919 | } | |
920 | ||
f8b02a85 | 921 | fc_starget_node_name(starget) = node_name; |
8482e118 | 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); | |
f363b943 | 928 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 | 929 | fc_port_t *fcport; |
f8b02a85 | 930 | u64 port_name = 0; |
8482e118 | 931 | |
bdf79621 | 932 | list_for_each_entry(fcport, &ha->fcports, list) { |
5ab5a4dd AV |
933 | if (fcport->rport && |
934 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 935 | port_name = wwn_to_u64(fcport->port_name); |
bdf79621 | 936 | break; |
937 | } | |
938 | } | |
939 | ||
f8b02a85 | 940 | fc_starget_port_name(starget) = port_name; |
8482e118 | 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); | |
f363b943 | 947 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 | 948 | fc_port_t *fcport; |
949 | uint32_t port_id = ~0U; | |
950 | ||
951 | list_for_each_entry(fcport, &ha->fcports, list) { | |
5ab5a4dd AV |
952 | if (fcport->rport && |
953 | starget->id == fcport->rport->scsi_target_id) { | |
bdf79621 | 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 | } | |
8482e118 | 959 | |
8482e118 | 960 | fc_starget_port_id(starget) = port_id; |
961 | } | |
962 | ||
8482e118 | 963 | static void |
964 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
965 | { | |
8482e118 | 966 | if (timeout) |
85821c90 | 967 | rport->dev_loss_tmo = timeout; |
8482e118 | 968 | else |
85821c90 | 969 | rport->dev_loss_tmo = 1; |
8482e118 | 970 | } |
971 | ||
5f3a9a20 SJ |
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 | ||
91ca7b01 AV |
999 | static int |
1000 | qla2x00_issue_lip(struct Scsi_Host *shost) | |
1001 | { | |
f363b943 | 1002 | scsi_qla_host_t *ha = shost_priv(shost); |
91ca7b01 | 1003 | |
a4722cf2 | 1004 | qla2x00_loop_reset(ha); |
91ca7b01 AV |
1005 | return 0; |
1006 | } | |
1007 | ||
392e2f65 | 1008 | static struct fc_host_statistics * |
1009 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) | |
1010 | { | |
da4541b6 | 1011 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
392e2f65 | 1012 | int rval; |
43ef0580 AV |
1013 | struct link_statistics *stats; |
1014 | dma_addr_t stats_dma; | |
392e2f65 | 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 | ||
43ef0580 AV |
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; | |
e428924c | 1029 | if (IS_FWI2_CAPABLE(ha)) { |
43ef0580 | 1030 | rval = qla24xx_get_isp_stats(ha, stats, stats_dma); |
178779a6 AV |
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. */ | |
43ef0580 AV |
1036 | rval = qla2x00_get_link_status(ha, ha->loop_id, stats, |
1037 | stats_dma); | |
392e2f65 | 1038 | } |
178779a6 AV |
1039 | |
1040 | if (rval != QLA_SUCCESS) | |
43ef0580 AV |
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)) { | |
032d8dd7 | 1050 | pfc_host_stat->lip_count = stats->lip_cnt; |
43ef0580 AV |
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 | } | |
392e2f65 | 1056 | |
43ef0580 AV |
1057 | done_free: |
1058 | dma_pool_free(ha->s_dma_pool, stats, stats_dma); | |
178779a6 | 1059 | done: |
392e2f65 | 1060 | return pfc_host_stat; |
1061 | } | |
1062 | ||
1620f7c2 AV |
1063 | static void |
1064 | qla2x00_get_host_symbolic_name(struct Scsi_Host *shost) | |
1065 | { | |
f363b943 | 1066 | scsi_qla_host_t *ha = shost_priv(shost); |
1620f7c2 AV |
1067 | |
1068 | qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost)); | |
1069 | } | |
1070 | ||
a740a3f0 AV |
1071 | static void |
1072 | qla2x00_set_host_system_hostname(struct Scsi_Host *shost) | |
1073 | { | |
f363b943 | 1074 | scsi_qla_host_t *ha = shost_priv(shost); |
a740a3f0 AV |
1075 | |
1076 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); | |
1077 | } | |
1078 | ||
90991c85 AV |
1079 | static void |
1080 | qla2x00_get_host_fabric_name(struct Scsi_Host *shost) | |
1081 | { | |
f363b943 | 1082 | scsi_qla_host_t *ha = shost_priv(shost); |
90991c85 AV |
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 | ||
7047fcdd AV |
1093 | static void |
1094 | qla2x00_get_host_port_state(struct Scsi_Host *shost) | |
1095 | { | |
da4541b6 | 1096 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
7047fcdd AV |
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 | ||
2c3dfe3f SJ |
1106 | static int |
1107 | qla24xx_vport_create(struct fc_vport *fc_vport, bool disable) | |
1108 | { | |
1109 | int ret = 0; | |
f363b943 | 1110 | scsi_qla_host_t *ha = shost_priv(fc_vport->shost); |
2c3dfe3f SJ |
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 | ||
a824ebb3 | 1176 | static int |
2c3dfe3f SJ |
1177 | qla24xx_vport_delete(struct fc_vport *fc_vport) |
1178 | { | |
2c3dfe3f SJ |
1179 | scsi_qla_host_t *vha = fc_vport->dd_data; |
1180 | ||
1181 | qla24xx_disable_vp(vha); | |
1182 | qla24xx_deallocate_vp_id(vha); | |
1183 | ||
2c3dfe3f SJ |
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 | ||
a824ebb3 | 1203 | static int |
2c3dfe3f SJ |
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 | ||
1c97a12a | 1216 | struct fc_function_template qla2xxx_transport_functions = { |
8482e118 | 1217 | |
1218 | .show_host_node_name = 1, | |
1219 | .show_host_port_name = 1, | |
ad3e0eda | 1220 | .show_host_supported_classes = 1, |
2ae2b370 | 1221 | .show_host_supported_speeds = 1, |
ad3e0eda | 1222 | |
8482e118 | 1223 | .get_host_port_id = qla2x00_get_host_port_id, |
1224 | .show_host_port_id = 1, | |
04414013 | 1225 | .get_host_speed = qla2x00_get_host_speed, |
1226 | .show_host_speed = 1, | |
8d067623 | 1227 | .get_host_port_type = qla2x00_get_host_port_type, |
1228 | .show_host_port_type = 1, | |
1620f7c2 AV |
1229 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
1230 | .show_host_symbolic_name = 1, | |
a740a3f0 AV |
1231 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
1232 | .show_host_system_hostname = 1, | |
90991c85 AV |
1233 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
1234 | .show_host_fabric_name = 1, | |
7047fcdd AV |
1235 | .get_host_port_state = qla2x00_get_host_port_state, |
1236 | .show_host_port_state = 1, | |
8482e118 | 1237 | |
bdf79621 | 1238 | .dd_fcrport_size = sizeof(struct fc_port *), |
ad3e0eda | 1239 | .show_rport_supported_classes = 1, |
8482e118 | 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 | ||
8482e118 | 1248 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
1249 | .show_rport_dev_loss_tmo = 1, | |
1250 | ||
91ca7b01 | 1251 | .issue_fc_host_lip = qla2x00_issue_lip, |
5f3a9a20 SJ |
1252 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
1253 | .terminate_rport_io = qla2x00_terminate_rport_io, | |
392e2f65 | 1254 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
2c3dfe3f SJ |
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 | ||
2c3dfe3f SJ |
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, | |
5f3a9a20 SJ |
1296 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
1297 | .terminate_rport_io = qla2x00_terminate_rport_io, | |
2c3dfe3f | 1298 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
8482e118 | 1299 | }; |
1300 | ||
8482e118 | 1301 | void |
1302 | qla2x00_init_host_attr(scsi_qla_host_t *ha) | |
1303 | { | |
2ae2b370 AV |
1304 | u32 speed = FC_PORTSPEED_UNKNOWN; |
1305 | ||
dad9c8c1 | 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); | |
ad3e0eda | 1308 | fc_host_supported_classes(ha->host) = FC_COS_CLASS3; |
4d0ea247 | 1309 | fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;; |
2c3dfe3f | 1310 | fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count; |
2ae2b370 AV |
1311 | |
1312 | if (IS_QLA25XX(ha)) | |
1313 | speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | | |
1314 | FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; | |
4d4df193 | 1315 | else if (IS_QLA24XX_TYPE(ha)) |
2ae2b370 AV |
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; | |
8482e118 | 1323 | } |