blob: fd6f7b10054798a73175e21bbdb07ae42d75e29d [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090012#include <linux/delay.h>
8482e112005-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
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050026
27 if (ha->fw_dump_reading == 0)
28 return 0;
8482e112005-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);
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -050040 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080041 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -050042 int reading;
8482e112005-04-17 15:04:54 -050043
Giridhar Malavalia9083012010-04-12 17:59:55 -070044 if (IS_QLA82XX(ha)) {
45 DEBUG2(qla_printk(KERN_INFO, ha,
46 "Firmware dump not supported for ISP82xx\n"));
47 return count;
48 }
49
8482e112005-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;
8482e112005-04-17 15:04:54 -050058
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070059 qla_printk(KERN_INFO, ha,
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;
8482e112005-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) {
8482e112005-04-17 15:04:54 -050067 ha->fw_dump_reading = 1;
68
8482e112005-04-17 15:04:54 -050069 qla_printk(KERN_INFO, ha,
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);
8482e112005-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;
8482e112005-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,
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -0500100 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800101 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500102
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700103 if (!capable(CAP_SYS_ADMIN))
8482e112005-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);
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -0500119 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800120 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500121 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500122
Andrew Vasquez3d790382009-03-24 09:08:14 -0700123 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
124 !ha->isp_ops->write_nvram)
8482e112005-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 }
8482e112005-04-17 15:04:54 -0500149
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700150 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
151 qla_printk(KERN_WARNING, ha,
152 "HBA not online, failing NVRAM update.\n");
153 return -EAGAIN;
154 }
155
8482e112005-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);
8482e112005-04-17 15:04:54 -0500160
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700161 /* NVRAM settings take effect immediately. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800162 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700163 qla2xxx_wake_dpc(vha);
164 qla2x00_wait_for_chip_reset(vha);
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800165
8482e112005-04-17 15:04:54 -0500166 return (count);
167}
168
169static struct bin_attribute sysfs_nvram_attr = {
170 .attr = {
171 .name = "nvram",
172 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500173 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800174 .size = 512,
8482e112005-04-17 15:04:54 -0500175 .read = qla2x00_sysfs_read_nvram,
176 .write = qla2x00_sysfs_write_nvram,
177};
178
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800179static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700180qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800181 struct bin_attribute *bin_attr,
182 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800183{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800184 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800185 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800187
188 if (ha->optrom_state != QLA_SREADING)
189 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800190
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700191 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
192 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800193}
194
195static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700196qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800197 struct bin_attribute *bin_attr,
198 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800199{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800200 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800201 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800202 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800203
204 if (ha->optrom_state != QLA_SWRITING)
205 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700206 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800207 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700208 if (off + count > ha->optrom_region_size)
209 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800210
211 memcpy(&ha->optrom_buffer[off], buf, count);
212
213 return count;
214}
215
216static struct bin_attribute sysfs_optrom_attr = {
217 .attr = {
218 .name = "optrom",
219 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800220 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700221 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800222 .read = qla2x00_sysfs_read_optrom,
223 .write = qla2x00_sysfs_write_optrom,
224};
225
226static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700227qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800228 struct bin_attribute *bin_attr,
229 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800230{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800231 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 struct qla_hw_data *ha = vha->hw;
234
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700235 uint32_t start = 0;
236 uint32_t size = ha->optrom_size;
237 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800238
239 if (off)
240 return 0;
241
Andrew Vasquez85880802009-12-15 21:29:46 -0800242 if (unlikely(pci_channel_offline(ha->pdev)))
243 return 0;
244
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700245 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
246 return -EINVAL;
247 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800248 return -EINVAL;
249
250 switch (val) {
251 case 0:
252 if (ha->optrom_state != QLA_SREADING &&
253 ha->optrom_state != QLA_SWRITING)
254 break;
255
256 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700257
258 DEBUG2(qla_printk(KERN_INFO, ha,
259 "Freeing flash region allocation -- 0x%x bytes.\n",
260 ha->optrom_region_size));
261
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800262 vfree(ha->optrom_buffer);
263 ha->optrom_buffer = NULL;
264 break;
265 case 1:
266 if (ha->optrom_state != QLA_SWAITING)
267 break;
268
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700269 ha->optrom_region_start = start;
270 ha->optrom_region_size = start + size > ha->optrom_size ?
271 ha->optrom_size - start : size;
272
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800273 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700274 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800275 if (ha->optrom_buffer == NULL) {
276 qla_printk(KERN_WARNING, ha,
277 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700278 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800279
280 ha->optrom_state = QLA_SWAITING;
281 return count;
282 }
283
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700284 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
285 qla_printk(KERN_WARNING, ha,
286 "HBA not online, failing NVRAM update.\n");
287 return -EAGAIN;
288 }
289
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700290 DEBUG2(qla_printk(KERN_INFO, ha,
291 "Reading flash region -- 0x%x/0x%x.\n",
292 ha->optrom_region_start, ha->optrom_region_size));
293
294 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800295 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700296 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800297 break;
298 case 2:
299 if (ha->optrom_state != QLA_SWAITING)
300 break;
301
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700302 /*
303 * We need to be more restrictive on which FLASH regions are
304 * allowed to be updated via user-space. Regions accessible
305 * via this method include:
306 *
307 * ISP21xx/ISP22xx/ISP23xx type boards:
308 *
309 * 0x000000 -> 0x020000 -- Boot code.
310 *
311 * ISP2322/ISP24xx type boards:
312 *
313 * 0x000000 -> 0x07ffff -- Boot code.
314 * 0x080000 -> 0x0fffff -- Firmware.
315 *
316 * ISP25xx type boards:
317 *
318 * 0x000000 -> 0x07ffff -- Boot code.
319 * 0x080000 -> 0x0fffff -- Firmware.
320 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
321 */
322 valid = 0;
323 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
324 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700325 else if (start == (ha->flt_region_boot * 4) ||
326 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700327 valid = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700328 else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
329 valid = 1;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700330 if (!valid) {
331 qla_printk(KERN_WARNING, ha,
332 "Invalid start region 0x%x/0x%x.\n", start, size);
333 return -EINVAL;
334 }
335
336 ha->optrom_region_start = start;
337 ha->optrom_region_size = start + size > ha->optrom_size ?
338 ha->optrom_size - start : size;
339
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800340 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700341 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800342 if (ha->optrom_buffer == NULL) {
343 qla_printk(KERN_WARNING, ha,
344 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700345 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800346
347 ha->optrom_state = QLA_SWAITING;
348 return count;
349 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700350
351 DEBUG2(qla_printk(KERN_INFO, ha,
352 "Staging flash region write -- 0x%x/0x%x.\n",
353 ha->optrom_region_start, ha->optrom_region_size));
354
355 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800356 break;
357 case 3:
358 if (ha->optrom_state != QLA_SWRITING)
359 break;
360
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700361 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
362 qla_printk(KERN_WARNING, ha,
363 "HBA not online, failing flash update.\n");
364 return -EAGAIN;
365 }
366
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700367 DEBUG2(qla_printk(KERN_INFO, ha,
368 "Writing flash region -- 0x%x/0x%x.\n",
369 ha->optrom_region_start, ha->optrom_region_size));
370
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800371 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700372 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800373 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700374 default:
375 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800376 }
377 return count;
378}
379
380static struct bin_attribute sysfs_optrom_ctl_attr = {
381 .attr = {
382 .name = "optrom_ctl",
383 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800384 },
385 .size = 0,
386 .write = qla2x00_sysfs_write_optrom_ctl,
387};
388
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800389static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700390qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800391 struct bin_attribute *bin_attr,
392 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800393{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800394 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800395 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800396 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800397
Andrew Vasquez85880802009-12-15 21:29:46 -0800398 if (unlikely(pci_channel_offline(ha->pdev)))
399 return 0;
400
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700401 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800402 return 0;
403
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700404 if (IS_NOCACHE_VPD_TYPE(ha))
405 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
406 ha->vpd_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700407 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800408}
409
410static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700411qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800412 struct bin_attribute *bin_attr,
413 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800414{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800415 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800416 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800417 struct qla_hw_data *ha = vha->hw;
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700418 uint8_t *tmp_data;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800419
Andrew Vasquez85880802009-12-15 21:29:46 -0800420 if (unlikely(pci_channel_offline(ha->pdev)))
421 return 0;
422
Andrew Vasquez3d790382009-03-24 09:08:14 -0700423 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
424 !ha->isp_ops->write_nvram)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800425 return 0;
426
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700427 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
428 qla_printk(KERN_WARNING, ha,
429 "HBA not online, failing VPD update.\n");
430 return -EAGAIN;
431 }
432
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800433 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800434 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
435 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800436
Lalit Chandivaded0c3eef2009-03-24 09:08:09 -0700437 /* Update flash version information for 4Gb & above. */
438 if (!IS_FWI2_CAPABLE(ha))
439 goto done;
440
441 tmp_data = vmalloc(256);
442 if (!tmp_data) {
443 qla_printk(KERN_WARNING, ha,
444 "Unable to allocate memory for VPD information update.\n");
445 goto done;
446 }
447 ha->isp_ops->get_flash_version(vha, tmp_data);
448 vfree(tmp_data);
449done:
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800450 return count;
451}
452
453static struct bin_attribute sysfs_vpd_attr = {
454 .attr = {
455 .name = "vpd",
456 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800457 },
458 .size = 0,
459 .read = qla2x00_sysfs_read_vpd,
460 .write = qla2x00_sysfs_write_vpd,
461};
462
Andrew Vasquez88729e52006-06-23 16:10:50 -0700463static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700464qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800465 struct bin_attribute *bin_attr,
466 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700467{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800468 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700469 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800470 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez88729e52006-06-23 16:10:50 -0700471 uint16_t iter, addr, offset;
472 int rval;
473
474 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
475 return 0;
476
Andrew Vasqueze8711082008-01-31 12:33:48 -0800477 if (ha->sfp_data)
478 goto do_read;
479
480 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
481 &ha->sfp_data_dma);
482 if (!ha->sfp_data) {
483 qla_printk(KERN_WARNING, ha,
484 "Unable to allocate memory for SFP read-data.\n");
485 return 0;
486 }
487
488do_read:
489 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700490 addr = 0xa0;
491 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
492 iter++, offset += SFP_BLOCK_SIZE) {
493 if (iter == 4) {
494 /* Skip to next device address. */
495 addr = 0xa2;
496 offset = 0;
497 }
498
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800499 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700500 SFP_BLOCK_SIZE);
501 if (rval != QLA_SUCCESS) {
502 qla_printk(KERN_WARNING, ha,
503 "Unable to read SFP data (%x/%x/%x).\n", rval,
504 addr, offset);
505 count = 0;
506 break;
507 }
508 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
509 buf += SFP_BLOCK_SIZE;
510 }
511
512 return count;
513}
514
515static struct bin_attribute sysfs_sfp_attr = {
516 .attr = {
517 .name = "sfp",
518 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700519 },
520 .size = SFP_DEV_SIZE * 2,
521 .read = qla2x00_sysfs_read_sfp,
522};
523
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700524static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700525qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700526 struct bin_attribute *bin_attr,
527 char *buf, loff_t off, size_t count)
528{
529 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
530 struct device, kobj)));
531 struct qla_hw_data *ha = vha->hw;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700532 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700533 int type;
534
535 if (off != 0)
536 return 0;
537
538 type = simple_strtol(buf, NULL, 10);
539 switch (type) {
540 case 0x2025c:
541 qla_printk(KERN_INFO, ha,
542 "Issuing ISP reset on (%ld).\n", vha->host_no);
543
544 scsi_block_requests(vha->host);
545 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
546 qla2xxx_wake_dpc(vha);
547 qla2x00_wait_for_chip_reset(vha);
548 scsi_unblock_requests(vha->host);
549 break;
550 case 0x2025d:
551 if (!IS_QLA81XX(ha))
552 break;
553
554 qla_printk(KERN_INFO, ha,
555 "Issuing MPI reset on (%ld).\n", vha->host_no);
556
557 /* Make sure FC side is not in reset */
558 qla2x00_wait_for_hba_online(vha);
559
560 /* Issue MPI reset */
561 scsi_block_requests(vha->host);
562 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
563 qla_printk(KERN_WARNING, ha,
564 "MPI reset failed on (%ld).\n", vha->host_no);
565 scsi_unblock_requests(vha->host);
566 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700567 case 0x2025e:
568 if (!IS_QLA82XX(ha) || vha != base_vha) {
569 qla_printk(KERN_INFO, ha,
570 "FCoE ctx reset not supported for host%ld.\n",
571 vha->host_no);
572 return count;
573 }
574
575 qla_printk(KERN_INFO, ha,
576 "Issuing FCoE CTX reset on host%ld.\n", vha->host_no);
577 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
578 qla2xxx_wake_dpc(vha);
579 qla2x00_wait_for_fcoe_ctx_reset(vha);
580 break;
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700581 }
582 return count;
583}
584
585static struct bin_attribute sysfs_reset_attr = {
586 .attr = {
587 .name = "reset",
588 .mode = S_IWUSR,
589 },
590 .size = 0,
591 .write = qla2x00_sysfs_write_reset,
592};
593
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700594static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700595qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700596 struct bin_attribute *bin_attr,
597 char *buf, loff_t off, size_t count)
598{
599 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
600 struct device, kobj)));
601 struct qla_hw_data *ha = vha->hw;
602 uint16_t dev, adr, opt, len;
603 int rval;
604
605 ha->edc_data_len = 0;
606
607 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
608 return 0;
609
610 if (!ha->edc_data) {
611 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
612 &ha->edc_data_dma);
613 if (!ha->edc_data) {
614 DEBUG2(qla_printk(KERN_INFO, ha,
615 "Unable to allocate memory for EDC write.\n"));
616 return 0;
617 }
618 }
619
620 dev = le16_to_cpup((void *)&buf[0]);
621 adr = le16_to_cpup((void *)&buf[2]);
622 opt = le16_to_cpup((void *)&buf[4]);
623 len = le16_to_cpup((void *)&buf[6]);
624
625 if (!(opt & BIT_0))
626 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
627 return -EINVAL;
628
629 memcpy(ha->edc_data, &buf[8], len);
630
631 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
632 ha->edc_data, len, opt);
633 if (rval != QLA_SUCCESS) {
634 DEBUG2(qla_printk(KERN_INFO, ha,
635 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
636 rval, dev, adr, opt, len, *buf));
637 return 0;
638 }
639
640 return count;
641}
642
643static struct bin_attribute sysfs_edc_attr = {
644 .attr = {
645 .name = "edc",
646 .mode = S_IWUSR,
647 },
648 .size = 0,
649 .write = qla2x00_sysfs_write_edc,
650};
651
652static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700653qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700654 struct bin_attribute *bin_attr,
655 char *buf, loff_t off, size_t count)
656{
657 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
658 struct device, kobj)));
659 struct qla_hw_data *ha = vha->hw;
660 uint16_t dev, adr, opt, len;
661 int rval;
662
663 ha->edc_data_len = 0;
664
665 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
666 return 0;
667
668 if (!ha->edc_data) {
669 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
670 &ha->edc_data_dma);
671 if (!ha->edc_data) {
672 DEBUG2(qla_printk(KERN_INFO, ha,
673 "Unable to allocate memory for EDC status.\n"));
674 return 0;
675 }
676 }
677
678 dev = le16_to_cpup((void *)&buf[0]);
679 adr = le16_to_cpup((void *)&buf[2]);
680 opt = le16_to_cpup((void *)&buf[4]);
681 len = le16_to_cpup((void *)&buf[6]);
682
683 if (!(opt & BIT_0))
684 if (len == 0 || len > DMA_POOL_SIZE)
685 return -EINVAL;
686
687 memset(ha->edc_data, 0, len);
688 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
689 ha->edc_data, len, opt);
690 if (rval != QLA_SUCCESS) {
691 DEBUG2(qla_printk(KERN_INFO, ha,
692 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
693 rval, dev, adr, opt, len));
694 return 0;
695 }
696
697 ha->edc_data_len = len;
698
699 return count;
700}
701
702static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700703qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700704 struct bin_attribute *bin_attr,
705 char *buf, loff_t off, size_t count)
706{
707 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
708 struct device, kobj)));
709 struct qla_hw_data *ha = vha->hw;
710
711 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
712 return 0;
713
714 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
715 return -EINVAL;
716
717 memcpy(buf, ha->edc_data, ha->edc_data_len);
718
719 return ha->edc_data_len;
720}
721
722static struct bin_attribute sysfs_edc_status_attr = {
723 .attr = {
724 .name = "edc_status",
725 .mode = S_IRUSR | S_IWUSR,
726 },
727 .size = 0,
728 .write = qla2x00_sysfs_write_edc_status,
729 .read = qla2x00_sysfs_read_edc_status,
730};
731
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700732static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700733qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700734 struct bin_attribute *bin_attr,
735 char *buf, loff_t off, size_t count)
736{
737 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
738 struct device, kobj)));
739 struct qla_hw_data *ha = vha->hw;
740 int rval;
741 uint16_t actual_size;
742
743 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
744 return 0;
745
746 if (ha->xgmac_data)
747 goto do_read;
748
749 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
750 &ha->xgmac_data_dma, GFP_KERNEL);
751 if (!ha->xgmac_data) {
752 qla_printk(KERN_WARNING, ha,
753 "Unable to allocate memory for XGMAC read-data.\n");
754 return 0;
755 }
756
757do_read:
758 actual_size = 0;
759 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
760
761 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
762 XGMAC_DATA_SIZE, &actual_size);
763 if (rval != QLA_SUCCESS) {
764 qla_printk(KERN_WARNING, ha,
765 "Unable to read XGMAC data (%x).\n", rval);
766 count = 0;
767 }
768
769 count = actual_size > count ? count: actual_size;
770 memcpy(buf, ha->xgmac_data, count);
771
772 return count;
773}
774
775static struct bin_attribute sysfs_xgmac_stats_attr = {
776 .attr = {
777 .name = "xgmac_stats",
778 .mode = S_IRUSR,
779 },
780 .size = 0,
781 .read = qla2x00_sysfs_read_xgmac_stats,
782};
783
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700784static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700785qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700786 struct bin_attribute *bin_attr,
787 char *buf, loff_t off, size_t count)
788{
789 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
790 struct device, kobj)));
791 struct qla_hw_data *ha = vha->hw;
792 int rval;
793 uint16_t actual_size;
794
795 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
796 return 0;
797
798 if (ha->dcbx_tlv)
799 goto do_read;
800
801 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
802 &ha->dcbx_tlv_dma, GFP_KERNEL);
803 if (!ha->dcbx_tlv) {
804 qla_printk(KERN_WARNING, ha,
805 "Unable to allocate memory for DCBX TLV read-data.\n");
806 return 0;
807 }
808
809do_read:
810 actual_size = 0;
811 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
812
813 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
814 DCBX_TLV_DATA_SIZE);
815 if (rval != QLA_SUCCESS) {
816 qla_printk(KERN_WARNING, ha,
817 "Unable to read DCBX TLV data (%x).\n", rval);
818 count = 0;
819 }
820
821 memcpy(buf, ha->dcbx_tlv, count);
822
823 return count;
824}
825
826static struct bin_attribute sysfs_dcbx_tlv_attr = {
827 .attr = {
828 .name = "dcbx_tlv",
829 .mode = S_IRUSR,
830 },
831 .size = 0,
832 .read = qla2x00_sysfs_read_dcbx_tlv,
833};
834
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700835static struct sysfs_entry {
836 char *name;
837 struct bin_attribute *attr;
838 int is4GBp_only;
839} bin_file_entries[] = {
840 { "fw_dump", &sysfs_fw_dump_attr, },
841 { "nvram", &sysfs_nvram_attr, },
842 { "optrom", &sysfs_optrom_attr, },
843 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
844 { "vpd", &sysfs_vpd_attr, 1 },
845 { "sfp", &sysfs_sfp_attr, 1 },
Lalit Chandivade6e181be2009-03-26 08:49:17 -0700846 { "reset", &sysfs_reset_attr, },
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700847 { "edc", &sysfs_edc_attr, 2 },
848 { "edc_status", &sysfs_edc_status_attr, 2 },
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700849 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -0700850 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800851 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700852};
853
8482e112005-04-17 15:04:54 -0500854void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800855qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500856{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800857 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700858 struct sysfs_entry *iter;
859 int ret;
8482e112005-04-17 15:04:54 -0500860
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700861 for (iter = bin_file_entries; iter->name; iter++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800862 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700863 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700864 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
865 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700866 if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700867 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700868
869 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
870 iter->attr);
871 if (ret)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800872 qla_printk(KERN_INFO, vha->hw,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700873 "Unable to create sysfs %s binary attribute "
874 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700875 }
8482e112005-04-17 15:04:54 -0500876}
877
878void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800879qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -0500880{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800881 struct Scsi_Host *host = vha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700882 struct sysfs_entry *iter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800883 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -0500884
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700885 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700886 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700887 continue;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -0700888 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
889 continue;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700890 if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
Andrew Vasquezce0423f2009-06-03 09:55:13 -0700891 continue;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700892
Andrew Vasquez7914d002006-06-23 16:10:55 -0700893 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700894 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700895 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800896
897 if (ha->beacon_blink_led == 1)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800898 ha->isp_ops->beacon_off(vha);
8482e112005-04-17 15:04:54 -0500899}
900
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700901/* Scsi_Host attributes. */
902
903static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100904qla2x00_drvr_version_show(struct device *dev,
905 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700906{
907 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
908}
909
910static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100911qla2x00_fw_version_show(struct device *dev,
912 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700913{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800914 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
915 struct qla_hw_data *ha = vha->hw;
916 char fw_str[128];
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700917
918 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800919 ha->isp_ops->fw_version_str(vha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700920}
921
922static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100923qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
924 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700925{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800926 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700928 uint32_t sn;
929
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700930 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700932 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
933 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700934
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700935 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
936 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
937 sn % 100000);
938}
939
940static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100941qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
942 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700943{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800944 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
945 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700946}
947
948static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100949qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
950 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700951{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800952 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
953 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700954 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
955 ha->product_id[0], ha->product_id[1], ha->product_id[2],
956 ha->product_id[3]);
957}
958
959static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100960qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
961 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700962{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800963 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
964 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700965}
966
967static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100968qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
969 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700970{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700972 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800973 vha->hw->model_desc ? vha->hw->model_desc : "");
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700974}
975
976static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100977qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
978 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700979{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800980 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700981 char pci_info[30];
982
983 return snprintf(buf, PAGE_SIZE, "%s\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800984 vha->hw->isp_ops->pci_info_str(vha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700985}
986
987static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100988qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
989 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700990{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800991 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
992 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700993 int len = 0;
994
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800995 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
Andrew Vasquez62542f42010-05-04 15:01:22 -0700996 atomic_read(&vha->loop_state) == LOOP_DEAD ||
997 vha->device_flags & DFLG_NO_CABLE)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700998 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800999 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1000 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1001 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001002 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1003 else {
1004 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
1005
1006 switch (ha->current_topology) {
1007 case ISP_CFG_NL:
1008 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1009 break;
1010 case ISP_CFG_FL:
1011 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1012 break;
1013 case ISP_CFG_N:
1014 len += snprintf(buf + len, PAGE_SIZE-len,
1015 "N_Port to N_Port\n");
1016 break;
1017 case ISP_CFG_F:
1018 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1019 break;
1020 default:
1021 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1022 break;
1023 }
1024 }
1025 return len;
1026}
1027
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001028static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001029qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1030 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001031{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001032 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001033 int len = 0;
1034
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001035 switch (vha->hw->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001036 case QLA_ZIO_MODE_6:
1037 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1038 break;
1039 case QLA_ZIO_DISABLED:
1040 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1041 break;
1042 }
1043 return len;
1044}
1045
1046static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001047qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1048 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001049{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1051 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001052 int val = 0;
1053 uint16_t zio_mode;
1054
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001055 if (!IS_ZIO_SUPPORTED(ha))
1056 return -ENOTSUPP;
1057
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001058 if (sscanf(buf, "%d", &val) != 1)
1059 return -EINVAL;
1060
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001061 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001062 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001063 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001064 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001065
1066 /* Update per-hba values and queue a reset. */
1067 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1068 ha->zio_mode = zio_mode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001069 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001070 }
1071 return strlen(buf);
1072}
1073
1074static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001075qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1076 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001077{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001078 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001079
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001080 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001081}
1082
1083static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001084qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1085 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001086{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001087 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001088 int val = 0;
1089 uint16_t zio_timer;
1090
1091 if (sscanf(buf, "%d", &val) != 1)
1092 return -EINVAL;
1093 if (val > 25500 || val < 100)
1094 return -ERANGE;
1095
1096 zio_timer = (uint16_t)(val / 100);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001097 vha->hw->zio_timer = zio_timer;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001098
1099 return strlen(buf);
1100}
1101
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001103qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1104 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001105{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001106 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001107 int len = 0;
1108
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001109 if (vha->hw->beacon_blink_led)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001110 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1111 else
1112 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1113 return len;
1114}
1115
1116static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001117qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1118 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001119{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001120 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1121 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001122 int val = 0;
1123 int rval;
1124
1125 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1126 return -EPERM;
1127
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001128 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001129 qla_printk(KERN_WARNING, ha,
1130 "Abort ISP active -- ignoring beacon request.\n");
1131 return -EBUSY;
1132 }
1133
1134 if (sscanf(buf, "%d", &val) != 1)
1135 return -EINVAL;
1136
1137 if (val)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001138 rval = ha->isp_ops->beacon_on(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001139 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001140 rval = ha->isp_ops->beacon_off(vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001141
1142 if (rval != QLA_SUCCESS)
1143 count = 0;
1144
1145 return count;
1146}
1147
Andrew Vasquez30c47662007-01-29 10:22:21 -08001148static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001149qla2x00_optrom_bios_version_show(struct device *dev,
1150 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001151{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001152 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1153 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001154 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1155 ha->bios_revision[0]);
1156}
1157
1158static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001159qla2x00_optrom_efi_version_show(struct device *dev,
1160 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001161{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001162 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1163 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001164 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1165 ha->efi_revision[0]);
1166}
1167
1168static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001169qla2x00_optrom_fcode_version_show(struct device *dev,
1170 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001171{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001172 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1173 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001174 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1175 ha->fcode_revision[0]);
1176}
1177
1178static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001179qla2x00_optrom_fw_version_show(struct device *dev,
1180 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08001181{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001182 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1183 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08001184 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1185 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1186 ha->fw_revision[3]);
1187}
1188
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001189static ssize_t
1190qla2x00_total_isp_aborts_show(struct device *dev,
1191 struct device_attribute *attr, char *buf)
1192{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001193 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1194 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001195 return snprintf(buf, PAGE_SIZE, "%d\n",
1196 ha->qla_stats.total_isp_aborts);
1197}
1198
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001199static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001200qla24xx_84xx_fw_version_show(struct device *dev,
1201 struct device_attribute *attr, char *buf)
1202{
1203 int rval = QLA_SUCCESS;
1204 uint16_t status[2] = {0, 0};
1205 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1206 struct qla_hw_data *ha = vha->hw;
1207
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001208 if (!IS_QLA84XX(ha))
1209 return snprintf(buf, PAGE_SIZE, "\n");
1210
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001211 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001212 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001213
1214 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1215 return snprintf(buf, PAGE_SIZE, "%u\n",
1216 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001217
1218 return snprintf(buf, PAGE_SIZE, "\n");
1219}
1220
1221static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001222qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1223 char *buf)
1224{
1225 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1226 struct qla_hw_data *ha = vha->hw;
1227
1228 if (!IS_QLA81XX(ha))
1229 return snprintf(buf, PAGE_SIZE, "\n");
1230
Andrew Vasquez55a96152009-03-24 09:08:03 -07001231 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001232 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001233 ha->mpi_capabilities);
1234}
1235
1236static ssize_t
1237qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1238 char *buf)
1239{
1240 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1241 struct qla_hw_data *ha = vha->hw;
1242
1243 if (!IS_QLA81XX(ha))
1244 return snprintf(buf, PAGE_SIZE, "\n");
1245
1246 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1247 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001248}
1249
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001250static ssize_t
1251qla2x00_flash_block_size_show(struct device *dev,
1252 struct device_attribute *attr, char *buf)
1253{
1254 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1255 struct qla_hw_data *ha = vha->hw;
1256
1257 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1258}
1259
Andrew Vasquezbad70012009-04-06 22:33:38 -07001260static ssize_t
1261qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1262 char *buf)
1263{
1264 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1265
Giridhar Malavalia9083012010-04-12 17:59:55 -07001266 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001267 return snprintf(buf, PAGE_SIZE, "\n");
1268
1269 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1270}
1271
1272static ssize_t
1273qla2x00_vn_port_mac_address_show(struct device *dev,
1274 struct device_attribute *attr, char *buf)
1275{
1276 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1277
Giridhar Malavalia9083012010-04-12 17:59:55 -07001278 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001279 return snprintf(buf, PAGE_SIZE, "\n");
1280
1281 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1282 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1283 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1284 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1285}
1286
Andrew Vasquez7f774022009-06-03 09:55:12 -07001287static ssize_t
1288qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1289 char *buf)
1290{
1291 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1292
1293 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1294}
1295
Andrew Vasquez656e8912009-06-03 09:55:29 -07001296static ssize_t
1297qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1298 char *buf)
1299{
1300 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001301 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001302 uint16_t state[5];
1303
Santosh Vernekard6136f32010-03-19 16:59:20 -07001304 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1305 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1306 DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
1307 __func__, vha->host_no));
1308 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001309 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001310 if (rval != QLA_SUCCESS)
1311 memset(state, -1, sizeof(state));
1312
1313 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1314 state[1], state[2], state[3], state[4]);
1315}
1316
Tony Jonesee959b02008-02-22 00:13:36 +01001317static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1318static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1319static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1320static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1321static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1322static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1323static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1324static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001325static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001326static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1327static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1328 qla2x00_zio_timer_store);
1329static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1330 qla2x00_beacon_store);
1331static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1332 qla2x00_optrom_bios_version_show, NULL);
1333static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1334 qla2x00_optrom_efi_version_show, NULL);
1335static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1336 qla2x00_optrom_fcode_version_show, NULL);
1337static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1338 NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001339static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1340 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001341static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1342 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001343static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001344static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001345static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1346 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001347static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1348static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1349 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001350static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001351static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001352
Tony Jonesee959b02008-02-22 00:13:36 +01001353struct device_attribute *qla2x00_host_attrs[] = {
1354 &dev_attr_driver_version,
1355 &dev_attr_fw_version,
1356 &dev_attr_serial_num,
1357 &dev_attr_isp_name,
1358 &dev_attr_isp_id,
1359 &dev_attr_model_name,
1360 &dev_attr_model_desc,
1361 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001362 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001363 &dev_attr_zio,
1364 &dev_attr_zio_timer,
1365 &dev_attr_beacon,
1366 &dev_attr_optrom_bios_version,
1367 &dev_attr_optrom_efi_version,
1368 &dev_attr_optrom_fcode_version,
1369 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001370 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001371 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001372 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001373 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001374 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001375 &dev_attr_vlan_id,
1376 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001377 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001378 &dev_attr_fw_state,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001379 NULL,
1380};
1381
8482e112005-04-17 15:04:54 -05001382/* Host attributes. */
1383
1384static void
1385qla2x00_get_host_port_id(struct Scsi_Host *shost)
1386{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001387 scsi_qla_host_t *vha = shost_priv(shost);
8482e112005-04-17 15:04:54 -05001388
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001389 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1390 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e112005-04-17 15:04:54 -05001391}
1392
1393static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001394qla2x00_get_host_speed(struct Scsi_Host *shost)
1395{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001396 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1397 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001398 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001399
1400 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001401 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001402 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001403 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001404 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001405 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001406 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001407 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001408 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001409 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001410 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001411 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001412 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001413 case PORT_SPEED_10GB:
1414 speed = FC_PORTSPEED_10GBIT;
1415 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001416 }
1417 fc_host_speed(shost) = speed;
1418}
1419
1420static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001421qla2x00_get_host_port_type(struct Scsi_Host *shost)
1422{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001423 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001424 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1425
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001426 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001427 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1428 return;
1429 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001430 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001431 case ISP_CFG_NL:
1432 port_type = FC_PORTTYPE_LPORT;
1433 break;
1434 case ISP_CFG_FL:
1435 port_type = FC_PORTTYPE_NLPORT;
1436 break;
1437 case ISP_CFG_N:
1438 port_type = FC_PORTTYPE_PTP;
1439 break;
1440 case ISP_CFG_F:
1441 port_type = FC_PORTTYPE_NPORT;
1442 break;
1443 }
1444 fc_host_port_type(shost) = port_type;
1445}
1446
1447static void
8482e112005-04-17 15:04:54 -05001448qla2x00_get_starget_node_name(struct scsi_target *starget)
1449{
1450 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001451 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001452 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001453 u64 node_name = 0;
8482e112005-04-17 15:04:54 -05001454
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001455 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001456 if (fcport->rport &&
1457 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001458 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001459 break;
1460 }
1461 }
1462
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001463 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -05001464}
1465
1466static void
1467qla2x00_get_starget_port_name(struct scsi_target *starget)
1468{
1469 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001470 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001471 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001472 u64 port_name = 0;
8482e112005-04-17 15:04:54 -05001473
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001474 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001475 if (fcport->rport &&
1476 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001477 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001478 break;
1479 }
1480 }
1481
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001482 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -05001483}
1484
1485static void
1486qla2x00_get_starget_port_id(struct scsi_target *starget)
1487{
1488 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001489 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001490 fc_port_t *fcport;
1491 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -05001492
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001493 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001494 if (fcport->rport &&
1495 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001496 port_id = fcport->d_id.b.domain << 16 |
1497 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1498 break;
1499 }
1500 }
1501
8482e112005-04-17 15:04:54 -05001502 fc_starget_port_id(starget) = port_id;
1503}
1504
1505static void
8482e112005-04-17 15:04:54 -05001506qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1507{
8482e112005-04-17 15:04:54 -05001508 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001509 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -05001510 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001511 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -05001512}
1513
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001514static void
1515qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1516{
1517 struct Scsi_Host *host = rport_to_shost(rport);
1518 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1519
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001520 if (!fcport)
1521 return;
1522
Andrew Vasquez85880802009-12-15 21:29:46 -08001523 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1524 return;
1525
1526 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001527 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001528 return;
1529 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001530
1531 /*
1532 * Transport has effectively 'deleted' the rport, clear
1533 * all local references.
1534 */
1535 spin_lock_irq(host->host_lock);
1536 fcport->rport = NULL;
1537 *((fc_port_t **)rport->dd_data) = NULL;
1538 spin_unlock_irq(host->host_lock);
1539}
1540
1541static void
1542qla2x00_terminate_rport_io(struct fc_rport *rport)
1543{
1544 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1545
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001546 if (!fcport)
1547 return;
1548
Andrew Vasquez85880802009-12-15 21:29:46 -08001549 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1550 return;
1551
Seokmann Jub9b12f72009-03-24 09:08:18 -07001552 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1553 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1554 return;
1555 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001556 /*
1557 * At this point all fcport's software-states are cleared. Perform any
1558 * final cleanup of firmware resources (PCBs and XCBs).
1559 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001560 if (fcport->loop_id != FC_NO_LOOP_ID &&
1561 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001562 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1563 fcport->loop_id, fcport->d_id.b.domain,
1564 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001565}
1566
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001567static int
1568qla2x00_issue_lip(struct Scsi_Host *shost)
1569{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001570 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001571
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001572 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001573 return 0;
1574}
1575
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001576static struct fc_host_statistics *
1577qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1578{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001579 scsi_qla_host_t *vha = shost_priv(shost);
1580 struct qla_hw_data *ha = vha->hw;
1581 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001582 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001583 struct link_statistics *stats;
1584 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001585 struct fc_host_statistics *pfc_host_stat;
1586
1587 pfc_host_stat = &ha->fc_host_stat;
1588 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1589
Andrew Vasquez85880802009-12-15 21:29:46 -08001590 if (test_bit(UNLOADING, &vha->dpc_flags))
1591 goto done;
1592
1593 if (unlikely(pci_channel_offline(ha->pdev)))
1594 goto done;
1595
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001596 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1597 if (stats == NULL) {
1598 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001599 __func__, base_vha->host_no));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001600 goto done;
1601 }
1602 memset(stats, 0, DMA_POOL_SIZE);
1603
1604 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001605 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001606 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1607 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1608 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1609 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001610 !ha->dpc_active) {
1611 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001612 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1613 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001614 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001615
1616 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001617 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001618
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001619 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1620 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1621 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1622 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1623 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1624 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1625 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001626 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001627 pfc_host_stat->tx_frames = stats->tx_frames;
1628 pfc_host_stat->rx_frames = stats->rx_frames;
1629 pfc_host_stat->dumped_frames = stats->dumped_frames;
1630 pfc_host_stat->nos_count = stats->nos_rcvd;
1631 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001632 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1633 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001634
1635done_free:
1636 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001637done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001638 return pfc_host_stat;
1639}
1640
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001641static void
1642qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1643{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001644 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001645
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001646 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001647}
1648
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001649static void
1650qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1651{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001652 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001653
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001654 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001655}
1656
Andrew Vasquez90991c82006-10-02 12:00:46 -07001657static void
1658qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1659{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001660 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001661 u64 node_name;
1662
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001663 if (vha->device_flags & SWITCH_FOUND)
1664 node_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001665 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001666 node_name = wwn_to_u64(vha->node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001667
1668 fc_host_fabric_name(shost) = node_name;
1669}
1670
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001671static void
1672qla2x00_get_host_port_state(struct Scsi_Host *shost)
1673{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001674 scsi_qla_host_t *vha = shost_priv(shost);
1675 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001676
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001677 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001678 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001679 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001680 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1681 else
1682 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1683}
1684
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001685static int
1686qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1687{
1688 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001689 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001690 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1691 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001692 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001693 uint16_t options = 0;
1694 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001695 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001696
1697 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1698 if (ret) {
1699 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1700 "status %x\n", ret));
1701 return (ret);
1702 }
1703
1704 vha = qla24xx_create_vhost(fc_vport);
1705 if (vha == NULL) {
1706 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1707 vha));
1708 return FC_VPORT_FAILED;
1709 }
1710 if (disable) {
1711 atomic_set(&vha->vp_state, VP_OFFLINE);
1712 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1713 } else
1714 atomic_set(&vha->vp_state, VP_FAILED);
1715
1716 /* ready to create vport */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001717 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1718 vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001719
1720 /* initialized vport states */
1721 atomic_set(&vha->loop_state, LOOP_DOWN);
1722 vha->vp_err_state= VP_ERR_PORTDWN;
1723 vha->vp_prev_err_state= VP_ERR_UNKWN;
1724 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001725 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1726 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001727 /* Don't retry or attempt login of this virtual port */
1728 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001729 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001730 atomic_set(&vha->loop_state, LOOP_DEAD);
1731 if (!disable)
1732 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1733 }
1734
Arun Easiba77ef52010-05-28 15:08:27 -07001735 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001736 if (ha->fw_attributes & BIT_4) {
1737 vha->flags.difdix_supported = 1;
1738 DEBUG18(qla_printk(KERN_INFO, ha,
1739 "Registering for DIF/DIX type 1 and 3"
1740 " protection.\n"));
1741 scsi_host_set_prot(vha->host,
1742 SHOST_DIF_TYPE1_PROTECTION
1743 | SHOST_DIF_TYPE3_PROTECTION
1744 | SHOST_DIX_TYPE1_PROTECTION
1745 | SHOST_DIX_TYPE3_PROTECTION);
1746 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1747 } else
1748 vha->flags.difdix_supported = 0;
1749 }
1750
James Bottomleyd139b9b2009-11-05 13:33:12 -06001751 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1752 &ha->pdev->dev)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001753 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1754 vha->host_no, vha->vp_idx));
1755 goto vport_create_failed_2;
1756 }
1757
1758 /* initialize attributes */
1759 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1760 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1761 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001762 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001763 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001764 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001765
1766 qla24xx_vport_disable(fc_vport, disable);
1767
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001768 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001769 req = ha->req_q_map[1];
1770 goto vport_queue;
1771 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001772 goto vport_queue;
1773 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001774 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1775 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1776 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001777 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001778 qos = ha->npiv_info[cnt].q_qos;
1779 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001780 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001781 }
1782 if (qos) {
1783 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1784 qos);
1785 if (!ret)
1786 qla_printk(KERN_WARNING, ha,
1787 "Can't create request queue for vp_idx:%d\n",
1788 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001789 else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001790 DEBUG2(qla_printk(KERN_INFO, ha,
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001791 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1792 ret, qos, vha->vp_idx));
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001793 req = ha->req_q_map[ret];
1794 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001795 }
1796
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001797vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001798 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001799 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001800
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001801vport_create_failed_2:
1802 qla24xx_disable_vp(vha);
1803 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001804 scsi_host_put(vha->host);
1805 return FC_VPORT_FAILED;
1806}
1807
Adrian Bunka824ebb2008-01-17 09:02:15 -08001808static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001809qla24xx_vport_delete(struct fc_vport *fc_vport)
1810{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001811 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001812 fc_port_t *fcport, *tfcport;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001813 struct qla_hw_data *ha = vha->hw;
1814 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001815
1816 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001817 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001818 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001819
1820 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001821
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001822 fc_remove_host(vha->host);
1823
1824 scsi_remove_host(vha->host);
1825
1826 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1827 list_del(&fcport->list);
1828 kfree(fcport);
1829 fcport = NULL;
1830 }
1831
1832 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001833
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001834 mutex_lock(&ha->vport_lock);
1835 ha->cur_vport_count--;
1836 clear_bit(vha->vp_idx, ha->vp_idx_map);
1837 mutex_unlock(&ha->vport_lock);
1838
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001839 if (vha->timer_active) {
1840 qla2x00_vp_stop_timer(vha);
1841 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1842 "has stopped\n",
1843 vha->host_no, vha->vp_idx, vha));
1844 }
1845
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001846 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001847 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001848 qla_printk(KERN_WARNING, ha,
1849 "Queue delete failed.\n");
1850 }
1851
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852 scsi_host_put(vha->host);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001853 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001854 return 0;
1855}
1856
Adrian Bunka824ebb2008-01-17 09:02:15 -08001857static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001858qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1859{
1860 scsi_qla_host_t *vha = fc_vport->dd_data;
1861
1862 if (disable)
1863 qla24xx_disable_vp(vha);
1864 else
1865 qla24xx_enable_vp(vha);
1866
1867 return 0;
1868}
1869
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001870struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001871
1872 .show_host_node_name = 1,
1873 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001874 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001875 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001876
8482e112005-04-17 15:04:54 -05001877 .get_host_port_id = qla2x00_get_host_port_id,
1878 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001879 .get_host_speed = qla2x00_get_host_speed,
1880 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001881 .get_host_port_type = qla2x00_get_host_port_type,
1882 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001883 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1884 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001885 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1886 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001887 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1888 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001889 .get_host_port_state = qla2x00_get_host_port_state,
1890 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001891
bdf79622005-04-17 15:06:53 -05001892 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001893 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001894
1895 .get_starget_node_name = qla2x00_get_starget_node_name,
1896 .show_starget_node_name = 1,
1897 .get_starget_port_name = qla2x00_get_starget_port_name,
1898 .show_starget_port_name = 1,
1899 .get_starget_port_id = qla2x00_get_starget_port_id,
1900 .show_starget_port_id = 1,
1901
8482e112005-04-17 15:04:54 -05001902 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1903 .show_rport_dev_loss_tmo = 1,
1904
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001905 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001906 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1907 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001908 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001909
1910 .vport_create = qla24xx_vport_create,
1911 .vport_disable = qla24xx_vport_disable,
1912 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001913 .bsg_request = qla24xx_bsg_request,
1914 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001915};
1916
1917struct fc_function_template qla2xxx_transport_vport_functions = {
1918
1919 .show_host_node_name = 1,
1920 .show_host_port_name = 1,
1921 .show_host_supported_classes = 1,
1922
1923 .get_host_port_id = qla2x00_get_host_port_id,
1924 .show_host_port_id = 1,
1925 .get_host_speed = qla2x00_get_host_speed,
1926 .show_host_speed = 1,
1927 .get_host_port_type = qla2x00_get_host_port_type,
1928 .show_host_port_type = 1,
1929 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1930 .show_host_symbolic_name = 1,
1931 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1932 .show_host_system_hostname = 1,
1933 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1934 .show_host_fabric_name = 1,
1935 .get_host_port_state = qla2x00_get_host_port_state,
1936 .show_host_port_state = 1,
1937
1938 .dd_fcrport_size = sizeof(struct fc_port *),
1939 .show_rport_supported_classes = 1,
1940
1941 .get_starget_node_name = qla2x00_get_starget_node_name,
1942 .show_starget_node_name = 1,
1943 .get_starget_port_name = qla2x00_get_starget_port_name,
1944 .show_starget_port_name = 1,
1945 .get_starget_port_id = qla2x00_get_starget_port_id,
1946 .show_starget_port_id = 1,
1947
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001948 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1949 .show_rport_dev_loss_tmo = 1,
1950
1951 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001952 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1953 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001954 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001955 .bsg_request = qla24xx_bsg_request,
1956 .bsg_timeout = qla24xx_bsg_timeout,
8482e112005-04-17 15:04:54 -05001957};
1958
8482e112005-04-17 15:04:54 -05001959void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001960qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e112005-04-17 15:04:54 -05001961{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001962 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001963 u32 speed = FC_PORTSPEED_UNKNOWN;
1964
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001965 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1966 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1967 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1968 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1969 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001970
Giridhar Malavalia9083012010-04-12 17:59:55 -07001971 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001972 speed = FC_PORTSPEED_10GBIT;
1973 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001974 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1975 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001976 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001977 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1978 FC_PORTSPEED_1GBIT;
1979 else if (IS_QLA23XX(ha))
1980 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1981 else
1982 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001983 fc_host_supported_speeds(vha->host) = speed;
8482e112005-04-17 15:04:54 -05001984}