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