blob: da804f487f21871a8e68cf784069afc91db56252 [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"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
8482e1182005-04-17 15:04:54 -05009
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070010#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050011#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090013#include <linux/delay.h>
8482e1182005-04-17 15:04:54 -050014
Adrian Bunka824ebb2008-01-17 09:02:15 -080015static int qla24xx_vport_disable(struct fc_vport *, bool);
Giridhar Malavali6e980162010-03-19 17:03:58 -070016
8482e1182005-04-17 15:04:54 -050017/* SYSFS attributes --------------------------------------------------------- */
18
19static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070020qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080021 struct bin_attribute *bin_attr,
22 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050023{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080024 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050025 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080026 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali08de2842011-08-16 11:31:44 -070027 int rval = 0;
8482e1182005-04-17 15:04:54 -050028
29 if (ha->fw_dump_reading == 0)
30 return 0;
8482e1182005-04-17 15:04:54 -050031
Giridhar Malavali08de2842011-08-16 11:31:44 -070032 if (IS_QLA82XX(ha)) {
33 if (off < ha->md_template_size) {
34 rval = memory_read_from_buffer(buf, count,
35 &off, ha->md_tmplt_hdr, ha->md_template_size);
36 return rval;
37 }
38 off -= ha->md_template_size;
39 rval = memory_read_from_buffer(buf, count,
40 &off, ha->md_dump, ha->md_dump_size);
41 return rval;
42 } else
43 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
Akinobu Mitab3dc9082008-07-24 08:31:47 -070044 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050045}
46
47static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070048qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080049 struct bin_attribute *bin_attr,
50 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050051{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080052 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050053 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080054 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050055 int reading;
8482e1182005-04-17 15:04:54 -050056
57 if (off != 0)
58 return (0);
59
60 reading = simple_strtol(buf, NULL, 10);
61 switch (reading) {
62 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070063 if (!ha->fw_dump_reading)
64 break;
8482e1182005-04-17 15:04:54 -050065
Saurav Kashyap7c3df132011-07-14 12:00:13 -070066 ql_log(ql_log_info, vha, 0x705d,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080067 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070068
Giridhar Malavali08de2842011-08-16 11:31:44 -070069 if (IS_QLA82XX(vha->hw)) {
70 qla82xx_md_free(vha);
71 qla82xx_md_prep(vha);
72 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070073 ha->fw_dump_reading = 0;
74 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050075 break;
76 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070077 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050078 ha->fw_dump_reading = 1;
79
Saurav Kashyap7c3df132011-07-14 12:00:13 -070080 ql_log(ql_log_info, vha, 0x705e,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070081 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080082 vha->host_no);
8482e1182005-04-17 15:04:54 -050083 }
84 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070085 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080086 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070087 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070088 case 3:
Giridhar Malavali08de2842011-08-16 11:31:44 -070089 if (IS_QLA82XX(ha)) {
90 qla82xx_idc_lock(ha);
91 qla82xx_set_reset_owner(vha);
92 qla82xx_idc_unlock(ha);
93 } else
94 qla2x00_system_error(vha);
95 break;
96 case 4:
97 if (IS_QLA82XX(ha)) {
98 if (ha->md_tmplt_hdr)
99 ql_dbg(ql_dbg_user, vha, 0x705b,
100 "MiniDump supported with this firmware.\n");
101 else
102 ql_dbg(ql_dbg_user, vha, 0x709d,
103 "MiniDump not supported with this firmware.\n");
104 }
105 break;
106 case 5:
107 if (IS_QLA82XX(ha))
108 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez68af0812008-05-12 22:21:13 -0700109 break;
8482e1182005-04-17 15:04:54 -0500110 }
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800111 return count;
8482e1182005-04-17 15:04:54 -0500112}
113
114static struct bin_attribute sysfs_fw_dump_attr = {
115 .attr = {
116 .name = "fw_dump",
117 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500118 },
119 .size = 0,
120 .read = qla2x00_sysfs_read_fw_dump,
121 .write = qla2x00_sysfs_write_fw_dump,
122};
123
124static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700125qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800126 struct bin_attribute *bin_attr,
127 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500128{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800129 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500130 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800131 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500132
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700133 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500134 return 0;
135
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700136 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700137 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700138 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700139 return memory_read_from_buffer(buf, count, &off, ha->nvram,
140 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500141}
142
143static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700144qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800145 struct bin_attribute *bin_attr,
146 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500147{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800148 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500149 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800150 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500151 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500152
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700153 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
154 !ha->isp_ops->write_nvram)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700155 return -EINVAL;
8482e1182005-04-17 15:04:54 -0500156
157 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700158 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700159 uint32_t *iter;
160 uint32_t chksum;
161
162 iter = (uint32_t *)buf;
163 chksum = 0;
164 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
165 chksum += le32_to_cpu(*iter++);
166 chksum = ~chksum + 1;
167 *iter = cpu_to_le32(chksum);
168 } else {
169 uint8_t *iter;
170 uint8_t chksum;
171
172 iter = (uint8_t *)buf;
173 chksum = 0;
174 for (cnt = 0; cnt < count - 1; cnt++)
175 chksum += *iter++;
176 chksum = ~chksum + 1;
177 *iter = chksum;
178 }
8482e1182005-04-17 15:04:54 -0500179
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700180 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700181 ql_log(ql_log_warn, vha, 0x705f,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700182 "HBA not online, failing NVRAM update.\n");
183 return -EAGAIN;
184 }
185
8482e1182005-04-17 15:04:54 -0500186 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800187 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
188 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700189 count);
8482e1182005-04-17 15:04:54 -0500190
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700191 ql_dbg(ql_dbg_user, vha, 0x7060,
192 "Setting ISP_ABORT_NEEDED\n");
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700193 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800194 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700195 qla2xxx_wake_dpc(vha);
196 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800197
Joe Carnucciob668ae32011-08-16 11:31:53 -0700198 return count;
8482e1182005-04-17 15:04:54 -0500199}
200
201static struct bin_attribute sysfs_nvram_attr = {
202 .attr = {
203 .name = "nvram",
204 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500205 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800206 .size = 512,
8482e1182005-04-17 15:04:54 -0500207 .read = qla2x00_sysfs_read_nvram,
208 .write = qla2x00_sysfs_write_nvram,
209};
210
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800211static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700212qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800213 struct bin_attribute *bin_attr,
214 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800215{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800216 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800217 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800218 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800219
220 if (ha->optrom_state != QLA_SREADING)
221 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800222
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700223 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
224 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800225}
226
227static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700228qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800229 struct bin_attribute *bin_attr,
230 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800231{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800232 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800233 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800234 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800235
236 if (ha->optrom_state != QLA_SWRITING)
237 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700238 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800239 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700240 if (off + count > ha->optrom_region_size)
241 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800242
243 memcpy(&ha->optrom_buffer[off], buf, count);
244
245 return count;
246}
247
248static struct bin_attribute sysfs_optrom_attr = {
249 .attr = {
250 .name = "optrom",
251 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800252 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700253 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800254 .read = qla2x00_sysfs_read_optrom,
255 .write = qla2x00_sysfs_write_optrom,
256};
257
258static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700259qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800260 struct bin_attribute *bin_attr,
261 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800262{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800263 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800264 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800265 struct qla_hw_data *ha = vha->hw;
266
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700267 uint32_t start = 0;
268 uint32_t size = ha->optrom_size;
269 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800270
271 if (off)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700272 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800273
Andrew Vasquez85880802009-12-15 21:29:46 -0800274 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700275 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800276
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700277 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
278 return -EINVAL;
279 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800280 return -EINVAL;
281
282 switch (val) {
283 case 0:
284 if (ha->optrom_state != QLA_SREADING &&
285 ha->optrom_state != QLA_SWRITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700286 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800287
288 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700289
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700290 ql_dbg(ql_dbg_user, vha, 0x7061,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700291 "Freeing flash region allocation -- 0x%x bytes.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700292 ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700293
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800294 vfree(ha->optrom_buffer);
295 ha->optrom_buffer = NULL;
296 break;
297 case 1:
298 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700299 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800300
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700301 ha->optrom_region_start = start;
302 ha->optrom_region_size = start + size > ha->optrom_size ?
303 ha->optrom_size - start : size;
304
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800305 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700306 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800307 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700308 ql_log(ql_log_warn, vha, 0x7062,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800309 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700310 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800311
312 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700313 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800314 }
315
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700316 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700317 ql_log(ql_log_warn, vha, 0x7063,
318 "HBA not online, failing NVRAM update.\n");
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700319 return -EAGAIN;
320 }
321
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 ql_dbg(ql_dbg_user, vha, 0x7064,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700323 "Reading flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700324 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700325
326 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800327 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700328 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800329 break;
330 case 2:
331 if (ha->optrom_state != QLA_SWAITING)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700332 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800333
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700334 /*
335 * We need to be more restrictive on which FLASH regions are
336 * allowed to be updated via user-space. Regions accessible
337 * via this method include:
338 *
339 * ISP21xx/ISP22xx/ISP23xx type boards:
340 *
341 * 0x000000 -> 0x020000 -- Boot code.
342 *
343 * ISP2322/ISP24xx type boards:
344 *
345 * 0x000000 -> 0x07ffff -- Boot code.
346 * 0x080000 -> 0x0fffff -- Firmware.
347 *
348 * ISP25xx type boards:
349 *
350 * 0x000000 -> 0x07ffff -- Boot code.
351 * 0x080000 -> 0x0fffff -- Firmware.
352 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
353 */
354 valid = 0;
355 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
356 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700357 else if (start == (ha->flt_region_boot * 4) ||
358 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700359 valid = 1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800360 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
361 || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700362 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700363 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700364 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700365 "Invalid start region 0x%x/0x%x.\n", start, size);
366 return -EINVAL;
367 }
368
369 ha->optrom_region_start = start;
370 ha->optrom_region_size = start + size > ha->optrom_size ?
371 ha->optrom_size - start : size;
372
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800373 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700374 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800375 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800377 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700378 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800379
380 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob668ae32011-08-16 11:31:53 -0700381 return -ENOMEM;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800382 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700383
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700384 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700385 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700386 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700387
388 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800389 break;
390 case 3:
391 if (ha->optrom_state != QLA_SWRITING)
Joe Carnuccio71dfe9e2011-11-18 09:03:13 -0800392 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800393
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700394 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700395 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700396 "HBA not online, failing flash update.\n");
397 return -EAGAIN;
398 }
399
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700400 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700401 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700402 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700403
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800404 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700405 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800406 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700407 default:
Joe Carnucciob668ae32011-08-16 11:31:53 -0700408 return -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800409 }
410 return count;
411}
412
413static struct bin_attribute sysfs_optrom_ctl_attr = {
414 .attr = {
415 .name = "optrom_ctl",
416 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800417 },
418 .size = 0,
419 .write = qla2x00_sysfs_write_optrom_ctl,
420};
421
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800422static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700423qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800424 struct bin_attribute *bin_attr,
425 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800426{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800427 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800428 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800429 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800430
Andrew Vasquez85880802009-12-15 21:29:46 -0800431 if (unlikely(pci_channel_offline(ha->pdev)))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700432 return -EAGAIN;
Andrew Vasquez85880802009-12-15 21:29:46 -0800433
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700434 if (!capable(CAP_SYS_ADMIN))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700435 return -EINVAL;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800436
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700437 if (IS_NOCACHE_VPD_TYPE(ha))
438 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
439 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700440 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800441}
442
443static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700444qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800445 struct bin_attribute *bin_attr,
446 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800447{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800448 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800449 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800450 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700451 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800452
Andrew Vasquez85880802009-12-15 21:29:46 -0800453 if (unlikely(pci_channel_offline(ha->pdev)))
454 return 0;
455
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700456 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
457 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800458 return 0;
459
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700460 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700461 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700462 "HBA not online, failing VPD update.\n");
463 return -EAGAIN;
464 }
465
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800466 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800467 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
468 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800469
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700470 /* Update flash version information for 4Gb & above. */
471 if (!IS_FWI2_CAPABLE(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700472 return -EINVAL;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700473
474 tmp_data = vmalloc(256);
475 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700476 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700477 "Unable to allocate memory for VPD information update.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700478 return -ENOMEM;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700479 }
480 ha->isp_ops->get_flash_version(vha, tmp_data);
481 vfree(tmp_data);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700482
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800483 return count;
484}
485
486static struct bin_attribute sysfs_vpd_attr = {
487 .attr = {
488 .name = "vpd",
489 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800490 },
491 .size = 0,
492 .read = qla2x00_sysfs_read_vpd,
493 .write = qla2x00_sysfs_write_vpd,
494};
495
Andrew Vasquez88729e52006-06-23 16:10:50 -0700496static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700497qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800498 struct bin_attribute *bin_attr,
499 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700500{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800501 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700502 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800503 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700504 uint16_t iter, addr, offset;
505 int rval;
506
507 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
508 return 0;
509
Andrew Vasqueze8711082008-01-31 12:33:48 -0800510 if (ha->sfp_data)
511 goto do_read;
512
513 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
514 &ha->sfp_data_dma);
515 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700516 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800517 "Unable to allocate memory for SFP read-data.\n");
518 return 0;
519 }
520
521do_read:
522 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700523 addr = 0xa0;
524 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
525 iter++, offset += SFP_BLOCK_SIZE) {
526 if (iter == 4) {
527 /* Skip to next device address. */
528 addr = 0xa2;
529 offset = 0;
530 }
531
Joe Carnuccio6766df92011-05-10 11:30:15 -0700532 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
533 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700534 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700535 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700536 "Unable to read SFP data (%x/%x/%x).\n", rval,
537 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700538
Joe Carnucciob668ae32011-08-16 11:31:53 -0700539 return -EIO;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700540 }
541 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
542 buf += SFP_BLOCK_SIZE;
543 }
544
545 return count;
546}
547
548static struct bin_attribute sysfs_sfp_attr = {
549 .attr = {
550 .name = "sfp",
551 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700552 },
553 .size = SFP_DEV_SIZE * 2,
554 .read = qla2x00_sysfs_read_sfp,
555};
556
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700557static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700558qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700559 struct bin_attribute *bin_attr,
560 char *buf, loff_t off, size_t count)
561{
562 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
563 struct device, kobj)));
564 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700565 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700566 int type;
567
568 if (off != 0)
Joe Carnucciob668ae32011-08-16 11:31:53 -0700569 return -EINVAL;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700570
571 type = simple_strtol(buf, NULL, 10);
572 switch (type) {
573 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700574 ql_log(ql_log_info, vha, 0x706e,
575 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700576
577 scsi_block_requests(vha->host);
578 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavali08de2842011-08-16 11:31:44 -0700579 if (IS_QLA82XX(ha)) {
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -0400580 ha->flags.isp82xx_no_md_cap = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700581 qla82xx_idc_lock(ha);
582 qla82xx_set_reset_owner(vha);
583 qla82xx_idc_unlock(ha);
584 }
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700585 qla2xxx_wake_dpc(vha);
586 qla2x00_wait_for_chip_reset(vha);
587 scsi_unblock_requests(vha->host);
588 break;
589 case 0x2025d:
Nigel Kirklandf863f602012-05-15 14:34:19 -0400590 if (!IS_QLA81XX(ha) || !IS_QLA8031(ha))
Joe Carnucciob668ae32011-08-16 11:31:53 -0700591 return -EPERM;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700592
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700593 ql_log(ql_log_info, vha, 0x706f,
594 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700595
596 /* Make sure FC side is not in reset */
597 qla2x00_wait_for_hba_online(vha);
598
599 /* Issue MPI reset */
600 scsi_block_requests(vha->host);
601 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700602 ql_log(ql_log_warn, vha, 0x7070,
603 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700604 scsi_unblock_requests(vha->host);
605 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700606 case 0x2025e:
607 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700608 ql_log(ql_log_info, vha, 0x7071,
609 "FCoE ctx reset no supported.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700610 return -EPERM;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700611 }
612
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700613 ql_log(ql_log_info, vha, 0x7072,
614 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700615 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
616 qla2xxx_wake_dpc(vha);
617 qla2x00_wait_for_fcoe_ctx_reset(vha);
618 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700619 }
620 return count;
621}
622
623static struct bin_attribute sysfs_reset_attr = {
624 .attr = {
625 .name = "reset",
626 .mode = S_IWUSR,
627 },
628 .size = 0,
629 .write = qla2x00_sysfs_write_reset,
630};
631
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700632static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700633qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700634 struct bin_attribute *bin_attr,
635 char *buf, loff_t off, size_t count)
636{
637 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
638 struct device, kobj)));
639 struct qla_hw_data *ha = vha->hw;
640 int rval;
641 uint16_t actual_size;
642
643 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
644 return 0;
645
646 if (ha->xgmac_data)
647 goto do_read;
648
649 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
650 &ha->xgmac_data_dma, GFP_KERNEL);
651 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700652 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700653 "Unable to allocate memory for XGMAC read-data.\n");
654 return 0;
655 }
656
657do_read:
658 actual_size = 0;
659 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
660
661 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
662 XGMAC_DATA_SIZE, &actual_size);
663 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700664 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700665 "Unable to read XGMAC data (%x).\n", rval);
666 count = 0;
667 }
668
669 count = actual_size > count ? count: actual_size;
670 memcpy(buf, ha->xgmac_data, count);
671
672 return count;
673}
674
675static struct bin_attribute sysfs_xgmac_stats_attr = {
676 .attr = {
677 .name = "xgmac_stats",
678 .mode = S_IRUSR,
679 },
680 .size = 0,
681 .read = qla2x00_sysfs_read_xgmac_stats,
682};
683
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700684static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700685qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700686 struct bin_attribute *bin_attr,
687 char *buf, loff_t off, size_t count)
688{
689 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
690 struct device, kobj)));
691 struct qla_hw_data *ha = vha->hw;
692 int rval;
693 uint16_t actual_size;
694
695 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
696 return 0;
697
698 if (ha->dcbx_tlv)
699 goto do_read;
700
701 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
702 &ha->dcbx_tlv_dma, GFP_KERNEL);
703 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700704 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700705 "Unable to allocate memory for DCBX TLV read-data.\n");
Joe Carnucciob668ae32011-08-16 11:31:53 -0700706 return -ENOMEM;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700707 }
708
709do_read:
710 actual_size = 0;
711 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
712
713 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
714 DCBX_TLV_DATA_SIZE);
715 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700716 ql_log(ql_log_warn, vha, 0x7079,
717 "Unable to read DCBX TLV (%x).\n", rval);
Joe Carnucciob668ae32011-08-16 11:31:53 -0700718 return -EIO;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700719 }
720
721 memcpy(buf, ha->dcbx_tlv, count);
722
723 return count;
724}
725
726static struct bin_attribute sysfs_dcbx_tlv_attr = {
727 .attr = {
728 .name = "dcbx_tlv",
729 .mode = S_IRUSR,
730 },
731 .size = 0,
732 .read = qla2x00_sysfs_read_dcbx_tlv,
733};
734
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700735static struct sysfs_entry {
736 char *name;
737 struct bin_attribute *attr;
738 int is4GBp_only;
739} bin_file_entries[] = {
740 { "fw_dump", &sysfs_fw_dump_attr, },
741 { "nvram", &sysfs_nvram_attr, },
742 { "optrom", &sysfs_optrom_attr, },
743 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
744 { "vpd", &sysfs_vpd_attr, 1 },
745 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700746 { "reset", &sysfs_reset_attr, },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700747 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700748 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800749 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700750};
751
8482e1182005-04-17 15:04:54 -0500752void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800753qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500754{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800755 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700756 struct sysfs_entry *iter;
757 int ret;
8482e1182005-04-17 15:04:54 -0500758
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700759 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800760 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700761 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700762 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
763 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800764 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700765 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700766
767 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
768 iter->attr);
769 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700770 ql_log(ql_log_warn, vha, 0x00f3,
771 "Unable to create sysfs %s binary attribute (%d).\n",
772 iter->name, ret);
773 else
774 ql_dbg(ql_dbg_init, vha, 0x00f4,
775 "Successfully created sysfs %s binary attribure.\n",
776 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700777 }
8482e1182005-04-17 15:04:54 -0500778}
779
780void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800781qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500782{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800783 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700784 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800785 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500786
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700787 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700788 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700789 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700790 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
791 continue;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800792 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700793 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700794
Andrew Vasquez7914d002006-06-23 16:10:55 -0700795 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700796 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700797 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800798
799 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800800 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500801}
802
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700803/* Scsi_Host attributes. */
804
805static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100806qla2x00_drvr_version_show(struct device *dev,
807 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700808{
809 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
810}
811
812static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100813qla2x00_fw_version_show(struct device *dev,
814 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700815{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800816 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
817 struct qla_hw_data *ha = vha->hw;
818 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700819
820 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800821 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700822}
823
824static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100825qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
826 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700827{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800828 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
829 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700830 uint32_t sn;
831
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700832 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800833 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700834 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
835 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700836
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700837 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
838 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
839 sn % 100000);
840}
841
842static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100843qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
844 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700845{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800846 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
847 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700848}
849
850static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100851qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
852 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700853{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800854 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
855 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700856 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
857 ha->product_id[0], ha->product_id[1], ha->product_id[2],
858 ha->product_id[3]);
859}
860
861static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100862qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
863 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700864{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800865 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
866 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700867}
868
869static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100870qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
871 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700872{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800873 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700874 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800875 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700876}
877
878static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100879qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
880 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700881{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800882 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700883 char pci_info[30];
884
885 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800886 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700887}
888
889static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100890qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
891 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700892{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800893 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
894 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700895 int len = 0;
896
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800897 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -0700898 atomic_read(&vha->loop_state) == LOOP_DEAD ||
899 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700900 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800901 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -0800902 qla2x00_reset_active(vha))
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700903 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
904 else {
905 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
906
907 switch (ha->current_topology) {
908 case ISP_CFG_NL:
909 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
910 break;
911 case ISP_CFG_FL:
912 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
913 break;
914 case ISP_CFG_N:
915 len += snprintf(buf + len, PAGE_SIZE-len,
916 "N_Port to N_Port\n");
917 break;
918 case ISP_CFG_F:
919 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
920 break;
921 default:
922 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
923 break;
924 }
925 }
926 return len;
927}
928
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700929static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100930qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
931 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700932{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800933 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700934 int len = 0;
935
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800936 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700937 case QLA_ZIO_MODE_6:
938 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
939 break;
940 case QLA_ZIO_DISABLED:
941 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
942 break;
943 }
944 return len;
945}
946
947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100948qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
949 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700950{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800951 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
952 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700953 int val = 0;
954 uint16_t zio_mode;
955
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800956 if (!IS_ZIO_SUPPORTED(ha))
957 return -ENOTSUPP;
958
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700959 if (sscanf(buf, "%d", &val) != 1)
960 return -EINVAL;
961
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800962 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700963 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800964 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700965 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700966
967 /* Update per-hba values and queue a reset. */
968 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
969 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800970 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700971 }
972 return strlen(buf);
973}
974
975static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100976qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
977 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700978{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800979 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700980
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800981 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700982}
983
984static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100985qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
986 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700987{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800988 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700989 int val = 0;
990 uint16_t zio_timer;
991
992 if (sscanf(buf, "%d", &val) != 1)
993 return -EINVAL;
994 if (val > 25500 || val < 100)
995 return -ERANGE;
996
997 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800998 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700999
1000 return strlen(buf);
1001}
1002
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001003static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001004qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1005 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001006{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001008 int len = 0;
1009
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001010 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001011 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1012 else
1013 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1014 return len;
1015}
1016
1017static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001018qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1019 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001020{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001021 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1022 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001023 int val = 0;
1024 int rval;
1025
1026 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1027 return -EPERM;
1028
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001029 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001030 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001031 "Abort ISP active -- ignoring beacon request.\n");
1032 return -EBUSY;
1033 }
1034
1035 if (sscanf(buf, "%d", &val) != 1)
1036 return -EINVAL;
1037
1038 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001039 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001040 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001041 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001042
1043 if (rval != QLA_SUCCESS)
1044 count = 0;
1045
1046 return count;
1047}
1048
Andrew Vasquez30c47662007-01-29 10:22:21 -08001049static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001050qla2x00_optrom_bios_version_show(struct device *dev,
1051 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001052{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001053 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1054 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001055 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1056 ha->bios_revision[0]);
1057}
1058
1059static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001060qla2x00_optrom_efi_version_show(struct device *dev,
1061 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001062{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001063 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1064 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001065 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1066 ha->efi_revision[0]);
1067}
1068
1069static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001070qla2x00_optrom_fcode_version_show(struct device *dev,
1071 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001072{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001073 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1074 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001075 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1076 ha->fcode_revision[0]);
1077}
1078
1079static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001080qla2x00_optrom_fw_version_show(struct device *dev,
1081 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001082{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001083 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1084 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001085 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1086 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1087 ha->fw_revision[3]);
1088}
1089
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001090static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001091qla2x00_optrom_gold_fw_version_show(struct device *dev,
1092 struct device_attribute *attr, char *buf)
1093{
1094 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1095 struct qla_hw_data *ha = vha->hw;
1096
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001097 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001098 return snprintf(buf, PAGE_SIZE, "\n");
1099
1100 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1101 ha->gold_fw_version[0], ha->gold_fw_version[1],
1102 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1103}
1104
1105static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001106qla2x00_total_isp_aborts_show(struct device *dev,
1107 struct device_attribute *attr, char *buf)
1108{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001109 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001110 return snprintf(buf, PAGE_SIZE, "%d\n",
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001111 vha->qla_stats.total_isp_aborts);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001112}
1113
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001114static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001115qla24xx_84xx_fw_version_show(struct device *dev,
1116 struct device_attribute *attr, char *buf)
1117{
1118 int rval = QLA_SUCCESS;
1119 uint16_t status[2] = {0, 0};
1120 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1121 struct qla_hw_data *ha = vha->hw;
1122
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001123 if (!IS_QLA84XX(ha))
1124 return snprintf(buf, PAGE_SIZE, "\n");
1125
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001126 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001127 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001128
1129 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1130 return snprintf(buf, PAGE_SIZE, "%u\n",
1131 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001132
1133 return snprintf(buf, PAGE_SIZE, "\n");
1134}
1135
1136static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001137qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1138 char *buf)
1139{
1140 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1141 struct qla_hw_data *ha = vha->hw;
1142
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001143 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001144 return snprintf(buf, PAGE_SIZE, "\n");
1145
Andrew Vasquez55a96152009-03-24 09:08:03 -07001146 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001147 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001148 ha->mpi_capabilities);
1149}
1150
1151static ssize_t
1152qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1153 char *buf)
1154{
1155 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1156 struct qla_hw_data *ha = vha->hw;
1157
Nigel Kirklandf863f602012-05-15 14:34:19 -04001158 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001159 return snprintf(buf, PAGE_SIZE, "\n");
1160
1161 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1162 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001163}
1164
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001165static ssize_t
1166qla2x00_flash_block_size_show(struct device *dev,
1167 struct device_attribute *attr, char *buf)
1168{
1169 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1170 struct qla_hw_data *ha = vha->hw;
1171
1172 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1173}
1174
Andrew Vasquezbad70012009-04-06 22:33:38 -07001175static ssize_t
1176qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1177 char *buf)
1178{
1179 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1180
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001181 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001182 return snprintf(buf, PAGE_SIZE, "\n");
1183
1184 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1185}
1186
1187static ssize_t
1188qla2x00_vn_port_mac_address_show(struct device *dev,
1189 struct device_attribute *attr, char *buf)
1190{
1191 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1192
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001193 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001194 return snprintf(buf, PAGE_SIZE, "\n");
1195
1196 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1197 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1198 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1199 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1200}
1201
Andrew Vasquez7f774022009-06-03 09:55:12 -07001202static ssize_t
1203qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1204 char *buf)
1205{
1206 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1207
1208 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1209}
1210
Andrew Vasquez656e8912009-06-03 09:55:29 -07001211static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001212qla2x00_thermal_temp_show(struct device *dev,
1213 struct device_attribute *attr, char *buf)
1214{
1215 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1216 int rval = QLA_FUNCTION_FAILED;
1217 uint16_t temp, frac;
1218
1219 if (!vha->hw->flags.thermal_supported)
1220 return snprintf(buf, PAGE_SIZE, "\n");
1221
1222 temp = frac = 0;
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001223 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001224 ql_log(ql_log_warn, vha, 0x707b,
1225 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001226 else if (!vha->hw->flags.eeh_busy)
1227 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1228 if (rval != QLA_SUCCESS)
Joe Carnuccioaa615562012-02-09 11:15:40 -08001229 return snprintf(buf, PAGE_SIZE, "\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001230
1231 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1232}
1233
1234static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001235qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1236 char *buf)
1237{
1238 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001239 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001240 uint16_t state[5];
1241
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001242 if (qla2x00_reset_active(vha))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_log(ql_log_warn, vha, 0x707c,
1244 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001245 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001246 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001247 if (rval != QLA_SUCCESS)
1248 memset(state, -1, sizeof(state));
1249
1250 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1251 state[1], state[2], state[3], state[4]);
1252}
1253
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001254static ssize_t
1255qla2x00_diag_requests_show(struct device *dev,
1256 struct device_attribute *attr, char *buf)
1257{
1258 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1259
1260 if (!IS_BIDI_CAPABLE(vha->hw))
1261 return snprintf(buf, PAGE_SIZE, "\n");
1262
1263 return snprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1264}
1265
1266static ssize_t
1267qla2x00_diag_megabytes_show(struct device *dev,
1268 struct device_attribute *attr, char *buf)
1269{
1270 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1271
1272 if (!IS_BIDI_CAPABLE(vha->hw))
1273 return snprintf(buf, PAGE_SIZE, "\n");
1274
1275 return snprintf(buf, PAGE_SIZE, "%llu\n",
1276 vha->bidi_stats.transfer_bytes >> 20);
1277}
1278
Harish Zunjarrao40129a42012-08-22 14:21:02 -04001279static ssize_t
1280qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1281 char *buf)
1282{
1283 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1284 struct qla_hw_data *ha = vha->hw;
1285 uint32_t size;
1286
1287 if (!ha->fw_dumped)
1288 size = 0;
1289 else if (IS_QLA82XX(ha))
1290 size = ha->md_template_size + ha->md_dump_size;
1291 else
1292 size = ha->fw_dump_len;
1293
1294 return snprintf(buf, PAGE_SIZE, "%d\n", size);
1295}
1296
Tony Jonesee959b02008-02-22 00:13:36 +01001297static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1298static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1299static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1300static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1301static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1302static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1303static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1304static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001305static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001306static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1307static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1308 qla2x00_zio_timer_store);
1309static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1310 qla2x00_beacon_store);
1311static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1312 qla2x00_optrom_bios_version_show, NULL);
1313static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1314 qla2x00_optrom_efi_version_show, NULL);
1315static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1316 qla2x00_optrom_fcode_version_show, NULL);
1317static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1318 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001319static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1320 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001321static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1322 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001323static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1324 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001325static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001326static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001327static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1328 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001329static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1330static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1331 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001332static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001333static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001334static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001335static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
1336static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
Harish Zunjarrao40129a42012-08-22 14:21:02 -04001337static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001338
Tony Jonesee959b02008-02-22 00:13:36 +01001339struct device_attribute *qla2x00_host_attrs[] = {
1340 &dev_attr_driver_version,
1341 &dev_attr_fw_version,
1342 &dev_attr_serial_num,
1343 &dev_attr_isp_name,
1344 &dev_attr_isp_id,
1345 &dev_attr_model_name,
1346 &dev_attr_model_desc,
1347 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001348 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001349 &dev_attr_zio,
1350 &dev_attr_zio_timer,
1351 &dev_attr_beacon,
1352 &dev_attr_optrom_bios_version,
1353 &dev_attr_optrom_efi_version,
1354 &dev_attr_optrom_fcode_version,
1355 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001356 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001357 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001358 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001359 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001360 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001361 &dev_attr_vlan_id,
1362 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001363 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001364 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001365 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001366 &dev_attr_thermal_temp,
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001367 &dev_attr_diag_requests,
1368 &dev_attr_diag_megabytes,
Harish Zunjarrao40129a42012-08-22 14:21:02 -04001369 &dev_attr_fw_dump_size,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001370 NULL,
1371};
1372
8482e1182005-04-17 15:04:54 -05001373/* Host attributes. */
1374
1375static void
1376qla2x00_get_host_port_id(struct Scsi_Host *shost)
1377{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001378 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001379
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001380 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1381 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001382}
1383
1384static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001385qla2x00_get_host_speed(struct Scsi_Host *shost)
1386{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001387 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1388 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001389 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001390
1391 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001392 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001393 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001394 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001395 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001396 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001397 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001398 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001399 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001400 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001401 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001402 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001403 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001404 case PORT_SPEED_10GB:
1405 speed = FC_PORTSPEED_10GBIT;
1406 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001407 case PORT_SPEED_16GB:
1408 speed = FC_PORTSPEED_16GBIT;
1409 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001410 }
1411 fc_host_speed(shost) = speed;
1412}
1413
1414static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001415qla2x00_get_host_port_type(struct Scsi_Host *shost)
1416{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001417 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001418 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1419
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001420 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001421 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1422 return;
1423 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001424 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001425 case ISP_CFG_NL:
1426 port_type = FC_PORTTYPE_LPORT;
1427 break;
1428 case ISP_CFG_FL:
1429 port_type = FC_PORTTYPE_NLPORT;
1430 break;
1431 case ISP_CFG_N:
1432 port_type = FC_PORTTYPE_PTP;
1433 break;
1434 case ISP_CFG_F:
1435 port_type = FC_PORTTYPE_NPORT;
1436 break;
1437 }
1438 fc_host_port_type(shost) = port_type;
1439}
1440
1441static void
8482e1182005-04-17 15:04:54 -05001442qla2x00_get_starget_node_name(struct scsi_target *starget)
1443{
1444 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001445 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001446 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001447 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001448
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001449 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001450 if (fcport->rport &&
1451 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001452 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001453 break;
1454 }
1455 }
1456
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001457 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001458}
1459
1460static void
1461qla2x00_get_starget_port_name(struct scsi_target *starget)
1462{
1463 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001464 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001465 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001466 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001467
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001468 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001469 if (fcport->rport &&
1470 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001471 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001472 break;
1473 }
1474 }
1475
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001476 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001477}
1478
1479static void
1480qla2x00_get_starget_port_id(struct scsi_target *starget)
1481{
1482 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001483 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001484 fc_port_t *fcport;
1485 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001486
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001487 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001488 if (fcport->rport &&
1489 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001490 port_id = fcport->d_id.b.domain << 16 |
1491 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1492 break;
1493 }
1494 }
1495
8482e1182005-04-17 15:04:54 -05001496 fc_starget_port_id(starget) = port_id;
1497}
1498
1499static void
8482e1182005-04-17 15:04:54 -05001500qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1501{
8482e1182005-04-17 15:04:54 -05001502 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001503 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001504 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001505 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001506}
1507
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001508static void
1509qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1510{
1511 struct Scsi_Host *host = rport_to_shost(rport);
1512 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001513 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001514
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001515 if (!fcport)
1516 return;
1517
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001518 /* Now that the rport has been deleted, set the fcport state to
1519 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001520 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001521
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001522 /*
1523 * Transport has effectively 'deleted' the rport, clear
1524 * all local references.
1525 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001526 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001527 fcport->rport = fcport->drport = NULL;
1528 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001529 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001530
Andrew Vasquez85880802009-12-15 21:29:46 -08001531 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1532 return;
1533
1534 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001535 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001536 return;
1537 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001538}
1539
1540static void
1541qla2x00_terminate_rport_io(struct fc_rport *rport)
1542{
1543 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1544
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001545 if (!fcport)
1546 return;
1547
Andrew Vasquez85880802009-12-15 21:29:46 -08001548 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1549 return;
1550
Seokmann Jub9b12f72009-03-24 09:08:18 -07001551 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1552 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1553 return;
1554 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001555 /*
1556 * At this point all fcport's software-states are cleared. Perform any
1557 * final cleanup of firmware resources (PCBs and XCBs).
1558 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001559 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezaf11f642012-02-09 11:15:43 -08001560 !test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
1561 if (IS_FWI2_CAPABLE(fcport->vha->hw))
1562 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1563 fcport->loop_id, fcport->d_id.b.domain,
1564 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1565 else
1566 qla2x00_port_logout(fcport->vha, fcport);
1567 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001568}
1569
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001570static int
1571qla2x00_issue_lip(struct Scsi_Host *shost)
1572{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001573 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001574
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001575 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001576 return 0;
1577}
1578
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001579static struct fc_host_statistics *
1580qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1581{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001582 scsi_qla_host_t *vha = shost_priv(shost);
1583 struct qla_hw_data *ha = vha->hw;
1584 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001585 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001586 struct link_statistics *stats;
1587 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001588 struct fc_host_statistics *pfc_host_stat;
1589
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001590 pfc_host_stat = &vha->fc_host_stat;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001591 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1592
Andrew Vasquez85880802009-12-15 21:29:46 -08001593 if (test_bit(UNLOADING, &vha->dpc_flags))
1594 goto done;
1595
1596 if (unlikely(pci_channel_offline(ha->pdev)))
1597 goto done;
1598
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001599 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1600 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001601 ql_log(ql_log_warn, vha, 0x707d,
1602 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001603 goto done;
1604 }
1605 memset(stats, 0, DMA_POOL_SIZE);
1606
1607 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001608 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001609 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1610 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001611 !qla2x00_reset_active(vha) && !ha->dpc_active) {
Andrew Vasquez178779a2007-01-29 10:22:25 -08001612 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001613 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1614 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001615 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001616
1617 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001618 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001619
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001620 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1621 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1622 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1623 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1624 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1625 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1626 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001627 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001628 pfc_host_stat->tx_frames = stats->tx_frames;
1629 pfc_host_stat->rx_frames = stats->rx_frames;
1630 pfc_host_stat->dumped_frames = stats->dumped_frames;
1631 pfc_host_stat->nos_count = stats->nos_rcvd;
1632 }
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04001633 pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
1634 pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001635
1636done_free:
1637 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001638done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001639 return pfc_host_stat;
1640}
1641
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001642static void
1643qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1644{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001645 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001646
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001647 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001648}
1649
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001650static void
1651qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1652{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001653 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001654
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001655 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001656}
1657
Andrew Vasquez90991c82006-10-02 12:00:46 -07001658static void
1659qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1660{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001661 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001662 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1663 0xFF, 0xFF, 0xFF, 0xFF};
1664 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001665
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001666 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001667 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001668
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001669 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001670}
1671
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001672static void
1673qla2x00_get_host_port_state(struct Scsi_Host *shost)
1674{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001675 scsi_qla_host_t *vha = shost_priv(shost);
1676 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001677
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001678 if (!base_vha->flags.online) {
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001679 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001680 return;
1681 }
1682
1683 switch (atomic_read(&base_vha->loop_state)) {
1684 case LOOP_UPDATE:
1685 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1686 break;
1687 case LOOP_DOWN:
1688 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
1689 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
1690 else
1691 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1692 break;
1693 case LOOP_DEAD:
1694 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1695 break;
1696 case LOOP_READY:
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001697 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
Saurav Kashyap49e85c22011-11-18 09:02:20 -08001698 break;
1699 default:
1700 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1701 break;
1702 }
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001703}
1704
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001705static int
1706qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1707{
1708 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001709 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001710 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1711 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001712 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001713 uint16_t options = 0;
1714 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001715 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001716
1717 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1718 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001719 ql_log(ql_log_warn, vha, 0x707e,
1720 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001721 return (ret);
1722 }
1723
1724 vha = qla24xx_create_vhost(fc_vport);
1725 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001726 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001727 return FC_VPORT_FAILED;
1728 }
1729 if (disable) {
1730 atomic_set(&vha->vp_state, VP_OFFLINE);
1731 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1732 } else
1733 atomic_set(&vha->vp_state, VP_FAILED);
1734
1735 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001736 ql_log(ql_log_info, vha, 0x7080,
1737 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001738
1739 /* initialized vport states */
1740 atomic_set(&vha->loop_state, LOOP_DOWN);
1741 vha->vp_err_state= VP_ERR_PORTDWN;
1742 vha->vp_prev_err_state= VP_ERR_UNKWN;
1743 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001744 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1745 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001746 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001747 ql_dbg(ql_dbg_user, vha, 0x7081,
1748 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001749 atomic_set(&vha->loop_state, LOOP_DEAD);
1750 if (!disable)
1751 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1752 }
1753
Arun Easie02587d2011-08-16 11:29:23 -07001754 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001755 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07001756 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07001757 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001758 ql_dbg(ql_dbg_user, vha, 0x7082,
1759 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07001760 if (ql2xenabledif == 1)
1761 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07001762 scsi_host_set_prot(vha->host,
Arun Easi8cb20492011-08-16 11:29:22 -07001763 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001764 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001765 | SHOST_DIF_TYPE3_PROTECTION
1766 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001767 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001768 | SHOST_DIX_TYPE3_PROTECTION);
1769 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1770 } else
1771 vha->flags.difdix_supported = 0;
1772 }
1773
James Bottomleyd139b9b2009-11-05 13:33:12 -06001774 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1775 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001776 ql_dbg(ql_dbg_user, vha, 0x7083,
1777 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001778 goto vport_create_failed_2;
1779 }
1780
1781 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001782 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001783 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1784 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1785 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001786 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001787 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001788 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001789
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001790 qlt_vport_create(vha, ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001791 qla24xx_vport_disable(fc_vport, disable);
1792
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001793 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001794 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001795 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1796 "Request queue %p attached with "
1797 "VP[%d], cpu affinity =%d\n",
1798 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001799 goto vport_queue;
1800 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001801 goto vport_queue;
1802 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001803 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1804 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1805 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001806 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001807 qos = ha->npiv_info[cnt].q_qos;
1808 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001809 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001810 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001811
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001812 if (qos) {
1813 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1814 qos);
1815 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001816 ql_log(ql_log_warn, vha, 0x7084,
1817 "Can't create request queue for VP[%d]\n",
1818 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001819 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001820 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1821 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1822 ret, qos, vha->vp_idx);
1823 ql_dbg(ql_dbg_user, vha, 0x7085,
1824 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1825 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001826 req = ha->req_q_map[ret];
1827 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001828 }
1829
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001830vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001831 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001832 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001833
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001834vport_create_failed_2:
1835 qla24xx_disable_vp(vha);
1836 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001837 scsi_host_put(vha->host);
1838 return FC_VPORT_FAILED;
1839}
1840
Adrian Bunka824ebb2008-01-17 09:02:15 -08001841static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001842qla24xx_vport_delete(struct fc_vport *fc_vport)
1843{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001844 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001845 struct qla_hw_data *ha = vha->hw;
1846 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001847
1848 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001849 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001850 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001851
1852 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001853
Arun Easifeafb7b2010-09-03 14:57:00 -07001854 vha->flags.delete_progress = 1;
1855
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001856 fc_remove_host(vha->host);
1857
1858 scsi_remove_host(vha->host);
1859
Arun Easi9f406822011-05-10 11:18:17 -07001860 /* Allow timer to run to drain queued items, when removing vp */
1861 qla24xx_deallocate_vp_id(vha);
1862
Arun Easifeafb7b2010-09-03 14:57:00 -07001863 if (vha->timer_active) {
1864 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001865 ql_dbg(ql_dbg_user, vha, 0x7086,
1866 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001867 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001868
Arun Easifeafb7b2010-09-03 14:57:00 -07001869 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001870 if (ql2xextended_error_logging & ql_dbg_user)
1871 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001872 * the net we have placed below */
1873
1874 BUG_ON(atomic_read(&vha->vref_count));
1875
1876 qla2x00_free_fcports(vha);
1877
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001878 mutex_lock(&ha->vport_lock);
1879 ha->cur_vport_count--;
1880 clear_bit(vha->vp_idx, ha->vp_idx_map);
1881 mutex_unlock(&ha->vport_lock);
1882
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001883 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001884 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001885 ql_log(ql_log_warn, vha, 0x7087,
1886 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001887 }
1888
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001889 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001890 scsi_host_put(vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001891 return 0;
1892}
1893
Adrian Bunka824ebb2008-01-17 09:02:15 -08001894static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001895qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1896{
1897 scsi_qla_host_t *vha = fc_vport->dd_data;
1898
1899 if (disable)
1900 qla24xx_disable_vp(vha);
1901 else
1902 qla24xx_enable_vp(vha);
1903
1904 return 0;
1905}
1906
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001907struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001908
1909 .show_host_node_name = 1,
1910 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001911 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001912 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001913
8482e1182005-04-17 15:04:54 -05001914 .get_host_port_id = qla2x00_get_host_port_id,
1915 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001916 .get_host_speed = qla2x00_get_host_speed,
1917 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001918 .get_host_port_type = qla2x00_get_host_port_type,
1919 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001920 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1921 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001922 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1923 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001924 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1925 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001926 .get_host_port_state = qla2x00_get_host_port_state,
1927 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001928
bdf79622005-04-17 15:06:53 -05001929 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001930 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001931
1932 .get_starget_node_name = qla2x00_get_starget_node_name,
1933 .show_starget_node_name = 1,
1934 .get_starget_port_name = qla2x00_get_starget_port_name,
1935 .show_starget_port_name = 1,
1936 .get_starget_port_id = qla2x00_get_starget_port_id,
1937 .show_starget_port_id = 1,
1938
8482e1182005-04-17 15:04:54 -05001939 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1940 .show_rport_dev_loss_tmo = 1,
1941
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001942 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001943 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1944 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001945 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001946
1947 .vport_create = qla24xx_vport_create,
1948 .vport_disable = qla24xx_vport_disable,
1949 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001950 .bsg_request = qla24xx_bsg_request,
1951 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001952};
1953
1954struct fc_function_template qla2xxx_transport_vport_functions = {
1955
1956 .show_host_node_name = 1,
1957 .show_host_port_name = 1,
1958 .show_host_supported_classes = 1,
1959
1960 .get_host_port_id = qla2x00_get_host_port_id,
1961 .show_host_port_id = 1,
1962 .get_host_speed = qla2x00_get_host_speed,
1963 .show_host_speed = 1,
1964 .get_host_port_type = qla2x00_get_host_port_type,
1965 .show_host_port_type = 1,
1966 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1967 .show_host_symbolic_name = 1,
1968 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1969 .show_host_system_hostname = 1,
1970 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1971 .show_host_fabric_name = 1,
1972 .get_host_port_state = qla2x00_get_host_port_state,
1973 .show_host_port_state = 1,
1974
1975 .dd_fcrport_size = sizeof(struct fc_port *),
1976 .show_rport_supported_classes = 1,
1977
1978 .get_starget_node_name = qla2x00_get_starget_node_name,
1979 .show_starget_node_name = 1,
1980 .get_starget_port_name = qla2x00_get_starget_port_name,
1981 .show_starget_port_name = 1,
1982 .get_starget_port_id = qla2x00_get_starget_port_id,
1983 .show_starget_port_id = 1,
1984
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001985 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1986 .show_rport_dev_loss_tmo = 1,
1987
1988 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001989 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1990 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001991 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001992 .bsg_request = qla24xx_bsg_request,
1993 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05001994};
1995
8482e1182005-04-17 15:04:54 -05001996void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001997qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05001998{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001999 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002000 u32 speed = FC_PORTSPEED_UNKNOWN;
2001
Mike Christied2b5f102010-09-15 16:52:30 -05002002 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002003 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2004 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002005 fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
2006 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002007 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2008 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002009
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002010 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002011 speed = FC_PORTSPEED_10GBIT;
Giridhar Malavali6f606d22012-05-15 14:34:18 -04002012 else if (IS_QLA2031(ha))
2013 speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
2014 FC_PORTSPEED_4GBIT;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002015 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002016 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2017 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002018 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002019 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2020 FC_PORTSPEED_1GBIT;
2021 else if (IS_QLA23XX(ha))
2022 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2023 else
2024 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002025 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002026}