blob: 0ddfe7106b3bd1cc270849d76e2d7b8a9071e296 [file] [log] [blame]
8482e112005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
8482e112005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e112005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
FUJITA Tomonori00eabe72008-07-28 11:59:20 +090011#include <linux/delay.h>
8482e112005-04-17 15:04:54 -050012
Adrian Bunka824ebb2008-01-17 09:02:15 -080013static int qla24xx_vport_disable(struct fc_vport *, bool);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070014
8482e112005-04-17 15:04:54 -050015/* SYSFS attributes --------------------------------------------------------- */
16
17static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080018qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
19 struct bin_attribute *bin_attr,
20 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050021{
Andrew Vasquezf363b942007-09-20 14:07:45 -070022 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050023 struct device, kobj)));
24
25 if (ha->fw_dump_reading == 0)
26 return 0;
8482e112005-04-17 15:04:54 -050027
Akinobu Mitab3dc9082008-07-24 08:31:47 -070028 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
29 ha->fw_dump_len);
8482e112005-04-17 15:04:54 -050030}
31
32static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080033qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
34 struct bin_attribute *bin_attr,
35 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050036{
Andrew Vasquezf363b942007-09-20 14:07:45 -070037 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050038 struct device, kobj)));
39 int reading;
8482e112005-04-17 15:04:54 -050040
41 if (off != 0)
42 return (0);
43
44 reading = simple_strtol(buf, NULL, 10);
45 switch (reading) {
46 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070047 if (!ha->fw_dump_reading)
48 break;
8482e112005-04-17 15:04:54 -050049
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070050 qla_printk(KERN_INFO, ha,
51 "Firmware dump cleared on (%ld).\n", ha->host_no);
52
53 ha->fw_dump_reading = 0;
54 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050055 break;
56 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070057 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050058 ha->fw_dump_reading = 1;
59
8482e112005-04-17 15:04:54 -050060 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070061 "Raw firmware dump ready for read on (%ld).\n",
8482e112005-04-17 15:04:54 -050062 ha->host_no);
8482e112005-04-17 15:04:54 -050063 }
64 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070065 case 2:
66 qla2x00_alloc_fw_dump(ha);
67 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070068 case 3:
69 qla2x00_system_error(ha);
70 break;
8482e112005-04-17 15:04:54 -050071 }
72 return (count);
73}
74
75static struct bin_attribute sysfs_fw_dump_attr = {
76 .attr = {
77 .name = "fw_dump",
78 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050079 },
80 .size = 0,
81 .read = qla2x00_sysfs_read_fw_dump,
82 .write = qla2x00_sysfs_write_fw_dump,
83};
84
85static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080086qla2x00_sysfs_read_nvram(struct kobject *kobj,
87 struct bin_attribute *bin_attr,
88 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050089{
Andrew Vasquezf363b942007-09-20 14:07:45 -070090 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050091 struct device, kobj)));
8482e112005-04-17 15:04:54 -050092
Akinobu Mitab3dc9082008-07-24 08:31:47 -070093 if (!capable(CAP_SYS_ADMIN))
8482e112005-04-17 15:04:54 -050094 return 0;
95
Seokmann Ju281afe12007-07-26 13:43:34 -070096 /* Read NVRAM data from cache. */
Akinobu Mitab3dc9082008-07-24 08:31:47 -070097 return memory_read_from_buffer(buf, count, &off, ha->nvram,
98 ha->nvram_size);
8482e112005-04-17 15:04:54 -050099}
100
101static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800102qla2x00_sysfs_write_nvram(struct kobject *kobj,
103 struct bin_attribute *bin_attr,
104 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500105{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700106 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -0500107 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500108 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500109
Andrew Vasquez459c5372005-07-06 10:31:07 -0700110 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500111 return 0;
112
113 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700114 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700115 uint32_t *iter;
116 uint32_t chksum;
117
118 iter = (uint32_t *)buf;
119 chksum = 0;
120 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
121 chksum += le32_to_cpu(*iter++);
122 chksum = ~chksum + 1;
123 *iter = cpu_to_le32(chksum);
124 } else {
125 uint8_t *iter;
126 uint8_t chksum;
127
128 iter = (uint8_t *)buf;
129 chksum = 0;
130 for (cnt = 0; cnt < count - 1; cnt++)
131 chksum += *iter++;
132 chksum = ~chksum + 1;
133 *iter = chksum;
134 }
8482e112005-04-17 15:04:54 -0500135
136 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700137 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
Andrew Vasquezc45bcc82007-09-20 14:07:42 -0700138 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700139 count);
8482e112005-04-17 15:04:54 -0500140
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800141 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
142
8482e112005-04-17 15:04:54 -0500143 return (count);
144}
145
146static struct bin_attribute sysfs_nvram_attr = {
147 .attr = {
148 .name = "nvram",
149 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500150 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800151 .size = 512,
8482e112005-04-17 15:04:54 -0500152 .read = qla2x00_sysfs_read_nvram,
153 .write = qla2x00_sysfs_write_nvram,
154};
155
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800156static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800157qla2x00_sysfs_read_optrom(struct kobject *kobj,
158 struct bin_attribute *bin_attr,
159 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800160{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700161 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800162 struct device, kobj)));
163
164 if (ha->optrom_state != QLA_SREADING)
165 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800166
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700167 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
168 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800169}
170
171static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800172qla2x00_sysfs_write_optrom(struct kobject *kobj,
173 struct bin_attribute *bin_attr,
174 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800175{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700176 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800177 struct device, kobj)));
178
179 if (ha->optrom_state != QLA_SWRITING)
180 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700181 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800182 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700183 if (off + count > ha->optrom_region_size)
184 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800185
186 memcpy(&ha->optrom_buffer[off], buf, count);
187
188 return count;
189}
190
191static struct bin_attribute sysfs_optrom_attr = {
192 .attr = {
193 .name = "optrom",
194 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800195 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700196 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800197 .read = qla2x00_sysfs_read_optrom,
198 .write = qla2x00_sysfs_write_optrom,
199};
200
201static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800202qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
203 struct bin_attribute *bin_attr,
204 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800205{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700206 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800207 struct device, kobj)));
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700208 uint32_t start = 0;
209 uint32_t size = ha->optrom_size;
210 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800211
212 if (off)
213 return 0;
214
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700215 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
216 return -EINVAL;
217 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800218 return -EINVAL;
219
220 switch (val) {
221 case 0:
222 if (ha->optrom_state != QLA_SREADING &&
223 ha->optrom_state != QLA_SWRITING)
224 break;
225
226 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700227
228 DEBUG2(qla_printk(KERN_INFO, ha,
229 "Freeing flash region allocation -- 0x%x bytes.\n",
230 ha->optrom_region_size));
231
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 vfree(ha->optrom_buffer);
233 ha->optrom_buffer = NULL;
234 break;
235 case 1:
236 if (ha->optrom_state != QLA_SWAITING)
237 break;
238
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700239 if (start & 0xfff) {
240 qla_printk(KERN_WARNING, ha,
241 "Invalid start region 0x%x/0x%x.\n", start, size);
242 return -EINVAL;
243 }
244
245 ha->optrom_region_start = start;
246 ha->optrom_region_size = start + size > ha->optrom_size ?
247 ha->optrom_size - start : size;
248
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800249 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700250 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800251 if (ha->optrom_buffer == NULL) {
252 qla_printk(KERN_WARNING, ha,
253 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700254 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800255
256 ha->optrom_state = QLA_SWAITING;
257 return count;
258 }
259
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700260 DEBUG2(qla_printk(KERN_INFO, ha,
261 "Reading flash region -- 0x%x/0x%x.\n",
262 ha->optrom_region_start, ha->optrom_region_size));
263
264 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
265 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
266 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800267 break;
268 case 2:
269 if (ha->optrom_state != QLA_SWAITING)
270 break;
271
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700272 /*
273 * We need to be more restrictive on which FLASH regions are
274 * allowed to be updated via user-space. Regions accessible
275 * via this method include:
276 *
277 * ISP21xx/ISP22xx/ISP23xx type boards:
278 *
279 * 0x000000 -> 0x020000 -- Boot code.
280 *
281 * ISP2322/ISP24xx type boards:
282 *
283 * 0x000000 -> 0x07ffff -- Boot code.
284 * 0x080000 -> 0x0fffff -- Firmware.
285 *
286 * ISP25xx type boards:
287 *
288 * 0x000000 -> 0x07ffff -- Boot code.
289 * 0x080000 -> 0x0fffff -- Firmware.
290 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
291 */
292 valid = 0;
293 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
294 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700295 else if (start == (ha->flt_region_boot * 4) ||
296 start == (ha->flt_region_fw * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700297 valid = 1;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700298 else if (IS_QLA25XX(ha) &&
299 start == (ha->flt_region_vpd_nvram * 4))
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700300 valid = 1;
301 if (!valid) {
302 qla_printk(KERN_WARNING, ha,
303 "Invalid start region 0x%x/0x%x.\n", start, size);
304 return -EINVAL;
305 }
306
307 ha->optrom_region_start = start;
308 ha->optrom_region_size = start + size > ha->optrom_size ?
309 ha->optrom_size - start : size;
310
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800311 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700312 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800313 if (ha->optrom_buffer == NULL) {
314 qla_printk(KERN_WARNING, ha,
315 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700316 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800317
318 ha->optrom_state = QLA_SWAITING;
319 return count;
320 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700321
322 DEBUG2(qla_printk(KERN_INFO, ha,
323 "Staging flash region write -- 0x%x/0x%x.\n",
324 ha->optrom_region_start, ha->optrom_region_size));
325
326 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800327 break;
328 case 3:
329 if (ha->optrom_state != QLA_SWRITING)
330 break;
331
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700332 DEBUG2(qla_printk(KERN_INFO, ha,
333 "Writing flash region -- 0x%x/0x%x.\n",
334 ha->optrom_region_start, ha->optrom_region_size));
335
336 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
337 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800338 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700339 default:
340 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800341 }
342 return count;
343}
344
345static struct bin_attribute sysfs_optrom_ctl_attr = {
346 .attr = {
347 .name = "optrom_ctl",
348 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800349 },
350 .size = 0,
351 .write = qla2x00_sysfs_write_optrom_ctl,
352};
353
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800354static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800355qla2x00_sysfs_read_vpd(struct kobject *kobj,
356 struct bin_attribute *bin_attr,
357 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800358{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700359 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800360 struct device, kobj)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800361
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700362 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800363 return 0;
364
Seokmann Ju281afe12007-07-26 13:43:34 -0700365 /* Read NVRAM data from cache. */
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700366 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800367}
368
369static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800370qla2x00_sysfs_write_vpd(struct kobject *kobj,
371 struct bin_attribute *bin_attr,
372 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800373{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700374 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800375 struct device, kobj)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800376
377 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
378 return 0;
379
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800380 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700381 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
Seokmann Ju281afe12007-07-26 13:43:34 -0700382 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800383
384 return count;
385}
386
387static struct bin_attribute sysfs_vpd_attr = {
388 .attr = {
389 .name = "vpd",
390 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800391 },
392 .size = 0,
393 .read = qla2x00_sysfs_read_vpd,
394 .write = qla2x00_sysfs_write_vpd,
395};
396
Andrew Vasquez88729e52006-06-23 16:10:50 -0700397static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800398qla2x00_sysfs_read_sfp(struct kobject *kobj,
399 struct bin_attribute *bin_attr,
400 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700401{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700402 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700403 struct device, kobj)));
404 uint16_t iter, addr, offset;
405 int rval;
406
407 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
408 return 0;
409
Andrew Vasqueze8711082008-01-31 12:33:48 -0800410 if (ha->sfp_data)
411 goto do_read;
412
413 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
414 &ha->sfp_data_dma);
415 if (!ha->sfp_data) {
416 qla_printk(KERN_WARNING, ha,
417 "Unable to allocate memory for SFP read-data.\n");
418 return 0;
419 }
420
421do_read:
422 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700423 addr = 0xa0;
424 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
425 iter++, offset += SFP_BLOCK_SIZE) {
426 if (iter == 4) {
427 /* Skip to next device address. */
428 addr = 0xa2;
429 offset = 0;
430 }
431
432 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
433 SFP_BLOCK_SIZE);
434 if (rval != QLA_SUCCESS) {
435 qla_printk(KERN_WARNING, ha,
436 "Unable to read SFP data (%x/%x/%x).\n", rval,
437 addr, offset);
438 count = 0;
439 break;
440 }
441 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
442 buf += SFP_BLOCK_SIZE;
443 }
444
445 return count;
446}
447
448static struct bin_attribute sysfs_sfp_attr = {
449 .attr = {
450 .name = "sfp",
451 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700452 },
453 .size = SFP_DEV_SIZE * 2,
454 .read = qla2x00_sysfs_read_sfp,
455};
456
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700457static struct sysfs_entry {
458 char *name;
459 struct bin_attribute *attr;
460 int is4GBp_only;
461} bin_file_entries[] = {
462 { "fw_dump", &sysfs_fw_dump_attr, },
463 { "nvram", &sysfs_nvram_attr, },
464 { "optrom", &sysfs_optrom_attr, },
465 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
466 { "vpd", &sysfs_vpd_attr, 1 },
467 { "sfp", &sysfs_sfp_attr, 1 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800468 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700469};
470
8482e112005-04-17 15:04:54 -0500471void
472qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
473{
474 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700475 struct sysfs_entry *iter;
476 int ret;
8482e112005-04-17 15:04:54 -0500477
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700478 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700479 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700480 continue;
481
482 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
483 iter->attr);
484 if (ret)
485 qla_printk(KERN_INFO, ha,
486 "Unable to create sysfs %s binary attribute "
487 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700488 }
8482e112005-04-17 15:04:54 -0500489}
490
491void
492qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
493{
494 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700495 struct sysfs_entry *iter;
8482e112005-04-17 15:04:54 -0500496
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700497 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700498 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700499 continue;
500
Andrew Vasquez7914d002006-06-23 16:10:55 -0700501 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700502 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700503 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800504
505 if (ha->beacon_blink_led == 1)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700506 ha->isp_ops->beacon_off(ha);
8482e112005-04-17 15:04:54 -0500507}
508
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700509/* Scsi_Host attributes. */
510
511static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100512qla2x00_drvr_version_show(struct device *dev,
513 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700514{
515 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
516}
517
518static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100519qla2x00_fw_version_show(struct device *dev,
520 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700521{
Tony Jonesee959b02008-02-22 00:13:36 +0100522 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700523 char fw_str[30];
524
525 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700526 ha->isp_ops->fw_version_str(ha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700527}
528
529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
531 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700534 uint32_t sn;
535
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700536 if (IS_FWI2_CAPABLE(ha)) {
537 qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
538 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
539 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700540
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700541 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
542 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
543 sn % 100000);
544}
545
546static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100547qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
548 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700549{
Tony Jonesee959b02008-02-22 00:13:36 +0100550 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800551 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700552}
553
554static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100555qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
556 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700557{
Tony Jonesee959b02008-02-22 00:13:36 +0100558 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700559 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
560 ha->product_id[0], ha->product_id[1], ha->product_id[2],
561 ha->product_id[3]);
562}
563
564static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100565qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
566 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700567{
Tony Jonesee959b02008-02-22 00:13:36 +0100568 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700569 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
570}
571
572static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100573qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
574 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700575{
Tony Jonesee959b02008-02-22 00:13:36 +0100576 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700577 return snprintf(buf, PAGE_SIZE, "%s\n",
578 ha->model_desc ? ha->model_desc: "");
579}
580
581static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100582qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
583 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700584{
Tony Jonesee959b02008-02-22 00:13:36 +0100585 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700586 char pci_info[30];
587
588 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700589 ha->isp_ops->pci_info_str(ha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700590}
591
592static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100593qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
594 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700595{
Tony Jonesee959b02008-02-22 00:13:36 +0100596 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700597 int len = 0;
598
599 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
600 atomic_read(&ha->loop_state) == LOOP_DEAD)
601 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
602 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
603 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
604 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
605 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
606 else {
607 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
608
609 switch (ha->current_topology) {
610 case ISP_CFG_NL:
611 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
612 break;
613 case ISP_CFG_FL:
614 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
615 break;
616 case ISP_CFG_N:
617 len += snprintf(buf + len, PAGE_SIZE-len,
618 "N_Port to N_Port\n");
619 break;
620 case ISP_CFG_F:
621 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
622 break;
623 default:
624 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
625 break;
626 }
627 }
628 return len;
629}
630
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700631static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100632qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
633 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700634{
Tony Jonesee959b02008-02-22 00:13:36 +0100635 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700636 int len = 0;
637
638 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700639 case QLA_ZIO_MODE_6:
640 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
641 break;
642 case QLA_ZIO_DISABLED:
643 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
644 break;
645 }
646 return len;
647}
648
649static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100650qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
651 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700652{
Tony Jonesee959b02008-02-22 00:13:36 +0100653 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700654 int val = 0;
655 uint16_t zio_mode;
656
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800657 if (!IS_ZIO_SUPPORTED(ha))
658 return -ENOTSUPP;
659
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700660 if (sscanf(buf, "%d", &val) != 1)
661 return -EINVAL;
662
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800663 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700664 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800665 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700666 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700667
668 /* Update per-hba values and queue a reset. */
669 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
670 ha->zio_mode = zio_mode;
671 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
672 }
673 return strlen(buf);
674}
675
676static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100677qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
678 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700679{
Tony Jonesee959b02008-02-22 00:13:36 +0100680 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700681
682 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
683}
684
685static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100686qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
687 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700688{
Tony Jonesee959b02008-02-22 00:13:36 +0100689 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700690 int val = 0;
691 uint16_t zio_timer;
692
693 if (sscanf(buf, "%d", &val) != 1)
694 return -EINVAL;
695 if (val > 25500 || val < 100)
696 return -ERANGE;
697
698 zio_timer = (uint16_t)(val / 100);
699 ha->zio_timer = zio_timer;
700
701 return strlen(buf);
702}
703
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800704static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100705qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
706 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800707{
Tony Jonesee959b02008-02-22 00:13:36 +0100708 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800709 int len = 0;
710
711 if (ha->beacon_blink_led)
712 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
713 else
714 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
715 return len;
716}
717
718static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100719qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
720 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800721{
Tony Jonesee959b02008-02-22 00:13:36 +0100722 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800723 int val = 0;
724 int rval;
725
726 if (IS_QLA2100(ha) || IS_QLA2200(ha))
727 return -EPERM;
728
729 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
730 qla_printk(KERN_WARNING, ha,
731 "Abort ISP active -- ignoring beacon request.\n");
732 return -EBUSY;
733 }
734
735 if (sscanf(buf, "%d", &val) != 1)
736 return -EINVAL;
737
738 if (val)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700739 rval = ha->isp_ops->beacon_on(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800740 else
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700741 rval = ha->isp_ops->beacon_off(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800742
743 if (rval != QLA_SUCCESS)
744 count = 0;
745
746 return count;
747}
748
Andrew Vasquez30c47662007-01-29 10:22:21 -0800749static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100750qla2x00_optrom_bios_version_show(struct device *dev,
751 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800752{
Tony Jonesee959b02008-02-22 00:13:36 +0100753 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800754
755 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
756 ha->bios_revision[0]);
757}
758
759static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100760qla2x00_optrom_efi_version_show(struct device *dev,
761 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800762{
Tony Jonesee959b02008-02-22 00:13:36 +0100763 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800764
765 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
766 ha->efi_revision[0]);
767}
768
769static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100770qla2x00_optrom_fcode_version_show(struct device *dev,
771 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800772{
Tony Jonesee959b02008-02-22 00:13:36 +0100773 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800774
775 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
776 ha->fcode_revision[0]);
777}
778
779static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100780qla2x00_optrom_fw_version_show(struct device *dev,
781 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800782{
Tony Jonesee959b02008-02-22 00:13:36 +0100783 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800784
785 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
786 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
787 ha->fw_revision[3]);
788}
789
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700790static ssize_t
791qla2x00_total_isp_aborts_show(struct device *dev,
792 struct device_attribute *attr, char *buf)
793{
794 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
795
796 return snprintf(buf, PAGE_SIZE, "%d\n",
797 ha->qla_stats.total_isp_aborts);
798}
799
Tony Jonesee959b02008-02-22 00:13:36 +0100800static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
801static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
802static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
803static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
804static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
805static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
806static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
807static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100808static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +0100809static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
810static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
811 qla2x00_zio_timer_store);
812static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
813 qla2x00_beacon_store);
814static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
815 qla2x00_optrom_bios_version_show, NULL);
816static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
817 qla2x00_optrom_efi_version_show, NULL);
818static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
819 qla2x00_optrom_fcode_version_show, NULL);
820static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
821 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700822static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
823 NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700824
Tony Jonesee959b02008-02-22 00:13:36 +0100825struct device_attribute *qla2x00_host_attrs[] = {
826 &dev_attr_driver_version,
827 &dev_attr_fw_version,
828 &dev_attr_serial_num,
829 &dev_attr_isp_name,
830 &dev_attr_isp_id,
831 &dev_attr_model_name,
832 &dev_attr_model_desc,
833 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100834 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +0100835 &dev_attr_zio,
836 &dev_attr_zio_timer,
837 &dev_attr_beacon,
838 &dev_attr_optrom_bios_version,
839 &dev_attr_optrom_efi_version,
840 &dev_attr_optrom_fcode_version,
841 &dev_attr_optrom_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700842 &dev_attr_total_isp_aborts,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700843 NULL,
844};
845
8482e112005-04-17 15:04:54 -0500846/* Host attributes. */
847
848static void
849qla2x00_get_host_port_id(struct Scsi_Host *shost)
850{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700851 scsi_qla_host_t *ha = shost_priv(shost);
8482e112005-04-17 15:04:54 -0500852
853 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
854 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
855}
856
857static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800858qla2x00_get_host_speed(struct Scsi_Host *shost)
859{
Seokmann Juda4541b2008-01-31 12:33:52 -0800860 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700861 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800862
863 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700864 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700865 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800866 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700867 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700868 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800869 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700870 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700871 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800872 break;
Seokmann Juda4541b2008-01-31 12:33:52 -0800873 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700874 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -0800875 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800876 }
877 fc_host_speed(shost) = speed;
878}
879
880static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800881qla2x00_get_host_port_type(struct Scsi_Host *shost)
882{
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700883 scsi_qla_host_t *ha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800884 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
885
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700886 if (ha->parent) {
887 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
888 return;
889 }
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800890 switch (ha->current_topology) {
891 case ISP_CFG_NL:
892 port_type = FC_PORTTYPE_LPORT;
893 break;
894 case ISP_CFG_FL:
895 port_type = FC_PORTTYPE_NLPORT;
896 break;
897 case ISP_CFG_N:
898 port_type = FC_PORTTYPE_PTP;
899 break;
900 case ISP_CFG_F:
901 port_type = FC_PORTTYPE_NPORT;
902 break;
903 }
904 fc_host_port_type(shost) = port_type;
905}
906
907static void
8482e112005-04-17 15:04:54 -0500908qla2x00_get_starget_node_name(struct scsi_target *starget)
909{
910 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700911 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500912 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700913 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500914
bdf79622005-04-17 15:06:53 -0500915 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700916 if (fcport->rport &&
917 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700918 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500919 break;
920 }
921 }
922
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700923 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500924}
925
926static void
927qla2x00_get_starget_port_name(struct scsi_target *starget)
928{
929 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700930 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500931 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700932 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500933
bdf79622005-04-17 15:06:53 -0500934 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700935 if (fcport->rport &&
936 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700937 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500938 break;
939 }
940 }
941
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700942 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500943}
944
945static void
946qla2x00_get_starget_port_id(struct scsi_target *starget)
947{
948 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700949 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500950 fc_port_t *fcport;
951 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500952
bdf79622005-04-17 15:06:53 -0500953 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700954 if (fcport->rport &&
955 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -0500956 port_id = fcport->d_id.b.domain << 16 |
957 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
958 break;
959 }
960 }
961
8482e112005-04-17 15:04:54 -0500962 fc_starget_port_id(starget) = port_id;
963}
964
965static void
8482e112005-04-17 15:04:54 -0500966qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
967{
8482e112005-04-17 15:04:54 -0500968 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -0700969 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -0500970 else
Andrew Vasquez85821c92008-07-10 16:55:48 -0700971 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -0500972}
973
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700974static void
975qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
976{
977 struct Scsi_Host *host = rport_to_shost(rport);
978 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
979
980 qla2x00_abort_fcport_cmds(fcport);
981
982 /*
983 * Transport has effectively 'deleted' the rport, clear
984 * all local references.
985 */
986 spin_lock_irq(host->host_lock);
987 fcport->rport = NULL;
988 *((fc_port_t **)rport->dd_data) = NULL;
989 spin_unlock_irq(host->host_lock);
990}
991
992static void
993qla2x00_terminate_rport_io(struct fc_rport *rport)
994{
995 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
996
Andrew Vasquez6390d1f2008-08-13 21:36:56 -0700997 /*
998 * At this point all fcport's software-states are cleared. Perform any
999 * final cleanup of firmware resources (PCBs and XCBs).
1000 */
1001 if (fcport->loop_id != FC_NO_LOOP_ID) {
1002 fcport->ha->isp_ops->fabric_logout(fcport->ha, fcport->loop_id,
1003 fcport->d_id.b.domain, fcport->d_id.b.area,
1004 fcport->d_id.b.al_pa);
1005 fcport->loop_id = FC_NO_LOOP_ID;
1006 }
1007
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001008 qla2x00_abort_fcport_cmds(fcport);
1009 scsi_target_unblock(&rport->dev);
1010}
1011
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001012static int
1013qla2x00_issue_lip(struct Scsi_Host *shost)
1014{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001015 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001016
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001017 qla2x00_loop_reset(ha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001018 return 0;
1019}
1020
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001021static struct fc_host_statistics *
1022qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1023{
Seokmann Juda4541b2008-01-31 12:33:52 -08001024 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001025 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001026 struct link_statistics *stats;
1027 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001028 struct fc_host_statistics *pfc_host_stat;
1029
1030 pfc_host_stat = &ha->fc_host_stat;
1031 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1032
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001033 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1034 if (stats == NULL) {
1035 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1036 __func__, ha->host_no));
1037 goto done;
1038 }
1039 memset(stats, 0, DMA_POOL_SIZE);
1040
1041 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001042 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001043 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001044 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1045 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1046 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1047 !ha->dpc_active) {
1048 /* Must be in a 'READY' state for statistics retrieval. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001049 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1050 stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001051 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001052
1053 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001054 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001055
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001056 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1057 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1058 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1059 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1060 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1061 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1062 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001063 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001064 pfc_host_stat->tx_frames = stats->tx_frames;
1065 pfc_host_stat->rx_frames = stats->rx_frames;
1066 pfc_host_stat->dumped_frames = stats->dumped_frames;
1067 pfc_host_stat->nos_count = stats->nos_rcvd;
1068 }
Harish Zunjarrao49fd4622008-09-11 21:22:47 -07001069 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1070 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001071
1072done_free:
1073 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001074done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001075 return pfc_host_stat;
1076}
1077
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001078static void
1079qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1080{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001081 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001082
1083 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1084}
1085
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001086static void
1087qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1088{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001089 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001090
1091 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1092}
1093
Andrew Vasquez90991c82006-10-02 12:00:46 -07001094static void
1095qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1096{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001097 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001098 u64 node_name;
1099
1100 if (ha->device_flags & SWITCH_FOUND)
1101 node_name = wwn_to_u64(ha->fabric_node_name);
1102 else
1103 node_name = wwn_to_u64(ha->node_name);
1104
1105 fc_host_fabric_name(shost) = node_name;
1106}
1107
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001108static void
1109qla2x00_get_host_port_state(struct Scsi_Host *shost)
1110{
Seokmann Juda4541b2008-01-31 12:33:52 -08001111 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001112
1113 if (!ha->flags.online)
1114 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1115 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1116 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1117 else
1118 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1119}
1120
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001121static int
1122qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1123{
1124 int ret = 0;
Andrew Vasquezf363b942007-09-20 14:07:45 -07001125 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001126 scsi_qla_host_t *vha;
1127
1128 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1129 if (ret) {
1130 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1131 "status %x\n", ret));
1132 return (ret);
1133 }
1134
1135 vha = qla24xx_create_vhost(fc_vport);
1136 if (vha == NULL) {
1137 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1138 vha));
1139 return FC_VPORT_FAILED;
1140 }
1141 if (disable) {
1142 atomic_set(&vha->vp_state, VP_OFFLINE);
1143 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1144 } else
1145 atomic_set(&vha->vp_state, VP_FAILED);
1146
1147 /* ready to create vport */
1148 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1149
1150 /* initialized vport states */
1151 atomic_set(&vha->loop_state, LOOP_DOWN);
1152 vha->vp_err_state= VP_ERR_PORTDWN;
1153 vha->vp_prev_err_state= VP_ERR_UNKWN;
1154 /* Check if physical ha port is Up */
1155 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1156 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1157 /* Don't retry or attempt login of this virtual port */
1158 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1159 vha->host_no));
1160 atomic_set(&vha->loop_state, LOOP_DEAD);
1161 if (!disable)
1162 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1163 }
1164
1165 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1166 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1167 vha->host_no, vha->vp_idx));
1168 goto vport_create_failed_2;
1169 }
1170
1171 /* initialize attributes */
1172 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1173 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1174 fc_host_supported_classes(vha->host) =
1175 fc_host_supported_classes(ha->host);
1176 fc_host_supported_speeds(vha->host) =
1177 fc_host_supported_speeds(ha->host);
1178
1179 qla24xx_vport_disable(fc_vport, disable);
1180
1181 return 0;
1182vport_create_failed_2:
1183 qla24xx_disable_vp(vha);
1184 qla24xx_deallocate_vp_id(vha);
1185 kfree(vha->port_name);
1186 kfree(vha->node_name);
1187 scsi_host_put(vha->host);
1188 return FC_VPORT_FAILED;
1189}
1190
Adrian Bunka824ebb2008-01-17 09:02:15 -08001191static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001192qla24xx_vport_delete(struct fc_vport *fc_vport)
1193{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001194 scsi_qla_host_t *vha = fc_vport->dd_data;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001195 scsi_qla_host_t *pha = to_qla_parent(vha);
1196
1197 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1198 test_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags))
1199 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001200
1201 qla24xx_disable_vp(vha);
1202 qla24xx_deallocate_vp_id(vha);
1203
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001204 kfree(vha->node_name);
1205 kfree(vha->port_name);
1206
1207 if (vha->timer_active) {
1208 qla2x00_vp_stop_timer(vha);
1209 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1210 "has stopped\n",
1211 vha->host_no, vha->vp_idx, vha));
1212 }
1213
1214 fc_remove_host(vha->host);
1215
1216 scsi_remove_host(vha->host);
1217
1218 scsi_host_put(vha->host);
1219
1220 return 0;
1221}
1222
Adrian Bunka824ebb2008-01-17 09:02:15 -08001223static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001224qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1225{
1226 scsi_qla_host_t *vha = fc_vport->dd_data;
1227
1228 if (disable)
1229 qla24xx_disable_vp(vha);
1230 else
1231 qla24xx_enable_vp(vha);
1232
1233 return 0;
1234}
1235
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001236struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001237
1238 .show_host_node_name = 1,
1239 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001240 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001241 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001242
8482e112005-04-17 15:04:54 -05001243 .get_host_port_id = qla2x00_get_host_port_id,
1244 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001245 .get_host_speed = qla2x00_get_host_speed,
1246 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001247 .get_host_port_type = qla2x00_get_host_port_type,
1248 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001249 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1250 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001251 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1252 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001253 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1254 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001255 .get_host_port_state = qla2x00_get_host_port_state,
1256 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001257
bdf79622005-04-17 15:06:53 -05001258 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001259 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001260
1261 .get_starget_node_name = qla2x00_get_starget_node_name,
1262 .show_starget_node_name = 1,
1263 .get_starget_port_name = qla2x00_get_starget_port_name,
1264 .show_starget_port_name = 1,
1265 .get_starget_port_id = qla2x00_get_starget_port_id,
1266 .show_starget_port_id = 1,
1267
8482e112005-04-17 15:04:54 -05001268 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1269 .show_rport_dev_loss_tmo = 1,
1270
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001271 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001272 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1273 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001274 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001275
1276 .vport_create = qla24xx_vport_create,
1277 .vport_disable = qla24xx_vport_disable,
1278 .vport_delete = qla24xx_vport_delete,
1279};
1280
1281struct fc_function_template qla2xxx_transport_vport_functions = {
1282
1283 .show_host_node_name = 1,
1284 .show_host_port_name = 1,
1285 .show_host_supported_classes = 1,
1286
1287 .get_host_port_id = qla2x00_get_host_port_id,
1288 .show_host_port_id = 1,
1289 .get_host_speed = qla2x00_get_host_speed,
1290 .show_host_speed = 1,
1291 .get_host_port_type = qla2x00_get_host_port_type,
1292 .show_host_port_type = 1,
1293 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1294 .show_host_symbolic_name = 1,
1295 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1296 .show_host_system_hostname = 1,
1297 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1298 .show_host_fabric_name = 1,
1299 .get_host_port_state = qla2x00_get_host_port_state,
1300 .show_host_port_state = 1,
1301
1302 .dd_fcrport_size = sizeof(struct fc_port *),
1303 .show_rport_supported_classes = 1,
1304
1305 .get_starget_node_name = qla2x00_get_starget_node_name,
1306 .show_starget_node_name = 1,
1307 .get_starget_port_name = qla2x00_get_starget_port_name,
1308 .show_starget_port_name = 1,
1309 .get_starget_port_id = qla2x00_get_starget_port_id,
1310 .show_starget_port_id = 1,
1311
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001312 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1313 .show_rport_dev_loss_tmo = 1,
1314
1315 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001316 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1317 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001318 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -05001319};
1320
8482e112005-04-17 15:04:54 -05001321void
1322qla2x00_init_host_attr(scsi_qla_host_t *ha)
1323{
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001324 u32 speed = FC_PORTSPEED_UNKNOWN;
1325
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -08001326 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1327 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001328 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001329 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001330 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001331
1332 if (IS_QLA25XX(ha))
1333 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1334 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001335 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001336 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1337 FC_PORTSPEED_1GBIT;
1338 else if (IS_QLA23XX(ha))
1339 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1340 else
1341 speed = FC_PORTSPEED_1GBIT;
1342 fc_host_supported_speeds(ha->host) = speed;
8482e112005-04-17 15:04:54 -05001343}