]>
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 AV |
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 AV |
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 AV |
24 | |
25 | if (ha->fw_dump_reading == 0) | |
26 | return 0; | |
a7a167bf AV |
27 | if (off > ha->fw_dump_len) |
28 | return 0; | |
29 | if (off + count > ha->fw_dump_len) | |
30 | count = ha->fw_dump_len - off; | |
8482e118 | 31 | |
a7a167bf | 32 | memcpy(buf, &rbuf[off], count); |
8482e118 AV |
33 | |
34 | return (count); | |
35 | } | |
36 | ||
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 AV |
43 | struct device, kobj))); |
44 | int reading; | |
8482e118 AV |
45 | |
46 | if (off != 0) | |
47 | return (0); | |
48 | ||
49 | reading = simple_strtol(buf, NULL, 10); | |
50 | switch (reading) { | |
51 | case 0: | |
a7a167bf AV |
52 | if (!ha->fw_dump_reading) |
53 | break; | |
8482e118 | 54 | |
a7a167bf AV |
55 | qla_printk(KERN_INFO, ha, |
56 | "Firmware dump cleared on (%ld).\n", ha->host_no); | |
57 | ||
58 | ha->fw_dump_reading = 0; | |
59 | ha->fw_dumped = 0; | |
8482e118 AV |
60 | break; |
61 | case 1: | |
d4e3e04d | 62 | if (ha->fw_dumped && !ha->fw_dump_reading) { |
8482e118 AV |
63 | ha->fw_dump_reading = 1; |
64 | ||
8482e118 | 65 | qla_printk(KERN_INFO, ha, |
a7a167bf | 66 | "Raw firmware dump ready for read on (%ld).\n", |
8482e118 | 67 | ha->host_no); |
8482e118 AV |
68 | } |
69 | break; | |
a7a167bf AV |
70 | case 2: |
71 | qla2x00_alloc_fw_dump(ha); | |
72 | break; | |
8482e118 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 AV |
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 | ||
e8711085 AV |
431 | if (ha->sfp_data) |
432 | goto do_read; | |
433 | ||
434 | ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
435 | &ha->sfp_data_dma); | |
436 | if (!ha->sfp_data) { | |
437 | qla_printk(KERN_WARNING, ha, | |
438 | "Unable to allocate memory for SFP read-data.\n"); | |
439 | return 0; | |
440 | } | |
441 | ||
442 | do_read: | |
443 | memset(ha->sfp_data, 0, SFP_BLOCK_SIZE); | |
88729e53 AV |
444 | addr = 0xa0; |
445 | for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE; | |
446 | iter++, offset += SFP_BLOCK_SIZE) { | |
447 | if (iter == 4) { | |
448 | /* Skip to next device address. */ | |
449 | addr = 0xa2; | |
450 | offset = 0; | |
451 | } | |
452 | ||
453 | rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset, | |
454 | SFP_BLOCK_SIZE); | |
455 | if (rval != QLA_SUCCESS) { | |
456 | qla_printk(KERN_WARNING, ha, | |
457 | "Unable to read SFP data (%x/%x/%x).\n", rval, | |
458 | addr, offset); | |
459 | count = 0; | |
460 | break; | |
461 | } | |
462 | memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE); | |
463 | buf += SFP_BLOCK_SIZE; | |
464 | } | |
465 | ||
466 | return count; | |
467 | } | |
468 | ||
469 | static struct bin_attribute sysfs_sfp_attr = { | |
470 | .attr = { | |
471 | .name = "sfp", | |
472 | .mode = S_IRUSR | S_IWUSR, | |
88729e53 AV |
473 | }, |
474 | .size = SFP_DEV_SIZE * 2, | |
475 | .read = qla2x00_sysfs_read_sfp, | |
476 | }; | |
477 | ||
f1663ad5 AV |
478 | static struct sysfs_entry { |
479 | char *name; | |
480 | struct bin_attribute *attr; | |
481 | int is4GBp_only; | |
482 | } bin_file_entries[] = { | |
483 | { "fw_dump", &sysfs_fw_dump_attr, }, | |
484 | { "nvram", &sysfs_nvram_attr, }, | |
485 | { "optrom", &sysfs_optrom_attr, }, | |
486 | { "optrom_ctl", &sysfs_optrom_ctl_attr, }, | |
487 | { "vpd", &sysfs_vpd_attr, 1 }, | |
488 | { "sfp", &sysfs_sfp_attr, 1 }, | |
46ddab7b | 489 | { NULL }, |
f1663ad5 AV |
490 | }; |
491 | ||
8482e118 AV |
492 | void |
493 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) | |
494 | { | |
495 | struct Scsi_Host *host = ha->host; | |
f1663ad5 AV |
496 | struct sysfs_entry *iter; |
497 | int ret; | |
8482e118 | 498 | |
f1663ad5 | 499 | for (iter = bin_file_entries; iter->name; iter++) { |
e428924c | 500 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
f1663ad5 AV |
501 | continue; |
502 | ||
503 | ret = sysfs_create_bin_file(&host->shost_gendev.kobj, | |
504 | iter->attr); | |
505 | if (ret) | |
506 | qla_printk(KERN_INFO, ha, | |
507 | "Unable to create sysfs %s binary attribute " | |
508 | "(%d).\n", iter->name, ret); | |
7914d004 | 509 | } |
8482e118 AV |
510 | } |
511 | ||
512 | void | |
513 | qla2x00_free_sysfs_attr(scsi_qla_host_t *ha) | |
514 | { | |
515 | struct Scsi_Host *host = ha->host; | |
f1663ad5 AV |
516 | struct sysfs_entry *iter; |
517 | ||
518 | for (iter = bin_file_entries; iter->name; iter++) { | |
e428924c | 519 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
f1663ad5 | 520 | continue; |
8482e118 | 521 | |
88729e53 | 522 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
f1663ad5 | 523 | iter->attr); |
7914d004 | 524 | } |
f6df144c AV |
525 | |
526 | if (ha->beacon_blink_led == 1) | |
fd34f556 | 527 | ha->isp_ops->beacon_off(ha); |
8482e118 AV |
528 | } |
529 | ||
afb046e2 AV |
530 | /* Scsi_Host attributes. */ |
531 | ||
532 | static ssize_t | |
533 | qla2x00_drvr_version_show(struct class_device *cdev, char *buf) | |
534 | { | |
535 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); | |
536 | } | |
537 | ||
538 | static ssize_t | |
539 | qla2x00_fw_version_show(struct class_device *cdev, char *buf) | |
540 | { | |
f363b943 | 541 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
542 | char fw_str[30]; |
543 | ||
544 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
fd34f556 | 545 | ha->isp_ops->fw_version_str(ha, fw_str)); |
afb046e2 AV |
546 | } |
547 | ||
548 | static ssize_t | |
549 | qla2x00_serial_num_show(struct class_device *cdev, char *buf) | |
550 | { | |
f363b943 | 551 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
552 | uint32_t sn; |
553 | ||
8b7afc2a AV |
554 | if (IS_FWI2_CAPABLE(ha)) |
555 | return snprintf(buf, PAGE_SIZE, "\n"); | |
556 | ||
afb046e2 AV |
557 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; |
558 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, | |
559 | sn % 100000); | |
560 | } | |
561 | ||
562 | static ssize_t | |
563 | qla2x00_isp_name_show(struct class_device *cdev, char *buf) | |
564 | { | |
f363b943 | 565 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
5433383e | 566 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device); |
afb046e2 AV |
567 | } |
568 | ||
569 | static ssize_t | |
570 | qla2x00_isp_id_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, "%04x %04x %04x %04x\n", |
574 | ha->product_id[0], ha->product_id[1], ha->product_id[2], | |
575 | ha->product_id[3]); | |
576 | } | |
577 | ||
578 | static ssize_t | |
579 | qla2x00_model_name_show(struct class_device *cdev, char *buf) | |
580 | { | |
f363b943 | 581 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
582 | return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number); |
583 | } | |
584 | ||
585 | static ssize_t | |
586 | qla2x00_model_desc_show(struct class_device *cdev, char *buf) | |
587 | { | |
f363b943 | 588 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
589 | return snprintf(buf, PAGE_SIZE, "%s\n", |
590 | ha->model_desc ? ha->model_desc: ""); | |
591 | } | |
592 | ||
593 | static ssize_t | |
594 | qla2x00_pci_info_show(struct class_device *cdev, char *buf) | |
595 | { | |
f363b943 | 596 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
597 | char pci_info[30]; |
598 | ||
599 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
fd34f556 | 600 | ha->isp_ops->pci_info_str(ha, pci_info)); |
afb046e2 AV |
601 | } |
602 | ||
603 | static ssize_t | |
604 | qla2x00_state_show(struct class_device *cdev, char *buf) | |
605 | { | |
f363b943 | 606 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
afb046e2 AV |
607 | int len = 0; |
608 | ||
609 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || | |
610 | atomic_read(&ha->loop_state) == LOOP_DEAD) | |
611 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); | |
612 | else if (atomic_read(&ha->loop_state) != LOOP_READY || | |
613 | test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) || | |
614 | test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) | |
615 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); | |
616 | else { | |
617 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); | |
618 | ||
619 | switch (ha->current_topology) { | |
620 | case ISP_CFG_NL: | |
621 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
622 | break; | |
623 | case ISP_CFG_FL: | |
624 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); | |
625 | break; | |
626 | case ISP_CFG_N: | |
627 | len += snprintf(buf + len, PAGE_SIZE-len, | |
628 | "N_Port to N_Port\n"); | |
629 | break; | |
630 | case ISP_CFG_F: | |
631 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); | |
632 | break; | |
633 | default: | |
634 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
635 | break; | |
636 | } | |
637 | } | |
638 | return len; | |
639 | } | |
640 | ||
4fdfefe5 AV |
641 | static ssize_t |
642 | qla2x00_zio_show(struct class_device *cdev, char *buf) | |
643 | { | |
f363b943 | 644 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
4fdfefe5 AV |
645 | int len = 0; |
646 | ||
647 | switch (ha->zio_mode) { | |
4fdfefe5 AV |
648 | case QLA_ZIO_MODE_6: |
649 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); | |
650 | break; | |
651 | case QLA_ZIO_DISABLED: | |
652 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
653 | break; | |
654 | } | |
655 | return len; | |
656 | } | |
657 | ||
658 | static ssize_t | |
659 | qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count) | |
660 | { | |
f363b943 | 661 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
4fdfefe5 AV |
662 | int val = 0; |
663 | uint16_t zio_mode; | |
664 | ||
4a59f71d AV |
665 | if (!IS_ZIO_SUPPORTED(ha)) |
666 | return -ENOTSUPP; | |
667 | ||
4fdfefe5 AV |
668 | if (sscanf(buf, "%d", &val) != 1) |
669 | return -EINVAL; | |
670 | ||
4a59f71d | 671 | if (val) |
4fdfefe5 | 672 | zio_mode = QLA_ZIO_MODE_6; |
4a59f71d | 673 | else |
4fdfefe5 | 674 | zio_mode = QLA_ZIO_DISABLED; |
4fdfefe5 AV |
675 | |
676 | /* Update per-hba values and queue a reset. */ | |
677 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { | |
678 | ha->zio_mode = zio_mode; | |
679 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
680 | } | |
681 | return strlen(buf); | |
682 | } | |
683 | ||
684 | static ssize_t | |
685 | qla2x00_zio_timer_show(struct class_device *cdev, char *buf) | |
686 | { | |
f363b943 | 687 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
4fdfefe5 AV |
688 | |
689 | return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100); | |
690 | } | |
691 | ||
692 | static ssize_t | |
693 | qla2x00_zio_timer_store(struct class_device *cdev, const char *buf, | |
694 | size_t count) | |
695 | { | |
f363b943 | 696 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
4fdfefe5 AV |
697 | int val = 0; |
698 | uint16_t zio_timer; | |
699 | ||
700 | if (sscanf(buf, "%d", &val) != 1) | |
701 | return -EINVAL; | |
702 | if (val > 25500 || val < 100) | |
703 | return -ERANGE; | |
704 | ||
705 | zio_timer = (uint16_t)(val / 100); | |
706 | ha->zio_timer = zio_timer; | |
707 | ||
708 | return strlen(buf); | |
709 | } | |
710 | ||
f6df144c AV |
711 | static ssize_t |
712 | qla2x00_beacon_show(struct class_device *cdev, char *buf) | |
713 | { | |
f363b943 | 714 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
f6df144c AV |
715 | int len = 0; |
716 | ||
717 | if (ha->beacon_blink_led) | |
718 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); | |
719 | else | |
720 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
721 | return len; | |
722 | } | |
723 | ||
724 | static ssize_t | |
725 | qla2x00_beacon_store(struct class_device *cdev, const char *buf, | |
726 | size_t count) | |
727 | { | |
f363b943 | 728 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
f6df144c AV |
729 | int val = 0; |
730 | int rval; | |
731 | ||
732 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | |
733 | return -EPERM; | |
734 | ||
735 | if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) { | |
736 | qla_printk(KERN_WARNING, ha, | |
737 | "Abort ISP active -- ignoring beacon request.\n"); | |
738 | return -EBUSY; | |
739 | } | |
740 | ||
741 | if (sscanf(buf, "%d", &val) != 1) | |
742 | return -EINVAL; | |
743 | ||
744 | if (val) | |
fd34f556 | 745 | rval = ha->isp_ops->beacon_on(ha); |
f6df144c | 746 | else |
fd34f556 | 747 | rval = ha->isp_ops->beacon_off(ha); |
f6df144c AV |
748 | |
749 | if (rval != QLA_SUCCESS) | |
750 | count = 0; | |
751 | ||
752 | return count; | |
753 | } | |
754 | ||
30c47662 AV |
755 | static ssize_t |
756 | qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf) | |
757 | { | |
f363b943 | 758 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
30c47662 AV |
759 | |
760 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1], | |
761 | ha->bios_revision[0]); | |
762 | } | |
763 | ||
764 | static ssize_t | |
765 | qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf) | |
766 | { | |
f363b943 | 767 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
30c47662 AV |
768 | |
769 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1], | |
770 | ha->efi_revision[0]); | |
771 | } | |
772 | ||
773 | static ssize_t | |
774 | qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf) | |
775 | { | |
f363b943 | 776 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
30c47662 AV |
777 | |
778 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1], | |
779 | ha->fcode_revision[0]); | |
780 | } | |
781 | ||
782 | static ssize_t | |
783 | qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf) | |
784 | { | |
f363b943 | 785 | scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev)); |
30c47662 AV |
786 | |
787 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n", | |
788 | ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2], | |
789 | ha->fw_revision[3]); | |
790 | } | |
791 | ||
afb046e2 AV |
792 | static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, |
793 | NULL); | |
794 | static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); | |
795 | static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); | |
796 | static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); | |
797 | static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); | |
798 | static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); | |
799 | static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); | |
800 | static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); | |
801 | static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL); | |
4fdfefe5 AV |
802 | static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, |
803 | qla2x00_zio_store); | |
804 | static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, | |
805 | qla2x00_zio_timer_store); | |
f6df144c AV |
806 | static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, |
807 | qla2x00_beacon_store); | |
30c47662 AV |
808 | static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO, |
809 | qla2x00_optrom_bios_version_show, NULL); | |
810 | static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO, | |
811 | qla2x00_optrom_efi_version_show, NULL); | |
812 | static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO, | |
813 | qla2x00_optrom_fcode_version_show, NULL); | |
814 | static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO, | |
815 | qla2x00_optrom_fw_version_show, NULL); | |
afb046e2 AV |
816 | |
817 | struct class_device_attribute *qla2x00_host_attrs[] = { | |
818 | &class_device_attr_driver_version, | |
819 | &class_device_attr_fw_version, | |
820 | &class_device_attr_serial_num, | |
821 | &class_device_attr_isp_name, | |
822 | &class_device_attr_isp_id, | |
823 | &class_device_attr_model_name, | |
824 | &class_device_attr_model_desc, | |
825 | &class_device_attr_pci_info, | |
826 | &class_device_attr_state, | |
4fdfefe5 AV |
827 | &class_device_attr_zio, |
828 | &class_device_attr_zio_timer, | |
f6df144c | 829 | &class_device_attr_beacon, |
30c47662 AV |
830 | &class_device_attr_optrom_bios_version, |
831 | &class_device_attr_optrom_efi_version, | |
832 | &class_device_attr_optrom_fcode_version, | |
833 | &class_device_attr_optrom_fw_version, | |
afb046e2 AV |
834 | NULL, |
835 | }; | |
836 | ||
8482e118 AV |
837 | /* Host attributes. */ |
838 | ||
839 | static void | |
840 | qla2x00_get_host_port_id(struct Scsi_Host *shost) | |
841 | { | |
f363b943 | 842 | scsi_qla_host_t *ha = shost_priv(shost); |
8482e118 AV |
843 | |
844 | fc_host_port_id(shost) = ha->d_id.b.domain << 16 | | |
845 | ha->d_id.b.area << 8 | ha->d_id.b.al_pa; | |
846 | } | |
847 | ||
04414013 AV |
848 | static void |
849 | qla2x00_get_host_speed(struct Scsi_Host *shost) | |
850 | { | |
da4541b6 | 851 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
2ae2b370 | 852 | u32 speed = FC_PORTSPEED_UNKNOWN; |
04414013 AV |
853 | |
854 | switch (ha->link_data_rate) { | |
d8b45213 | 855 | case PORT_SPEED_1GB: |
2ae2b370 | 856 | speed = FC_PORTSPEED_1GBIT; |
04414013 | 857 | break; |
d8b45213 | 858 | case PORT_SPEED_2GB: |
2ae2b370 | 859 | speed = FC_PORTSPEED_2GBIT; |
04414013 | 860 | break; |
d8b45213 | 861 | case PORT_SPEED_4GB: |
2ae2b370 | 862 | speed = FC_PORTSPEED_4GBIT; |
04414013 | 863 | break; |
da4541b6 | 864 | case PORT_SPEED_8GB: |
2ae2b370 | 865 | speed = FC_PORTSPEED_8GBIT; |
da4541b6 | 866 | break; |
04414013 AV |
867 | } |
868 | fc_host_speed(shost) = speed; | |
869 | } | |
870 | ||
8d067623 AV |
871 | static void |
872 | qla2x00_get_host_port_type(struct Scsi_Host *shost) | |
873 | { | |
da4541b6 | 874 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
8d067623 AV |
875 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
876 | ||
877 | switch (ha->current_topology) { | |
878 | case ISP_CFG_NL: | |
879 | port_type = FC_PORTTYPE_LPORT; | |
880 | break; | |
881 | case ISP_CFG_FL: | |
882 | port_type = FC_PORTTYPE_NLPORT; | |
883 | break; | |
884 | case ISP_CFG_N: | |
885 | port_type = FC_PORTTYPE_PTP; | |
886 | break; | |
887 | case ISP_CFG_F: | |
888 | port_type = FC_PORTTYPE_NPORT; | |
889 | break; | |
890 | } | |
891 | fc_host_port_type(shost) = port_type; | |
892 | } | |
893 | ||
8482e118 AV |
894 | static void |
895 | qla2x00_get_starget_node_name(struct scsi_target *starget) | |
896 | { | |
897 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
f363b943 | 898 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 | 899 | fc_port_t *fcport; |
f8b02a85 | 900 | u64 node_name = 0; |
8482e118 | 901 | |
bdf79621 | 902 | list_for_each_entry(fcport, &ha->fcports, list) { |
5ab5a4dd AV |
903 | if (fcport->rport && |
904 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 905 | node_name = wwn_to_u64(fcport->node_name); |
bdf79621 AV |
906 | break; |
907 | } | |
908 | } | |
909 | ||
f8b02a85 | 910 | fc_starget_node_name(starget) = node_name; |
8482e118 AV |
911 | } |
912 | ||
913 | static void | |
914 | qla2x00_get_starget_port_name(struct scsi_target *starget) | |
915 | { | |
916 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
f363b943 | 917 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 | 918 | fc_port_t *fcport; |
f8b02a85 | 919 | u64 port_name = 0; |
8482e118 | 920 | |
bdf79621 | 921 | list_for_each_entry(fcport, &ha->fcports, list) { |
5ab5a4dd AV |
922 | if (fcport->rport && |
923 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 924 | port_name = wwn_to_u64(fcport->port_name); |
bdf79621 AV |
925 | break; |
926 | } | |
927 | } | |
928 | ||
f8b02a85 | 929 | fc_starget_port_name(starget) = port_name; |
8482e118 AV |
930 | } |
931 | ||
932 | static void | |
933 | qla2x00_get_starget_port_id(struct scsi_target *starget) | |
934 | { | |
935 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
f363b943 | 936 | scsi_qla_host_t *ha = shost_priv(host); |
bdf79621 AV |
937 | fc_port_t *fcport; |
938 | uint32_t port_id = ~0U; | |
939 | ||
940 | list_for_each_entry(fcport, &ha->fcports, list) { | |
5ab5a4dd AV |
941 | if (fcport->rport && |
942 | starget->id == fcport->rport->scsi_target_id) { | |
bdf79621 AV |
943 | port_id = fcport->d_id.b.domain << 16 | |
944 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; | |
945 | break; | |
946 | } | |
947 | } | |
8482e118 | 948 | |
8482e118 AV |
949 | fc_starget_port_id(starget) = port_id; |
950 | } | |
951 | ||
952 | static void | |
953 | qla2x00_get_rport_loss_tmo(struct fc_rport *rport) | |
954 | { | |
bdf79621 | 955 | struct Scsi_Host *host = rport_to_shost(rport); |
f363b943 | 956 | scsi_qla_host_t *ha = shost_priv(host); |
8482e118 AV |
957 | |
958 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; | |
959 | } | |
960 | ||
961 | static void | |
962 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
963 | { | |
bdf79621 | 964 | struct Scsi_Host *host = rport_to_shost(rport); |
f363b943 | 965 | scsi_qla_host_t *ha = shost_priv(host); |
8482e118 AV |
966 | |
967 | if (timeout) | |
968 | ha->port_down_retry_count = timeout; | |
969 | else | |
970 | ha->port_down_retry_count = 1; | |
971 | ||
972 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; | |
973 | } | |
974 | ||
91ca7b01 AV |
975 | static int |
976 | qla2x00_issue_lip(struct Scsi_Host *shost) | |
977 | { | |
f363b943 | 978 | scsi_qla_host_t *ha = shost_priv(shost); |
91ca7b01 | 979 | |
a4722cf2 | 980 | qla2x00_loop_reset(ha); |
91ca7b01 AV |
981 | return 0; |
982 | } | |
983 | ||
392e2f65 AV |
984 | static struct fc_host_statistics * |
985 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) | |
986 | { | |
da4541b6 | 987 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
392e2f65 | 988 | int rval; |
43ef0580 AV |
989 | struct link_statistics *stats; |
990 | dma_addr_t stats_dma; | |
392e2f65 AV |
991 | struct fc_host_statistics *pfc_host_stat; |
992 | ||
993 | pfc_host_stat = &ha->fc_host_stat; | |
994 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); | |
995 | ||
43ef0580 AV |
996 | stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma); |
997 | if (stats == NULL) { | |
998 | DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n", | |
999 | __func__, ha->host_no)); | |
1000 | goto done; | |
1001 | } | |
1002 | memset(stats, 0, DMA_POOL_SIZE); | |
1003 | ||
1004 | rval = QLA_FUNCTION_FAILED; | |
e428924c | 1005 | if (IS_FWI2_CAPABLE(ha)) { |
43ef0580 | 1006 | rval = qla24xx_get_isp_stats(ha, stats, stats_dma); |
178779a6 AV |
1007 | } else if (atomic_read(&ha->loop_state) == LOOP_READY && |
1008 | !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) && | |
1009 | !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) && | |
1010 | !ha->dpc_active) { | |
1011 | /* Must be in a 'READY' state for statistics retrieval. */ | |
43ef0580 AV |
1012 | rval = qla2x00_get_link_status(ha, ha->loop_id, stats, |
1013 | stats_dma); | |
392e2f65 | 1014 | } |
178779a6 AV |
1015 | |
1016 | if (rval != QLA_SUCCESS) | |
43ef0580 AV |
1017 | goto done_free; |
1018 | ||
1019 | pfc_host_stat->link_failure_count = stats->link_fail_cnt; | |
1020 | pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt; | |
1021 | pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt; | |
1022 | pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt; | |
1023 | pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt; | |
1024 | pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt; | |
1025 | if (IS_FWI2_CAPABLE(ha)) { | |
1026 | pfc_host_stat->tx_frames = stats->tx_frames; | |
1027 | pfc_host_stat->rx_frames = stats->rx_frames; | |
1028 | pfc_host_stat->dumped_frames = stats->dumped_frames; | |
1029 | pfc_host_stat->nos_count = stats->nos_rcvd; | |
1030 | } | |
392e2f65 | 1031 | |
43ef0580 AV |
1032 | done_free: |
1033 | dma_pool_free(ha->s_dma_pool, stats, stats_dma); | |
178779a6 | 1034 | done: |
392e2f65 AV |
1035 | return pfc_host_stat; |
1036 | } | |
1037 | ||
1620f7c2 AV |
1038 | static void |
1039 | qla2x00_get_host_symbolic_name(struct Scsi_Host *shost) | |
1040 | { | |
f363b943 | 1041 | scsi_qla_host_t *ha = shost_priv(shost); |
1620f7c2 AV |
1042 | |
1043 | qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost)); | |
1044 | } | |
1045 | ||
a740a3f0 AV |
1046 | static void |
1047 | qla2x00_set_host_system_hostname(struct Scsi_Host *shost) | |
1048 | { | |
f363b943 | 1049 | scsi_qla_host_t *ha = shost_priv(shost); |
a740a3f0 AV |
1050 | |
1051 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); | |
1052 | } | |
1053 | ||
90991c85 AV |
1054 | static void |
1055 | qla2x00_get_host_fabric_name(struct Scsi_Host *shost) | |
1056 | { | |
f363b943 | 1057 | scsi_qla_host_t *ha = shost_priv(shost); |
90991c85 AV |
1058 | u64 node_name; |
1059 | ||
1060 | if (ha->device_flags & SWITCH_FOUND) | |
1061 | node_name = wwn_to_u64(ha->fabric_node_name); | |
1062 | else | |
1063 | node_name = wwn_to_u64(ha->node_name); | |
1064 | ||
1065 | fc_host_fabric_name(shost) = node_name; | |
1066 | } | |
1067 | ||
7047fcdd AV |
1068 | static void |
1069 | qla2x00_get_host_port_state(struct Scsi_Host *shost) | |
1070 | { | |
da4541b6 | 1071 | scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost)); |
7047fcdd AV |
1072 | |
1073 | if (!ha->flags.online) | |
1074 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | |
1075 | else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) | |
1076 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
1077 | else | |
1078 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
1079 | } | |
1080 | ||
2c3dfe3f SJ |
1081 | static int |
1082 | qla24xx_vport_create(struct fc_vport *fc_vport, bool disable) | |
1083 | { | |
1084 | int ret = 0; | |
f363b943 | 1085 | scsi_qla_host_t *ha = shost_priv(fc_vport->shost); |
2c3dfe3f SJ |
1086 | scsi_qla_host_t *vha; |
1087 | ||
1088 | ret = qla24xx_vport_create_req_sanity_check(fc_vport); | |
1089 | if (ret) { | |
1090 | DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, " | |
1091 | "status %x\n", ret)); | |
1092 | return (ret); | |
1093 | } | |
1094 | ||
1095 | vha = qla24xx_create_vhost(fc_vport); | |
1096 | if (vha == NULL) { | |
1097 | DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n", | |
1098 | vha)); | |
1099 | return FC_VPORT_FAILED; | |
1100 | } | |
1101 | if (disable) { | |
1102 | atomic_set(&vha->vp_state, VP_OFFLINE); | |
1103 | fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); | |
1104 | } else | |
1105 | atomic_set(&vha->vp_state, VP_FAILED); | |
1106 | ||
1107 | /* ready to create vport */ | |
1108 | qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx); | |
1109 | ||
1110 | /* initialized vport states */ | |
1111 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
1112 | vha->vp_err_state= VP_ERR_PORTDWN; | |
1113 | vha->vp_prev_err_state= VP_ERR_UNKWN; | |
1114 | /* Check if physical ha port is Up */ | |
1115 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || | |
1116 | atomic_read(&ha->loop_state) == LOOP_DEAD) { | |
1117 | /* Don't retry or attempt login of this virtual port */ | |
1118 | DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n", | |
1119 | vha->host_no)); | |
1120 | atomic_set(&vha->loop_state, LOOP_DEAD); | |
1121 | if (!disable) | |
1122 | fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN); | |
1123 | } | |
1124 | ||
1125 | if (scsi_add_host(vha->host, &fc_vport->dev)) { | |
1126 | DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n", | |
1127 | vha->host_no, vha->vp_idx)); | |
1128 | goto vport_create_failed_2; | |
1129 | } | |
1130 | ||
1131 | /* initialize attributes */ | |
1132 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); | |
1133 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); | |
1134 | fc_host_supported_classes(vha->host) = | |
1135 | fc_host_supported_classes(ha->host); | |
1136 | fc_host_supported_speeds(vha->host) = | |
1137 | fc_host_supported_speeds(ha->host); | |
1138 | ||
1139 | qla24xx_vport_disable(fc_vport, disable); | |
1140 | ||
1141 | return 0; | |
1142 | vport_create_failed_2: | |
1143 | qla24xx_disable_vp(vha); | |
1144 | qla24xx_deallocate_vp_id(vha); | |
1145 | kfree(vha->port_name); | |
1146 | kfree(vha->node_name); | |
1147 | scsi_host_put(vha->host); | |
1148 | return FC_VPORT_FAILED; | |
1149 | } | |
1150 | ||
a824ebb3 | 1151 | static int |
2c3dfe3f SJ |
1152 | qla24xx_vport_delete(struct fc_vport *fc_vport) |
1153 | { | |
f363b943 | 1154 | scsi_qla_host_t *ha = shost_priv(fc_vport->shost); |
2c3dfe3f SJ |
1155 | scsi_qla_host_t *vha = fc_vport->dd_data; |
1156 | ||
1157 | qla24xx_disable_vp(vha); | |
1158 | qla24xx_deallocate_vp_id(vha); | |
1159 | ||
1160 | down(&ha->vport_sem); | |
1161 | ha->cur_vport_count--; | |
eb66dc60 | 1162 | clear_bit(vha->vp_idx, ha->vp_idx_map); |
2c3dfe3f SJ |
1163 | up(&ha->vport_sem); |
1164 | ||
1165 | kfree(vha->node_name); | |
1166 | kfree(vha->port_name); | |
1167 | ||
1168 | if (vha->timer_active) { | |
1169 | qla2x00_vp_stop_timer(vha); | |
1170 | DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p " | |
1171 | "has stopped\n", | |
1172 | vha->host_no, vha->vp_idx, vha)); | |
1173 | } | |
1174 | ||
1175 | fc_remove_host(vha->host); | |
1176 | ||
1177 | scsi_remove_host(vha->host); | |
1178 | ||
1179 | scsi_host_put(vha->host); | |
1180 | ||
1181 | return 0; | |
1182 | } | |
1183 | ||
a824ebb3 | 1184 | static int |
2c3dfe3f SJ |
1185 | qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable) |
1186 | { | |
1187 | scsi_qla_host_t *vha = fc_vport->dd_data; | |
1188 | ||
1189 | if (disable) | |
1190 | qla24xx_disable_vp(vha); | |
1191 | else | |
1192 | qla24xx_enable_vp(vha); | |
1193 | ||
1194 | return 0; | |
1195 | } | |
1196 | ||
1c97a12a | 1197 | struct fc_function_template qla2xxx_transport_functions = { |
8482e118 AV |
1198 | |
1199 | .show_host_node_name = 1, | |
1200 | .show_host_port_name = 1, | |
ad3e0eda | 1201 | .show_host_supported_classes = 1, |
2ae2b370 | 1202 | .show_host_supported_speeds = 1, |
ad3e0eda | 1203 | |
8482e118 AV |
1204 | .get_host_port_id = qla2x00_get_host_port_id, |
1205 | .show_host_port_id = 1, | |
04414013 AV |
1206 | .get_host_speed = qla2x00_get_host_speed, |
1207 | .show_host_speed = 1, | |
8d067623 AV |
1208 | .get_host_port_type = qla2x00_get_host_port_type, |
1209 | .show_host_port_type = 1, | |
1620f7c2 AV |
1210 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
1211 | .show_host_symbolic_name = 1, | |
a740a3f0 AV |
1212 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
1213 | .show_host_system_hostname = 1, | |
90991c85 AV |
1214 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
1215 | .show_host_fabric_name = 1, | |
7047fcdd AV |
1216 | .get_host_port_state = qla2x00_get_host_port_state, |
1217 | .show_host_port_state = 1, | |
8482e118 | 1218 | |
bdf79621 | 1219 | .dd_fcrport_size = sizeof(struct fc_port *), |
ad3e0eda | 1220 | .show_rport_supported_classes = 1, |
8482e118 AV |
1221 | |
1222 | .get_starget_node_name = qla2x00_get_starget_node_name, | |
1223 | .show_starget_node_name = 1, | |
1224 | .get_starget_port_name = qla2x00_get_starget_port_name, | |
1225 | .show_starget_port_name = 1, | |
1226 | .get_starget_port_id = qla2x00_get_starget_port_id, | |
1227 | .show_starget_port_id = 1, | |
1228 | ||
1229 | .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo, | |
1230 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, | |
1231 | .show_rport_dev_loss_tmo = 1, | |
1232 | ||
91ca7b01 | 1233 | .issue_fc_host_lip = qla2x00_issue_lip, |
392e2f65 | 1234 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
2c3dfe3f SJ |
1235 | |
1236 | .vport_create = qla24xx_vport_create, | |
1237 | .vport_disable = qla24xx_vport_disable, | |
1238 | .vport_delete = qla24xx_vport_delete, | |
1239 | }; | |
1240 | ||
1241 | struct fc_function_template qla2xxx_transport_vport_functions = { | |
1242 | ||
1243 | .show_host_node_name = 1, | |
1244 | .show_host_port_name = 1, | |
1245 | .show_host_supported_classes = 1, | |
1246 | ||
1247 | .get_host_port_id = qla2x00_get_host_port_id, | |
1248 | .show_host_port_id = 1, | |
1249 | .get_host_speed = qla2x00_get_host_speed, | |
1250 | .show_host_speed = 1, | |
1251 | .get_host_port_type = qla2x00_get_host_port_type, | |
1252 | .show_host_port_type = 1, | |
1253 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, | |
1254 | .show_host_symbolic_name = 1, | |
1255 | .set_host_system_hostname = qla2x00_set_host_system_hostname, | |
1256 | .show_host_system_hostname = 1, | |
1257 | .get_host_fabric_name = qla2x00_get_host_fabric_name, | |
1258 | .show_host_fabric_name = 1, | |
1259 | .get_host_port_state = qla2x00_get_host_port_state, | |
1260 | .show_host_port_state = 1, | |
1261 | ||
1262 | .dd_fcrport_size = sizeof(struct fc_port *), | |
1263 | .show_rport_supported_classes = 1, | |
1264 | ||
1265 | .get_starget_node_name = qla2x00_get_starget_node_name, | |
1266 | .show_starget_node_name = 1, | |
1267 | .get_starget_port_name = qla2x00_get_starget_port_name, | |
1268 | .show_starget_port_name = 1, | |
1269 | .get_starget_port_id = qla2x00_get_starget_port_id, | |
1270 | .show_starget_port_id = 1, | |
1271 | ||
1272 | .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo, | |
1273 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, | |
1274 | .show_rport_dev_loss_tmo = 1, | |
1275 | ||
1276 | .issue_fc_host_lip = qla2x00_issue_lip, | |
1277 | .get_fc_host_stats = qla2x00_get_fc_host_stats, | |
8482e118 AV |
1278 | }; |
1279 | ||
8482e118 AV |
1280 | void |
1281 | qla2x00_init_host_attr(scsi_qla_host_t *ha) | |
1282 | { | |
2ae2b370 AV |
1283 | u32 speed = FC_PORTSPEED_UNKNOWN; |
1284 | ||
dad9c8c1 AV |
1285 | fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name); |
1286 | fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name); | |
ad3e0eda | 1287 | fc_host_supported_classes(ha->host) = FC_COS_CLASS3; |
4d0ea247 | 1288 | fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;; |
2c3dfe3f | 1289 | fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count; |
2ae2b370 AV |
1290 | |
1291 | if (IS_QLA25XX(ha)) | |
1292 | speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | | |
1293 | FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; | |
4d4df193 | 1294 | else if (IS_QLA24XX_TYPE(ha)) |
2ae2b370 AV |
1295 | speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT | |
1296 | FC_PORTSPEED_1GBIT; | |
1297 | else if (IS_QLA23XX(ha)) | |
1298 | speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; | |
1299 | else | |
1300 | speed = FC_PORTSPEED_1GBIT; | |
1301 | fc_host_supported_speeds(ha->host) = speed; | |
8482e118 | 1302 | } |