blob: d3e58d763b4347f77fa0685b7598d63d603a56e7 [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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-10-13 09:33:37 -0700858 struct sysfs_entry *iter;
859 int ret;
8482e1182005-04-17 15:04:54 -0500860
Andrew Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-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 Vasquezf1663ad52006-10-13 09:33:37 -0700892
Andrew Vasquez7914d002006-06-23 16:10:55 -0700893 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad52006-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
Andrew Vasquez794a5692010-12-21 16:00:21 -08001312qla2x00_thermal_temp_show(struct device *dev,
1313 struct device_attribute *attr, char *buf)
1314{
1315 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1316 int rval = QLA_FUNCTION_FAILED;
1317 uint16_t temp, frac;
1318
1319 if (!vha->hw->flags.thermal_supported)
1320 return snprintf(buf, PAGE_SIZE, "\n");
1321
1322 temp = frac = 0;
1323 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1324 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1325 DEBUG2_3_11(printk(KERN_WARNING
1326 "%s(%ld): isp reset in progress.\n",
1327 __func__, vha->host_no));
1328 else if (!vha->hw->flags.eeh_busy)
1329 rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
1330 if (rval != QLA_SUCCESS)
1331 temp = frac = 0;
1332
1333 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
1334}
1335
1336static ssize_t
Andrew Vasquez656e8912009-06-03 09:55:29 -07001337qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1338 char *buf)
1339{
1340 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
Andrew Vasquez85880802009-12-15 21:29:46 -08001341 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez656e8912009-06-03 09:55:29 -07001342 uint16_t state[5];
1343
Santosh Vernekard6136f32010-03-19 16:59:20 -07001344 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1345 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1346 DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
1347 __func__, vha->host_no));
1348 else if (!vha->hw->flags.eeh_busy)
Andrew Vasquez85880802009-12-15 21:29:46 -08001349 rval = qla2x00_get_firmware_state(vha, state);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001350 if (rval != QLA_SUCCESS)
1351 memset(state, -1, sizeof(state));
1352
1353 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1354 state[1], state[2], state[3], state[4]);
1355}
1356
Tony Jonesee959b02008-02-22 00:13:36 +01001357static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1358static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1359static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1360static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1361static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1362static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1363static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1364static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001365static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001366static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1367static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1368 qla2x00_zio_timer_store);
1369static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1370 qla2x00_beacon_store);
1371static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1372 qla2x00_optrom_bios_version_show, NULL);
1373static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1374 qla2x00_optrom_efi_version_show, NULL);
1375static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1376 qla2x00_optrom_fcode_version_show, NULL);
1377static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1378 NULL);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001379static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
1380 qla2x00_optrom_gold_fw_version_show, NULL);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001381static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1382 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001383static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1384 NULL);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001385static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
Andrew Vasquez55a96152009-03-24 09:08:03 -07001386static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001387static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1388 NULL);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001389static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1390static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1391 qla2x00_vn_port_mac_address_show, NULL);
Andrew Vasquez7f774022009-06-03 09:55:12 -07001392static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
Andrew Vasquez656e8912009-06-03 09:55:29 -07001393static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
Andrew Vasquez794a5692010-12-21 16:00:21 -08001394static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001395
Tony Jonesee959b02008-02-22 00:13:36 +01001396struct device_attribute *qla2x00_host_attrs[] = {
1397 &dev_attr_driver_version,
1398 &dev_attr_fw_version,
1399 &dev_attr_serial_num,
1400 &dev_attr_isp_name,
1401 &dev_attr_isp_id,
1402 &dev_attr_model_name,
1403 &dev_attr_model_desc,
1404 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001405 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01001406 &dev_attr_zio,
1407 &dev_attr_zio_timer,
1408 &dev_attr_beacon,
1409 &dev_attr_optrom_bios_version,
1410 &dev_attr_optrom_efi_version,
1411 &dev_attr_optrom_fcode_version,
1412 &dev_attr_optrom_fw_version,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001413 &dev_attr_84xx_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07001414 &dev_attr_total_isp_aborts,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001415 &dev_attr_mpi_version,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001416 &dev_attr_phy_version,
Lalit Chandivadefbcbb5d2009-03-24 09:08:11 -07001417 &dev_attr_flash_block_size,
Andrew Vasquezbad70012009-04-06 22:33:38 -07001418 &dev_attr_vlan_id,
1419 &dev_attr_vn_port_mac_address,
Andrew Vasquez7f774022009-06-03 09:55:12 -07001420 &dev_attr_fabric_param,
Andrew Vasquez656e8912009-06-03 09:55:29 -07001421 &dev_attr_fw_state,
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05001422 &dev_attr_optrom_gold_fw_version,
Andrew Vasquez794a5692010-12-21 16:00:21 -08001423 &dev_attr_thermal_temp,
Andrew Vasquezafb046e2005-08-26 19:09:40 -07001424 NULL,
1425};
1426
8482e1182005-04-17 15:04:54 -05001427/* Host attributes. */
1428
1429static void
1430qla2x00_get_host_port_id(struct Scsi_Host *shost)
1431{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432 scsi_qla_host_t *vha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -05001433
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001434 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1435 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
8482e1182005-04-17 15:04:54 -05001436}
1437
1438static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001439qla2x00_get_host_speed(struct Scsi_Host *shost)
1440{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001441 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1442 (shost_priv(shost)))->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001443 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001444
1445 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001446 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001447 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001448 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001449 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001450 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001451 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001452 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001453 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001454 break;
Seokmann Juda4541b2008-01-31 12:33:52 -08001455 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001456 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -08001457 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001458 case PORT_SPEED_10GB:
1459 speed = FC_PORTSPEED_10GBIT;
1460 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001461 }
1462 fc_host_speed(shost) = speed;
1463}
1464
1465static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001466qla2x00_get_host_port_type(struct Scsi_Host *shost)
1467{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001468 scsi_qla_host_t *vha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001469 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1470
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001471 if (vha->vp_idx) {
Shyam Sundar2f2fa132008-05-12 22:21:07 -07001472 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1473 return;
1474 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001475 switch (vha->hw->current_topology) {
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001476 case ISP_CFG_NL:
1477 port_type = FC_PORTTYPE_LPORT;
1478 break;
1479 case ISP_CFG_FL:
1480 port_type = FC_PORTTYPE_NLPORT;
1481 break;
1482 case ISP_CFG_N:
1483 port_type = FC_PORTTYPE_PTP;
1484 break;
1485 case ISP_CFG_F:
1486 port_type = FC_PORTTYPE_NPORT;
1487 break;
1488 }
1489 fc_host_port_type(shost) = port_type;
1490}
1491
1492static void
8482e1182005-04-17 15:04:54 -05001493qla2x00_get_starget_node_name(struct scsi_target *starget)
1494{
1495 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001496 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001497 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001498 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -05001499
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001500 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001501 if (fcport->rport &&
1502 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001503 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -05001504 break;
1505 }
1506 }
1507
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001508 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -05001509}
1510
1511static void
1512qla2x00_get_starget_port_name(struct scsi_target *starget)
1513{
1514 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001515 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001516 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001517 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -05001518
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001519 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001520 if (fcport->rport &&
1521 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001522 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -05001523 break;
1524 }
1525 }
1526
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07001527 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -05001528}
1529
1530static void
1531qla2x00_get_starget_port_id(struct scsi_target *starget)
1532{
1533 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001534 scsi_qla_host_t *vha = shost_priv(host);
bdf79622005-04-17 15:06:53 -05001535 fc_port_t *fcport;
1536 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -05001537
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001538 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -07001539 if (fcport->rport &&
1540 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -05001541 port_id = fcport->d_id.b.domain << 16 |
1542 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1543 break;
1544 }
1545 }
1546
8482e1182005-04-17 15:04:54 -05001547 fc_starget_port_id(starget) = port_id;
1548}
1549
1550static void
8482e1182005-04-17 15:04:54 -05001551qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1552{
8482e1182005-04-17 15:04:54 -05001553 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -07001554 rport->dev_loss_tmo = timeout;
8482e1182005-04-17 15:04:54 -05001555 else
Andrew Vasquez85821c92008-07-10 16:55:48 -07001556 rport->dev_loss_tmo = 1;
8482e1182005-04-17 15:04:54 -05001557}
1558
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001559static void
1560qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1561{
1562 struct Scsi_Host *host = rport_to_shost(rport);
1563 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001564 unsigned long flags;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001565
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001566 if (!fcport)
1567 return;
1568
Giridhar Malavali38170fa2010-10-15 11:27:49 -07001569 /* Now that the rport has been deleted, set the fcport state to
1570 FCS_DEVICE_DEAD */
1571 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
1572
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001573 /*
1574 * Transport has effectively 'deleted' the rport, clear
1575 * all local references.
1576 */
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001577 spin_lock_irqsave(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001578 fcport->rport = fcport->drport = NULL;
1579 *((fc_port_t **)rport->dd_data) = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08001580 spin_unlock_irqrestore(host->host_lock, flags);
Giridhar Malavali3fadb80b2010-09-03 15:20:55 -07001581
Andrew Vasquez85880802009-12-15 21:29:46 -08001582 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1583 return;
1584
1585 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -07001586 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
Andrew Vasquez85880802009-12-15 21:29:46 -08001587 return;
1588 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001589}
1590
1591static void
1592qla2x00_terminate_rport_io(struct fc_rport *rport)
1593{
1594 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1595
Seokmann Ju3c01b4f2009-01-22 09:45:38 -08001596 if (!fcport)
1597 return;
1598
Andrew Vasquez85880802009-12-15 21:29:46 -08001599 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1600 return;
1601
Seokmann Jub9b12f72009-03-24 09:08:18 -07001602 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1603 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1604 return;
1605 }
Andrew Vasquez6390d1f2008-08-13 21:36:56 -07001606 /*
1607 * At this point all fcport's software-states are cleared. Perform any
1608 * final cleanup of firmware resources (PCBs and XCBs).
1609 */
Andrew Vasquez6805c152009-06-03 09:55:27 -07001610 if (fcport->loop_id != FC_NO_LOOP_ID &&
1611 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001612 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1613 fcport->loop_id, fcport->d_id.b.domain,
1614 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001615}
1616
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001617static int
1618qla2x00_issue_lip(struct Scsi_Host *shost)
1619{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001620 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001621
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001622 qla2x00_loop_reset(vha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001623 return 0;
1624}
1625
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001626static struct fc_host_statistics *
1627qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1628{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001629 scsi_qla_host_t *vha = shost_priv(shost);
1630 struct qla_hw_data *ha = vha->hw;
1631 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001632 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001633 struct link_statistics *stats;
1634 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001635 struct fc_host_statistics *pfc_host_stat;
1636
1637 pfc_host_stat = &ha->fc_host_stat;
1638 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1639
Andrew Vasquez85880802009-12-15 21:29:46 -08001640 if (test_bit(UNLOADING, &vha->dpc_flags))
1641 goto done;
1642
1643 if (unlikely(pci_channel_offline(ha->pdev)))
1644 goto done;
1645
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001646 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1647 if (stats == NULL) {
1648 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001649 __func__, base_vha->host_no));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001650 goto done;
1651 }
1652 memset(stats, 0, DMA_POOL_SIZE);
1653
1654 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001655 if (IS_FWI2_CAPABLE(ha)) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001656 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1657 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1658 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1659 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
Andrew Vasquez178779a2007-01-29 10:22:25 -08001660 !ha->dpc_active) {
1661 /* Must be in a 'READY' state for statistics retrieval. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001662 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1663 stats, stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001664 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001665
1666 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001667 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001668
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001669 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1670 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1671 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1672 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1673 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1674 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1675 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001676 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001677 pfc_host_stat->tx_frames = stats->tx_frames;
1678 pfc_host_stat->rx_frames = stats->rx_frames;
1679 pfc_host_stat->dumped_frames = stats->dumped_frames;
1680 pfc_host_stat->nos_count = stats->nos_rcvd;
1681 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001682 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1683 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001684
1685done_free:
1686 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001687done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001688 return pfc_host_stat;
1689}
1690
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001691static void
1692qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1693{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001694 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001695
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001696 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001697}
1698
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001699static void
1700qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1701{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001702 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001703
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001704 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001705}
1706
Andrew Vasquez90991c82006-10-02 12:00:46 -07001707static void
1708qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1709{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001710 scsi_qla_host_t *vha = shost_priv(shost);
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001711 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1712 0xFF, 0xFF, 0xFF, 0xFF};
1713 u64 fabric_name = wwn_to_u64(node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001714
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001715 if (vha->device_flags & SWITCH_FOUND)
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001716 fabric_name = wwn_to_u64(vha->fabric_node_name);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001717
Giridhar Malavali35e0cbd2010-09-03 15:20:51 -07001718 fc_host_fabric_name(shost) = fabric_name;
Andrew Vasquez90991c82006-10-02 12:00:46 -07001719}
1720
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001721static void
1722qla2x00_get_host_port_state(struct Scsi_Host *shost)
1723{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001724 scsi_qla_host_t *vha = shost_priv(shost);
1725 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001726
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001727 if (!base_vha->flags.online)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001728 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001729 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001730 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1731 else
1732 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1733}
1734
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001735static int
1736qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1737{
1738 int ret = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001739 uint8_t qos = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001740 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1741 scsi_qla_host_t *vha = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001742 struct qla_hw_data *ha = base_vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001743 uint16_t options = 0;
1744 int cnt;
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001745 struct req_que *req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001746
1747 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1748 if (ret) {
1749 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1750 "status %x\n", ret));
1751 return (ret);
1752 }
1753
1754 vha = qla24xx_create_vhost(fc_vport);
1755 if (vha == NULL) {
1756 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1757 vha));
1758 return FC_VPORT_FAILED;
1759 }
1760 if (disable) {
1761 atomic_set(&vha->vp_state, VP_OFFLINE);
1762 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1763 } else
1764 atomic_set(&vha->vp_state, VP_FAILED);
1765
1766 /* ready to create vport */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001767 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1768 vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001769
1770 /* initialized vport states */
1771 atomic_set(&vha->loop_state, LOOP_DOWN);
1772 vha->vp_err_state= VP_ERR_PORTDWN;
1773 vha->vp_prev_err_state= VP_ERR_UNKWN;
1774 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001775 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1776 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001777 /* Don't retry or attempt login of this virtual port */
1778 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001779 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001780 atomic_set(&vha->loop_state, LOOP_DEAD);
1781 if (!disable)
1782 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1783 }
1784
Arun Easiba77ef52010-05-28 15:08:27 -07001785 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07001786 if (ha->fw_attributes & BIT_4) {
1787 vha->flags.difdix_supported = 1;
1788 DEBUG18(qla_printk(KERN_INFO, ha,
1789 "Registering for DIF/DIX type 1 and 3"
1790 " protection.\n"));
1791 scsi_host_set_prot(vha->host,
1792 SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001793 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001794 | SHOST_DIF_TYPE3_PROTECTION
1795 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05001796 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07001797 | SHOST_DIX_TYPE3_PROTECTION);
1798 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1799 } else
1800 vha->flags.difdix_supported = 0;
1801 }
1802
James Bottomleyd139b9b2009-11-05 13:33:12 -06001803 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1804 &ha->pdev->dev)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001805 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1806 vha->host_no, vha->vp_idx));
1807 goto vport_create_failed_2;
1808 }
1809
1810 /* initialize attributes */
Mike Christied2b5f102010-09-15 16:52:30 -05001811 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001812 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1813 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1814 fc_host_supported_classes(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001815 fc_host_supported_classes(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001816 fc_host_supported_speeds(vha->host) =
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001817 fc_host_supported_speeds(base_vha->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001818
1819 qla24xx_vport_disable(fc_vport, disable);
1820
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001821 if (ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001822 req = ha->req_q_map[1];
1823 goto vport_queue;
1824 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001825 goto vport_queue;
1826 /* Create a request queue in QoS mode for the vport */
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001827 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1828 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1829 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001830 8) == 0) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001831 qos = ha->npiv_info[cnt].q_qos;
1832 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001833 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001834 }
1835 if (qos) {
1836 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1837 qos);
1838 if (!ret)
1839 qla_printk(KERN_WARNING, ha,
1840 "Can't create request queue for vp_idx:%d\n",
1841 vha->vp_idx);
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001842 else {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001843 DEBUG2(qla_printk(KERN_INFO, ha,
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001844 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1845 ret, qos, vha->vp_idx));
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001846 req = ha->req_q_map[ret];
1847 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001848 }
1849
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001850vport_queue:
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001851 vha->req = req;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852 return 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001853
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001854vport_create_failed_2:
1855 qla24xx_disable_vp(vha);
1856 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001857 scsi_host_put(vha->host);
1858 return FC_VPORT_FAILED;
1859}
1860
Adrian Bunka824ebb2008-01-17 09:02:15 -08001861static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001862qla24xx_vport_delete(struct fc_vport *fc_vport)
1863{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001864 scsi_qla_host_t *vha = fc_vport->dd_data;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001865 struct qla_hw_data *ha = vha->hw;
1866 uint16_t id = vha->vp_idx;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001867
1868 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001869 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001870 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001871
1872 qla24xx_disable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001873
Arun Easifeafb7b2010-09-03 14:57:00 -07001874 vha->flags.delete_progress = 1;
1875
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001876 fc_remove_host(vha->host);
1877
1878 scsi_remove_host(vha->host);
1879
Arun Easifeafb7b2010-09-03 14:57:00 -07001880 if (vha->timer_active) {
1881 qla2x00_vp_stop_timer(vha);
1882 DEBUG15(printk(KERN_INFO "scsi(%ld): timer for the vport[%d]"
1883 " = %p has stopped\n", vha->host_no, vha->vp_idx, vha));
1884 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001885
1886 qla24xx_deallocate_vp_id(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001887
Arun Easifeafb7b2010-09-03 14:57:00 -07001888 /* No pending activities shall be there on the vha now */
1889 DEBUG(msleep(random32()%10)); /* Just to see if something falls on
1890 * the net we have placed below */
1891
1892 BUG_ON(atomic_read(&vha->vref_count));
1893
1894 qla2x00_free_fcports(vha);
1895
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001896 mutex_lock(&ha->vport_lock);
1897 ha->cur_vport_count--;
1898 clear_bit(vha->vp_idx, ha->vp_idx_map);
1899 mutex_unlock(&ha->vport_lock);
1900
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001901 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001902 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
Anirban Chakrabortycf5a1632009-02-08 20:50:13 -08001903 qla_printk(KERN_WARNING, ha,
1904 "Queue delete failed.\n");
1905 }
1906
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001907 scsi_host_put(vha->host);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001908 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001909 return 0;
1910}
1911
Adrian Bunka824ebb2008-01-17 09:02:15 -08001912static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001913qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1914{
1915 scsi_qla_host_t *vha = fc_vport->dd_data;
1916
1917 if (disable)
1918 qla24xx_disable_vp(vha);
1919 else
1920 qla24xx_enable_vp(vha);
1921
1922 return 0;
1923}
1924
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001925struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001926
1927 .show_host_node_name = 1,
1928 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001929 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001930 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001931
8482e1182005-04-17 15:04:54 -05001932 .get_host_port_id = qla2x00_get_host_port_id,
1933 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001934 .get_host_speed = qla2x00_get_host_speed,
1935 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001936 .get_host_port_type = qla2x00_get_host_port_type,
1937 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001938 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1939 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001940 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1941 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001942 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1943 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001944 .get_host_port_state = qla2x00_get_host_port_state,
1945 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001946
bdf79622005-04-17 15:06:53 -05001947 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001948 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001949
1950 .get_starget_node_name = qla2x00_get_starget_node_name,
1951 .show_starget_node_name = 1,
1952 .get_starget_port_name = qla2x00_get_starget_port_name,
1953 .show_starget_port_name = 1,
1954 .get_starget_port_id = qla2x00_get_starget_port_id,
1955 .show_starget_port_id = 1,
1956
8482e1182005-04-17 15:04:54 -05001957 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1958 .show_rport_dev_loss_tmo = 1,
1959
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001960 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001961 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1962 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001963 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001964
1965 .vport_create = qla24xx_vport_create,
1966 .vport_disable = qla24xx_vport_disable,
1967 .vport_delete = qla24xx_vport_delete,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001968 .bsg_request = qla24xx_bsg_request,
1969 .bsg_timeout = qla24xx_bsg_timeout,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001970};
1971
1972struct fc_function_template qla2xxx_transport_vport_functions = {
1973
1974 .show_host_node_name = 1,
1975 .show_host_port_name = 1,
1976 .show_host_supported_classes = 1,
1977
1978 .get_host_port_id = qla2x00_get_host_port_id,
1979 .show_host_port_id = 1,
1980 .get_host_speed = qla2x00_get_host_speed,
1981 .show_host_speed = 1,
1982 .get_host_port_type = qla2x00_get_host_port_type,
1983 .show_host_port_type = 1,
1984 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1985 .show_host_symbolic_name = 1,
1986 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1987 .show_host_system_hostname = 1,
1988 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1989 .show_host_fabric_name = 1,
1990 .get_host_port_state = qla2x00_get_host_port_state,
1991 .show_host_port_state = 1,
1992
1993 .dd_fcrport_size = sizeof(struct fc_port *),
1994 .show_rport_supported_classes = 1,
1995
1996 .get_starget_node_name = qla2x00_get_starget_node_name,
1997 .show_starget_node_name = 1,
1998 .get_starget_port_name = qla2x00_get_starget_port_name,
1999 .show_starget_port_name = 1,
2000 .get_starget_port_id = qla2x00_get_starget_port_id,
2001 .show_starget_port_id = 1,
2002
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002003 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2004 .show_rport_dev_loss_tmo = 1,
2005
2006 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002007 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2008 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002009 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002010 .bsg_request = qla24xx_bsg_request,
2011 .bsg_timeout = qla24xx_bsg_timeout,
8482e1182005-04-17 15:04:54 -05002012};
2013
8482e1182005-04-17 15:04:54 -05002014void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002015qla2x00_init_host_attr(scsi_qla_host_t *vha)
8482e1182005-04-17 15:04:54 -05002016{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002017 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002018 u32 speed = FC_PORTSPEED_UNKNOWN;
2019
Mike Christied2b5f102010-09-15 16:52:30 -05002020 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002021 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2022 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2023 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
2024 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2025 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002026
Giridhar Malavalia9083012010-04-12 17:59:55 -07002027 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002028 speed = FC_PORTSPEED_10GBIT;
2029 else if (IS_QLA25XX(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002030 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2031 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002032 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07002033 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2034 FC_PORTSPEED_1GBIT;
2035 else if (IS_QLA23XX(ha))
2036 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2037 else
2038 speed = FC_PORTSPEED_1GBIT;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002039 fc_host_supported_speeds(vha->host) = speed;
8482e1182005-04-17 15:04:54 -05002040}