blob: 114bc5a81171993ac91c27ba600cee72adb9aed9 [file] [log] [blame]
8482e1182005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Giridhar Malavalide7c5d02010-07-23 15:28:36 +05003 * Copyright (c) 2003-2010 QLogic Corporation
8482e1182005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e1182005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090012#include <linux/delay.h>
8482e1182005-04-17 15:04:54 -050013
Adrian Bunka824ebb2008-01-17 09:02:15 -080014static int qla24xx_vport_disable(struct fc_vport *, bool);
Giridhar Malavali6e980162010-03-19 17:03:58 -070015
8482e1182005-04-17 15:04:54 -050016/* SYSFS attributes --------------------------------------------------------- */
17
18static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070019qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080020 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050022{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050024 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050026
27 if (ha->fw_dump_reading == 0)
28 return 0;
8482e1182005-04-17 15:04:54 -050029
Akinobu Mitab3dc9082008-07-24 08:31:47 -070030 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
31 ha->fw_dump_len);
8482e1182005-04-17 15:04:54 -050032}
33
34static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070035qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080036 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050038{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080039 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050040 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080041 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -050042 int reading;
8482e1182005-04-17 15:04:54 -050043
Giridhar Malavalia9083012010-04-12 17:59:55 -070044 if (IS_QLA82XX(ha)) {
45 DEBUG2(qla_printk(KERN_INFO, ha,
46 "Firmware dump not supported for ISP82xx\n"));
47 return count;
48 }
49
8482e1182005-04-17 15:04:54 -050050 if (off != 0)
51 return (0);
52
53 reading = simple_strtol(buf, NULL, 10);
54 switch (reading) {
55 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070056 if (!ha->fw_dump_reading)
57 break;
8482e1182005-04-17 15:04:54 -050058
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;
8482e1182005-04-17 15:04:54 -050064 break;
65 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070066 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050067 ha->fw_dump_reading = 1;
68
8482e1182005-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);
8482e1182005-04-17 15:04:54 -050072 }
73 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074 case 2:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080075 qla2x00_alloc_fw_dump(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070076 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070077 case 3:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080078 qla2x00_system_error(vha);
Andrew Vasquez68af0812008-05-12 22:21:13 -070079 break;
8482e1182005-04-17 15:04:54 -050080 }
81 return (count);
82}
83
84static struct bin_attribute sysfs_fw_dump_attr = {
85 .attr = {
86 .name = "fw_dump",
87 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -050088 },
89 .size = 0,
90 .read = qla2x00_sysfs_read_fw_dump,
91 .write = qla2x00_sysfs_write_fw_dump,
92};
93
94static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -070095qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080096 struct bin_attribute *bin_attr,
97 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050098{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080099 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500100 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800101 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500102
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700103 if (!capable(CAP_SYS_ADMIN))
8482e1182005-04-17 15:04:54 -0500104 return 0;
105
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700106 if (IS_NOCACHE_VPD_TYPE(ha))
Andrew Vasquez8f979752009-04-06 22:33:43 -0700107 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez6749ce32009-03-24 09:08:17 -0700108 ha->nvram_size);
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700109 return memory_read_from_buffer(buf, count, &off, ha->nvram,
110 ha->nvram_size);
8482e1182005-04-17 15:04:54 -0500111}
112
113static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -0700114qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800115 struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500117{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800118 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500119 struct device, kobj)));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800120 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -0500121 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500122
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700123 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
124 !ha->isp_ops->write_nvram)
8482e1182005-04-17 15:04:54 -0500125 return 0;
126
127 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700128 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700129 uint32_t *iter;
130 uint32_t chksum;
131
132 iter = (uint32_t *)buf;
133 chksum = 0;
134 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
135 chksum += le32_to_cpu(*iter++);
136 chksum = ~chksum + 1;
137 *iter = cpu_to_le32(chksum);
138 } else {
139 uint8_t *iter;
140 uint8_t chksum;
141
142 iter = (uint8_t *)buf;
143 chksum = 0;
144 for (cnt = 0; cnt < count - 1; cnt++)
145 chksum += *iter++;
146 chksum = ~chksum + 1;
147 *iter = chksum;
148 }
8482e1182005-04-17 15:04:54 -0500149
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700150 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
151 qla_printk(KERN_WARNING, ha,
152 "HBA not online, failing NVRAM update.\n");
153 return -EAGAIN;
154 }
155
8482e1182005-04-17 15:04:54 -0500156 /* Write NVRAM. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800157 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
158 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700159 count);
8482e1182005-04-17 15:04:54 -0500160
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
8482e1182005-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,
8482e1182005-04-17 15:04:54 -0500173 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800174 .size = 512,
8482e1182005-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 Vasquez3d79038f2009-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
8482e1182005-04-17 15:04:54 -0500854void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800855qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-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;
8482e1182005-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 }
8482e1182005-04-17 15:04:54 -0500876}
877
878void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800879qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
8482e1182005-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;
8482e1182005-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);
8482e1182005-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
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001190qla2x00_optrom_gold_fw_version_show(struct device *dev,
1191 struct device_attribute *attr, char *buf)
1192{
1193 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1194 struct qla_hw_data *ha = vha->hw;
1195
1196 if (!IS_QLA81XX(ha))
1197 return snprintf(buf, PAGE_SIZE, "\n");
1198
1199 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1200 ha->gold_fw_version[0], ha->gold_fw_version[1],
1201 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1202}
1203
1204static ssize_t
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001205qla2x00_total_isp_aborts_show(struct device *dev,
1206 struct device_attribute *attr, char *buf)
1207{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001208 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1209 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001210 return snprintf(buf, PAGE_SIZE, "%d\n",
1211 ha->qla_stats.total_isp_aborts);
1212}
1213
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001214static ssize_t
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001215qla24xx_84xx_fw_version_show(struct device *dev,
1216 struct device_attribute *attr, char *buf)
1217{
1218 int rval = QLA_SUCCESS;
1219 uint16_t status[2] = {0, 0};
1220 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1221 struct qla_hw_data *ha = vha->hw;
1222
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001223 if (!IS_QLA84XX(ha))
1224 return snprintf(buf, PAGE_SIZE, "\n");
1225
Giridhar Malavali6c7ccf72010-05-28 15:08:29 -07001226 if (ha->cs84xx->op_fw_version == 0)
Andrew Vasquez0b9dae62010-05-04 15:01:21 -07001227 rval = qla84xx_verify_chip(vha, status);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001228
1229 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1230 return snprintf(buf, PAGE_SIZE, "%u\n",
1231 (uint32_t)ha->cs84xx->op_fw_version);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001232
1233 return snprintf(buf, PAGE_SIZE, "\n");
1234}
1235
1236static ssize_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001237qla2x00_mpi_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
Andrew Vasquez55a96152009-03-24 09:08:03 -07001246 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001247 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
Andrew Vasquez55a96152009-03-24 09:08:03 -07001248 ha->mpi_capabilities);
1249}
1250
1251static ssize_t
1252qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1253 char *buf)
1254{
1255 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1256 struct qla_hw_data *ha = vha->hw;
1257
1258 if (!IS_QLA81XX(ha))
1259 return snprintf(buf, PAGE_SIZE, "\n");
1260
1261 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1262 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001263}
1264
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001265static ssize_t
1266qla2x00_flash_block_size_show(struct device *dev,
1267 struct device_attribute *attr, char *buf)
1268{
1269 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1270 struct qla_hw_data *ha = vha->hw;
1271
1272 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1273}
1274
Andrew Vasquezbad70012009-04-06 22:33:38 -07001275static ssize_t
1276qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1277 char *buf)
1278{
1279 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1280
Giridhar Malavalia9083012010-04-12 17:59:55 -07001281 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001282 return snprintf(buf, PAGE_SIZE, "\n");
1283
1284 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1285}
1286
1287static ssize_t
1288qla2x00_vn_port_mac_address_show(struct device *dev,
1289 struct device_attribute *attr, char *buf)
1290{
1291 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1292
Giridhar Malavalia9083012010-04-12 17:59:55 -07001293 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001294 return snprintf(buf, PAGE_SIZE, "\n");
1295
1296 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1297 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1298 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1299 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1300}
1301
Andrew Vasquez7f774022009-06-03 09:55:12 -07001302static ssize_t
1303qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1304 char *buf)
1305{
1306 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1307
1308 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1309}
1310
Andrew Vasquez656e8912009-06-03 09:55:29 -07001311static ssize_t
1312qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1313 char *buf)
1314{
1315 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001316 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001317 uint16_t state[5];
1318
Santosh Vernekard6136f32010-03-19 16:59:20 -07001319 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1320 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1321 DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
1322 __func__, vha->host_no));
1323 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001324 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001325 if (rval != QLA_SUCCESS)
1326 memset(state, -1, sizeof(state));
1327
1328 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1329 state[1], state[2], state[3], state[4]);
1330}
1331
Tony Jonesee959b02008-02-22 00:13:36 +01001332static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1333static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1334static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1335static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1336static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1337static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1338static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1339static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001340static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001341static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1342static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1343 qla2x00_zio_timer_store);
1344static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1345 qla2x00_beacon_store);
1346static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1347 qla2x00_optrom_bios_version_show, NULL);
1348static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1349 qla2x00_optrom_efi_version_show, NULL);
1350static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1351 qla2x00_optrom_fcode_version_show, NULL);
1352static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1353 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001354static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1355 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001356static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1357 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001358static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1359 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001360static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001361static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001362static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1363 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001364static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1365static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1366 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001367static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001368static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001369
Tony Jonesee959b02008-02-22 00:13:36 +01001370struct device_attribute *qla2x00_host_attrs[] = {
1371 &dev_attr_driver_version,
1372 &dev_attr_fw_version,
1373 &dev_attr_serial_num,
1374 &dev_attr_isp_name,
1375 &dev_attr_isp_id,
1376 &dev_attr_model_name,
1377 &dev_attr_model_desc,
1378 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001379 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001380 &dev_attr_zio,
1381 &dev_attr_zio_timer,
1382 &dev_attr_beacon,
1383 &dev_attr_optrom_bios_version,
1384 &dev_attr_optrom_efi_version,
1385 &dev_attr_optrom_fcode_version,
1386 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001387 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001388 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001389 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001390 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001391 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001392 &dev_attr_vlan_id,
1393 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001394 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001395 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001396 &dev_attr_optrom_gold_fw_version,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001397 NULL,
1398};
1399
8482e1182005-04-17 15:04:54 -05001400/* Host attributes. */
1401
1402static void
1403qla2x00_get_host_port_id(struct Scsi_Host *shost)
1404{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001405 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001406
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001407 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1408 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001409}
1410
1411static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001412qla2x00_get_host_speed(struct Scsi_Host *shost)
1413{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001414 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1415 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001416 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001417
1418 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001419 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001420 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001421 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001422 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001423 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001424 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001425 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001426 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001427 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001428 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001429 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001430 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001431 case PORT_SPEED_10GB:
1432 speed = FC_PORTSPEED_10GBIT;
1433 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001434 }
1435 fc_host_speed(shost) = speed;
1436}
1437
1438static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001439qla2x00_get_host_port_type(struct Scsi_Host *shost)
1440{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001441 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001442 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1443
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001444 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001445 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1446 return;
1447 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001448 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001449 case ISP_CFG_NL:
1450 port_type = FC_PORTTYPE_LPORT;
1451 break;
1452 case ISP_CFG_FL:
1453 port_type = FC_PORTTYPE_NLPORT;
1454 break;
1455 case ISP_CFG_N:
1456 port_type = FC_PORTTYPE_PTP;
1457 break;
1458 case ISP_CFG_F:
1459 port_type = FC_PORTTYPE_NPORT;
1460 break;
1461 }
1462 fc_host_port_type(shost) = port_type;
1463}
1464
1465static void
8482e1182005-04-17 15:04:54 -05001466qla2x00_get_starget_node_name(struct scsi_target *starget)
1467{
1468 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001469 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001470 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001471 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001472
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001473 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001474 if (fcport->rport &&
1475 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001476 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001477 break;
1478 }
1479 }
1480
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001481 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001482}
1483
1484static void
1485qla2x00_get_starget_port_name(struct scsi_target *starget)
1486{
1487 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001488 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001489 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001490 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001491
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001492 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001493 if (fcport->rport &&
1494 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001495 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001496 break;
1497 }
1498 }
1499
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001500 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001501}
1502
1503static void
1504qla2x00_get_starget_port_id(struct scsi_target *starget)
1505{
1506 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001507 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001508 fc_port_t *fcport;
1509 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001510
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001511 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001512 if (fcport->rport &&
1513 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001514 port_id = fcport->d_id.b.domain << 16 |
1515 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1516 break;
1517 }
1518 }
1519
8482e1182005-04-17 15:04:54 -05001520 fc_starget_port_id(starget) = port_id;
1521}
1522
1523static void
8482e1182005-04-17 15:04:54 -05001524qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1525{
8482e1182005-04-17 15:04:54 -05001526 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001527 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001528 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001529 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001530}
1531
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001532static void
1533qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1534{
1535 struct Scsi_Host *host = rport_to_shost(rport);
1536 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1537
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001538 if (!fcport)
1539 return;
1540
Andrew Vasquez85880802009-12-15 21:29:46 -08001541 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1542 return;
1543
1544 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001545 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001546 return;
1547 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001548
1549 /*
1550 * Transport has effectively 'deleted' the rport, clear
1551 * all local references.
1552 */
1553 spin_lock_irq(host->host_lock);
1554 fcport->rport = NULL;
1555 *((fc_port_t **)rport->dd_data) = NULL;
1556 spin_unlock_irq(host->host_lock);
1557}
1558
1559static void
1560qla2x00_terminate_rport_io(struct fc_rport *rport)
1561{
1562 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1563
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001564 if (!fcport)
1565 return;
1566
Andrew Vasquez85880802009-12-15 21:29:46 -08001567 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1568 return;
1569
Seokmann Jub9b12f72009-03-24 09:08:18 -07001570 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1571 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1572 return;
1573 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001574 /*
1575 * At this point all fcport's software-states are cleared. Perform any
1576 * final cleanup of firmware resources (PCBs and XCBs).
1577 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001578 if (fcport->loop_id != FC_NO_LOOP_ID &&
1579 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001580 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1581 fcport->loop_id, fcport->d_id.b.domain,
1582 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001583}
1584
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001585static int
1586qla2x00_issue_lip(struct Scsi_Host *shost)
1587{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001588 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001589
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001590 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001591 return 0;
1592}
1593
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001594static struct fc_host_statistics *
1595qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1596{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001597 scsi_qla_host_t *vha = shost_priv(shost);
1598 struct qla_hw_data *ha = vha->hw;
1599 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001600 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001601 struct link_statistics *stats;
1602 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001603 struct fc_host_statistics *pfc_host_stat;
1604
1605 pfc_host_stat = &ha->fc_host_stat;
1606 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1607
Andrew Vasquez85880802009-12-15 21:29:46 -08001608 if (test_bit(UNLOADING, &vha->dpc_flags))
1609 goto done;
1610
1611 if (unlikely(pci_channel_offline(ha->pdev)))
1612 goto done;
1613
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001614 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1615 if (stats == NULL) {
1616 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001617 __func__, base_vha->host_no));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001618 goto done;
1619 }
1620 memset(stats, 0, DMA_POOL_SIZE);
1621
1622 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001623 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1625 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1626 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1627 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001628 !ha->dpc_active) {
1629 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001630 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1631 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001632 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001633
1634 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001635 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001636
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001637 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1638 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1639 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1640 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1641 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1642 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1643 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001644 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001645 pfc_host_stat->tx_frames = stats->tx_frames;
1646 pfc_host_stat->rx_frames = stats->rx_frames;
1647 pfc_host_stat->dumped_frames = stats->dumped_frames;
1648 pfc_host_stat->nos_count = stats->nos_rcvd;
1649 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001650 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1651 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001652
1653done_free:
1654 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001655done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001656 return pfc_host_stat;
1657}
1658
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001659static void
1660qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1661{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001662 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001663
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001664 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001665}
1666
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001667static void
1668qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1669{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001670 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001671
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001672 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001673}
1674
Andrew Vasquez90991c82006-10-02 12:00:46 -07001675static void
1676qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1677{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001678 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001679 u64 node_name;
1680
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001681 if (vha->device_flags & SWITCH_FOUND)
1682 node_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001683 else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001684 node_name = wwn_to_u64(vha->node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001685
1686 fc_host_fabric_name(shost) = node_name;
1687}
1688
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001689static void
1690qla2x00_get_host_port_state(struct Scsi_Host *shost)
1691{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001692 scsi_qla_host_t *vha = shost_priv(shost);
1693 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001694
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001695 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001696 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001697 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001698 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1699 else
1700 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1701}
1702
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001703static int
1704qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1705{
1706 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001707 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001708 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1709 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001710 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001711 uint16_t options = 0;
1712 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001713 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001714
1715 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1716 if (ret) {
1717 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1718 "status %x\n", ret));
1719 return (ret);
1720 }
1721
1722 vha = qla24xx_create_vhost(fc_vport);
1723 if (vha == NULL) {
1724 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1725 vha));
1726 return FC_VPORT_FAILED;
1727 }
1728 if (disable) {
1729 atomic_set(&vha->vp_state, VP_OFFLINE);
1730 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1731 } else
1732 atomic_set(&vha->vp_state, VP_FAILED);
1733
1734 /* ready to create vport */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1736 vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001737
1738 /* initialized vport states */
1739 atomic_set(&vha->loop_state, LOOP_DOWN);
1740 vha->vp_err_state= VP_ERR_PORTDWN;
1741 vha->vp_prev_err_state= VP_ERR_UNKWN;
1742 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1744 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001745 /* Don't retry or attempt login of this virtual port */
1746 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001747 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001748 atomic_set(&vha->loop_state, LOOP_DEAD);
1749 if (!disable)
1750 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1751 }
1752
Arun Easiba77ef52010-05-28 15:08:27 -07001753 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001754 if (ha->fw_attributes & BIT_4) {
1755 vha->flags.difdix_supported = 1;
1756 DEBUG18(qla_printk(KERN_INFO, ha,
1757 "Registering for DIF/DIX type 1 and 3"
1758 " protection.\n"));
1759 scsi_host_set_prot(vha->host,
1760 SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001761 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001762 | SHOST_DIF_TYPE3_PROTECTION
1763 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001764 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001765 | SHOST_DIX_TYPE3_PROTECTION);
1766 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1767 } else
1768 vha->flags.difdix_supported = 0;
1769 }
1770
James Bottomleyd139b9b2009-11-05 13:33:12 -06001771 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1772 &ha->pdev->dev)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001773 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1774 vha->host_no, vha->vp_idx));
1775 goto vport_create_failed_2;
1776 }
1777
1778 /* initialize attributes */
1779 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1780 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1781 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001782 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001783 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001784 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001785
1786 qla24xx_vport_disable(fc_vport, disable);
1787
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001788 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001789 req = ha->req_q_map[1];
1790 goto vport_queue;
1791 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001792 goto vport_queue;
1793 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001794 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1795 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1796 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001797 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001798 qos = ha->npiv_info[cnt].q_qos;
1799 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001801 }
1802 if (qos) {
1803 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1804 qos);
1805 if (!ret)
1806 qla_printk(KERN_WARNING, ha,
1807 "Can't create request queue for vp_idx:%d\n",
1808 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001809 else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001810 DEBUG2(qla_printk(KERN_INFO, ha,
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001811 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1812 ret, qos, vha->vp_idx));
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001813 req = ha->req_q_map[ret];
1814 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001815 }
1816
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001817vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001818 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001819 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001820
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001821vport_create_failed_2:
1822 qla24xx_disable_vp(vha);
1823 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001824 scsi_host_put(vha->host);
1825 return FC_VPORT_FAILED;
1826}
1827
Adrian Bunka824ebb2008-01-17 09:02:15 -08001828static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001829qla24xx_vport_delete(struct fc_vport *fc_vport)
1830{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001831 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001832 struct qla_hw_data *ha = vha->hw;
1833 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001834
1835 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001836 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001837 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001838
1839 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001840
Arun Easifeafb7b2010-09-03 14:57:00 -07001841 vha->flags.delete_progress = 1;
1842
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001843 fc_remove_host(vha->host);
1844
1845 scsi_remove_host(vha->host);
1846
Arun Easifeafb7b2010-09-03 14:57:00 -07001847 if (vha->timer_active) {
1848 qla2x00_vp_stop_timer(vha);
1849 DEBUG15(printk(KERN_INFO "scsi(%ld): timer for the vport[%d]"
1850 " = %p has stopped\n", vha->host_no, vha->vp_idx, vha));
1851 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001852
1853 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001854
Arun Easifeafb7b2010-09-03 14:57:00 -07001855 /* No pending activities shall be there on the vha now */
1856 DEBUG(msleep(random32()%10)); /* Just to see if something falls on
1857 * the net we have placed below */
1858
1859 BUG_ON(atomic_read(&vha->vref_count));
1860
1861 qla2x00_free_fcports(vha);
1862
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001863 mutex_lock(&ha->vport_lock);
1864 ha->cur_vport_count--;
1865 clear_bit(vha->vp_idx, ha->vp_idx_map);
1866 mutex_unlock(&ha->vport_lock);
1867
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001868 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001869 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001870 qla_printk(KERN_WARNING, ha,
1871 "Queue delete failed.\n");
1872 }
1873
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001874 scsi_host_put(vha->host);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001875 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001876 return 0;
1877}
1878
Adrian Bunka824ebb2008-01-17 09:02:15 -08001879static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001880qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1881{
1882 scsi_qla_host_t *vha = fc_vport->dd_data;
1883
1884 if (disable)
1885 qla24xx_disable_vp(vha);
1886 else
1887 qla24xx_enable_vp(vha);
1888
1889 return 0;
1890}
1891
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001892struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001893
1894 .show_host_node_name = 1,
1895 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001896 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001897 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001898
8482e1182005-04-17 15:04:54 -05001899 .get_host_port_id = qla2x00_get_host_port_id,
1900 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001901 .get_host_speed = qla2x00_get_host_speed,
1902 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001903 .get_host_port_type = qla2x00_get_host_port_type,
1904 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001905 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1906 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001907 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1908 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001909 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1910 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001911 .get_host_port_state = qla2x00_get_host_port_state,
1912 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001913
bdf79622005-04-17 15:06:53 -05001914 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001915 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001916
1917 .get_starget_node_name = qla2x00_get_starget_node_name,
1918 .show_starget_node_name = 1,
1919 .get_starget_port_name = qla2x00_get_starget_port_name,
1920 .show_starget_port_name = 1,
1921 .get_starget_port_id = qla2x00_get_starget_port_id,
1922 .show_starget_port_id = 1,
1923
8482e1182005-04-17 15:04:54 -05001924 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1925 .show_rport_dev_loss_tmo = 1,
1926
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001927 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001928 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1929 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001930 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001931
1932 .vport_create = qla24xx_vport_create,
1933 .vport_disable = qla24xx_vport_disable,
1934 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001935 .bsg_request = qla24xx_bsg_request,
1936 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001937};
1938
1939struct fc_function_template qla2xxx_transport_vport_functions = {
1940
1941 .show_host_node_name = 1,
1942 .show_host_port_name = 1,
1943 .show_host_supported_classes = 1,
1944
1945 .get_host_port_id = qla2x00_get_host_port_id,
1946 .show_host_port_id = 1,
1947 .get_host_speed = qla2x00_get_host_speed,
1948 .show_host_speed = 1,
1949 .get_host_port_type = qla2x00_get_host_port_type,
1950 .show_host_port_type = 1,
1951 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1952 .show_host_symbolic_name = 1,
1953 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1954 .show_host_system_hostname = 1,
1955 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1956 .show_host_fabric_name = 1,
1957 .get_host_port_state = qla2x00_get_host_port_state,
1958 .show_host_port_state = 1,
1959
1960 .dd_fcrport_size = sizeof(struct fc_port *),
1961 .show_rport_supported_classes = 1,
1962
1963 .get_starget_node_name = qla2x00_get_starget_node_name,
1964 .show_starget_node_name = 1,
1965 .get_starget_port_name = qla2x00_get_starget_port_name,
1966 .show_starget_port_name = 1,
1967 .get_starget_port_id = qla2x00_get_starget_port_id,
1968 .show_starget_port_id = 1,
1969
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001970 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1971 .show_rport_dev_loss_tmo = 1,
1972
1973 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001974 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1975 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001976 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001977 .bsg_request = qla24xx_bsg_request,
1978 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05001979};
1980
8482e1182005-04-17 15:04:54 -05001981void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001982qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05001983{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001984 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001985 u32 speed = FC_PORTSPEED_UNKNOWN;
1986
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001987 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1988 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1989 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1990 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1991 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001992
Giridhar Malavalia9083012010-04-12 17:59:55 -07001993 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001994 speed = FC_PORTSPEED_10GBIT;
1995 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001996 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1997 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001998 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001999 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2000 FC_PORTSPEED_1GBIT;
2001 else if (IS_QLA23XX(ha))
2002 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2003 else
2004 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002005 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002006}