blob: 8728e873996d7dbe699b325d953a9afdf8bab51f [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>
8482e112005-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
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -050022 struct device, kobj)));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070023 char *rbuf = (char *)ha->fw_dump;
8482e112005-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;
8482e112005-04-17 15:04:54 -050031
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070032 memcpy(buf, &rbuf[off], count);
8482e112005-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)
8482e112005-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,
8482e112005-04-17 15:04:54 -050043 struct device, kobj)));
44 int reading;
8482e112005-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;
8482e112005-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;
8482e112005-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) {
8482e112005-04-17 15:04:54 -050063 ha->fw_dump_reading = 1;
64
8482e112005-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",
8482e112005-04-17 15:04:54 -050067 ha->host_no);
8482e112005-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;
Andrew Vasquez68af0812008-05-12 22:21:13 -070073 case 3:
74 qla2x00_system_error(ha);
75 break;
8482e112005-04-17 15:04:54 -050076 }
77 return (count);
78}
79
80static struct bin_attribute sysfs_fw_dump_attr = {
81 .attr = {
82 .name = "fw_dump",
83 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050084 },
85 .size = 0,
86 .read = qla2x00_sysfs_read_fw_dump,
87 .write = qla2x00_sysfs_write_fw_dump,
88};
89
90static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080091qla2x00_sysfs_read_nvram(struct kobject *kobj,
92 struct bin_attribute *bin_attr,
93 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050094{
Andrew Vasquezf363b942007-09-20 14:07:45 -070095 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050096 struct device, kobj)));
Seokmann Ju281afe12007-07-26 13:43:34 -070097 int size = ha->nvram_size;
98 char *nvram_cache = ha->nvram;
8482e112005-04-17 15:04:54 -050099
Seokmann Ju281afe12007-07-26 13:43:34 -0700100 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
8482e112005-04-17 15:04:54 -0500101 return 0;
Seokmann Ju281afe12007-07-26 13:43:34 -0700102 if (off + count > size) {
103 size -= off;
104 count = size;
105 }
8482e112005-04-17 15:04:54 -0500106
Seokmann Ju281afe12007-07-26 13:43:34 -0700107 /* Read NVRAM data from cache. */
108 memcpy(buf, &nvram_cache[off], count);
8482e112005-04-17 15:04:54 -0500109
Seokmann Ju281afe12007-07-26 13:43:34 -0700110 return count;
8482e112005-04-17 15:04:54 -0500111}
112
113static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800114qla2x00_sysfs_write_nvram(struct kobject *kobj,
115 struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500117{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700118 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -0500119 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500120 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500121
Andrew Vasquez459c5372005-07-06 10:31:07 -0700122 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500123 return 0;
124
125 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700126 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700127 uint32_t *iter;
128 uint32_t chksum;
129
130 iter = (uint32_t *)buf;
131 chksum = 0;
132 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
133 chksum += le32_to_cpu(*iter++);
134 chksum = ~chksum + 1;
135 *iter = cpu_to_le32(chksum);
136 } else {
137 uint8_t *iter;
138 uint8_t chksum;
139
140 iter = (uint8_t *)buf;
141 chksum = 0;
142 for (cnt = 0; cnt < count - 1; cnt++)
143 chksum += *iter++;
144 chksum = ~chksum + 1;
145 *iter = chksum;
146 }
8482e112005-04-17 15:04:54 -0500147
148 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700149 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
Andrew Vasquezc45bcc82007-09-20 14:07:42 -0700150 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700151 count);
8482e112005-04-17 15:04:54 -0500152
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800153 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
154
8482e112005-04-17 15:04:54 -0500155 return (count);
156}
157
158static struct bin_attribute sysfs_nvram_attr = {
159 .attr = {
160 .name = "nvram",
161 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500162 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800163 .size = 512,
8482e112005-04-17 15:04:54 -0500164 .read = qla2x00_sysfs_read_nvram,
165 .write = qla2x00_sysfs_write_nvram,
166};
167
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800168static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800169qla2x00_sysfs_read_optrom(struct kobject *kobj,
170 struct bin_attribute *bin_attr,
171 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800172{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700173 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800174 struct device, kobj)));
175
176 if (ha->optrom_state != QLA_SREADING)
177 return 0;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700178 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800179 return 0;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700180 if (off + count > ha->optrom_region_size)
181 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800182
183 memcpy(buf, &ha->optrom_buffer[off], count);
184
185 return count;
186}
187
188static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800189qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800192{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700193 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800194 struct device, kobj)));
195
196 if (ha->optrom_state != QLA_SWRITING)
197 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700198 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800199 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700200 if (off + count > ha->optrom_region_size)
201 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800202
203 memcpy(&ha->optrom_buffer[off], buf, count);
204
205 return count;
206}
207
208static struct bin_attribute sysfs_optrom_attr = {
209 .attr = {
210 .name = "optrom",
211 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800212 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700213 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800214 .read = qla2x00_sysfs_read_optrom,
215 .write = qla2x00_sysfs_write_optrom,
216};
217
218static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800219qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
220 struct bin_attribute *bin_attr,
221 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800222{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700223 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800224 struct device, kobj)));
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700225 uint32_t start = 0;
226 uint32_t size = ha->optrom_size;
227 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800228
229 if (off)
230 return 0;
231
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700232 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
233 return -EINVAL;
234 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800235 return -EINVAL;
236
237 switch (val) {
238 case 0:
239 if (ha->optrom_state != QLA_SREADING &&
240 ha->optrom_state != QLA_SWRITING)
241 break;
242
243 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700244
245 DEBUG2(qla_printk(KERN_INFO, ha,
246 "Freeing flash region allocation -- 0x%x bytes.\n",
247 ha->optrom_region_size));
248
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800249 vfree(ha->optrom_buffer);
250 ha->optrom_buffer = NULL;
251 break;
252 case 1:
253 if (ha->optrom_state != QLA_SWAITING)
254 break;
255
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700256 if (start & 0xfff) {
257 qla_printk(KERN_WARNING, ha,
258 "Invalid start region 0x%x/0x%x.\n", start, size);
259 return -EINVAL;
260 }
261
262 ha->optrom_region_start = start;
263 ha->optrom_region_size = start + size > ha->optrom_size ?
264 ha->optrom_size - start : size;
265
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800266 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700267 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800268 if (ha->optrom_buffer == NULL) {
269 qla_printk(KERN_WARNING, ha,
270 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700271 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800272
273 ha->optrom_state = QLA_SWAITING;
274 return count;
275 }
276
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700277 DEBUG2(qla_printk(KERN_INFO, ha,
278 "Reading flash region -- 0x%x/0x%x.\n",
279 ha->optrom_region_start, ha->optrom_region_size));
280
281 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
282 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
283 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800284 break;
285 case 2:
286 if (ha->optrom_state != QLA_SWAITING)
287 break;
288
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700289 /*
290 * We need to be more restrictive on which FLASH regions are
291 * allowed to be updated via user-space. Regions accessible
292 * via this method include:
293 *
294 * ISP21xx/ISP22xx/ISP23xx type boards:
295 *
296 * 0x000000 -> 0x020000 -- Boot code.
297 *
298 * ISP2322/ISP24xx type boards:
299 *
300 * 0x000000 -> 0x07ffff -- Boot code.
301 * 0x080000 -> 0x0fffff -- Firmware.
302 *
303 * ISP25xx type boards:
304 *
305 * 0x000000 -> 0x07ffff -- Boot code.
306 * 0x080000 -> 0x0fffff -- Firmware.
307 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
308 */
309 valid = 0;
310 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
311 valid = 1;
312 else if (start == (FA_BOOT_CODE_ADDR*4) ||
313 start == (FA_RISC_CODE_ADDR*4))
314 valid = 1;
315 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
316 valid = 1;
317 if (!valid) {
318 qla_printk(KERN_WARNING, ha,
319 "Invalid start region 0x%x/0x%x.\n", start, size);
320 return -EINVAL;
321 }
322
323 ha->optrom_region_start = start;
324 ha->optrom_region_size = start + size > ha->optrom_size ?
325 ha->optrom_size - start : size;
326
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800327 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700328 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800329 if (ha->optrom_buffer == NULL) {
330 qla_printk(KERN_WARNING, ha,
331 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700332 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800333
334 ha->optrom_state = QLA_SWAITING;
335 return count;
336 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700337
338 DEBUG2(qla_printk(KERN_INFO, ha,
339 "Staging flash region write -- 0x%x/0x%x.\n",
340 ha->optrom_region_start, ha->optrom_region_size));
341
342 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800343 break;
344 case 3:
345 if (ha->optrom_state != QLA_SWRITING)
346 break;
347
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700348 DEBUG2(qla_printk(KERN_INFO, ha,
349 "Writing flash region -- 0x%x/0x%x.\n",
350 ha->optrom_region_start, ha->optrom_region_size));
351
352 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
353 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800354 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700355 default:
356 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800357 }
358 return count;
359}
360
361static struct bin_attribute sysfs_optrom_ctl_attr = {
362 .attr = {
363 .name = "optrom_ctl",
364 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800365 },
366 .size = 0,
367 .write = qla2x00_sysfs_write_optrom_ctl,
368};
369
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800370static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800371qla2x00_sysfs_read_vpd(struct kobject *kobj,
372 struct bin_attribute *bin_attr,
373 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800374{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700375 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800376 struct device, kobj)));
Seokmann Ju281afe12007-07-26 13:43:34 -0700377 int size = ha->vpd_size;
378 char *vpd_cache = ha->vpd;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800379
Seokmann Ju281afe12007-07-26 13:43:34 -0700380 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800381 return 0;
Seokmann Ju281afe12007-07-26 13:43:34 -0700382 if (off + count > size) {
383 size -= off;
384 count = size;
385 }
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800386
Seokmann Ju281afe12007-07-26 13:43:34 -0700387 /* Read NVRAM data from cache. */
388 memcpy(buf, &vpd_cache[off], count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800389
Seokmann Ju281afe12007-07-26 13:43:34 -0700390 return count;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800391}
392
393static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800394qla2x00_sysfs_write_vpd(struct kobject *kobj,
395 struct bin_attribute *bin_attr,
396 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800397{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700398 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800399 struct device, kobj)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800400
401 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
402 return 0;
403
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800404 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700405 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
Seokmann Ju281afe12007-07-26 13:43:34 -0700406 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800407
408 return count;
409}
410
411static struct bin_attribute sysfs_vpd_attr = {
412 .attr = {
413 .name = "vpd",
414 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800415 },
416 .size = 0,
417 .read = qla2x00_sysfs_read_vpd,
418 .write = qla2x00_sysfs_write_vpd,
419};
420
Andrew Vasquez88729e52006-06-23 16:10:50 -0700421static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800422qla2x00_sysfs_read_sfp(struct kobject *kobj,
423 struct bin_attribute *bin_attr,
424 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700425{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700426 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700427 struct device, kobj)));
428 uint16_t iter, addr, offset;
429 int rval;
430
431 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
432 return 0;
433
Andrew Vasqueze8711082008-01-31 12:33:48 -0800434 if (ha->sfp_data)
435 goto do_read;
436
437 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
438 &ha->sfp_data_dma);
439 if (!ha->sfp_data) {
440 qla_printk(KERN_WARNING, ha,
441 "Unable to allocate memory for SFP read-data.\n");
442 return 0;
443 }
444
445do_read:
446 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700447 addr = 0xa0;
448 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
449 iter++, offset += SFP_BLOCK_SIZE) {
450 if (iter == 4) {
451 /* Skip to next device address. */
452 addr = 0xa2;
453 offset = 0;
454 }
455
456 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
457 SFP_BLOCK_SIZE);
458 if (rval != QLA_SUCCESS) {
459 qla_printk(KERN_WARNING, ha,
460 "Unable to read SFP data (%x/%x/%x).\n", rval,
461 addr, offset);
462 count = 0;
463 break;
464 }
465 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
466 buf += SFP_BLOCK_SIZE;
467 }
468
469 return count;
470}
471
472static struct bin_attribute sysfs_sfp_attr = {
473 .attr = {
474 .name = "sfp",
475 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700476 },
477 .size = SFP_DEV_SIZE * 2,
478 .read = qla2x00_sysfs_read_sfp,
479};
480
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700481static struct sysfs_entry {
482 char *name;
483 struct bin_attribute *attr;
484 int is4GBp_only;
485} bin_file_entries[] = {
486 { "fw_dump", &sysfs_fw_dump_attr, },
487 { "nvram", &sysfs_nvram_attr, },
488 { "optrom", &sysfs_optrom_attr, },
489 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
490 { "vpd", &sysfs_vpd_attr, 1 },
491 { "sfp", &sysfs_sfp_attr, 1 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800492 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700493};
494
8482e112005-04-17 15:04:54 -0500495void
496qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
497{
498 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700499 struct sysfs_entry *iter;
500 int ret;
8482e112005-04-17 15:04:54 -0500501
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700502 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700503 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700504 continue;
505
506 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
507 iter->attr);
508 if (ret)
509 qla_printk(KERN_INFO, ha,
510 "Unable to create sysfs %s binary attribute "
511 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700512 }
8482e112005-04-17 15:04:54 -0500513}
514
515void
516qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
517{
518 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700519 struct sysfs_entry *iter;
8482e112005-04-17 15:04:54 -0500520
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700521 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700522 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700523 continue;
524
Andrew Vasquez7914d002006-06-23 16:10:55 -0700525 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700526 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700527 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800528
529 if (ha->beacon_blink_led == 1)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700530 ha->isp_ops->beacon_off(ha);
8482e112005-04-17 15:04:54 -0500531}
532
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700533/* Scsi_Host attributes. */
534
535static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100536qla2x00_drvr_version_show(struct device *dev,
537 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700538{
539 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
540}
541
542static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100543qla2x00_fw_version_show(struct device *dev,
544 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700545{
Tony Jonesee959b02008-02-22 00:13:36 +0100546 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700547 char fw_str[30];
548
549 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700550 ha->isp_ops->fw_version_str(ha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700551}
552
553static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100554qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
555 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700556{
Tony Jonesee959b02008-02-22 00:13:36 +0100557 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700558 uint32_t sn;
559
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700560 if (IS_FWI2_CAPABLE(ha))
561 return snprintf(buf, PAGE_SIZE, "\n");
562
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700563 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
564 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
565 sn % 100000);
566}
567
568static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100569qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
570 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700571{
Tony Jonesee959b02008-02-22 00:13:36 +0100572 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800573 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700574}
575
576static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100577qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
578 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700579{
Tony Jonesee959b02008-02-22 00:13:36 +0100580 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700581 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
582 ha->product_id[0], ha->product_id[1], ha->product_id[2],
583 ha->product_id[3]);
584}
585
586static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100587qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
588 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700589{
Tony Jonesee959b02008-02-22 00:13:36 +0100590 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700591 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
592}
593
594static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100595qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
596 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700597{
Tony Jonesee959b02008-02-22 00:13:36 +0100598 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700599 return snprintf(buf, PAGE_SIZE, "%s\n",
600 ha->model_desc ? ha->model_desc: "");
601}
602
603static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100604qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
605 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700606{
Tony Jonesee959b02008-02-22 00:13:36 +0100607 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700608 char pci_info[30];
609
610 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700611 ha->isp_ops->pci_info_str(ha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700612}
613
614static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100615qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
616 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700617{
Tony Jonesee959b02008-02-22 00:13:36 +0100618 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700619 int len = 0;
620
621 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
622 atomic_read(&ha->loop_state) == LOOP_DEAD)
623 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
624 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
625 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
626 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
627 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
628 else {
629 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
630
631 switch (ha->current_topology) {
632 case ISP_CFG_NL:
633 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
634 break;
635 case ISP_CFG_FL:
636 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
637 break;
638 case ISP_CFG_N:
639 len += snprintf(buf + len, PAGE_SIZE-len,
640 "N_Port to N_Port\n");
641 break;
642 case ISP_CFG_F:
643 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
644 break;
645 default:
646 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
647 break;
648 }
649 }
650 return len;
651}
652
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700653static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100654qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
655 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700656{
Tony Jonesee959b02008-02-22 00:13:36 +0100657 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700658 int len = 0;
659
660 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700661 case QLA_ZIO_MODE_6:
662 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
663 break;
664 case QLA_ZIO_DISABLED:
665 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
666 break;
667 }
668 return len;
669}
670
671static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100672qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
673 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700674{
Tony Jonesee959b02008-02-22 00:13:36 +0100675 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700676 int val = 0;
677 uint16_t zio_mode;
678
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800679 if (!IS_ZIO_SUPPORTED(ha))
680 return -ENOTSUPP;
681
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700682 if (sscanf(buf, "%d", &val) != 1)
683 return -EINVAL;
684
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800685 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700686 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800687 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700688 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700689
690 /* Update per-hba values and queue a reset. */
691 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
692 ha->zio_mode = zio_mode;
693 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
694 }
695 return strlen(buf);
696}
697
698static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100699qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
700 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700701{
Tony Jonesee959b02008-02-22 00:13:36 +0100702 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700703
704 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
705}
706
707static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100708qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
709 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700710{
Tony Jonesee959b02008-02-22 00:13:36 +0100711 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700712 int val = 0;
713 uint16_t zio_timer;
714
715 if (sscanf(buf, "%d", &val) != 1)
716 return -EINVAL;
717 if (val > 25500 || val < 100)
718 return -ERANGE;
719
720 zio_timer = (uint16_t)(val / 100);
721 ha->zio_timer = zio_timer;
722
723 return strlen(buf);
724}
725
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800726static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100727qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
728 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800729{
Tony Jonesee959b02008-02-22 00:13:36 +0100730 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800731 int len = 0;
732
733 if (ha->beacon_blink_led)
734 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
735 else
736 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
737 return len;
738}
739
740static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100741qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
742 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800743{
Tony Jonesee959b02008-02-22 00:13:36 +0100744 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800745 int val = 0;
746 int rval;
747
748 if (IS_QLA2100(ha) || IS_QLA2200(ha))
749 return -EPERM;
750
751 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
752 qla_printk(KERN_WARNING, ha,
753 "Abort ISP active -- ignoring beacon request.\n");
754 return -EBUSY;
755 }
756
757 if (sscanf(buf, "%d", &val) != 1)
758 return -EINVAL;
759
760 if (val)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700761 rval = ha->isp_ops->beacon_on(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800762 else
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700763 rval = ha->isp_ops->beacon_off(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800764
765 if (rval != QLA_SUCCESS)
766 count = 0;
767
768 return count;
769}
770
Andrew Vasquez30c47662007-01-29 10:22:21 -0800771static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100772qla2x00_optrom_bios_version_show(struct device *dev,
773 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800774{
Tony Jonesee959b02008-02-22 00:13:36 +0100775 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800776
777 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
778 ha->bios_revision[0]);
779}
780
781static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100782qla2x00_optrom_efi_version_show(struct device *dev,
783 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800784{
Tony Jonesee959b02008-02-22 00:13:36 +0100785 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800786
787 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
788 ha->efi_revision[0]);
789}
790
791static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100792qla2x00_optrom_fcode_version_show(struct device *dev,
793 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800794{
Tony Jonesee959b02008-02-22 00:13:36 +0100795 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800796
797 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
798 ha->fcode_revision[0]);
799}
800
801static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100802qla2x00_optrom_fw_version_show(struct device *dev,
803 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800804{
Tony Jonesee959b02008-02-22 00:13:36 +0100805 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800806
807 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
808 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
809 ha->fw_revision[3]);
810}
811
Tony Jonesee959b02008-02-22 00:13:36 +0100812static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
813static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
814static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
815static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
816static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
817static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
818static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
819static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100820static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +0100821static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
822static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
823 qla2x00_zio_timer_store);
824static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
825 qla2x00_beacon_store);
826static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
827 qla2x00_optrom_bios_version_show, NULL);
828static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
829 qla2x00_optrom_efi_version_show, NULL);
830static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
831 qla2x00_optrom_fcode_version_show, NULL);
832static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
833 NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700834
Tony Jonesee959b02008-02-22 00:13:36 +0100835struct device_attribute *qla2x00_host_attrs[] = {
836 &dev_attr_driver_version,
837 &dev_attr_fw_version,
838 &dev_attr_serial_num,
839 &dev_attr_isp_name,
840 &dev_attr_isp_id,
841 &dev_attr_model_name,
842 &dev_attr_model_desc,
843 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100844 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +0100845 &dev_attr_zio,
846 &dev_attr_zio_timer,
847 &dev_attr_beacon,
848 &dev_attr_optrom_bios_version,
849 &dev_attr_optrom_efi_version,
850 &dev_attr_optrom_fcode_version,
851 &dev_attr_optrom_fw_version,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700852 NULL,
853};
854
8482e112005-04-17 15:04:54 -0500855/* Host attributes. */
856
857static void
858qla2x00_get_host_port_id(struct Scsi_Host *shost)
859{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700860 scsi_qla_host_t *ha = shost_priv(shost);
8482e112005-04-17 15:04:54 -0500861
862 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
863 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
864}
865
866static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800867qla2x00_get_host_speed(struct Scsi_Host *shost)
868{
Seokmann Juda4541b2008-01-31 12:33:52 -0800869 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700870 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800871
872 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700873 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700874 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800875 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700876 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700877 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800878 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700879 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700880 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800881 break;
Seokmann Juda4541b2008-01-31 12:33:52 -0800882 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700883 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -0800884 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800885 }
886 fc_host_speed(shost) = speed;
887}
888
889static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800890qla2x00_get_host_port_type(struct Scsi_Host *shost)
891{
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700892 scsi_qla_host_t *ha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800893 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
894
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700895 if (ha->parent) {
896 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
897 return;
898 }
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800899 switch (ha->current_topology) {
900 case ISP_CFG_NL:
901 port_type = FC_PORTTYPE_LPORT;
902 break;
903 case ISP_CFG_FL:
904 port_type = FC_PORTTYPE_NLPORT;
905 break;
906 case ISP_CFG_N:
907 port_type = FC_PORTTYPE_PTP;
908 break;
909 case ISP_CFG_F:
910 port_type = FC_PORTTYPE_NPORT;
911 break;
912 }
913 fc_host_port_type(shost) = port_type;
914}
915
916static void
8482e112005-04-17 15:04:54 -0500917qla2x00_get_starget_node_name(struct scsi_target *starget)
918{
919 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700920 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500921 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700922 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500923
bdf79622005-04-17 15:06:53 -0500924 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700925 if (fcport->rport &&
926 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700927 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500928 break;
929 }
930 }
931
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700932 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500933}
934
935static void
936qla2x00_get_starget_port_name(struct scsi_target *starget)
937{
938 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700939 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500940 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700941 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500942
bdf79622005-04-17 15:06:53 -0500943 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700944 if (fcport->rport &&
945 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700946 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500947 break;
948 }
949 }
950
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700951 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500952}
953
954static void
955qla2x00_get_starget_port_id(struct scsi_target *starget)
956{
957 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700958 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500959 fc_port_t *fcport;
960 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500961
bdf79622005-04-17 15:06:53 -0500962 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700963 if (fcport->rport &&
964 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -0500965 port_id = fcport->d_id.b.domain << 16 |
966 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
967 break;
968 }
969 }
970
8482e112005-04-17 15:04:54 -0500971 fc_starget_port_id(starget) = port_id;
972}
973
974static void
8482e112005-04-17 15:04:54 -0500975qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
976{
8482e112005-04-17 15:04:54 -0500977 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -0700978 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -0500979 else
Andrew Vasquez85821c92008-07-10 16:55:48 -0700980 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -0500981}
982
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700983static void
984qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
985{
986 struct Scsi_Host *host = rport_to_shost(rport);
987 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
988
989 qla2x00_abort_fcport_cmds(fcport);
990
991 /*
992 * Transport has effectively 'deleted' the rport, clear
993 * all local references.
994 */
995 spin_lock_irq(host->host_lock);
996 fcport->rport = NULL;
997 *((fc_port_t **)rport->dd_data) = NULL;
998 spin_unlock_irq(host->host_lock);
999}
1000
1001static void
1002qla2x00_terminate_rport_io(struct fc_rport *rport)
1003{
1004 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1005
1006 qla2x00_abort_fcport_cmds(fcport);
1007 scsi_target_unblock(&rport->dev);
1008}
1009
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001010static int
1011qla2x00_issue_lip(struct Scsi_Host *shost)
1012{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001013 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001014
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001015 qla2x00_loop_reset(ha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001016 return 0;
1017}
1018
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001019static struct fc_host_statistics *
1020qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1021{
Seokmann Juda4541b2008-01-31 12:33:52 -08001022 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001023 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001024 struct link_statistics *stats;
1025 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001026 struct fc_host_statistics *pfc_host_stat;
1027
1028 pfc_host_stat = &ha->fc_host_stat;
1029 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1030
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001031 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1032 if (stats == NULL) {
1033 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1034 __func__, ha->host_no));
1035 goto done;
1036 }
1037 memset(stats, 0, DMA_POOL_SIZE);
1038
1039 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001040 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001041 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001042 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1043 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1044 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1045 !ha->dpc_active) {
1046 /* Must be in a 'READY' state for statistics retrieval. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001047 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1048 stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001049 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001050
1051 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001052 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001053
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001054 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1055 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1056 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1057 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1058 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1059 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1060 if (IS_FWI2_CAPABLE(ha)) {
1061 pfc_host_stat->tx_frames = stats->tx_frames;
1062 pfc_host_stat->rx_frames = stats->rx_frames;
1063 pfc_host_stat->dumped_frames = stats->dumped_frames;
1064 pfc_host_stat->nos_count = stats->nos_rcvd;
1065 }
1066
1067done_free:
1068 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001069done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001070 return pfc_host_stat;
1071}
1072
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001073static void
1074qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1075{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001076 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001077
1078 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1079}
1080
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001081static void
1082qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1083{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001084 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001085
1086 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1087}
1088
Andrew Vasquez90991c82006-10-02 12:00:46 -07001089static void
1090qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1091{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001092 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001093 u64 node_name;
1094
1095 if (ha->device_flags & SWITCH_FOUND)
1096 node_name = wwn_to_u64(ha->fabric_node_name);
1097 else
1098 node_name = wwn_to_u64(ha->node_name);
1099
1100 fc_host_fabric_name(shost) = node_name;
1101}
1102
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001103static void
1104qla2x00_get_host_port_state(struct Scsi_Host *shost)
1105{
Seokmann Juda4541b2008-01-31 12:33:52 -08001106 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001107
1108 if (!ha->flags.online)
1109 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1110 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1111 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1112 else
1113 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1114}
1115
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001116static int
1117qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1118{
1119 int ret = 0;
Andrew Vasquezf363b942007-09-20 14:07:45 -07001120 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001121 scsi_qla_host_t *vha;
1122
1123 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1124 if (ret) {
1125 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1126 "status %x\n", ret));
1127 return (ret);
1128 }
1129
1130 vha = qla24xx_create_vhost(fc_vport);
1131 if (vha == NULL) {
1132 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1133 vha));
1134 return FC_VPORT_FAILED;
1135 }
1136 if (disable) {
1137 atomic_set(&vha->vp_state, VP_OFFLINE);
1138 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1139 } else
1140 atomic_set(&vha->vp_state, VP_FAILED);
1141
1142 /* ready to create vport */
1143 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1144
1145 /* initialized vport states */
1146 atomic_set(&vha->loop_state, LOOP_DOWN);
1147 vha->vp_err_state= VP_ERR_PORTDWN;
1148 vha->vp_prev_err_state= VP_ERR_UNKWN;
1149 /* Check if physical ha port is Up */
1150 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1151 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1152 /* Don't retry or attempt login of this virtual port */
1153 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1154 vha->host_no));
1155 atomic_set(&vha->loop_state, LOOP_DEAD);
1156 if (!disable)
1157 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1158 }
1159
1160 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1161 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1162 vha->host_no, vha->vp_idx));
1163 goto vport_create_failed_2;
1164 }
1165
1166 /* initialize attributes */
1167 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1168 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1169 fc_host_supported_classes(vha->host) =
1170 fc_host_supported_classes(ha->host);
1171 fc_host_supported_speeds(vha->host) =
1172 fc_host_supported_speeds(ha->host);
1173
1174 qla24xx_vport_disable(fc_vport, disable);
1175
1176 return 0;
1177vport_create_failed_2:
1178 qla24xx_disable_vp(vha);
1179 qla24xx_deallocate_vp_id(vha);
1180 kfree(vha->port_name);
1181 kfree(vha->node_name);
1182 scsi_host_put(vha->host);
1183 return FC_VPORT_FAILED;
1184}
1185
Adrian Bunka824ebb2008-01-17 09:02:15 -08001186static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001187qla24xx_vport_delete(struct fc_vport *fc_vport)
1188{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001189 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001190 scsi_qla_host_t *vha = fc_vport->dd_data;
1191
1192 qla24xx_disable_vp(vha);
1193 qla24xx_deallocate_vp_id(vha);
1194
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001195 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001196 ha->cur_vport_count--;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001197 clear_bit(vha->vp_idx, ha->vp_idx_map);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001198 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001199
1200 kfree(vha->node_name);
1201 kfree(vha->port_name);
1202
1203 if (vha->timer_active) {
1204 qla2x00_vp_stop_timer(vha);
1205 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1206 "has stopped\n",
1207 vha->host_no, vha->vp_idx, vha));
1208 }
1209
1210 fc_remove_host(vha->host);
1211
1212 scsi_remove_host(vha->host);
1213
1214 scsi_host_put(vha->host);
1215
1216 return 0;
1217}
1218
Adrian Bunka824ebb2008-01-17 09:02:15 -08001219static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001220qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1221{
1222 scsi_qla_host_t *vha = fc_vport->dd_data;
1223
1224 if (disable)
1225 qla24xx_disable_vp(vha);
1226 else
1227 qla24xx_enable_vp(vha);
1228
1229 return 0;
1230}
1231
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001232struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001233
1234 .show_host_node_name = 1,
1235 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001236 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001237 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001238
8482e112005-04-17 15:04:54 -05001239 .get_host_port_id = qla2x00_get_host_port_id,
1240 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001241 .get_host_speed = qla2x00_get_host_speed,
1242 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001243 .get_host_port_type = qla2x00_get_host_port_type,
1244 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001245 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1246 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001247 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1248 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001249 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1250 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001251 .get_host_port_state = qla2x00_get_host_port_state,
1252 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001253
bdf79622005-04-17 15:06:53 -05001254 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001255 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001256
1257 .get_starget_node_name = qla2x00_get_starget_node_name,
1258 .show_starget_node_name = 1,
1259 .get_starget_port_name = qla2x00_get_starget_port_name,
1260 .show_starget_port_name = 1,
1261 .get_starget_port_id = qla2x00_get_starget_port_id,
1262 .show_starget_port_id = 1,
1263
8482e112005-04-17 15:04:54 -05001264 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1265 .show_rport_dev_loss_tmo = 1,
1266
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001267 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001268 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1269 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001270 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001271
1272 .vport_create = qla24xx_vport_create,
1273 .vport_disable = qla24xx_vport_disable,
1274 .vport_delete = qla24xx_vport_delete,
1275};
1276
1277struct fc_function_template qla2xxx_transport_vport_functions = {
1278
1279 .show_host_node_name = 1,
1280 .show_host_port_name = 1,
1281 .show_host_supported_classes = 1,
1282
1283 .get_host_port_id = qla2x00_get_host_port_id,
1284 .show_host_port_id = 1,
1285 .get_host_speed = qla2x00_get_host_speed,
1286 .show_host_speed = 1,
1287 .get_host_port_type = qla2x00_get_host_port_type,
1288 .show_host_port_type = 1,
1289 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1290 .show_host_symbolic_name = 1,
1291 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1292 .show_host_system_hostname = 1,
1293 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1294 .show_host_fabric_name = 1,
1295 .get_host_port_state = qla2x00_get_host_port_state,
1296 .show_host_port_state = 1,
1297
1298 .dd_fcrport_size = sizeof(struct fc_port *),
1299 .show_rport_supported_classes = 1,
1300
1301 .get_starget_node_name = qla2x00_get_starget_node_name,
1302 .show_starget_node_name = 1,
1303 .get_starget_port_name = qla2x00_get_starget_port_name,
1304 .show_starget_port_name = 1,
1305 .get_starget_port_id = qla2x00_get_starget_port_id,
1306 .show_starget_port_id = 1,
1307
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001308 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1309 .show_rport_dev_loss_tmo = 1,
1310
1311 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001312 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1313 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001314 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -05001315};
1316
8482e112005-04-17 15:04:54 -05001317void
1318qla2x00_init_host_attr(scsi_qla_host_t *ha)
1319{
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001320 u32 speed = FC_PORTSPEED_UNKNOWN;
1321
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -08001322 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1323 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001324 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001325 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001326 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001327
1328 if (IS_QLA25XX(ha))
1329 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1330 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001331 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001332 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1333 FC_PORTSPEED_1GBIT;
1334 else if (IS_QLA23XX(ha))
1335 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1336 else
1337 speed = FC_PORTSPEED_1GBIT;
1338 fc_host_supported_speeds(ha->host) = speed;
8482e112005-04-17 15:04:54 -05001339}