blob: 9f41b3b4358fd834b4cb708401dad2eb952f50f4 [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 Malavalia9083012010-04-12 17:59:55 -0700359 else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
360 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700361 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700362 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700363 "Invalid start region 0x%x/0x%x.\n", start, size);
364 return -EINVAL;
365 }
366
367 ha->optrom_region_start = start;
368 ha->optrom_region_size = start + size > ha->optrom_size ?
369 ha->optrom_size - start : size;
370
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800371 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700372 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800373 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700374 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800375 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800377
378 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700379 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800380 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700381
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700382 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700383 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700384 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700385
386 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800387 break;
388 case 3:
389 if (ha->optrom_state != QLA_SWRITING)
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800390 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800391
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700392 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700393 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700394 "HBA not online, failing flash update.\n");
395 return -EAGAIN;
396 }
397
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700398 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700399 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700400 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700401
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800402 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700403 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800404 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700405 default:
Joe Carnucciob668ae32011-08-16 11:31:53 -0700406 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800407 }
408 return count;
409}
410
411static struct bin_attribute sysfs_optrom_ctl_attr = {
412 .attr = {
413 .name = "optrom_ctl",
414 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800415 },
416 .size = 0,
417 .write = qla2x00_sysfs_write_optrom_ctl,
418};
419
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800420static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700421qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800422 struct bin_attribute *bin_attr,
423 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800424{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800425 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800426 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800427 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800428
Andrew Vasquez85880802009-12-15 21:29:46 -0800429 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700430 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800431
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700432 if (!capable(CAP_SYS_ADMIN))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700433 return -EINVAL;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800434
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700435 if (IS_NOCACHE_VPD_TYPE(ha))
436 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
437 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700438 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800439}
440
441static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700442qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800443 struct bin_attribute *bin_attr,
444 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800445{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800446 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800447 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800448 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700449 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800450
Andrew Vasquez85880802009-12-15 21:29:46 -0800451 if (unlikely(pci_channel_offline(ha->pdev)))
452 return 0;
453
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700454 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
455 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800456 return 0;
457
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700458 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700459 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700460 "HBA not online, failing VPD update.\n");
461 return -EAGAIN;
462 }
463
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800464 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800465 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
466 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800467
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700468 /* Update flash version information for 4Gb & above. */
469 if (!IS_FWI2_CAPABLE(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700470 return -EINVAL;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700471
472 tmp_data = vmalloc(256);
473 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700474 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700475 "Unable to allocate memory for VPD information update.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700476 return -ENOMEM;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700477 }
478 ha->isp_ops->get_flash_version(vha, tmp_data);
479 vfree(tmp_data);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700480
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800481 return count;
482}
483
484static struct bin_attribute sysfs_vpd_attr = {
485 .attr = {
486 .name = "vpd",
487 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800488 },
489 .size = 0,
490 .read = qla2x00_sysfs_read_vpd,
491 .write = qla2x00_sysfs_write_vpd,
492};
493
Andrew Vasquez88729e52006-06-23 16:10:50 -0700494static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700495qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800496 struct bin_attribute *bin_attr,
497 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700498{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800499 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700500 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800501 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700502 uint16_t iter, addr, offset;
503 int rval;
504
505 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
506 return 0;
507
Andrew Vasqueze8711082008-01-31 12:33:48 -0800508 if (ha->sfp_data)
509 goto do_read;
510
511 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
512 &ha->sfp_data_dma);
513 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700514 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800515 "Unable to allocate memory for SFP read-data.\n");
516 return 0;
517 }
518
519do_read:
520 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700521 addr = 0xa0;
522 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
523 iter++, offset += SFP_BLOCK_SIZE) {
524 if (iter == 4) {
525 /* Skip to next device address. */
526 addr = 0xa2;
527 offset = 0;
528 }
529
Joe Carnuccio6766df92011-05-10 11:30:15 -0700530 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
531 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700532 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700533 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700534 "Unable to read SFP data (%x/%x/%x).\n", rval,
535 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700536
Joe Carnucciob668ae32011-08-16 11:31:53 -0700537 return -EIO;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700538 }
539 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
540 buf += SFP_BLOCK_SIZE;
541 }
542
543 return count;
544}
545
546static struct bin_attribute sysfs_sfp_attr = {
547 .attr = {
548 .name = "sfp",
549 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700550 },
551 .size = SFP_DEV_SIZE * 2,
552 .read = qla2x00_sysfs_read_sfp,
553};
554
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700555static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700556qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700557 struct bin_attribute *bin_attr,
558 char *buf, loff_t off, size_t count)
559{
560 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
561 struct device, kobj)));
562 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700563 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700564 int type;
565
566 if (off != 0)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700567 return -EINVAL;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700568
569 type = simple_strtol(buf, NULL, 10);
570 switch (type) {
571 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700572 ql_log(ql_log_info, vha, 0x706e,
573 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700574
575 scsi_block_requests(vha->host);
576 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavali08de2842011-08-16 11:31:44 -0700577 if (IS_QLA82XX(ha)) {
578 qla82xx_idc_lock(ha);
579 qla82xx_set_reset_owner(vha);
580 qla82xx_idc_unlock(ha);
581 }
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700582 qla2xxx_wake_dpc(vha);
583 qla2x00_wait_for_chip_reset(vha);
584 scsi_unblock_requests(vha->host);
585 break;
586 case 0x2025d:
587 if (!IS_QLA81XX(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700588 return -EPERM;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700589
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700590 ql_log(ql_log_info, vha, 0x706f,
591 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700592
593 /* Make sure FC side is not in reset */
594 qla2x00_wait_for_hba_online(vha);
595
596 /* Issue MPI reset */
597 scsi_block_requests(vha->host);
598 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700599 ql_log(ql_log_warn, vha, 0x7070,
600 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700601 scsi_unblock_requests(vha->host);
602 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700603 case 0x2025e:
604 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700605 ql_log(ql_log_info, vha, 0x7071,
606 "FCoE ctx reset no supported.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700607 return -EPERM;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700608 }
609
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700610 ql_log(ql_log_info, vha, 0x7072,
611 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700612 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
613 qla2xxx_wake_dpc(vha);
614 qla2x00_wait_for_fcoe_ctx_reset(vha);
615 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700616 }
617 return count;
618}
619
620static struct bin_attribute sysfs_reset_attr = {
621 .attr = {
622 .name = "reset",
623 .mode = S_IWUSR,
624 },
625 .size = 0,
626 .write = qla2x00_sysfs_write_reset,
627};
628
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700629static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700630qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700631 struct bin_attribute *bin_attr,
632 char *buf, loff_t off, size_t count)
633{
634 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
635 struct device, kobj)));
636 struct qla_hw_data *ha = vha->hw;
637 uint16_t dev, adr, opt, len;
638 int rval;
639
640 ha->edc_data_len = 0;
641
642 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700643 return -EINVAL;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700644
645 if (!ha->edc_data) {
646 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
647 &ha->edc_data_dma);
648 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700649 ql_log(ql_log_warn, vha, 0x7073,
650 "Unable to allocate memory for EDC write.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700651 return -ENOMEM;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700652 }
653 }
654
655 dev = le16_to_cpup((void *)&buf[0]);
656 adr = le16_to_cpup((void *)&buf[2]);
657 opt = le16_to_cpup((void *)&buf[4]);
658 len = le16_to_cpup((void *)&buf[6]);
659
660 if (!(opt & BIT_0))
661 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
662 return -EINVAL;
663
664 memcpy(ha->edc_data, &buf[8], len);
665
Joe Carnuccio6766df92011-05-10 11:30:15 -0700666 rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
667 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700668 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700669 ql_log(ql_log_warn, vha, 0x7074,
Joe Perchesd8424f62011-11-18 09:03:06 -0800670 "Unable to write EDC (%x) %02x:%04x:%02x:%02x:%02hhx\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700671 rval, dev, adr, opt, len, buf[8]);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700672 return -EIO;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700673 }
674
675 return count;
676}
677
678static struct bin_attribute sysfs_edc_attr = {
679 .attr = {
680 .name = "edc",
681 .mode = S_IWUSR,
682 },
683 .size = 0,
684 .write = qla2x00_sysfs_write_edc,
685};
686
687static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700688qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700689 struct bin_attribute *bin_attr,
690 char *buf, loff_t off, size_t count)
691{
692 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
693 struct device, kobj)));
694 struct qla_hw_data *ha = vha->hw;
695 uint16_t dev, adr, opt, len;
696 int rval;
697
698 ha->edc_data_len = 0;
699
700 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700701 return -EINVAL;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700702
703 if (!ha->edc_data) {
704 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
705 &ha->edc_data_dma);
706 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700707 ql_log(ql_log_warn, vha, 0x708c,
708 "Unable to allocate memory for EDC status.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700709 return -ENOMEM;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700710 }
711 }
712
713 dev = le16_to_cpup((void *)&buf[0]);
714 adr = le16_to_cpup((void *)&buf[2]);
715 opt = le16_to_cpup((void *)&buf[4]);
716 len = le16_to_cpup((void *)&buf[6]);
717
718 if (!(opt & BIT_0))
719 if (len == 0 || len > DMA_POOL_SIZE)
720 return -EINVAL;
721
722 memset(ha->edc_data, 0, len);
Joe Carnuccio6766df92011-05-10 11:30:15 -0700723 rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
724 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700725 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700726 ql_log(ql_log_info, vha, 0x7075,
Joe Perchesd8424f62011-11-18 09:03:06 -0800727 "Unable to write EDC status (%x) %02x:%04x:%02x:%02x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700728 rval, dev, adr, opt, len);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700729 return -EIO;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700730 }
731
732 ha->edc_data_len = len;
733
734 return count;
735}
736
737static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700738qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700739 struct bin_attribute *bin_attr,
740 char *buf, loff_t off, size_t count)
741{
742 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
743 struct device, kobj)));
744 struct qla_hw_data *ha = vha->hw;
745
746 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
747 return 0;
748
749 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
750 return -EINVAL;
751
752 memcpy(buf, ha->edc_data, ha->edc_data_len);
753
754 return ha->edc_data_len;
755}
756
757static struct bin_attribute sysfs_edc_status_attr = {
758 .attr = {
759 .name = "edc_status",
760 .mode = S_IRUSR | S_IWUSR,
761 },
762 .size = 0,
763 .write = qla2x00_sysfs_write_edc_status,
764 .read = qla2x00_sysfs_read_edc_status,
765};
766
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700767static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700768qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700769 struct bin_attribute *bin_attr,
770 char *buf, loff_t off, size_t count)
771{
772 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
773 struct device, kobj)));
774 struct qla_hw_data *ha = vha->hw;
775 int rval;
776 uint16_t actual_size;
777
778 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
779 return 0;
780
781 if (ha->xgmac_data)
782 goto do_read;
783
784 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
785 &ha->xgmac_data_dma, GFP_KERNEL);
786 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700787 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700788 "Unable to allocate memory for XGMAC read-data.\n");
789 return 0;
790 }
791
792do_read:
793 actual_size = 0;
794 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
795
796 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
797 XGMAC_DATA_SIZE, &actual_size);
798 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700799 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700800 "Unable to read XGMAC data (%x).\n", rval);
801 count = 0;
802 }
803
804 count = actual_size > count ? count: actual_size;
805 memcpy(buf, ha->xgmac_data, count);
806
807 return count;
808}
809
810static struct bin_attribute sysfs_xgmac_stats_attr = {
811 .attr = {
812 .name = "xgmac_stats",
813 .mode = S_IRUSR,
814 },
815 .size = 0,
816 .read = qla2x00_sysfs_read_xgmac_stats,
817};
818
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700819static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700820qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700821 struct bin_attribute *bin_attr,
822 char *buf, loff_t off, size_t count)
823{
824 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
825 struct device, kobj)));
826 struct qla_hw_data *ha = vha->hw;
827 int rval;
828 uint16_t actual_size;
829
830 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
831 return 0;
832
833 if (ha->dcbx_tlv)
834 goto do_read;
835
836 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
837 &ha->dcbx_tlv_dma, GFP_KERNEL);
838 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700839 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700840 "Unable to allocate memory for DCBX TLV read-data.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700841 return -ENOMEM;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700842 }
843
844do_read:
845 actual_size = 0;
846 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
847
848 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
849 DCBX_TLV_DATA_SIZE);
850 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700851 ql_log(ql_log_warn, vha, 0x7079,
852 "Unable to read DCBX TLV (%x).\n", rval);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700853 return -EIO;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700854 }
855
856 memcpy(buf, ha->dcbx_tlv, count);
857
858 return count;
859}
860
861static struct bin_attribute sysfs_dcbx_tlv_attr = {
862 .attr = {
863 .name = "dcbx_tlv",
864 .mode = S_IRUSR,
865 },
866 .size = 0,
867 .read = qla2x00_sysfs_read_dcbx_tlv,
868};
869
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700870static struct sysfs_entry {
871 char *name;
872 struct bin_attribute *attr;
873 int is4GBp_only;
874} bin_file_entries[] = {
875 { "fw_dump", &sysfs_fw_dump_attr, },
876 { "nvram", &sysfs_nvram_attr, },
877 { "optrom", &sysfs_optrom_attr, },
878 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
879 { "vpd", &sysfs_vpd_attr, 1 },
880 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700881 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700882 { "edc", &sysfs_edc_attr, 2 },
883 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700884 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700885 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800886 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700887};
888
8482e1182005-04-17 15:04:54 -0500889void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800890qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500891{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800892 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700893 struct sysfs_entry *iter;
894 int ret;
8482e1182005-04-17 15:04:54 -0500895
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700896 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800897 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700898 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700899 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
900 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700901 if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700902 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700903
904 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
905 iter->attr);
906 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700907 ql_log(ql_log_warn, vha, 0x00f3,
908 "Unable to create sysfs %s binary attribute (%d).\n",
909 iter->name, ret);
910 else
911 ql_dbg(ql_dbg_init, vha, 0x00f4,
912 "Successfully created sysfs %s binary attribure.\n",
913 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700914 }
8482e1182005-04-17 15:04:54 -0500915}
916
917void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800918qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500919{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800920 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700921 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800922 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500923
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700924 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700925 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700926 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700927 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
928 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700929 if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700930 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700931
Andrew Vasquez7914d002006-06-23 16:10:55 -0700932 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700933 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700934 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800935
936 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800937 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500938}
939
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700940/* Scsi_Host attributes. */
941
942static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100943qla2x00_drvr_version_show(struct device *dev,
944 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700945{
946 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
947}
948
949static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100950qla2x00_fw_version_show(struct device *dev,
951 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700952{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800953 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
954 struct qla_hw_data *ha = vha->hw;
955 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700956
957 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700959}
960
961static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100962qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
963 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700964{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800965 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
966 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700967 uint32_t sn;
968
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700969 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800970 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700971 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
972 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700973
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700974 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
975 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
976 sn % 100000);
977}
978
979static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100980qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700982{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800983 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
984 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700985}
986
987static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100988qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
989 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700990{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800991 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
992 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700993 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
994 ha->product_id[0], ha->product_id[1], ha->product_id[2],
995 ha->product_id[3]);
996}
997
998static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100999qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1000 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001001{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001002 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1003 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001004}
1005
1006static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001007qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1008 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001009{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001010 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001011 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001012 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001013}
1014
1015static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001016qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1017 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001018{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001019 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001020 char pci_info[30];
1021
1022 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001023 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001024}
1025
1026static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001027qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1028 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001029{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001030 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1031 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001032 int len = 0;
1033
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001034 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -07001035 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1036 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001037 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001038 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001039 qla2x00_reset_active(vha))
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001040 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1041 else {
1042 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
1043
1044 switch (ha->current_topology) {
1045 case ISP_CFG_NL:
1046 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1047 break;
1048 case ISP_CFG_FL:
1049 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1050 break;
1051 case ISP_CFG_N:
1052 len += snprintf(buf + len, PAGE_SIZE-len,
1053 "N_Port to N_Port\n");
1054 break;
1055 case ISP_CFG_F:
1056 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1057 break;
1058 default:
1059 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1060 break;
1061 }
1062 }
1063 return len;
1064}
1065
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001066static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001067qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1068 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001069{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001070 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001071 int len = 0;
1072
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001073 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001074 case QLA_ZIO_MODE_6:
1075 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1076 break;
1077 case QLA_ZIO_DISABLED:
1078 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1079 break;
1080 }
1081 return len;
1082}
1083
1084static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001085qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1086 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001087{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001088 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1089 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001090 int val = 0;
1091 uint16_t zio_mode;
1092
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001093 if (!IS_ZIO_SUPPORTED(ha))
1094 return -ENOTSUPP;
1095
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001096 if (sscanf(buf, "%d", &val) != 1)
1097 return -EINVAL;
1098
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001099 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001100 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001101 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001102 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001103
1104 /* Update per-hba values and queue a reset. */
1105 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1106 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001107 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001108 }
1109 return strlen(buf);
1110}
1111
1112static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001113qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1114 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001115{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001116 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001117
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001118 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001119}
1120
1121static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001122qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1123 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001124{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001125 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001126 int val = 0;
1127 uint16_t zio_timer;
1128
1129 if (sscanf(buf, "%d", &val) != 1)
1130 return -EINVAL;
1131 if (val > 25500 || val < 100)
1132 return -ERANGE;
1133
1134 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001135 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001136
1137 return strlen(buf);
1138}
1139
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001140static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001141qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1142 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001143{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001144 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001145 int len = 0;
1146
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001147 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001148 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1149 else
1150 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1151 return len;
1152}
1153
1154static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001155qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1156 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001157{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001158 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1159 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001160 int val = 0;
1161 int rval;
1162
1163 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1164 return -EPERM;
1165
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001166 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001168 "Abort ISP active -- ignoring beacon request.\n");
1169 return -EBUSY;
1170 }
1171
1172 if (sscanf(buf, "%d", &val) != 1)
1173 return -EINVAL;
1174
1175 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001176 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001177 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001179
1180 if (rval != QLA_SUCCESS)
1181 count = 0;
1182
1183 return count;
1184}
1185
Andrew Vasquez30c47662007-01-29 10:22:21 -08001186static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001187qla2x00_optrom_bios_version_show(struct device *dev,
1188 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001189{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001190 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1191 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001192 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1193 ha->bios_revision[0]);
1194}
1195
1196static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001197qla2x00_optrom_efi_version_show(struct device *dev,
1198 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001199{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001200 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1201 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001202 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1203 ha->efi_revision[0]);
1204}
1205
1206static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001207qla2x00_optrom_fcode_version_show(struct device *dev,
1208 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001209{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001210 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1211 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001212 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1213 ha->fcode_revision[0]);
1214}
1215
1216static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001217qla2x00_optrom_fw_version_show(struct device *dev,
1218 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001219{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001220 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1221 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001222 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1223 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1224 ha->fw_revision[3]);
1225}
1226
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001227static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001228qla2x00_optrom_gold_fw_version_show(struct device *dev,
1229 struct device_attribute *attr, char *buf)
1230{
1231 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1232 struct qla_hw_data *ha = vha->hw;
1233
1234 if (!IS_QLA81XX(ha))
1235 return snprintf(buf, PAGE_SIZE, "\n");
1236
1237 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1238 ha->gold_fw_version[0], ha->gold_fw_version[1],
1239 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1240}
1241
1242static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001243qla2x00_total_isp_aborts_show(struct device *dev,
1244 struct device_attribute *attr, char *buf)
1245{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001246 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1247 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001248 return snprintf(buf, PAGE_SIZE, "%d\n",
1249 ha->qla_stats.total_isp_aborts);
1250}
1251
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001252static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001253qla24xx_84xx_fw_version_show(struct device *dev,
1254 struct device_attribute *attr, char *buf)
1255{
1256 int rval = QLA_SUCCESS;
1257 uint16_t status[2] = {0, 0};
1258 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1259 struct qla_hw_data *ha = vha->hw;
1260
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001261 if (!IS_QLA84XX(ha))
1262 return snprintf(buf, PAGE_SIZE, "\n");
1263
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001264 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001265 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001266
1267 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1268 return snprintf(buf, PAGE_SIZE, "%u\n",
1269 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001270
1271 return snprintf(buf, PAGE_SIZE, "\n");
1272}
1273
1274static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001275qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1276 char *buf)
1277{
1278 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1279 struct qla_hw_data *ha = vha->hw;
1280
1281 if (!IS_QLA81XX(ha))
1282 return snprintf(buf, PAGE_SIZE, "\n");
1283
Andrew Vasquez55a96152009-03-24 09:08:03 -07001284 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001285 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001286 ha->mpi_capabilities);
1287}
1288
1289static ssize_t
1290qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1291 char *buf)
1292{
1293 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1294 struct qla_hw_data *ha = vha->hw;
1295
1296 if (!IS_QLA81XX(ha))
1297 return snprintf(buf, PAGE_SIZE, "\n");
1298
1299 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1300 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001301}
1302
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001303static ssize_t
1304qla2x00_flash_block_size_show(struct device *dev,
1305 struct device_attribute *attr, char *buf)
1306{
1307 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1308 struct qla_hw_data *ha = vha->hw;
1309
1310 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1311}
1312
Andrew Vasquezbad70012009-04-06 22:33:38 -07001313static ssize_t
1314qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1315 char *buf)
1316{
1317 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1318
Giridhar Malavalia9083012010-04-12 17:59:55 -07001319 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001320 return snprintf(buf, PAGE_SIZE, "\n");
1321
1322 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1323}
1324
1325static ssize_t
1326qla2x00_vn_port_mac_address_show(struct device *dev,
1327 struct device_attribute *attr, char *buf)
1328{
1329 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1330
Giridhar Malavalia9083012010-04-12 17:59:55 -07001331 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001332 return snprintf(buf, PAGE_SIZE, "\n");
1333
1334 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1335 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1336 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1337 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1338}
1339
Andrew Vasquez7f774022009-06-03 09:55:12 -07001340static ssize_t
1341qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1342 char *buf)
1343{
1344 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1345
1346 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1347}
1348
Andrew Vasquez656e8912009-06-03 09:55:29 -07001349static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001350qla2x00_thermal_temp_show(struct device *dev,
1351 struct device_attribute *attr, char *buf)
1352{
1353 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1354 int rval = QLA_FUNCTION_FAILED;
1355 uint16_t temp, frac;
1356
1357 if (!vha->hw->flags.thermal_supported)
1358 return snprintf(buf, PAGE_SIZE, "\n");
1359
1360 temp = frac = 0;
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001361 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001362 ql_log(ql_log_warn, vha, 0x707b,
1363 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001364 else if (!vha->hw->flags.eeh_busy)
1365 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1366 if (rval != QLA_SUCCESS)
1367 temp = frac = 0;
1368
1369 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1370}
1371
1372static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001373qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1374 char *buf)
1375{
1376 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001377 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001378 uint16_t state[5];
1379
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001380 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001381 ql_log(ql_log_warn, vha, 0x707c,
1382 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001383 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001384 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001385 if (rval != QLA_SUCCESS)
1386 memset(state, -1, sizeof(state));
1387
1388 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1389 state[1], state[2], state[3], state[4]);
1390}
1391
Tony Jonesee959b02008-02-22 00:13:36 +01001392static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1393static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1394static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1395static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1396static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1397static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1398static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1399static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001400static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001401static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1402static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1403 qla2x00_zio_timer_store);
1404static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1405 qla2x00_beacon_store);
1406static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1407 qla2x00_optrom_bios_version_show, NULL);
1408static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1409 qla2x00_optrom_efi_version_show, NULL);
1410static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1411 qla2x00_optrom_fcode_version_show, NULL);
1412static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1413 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001414static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1415 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001416static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1417 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001418static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1419 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001420static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001421static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001422static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1423 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001424static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1425static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1426 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001427static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001428static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001429static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001430
Tony Jonesee959b02008-02-22 00:13:36 +01001431struct device_attribute *qla2x00_host_attrs[] = {
1432 &dev_attr_driver_version,
1433 &dev_attr_fw_version,
1434 &dev_attr_serial_num,
1435 &dev_attr_isp_name,
1436 &dev_attr_isp_id,
1437 &dev_attr_model_name,
1438 &dev_attr_model_desc,
1439 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001440 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001441 &dev_attr_zio,
1442 &dev_attr_zio_timer,
1443 &dev_attr_beacon,
1444 &dev_attr_optrom_bios_version,
1445 &dev_attr_optrom_efi_version,
1446 &dev_attr_optrom_fcode_version,
1447 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001448 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001449 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001450 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001451 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001452 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001453 &dev_attr_vlan_id,
1454 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001455 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001456 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001457 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001458 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001459 NULL,
1460};
1461
8482e1182005-04-17 15:04:54 -05001462/* Host attributes. */
1463
1464static void
1465qla2x00_get_host_port_id(struct Scsi_Host *shost)
1466{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001467 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001468
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001469 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1470 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001471}
1472
1473static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001474qla2x00_get_host_speed(struct Scsi_Host *shost)
1475{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001476 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1477 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001478 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001479
1480 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001481 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001482 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001483 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001484 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001485 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001486 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001487 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001488 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001489 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001490 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001491 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001492 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001493 case PORT_SPEED_10GB:
1494 speed = FC_PORTSPEED_10GBIT;
1495 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001496 }
1497 fc_host_speed(shost) = speed;
1498}
1499
1500static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001501qla2x00_get_host_port_type(struct Scsi_Host *shost)
1502{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001504 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1505
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001506 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001507 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1508 return;
1509 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001510 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001511 case ISP_CFG_NL:
1512 port_type = FC_PORTTYPE_LPORT;
1513 break;
1514 case ISP_CFG_FL:
1515 port_type = FC_PORTTYPE_NLPORT;
1516 break;
1517 case ISP_CFG_N:
1518 port_type = FC_PORTTYPE_PTP;
1519 break;
1520 case ISP_CFG_F:
1521 port_type = FC_PORTTYPE_NPORT;
1522 break;
1523 }
1524 fc_host_port_type(shost) = port_type;
1525}
1526
1527static void
8482e1182005-04-17 15:04:54 -05001528qla2x00_get_starget_node_name(struct scsi_target *starget)
1529{
1530 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001531 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001532 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001533 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001534
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001535 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001536 if (fcport->rport &&
1537 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001538 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001539 break;
1540 }
1541 }
1542
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001543 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001544}
1545
1546static void
1547qla2x00_get_starget_port_name(struct scsi_target *starget)
1548{
1549 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001550 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001551 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001552 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001553
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001554 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001555 if (fcport->rport &&
1556 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001557 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001558 break;
1559 }
1560 }
1561
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001562 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001563}
1564
1565static void
1566qla2x00_get_starget_port_id(struct scsi_target *starget)
1567{
1568 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001569 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001570 fc_port_t *fcport;
1571 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001572
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001573 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001574 if (fcport->rport &&
1575 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001576 port_id = fcport->d_id.b.domain << 16 |
1577 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1578 break;
1579 }
1580 }
1581
8482e1182005-04-17 15:04:54 -05001582 fc_starget_port_id(starget) = port_id;
1583}
1584
1585static void
8482e1182005-04-17 15:04:54 -05001586qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1587{
8482e1182005-04-17 15:04:54 -05001588 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001589 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001590 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001591 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001592}
1593
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001594static void
1595qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1596{
1597 struct Scsi_Host *host = rport_to_shost(rport);
1598 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001599 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001600
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001601 if (!fcport)
1602 return;
1603
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001604 /* Now that the rport has been deleted, set the fcport state to
1605 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001606 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001607
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001608 /*
1609 * Transport has effectively 'deleted' the rport, clear
1610 * all local references.
1611 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001612 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001613 fcport->rport = fcport->drport = NULL;
1614 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001615 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001616
Andrew Vasquez85880802009-12-15 21:29:46 -08001617 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1618 return;
1619
1620 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001621 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001622 return;
1623 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001624}
1625
1626static void
1627qla2x00_terminate_rport_io(struct fc_rport *rport)
1628{
1629 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1630
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001631 if (!fcport)
1632 return;
1633
Andrew Vasquez85880802009-12-15 21:29:46 -08001634 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1635 return;
1636
Seokmann Jub9b12f72009-03-24 09:08:18 -07001637 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1638 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1639 return;
1640 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001641 /*
1642 * At this point all fcport's software-states are cleared. Perform any
1643 * final cleanup of firmware resources (PCBs and XCBs).
1644 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001645 if (fcport->loop_id != FC_NO_LOOP_ID &&
1646 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001647 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1648 fcport->loop_id, fcport->d_id.b.domain,
1649 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001650}
1651
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001652static int
1653qla2x00_issue_lip(struct Scsi_Host *shost)
1654{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001655 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001656
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001657 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001658 return 0;
1659}
1660
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001661static struct fc_host_statistics *
1662qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1663{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001664 scsi_qla_host_t *vha = shost_priv(shost);
1665 struct qla_hw_data *ha = vha->hw;
1666 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001667 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001668 struct link_statistics *stats;
1669 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001670 struct fc_host_statistics *pfc_host_stat;
1671
1672 pfc_host_stat = &ha->fc_host_stat;
1673 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1674
Andrew Vasquez85880802009-12-15 21:29:46 -08001675 if (test_bit(UNLOADING, &vha->dpc_flags))
1676 goto done;
1677
1678 if (unlikely(pci_channel_offline(ha->pdev)))
1679 goto done;
1680
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001681 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1682 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 ql_log(ql_log_warn, vha, 0x707d,
1684 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001685 goto done;
1686 }
1687 memset(stats, 0, DMA_POOL_SIZE);
1688
1689 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001690 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001691 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1692 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001693 !qla2x00_reset_active(vha) && !ha->dpc_active) {
Andrew Vasquez178779a2007-01-29 10:22:25 -08001694 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001695 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1696 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001697 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001698
1699 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001700 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001701
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001702 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1703 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1704 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1705 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1706 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1707 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1708 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001709 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001710 pfc_host_stat->tx_frames = stats->tx_frames;
1711 pfc_host_stat->rx_frames = stats->rx_frames;
1712 pfc_host_stat->dumped_frames = stats->dumped_frames;
1713 pfc_host_stat->nos_count = stats->nos_rcvd;
1714 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001715 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1716 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001717
1718done_free:
1719 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001720done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001721 return pfc_host_stat;
1722}
1723
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001724static void
1725qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1726{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001727 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001728
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001729 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001730}
1731
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001732static void
1733qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1734{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001736
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001737 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001738}
1739
Andrew Vasquez90991c82006-10-02 12:00:46 -07001740static void
1741qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1742{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001744 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1745 0xFF, 0xFF, 0xFF, 0xFF};
1746 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001747
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001748 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001749 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001750
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001751 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001752}
1753
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001754static void
1755qla2x00_get_host_port_state(struct Scsi_Host *shost)
1756{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001757 scsi_qla_host_t *vha = shost_priv(shost);
1758 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001759
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001760 if (!base_vha->flags.online) {
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001761 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001762 return;
1763 }
1764
1765 switch (atomic_read(&base_vha->loop_state)) {
1766 case LOOP_UPDATE:
1767 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1768 break;
1769 case LOOP_DOWN:
1770 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
1771 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1772 else
1773 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1774 break;
1775 case LOOP_DEAD:
1776 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1777 break;
1778 case LOOP_READY:
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001779 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001780 break;
1781 default:
1782 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1783 break;
1784 }
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001785}
1786
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001787static int
1788qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1789{
1790 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001791 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001792 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1793 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001794 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001795 uint16_t options = 0;
1796 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001797 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001798
1799 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1800 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001801 ql_log(ql_log_warn, vha, 0x707e,
1802 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001803 return (ret);
1804 }
1805
1806 vha = qla24xx_create_vhost(fc_vport);
1807 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001808 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001809 return FC_VPORT_FAILED;
1810 }
1811 if (disable) {
1812 atomic_set(&vha->vp_state, VP_OFFLINE);
1813 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1814 } else
1815 atomic_set(&vha->vp_state, VP_FAILED);
1816
1817 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001818 ql_log(ql_log_info, vha, 0x7080,
1819 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001820
1821 /* initialized vport states */
1822 atomic_set(&vha->loop_state, LOOP_DOWN);
1823 vha->vp_err_state= VP_ERR_PORTDWN;
1824 vha->vp_prev_err_state= VP_ERR_UNKWN;
1825 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001826 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1827 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001828 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001829 ql_dbg(ql_dbg_user, vha, 0x7081,
1830 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001831 atomic_set(&vha->loop_state, LOOP_DEAD);
1832 if (!disable)
1833 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1834 }
1835
Arun Easie02587d2011-08-16 11:29:23 -07001836 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001837 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07001838 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07001839 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001840 ql_dbg(ql_dbg_user, vha, 0x7082,
1841 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07001842 if (ql2xenabledif == 1)
1843 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07001844 scsi_host_set_prot(vha->host,
Arun Easi8cb20492011-08-16 11:29:22 -07001845 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001846 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001847 | SHOST_DIF_TYPE3_PROTECTION
1848 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001849 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001850 | SHOST_DIX_TYPE3_PROTECTION);
1851 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1852 } else
1853 vha->flags.difdix_supported = 0;
1854 }
1855
James Bottomleyd139b9b2009-11-05 13:33:12 -06001856 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1857 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001858 ql_dbg(ql_dbg_user, vha, 0x7083,
1859 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001860 goto vport_create_failed_2;
1861 }
1862
1863 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001864 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001865 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1866 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1867 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001868 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001869 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001870 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001871
1872 qla24xx_vport_disable(fc_vport, disable);
1873
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001874 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001875 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001876 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1877 "Request queue %p attached with "
1878 "VP[%d], cpu affinity =%d\n",
1879 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001880 goto vport_queue;
1881 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001882 goto vport_queue;
1883 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001884 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1885 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1886 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001887 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001888 qos = ha->npiv_info[cnt].q_qos;
1889 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001890 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001891 }
1892 if (qos) {
1893 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1894 qos);
1895 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001896 ql_log(ql_log_warn, vha, 0x7084,
1897 "Can't create request queue for VP[%d]\n",
1898 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001899 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001900 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1901 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1902 ret, qos, vha->vp_idx);
1903 ql_dbg(ql_dbg_user, vha, 0x7085,
1904 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1905 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001906 req = ha->req_q_map[ret];
1907 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001908 }
1909
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001910vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001911 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001912 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001913
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001914vport_create_failed_2:
1915 qla24xx_disable_vp(vha);
1916 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001917 scsi_host_put(vha->host);
1918 return FC_VPORT_FAILED;
1919}
1920
Adrian Bunka824ebb2008-01-17 09:02:15 -08001921static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001922qla24xx_vport_delete(struct fc_vport *fc_vport)
1923{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001924 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001925 struct qla_hw_data *ha = vha->hw;
1926 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001927
1928 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001929 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001930 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001931
1932 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001933
Arun Easifeafb7b2010-09-03 14:57:00 -07001934 vha->flags.delete_progress = 1;
1935
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001936 fc_remove_host(vha->host);
1937
1938 scsi_remove_host(vha->host);
1939
Arun Easi9f406822011-05-10 11:18:17 -07001940 /* Allow timer to run to drain queued items, when removing vp */
1941 qla24xx_deallocate_vp_id(vha);
1942
Arun Easifeafb7b2010-09-03 14:57:00 -07001943 if (vha->timer_active) {
1944 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001945 ql_dbg(ql_dbg_user, vha, 0x7086,
1946 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001947 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001948
Arun Easifeafb7b2010-09-03 14:57:00 -07001949 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001950 if (ql2xextended_error_logging & ql_dbg_user)
1951 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001952 * the net we have placed below */
1953
1954 BUG_ON(atomic_read(&vha->vref_count));
1955
1956 qla2x00_free_fcports(vha);
1957
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001958 mutex_lock(&ha->vport_lock);
1959 ha->cur_vport_count--;
1960 clear_bit(vha->vp_idx, ha->vp_idx_map);
1961 mutex_unlock(&ha->vport_lock);
1962
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001963 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001964 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001965 ql_log(ql_log_warn, vha, 0x7087,
1966 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001967 }
1968
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001969 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001970 scsi_host_put(vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001971 return 0;
1972}
1973
Adrian Bunka824ebb2008-01-17 09:02:15 -08001974static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001975qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1976{
1977 scsi_qla_host_t *vha = fc_vport->dd_data;
1978
1979 if (disable)
1980 qla24xx_disable_vp(vha);
1981 else
1982 qla24xx_enable_vp(vha);
1983
1984 return 0;
1985}
1986
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001987struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001988
1989 .show_host_node_name = 1,
1990 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001991 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001992 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001993
8482e1182005-04-17 15:04:54 -05001994 .get_host_port_id = qla2x00_get_host_port_id,
1995 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001996 .get_host_speed = qla2x00_get_host_speed,
1997 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001998 .get_host_port_type = qla2x00_get_host_port_type,
1999 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07002000 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2001 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002002 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2003 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07002004 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2005 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07002006 .get_host_port_state = qla2x00_get_host_port_state,
2007 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05002008
bdf79622005-04-17 15:06:53 -05002009 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002010 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05002011
2012 .get_starget_node_name = qla2x00_get_starget_node_name,
2013 .show_starget_node_name = 1,
2014 .get_starget_port_name = qla2x00_get_starget_port_name,
2015 .show_starget_port_name = 1,
2016 .get_starget_port_id = qla2x00_get_starget_port_id,
2017 .show_starget_port_id = 1,
2018
8482e1182005-04-17 15:04:54 -05002019 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2020 .show_rport_dev_loss_tmo = 1,
2021
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002022 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002023 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2024 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002025 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002026
2027 .vport_create = qla24xx_vport_create,
2028 .vport_disable = qla24xx_vport_disable,
2029 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002030 .bsg_request = qla24xx_bsg_request,
2031 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002032};
2033
2034struct fc_function_template qla2xxx_transport_vport_functions = {
2035
2036 .show_host_node_name = 1,
2037 .show_host_port_name = 1,
2038 .show_host_supported_classes = 1,
2039
2040 .get_host_port_id = qla2x00_get_host_port_id,
2041 .show_host_port_id = 1,
2042 .get_host_speed = qla2x00_get_host_speed,
2043 .show_host_speed = 1,
2044 .get_host_port_type = qla2x00_get_host_port_type,
2045 .show_host_port_type = 1,
2046 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2047 .show_host_symbolic_name = 1,
2048 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2049 .show_host_system_hostname = 1,
2050 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2051 .show_host_fabric_name = 1,
2052 .get_host_port_state = qla2x00_get_host_port_state,
2053 .show_host_port_state = 1,
2054
2055 .dd_fcrport_size = sizeof(struct fc_port *),
2056 .show_rport_supported_classes = 1,
2057
2058 .get_starget_node_name = qla2x00_get_starget_node_name,
2059 .show_starget_node_name = 1,
2060 .get_starget_port_name = qla2x00_get_starget_port_name,
2061 .show_starget_port_name = 1,
2062 .get_starget_port_id = qla2x00_get_starget_port_id,
2063 .show_starget_port_id = 1,
2064
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002065 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2066 .show_rport_dev_loss_tmo = 1,
2067
2068 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002069 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2070 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002071 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002072 .bsg_request = qla24xx_bsg_request,
2073 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05002074};
2075
8482e1182005-04-17 15:04:54 -05002076void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002077qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05002078{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002079 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002080 u32 speed = FC_PORTSPEED_UNKNOWN;
2081
Mike Christied2b5f102010-09-15 16:52:30 -05002082 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002083 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2084 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2085 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
2086 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2087 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002088
Giridhar Malavalia9083012010-04-12 17:59:55 -07002089 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002090 speed = FC_PORTSPEED_10GBIT;
2091 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002092 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2093 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002094 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002095 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2096 FC_PORTSPEED_1GBIT;
2097 else if (IS_QLA23XX(ha))
2098 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2099 else
2100 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002101 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002102}