blob: f8d7692851fa18c0be909d1bbd65575e7c70394b [file] [log] [blame]
8482e1182005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
8482e1182005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e1182005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090012#include <linux/delay.h>
8482e1182005-04-17 15:04:54 -050013
Adrian Bunka824ebb2008-01-17 09:02:15 -080014static int qla24xx_vport_disable(struct fc_vport *, bool);
Giridhar Malavali6e980162010-03-19 17:03:58 -070015
8482e1182005-04-17 15:04:54 -050016/* SYSFS attributes --------------------------------------------------------- */
17
18static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070019qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080020 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050022{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali08de2842011-08-16 11:31:44 -070026 int rval = 0;
8482e1182005-04-17 15:04:54 -050027
28 if (ha->fw_dump_reading == 0)
29 return 0;
8482e1182005-04-17 15:04:54 -050030
Giridhar Malavali08de2842011-08-16 11:31:44 -070031 if (IS_QLA82XX(ha)) {
32 if (off < ha->md_template_size) {
33 rval = memory_read_from_buffer(buf, count,
34 &off, ha->md_tmplt_hdr, ha->md_template_size);
35 return rval;
36 }
37 off -= ha->md_template_size;
38 rval = memory_read_from_buffer(buf, count,
39 &off, ha->md_dump, ha->md_dump_size);
40 return rval;
41 } else
42 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
Akinobu Mitab3dc9082008-07-24 08:31:47 -070043 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050044}
45
46static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070047qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080048 struct bin_attribute *bin_attr,
49 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050050{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080051 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050052 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080053 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050054 int reading;
8482e1182005-04-17 15:04:54 -050055
56 if (off != 0)
57 return (0);
58
59 reading = simple_strtol(buf, NULL, 10);
60 switch (reading) {
61 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070062 if (!ha->fw_dump_reading)
63 break;
8482e1182005-04-17 15:04:54 -050064
Saurav Kashyap7c3df132011-07-14 12:00:13 -070065 ql_log(ql_log_info, vha, 0x705d,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070067
Giridhar Malavali08de2842011-08-16 11:31:44 -070068 if (IS_QLA82XX(vha->hw)) {
69 qla82xx_md_free(vha);
70 qla82xx_md_prep(vha);
71 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070072 ha->fw_dump_reading = 0;
73 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050074 break;
75 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070076 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050077 ha->fw_dump_reading = 1;
78
Saurav Kashyap7c3df132011-07-14 12:00:13 -070079 ql_log(ql_log_info, vha, 0x705e,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070080 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080081 vha->host_no);
8482e1182005-04-17 15:04:54 -050082 }
83 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070084 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080085 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070086 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070087 case 3:
Giridhar Malavali08de2842011-08-16 11:31:44 -070088 if (IS_QLA82XX(ha)) {
89 qla82xx_idc_lock(ha);
90 qla82xx_set_reset_owner(vha);
91 qla82xx_idc_unlock(ha);
92 } else
93 qla2x00_system_error(vha);
94 break;
95 case 4:
96 if (IS_QLA82XX(ha)) {
97 if (ha->md_tmplt_hdr)
98 ql_dbg(ql_dbg_user, vha, 0x705b,
99 "MiniDump supported with this firmware.\n");
100 else
101 ql_dbg(ql_dbg_user, vha, 0x709d,
102 "MiniDump not supported with this firmware.\n");
103 }
104 break;
105 case 5:
106 if (IS_QLA82XX(ha))
107 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez68af0812008-05-12 22:21:13 -0700108 break;
8482e1182005-04-17 15:04:54 -0500109 }
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800110 return count;
8482e1182005-04-17 15:04:54 -0500111}
112
113static struct bin_attribute sysfs_fw_dump_attr = {
114 .attr = {
115 .name = "fw_dump",
116 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500117 },
118 .size = 0,
119 .read = qla2x00_sysfs_read_fw_dump,
120 .write = qla2x00_sysfs_write_fw_dump,
121};
122
123static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700124qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800125 struct bin_attribute *bin_attr,
126 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500127{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800128 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500129 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800130 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500131
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700132 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500133 return 0;
134
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700135 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700136 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700137 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700138 return memory_read_from_buffer(buf, count, &off, ha->nvram,
139 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500140}
141
142static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700143qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800144 struct bin_attribute *bin_attr,
145 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500146{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800147 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500148 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800149 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500150 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500151
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700152 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
153 !ha->isp_ops->write_nvram)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700154 return -EINVAL;
8482e1182005-04-17 15:04:54 -0500155
156 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700157 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700158 uint32_t *iter;
159 uint32_t chksum;
160
161 iter = (uint32_t *)buf;
162 chksum = 0;
163 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
164 chksum += le32_to_cpu(*iter++);
165 chksum = ~chksum + 1;
166 *iter = cpu_to_le32(chksum);
167 } else {
168 uint8_t *iter;
169 uint8_t chksum;
170
171 iter = (uint8_t *)buf;
172 chksum = 0;
173 for (cnt = 0; cnt < count - 1; cnt++)
174 chksum += *iter++;
175 chksum = ~chksum + 1;
176 *iter = chksum;
177 }
8482e1182005-04-17 15:04:54 -0500178
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700179 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700180 ql_log(ql_log_warn, vha, 0x705f,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700181 "HBA not online, failing NVRAM update.\n");
182 return -EAGAIN;
183 }
184
8482e1182005-04-17 15:04:54 -0500185 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
187 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700188 count);
8482e1182005-04-17 15:04:54 -0500189
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 ql_dbg(ql_dbg_user, vha, 0x7060,
191 "Setting ISP_ABORT_NEEDED\n");
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700192 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700194 qla2xxx_wake_dpc(vha);
195 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800196
Joe Carnucciob668ae32011-08-16 11:31:53 -0700197 return count;
8482e1182005-04-17 15:04:54 -0500198}
199
200static struct bin_attribute sysfs_nvram_attr = {
201 .attr = {
202 .name = "nvram",
203 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500204 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800205 .size = 512,
8482e1182005-04-17 15:04:54 -0500206 .read = qla2x00_sysfs_read_nvram,
207 .write = qla2x00_sysfs_write_nvram,
208};
209
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800210static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700211qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800212 struct bin_attribute *bin_attr,
213 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800214{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800215 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800216 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800217 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800218
219 if (ha->optrom_state != QLA_SREADING)
220 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800221
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700222 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
223 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224}
225
226static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700227qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800228 struct bin_attribute *bin_attr,
229 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800230{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800231 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800234
235 if (ha->optrom_state != QLA_SWRITING)
236 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700237 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800238 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700239 if (off + count > ha->optrom_region_size)
240 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800241
242 memcpy(&ha->optrom_buffer[off], buf, count);
243
244 return count;
245}
246
247static struct bin_attribute sysfs_optrom_attr = {
248 .attr = {
249 .name = "optrom",
250 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800251 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700252 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800253 .read = qla2x00_sysfs_read_optrom,
254 .write = qla2x00_sysfs_write_optrom,
255};
256
257static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700258qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800259 struct bin_attribute *bin_attr,
260 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800261{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800262 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800263 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800264 struct qla_hw_data *ha = vha->hw;
265
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700266 uint32_t start = 0;
267 uint32_t size = ha->optrom_size;
268 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269
270 if (off)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700271 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800272
Andrew Vasquez85880802009-12-15 21:29:46 -0800273 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700274 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800275
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700276 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
277 return -EINVAL;
278 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800279 return -EINVAL;
280
281 switch (val) {
282 case 0:
283 if (ha->optrom_state != QLA_SREADING &&
284 ha->optrom_state != QLA_SWRITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700285 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800286
287 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700288
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700289 ql_dbg(ql_dbg_user, vha, 0x7061,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700290 "Freeing flash region allocation -- 0x%x bytes.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700291 ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700292
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800293 vfree(ha->optrom_buffer);
294 ha->optrom_buffer = NULL;
295 break;
296 case 1:
297 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700298 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800299
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700300 ha->optrom_region_start = start;
301 ha->optrom_region_size = start + size > ha->optrom_size ?
302 ha->optrom_size - start : size;
303
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800304 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700305 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800306 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700307 ql_log(ql_log_warn, vha, 0x7062,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800308 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700309 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800310
311 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700312 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800313 }
314
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700315 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_log(ql_log_warn, vha, 0x7063,
317 "HBA not online, failing NVRAM update.\n");
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700318 return -EAGAIN;
319 }
320
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 ql_dbg(ql_dbg_user, vha, 0x7064,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700322 "Reading flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700324
325 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800326 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700327 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800328 break;
329 case 2:
330 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700331 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800332
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700333 /*
334 * We need to be more restrictive on which FLASH regions are
335 * allowed to be updated via user-space. Regions accessible
336 * via this method include:
337 *
338 * ISP21xx/ISP22xx/ISP23xx type boards:
339 *
340 * 0x000000 -> 0x020000 -- Boot code.
341 *
342 * ISP2322/ISP24xx type boards:
343 *
344 * 0x000000 -> 0x07ffff -- Boot code.
345 * 0x080000 -> 0x0fffff -- Firmware.
346 *
347 * ISP25xx type boards:
348 *
349 * 0x000000 -> 0x07ffff -- Boot code.
350 * 0x080000 -> 0x0fffff -- Firmware.
351 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
352 */
353 valid = 0;
354 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
355 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700356 else if (start == (ha->flt_region_boot * 4) ||
357 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700358 valid = 1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800359 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
360 || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700361 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700362 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700363 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700364 "Invalid start region 0x%x/0x%x.\n", start, size);
365 return -EINVAL;
366 }
367
368 ha->optrom_region_start = start;
369 ha->optrom_region_size = start + size > ha->optrom_size ?
370 ha->optrom_size - start : size;
371
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800372 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700373 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800374 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700375 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800376 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700377 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800378
379 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700380 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800381 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700382
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700383 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700384 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700385 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700386
387 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800388 break;
389 case 3:
390 if (ha->optrom_state != QLA_SWRITING)
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800391 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800392
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700393 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700394 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700395 "HBA not online, failing flash update.\n");
396 return -EAGAIN;
397 }
398
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700399 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700400 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700401 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700402
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800403 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700404 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800405 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700406 default:
Joe Carnucciob668ae32011-08-16 11:31:53 -0700407 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800408 }
409 return count;
410}
411
412static struct bin_attribute sysfs_optrom_ctl_attr = {
413 .attr = {
414 .name = "optrom_ctl",
415 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800416 },
417 .size = 0,
418 .write = qla2x00_sysfs_write_optrom_ctl,
419};
420
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800421static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700422qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800423 struct bin_attribute *bin_attr,
424 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800425{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800426 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800427 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800428 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800429
Andrew Vasquez85880802009-12-15 21:29:46 -0800430 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700431 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800432
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700433 if (!capable(CAP_SYS_ADMIN))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700434 return -EINVAL;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800435
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700436 if (IS_NOCACHE_VPD_TYPE(ha))
437 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
438 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700439 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800440}
441
442static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700443qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800444 struct bin_attribute *bin_attr,
445 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800446{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800447 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800448 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800449 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700450 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800451
Andrew Vasquez85880802009-12-15 21:29:46 -0800452 if (unlikely(pci_channel_offline(ha->pdev)))
453 return 0;
454
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700455 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
456 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800457 return 0;
458
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700459 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700460 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700461 "HBA not online, failing VPD update.\n");
462 return -EAGAIN;
463 }
464
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800465 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800466 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
467 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800468
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700469 /* Update flash version information for 4Gb & above. */
470 if (!IS_FWI2_CAPABLE(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700471 return -EINVAL;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700472
473 tmp_data = vmalloc(256);
474 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700475 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700476 "Unable to allocate memory for VPD information update.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700477 return -ENOMEM;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700478 }
479 ha->isp_ops->get_flash_version(vha, tmp_data);
480 vfree(tmp_data);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700481
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800482 return count;
483}
484
485static struct bin_attribute sysfs_vpd_attr = {
486 .attr = {
487 .name = "vpd",
488 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800489 },
490 .size = 0,
491 .read = qla2x00_sysfs_read_vpd,
492 .write = qla2x00_sysfs_write_vpd,
493};
494
Andrew Vasquez88729e52006-06-23 16:10:50 -0700495static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700496qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800497 struct bin_attribute *bin_attr,
498 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700499{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800500 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700501 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800502 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700503 uint16_t iter, addr, offset;
504 int rval;
505
506 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
507 return 0;
508
Andrew Vasqueze8711082008-01-31 12:33:48 -0800509 if (ha->sfp_data)
510 goto do_read;
511
512 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
513 &ha->sfp_data_dma);
514 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700515 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800516 "Unable to allocate memory for SFP read-data.\n");
517 return 0;
518 }
519
520do_read:
521 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700522 addr = 0xa0;
523 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
524 iter++, offset += SFP_BLOCK_SIZE) {
525 if (iter == 4) {
526 /* Skip to next device address. */
527 addr = 0xa2;
528 offset = 0;
529 }
530
Joe Carnuccio6766df92011-05-10 11:30:15 -0700531 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
532 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700533 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700534 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700535 "Unable to read SFP data (%x/%x/%x).\n", rval,
536 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700537
Joe Carnucciob668ae32011-08-16 11:31:53 -0700538 return -EIO;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700539 }
540 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
541 buf += SFP_BLOCK_SIZE;
542 }
543
544 return count;
545}
546
547static struct bin_attribute sysfs_sfp_attr = {
548 .attr = {
549 .name = "sfp",
550 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700551 },
552 .size = SFP_DEV_SIZE * 2,
553 .read = qla2x00_sysfs_read_sfp,
554};
555
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700556static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700557qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700558 struct bin_attribute *bin_attr,
559 char *buf, loff_t off, size_t count)
560{
561 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
562 struct device, kobj)));
563 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700564 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700565 int type;
566
567 if (off != 0)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700568 return -EINVAL;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700569
570 type = simple_strtol(buf, NULL, 10);
571 switch (type) {
572 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700573 ql_log(ql_log_info, vha, 0x706e,
574 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700575
576 scsi_block_requests(vha->host);
577 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavali08de2842011-08-16 11:31:44 -0700578 if (IS_QLA82XX(ha)) {
579 qla82xx_idc_lock(ha);
580 qla82xx_set_reset_owner(vha);
581 qla82xx_idc_unlock(ha);
582 }
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700583 qla2xxx_wake_dpc(vha);
584 qla2x00_wait_for_chip_reset(vha);
585 scsi_unblock_requests(vha->host);
586 break;
587 case 0x2025d:
588 if (!IS_QLA81XX(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700589 return -EPERM;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700590
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700591 ql_log(ql_log_info, vha, 0x706f,
592 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700593
594 /* Make sure FC side is not in reset */
595 qla2x00_wait_for_hba_online(vha);
596
597 /* Issue MPI reset */
598 scsi_block_requests(vha->host);
599 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700600 ql_log(ql_log_warn, vha, 0x7070,
601 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700602 scsi_unblock_requests(vha->host);
603 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700604 case 0x2025e:
605 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700606 ql_log(ql_log_info, vha, 0x7071,
607 "FCoE ctx reset no supported.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700608 return -EPERM;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700609 }
610
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700611 ql_log(ql_log_info, vha, 0x7072,
612 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700613 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
614 qla2xxx_wake_dpc(vha);
615 qla2x00_wait_for_fcoe_ctx_reset(vha);
616 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700617 }
618 return count;
619}
620
621static struct bin_attribute sysfs_reset_attr = {
622 .attr = {
623 .name = "reset",
624 .mode = S_IWUSR,
625 },
626 .size = 0,
627 .write = qla2x00_sysfs_write_reset,
628};
629
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700630static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700631qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700632 struct bin_attribute *bin_attr,
633 char *buf, loff_t off, size_t count)
634{
635 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
636 struct device, kobj)));
637 struct qla_hw_data *ha = vha->hw;
638 int rval;
639 uint16_t actual_size;
640
641 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
642 return 0;
643
644 if (ha->xgmac_data)
645 goto do_read;
646
647 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
648 &ha->xgmac_data_dma, GFP_KERNEL);
649 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700651 "Unable to allocate memory for XGMAC read-data.\n");
652 return 0;
653 }
654
655do_read:
656 actual_size = 0;
657 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
658
659 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
660 XGMAC_DATA_SIZE, &actual_size);
661 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700662 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700663 "Unable to read XGMAC data (%x).\n", rval);
664 count = 0;
665 }
666
667 count = actual_size > count ? count: actual_size;
668 memcpy(buf, ha->xgmac_data, count);
669
670 return count;
671}
672
673static struct bin_attribute sysfs_xgmac_stats_attr = {
674 .attr = {
675 .name = "xgmac_stats",
676 .mode = S_IRUSR,
677 },
678 .size = 0,
679 .read = qla2x00_sysfs_read_xgmac_stats,
680};
681
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700682static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700683qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700684 struct bin_attribute *bin_attr,
685 char *buf, loff_t off, size_t count)
686{
687 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
688 struct device, kobj)));
689 struct qla_hw_data *ha = vha->hw;
690 int rval;
691 uint16_t actual_size;
692
693 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
694 return 0;
695
696 if (ha->dcbx_tlv)
697 goto do_read;
698
699 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
700 &ha->dcbx_tlv_dma, GFP_KERNEL);
701 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700702 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700703 "Unable to allocate memory for DCBX TLV read-data.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700704 return -ENOMEM;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700705 }
706
707do_read:
708 actual_size = 0;
709 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
710
711 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
712 DCBX_TLV_DATA_SIZE);
713 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700714 ql_log(ql_log_warn, vha, 0x7079,
715 "Unable to read DCBX TLV (%x).\n", rval);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700716 return -EIO;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700717 }
718
719 memcpy(buf, ha->dcbx_tlv, count);
720
721 return count;
722}
723
724static struct bin_attribute sysfs_dcbx_tlv_attr = {
725 .attr = {
726 .name = "dcbx_tlv",
727 .mode = S_IRUSR,
728 },
729 .size = 0,
730 .read = qla2x00_sysfs_read_dcbx_tlv,
731};
732
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700733static struct sysfs_entry {
734 char *name;
735 struct bin_attribute *attr;
736 int is4GBp_only;
737} bin_file_entries[] = {
738 { "fw_dump", &sysfs_fw_dump_attr, },
739 { "nvram", &sysfs_nvram_attr, },
740 { "optrom", &sysfs_optrom_attr, },
741 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
742 { "vpd", &sysfs_vpd_attr, 1 },
743 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700744 { "reset", &sysfs_reset_attr, },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700745 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700746 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800747 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700748};
749
8482e1182005-04-17 15:04:54 -0500750void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800751qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500752{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800753 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700754 struct sysfs_entry *iter;
755 int ret;
8482e1182005-04-17 15:04:54 -0500756
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700757 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800758 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700759 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700760 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
761 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800762 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700763 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700764
765 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
766 iter->attr);
767 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700768 ql_log(ql_log_warn, vha, 0x00f3,
769 "Unable to create sysfs %s binary attribute (%d).\n",
770 iter->name, ret);
771 else
772 ql_dbg(ql_dbg_init, vha, 0x00f4,
773 "Successfully created sysfs %s binary attribure.\n",
774 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700775 }
8482e1182005-04-17 15:04:54 -0500776}
777
778void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800779qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500780{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800781 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700782 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800783 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500784
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700785 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700786 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700787 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700788 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
789 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800790 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700791 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700792
Andrew Vasquez7914d002006-06-23 16:10:55 -0700793 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700794 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700795 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800796
797 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800798 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500799}
800
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700801/* Scsi_Host attributes. */
802
803static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100804qla2x00_drvr_version_show(struct device *dev,
805 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700806{
807 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
808}
809
810static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100811qla2x00_fw_version_show(struct device *dev,
812 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700813{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800814 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
815 struct qla_hw_data *ha = vha->hw;
816 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700817
818 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800819 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700820}
821
822static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100823qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
824 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700825{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800826 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
827 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700828 uint32_t sn;
829
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700830 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800831 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700832 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
833 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700834
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700835 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
836 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
837 sn % 100000);
838}
839
840static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100841qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
842 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700843{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800844 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
845 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700846}
847
848static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100849qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
850 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700851{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800852 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
853 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700854 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
855 ha->product_id[0], ha->product_id[1], ha->product_id[2],
856 ha->product_id[3]);
857}
858
859static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100860qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
861 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700862{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800863 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
864 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700865}
866
867static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100868qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
869 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700870{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800871 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700872 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800873 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700874}
875
876static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100877qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
878 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700879{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800880 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700881 char pci_info[30];
882
883 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800884 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700885}
886
887static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100888qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
889 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700890{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800891 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
892 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700893 int len = 0;
894
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -0700896 atomic_read(&vha->loop_state) == LOOP_DEAD ||
897 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700898 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800899 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -0800900 qla2x00_reset_active(vha))
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700901 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
902 else {
903 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
904
905 switch (ha->current_topology) {
906 case ISP_CFG_NL:
907 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
908 break;
909 case ISP_CFG_FL:
910 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
911 break;
912 case ISP_CFG_N:
913 len += snprintf(buf + len, PAGE_SIZE-len,
914 "N_Port to N_Port\n");
915 break;
916 case ISP_CFG_F:
917 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
918 break;
919 default:
920 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
921 break;
922 }
923 }
924 return len;
925}
926
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700927static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100928qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
929 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700930{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700932 int len = 0;
933
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800934 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700935 case QLA_ZIO_MODE_6:
936 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
937 break;
938 case QLA_ZIO_DISABLED:
939 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
940 break;
941 }
942 return len;
943}
944
945static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100946qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
947 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700948{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800949 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
950 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700951 int val = 0;
952 uint16_t zio_mode;
953
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800954 if (!IS_ZIO_SUPPORTED(ha))
955 return -ENOTSUPP;
956
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700957 if (sscanf(buf, "%d", &val) != 1)
958 return -EINVAL;
959
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800960 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700961 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800962 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700963 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700964
965 /* Update per-hba values and queue a reset. */
966 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
967 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800968 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700969 }
970 return strlen(buf);
971}
972
973static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100974qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
975 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700976{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800977 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700978
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800979 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700980}
981
982static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100983qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
984 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700985{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800986 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700987 int val = 0;
988 uint16_t zio_timer;
989
990 if (sscanf(buf, "%d", &val) != 1)
991 return -EINVAL;
992 if (val > 25500 || val < 100)
993 return -ERANGE;
994
995 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800996 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700997
998 return strlen(buf);
999}
1000
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001001static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001002qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1003 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001004{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001005 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001006 int len = 0;
1007
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001008 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001009 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1010 else
1011 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1012 return len;
1013}
1014
1015static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001016qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1017 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001018{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001019 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1020 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001021 int val = 0;
1022 int rval;
1023
1024 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1025 return -EPERM;
1026
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001028 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001029 "Abort ISP active -- ignoring beacon request.\n");
1030 return -EBUSY;
1031 }
1032
1033 if (sscanf(buf, "%d", &val) != 1)
1034 return -EINVAL;
1035
1036 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001037 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001038 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001039 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001040
1041 if (rval != QLA_SUCCESS)
1042 count = 0;
1043
1044 return count;
1045}
1046
Andrew Vasquez30c47662007-01-29 10:22:21 -08001047static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001048qla2x00_optrom_bios_version_show(struct device *dev,
1049 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001050{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001051 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1052 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001053 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1054 ha->bios_revision[0]);
1055}
1056
1057static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001058qla2x00_optrom_efi_version_show(struct device *dev,
1059 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001060{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001061 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1062 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001063 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1064 ha->efi_revision[0]);
1065}
1066
1067static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001068qla2x00_optrom_fcode_version_show(struct device *dev,
1069 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001070{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001071 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1072 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001073 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1074 ha->fcode_revision[0]);
1075}
1076
1077static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001078qla2x00_optrom_fw_version_show(struct device *dev,
1079 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001080{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001081 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001083 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1084 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1085 ha->fw_revision[3]);
1086}
1087
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001088static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001089qla2x00_optrom_gold_fw_version_show(struct device *dev,
1090 struct device_attribute *attr, char *buf)
1091{
1092 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1093 struct qla_hw_data *ha = vha->hw;
1094
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001095 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001096 return snprintf(buf, PAGE_SIZE, "\n");
1097
1098 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1099 ha->gold_fw_version[0], ha->gold_fw_version[1],
1100 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1101}
1102
1103static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001104qla2x00_total_isp_aborts_show(struct device *dev,
1105 struct device_attribute *attr, char *buf)
1106{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001107 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001108 return snprintf(buf, PAGE_SIZE, "%d\n",
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001109 vha->qla_stats.total_isp_aborts);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001110}
1111
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001112static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001113qla24xx_84xx_fw_version_show(struct device *dev,
1114 struct device_attribute *attr, char *buf)
1115{
1116 int rval = QLA_SUCCESS;
1117 uint16_t status[2] = {0, 0};
1118 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1119 struct qla_hw_data *ha = vha->hw;
1120
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001121 if (!IS_QLA84XX(ha))
1122 return snprintf(buf, PAGE_SIZE, "\n");
1123
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001124 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001125 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001126
1127 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1128 return snprintf(buf, PAGE_SIZE, "%u\n",
1129 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001130
1131 return snprintf(buf, PAGE_SIZE, "\n");
1132}
1133
1134static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001135qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1136 char *buf)
1137{
1138 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1139 struct qla_hw_data *ha = vha->hw;
1140
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001141 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001142 return snprintf(buf, PAGE_SIZE, "\n");
1143
Andrew Vasquez55a96152009-03-24 09:08:03 -07001144 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001145 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001146 ha->mpi_capabilities);
1147}
1148
1149static ssize_t
1150qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1151 char *buf)
1152{
1153 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1154 struct qla_hw_data *ha = vha->hw;
1155
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001156 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001157 return snprintf(buf, PAGE_SIZE, "\n");
1158
1159 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1160 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001161}
1162
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001163static ssize_t
1164qla2x00_flash_block_size_show(struct device *dev,
1165 struct device_attribute *attr, char *buf)
1166{
1167 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1168 struct qla_hw_data *ha = vha->hw;
1169
1170 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1171}
1172
Andrew Vasquezbad70012009-04-06 22:33:38 -07001173static ssize_t
1174qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1175 char *buf)
1176{
1177 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1178
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001179 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001180 return snprintf(buf, PAGE_SIZE, "\n");
1181
1182 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1183}
1184
1185static ssize_t
1186qla2x00_vn_port_mac_address_show(struct device *dev,
1187 struct device_attribute *attr, char *buf)
1188{
1189 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1190
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001191 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001192 return snprintf(buf, PAGE_SIZE, "\n");
1193
1194 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1195 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1196 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1197 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1198}
1199
Andrew Vasquez7f774022009-06-03 09:55:12 -07001200static ssize_t
1201qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1202 char *buf)
1203{
1204 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1205
1206 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1207}
1208
Andrew Vasquez656e8912009-06-03 09:55:29 -07001209static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001210qla2x00_thermal_temp_show(struct device *dev,
1211 struct device_attribute *attr, char *buf)
1212{
1213 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1214 int rval = QLA_FUNCTION_FAILED;
1215 uint16_t temp, frac;
1216
1217 if (!vha->hw->flags.thermal_supported)
1218 return snprintf(buf, PAGE_SIZE, "\n");
1219
1220 temp = frac = 0;
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001221 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001222 ql_log(ql_log_warn, vha, 0x707b,
1223 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001224 else if (!vha->hw->flags.eeh_busy)
1225 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1226 if (rval != QLA_SUCCESS)
Joe Carnuccioaa615562012-02-09 11:15:40 -08001227 return snprintf(buf, PAGE_SIZE, "\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001228
1229 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1230}
1231
1232static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001233qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1234 char *buf)
1235{
1236 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001237 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001238 uint16_t state[5];
1239
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001240 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001241 ql_log(ql_log_warn, vha, 0x707c,
1242 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001243 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001244 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001245 if (rval != QLA_SUCCESS)
1246 memset(state, -1, sizeof(state));
1247
1248 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1249 state[1], state[2], state[3], state[4]);
1250}
1251
Tony Jonesee959b02008-02-22 00:13:36 +01001252static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1253static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1254static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1255static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1256static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1257static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1258static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1259static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001260static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001261static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1262static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1263 qla2x00_zio_timer_store);
1264static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1265 qla2x00_beacon_store);
1266static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1267 qla2x00_optrom_bios_version_show, NULL);
1268static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1269 qla2x00_optrom_efi_version_show, NULL);
1270static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1271 qla2x00_optrom_fcode_version_show, NULL);
1272static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1273 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001274static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1275 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001276static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1277 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001278static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1279 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001280static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001281static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001282static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1283 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001284static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1285static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1286 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001287static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001288static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001289static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001290
Tony Jonesee959b02008-02-22 00:13:36 +01001291struct device_attribute *qla2x00_host_attrs[] = {
1292 &dev_attr_driver_version,
1293 &dev_attr_fw_version,
1294 &dev_attr_serial_num,
1295 &dev_attr_isp_name,
1296 &dev_attr_isp_id,
1297 &dev_attr_model_name,
1298 &dev_attr_model_desc,
1299 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001300 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001301 &dev_attr_zio,
1302 &dev_attr_zio_timer,
1303 &dev_attr_beacon,
1304 &dev_attr_optrom_bios_version,
1305 &dev_attr_optrom_efi_version,
1306 &dev_attr_optrom_fcode_version,
1307 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001308 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001309 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001310 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001311 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001312 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001313 &dev_attr_vlan_id,
1314 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001315 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001316 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001317 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001318 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001319 NULL,
1320};
1321
8482e1182005-04-17 15:04:54 -05001322/* Host attributes. */
1323
1324static void
1325qla2x00_get_host_port_id(struct Scsi_Host *shost)
1326{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001327 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001328
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001329 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1330 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001331}
1332
1333static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001334qla2x00_get_host_speed(struct Scsi_Host *shost)
1335{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001336 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1337 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001338 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001339
1340 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001341 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001342 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001343 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001344 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001345 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001346 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001347 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001348 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001349 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001350 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001351 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001352 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001353 case PORT_SPEED_10GB:
1354 speed = FC_PORTSPEED_10GBIT;
1355 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001356 case PORT_SPEED_16GB:
1357 speed = FC_PORTSPEED_16GBIT;
1358 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001359 }
1360 fc_host_speed(shost) = speed;
1361}
1362
1363static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001364qla2x00_get_host_port_type(struct Scsi_Host *shost)
1365{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001366 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001367 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1368
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001369 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001370 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1371 return;
1372 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001373 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001374 case ISP_CFG_NL:
1375 port_type = FC_PORTTYPE_LPORT;
1376 break;
1377 case ISP_CFG_FL:
1378 port_type = FC_PORTTYPE_NLPORT;
1379 break;
1380 case ISP_CFG_N:
1381 port_type = FC_PORTTYPE_PTP;
1382 break;
1383 case ISP_CFG_F:
1384 port_type = FC_PORTTYPE_NPORT;
1385 break;
1386 }
1387 fc_host_port_type(shost) = port_type;
1388}
1389
1390static void
8482e1182005-04-17 15:04:54 -05001391qla2x00_get_starget_node_name(struct scsi_target *starget)
1392{
1393 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001394 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001395 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001396 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001397
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001398 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001399 if (fcport->rport &&
1400 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001401 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001402 break;
1403 }
1404 }
1405
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001406 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001407}
1408
1409static void
1410qla2x00_get_starget_port_name(struct scsi_target *starget)
1411{
1412 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001413 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001414 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001415 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001416
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001417 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001418 if (fcport->rport &&
1419 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001420 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001421 break;
1422 }
1423 }
1424
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001425 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001426}
1427
1428static void
1429qla2x00_get_starget_port_id(struct scsi_target *starget)
1430{
1431 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001433 fc_port_t *fcport;
1434 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001435
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001436 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001437 if (fcport->rport &&
1438 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001439 port_id = fcport->d_id.b.domain << 16 |
1440 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1441 break;
1442 }
1443 }
1444
8482e1182005-04-17 15:04:54 -05001445 fc_starget_port_id(starget) = port_id;
1446}
1447
1448static void
8482e1182005-04-17 15:04:54 -05001449qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1450{
8482e1182005-04-17 15:04:54 -05001451 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001452 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001453 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001454 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001455}
1456
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001457static void
1458qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1459{
1460 struct Scsi_Host *host = rport_to_shost(rport);
1461 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001462 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001463
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001464 if (!fcport)
1465 return;
1466
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001467 /* Now that the rport has been deleted, set the fcport state to
1468 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001469 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001470
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001471 /*
1472 * Transport has effectively 'deleted' the rport, clear
1473 * all local references.
1474 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001475 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001476 fcport->rport = fcport->drport = NULL;
1477 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001478 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001479
Andrew Vasquez85880802009-12-15 21:29:46 -08001480 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1481 return;
1482
1483 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001484 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001485 return;
1486 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001487}
1488
1489static void
1490qla2x00_terminate_rport_io(struct fc_rport *rport)
1491{
1492 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1493
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001494 if (!fcport)
1495 return;
1496
Andrew Vasquez85880802009-12-15 21:29:46 -08001497 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1498 return;
1499
Seokmann Jub9b12f72009-03-24 09:08:18 -07001500 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1501 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1502 return;
1503 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001504 /*
1505 * At this point all fcport's software-states are cleared. Perform any
1506 * final cleanup of firmware resources (PCBs and XCBs).
1507 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001508 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezaf11f642012-02-09 11:15:43 -08001509 !test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
1510 if (IS_FWI2_CAPABLE(fcport->vha->hw))
1511 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1512 fcport->loop_id, fcport->d_id.b.domain,
1513 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1514 else
1515 qla2x00_port_logout(fcport->vha, fcport);
1516 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001517}
1518
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001519static int
1520qla2x00_issue_lip(struct Scsi_Host *shost)
1521{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001522 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001523
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001524 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001525 return 0;
1526}
1527
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001528static struct fc_host_statistics *
1529qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1530{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001531 scsi_qla_host_t *vha = shost_priv(shost);
1532 struct qla_hw_data *ha = vha->hw;
1533 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001534 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001535 struct link_statistics *stats;
1536 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001537 struct fc_host_statistics *pfc_host_stat;
1538
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001539 pfc_host_stat = &vha->fc_host_stat;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001540 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1541
Andrew Vasquez85880802009-12-15 21:29:46 -08001542 if (test_bit(UNLOADING, &vha->dpc_flags))
1543 goto done;
1544
1545 if (unlikely(pci_channel_offline(ha->pdev)))
1546 goto done;
1547
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001548 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1549 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001550 ql_log(ql_log_warn, vha, 0x707d,
1551 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001552 goto done;
1553 }
1554 memset(stats, 0, DMA_POOL_SIZE);
1555
1556 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001557 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001558 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1559 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001560 !qla2x00_reset_active(vha) && !ha->dpc_active) {
Andrew Vasquez178779a2007-01-29 10:22:25 -08001561 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001562 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1563 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001564 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001565
1566 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001567 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001568
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001569 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1570 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1571 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1572 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1573 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1574 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1575 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001576 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001577 pfc_host_stat->tx_frames = stats->tx_frames;
1578 pfc_host_stat->rx_frames = stats->rx_frames;
1579 pfc_host_stat->dumped_frames = stats->dumped_frames;
1580 pfc_host_stat->nos_count = stats->nos_rcvd;
1581 }
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001582 pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
1583 pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001584
1585done_free:
1586 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001587done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001588 return pfc_host_stat;
1589}
1590
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001591static void
1592qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1593{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001594 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001595
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001596 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001597}
1598
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001599static void
1600qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1601{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001602 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001603
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001604 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001605}
1606
Andrew Vasquez90991c82006-10-02 12:00:46 -07001607static void
1608qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1609{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001610 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001611 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1612 0xFF, 0xFF, 0xFF, 0xFF};
1613 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001614
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001615 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001616 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001617
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001618 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001619}
1620
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001621static void
1622qla2x00_get_host_port_state(struct Scsi_Host *shost)
1623{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 scsi_qla_host_t *vha = shost_priv(shost);
1625 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001626
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001627 if (!base_vha->flags.online) {
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001628 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001629 return;
1630 }
1631
1632 switch (atomic_read(&base_vha->loop_state)) {
1633 case LOOP_UPDATE:
1634 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1635 break;
1636 case LOOP_DOWN:
1637 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
1638 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1639 else
1640 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1641 break;
1642 case LOOP_DEAD:
1643 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1644 break;
1645 case LOOP_READY:
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001646 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001647 break;
1648 default:
1649 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1650 break;
1651 }
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001652}
1653
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001654static int
1655qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1656{
1657 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001658 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001659 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1660 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001661 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001662 uint16_t options = 0;
1663 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001664 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001665
1666 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1667 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001668 ql_log(ql_log_warn, vha, 0x707e,
1669 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001670 return (ret);
1671 }
1672
1673 vha = qla24xx_create_vhost(fc_vport);
1674 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001675 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001676 return FC_VPORT_FAILED;
1677 }
1678 if (disable) {
1679 atomic_set(&vha->vp_state, VP_OFFLINE);
1680 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1681 } else
1682 atomic_set(&vha->vp_state, VP_FAILED);
1683
1684 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001685 ql_log(ql_log_info, vha, 0x7080,
1686 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001687
1688 /* initialized vport states */
1689 atomic_set(&vha->loop_state, LOOP_DOWN);
1690 vha->vp_err_state= VP_ERR_PORTDWN;
1691 vha->vp_prev_err_state= VP_ERR_UNKWN;
1692 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001693 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1694 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001695 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001696 ql_dbg(ql_dbg_user, vha, 0x7081,
1697 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001698 atomic_set(&vha->loop_state, LOOP_DEAD);
1699 if (!disable)
1700 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1701 }
1702
Arun Easie02587d2011-08-16 11:29:23 -07001703 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001704 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07001705 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07001706 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001707 ql_dbg(ql_dbg_user, vha, 0x7082,
1708 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07001709 if (ql2xenabledif == 1)
1710 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07001711 scsi_host_set_prot(vha->host,
Arun Easi8cb20492011-08-16 11:29:22 -07001712 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001713 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001714 | SHOST_DIF_TYPE3_PROTECTION
1715 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001716 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001717 | SHOST_DIX_TYPE3_PROTECTION);
1718 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1719 } else
1720 vha->flags.difdix_supported = 0;
1721 }
1722
James Bottomleyd139b9b2009-11-05 13:33:12 -06001723 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1724 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001725 ql_dbg(ql_dbg_user, vha, 0x7083,
1726 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001727 goto vport_create_failed_2;
1728 }
1729
1730 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001731 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001732 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1733 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1734 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001736 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001737 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001738
1739 qla24xx_vport_disable(fc_vport, disable);
1740
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001741 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001742 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001743 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1744 "Request queue %p attached with "
1745 "VP[%d], cpu affinity =%d\n",
1746 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001747 goto vport_queue;
1748 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001749 goto vport_queue;
1750 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001751 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1752 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1753 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001754 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001755 qos = ha->npiv_info[cnt].q_qos;
1756 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001757 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001758 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001759
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001760 if (qos) {
1761 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1762 qos);
1763 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001764 ql_log(ql_log_warn, vha, 0x7084,
1765 "Can't create request queue for VP[%d]\n",
1766 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001767 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001768 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1769 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1770 ret, qos, vha->vp_idx);
1771 ql_dbg(ql_dbg_user, vha, 0x7085,
1772 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1773 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001774 req = ha->req_q_map[ret];
1775 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001776 }
1777
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001778vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001779 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001780 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001781
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001782vport_create_failed_2:
1783 qla24xx_disable_vp(vha);
1784 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001785 scsi_host_put(vha->host);
1786 return FC_VPORT_FAILED;
1787}
1788
Adrian Bunka824ebb2008-01-17 09:02:15 -08001789static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001790qla24xx_vport_delete(struct fc_vport *fc_vport)
1791{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001792 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001793 struct qla_hw_data *ha = vha->hw;
1794 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001795
1796 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001797 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001798 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001799
1800 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001801
Arun Easifeafb7b2010-09-03 14:57:00 -07001802 vha->flags.delete_progress = 1;
1803
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001804 fc_remove_host(vha->host);
1805
1806 scsi_remove_host(vha->host);
1807
Arun Easi9f406822011-05-10 11:18:17 -07001808 /* Allow timer to run to drain queued items, when removing vp */
1809 qla24xx_deallocate_vp_id(vha);
1810
Arun Easifeafb7b2010-09-03 14:57:00 -07001811 if (vha->timer_active) {
1812 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001813 ql_dbg(ql_dbg_user, vha, 0x7086,
1814 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001815 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001816
Arun Easifeafb7b2010-09-03 14:57:00 -07001817 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001818 if (ql2xextended_error_logging & ql_dbg_user)
1819 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001820 * the net we have placed below */
1821
1822 BUG_ON(atomic_read(&vha->vref_count));
1823
1824 qla2x00_free_fcports(vha);
1825
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001826 mutex_lock(&ha->vport_lock);
1827 ha->cur_vport_count--;
1828 clear_bit(vha->vp_idx, ha->vp_idx_map);
1829 mutex_unlock(&ha->vport_lock);
1830
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001831 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001832 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001833 ql_log(ql_log_warn, vha, 0x7087,
1834 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001835 }
1836
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001837 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001838 scsi_host_put(vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001839 return 0;
1840}
1841
Adrian Bunka824ebb2008-01-17 09:02:15 -08001842static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001843qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1844{
1845 scsi_qla_host_t *vha = fc_vport->dd_data;
1846
1847 if (disable)
1848 qla24xx_disable_vp(vha);
1849 else
1850 qla24xx_enable_vp(vha);
1851
1852 return 0;
1853}
1854
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001855struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001856
1857 .show_host_node_name = 1,
1858 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001859 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001860 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001861
8482e1182005-04-17 15:04:54 -05001862 .get_host_port_id = qla2x00_get_host_port_id,
1863 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001864 .get_host_speed = qla2x00_get_host_speed,
1865 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001866 .get_host_port_type = qla2x00_get_host_port_type,
1867 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001868 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1869 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001870 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1871 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001872 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1873 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001874 .get_host_port_state = qla2x00_get_host_port_state,
1875 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001876
bdf79622005-04-17 15:06:53 -05001877 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001878 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001879
1880 .get_starget_node_name = qla2x00_get_starget_node_name,
1881 .show_starget_node_name = 1,
1882 .get_starget_port_name = qla2x00_get_starget_port_name,
1883 .show_starget_port_name = 1,
1884 .get_starget_port_id = qla2x00_get_starget_port_id,
1885 .show_starget_port_id = 1,
1886
8482e1182005-04-17 15:04:54 -05001887 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1888 .show_rport_dev_loss_tmo = 1,
1889
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001890 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001891 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1892 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001893 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001894
1895 .vport_create = qla24xx_vport_create,
1896 .vport_disable = qla24xx_vport_disable,
1897 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001898 .bsg_request = qla24xx_bsg_request,
1899 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001900};
1901
1902struct fc_function_template qla2xxx_transport_vport_functions = {
1903
1904 .show_host_node_name = 1,
1905 .show_host_port_name = 1,
1906 .show_host_supported_classes = 1,
1907
1908 .get_host_port_id = qla2x00_get_host_port_id,
1909 .show_host_port_id = 1,
1910 .get_host_speed = qla2x00_get_host_speed,
1911 .show_host_speed = 1,
1912 .get_host_port_type = qla2x00_get_host_port_type,
1913 .show_host_port_type = 1,
1914 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1915 .show_host_symbolic_name = 1,
1916 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1917 .show_host_system_hostname = 1,
1918 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1919 .show_host_fabric_name = 1,
1920 .get_host_port_state = qla2x00_get_host_port_state,
1921 .show_host_port_state = 1,
1922
1923 .dd_fcrport_size = sizeof(struct fc_port *),
1924 .show_rport_supported_classes = 1,
1925
1926 .get_starget_node_name = qla2x00_get_starget_node_name,
1927 .show_starget_node_name = 1,
1928 .get_starget_port_name = qla2x00_get_starget_port_name,
1929 .show_starget_port_name = 1,
1930 .get_starget_port_id = qla2x00_get_starget_port_id,
1931 .show_starget_port_id = 1,
1932
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001933 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1934 .show_rport_dev_loss_tmo = 1,
1935
1936 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001937 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1938 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001939 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001940 .bsg_request = qla24xx_bsg_request,
1941 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05001942};
1943
8482e1182005-04-17 15:04:54 -05001944void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001945qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05001946{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001947 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001948 u32 speed = FC_PORTSPEED_UNKNOWN;
1949
Mike Christied2b5f102010-09-15 16:52:30 -05001950 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001951 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1952 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1953 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1954 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1955 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001956
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001957 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001958 speed = FC_PORTSPEED_10GBIT;
Giridhar Malavali6f606d22012-05-15 14:34:18 -04001959 else if (IS_QLA2031(ha))
1960 speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
1961 FC_PORTSPEED_4GBIT;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001962 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001963 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1964 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001965 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001966 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1967 FC_PORTSPEED_1GBIT;
1968 else if (IS_QLA23XX(ha))
1969 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1970 else
1971 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001972 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05001973}