blob: 00df96b96a1b57d9bd4b6eed482fbb643c7feeb0 [file] [log] [blame]
8482e1182005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
8482e1182005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e1182005-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>
8482e1182005-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
8482e1182005-04-17 15:04:54 -050016/* SYSFS attributes --------------------------------------------------------- */
17
18static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070019qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080020 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
8482e1182005-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,
8482e1182005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali08de2842011-08-16 11:31:44 -070026 int rval = 0;
8482e1182005-04-17 15:04:54 -050027
28 if (ha->fw_dump_reading == 0)
29 return 0;
8482e1182005-04-17 15:04:54 -050030
Giridhar Malavali08de2842011-08-16 11:31:44 -070031 if (IS_QLA82XX(ha)) {
32 if (off < ha->md_template_size) {
33 rval = memory_read_from_buffer(buf, count,
34 &off, ha->md_tmplt_hdr, ha->md_template_size);
35 return rval;
36 }
37 off -= ha->md_template_size;
38 rval = memory_read_from_buffer(buf, count,
39 &off, ha->md_dump, ha->md_dump_size);
40 return rval;
41 } else
42 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
Akinobu Mitab3dc9082008-07-24 08:31:47 -070043 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050044}
45
46static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070047qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080048 struct bin_attribute *bin_attr,
49 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050050{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080051 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050052 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080053 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050054 int reading;
8482e1182005-04-17 15:04:54 -050055
56 if (off != 0)
57 return (0);
58
59 reading = simple_strtol(buf, NULL, 10);
60 switch (reading) {
61 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070062 if (!ha->fw_dump_reading)
63 break;
8482e1182005-04-17 15:04:54 -050064
Saurav Kashyap7c3df132011-07-14 12:00:13 -070065 ql_log(ql_log_info, vha, 0x705d,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070067
Giridhar Malavali08de2842011-08-16 11:31:44 -070068 if (IS_QLA82XX(vha->hw)) {
69 qla82xx_md_free(vha);
70 qla82xx_md_prep(vha);
71 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070072 ha->fw_dump_reading = 0;
73 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050074 break;
75 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070076 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050077 ha->fw_dump_reading = 1;
78
Saurav Kashyap7c3df132011-07-14 12:00:13 -070079 ql_log(ql_log_info, vha, 0x705e,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070080 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080081 vha->host_no);
8482e1182005-04-17 15:04:54 -050082 }
83 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070084 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080085 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070086 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070087 case 3:
Giridhar Malavali08de2842011-08-16 11:31:44 -070088 if (IS_QLA82XX(ha)) {
89 qla82xx_idc_lock(ha);
90 qla82xx_set_reset_owner(vha);
91 qla82xx_idc_unlock(ha);
92 } else
93 qla2x00_system_error(vha);
94 break;
95 case 4:
96 if (IS_QLA82XX(ha)) {
97 if (ha->md_tmplt_hdr)
98 ql_dbg(ql_dbg_user, vha, 0x705b,
99 "MiniDump supported with this firmware.\n");
100 else
101 ql_dbg(ql_dbg_user, vha, 0x709d,
102 "MiniDump not supported with this firmware.\n");
103 }
104 break;
105 case 5:
106 if (IS_QLA82XX(ha))
107 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez68af0812008-05-12 22:21:13 -0700108 break;
8482e1182005-04-17 15:04:54 -0500109 }
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800110 return count;
8482e1182005-04-17 15:04:54 -0500111}
112
113static struct bin_attribute sysfs_fw_dump_attr = {
114 .attr = {
115 .name = "fw_dump",
116 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500117 },
118 .size = 0,
119 .read = qla2x00_sysfs_read_fw_dump,
120 .write = qla2x00_sysfs_write_fw_dump,
121};
122
123static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700124qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800125 struct bin_attribute *bin_attr,
126 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500127{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800128 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500129 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800130 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500131
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700132 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500133 return 0;
134
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700135 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700136 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700137 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700138 return memory_read_from_buffer(buf, count, &off, ha->nvram,
139 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500140}
141
142static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700143qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800144 struct bin_attribute *bin_attr,
145 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500146{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800147 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500148 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800149 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500150 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500151
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700152 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
153 !ha->isp_ops->write_nvram)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700154 return -EINVAL;
8482e1182005-04-17 15:04:54 -0500155
156 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700157 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700158 uint32_t *iter;
159 uint32_t chksum;
160
161 iter = (uint32_t *)buf;
162 chksum = 0;
163 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
164 chksum += le32_to_cpu(*iter++);
165 chksum = ~chksum + 1;
166 *iter = cpu_to_le32(chksum);
167 } else {
168 uint8_t *iter;
169 uint8_t chksum;
170
171 iter = (uint8_t *)buf;
172 chksum = 0;
173 for (cnt = 0; cnt < count - 1; cnt++)
174 chksum += *iter++;
175 chksum = ~chksum + 1;
176 *iter = chksum;
177 }
8482e1182005-04-17 15:04:54 -0500178
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700179 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700180 ql_log(ql_log_warn, vha, 0x705f,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700181 "HBA not online, failing NVRAM update.\n");
182 return -EAGAIN;
183 }
184
8482e1182005-04-17 15:04:54 -0500185 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
187 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700188 count);
8482e1182005-04-17 15:04:54 -0500189
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 ql_dbg(ql_dbg_user, vha, 0x7060,
191 "Setting ISP_ABORT_NEEDED\n");
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700192 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700194 qla2xxx_wake_dpc(vha);
195 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800196
Joe Carnucciob668ae32011-08-16 11:31:53 -0700197 return count;
8482e1182005-04-17 15:04:54 -0500198}
199
200static struct bin_attribute sysfs_nvram_attr = {
201 .attr = {
202 .name = "nvram",
203 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500204 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800205 .size = 512,
8482e1182005-04-17 15:04:54 -0500206 .read = qla2x00_sysfs_read_nvram,
207 .write = qla2x00_sysfs_write_nvram,
208};
209
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800210static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700211qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800212 struct bin_attribute *bin_attr,
213 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800214{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800215 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800216 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800217 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800218
219 if (ha->optrom_state != QLA_SREADING)
220 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800221
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700222 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
223 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224}
225
226static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700227qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800228 struct bin_attribute *bin_attr,
229 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800230{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800231 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800234
235 if (ha->optrom_state != QLA_SWRITING)
236 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700237 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800238 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700239 if (off + count > ha->optrom_region_size)
240 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800241
242 memcpy(&ha->optrom_buffer[off], buf, count);
243
244 return count;
245}
246
247static struct bin_attribute sysfs_optrom_attr = {
248 .attr = {
249 .name = "optrom",
250 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800251 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700252 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800253 .read = qla2x00_sysfs_read_optrom,
254 .write = qla2x00_sysfs_write_optrom,
255};
256
257static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700258qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800259 struct bin_attribute *bin_attr,
260 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800261{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800262 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800263 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800264 struct qla_hw_data *ha = vha->hw;
265
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700266 uint32_t start = 0;
267 uint32_t size = ha->optrom_size;
268 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269
270 if (off)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700271 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800272
Andrew Vasquez85880802009-12-15 21:29:46 -0800273 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700274 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800275
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700276 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
277 return -EINVAL;
278 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800279 return -EINVAL;
280
281 switch (val) {
282 case 0:
283 if (ha->optrom_state != QLA_SREADING &&
284 ha->optrom_state != QLA_SWRITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700285 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800286
287 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700288
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700289 ql_dbg(ql_dbg_user, vha, 0x7061,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700290 "Freeing flash region allocation -- 0x%x bytes.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700291 ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700292
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800293 vfree(ha->optrom_buffer);
294 ha->optrom_buffer = NULL;
295 break;
296 case 1:
297 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700298 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800299
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700300 ha->optrom_region_start = start;
301 ha->optrom_region_size = start + size > ha->optrom_size ?
302 ha->optrom_size - start : size;
303
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800304 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700305 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800306 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700307 ql_log(ql_log_warn, vha, 0x7062,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800308 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700309 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800310
311 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700312 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800313 }
314
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700315 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_log(ql_log_warn, vha, 0x7063,
317 "HBA not online, failing NVRAM update.\n");
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700318 return -EAGAIN;
319 }
320
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 ql_dbg(ql_dbg_user, vha, 0x7064,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700322 "Reading flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700324
325 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800326 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700327 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800328 break;
329 case 2:
330 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700331 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800332
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700333 /*
334 * We need to be more restrictive on which FLASH regions are
335 * allowed to be updated via user-space. Regions accessible
336 * via this method include:
337 *
338 * ISP21xx/ISP22xx/ISP23xx type boards:
339 *
340 * 0x000000 -> 0x020000 -- Boot code.
341 *
342 * ISP2322/ISP24xx type boards:
343 *
344 * 0x000000 -> 0x07ffff -- Boot code.
345 * 0x080000 -> 0x0fffff -- Firmware.
346 *
347 * ISP25xx type boards:
348 *
349 * 0x000000 -> 0x07ffff -- Boot code.
350 * 0x080000 -> 0x0fffff -- Firmware.
351 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
352 */
353 valid = 0;
354 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
355 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700356 else if (start == (ha->flt_region_boot * 4) ||
357 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700358 valid = 1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800359 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
360 || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700361 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700362 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700363 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700364 "Invalid start region 0x%x/0x%x.\n", start, size);
365 return -EINVAL;
366 }
367
368 ha->optrom_region_start = start;
369 ha->optrom_region_size = start + size > ha->optrom_size ?
370 ha->optrom_size - start : size;
371
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800372 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700373 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800374 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700375 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800376 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700377 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800378
379 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700380 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800381 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700382
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700383 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700384 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700385 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700386
387 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800388 break;
389 case 3:
390 if (ha->optrom_state != QLA_SWRITING)
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800391 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800392
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700393 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700394 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700395 "HBA not online, failing flash update.\n");
396 return -EAGAIN;
397 }
398
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700399 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700400 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700401 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700402
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800403 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700404 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800405 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700406 default:
Joe Carnucciob668ae32011-08-16 11:31:53 -0700407 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800408 }
409 return count;
410}
411
412static struct bin_attribute sysfs_optrom_ctl_attr = {
413 .attr = {
414 .name = "optrom_ctl",
415 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800416 },
417 .size = 0,
418 .write = qla2x00_sysfs_write_optrom_ctl,
419};
420
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800421static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700422qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800423 struct bin_attribute *bin_attr,
424 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800425{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800426 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800427 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800428 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800429
Andrew Vasquez85880802009-12-15 21:29:46 -0800430 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700431 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800432
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700433 if (!capable(CAP_SYS_ADMIN))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700434 return -EINVAL;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800435
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700436 if (IS_NOCACHE_VPD_TYPE(ha))
437 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
438 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700439 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800440}
441
442static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700443qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800444 struct bin_attribute *bin_attr,
445 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800446{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800447 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800448 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800449 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700450 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800451
Andrew Vasquez85880802009-12-15 21:29:46 -0800452 if (unlikely(pci_channel_offline(ha->pdev)))
453 return 0;
454
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700455 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
456 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800457 return 0;
458
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700459 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700460 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700461 "HBA not online, failing VPD update.\n");
462 return -EAGAIN;
463 }
464
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800465 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800466 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
467 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800468
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700469 /* Update flash version information for 4Gb & above. */
470 if (!IS_FWI2_CAPABLE(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700471 return -EINVAL;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700472
473 tmp_data = vmalloc(256);
474 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700475 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700476 "Unable to allocate memory for VPD information update.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700477 return -ENOMEM;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700478 }
479 ha->isp_ops->get_flash_version(vha, tmp_data);
480 vfree(tmp_data);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700481
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800482 return count;
483}
484
485static struct bin_attribute sysfs_vpd_attr = {
486 .attr = {
487 .name = "vpd",
488 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800489 },
490 .size = 0,
491 .read = qla2x00_sysfs_read_vpd,
492 .write = qla2x00_sysfs_write_vpd,
493};
494
Andrew Vasquez88729e52006-06-23 16:10:50 -0700495static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700496qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800497 struct bin_attribute *bin_attr,
498 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700499{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800500 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700501 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800502 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700503 uint16_t iter, addr, offset;
504 int rval;
505
506 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
507 return 0;
508
Andrew Vasqueze8711082008-01-31 12:33:48 -0800509 if (ha->sfp_data)
510 goto do_read;
511
512 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
513 &ha->sfp_data_dma);
514 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700515 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800516 "Unable to allocate memory for SFP read-data.\n");
517 return 0;
518 }
519
520do_read:
521 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700522 addr = 0xa0;
523 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
524 iter++, offset += SFP_BLOCK_SIZE) {
525 if (iter == 4) {
526 /* Skip to next device address. */
527 addr = 0xa2;
528 offset = 0;
529 }
530
Joe Carnuccio6766df92011-05-10 11:30:15 -0700531 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
532 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700533 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700534 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700535 "Unable to read SFP data (%x/%x/%x).\n", rval,
536 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700537
Joe Carnucciob668ae32011-08-16 11:31:53 -0700538 return -EIO;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700539 }
540 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
541 buf += SFP_BLOCK_SIZE;
542 }
543
544 return count;
545}
546
547static struct bin_attribute sysfs_sfp_attr = {
548 .attr = {
549 .name = "sfp",
550 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700551 },
552 .size = SFP_DEV_SIZE * 2,
553 .read = qla2x00_sysfs_read_sfp,
554};
555
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700556static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700557qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700558 struct bin_attribute *bin_attr,
559 char *buf, loff_t off, size_t count)
560{
561 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
562 struct device, kobj)));
563 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700564 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700565 int type;
566
567 if (off != 0)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700568 return -EINVAL;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700569
570 type = simple_strtol(buf, NULL, 10);
571 switch (type) {
572 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700573 ql_log(ql_log_info, vha, 0x706e,
574 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700575
576 scsi_block_requests(vha->host);
577 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavali08de2842011-08-16 11:31:44 -0700578 if (IS_QLA82XX(ha)) {
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -0400579 ha->flags.isp82xx_no_md_cap = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700580 qla82xx_idc_lock(ha);
581 qla82xx_set_reset_owner(vha);
582 qla82xx_idc_unlock(ha);
583 }
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700584 qla2xxx_wake_dpc(vha);
585 qla2x00_wait_for_chip_reset(vha);
586 scsi_unblock_requests(vha->host);
587 break;
588 case 0x2025d:
Nigel Kirklandf863f602012-05-15 14:34:19 -0400589 if (!IS_QLA81XX(ha) || !IS_QLA8031(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700590 return -EPERM;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700591
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700592 ql_log(ql_log_info, vha, 0x706f,
593 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700594
595 /* Make sure FC side is not in reset */
596 qla2x00_wait_for_hba_online(vha);
597
598 /* Issue MPI reset */
599 scsi_block_requests(vha->host);
600 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700601 ql_log(ql_log_warn, vha, 0x7070,
602 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700603 scsi_unblock_requests(vha->host);
604 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700605 case 0x2025e:
606 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700607 ql_log(ql_log_info, vha, 0x7071,
608 "FCoE ctx reset no supported.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700609 return -EPERM;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700610 }
611
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700612 ql_log(ql_log_info, vha, 0x7072,
613 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700614 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
615 qla2xxx_wake_dpc(vha);
616 qla2x00_wait_for_fcoe_ctx_reset(vha);
617 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700618 }
619 return count;
620}
621
622static struct bin_attribute sysfs_reset_attr = {
623 .attr = {
624 .name = "reset",
625 .mode = S_IWUSR,
626 },
627 .size = 0,
628 .write = qla2x00_sysfs_write_reset,
629};
630
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700631static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700632qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700633 struct bin_attribute *bin_attr,
634 char *buf, loff_t off, size_t count)
635{
636 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
637 struct device, kobj)));
638 struct qla_hw_data *ha = vha->hw;
639 int rval;
640 uint16_t actual_size;
641
642 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
643 return 0;
644
645 if (ha->xgmac_data)
646 goto do_read;
647
648 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
649 &ha->xgmac_data_dma, GFP_KERNEL);
650 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700651 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700652 "Unable to allocate memory for XGMAC read-data.\n");
653 return 0;
654 }
655
656do_read:
657 actual_size = 0;
658 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
659
660 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
661 XGMAC_DATA_SIZE, &actual_size);
662 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700663 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700664 "Unable to read XGMAC data (%x).\n", rval);
665 count = 0;
666 }
667
668 count = actual_size > count ? count: actual_size;
669 memcpy(buf, ha->xgmac_data, count);
670
671 return count;
672}
673
674static struct bin_attribute sysfs_xgmac_stats_attr = {
675 .attr = {
676 .name = "xgmac_stats",
677 .mode = S_IRUSR,
678 },
679 .size = 0,
680 .read = qla2x00_sysfs_read_xgmac_stats,
681};
682
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700683static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700684qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700685 struct bin_attribute *bin_attr,
686 char *buf, loff_t off, size_t count)
687{
688 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
689 struct device, kobj)));
690 struct qla_hw_data *ha = vha->hw;
691 int rval;
692 uint16_t actual_size;
693
694 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
695 return 0;
696
697 if (ha->dcbx_tlv)
698 goto do_read;
699
700 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
701 &ha->dcbx_tlv_dma, GFP_KERNEL);
702 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700703 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700704 "Unable to allocate memory for DCBX TLV read-data.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700705 return -ENOMEM;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700706 }
707
708do_read:
709 actual_size = 0;
710 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
711
712 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
713 DCBX_TLV_DATA_SIZE);
714 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700715 ql_log(ql_log_warn, vha, 0x7079,
716 "Unable to read DCBX TLV (%x).\n", rval);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700717 return -EIO;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700718 }
719
720 memcpy(buf, ha->dcbx_tlv, count);
721
722 return count;
723}
724
725static struct bin_attribute sysfs_dcbx_tlv_attr = {
726 .attr = {
727 .name = "dcbx_tlv",
728 .mode = S_IRUSR,
729 },
730 .size = 0,
731 .read = qla2x00_sysfs_read_dcbx_tlv,
732};
733
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700734static struct sysfs_entry {
735 char *name;
736 struct bin_attribute *attr;
737 int is4GBp_only;
738} bin_file_entries[] = {
739 { "fw_dump", &sysfs_fw_dump_attr, },
740 { "nvram", &sysfs_nvram_attr, },
741 { "optrom", &sysfs_optrom_attr, },
742 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
743 { "vpd", &sysfs_vpd_attr, 1 },
744 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700745 { "reset", &sysfs_reset_attr, },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700746 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700747 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800748 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700749};
750
8482e1182005-04-17 15:04:54 -0500751void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800752qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500753{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800754 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700755 struct sysfs_entry *iter;
756 int ret;
8482e1182005-04-17 15:04:54 -0500757
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700758 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800759 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700760 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700761 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
762 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800763 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700764 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700765
766 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
767 iter->attr);
768 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700769 ql_log(ql_log_warn, vha, 0x00f3,
770 "Unable to create sysfs %s binary attribute (%d).\n",
771 iter->name, ret);
772 else
773 ql_dbg(ql_dbg_init, vha, 0x00f4,
774 "Successfully created sysfs %s binary attribure.\n",
775 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700776 }
8482e1182005-04-17 15:04:54 -0500777}
778
779void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800780qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500781{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800782 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700783 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800784 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500785
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700786 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700787 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700788 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700789 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
790 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800791 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700792 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700793
Andrew Vasquez7914d002006-06-23 16:10:55 -0700794 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700795 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700796 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800797
798 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800799 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500800}
801
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700802/* Scsi_Host attributes. */
803
804static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100805qla2x00_drvr_version_show(struct device *dev,
806 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700807{
808 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
809}
810
811static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100812qla2x00_fw_version_show(struct device *dev,
813 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700814{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800815 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
816 struct qla_hw_data *ha = vha->hw;
817 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700818
819 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800820 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700821}
822
823static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100824qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
825 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700826{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800827 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700829 uint32_t sn;
830
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700831 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800832 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700833 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
834 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700835
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700836 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
837 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
838 sn % 100000);
839}
840
841static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100842qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
843 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700844{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800845 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
846 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700847}
848
849static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100850qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
851 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700852{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800853 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
854 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700855 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
856 ha->product_id[0], ha->product_id[1], ha->product_id[2],
857 ha->product_id[3]);
858}
859
860static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100861qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
862 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700863{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
865 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700866}
867
868static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100869qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
870 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700871{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800872 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700873 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800874 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700875}
876
877static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100878qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
879 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700880{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800881 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700882 char pci_info[30];
883
884 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800885 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700886}
887
888static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100889qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
890 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700891{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800892 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
893 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700894 int len = 0;
895
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800896 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -0700897 atomic_read(&vha->loop_state) == LOOP_DEAD ||
898 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700899 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800900 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -0800901 qla2x00_reset_active(vha))
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700902 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
903 else {
904 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
905
906 switch (ha->current_topology) {
907 case ISP_CFG_NL:
908 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
909 break;
910 case ISP_CFG_FL:
911 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
912 break;
913 case ISP_CFG_N:
914 len += snprintf(buf + len, PAGE_SIZE-len,
915 "N_Port to N_Port\n");
916 break;
917 case ISP_CFG_F:
918 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
919 break;
920 default:
921 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
922 break;
923 }
924 }
925 return len;
926}
927
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700928static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100929qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
930 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700931{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800932 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700933 int len = 0;
934
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800935 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700936 case QLA_ZIO_MODE_6:
937 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
938 break;
939 case QLA_ZIO_DISABLED:
940 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
941 break;
942 }
943 return len;
944}
945
946static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100947qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
948 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700949{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800950 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
951 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700952 int val = 0;
953 uint16_t zio_mode;
954
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800955 if (!IS_ZIO_SUPPORTED(ha))
956 return -ENOTSUPP;
957
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700958 if (sscanf(buf, "%d", &val) != 1)
959 return -EINVAL;
960
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800961 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700962 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800963 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700964 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700965
966 /* Update per-hba values and queue a reset. */
967 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
968 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800969 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700970 }
971 return strlen(buf);
972}
973
974static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100975qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
976 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700977{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800978 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700979
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800980 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700981}
982
983static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100984qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
985 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700986{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800987 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700988 int val = 0;
989 uint16_t zio_timer;
990
991 if (sscanf(buf, "%d", &val) != 1)
992 return -EINVAL;
993 if (val > 25500 || val < 100)
994 return -ERANGE;
995
996 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700998
999 return strlen(buf);
1000}
1001
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001002static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001003qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1004 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001005{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001006 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001007 int len = 0;
1008
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001009 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001010 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1011 else
1012 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1013 return len;
1014}
1015
1016static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001017qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1018 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001019{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001020 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1021 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001022 int val = 0;
1023 int rval;
1024
1025 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1026 return -EPERM;
1027
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001028 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001029 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001030 "Abort ISP active -- ignoring beacon request.\n");
1031 return -EBUSY;
1032 }
1033
1034 if (sscanf(buf, "%d", &val) != 1)
1035 return -EINVAL;
1036
1037 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001038 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001039 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001040 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001041
1042 if (rval != QLA_SUCCESS)
1043 count = 0;
1044
1045 return count;
1046}
1047
Andrew Vasquez30c47662007-01-29 10:22:21 -08001048static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001049qla2x00_optrom_bios_version_show(struct device *dev,
1050 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001051{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001052 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1053 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001054 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1055 ha->bios_revision[0]);
1056}
1057
1058static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001059qla2x00_optrom_efi_version_show(struct device *dev,
1060 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001061{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001062 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1063 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001064 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1065 ha->efi_revision[0]);
1066}
1067
1068static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001069qla2x00_optrom_fcode_version_show(struct device *dev,
1070 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001071{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1073 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001074 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1075 ha->fcode_revision[0]);
1076}
1077
1078static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001079qla2x00_optrom_fw_version_show(struct device *dev,
1080 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001081{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001082 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1083 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001084 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1085 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1086 ha->fw_revision[3]);
1087}
1088
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001089static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001090qla2x00_optrom_gold_fw_version_show(struct device *dev,
1091 struct device_attribute *attr, char *buf)
1092{
1093 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1094 struct qla_hw_data *ha = vha->hw;
1095
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001096 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001097 return snprintf(buf, PAGE_SIZE, "\n");
1098
1099 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1100 ha->gold_fw_version[0], ha->gold_fw_version[1],
1101 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1102}
1103
1104static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001105qla2x00_total_isp_aborts_show(struct device *dev,
1106 struct device_attribute *attr, char *buf)
1107{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001108 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001109 return snprintf(buf, PAGE_SIZE, "%d\n",
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001110 vha->qla_stats.total_isp_aborts);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001111}
1112
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001113static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001114qla24xx_84xx_fw_version_show(struct device *dev,
1115 struct device_attribute *attr, char *buf)
1116{
1117 int rval = QLA_SUCCESS;
1118 uint16_t status[2] = {0, 0};
1119 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1120 struct qla_hw_data *ha = vha->hw;
1121
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001122 if (!IS_QLA84XX(ha))
1123 return snprintf(buf, PAGE_SIZE, "\n");
1124
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001125 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001126 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001127
1128 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1129 return snprintf(buf, PAGE_SIZE, "%u\n",
1130 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001131
1132 return snprintf(buf, PAGE_SIZE, "\n");
1133}
1134
1135static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001136qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1137 char *buf)
1138{
1139 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1140 struct qla_hw_data *ha = vha->hw;
1141
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001142 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001143 return snprintf(buf, PAGE_SIZE, "\n");
1144
Andrew Vasquez55a96152009-03-24 09:08:03 -07001145 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001146 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001147 ha->mpi_capabilities);
1148}
1149
1150static ssize_t
1151qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1152 char *buf)
1153{
1154 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1155 struct qla_hw_data *ha = vha->hw;
1156
Nigel Kirklandf863f602012-05-15 14:34:19 -04001157 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001158 return snprintf(buf, PAGE_SIZE, "\n");
1159
1160 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1161 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001162}
1163
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001164static ssize_t
1165qla2x00_flash_block_size_show(struct device *dev,
1166 struct device_attribute *attr, char *buf)
1167{
1168 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1169 struct qla_hw_data *ha = vha->hw;
1170
1171 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1172}
1173
Andrew Vasquezbad70012009-04-06 22:33:38 -07001174static ssize_t
1175qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1176 char *buf)
1177{
1178 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1179
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001180 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001181 return snprintf(buf, PAGE_SIZE, "\n");
1182
1183 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1184}
1185
1186static ssize_t
1187qla2x00_vn_port_mac_address_show(struct device *dev,
1188 struct device_attribute *attr, char *buf)
1189{
1190 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1191
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001192 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001193 return snprintf(buf, PAGE_SIZE, "\n");
1194
1195 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1196 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1197 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1198 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1199}
1200
Andrew Vasquez7f774022009-06-03 09:55:12 -07001201static ssize_t
1202qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1203 char *buf)
1204{
1205 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1206
1207 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1208}
1209
Andrew Vasquez656e8912009-06-03 09:55:29 -07001210static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001211qla2x00_thermal_temp_show(struct device *dev,
1212 struct device_attribute *attr, char *buf)
1213{
1214 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1215 int rval = QLA_FUNCTION_FAILED;
1216 uint16_t temp, frac;
1217
1218 if (!vha->hw->flags.thermal_supported)
1219 return snprintf(buf, PAGE_SIZE, "\n");
1220
1221 temp = frac = 0;
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001222 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001223 ql_log(ql_log_warn, vha, 0x707b,
1224 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001225 else if (!vha->hw->flags.eeh_busy)
1226 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1227 if (rval != QLA_SUCCESS)
Joe Carnuccioaa615562012-02-09 11:15:40 -08001228 return snprintf(buf, PAGE_SIZE, "\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001229
1230 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1231}
1232
1233static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001234qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1235 char *buf)
1236{
1237 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001238 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001239 uint16_t state[5];
1240
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001241 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001242 ql_log(ql_log_warn, vha, 0x707c,
1243 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001244 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001245 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001246 if (rval != QLA_SUCCESS)
1247 memset(state, -1, sizeof(state));
1248
1249 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1250 state[1], state[2], state[3], state[4]);
1251}
1252
Tony Jonesee959b02008-02-22 00:13:36 +01001253static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1254static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1255static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1256static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1257static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1258static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1259static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1260static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001261static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001262static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1263static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1264 qla2x00_zio_timer_store);
1265static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1266 qla2x00_beacon_store);
1267static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1268 qla2x00_optrom_bios_version_show, NULL);
1269static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1270 qla2x00_optrom_efi_version_show, NULL);
1271static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1272 qla2x00_optrom_fcode_version_show, NULL);
1273static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1274 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001275static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1276 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001277static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1278 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001279static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1280 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001281static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001282static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001283static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1284 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001285static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1286static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1287 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001288static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001289static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001290static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001291
Tony Jonesee959b02008-02-22 00:13:36 +01001292struct device_attribute *qla2x00_host_attrs[] = {
1293 &dev_attr_driver_version,
1294 &dev_attr_fw_version,
1295 &dev_attr_serial_num,
1296 &dev_attr_isp_name,
1297 &dev_attr_isp_id,
1298 &dev_attr_model_name,
1299 &dev_attr_model_desc,
1300 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001301 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001302 &dev_attr_zio,
1303 &dev_attr_zio_timer,
1304 &dev_attr_beacon,
1305 &dev_attr_optrom_bios_version,
1306 &dev_attr_optrom_efi_version,
1307 &dev_attr_optrom_fcode_version,
1308 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001309 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001310 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001311 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001312 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001313 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001314 &dev_attr_vlan_id,
1315 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001316 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001317 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001318 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001319 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001320 NULL,
1321};
1322
8482e1182005-04-17 15:04:54 -05001323/* Host attributes. */
1324
1325static void
1326qla2x00_get_host_port_id(struct Scsi_Host *shost)
1327{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001328 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001329
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001330 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1331 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001332}
1333
1334static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001335qla2x00_get_host_speed(struct Scsi_Host *shost)
1336{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001337 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1338 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001339 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001340
1341 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001342 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001343 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001344 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001345 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001346 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001347 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001348 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001349 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001350 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001351 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001352 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001353 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001354 case PORT_SPEED_10GB:
1355 speed = FC_PORTSPEED_10GBIT;
1356 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001357 case PORT_SPEED_16GB:
1358 speed = FC_PORTSPEED_16GBIT;
1359 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001360 }
1361 fc_host_speed(shost) = speed;
1362}
1363
1364static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001365qla2x00_get_host_port_type(struct Scsi_Host *shost)
1366{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001367 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001368 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1369
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001370 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001371 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1372 return;
1373 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001374 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001375 case ISP_CFG_NL:
1376 port_type = FC_PORTTYPE_LPORT;
1377 break;
1378 case ISP_CFG_FL:
1379 port_type = FC_PORTTYPE_NLPORT;
1380 break;
1381 case ISP_CFG_N:
1382 port_type = FC_PORTTYPE_PTP;
1383 break;
1384 case ISP_CFG_F:
1385 port_type = FC_PORTTYPE_NPORT;
1386 break;
1387 }
1388 fc_host_port_type(shost) = port_type;
1389}
1390
1391static void
8482e1182005-04-17 15:04:54 -05001392qla2x00_get_starget_node_name(struct scsi_target *starget)
1393{
1394 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001395 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001396 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001397 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001398
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001399 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001400 if (fcport->rport &&
1401 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001402 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001403 break;
1404 }
1405 }
1406
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001407 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001408}
1409
1410static void
1411qla2x00_get_starget_port_name(struct scsi_target *starget)
1412{
1413 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001414 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001415 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001416 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001417
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001418 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001419 if (fcport->rport &&
1420 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001421 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001422 break;
1423 }
1424 }
1425
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001426 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001427}
1428
1429static void
1430qla2x00_get_starget_port_id(struct scsi_target *starget)
1431{
1432 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001433 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001434 fc_port_t *fcport;
1435 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001436
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001437 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001438 if (fcport->rport &&
1439 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001440 port_id = fcport->d_id.b.domain << 16 |
1441 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1442 break;
1443 }
1444 }
1445
8482e1182005-04-17 15:04:54 -05001446 fc_starget_port_id(starget) = port_id;
1447}
1448
1449static void
8482e1182005-04-17 15:04:54 -05001450qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1451{
8482e1182005-04-17 15:04:54 -05001452 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001453 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001454 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001455 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001456}
1457
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001458static void
1459qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1460{
1461 struct Scsi_Host *host = rport_to_shost(rport);
1462 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001463 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001464
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001465 if (!fcport)
1466 return;
1467
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001468 /* Now that the rport has been deleted, set the fcport state to
1469 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001470 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001471
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001472 /*
1473 * Transport has effectively 'deleted' the rport, clear
1474 * all local references.
1475 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001476 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001477 fcport->rport = fcport->drport = NULL;
1478 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001479 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001480
Andrew Vasquez85880802009-12-15 21:29:46 -08001481 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1482 return;
1483
1484 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001485 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001486 return;
1487 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001488}
1489
1490static void
1491qla2x00_terminate_rport_io(struct fc_rport *rport)
1492{
1493 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1494
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001495 if (!fcport)
1496 return;
1497
Andrew Vasquez85880802009-12-15 21:29:46 -08001498 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1499 return;
1500
Seokmann Jub9b12f72009-03-24 09:08:18 -07001501 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1502 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1503 return;
1504 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001505 /*
1506 * At this point all fcport's software-states are cleared. Perform any
1507 * final cleanup of firmware resources (PCBs and XCBs).
1508 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001509 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezaf11f642012-02-09 11:15:43 -08001510 !test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
1511 if (IS_FWI2_CAPABLE(fcport->vha->hw))
1512 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1513 fcport->loop_id, fcport->d_id.b.domain,
1514 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1515 else
1516 qla2x00_port_logout(fcport->vha, fcport);
1517 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001518}
1519
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001520static int
1521qla2x00_issue_lip(struct Scsi_Host *shost)
1522{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001523 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001524
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001525 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001526 return 0;
1527}
1528
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001529static struct fc_host_statistics *
1530qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1531{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001532 scsi_qla_host_t *vha = shost_priv(shost);
1533 struct qla_hw_data *ha = vha->hw;
1534 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001535 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001536 struct link_statistics *stats;
1537 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001538 struct fc_host_statistics *pfc_host_stat;
1539
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001540 pfc_host_stat = &vha->fc_host_stat;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001541 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1542
Andrew Vasquez85880802009-12-15 21:29:46 -08001543 if (test_bit(UNLOADING, &vha->dpc_flags))
1544 goto done;
1545
1546 if (unlikely(pci_channel_offline(ha->pdev)))
1547 goto done;
1548
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001549 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1550 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001551 ql_log(ql_log_warn, vha, 0x707d,
1552 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001553 goto done;
1554 }
1555 memset(stats, 0, DMA_POOL_SIZE);
1556
1557 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001558 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001559 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1560 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001561 !qla2x00_reset_active(vha) && !ha->dpc_active) {
Andrew Vasquez178779a2007-01-29 10:22:25 -08001562 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001563 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1564 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001565 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001566
1567 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001568 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001569
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001570 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1571 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1572 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1573 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1574 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1575 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1576 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001577 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001578 pfc_host_stat->tx_frames = stats->tx_frames;
1579 pfc_host_stat->rx_frames = stats->rx_frames;
1580 pfc_host_stat->dumped_frames = stats->dumped_frames;
1581 pfc_host_stat->nos_count = stats->nos_rcvd;
1582 }
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001583 pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
1584 pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001585
1586done_free:
1587 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001588done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001589 return pfc_host_stat;
1590}
1591
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001592static void
1593qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1594{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001595 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001596
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001597 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001598}
1599
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001600static void
1601qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1602{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001603 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001604
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001605 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001606}
1607
Andrew Vasquez90991c82006-10-02 12:00:46 -07001608static void
1609qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1610{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001611 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001612 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1613 0xFF, 0xFF, 0xFF, 0xFF};
1614 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001615
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001616 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001617 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001618
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001619 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001620}
1621
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001622static void
1623qla2x00_get_host_port_state(struct Scsi_Host *shost)
1624{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001625 scsi_qla_host_t *vha = shost_priv(shost);
1626 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001627
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001628 if (!base_vha->flags.online) {
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001629 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001630 return;
1631 }
1632
1633 switch (atomic_read(&base_vha->loop_state)) {
1634 case LOOP_UPDATE:
1635 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1636 break;
1637 case LOOP_DOWN:
1638 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
1639 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1640 else
1641 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1642 break;
1643 case LOOP_DEAD:
1644 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1645 break;
1646 case LOOP_READY:
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001647 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001648 break;
1649 default:
1650 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1651 break;
1652 }
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001653}
1654
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001655static int
1656qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1657{
1658 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001659 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001660 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1661 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001662 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001663 uint16_t options = 0;
1664 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001665 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001666
1667 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1668 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001669 ql_log(ql_log_warn, vha, 0x707e,
1670 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001671 return (ret);
1672 }
1673
1674 vha = qla24xx_create_vhost(fc_vport);
1675 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001676 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001677 return FC_VPORT_FAILED;
1678 }
1679 if (disable) {
1680 atomic_set(&vha->vp_state, VP_OFFLINE);
1681 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1682 } else
1683 atomic_set(&vha->vp_state, VP_FAILED);
1684
1685 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001686 ql_log(ql_log_info, vha, 0x7080,
1687 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001688
1689 /* initialized vport states */
1690 atomic_set(&vha->loop_state, LOOP_DOWN);
1691 vha->vp_err_state= VP_ERR_PORTDWN;
1692 vha->vp_prev_err_state= VP_ERR_UNKWN;
1693 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001694 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1695 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001696 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001697 ql_dbg(ql_dbg_user, vha, 0x7081,
1698 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001699 atomic_set(&vha->loop_state, LOOP_DEAD);
1700 if (!disable)
1701 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1702 }
1703
Arun Easie02587d2011-08-16 11:29:23 -07001704 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001705 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07001706 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07001707 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001708 ql_dbg(ql_dbg_user, vha, 0x7082,
1709 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07001710 if (ql2xenabledif == 1)
1711 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07001712 scsi_host_set_prot(vha->host,
Arun Easi8cb20492011-08-16 11:29:22 -07001713 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001714 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001715 | SHOST_DIF_TYPE3_PROTECTION
1716 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001717 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001718 | SHOST_DIX_TYPE3_PROTECTION);
1719 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1720 } else
1721 vha->flags.difdix_supported = 0;
1722 }
1723
James Bottomleyd139b9b2009-11-05 13:33:12 -06001724 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1725 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001726 ql_dbg(ql_dbg_user, vha, 0x7083,
1727 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001728 goto vport_create_failed_2;
1729 }
1730
1731 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001732 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001733 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1734 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1735 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001736 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001737 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001738 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001739
1740 qla24xx_vport_disable(fc_vport, disable);
1741
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001742 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001743 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001744 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1745 "Request queue %p attached with "
1746 "VP[%d], cpu affinity =%d\n",
1747 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001748 goto vport_queue;
1749 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001750 goto vport_queue;
1751 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001752 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1753 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1754 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001755 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001756 qos = ha->npiv_info[cnt].q_qos;
1757 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001758 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001759 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001760
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001761 if (qos) {
1762 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1763 qos);
1764 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001765 ql_log(ql_log_warn, vha, 0x7084,
1766 "Can't create request queue for VP[%d]\n",
1767 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001768 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001769 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1770 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1771 ret, qos, vha->vp_idx);
1772 ql_dbg(ql_dbg_user, vha, 0x7085,
1773 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1774 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001775 req = ha->req_q_map[ret];
1776 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001777 }
1778
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001779vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001780 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001781 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001782
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001783vport_create_failed_2:
1784 qla24xx_disable_vp(vha);
1785 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001786 scsi_host_put(vha->host);
1787 return FC_VPORT_FAILED;
1788}
1789
Adrian Bunka824ebb2008-01-17 09:02:15 -08001790static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001791qla24xx_vport_delete(struct fc_vport *fc_vport)
1792{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001793 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001794 struct qla_hw_data *ha = vha->hw;
1795 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001796
1797 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001798 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001799 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001800
1801 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802
Arun Easifeafb7b2010-09-03 14:57:00 -07001803 vha->flags.delete_progress = 1;
1804
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001805 fc_remove_host(vha->host);
1806
1807 scsi_remove_host(vha->host);
1808
Arun Easi9f406822011-05-10 11:18:17 -07001809 /* Allow timer to run to drain queued items, when removing vp */
1810 qla24xx_deallocate_vp_id(vha);
1811
Arun Easifeafb7b2010-09-03 14:57:00 -07001812 if (vha->timer_active) {
1813 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001814 ql_dbg(ql_dbg_user, vha, 0x7086,
1815 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001816 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001817
Arun Easifeafb7b2010-09-03 14:57:00 -07001818 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001819 if (ql2xextended_error_logging & ql_dbg_user)
1820 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001821 * the net we have placed below */
1822
1823 BUG_ON(atomic_read(&vha->vref_count));
1824
1825 qla2x00_free_fcports(vha);
1826
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001827 mutex_lock(&ha->vport_lock);
1828 ha->cur_vport_count--;
1829 clear_bit(vha->vp_idx, ha->vp_idx_map);
1830 mutex_unlock(&ha->vport_lock);
1831
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001832 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001833 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001834 ql_log(ql_log_warn, vha, 0x7087,
1835 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001836 }
1837
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001838 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001839 scsi_host_put(vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001840 return 0;
1841}
1842
Adrian Bunka824ebb2008-01-17 09:02:15 -08001843static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001844qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1845{
1846 scsi_qla_host_t *vha = fc_vport->dd_data;
1847
1848 if (disable)
1849 qla24xx_disable_vp(vha);
1850 else
1851 qla24xx_enable_vp(vha);
1852
1853 return 0;
1854}
1855
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001856struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001857
1858 .show_host_node_name = 1,
1859 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001860 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001861 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001862
8482e1182005-04-17 15:04:54 -05001863 .get_host_port_id = qla2x00_get_host_port_id,
1864 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001865 .get_host_speed = qla2x00_get_host_speed,
1866 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001867 .get_host_port_type = qla2x00_get_host_port_type,
1868 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001869 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1870 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001871 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1872 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001873 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1874 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001875 .get_host_port_state = qla2x00_get_host_port_state,
1876 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001877
bdf79622005-04-17 15:06:53 -05001878 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001879 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001880
1881 .get_starget_node_name = qla2x00_get_starget_node_name,
1882 .show_starget_node_name = 1,
1883 .get_starget_port_name = qla2x00_get_starget_port_name,
1884 .show_starget_port_name = 1,
1885 .get_starget_port_id = qla2x00_get_starget_port_id,
1886 .show_starget_port_id = 1,
1887
8482e1182005-04-17 15:04:54 -05001888 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1889 .show_rport_dev_loss_tmo = 1,
1890
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001891 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001892 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1893 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001894 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001895
1896 .vport_create = qla24xx_vport_create,
1897 .vport_disable = qla24xx_vport_disable,
1898 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001899 .bsg_request = qla24xx_bsg_request,
1900 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001901};
1902
1903struct fc_function_template qla2xxx_transport_vport_functions = {
1904
1905 .show_host_node_name = 1,
1906 .show_host_port_name = 1,
1907 .show_host_supported_classes = 1,
1908
1909 .get_host_port_id = qla2x00_get_host_port_id,
1910 .show_host_port_id = 1,
1911 .get_host_speed = qla2x00_get_host_speed,
1912 .show_host_speed = 1,
1913 .get_host_port_type = qla2x00_get_host_port_type,
1914 .show_host_port_type = 1,
1915 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1916 .show_host_symbolic_name = 1,
1917 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1918 .show_host_system_hostname = 1,
1919 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1920 .show_host_fabric_name = 1,
1921 .get_host_port_state = qla2x00_get_host_port_state,
1922 .show_host_port_state = 1,
1923
1924 .dd_fcrport_size = sizeof(struct fc_port *),
1925 .show_rport_supported_classes = 1,
1926
1927 .get_starget_node_name = qla2x00_get_starget_node_name,
1928 .show_starget_node_name = 1,
1929 .get_starget_port_name = qla2x00_get_starget_port_name,
1930 .show_starget_port_name = 1,
1931 .get_starget_port_id = qla2x00_get_starget_port_id,
1932 .show_starget_port_id = 1,
1933
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001934 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1935 .show_rport_dev_loss_tmo = 1,
1936
1937 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001938 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1939 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001940 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001941 .bsg_request = qla24xx_bsg_request,
1942 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05001943};
1944
8482e1182005-04-17 15:04:54 -05001945void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001946qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05001947{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001948 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001949 u32 speed = FC_PORTSPEED_UNKNOWN;
1950
Mike Christied2b5f102010-09-15 16:52:30 -05001951 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001952 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1953 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1954 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1955 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1956 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001957
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001958 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001959 speed = FC_PORTSPEED_10GBIT;
Giridhar Malavali6f606d22012-05-15 14:34:18 -04001960 else if (IS_QLA2031(ha))
1961 speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
1962 FC_PORTSPEED_4GBIT;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001963 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001964 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1965 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001966 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001967 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1968 FC_PORTSPEED_1GBIT;
1969 else if (IS_QLA23XX(ha))
1970 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1971 else
1972 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001973 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05001974}