blob: 7836eb01c7fcd16a583e2d55884da2eea035de47 [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;
8482e1182005-04-17 15:04:54 -050026
27 if (ha->fw_dump_reading == 0)
28 return 0;
8482e1182005-04-17 15:04:54 -050029
Akinobu Mitab3dc9082008-07-24 08:31:47 -070030 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
31 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050032}
33
34static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070035qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080036 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050038{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080039 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050040 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080041 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050042 int reading;
8482e1182005-04-17 15:04:54 -050043
Giridhar Malavalia9083012010-04-12 17:59:55 -070044 if (IS_QLA82XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -070045 ql_dbg(ql_dbg_user, vha, 0x705b,
46 "Firmware dump not supported for ISP82xx\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -070047 return count;
48 }
49
8482e1182005-04-17 15:04:54 -050050 if (off != 0)
51 return (0);
52
53 reading = simple_strtol(buf, NULL, 10);
54 switch (reading) {
55 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070056 if (!ha->fw_dump_reading)
57 break;
8482e1182005-04-17 15:04:54 -050058
Saurav Kashyap7c3df132011-07-14 12:00:13 -070059 ql_log(ql_log_info, vha, 0x705d,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080060 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070061
62 ha->fw_dump_reading = 0;
63 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050064 break;
65 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070066 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050067 ha->fw_dump_reading = 1;
68
Saurav Kashyap7c3df132011-07-14 12:00:13 -070069 ql_log(ql_log_info, vha, 0x705e,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070070 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080071 vha->host_no);
8482e1182005-04-17 15:04:54 -050072 }
73 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080075 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070076 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070077 case 3:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080078 qla2x00_system_error(vha);
Andrew Vasquez68af0812008-05-12 22:21:13 -070079 break;
8482e1182005-04-17 15:04:54 -050080 }
81 return (count);
82}
83
84static struct bin_attribute sysfs_fw_dump_attr = {
85 .attr = {
86 .name = "fw_dump",
87 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -050088 },
89 .size = 0,
90 .read = qla2x00_sysfs_read_fw_dump,
91 .write = qla2x00_sysfs_write_fw_dump,
92};
93
94static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070095qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080096 struct bin_attribute *bin_attr,
97 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050098{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080099 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500100 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800101 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500102
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700103 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500104 return 0;
105
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700106 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700107 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700108 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700109 return memory_read_from_buffer(buf, count, &off, ha->nvram,
110 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500111}
112
113static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700114qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800115 struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500117{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800118 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500119 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800120 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500121 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500122
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700123 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
124 !ha->isp_ops->write_nvram)
8482e1182005-04-17 15:04:54 -0500125 return 0;
126
127 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700128 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700129 uint32_t *iter;
130 uint32_t chksum;
131
132 iter = (uint32_t *)buf;
133 chksum = 0;
134 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
135 chksum += le32_to_cpu(*iter++);
136 chksum = ~chksum + 1;
137 *iter = cpu_to_le32(chksum);
138 } else {
139 uint8_t *iter;
140 uint8_t chksum;
141
142 iter = (uint8_t *)buf;
143 chksum = 0;
144 for (cnt = 0; cnt < count - 1; cnt++)
145 chksum += *iter++;
146 chksum = ~chksum + 1;
147 *iter = chksum;
148 }
8482e1182005-04-17 15:04:54 -0500149
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700150 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700151 ql_log(ql_log_warn, vha, 0x705f,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700152 "HBA not online, failing NVRAM update.\n");
153 return -EAGAIN;
154 }
155
8482e1182005-04-17 15:04:54 -0500156 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800157 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
158 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700159 count);
8482e1182005-04-17 15:04:54 -0500160
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 ql_dbg(ql_dbg_user, vha, 0x7060,
162 "Setting ISP_ABORT_NEEDED\n");
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700163 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800164 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700165 qla2xxx_wake_dpc(vha);
166 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800167
8482e1182005-04-17 15:04:54 -0500168 return (count);
169}
170
171static struct bin_attribute sysfs_nvram_attr = {
172 .attr = {
173 .name = "nvram",
174 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500175 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800176 .size = 512,
8482e1182005-04-17 15:04:54 -0500177 .read = qla2x00_sysfs_read_nvram,
178 .write = qla2x00_sysfs_write_nvram,
179};
180
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800181static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700182qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800183 struct bin_attribute *bin_attr,
184 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800185{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800187 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800188 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800189
190 if (ha->optrom_state != QLA_SREADING)
191 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800192
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700193 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
194 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800195}
196
197static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700198qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800199 struct bin_attribute *bin_attr,
200 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800201{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800202 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800203 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800204 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800205
206 if (ha->optrom_state != QLA_SWRITING)
207 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700208 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800209 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700210 if (off + count > ha->optrom_region_size)
211 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800212
213 memcpy(&ha->optrom_buffer[off], buf, count);
214
215 return count;
216}
217
218static struct bin_attribute sysfs_optrom_attr = {
219 .attr = {
220 .name = "optrom",
221 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800222 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700223 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224 .read = qla2x00_sysfs_read_optrom,
225 .write = qla2x00_sysfs_write_optrom,
226};
227
228static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700229qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800230 struct bin_attribute *bin_attr,
231 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800234 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800235 struct qla_hw_data *ha = vha->hw;
236
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700237 uint32_t start = 0;
238 uint32_t size = ha->optrom_size;
239 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800240
241 if (off)
242 return 0;
243
Andrew Vasquez85880802009-12-15 21:29:46 -0800244 if (unlikely(pci_channel_offline(ha->pdev)))
245 return 0;
246
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700247 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
248 return -EINVAL;
249 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800250 return -EINVAL;
251
252 switch (val) {
253 case 0:
254 if (ha->optrom_state != QLA_SREADING &&
255 ha->optrom_state != QLA_SWRITING)
256 break;
257
258 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700259
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700260 ql_dbg(ql_dbg_user, vha, 0x7061,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700261 "Freeing flash region allocation -- 0x%x bytes.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700262 ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700263
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800264 vfree(ha->optrom_buffer);
265 ha->optrom_buffer = NULL;
266 break;
267 case 1:
268 if (ha->optrom_state != QLA_SWAITING)
269 break;
270
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700271 ha->optrom_region_start = start;
272 ha->optrom_region_size = start + size > ha->optrom_size ?
273 ha->optrom_size - start : size;
274
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800275 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700276 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800277 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700278 ql_log(ql_log_warn, vha, 0x7062,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800279 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700280 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800281
282 ha->optrom_state = QLA_SWAITING;
283 return count;
284 }
285
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700286 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700287 ql_log(ql_log_warn, vha, 0x7063,
288 "HBA not online, failing NVRAM update.\n");
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700289 return -EAGAIN;
290 }
291
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700292 ql_dbg(ql_dbg_user, vha, 0x7064,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700293 "Reading flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700295
296 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800297 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700298 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800299 break;
300 case 2:
301 if (ha->optrom_state != QLA_SWAITING)
302 break;
303
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700304 /*
305 * We need to be more restrictive on which FLASH regions are
306 * allowed to be updated via user-space. Regions accessible
307 * via this method include:
308 *
309 * ISP21xx/ISP22xx/ISP23xx type boards:
310 *
311 * 0x000000 -> 0x020000 -- Boot code.
312 *
313 * ISP2322/ISP24xx type boards:
314 *
315 * 0x000000 -> 0x07ffff -- Boot code.
316 * 0x080000 -> 0x0fffff -- Firmware.
317 *
318 * ISP25xx type boards:
319 *
320 * 0x000000 -> 0x07ffff -- Boot code.
321 * 0x080000 -> 0x0fffff -- Firmware.
322 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
323 */
324 valid = 0;
325 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
326 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700327 else if (start == (ha->flt_region_boot * 4) ||
328 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700329 valid = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700330 else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
331 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700332 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700333 ql_log(ql_log_warn, vha, 0x7065,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700334 "Invalid start region 0x%x/0x%x.\n", start, size);
335 return -EINVAL;
336 }
337
338 ha->optrom_region_start = start;
339 ha->optrom_region_size = start + size > ha->optrom_size ?
340 ha->optrom_size - start : size;
341
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800342 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700343 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800344 if (ha->optrom_buffer == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700345 ql_log(ql_log_warn, vha, 0x7066,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800346 "Unable to allocate memory for optrom update "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700347 "(%x)\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800348
349 ha->optrom_state = QLA_SWAITING;
350 return count;
351 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700352
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700353 ql_dbg(ql_dbg_user, vha, 0x7067,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700354 "Staging flash region write -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700355 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700356
357 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800358 break;
359 case 3:
360 if (ha->optrom_state != QLA_SWRITING)
361 break;
362
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700363 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700364 ql_log(ql_log_warn, vha, 0x7068,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700365 "HBA not online, failing flash update.\n");
366 return -EAGAIN;
367 }
368
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700369 ql_dbg(ql_dbg_user, vha, 0x7069,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700370 "Writing flash region -- 0x%x/0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700371 ha->optrom_region_start, ha->optrom_region_size);
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700372
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800373 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700374 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800375 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700376 default:
377 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800378 }
379 return count;
380}
381
382static struct bin_attribute sysfs_optrom_ctl_attr = {
383 .attr = {
384 .name = "optrom_ctl",
385 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800386 },
387 .size = 0,
388 .write = qla2x00_sysfs_write_optrom_ctl,
389};
390
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800391static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700392qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800393 struct bin_attribute *bin_attr,
394 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800395{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800396 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800397 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800398 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800399
Andrew Vasquez85880802009-12-15 21:29:46 -0800400 if (unlikely(pci_channel_offline(ha->pdev)))
401 return 0;
402
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700403 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800404 return 0;
405
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700406 if (IS_NOCACHE_VPD_TYPE(ha))
407 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
408 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700409 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800410}
411
412static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700413qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800414 struct bin_attribute *bin_attr,
415 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800416{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800417 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800418 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800419 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700420 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800421
Andrew Vasquez85880802009-12-15 21:29:46 -0800422 if (unlikely(pci_channel_offline(ha->pdev)))
423 return 0;
424
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700425 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
426 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800427 return 0;
428
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700429 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700430 ql_log(ql_log_warn, vha, 0x706a,
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700431 "HBA not online, failing VPD update.\n");
432 return -EAGAIN;
433 }
434
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800435 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800436 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
437 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800438
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700439 /* Update flash version information for 4Gb & above. */
440 if (!IS_FWI2_CAPABLE(ha))
441 goto done;
442
443 tmp_data = vmalloc(256);
444 if (!tmp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700445 ql_log(ql_log_warn, vha, 0x706b,
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700446 "Unable to allocate memory for VPD information update.\n");
447 goto done;
448 }
449 ha->isp_ops->get_flash_version(vha, tmp_data);
450 vfree(tmp_data);
451done:
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800452 return count;
453}
454
455static struct bin_attribute sysfs_vpd_attr = {
456 .attr = {
457 .name = "vpd",
458 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800459 },
460 .size = 0,
461 .read = qla2x00_sysfs_read_vpd,
462 .write = qla2x00_sysfs_write_vpd,
463};
464
Andrew Vasquez88729e52006-06-23 16:10:50 -0700465static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700466qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800467 struct bin_attribute *bin_attr,
468 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700469{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800470 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700471 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800472 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700473 uint16_t iter, addr, offset;
474 int rval;
475
476 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
477 return 0;
478
Andrew Vasqueze8711082008-01-31 12:33:48 -0800479 if (ha->sfp_data)
480 goto do_read;
481
482 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
483 &ha->sfp_data_dma);
484 if (!ha->sfp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700485 ql_log(ql_log_warn, vha, 0x706c,
Andrew Vasqueze8711082008-01-31 12:33:48 -0800486 "Unable to allocate memory for SFP read-data.\n");
487 return 0;
488 }
489
490do_read:
491 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700492 addr = 0xa0;
493 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
494 iter++, offset += SFP_BLOCK_SIZE) {
495 if (iter == 4) {
496 /* Skip to next device address. */
497 addr = 0xa2;
498 offset = 0;
499 }
500
Joe Carnuccio6766df92011-05-10 11:30:15 -0700501 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
502 addr, offset, SFP_BLOCK_SIZE, 0);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700503 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700504 ql_log(ql_log_warn, vha, 0x706d,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700505 "Unable to read SFP data (%x/%x/%x).\n", rval,
506 addr, offset);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700507
Andrew Vasquez88729e52006-06-23 16:10:50 -0700508 count = 0;
509 break;
510 }
511 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
512 buf += SFP_BLOCK_SIZE;
513 }
514
515 return count;
516}
517
518static struct bin_attribute sysfs_sfp_attr = {
519 .attr = {
520 .name = "sfp",
521 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700522 },
523 .size = SFP_DEV_SIZE * 2,
524 .read = qla2x00_sysfs_read_sfp,
525};
526
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700527static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700528qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700529 struct bin_attribute *bin_attr,
530 char *buf, loff_t off, size_t count)
531{
532 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
533 struct device, kobj)));
534 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700535 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700536 int type;
537
538 if (off != 0)
539 return 0;
540
541 type = simple_strtol(buf, NULL, 10);
542 switch (type) {
543 case 0x2025c:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700544 ql_log(ql_log_info, vha, 0x706e,
545 "Issuing ISP reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700546
547 scsi_block_requests(vha->host);
548 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
549 qla2xxx_wake_dpc(vha);
550 qla2x00_wait_for_chip_reset(vha);
551 scsi_unblock_requests(vha->host);
552 break;
553 case 0x2025d:
554 if (!IS_QLA81XX(ha))
555 break;
556
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700557 ql_log(ql_log_info, vha, 0x706f,
558 "Issuing MPI reset.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700559
560 /* Make sure FC side is not in reset */
561 qla2x00_wait_for_hba_online(vha);
562
563 /* Issue MPI reset */
564 scsi_block_requests(vha->host);
565 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700566 ql_log(ql_log_warn, vha, 0x7070,
567 "MPI reset failed.\n");
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700568 scsi_unblock_requests(vha->host);
569 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700570 case 0x2025e:
571 if (!IS_QLA82XX(ha) || vha != base_vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700572 ql_log(ql_log_info, vha, 0x7071,
573 "FCoE ctx reset no supported.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700574 return count;
575 }
576
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700577 ql_log(ql_log_info, vha, 0x7072,
578 "Issuing FCoE ctx reset.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700579 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
580 qla2xxx_wake_dpc(vha);
581 qla2x00_wait_for_fcoe_ctx_reset(vha);
582 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700583 }
584 return count;
585}
586
587static struct bin_attribute sysfs_reset_attr = {
588 .attr = {
589 .name = "reset",
590 .mode = S_IWUSR,
591 },
592 .size = 0,
593 .write = qla2x00_sysfs_write_reset,
594};
595
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700596static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700597qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700598 struct bin_attribute *bin_attr,
599 char *buf, loff_t off, size_t count)
600{
601 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
602 struct device, kobj)));
603 struct qla_hw_data *ha = vha->hw;
604 uint16_t dev, adr, opt, len;
605 int rval;
606
607 ha->edc_data_len = 0;
608
609 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
610 return 0;
611
612 if (!ha->edc_data) {
613 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
614 &ha->edc_data_dma);
615 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700616 ql_log(ql_log_warn, vha, 0x7073,
617 "Unable to allocate memory for EDC write.\n");
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700618 return 0;
619 }
620 }
621
622 dev = le16_to_cpup((void *)&buf[0]);
623 adr = le16_to_cpup((void *)&buf[2]);
624 opt = le16_to_cpup((void *)&buf[4]);
625 len = le16_to_cpup((void *)&buf[6]);
626
627 if (!(opt & BIT_0))
628 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
629 return -EINVAL;
630
631 memcpy(ha->edc_data, &buf[8], len);
632
Joe Carnuccio6766df92011-05-10 11:30:15 -0700633 rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
634 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700635 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700636 ql_log(ql_log_warn, vha, 0x7074,
637 "Unable to write EDC (%x) %02x:%04x:%02x:%02x\n",
638 rval, dev, adr, opt, len, buf[8]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700639 return 0;
640 }
641
642 return count;
643}
644
645static struct bin_attribute sysfs_edc_attr = {
646 .attr = {
647 .name = "edc",
648 .mode = S_IWUSR,
649 },
650 .size = 0,
651 .write = qla2x00_sysfs_write_edc,
652};
653
654static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700655qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700656 struct bin_attribute *bin_attr,
657 char *buf, loff_t off, size_t count)
658{
659 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
660 struct device, kobj)));
661 struct qla_hw_data *ha = vha->hw;
662 uint16_t dev, adr, opt, len;
663 int rval;
664
665 ha->edc_data_len = 0;
666
667 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
668 return 0;
669
670 if (!ha->edc_data) {
671 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
672 &ha->edc_data_dma);
673 if (!ha->edc_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700674 ql_log(ql_log_warn, vha, 0x708c,
675 "Unable to allocate memory for EDC status.\n");
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700676 return 0;
677 }
678 }
679
680 dev = le16_to_cpup((void *)&buf[0]);
681 adr = le16_to_cpup((void *)&buf[2]);
682 opt = le16_to_cpup((void *)&buf[4]);
683 len = le16_to_cpup((void *)&buf[6]);
684
685 if (!(opt & BIT_0))
686 if (len == 0 || len > DMA_POOL_SIZE)
687 return -EINVAL;
688
689 memset(ha->edc_data, 0, len);
Joe Carnuccio6766df92011-05-10 11:30:15 -0700690 rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
691 dev, adr, len, opt);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700692 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 ql_log(ql_log_info, vha, 0x7075,
694 "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
695 rval, dev, adr, opt, len);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700696 return 0;
697 }
698
699 ha->edc_data_len = len;
700
701 return count;
702}
703
704static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700705qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700706 struct bin_attribute *bin_attr,
707 char *buf, loff_t off, size_t count)
708{
709 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
710 struct device, kobj)));
711 struct qla_hw_data *ha = vha->hw;
712
713 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
714 return 0;
715
716 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
717 return -EINVAL;
718
719 memcpy(buf, ha->edc_data, ha->edc_data_len);
720
721 return ha->edc_data_len;
722}
723
724static struct bin_attribute sysfs_edc_status_attr = {
725 .attr = {
726 .name = "edc_status",
727 .mode = S_IRUSR | S_IWUSR,
728 },
729 .size = 0,
730 .write = qla2x00_sysfs_write_edc_status,
731 .read = qla2x00_sysfs_read_edc_status,
732};
733
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700734static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700735qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700736 struct bin_attribute *bin_attr,
737 char *buf, loff_t off, size_t count)
738{
739 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
740 struct device, kobj)));
741 struct qla_hw_data *ha = vha->hw;
742 int rval;
743 uint16_t actual_size;
744
745 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
746 return 0;
747
748 if (ha->xgmac_data)
749 goto do_read;
750
751 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
752 &ha->xgmac_data_dma, GFP_KERNEL);
753 if (!ha->xgmac_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700754 ql_log(ql_log_warn, vha, 0x7076,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700755 "Unable to allocate memory for XGMAC read-data.\n");
756 return 0;
757 }
758
759do_read:
760 actual_size = 0;
761 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
762
763 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
764 XGMAC_DATA_SIZE, &actual_size);
765 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700766 ql_log(ql_log_warn, vha, 0x7077,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700767 "Unable to read XGMAC data (%x).\n", rval);
768 count = 0;
769 }
770
771 count = actual_size > count ? count: actual_size;
772 memcpy(buf, ha->xgmac_data, count);
773
774 return count;
775}
776
777static struct bin_attribute sysfs_xgmac_stats_attr = {
778 .attr = {
779 .name = "xgmac_stats",
780 .mode = S_IRUSR,
781 },
782 .size = 0,
783 .read = qla2x00_sysfs_read_xgmac_stats,
784};
785
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700786static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700787qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700788 struct bin_attribute *bin_attr,
789 char *buf, loff_t off, size_t count)
790{
791 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
792 struct device, kobj)));
793 struct qla_hw_data *ha = vha->hw;
794 int rval;
795 uint16_t actual_size;
796
797 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
798 return 0;
799
800 if (ha->dcbx_tlv)
801 goto do_read;
802
803 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
804 &ha->dcbx_tlv_dma, GFP_KERNEL);
805 if (!ha->dcbx_tlv) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700806 ql_log(ql_log_warn, vha, 0x7078,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700807 "Unable to allocate memory for DCBX TLV read-data.\n");
808 return 0;
809 }
810
811do_read:
812 actual_size = 0;
813 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
814
815 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
816 DCBX_TLV_DATA_SIZE);
817 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700818 ql_log(ql_log_warn, vha, 0x7079,
819 "Unable to read DCBX TLV (%x).\n", rval);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700820 count = 0;
821 }
822
823 memcpy(buf, ha->dcbx_tlv, count);
824
825 return count;
826}
827
828static struct bin_attribute sysfs_dcbx_tlv_attr = {
829 .attr = {
830 .name = "dcbx_tlv",
831 .mode = S_IRUSR,
832 },
833 .size = 0,
834 .read = qla2x00_sysfs_read_dcbx_tlv,
835};
836
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700837static struct sysfs_entry {
838 char *name;
839 struct bin_attribute *attr;
840 int is4GBp_only;
841} bin_file_entries[] = {
842 { "fw_dump", &sysfs_fw_dump_attr, },
843 { "nvram", &sysfs_nvram_attr, },
844 { "optrom", &sysfs_optrom_attr, },
845 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
846 { "vpd", &sysfs_vpd_attr, 1 },
847 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700848 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700849 { "edc", &sysfs_edc_attr, 2 },
850 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700851 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700852 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800853 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700854};
855
8482e1182005-04-17 15:04:54 -0500856void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800857qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500858{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800859 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700860 struct sysfs_entry *iter;
861 int ret;
8482e1182005-04-17 15:04:54 -0500862
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700863 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700865 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700866 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
867 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700868 if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700869 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700870
871 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
872 iter->attr);
873 if (ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 ql_log(ql_log_warn, vha, 0x00f3,
875 "Unable to create sysfs %s binary attribute (%d).\n",
876 iter->name, ret);
877 else
878 ql_dbg(ql_dbg_init, vha, 0x00f4,
879 "Successfully created sysfs %s binary attribure.\n",
880 iter->name);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700881 }
8482e1182005-04-17 15:04:54 -0500882}
883
884void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800885qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -0500886{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800887 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700888 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800889 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500890
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700891 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700892 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700893 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700894 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
895 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700896 if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700897 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700898
Andrew Vasquez7914d002006-06-23 16:10:55 -0700899 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700900 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700901 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800902
903 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800904 ha->isp_ops->beacon_off(vha);
8482e1182005-04-17 15:04:54 -0500905}
906
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700907/* Scsi_Host attributes. */
908
909static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100910qla2x00_drvr_version_show(struct device *dev,
911 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700912{
913 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
914}
915
916static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100917qla2x00_fw_version_show(struct device *dev,
918 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700919{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800920 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
921 struct qla_hw_data *ha = vha->hw;
922 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700923
924 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800925 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700926}
927
928static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100929qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
930 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700931{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800932 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
933 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700934 uint32_t sn;
935
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700936 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800937 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700938 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
939 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700940
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700941 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
942 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
943 sn % 100000);
944}
945
946static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100947qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
948 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700949{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800950 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
951 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700952}
953
954static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100955qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
956 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700957{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
959 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700960 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
961 ha->product_id[0], ha->product_id[1], ha->product_id[2],
962 ha->product_id[3]);
963}
964
965static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100966qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
967 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700968{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800969 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
970 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700971}
972
973static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100974qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
975 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700976{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800977 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700978 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800979 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700980}
981
982static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100983qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
984 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700985{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800986 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700987 char pci_info[30];
988
989 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800990 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700991}
992
993static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100994qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
995 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700996{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
998 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700999 int len = 0;
1000
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001001 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -07001002 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1003 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001004 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001005 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1006 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1007 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001008 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1009 else {
1010 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
1011
1012 switch (ha->current_topology) {
1013 case ISP_CFG_NL:
1014 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1015 break;
1016 case ISP_CFG_FL:
1017 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1018 break;
1019 case ISP_CFG_N:
1020 len += snprintf(buf + len, PAGE_SIZE-len,
1021 "N_Port to N_Port\n");
1022 break;
1023 case ISP_CFG_F:
1024 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1025 break;
1026 default:
1027 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1028 break;
1029 }
1030 }
1031 return len;
1032}
1033
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001034static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001035qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1036 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001037{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001038 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001039 int len = 0;
1040
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001041 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001042 case QLA_ZIO_MODE_6:
1043 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1044 break;
1045 case QLA_ZIO_DISABLED:
1046 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1047 break;
1048 }
1049 return len;
1050}
1051
1052static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001053qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1054 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001055{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001056 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1057 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001058 int val = 0;
1059 uint16_t zio_mode;
1060
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001061 if (!IS_ZIO_SUPPORTED(ha))
1062 return -ENOTSUPP;
1063
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001064 if (sscanf(buf, "%d", &val) != 1)
1065 return -EINVAL;
1066
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001067 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001068 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001069 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001070 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001071
1072 /* Update per-hba values and queue a reset. */
1073 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1074 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001075 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001076 }
1077 return strlen(buf);
1078}
1079
1080static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001081qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1082 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001083{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001084 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001085
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001086 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001087}
1088
1089static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001090qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1091 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001092{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001093 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001094 int val = 0;
1095 uint16_t zio_timer;
1096
1097 if (sscanf(buf, "%d", &val) != 1)
1098 return -EINVAL;
1099 if (val > 25500 || val < 100)
1100 return -ERANGE;
1101
1102 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001103 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001104
1105 return strlen(buf);
1106}
1107
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001108static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001109qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1110 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001111{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001112 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001113 int len = 0;
1114
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001115 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001116 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1117 else
1118 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1119 return len;
1120}
1121
1122static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001123qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1124 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001125{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001126 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1127 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001128 int val = 0;
1129 int rval;
1130
1131 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1132 return -EPERM;
1133
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001134 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001135 ql_log(ql_log_warn, vha, 0x707a,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001136 "Abort ISP active -- ignoring beacon request.\n");
1137 return -EBUSY;
1138 }
1139
1140 if (sscanf(buf, "%d", &val) != 1)
1141 return -EINVAL;
1142
1143 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001144 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001145 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001146 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001147
1148 if (rval != QLA_SUCCESS)
1149 count = 0;
1150
1151 return count;
1152}
1153
Andrew Vasquez30c47662007-01-29 10:22:21 -08001154static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001155qla2x00_optrom_bios_version_show(struct device *dev,
1156 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001157{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001158 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1159 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001160 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1161 ha->bios_revision[0]);
1162}
1163
1164static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001165qla2x00_optrom_efi_version_show(struct device *dev,
1166 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001167{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001168 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1169 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001170 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1171 ha->efi_revision[0]);
1172}
1173
1174static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001175qla2x00_optrom_fcode_version_show(struct device *dev,
1176 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001177{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1179 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001180 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1181 ha->fcode_revision[0]);
1182}
1183
1184static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001185qla2x00_optrom_fw_version_show(struct device *dev,
1186 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001187{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1189 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001190 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1191 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1192 ha->fw_revision[3]);
1193}
1194
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001195static ssize_t
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001196qla2x00_optrom_gold_fw_version_show(struct device *dev,
1197 struct device_attribute *attr, char *buf)
1198{
1199 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1200 struct qla_hw_data *ha = vha->hw;
1201
1202 if (!IS_QLA81XX(ha))
1203 return snprintf(buf, PAGE_SIZE, "\n");
1204
1205 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1206 ha->gold_fw_version[0], ha->gold_fw_version[1],
1207 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1208}
1209
1210static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001211qla2x00_total_isp_aborts_show(struct device *dev,
1212 struct device_attribute *attr, char *buf)
1213{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001214 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1215 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001216 return snprintf(buf, PAGE_SIZE, "%d\n",
1217 ha->qla_stats.total_isp_aborts);
1218}
1219
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001220static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001221qla24xx_84xx_fw_version_show(struct device *dev,
1222 struct device_attribute *attr, char *buf)
1223{
1224 int rval = QLA_SUCCESS;
1225 uint16_t status[2] = {0, 0};
1226 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1227 struct qla_hw_data *ha = vha->hw;
1228
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001229 if (!IS_QLA84XX(ha))
1230 return snprintf(buf, PAGE_SIZE, "\n");
1231
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001232 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001233 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001234
1235 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1236 return snprintf(buf, PAGE_SIZE, "%u\n",
1237 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001238
1239 return snprintf(buf, PAGE_SIZE, "\n");
1240}
1241
1242static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001243qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1244 char *buf)
1245{
1246 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1247 struct qla_hw_data *ha = vha->hw;
1248
1249 if (!IS_QLA81XX(ha))
1250 return snprintf(buf, PAGE_SIZE, "\n");
1251
Andrew Vasquez55a96152009-03-24 09:08:03 -07001252 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001253 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001254 ha->mpi_capabilities);
1255}
1256
1257static ssize_t
1258qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1259 char *buf)
1260{
1261 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1262 struct qla_hw_data *ha = vha->hw;
1263
1264 if (!IS_QLA81XX(ha))
1265 return snprintf(buf, PAGE_SIZE, "\n");
1266
1267 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1268 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001269}
1270
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001271static ssize_t
1272qla2x00_flash_block_size_show(struct device *dev,
1273 struct device_attribute *attr, char *buf)
1274{
1275 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1276 struct qla_hw_data *ha = vha->hw;
1277
1278 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1279}
1280
Andrew Vasquezbad70012009-04-06 22:33:38 -07001281static ssize_t
1282qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1283 char *buf)
1284{
1285 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1286
Giridhar Malavalia9083012010-04-12 17:59:55 -07001287 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001288 return snprintf(buf, PAGE_SIZE, "\n");
1289
1290 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1291}
1292
1293static ssize_t
1294qla2x00_vn_port_mac_address_show(struct device *dev,
1295 struct device_attribute *attr, char *buf)
1296{
1297 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1298
Giridhar Malavalia9083012010-04-12 17:59:55 -07001299 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001300 return snprintf(buf, PAGE_SIZE, "\n");
1301
1302 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1303 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1304 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1305 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1306}
1307
Andrew Vasquez7f774022009-06-03 09:55:12 -07001308static ssize_t
1309qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1310 char *buf)
1311{
1312 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1313
1314 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1315}
1316
Andrew Vasquez656e8912009-06-03 09:55:29 -07001317static ssize_t
Andrew Vasquez794a5692010-12-21 16:00:21 -08001318qla2x00_thermal_temp_show(struct device *dev,
1319 struct device_attribute *attr, char *buf)
1320{
1321 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1322 int rval = QLA_FUNCTION_FAILED;
1323 uint16_t temp, frac;
1324
1325 if (!vha->hw->flags.thermal_supported)
1326 return snprintf(buf, PAGE_SIZE, "\n");
1327
1328 temp = frac = 0;
1329 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1330 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001331 ql_log(ql_log_warn, vha, 0x707b,
1332 "ISP reset active.\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08001333 else if (!vha->hw->flags.eeh_busy)
1334 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1335 if (rval != QLA_SUCCESS)
1336 temp = frac = 0;
1337
1338 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1339}
1340
1341static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001342qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1343 char *buf)
1344{
1345 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001346 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001347 uint16_t state[5];
1348
Santosh Vernekard6136f32010-03-19 16:59:20 -07001349 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1350 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001351 ql_log(ql_log_warn, vha, 0x707c,
1352 "ISP reset active.\n");
Santosh Vernekard6136f32010-03-19 16:59:20 -07001353 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001354 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001355 if (rval != QLA_SUCCESS)
1356 memset(state, -1, sizeof(state));
1357
1358 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1359 state[1], state[2], state[3], state[4]);
1360}
1361
Tony Jonesee959b02008-02-22 00:13:36 +01001362static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1363static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1364static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1365static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1366static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1367static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1368static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1369static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001370static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001371static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1372static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1373 qla2x00_zio_timer_store);
1374static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1375 qla2x00_beacon_store);
1376static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1377 qla2x00_optrom_bios_version_show, NULL);
1378static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1379 qla2x00_optrom_efi_version_show, NULL);
1380static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1381 qla2x00_optrom_fcode_version_show, NULL);
1382static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1383 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001384static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1385 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001386static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1387 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001388static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1389 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001390static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001391static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001392static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1393 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001394static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1395static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1396 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001397static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001398static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001399static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001400
Tony Jonesee959b02008-02-22 00:13:36 +01001401struct device_attribute *qla2x00_host_attrs[] = {
1402 &dev_attr_driver_version,
1403 &dev_attr_fw_version,
1404 &dev_attr_serial_num,
1405 &dev_attr_isp_name,
1406 &dev_attr_isp_id,
1407 &dev_attr_model_name,
1408 &dev_attr_model_desc,
1409 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001410 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001411 &dev_attr_zio,
1412 &dev_attr_zio_timer,
1413 &dev_attr_beacon,
1414 &dev_attr_optrom_bios_version,
1415 &dev_attr_optrom_efi_version,
1416 &dev_attr_optrom_fcode_version,
1417 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001418 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001419 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001420 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001421 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001422 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001423 &dev_attr_vlan_id,
1424 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001425 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001426 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001427 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001428 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001429 NULL,
1430};
1431
8482e1182005-04-17 15:04:54 -05001432/* Host attributes. */
1433
1434static void
1435qla2x00_get_host_port_id(struct Scsi_Host *shost)
1436{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001437 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001438
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001439 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1440 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001441}
1442
1443static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001444qla2x00_get_host_speed(struct Scsi_Host *shost)
1445{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001446 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1447 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001448 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001449
1450 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001451 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001452 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001453 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001454 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001455 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001456 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001457 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001458 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001459 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001460 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001461 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001462 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001463 case PORT_SPEED_10GB:
1464 speed = FC_PORTSPEED_10GBIT;
1465 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001466 }
1467 fc_host_speed(shost) = speed;
1468}
1469
1470static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001471qla2x00_get_host_port_type(struct Scsi_Host *shost)
1472{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001473 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001474 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1475
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001476 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001477 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1478 return;
1479 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001481 case ISP_CFG_NL:
1482 port_type = FC_PORTTYPE_LPORT;
1483 break;
1484 case ISP_CFG_FL:
1485 port_type = FC_PORTTYPE_NLPORT;
1486 break;
1487 case ISP_CFG_N:
1488 port_type = FC_PORTTYPE_PTP;
1489 break;
1490 case ISP_CFG_F:
1491 port_type = FC_PORTTYPE_NPORT;
1492 break;
1493 }
1494 fc_host_port_type(shost) = port_type;
1495}
1496
1497static void
8482e1182005-04-17 15:04:54 -05001498qla2x00_get_starget_node_name(struct scsi_target *starget)
1499{
1500 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001501 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001502 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001503 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001504
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001505 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001506 if (fcport->rport &&
1507 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001508 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001509 break;
1510 }
1511 }
1512
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001513 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001514}
1515
1516static void
1517qla2x00_get_starget_port_name(struct scsi_target *starget)
1518{
1519 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001520 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001521 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001522 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001523
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001524 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001525 if (fcport->rport &&
1526 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001527 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001528 break;
1529 }
1530 }
1531
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001532 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001533}
1534
1535static void
1536qla2x00_get_starget_port_id(struct scsi_target *starget)
1537{
1538 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001539 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001540 fc_port_t *fcport;
1541 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001542
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001543 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001544 if (fcport->rport &&
1545 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001546 port_id = fcport->d_id.b.domain << 16 |
1547 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1548 break;
1549 }
1550 }
1551
8482e1182005-04-17 15:04:54 -05001552 fc_starget_port_id(starget) = port_id;
1553}
1554
1555static void
8482e1182005-04-17 15:04:54 -05001556qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1557{
8482e1182005-04-17 15:04:54 -05001558 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001559 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001560 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001561 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001562}
1563
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001564static void
1565qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1566{
1567 struct Scsi_Host *host = rport_to_shost(rport);
1568 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001569 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001570
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001571 if (!fcport)
1572 return;
1573
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001574 /* Now that the rport has been deleted, set the fcport state to
1575 FCS_DEVICE_DEAD */
Chad Dupuisec426e12011-03-30 11:46:32 -07001576 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001577
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001578 /*
1579 * Transport has effectively 'deleted' the rport, clear
1580 * all local references.
1581 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001582 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001583 fcport->rport = fcport->drport = NULL;
1584 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001585 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001586
Andrew Vasquez85880802009-12-15 21:29:46 -08001587 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1588 return;
1589
1590 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001591 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001592 return;
1593 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001594}
1595
1596static void
1597qla2x00_terminate_rport_io(struct fc_rport *rport)
1598{
1599 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1600
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001601 if (!fcport)
1602 return;
1603
Andrew Vasquez85880802009-12-15 21:29:46 -08001604 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1605 return;
1606
Seokmann Jub9b12f72009-03-24 09:08:18 -07001607 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1608 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1609 return;
1610 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001611 /*
1612 * At this point all fcport's software-states are cleared. Perform any
1613 * final cleanup of firmware resources (PCBs and XCBs).
1614 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001615 if (fcport->loop_id != FC_NO_LOOP_ID &&
1616 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001617 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1618 fcport->loop_id, fcport->d_id.b.domain,
1619 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001620}
1621
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001622static int
1623qla2x00_issue_lip(struct Scsi_Host *shost)
1624{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001625 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001626
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001627 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001628 return 0;
1629}
1630
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001631static struct fc_host_statistics *
1632qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1633{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001634 scsi_qla_host_t *vha = shost_priv(shost);
1635 struct qla_hw_data *ha = vha->hw;
1636 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001637 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001638 struct link_statistics *stats;
1639 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001640 struct fc_host_statistics *pfc_host_stat;
1641
1642 pfc_host_stat = &ha->fc_host_stat;
1643 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1644
Andrew Vasquez85880802009-12-15 21:29:46 -08001645 if (test_bit(UNLOADING, &vha->dpc_flags))
1646 goto done;
1647
1648 if (unlikely(pci_channel_offline(ha->pdev)))
1649 goto done;
1650
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001651 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1652 if (stats == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001653 ql_log(ql_log_warn, vha, 0x707d,
1654 "Failed to allocate memory for stats.\n");
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001655 goto done;
1656 }
1657 memset(stats, 0, DMA_POOL_SIZE);
1658
1659 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001660 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001661 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1662 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1663 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1664 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001665 !ha->dpc_active) {
1666 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001667 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1668 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001669 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001670
1671 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001672 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001673
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001674 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1675 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1676 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1677 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1678 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1679 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1680 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001681 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001682 pfc_host_stat->tx_frames = stats->tx_frames;
1683 pfc_host_stat->rx_frames = stats->rx_frames;
1684 pfc_host_stat->dumped_frames = stats->dumped_frames;
1685 pfc_host_stat->nos_count = stats->nos_rcvd;
1686 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001687 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1688 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001689
1690done_free:
1691 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001692done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001693 return pfc_host_stat;
1694}
1695
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001696static void
1697qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1698{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001699 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001700
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001701 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001702}
1703
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001704static void
1705qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1706{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001707 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001708
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001709 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001710}
1711
Andrew Vasquez90991c82006-10-02 12:00:46 -07001712static void
1713qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1714{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001715 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001716 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1717 0xFF, 0xFF, 0xFF, 0xFF};
1718 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001719
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001720 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001721 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001722
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001723 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001724}
1725
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001726static void
1727qla2x00_get_host_port_state(struct Scsi_Host *shost)
1728{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001729 scsi_qla_host_t *vha = shost_priv(shost);
1730 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001731
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001732 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001733 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001734 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001735 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1736 else
1737 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1738}
1739
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001740static int
1741qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1742{
1743 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001744 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001745 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1746 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001747 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001748 uint16_t options = 0;
1749 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001750 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001751
1752 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1753 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001754 ql_log(ql_log_warn, vha, 0x707e,
1755 "Vport sanity check failed, status %x\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001756 return (ret);
1757 }
1758
1759 vha = qla24xx_create_vhost(fc_vport);
1760 if (vha == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001761 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001762 return FC_VPORT_FAILED;
1763 }
1764 if (disable) {
1765 atomic_set(&vha->vp_state, VP_OFFLINE);
1766 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1767 } else
1768 atomic_set(&vha->vp_state, VP_FAILED);
1769
1770 /* ready to create vport */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001771 ql_log(ql_log_info, vha, 0x7080,
1772 "VP entry id %d assigned.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001773
1774 /* initialized vport states */
1775 atomic_set(&vha->loop_state, LOOP_DOWN);
1776 vha->vp_err_state= VP_ERR_PORTDWN;
1777 vha->vp_prev_err_state= VP_ERR_UNKWN;
1778 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001779 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1780 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001781 /* Don't retry or attempt login of this virtual port */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001782 ql_dbg(ql_dbg_user, vha, 0x7081,
1783 "Vport loop state is not UP.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001784 atomic_set(&vha->loop_state, LOOP_DEAD);
1785 if (!disable)
1786 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1787 }
1788
Arun Easiba77ef52010-05-28 15:08:27 -07001789 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001790 if (ha->fw_attributes & BIT_4) {
1791 vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001792 ql_dbg(ql_dbg_user, vha, 0x7082,
1793 "Registered for DIF/DIX type 1 and 3 protection.\n");
Arun Easibad75002010-05-04 15:01:30 -07001794 scsi_host_set_prot(vha->host,
1795 SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001796 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001797 | SHOST_DIF_TYPE3_PROTECTION
1798 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001799 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001800 | SHOST_DIX_TYPE3_PROTECTION);
1801 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1802 } else
1803 vha->flags.difdix_supported = 0;
1804 }
1805
James Bottomleyd139b9b2009-11-05 13:33:12 -06001806 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1807 &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001808 ql_dbg(ql_dbg_user, vha, 0x7083,
1809 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001810 goto vport_create_failed_2;
1811 }
1812
1813 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001814 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001815 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1816 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1817 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001818 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001819 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001820 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001821
1822 qla24xx_vport_disable(fc_vport, disable);
1823
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001824 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001825 req = ha->req_q_map[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001826 ql_dbg(ql_dbg_multiq, vha, 0xc000,
1827 "Request queue %p attached with "
1828 "VP[%d], cpu affinity =%d\n",
1829 req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001830 goto vport_queue;
1831 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001832 goto vport_queue;
1833 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001834 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1835 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1836 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001837 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001838 qos = ha->npiv_info[cnt].q_qos;
1839 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001840 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001841 }
1842 if (qos) {
1843 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1844 qos);
1845 if (!ret)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001846 ql_log(ql_log_warn, vha, 0x7084,
1847 "Can't create request queue for VP[%d]\n",
1848 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001849 else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001850 ql_dbg(ql_dbg_multiq, vha, 0xc001,
1851 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1852 ret, qos, vha->vp_idx);
1853 ql_dbg(ql_dbg_user, vha, 0x7085,
1854 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1855 ret, qos, vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001856 req = ha->req_q_map[ret];
1857 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001858 }
1859
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001860vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001861 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001862 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001863
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001864vport_create_failed_2:
1865 qla24xx_disable_vp(vha);
1866 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001867 scsi_host_put(vha->host);
1868 return FC_VPORT_FAILED;
1869}
1870
Adrian Bunka824ebb2008-01-17 09:02:15 -08001871static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001872qla24xx_vport_delete(struct fc_vport *fc_vport)
1873{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001874 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001875 struct qla_hw_data *ha = vha->hw;
1876 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001877
1878 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001879 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001880 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001881
1882 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001883
Arun Easifeafb7b2010-09-03 14:57:00 -07001884 vha->flags.delete_progress = 1;
1885
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001886 fc_remove_host(vha->host);
1887
1888 scsi_remove_host(vha->host);
1889
Arun Easi9f406822011-05-10 11:18:17 -07001890 /* Allow timer to run to drain queued items, when removing vp */
1891 qla24xx_deallocate_vp_id(vha);
1892
Arun Easifeafb7b2010-09-03 14:57:00 -07001893 if (vha->timer_active) {
1894 qla2x00_vp_stop_timer(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001895 ql_dbg(ql_dbg_user, vha, 0x7086,
1896 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
Arun Easifeafb7b2010-09-03 14:57:00 -07001897 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001898
Arun Easifeafb7b2010-09-03 14:57:00 -07001899 /* No pending activities shall be there on the vha now */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001900 if (ql2xextended_error_logging & ql_dbg_user)
1901 msleep(random32()%10); /* Just to see if something falls on
Arun Easifeafb7b2010-09-03 14:57:00 -07001902 * the net we have placed below */
1903
1904 BUG_ON(atomic_read(&vha->vref_count));
1905
1906 qla2x00_free_fcports(vha);
1907
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001908 mutex_lock(&ha->vport_lock);
1909 ha->cur_vport_count--;
1910 clear_bit(vha->vp_idx, ha->vp_idx_map);
1911 mutex_unlock(&ha->vport_lock);
1912
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001913 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001914 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001915 ql_log(ql_log_warn, vha, 0x7087,
1916 "Queue delete failed.\n");
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001917 }
1918
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001919 scsi_host_put(vha->host);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001920 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001921 return 0;
1922}
1923
Adrian Bunka824ebb2008-01-17 09:02:15 -08001924static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001925qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1926{
1927 scsi_qla_host_t *vha = fc_vport->dd_data;
1928
1929 if (disable)
1930 qla24xx_disable_vp(vha);
1931 else
1932 qla24xx_enable_vp(vha);
1933
1934 return 0;
1935}
1936
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001937struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001938
1939 .show_host_node_name = 1,
1940 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001941 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001942 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001943
8482e1182005-04-17 15:04:54 -05001944 .get_host_port_id = qla2x00_get_host_port_id,
1945 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001946 .get_host_speed = qla2x00_get_host_speed,
1947 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001948 .get_host_port_type = qla2x00_get_host_port_type,
1949 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001950 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1951 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001952 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1953 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001954 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1955 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001956 .get_host_port_state = qla2x00_get_host_port_state,
1957 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001958
bdf79622005-04-17 15:06:53 -05001959 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001960 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001961
1962 .get_starget_node_name = qla2x00_get_starget_node_name,
1963 .show_starget_node_name = 1,
1964 .get_starget_port_name = qla2x00_get_starget_port_name,
1965 .show_starget_port_name = 1,
1966 .get_starget_port_id = qla2x00_get_starget_port_id,
1967 .show_starget_port_id = 1,
1968
8482e1182005-04-17 15:04:54 -05001969 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1970 .show_rport_dev_loss_tmo = 1,
1971
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001972 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001973 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1974 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001975 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001976
1977 .vport_create = qla24xx_vport_create,
1978 .vport_disable = qla24xx_vport_disable,
1979 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001980 .bsg_request = qla24xx_bsg_request,
1981 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001982};
1983
1984struct fc_function_template qla2xxx_transport_vport_functions = {
1985
1986 .show_host_node_name = 1,
1987 .show_host_port_name = 1,
1988 .show_host_supported_classes = 1,
1989
1990 .get_host_port_id = qla2x00_get_host_port_id,
1991 .show_host_port_id = 1,
1992 .get_host_speed = qla2x00_get_host_speed,
1993 .show_host_speed = 1,
1994 .get_host_port_type = qla2x00_get_host_port_type,
1995 .show_host_port_type = 1,
1996 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1997 .show_host_symbolic_name = 1,
1998 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1999 .show_host_system_hostname = 1,
2000 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2001 .show_host_fabric_name = 1,
2002 .get_host_port_state = qla2x00_get_host_port_state,
2003 .show_host_port_state = 1,
2004
2005 .dd_fcrport_size = sizeof(struct fc_port *),
2006 .show_rport_supported_classes = 1,
2007
2008 .get_starget_node_name = qla2x00_get_starget_node_name,
2009 .show_starget_node_name = 1,
2010 .get_starget_port_name = qla2x00_get_starget_port_name,
2011 .show_starget_port_name = 1,
2012 .get_starget_port_id = qla2x00_get_starget_port_id,
2013 .show_starget_port_id = 1,
2014
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002015 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2016 .show_rport_dev_loss_tmo = 1,
2017
2018 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002019 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2020 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002021 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002022 .bsg_request = qla24xx_bsg_request,
2023 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05002024};
2025
8482e1182005-04-17 15:04:54 -05002026void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002027qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05002028{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002029 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002030 u32 speed = FC_PORTSPEED_UNKNOWN;
2031
Mike Christied2b5f102010-09-15 16:52:30 -05002032 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002033 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2034 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2035 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
2036 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2037 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002038
Giridhar Malavalia9083012010-04-12 17:59:55 -07002039 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002040 speed = FC_PORTSPEED_10GBIT;
2041 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002042 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2043 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002044 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002045 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2046 FC_PORTSPEED_1GBIT;
2047 else if (IS_QLA23XX(ha))
2048 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2049 else
2050 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002051 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002052}