blob: 7a4409ab30eaaab0b751226f4e0713b5469166d5 [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)));
23
24 if (ha->fw_dump_reading == 0)
25 return 0;
8482e112005-04-17 15:04:54 -050026
Akinobu Mitab3dc9082008-07-24 08:31:47 -070027 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
28 ha->fw_dump_len);
8482e112005-04-17 15:04:54 -050029}
30
31static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080032qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
33 struct bin_attribute *bin_attr,
34 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050035{
Andrew Vasquezf363b942007-09-20 14:07:45 -070036 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050037 struct device, kobj)));
38 int reading;
8482e112005-04-17 15:04:54 -050039
40 if (off != 0)
41 return (0);
42
43 reading = simple_strtol(buf, NULL, 10);
44 switch (reading) {
45 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070046 if (!ha->fw_dump_reading)
47 break;
8482e112005-04-17 15:04:54 -050048
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070049 qla_printk(KERN_INFO, ha,
50 "Firmware dump cleared on (%ld).\n", ha->host_no);
51
52 ha->fw_dump_reading = 0;
53 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050054 break;
55 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070056 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050057 ha->fw_dump_reading = 1;
58
8482e112005-04-17 15:04:54 -050059 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070060 "Raw firmware dump ready for read on (%ld).\n",
8482e112005-04-17 15:04:54 -050061 ha->host_no);
8482e112005-04-17 15:04:54 -050062 }
63 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070064 case 2:
65 qla2x00_alloc_fw_dump(ha);
66 break;
Andrew Vasquez68af0812008-05-12 22:21:13 -070067 case 3:
68 qla2x00_system_error(ha);
69 break;
8482e112005-04-17 15:04:54 -050070 }
71 return (count);
72}
73
74static struct bin_attribute sysfs_fw_dump_attr = {
75 .attr = {
76 .name = "fw_dump",
77 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050078 },
79 .size = 0,
80 .read = qla2x00_sysfs_read_fw_dump,
81 .write = qla2x00_sysfs_write_fw_dump,
82};
83
84static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080085qla2x00_sysfs_read_nvram(struct kobject *kobj,
86 struct bin_attribute *bin_attr,
87 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050088{
Andrew Vasquezf363b942007-09-20 14:07:45 -070089 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -050090 struct device, kobj)));
8482e112005-04-17 15:04:54 -050091
Akinobu Mitab3dc9082008-07-24 08:31:47 -070092 if (!capable(CAP_SYS_ADMIN))
8482e112005-04-17 15:04:54 -050093 return 0;
94
Seokmann Ju281afe12007-07-26 13:43:34 -070095 /* Read NVRAM data from cache. */
Akinobu Mitab3dc9082008-07-24 08:31:47 -070096 return memory_read_from_buffer(buf, count, &off, ha->nvram,
97 ha->nvram_size);
8482e112005-04-17 15:04:54 -050098}
99
100static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800101qla2x00_sysfs_write_nvram(struct kobject *kobj,
102 struct bin_attribute *bin_attr,
103 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500104{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700105 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
8482e112005-04-17 15:04:54 -0500106 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500107 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500108
Andrew Vasquez459c5372005-07-06 10:31:07 -0700109 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500110 return 0;
111
112 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700113 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700114 uint32_t *iter;
115 uint32_t chksum;
116
117 iter = (uint32_t *)buf;
118 chksum = 0;
119 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
120 chksum += le32_to_cpu(*iter++);
121 chksum = ~chksum + 1;
122 *iter = cpu_to_le32(chksum);
123 } else {
124 uint8_t *iter;
125 uint8_t chksum;
126
127 iter = (uint8_t *)buf;
128 chksum = 0;
129 for (cnt = 0; cnt < count - 1; cnt++)
130 chksum += *iter++;
131 chksum = ~chksum + 1;
132 *iter = chksum;
133 }
8482e112005-04-17 15:04:54 -0500134
135 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700136 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
Andrew Vasquezc45bcc82007-09-20 14:07:42 -0700137 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
Seokmann Ju281afe12007-07-26 13:43:34 -0700138 count);
8482e112005-04-17 15:04:54 -0500139
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800140 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
141
8482e112005-04-17 15:04:54 -0500142 return (count);
143}
144
145static struct bin_attribute sysfs_nvram_attr = {
146 .attr = {
147 .name = "nvram",
148 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500149 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800150 .size = 512,
8482e112005-04-17 15:04:54 -0500151 .read = qla2x00_sysfs_read_nvram,
152 .write = qla2x00_sysfs_write_nvram,
153};
154
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800155static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800156qla2x00_sysfs_read_optrom(struct kobject *kobj,
157 struct bin_attribute *bin_attr,
158 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800159{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700160 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800161 struct device, kobj)));
162
163 if (ha->optrom_state != QLA_SREADING)
164 return 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800165
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700166 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
167 ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800168}
169
170static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800171qla2x00_sysfs_write_optrom(struct kobject *kobj,
172 struct bin_attribute *bin_attr,
173 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800174{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700175 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800176 struct device, kobj)));
177
178 if (ha->optrom_state != QLA_SWRITING)
179 return -EINVAL;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700180 if (off > ha->optrom_region_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800181 return -ERANGE;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700182 if (off + count > ha->optrom_region_size)
183 count = ha->optrom_region_size - off;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800184
185 memcpy(&ha->optrom_buffer[off], buf, count);
186
187 return count;
188}
189
190static struct bin_attribute sysfs_optrom_attr = {
191 .attr = {
192 .name = "optrom",
193 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800194 },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700195 .size = 0,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800196 .read = qla2x00_sysfs_read_optrom,
197 .write = qla2x00_sysfs_write_optrom,
198};
199
200static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800201qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
202 struct bin_attribute *bin_attr,
203 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800204{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700205 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800206 struct device, kobj)));
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700207 uint32_t start = 0;
208 uint32_t size = ha->optrom_size;
209 int val, valid;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800210
211 if (off)
212 return 0;
213
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700214 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
215 return -EINVAL;
216 if (start > ha->optrom_size)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800217 return -EINVAL;
218
219 switch (val) {
220 case 0:
221 if (ha->optrom_state != QLA_SREADING &&
222 ha->optrom_state != QLA_SWRITING)
223 break;
224
225 ha->optrom_state = QLA_SWAITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700226
227 DEBUG2(qla_printk(KERN_INFO, ha,
228 "Freeing flash region allocation -- 0x%x bytes.\n",
229 ha->optrom_region_size));
230
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800231 vfree(ha->optrom_buffer);
232 ha->optrom_buffer = NULL;
233 break;
234 case 1:
235 if (ha->optrom_state != QLA_SWAITING)
236 break;
237
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700238 if (start & 0xfff) {
239 qla_printk(KERN_WARNING, ha,
240 "Invalid start region 0x%x/0x%x.\n", start, size);
241 return -EINVAL;
242 }
243
244 ha->optrom_region_start = start;
245 ha->optrom_region_size = start + size > ha->optrom_size ?
246 ha->optrom_size - start : size;
247
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800248 ha->optrom_state = QLA_SREADING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700249 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800250 if (ha->optrom_buffer == NULL) {
251 qla_printk(KERN_WARNING, ha,
252 "Unable to allocate memory for optrom retrieval "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700253 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800254
255 ha->optrom_state = QLA_SWAITING;
256 return count;
257 }
258
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700259 DEBUG2(qla_printk(KERN_INFO, ha,
260 "Reading flash region -- 0x%x/0x%x.\n",
261 ha->optrom_region_start, ha->optrom_region_size));
262
263 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
264 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
265 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800266 break;
267 case 2:
268 if (ha->optrom_state != QLA_SWAITING)
269 break;
270
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700271 /*
272 * We need to be more restrictive on which FLASH regions are
273 * allowed to be updated via user-space. Regions accessible
274 * via this method include:
275 *
276 * ISP21xx/ISP22xx/ISP23xx type boards:
277 *
278 * 0x000000 -> 0x020000 -- Boot code.
279 *
280 * ISP2322/ISP24xx type boards:
281 *
282 * 0x000000 -> 0x07ffff -- Boot code.
283 * 0x080000 -> 0x0fffff -- Firmware.
284 *
285 * ISP25xx type boards:
286 *
287 * 0x000000 -> 0x07ffff -- Boot code.
288 * 0x080000 -> 0x0fffff -- Firmware.
289 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
290 */
291 valid = 0;
292 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
293 valid = 1;
294 else if (start == (FA_BOOT_CODE_ADDR*4) ||
295 start == (FA_RISC_CODE_ADDR*4))
296 valid = 1;
297 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
298 valid = 1;
299 if (!valid) {
300 qla_printk(KERN_WARNING, ha,
301 "Invalid start region 0x%x/0x%x.\n", start, size);
302 return -EINVAL;
303 }
304
305 ha->optrom_region_start = start;
306 ha->optrom_region_size = start + size > ha->optrom_size ?
307 ha->optrom_size - start : size;
308
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800309 ha->optrom_state = QLA_SWRITING;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700310 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800311 if (ha->optrom_buffer == NULL) {
312 qla_printk(KERN_WARNING, ha,
313 "Unable to allocate memory for optrom update "
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700314 "(%x).\n", ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800315
316 ha->optrom_state = QLA_SWAITING;
317 return count;
318 }
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700319
320 DEBUG2(qla_printk(KERN_INFO, ha,
321 "Staging flash region write -- 0x%x/0x%x.\n",
322 ha->optrom_region_start, ha->optrom_region_size));
323
324 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800325 break;
326 case 3:
327 if (ha->optrom_state != QLA_SWRITING)
328 break;
329
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700330 DEBUG2(qla_printk(KERN_INFO, ha,
331 "Writing flash region -- 0x%x/0x%x.\n",
332 ha->optrom_region_start, ha->optrom_region_size));
333
334 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
335 ha->optrom_region_start, ha->optrom_region_size);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800336 break;
Joe Carnucciob7cc1762007-09-20 14:07:35 -0700337 default:
338 count = -EINVAL;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800339 }
340 return count;
341}
342
343static struct bin_attribute sysfs_optrom_ctl_attr = {
344 .attr = {
345 .name = "optrom_ctl",
346 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800347 },
348 .size = 0,
349 .write = qla2x00_sysfs_write_optrom_ctl,
350};
351
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800352static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800353qla2x00_sysfs_read_vpd(struct kobject *kobj,
354 struct bin_attribute *bin_attr,
355 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800356{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700357 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800358 struct device, kobj)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800359
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700360 if (!capable(CAP_SYS_ADMIN))
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800361 return 0;
362
Seokmann Ju281afe12007-07-26 13:43:34 -0700363 /* Read NVRAM data from cache. */
Akinobu Mitab3dc9082008-07-24 08:31:47 -0700364 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800365}
366
367static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800368qla2x00_sysfs_write_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)));
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800374
375 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
376 return 0;
377
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800378 /* Write NVRAM. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700379 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
Seokmann Ju281afe12007-07-26 13:43:34 -0700380 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800381
382 return count;
383}
384
385static struct bin_attribute sysfs_vpd_attr = {
386 .attr = {
387 .name = "vpd",
388 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800389 },
390 .size = 0,
391 .read = qla2x00_sysfs_read_vpd,
392 .write = qla2x00_sysfs_write_vpd,
393};
394
Andrew Vasquez88729e52006-06-23 16:10:50 -0700395static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800396qla2x00_sysfs_read_sfp(struct kobject *kobj,
397 struct bin_attribute *bin_attr,
398 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700399{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700400 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700401 struct device, kobj)));
402 uint16_t iter, addr, offset;
403 int rval;
404
405 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
406 return 0;
407
Andrew Vasqueze8711082008-01-31 12:33:48 -0800408 if (ha->sfp_data)
409 goto do_read;
410
411 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
412 &ha->sfp_data_dma);
413 if (!ha->sfp_data) {
414 qla_printk(KERN_WARNING, ha,
415 "Unable to allocate memory for SFP read-data.\n");
416 return 0;
417 }
418
419do_read:
420 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
Andrew Vasquez88729e52006-06-23 16:10:50 -0700421 addr = 0xa0;
422 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
423 iter++, offset += SFP_BLOCK_SIZE) {
424 if (iter == 4) {
425 /* Skip to next device address. */
426 addr = 0xa2;
427 offset = 0;
428 }
429
430 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
431 SFP_BLOCK_SIZE);
432 if (rval != QLA_SUCCESS) {
433 qla_printk(KERN_WARNING, ha,
434 "Unable to read SFP data (%x/%x/%x).\n", rval,
435 addr, offset);
436 count = 0;
437 break;
438 }
439 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
440 buf += SFP_BLOCK_SIZE;
441 }
442
443 return count;
444}
445
446static struct bin_attribute sysfs_sfp_attr = {
447 .attr = {
448 .name = "sfp",
449 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700450 },
451 .size = SFP_DEV_SIZE * 2,
452 .read = qla2x00_sysfs_read_sfp,
453};
454
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700455static struct sysfs_entry {
456 char *name;
457 struct bin_attribute *attr;
458 int is4GBp_only;
459} bin_file_entries[] = {
460 { "fw_dump", &sysfs_fw_dump_attr, },
461 { "nvram", &sysfs_nvram_attr, },
462 { "optrom", &sysfs_optrom_attr, },
463 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
464 { "vpd", &sysfs_vpd_attr, 1 },
465 { "sfp", &sysfs_sfp_attr, 1 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800466 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700467};
468
8482e112005-04-17 15:04:54 -0500469void
470qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
471{
472 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700473 struct sysfs_entry *iter;
474 int ret;
8482e112005-04-17 15:04:54 -0500475
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700476 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700477 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700478 continue;
479
480 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
481 iter->attr);
482 if (ret)
483 qla_printk(KERN_INFO, ha,
484 "Unable to create sysfs %s binary attribute "
485 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700486 }
8482e112005-04-17 15:04:54 -0500487}
488
489void
490qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
491{
492 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700493 struct sysfs_entry *iter;
8482e112005-04-17 15:04:54 -0500494
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700495 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700496 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700497 continue;
498
Andrew Vasquez7914d002006-06-23 16:10:55 -0700499 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700500 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700501 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800502
503 if (ha->beacon_blink_led == 1)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700504 ha->isp_ops->beacon_off(ha);
8482e112005-04-17 15:04:54 -0500505}
506
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700507/* Scsi_Host attributes. */
508
509static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100510qla2x00_drvr_version_show(struct device *dev,
511 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700512{
513 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
514}
515
516static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100517qla2x00_fw_version_show(struct device *dev,
518 struct device_attribute *attr, char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700519{
Tony Jonesee959b02008-02-22 00:13:36 +0100520 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700521 char fw_str[30];
522
523 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700524 ha->isp_ops->fw_version_str(ha, fw_str));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700525}
526
527static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100528qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
529 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700530{
Tony Jonesee959b02008-02-22 00:13:36 +0100531 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700532 uint32_t sn;
533
Joe Carnuccio1ee27142008-07-10 16:55:53 -0700534 if (IS_FWI2_CAPABLE(ha)) {
535 qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
536 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
537 }
Andrew Vasquez8b7afc22007-10-19 15:59:19 -0700538
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700539 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
540 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
541 sn % 100000);
542}
543
544static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100545qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
546 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700547{
Tony Jonesee959b02008-02-22 00:13:36 +0100548 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800549 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700550}
551
552static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100553qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
554 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700555{
Tony Jonesee959b02008-02-22 00:13:36 +0100556 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700557 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
558 ha->product_id[0], ha->product_id[1], ha->product_id[2],
559 ha->product_id[3]);
560}
561
562static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100563qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
564 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700565{
Tony Jonesee959b02008-02-22 00:13:36 +0100566 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700567 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
568}
569
570static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100571qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
572 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700573{
Tony Jonesee959b02008-02-22 00:13:36 +0100574 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700575 return snprintf(buf, PAGE_SIZE, "%s\n",
576 ha->model_desc ? ha->model_desc: "");
577}
578
579static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100580qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
581 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700582{
Tony Jonesee959b02008-02-22 00:13:36 +0100583 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700584 char pci_info[30];
585
586 return snprintf(buf, PAGE_SIZE, "%s\n",
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700587 ha->isp_ops->pci_info_str(ha, pci_info));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700588}
589
590static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100591qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
592 char *buf)
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700593{
Tony Jonesee959b02008-02-22 00:13:36 +0100594 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700595 int len = 0;
596
597 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
598 atomic_read(&ha->loop_state) == LOOP_DEAD)
599 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
600 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
601 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
602 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
603 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
604 else {
605 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
606
607 switch (ha->current_topology) {
608 case ISP_CFG_NL:
609 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
610 break;
611 case ISP_CFG_FL:
612 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
613 break;
614 case ISP_CFG_N:
615 len += snprintf(buf + len, PAGE_SIZE-len,
616 "N_Port to N_Port\n");
617 break;
618 case ISP_CFG_F:
619 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
620 break;
621 default:
622 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
623 break;
624 }
625 }
626 return len;
627}
628
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700629static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100630qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
631 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700632{
Tony Jonesee959b02008-02-22 00:13:36 +0100633 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700634 int len = 0;
635
636 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700637 case QLA_ZIO_MODE_6:
638 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
639 break;
640 case QLA_ZIO_DISABLED:
641 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
642 break;
643 }
644 return len;
645}
646
647static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100648qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
649 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700650{
Tony Jonesee959b02008-02-22 00:13:36 +0100651 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700652 int val = 0;
653 uint16_t zio_mode;
654
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800655 if (!IS_ZIO_SUPPORTED(ha))
656 return -ENOTSUPP;
657
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700658 if (sscanf(buf, "%d", &val) != 1)
659 return -EINVAL;
660
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800661 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700662 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800663 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700664 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700665
666 /* Update per-hba values and queue a reset. */
667 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
668 ha->zio_mode = zio_mode;
669 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
670 }
671 return strlen(buf);
672}
673
674static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100675qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
676 char *buf)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700677{
Tony Jonesee959b02008-02-22 00:13:36 +0100678 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700679
680 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
681}
682
683static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100684qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
685 const char *buf, size_t count)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700686{
Tony Jonesee959b02008-02-22 00:13:36 +0100687 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700688 int val = 0;
689 uint16_t zio_timer;
690
691 if (sscanf(buf, "%d", &val) != 1)
692 return -EINVAL;
693 if (val > 25500 || val < 100)
694 return -ERANGE;
695
696 zio_timer = (uint16_t)(val / 100);
697 ha->zio_timer = zio_timer;
698
699 return strlen(buf);
700}
701
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800702static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100703qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
704 char *buf)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800705{
Tony Jonesee959b02008-02-22 00:13:36 +0100706 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800707 int len = 0;
708
709 if (ha->beacon_blink_led)
710 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
711 else
712 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
713 return len;
714}
715
716static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100717qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
718 const char *buf, size_t count)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800719{
Tony Jonesee959b02008-02-22 00:13:36 +0100720 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800721 int val = 0;
722 int rval;
723
724 if (IS_QLA2100(ha) || IS_QLA2200(ha))
725 return -EPERM;
726
727 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
728 qla_printk(KERN_WARNING, ha,
729 "Abort ISP active -- ignoring beacon request.\n");
730 return -EBUSY;
731 }
732
733 if (sscanf(buf, "%d", &val) != 1)
734 return -EINVAL;
735
736 if (val)
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700737 rval = ha->isp_ops->beacon_on(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800738 else
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700739 rval = ha->isp_ops->beacon_off(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800740
741 if (rval != QLA_SUCCESS)
742 count = 0;
743
744 return count;
745}
746
Andrew Vasquez30c47662007-01-29 10:22:21 -0800747static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100748qla2x00_optrom_bios_version_show(struct device *dev,
749 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800750{
Tony Jonesee959b02008-02-22 00:13:36 +0100751 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800752
753 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
754 ha->bios_revision[0]);
755}
756
757static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100758qla2x00_optrom_efi_version_show(struct device *dev,
759 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800760{
Tony Jonesee959b02008-02-22 00:13:36 +0100761 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800762
763 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
764 ha->efi_revision[0]);
765}
766
767static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100768qla2x00_optrom_fcode_version_show(struct device *dev,
769 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800770{
Tony Jonesee959b02008-02-22 00:13:36 +0100771 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800772
773 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
774 ha->fcode_revision[0]);
775}
776
777static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100778qla2x00_optrom_fw_version_show(struct device *dev,
779 struct device_attribute *attr, char *buf)
Andrew Vasquez30c47662007-01-29 10:22:21 -0800780{
Tony Jonesee959b02008-02-22 00:13:36 +0100781 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
Andrew Vasquez30c47662007-01-29 10:22:21 -0800782
783 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
784 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
785 ha->fw_revision[3]);
786}
787
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700788static ssize_t
789qla2x00_total_isp_aborts_show(struct device *dev,
790 struct device_attribute *attr, char *buf)
791{
792 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
793
794 return snprintf(buf, PAGE_SIZE, "%d\n",
795 ha->qla_stats.total_isp_aborts);
796}
797
Tony Jonesee959b02008-02-22 00:13:36 +0100798static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
799static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
800static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
801static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
802static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
803static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
804static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
805static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100806static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +0100807static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
808static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
809 qla2x00_zio_timer_store);
810static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
811 qla2x00_beacon_store);
812static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
813 qla2x00_optrom_bios_version_show, NULL);
814static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
815 qla2x00_optrom_efi_version_show, NULL);
816static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
817 qla2x00_optrom_fcode_version_show, NULL);
818static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
819 NULL);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700820static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
821 NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700822
Tony Jonesee959b02008-02-22 00:13:36 +0100823struct device_attribute *qla2x00_host_attrs[] = {
824 &dev_attr_driver_version,
825 &dev_attr_fw_version,
826 &dev_attr_serial_num,
827 &dev_attr_isp_name,
828 &dev_attr_isp_id,
829 &dev_attr_model_name,
830 &dev_attr_model_desc,
831 &dev_attr_pci_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100832 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +0100833 &dev_attr_zio,
834 &dev_attr_zio_timer,
835 &dev_attr_beacon,
836 &dev_attr_optrom_bios_version,
837 &dev_attr_optrom_efi_version,
838 &dev_attr_optrom_fcode_version,
839 &dev_attr_optrom_fw_version,
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -0700840 &dev_attr_total_isp_aborts,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700841 NULL,
842};
843
8482e112005-04-17 15:04:54 -0500844/* Host attributes. */
845
846static void
847qla2x00_get_host_port_id(struct Scsi_Host *shost)
848{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700849 scsi_qla_host_t *ha = shost_priv(shost);
8482e112005-04-17 15:04:54 -0500850
851 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
852 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
853}
854
855static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800856qla2x00_get_host_speed(struct Scsi_Host *shost)
857{
Seokmann Juda4541b2008-01-31 12:33:52 -0800858 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700859 u32 speed = FC_PORTSPEED_UNKNOWN;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800860
861 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700862 case PORT_SPEED_1GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700863 speed = FC_PORTSPEED_1GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800864 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700865 case PORT_SPEED_2GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700866 speed = FC_PORTSPEED_2GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800867 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700868 case PORT_SPEED_4GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700869 speed = FC_PORTSPEED_4GBIT;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800870 break;
Seokmann Juda4541b2008-01-31 12:33:52 -0800871 case PORT_SPEED_8GB:
Andrew Vasquez2ae2b372008-04-03 13:13:14 -0700872 speed = FC_PORTSPEED_8GBIT;
Seokmann Juda4541b2008-01-31 12:33:52 -0800873 break;
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800874 }
875 fc_host_speed(shost) = speed;
876}
877
878static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800879qla2x00_get_host_port_type(struct Scsi_Host *shost)
880{
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700881 scsi_qla_host_t *ha = shost_priv(shost);
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800882 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
883
Shyam Sundar2f2fa132008-05-12 22:21:07 -0700884 if (ha->parent) {
885 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
886 return;
887 }
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800888 switch (ha->current_topology) {
889 case ISP_CFG_NL:
890 port_type = FC_PORTTYPE_LPORT;
891 break;
892 case ISP_CFG_FL:
893 port_type = FC_PORTTYPE_NLPORT;
894 break;
895 case ISP_CFG_N:
896 port_type = FC_PORTTYPE_PTP;
897 break;
898 case ISP_CFG_F:
899 port_type = FC_PORTTYPE_NPORT;
900 break;
901 }
902 fc_host_port_type(shost) = port_type;
903}
904
905static void
8482e112005-04-17 15:04:54 -0500906qla2x00_get_starget_node_name(struct scsi_target *starget)
907{
908 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700909 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500910 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700911 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500912
bdf79622005-04-17 15:06:53 -0500913 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700914 if (fcport->rport &&
915 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700916 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500917 break;
918 }
919 }
920
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700921 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500922}
923
924static void
925qla2x00_get_starget_port_name(struct scsi_target *starget)
926{
927 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700928 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500929 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700930 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500931
bdf79622005-04-17 15:06:53 -0500932 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700933 if (fcport->rport &&
934 starget->id == fcport->rport->scsi_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700935 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500936 break;
937 }
938 }
939
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700940 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500941}
942
943static void
944qla2x00_get_starget_port_id(struct scsi_target *starget)
945{
946 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
Andrew Vasquezf363b942007-09-20 14:07:45 -0700947 scsi_qla_host_t *ha = shost_priv(host);
bdf79622005-04-17 15:06:53 -0500948 fc_port_t *fcport;
949 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500950
bdf79622005-04-17 15:06:53 -0500951 list_for_each_entry(fcport, &ha->fcports, list) {
Andrew Vasquez5ab5a4d2008-04-03 13:13:16 -0700952 if (fcport->rport &&
953 starget->id == fcport->rport->scsi_target_id) {
bdf79622005-04-17 15:06:53 -0500954 port_id = fcport->d_id.b.domain << 16 |
955 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
956 break;
957 }
958 }
959
8482e112005-04-17 15:04:54 -0500960 fc_starget_port_id(starget) = port_id;
961}
962
963static void
8482e112005-04-17 15:04:54 -0500964qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
965{
8482e112005-04-17 15:04:54 -0500966 if (timeout)
Andrew Vasquez85821c92008-07-10 16:55:48 -0700967 rport->dev_loss_tmo = timeout;
8482e112005-04-17 15:04:54 -0500968 else
Andrew Vasquez85821c92008-07-10 16:55:48 -0700969 rport->dev_loss_tmo = 1;
8482e112005-04-17 15:04:54 -0500970}
971
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700972static void
973qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
974{
975 struct Scsi_Host *host = rport_to_shost(rport);
976 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
977
978 qla2x00_abort_fcport_cmds(fcport);
979
980 /*
981 * Transport has effectively 'deleted' the rport, clear
982 * all local references.
983 */
984 spin_lock_irq(host->host_lock);
985 fcport->rport = NULL;
986 *((fc_port_t **)rport->dd_data) = NULL;
987 spin_unlock_irq(host->host_lock);
988}
989
990static void
991qla2x00_terminate_rport_io(struct fc_rport *rport)
992{
993 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
994
995 qla2x00_abort_fcport_cmds(fcport);
996 scsi_target_unblock(&rport->dev);
997}
998
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700999static int
1000qla2x00_issue_lip(struct Scsi_Host *shost)
1001{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001002 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001003
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001004 qla2x00_loop_reset(ha);
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001005 return 0;
1006}
1007
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001008static struct fc_host_statistics *
1009qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1010{
Seokmann Juda4541b2008-01-31 12:33:52 -08001011 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001012 int rval;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001013 struct link_statistics *stats;
1014 dma_addr_t stats_dma;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001015 struct fc_host_statistics *pfc_host_stat;
1016
1017 pfc_host_stat = &ha->fc_host_stat;
1018 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1019
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001020 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1021 if (stats == NULL) {
1022 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1023 __func__, ha->host_no));
1024 goto done;
1025 }
1026 memset(stats, 0, DMA_POOL_SIZE);
1027
1028 rval = QLA_FUNCTION_FAILED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001029 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001030 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001031 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1032 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1033 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1034 !ha->dpc_active) {
1035 /* Must be in a 'READY' state for statistics retrieval. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001036 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1037 stats_dma);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001038 }
Andrew Vasquez178779a2007-01-29 10:22:25 -08001039
1040 if (rval != QLA_SUCCESS)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001041 goto done_free;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001042
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001043 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1044 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1045 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1046 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1047 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1048 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1049 if (IS_FWI2_CAPABLE(ha)) {
Harish Zunjarrao032d8dd2008-07-10 16:55:50 -07001050 pfc_host_stat->lip_count = stats->lip_cnt;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08001051 pfc_host_stat->tx_frames = stats->tx_frames;
1052 pfc_host_stat->rx_frames = stats->rx_frames;
1053 pfc_host_stat->dumped_frames = stats->dumped_frames;
1054 pfc_host_stat->nos_count = stats->nos_rcvd;
1055 }
1056
1057done_free:
1058 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
Andrew Vasquez178779a2007-01-29 10:22:25 -08001059done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001060 return pfc_host_stat;
1061}
1062
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001063static void
1064qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1065{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001066 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001067
1068 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1069}
1070
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001071static void
1072qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1073{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001074 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001075
1076 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1077}
1078
Andrew Vasquez90991c82006-10-02 12:00:46 -07001079static void
1080qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1081{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001082 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez90991c82006-10-02 12:00:46 -07001083 u64 node_name;
1084
1085 if (ha->device_flags & SWITCH_FOUND)
1086 node_name = wwn_to_u64(ha->fabric_node_name);
1087 else
1088 node_name = wwn_to_u64(ha->node_name);
1089
1090 fc_host_fabric_name(shost) = node_name;
1091}
1092
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001093static void
1094qla2x00_get_host_port_state(struct Scsi_Host *shost)
1095{
Seokmann Juda4541b2008-01-31 12:33:52 -08001096 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001097
1098 if (!ha->flags.online)
1099 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1100 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1101 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1102 else
1103 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1104}
1105
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001106static int
1107qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1108{
1109 int ret = 0;
Andrew Vasquezf363b942007-09-20 14:07:45 -07001110 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001111 scsi_qla_host_t *vha;
1112
1113 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1114 if (ret) {
1115 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1116 "status %x\n", ret));
1117 return (ret);
1118 }
1119
1120 vha = qla24xx_create_vhost(fc_vport);
1121 if (vha == NULL) {
1122 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1123 vha));
1124 return FC_VPORT_FAILED;
1125 }
1126 if (disable) {
1127 atomic_set(&vha->vp_state, VP_OFFLINE);
1128 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1129 } else
1130 atomic_set(&vha->vp_state, VP_FAILED);
1131
1132 /* ready to create vport */
1133 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1134
1135 /* initialized vport states */
1136 atomic_set(&vha->loop_state, LOOP_DOWN);
1137 vha->vp_err_state= VP_ERR_PORTDWN;
1138 vha->vp_prev_err_state= VP_ERR_UNKWN;
1139 /* Check if physical ha port is Up */
1140 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1141 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1142 /* Don't retry or attempt login of this virtual port */
1143 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1144 vha->host_no));
1145 atomic_set(&vha->loop_state, LOOP_DEAD);
1146 if (!disable)
1147 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1148 }
1149
1150 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1151 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1152 vha->host_no, vha->vp_idx));
1153 goto vport_create_failed_2;
1154 }
1155
1156 /* initialize attributes */
1157 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1158 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1159 fc_host_supported_classes(vha->host) =
1160 fc_host_supported_classes(ha->host);
1161 fc_host_supported_speeds(vha->host) =
1162 fc_host_supported_speeds(ha->host);
1163
1164 qla24xx_vport_disable(fc_vport, disable);
1165
1166 return 0;
1167vport_create_failed_2:
1168 qla24xx_disable_vp(vha);
1169 qla24xx_deallocate_vp_id(vha);
1170 kfree(vha->port_name);
1171 kfree(vha->node_name);
1172 scsi_host_put(vha->host);
1173 return FC_VPORT_FAILED;
1174}
1175
Adrian Bunka824ebb2008-01-17 09:02:15 -08001176static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001177qla24xx_vport_delete(struct fc_vport *fc_vport)
1178{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001179 scsi_qla_host_t *vha = fc_vport->dd_data;
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001180 scsi_qla_host_t *pha = to_qla_parent(vha);
1181
1182 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1183 test_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags))
1184 msleep(1000);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001185
1186 qla24xx_disable_vp(vha);
1187 qla24xx_deallocate_vp_id(vha);
1188
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001189 kfree(vha->node_name);
1190 kfree(vha->port_name);
1191
1192 if (vha->timer_active) {
1193 qla2x00_vp_stop_timer(vha);
1194 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1195 "has stopped\n",
1196 vha->host_no, vha->vp_idx, vha));
1197 }
1198
1199 fc_remove_host(vha->host);
1200
1201 scsi_remove_host(vha->host);
1202
1203 scsi_host_put(vha->host);
1204
1205 return 0;
1206}
1207
Adrian Bunka824ebb2008-01-17 09:02:15 -08001208static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001209qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1210{
1211 scsi_qla_host_t *vha = fc_vport->dd_data;
1212
1213 if (disable)
1214 qla24xx_disable_vp(vha);
1215 else
1216 qla24xx_enable_vp(vha);
1217
1218 return 0;
1219}
1220
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001221struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001222
1223 .show_host_node_name = 1,
1224 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001225 .show_host_supported_classes = 1,
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001226 .show_host_supported_speeds = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001227
8482e112005-04-17 15:04:54 -05001228 .get_host_port_id = qla2x00_get_host_port_id,
1229 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001230 .get_host_speed = qla2x00_get_host_speed,
1231 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001232 .get_host_port_type = qla2x00_get_host_port_type,
1233 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001234 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1235 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001236 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1237 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001238 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1239 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001240 .get_host_port_state = qla2x00_get_host_port_state,
1241 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001242
bdf79622005-04-17 15:06:53 -05001243 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001244 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001245
1246 .get_starget_node_name = qla2x00_get_starget_node_name,
1247 .show_starget_node_name = 1,
1248 .get_starget_port_name = qla2x00_get_starget_port_name,
1249 .show_starget_port_name = 1,
1250 .get_starget_port_id = qla2x00_get_starget_port_id,
1251 .show_starget_port_id = 1,
1252
8482e112005-04-17 15:04:54 -05001253 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1254 .show_rport_dev_loss_tmo = 1,
1255
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001256 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001257 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1258 .terminate_rport_io = qla2x00_terminate_rport_io,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001259 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001260
1261 .vport_create = qla24xx_vport_create,
1262 .vport_disable = qla24xx_vport_disable,
1263 .vport_delete = qla24xx_vport_delete,
1264};
1265
1266struct fc_function_template qla2xxx_transport_vport_functions = {
1267
1268 .show_host_node_name = 1,
1269 .show_host_port_name = 1,
1270 .show_host_supported_classes = 1,
1271
1272 .get_host_port_id = qla2x00_get_host_port_id,
1273 .show_host_port_id = 1,
1274 .get_host_speed = qla2x00_get_host_speed,
1275 .show_host_speed = 1,
1276 .get_host_port_type = qla2x00_get_host_port_type,
1277 .show_host_port_type = 1,
1278 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1279 .show_host_symbolic_name = 1,
1280 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1281 .show_host_system_hostname = 1,
1282 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1283 .show_host_fabric_name = 1,
1284 .get_host_port_state = qla2x00_get_host_port_state,
1285 .show_host_port_state = 1,
1286
1287 .dd_fcrport_size = sizeof(struct fc_port *),
1288 .show_rport_supported_classes = 1,
1289
1290 .get_starget_node_name = qla2x00_get_starget_node_name,
1291 .show_starget_node_name = 1,
1292 .get_starget_port_name = qla2x00_get_starget_port_name,
1293 .show_starget_port_name = 1,
1294 .get_starget_port_id = qla2x00_get_starget_port_id,
1295 .show_starget_port_id = 1,
1296
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001297 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1298 .show_rport_dev_loss_tmo = 1,
1299
1300 .issue_fc_host_lip = qla2x00_issue_lip,
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001301 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1302 .terminate_rport_io = qla2x00_terminate_rport_io,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001303 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -05001304};
1305
8482e112005-04-17 15:04:54 -05001306void
1307qla2x00_init_host_attr(scsi_qla_host_t *ha)
1308{
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001309 u32 speed = FC_PORTSPEED_UNKNOWN;
1310
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -08001311 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1312 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001313 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001314 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001315 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001316
1317 if (IS_QLA25XX(ha))
1318 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1319 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001320 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez2ae2b372008-04-03 13:13:14 -07001321 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1322 FC_PORTSPEED_1GBIT;
1323 else if (IS_QLA23XX(ha))
1324 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1325 else
1326 speed = FC_PORTSPEED_1GBIT;
1327 fc_host_supported_speeds(ha->host) = speed;
8482e112005-04-17 15:04:54 -05001328}