blob: e8c1c9e01a7b9de695dfe6b17936c00e805cfc55 [file] [log] [blame]
8482e112005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
8482e112005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e112005-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>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090011#include <linux/delay.h>
8482e112005-04-17 15:04:54 -050012
Adrian Bunka824ebb2008-01-17 09:02:15 -080013static int qla24xx_vport_disable(struct fc_vport *, bool);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070014
8482e112005-04-17 15:04:54 -050015/* SYSFS attributes --------------------------------------------------------- */
16
17static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080018qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
19 struct bin_attribute *bin_attr,
20 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050021{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080022 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050023 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080024 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050025
26 if (ha->fw_dump_reading == 0)
27 return 0;
8482e112005-04-17 15:04:54 -050028
Akinobu Mitab3dc9082008-07-24 08:31:47 -070029 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
30 ha->fw_dump_len);
8482e112005-04-17 15:04:54 -050031}
32
33static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080034qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
35 struct bin_attribute *bin_attr,
36 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050037{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080038 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050039 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080040 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050041 int reading;
8482e112005-04-17 15:04:54 -050042
43 if (off != 0)
44 return (0);
45
46 reading = simple_strtol(buf, NULL, 10);
47 switch (reading) {
48 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070049 if (!ha->fw_dump_reading)
50 break;
8482e112005-04-17 15:04:54 -050051
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070052 qla_printk(KERN_INFO, ha,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080053 "Firmware dump cleared on (%ld).\n", vha->host_no);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070054
55 ha->fw_dump_reading = 0;
56 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050057 break;
58 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070059 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050060 ha->fw_dump_reading = 1;
61
8482e112005-04-17 15:04:54 -050062 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070063 "Raw firmware dump ready for read on (%ld).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080064 vha->host_no);
8482e112005-04-17 15:04:54 -050065 }
66 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070067 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080068 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070069 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070070 case 3:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080071 qla2x00_system_error(vha);
Andrew Vasquez68af0812008-05-12 22:21:13 -070072 break;
8482e112005-04-17 15:04:54 -050073 }
74 return (count);
75}
76
77static struct bin_attribute sysfs_fw_dump_attr = {
78 .attr = {
79 .name = "fw_dump",
80 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050081 },
82 .size = 0,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
85};
86
87static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080088qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050091{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080092 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050093 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080094 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050095
Akinobu Mitab3dc9082008-07-24 08:31:47 -070096 if (!capable(CAP_SYS_ADMIN))
8482e112005-04-17 15:04:54 -050097 return 0;
98
Andrew Vasquez6749ce32009-03-24 09:08:17 -070099 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700100 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700101 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700102 return memory_read_from_buffer(buf, count, &off, ha->nvram,
103 ha->nvram_size);
8482e112005-04-17 15:04:54 -0500104}
105
106static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800107qla2x00_sysfs_write_nvram(struct kobject *kobj,
108 struct bin_attribute *bin_attr,
109 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500110{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800111 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -0500112 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800113 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500114 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500115
Andrew Vasquez3d790382009-03-24 09:08:14 -0700116 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
117 !ha->isp_ops->write_nvram)
8482e112005-04-17 15:04:54 -0500118 return 0;
119
120 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700121 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700122 uint32_t *iter;
123 uint32_t chksum;
124
125 iter = (uint32_t *)buf;
126 chksum = 0;
127 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
128 chksum += le32_to_cpu(*iter++);
129 chksum = ~chksum + 1;
130 *iter = cpu_to_le32(chksum);
131 } else {
132 uint8_t *iter;
133 uint8_t chksum;
134
135 iter = (uint8_t *)buf;
136 chksum = 0;
137 for (cnt = 0; cnt < count - 1; cnt++)
138 chksum += *iter++;
139 chksum = ~chksum + 1;
140 *iter = chksum;
141 }
8482e112005-04-17 15:04:54 -0500142
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700143 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
144 qla_printk(KERN_WARNING, ha,
145 "HBA not online, failing NVRAM update.\n");
146 return -EAGAIN;
147 }
148
8482e112005-04-17 15:04:54 -0500149 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800150 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
151 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700152 count);
8482e112005-04-17 15:04:54 -0500153
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700154 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800155 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700156 qla2xxx_wake_dpc(vha);
157 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800158
8482e112005-04-17 15:04:54 -0500159 return (count);
160}
161
162static struct bin_attribute sysfs_nvram_attr = {
163 .attr = {
164 .name = "nvram",
165 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500166 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800167 .size = 512,
8482e112005-04-17 15:04:54 -0500168 .read = qla2x00_sysfs_read_nvram,
169 .write = qla2x00_sysfs_write_nvram,
170};
171
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800172static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800173qla2x00_sysfs_read_optrom(struct kobject *kobj,
174 struct bin_attribute *bin_attr,
175 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800176{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800177 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800178 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800179 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800180
181 if (ha->optrom_state != QLA_SREADING)
182 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800183
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700184 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
185 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800186}
187
188static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800189qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800192{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800193 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800194 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800195 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800196
197 if (ha->optrom_state != QLA_SWRITING)
198 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700199 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800200 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700201 if (off + count > ha->optrom_region_size)
202 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800203
204 memcpy(&ha->optrom_buffer[off], buf, count);
205
206 return count;
207}
208
209static struct bin_attribute sysfs_optrom_attr = {
210 .attr = {
211 .name = "optrom",
212 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800213 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700214 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800215 .read = qla2x00_sysfs_read_optrom,
216 .write = qla2x00_sysfs_write_optrom,
217};
218
219static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800220qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
221 struct bin_attribute *bin_attr,
222 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800223{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800224 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800225 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800226 struct qla_hw_data *ha = vha->hw;
227
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700228 uint32_t start = 0;
229 uint32_t size = ha->optrom_size;
230 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800231
232 if (off)
233 return 0;
234
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700235 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
236 return -EINVAL;
237 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800238 return -EINVAL;
239
240 switch (val) {
241 case 0:
242 if (ha->optrom_state != QLA_SREADING &&
243 ha->optrom_state != QLA_SWRITING)
244 break;
245
246 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700247
248 DEBUG2(qla_printk(KERN_INFO, ha,
249 "Freeing flash region allocation -- 0x%x bytes.\n",
250 ha->optrom_region_size));
251
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800252 vfree(ha->optrom_buffer);
253 ha->optrom_buffer = NULL;
254 break;
255 case 1:
256 if (ha->optrom_state != QLA_SWAITING)
257 break;
258
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700259 ha->optrom_region_start = start;
260 ha->optrom_region_size = start + size > ha->optrom_size ?
261 ha->optrom_size - start : size;
262
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800263 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700264 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800265 if (ha->optrom_buffer == NULL) {
266 qla_printk(KERN_WARNING, ha,
267 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700268 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269
270 ha->optrom_state = QLA_SWAITING;
271 return count;
272 }
273
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700274 DEBUG2(qla_printk(KERN_INFO, ha,
275 "Reading flash region -- 0x%x/0x%x.\n",
276 ha->optrom_region_start, ha->optrom_region_size));
277
278 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800279 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700280 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800281 break;
282 case 2:
283 if (ha->optrom_state != QLA_SWAITING)
284 break;
285
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700286 /*
287 * We need to be more restrictive on which FLASH regions are
288 * allowed to be updated via user-space. Regions accessible
289 * via this method include:
290 *
291 * ISP21xx/ISP22xx/ISP23xx type boards:
292 *
293 * 0x000000 -> 0x020000 -- Boot code.
294 *
295 * ISP2322/ISP24xx type boards:
296 *
297 * 0x000000 -> 0x07ffff -- Boot code.
298 * 0x080000 -> 0x0fffff -- Firmware.
299 *
300 * ISP25xx type boards:
301 *
302 * 0x000000 -> 0x07ffff -- Boot code.
303 * 0x080000 -> 0x0fffff -- Firmware.
304 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
305 */
306 valid = 0;
307 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
308 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700309 else if (start == (ha->flt_region_boot * 4) ||
310 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700311 valid = 1;
Andrew Vasquez6431c5d2009-03-05 11:07:00 -0800312 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700313 valid = 1;
314 if (!valid) {
315 qla_printk(KERN_WARNING, ha,
316 "Invalid start region 0x%x/0x%x.\n", start, size);
317 return -EINVAL;
318 }
319
320 ha->optrom_region_start = start;
321 ha->optrom_region_size = start + size > ha->optrom_size ?
322 ha->optrom_size - start : size;
323
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800324 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700325 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800326 if (ha->optrom_buffer == NULL) {
327 qla_printk(KERN_WARNING, ha,
328 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700329 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800330
331 ha->optrom_state = QLA_SWAITING;
332 return count;
333 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700334
335 DEBUG2(qla_printk(KERN_INFO, ha,
336 "Staging flash region write -- 0x%x/0x%x.\n",
337 ha->optrom_region_start, ha->optrom_region_size));
338
339 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800340 break;
341 case 3:
342 if (ha->optrom_state != QLA_SWRITING)
343 break;
344
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700345 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
346 qla_printk(KERN_WARNING, ha,
347 "HBA not online, failing flash update.\n");
348 return -EAGAIN;
349 }
350
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700351 DEBUG2(qla_printk(KERN_INFO, ha,
352 "Writing flash region -- 0x%x/0x%x.\n",
353 ha->optrom_region_start, ha->optrom_region_size));
354
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800355 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700356 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800357 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700358 default:
359 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800360 }
361 return count;
362}
363
364static struct bin_attribute sysfs_optrom_ctl_attr = {
365 .attr = {
366 .name = "optrom_ctl",
367 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800368 },
369 .size = 0,
370 .write = qla2x00_sysfs_write_optrom_ctl,
371};
372
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800373static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800374qla2x00_sysfs_read_vpd(struct kobject *kobj,
375 struct bin_attribute *bin_attr,
376 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800377{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800378 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800379 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800380 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800381
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700382 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800383 return 0;
384
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700385 if (IS_NOCACHE_VPD_TYPE(ha))
386 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
387 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700388 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800389}
390
391static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800392qla2x00_sysfs_write_vpd(struct kobject *kobj,
393 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;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700399 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800400
Andrew Vasquez3d790382009-03-24 09:08:14 -0700401 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
402 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800403 return 0;
404
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700405 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
406 qla_printk(KERN_WARNING, ha,
407 "HBA not online, failing VPD update.\n");
408 return -EAGAIN;
409 }
410
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800411 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800412 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
413 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800414
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700415 /* Update flash version information for 4Gb & above. */
416 if (!IS_FWI2_CAPABLE(ha))
417 goto done;
418
419 tmp_data = vmalloc(256);
420 if (!tmp_data) {
421 qla_printk(KERN_WARNING, ha,
422 "Unable to allocate memory for VPD information update.\n");
423 goto done;
424 }
425 ha->isp_ops->get_flash_version(vha, tmp_data);
426 vfree(tmp_data);
427done:
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800428 return count;
429}
430
431static struct bin_attribute sysfs_vpd_attr = {
432 .attr = {
433 .name = "vpd",
434 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800435 },
436 .size = 0,
437 .read = qla2x00_sysfs_read_vpd,
438 .write = qla2x00_sysfs_write_vpd,
439};
440
Andrew Vasquez88729e52006-06-23 16:10:50 -0700441static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800442qla2x00_sysfs_read_sfp(struct kobject *kobj,
443 struct bin_attribute *bin_attr,
444 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700445{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800446 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700447 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800448 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700449 uint16_t iter, addr, offset;
450 int rval;
451
452 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
453 return 0;
454
Andrew Vasqueze8711082008-01-31 12:33:48 -0800455 if (ha->sfp_data)
456 goto do_read;
457
458 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
459 &ha->sfp_data_dma);
460 if (!ha->sfp_data) {
461 qla_printk(KERN_WARNING, ha,
462 "Unable to allocate memory for SFP read-data.\n");
463 return 0;
464 }
465
466do_read:
467 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700468 addr = 0xa0;
469 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
470 iter++, offset += SFP_BLOCK_SIZE) {
471 if (iter == 4) {
472 /* Skip to next device address. */
473 addr = 0xa2;
474 offset = 0;
475 }
476
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800477 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700478 SFP_BLOCK_SIZE);
479 if (rval != QLA_SUCCESS) {
480 qla_printk(KERN_WARNING, ha,
481 "Unable to read SFP data (%x/%x/%x).\n", rval,
482 addr, offset);
483 count = 0;
484 break;
485 }
486 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
487 buf += SFP_BLOCK_SIZE;
488 }
489
490 return count;
491}
492
493static struct bin_attribute sysfs_sfp_attr = {
494 .attr = {
495 .name = "sfp",
496 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700497 },
498 .size = SFP_DEV_SIZE * 2,
499 .read = qla2x00_sysfs_read_sfp,
500};
501
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700502static ssize_t
503qla2x00_sysfs_write_reset(struct kobject *kobj,
504 struct bin_attribute *bin_attr,
505 char *buf, loff_t off, size_t count)
506{
507 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
508 struct device, kobj)));
509 struct qla_hw_data *ha = vha->hw;
510 int type;
511
512 if (off != 0)
513 return 0;
514
515 type = simple_strtol(buf, NULL, 10);
516 switch (type) {
517 case 0x2025c:
518 qla_printk(KERN_INFO, ha,
519 "Issuing ISP reset on (%ld).\n", vha->host_no);
520
521 scsi_block_requests(vha->host);
522 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
523 qla2xxx_wake_dpc(vha);
524 qla2x00_wait_for_chip_reset(vha);
525 scsi_unblock_requests(vha->host);
526 break;
527 case 0x2025d:
528 if (!IS_QLA81XX(ha))
529 break;
530
531 qla_printk(KERN_INFO, ha,
532 "Issuing MPI reset on (%ld).\n", vha->host_no);
533
534 /* Make sure FC side is not in reset */
535 qla2x00_wait_for_hba_online(vha);
536
537 /* Issue MPI reset */
538 scsi_block_requests(vha->host);
539 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
540 qla_printk(KERN_WARNING, ha,
541 "MPI reset failed on (%ld).\n", vha->host_no);
542 scsi_unblock_requests(vha->host);
543 break;
544 }
545 return count;
546}
547
548static struct bin_attribute sysfs_reset_attr = {
549 .attr = {
550 .name = "reset",
551 .mode = S_IWUSR,
552 },
553 .size = 0,
554 .write = qla2x00_sysfs_write_reset,
555};
556
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700557static ssize_t
558qla2x00_sysfs_write_edc(struct kobject *kobj,
559 struct bin_attribute *bin_attr,
560 char *buf, loff_t off, size_t count)
561{
562 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
563 struct device, kobj)));
564 struct qla_hw_data *ha = vha->hw;
565 uint16_t dev, adr, opt, len;
566 int rval;
567
568 ha->edc_data_len = 0;
569
570 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
571 return 0;
572
573 if (!ha->edc_data) {
574 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
575 &ha->edc_data_dma);
576 if (!ha->edc_data) {
577 DEBUG2(qla_printk(KERN_INFO, ha,
578 "Unable to allocate memory for EDC write.\n"));
579 return 0;
580 }
581 }
582
583 dev = le16_to_cpup((void *)&buf[0]);
584 adr = le16_to_cpup((void *)&buf[2]);
585 opt = le16_to_cpup((void *)&buf[4]);
586 len = le16_to_cpup((void *)&buf[6]);
587
588 if (!(opt & BIT_0))
589 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
590 return -EINVAL;
591
592 memcpy(ha->edc_data, &buf[8], len);
593
594 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
595 ha->edc_data, len, opt);
596 if (rval != QLA_SUCCESS) {
597 DEBUG2(qla_printk(KERN_INFO, ha,
598 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
599 rval, dev, adr, opt, len, *buf));
600 return 0;
601 }
602
603 return count;
604}
605
606static struct bin_attribute sysfs_edc_attr = {
607 .attr = {
608 .name = "edc",
609 .mode = S_IWUSR,
610 },
611 .size = 0,
612 .write = qla2x00_sysfs_write_edc,
613};
614
615static ssize_t
616qla2x00_sysfs_write_edc_status(struct kobject *kobj,
617 struct bin_attribute *bin_attr,
618 char *buf, loff_t off, size_t count)
619{
620 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
621 struct device, kobj)));
622 struct qla_hw_data *ha = vha->hw;
623 uint16_t dev, adr, opt, len;
624 int rval;
625
626 ha->edc_data_len = 0;
627
628 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
629 return 0;
630
631 if (!ha->edc_data) {
632 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
633 &ha->edc_data_dma);
634 if (!ha->edc_data) {
635 DEBUG2(qla_printk(KERN_INFO, ha,
636 "Unable to allocate memory for EDC status.\n"));
637 return 0;
638 }
639 }
640
641 dev = le16_to_cpup((void *)&buf[0]);
642 adr = le16_to_cpup((void *)&buf[2]);
643 opt = le16_to_cpup((void *)&buf[4]);
644 len = le16_to_cpup((void *)&buf[6]);
645
646 if (!(opt & BIT_0))
647 if (len == 0 || len > DMA_POOL_SIZE)
648 return -EINVAL;
649
650 memset(ha->edc_data, 0, len);
651 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
652 ha->edc_data, len, opt);
653 if (rval != QLA_SUCCESS) {
654 DEBUG2(qla_printk(KERN_INFO, ha,
655 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
656 rval, dev, adr, opt, len));
657 return 0;
658 }
659
660 ha->edc_data_len = len;
661
662 return count;
663}
664
665static ssize_t
666qla2x00_sysfs_read_edc_status(struct kobject *kobj,
667 struct bin_attribute *bin_attr,
668 char *buf, loff_t off, size_t count)
669{
670 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
671 struct device, kobj)));
672 struct qla_hw_data *ha = vha->hw;
673
674 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
675 return 0;
676
677 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
678 return -EINVAL;
679
680 memcpy(buf, ha->edc_data, ha->edc_data_len);
681
682 return ha->edc_data_len;
683}
684
685static struct bin_attribute sysfs_edc_status_attr = {
686 .attr = {
687 .name = "edc_status",
688 .mode = S_IRUSR | S_IWUSR,
689 },
690 .size = 0,
691 .write = qla2x00_sysfs_write_edc_status,
692 .read = qla2x00_sysfs_read_edc_status,
693};
694
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700695static ssize_t
696qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
697 struct bin_attribute *bin_attr,
698 char *buf, loff_t off, size_t count)
699{
700 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
701 struct device, kobj)));
702 struct qla_hw_data *ha = vha->hw;
703 int rval;
704 uint16_t actual_size;
705
706 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
707 return 0;
708
709 if (ha->xgmac_data)
710 goto do_read;
711
712 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
713 &ha->xgmac_data_dma, GFP_KERNEL);
714 if (!ha->xgmac_data) {
715 qla_printk(KERN_WARNING, ha,
716 "Unable to allocate memory for XGMAC read-data.\n");
717 return 0;
718 }
719
720do_read:
721 actual_size = 0;
722 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
723
724 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
725 XGMAC_DATA_SIZE, &actual_size);
726 if (rval != QLA_SUCCESS) {
727 qla_printk(KERN_WARNING, ha,
728 "Unable to read XGMAC data (%x).\n", rval);
729 count = 0;
730 }
731
732 count = actual_size > count ? count: actual_size;
733 memcpy(buf, ha->xgmac_data, count);
734
735 return count;
736}
737
738static struct bin_attribute sysfs_xgmac_stats_attr = {
739 .attr = {
740 .name = "xgmac_stats",
741 .mode = S_IRUSR,
742 },
743 .size = 0,
744 .read = qla2x00_sysfs_read_xgmac_stats,
745};
746
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700747static struct sysfs_entry {
748 char *name;
749 struct bin_attribute *attr;
750 int is4GBp_only;
751} bin_file_entries[] = {
752 { "fw_dump", &sysfs_fw_dump_attr, },
753 { "nvram", &sysfs_nvram_attr, },
754 { "optrom", &sysfs_optrom_attr, },
755 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
756 { "vpd", &sysfs_vpd_attr, 1 },
757 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700758 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700759 { "edc", &sysfs_edc_attr, 2 },
760 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700761 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800762 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700763};
764
8482e112005-04-17 15:04:54 -0500765void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800766qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500767{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800768 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700769 struct sysfs_entry *iter;
770 int ret;
8482e112005-04-17 15:04:54 -0500771
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700772 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800773 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700774 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700775 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
776 continue;
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700777 if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
778 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700779
780 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
781 iter->attr);
782 if (ret)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800783 qla_printk(KERN_INFO, vha->hw,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700784 "Unable to create sysfs %s binary attribute "
785 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700786 }
8482e112005-04-17 15:04:54 -0500787}
788
789void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800790qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500791{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800792 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700793 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800794 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500795
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700796 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700797 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700798 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700799 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
800 continue;
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700801 if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
802 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700803
Andrew Vasquez7914d002006-06-23 16:10:55 -0700804 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700805 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700806 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800807
808 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800809 ha->isp_ops->beacon_off(vha);
8482e112005-04-17 15:04:54 -0500810}
811
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700812/* Scsi_Host attributes. */
813
814static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100815qla2x00_drvr_version_show(struct device *dev,
816 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700817{
818 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
819}
820
821static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100822qla2x00_fw_version_show(struct device *dev,
823 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700824{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800825 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
826 struct qla_hw_data *ha = vha->hw;
827 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700828
829 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800830 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700831}
832
833static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100834qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
835 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700836{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800837 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
838 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700839 uint32_t sn;
840
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700841 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800842 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700843 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
844 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700845
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700846 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
847 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
848 sn % 100000);
849}
850
851static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100852qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
853 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700854{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800855 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
856 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700857}
858
859static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100860qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
861 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700862{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800863 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
864 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700865 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
866 ha->product_id[0], ha->product_id[1], ha->product_id[2],
867 ha->product_id[3]);
868}
869
870static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100871qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
872 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700873{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800874 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
875 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700876}
877
878static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100879qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
880 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700881{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800882 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700883 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800884 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700885}
886
887static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100888qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
889 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700890{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800891 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700892 char pci_info[30];
893
894 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700896}
897
898static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100899qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
900 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700901{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800902 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
903 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700904 int len = 0;
905
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800906 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
907 atomic_read(&vha->loop_state) == LOOP_DEAD)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700908 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800909 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
910 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
911 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700912 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
913 else {
914 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
915
916 switch (ha->current_topology) {
917 case ISP_CFG_NL:
918 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
919 break;
920 case ISP_CFG_FL:
921 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
922 break;
923 case ISP_CFG_N:
924 len += snprintf(buf + len, PAGE_SIZE-len,
925 "N_Port to N_Port\n");
926 break;
927 case ISP_CFG_F:
928 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
929 break;
930 default:
931 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
932 break;
933 }
934 }
935 return len;
936}
937
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700938static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100939qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
940 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700941{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800942 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700943 int len = 0;
944
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800945 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700946 case QLA_ZIO_MODE_6:
947 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
948 break;
949 case QLA_ZIO_DISABLED:
950 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
951 break;
952 }
953 return len;
954}
955
956static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100957qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
958 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700959{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800960 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
961 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700962 int val = 0;
963 uint16_t zio_mode;
964
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800965 if (!IS_ZIO_SUPPORTED(ha))
966 return -ENOTSUPP;
967
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700968 if (sscanf(buf, "%d", &val) != 1)
969 return -EINVAL;
970
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800971 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700972 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800973 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700974 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700975
976 /* Update per-hba values and queue a reset. */
977 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
978 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800979 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700980 }
981 return strlen(buf);
982}
983
984static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100985qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
986 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700987{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800988 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700989
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800990 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700991}
992
993static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100994qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
995 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700996{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700998 int val = 0;
999 uint16_t zio_timer;
1000
1001 if (sscanf(buf, "%d", &val) != 1)
1002 return -EINVAL;
1003 if (val > 25500 || val < 100)
1004 return -ERANGE;
1005
1006 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001008
1009 return strlen(buf);
1010}
1011
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001012static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001013qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1014 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001015{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001016 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001017 int len = 0;
1018
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001019 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001020 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1021 else
1022 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1023 return len;
1024}
1025
1026static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001027qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1028 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001029{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001030 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1031 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001032 int val = 0;
1033 int rval;
1034
1035 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1036 return -EPERM;
1037
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001038 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001039 qla_printk(KERN_WARNING, ha,
1040 "Abort ISP active -- ignoring beacon request.\n");
1041 return -EBUSY;
1042 }
1043
1044 if (sscanf(buf, "%d", &val) != 1)
1045 return -EINVAL;
1046
1047 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001048 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001049 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001051
1052 if (rval != QLA_SUCCESS)
1053 count = 0;
1054
1055 return count;
1056}
1057
Andrew Vasquez30c47662007-01-29 10:22:21 -08001058static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001059qla2x00_optrom_bios_version_show(struct device *dev,
1060 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001061{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001062 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1063 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001064 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1065 ha->bios_revision[0]);
1066}
1067
1068static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001069qla2x00_optrom_efi_version_show(struct device *dev,
1070 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001071{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1073 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001074 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1075 ha->efi_revision[0]);
1076}
1077
1078static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001079qla2x00_optrom_fcode_version_show(struct device *dev,
1080 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001081{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001082 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1083 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001084 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1085 ha->fcode_revision[0]);
1086}
1087
1088static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001089qla2x00_optrom_fw_version_show(struct device *dev,
1090 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001091{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001092 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1093 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001094 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1095 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1096 ha->fw_revision[3]);
1097}
1098
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001099static ssize_t
1100qla2x00_total_isp_aborts_show(struct device *dev,
1101 struct device_attribute *attr, char *buf)
1102{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001103 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1104 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001105 return snprintf(buf, PAGE_SIZE, "%d\n",
1106 ha->qla_stats.total_isp_aborts);
1107}
1108
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001109static ssize_t
1110qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1111 char *buf)
1112{
1113 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1114 struct qla_hw_data *ha = vha->hw;
1115
1116 if (!IS_QLA81XX(ha))
1117 return snprintf(buf, PAGE_SIZE, "\n");
1118
Andrew Vasquez55a96152009-03-24 09:08:03 -07001119 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001120 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001121 ha->mpi_capabilities);
1122}
1123
1124static ssize_t
1125qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1126 char *buf)
1127{
1128 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1129 struct qla_hw_data *ha = vha->hw;
1130
1131 if (!IS_QLA81XX(ha))
1132 return snprintf(buf, PAGE_SIZE, "\n");
1133
1134 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1135 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001136}
1137
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001138static ssize_t
1139qla2x00_flash_block_size_show(struct device *dev,
1140 struct device_attribute *attr, char *buf)
1141{
1142 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1143 struct qla_hw_data *ha = vha->hw;
1144
1145 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1146}
1147
Andrew Vasquezbad70012009-04-06 22:33:38 -07001148static ssize_t
1149qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1150 char *buf)
1151{
1152 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1153
1154 if (!IS_QLA81XX(vha->hw))
1155 return snprintf(buf, PAGE_SIZE, "\n");
1156
1157 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1158}
1159
1160static ssize_t
1161qla2x00_vn_port_mac_address_show(struct device *dev,
1162 struct device_attribute *attr, char *buf)
1163{
1164 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1165
1166 if (!IS_QLA81XX(vha->hw))
1167 return snprintf(buf, PAGE_SIZE, "\n");
1168
1169 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1170 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1171 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1172 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1173}
1174
Andrew Vasquez7f774022009-06-03 09:55:12 -07001175static ssize_t
1176qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1177 char *buf)
1178{
1179 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1180
1181 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1182}
1183
Tony Jonesee959b02008-02-22 00:13:36 +01001184static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1185static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1186static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1187static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1188static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1189static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1190static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1191static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001192static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001193static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1194static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1195 qla2x00_zio_timer_store);
1196static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1197 qla2x00_beacon_store);
1198static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1199 qla2x00_optrom_bios_version_show, NULL);
1200static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1201 qla2x00_optrom_efi_version_show, NULL);
1202static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1203 qla2x00_optrom_fcode_version_show, NULL);
1204static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1205 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001206static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1207 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001208static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001209static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001210static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1211 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001212static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1213static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1214 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001215static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001216
Tony Jonesee959b02008-02-22 00:13:36 +01001217struct device_attribute *qla2x00_host_attrs[] = {
1218 &dev_attr_driver_version,
1219 &dev_attr_fw_version,
1220 &dev_attr_serial_num,
1221 &dev_attr_isp_name,
1222 &dev_attr_isp_id,
1223 &dev_attr_model_name,
1224 &dev_attr_model_desc,
1225 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001226 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001227 &dev_attr_zio,
1228 &dev_attr_zio_timer,
1229 &dev_attr_beacon,
1230 &dev_attr_optrom_bios_version,
1231 &dev_attr_optrom_efi_version,
1232 &dev_attr_optrom_fcode_version,
1233 &dev_attr_optrom_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001234 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001235 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001236 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001237 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001238 &dev_attr_vlan_id,
1239 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001240 &dev_attr_fabric_param,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001241 NULL,
1242};
1243
8482e112005-04-17 15:04:54 -05001244/* Host attributes. */
1245
1246static void
1247qla2x00_get_host_port_id(struct Scsi_Host *shost)
1248{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001249 scsi_qla_host_t *vha = shost_priv(shost);
8482e112005-04-17 15:04:54 -05001250
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001251 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1252 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e112005-04-17 15:04:54 -05001253}
1254
1255static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001256qla2x00_get_host_speed(struct Scsi_Host *shost)
1257{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001258 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1259 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001260 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001261
1262 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001263 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001264 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001265 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001266 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001267 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001268 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001269 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001270 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001271 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001272 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001273 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001274 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001275 case PORT_SPEED_10GB:
1276 speed = FC_PORTSPEED_10GBIT;
1277 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001278 }
1279 fc_host_speed(shost) = speed;
1280}
1281
1282static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001283qla2x00_get_host_port_type(struct Scsi_Host *shost)
1284{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001285 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001286 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1287
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001288 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001289 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1290 return;
1291 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001292 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001293 case ISP_CFG_NL:
1294 port_type = FC_PORTTYPE_LPORT;
1295 break;
1296 case ISP_CFG_FL:
1297 port_type = FC_PORTTYPE_NLPORT;
1298 break;
1299 case ISP_CFG_N:
1300 port_type = FC_PORTTYPE_PTP;
1301 break;
1302 case ISP_CFG_F:
1303 port_type = FC_PORTTYPE_NPORT;
1304 break;
1305 }
1306 fc_host_port_type(shost) = port_type;
1307}
1308
1309static void
8482e112005-04-17 15:04:54 -05001310qla2x00_get_starget_node_name(struct scsi_target *starget)
1311{
1312 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001313 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001314 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001315 u64 node_name = 0;
8482e112005-04-17 15:04:54 -05001316
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001317 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001318 if (fcport->rport &&
1319 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001320 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001321 break;
1322 }
1323 }
1324
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001325 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -05001326}
1327
1328static void
1329qla2x00_get_starget_port_name(struct scsi_target *starget)
1330{
1331 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001332 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001333 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001334 u64 port_name = 0;
8482e112005-04-17 15:04:54 -05001335
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001336 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001337 if (fcport->rport &&
1338 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001339 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001340 break;
1341 }
1342 }
1343
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001344 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -05001345}
1346
1347static void
1348qla2x00_get_starget_port_id(struct scsi_target *starget)
1349{
1350 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001351 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001352 fc_port_t *fcport;
1353 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -05001354
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001355 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001356 if (fcport->rport &&
1357 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001358 port_id = fcport->d_id.b.domain << 16 |
1359 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1360 break;
1361 }
1362 }
1363
8482e112005-04-17 15:04:54 -05001364 fc_starget_port_id(starget) = port_id;
1365}
1366
1367static void
8482e112005-04-17 15:04:54 -05001368qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1369{
8482e112005-04-17 15:04:54 -05001370 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001371 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -05001372 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001373 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -05001374}
1375
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001376static void
1377qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1378{
1379 struct Scsi_Host *host = rport_to_shost(rport);
1380 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1381
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001382 if (!fcport)
1383 return;
1384
Seokmann Jub9b12f72009-03-24 09:08:18 -07001385 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev)))
1386 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1387 else
1388 qla2x00_abort_fcport_cmds(fcport);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001389
1390 /*
1391 * Transport has effectively 'deleted' the rport, clear
1392 * all local references.
1393 */
1394 spin_lock_irq(host->host_lock);
1395 fcport->rport = NULL;
1396 *((fc_port_t **)rport->dd_data) = NULL;
1397 spin_unlock_irq(host->host_lock);
1398}
1399
1400static void
1401qla2x00_terminate_rport_io(struct fc_rport *rport)
1402{
1403 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1404
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001405 if (!fcport)
1406 return;
1407
Seokmann Jub9b12f72009-03-24 09:08:18 -07001408 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1409 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1410 return;
1411 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001412 /*
1413 * At this point all fcport's software-states are cleared. Perform any
1414 * final cleanup of firmware resources (PCBs and XCBs).
1415 */
Andrew Vasquezbe67e652009-03-24 09:08:02 -07001416 if (fcport->loop_id != FC_NO_LOOP_ID)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001417 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1418 fcport->loop_id, fcport->d_id.b.domain,
1419 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001420
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001421 qla2x00_abort_fcport_cmds(fcport);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001422}
1423
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001424static int
1425qla2x00_issue_lip(struct Scsi_Host *shost)
1426{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001427 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001428
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001429 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001430 return 0;
1431}
1432
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001433static struct fc_host_statistics *
1434qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1435{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001436 scsi_qla_host_t *vha = shost_priv(shost);
1437 struct qla_hw_data *ha = vha->hw;
1438 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001439 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001440 struct link_statistics *stats;
1441 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001442 struct fc_host_statistics *pfc_host_stat;
1443
1444 pfc_host_stat = &ha->fc_host_stat;
1445 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1446
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001447 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1448 if (stats == NULL) {
1449 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001450 __func__, base_vha->host_no));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001451 goto done;
1452 }
1453 memset(stats, 0, DMA_POOL_SIZE);
1454
1455 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001456 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001457 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1458 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1459 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1460 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001461 !ha->dpc_active) {
1462 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001463 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1464 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001465 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001466
1467 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001468 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001469
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001470 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1471 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1472 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1473 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1474 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1475 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1476 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001477 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001478 pfc_host_stat->tx_frames = stats->tx_frames;
1479 pfc_host_stat->rx_frames = stats->rx_frames;
1480 pfc_host_stat->dumped_frames = stats->dumped_frames;
1481 pfc_host_stat->nos_count = stats->nos_rcvd;
1482 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001483 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1484 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001485
1486done_free:
1487 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001488done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001489 return pfc_host_stat;
1490}
1491
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001492static void
1493qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1494{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001495 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001496
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001497 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001498}
1499
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001500static void
1501qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1502{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001504
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001505 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001506}
1507
Andrew Vasquez90991c82006-10-02 12:00:46 -07001508static void
1509qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1510{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001511 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001512 u64 node_name;
1513
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001514 if (vha->device_flags & SWITCH_FOUND)
1515 node_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001516 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001517 node_name = wwn_to_u64(vha->node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001518
1519 fc_host_fabric_name(shost) = node_name;
1520}
1521
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001522static void
1523qla2x00_get_host_port_state(struct Scsi_Host *shost)
1524{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001525 scsi_qla_host_t *vha = shost_priv(shost);
1526 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001527
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001528 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001529 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001530 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001531 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1532 else
1533 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1534}
1535
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001536static int
1537qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1538{
1539 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001540 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001541 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1542 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001543 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001544 uint16_t options = 0;
1545 int cnt;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001546
1547 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1548 if (ret) {
1549 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1550 "status %x\n", ret));
1551 return (ret);
1552 }
1553
1554 vha = qla24xx_create_vhost(fc_vport);
1555 if (vha == NULL) {
1556 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1557 vha));
1558 return FC_VPORT_FAILED;
1559 }
1560 if (disable) {
1561 atomic_set(&vha->vp_state, VP_OFFLINE);
1562 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1563 } else
1564 atomic_set(&vha->vp_state, VP_FAILED);
1565
1566 /* ready to create vport */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001567 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1568 vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001569
1570 /* initialized vport states */
1571 atomic_set(&vha->loop_state, LOOP_DOWN);
1572 vha->vp_err_state= VP_ERR_PORTDWN;
1573 vha->vp_prev_err_state= VP_ERR_UNKWN;
1574 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001575 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1576 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001577 /* Don't retry or attempt login of this virtual port */
1578 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001579 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001580 atomic_set(&vha->loop_state, LOOP_DEAD);
1581 if (!disable)
1582 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1583 }
1584
1585 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1586 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1587 vha->host_no, vha->vp_idx));
1588 goto vport_create_failed_2;
1589 }
1590
1591 /* initialize attributes */
1592 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1593 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1594 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001595 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001596 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001597 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001598
1599 qla24xx_vport_disable(fc_vport, disable);
1600
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001601 ret = 0;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001602 if (ha->cur_vport_count <= ha->flex_port_count || ql2xmultique_tag
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001603 || ha->max_req_queues == 1 || !ha->npiv_info)
1604 goto vport_queue;
1605 /* Create a request queue in QoS mode for the vport */
1606 for (cnt = ha->flex_port_count; cnt < ha->nvram_npiv_size; cnt++) {
1607 if (ha->npiv_info[cnt].port_name == vha->port_name &&
1608 ha->npiv_info[cnt].node_name == vha->node_name) {
1609 qos = ha->npiv_info[cnt].q_qos;
1610 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001611 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001612 }
1613 if (qos) {
1614 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1615 qos);
1616 if (!ret)
1617 qla_printk(KERN_WARNING, ha,
1618 "Can't create request queue for vp_idx:%d\n",
1619 vha->vp_idx);
1620 else
1621 DEBUG2(qla_printk(KERN_INFO, ha,
1622 "Request Que:%d created for vp_idx:%d\n",
1623 ret, vha->vp_idx));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001624 }
1625
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001626vport_queue:
1627 vha->req = ha->req_q_map[ret];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001628 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001629
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001630vport_create_failed_2:
1631 qla24xx_disable_vp(vha);
1632 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001633 scsi_host_put(vha->host);
1634 return FC_VPORT_FAILED;
1635}
1636
Adrian Bunka824ebb2008-01-17 09:02:15 -08001637static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001638qla24xx_vport_delete(struct fc_vport *fc_vport)
1639{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001640 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001641 fc_port_t *fcport, *tfcport;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001642 struct qla_hw_data *ha = vha->hw;
1643 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001644
1645 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001646 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001647 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001648
1649 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001650
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001651 fc_remove_host(vha->host);
1652
1653 scsi_remove_host(vha->host);
1654
1655 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1656 list_del(&fcport->list);
1657 kfree(fcport);
1658 fcport = NULL;
1659 }
1660
1661 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001662
1663 if (vha->timer_active) {
1664 qla2x00_vp_stop_timer(vha);
1665 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1666 "has stopped\n",
1667 vha->host_no, vha->vp_idx, vha));
1668 }
1669
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001670 if (vha->req->id && !ql2xmultique_tag) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001671 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001672 qla_printk(KERN_WARNING, ha,
1673 "Queue delete failed.\n");
1674 }
1675
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001676 scsi_host_put(vha->host);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001677 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001678 return 0;
1679}
1680
Adrian Bunka824ebb2008-01-17 09:02:15 -08001681static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001682qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1683{
1684 scsi_qla_host_t *vha = fc_vport->dd_data;
1685
1686 if (disable)
1687 qla24xx_disable_vp(vha);
1688 else
1689 qla24xx_enable_vp(vha);
1690
1691 return 0;
1692}
1693
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001694struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001695
1696 .show_host_node_name = 1,
1697 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001698 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001699 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001700
8482e112005-04-17 15:04:54 -05001701 .get_host_port_id = qla2x00_get_host_port_id,
1702 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001703 .get_host_speed = qla2x00_get_host_speed,
1704 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001705 .get_host_port_type = qla2x00_get_host_port_type,
1706 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001707 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1708 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001709 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1710 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001711 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1712 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001713 .get_host_port_state = qla2x00_get_host_port_state,
1714 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001715
bdf79622005-04-17 15:06:53 -05001716 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001717 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001718
1719 .get_starget_node_name = qla2x00_get_starget_node_name,
1720 .show_starget_node_name = 1,
1721 .get_starget_port_name = qla2x00_get_starget_port_name,
1722 .show_starget_port_name = 1,
1723 .get_starget_port_id = qla2x00_get_starget_port_id,
1724 .show_starget_port_id = 1,
1725
8482e112005-04-17 15:04:54 -05001726 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1727 .show_rport_dev_loss_tmo = 1,
1728
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001729 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001730 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1731 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001732 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001733
1734 .vport_create = qla24xx_vport_create,
1735 .vport_disable = qla24xx_vport_disable,
1736 .vport_delete = qla24xx_vport_delete,
1737};
1738
1739struct fc_function_template qla2xxx_transport_vport_functions = {
1740
1741 .show_host_node_name = 1,
1742 .show_host_port_name = 1,
1743 .show_host_supported_classes = 1,
1744
1745 .get_host_port_id = qla2x00_get_host_port_id,
1746 .show_host_port_id = 1,
1747 .get_host_speed = qla2x00_get_host_speed,
1748 .show_host_speed = 1,
1749 .get_host_port_type = qla2x00_get_host_port_type,
1750 .show_host_port_type = 1,
1751 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1752 .show_host_symbolic_name = 1,
1753 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1754 .show_host_system_hostname = 1,
1755 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1756 .show_host_fabric_name = 1,
1757 .get_host_port_state = qla2x00_get_host_port_state,
1758 .show_host_port_state = 1,
1759
1760 .dd_fcrport_size = sizeof(struct fc_port *),
1761 .show_rport_supported_classes = 1,
1762
1763 .get_starget_node_name = qla2x00_get_starget_node_name,
1764 .show_starget_node_name = 1,
1765 .get_starget_port_name = qla2x00_get_starget_port_name,
1766 .show_starget_port_name = 1,
1767 .get_starget_port_id = qla2x00_get_starget_port_id,
1768 .show_starget_port_id = 1,
1769
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001770 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1771 .show_rport_dev_loss_tmo = 1,
1772
1773 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001774 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1775 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001776 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -05001777};
1778
8482e112005-04-17 15:04:54 -05001779void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001780qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -05001781{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001782 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001783 u32 speed = FC_PORTSPEED_UNKNOWN;
1784
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001785 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1786 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1787 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1788 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1789 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001790
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001791 if (IS_QLA81XX(ha))
1792 speed = FC_PORTSPEED_10GBIT;
1793 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001794 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1795 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001796 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001797 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1798 FC_PORTSPEED_1GBIT;
1799 else if (IS_QLA23XX(ha))
1800 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1801 else
1802 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001803 fc_host_supported_speeds(vha->host) = speed;
8482e112005-04-17 15:04:54 -05001804}