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