blob: 2caf841cbba929474e656f6756f122439d73f3d4 [file] [log] [blame]
8482e1182005-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
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>
8482e1182005-04-17 15:04:54 -050011
Adrian Bunka824ebb2008-01-17 09:02:15 -080012static int qla24xx_vport_disable(struct fc_vport *, bool);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070013
8482e1182005-04-17 15:04:54 -050014/* SYSFS attributes --------------------------------------------------------- */
15
16static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080017qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
18 struct bin_attribute *bin_attr,
19 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050020{
Andrew Vasquezf363b942007-09-20 14:07:45 -070021 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050022 struct device, kobj)));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070023 char *rbuf = (char *)ha->fw_dump;
8482e1182005-04-17 15:04:54 -050024
25 if (ha->fw_dump_reading == 0)
26 return 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070027 if (off > ha->fw_dump_len)
28 return 0;
29 if (off + count > ha->fw_dump_len)
30 count = ha->fw_dump_len - off;
8482e1182005-04-17 15:04:54 -050031
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070032 memcpy(buf, &rbuf[off], count);
8482e1182005-04-17 15:04:54 -050033
34 return (count);
35}
36
37static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080038qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
39 struct bin_attribute *bin_attr,
40 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050041{
Andrew Vasquezf363b942007-09-20 14:07:45 -070042 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050043 struct device, kobj)));
44 int reading;
8482e1182005-04-17 15:04:54 -050045
46 if (off != 0)
47 return (0);
48
49 reading = simple_strtol(buf, NULL, 10);
50 switch (reading) {
51 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070052 if (!ha->fw_dump_reading)
53 break;
8482e1182005-04-17 15:04:54 -050054
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070055 qla_printk(KERN_INFO, ha,
56 "Firmware dump cleared on (%ld).\n", ha->host_no);
57
58 ha->fw_dump_reading = 0;
59 ha->fw_dumped = 0;
8482e1182005-04-17 15:04:54 -050060 break;
61 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070062 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e1182005-04-17 15:04:54 -050063 ha->fw_dump_reading = 1;
64
8482e1182005-04-17 15:04:54 -050065 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070066 "Raw firmware dump ready for read on (%ld).\n",
8482e1182005-04-17 15:04:54 -050067 ha->host_no);
8482e1182005-04-17 15:04:54 -050068 }
69 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070070 case 2:
71 qla2x00_alloc_fw_dump(ha);
72 break;
8482e1182005-04-17 15:04:54 -050073 }
74 return (count);
75}
76
77static struct bin_attribute sysfs_fw_dump_attr = {
78 .attr = {
79 .name = "fw_dump",
80 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -050081 },
82 .size = 0,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
85};
86
87static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080088qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -050091{
Andrew Vasquezf363b942007-09-20 14:07:45 -070092 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -050093 struct device, kobj)));
Seokmann Ju281afe12007-07-26 13:43:34 -070094 int size = ha->nvram_size;
95 char *nvram_cache = ha->nvram;
8482e1182005-04-17 15:04:54 -050096
Seokmann Ju281afe12007-07-26 13:43:34 -070097 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
8482e1182005-04-17 15:04:54 -050098 return 0;
Seokmann Ju281afe12007-07-26 13:43:34 -070099 if (off + count > size) {
100 size -= off;
101 count = size;
102 }
8482e1182005-04-17 15:04:54 -0500103
Seokmann Ju281afe12007-07-26 13:43:34 -0700104 /* Read NVRAM data from cache. */
105 memcpy(buf, &nvram_cache[off], count);
8482e1182005-04-17 15:04:54 -0500106
Seokmann Ju281afe12007-07-26 13:43:34 -0700107 return count;
8482e1182005-04-17 15:04:54 -0500108}
109
110static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800111qla2x00_sysfs_write_nvram(struct kobject *kobj,
112 struct bin_attribute *bin_attr,
113 char *buf, loff_t off, size_t count)
8482e1182005-04-17 15:04:54 -0500114{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700115 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e1182005-04-17 15:04:54 -0500116 struct device, kobj)));
8482e1182005-04-17 15:04:54 -0500117 uint16_t cnt;
8482e1182005-04-17 15:04:54 -0500118
Andrew Vasquez459c5372005-07-06 10:31:07 -0700119 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e1182005-04-17 15:04:54 -0500120 return 0;
121
122 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700123 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700124 uint32_t *iter;
125 uint32_t chksum;
126
127 iter = (uint32_t *)buf;
128 chksum = 0;
129 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
130 chksum += le32_to_cpu(*iter++);
131 chksum = ~chksum + 1;
132 *iter = cpu_to_le32(chksum);
133 } else {
134 uint8_t *iter;
135 uint8_t chksum;
136
137 iter = (uint8_t *)buf;
138 chksum = 0;
139 for (cnt = 0; cnt < count - 1; cnt++)
140 chksum += *iter++;
141 chksum = ~chksum + 1;
142 *iter = chksum;
143 }
8482e1182005-04-17 15:04:54 -0500144
145 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700146 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
Andrew Vasquezc45bcc82007-09-20 14:07:42 -0700147 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700148 count);
8482e1182005-04-17 15:04:54 -0500149
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800150 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
151
8482e1182005-04-17 15:04:54 -0500152 return (count);
153}
154
155static struct bin_attribute sysfs_nvram_attr = {
156 .attr = {
157 .name = "nvram",
158 .mode = S_IRUSR | S_IWUSR,
8482e1182005-04-17 15:04:54 -0500159 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800160 .size = 512,
8482e1182005-04-17 15:04:54 -0500161 .read = qla2x00_sysfs_read_nvram,
162 .write = qla2x00_sysfs_write_nvram,
163};
164
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800165static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800166qla2x00_sysfs_read_optrom(struct kobject *kobj,
167 struct bin_attribute *bin_attr,
168 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800169{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700170 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800171 struct device, kobj)));
172
173 if (ha->optrom_state != QLA_SREADING)
174 return 0;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700175 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800176 return 0;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700177 if (off + count > ha->optrom_region_size)
178 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800179
180 memcpy(buf, &ha->optrom_buffer[off], count);
181
182 return count;
183}
184
185static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800186qla2x00_sysfs_write_optrom(struct kobject *kobj,
187 struct bin_attribute *bin_attr,
188 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800189{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700190 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800191 struct device, kobj)));
192
193 if (ha->optrom_state != QLA_SWRITING)
194 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700195 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800196 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700197 if (off + count > ha->optrom_region_size)
198 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800199
200 memcpy(&ha->optrom_buffer[off], buf, count);
201
202 return count;
203}
204
205static struct bin_attribute sysfs_optrom_attr = {
206 .attr = {
207 .name = "optrom",
208 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800209 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700210 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800211 .read = qla2x00_sysfs_read_optrom,
212 .write = qla2x00_sysfs_write_optrom,
213};
214
215static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800216qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
217 struct bin_attribute *bin_attr,
218 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800219{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700220 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800221 struct device, kobj)));
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700222 uint32_t start = 0;
223 uint32_t size = ha->optrom_size;
224 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800225
226 if (off)
227 return 0;
228
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700229 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
230 return -EINVAL;
231 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800232 return -EINVAL;
233
234 switch (val) {
235 case 0:
236 if (ha->optrom_state != QLA_SREADING &&
237 ha->optrom_state != QLA_SWRITING)
238 break;
239
240 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700241
242 DEBUG2(qla_printk(KERN_INFO, ha,
243 "Freeing flash region allocation -- 0x%x bytes.\n",
244 ha->optrom_region_size));
245
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800246 vfree(ha->optrom_buffer);
247 ha->optrom_buffer = NULL;
248 break;
249 case 1:
250 if (ha->optrom_state != QLA_SWAITING)
251 break;
252
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700253 if (start & 0xfff) {
254 qla_printk(KERN_WARNING, ha,
255 "Invalid start region 0x%x/0x%x.\n", start, size);
256 return -EINVAL;
257 }
258
259 ha->optrom_region_start = start;
260 ha->optrom_region_size = start + size > ha->optrom_size ?
261 ha->optrom_size - start : size;
262
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800263 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700264 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800265 if (ha->optrom_buffer == NULL) {
266 qla_printk(KERN_WARNING, ha,
267 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700268 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800269
270 ha->optrom_state = QLA_SWAITING;
271 return count;
272 }
273
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700274 DEBUG2(qla_printk(KERN_INFO, ha,
275 "Reading flash region -- 0x%x/0x%x.\n",
276 ha->optrom_region_start, ha->optrom_region_size));
277
278 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
279 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
280 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800281 break;
282 case 2:
283 if (ha->optrom_state != QLA_SWAITING)
284 break;
285
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700286 /*
287 * We need to be more restrictive on which FLASH regions are
288 * allowed to be updated via user-space. Regions accessible
289 * via this method include:
290 *
291 * ISP21xx/ISP22xx/ISP23xx type boards:
292 *
293 * 0x000000 -> 0x020000 -- Boot code.
294 *
295 * ISP2322/ISP24xx type boards:
296 *
297 * 0x000000 -> 0x07ffff -- Boot code.
298 * 0x080000 -> 0x0fffff -- Firmware.
299 *
300 * ISP25xx type boards:
301 *
302 * 0x000000 -> 0x07ffff -- Boot code.
303 * 0x080000 -> 0x0fffff -- Firmware.
304 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
305 */
306 valid = 0;
307 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
308 valid = 1;
309 else if (start == (FA_BOOT_CODE_ADDR*4) ||
310 start == (FA_RISC_CODE_ADDR*4))
311 valid = 1;
312 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
313 valid = 1;
314 if (!valid) {
315 qla_printk(KERN_WARNING, ha,
316 "Invalid start region 0x%x/0x%x.\n", start, size);
317 return -EINVAL;
318 }
319
320 ha->optrom_region_start = start;
321 ha->optrom_region_size = start + size > ha->optrom_size ?
322 ha->optrom_size - start : size;
323
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800324 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700325 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800326 if (ha->optrom_buffer == NULL) {
327 qla_printk(KERN_WARNING, ha,
328 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700329 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800330
331 ha->optrom_state = QLA_SWAITING;
332 return count;
333 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700334
335 DEBUG2(qla_printk(KERN_INFO, ha,
336 "Staging flash region write -- 0x%x/0x%x.\n",
337 ha->optrom_region_start, ha->optrom_region_size));
338
339 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800340 break;
341 case 3:
342 if (ha->optrom_state != QLA_SWRITING)
343 break;
344
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700345 DEBUG2(qla_printk(KERN_INFO, ha,
346 "Writing flash region -- 0x%x/0x%x.\n",
347 ha->optrom_region_start, ha->optrom_region_size));
348
349 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
350 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800351 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700352 default:
353 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800354 }
355 return count;
356}
357
358static struct bin_attribute sysfs_optrom_ctl_attr = {
359 .attr = {
360 .name = "optrom_ctl",
361 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800362 },
363 .size = 0,
364 .write = qla2x00_sysfs_write_optrom_ctl,
365};
366
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800367static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800368qla2x00_sysfs_read_vpd(struct kobject *kobj,
369 struct bin_attribute *bin_attr,
370 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800371{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700372 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800373 struct device, kobj)));
Seokmann Ju281afe12007-07-26 13:43:34 -0700374 int size = ha->vpd_size;
375 char *vpd_cache = ha->vpd;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800376
Seokmann Ju281afe12007-07-26 13:43:34 -0700377 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800378 return 0;
Seokmann Ju281afe12007-07-26 13:43:34 -0700379 if (off + count > size) {
380 size -= off;
381 count = size;
382 }
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800383
Seokmann Ju281afe12007-07-26 13:43:34 -0700384 /* Read NVRAM data from cache. */
385 memcpy(buf, &vpd_cache[off], count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800386
Seokmann Ju281afe12007-07-26 13:43:34 -0700387 return count;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800388}
389
390static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800391qla2x00_sysfs_write_vpd(struct kobject *kobj,
392 struct bin_attribute *bin_attr,
393 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800394{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700395 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800396 struct device, kobj)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800397
398 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
399 return 0;
400
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800401 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700402 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
Seokmann Ju281afe12007-07-26 13:43:34 -0700403 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800404
405 return count;
406}
407
408static struct bin_attribute sysfs_vpd_attr = {
409 .attr = {
410 .name = "vpd",
411 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800412 },
413 .size = 0,
414 .read = qla2x00_sysfs_read_vpd,
415 .write = qla2x00_sysfs_write_vpd,
416};
417
Andrew Vasquez88729e52006-06-23 16:10:50 -0700418static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800419qla2x00_sysfs_read_sfp(struct kobject *kobj,
420 struct bin_attribute *bin_attr,
421 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700422{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700423 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700424 struct device, kobj)));
425 uint16_t iter, addr, offset;
426 int rval;
427
428 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
429 return 0;
430
Andrew Vasqueze8711082008-01-31 12:33:48 -0800431 if (ha->sfp_data)
432 goto do_read;
433
434 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
435 &ha->sfp_data_dma);
436 if (!ha->sfp_data) {
437 qla_printk(KERN_WARNING, ha,
438 "Unable to allocate memory for SFP read-data.\n");
439 return 0;
440 }
441
442do_read:
443 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700444 addr = 0xa0;
445 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
446 iter++, offset += SFP_BLOCK_SIZE) {
447 if (iter == 4) {
448 /* Skip to next device address. */
449 addr = 0xa2;
450 offset = 0;
451 }
452
453 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
454 SFP_BLOCK_SIZE);
455 if (rval != QLA_SUCCESS) {
456 qla_printk(KERN_WARNING, ha,
457 "Unable to read SFP data (%x/%x/%x).\n", rval,
458 addr, offset);
459 count = 0;
460 break;
461 }
462 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
463 buf += SFP_BLOCK_SIZE;
464 }
465
466 return count;
467}
468
469static struct bin_attribute sysfs_sfp_attr = {
470 .attr = {
471 .name = "sfp",
472 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700473 },
474 .size = SFP_DEV_SIZE * 2,
475 .read = qla2x00_sysfs_read_sfp,
476};
477
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700478static struct sysfs_entry {
479 char *name;
480 struct bin_attribute *attr;
481 int is4GBp_only;
482} bin_file_entries[] = {
483 { "fw_dump", &sysfs_fw_dump_attr, },
484 { "nvram", &sysfs_nvram_attr, },
485 { "optrom", &sysfs_optrom_attr, },
486 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
487 { "vpd", &sysfs_vpd_attr, 1 },
488 { "sfp", &sysfs_sfp_attr, 1 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800489 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700490};
491
8482e1182005-04-17 15:04:54 -0500492void
493qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
494{
495 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700496 struct sysfs_entry *iter;
497 int ret;
8482e1182005-04-17 15:04:54 -0500498
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700499 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700500 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700501 continue;
502
503 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
504 iter->attr);
505 if (ret)
506 qla_printk(KERN_INFO, ha,
507 "Unable to create sysfs %s binary attribute "
508 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700509 }
8482e1182005-04-17 15:04:54 -0500510}
511
512void
513qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
514{
515 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700516 struct sysfs_entry *iter;
8482e1182005-04-17 15:04:54 -0500517
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700518 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700519 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700520 continue;
521
Andrew Vasquez7914d002006-06-23 16:10:55 -0700522 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700523 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700524 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800525
526 if (ha->beacon_blink_led == 1)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700527 ha->isp_ops->beacon_off(ha);
8482e1182005-04-17 15:04:54 -0500528}
529
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700530/* Scsi_Host attributes. */
531
532static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100533qla2x00_drvr_version_show(struct device *dev,
534 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700535{
536 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
537}
538
539static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100540qla2x00_fw_version_show(struct device *dev,
541 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700542{
Tony Jonesee959b02008-02-22 00:13:36 +0100543 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700544 char fw_str[30];
545
546 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700547 ha->isp_ops->fw_version_str(ha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700548}
549
550static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100551qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
552 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700553{
Tony Jonesee959b02008-02-22 00:13:36 +0100554 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700555 uint32_t sn;
556
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700557 if (IS_FWI2_CAPABLE(ha))
558 return snprintf(buf, PAGE_SIZE, "\n");
559
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700560 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
561 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
562 sn % 100000);
563}
564
565static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100566qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
567 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700568{
Tony Jonesee959b02008-02-22 00:13:36 +0100569 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800570 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700571}
572
573static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100574qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
575 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700576{
Tony Jonesee959b02008-02-22 00:13:36 +0100577 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700578 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
579 ha->product_id[0], ha->product_id[1], ha->product_id[2],
580 ha->product_id[3]);
581}
582
583static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100584qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
585 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700586{
Tony Jonesee959b02008-02-22 00:13:36 +0100587 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700588 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
589}
590
591static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100592qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
593 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700594{
Tony Jonesee959b02008-02-22 00:13:36 +0100595 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700596 return snprintf(buf, PAGE_SIZE, "%s\n",
597 ha->model_desc ? ha->model_desc: "");
598}
599
600static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100601qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
602 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700603{
Tony Jonesee959b02008-02-22 00:13:36 +0100604 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700605 char pci_info[30];
606
607 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700608 ha->isp_ops->pci_info_str(ha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700609}
610
611static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100612qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
613 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700614{
Tony Jonesee959b02008-02-22 00:13:36 +0100615 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700616 int len = 0;
617
618 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
619 atomic_read(&ha->loop_state) == LOOP_DEAD)
620 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
621 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
622 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
623 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
624 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
625 else {
626 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
627
628 switch (ha->current_topology) {
629 case ISP_CFG_NL:
630 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
631 break;
632 case ISP_CFG_FL:
633 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
634 break;
635 case ISP_CFG_N:
636 len += snprintf(buf + len, PAGE_SIZE-len,
637 "N_Port to N_Port\n");
638 break;
639 case ISP_CFG_F:
640 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
641 break;
642 default:
643 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
644 break;
645 }
646 }
647 return len;
648}
649
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700650static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100651qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
652 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700653{
Tony Jonesee959b02008-02-22 00:13:36 +0100654 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700655 int len = 0;
656
657 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700658 case QLA_ZIO_MODE_6:
659 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
660 break;
661 case QLA_ZIO_DISABLED:
662 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
663 break;
664 }
665 return len;
666}
667
668static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100669qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
670 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700671{
Tony Jonesee959b02008-02-22 00:13:36 +0100672 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700673 int val = 0;
674 uint16_t zio_mode;
675
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800676 if (!IS_ZIO_SUPPORTED(ha))
677 return -ENOTSUPP;
678
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700679 if (sscanf(buf, "%d", &val) != 1)
680 return -EINVAL;
681
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800682 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700683 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800684 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700685 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700686
687 /* Update per-hba values and queue a reset. */
688 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
689 ha->zio_mode = zio_mode;
690 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
691 }
692 return strlen(buf);
693}
694
695static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100696qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
697 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700698{
Tony Jonesee959b02008-02-22 00:13:36 +0100699 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700700
701 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
702}
703
704static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100705qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
706 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700707{
Tony Jonesee959b02008-02-22 00:13:36 +0100708 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700709 int val = 0;
710 uint16_t zio_timer;
711
712 if (sscanf(buf, "%d", &val) != 1)
713 return -EINVAL;
714 if (val > 25500 || val < 100)
715 return -ERANGE;
716
717 zio_timer = (uint16_t)(val / 100);
718 ha->zio_timer = zio_timer;
719
720 return strlen(buf);
721}
722
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800723static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100724qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
725 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800726{
Tony Jonesee959b02008-02-22 00:13:36 +0100727 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800728 int len = 0;
729
730 if (ha->beacon_blink_led)
731 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
732 else
733 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
734 return len;
735}
736
737static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100738qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
739 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800740{
Tony Jonesee959b02008-02-22 00:13:36 +0100741 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800742 int val = 0;
743 int rval;
744
745 if (IS_QLA2100(ha) || IS_QLA2200(ha))
746 return -EPERM;
747
748 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
749 qla_printk(KERN_WARNING, ha,
750 "Abort ISP active -- ignoring beacon request.\n");
751 return -EBUSY;
752 }
753
754 if (sscanf(buf, "%d", &val) != 1)
755 return -EINVAL;
756
757 if (val)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700758 rval = ha->isp_ops->beacon_on(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800759 else
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700760 rval = ha->isp_ops->beacon_off(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800761
762 if (rval != QLA_SUCCESS)
763 count = 0;
764
765 return count;
766}
767
Andrew Vasquez30c47662007-01-29 10:22:21 -0800768static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100769qla2x00_optrom_bios_version_show(struct device *dev,
770 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800771{
Tony Jonesee959b02008-02-22 00:13:36 +0100772 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800773
774 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
775 ha->bios_revision[0]);
776}
777
778static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100779qla2x00_optrom_efi_version_show(struct device *dev,
780 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800781{
Tony Jonesee959b02008-02-22 00:13:36 +0100782 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800783
784 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
785 ha->efi_revision[0]);
786}
787
788static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100789qla2x00_optrom_fcode_version_show(struct device *dev,
790 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800791{
Tony Jonesee959b02008-02-22 00:13:36 +0100792 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800793
794 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
795 ha->fcode_revision[0]);
796}
797
798static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100799qla2x00_optrom_fw_version_show(struct device *dev,
800 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800801{
Tony Jonesee959b02008-02-22 00:13:36 +0100802 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800803
804 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
805 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
806 ha->fw_revision[3]);
807}
808
Tony Jonesee959b02008-02-22 00:13:36 +0100809static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
810static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
811static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
812static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
813static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
814static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
815static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
816static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100817static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +0100818static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
819static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
820 qla2x00_zio_timer_store);
821static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
822 qla2x00_beacon_store);
823static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
824 qla2x00_optrom_bios_version_show, NULL);
825static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
826 qla2x00_optrom_efi_version_show, NULL);
827static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
828 qla2x00_optrom_fcode_version_show, NULL);
829static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
830 NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700831
Tony Jonesee959b02008-02-22 00:13:36 +0100832struct device_attribute *qla2x00_host_attrs[] = {
833 &dev_attr_driver_version,
834 &dev_attr_fw_version,
835 &dev_attr_serial_num,
836 &dev_attr_isp_name,
837 &dev_attr_isp_id,
838 &dev_attr_model_name,
839 &dev_attr_model_desc,
840 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100841 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +0100842 &dev_attr_zio,
843 &dev_attr_zio_timer,
844 &dev_attr_beacon,
845 &dev_attr_optrom_bios_version,
846 &dev_attr_optrom_efi_version,
847 &dev_attr_optrom_fcode_version,
848 &dev_attr_optrom_fw_version,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700849 NULL,
850};
851
8482e1182005-04-17 15:04:54 -0500852/* Host attributes. */
853
854static void
855qla2x00_get_host_port_id(struct Scsi_Host *shost)
856{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700857 scsi_qla_host_t *ha = shost_priv(shost);
8482e1182005-04-17 15:04:54 -0500858
859 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
860 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
861}
862
863static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800864qla2x00_get_host_speed(struct Scsi_Host *shost)
865{
Seokmann Juda4541b2008-01-31 12:33:52 -0800866 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700867 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800868
869 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700870 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700871 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800872 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700873 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700874 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800875 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700876 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700877 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800878 break;
Seokmann Juda4541b2008-01-31 12:33:52 -0800879 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700880 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -0800881 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800882 }
883 fc_host_speed(shost) = speed;
884}
885
886static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800887qla2x00_get_host_port_type(struct Scsi_Host *shost)
888{
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700889 scsi_qla_host_t *ha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800890 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
891
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700892 if (ha->parent) {
893 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
894 return;
895 }
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800896 switch (ha->current_topology) {
897 case ISP_CFG_NL:
898 port_type = FC_PORTTYPE_LPORT;
899 break;
900 case ISP_CFG_FL:
901 port_type = FC_PORTTYPE_NLPORT;
902 break;
903 case ISP_CFG_N:
904 port_type = FC_PORTTYPE_PTP;
905 break;
906 case ISP_CFG_F:
907 port_type = FC_PORTTYPE_NPORT;
908 break;
909 }
910 fc_host_port_type(shost) = port_type;
911}
912
913static void
8482e1182005-04-17 15:04:54 -0500914qla2x00_get_starget_node_name(struct scsi_target *starget)
915{
916 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700917 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500918 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700919 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -0500920
bdf79622005-04-17 15:06:53 -0500921 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700922 if (fcport->rport &&
923 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700924 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500925 break;
926 }
927 }
928
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700929 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -0500930}
931
932static void
933qla2x00_get_starget_port_name(struct scsi_target *starget)
934{
935 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700936 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500937 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700938 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -0500939
bdf79622005-04-17 15:06:53 -0500940 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700941 if (fcport->rport &&
942 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700943 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500944 break;
945 }
946 }
947
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700948 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -0500949}
950
951static void
952qla2x00_get_starget_port_id(struct scsi_target *starget)
953{
954 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700955 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500956 fc_port_t *fcport;
957 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -0500958
bdf79622005-04-17 15:06:53 -0500959 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700960 if (fcport->rport &&
961 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -0500962 port_id = fcport->d_id.b.domain << 16 |
963 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
964 break;
965 }
966 }
967
8482e1182005-04-17 15:04:54 -0500968 fc_starget_port_id(starget) = port_id;
969}
970
971static void
972qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
973{
bdf79622005-04-17 15:06:53 -0500974 struct Scsi_Host *host = rport_to_shost(rport);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700975 scsi_qla_host_t *ha = shost_priv(host);
8482e1182005-04-17 15:04:54 -0500976
977 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
978}
979
980static void
981qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
982{
bdf79622005-04-17 15:06:53 -0500983 struct Scsi_Host *host = rport_to_shost(rport);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700984 scsi_qla_host_t *ha = shost_priv(host);
8482e1182005-04-17 15:04:54 -0500985
986 if (timeout)
987 ha->port_down_retry_count = timeout;
988 else
989 ha->port_down_retry_count = 1;
990
991 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
992}
993
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700994static int
995qla2x00_issue_lip(struct Scsi_Host *shost)
996{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700997 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700998
Andrew Vasqueza4722cf2008-01-17 09:02:12 -0800999 qla2x00_loop_reset(ha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001000 return 0;
1001}
1002
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001003static struct fc_host_statistics *
1004qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1005{
Seokmann Juda4541b2008-01-31 12:33:52 -08001006 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001007 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001008 struct link_statistics *stats;
1009 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001010 struct fc_host_statistics *pfc_host_stat;
1011
1012 pfc_host_stat = &ha->fc_host_stat;
1013 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1014
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001015 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1016 if (stats == NULL) {
1017 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1018 __func__, ha->host_no));
1019 goto done;
1020 }
1021 memset(stats, 0, DMA_POOL_SIZE);
1022
1023 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001024 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001025 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001026 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1027 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1028 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1029 !ha->dpc_active) {
1030 /* Must be in a 'READY' state for statistics retrieval. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001031 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1032 stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001033 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001034
1035 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001036 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001037
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001038 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1039 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1040 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1041 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1042 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1043 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1044 if (IS_FWI2_CAPABLE(ha)) {
1045 pfc_host_stat->tx_frames = stats->tx_frames;
1046 pfc_host_stat->rx_frames = stats->rx_frames;
1047 pfc_host_stat->dumped_frames = stats->dumped_frames;
1048 pfc_host_stat->nos_count = stats->nos_rcvd;
1049 }
1050
1051done_free:
1052 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001053done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001054 return pfc_host_stat;
1055}
1056
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001057static void
1058qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1059{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001060 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001061
1062 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1063}
1064
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001065static void
1066qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1067{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001068 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001069
1070 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1071}
1072
Andrew Vasquez90991c82006-10-02 12:00:46 -07001073static void
1074qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1075{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001076 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001077 u64 node_name;
1078
1079 if (ha->device_flags & SWITCH_FOUND)
1080 node_name = wwn_to_u64(ha->fabric_node_name);
1081 else
1082 node_name = wwn_to_u64(ha->node_name);
1083
1084 fc_host_fabric_name(shost) = node_name;
1085}
1086
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001087static void
1088qla2x00_get_host_port_state(struct Scsi_Host *shost)
1089{
Seokmann Juda4541b2008-01-31 12:33:52 -08001090 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001091
1092 if (!ha->flags.online)
1093 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1094 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1095 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1096 else
1097 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1098}
1099
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001100static int
1101qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1102{
1103 int ret = 0;
Andrew Vasquezf363b942007-09-20 14:07:45 -07001104 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001105 scsi_qla_host_t *vha;
1106
1107 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1108 if (ret) {
1109 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1110 "status %x\n", ret));
1111 return (ret);
1112 }
1113
1114 vha = qla24xx_create_vhost(fc_vport);
1115 if (vha == NULL) {
1116 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1117 vha));
1118 return FC_VPORT_FAILED;
1119 }
1120 if (disable) {
1121 atomic_set(&vha->vp_state, VP_OFFLINE);
1122 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1123 } else
1124 atomic_set(&vha->vp_state, VP_FAILED);
1125
1126 /* ready to create vport */
1127 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1128
1129 /* initialized vport states */
1130 atomic_set(&vha->loop_state, LOOP_DOWN);
1131 vha->vp_err_state= VP_ERR_PORTDWN;
1132 vha->vp_prev_err_state= VP_ERR_UNKWN;
1133 /* Check if physical ha port is Up */
1134 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1135 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1136 /* Don't retry or attempt login of this virtual port */
1137 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1138 vha->host_no));
1139 atomic_set(&vha->loop_state, LOOP_DEAD);
1140 if (!disable)
1141 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1142 }
1143
1144 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1145 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1146 vha->host_no, vha->vp_idx));
1147 goto vport_create_failed_2;
1148 }
1149
1150 /* initialize attributes */
1151 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1152 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1153 fc_host_supported_classes(vha->host) =
1154 fc_host_supported_classes(ha->host);
1155 fc_host_supported_speeds(vha->host) =
1156 fc_host_supported_speeds(ha->host);
1157
1158 qla24xx_vport_disable(fc_vport, disable);
1159
1160 return 0;
1161vport_create_failed_2:
1162 qla24xx_disable_vp(vha);
1163 qla24xx_deallocate_vp_id(vha);
1164 kfree(vha->port_name);
1165 kfree(vha->node_name);
1166 scsi_host_put(vha->host);
1167 return FC_VPORT_FAILED;
1168}
1169
Adrian Bunka824ebb2008-01-17 09:02:15 -08001170static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001171qla24xx_vport_delete(struct fc_vport *fc_vport)
1172{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001173 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001174 scsi_qla_host_t *vha = fc_vport->dd_data;
1175
1176 qla24xx_disable_vp(vha);
1177 qla24xx_deallocate_vp_id(vha);
1178
1179 down(&ha->vport_sem);
1180 ha->cur_vport_count--;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001181 clear_bit(vha->vp_idx, ha->vp_idx_map);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001182 up(&ha->vport_sem);
1183
1184 kfree(vha->node_name);
1185 kfree(vha->port_name);
1186
1187 if (vha->timer_active) {
1188 qla2x00_vp_stop_timer(vha);
1189 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1190 "has stopped\n",
1191 vha->host_no, vha->vp_idx, vha));
1192 }
1193
1194 fc_remove_host(vha->host);
1195
1196 scsi_remove_host(vha->host);
1197
1198 scsi_host_put(vha->host);
1199
1200 return 0;
1201}
1202
Adrian Bunka824ebb2008-01-17 09:02:15 -08001203static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001204qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1205{
1206 scsi_qla_host_t *vha = fc_vport->dd_data;
1207
1208 if (disable)
1209 qla24xx_disable_vp(vha);
1210 else
1211 qla24xx_enable_vp(vha);
1212
1213 return 0;
1214}
1215
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001216struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -05001217
1218 .show_host_node_name = 1,
1219 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001220 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001221 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001222
8482e1182005-04-17 15:04:54 -05001223 .get_host_port_id = qla2x00_get_host_port_id,
1224 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001225 .get_host_speed = qla2x00_get_host_speed,
1226 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001227 .get_host_port_type = qla2x00_get_host_port_type,
1228 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001229 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1230 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001231 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1232 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001233 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1234 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001235 .get_host_port_state = qla2x00_get_host_port_state,
1236 .show_host_port_state = 1,
8482e1182005-04-17 15:04:54 -05001237
bdf79622005-04-17 15:06:53 -05001238 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001239 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -05001240
1241 .get_starget_node_name = qla2x00_get_starget_node_name,
1242 .show_starget_node_name = 1,
1243 .get_starget_port_name = qla2x00_get_starget_port_name,
1244 .show_starget_port_name = 1,
1245 .get_starget_port_id = qla2x00_get_starget_port_id,
1246 .show_starget_port_id = 1,
1247
1248 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1249 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1250 .show_rport_dev_loss_tmo = 1,
1251
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001252 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001253 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001254
1255 .vport_create = qla24xx_vport_create,
1256 .vport_disable = qla24xx_vport_disable,
1257 .vport_delete = qla24xx_vport_delete,
1258};
1259
1260struct fc_function_template qla2xxx_transport_vport_functions = {
1261
1262 .show_host_node_name = 1,
1263 .show_host_port_name = 1,
1264 .show_host_supported_classes = 1,
1265
1266 .get_host_port_id = qla2x00_get_host_port_id,
1267 .show_host_port_id = 1,
1268 .get_host_speed = qla2x00_get_host_speed,
1269 .show_host_speed = 1,
1270 .get_host_port_type = qla2x00_get_host_port_type,
1271 .show_host_port_type = 1,
1272 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1273 .show_host_symbolic_name = 1,
1274 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1275 .show_host_system_hostname = 1,
1276 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1277 .show_host_fabric_name = 1,
1278 .get_host_port_state = qla2x00_get_host_port_state,
1279 .show_host_port_state = 1,
1280
1281 .dd_fcrport_size = sizeof(struct fc_port *),
1282 .show_rport_supported_classes = 1,
1283
1284 .get_starget_node_name = qla2x00_get_starget_node_name,
1285 .show_starget_node_name = 1,
1286 .get_starget_port_name = qla2x00_get_starget_port_name,
1287 .show_starget_port_name = 1,
1288 .get_starget_port_id = qla2x00_get_starget_port_id,
1289 .show_starget_port_id = 1,
1290
1291 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1292 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1293 .show_rport_dev_loss_tmo = 1,
1294
1295 .issue_fc_host_lip = qla2x00_issue_lip,
1296 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e1182005-04-17 15:04:54 -05001297};
1298
8482e1182005-04-17 15:04:54 -05001299void
1300qla2x00_init_host_attr(scsi_qla_host_t *ha)
1301{
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001302 u32 speed = FC_PORTSPEED_UNKNOWN;
1303
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -08001304 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1305 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001306 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001307 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001308 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001309
1310 if (IS_QLA25XX(ha))
1311 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1312 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001313 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001314 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1315 FC_PORTSPEED_1GBIT;
1316 else if (IS_QLA23XX(ha))
1317 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1318 else
1319 speed = FC_PORTSPEED_1GBIT;
1320 fc_host_supported_speeds(ha->host) = speed;
8482e1182005-04-17 15:04:54 -05001321}