blob: 90bf7ad42f67a9d5bb0a8761bc8a231a838efb40 [file] [log] [blame]
8482e112005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
8482e112005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e112005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090012#include <linux/delay.h>
8482e112005-04-17 15:04:54 -050013
Adrian Bunka824ebb2008-01-17 09:02:15 -080014static int qla24xx_vport_disable(struct fc_vport *, bool);
Giridhar Malavali6e980162010-03-19 17:03:58 -070015
8482e112005-04-17 15:04:54 -050016/* SYSFS attributes --------------------------------------------------------- */
17
18static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080019qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
20 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050022{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050026
27 if (ha->fw_dump_reading == 0)
28 return 0;
8482e112005-04-17 15:04:54 -050029
Akinobu Mitab3dc9082008-07-24 08:31:47 -070030 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
31 ha->fw_dump_len);
8482e112005-04-17 15:04:54 -050032}
33
34static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080035qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
36 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050038{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080039 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050040 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080041 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050042 int reading;
8482e112005-04-17 15:04:54 -050043
44 if (off != 0)
45 return (0);
46
47 reading = simple_strtol(buf, NULL, 10);
48 switch (reading) {
49 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070050 if (!ha->fw_dump_reading)
51 break;
8482e112005-04-17 15:04:54 -050052
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053 qla_printk(KERN_INFO, ha,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080054 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070055
56 ha->fw_dump_reading = 0;
57 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050058 break;
59 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070060 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050061 ha->fw_dump_reading = 1;
62
8482e112005-04-17 15:04:54 -050063 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070064 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080065 vha->host_no);
8482e112005-04-17 15:04:54 -050066 }
67 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070068 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080069 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070070 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070071 case 3:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080072 qla2x00_system_error(vha);
Andrew Vasquez68af0812008-05-12 22:21:13 -070073 break;
8482e112005-04-17 15:04:54 -050074 }
75 return (count);
76}
77
78static struct bin_attribute sysfs_fw_dump_attr = {
79 .attr = {
80 .name = "fw_dump",
81 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050082 },
83 .size = 0,
84 .read = qla2x00_sysfs_read_fw_dump,
85 .write = qla2x00_sysfs_write_fw_dump,
86};
87
88static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080089qla2x00_sysfs_read_nvram(struct kobject *kobj,
90 struct bin_attribute *bin_attr,
91 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050092{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080093 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050094 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080095 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050096
Akinobu Mitab3dc9082008-07-24 08:31:47 -070097 if (!capable(CAP_SYS_ADMIN))
8482e112005-04-17 15:04:54 -050098 return 0;
99
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700100 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700101 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700102 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700103 return memory_read_from_buffer(buf, count, &off, ha->nvram,
104 ha->nvram_size);
8482e112005-04-17 15:04:54 -0500105}
106
107static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800108qla2x00_sysfs_write_nvram(struct kobject *kobj,
109 struct bin_attribute *bin_attr,
110 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500111{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800112 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -0500113 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800114 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500115 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500116
Andrew Vasquez3d790382009-03-24 09:08:14 -0700117 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
118 !ha->isp_ops->write_nvram)
8482e112005-04-17 15:04:54 -0500119 return 0;
120
121 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700122 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700123 uint32_t *iter;
124 uint32_t chksum;
125
126 iter = (uint32_t *)buf;
127 chksum = 0;
128 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
129 chksum += le32_to_cpu(*iter++);
130 chksum = ~chksum + 1;
131 *iter = cpu_to_le32(chksum);
132 } else {
133 uint8_t *iter;
134 uint8_t chksum;
135
136 iter = (uint8_t *)buf;
137 chksum = 0;
138 for (cnt = 0; cnt < count - 1; cnt++)
139 chksum += *iter++;
140 chksum = ~chksum + 1;
141 *iter = chksum;
142 }
8482e112005-04-17 15:04:54 -0500143
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700144 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
145 qla_printk(KERN_WARNING, ha,
146 "HBA not online, failing NVRAM update.\n");
147 return -EAGAIN;
148 }
149
8482e112005-04-17 15:04:54 -0500150 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800151 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
152 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700153 count);
8482e112005-04-17 15:04:54 -0500154
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700155 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800156 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700157 qla2xxx_wake_dpc(vha);
158 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800159
8482e112005-04-17 15:04:54 -0500160 return (count);
161}
162
163static struct bin_attribute sysfs_nvram_attr = {
164 .attr = {
165 .name = "nvram",
166 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500167 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800168 .size = 512,
8482e112005-04-17 15:04:54 -0500169 .read = qla2x00_sysfs_read_nvram,
170 .write = qla2x00_sysfs_write_nvram,
171};
172
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800173static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800174qla2x00_sysfs_read_optrom(struct kobject *kobj,
175 struct bin_attribute *bin_attr,
176 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800177{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800178 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800179 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800180 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800181
182 if (ha->optrom_state != QLA_SREADING)
183 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800184
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700185 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
186 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800187}
188
189static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800190qla2x00_sysfs_write_optrom(struct kobject *kobj,
191 struct bin_attribute *bin_attr,
192 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800193{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800194 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800195 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800196 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800197
198 if (ha->optrom_state != QLA_SWRITING)
199 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700200 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800201 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700202 if (off + count > ha->optrom_region_size)
203 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800204
205 memcpy(&ha->optrom_buffer[off], buf, count);
206
207 return count;
208}
209
210static struct bin_attribute sysfs_optrom_attr = {
211 .attr = {
212 .name = "optrom",
213 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800214 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700215 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800216 .read = qla2x00_sysfs_read_optrom,
217 .write = qla2x00_sysfs_write_optrom,
218};
219
220static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800221qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
222 struct bin_attribute *bin_attr,
223 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800225 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800226 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800227 struct qla_hw_data *ha = vha->hw;
228
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700229 uint32_t start = 0;
230 uint32_t size = ha->optrom_size;
231 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232
233 if (off)
234 return 0;
235
Andrew Vasquez85880802009-12-15 21:29:46 -0800236 if (unlikely(pci_channel_offline(ha->pdev)))
237 return 0;
238
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700239 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
240 return -EINVAL;
241 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800242 return -EINVAL;
243
244 switch (val) {
245 case 0:
246 if (ha->optrom_state != QLA_SREADING &&
247 ha->optrom_state != QLA_SWRITING)
248 break;
249
250 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700251
252 DEBUG2(qla_printk(KERN_INFO, ha,
253 "Freeing flash region allocation -- 0x%x bytes.\n",
254 ha->optrom_region_size));
255
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800256 vfree(ha->optrom_buffer);
257 ha->optrom_buffer = NULL;
258 break;
259 case 1:
260 if (ha->optrom_state != QLA_SWAITING)
261 break;
262
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700263 ha->optrom_region_start = start;
264 ha->optrom_region_size = start + size > ha->optrom_size ?
265 ha->optrom_size - start : size;
266
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800267 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700268 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269 if (ha->optrom_buffer == NULL) {
270 qla_printk(KERN_WARNING, ha,
271 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700272 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800273
274 ha->optrom_state = QLA_SWAITING;
275 return count;
276 }
277
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700278 DEBUG2(qla_printk(KERN_INFO, ha,
279 "Reading flash region -- 0x%x/0x%x.\n",
280 ha->optrom_region_start, ha->optrom_region_size));
281
282 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800283 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700284 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800285 break;
286 case 2:
287 if (ha->optrom_state != QLA_SWAITING)
288 break;
289
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700290 /*
291 * We need to be more restrictive on which FLASH regions are
292 * allowed to be updated via user-space. Regions accessible
293 * via this method include:
294 *
295 * ISP21xx/ISP22xx/ISP23xx type boards:
296 *
297 * 0x000000 -> 0x020000 -- Boot code.
298 *
299 * ISP2322/ISP24xx type boards:
300 *
301 * 0x000000 -> 0x07ffff -- Boot code.
302 * 0x080000 -> 0x0fffff -- Firmware.
303 *
304 * ISP25xx type boards:
305 *
306 * 0x000000 -> 0x07ffff -- Boot code.
307 * 0x080000 -> 0x0fffff -- Firmware.
308 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
309 */
310 valid = 0;
311 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
312 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700313 else if (start == (ha->flt_region_boot * 4) ||
314 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700315 valid = 1;
Andrew Vasquez6431c5d2009-03-05 11:07:00 -0800316 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700317 valid = 1;
318 if (!valid) {
319 qla_printk(KERN_WARNING, ha,
320 "Invalid start region 0x%x/0x%x.\n", start, size);
321 return -EINVAL;
322 }
323
324 ha->optrom_region_start = start;
325 ha->optrom_region_size = start + size > ha->optrom_size ?
326 ha->optrom_size - start : size;
327
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800328 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700329 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800330 if (ha->optrom_buffer == NULL) {
331 qla_printk(KERN_WARNING, ha,
332 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700333 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800334
335 ha->optrom_state = QLA_SWAITING;
336 return count;
337 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700338
339 DEBUG2(qla_printk(KERN_INFO, ha,
340 "Staging flash region write -- 0x%x/0x%x.\n",
341 ha->optrom_region_start, ha->optrom_region_size));
342
343 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800344 break;
345 case 3:
346 if (ha->optrom_state != QLA_SWRITING)
347 break;
348
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700349 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
350 qla_printk(KERN_WARNING, ha,
351 "HBA not online, failing flash update.\n");
352 return -EAGAIN;
353 }
354
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700355 DEBUG2(qla_printk(KERN_INFO, ha,
356 "Writing flash region -- 0x%x/0x%x.\n",
357 ha->optrom_region_start, ha->optrom_region_size));
358
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800359 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700360 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800361 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700362 default:
363 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800364 }
365 return count;
366}
367
368static struct bin_attribute sysfs_optrom_ctl_attr = {
369 .attr = {
370 .name = "optrom_ctl",
371 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800372 },
373 .size = 0,
374 .write = qla2x00_sysfs_write_optrom_ctl,
375};
376
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800377static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800378qla2x00_sysfs_read_vpd(struct kobject *kobj,
379 struct bin_attribute *bin_attr,
380 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800381{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800382 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800383 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800384 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800385
Andrew Vasquez85880802009-12-15 21:29:46 -0800386 if (unlikely(pci_channel_offline(ha->pdev)))
387 return 0;
388
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700389 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800390 return 0;
391
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700392 if (IS_NOCACHE_VPD_TYPE(ha))
393 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
394 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700395 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800396}
397
398static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800399qla2x00_sysfs_write_vpd(struct kobject *kobj,
400 struct bin_attribute *bin_attr,
401 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800402{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800403 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800404 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800405 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700406 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800407
Andrew Vasquez85880802009-12-15 21:29:46 -0800408 if (unlikely(pci_channel_offline(ha->pdev)))
409 return 0;
410
Andrew Vasquez3d790382009-03-24 09:08:14 -0700411 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
412 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800413 return 0;
414
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700415 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
416 qla_printk(KERN_WARNING, ha,
417 "HBA not online, failing VPD update.\n");
418 return -EAGAIN;
419 }
420
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800421 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800422 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
423 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800424
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700425 /* Update flash version information for 4Gb & above. */
426 if (!IS_FWI2_CAPABLE(ha))
427 goto done;
428
429 tmp_data = vmalloc(256);
430 if (!tmp_data) {
431 qla_printk(KERN_WARNING, ha,
432 "Unable to allocate memory for VPD information update.\n");
433 goto done;
434 }
435 ha->isp_ops->get_flash_version(vha, tmp_data);
436 vfree(tmp_data);
437done:
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800438 return count;
439}
440
441static struct bin_attribute sysfs_vpd_attr = {
442 .attr = {
443 .name = "vpd",
444 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800445 },
446 .size = 0,
447 .read = qla2x00_sysfs_read_vpd,
448 .write = qla2x00_sysfs_write_vpd,
449};
450
Andrew Vasquez88729e52006-06-23 16:10:50 -0700451static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800452qla2x00_sysfs_read_sfp(struct kobject *kobj,
453 struct bin_attribute *bin_attr,
454 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700455{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800456 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700457 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800458 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700459 uint16_t iter, addr, offset;
460 int rval;
461
462 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
463 return 0;
464
Andrew Vasqueze8711082008-01-31 12:33:48 -0800465 if (ha->sfp_data)
466 goto do_read;
467
468 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
469 &ha->sfp_data_dma);
470 if (!ha->sfp_data) {
471 qla_printk(KERN_WARNING, ha,
472 "Unable to allocate memory for SFP read-data.\n");
473 return 0;
474 }
475
476do_read:
477 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700478 addr = 0xa0;
479 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
480 iter++, offset += SFP_BLOCK_SIZE) {
481 if (iter == 4) {
482 /* Skip to next device address. */
483 addr = 0xa2;
484 offset = 0;
485 }
486
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800487 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700488 SFP_BLOCK_SIZE);
489 if (rval != QLA_SUCCESS) {
490 qla_printk(KERN_WARNING, ha,
491 "Unable to read SFP data (%x/%x/%x).\n", rval,
492 addr, offset);
493 count = 0;
494 break;
495 }
496 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
497 buf += SFP_BLOCK_SIZE;
498 }
499
500 return count;
501}
502
503static struct bin_attribute sysfs_sfp_attr = {
504 .attr = {
505 .name = "sfp",
506 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700507 },
508 .size = SFP_DEV_SIZE * 2,
509 .read = qla2x00_sysfs_read_sfp,
510};
511
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700512static ssize_t
513qla2x00_sysfs_write_reset(struct kobject *kobj,
514 struct bin_attribute *bin_attr,
515 char *buf, loff_t off, size_t count)
516{
517 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
518 struct device, kobj)));
519 struct qla_hw_data *ha = vha->hw;
520 int type;
521
522 if (off != 0)
523 return 0;
524
525 type = simple_strtol(buf, NULL, 10);
526 switch (type) {
527 case 0x2025c:
528 qla_printk(KERN_INFO, ha,
529 "Issuing ISP reset on (%ld).\n", vha->host_no);
530
531 scsi_block_requests(vha->host);
532 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
533 qla2xxx_wake_dpc(vha);
534 qla2x00_wait_for_chip_reset(vha);
535 scsi_unblock_requests(vha->host);
536 break;
537 case 0x2025d:
538 if (!IS_QLA81XX(ha))
539 break;
540
541 qla_printk(KERN_INFO, ha,
542 "Issuing MPI reset on (%ld).\n", vha->host_no);
543
544 /* Make sure FC side is not in reset */
545 qla2x00_wait_for_hba_online(vha);
546
547 /* Issue MPI reset */
548 scsi_block_requests(vha->host);
549 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
550 qla_printk(KERN_WARNING, ha,
551 "MPI reset failed on (%ld).\n", vha->host_no);
552 scsi_unblock_requests(vha->host);
553 break;
554 }
555 return count;
556}
557
558static struct bin_attribute sysfs_reset_attr = {
559 .attr = {
560 .name = "reset",
561 .mode = S_IWUSR,
562 },
563 .size = 0,
564 .write = qla2x00_sysfs_write_reset,
565};
566
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700567static ssize_t
568qla2x00_sysfs_write_edc(struct kobject *kobj,
569 struct bin_attribute *bin_attr,
570 char *buf, loff_t off, size_t count)
571{
572 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
573 struct device, kobj)));
574 struct qla_hw_data *ha = vha->hw;
575 uint16_t dev, adr, opt, len;
576 int rval;
577
578 ha->edc_data_len = 0;
579
580 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
581 return 0;
582
583 if (!ha->edc_data) {
584 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
585 &ha->edc_data_dma);
586 if (!ha->edc_data) {
587 DEBUG2(qla_printk(KERN_INFO, ha,
588 "Unable to allocate memory for EDC write.\n"));
589 return 0;
590 }
591 }
592
593 dev = le16_to_cpup((void *)&buf[0]);
594 adr = le16_to_cpup((void *)&buf[2]);
595 opt = le16_to_cpup((void *)&buf[4]);
596 len = le16_to_cpup((void *)&buf[6]);
597
598 if (!(opt & BIT_0))
599 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
600 return -EINVAL;
601
602 memcpy(ha->edc_data, &buf[8], len);
603
604 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
605 ha->edc_data, len, opt);
606 if (rval != QLA_SUCCESS) {
607 DEBUG2(qla_printk(KERN_INFO, ha,
608 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
609 rval, dev, adr, opt, len, *buf));
610 return 0;
611 }
612
613 return count;
614}
615
616static struct bin_attribute sysfs_edc_attr = {
617 .attr = {
618 .name = "edc",
619 .mode = S_IWUSR,
620 },
621 .size = 0,
622 .write = qla2x00_sysfs_write_edc,
623};
624
625static ssize_t
626qla2x00_sysfs_write_edc_status(struct kobject *kobj,
627 struct bin_attribute *bin_attr,
628 char *buf, loff_t off, size_t count)
629{
630 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
631 struct device, kobj)));
632 struct qla_hw_data *ha = vha->hw;
633 uint16_t dev, adr, opt, len;
634 int rval;
635
636 ha->edc_data_len = 0;
637
638 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
639 return 0;
640
641 if (!ha->edc_data) {
642 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
643 &ha->edc_data_dma);
644 if (!ha->edc_data) {
645 DEBUG2(qla_printk(KERN_INFO, ha,
646 "Unable to allocate memory for EDC status.\n"));
647 return 0;
648 }
649 }
650
651 dev = le16_to_cpup((void *)&buf[0]);
652 adr = le16_to_cpup((void *)&buf[2]);
653 opt = le16_to_cpup((void *)&buf[4]);
654 len = le16_to_cpup((void *)&buf[6]);
655
656 if (!(opt & BIT_0))
657 if (len == 0 || len > DMA_POOL_SIZE)
658 return -EINVAL;
659
660 memset(ha->edc_data, 0, len);
661 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
662 ha->edc_data, len, opt);
663 if (rval != QLA_SUCCESS) {
664 DEBUG2(qla_printk(KERN_INFO, ha,
665 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
666 rval, dev, adr, opt, len));
667 return 0;
668 }
669
670 ha->edc_data_len = len;
671
672 return count;
673}
674
675static ssize_t
676qla2x00_sysfs_read_edc_status(struct kobject *kobj,
677 struct bin_attribute *bin_attr,
678 char *buf, loff_t off, size_t count)
679{
680 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
681 struct device, kobj)));
682 struct qla_hw_data *ha = vha->hw;
683
684 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
685 return 0;
686
687 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
688 return -EINVAL;
689
690 memcpy(buf, ha->edc_data, ha->edc_data_len);
691
692 return ha->edc_data_len;
693}
694
695static struct bin_attribute sysfs_edc_status_attr = {
696 .attr = {
697 .name = "edc_status",
698 .mode = S_IRUSR | S_IWUSR,
699 },
700 .size = 0,
701 .write = qla2x00_sysfs_write_edc_status,
702 .read = qla2x00_sysfs_read_edc_status,
703};
704
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700705static ssize_t
706qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
707 struct bin_attribute *bin_attr,
708 char *buf, loff_t off, size_t count)
709{
710 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
711 struct device, kobj)));
712 struct qla_hw_data *ha = vha->hw;
713 int rval;
714 uint16_t actual_size;
715
716 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
717 return 0;
718
719 if (ha->xgmac_data)
720 goto do_read;
721
722 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
723 &ha->xgmac_data_dma, GFP_KERNEL);
724 if (!ha->xgmac_data) {
725 qla_printk(KERN_WARNING, ha,
726 "Unable to allocate memory for XGMAC read-data.\n");
727 return 0;
728 }
729
730do_read:
731 actual_size = 0;
732 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
733
734 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
735 XGMAC_DATA_SIZE, &actual_size);
736 if (rval != QLA_SUCCESS) {
737 qla_printk(KERN_WARNING, ha,
738 "Unable to read XGMAC data (%x).\n", rval);
739 count = 0;
740 }
741
742 count = actual_size > count ? count: actual_size;
743 memcpy(buf, ha->xgmac_data, count);
744
745 return count;
746}
747
748static struct bin_attribute sysfs_xgmac_stats_attr = {
749 .attr = {
750 .name = "xgmac_stats",
751 .mode = S_IRUSR,
752 },
753 .size = 0,
754 .read = qla2x00_sysfs_read_xgmac_stats,
755};
756
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700757static ssize_t
758qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
759 struct bin_attribute *bin_attr,
760 char *buf, loff_t off, size_t count)
761{
762 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
763 struct device, kobj)));
764 struct qla_hw_data *ha = vha->hw;
765 int rval;
766 uint16_t actual_size;
767
768 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
769 return 0;
770
771 if (ha->dcbx_tlv)
772 goto do_read;
773
774 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
775 &ha->dcbx_tlv_dma, GFP_KERNEL);
776 if (!ha->dcbx_tlv) {
777 qla_printk(KERN_WARNING, ha,
778 "Unable to allocate memory for DCBX TLV read-data.\n");
779 return 0;
780 }
781
782do_read:
783 actual_size = 0;
784 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
785
786 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
787 DCBX_TLV_DATA_SIZE);
788 if (rval != QLA_SUCCESS) {
789 qla_printk(KERN_WARNING, ha,
790 "Unable to read DCBX TLV data (%x).\n", rval);
791 count = 0;
792 }
793
794 memcpy(buf, ha->dcbx_tlv, count);
795
796 return count;
797}
798
799static struct bin_attribute sysfs_dcbx_tlv_attr = {
800 .attr = {
801 .name = "dcbx_tlv",
802 .mode = S_IRUSR,
803 },
804 .size = 0,
805 .read = qla2x00_sysfs_read_dcbx_tlv,
806};
807
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700808static struct sysfs_entry {
809 char *name;
810 struct bin_attribute *attr;
811 int is4GBp_only;
812} bin_file_entries[] = {
813 { "fw_dump", &sysfs_fw_dump_attr, },
814 { "nvram", &sysfs_nvram_attr, },
815 { "optrom", &sysfs_optrom_attr, },
816 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
817 { "vpd", &sysfs_vpd_attr, 1 },
818 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700819 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700820 { "edc", &sysfs_edc_attr, 2 },
821 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700822 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700823 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800824 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700825};
826
8482e112005-04-17 15:04:54 -0500827void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800828qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500829{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800830 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700831 struct sysfs_entry *iter;
832 int ret;
8482e112005-04-17 15:04:54 -0500833
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700834 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800835 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700836 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700837 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
838 continue;
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700839 if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
840 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700841
842 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
843 iter->attr);
844 if (ret)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800845 qla_printk(KERN_INFO, vha->hw,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700846 "Unable to create sysfs %s binary attribute "
847 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700848 }
8482e112005-04-17 15:04:54 -0500849}
850
851void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800852qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500853{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800854 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700855 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800856 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500857
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700858 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700859 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700860 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700861 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
862 continue;
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700863 if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
864 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700865
Andrew Vasquez7914d002006-06-23 16:10:55 -0700866 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700867 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700868 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800869
870 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800871 ha->isp_ops->beacon_off(vha);
8482e112005-04-17 15:04:54 -0500872}
873
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700874/* Scsi_Host attributes. */
875
876static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100877qla2x00_drvr_version_show(struct device *dev,
878 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700879{
880 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
881}
882
883static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100884qla2x00_fw_version_show(struct device *dev,
885 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700886{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800887 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
888 struct qla_hw_data *ha = vha->hw;
889 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700890
891 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800892 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700893}
894
895static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100896qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
897 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700898{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800899 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
900 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700901 uint32_t sn;
902
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700903 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800904 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700905 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
906 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700907
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700908 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
909 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
910 sn % 100000);
911}
912
913static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100914qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
915 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700916{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800917 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
918 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700919}
920
921static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100922qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
923 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700924{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800925 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
926 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700927 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
928 ha->product_id[0], ha->product_id[1], ha->product_id[2],
929 ha->product_id[3]);
930}
931
932static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100933qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
934 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700935{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800936 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
937 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700938}
939
940static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100941qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
942 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700943{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800944 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700945 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800946 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700947}
948
949static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100950qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
951 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700952{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800953 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700954 char pci_info[30];
955
956 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800957 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700958}
959
960static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100961qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
962 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700963{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800964 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
965 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700966 int len = 0;
967
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800968 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
969 atomic_read(&vha->loop_state) == LOOP_DEAD)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700970 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
972 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
973 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700974 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
975 else {
976 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
977
978 switch (ha->current_topology) {
979 case ISP_CFG_NL:
980 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
981 break;
982 case ISP_CFG_FL:
983 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
984 break;
985 case ISP_CFG_N:
986 len += snprintf(buf + len, PAGE_SIZE-len,
987 "N_Port to N_Port\n");
988 break;
989 case ISP_CFG_F:
990 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
991 break;
992 default:
993 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
994 break;
995 }
996 }
997 return len;
998}
999
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001000static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001001qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1002 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001003{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001004 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001005 int len = 0;
1006
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001008 case QLA_ZIO_MODE_6:
1009 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1010 break;
1011 case QLA_ZIO_DISABLED:
1012 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1013 break;
1014 }
1015 return len;
1016}
1017
1018static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001019qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1020 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001021{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001022 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1023 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001024 int val = 0;
1025 uint16_t zio_mode;
1026
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001027 if (!IS_ZIO_SUPPORTED(ha))
1028 return -ENOTSUPP;
1029
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001030 if (sscanf(buf, "%d", &val) != 1)
1031 return -EINVAL;
1032
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001033 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001034 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001035 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001036 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001037
1038 /* Update per-hba values and queue a reset. */
1039 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1040 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001041 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001042 }
1043 return strlen(buf);
1044}
1045
1046static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001047qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1048 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001049{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001051
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001052 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001053}
1054
1055static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001056qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1057 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001058{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001059 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001060 int val = 0;
1061 uint16_t zio_timer;
1062
1063 if (sscanf(buf, "%d", &val) != 1)
1064 return -EINVAL;
1065 if (val > 25500 || val < 100)
1066 return -ERANGE;
1067
1068 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001069 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001070
1071 return strlen(buf);
1072}
1073
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001074static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001075qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1076 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001077{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001078 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001079 int len = 0;
1080
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001081 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001082 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1083 else
1084 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1085 return len;
1086}
1087
1088static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001089qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1090 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001091{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001092 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1093 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001094 int val = 0;
1095 int rval;
1096
1097 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1098 return -EPERM;
1099
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001100 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001101 qla_printk(KERN_WARNING, ha,
1102 "Abort ISP active -- ignoring beacon request.\n");
1103 return -EBUSY;
1104 }
1105
1106 if (sscanf(buf, "%d", &val) != 1)
1107 return -EINVAL;
1108
1109 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001110 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001111 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001112 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001113
1114 if (rval != QLA_SUCCESS)
1115 count = 0;
1116
1117 return count;
1118}
1119
Andrew Vasquez30c47662007-01-29 10:22:21 -08001120static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001121qla2x00_optrom_bios_version_show(struct device *dev,
1122 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001123{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001124 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1125 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001126 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1127 ha->bios_revision[0]);
1128}
1129
1130static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001131qla2x00_optrom_efi_version_show(struct device *dev,
1132 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001133{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001134 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1135 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001136 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1137 ha->efi_revision[0]);
1138}
1139
1140static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001141qla2x00_optrom_fcode_version_show(struct device *dev,
1142 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001143{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001144 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1145 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001146 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1147 ha->fcode_revision[0]);
1148}
1149
1150static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001151qla2x00_optrom_fw_version_show(struct device *dev,
1152 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001153{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001154 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1155 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001156 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1157 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1158 ha->fw_revision[3]);
1159}
1160
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001161static ssize_t
1162qla2x00_total_isp_aborts_show(struct device *dev,
1163 struct device_attribute *attr, char *buf)
1164{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001165 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1166 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001167 return snprintf(buf, PAGE_SIZE, "%d\n",
1168 ha->qla_stats.total_isp_aborts);
1169}
1170
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001171static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001172qla24xx_84xx_fw_version_show(struct device *dev,
1173 struct device_attribute *attr, char *buf)
1174{
1175 int rval = QLA_SUCCESS;
1176 uint16_t status[2] = {0, 0};
1177 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1178 struct qla_hw_data *ha = vha->hw;
1179
1180 if (IS_QLA84XX(ha) && ha->cs84xx) {
1181 if (ha->cs84xx->op_fw_version == 0) {
1182 rval = qla84xx_verify_chip(vha, status);
1183 }
1184
1185 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1186 return snprintf(buf, PAGE_SIZE, "%u\n",
1187 (uint32_t)ha->cs84xx->op_fw_version);
1188 }
1189
1190 return snprintf(buf, PAGE_SIZE, "\n");
1191}
1192
1193static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001194qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1195 char *buf)
1196{
1197 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1198 struct qla_hw_data *ha = vha->hw;
1199
1200 if (!IS_QLA81XX(ha))
1201 return snprintf(buf, PAGE_SIZE, "\n");
1202
Andrew Vasquez55a96152009-03-24 09:08:03 -07001203 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001204 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001205 ha->mpi_capabilities);
1206}
1207
1208static ssize_t
1209qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1210 char *buf)
1211{
1212 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1213 struct qla_hw_data *ha = vha->hw;
1214
1215 if (!IS_QLA81XX(ha))
1216 return snprintf(buf, PAGE_SIZE, "\n");
1217
1218 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1219 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001220}
1221
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001222static ssize_t
1223qla2x00_flash_block_size_show(struct device *dev,
1224 struct device_attribute *attr, char *buf)
1225{
1226 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1227 struct qla_hw_data *ha = vha->hw;
1228
1229 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1230}
1231
Andrew Vasquezbad70012009-04-06 22:33:38 -07001232static ssize_t
1233qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1234 char *buf)
1235{
1236 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1237
1238 if (!IS_QLA81XX(vha->hw))
1239 return snprintf(buf, PAGE_SIZE, "\n");
1240
1241 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1242}
1243
1244static ssize_t
1245qla2x00_vn_port_mac_address_show(struct device *dev,
1246 struct device_attribute *attr, char *buf)
1247{
1248 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1249
1250 if (!IS_QLA81XX(vha->hw))
1251 return snprintf(buf, PAGE_SIZE, "\n");
1252
1253 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1254 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1255 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1256 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1257}
1258
Andrew Vasquez7f774022009-06-03 09:55:12 -07001259static ssize_t
1260qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1261 char *buf)
1262{
1263 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1264
1265 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1266}
1267
Andrew Vasquez656e8912009-06-03 09:55:29 -07001268static ssize_t
1269qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1270 char *buf)
1271{
1272 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001273 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001274 uint16_t state[5];
1275
Santosh Vernekard6136f32010-03-19 16:59:20 -07001276 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1277 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1278 DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
1279 __func__, vha->host_no));
1280 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001281 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001282 if (rval != QLA_SUCCESS)
1283 memset(state, -1, sizeof(state));
1284
1285 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1286 state[1], state[2], state[3], state[4]);
1287}
1288
Tony Jonesee959b02008-02-22 00:13:36 +01001289static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1290static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1291static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1292static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1293static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1294static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1295static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1296static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001297static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001298static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1299static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1300 qla2x00_zio_timer_store);
1301static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1302 qla2x00_beacon_store);
1303static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1304 qla2x00_optrom_bios_version_show, NULL);
1305static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1306 qla2x00_optrom_efi_version_show, NULL);
1307static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1308 qla2x00_optrom_fcode_version_show, NULL);
1309static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1310 NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001311static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1312 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001313static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1314 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001315static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001316static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001317static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1318 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001319static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1320static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1321 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001322static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001323static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001324
Tony Jonesee959b02008-02-22 00:13:36 +01001325struct device_attribute *qla2x00_host_attrs[] = {
1326 &dev_attr_driver_version,
1327 &dev_attr_fw_version,
1328 &dev_attr_serial_num,
1329 &dev_attr_isp_name,
1330 &dev_attr_isp_id,
1331 &dev_attr_model_name,
1332 &dev_attr_model_desc,
1333 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001334 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001335 &dev_attr_zio,
1336 &dev_attr_zio_timer,
1337 &dev_attr_beacon,
1338 &dev_attr_optrom_bios_version,
1339 &dev_attr_optrom_efi_version,
1340 &dev_attr_optrom_fcode_version,
1341 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001342 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001343 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001344 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001345 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001346 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001347 &dev_attr_vlan_id,
1348 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001349 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001350 &dev_attr_fw_state,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001351 NULL,
1352};
1353
8482e112005-04-17 15:04:54 -05001354/* Host attributes. */
1355
1356static void
1357qla2x00_get_host_port_id(struct Scsi_Host *shost)
1358{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001359 scsi_qla_host_t *vha = shost_priv(shost);
8482e112005-04-17 15:04:54 -05001360
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001361 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1362 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e112005-04-17 15:04:54 -05001363}
1364
1365static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001366qla2x00_get_host_speed(struct Scsi_Host *shost)
1367{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001368 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1369 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001370 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001371
1372 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001373 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001374 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001375 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001376 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001377 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001378 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001379 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001380 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001381 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001382 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001383 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001384 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001385 case PORT_SPEED_10GB:
1386 speed = FC_PORTSPEED_10GBIT;
1387 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001388 }
1389 fc_host_speed(shost) = speed;
1390}
1391
1392static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001393qla2x00_get_host_port_type(struct Scsi_Host *shost)
1394{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001395 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001396 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1397
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001398 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001399 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1400 return;
1401 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001403 case ISP_CFG_NL:
1404 port_type = FC_PORTTYPE_LPORT;
1405 break;
1406 case ISP_CFG_FL:
1407 port_type = FC_PORTTYPE_NLPORT;
1408 break;
1409 case ISP_CFG_N:
1410 port_type = FC_PORTTYPE_PTP;
1411 break;
1412 case ISP_CFG_F:
1413 port_type = FC_PORTTYPE_NPORT;
1414 break;
1415 }
1416 fc_host_port_type(shost) = port_type;
1417}
1418
1419static void
8482e112005-04-17 15:04:54 -05001420qla2x00_get_starget_node_name(struct scsi_target *starget)
1421{
1422 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001423 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001424 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001425 u64 node_name = 0;
8482e112005-04-17 15:04:54 -05001426
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001427 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001428 if (fcport->rport &&
1429 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001430 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001431 break;
1432 }
1433 }
1434
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001435 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -05001436}
1437
1438static void
1439qla2x00_get_starget_port_name(struct scsi_target *starget)
1440{
1441 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001442 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001443 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001444 u64 port_name = 0;
8482e112005-04-17 15:04:54 -05001445
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001446 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001447 if (fcport->rport &&
1448 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001449 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001450 break;
1451 }
1452 }
1453
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001454 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -05001455}
1456
1457static void
1458qla2x00_get_starget_port_id(struct scsi_target *starget)
1459{
1460 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001461 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001462 fc_port_t *fcport;
1463 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -05001464
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001465 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001466 if (fcport->rport &&
1467 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001468 port_id = fcport->d_id.b.domain << 16 |
1469 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1470 break;
1471 }
1472 }
1473
8482e112005-04-17 15:04:54 -05001474 fc_starget_port_id(starget) = port_id;
1475}
1476
1477static void
8482e112005-04-17 15:04:54 -05001478qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1479{
8482e112005-04-17 15:04:54 -05001480 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001481 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -05001482 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001483 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -05001484}
1485
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001486static void
1487qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1488{
1489 struct Scsi_Host *host = rport_to_shost(rport);
1490 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1491
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001492 if (!fcport)
1493 return;
1494
Andrew Vasquez85880802009-12-15 21:29:46 -08001495 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1496 return;
1497
1498 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001499 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001500 return;
1501 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001502
1503 /*
1504 * Transport has effectively 'deleted' the rport, clear
1505 * all local references.
1506 */
1507 spin_lock_irq(host->host_lock);
1508 fcport->rport = NULL;
1509 *((fc_port_t **)rport->dd_data) = NULL;
1510 spin_unlock_irq(host->host_lock);
1511}
1512
1513static void
1514qla2x00_terminate_rport_io(struct fc_rport *rport)
1515{
1516 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1517
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001518 if (!fcport)
1519 return;
1520
Andrew Vasquez85880802009-12-15 21:29:46 -08001521 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1522 return;
1523
Seokmann Jub9b12f72009-03-24 09:08:18 -07001524 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1525 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1526 return;
1527 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001528 /*
1529 * At this point all fcport's software-states are cleared. Perform any
1530 * final cleanup of firmware resources (PCBs and XCBs).
1531 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001532 if (fcport->loop_id != FC_NO_LOOP_ID &&
1533 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001534 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1535 fcport->loop_id, fcport->d_id.b.domain,
1536 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001537}
1538
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001539static int
1540qla2x00_issue_lip(struct Scsi_Host *shost)
1541{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001542 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001543
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001544 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001545 return 0;
1546}
1547
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001548static struct fc_host_statistics *
1549qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1550{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001551 scsi_qla_host_t *vha = shost_priv(shost);
1552 struct qla_hw_data *ha = vha->hw;
1553 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001554 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001555 struct link_statistics *stats;
1556 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001557 struct fc_host_statistics *pfc_host_stat;
1558
1559 pfc_host_stat = &ha->fc_host_stat;
1560 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1561
Andrew Vasquez85880802009-12-15 21:29:46 -08001562 if (test_bit(UNLOADING, &vha->dpc_flags))
1563 goto done;
1564
1565 if (unlikely(pci_channel_offline(ha->pdev)))
1566 goto done;
1567
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001568 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1569 if (stats == NULL) {
1570 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001571 __func__, base_vha->host_no));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001572 goto done;
1573 }
1574 memset(stats, 0, DMA_POOL_SIZE);
1575
1576 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001577 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001578 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1579 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1580 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1581 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001582 !ha->dpc_active) {
1583 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001584 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1585 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001586 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001587
1588 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001589 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001590
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001591 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1592 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1593 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1594 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1595 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1596 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1597 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001598 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001599 pfc_host_stat->tx_frames = stats->tx_frames;
1600 pfc_host_stat->rx_frames = stats->rx_frames;
1601 pfc_host_stat->dumped_frames = stats->dumped_frames;
1602 pfc_host_stat->nos_count = stats->nos_rcvd;
1603 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001604 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1605 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001606
1607done_free:
1608 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001609done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001610 return pfc_host_stat;
1611}
1612
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001613static void
1614qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1615{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001616 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001617
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001618 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001619}
1620
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001621static void
1622qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1623{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001625
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001626 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001627}
1628
Andrew Vasquez90991c82006-10-02 12:00:46 -07001629static void
1630qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1631{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001632 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001633 u64 node_name;
1634
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001635 if (vha->device_flags & SWITCH_FOUND)
1636 node_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001637 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001638 node_name = wwn_to_u64(vha->node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001639
1640 fc_host_fabric_name(shost) = node_name;
1641}
1642
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001643static void
1644qla2x00_get_host_port_state(struct Scsi_Host *shost)
1645{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001646 scsi_qla_host_t *vha = shost_priv(shost);
1647 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001648
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001649 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001650 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001651 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001652 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1653 else
1654 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1655}
1656
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001657static int
1658qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1659{
1660 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001661 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001662 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1663 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001664 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001665 uint16_t options = 0;
1666 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001667 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001668
1669 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1670 if (ret) {
1671 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1672 "status %x\n", ret));
1673 return (ret);
1674 }
1675
1676 vha = qla24xx_create_vhost(fc_vport);
1677 if (vha == NULL) {
1678 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1679 vha));
1680 return FC_VPORT_FAILED;
1681 }
1682 if (disable) {
1683 atomic_set(&vha->vp_state, VP_OFFLINE);
1684 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1685 } else
1686 atomic_set(&vha->vp_state, VP_FAILED);
1687
1688 /* ready to create vport */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001689 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1690 vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001691
1692 /* initialized vport states */
1693 atomic_set(&vha->loop_state, LOOP_DOWN);
1694 vha->vp_err_state= VP_ERR_PORTDWN;
1695 vha->vp_prev_err_state= VP_ERR_UNKWN;
1696 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001697 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1698 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001699 /* Don't retry or attempt login of this virtual port */
1700 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001701 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001702 atomic_set(&vha->loop_state, LOOP_DEAD);
1703 if (!disable)
1704 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1705 }
1706
James Bottomleyd139b9b2009-11-05 13:33:12 -06001707 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1708 &ha->pdev->dev)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001709 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1710 vha->host_no, vha->vp_idx));
1711 goto vport_create_failed_2;
1712 }
1713
1714 /* initialize attributes */
1715 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1716 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1717 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001718 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001719 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001720 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001721
1722 qla24xx_vport_disable(fc_vport, disable);
1723
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001724 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001725 req = ha->req_q_map[1];
1726 goto vport_queue;
1727 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001728 goto vport_queue;
1729 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001730 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1731 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1732 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001733 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001734 qos = ha->npiv_info[cnt].q_qos;
1735 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001736 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001737 }
1738 if (qos) {
1739 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1740 qos);
1741 if (!ret)
1742 qla_printk(KERN_WARNING, ha,
1743 "Can't create request queue for vp_idx:%d\n",
1744 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001745 else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001746 DEBUG2(qla_printk(KERN_INFO, ha,
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001747 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1748 ret, qos, vha->vp_idx));
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001749 req = ha->req_q_map[ret];
1750 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001751 }
1752
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001753vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001754 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001755 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001756
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001757vport_create_failed_2:
1758 qla24xx_disable_vp(vha);
1759 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001760 scsi_host_put(vha->host);
1761 return FC_VPORT_FAILED;
1762}
1763
Adrian Bunka824ebb2008-01-17 09:02:15 -08001764static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001765qla24xx_vport_delete(struct fc_vport *fc_vport)
1766{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001767 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001768 fc_port_t *fcport, *tfcport;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001769 struct qla_hw_data *ha = vha->hw;
1770 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001771
1772 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001773 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001774 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001775
1776 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001777
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001778 fc_remove_host(vha->host);
1779
1780 scsi_remove_host(vha->host);
1781
1782 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1783 list_del(&fcport->list);
1784 kfree(fcport);
1785 fcport = NULL;
1786 }
1787
1788 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001789
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001790 mutex_lock(&ha->vport_lock);
1791 ha->cur_vport_count--;
1792 clear_bit(vha->vp_idx, ha->vp_idx_map);
1793 mutex_unlock(&ha->vport_lock);
1794
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001795 if (vha->timer_active) {
1796 qla2x00_vp_stop_timer(vha);
1797 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1798 "has stopped\n",
1799 vha->host_no, vha->vp_idx, vha));
1800 }
1801
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001802 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001803 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001804 qla_printk(KERN_WARNING, ha,
1805 "Queue delete failed.\n");
1806 }
1807
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001808 scsi_host_put(vha->host);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001809 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001810 return 0;
1811}
1812
Adrian Bunka824ebb2008-01-17 09:02:15 -08001813static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001814qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1815{
1816 scsi_qla_host_t *vha = fc_vport->dd_data;
1817
1818 if (disable)
1819 qla24xx_disable_vp(vha);
1820 else
1821 qla24xx_enable_vp(vha);
1822
1823 return 0;
1824}
1825
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001826struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001827
1828 .show_host_node_name = 1,
1829 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001830 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001831 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001832
8482e112005-04-17 15:04:54 -05001833 .get_host_port_id = qla2x00_get_host_port_id,
1834 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001835 .get_host_speed = qla2x00_get_host_speed,
1836 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001837 .get_host_port_type = qla2x00_get_host_port_type,
1838 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001839 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1840 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001841 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1842 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001843 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1844 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001845 .get_host_port_state = qla2x00_get_host_port_state,
1846 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001847
bdf79622005-04-17 15:06:53 -05001848 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001849 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001850
1851 .get_starget_node_name = qla2x00_get_starget_node_name,
1852 .show_starget_node_name = 1,
1853 .get_starget_port_name = qla2x00_get_starget_port_name,
1854 .show_starget_port_name = 1,
1855 .get_starget_port_id = qla2x00_get_starget_port_id,
1856 .show_starget_port_id = 1,
1857
8482e112005-04-17 15:04:54 -05001858 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1859 .show_rport_dev_loss_tmo = 1,
1860
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001861 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001862 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1863 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001864 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001865
1866 .vport_create = qla24xx_vport_create,
1867 .vport_disable = qla24xx_vport_disable,
1868 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001869 .bsg_request = qla24xx_bsg_request,
1870 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001871};
1872
1873struct fc_function_template qla2xxx_transport_vport_functions = {
1874
1875 .show_host_node_name = 1,
1876 .show_host_port_name = 1,
1877 .show_host_supported_classes = 1,
1878
1879 .get_host_port_id = qla2x00_get_host_port_id,
1880 .show_host_port_id = 1,
1881 .get_host_speed = qla2x00_get_host_speed,
1882 .show_host_speed = 1,
1883 .get_host_port_type = qla2x00_get_host_port_type,
1884 .show_host_port_type = 1,
1885 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1886 .show_host_symbolic_name = 1,
1887 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1888 .show_host_system_hostname = 1,
1889 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1890 .show_host_fabric_name = 1,
1891 .get_host_port_state = qla2x00_get_host_port_state,
1892 .show_host_port_state = 1,
1893
1894 .dd_fcrport_size = sizeof(struct fc_port *),
1895 .show_rport_supported_classes = 1,
1896
1897 .get_starget_node_name = qla2x00_get_starget_node_name,
1898 .show_starget_node_name = 1,
1899 .get_starget_port_name = qla2x00_get_starget_port_name,
1900 .show_starget_port_name = 1,
1901 .get_starget_port_id = qla2x00_get_starget_port_id,
1902 .show_starget_port_id = 1,
1903
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001904 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1905 .show_rport_dev_loss_tmo = 1,
1906
1907 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001908 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1909 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001910 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001911 .bsg_request = qla24xx_bsg_request,
1912 .bsg_timeout = qla24xx_bsg_timeout,
8482e112005-04-17 15:04:54 -05001913};
1914
8482e112005-04-17 15:04:54 -05001915void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001916qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -05001917{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001918 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001919 u32 speed = FC_PORTSPEED_UNKNOWN;
1920
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001921 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1922 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1923 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1924 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1925 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001926
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001927 if (IS_QLA81XX(ha))
1928 speed = FC_PORTSPEED_10GBIT;
1929 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001930 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1931 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001932 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001933 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1934 FC_PORTSPEED_1GBIT;
1935 else if (IS_QLA23XX(ha))
1936 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1937 else
1938 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001939 fc_host_supported_speeds(vha->host) = speed;
8482e112005-04-17 15:04:54 -05001940}