blob: df0002f7880501aa1cd3f7af2e971cfe5afddb98 [file] [log] [blame]
8482e1182005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
8482e1182005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e1182005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090012#include <linux/delay.h>
8482e1182005-04-17 15:04:54 -050013
Adrian Bunka824ebb2008-01-17 09:02:15 -080014static int qla24xx_vport_disable(struct fc_vport *, bool);
Giridhar Malavali6e980162010-03-19 17:03:58 -070015
8482e1182005-04-17 15:04:54 -050016/* SYSFS attributes --------------------------------------------------------- */
17
18static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070019qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080020 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050022{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali08de2842011-08-16 11:31:44 -070026 int rval = 0;
8482e1182005-04-17 15:04:54 -050027
28 if (ha->fw_dump_reading == 0)
29 return 0;
8482e1182005-04-17 15:04:54 -050030
Giridhar Malavali08de2842011-08-16 11:31:44 -070031 if (IS_QLA82XX(ha)) {
32 if (off < ha->md_template_size) {
33 rval = memory_read_from_buffer(buf, count,
34 &off, ha->md_tmplt_hdr, ha->md_template_size);
35 return rval;
36 }
37 off -= ha->md_template_size;
38 rval = memory_read_from_buffer(buf, count,
39 &off, ha->md_dump, ha->md_dump_size);
40 return rval;
41 } else
42 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
Akinobu Mitab3dc9082008-07-24 08:31:47 -070043 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050044}
45
46static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070047qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080048 struct bin_attribute *bin_attr,
49 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050050{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080051 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050052 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080053 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050054 int reading;
8482e1182005-04-17 15:04:54 -050055
56 if (off != 0)
57 return (0);
58
59 reading = simple_strtol(buf, NULL, 10);
60 switch (reading) {
61 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070062 if (!ha->fw_dump_reading)
63 break;
8482e1182005-04-17 15:04:54 -050064
Saurav Kashyap7c3df132011-07-14 12:00:13 -070065 ql_log(ql_log_info, vha, 0x705d,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070067
Giridhar Malavali08de2842011-08-16 11:31:44 -070068 if (IS_QLA82XX(vha->hw)) {
69 qla82xx_md_free(vha);
70 qla82xx_md_prep(vha);
71 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070072 ha->fw_dump_reading = 0;
73 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050074 break;
75 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070076 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050077 ha->fw_dump_reading = 1;
78
Saurav Kashyap7c3df132011-07-14 12:00:13 -070079 ql_log(ql_log_info, vha, 0x705e,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070080 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080081 vha->host_no);
8482e1182005-04-17 15:04:54 -050082 }
83 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070084 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080085 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070086 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070087 case 3:
Giridhar Malavali08de2842011-08-16 11:31:44 -070088 if (IS_QLA82XX(ha)) {
89 qla82xx_idc_lock(ha);
90 qla82xx_set_reset_owner(vha);
91 qla82xx_idc_unlock(ha);
92 } else
93 qla2x00_system_error(vha);
94 break;
95 case 4:
96 if (IS_QLA82XX(ha)) {
97 if (ha->md_tmplt_hdr)
98 ql_dbg(ql_dbg_user, vha, 0x705b,
99 "MiniDump supported with this firmware.\n");
100 else
101 ql_dbg(ql_dbg_user, vha, 0x709d,
102 "MiniDump not supported with this firmware.\n");
103 }
104 break;
105 case 5:
106 if (IS_QLA82XX(ha))
107 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez68af0812008-05-12 22:21:13 -0700108 break;
8482e1182005-04-17 15:04:54 -0500109 }
110 return (count);
111}
112
113static struct bin_attribute sysfs_fw_dump_attr = {
114 .attr = {
115 .name = "fw_dump",
116 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500117 },
118 .size = 0,
119 .read = qla2x00_sysfs_read_fw_dump,
120 .write = qla2x00_sysfs_write_fw_dump,
121};
122
123static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700124qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800125 struct bin_attribute *bin_attr,
126 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500127{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800128 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500129 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800130 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500131
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700132 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500133 return 0;
134
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700135 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700136 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700137 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700138 return memory_read_from_buffer(buf, count, &off, ha->nvram,
139 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500140}
141
142static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700143qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800144 struct bin_attribute *bin_attr,
145 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500146{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800147 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500148 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800149 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500150 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500151
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700152 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
153 !ha->isp_ops->write_nvram)
8482e1182005-04-17 15:04:54 -0500154 return 0;
155
156 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700157 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700158 uint32_t *iter;
159 uint32_t chksum;
160
161 iter = (uint32_t *)buf;
162 chksum = 0;
163 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
164 chksum += le32_to_cpu(*iter++);
165 chksum = ~chksum + 1;
166 *iter = cpu_to_le32(chksum);
167 } else {
168 uint8_t *iter;
169 uint8_t chksum;
170
171 iter = (uint8_t *)buf;
172 chksum = 0;
173 for (cnt = 0; cnt < count - 1; cnt++)
174 chksum += *iter++;
175 chksum = ~chksum + 1;
176 *iter = chksum;
177 }
8482e1182005-04-17 15:04:54 -0500178
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700179 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700180 ql_log(ql_log_warn, vha, 0x705f,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700181 "HBA not online, failing NVRAM update.\n");
182 return -EAGAIN;
183 }
184
8482e1182005-04-17 15:04:54 -0500185 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
187 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700188 count);
8482e1182005-04-17 15:04:54 -0500189
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 ql_dbg(ql_dbg_user, vha, 0x7060,
191 "Setting ISP_ABORT_NEEDED\n");
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700192 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700194 qla2xxx_wake_dpc(vha);
195 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800196
8482e1182005-04-17 15:04:54 -0500197 return (count);
198}
199
200static struct bin_attribute sysfs_nvram_attr = {
201 .attr = {
202 .name = "nvram",
203 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500204 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800205 .size = 512,
8482e1182005-04-17 15:04:54 -0500206 .read = qla2x00_sysfs_read_nvram,
207 .write = qla2x00_sysfs_write_nvram,
208};
209
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800210static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700211qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800212 struct bin_attribute *bin_attr,
213 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800214{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800215 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800216 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800217 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800218
219 if (ha->optrom_state != QLA_SREADING)
220 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800221
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700222 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
223 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224}
225
226static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700227qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800228 struct bin_attribute *bin_attr,
229 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800230{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800231 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800234
235 if (ha->optrom_state != QLA_SWRITING)
236 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700237 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800238 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700239 if (off + count > ha->optrom_region_size)
240 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800241
242 memcpy(&ha->optrom_buffer[off], buf, count);
243
244 return count;
245}
246
247static struct bin_attribute sysfs_optrom_attr = {
248 .attr = {
249 .name = "optrom",
250 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800251 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700252 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800253 .read = qla2x00_sysfs_read_optrom,
254 .write = qla2x00_sysfs_write_optrom,
255};
256
257static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700258qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800259 struct bin_attribute *bin_attr,
260 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800261{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800262 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800263 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800264 struct qla_hw_data *ha = vha->hw;
265
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700266 uint32_t start = 0;
267 uint32_t size = ha->optrom_size;
268 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269
270 if (off)
271 return 0;
272
Andrew Vasquez85880802009-12-15 21:29:46 -0800273 if (unlikely(pci_channel_offline(ha->pdev)))
274 return 0;
275
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700276 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
277 return -EINVAL;
278 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800279 return -EINVAL;
280
281 switch (val) {
282 case 0:
283 if (ha->optrom_state != QLA_SREADING &&
284 ha->optrom_state != QLA_SWRITING)
285 break;
286
287 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700288
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700289 ql_dbg(ql_dbg_user, vha, 0x7061,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700290 "Freeing flash region allocation -- 0x%x bytes.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700291 ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700292
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800293 vfree(ha->optrom_buffer);
294 ha->optrom_buffer = NULL;
295 break;
296 case 1:
297 if (ha->optrom_state != QLA_SWAITING)
298 break;
299
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700300 ha->optrom_region_start = start;
301 ha->optrom_region_size = start + size > ha->optrom_size ?
302 ha->optrom_size - start : size;
303
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800304 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700305 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800306 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700307 ql_log(ql_log_warn, vha, 0x7062,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800308 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700309 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800310
311 ha->optrom_state = QLA_SWAITING;
312 return count;
313 }
314
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700315 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_log(ql_log_warn, vha, 0x7063,
317 "HBA not online, failing NVRAM update.\n");
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700318 return -EAGAIN;
319 }
320
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 ql_dbg(ql_dbg_user, vha, 0x7064,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700322 "Reading flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700324
325 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800326 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700327 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800328 break;
329 case 2:
330 if (ha->optrom_state != QLA_SWAITING)
331 break;
332
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700333 /*
334 * We need to be more restrictive on which FLASH regions are
335 * allowed to be updated via user-space. Regions accessible
336 * via this method include:
337 *
338 * ISP21xx/ISP22xx/ISP23xx type boards:
339 *
340 * 0x000000 -> 0x020000 -- Boot code.
341 *
342 * ISP2322/ISP24xx type boards:
343 *
344 * 0x000000 -> 0x07ffff -- Boot code.
345 * 0x080000 -> 0x0fffff -- Firmware.
346 *
347 * ISP25xx type boards:
348 *
349 * 0x000000 -> 0x07ffff -- Boot code.
350 * 0x080000 -> 0x0fffff -- Firmware.
351 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
352 */
353 valid = 0;
354 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
355 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700356 else if (start == (ha->flt_region_boot * 4) ||
357 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700358 valid = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700359 else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
360 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700361 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700362 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700363 "Invalid start region 0x%x/0x%x.\n", start, size);
364 return -EINVAL;
365 }
366
367 ha->optrom_region_start = start;
368 ha->optrom_region_size = start + size > ha->optrom_size ?
369 ha->optrom_size - start : size;
370
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800371 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700372 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800373 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700374 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800375 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800377
378 ha->optrom_state = QLA_SWAITING;
379 return count;
380 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700381
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700382 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700383 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700384 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700385
386 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800387 break;
388 case 3:
389 if (ha->optrom_state != QLA_SWRITING)
390 break;
391
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700392 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700393 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700394 "HBA not online, failing flash update.\n");
395 return -EAGAIN;
396 }
397
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700398 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700399 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700400 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700401
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800402 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700403 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800404 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700405 default:
406 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800407 }
408 return count;
409}
410
411static struct bin_attribute sysfs_optrom_ctl_attr = {
412 .attr = {
413 .name = "optrom_ctl",
414 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800415 },
416 .size = 0,
417 .write = qla2x00_sysfs_write_optrom_ctl,
418};
419
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800420static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700421qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800422 struct bin_attribute *bin_attr,
423 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800424{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800425 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800426 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800427 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800428
Andrew Vasquez85880802009-12-15 21:29:46 -0800429 if (unlikely(pci_channel_offline(ha->pdev)))
430 return 0;
431
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700432 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800433 return 0;
434
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700435 if (IS_NOCACHE_VPD_TYPE(ha))
436 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
437 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700438 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800439}
440
441static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700442qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800443 struct bin_attribute *bin_attr,
444 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800445{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800446 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800447 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800448 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700449 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800450
Andrew Vasquez85880802009-12-15 21:29:46 -0800451 if (unlikely(pci_channel_offline(ha->pdev)))
452 return 0;
453
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700454 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
455 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800456 return 0;
457
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700458 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700459 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700460 "HBA not online, failing VPD update.\n");
461 return -EAGAIN;
462 }
463
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800464 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800465 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
466 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800467
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700468 /* Update flash version information for 4Gb & above. */
469 if (!IS_FWI2_CAPABLE(ha))
470 goto done;
471
472 tmp_data = vmalloc(256);
473 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700474 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700475 "Unable to allocate memory for VPD information update.\n");
476 goto done;
477 }
478 ha->isp_ops->get_flash_version(vha, tmp_data);
479 vfree(tmp_data);
480done:
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800481 return count;
482}
483
484static struct bin_attribute sysfs_vpd_attr = {
485 .attr = {
486 .name = "vpd",
487 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800488 },
489 .size = 0,
490 .read = qla2x00_sysfs_read_vpd,
491 .write = qla2x00_sysfs_write_vpd,
492};
493
Andrew Vasquez88729e52006-06-23 16:10:50 -0700494static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700495qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800496 struct bin_attribute *bin_attr,
497 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700498{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800499 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700500 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800501 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700502 uint16_t iter, addr, offset;
503 int rval;
504
505 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
506 return 0;
507
Andrew Vasqueze8711082008-01-31 12:33:48 -0800508 if (ha->sfp_data)
509 goto do_read;
510
511 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
512 &ha->sfp_data_dma);
513 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700514 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800515 "Unable to allocate memory for SFP read-data.\n");
516 return 0;
517 }
518
519do_read:
520 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700521 addr = 0xa0;
522 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
523 iter++, offset += SFP_BLOCK_SIZE) {
524 if (iter == 4) {
525 /* Skip to next device address. */
526 addr = 0xa2;
527 offset = 0;
528 }
529
Joe Carnuccio6766df92011-05-10 11:30:15 -0700530 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
531 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700532 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700533 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700534 "Unable to read SFP data (%x/%x/%x).\n", rval,
535 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700536
Andrew Vasquez88729e52006-06-23 16:10:50 -0700537 count = 0;
538 break;
539 }
540 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
541 buf += SFP_BLOCK_SIZE;
542 }
543
544 return count;
545}
546
547static struct bin_attribute sysfs_sfp_attr = {
548 .attr = {
549 .name = "sfp",
550 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700551 },
552 .size = SFP_DEV_SIZE * 2,
553 .read = qla2x00_sysfs_read_sfp,
554};
555
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700556static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700557qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700558 struct bin_attribute *bin_attr,
559 char *buf, loff_t off, size_t count)
560{
561 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
562 struct device, kobj)));
563 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700564 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700565 int type;
566
567 if (off != 0)
568 return 0;
569
570 type = simple_strtol(buf, NULL, 10);
571 switch (type) {
572 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700573 ql_log(ql_log_info, vha, 0x706e,
574 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700575
576 scsi_block_requests(vha->host);
577 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavali08de2842011-08-16 11:31:44 -0700578 if (IS_QLA82XX(ha)) {
579 qla82xx_idc_lock(ha);
580 qla82xx_set_reset_owner(vha);
581 qla82xx_idc_unlock(ha);
582 }
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700583 qla2xxx_wake_dpc(vha);
584 qla2x00_wait_for_chip_reset(vha);
585 scsi_unblock_requests(vha->host);
586 break;
587 case 0x2025d:
588 if (!IS_QLA81XX(ha))
589 break;
590
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700591 ql_log(ql_log_info, vha, 0x706f,
592 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700593
594 /* Make sure FC side is not in reset */
595 qla2x00_wait_for_hba_online(vha);
596
597 /* Issue MPI reset */
598 scsi_block_requests(vha->host);
599 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700600 ql_log(ql_log_warn, vha, 0x7070,
601 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700602 scsi_unblock_requests(vha->host);
603 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700604 case 0x2025e:
605 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700606 ql_log(ql_log_info, vha, 0x7071,
607 "FCoE ctx reset no supported.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700608 return count;
609 }
610
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700611 ql_log(ql_log_info, vha, 0x7072,
612 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700613 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
614 qla2xxx_wake_dpc(vha);
615 qla2x00_wait_for_fcoe_ctx_reset(vha);
616 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700617 }
618 return count;
619}
620
621static struct bin_attribute sysfs_reset_attr = {
622 .attr = {
623 .name = "reset",
624 .mode = S_IWUSR,
625 },
626 .size = 0,
627 .write = qla2x00_sysfs_write_reset,
628};
629
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700630static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700631qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700632 struct bin_attribute *bin_attr,
633 char *buf, loff_t off, size_t count)
634{
635 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
636 struct device, kobj)));
637 struct qla_hw_data *ha = vha->hw;
638 uint16_t dev, adr, opt, len;
639 int rval;
640
641 ha->edc_data_len = 0;
642
643 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
644 return 0;
645
646 if (!ha->edc_data) {
647 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
648 &ha->edc_data_dma);
649 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_log(ql_log_warn, vha, 0x7073,
651 "Unable to allocate memory for EDC write.\n");
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700652 return 0;
653 }
654 }
655
656 dev = le16_to_cpup((void *)&buf[0]);
657 adr = le16_to_cpup((void *)&buf[2]);
658 opt = le16_to_cpup((void *)&buf[4]);
659 len = le16_to_cpup((void *)&buf[6]);
660
661 if (!(opt & BIT_0))
662 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
663 return -EINVAL;
664
665 memcpy(ha->edc_data, &buf[8], len);
666
Joe Carnuccio6766df92011-05-10 11:30:15 -0700667 rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
668 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700669 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700670 ql_log(ql_log_warn, vha, 0x7074,
671 "Unable to write EDC (%x) %02x:%04x:%02x:%02x\n",
672 rval, dev, adr, opt, len, buf[8]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700673 return 0;
674 }
675
676 return count;
677}
678
679static struct bin_attribute sysfs_edc_attr = {
680 .attr = {
681 .name = "edc",
682 .mode = S_IWUSR,
683 },
684 .size = 0,
685 .write = qla2x00_sysfs_write_edc,
686};
687
688static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700689qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700690 struct bin_attribute *bin_attr,
691 char *buf, loff_t off, size_t count)
692{
693 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
694 struct device, kobj)));
695 struct qla_hw_data *ha = vha->hw;
696 uint16_t dev, adr, opt, len;
697 int rval;
698
699 ha->edc_data_len = 0;
700
701 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
702 return 0;
703
704 if (!ha->edc_data) {
705 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
706 &ha->edc_data_dma);
707 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700708 ql_log(ql_log_warn, vha, 0x708c,
709 "Unable to allocate memory for EDC status.\n");
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700710 return 0;
711 }
712 }
713
714 dev = le16_to_cpup((void *)&buf[0]);
715 adr = le16_to_cpup((void *)&buf[2]);
716 opt = le16_to_cpup((void *)&buf[4]);
717 len = le16_to_cpup((void *)&buf[6]);
718
719 if (!(opt & BIT_0))
720 if (len == 0 || len > DMA_POOL_SIZE)
721 return -EINVAL;
722
723 memset(ha->edc_data, 0, len);
Joe Carnuccio6766df92011-05-10 11:30:15 -0700724 rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
725 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700726 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700727 ql_log(ql_log_info, vha, 0x7075,
728 "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
729 rval, dev, adr, opt, len);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700730 return 0;
731 }
732
733 ha->edc_data_len = len;
734
735 return count;
736}
737
738static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700739qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700740 struct bin_attribute *bin_attr,
741 char *buf, loff_t off, size_t count)
742{
743 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
744 struct device, kobj)));
745 struct qla_hw_data *ha = vha->hw;
746
747 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
748 return 0;
749
750 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
751 return -EINVAL;
752
753 memcpy(buf, ha->edc_data, ha->edc_data_len);
754
755 return ha->edc_data_len;
756}
757
758static struct bin_attribute sysfs_edc_status_attr = {
759 .attr = {
760 .name = "edc_status",
761 .mode = S_IRUSR | S_IWUSR,
762 },
763 .size = 0,
764 .write = qla2x00_sysfs_write_edc_status,
765 .read = qla2x00_sysfs_read_edc_status,
766};
767
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700768static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700769qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700770 struct bin_attribute *bin_attr,
771 char *buf, loff_t off, size_t count)
772{
773 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
774 struct device, kobj)));
775 struct qla_hw_data *ha = vha->hw;
776 int rval;
777 uint16_t actual_size;
778
779 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
780 return 0;
781
782 if (ha->xgmac_data)
783 goto do_read;
784
785 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
786 &ha->xgmac_data_dma, GFP_KERNEL);
787 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700788 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700789 "Unable to allocate memory for XGMAC read-data.\n");
790 return 0;
791 }
792
793do_read:
794 actual_size = 0;
795 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
796
797 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
798 XGMAC_DATA_SIZE, &actual_size);
799 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700800 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700801 "Unable to read XGMAC data (%x).\n", rval);
802 count = 0;
803 }
804
805 count = actual_size > count ? count: actual_size;
806 memcpy(buf, ha->xgmac_data, count);
807
808 return count;
809}
810
811static struct bin_attribute sysfs_xgmac_stats_attr = {
812 .attr = {
813 .name = "xgmac_stats",
814 .mode = S_IRUSR,
815 },
816 .size = 0,
817 .read = qla2x00_sysfs_read_xgmac_stats,
818};
819
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700820static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700821qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700822 struct bin_attribute *bin_attr,
823 char *buf, loff_t off, size_t count)
824{
825 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
826 struct device, kobj)));
827 struct qla_hw_data *ha = vha->hw;
828 int rval;
829 uint16_t actual_size;
830
831 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
832 return 0;
833
834 if (ha->dcbx_tlv)
835 goto do_read;
836
837 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
838 &ha->dcbx_tlv_dma, GFP_KERNEL);
839 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700840 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700841 "Unable to allocate memory for DCBX TLV read-data.\n");
842 return 0;
843 }
844
845do_read:
846 actual_size = 0;
847 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
848
849 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
850 DCBX_TLV_DATA_SIZE);
851 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700852 ql_log(ql_log_warn, vha, 0x7079,
853 "Unable to read DCBX TLV (%x).\n", rval);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700854 count = 0;
855 }
856
857 memcpy(buf, ha->dcbx_tlv, count);
858
859 return count;
860}
861
862static struct bin_attribute sysfs_dcbx_tlv_attr = {
863 .attr = {
864 .name = "dcbx_tlv",
865 .mode = S_IRUSR,
866 },
867 .size = 0,
868 .read = qla2x00_sysfs_read_dcbx_tlv,
869};
870
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700871static struct sysfs_entry {
872 char *name;
873 struct bin_attribute *attr;
874 int is4GBp_only;
875} bin_file_entries[] = {
876 { "fw_dump", &sysfs_fw_dump_attr, },
877 { "nvram", &sysfs_nvram_attr, },
878 { "optrom", &sysfs_optrom_attr, },
879 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
880 { "vpd", &sysfs_vpd_attr, 1 },
881 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700882 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700883 { "edc", &sysfs_edc_attr, 2 },
884 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700885 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700886 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800887 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700888};
889
8482e1182005-04-17 15:04:54 -0500890void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800891qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500892{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800893 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700894 struct sysfs_entry *iter;
895 int ret;
8482e1182005-04-17 15:04:54 -0500896
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700897 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800898 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700899 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700900 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
901 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700902 if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700903 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700904
905 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
906 iter->attr);
907 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700908 ql_log(ql_log_warn, vha, 0x00f3,
909 "Unable to create sysfs %s binary attribute (%d).\n",
910 iter->name, ret);
911 else
912 ql_dbg(ql_dbg_init, vha, 0x00f4,
913 "Successfully created sysfs %s binary attribure.\n",
914 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700915 }
8482e1182005-04-17 15:04:54 -0500916}
917
918void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800919qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500920{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800921 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700922 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800923 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500924
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700925 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700926 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700927 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700928 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
929 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700930 if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700931 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700932
Andrew Vasquez7914d002006-06-23 16:10:55 -0700933 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700934 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700935 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800936
937 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800938 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500939}
940
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700941/* Scsi_Host attributes. */
942
943static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100944qla2x00_drvr_version_show(struct device *dev,
945 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700946{
947 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
948}
949
950static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100951qla2x00_fw_version_show(struct device *dev,
952 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700953{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800954 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
955 struct qla_hw_data *ha = vha->hw;
956 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700957
958 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800959 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700960}
961
962static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100963qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
964 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700965{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800966 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
967 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700968 uint32_t sn;
969
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700970 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700972 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
973 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700974
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700975 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
976 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
977 sn % 100000);
978}
979
980static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100981qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
982 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700983{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800984 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
985 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700986}
987
988static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100989qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
990 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700991{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800992 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
993 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700994 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
995 ha->product_id[0], ha->product_id[1], ha->product_id[2],
996 ha->product_id[3]);
997}
998
999static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001000qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1001 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001002{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001003 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1004 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001005}
1006
1007static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001008qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1009 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001010{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001011 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001012 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001013 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001014}
1015
1016static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001017qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1018 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001019{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001020 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001021 char pci_info[30];
1022
1023 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001024 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001025}
1026
1027static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001028qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1029 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001030{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001031 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1032 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001033 int len = 0;
1034
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001035 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -07001036 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1037 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001038 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001039 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1040 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1041 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001042 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1043 else {
1044 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
1045
1046 switch (ha->current_topology) {
1047 case ISP_CFG_NL:
1048 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1049 break;
1050 case ISP_CFG_FL:
1051 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1052 break;
1053 case ISP_CFG_N:
1054 len += snprintf(buf + len, PAGE_SIZE-len,
1055 "N_Port to N_Port\n");
1056 break;
1057 case ISP_CFG_F:
1058 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1059 break;
1060 default:
1061 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1062 break;
1063 }
1064 }
1065 return len;
1066}
1067
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001068static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001069qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1070 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001071{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001073 int len = 0;
1074
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001075 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001076 case QLA_ZIO_MODE_6:
1077 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1078 break;
1079 case QLA_ZIO_DISABLED:
1080 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1081 break;
1082 }
1083 return len;
1084}
1085
1086static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001087qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1088 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001089{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001090 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1091 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001092 int val = 0;
1093 uint16_t zio_mode;
1094
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001095 if (!IS_ZIO_SUPPORTED(ha))
1096 return -ENOTSUPP;
1097
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001098 if (sscanf(buf, "%d", &val) != 1)
1099 return -EINVAL;
1100
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001101 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001102 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001103 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001104 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001105
1106 /* Update per-hba values and queue a reset. */
1107 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1108 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001109 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001110 }
1111 return strlen(buf);
1112}
1113
1114static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001115qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1116 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001117{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001118 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001119
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001120 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001121}
1122
1123static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001124qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1125 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001126{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001127 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001128 int val = 0;
1129 uint16_t zio_timer;
1130
1131 if (sscanf(buf, "%d", &val) != 1)
1132 return -EINVAL;
1133 if (val > 25500 || val < 100)
1134 return -ERANGE;
1135
1136 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001137 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001138
1139 return strlen(buf);
1140}
1141
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001142static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001143qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1144 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001145{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001146 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001147 int len = 0;
1148
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001149 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001150 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1151 else
1152 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1153 return len;
1154}
1155
1156static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001157qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1158 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001159{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001160 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1161 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001162 int val = 0;
1163 int rval;
1164
1165 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1166 return -EPERM;
1167
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001168 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001170 "Abort ISP active -- ignoring beacon request.\n");
1171 return -EBUSY;
1172 }
1173
1174 if (sscanf(buf, "%d", &val) != 1)
1175 return -EINVAL;
1176
1177 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001179 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001180 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001181
1182 if (rval != QLA_SUCCESS)
1183 count = 0;
1184
1185 return count;
1186}
1187
Andrew Vasquez30c47662007-01-29 10:22:21 -08001188static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001189qla2x00_optrom_bios_version_show(struct device *dev,
1190 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001191{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001192 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1193 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001194 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1195 ha->bios_revision[0]);
1196}
1197
1198static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001199qla2x00_optrom_efi_version_show(struct device *dev,
1200 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001201{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001202 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1203 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001204 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1205 ha->efi_revision[0]);
1206}
1207
1208static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001209qla2x00_optrom_fcode_version_show(struct device *dev,
1210 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001211{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001212 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1213 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001214 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1215 ha->fcode_revision[0]);
1216}
1217
1218static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001219qla2x00_optrom_fw_version_show(struct device *dev,
1220 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001221{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001222 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1223 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001224 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1225 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1226 ha->fw_revision[3]);
1227}
1228
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001229static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001230qla2x00_optrom_gold_fw_version_show(struct device *dev,
1231 struct device_attribute *attr, char *buf)
1232{
1233 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1234 struct qla_hw_data *ha = vha->hw;
1235
1236 if (!IS_QLA81XX(ha))
1237 return snprintf(buf, PAGE_SIZE, "\n");
1238
1239 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1240 ha->gold_fw_version[0], ha->gold_fw_version[1],
1241 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1242}
1243
1244static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001245qla2x00_total_isp_aborts_show(struct device *dev,
1246 struct device_attribute *attr, char *buf)
1247{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001248 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1249 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001250 return snprintf(buf, PAGE_SIZE, "%d\n",
1251 ha->qla_stats.total_isp_aborts);
1252}
1253
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001254static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001255qla24xx_84xx_fw_version_show(struct device *dev,
1256 struct device_attribute *attr, char *buf)
1257{
1258 int rval = QLA_SUCCESS;
1259 uint16_t status[2] = {0, 0};
1260 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1261 struct qla_hw_data *ha = vha->hw;
1262
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001263 if (!IS_QLA84XX(ha))
1264 return snprintf(buf, PAGE_SIZE, "\n");
1265
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001266 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001267 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001268
1269 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1270 return snprintf(buf, PAGE_SIZE, "%u\n",
1271 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001272
1273 return snprintf(buf, PAGE_SIZE, "\n");
1274}
1275
1276static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001277qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
1279{
1280 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1281 struct qla_hw_data *ha = vha->hw;
1282
1283 if (!IS_QLA81XX(ha))
1284 return snprintf(buf, PAGE_SIZE, "\n");
1285
Andrew Vasquez55a96152009-03-24 09:08:03 -07001286 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001287 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001288 ha->mpi_capabilities);
1289}
1290
1291static ssize_t
1292qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1293 char *buf)
1294{
1295 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1296 struct qla_hw_data *ha = vha->hw;
1297
1298 if (!IS_QLA81XX(ha))
1299 return snprintf(buf, PAGE_SIZE, "\n");
1300
1301 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1302 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001303}
1304
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001305static ssize_t
1306qla2x00_flash_block_size_show(struct device *dev,
1307 struct device_attribute *attr, char *buf)
1308{
1309 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1310 struct qla_hw_data *ha = vha->hw;
1311
1312 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1313}
1314
Andrew Vasquezbad70012009-04-06 22:33:38 -07001315static ssize_t
1316qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1317 char *buf)
1318{
1319 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1320
Giridhar Malavalia9083012010-04-12 17:59:55 -07001321 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001322 return snprintf(buf, PAGE_SIZE, "\n");
1323
1324 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1325}
1326
1327static ssize_t
1328qla2x00_vn_port_mac_address_show(struct device *dev,
1329 struct device_attribute *attr, char *buf)
1330{
1331 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1332
Giridhar Malavalia9083012010-04-12 17:59:55 -07001333 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001334 return snprintf(buf, PAGE_SIZE, "\n");
1335
1336 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1337 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1338 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1339 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1340}
1341
Andrew Vasquez7f774022009-06-03 09:55:12 -07001342static ssize_t
1343qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1344 char *buf)
1345{
1346 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1347
1348 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1349}
1350
Andrew Vasquez656e8912009-06-03 09:55:29 -07001351static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001352qla2x00_thermal_temp_show(struct device *dev,
1353 struct device_attribute *attr, char *buf)
1354{
1355 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1356 int rval = QLA_FUNCTION_FAILED;
1357 uint16_t temp, frac;
1358
1359 if (!vha->hw->flags.thermal_supported)
1360 return snprintf(buf, PAGE_SIZE, "\n");
1361
1362 temp = frac = 0;
1363 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1364 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001365 ql_log(ql_log_warn, vha, 0x707b,
1366 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001367 else if (!vha->hw->flags.eeh_busy)
1368 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1369 if (rval != QLA_SUCCESS)
1370 temp = frac = 0;
1371
1372 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1373}
1374
1375static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001376qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1377 char *buf)
1378{
1379 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001380 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001381 uint16_t state[5];
1382
Santosh Vernekard6136f32010-03-19 16:59:20 -07001383 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1384 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001385 ql_log(ql_log_warn, vha, 0x707c,
1386 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001387 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001388 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001389 if (rval != QLA_SUCCESS)
1390 memset(state, -1, sizeof(state));
1391
1392 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1393 state[1], state[2], state[3], state[4]);
1394}
1395
Tony Jonesee959b02008-02-22 00:13:36 +01001396static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1397static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1398static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1399static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1400static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1401static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1402static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1403static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001404static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001405static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1406static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1407 qla2x00_zio_timer_store);
1408static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1409 qla2x00_beacon_store);
1410static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1411 qla2x00_optrom_bios_version_show, NULL);
1412static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1413 qla2x00_optrom_efi_version_show, NULL);
1414static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1415 qla2x00_optrom_fcode_version_show, NULL);
1416static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1417 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001418static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1419 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001420static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1421 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001422static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1423 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001424static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001425static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001426static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1427 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001428static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1429static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1430 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001431static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001432static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001433static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001434
Tony Jonesee959b02008-02-22 00:13:36 +01001435struct device_attribute *qla2x00_host_attrs[] = {
1436 &dev_attr_driver_version,
1437 &dev_attr_fw_version,
1438 &dev_attr_serial_num,
1439 &dev_attr_isp_name,
1440 &dev_attr_isp_id,
1441 &dev_attr_model_name,
1442 &dev_attr_model_desc,
1443 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001444 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001445 &dev_attr_zio,
1446 &dev_attr_zio_timer,
1447 &dev_attr_beacon,
1448 &dev_attr_optrom_bios_version,
1449 &dev_attr_optrom_efi_version,
1450 &dev_attr_optrom_fcode_version,
1451 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001452 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001453 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001454 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001455 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001456 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001457 &dev_attr_vlan_id,
1458 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001459 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001460 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001461 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001462 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001463 NULL,
1464};
1465
8482e1182005-04-17 15:04:54 -05001466/* Host attributes. */
1467
1468static void
1469qla2x00_get_host_port_id(struct Scsi_Host *shost)
1470{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001471 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001472
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001473 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1474 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001475}
1476
1477static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001478qla2x00_get_host_speed(struct Scsi_Host *shost)
1479{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1481 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001482 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001483
1484 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001485 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001486 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001487 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001488 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001489 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001490 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001491 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001492 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001493 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001494 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001495 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001496 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001497 case PORT_SPEED_10GB:
1498 speed = FC_PORTSPEED_10GBIT;
1499 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001500 }
1501 fc_host_speed(shost) = speed;
1502}
1503
1504static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001505qla2x00_get_host_port_type(struct Scsi_Host *shost)
1506{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001507 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001508 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1509
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001510 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001511 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1512 return;
1513 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001514 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001515 case ISP_CFG_NL:
1516 port_type = FC_PORTTYPE_LPORT;
1517 break;
1518 case ISP_CFG_FL:
1519 port_type = FC_PORTTYPE_NLPORT;
1520 break;
1521 case ISP_CFG_N:
1522 port_type = FC_PORTTYPE_PTP;
1523 break;
1524 case ISP_CFG_F:
1525 port_type = FC_PORTTYPE_NPORT;
1526 break;
1527 }
1528 fc_host_port_type(shost) = port_type;
1529}
1530
1531static void
8482e1182005-04-17 15:04:54 -05001532qla2x00_get_starget_node_name(struct scsi_target *starget)
1533{
1534 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001535 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001536 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001537 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001538
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001539 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001540 if (fcport->rport &&
1541 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001542 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001543 break;
1544 }
1545 }
1546
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001547 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001548}
1549
1550static void
1551qla2x00_get_starget_port_name(struct scsi_target *starget)
1552{
1553 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001554 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001555 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001556 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001557
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001558 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001559 if (fcport->rport &&
1560 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001561 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001562 break;
1563 }
1564 }
1565
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001566 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001567}
1568
1569static void
1570qla2x00_get_starget_port_id(struct scsi_target *starget)
1571{
1572 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001573 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001574 fc_port_t *fcport;
1575 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001576
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001577 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001578 if (fcport->rport &&
1579 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001580 port_id = fcport->d_id.b.domain << 16 |
1581 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1582 break;
1583 }
1584 }
1585
8482e1182005-04-17 15:04:54 -05001586 fc_starget_port_id(starget) = port_id;
1587}
1588
1589static void
8482e1182005-04-17 15:04:54 -05001590qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1591{
8482e1182005-04-17 15:04:54 -05001592 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001593 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001594 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001595 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001596}
1597
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001598static void
1599qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1600{
1601 struct Scsi_Host *host = rport_to_shost(rport);
1602 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001603 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001604
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001605 if (!fcport)
1606 return;
1607
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001608 /* Now that the rport has been deleted, set the fcport state to
1609 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001610 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001611
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001612 /*
1613 * Transport has effectively 'deleted' the rport, clear
1614 * all local references.
1615 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001616 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001617 fcport->rport = fcport->drport = NULL;
1618 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001619 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001620
Andrew Vasquez85880802009-12-15 21:29:46 -08001621 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1622 return;
1623
1624 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001625 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001626 return;
1627 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001628}
1629
1630static void
1631qla2x00_terminate_rport_io(struct fc_rport *rport)
1632{
1633 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1634
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001635 if (!fcport)
1636 return;
1637
Andrew Vasquez85880802009-12-15 21:29:46 -08001638 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1639 return;
1640
Seokmann Jub9b12f72009-03-24 09:08:18 -07001641 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1642 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1643 return;
1644 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001645 /*
1646 * At this point all fcport's software-states are cleared. Perform any
1647 * final cleanup of firmware resources (PCBs and XCBs).
1648 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001649 if (fcport->loop_id != FC_NO_LOOP_ID &&
1650 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001651 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1652 fcport->loop_id, fcport->d_id.b.domain,
1653 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001654}
1655
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001656static int
1657qla2x00_issue_lip(struct Scsi_Host *shost)
1658{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001659 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001660
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001661 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001662 return 0;
1663}
1664
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001665static struct fc_host_statistics *
1666qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1667{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001668 scsi_qla_host_t *vha = shost_priv(shost);
1669 struct qla_hw_data *ha = vha->hw;
1670 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001671 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001672 struct link_statistics *stats;
1673 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001674 struct fc_host_statistics *pfc_host_stat;
1675
1676 pfc_host_stat = &ha->fc_host_stat;
1677 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1678
Andrew Vasquez85880802009-12-15 21:29:46 -08001679 if (test_bit(UNLOADING, &vha->dpc_flags))
1680 goto done;
1681
1682 if (unlikely(pci_channel_offline(ha->pdev)))
1683 goto done;
1684
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001685 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1686 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001687 ql_log(ql_log_warn, vha, 0x707d,
1688 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001689 goto done;
1690 }
1691 memset(stats, 0, DMA_POOL_SIZE);
1692
1693 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001694 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001695 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1696 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1697 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1698 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001699 !ha->dpc_active) {
1700 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001701 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1702 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001703 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001704
1705 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001706 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001707
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001708 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1709 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1710 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1711 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1712 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1713 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1714 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001715 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001716 pfc_host_stat->tx_frames = stats->tx_frames;
1717 pfc_host_stat->rx_frames = stats->rx_frames;
1718 pfc_host_stat->dumped_frames = stats->dumped_frames;
1719 pfc_host_stat->nos_count = stats->nos_rcvd;
1720 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001721 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1722 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001723
1724done_free:
1725 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001726done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001727 return pfc_host_stat;
1728}
1729
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001730static void
1731qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1732{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001733 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001734
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001736}
1737
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001738static void
1739qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1740{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001741 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001742
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001744}
1745
Andrew Vasquez90991c82006-10-02 12:00:46 -07001746static void
1747qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1748{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001749 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001750 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1751 0xFF, 0xFF, 0xFF, 0xFF};
1752 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001753
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001754 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001755 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001756
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001757 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001758}
1759
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001760static void
1761qla2x00_get_host_port_state(struct Scsi_Host *shost)
1762{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001763 scsi_qla_host_t *vha = shost_priv(shost);
1764 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001765
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001766 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001767 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001768 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001769 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1770 else
1771 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1772}
1773
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001774static int
1775qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1776{
1777 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001778 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001779 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1780 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001781 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001782 uint16_t options = 0;
1783 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001784 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001785
1786 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1787 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001788 ql_log(ql_log_warn, vha, 0x707e,
1789 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001790 return (ret);
1791 }
1792
1793 vha = qla24xx_create_vhost(fc_vport);
1794 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001795 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001796 return FC_VPORT_FAILED;
1797 }
1798 if (disable) {
1799 atomic_set(&vha->vp_state, VP_OFFLINE);
1800 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1801 } else
1802 atomic_set(&vha->vp_state, VP_FAILED);
1803
1804 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001805 ql_log(ql_log_info, vha, 0x7080,
1806 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001807
1808 /* initialized vport states */
1809 atomic_set(&vha->loop_state, LOOP_DOWN);
1810 vha->vp_err_state= VP_ERR_PORTDWN;
1811 vha->vp_prev_err_state= VP_ERR_UNKWN;
1812 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001813 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1814 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001815 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001816 ql_dbg(ql_dbg_user, vha, 0x7081,
1817 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001818 atomic_set(&vha->loop_state, LOOP_DEAD);
1819 if (!disable)
1820 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1821 }
1822
Arun Easie02587d2011-08-16 11:29:23 -07001823 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001824 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07001825 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07001826 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001827 ql_dbg(ql_dbg_user, vha, 0x7082,
1828 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07001829 if (ql2xenabledif == 1)
1830 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07001831 scsi_host_set_prot(vha->host,
Arun Easi8cb20492011-08-16 11:29:22 -07001832 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001833 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001834 | SHOST_DIF_TYPE3_PROTECTION
1835 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001836 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001837 | SHOST_DIX_TYPE3_PROTECTION);
1838 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1839 } else
1840 vha->flags.difdix_supported = 0;
1841 }
1842
James Bottomleyd139b9b2009-11-05 13:33:12 -06001843 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1844 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001845 ql_dbg(ql_dbg_user, vha, 0x7083,
1846 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001847 goto vport_create_failed_2;
1848 }
1849
1850 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001851 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1853 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1854 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001855 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001856 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001857 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001858
1859 qla24xx_vport_disable(fc_vport, disable);
1860
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001861 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001862 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001863 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1864 "Request queue %p attached with "
1865 "VP[%d], cpu affinity =%d\n",
1866 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001867 goto vport_queue;
1868 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001869 goto vport_queue;
1870 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001871 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1872 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1873 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001874 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001875 qos = ha->npiv_info[cnt].q_qos;
1876 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001877 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001878 }
1879 if (qos) {
1880 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1881 qos);
1882 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001883 ql_log(ql_log_warn, vha, 0x7084,
1884 "Can't create request queue for VP[%d]\n",
1885 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001886 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001887 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1888 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1889 ret, qos, vha->vp_idx);
1890 ql_dbg(ql_dbg_user, vha, 0x7085,
1891 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1892 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001893 req = ha->req_q_map[ret];
1894 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001895 }
1896
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001897vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001898 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001899 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001900
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001901vport_create_failed_2:
1902 qla24xx_disable_vp(vha);
1903 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001904 scsi_host_put(vha->host);
1905 return FC_VPORT_FAILED;
1906}
1907
Adrian Bunka824ebb2008-01-17 09:02:15 -08001908static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001909qla24xx_vport_delete(struct fc_vport *fc_vport)
1910{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001911 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001912 struct qla_hw_data *ha = vha->hw;
1913 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001914
1915 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001916 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001917 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001918
1919 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001920
Arun Easifeafb7b2010-09-03 14:57:00 -07001921 vha->flags.delete_progress = 1;
1922
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001923 fc_remove_host(vha->host);
1924
1925 scsi_remove_host(vha->host);
1926
Arun Easi9f406822011-05-10 11:18:17 -07001927 /* Allow timer to run to drain queued items, when removing vp */
1928 qla24xx_deallocate_vp_id(vha);
1929
Arun Easifeafb7b2010-09-03 14:57:00 -07001930 if (vha->timer_active) {
1931 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001932 ql_dbg(ql_dbg_user, vha, 0x7086,
1933 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001934 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001935
Arun Easifeafb7b2010-09-03 14:57:00 -07001936 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001937 if (ql2xextended_error_logging & ql_dbg_user)
1938 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001939 * the net we have placed below */
1940
1941 BUG_ON(atomic_read(&vha->vref_count));
1942
1943 qla2x00_free_fcports(vha);
1944
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001945 mutex_lock(&ha->vport_lock);
1946 ha->cur_vport_count--;
1947 clear_bit(vha->vp_idx, ha->vp_idx_map);
1948 mutex_unlock(&ha->vport_lock);
1949
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001950 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001951 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001952 ql_log(ql_log_warn, vha, 0x7087,
1953 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001954 }
1955
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001956 scsi_host_put(vha->host);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001957 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001958 return 0;
1959}
1960
Adrian Bunka824ebb2008-01-17 09:02:15 -08001961static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001962qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1963{
1964 scsi_qla_host_t *vha = fc_vport->dd_data;
1965
1966 if (disable)
1967 qla24xx_disable_vp(vha);
1968 else
1969 qla24xx_enable_vp(vha);
1970
1971 return 0;
1972}
1973
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001974struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001975
1976 .show_host_node_name = 1,
1977 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001978 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001979 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001980
8482e1182005-04-17 15:04:54 -05001981 .get_host_port_id = qla2x00_get_host_port_id,
1982 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001983 .get_host_speed = qla2x00_get_host_speed,
1984 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001985 .get_host_port_type = qla2x00_get_host_port_type,
1986 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001987 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1988 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001989 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1990 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001991 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1992 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001993 .get_host_port_state = qla2x00_get_host_port_state,
1994 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001995
bdf79622005-04-17 15:06:53 -05001996 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001997 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001998
1999 .get_starget_node_name = qla2x00_get_starget_node_name,
2000 .show_starget_node_name = 1,
2001 .get_starget_port_name = qla2x00_get_starget_port_name,
2002 .show_starget_port_name = 1,
2003 .get_starget_port_id = qla2x00_get_starget_port_id,
2004 .show_starget_port_id = 1,
2005
8482e1182005-04-17 15:04:54 -05002006 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2007 .show_rport_dev_loss_tmo = 1,
2008
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002009 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002010 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2011 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002012 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002013
2014 .vport_create = qla24xx_vport_create,
2015 .vport_disable = qla24xx_vport_disable,
2016 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002017 .bsg_request = qla24xx_bsg_request,
2018 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002019};
2020
2021struct fc_function_template qla2xxx_transport_vport_functions = {
2022
2023 .show_host_node_name = 1,
2024 .show_host_port_name = 1,
2025 .show_host_supported_classes = 1,
2026
2027 .get_host_port_id = qla2x00_get_host_port_id,
2028 .show_host_port_id = 1,
2029 .get_host_speed = qla2x00_get_host_speed,
2030 .show_host_speed = 1,
2031 .get_host_port_type = qla2x00_get_host_port_type,
2032 .show_host_port_type = 1,
2033 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2034 .show_host_symbolic_name = 1,
2035 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2036 .show_host_system_hostname = 1,
2037 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2038 .show_host_fabric_name = 1,
2039 .get_host_port_state = qla2x00_get_host_port_state,
2040 .show_host_port_state = 1,
2041
2042 .dd_fcrport_size = sizeof(struct fc_port *),
2043 .show_rport_supported_classes = 1,
2044
2045 .get_starget_node_name = qla2x00_get_starget_node_name,
2046 .show_starget_node_name = 1,
2047 .get_starget_port_name = qla2x00_get_starget_port_name,
2048 .show_starget_port_name = 1,
2049 .get_starget_port_id = qla2x00_get_starget_port_id,
2050 .show_starget_port_id = 1,
2051
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002052 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2053 .show_rport_dev_loss_tmo = 1,
2054
2055 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002056 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2057 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002058 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002059 .bsg_request = qla24xx_bsg_request,
2060 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05002061};
2062
8482e1182005-04-17 15:04:54 -05002063void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002064qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05002065{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002066 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002067 u32 speed = FC_PORTSPEED_UNKNOWN;
2068
Mike Christied2b5f102010-09-15 16:52:30 -05002069 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002070 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2071 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2072 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
2073 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2074 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002075
Giridhar Malavalia9083012010-04-12 17:59:55 -07002076 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002077 speed = FC_PORTSPEED_10GBIT;
2078 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002079 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2080 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002081 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002082 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2083 FC_PORTSPEED_1GBIT;
2084 else if (IS_QLA23XX(ha))
2085 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2086 else
2087 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002088 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002089}