]>
Commit | Line | Data |
---|---|---|
8482e118 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
de7c5d05 | 3 | * Copyright (c) 2003-2010 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> |
5a0e3ad6 | 11 | #include <linux/slab.h> |
00eabe7c | 12 | #include <linux/delay.h> |
8482e118 | 13 | |
a824ebb3 | 14 | static int qla24xx_vport_disable(struct fc_vport *, bool); |
6e98016c | 15 | |
8482e118 AV |
16 | /* SYSFS attributes --------------------------------------------------------- */ |
17 | ||
18 | static ssize_t | |
2c3c8bea | 19 | qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
20 | struct bin_attribute *bin_attr, |
21 | char *buf, loff_t off, size_t count) | |
8482e118 | 22 | { |
7b867cf7 | 23 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 24 | struct device, kobj))); |
7b867cf7 | 25 | struct qla_hw_data *ha = vha->hw; |
8482e118 AV |
26 | |
27 | if (ha->fw_dump_reading == 0) | |
28 | return 0; | |
8482e118 | 29 | |
b3dc9088 AM |
30 | return memory_read_from_buffer(buf, count, &off, ha->fw_dump, |
31 | ha->fw_dump_len); | |
8482e118 AV |
32 | } |
33 | ||
34 | static ssize_t | |
2c3c8bea | 35 | qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
36 | struct bin_attribute *bin_attr, |
37 | char *buf, loff_t off, size_t count) | |
8482e118 | 38 | { |
7b867cf7 | 39 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 40 | struct device, kobj))); |
7b867cf7 | 41 | struct qla_hw_data *ha = vha->hw; |
8482e118 | 42 | int reading; |
8482e118 | 43 | |
a9083016 GM |
44 | if (IS_QLA82XX(ha)) { |
45 | DEBUG2(qla_printk(KERN_INFO, ha, | |
46 | "Firmware dump not supported for ISP82xx\n")); | |
47 | return count; | |
48 | } | |
49 | ||
8482e118 AV |
50 | if (off != 0) |
51 | return (0); | |
52 | ||
53 | reading = simple_strtol(buf, NULL, 10); | |
54 | switch (reading) { | |
55 | case 0: | |
a7a167bf AV |
56 | if (!ha->fw_dump_reading) |
57 | break; | |
8482e118 | 58 | |
a7a167bf | 59 | qla_printk(KERN_INFO, ha, |
7b867cf7 | 60 | "Firmware dump cleared on (%ld).\n", vha->host_no); |
a7a167bf AV |
61 | |
62 | ha->fw_dump_reading = 0; | |
63 | ha->fw_dumped = 0; | |
8482e118 AV |
64 | break; |
65 | case 1: | |
d4e3e04d | 66 | if (ha->fw_dumped && !ha->fw_dump_reading) { |
8482e118 AV |
67 | ha->fw_dump_reading = 1; |
68 | ||
8482e118 | 69 | qla_printk(KERN_INFO, ha, |
a7a167bf | 70 | "Raw firmware dump ready for read on (%ld).\n", |
7b867cf7 | 71 | vha->host_no); |
8482e118 AV |
72 | } |
73 | break; | |
a7a167bf | 74 | case 2: |
7b867cf7 | 75 | qla2x00_alloc_fw_dump(vha); |
a7a167bf | 76 | break; |
68af0811 | 77 | case 3: |
7b867cf7 | 78 | qla2x00_system_error(vha); |
68af0811 | 79 | break; |
8482e118 AV |
80 | } |
81 | return (count); | |
82 | } | |
83 | ||
84 | static struct bin_attribute sysfs_fw_dump_attr = { | |
85 | .attr = { | |
86 | .name = "fw_dump", | |
87 | .mode = S_IRUSR | S_IWUSR, | |
8482e118 AV |
88 | }, |
89 | .size = 0, | |
90 | .read = qla2x00_sysfs_read_fw_dump, | |
91 | .write = qla2x00_sysfs_write_fw_dump, | |
92 | }; | |
93 | ||
94 | static ssize_t | |
2c3c8bea | 95 | qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
96 | struct bin_attribute *bin_attr, |
97 | char *buf, loff_t off, size_t count) | |
8482e118 | 98 | { |
7b867cf7 | 99 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 100 | struct device, kobj))); |
7b867cf7 | 101 | struct qla_hw_data *ha = vha->hw; |
8482e118 | 102 | |
b3dc9088 | 103 | if (!capable(CAP_SYS_ADMIN)) |
8482e118 AV |
104 | return 0; |
105 | ||
6749ce36 | 106 | if (IS_NOCACHE_VPD_TYPE(ha)) |
8f979751 | 107 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
6749ce36 | 108 | ha->nvram_size); |
b3dc9088 AM |
109 | return memory_read_from_buffer(buf, count, &off, ha->nvram, |
110 | ha->nvram_size); | |
8482e118 AV |
111 | } |
112 | ||
113 | static ssize_t | |
2c3c8bea | 114 | qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
115 | struct bin_attribute *bin_attr, |
116 | char *buf, loff_t off, size_t count) | |
8482e118 | 117 | { |
7b867cf7 | 118 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
8482e118 | 119 | struct device, kobj))); |
7b867cf7 | 120 | struct qla_hw_data *ha = vha->hw; |
8482e118 | 121 | uint16_t cnt; |
8482e118 | 122 | |
3d79038f AV |
123 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size || |
124 | !ha->isp_ops->write_nvram) | |
8482e118 AV |
125 | return 0; |
126 | ||
127 | /* Checksum NVRAM. */ | |
e428924c | 128 | if (IS_FWI2_CAPABLE(ha)) { |
459c5378 AV |
129 | uint32_t *iter; |
130 | uint32_t chksum; | |
131 | ||
132 | iter = (uint32_t *)buf; | |
133 | chksum = 0; | |
134 | for (cnt = 0; cnt < ((count >> 2) - 1); cnt++) | |
135 | chksum += le32_to_cpu(*iter++); | |
136 | chksum = ~chksum + 1; | |
137 | *iter = cpu_to_le32(chksum); | |
138 | } else { | |
139 | uint8_t *iter; | |
140 | uint8_t chksum; | |
141 | ||
142 | iter = (uint8_t *)buf; | |
143 | chksum = 0; | |
144 | for (cnt = 0; cnt < count - 1; cnt++) | |
145 | chksum += *iter++; | |
146 | chksum = ~chksum + 1; | |
147 | *iter = chksum; | |
148 | } | |
8482e118 | 149 | |
2533cf67 LC |
150 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
151 | qla_printk(KERN_WARNING, ha, | |
152 | "HBA not online, failing NVRAM update.\n"); | |
153 | return -EAGAIN; | |
154 | } | |
155 | ||
8482e118 | 156 | /* Write NVRAM. */ |
7b867cf7 AC |
157 | ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count); |
158 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base, | |
281afe19 | 159 | count); |
8482e118 | 160 | |
2533cf67 | 161 | /* NVRAM settings take effect immediately. */ |
7b867cf7 | 162 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
2533cf67 LC |
163 | qla2xxx_wake_dpc(vha); |
164 | qla2x00_wait_for_chip_reset(vha); | |
26b8d348 | 165 | |
8482e118 AV |
166 | return (count); |
167 | } | |
168 | ||
169 | static struct bin_attribute sysfs_nvram_attr = { | |
170 | .attr = { | |
171 | .name = "nvram", | |
172 | .mode = S_IRUSR | S_IWUSR, | |
8482e118 | 173 | }, |
1b3f6365 | 174 | .size = 512, |
8482e118 AV |
175 | .read = qla2x00_sysfs_read_nvram, |
176 | .write = qla2x00_sysfs_write_nvram, | |
177 | }; | |
178 | ||
854165f4 | 179 | static ssize_t |
2c3c8bea | 180 | qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
181 | struct bin_attribute *bin_attr, |
182 | char *buf, loff_t off, size_t count) | |
854165f4 | 183 | { |
7b867cf7 | 184 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 185 | struct device, kobj))); |
7b867cf7 | 186 | struct qla_hw_data *ha = vha->hw; |
854165f4 AV |
187 | |
188 | if (ha->optrom_state != QLA_SREADING) | |
189 | return 0; | |
854165f4 | 190 | |
b3dc9088 AM |
191 | return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer, |
192 | ha->optrom_region_size); | |
854165f4 AV |
193 | } |
194 | ||
195 | static ssize_t | |
2c3c8bea | 196 | qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
197 | struct bin_attribute *bin_attr, |
198 | char *buf, loff_t off, size_t count) | |
854165f4 | 199 | { |
7b867cf7 | 200 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 201 | struct device, kobj))); |
7b867cf7 | 202 | struct qla_hw_data *ha = vha->hw; |
854165f4 AV |
203 | |
204 | if (ha->optrom_state != QLA_SWRITING) | |
205 | return -EINVAL; | |
b7cc176c | 206 | if (off > ha->optrom_region_size) |
854165f4 | 207 | return -ERANGE; |
b7cc176c JC |
208 | if (off + count > ha->optrom_region_size) |
209 | count = ha->optrom_region_size - off; | |
854165f4 AV |
210 | |
211 | memcpy(&ha->optrom_buffer[off], buf, count); | |
212 | ||
213 | return count; | |
214 | } | |
215 | ||
216 | static struct bin_attribute sysfs_optrom_attr = { | |
217 | .attr = { | |
218 | .name = "optrom", | |
219 | .mode = S_IRUSR | S_IWUSR, | |
854165f4 | 220 | }, |
c3a2f0df | 221 | .size = 0, |
854165f4 AV |
222 | .read = qla2x00_sysfs_read_optrom, |
223 | .write = qla2x00_sysfs_write_optrom, | |
224 | }; | |
225 | ||
226 | static ssize_t | |
2c3c8bea | 227 | qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
228 | struct bin_attribute *bin_attr, |
229 | char *buf, loff_t off, size_t count) | |
854165f4 | 230 | { |
7b867cf7 | 231 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
854165f4 | 232 | struct device, kobj))); |
7b867cf7 AC |
233 | struct qla_hw_data *ha = vha->hw; |
234 | ||
b7cc176c JC |
235 | uint32_t start = 0; |
236 | uint32_t size = ha->optrom_size; | |
237 | int val, valid; | |
854165f4 AV |
238 | |
239 | if (off) | |
240 | return 0; | |
241 | ||
85880801 AV |
242 | if (unlikely(pci_channel_offline(ha->pdev))) |
243 | return 0; | |
244 | ||
b7cc176c JC |
245 | if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1) |
246 | return -EINVAL; | |
247 | if (start > ha->optrom_size) | |
854165f4 AV |
248 | return -EINVAL; |
249 | ||
250 | switch (val) { | |
251 | case 0: | |
252 | if (ha->optrom_state != QLA_SREADING && | |
253 | ha->optrom_state != QLA_SWRITING) | |
254 | break; | |
255 | ||
256 | ha->optrom_state = QLA_SWAITING; | |
b7cc176c JC |
257 | |
258 | DEBUG2(qla_printk(KERN_INFO, ha, | |
259 | "Freeing flash region allocation -- 0x%x bytes.\n", | |
260 | ha->optrom_region_size)); | |
261 | ||
854165f4 AV |
262 | vfree(ha->optrom_buffer); |
263 | ha->optrom_buffer = NULL; | |
264 | break; | |
265 | case 1: | |
266 | if (ha->optrom_state != QLA_SWAITING) | |
267 | break; | |
268 | ||
b7cc176c JC |
269 | ha->optrom_region_start = start; |
270 | ha->optrom_region_size = start + size > ha->optrom_size ? | |
271 | ha->optrom_size - start : size; | |
272 | ||
854165f4 | 273 | ha->optrom_state = QLA_SREADING; |
b7cc176c | 274 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
854165f4 AV |
275 | if (ha->optrom_buffer == NULL) { |
276 | qla_printk(KERN_WARNING, ha, | |
277 | "Unable to allocate memory for optrom retrieval " | |
b7cc176c | 278 | "(%x).\n", ha->optrom_region_size); |
854165f4 AV |
279 | |
280 | ha->optrom_state = QLA_SWAITING; | |
281 | return count; | |
282 | } | |
283 | ||
86fbee86 LC |
284 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
285 | qla_printk(KERN_WARNING, ha, | |
286 | "HBA not online, failing NVRAM update.\n"); | |
287 | return -EAGAIN; | |
288 | } | |
289 | ||
b7cc176c JC |
290 | DEBUG2(qla_printk(KERN_INFO, ha, |
291 | "Reading flash region -- 0x%x/0x%x.\n", | |
292 | ha->optrom_region_start, ha->optrom_region_size)); | |
293 | ||
294 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); | |
7b867cf7 | 295 | ha->isp_ops->read_optrom(vha, ha->optrom_buffer, |
b7cc176c | 296 | ha->optrom_region_start, ha->optrom_region_size); |
854165f4 AV |
297 | break; |
298 | case 2: | |
299 | if (ha->optrom_state != QLA_SWAITING) | |
300 | break; | |
301 | ||
b7cc176c JC |
302 | /* |
303 | * We need to be more restrictive on which FLASH regions are | |
304 | * allowed to be updated via user-space. Regions accessible | |
305 | * via this method include: | |
306 | * | |
307 | * ISP21xx/ISP22xx/ISP23xx type boards: | |
308 | * | |
309 | * 0x000000 -> 0x020000 -- Boot code. | |
310 | * | |
311 | * ISP2322/ISP24xx type boards: | |
312 | * | |
313 | * 0x000000 -> 0x07ffff -- Boot code. | |
314 | * 0x080000 -> 0x0fffff -- Firmware. | |
315 | * | |
316 | * ISP25xx type boards: | |
317 | * | |
318 | * 0x000000 -> 0x07ffff -- Boot code. | |
319 | * 0x080000 -> 0x0fffff -- Firmware. | |
320 | * 0x120000 -> 0x12ffff -- VPD and HBA parameters. | |
321 | */ | |
322 | valid = 0; | |
323 | if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0) | |
324 | valid = 1; | |
c00d8994 AV |
325 | else if (start == (ha->flt_region_boot * 4) || |
326 | start == (ha->flt_region_fw * 4)) | |
b7cc176c | 327 | valid = 1; |
a9083016 GM |
328 | else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha)) |
329 | valid = 1; | |
b7cc176c JC |
330 | if (!valid) { |
331 | qla_printk(KERN_WARNING, ha, | |
332 | "Invalid start region 0x%x/0x%x.\n", start, size); | |
333 | return -EINVAL; | |
334 | } | |
335 | ||
336 | ha->optrom_region_start = start; | |
337 | ha->optrom_region_size = start + size > ha->optrom_size ? | |
338 | ha->optrom_size - start : size; | |
339 | ||
854165f4 | 340 | ha->optrom_state = QLA_SWRITING; |
b7cc176c | 341 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); |
854165f4 AV |
342 | if (ha->optrom_buffer == NULL) { |
343 | qla_printk(KERN_WARNING, ha, | |
344 | "Unable to allocate memory for optrom update " | |
b7cc176c | 345 | "(%x).\n", ha->optrom_region_size); |
854165f4 AV |
346 | |
347 | ha->optrom_state = QLA_SWAITING; | |
348 | return count; | |
349 | } | |
b7cc176c JC |
350 | |
351 | DEBUG2(qla_printk(KERN_INFO, ha, | |
352 | "Staging flash region write -- 0x%x/0x%x.\n", | |
353 | ha->optrom_region_start, ha->optrom_region_size)); | |
354 | ||
355 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); | |
854165f4 AV |
356 | break; |
357 | case 3: | |
358 | if (ha->optrom_state != QLA_SWRITING) | |
359 | break; | |
360 | ||
2533cf67 LC |
361 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
362 | qla_printk(KERN_WARNING, ha, | |
363 | "HBA not online, failing flash update.\n"); | |
364 | return -EAGAIN; | |
365 | } | |
366 | ||
b7cc176c JC |
367 | DEBUG2(qla_printk(KERN_INFO, ha, |
368 | "Writing flash region -- 0x%x/0x%x.\n", | |
369 | ha->optrom_region_start, ha->optrom_region_size)); | |
370 | ||
7b867cf7 | 371 | ha->isp_ops->write_optrom(vha, ha->optrom_buffer, |
b7cc176c | 372 | ha->optrom_region_start, ha->optrom_region_size); |
854165f4 | 373 | break; |
b7cc176c JC |
374 | default: |
375 | count = -EINVAL; | |
854165f4 AV |
376 | } |
377 | return count; | |
378 | } | |
379 | ||
380 | static struct bin_attribute sysfs_optrom_ctl_attr = { | |
381 | .attr = { | |
382 | .name = "optrom_ctl", | |
383 | .mode = S_IWUSR, | |
854165f4 AV |
384 | }, |
385 | .size = 0, | |
386 | .write = qla2x00_sysfs_write_optrom_ctl, | |
387 | }; | |
388 | ||
6f641790 | 389 | static ssize_t |
2c3c8bea | 390 | qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
391 | struct bin_attribute *bin_attr, |
392 | char *buf, loff_t off, size_t count) | |
6f641790 | 393 | { |
7b867cf7 | 394 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
6f641790 | 395 | struct device, kobj))); |
7b867cf7 | 396 | struct qla_hw_data *ha = vha->hw; |
6f641790 | 397 | |
85880801 AV |
398 | if (unlikely(pci_channel_offline(ha->pdev))) |
399 | return 0; | |
400 | ||
b3dc9088 | 401 | if (!capable(CAP_SYS_ADMIN)) |
6f641790 AV |
402 | return 0; |
403 | ||
6749ce36 AV |
404 | if (IS_NOCACHE_VPD_TYPE(ha)) |
405 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, | |
406 | ha->vpd_size); | |
b3dc9088 | 407 | return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size); |
6f641790 AV |
408 | } |
409 | ||
410 | static ssize_t | |
2c3c8bea | 411 | qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
412 | struct bin_attribute *bin_attr, |
413 | char *buf, loff_t off, size_t count) | |
6f641790 | 414 | { |
7b867cf7 | 415 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
6f641790 | 416 | struct device, kobj))); |
7b867cf7 | 417 | struct qla_hw_data *ha = vha->hw; |
d0c3eefa | 418 | uint8_t *tmp_data; |
6f641790 | 419 | |
85880801 AV |
420 | if (unlikely(pci_channel_offline(ha->pdev))) |
421 | return 0; | |
422 | ||
3d79038f AV |
423 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size || |
424 | !ha->isp_ops->write_nvram) | |
6f641790 AV |
425 | return 0; |
426 | ||
2533cf67 LC |
427 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
428 | qla_printk(KERN_WARNING, ha, | |
429 | "HBA not online, failing VPD update.\n"); | |
430 | return -EAGAIN; | |
431 | } | |
432 | ||
6f641790 | 433 | /* Write NVRAM. */ |
7b867cf7 AC |
434 | ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count); |
435 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count); | |
6f641790 | 436 | |
d0c3eefa LC |
437 | /* Update flash version information for 4Gb & above. */ |
438 | if (!IS_FWI2_CAPABLE(ha)) | |
439 | goto done; | |
440 | ||
441 | tmp_data = vmalloc(256); | |
442 | if (!tmp_data) { | |
443 | qla_printk(KERN_WARNING, ha, | |
444 | "Unable to allocate memory for VPD information update.\n"); | |
445 | goto done; | |
446 | } | |
447 | ha->isp_ops->get_flash_version(vha, tmp_data); | |
448 | vfree(tmp_data); | |
449 | done: | |
6f641790 AV |
450 | return count; |
451 | } | |
452 | ||
453 | static struct bin_attribute sysfs_vpd_attr = { | |
454 | .attr = { | |
455 | .name = "vpd", | |
456 | .mode = S_IRUSR | S_IWUSR, | |
6f641790 AV |
457 | }, |
458 | .size = 0, | |
459 | .read = qla2x00_sysfs_read_vpd, | |
460 | .write = qla2x00_sysfs_write_vpd, | |
461 | }; | |
462 | ||
88729e53 | 463 | static ssize_t |
2c3c8bea | 464 | qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
465 | struct bin_attribute *bin_attr, |
466 | char *buf, loff_t off, size_t count) | |
88729e53 | 467 | { |
7b867cf7 | 468 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, |
88729e53 | 469 | struct device, kobj))); |
7b867cf7 | 470 | struct qla_hw_data *ha = vha->hw; |
88729e53 AV |
471 | uint16_t iter, addr, offset; |
472 | int rval; | |
473 | ||
474 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2) | |
475 | return 0; | |
476 | ||
e8711085 AV |
477 | if (ha->sfp_data) |
478 | goto do_read; | |
479 | ||
480 | ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
481 | &ha->sfp_data_dma); | |
482 | if (!ha->sfp_data) { | |
483 | qla_printk(KERN_WARNING, ha, | |
484 | "Unable to allocate memory for SFP read-data.\n"); | |
485 | return 0; | |
486 | } | |
487 | ||
488 | do_read: | |
489 | memset(ha->sfp_data, 0, SFP_BLOCK_SIZE); | |
88729e53 AV |
490 | addr = 0xa0; |
491 | for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE; | |
492 | iter++, offset += SFP_BLOCK_SIZE) { | |
493 | if (iter == 4) { | |
494 | /* Skip to next device address. */ | |
495 | addr = 0xa2; | |
496 | offset = 0; | |
497 | } | |
498 | ||
7b867cf7 | 499 | rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset, |
88729e53 AV |
500 | SFP_BLOCK_SIZE); |
501 | if (rval != QLA_SUCCESS) { | |
502 | qla_printk(KERN_WARNING, ha, | |
503 | "Unable to read SFP data (%x/%x/%x).\n", rval, | |
504 | addr, offset); | |
505 | count = 0; | |
506 | break; | |
507 | } | |
508 | memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE); | |
509 | buf += SFP_BLOCK_SIZE; | |
510 | } | |
511 | ||
512 | return count; | |
513 | } | |
514 | ||
515 | static struct bin_attribute sysfs_sfp_attr = { | |
516 | .attr = { | |
517 | .name = "sfp", | |
518 | .mode = S_IRUSR | S_IWUSR, | |
88729e53 AV |
519 | }, |
520 | .size = SFP_DEV_SIZE * 2, | |
521 | .read = qla2x00_sysfs_read_sfp, | |
522 | }; | |
523 | ||
6e181be5 | 524 | static ssize_t |
2c3c8bea | 525 | qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj, |
6e181be5 LC |
526 | struct bin_attribute *bin_attr, |
527 | char *buf, loff_t off, size_t count) | |
528 | { | |
529 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
530 | struct device, kobj))); | |
531 | struct qla_hw_data *ha = vha->hw; | |
a9083016 | 532 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
6e181be5 LC |
533 | int type; |
534 | ||
535 | if (off != 0) | |
536 | return 0; | |
537 | ||
538 | type = simple_strtol(buf, NULL, 10); | |
539 | switch (type) { | |
540 | case 0x2025c: | |
541 | qla_printk(KERN_INFO, ha, | |
542 | "Issuing ISP reset on (%ld).\n", vha->host_no); | |
543 | ||
544 | scsi_block_requests(vha->host); | |
545 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | |
546 | qla2xxx_wake_dpc(vha); | |
547 | qla2x00_wait_for_chip_reset(vha); | |
548 | scsi_unblock_requests(vha->host); | |
549 | break; | |
550 | case 0x2025d: | |
551 | if (!IS_QLA81XX(ha)) | |
552 | break; | |
553 | ||
554 | qla_printk(KERN_INFO, ha, | |
555 | "Issuing MPI reset on (%ld).\n", vha->host_no); | |
556 | ||
557 | /* Make sure FC side is not in reset */ | |
558 | qla2x00_wait_for_hba_online(vha); | |
559 | ||
560 | /* Issue MPI reset */ | |
561 | scsi_block_requests(vha->host); | |
562 | if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS) | |
563 | qla_printk(KERN_WARNING, ha, | |
564 | "MPI reset failed on (%ld).\n", vha->host_no); | |
565 | scsi_unblock_requests(vha->host); | |
566 | break; | |
a9083016 GM |
567 | case 0x2025e: |
568 | if (!IS_QLA82XX(ha) || vha != base_vha) { | |
569 | qla_printk(KERN_INFO, ha, | |
570 | "FCoE ctx reset not supported for host%ld.\n", | |
571 | vha->host_no); | |
572 | return count; | |
573 | } | |
574 | ||
575 | qla_printk(KERN_INFO, ha, | |
576 | "Issuing FCoE CTX reset on host%ld.\n", vha->host_no); | |
577 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); | |
578 | qla2xxx_wake_dpc(vha); | |
579 | qla2x00_wait_for_fcoe_ctx_reset(vha); | |
580 | break; | |
6e181be5 LC |
581 | } |
582 | return count; | |
583 | } | |
584 | ||
585 | static struct bin_attribute sysfs_reset_attr = { | |
586 | .attr = { | |
587 | .name = "reset", | |
588 | .mode = S_IWUSR, | |
589 | }, | |
590 | .size = 0, | |
591 | .write = qla2x00_sysfs_write_reset, | |
592 | }; | |
593 | ||
ad0ecd61 | 594 | static ssize_t |
2c3c8bea | 595 | qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj, |
ad0ecd61 JC |
596 | struct bin_attribute *bin_attr, |
597 | char *buf, loff_t off, size_t count) | |
598 | { | |
599 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
600 | struct device, kobj))); | |
601 | struct qla_hw_data *ha = vha->hw; | |
602 | uint16_t dev, adr, opt, len; | |
603 | int rval; | |
604 | ||
605 | ha->edc_data_len = 0; | |
606 | ||
607 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8) | |
608 | return 0; | |
609 | ||
610 | if (!ha->edc_data) { | |
611 | ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
612 | &ha->edc_data_dma); | |
613 | if (!ha->edc_data) { | |
614 | DEBUG2(qla_printk(KERN_INFO, ha, | |
615 | "Unable to allocate memory for EDC write.\n")); | |
616 | return 0; | |
617 | } | |
618 | } | |
619 | ||
620 | dev = le16_to_cpup((void *)&buf[0]); | |
621 | adr = le16_to_cpup((void *)&buf[2]); | |
622 | opt = le16_to_cpup((void *)&buf[4]); | |
623 | len = le16_to_cpup((void *)&buf[6]); | |
624 | ||
625 | if (!(opt & BIT_0)) | |
626 | if (len == 0 || len > DMA_POOL_SIZE || len > count - 8) | |
627 | return -EINVAL; | |
628 | ||
629 | memcpy(ha->edc_data, &buf[8], len); | |
630 | ||
631 | rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma, | |
632 | ha->edc_data, len, opt); | |
633 | if (rval != QLA_SUCCESS) { | |
634 | DEBUG2(qla_printk(KERN_INFO, ha, | |
635 | "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n", | |
636 | rval, dev, adr, opt, len, *buf)); | |
637 | return 0; | |
638 | } | |
639 | ||
640 | return count; | |
641 | } | |
642 | ||
643 | static struct bin_attribute sysfs_edc_attr = { | |
644 | .attr = { | |
645 | .name = "edc", | |
646 | .mode = S_IWUSR, | |
647 | }, | |
648 | .size = 0, | |
649 | .write = qla2x00_sysfs_write_edc, | |
650 | }; | |
651 | ||
652 | static ssize_t | |
2c3c8bea | 653 | qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj, |
ad0ecd61 JC |
654 | struct bin_attribute *bin_attr, |
655 | char *buf, loff_t off, size_t count) | |
656 | { | |
657 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
658 | struct device, kobj))); | |
659 | struct qla_hw_data *ha = vha->hw; | |
660 | uint16_t dev, adr, opt, len; | |
661 | int rval; | |
662 | ||
663 | ha->edc_data_len = 0; | |
664 | ||
665 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8) | |
666 | return 0; | |
667 | ||
668 | if (!ha->edc_data) { | |
669 | ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
670 | &ha->edc_data_dma); | |
671 | if (!ha->edc_data) { | |
672 | DEBUG2(qla_printk(KERN_INFO, ha, | |
673 | "Unable to allocate memory for EDC status.\n")); | |
674 | return 0; | |
675 | } | |
676 | } | |
677 | ||
678 | dev = le16_to_cpup((void *)&buf[0]); | |
679 | adr = le16_to_cpup((void *)&buf[2]); | |
680 | opt = le16_to_cpup((void *)&buf[4]); | |
681 | len = le16_to_cpup((void *)&buf[6]); | |
682 | ||
683 | if (!(opt & BIT_0)) | |
684 | if (len == 0 || len > DMA_POOL_SIZE) | |
685 | return -EINVAL; | |
686 | ||
687 | memset(ha->edc_data, 0, len); | |
688 | rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma, | |
689 | ha->edc_data, len, opt); | |
690 | if (rval != QLA_SUCCESS) { | |
691 | DEBUG2(qla_printk(KERN_INFO, ha, | |
692 | "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n", | |
693 | rval, dev, adr, opt, len)); | |
694 | return 0; | |
695 | } | |
696 | ||
697 | ha->edc_data_len = len; | |
698 | ||
699 | return count; | |
700 | } | |
701 | ||
702 | static ssize_t | |
2c3c8bea | 703 | qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj, |
ad0ecd61 JC |
704 | struct bin_attribute *bin_attr, |
705 | char *buf, loff_t off, size_t count) | |
706 | { | |
707 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
708 | struct device, kobj))); | |
709 | struct qla_hw_data *ha = vha->hw; | |
710 | ||
711 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0) | |
712 | return 0; | |
713 | ||
714 | if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count) | |
715 | return -EINVAL; | |
716 | ||
717 | memcpy(buf, ha->edc_data, ha->edc_data_len); | |
718 | ||
719 | return ha->edc_data_len; | |
720 | } | |
721 | ||
722 | static struct bin_attribute sysfs_edc_status_attr = { | |
723 | .attr = { | |
724 | .name = "edc_status", | |
725 | .mode = S_IRUSR | S_IWUSR, | |
726 | }, | |
727 | .size = 0, | |
728 | .write = qla2x00_sysfs_write_edc_status, | |
729 | .read = qla2x00_sysfs_read_edc_status, | |
730 | }; | |
731 | ||
ce0423f4 | 732 | static ssize_t |
2c3c8bea | 733 | qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj, |
ce0423f4 AV |
734 | struct bin_attribute *bin_attr, |
735 | char *buf, loff_t off, size_t count) | |
736 | { | |
737 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
738 | struct device, kobj))); | |
739 | struct qla_hw_data *ha = vha->hw; | |
740 | int rval; | |
741 | uint16_t actual_size; | |
742 | ||
743 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE) | |
744 | return 0; | |
745 | ||
746 | if (ha->xgmac_data) | |
747 | goto do_read; | |
748 | ||
749 | ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, | |
750 | &ha->xgmac_data_dma, GFP_KERNEL); | |
751 | if (!ha->xgmac_data) { | |
752 | qla_printk(KERN_WARNING, ha, | |
753 | "Unable to allocate memory for XGMAC read-data.\n"); | |
754 | return 0; | |
755 | } | |
756 | ||
757 | do_read: | |
758 | actual_size = 0; | |
759 | memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE); | |
760 | ||
761 | rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma, | |
762 | XGMAC_DATA_SIZE, &actual_size); | |
763 | if (rval != QLA_SUCCESS) { | |
764 | qla_printk(KERN_WARNING, ha, | |
765 | "Unable to read XGMAC data (%x).\n", rval); | |
766 | count = 0; | |
767 | } | |
768 | ||
769 | count = actual_size > count ? count: actual_size; | |
770 | memcpy(buf, ha->xgmac_data, count); | |
771 | ||
772 | return count; | |
773 | } | |
774 | ||
775 | static struct bin_attribute sysfs_xgmac_stats_attr = { | |
776 | .attr = { | |
777 | .name = "xgmac_stats", | |
778 | .mode = S_IRUSR, | |
779 | }, | |
780 | .size = 0, | |
781 | .read = qla2x00_sysfs_read_xgmac_stats, | |
782 | }; | |
783 | ||
11bbc1d8 | 784 | static ssize_t |
2c3c8bea | 785 | qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj, |
11bbc1d8 AV |
786 | struct bin_attribute *bin_attr, |
787 | char *buf, loff_t off, size_t count) | |
788 | { | |
789 | struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, | |
790 | struct device, kobj))); | |
791 | struct qla_hw_data *ha = vha->hw; | |
792 | int rval; | |
793 | uint16_t actual_size; | |
794 | ||
795 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE) | |
796 | return 0; | |
797 | ||
798 | if (ha->dcbx_tlv) | |
799 | goto do_read; | |
800 | ||
801 | ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, | |
802 | &ha->dcbx_tlv_dma, GFP_KERNEL); | |
803 | if (!ha->dcbx_tlv) { | |
804 | qla_printk(KERN_WARNING, ha, | |
805 | "Unable to allocate memory for DCBX TLV read-data.\n"); | |
806 | return 0; | |
807 | } | |
808 | ||
809 | do_read: | |
810 | actual_size = 0; | |
811 | memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE); | |
812 | ||
813 | rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma, | |
814 | DCBX_TLV_DATA_SIZE); | |
815 | if (rval != QLA_SUCCESS) { | |
816 | qla_printk(KERN_WARNING, ha, | |
817 | "Unable to read DCBX TLV data (%x).\n", rval); | |
818 | count = 0; | |
819 | } | |
820 | ||
821 | memcpy(buf, ha->dcbx_tlv, count); | |
822 | ||
823 | return count; | |
824 | } | |
825 | ||
826 | static struct bin_attribute sysfs_dcbx_tlv_attr = { | |
827 | .attr = { | |
828 | .name = "dcbx_tlv", | |
829 | .mode = S_IRUSR, | |
830 | }, | |
831 | .size = 0, | |
832 | .read = qla2x00_sysfs_read_dcbx_tlv, | |
833 | }; | |
834 | ||
f1663ad5 AV |
835 | static struct sysfs_entry { |
836 | char *name; | |
837 | struct bin_attribute *attr; | |
838 | int is4GBp_only; | |
839 | } bin_file_entries[] = { | |
840 | { "fw_dump", &sysfs_fw_dump_attr, }, | |
841 | { "nvram", &sysfs_nvram_attr, }, | |
842 | { "optrom", &sysfs_optrom_attr, }, | |
843 | { "optrom_ctl", &sysfs_optrom_ctl_attr, }, | |
844 | { "vpd", &sysfs_vpd_attr, 1 }, | |
845 | { "sfp", &sysfs_sfp_attr, 1 }, | |
6e181be5 | 846 | { "reset", &sysfs_reset_attr, }, |
ad0ecd61 JC |
847 | { "edc", &sysfs_edc_attr, 2 }, |
848 | { "edc_status", &sysfs_edc_status_attr, 2 }, | |
ce0423f4 | 849 | { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 }, |
11bbc1d8 | 850 | { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 }, |
46ddab7b | 851 | { NULL }, |
f1663ad5 AV |
852 | }; |
853 | ||
8482e118 | 854 | void |
7b867cf7 | 855 | qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha) |
8482e118 | 856 | { |
7b867cf7 | 857 | struct Scsi_Host *host = vha->host; |
f1663ad5 AV |
858 | struct sysfs_entry *iter; |
859 | int ret; | |
8482e118 | 860 | |
f1663ad5 | 861 | for (iter = bin_file_entries; iter->name; iter++) { |
7b867cf7 | 862 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw)) |
f1663ad5 | 863 | continue; |
ad0ecd61 JC |
864 | if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw)) |
865 | continue; | |
a9083016 | 866 | if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw))) |
ce0423f4 | 867 | continue; |
f1663ad5 AV |
868 | |
869 | ret = sysfs_create_bin_file(&host->shost_gendev.kobj, | |
870 | iter->attr); | |
871 | if (ret) | |
7b867cf7 | 872 | qla_printk(KERN_INFO, vha->hw, |
f1663ad5 AV |
873 | "Unable to create sysfs %s binary attribute " |
874 | "(%d).\n", iter->name, ret); | |
7914d004 | 875 | } |
8482e118 AV |
876 | } |
877 | ||
878 | void | |
7b867cf7 | 879 | qla2x00_free_sysfs_attr(scsi_qla_host_t *vha) |
8482e118 | 880 | { |
7b867cf7 | 881 | struct Scsi_Host *host = vha->host; |
f1663ad5 | 882 | struct sysfs_entry *iter; |
7b867cf7 | 883 | struct qla_hw_data *ha = vha->hw; |
f1663ad5 AV |
884 | |
885 | for (iter = bin_file_entries; iter->name; iter++) { | |
e428924c | 886 | if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha)) |
f1663ad5 | 887 | continue; |
ad0ecd61 JC |
888 | if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha)) |
889 | continue; | |
a9083016 | 890 | if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw))) |
ce0423f4 | 891 | continue; |
8482e118 | 892 | |
88729e53 | 893 | sysfs_remove_bin_file(&host->shost_gendev.kobj, |
f1663ad5 | 894 | iter->attr); |
7914d004 | 895 | } |
f6df144c AV |
896 | |
897 | if (ha->beacon_blink_led == 1) | |
7b867cf7 | 898 | ha->isp_ops->beacon_off(vha); |
8482e118 AV |
899 | } |
900 | ||
afb046e2 AV |
901 | /* Scsi_Host attributes. */ |
902 | ||
903 | static ssize_t | |
ee959b00 TJ |
904 | qla2x00_drvr_version_show(struct device *dev, |
905 | struct device_attribute *attr, char *buf) | |
afb046e2 AV |
906 | { |
907 | return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); | |
908 | } | |
909 | ||
910 | static ssize_t | |
ee959b00 TJ |
911 | qla2x00_fw_version_show(struct device *dev, |
912 | struct device_attribute *attr, char *buf) | |
afb046e2 | 913 | { |
7b867cf7 AC |
914 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
915 | struct qla_hw_data *ha = vha->hw; | |
916 | char fw_str[128]; | |
afb046e2 AV |
917 | |
918 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
7b867cf7 | 919 | ha->isp_ops->fw_version_str(vha, fw_str)); |
afb046e2 AV |
920 | } |
921 | ||
922 | static ssize_t | |
ee959b00 TJ |
923 | qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr, |
924 | char *buf) | |
afb046e2 | 925 | { |
7b867cf7 AC |
926 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
927 | struct qla_hw_data *ha = vha->hw; | |
afb046e2 AV |
928 | uint32_t sn; |
929 | ||
1ee27146 | 930 | if (IS_FWI2_CAPABLE(ha)) { |
7b867cf7 | 931 | qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE); |
1ee27146 JC |
932 | return snprintf(buf, PAGE_SIZE, "%s\n", buf); |
933 | } | |
8b7afc2a | 934 | |
afb046e2 AV |
935 | sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1; |
936 | return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000, | |
937 | sn % 100000); | |
938 | } | |
939 | ||
940 | static ssize_t | |
ee959b00 TJ |
941 | qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr, |
942 | char *buf) | |
afb046e2 | 943 | { |
7b867cf7 AC |
944 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
945 | return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device); | |
afb046e2 AV |
946 | } |
947 | ||
948 | static ssize_t | |
ee959b00 TJ |
949 | qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr, |
950 | char *buf) | |
afb046e2 | 951 | { |
7b867cf7 AC |
952 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
953 | struct qla_hw_data *ha = vha->hw; | |
afb046e2 AV |
954 | return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n", |
955 | ha->product_id[0], ha->product_id[1], ha->product_id[2], | |
956 | ha->product_id[3]); | |
957 | } | |
958 | ||
959 | static ssize_t | |
ee959b00 TJ |
960 | qla2x00_model_name_show(struct device *dev, struct device_attribute *attr, |
961 | char *buf) | |
afb046e2 | 962 | { |
7b867cf7 AC |
963 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
964 | return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number); | |
afb046e2 AV |
965 | } |
966 | ||
967 | static ssize_t | |
ee959b00 TJ |
968 | qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr, |
969 | char *buf) | |
afb046e2 | 970 | { |
7b867cf7 | 971 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
afb046e2 | 972 | return snprintf(buf, PAGE_SIZE, "%s\n", |
7b867cf7 | 973 | vha->hw->model_desc ? vha->hw->model_desc : ""); |
afb046e2 AV |
974 | } |
975 | ||
976 | static ssize_t | |
ee959b00 TJ |
977 | qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr, |
978 | char *buf) | |
afb046e2 | 979 | { |
7b867cf7 | 980 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
afb046e2 AV |
981 | char pci_info[30]; |
982 | ||
983 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
7b867cf7 | 984 | vha->hw->isp_ops->pci_info_str(vha, pci_info)); |
afb046e2 AV |
985 | } |
986 | ||
987 | static ssize_t | |
bbd1ae41 HR |
988 | qla2x00_link_state_show(struct device *dev, struct device_attribute *attr, |
989 | char *buf) | |
afb046e2 | 990 | { |
7b867cf7 AC |
991 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
992 | struct qla_hw_data *ha = vha->hw; | |
afb046e2 AV |
993 | int len = 0; |
994 | ||
7b867cf7 | 995 | if (atomic_read(&vha->loop_state) == LOOP_DOWN || |
62542f4b AV |
996 | atomic_read(&vha->loop_state) == LOOP_DEAD || |
997 | vha->device_flags & DFLG_NO_CABLE) | |
afb046e2 | 998 | len = snprintf(buf, PAGE_SIZE, "Link Down\n"); |
7b867cf7 AC |
999 | else if (atomic_read(&vha->loop_state) != LOOP_READY || |
1000 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
1001 | test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | |
afb046e2 AV |
1002 | len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n"); |
1003 | else { | |
1004 | len = snprintf(buf, PAGE_SIZE, "Link Up - "); | |
1005 | ||
1006 | switch (ha->current_topology) { | |
1007 | case ISP_CFG_NL: | |
1008 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
1009 | break; | |
1010 | case ISP_CFG_FL: | |
1011 | len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n"); | |
1012 | break; | |
1013 | case ISP_CFG_N: | |
1014 | len += snprintf(buf + len, PAGE_SIZE-len, | |
1015 | "N_Port to N_Port\n"); | |
1016 | break; | |
1017 | case ISP_CFG_F: | |
1018 | len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n"); | |
1019 | break; | |
1020 | default: | |
1021 | len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n"); | |
1022 | break; | |
1023 | } | |
1024 | } | |
1025 | return len; | |
1026 | } | |
1027 | ||
4fdfefe5 | 1028 | static ssize_t |
ee959b00 TJ |
1029 | qla2x00_zio_show(struct device *dev, struct device_attribute *attr, |
1030 | char *buf) | |
4fdfefe5 | 1031 | { |
7b867cf7 | 1032 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
1033 | int len = 0; |
1034 | ||
7b867cf7 | 1035 | switch (vha->hw->zio_mode) { |
4fdfefe5 AV |
1036 | case QLA_ZIO_MODE_6: |
1037 | len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n"); | |
1038 | break; | |
1039 | case QLA_ZIO_DISABLED: | |
1040 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
1041 | break; | |
1042 | } | |
1043 | return len; | |
1044 | } | |
1045 | ||
1046 | static ssize_t | |
ee959b00 TJ |
1047 | qla2x00_zio_store(struct device *dev, struct device_attribute *attr, |
1048 | const char *buf, size_t count) | |
4fdfefe5 | 1049 | { |
7b867cf7 AC |
1050 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1051 | struct qla_hw_data *ha = vha->hw; | |
4fdfefe5 AV |
1052 | int val = 0; |
1053 | uint16_t zio_mode; | |
1054 | ||
4a59f71d AV |
1055 | if (!IS_ZIO_SUPPORTED(ha)) |
1056 | return -ENOTSUPP; | |
1057 | ||
4fdfefe5 AV |
1058 | if (sscanf(buf, "%d", &val) != 1) |
1059 | return -EINVAL; | |
1060 | ||
4a59f71d | 1061 | if (val) |
4fdfefe5 | 1062 | zio_mode = QLA_ZIO_MODE_6; |
4a59f71d | 1063 | else |
4fdfefe5 | 1064 | zio_mode = QLA_ZIO_DISABLED; |
4fdfefe5 AV |
1065 | |
1066 | /* Update per-hba values and queue a reset. */ | |
1067 | if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) { | |
1068 | ha->zio_mode = zio_mode; | |
7b867cf7 | 1069 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
4fdfefe5 AV |
1070 | } |
1071 | return strlen(buf); | |
1072 | } | |
1073 | ||
1074 | static ssize_t | |
ee959b00 TJ |
1075 | qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr, |
1076 | char *buf) | |
4fdfefe5 | 1077 | { |
7b867cf7 | 1078 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
4fdfefe5 | 1079 | |
7b867cf7 | 1080 | return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100); |
4fdfefe5 AV |
1081 | } |
1082 | ||
1083 | static ssize_t | |
ee959b00 TJ |
1084 | qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr, |
1085 | const char *buf, size_t count) | |
4fdfefe5 | 1086 | { |
7b867cf7 | 1087 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
4fdfefe5 AV |
1088 | int val = 0; |
1089 | uint16_t zio_timer; | |
1090 | ||
1091 | if (sscanf(buf, "%d", &val) != 1) | |
1092 | return -EINVAL; | |
1093 | if (val > 25500 || val < 100) | |
1094 | return -ERANGE; | |
1095 | ||
1096 | zio_timer = (uint16_t)(val / 100); | |
7b867cf7 | 1097 | vha->hw->zio_timer = zio_timer; |
4fdfefe5 AV |
1098 | |
1099 | return strlen(buf); | |
1100 | } | |
1101 | ||
f6df144c | 1102 | static ssize_t |
ee959b00 TJ |
1103 | qla2x00_beacon_show(struct device *dev, struct device_attribute *attr, |
1104 | char *buf) | |
f6df144c | 1105 | { |
7b867cf7 | 1106 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
f6df144c AV |
1107 | int len = 0; |
1108 | ||
7b867cf7 | 1109 | if (vha->hw->beacon_blink_led) |
f6df144c AV |
1110 | len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n"); |
1111 | else | |
1112 | len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n"); | |
1113 | return len; | |
1114 | } | |
1115 | ||
1116 | static ssize_t | |
ee959b00 TJ |
1117 | qla2x00_beacon_store(struct device *dev, struct device_attribute *attr, |
1118 | const char *buf, size_t count) | |
f6df144c | 1119 | { |
7b867cf7 AC |
1120 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1121 | struct qla_hw_data *ha = vha->hw; | |
f6df144c AV |
1122 | int val = 0; |
1123 | int rval; | |
1124 | ||
1125 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | |
1126 | return -EPERM; | |
1127 | ||
7b867cf7 | 1128 | if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) { |
f6df144c AV |
1129 | qla_printk(KERN_WARNING, ha, |
1130 | "Abort ISP active -- ignoring beacon request.\n"); | |
1131 | return -EBUSY; | |
1132 | } | |
1133 | ||
1134 | if (sscanf(buf, "%d", &val) != 1) | |
1135 | return -EINVAL; | |
1136 | ||
1137 | if (val) | |
7b867cf7 | 1138 | rval = ha->isp_ops->beacon_on(vha); |
f6df144c | 1139 | else |
7b867cf7 | 1140 | rval = ha->isp_ops->beacon_off(vha); |
f6df144c AV |
1141 | |
1142 | if (rval != QLA_SUCCESS) | |
1143 | count = 0; | |
1144 | ||
1145 | return count; | |
1146 | } | |
1147 | ||
30c47662 | 1148 | static ssize_t |
ee959b00 TJ |
1149 | qla2x00_optrom_bios_version_show(struct device *dev, |
1150 | struct device_attribute *attr, char *buf) | |
30c47662 | 1151 | { |
7b867cf7 AC |
1152 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1153 | struct qla_hw_data *ha = vha->hw; | |
30c47662 AV |
1154 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1], |
1155 | ha->bios_revision[0]); | |
1156 | } | |
1157 | ||
1158 | static ssize_t | |
ee959b00 TJ |
1159 | qla2x00_optrom_efi_version_show(struct device *dev, |
1160 | struct device_attribute *attr, char *buf) | |
30c47662 | 1161 | { |
7b867cf7 AC |
1162 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1163 | struct qla_hw_data *ha = vha->hw; | |
30c47662 AV |
1164 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1], |
1165 | ha->efi_revision[0]); | |
1166 | } | |
1167 | ||
1168 | static ssize_t | |
ee959b00 TJ |
1169 | qla2x00_optrom_fcode_version_show(struct device *dev, |
1170 | struct device_attribute *attr, char *buf) | |
30c47662 | 1171 | { |
7b867cf7 AC |
1172 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1173 | struct qla_hw_data *ha = vha->hw; | |
30c47662 AV |
1174 | return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1], |
1175 | ha->fcode_revision[0]); | |
1176 | } | |
1177 | ||
1178 | static ssize_t | |
ee959b00 TJ |
1179 | qla2x00_optrom_fw_version_show(struct device *dev, |
1180 | struct device_attribute *attr, char *buf) | |
30c47662 | 1181 | { |
7b867cf7 AC |
1182 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1183 | struct qla_hw_data *ha = vha->hw; | |
30c47662 AV |
1184 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n", |
1185 | ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2], | |
1186 | ha->fw_revision[3]); | |
1187 | } | |
1188 | ||
0f2d962f MI |
1189 | static ssize_t |
1190 | qla2x00_optrom_gold_fw_version_show(struct device *dev, | |
1191 | struct device_attribute *attr, char *buf) | |
1192 | { | |
1193 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1194 | struct qla_hw_data *ha = vha->hw; | |
1195 | ||
1196 | if (!IS_QLA81XX(ha)) | |
1197 | return snprintf(buf, PAGE_SIZE, "\n"); | |
1198 | ||
1199 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n", | |
1200 | ha->gold_fw_version[0], ha->gold_fw_version[1], | |
1201 | ha->gold_fw_version[2], ha->gold_fw_version[3]); | |
1202 | } | |
1203 | ||
e5f5f6f7 HZ |
1204 | static ssize_t |
1205 | qla2x00_total_isp_aborts_show(struct device *dev, | |
1206 | struct device_attribute *attr, char *buf) | |
1207 | { | |
7b867cf7 AC |
1208 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); |
1209 | struct qla_hw_data *ha = vha->hw; | |
e5f5f6f7 HZ |
1210 | return snprintf(buf, PAGE_SIZE, "%d\n", |
1211 | ha->qla_stats.total_isp_aborts); | |
1212 | } | |
1213 | ||
9a069e19 GM |
1214 | static ssize_t |
1215 | qla24xx_84xx_fw_version_show(struct device *dev, | |
1216 | struct device_attribute *attr, char *buf) | |
1217 | { | |
1218 | int rval = QLA_SUCCESS; | |
1219 | uint16_t status[2] = {0, 0}; | |
1220 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1221 | struct qla_hw_data *ha = vha->hw; | |
1222 | ||
0b9dae6a AV |
1223 | if (!IS_QLA84XX(ha)) |
1224 | return snprintf(buf, PAGE_SIZE, "\n"); | |
1225 | ||
6c7ccf7b | 1226 | if (ha->cs84xx->op_fw_version == 0) |
0b9dae6a | 1227 | rval = qla84xx_verify_chip(vha, status); |
9a069e19 GM |
1228 | |
1229 | if ((rval == QLA_SUCCESS) && (status[0] == 0)) | |
1230 | return snprintf(buf, PAGE_SIZE, "%u\n", | |
1231 | (uint32_t)ha->cs84xx->op_fw_version); | |
9a069e19 GM |
1232 | |
1233 | return snprintf(buf, PAGE_SIZE, "\n"); | |
1234 | } | |
1235 | ||
3a03eb79 AV |
1236 | static ssize_t |
1237 | qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr, | |
1238 | char *buf) | |
1239 | { | |
1240 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1241 | struct qla_hw_data *ha = vha->hw; | |
1242 | ||
1243 | if (!IS_QLA81XX(ha)) | |
1244 | return snprintf(buf, PAGE_SIZE, "\n"); | |
1245 | ||
55a96158 | 1246 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n", |
3a03eb79 | 1247 | ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2], |
55a96158 AV |
1248 | ha->mpi_capabilities); |
1249 | } | |
1250 | ||
1251 | static ssize_t | |
1252 | qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr, | |
1253 | char *buf) | |
1254 | { | |
1255 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1256 | struct qla_hw_data *ha = vha->hw; | |
1257 | ||
1258 | if (!IS_QLA81XX(ha)) | |
1259 | return snprintf(buf, PAGE_SIZE, "\n"); | |
1260 | ||
1261 | return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n", | |
1262 | ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]); | |
3a03eb79 AV |
1263 | } |
1264 | ||
fbcbb5d0 LC |
1265 | static ssize_t |
1266 | qla2x00_flash_block_size_show(struct device *dev, | |
1267 | struct device_attribute *attr, char *buf) | |
1268 | { | |
1269 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1270 | struct qla_hw_data *ha = vha->hw; | |
1271 | ||
1272 | return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size); | |
1273 | } | |
1274 | ||
bad7001c AV |
1275 | static ssize_t |
1276 | qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr, | |
1277 | char *buf) | |
1278 | { | |
1279 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1280 | ||
a9083016 | 1281 | if (!IS_QLA8XXX_TYPE(vha->hw)) |
bad7001c AV |
1282 | return snprintf(buf, PAGE_SIZE, "\n"); |
1283 | ||
1284 | return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id); | |
1285 | } | |
1286 | ||
1287 | static ssize_t | |
1288 | qla2x00_vn_port_mac_address_show(struct device *dev, | |
1289 | struct device_attribute *attr, char *buf) | |
1290 | { | |
1291 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1292 | ||
a9083016 | 1293 | if (!IS_QLA8XXX_TYPE(vha->hw)) |
bad7001c AV |
1294 | return snprintf(buf, PAGE_SIZE, "\n"); |
1295 | ||
1296 | return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n", | |
1297 | vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4], | |
1298 | vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2], | |
1299 | vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]); | |
1300 | } | |
1301 | ||
7f774025 AV |
1302 | static ssize_t |
1303 | qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr, | |
1304 | char *buf) | |
1305 | { | |
1306 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
1307 | ||
1308 | return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap); | |
1309 | } | |
1310 | ||
656e8912 AV |
1311 | static ssize_t |
1312 | qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr, | |
1313 | char *buf) | |
1314 | { | |
1315 | scsi_qla_host_t *vha = shost_priv(class_to_shost(dev)); | |
85880801 | 1316 | int rval = QLA_FUNCTION_FAILED; |
656e8912 AV |
1317 | uint16_t state[5]; |
1318 | ||
d6136f3f SV |
1319 | if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || |
1320 | test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | |
1321 | DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n", | |
1322 | __func__, vha->host_no)); | |
1323 | else if (!vha->hw->flags.eeh_busy) | |
85880801 | 1324 | rval = qla2x00_get_firmware_state(vha, state); |
656e8912 AV |
1325 | if (rval != QLA_SUCCESS) |
1326 | memset(state, -1, sizeof(state)); | |
1327 | ||
1328 | return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0], | |
1329 | state[1], state[2], state[3], state[4]); | |
1330 | } | |
1331 | ||
ee959b00 TJ |
1332 | static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL); |
1333 | static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); | |
1334 | static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); | |
1335 | static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); | |
1336 | static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL); | |
1337 | static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL); | |
1338 | static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL); | |
1339 | static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL); | |
bbd1ae41 | 1340 | static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL); |
ee959b00 TJ |
1341 | static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store); |
1342 | static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show, | |
1343 | qla2x00_zio_timer_store); | |
1344 | static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, | |
1345 | qla2x00_beacon_store); | |
1346 | static DEVICE_ATTR(optrom_bios_version, S_IRUGO, | |
1347 | qla2x00_optrom_bios_version_show, NULL); | |
1348 | static DEVICE_ATTR(optrom_efi_version, S_IRUGO, | |
1349 | qla2x00_optrom_efi_version_show, NULL); | |
1350 | static DEVICE_ATTR(optrom_fcode_version, S_IRUGO, | |
1351 | qla2x00_optrom_fcode_version_show, NULL); | |
1352 | static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show, | |
1353 | NULL); | |
0f2d962f MI |
1354 | static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO, |
1355 | qla2x00_optrom_gold_fw_version_show, NULL); | |
9a069e19 GM |
1356 | static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show, |
1357 | NULL); | |
e5f5f6f7 HZ |
1358 | static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show, |
1359 | NULL); | |
3a03eb79 | 1360 | static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL); |
55a96158 | 1361 | static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL); |
fbcbb5d0 LC |
1362 | static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show, |
1363 | NULL); | |
bad7001c AV |
1364 | static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL); |
1365 | static DEVICE_ATTR(vn_port_mac_address, S_IRUGO, | |
1366 | qla2x00_vn_port_mac_address_show, NULL); | |
7f774025 | 1367 | static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL); |
656e8912 | 1368 | static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL); |
ee959b00 TJ |
1369 | |
1370 | struct device_attribute *qla2x00_host_attrs[] = { | |
1371 | &dev_attr_driver_version, | |
1372 | &dev_attr_fw_version, | |
1373 | &dev_attr_serial_num, | |
1374 | &dev_attr_isp_name, | |
1375 | &dev_attr_isp_id, | |
1376 | &dev_attr_model_name, | |
1377 | &dev_attr_model_desc, | |
1378 | &dev_attr_pci_info, | |
bbd1ae41 | 1379 | &dev_attr_link_state, |
ee959b00 TJ |
1380 | &dev_attr_zio, |
1381 | &dev_attr_zio_timer, | |
1382 | &dev_attr_beacon, | |
1383 | &dev_attr_optrom_bios_version, | |
1384 | &dev_attr_optrom_efi_version, | |
1385 | &dev_attr_optrom_fcode_version, | |
1386 | &dev_attr_optrom_fw_version, | |
9a069e19 | 1387 | &dev_attr_84xx_fw_version, |
e5f5f6f7 | 1388 | &dev_attr_total_isp_aborts, |
3a03eb79 | 1389 | &dev_attr_mpi_version, |
55a96158 | 1390 | &dev_attr_phy_version, |
fbcbb5d0 | 1391 | &dev_attr_flash_block_size, |
bad7001c AV |
1392 | &dev_attr_vlan_id, |
1393 | &dev_attr_vn_port_mac_address, | |
7f774025 | 1394 | &dev_attr_fabric_param, |
656e8912 | 1395 | &dev_attr_fw_state, |
0f2d962f | 1396 | &dev_attr_optrom_gold_fw_version, |
afb046e2 AV |
1397 | NULL, |
1398 | }; | |
1399 | ||
8482e118 AV |
1400 | /* Host attributes. */ |
1401 | ||
1402 | static void | |
1403 | qla2x00_get_host_port_id(struct Scsi_Host *shost) | |
1404 | { | |
7b867cf7 | 1405 | scsi_qla_host_t *vha = shost_priv(shost); |
8482e118 | 1406 | |
7b867cf7 AC |
1407 | fc_host_port_id(shost) = vha->d_id.b.domain << 16 | |
1408 | vha->d_id.b.area << 8 | vha->d_id.b.al_pa; | |
8482e118 AV |
1409 | } |
1410 | ||
04414013 AV |
1411 | static void |
1412 | qla2x00_get_host_speed(struct Scsi_Host *shost) | |
1413 | { | |
7b867cf7 AC |
1414 | struct qla_hw_data *ha = ((struct scsi_qla_host *) |
1415 | (shost_priv(shost)))->hw; | |
2ae2b370 | 1416 | u32 speed = FC_PORTSPEED_UNKNOWN; |
04414013 AV |
1417 | |
1418 | switch (ha->link_data_rate) { | |
d8b45213 | 1419 | case PORT_SPEED_1GB: |
2ae2b370 | 1420 | speed = FC_PORTSPEED_1GBIT; |
04414013 | 1421 | break; |
d8b45213 | 1422 | case PORT_SPEED_2GB: |
2ae2b370 | 1423 | speed = FC_PORTSPEED_2GBIT; |
04414013 | 1424 | break; |
d8b45213 | 1425 | case PORT_SPEED_4GB: |
2ae2b370 | 1426 | speed = FC_PORTSPEED_4GBIT; |
04414013 | 1427 | break; |
da4541b6 | 1428 | case PORT_SPEED_8GB: |
2ae2b370 | 1429 | speed = FC_PORTSPEED_8GBIT; |
da4541b6 | 1430 | break; |
3a03eb79 AV |
1431 | case PORT_SPEED_10GB: |
1432 | speed = FC_PORTSPEED_10GBIT; | |
1433 | break; | |
04414013 AV |
1434 | } |
1435 | fc_host_speed(shost) = speed; | |
1436 | } | |
1437 | ||
8d067623 AV |
1438 | static void |
1439 | qla2x00_get_host_port_type(struct Scsi_Host *shost) | |
1440 | { | |
7b867cf7 | 1441 | scsi_qla_host_t *vha = shost_priv(shost); |
8d067623 AV |
1442 | uint32_t port_type = FC_PORTTYPE_UNKNOWN; |
1443 | ||
7b867cf7 | 1444 | if (vha->vp_idx) { |
2f2fa13d SS |
1445 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; |
1446 | return; | |
1447 | } | |
7b867cf7 | 1448 | switch (vha->hw->current_topology) { |
8d067623 AV |
1449 | case ISP_CFG_NL: |
1450 | port_type = FC_PORTTYPE_LPORT; | |
1451 | break; | |
1452 | case ISP_CFG_FL: | |
1453 | port_type = FC_PORTTYPE_NLPORT; | |
1454 | break; | |
1455 | case ISP_CFG_N: | |
1456 | port_type = FC_PORTTYPE_PTP; | |
1457 | break; | |
1458 | case ISP_CFG_F: | |
1459 | port_type = FC_PORTTYPE_NPORT; | |
1460 | break; | |
1461 | } | |
1462 | fc_host_port_type(shost) = port_type; | |
1463 | } | |
1464 | ||
8482e118 AV |
1465 | static void |
1466 | qla2x00_get_starget_node_name(struct scsi_target *starget) | |
1467 | { | |
1468 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
7b867cf7 | 1469 | scsi_qla_host_t *vha = shost_priv(host); |
bdf79621 | 1470 | fc_port_t *fcport; |
f8b02a85 | 1471 | u64 node_name = 0; |
8482e118 | 1472 | |
7b867cf7 | 1473 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
5ab5a4dd AV |
1474 | if (fcport->rport && |
1475 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 1476 | node_name = wwn_to_u64(fcport->node_name); |
bdf79621 AV |
1477 | break; |
1478 | } | |
1479 | } | |
1480 | ||
f8b02a85 | 1481 | fc_starget_node_name(starget) = node_name; |
8482e118 AV |
1482 | } |
1483 | ||
1484 | static void | |
1485 | qla2x00_get_starget_port_name(struct scsi_target *starget) | |
1486 | { | |
1487 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
7b867cf7 | 1488 | scsi_qla_host_t *vha = shost_priv(host); |
bdf79621 | 1489 | fc_port_t *fcport; |
f8b02a85 | 1490 | u64 port_name = 0; |
8482e118 | 1491 | |
7b867cf7 | 1492 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
5ab5a4dd AV |
1493 | if (fcport->rport && |
1494 | starget->id == fcport->rport->scsi_target_id) { | |
f8b02a85 | 1495 | port_name = wwn_to_u64(fcport->port_name); |
bdf79621 AV |
1496 | break; |
1497 | } | |
1498 | } | |
1499 | ||
f8b02a85 | 1500 | fc_starget_port_name(starget) = port_name; |
8482e118 AV |
1501 | } |
1502 | ||
1503 | static void | |
1504 | qla2x00_get_starget_port_id(struct scsi_target *starget) | |
1505 | { | |
1506 | struct Scsi_Host *host = dev_to_shost(starget->dev.parent); | |
7b867cf7 | 1507 | scsi_qla_host_t *vha = shost_priv(host); |
bdf79621 AV |
1508 | fc_port_t *fcport; |
1509 | uint32_t port_id = ~0U; | |
1510 | ||
7b867cf7 | 1511 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
5ab5a4dd AV |
1512 | if (fcport->rport && |
1513 | starget->id == fcport->rport->scsi_target_id) { | |
bdf79621 AV |
1514 | port_id = fcport->d_id.b.domain << 16 | |
1515 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; | |
1516 | break; | |
1517 | } | |
1518 | } | |
8482e118 | 1519 | |
8482e118 AV |
1520 | fc_starget_port_id(starget) = port_id; |
1521 | } | |
1522 | ||
8482e118 AV |
1523 | static void |
1524 | qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
1525 | { | |
8482e118 | 1526 | if (timeout) |
85821c90 | 1527 | rport->dev_loss_tmo = timeout; |
8482e118 | 1528 | else |
85821c90 | 1529 | rport->dev_loss_tmo = 1; |
8482e118 AV |
1530 | } |
1531 | ||
a74bdf46 MC |
1532 | static void |
1533 | qla2x00_get_host_def_loss_tmo(struct Scsi_Host *shost) | |
1534 | { | |
1535 | scsi_qla_host_t *vha = shost_priv(shost); | |
1536 | struct qla_hw_data *ha = vha->hw; | |
1537 | ||
1538 | fc_host_def_dev_loss_tmo(shost) = ha->port_down_retry_count; | |
1539 | } | |
1540 | ||
5f3a9a20 SJ |
1541 | static void |
1542 | qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport) | |
1543 | { | |
1544 | struct Scsi_Host *host = rport_to_shost(rport); | |
1545 | fc_port_t *fcport = *(fc_port_t **)rport->dd_data; | |
1546 | ||
3c01b4f9 SJ |
1547 | if (!fcport) |
1548 | return; | |
1549 | ||
85880801 AV |
1550 | if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags)) |
1551 | return; | |
1552 | ||
1553 | if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) { | |
b9b12f73 | 1554 | qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16); |
85880801 AV |
1555 | return; |
1556 | } | |
5f3a9a20 SJ |
1557 | |
1558 | /* | |
1559 | * Transport has effectively 'deleted' the rport, clear | |
1560 | * all local references. | |
1561 | */ | |
1562 | spin_lock_irq(host->host_lock); | |
1563 | fcport->rport = NULL; | |
1564 | *((fc_port_t **)rport->dd_data) = NULL; | |
1565 | spin_unlock_irq(host->host_lock); | |
1566 | } | |
1567 | ||
1568 | static void | |
1569 | qla2x00_terminate_rport_io(struct fc_rport *rport) | |
1570 | { | |
1571 | fc_port_t *fcport = *(fc_port_t **)rport->dd_data; | |
1572 | ||
3c01b4f9 SJ |
1573 | if (!fcport) |
1574 | return; | |
1575 | ||
85880801 AV |
1576 | if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags)) |
1577 | return; | |
1578 | ||
b9b12f73 SJ |
1579 | if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) { |
1580 | qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16); | |
1581 | return; | |
1582 | } | |
6390d1f3 AV |
1583 | /* |
1584 | * At this point all fcport's software-states are cleared. Perform any | |
1585 | * final cleanup of firmware resources (PCBs and XCBs). | |
1586 | */ | |
6805c150 AV |
1587 | if (fcport->loop_id != FC_NO_LOOP_ID && |
1588 | !test_bit(UNLOADING, &fcport->vha->dpc_flags)) | |
7b867cf7 AC |
1589 | fcport->vha->hw->isp_ops->fabric_logout(fcport->vha, |
1590 | fcport->loop_id, fcport->d_id.b.domain, | |
1591 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | |
5f3a9a20 SJ |
1592 | } |
1593 | ||
91ca7b01 AV |
1594 | static int |
1595 | qla2x00_issue_lip(struct Scsi_Host *shost) | |
1596 | { | |
7b867cf7 | 1597 | scsi_qla_host_t *vha = shost_priv(shost); |
91ca7b01 | 1598 | |
7b867cf7 | 1599 | qla2x00_loop_reset(vha); |
91ca7b01 AV |
1600 | return 0; |
1601 | } | |
1602 | ||
392e2f65 AV |
1603 | static struct fc_host_statistics * |
1604 | qla2x00_get_fc_host_stats(struct Scsi_Host *shost) | |
1605 | { | |
7b867cf7 AC |
1606 | scsi_qla_host_t *vha = shost_priv(shost); |
1607 | struct qla_hw_data *ha = vha->hw; | |
1608 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
392e2f65 | 1609 | int rval; |
43ef0580 AV |
1610 | struct link_statistics *stats; |
1611 | dma_addr_t stats_dma; | |
392e2f65 AV |
1612 | struct fc_host_statistics *pfc_host_stat; |
1613 | ||
1614 | pfc_host_stat = &ha->fc_host_stat; | |
1615 | memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); | |
1616 | ||
85880801 AV |
1617 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
1618 | goto done; | |
1619 | ||
1620 | if (unlikely(pci_channel_offline(ha->pdev))) | |
1621 | goto done; | |
1622 | ||
43ef0580 AV |
1623 | stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma); |
1624 | if (stats == NULL) { | |
1625 | DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n", | |
7b867cf7 | 1626 | __func__, base_vha->host_no)); |
43ef0580 AV |
1627 | goto done; |
1628 | } | |
1629 | memset(stats, 0, DMA_POOL_SIZE); | |
1630 | ||
1631 | rval = QLA_FUNCTION_FAILED; | |
e428924c | 1632 | if (IS_FWI2_CAPABLE(ha)) { |
7b867cf7 AC |
1633 | rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma); |
1634 | } else if (atomic_read(&base_vha->loop_state) == LOOP_READY && | |
1635 | !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) && | |
1636 | !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && | |
178779a6 AV |
1637 | !ha->dpc_active) { |
1638 | /* Must be in a 'READY' state for statistics retrieval. */ | |
7b867cf7 AC |
1639 | rval = qla2x00_get_link_status(base_vha, base_vha->loop_id, |
1640 | stats, stats_dma); | |
392e2f65 | 1641 | } |
178779a6 AV |
1642 | |
1643 | if (rval != QLA_SUCCESS) | |
43ef0580 AV |
1644 | goto done_free; |
1645 | ||
1646 | pfc_host_stat->link_failure_count = stats->link_fail_cnt; | |
1647 | pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt; | |
1648 | pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt; | |
1649 | pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt; | |
1650 | pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt; | |
1651 | pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt; | |
1652 | if (IS_FWI2_CAPABLE(ha)) { | |
032d8dd7 | 1653 | pfc_host_stat->lip_count = stats->lip_cnt; |
43ef0580 AV |
1654 | pfc_host_stat->tx_frames = stats->tx_frames; |
1655 | pfc_host_stat->rx_frames = stats->rx_frames; | |
1656 | pfc_host_stat->dumped_frames = stats->dumped_frames; | |
1657 | pfc_host_stat->nos_count = stats->nos_rcvd; | |
1658 | } | |
49fd462a HZ |
1659 | pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20; |
1660 | pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20; | |
392e2f65 | 1661 | |
43ef0580 AV |
1662 | done_free: |
1663 | dma_pool_free(ha->s_dma_pool, stats, stats_dma); | |
178779a6 | 1664 | done: |
392e2f65 AV |
1665 | return pfc_host_stat; |
1666 | } | |
1667 | ||
1620f7c2 AV |
1668 | static void |
1669 | qla2x00_get_host_symbolic_name(struct Scsi_Host *shost) | |
1670 | { | |
7b867cf7 | 1671 | scsi_qla_host_t *vha = shost_priv(shost); |
1620f7c2 | 1672 | |
7b867cf7 | 1673 | qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost)); |
1620f7c2 AV |
1674 | } |
1675 | ||
a740a3f0 AV |
1676 | static void |
1677 | qla2x00_set_host_system_hostname(struct Scsi_Host *shost) | |
1678 | { | |
7b867cf7 | 1679 | scsi_qla_host_t *vha = shost_priv(shost); |
a740a3f0 | 1680 | |
7b867cf7 | 1681 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); |
a740a3f0 AV |
1682 | } |
1683 | ||
90991c85 AV |
1684 | static void |
1685 | qla2x00_get_host_fabric_name(struct Scsi_Host *shost) | |
1686 | { | |
7b867cf7 | 1687 | scsi_qla_host_t *vha = shost_priv(shost); |
90991c85 AV |
1688 | u64 node_name; |
1689 | ||
7b867cf7 AC |
1690 | if (vha->device_flags & SWITCH_FOUND) |
1691 | node_name = wwn_to_u64(vha->fabric_node_name); | |
90991c85 | 1692 | else |
7b867cf7 | 1693 | node_name = wwn_to_u64(vha->node_name); |
90991c85 AV |
1694 | |
1695 | fc_host_fabric_name(shost) = node_name; | |
1696 | } | |
1697 | ||
7047fcdd AV |
1698 | static void |
1699 | qla2x00_get_host_port_state(struct Scsi_Host *shost) | |
1700 | { | |
7b867cf7 AC |
1701 | scsi_qla_host_t *vha = shost_priv(shost); |
1702 | struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev); | |
7047fcdd | 1703 | |
7b867cf7 | 1704 | if (!base_vha->flags.online) |
7047fcdd | 1705 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
7b867cf7 | 1706 | else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT) |
7047fcdd AV |
1707 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
1708 | else | |
1709 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
1710 | } | |
1711 | ||
2c3dfe3f SJ |
1712 | static int |
1713 | qla24xx_vport_create(struct fc_vport *fc_vport, bool disable) | |
1714 | { | |
1715 | int ret = 0; | |
2afa19a9 | 1716 | uint8_t qos = 0; |
7b867cf7 AC |
1717 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
1718 | scsi_qla_host_t *vha = NULL; | |
73208dfd | 1719 | struct qla_hw_data *ha = base_vha->hw; |
2afa19a9 AC |
1720 | uint16_t options = 0; |
1721 | int cnt; | |
59e0b8b0 | 1722 | struct req_que *req = ha->req_q_map[0]; |
2c3dfe3f SJ |
1723 | |
1724 | ret = qla24xx_vport_create_req_sanity_check(fc_vport); | |
1725 | if (ret) { | |
1726 | DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, " | |
1727 | "status %x\n", ret)); | |
1728 | return (ret); | |
1729 | } | |
1730 | ||
1731 | vha = qla24xx_create_vhost(fc_vport); | |
1732 | if (vha == NULL) { | |
1733 | DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n", | |
1734 | vha)); | |
1735 | return FC_VPORT_FAILED; | |
1736 | } | |
1737 | if (disable) { | |
1738 | atomic_set(&vha->vp_state, VP_OFFLINE); | |
1739 | fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); | |
1740 | } else | |
1741 | atomic_set(&vha->vp_state, VP_FAILED); | |
1742 | ||
1743 | /* ready to create vport */ | |
7b867cf7 AC |
1744 | qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n", |
1745 | vha->vp_idx); | |
2c3dfe3f SJ |
1746 | |
1747 | /* initialized vport states */ | |
1748 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
1749 | vha->vp_err_state= VP_ERR_PORTDWN; | |
1750 | vha->vp_prev_err_state= VP_ERR_UNKWN; | |
1751 | /* Check if physical ha port is Up */ | |
7b867cf7 AC |
1752 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
1753 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | |
2c3dfe3f SJ |
1754 | /* Don't retry or attempt login of this virtual port */ |
1755 | DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n", | |
7b867cf7 | 1756 | base_vha->host_no)); |
2c3dfe3f SJ |
1757 | atomic_set(&vha->loop_state, LOOP_DEAD); |
1758 | if (!disable) | |
1759 | fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN); | |
1760 | } | |
1761 | ||
ba77ef53 | 1762 | if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) { |
bad75002 AE |
1763 | if (ha->fw_attributes & BIT_4) { |
1764 | vha->flags.difdix_supported = 1; | |
1765 | DEBUG18(qla_printk(KERN_INFO, ha, | |
1766 | "Registering for DIF/DIX type 1 and 3" | |
1767 | " protection.\n")); | |
1768 | scsi_host_set_prot(vha->host, | |
1769 | SHOST_DIF_TYPE1_PROTECTION | |
0c470874 | 1770 | | SHOST_DIF_TYPE2_PROTECTION |
bad75002 AE |
1771 | | SHOST_DIF_TYPE3_PROTECTION |
1772 | | SHOST_DIX_TYPE1_PROTECTION | |
0c470874 | 1773 | | SHOST_DIX_TYPE2_PROTECTION |
bad75002 AE |
1774 | | SHOST_DIX_TYPE3_PROTECTION); |
1775 | scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC); | |
1776 | } else | |
1777 | vha->flags.difdix_supported = 0; | |
1778 | } | |
1779 | ||
d139b9bd JB |
1780 | if (scsi_add_host_with_dma(vha->host, &fc_vport->dev, |
1781 | &ha->pdev->dev)) { | |
2c3dfe3f SJ |
1782 | DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n", |
1783 | vha->host_no, vha->vp_idx)); | |
1784 | goto vport_create_failed_2; | |
1785 | } | |
1786 | ||
1787 | /* initialize attributes */ | |
1788 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); | |
1789 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); | |
1790 | fc_host_supported_classes(vha->host) = | |
7b867cf7 | 1791 | fc_host_supported_classes(base_vha->host); |
2c3dfe3f | 1792 | fc_host_supported_speeds(vha->host) = |
7b867cf7 | 1793 | fc_host_supported_speeds(base_vha->host); |
2c3dfe3f SJ |
1794 | |
1795 | qla24xx_vport_disable(fc_vport, disable); | |
1796 | ||
7163ea81 | 1797 | if (ha->flags.cpu_affinity_enabled) { |
59e0b8b0 AC |
1798 | req = ha->req_q_map[1]; |
1799 | goto vport_queue; | |
1800 | } else if (ql2xmaxqueues == 1 || !ha->npiv_info) | |
2afa19a9 AC |
1801 | goto vport_queue; |
1802 | /* Create a request queue in QoS mode for the vport */ | |
40859ae5 AC |
1803 | for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) { |
1804 | if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0 | |
1805 | && memcmp(ha->npiv_info[cnt].node_name, vha->node_name, | |
59e0b8b0 | 1806 | 8) == 0) { |
2afa19a9 AC |
1807 | qos = ha->npiv_info[cnt].q_qos; |
1808 | break; | |
73208dfd | 1809 | } |
2afa19a9 AC |
1810 | } |
1811 | if (qos) { | |
1812 | ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0, | |
1813 | qos); | |
1814 | if (!ret) | |
1815 | qla_printk(KERN_WARNING, ha, | |
1816 | "Can't create request queue for vp_idx:%d\n", | |
1817 | vha->vp_idx); | |
59e0b8b0 | 1818 | else { |
2afa19a9 | 1819 | DEBUG2(qla_printk(KERN_INFO, ha, |
40859ae5 AC |
1820 | "Request Que:%d (QoS: %d) created for vp_idx:%d\n", |
1821 | ret, qos, vha->vp_idx)); | |
59e0b8b0 AC |
1822 | req = ha->req_q_map[ret]; |
1823 | } | |
73208dfd AC |
1824 | } |
1825 | ||
2afa19a9 | 1826 | vport_queue: |
59e0b8b0 | 1827 | vha->req = req; |
2c3dfe3f | 1828 | return 0; |
2afa19a9 | 1829 | |
2c3dfe3f SJ |
1830 | vport_create_failed_2: |
1831 | qla24xx_disable_vp(vha); | |
1832 | qla24xx_deallocate_vp_id(vha); | |
2c3dfe3f SJ |
1833 | scsi_host_put(vha->host); |
1834 | return FC_VPORT_FAILED; | |
1835 | } | |
1836 | ||
a824ebb3 | 1837 | static int |
2c3dfe3f SJ |
1838 | qla24xx_vport_delete(struct fc_vport *fc_vport) |
1839 | { | |
2c3dfe3f | 1840 | scsi_qla_host_t *vha = fc_vport->dd_data; |
73208dfd AC |
1841 | struct qla_hw_data *ha = vha->hw; |
1842 | uint16_t id = vha->vp_idx; | |
c9c5ced9 AV |
1843 | |
1844 | while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) || | |
7b867cf7 | 1845 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) |
c9c5ced9 | 1846 | msleep(1000); |
2c3dfe3f SJ |
1847 | |
1848 | qla24xx_disable_vp(vha); | |
2c3dfe3f | 1849 | |
7b867cf7 AC |
1850 | fc_remove_host(vha->host); |
1851 | ||
1852 | scsi_remove_host(vha->host); | |
1853 | ||
8867048b | 1854 | qla2x00_free_fcports(vha); |
7b867cf7 AC |
1855 | |
1856 | qla24xx_deallocate_vp_id(vha); | |
2c3dfe3f | 1857 | |
0d6e61bc AV |
1858 | mutex_lock(&ha->vport_lock); |
1859 | ha->cur_vport_count--; | |
1860 | clear_bit(vha->vp_idx, ha->vp_idx_map); | |
1861 | mutex_unlock(&ha->vport_lock); | |
1862 | ||
2c3dfe3f SJ |
1863 | if (vha->timer_active) { |
1864 | qla2x00_vp_stop_timer(vha); | |
1865 | DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p " | |
1866 | "has stopped\n", | |
1867 | vha->host_no, vha->vp_idx, vha)); | |
1868 | } | |
1869 | ||
7163ea81 | 1870 | if (vha->req->id && !ha->flags.cpu_affinity_enabled) { |
2afa19a9 | 1871 | if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS) |
cf5a1631 AC |
1872 | qla_printk(KERN_WARNING, ha, |
1873 | "Queue delete failed.\n"); | |
1874 | } | |
1875 | ||
2c3dfe3f | 1876 | scsi_host_put(vha->host); |
73208dfd | 1877 | qla_printk(KERN_INFO, ha, "vport %d deleted\n", id); |
2c3dfe3f SJ |
1878 | return 0; |
1879 | } | |
1880 | ||
a824ebb3 | 1881 | static int |
2c3dfe3f SJ |
1882 | qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable) |
1883 | { | |
1884 | scsi_qla_host_t *vha = fc_vport->dd_data; | |
1885 | ||
1886 | if (disable) | |
1887 | qla24xx_disable_vp(vha); | |
1888 | else | |
1889 | qla24xx_enable_vp(vha); | |
1890 | ||
1891 | return 0; | |
1892 | } | |
1893 | ||
1c97a12a | 1894 | struct fc_function_template qla2xxx_transport_functions = { |
8482e118 AV |
1895 | |
1896 | .show_host_node_name = 1, | |
1897 | .show_host_port_name = 1, | |
ad3e0eda | 1898 | .show_host_supported_classes = 1, |
2ae2b370 | 1899 | .show_host_supported_speeds = 1, |
ad3e0eda | 1900 | |
8482e118 AV |
1901 | .get_host_port_id = qla2x00_get_host_port_id, |
1902 | .show_host_port_id = 1, | |
04414013 AV |
1903 | .get_host_speed = qla2x00_get_host_speed, |
1904 | .show_host_speed = 1, | |
8d067623 AV |
1905 | .get_host_port_type = qla2x00_get_host_port_type, |
1906 | .show_host_port_type = 1, | |
1620f7c2 AV |
1907 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, |
1908 | .show_host_symbolic_name = 1, | |
a740a3f0 AV |
1909 | .set_host_system_hostname = qla2x00_set_host_system_hostname, |
1910 | .show_host_system_hostname = 1, | |
90991c85 AV |
1911 | .get_host_fabric_name = qla2x00_get_host_fabric_name, |
1912 | .show_host_fabric_name = 1, | |
7047fcdd AV |
1913 | .get_host_port_state = qla2x00_get_host_port_state, |
1914 | .show_host_port_state = 1, | |
a74bdf46 | 1915 | .get_host_def_dev_loss_tmo = qla2x00_get_host_def_loss_tmo, |
8482e118 | 1916 | |
bdf79621 | 1917 | .dd_fcrport_size = sizeof(struct fc_port *), |
ad3e0eda | 1918 | .show_rport_supported_classes = 1, |
8482e118 AV |
1919 | |
1920 | .get_starget_node_name = qla2x00_get_starget_node_name, | |
1921 | .show_starget_node_name = 1, | |
1922 | .get_starget_port_name = qla2x00_get_starget_port_name, | |
1923 | .show_starget_port_name = 1, | |
1924 | .get_starget_port_id = qla2x00_get_starget_port_id, | |
1925 | .show_starget_port_id = 1, | |
1926 | ||
8482e118 AV |
1927 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
1928 | .show_rport_dev_loss_tmo = 1, | |
1929 | ||
91ca7b01 | 1930 | .issue_fc_host_lip = qla2x00_issue_lip, |
5f3a9a20 SJ |
1931 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
1932 | .terminate_rport_io = qla2x00_terminate_rport_io, | |
392e2f65 | 1933 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
2c3dfe3f SJ |
1934 | |
1935 | .vport_create = qla24xx_vport_create, | |
1936 | .vport_disable = qla24xx_vport_disable, | |
1937 | .vport_delete = qla24xx_vport_delete, | |
9a069e19 GM |
1938 | .bsg_request = qla24xx_bsg_request, |
1939 | .bsg_timeout = qla24xx_bsg_timeout, | |
2c3dfe3f SJ |
1940 | }; |
1941 | ||
1942 | struct fc_function_template qla2xxx_transport_vport_functions = { | |
1943 | ||
1944 | .show_host_node_name = 1, | |
1945 | .show_host_port_name = 1, | |
1946 | .show_host_supported_classes = 1, | |
1947 | ||
1948 | .get_host_port_id = qla2x00_get_host_port_id, | |
1949 | .show_host_port_id = 1, | |
1950 | .get_host_speed = qla2x00_get_host_speed, | |
1951 | .show_host_speed = 1, | |
1952 | .get_host_port_type = qla2x00_get_host_port_type, | |
1953 | .show_host_port_type = 1, | |
1954 | .get_host_symbolic_name = qla2x00_get_host_symbolic_name, | |
1955 | .show_host_symbolic_name = 1, | |
1956 | .set_host_system_hostname = qla2x00_set_host_system_hostname, | |
1957 | .show_host_system_hostname = 1, | |
1958 | .get_host_fabric_name = qla2x00_get_host_fabric_name, | |
1959 | .show_host_fabric_name = 1, | |
1960 | .get_host_port_state = qla2x00_get_host_port_state, | |
1961 | .show_host_port_state = 1, | |
a74bdf46 | 1962 | .get_host_def_dev_loss_tmo = qla2x00_get_host_def_loss_tmo, |
2c3dfe3f SJ |
1963 | |
1964 | .dd_fcrport_size = sizeof(struct fc_port *), | |
1965 | .show_rport_supported_classes = 1, | |
1966 | ||
1967 | .get_starget_node_name = qla2x00_get_starget_node_name, | |
1968 | .show_starget_node_name = 1, | |
1969 | .get_starget_port_name = qla2x00_get_starget_port_name, | |
1970 | .show_starget_port_name = 1, | |
1971 | .get_starget_port_id = qla2x00_get_starget_port_id, | |
1972 | .show_starget_port_id = 1, | |
1973 | ||
2c3dfe3f SJ |
1974 | .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo, |
1975 | .show_rport_dev_loss_tmo = 1, | |
1976 | ||
1977 | .issue_fc_host_lip = qla2x00_issue_lip, | |
5f3a9a20 SJ |
1978 | .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, |
1979 | .terminate_rport_io = qla2x00_terminate_rport_io, | |
2c3dfe3f | 1980 | .get_fc_host_stats = qla2x00_get_fc_host_stats, |
9a069e19 GM |
1981 | .bsg_request = qla24xx_bsg_request, |
1982 | .bsg_timeout = qla24xx_bsg_timeout, | |
8482e118 AV |
1983 | }; |
1984 | ||
8482e118 | 1985 | void |
7b867cf7 | 1986 | qla2x00_init_host_attr(scsi_qla_host_t *vha) |
8482e118 | 1987 | { |
7b867cf7 | 1988 | struct qla_hw_data *ha = vha->hw; |
2ae2b370 AV |
1989 | u32 speed = FC_PORTSPEED_UNKNOWN; |
1990 | ||
7b867cf7 AC |
1991 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); |
1992 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); | |
1993 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; | |
1994 | fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports; | |
1995 | fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count; | |
2ae2b370 | 1996 | |
a9083016 | 1997 | if (IS_QLA8XXX_TYPE(ha)) |
3a03eb79 AV |
1998 | speed = FC_PORTSPEED_10GBIT; |
1999 | else if (IS_QLA25XX(ha)) | |
2ae2b370 AV |
2000 | speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | |
2001 | FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; | |
4d4df193 | 2002 | else if (IS_QLA24XX_TYPE(ha)) |
2ae2b370 AV |
2003 | speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT | |
2004 | FC_PORTSPEED_1GBIT; | |
2005 | else if (IS_QLA23XX(ha)) | |
2006 | speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; | |
2007 | else | |
2008 | speed = FC_PORTSPEED_1GBIT; | |
7b867cf7 | 2009 | fc_host_supported_speeds(vha->host) = speed; |
8482e118 | 2010 | } |