blob: e96d58ded57c3a08e28a7ddc73ecc193f6762107 [file] [log] [blame]
8482e112005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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
7aaef272005-04-17 16:32:42 -05009#include <linux/vmalloc.h>
8482e112005-04-17 15:04:54 -050010
11/* SYSFS attributes --------------------------------------------------------- */
12
13static ssize_t
14qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
15 size_t count)
16{
17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
18 struct device, kobj)));
19
20 if (ha->fw_dump_reading == 0)
21 return 0;
22 if (off > ha->fw_dump_buffer_len)
23 return 0;
24 if (off + count > ha->fw_dump_buffer_len)
25 count = ha->fw_dump_buffer_len - off;
26
27 memcpy(buf, &ha->fw_dump_buffer[off], count);
28
29 return (count);
30}
31
32static ssize_t
33qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
34 size_t count)
35{
36 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
37 struct device, kobj)));
38 int reading;
39 uint32_t dump_size;
40
41 if (off != 0)
42 return (0);
43
44 reading = simple_strtol(buf, NULL, 10);
45 switch (reading) {
46 case 0:
47 if (ha->fw_dump_reading == 1) {
48 qla_printk(KERN_INFO, ha,
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070049 "Firmware dump cleared on (%ld).\n", ha->host_no);
8482e112005-04-17 15:04:54 -050050
51 vfree(ha->fw_dump_buffer);
8482e112005-04-17 15:04:54 -050052 ha->fw_dump_buffer = NULL;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070053 ha->fw_dump_reading = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -070054 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050055 }
56 break;
57 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070058 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050059 ha->fw_dump_reading = 1;
60
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -080061 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquezfca29702005-07-06 10:31:47 -070062 dump_size = FW_DUMP_SIZE_24XX;
63 else {
64 dump_size = FW_DUMP_SIZE_1M;
65 if (ha->fw_memory_size < 0x20000)
66 dump_size = FW_DUMP_SIZE_128K;
67 else if (ha->fw_memory_size < 0x80000)
68 dump_size = FW_DUMP_SIZE_512K;
69 }
8482e112005-04-17 15:04:54 -050070 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
71 if (ha->fw_dump_buffer == NULL) {
72 qla_printk(KERN_WARNING, ha,
73 "Unable to allocate memory for firmware "
74 "dump buffer (%d).\n", dump_size);
75
76 ha->fw_dump_reading = 0;
77 return (count);
78 }
79 qla_printk(KERN_INFO, ha,
80 "Firmware dump ready for read on (%ld).\n",
81 ha->host_no);
82 memset(ha->fw_dump_buffer, 0, dump_size);
Andrew Vasquezabbd8872005-07-06 10:30:05 -070083 ha->isp_ops.ascii_fw_dump(ha);
8482e112005-04-17 15:04:54 -050084 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
85 }
86 break;
87 }
88 return (count);
89}
90
91static struct bin_attribute sysfs_fw_dump_attr = {
92 .attr = {
93 .name = "fw_dump",
94 .mode = S_IRUSR | S_IWUSR,
95 .owner = THIS_MODULE,
96 },
97 .size = 0,
98 .read = qla2x00_sysfs_read_fw_dump,
99 .write = qla2x00_sysfs_write_fw_dump,
100};
101
102static ssize_t
103qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
104 size_t count)
105{
106 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
107 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500108 unsigned long flags;
8482e112005-04-17 15:04:54 -0500109
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800110 if (!capable(CAP_SYS_ADMIN) || off != 0)
8482e112005-04-17 15:04:54 -0500111 return 0;
112
113 /* Read NVRAM. */
114 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700115 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
116 ha->nvram_size);
8482e112005-04-17 15:04:54 -0500117 spin_unlock_irqrestore(&ha->hardware_lock, flags);
118
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800119 return ha->nvram_size;
8482e112005-04-17 15:04:54 -0500120}
121
122static ssize_t
123qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
124 size_t count)
125{
126 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
127 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500128 unsigned long flags;
129 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500130
Andrew Vasquez459c5372005-07-06 10:31:07 -0700131 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500132 return 0;
133
134 /* Checksum NVRAM. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800135 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700136 uint32_t *iter;
137 uint32_t chksum;
138
139 iter = (uint32_t *)buf;
140 chksum = 0;
141 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
142 chksum += le32_to_cpu(*iter++);
143 chksum = ~chksum + 1;
144 *iter = cpu_to_le32(chksum);
145 } else {
146 uint8_t *iter;
147 uint8_t chksum;
148
149 iter = (uint8_t *)buf;
150 chksum = 0;
151 for (cnt = 0; cnt < count - 1; cnt++)
152 chksum += *iter++;
153 chksum = ~chksum + 1;
154 *iter = chksum;
155 }
8482e112005-04-17 15:04:54 -0500156
157 /* Write NVRAM. */
158 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700159 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
8482e112005-04-17 15:04:54 -0500160 spin_unlock_irqrestore(&ha->hardware_lock, flags);
161
162 return (count);
163}
164
165static struct bin_attribute sysfs_nvram_attr = {
166 .attr = {
167 .name = "nvram",
168 .mode = S_IRUSR | S_IWUSR,
169 .owner = THIS_MODULE,
170 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800171 .size = 512,
8482e112005-04-17 15:04:54 -0500172 .read = qla2x00_sysfs_read_nvram,
173 .write = qla2x00_sysfs_write_nvram,
174};
175
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800176static ssize_t
177qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
178 size_t count)
179{
180 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
181 struct device, kobj)));
182
183 if (ha->optrom_state != QLA_SREADING)
184 return 0;
185 if (off > ha->optrom_size)
186 return 0;
187 if (off + count > ha->optrom_size)
188 count = ha->optrom_size - off;
189
190 memcpy(buf, &ha->optrom_buffer[off], count);
191
192 return count;
193}
194
195static ssize_t
196qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off,
197 size_t count)
198{
199 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
200 struct device, kobj)));
201
202 if (ha->optrom_state != QLA_SWRITING)
203 return -EINVAL;
204 if (off > ha->optrom_size)
205 return -ERANGE;
206 if (off + count > ha->optrom_size)
207 count = ha->optrom_size - off;
208
209 memcpy(&ha->optrom_buffer[off], buf, count);
210
211 return count;
212}
213
214static struct bin_attribute sysfs_optrom_attr = {
215 .attr = {
216 .name = "optrom",
217 .mode = S_IRUSR | S_IWUSR,
218 .owner = THIS_MODULE,
219 },
220 .size = OPTROM_SIZE_24XX,
221 .read = qla2x00_sysfs_read_optrom,
222 .write = qla2x00_sysfs_write_optrom,
223};
224
225static ssize_t
226qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
227 size_t count)
228{
229 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
230 struct device, kobj)));
231 int val;
232
233 if (off)
234 return 0;
235
236 if (sscanf(buf, "%d", &val) != 1)
237 return -EINVAL;
238
239 switch (val) {
240 case 0:
241 if (ha->optrom_state != QLA_SREADING &&
242 ha->optrom_state != QLA_SWRITING)
243 break;
244
245 ha->optrom_state = QLA_SWAITING;
246 vfree(ha->optrom_buffer);
247 ha->optrom_buffer = NULL;
248 break;
249 case 1:
250 if (ha->optrom_state != QLA_SWAITING)
251 break;
252
253 ha->optrom_state = QLA_SREADING;
254 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
255 if (ha->optrom_buffer == NULL) {
256 qla_printk(KERN_WARNING, ha,
257 "Unable to allocate memory for optrom retrieval "
258 "(%x).\n", ha->optrom_size);
259
260 ha->optrom_state = QLA_SWAITING;
261 return count;
262 }
263
264 memset(ha->optrom_buffer, 0, ha->optrom_size);
265 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
266 ha->optrom_size);
267 break;
268 case 2:
269 if (ha->optrom_state != QLA_SWAITING)
270 break;
271
272 ha->optrom_state = QLA_SWRITING;
273 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
274 if (ha->optrom_buffer == NULL) {
275 qla_printk(KERN_WARNING, ha,
276 "Unable to allocate memory for optrom update "
277 "(%x).\n", ha->optrom_size);
278
279 ha->optrom_state = QLA_SWAITING;
280 return count;
281 }
282 memset(ha->optrom_buffer, 0, ha->optrom_size);
283 break;
284 case 3:
285 if (ha->optrom_state != QLA_SWRITING)
286 break;
287
288 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
289 ha->optrom_size);
290 break;
291 }
292 return count;
293}
294
295static struct bin_attribute sysfs_optrom_ctl_attr = {
296 .attr = {
297 .name = "optrom_ctl",
298 .mode = S_IWUSR,
299 .owner = THIS_MODULE,
300 },
301 .size = 0,
302 .write = qla2x00_sysfs_write_optrom_ctl,
303};
304
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800305static ssize_t
306qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
307 size_t count)
308{
309 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
310 struct device, kobj)));
311 unsigned long flags;
312
313 if (!capable(CAP_SYS_ADMIN) || off != 0)
314 return 0;
315
316 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
317 return -ENOTSUPP;
318
319 /* Read NVRAM. */
320 spin_lock_irqsave(&ha->hardware_lock, flags);
321 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
322 spin_unlock_irqrestore(&ha->hardware_lock, flags);
323
324 return ha->vpd_size;
325}
326
327static ssize_t
328qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
329 size_t count)
330{
331 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
332 struct device, kobj)));
333 unsigned long flags;
334
335 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
336 return 0;
337
338 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
339 return -ENOTSUPP;
340
341 /* Write NVRAM. */
342 spin_lock_irqsave(&ha->hardware_lock, flags);
343 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
344 spin_unlock_irqrestore(&ha->hardware_lock, flags);
345
346 return count;
347}
348
349static struct bin_attribute sysfs_vpd_attr = {
350 .attr = {
351 .name = "vpd",
352 .mode = S_IRUSR | S_IWUSR,
353 .owner = THIS_MODULE,
354 },
355 .size = 0,
356 .read = qla2x00_sysfs_read_vpd,
357 .write = qla2x00_sysfs_write_vpd,
358};
359
8482e112005-04-17 15:04:54 -0500360void
361qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
362{
363 struct Scsi_Host *host = ha->host;
364
365 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
366 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800367 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
368 sysfs_create_bin_file(&host->shost_gendev.kobj,
369 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800370 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
8482e112005-04-17 15:04:54 -0500371}
372
373void
374qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
375{
376 struct Scsi_Host *host = ha->host;
377
378 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
379 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800380 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
381 sysfs_remove_bin_file(&host->shost_gendev.kobj,
382 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800383 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800384
385 if (ha->beacon_blink_led == 1)
386 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500387}
388
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700389/* Scsi_Host attributes. */
390
391static ssize_t
392qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
393{
394 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
395}
396
397static ssize_t
398qla2x00_fw_version_show(struct class_device *cdev, char *buf)
399{
400 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
401 char fw_str[30];
402
403 return snprintf(buf, PAGE_SIZE, "%s\n",
404 ha->isp_ops.fw_version_str(ha, fw_str));
405}
406
407static ssize_t
408qla2x00_serial_num_show(struct class_device *cdev, char *buf)
409{
410 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
411 uint32_t sn;
412
413 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
414 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
415 sn % 100000);
416}
417
418static ssize_t
419qla2x00_isp_name_show(struct class_device *cdev, char *buf)
420{
421 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800422 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700423}
424
425static ssize_t
426qla2x00_isp_id_show(struct class_device *cdev, char *buf)
427{
428 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
429 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
430 ha->product_id[0], ha->product_id[1], ha->product_id[2],
431 ha->product_id[3]);
432}
433
434static ssize_t
435qla2x00_model_name_show(struct class_device *cdev, char *buf)
436{
437 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
438 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
439}
440
441static ssize_t
442qla2x00_model_desc_show(struct class_device *cdev, char *buf)
443{
444 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
445 return snprintf(buf, PAGE_SIZE, "%s\n",
446 ha->model_desc ? ha->model_desc: "");
447}
448
449static ssize_t
450qla2x00_pci_info_show(struct class_device *cdev, char *buf)
451{
452 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
453 char pci_info[30];
454
455 return snprintf(buf, PAGE_SIZE, "%s\n",
456 ha->isp_ops.pci_info_str(ha, pci_info));
457}
458
459static ssize_t
460qla2x00_state_show(struct class_device *cdev, char *buf)
461{
462 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
463 int len = 0;
464
465 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
466 atomic_read(&ha->loop_state) == LOOP_DEAD)
467 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
468 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
469 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
470 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
471 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
472 else {
473 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
474
475 switch (ha->current_topology) {
476 case ISP_CFG_NL:
477 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
478 break;
479 case ISP_CFG_FL:
480 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
481 break;
482 case ISP_CFG_N:
483 len += snprintf(buf + len, PAGE_SIZE-len,
484 "N_Port to N_Port\n");
485 break;
486 case ISP_CFG_F:
487 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
488 break;
489 default:
490 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
491 break;
492 }
493 }
494 return len;
495}
496
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700497static ssize_t
498qla2x00_zio_show(struct class_device *cdev, char *buf)
499{
500 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
501 int len = 0;
502
503 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700504 case QLA_ZIO_MODE_6:
505 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
506 break;
507 case QLA_ZIO_DISABLED:
508 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
509 break;
510 }
511 return len;
512}
513
514static ssize_t
515qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
516{
517 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
518 int val = 0;
519 uint16_t zio_mode;
520
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800521 if (!IS_ZIO_SUPPORTED(ha))
522 return -ENOTSUPP;
523
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700524 if (sscanf(buf, "%d", &val) != 1)
525 return -EINVAL;
526
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800527 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700528 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800529 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700530 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700531
532 /* Update per-hba values and queue a reset. */
533 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
534 ha->zio_mode = zio_mode;
535 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
536 }
537 return strlen(buf);
538}
539
540static ssize_t
541qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
542{
543 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
544
545 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
546}
547
548static ssize_t
549qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
550 size_t count)
551{
552 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
553 int val = 0;
554 uint16_t zio_timer;
555
556 if (sscanf(buf, "%d", &val) != 1)
557 return -EINVAL;
558 if (val > 25500 || val < 100)
559 return -ERANGE;
560
561 zio_timer = (uint16_t)(val / 100);
562 ha->zio_timer = zio_timer;
563
564 return strlen(buf);
565}
566
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800567static ssize_t
568qla2x00_beacon_show(struct class_device *cdev, char *buf)
569{
570 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
571 int len = 0;
572
573 if (ha->beacon_blink_led)
574 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
575 else
576 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
577 return len;
578}
579
580static ssize_t
581qla2x00_beacon_store(struct class_device *cdev, const char *buf,
582 size_t count)
583{
584 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
585 int val = 0;
586 int rval;
587
588 if (IS_QLA2100(ha) || IS_QLA2200(ha))
589 return -EPERM;
590
591 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
592 qla_printk(KERN_WARNING, ha,
593 "Abort ISP active -- ignoring beacon request.\n");
594 return -EBUSY;
595 }
596
597 if (sscanf(buf, "%d", &val) != 1)
598 return -EINVAL;
599
600 if (val)
601 rval = ha->isp_ops.beacon_on(ha);
602 else
603 rval = ha->isp_ops.beacon_off(ha);
604
605 if (rval != QLA_SUCCESS)
606 count = 0;
607
608 return count;
609}
610
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700611static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
612 NULL);
613static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
614static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
615static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
616static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
617static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
618static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
619static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
620static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700621static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
622 qla2x00_zio_store);
623static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
624 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800625static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
626 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700627
628struct class_device_attribute *qla2x00_host_attrs[] = {
629 &class_device_attr_driver_version,
630 &class_device_attr_fw_version,
631 &class_device_attr_serial_num,
632 &class_device_attr_isp_name,
633 &class_device_attr_isp_id,
634 &class_device_attr_model_name,
635 &class_device_attr_model_desc,
636 &class_device_attr_pci_info,
637 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700638 &class_device_attr_zio,
639 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800640 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700641 NULL,
642};
643
8482e112005-04-17 15:04:54 -0500644/* Host attributes. */
645
646static void
647qla2x00_get_host_port_id(struct Scsi_Host *shost)
648{
649 scsi_qla_host_t *ha = to_qla_host(shost);
650
651 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
652 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
653}
654
655static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800656qla2x00_get_host_speed(struct Scsi_Host *shost)
657{
658 scsi_qla_host_t *ha = to_qla_host(shost);
659 uint32_t speed = 0;
660
661 switch (ha->link_data_rate) {
662 case LDR_1GB:
663 speed = 1;
664 break;
665 case LDR_2GB:
666 speed = 2;
667 break;
668 case LDR_4GB:
669 speed = 4;
670 break;
671 }
672 fc_host_speed(shost) = speed;
673}
674
675static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800676qla2x00_get_host_port_type(struct Scsi_Host *shost)
677{
678 scsi_qla_host_t *ha = to_qla_host(shost);
679 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
680
681 switch (ha->current_topology) {
682 case ISP_CFG_NL:
683 port_type = FC_PORTTYPE_LPORT;
684 break;
685 case ISP_CFG_FL:
686 port_type = FC_PORTTYPE_NLPORT;
687 break;
688 case ISP_CFG_N:
689 port_type = FC_PORTTYPE_PTP;
690 break;
691 case ISP_CFG_F:
692 port_type = FC_PORTTYPE_NPORT;
693 break;
694 }
695 fc_host_port_type(shost) = port_type;
696}
697
698static void
8482e112005-04-17 15:04:54 -0500699qla2x00_get_starget_node_name(struct scsi_target *starget)
700{
701 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
702 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500703 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700704 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500705
bdf79622005-04-17 15:06:53 -0500706 list_for_each_entry(fcport, &ha->fcports, list) {
707 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700708 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500709 break;
710 }
711 }
712
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700713 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500714}
715
716static void
717qla2x00_get_starget_port_name(struct scsi_target *starget)
718{
719 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
720 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500721 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700722 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500723
bdf79622005-04-17 15:06:53 -0500724 list_for_each_entry(fcport, &ha->fcports, list) {
725 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700726 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500727 break;
728 }
729 }
730
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700731 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500732}
733
734static void
735qla2x00_get_starget_port_id(struct scsi_target *starget)
736{
737 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
738 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500739 fc_port_t *fcport;
740 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500741
bdf79622005-04-17 15:06:53 -0500742 list_for_each_entry(fcport, &ha->fcports, list) {
743 if (starget->id == fcport->os_target_id) {
744 port_id = fcport->d_id.b.domain << 16 |
745 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
746 break;
747 }
748 }
749
8482e112005-04-17 15:04:54 -0500750 fc_starget_port_id(starget) = port_id;
751}
752
753static void
754qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
755{
bdf79622005-04-17 15:06:53 -0500756 struct Scsi_Host *host = rport_to_shost(rport);
757 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500758
759 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
760}
761
762static void
763qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
764{
bdf79622005-04-17 15:06:53 -0500765 struct Scsi_Host *host = rport_to_shost(rport);
766 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500767
768 if (timeout)
769 ha->port_down_retry_count = timeout;
770 else
771 ha->port_down_retry_count = 1;
772
773 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
774}
775
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700776static int
777qla2x00_issue_lip(struct Scsi_Host *shost)
778{
779 scsi_qla_host_t *ha = to_qla_host(shost);
780
781 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
782 return 0;
783}
784
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800785static struct fc_host_statistics *
786qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
787{
788 scsi_qla_host_t *ha = to_qla_host(shost);
789 int rval;
790 uint16_t mb_stat[1];
791 link_stat_t stat_buf;
792 struct fc_host_statistics *pfc_host_stat;
793
794 pfc_host_stat = &ha->fc_host_stat;
795 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
796
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800797 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800798 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
799 sizeof(stat_buf) / 4, mb_stat);
800 } else {
801 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
802 mb_stat);
803 }
804 if (rval != 0) {
805 qla_printk(KERN_WARNING, ha,
806 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
807 return pfc_host_stat;
808 }
809
810 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
811 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
812 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
813 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
814 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
815 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
816
817 return pfc_host_stat;
818}
819
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400820struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -0500821
822 .show_host_node_name = 1,
823 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700824 .show_host_supported_classes = 1,
825
8482e112005-04-17 15:04:54 -0500826 .get_host_port_id = qla2x00_get_host_port_id,
827 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800828 .get_host_speed = qla2x00_get_host_speed,
829 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800830 .get_host_port_type = qla2x00_get_host_port_type,
831 .show_host_port_type = 1,
8482e112005-04-17 15:04:54 -0500832
bdf79622005-04-17 15:06:53 -0500833 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700834 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -0500835
836 .get_starget_node_name = qla2x00_get_starget_node_name,
837 .show_starget_node_name = 1,
838 .get_starget_port_name = qla2x00_get_starget_port_name,
839 .show_starget_port_name = 1,
840 .get_starget_port_id = qla2x00_get_starget_port_id,
841 .show_starget_port_id = 1,
842
843 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
844 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
845 .show_rport_dev_loss_tmo = 1,
846
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700847 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800848 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -0500849};
850
8482e112005-04-17 15:04:54 -0500851void
852qla2x00_init_host_attr(scsi_qla_host_t *ha)
853{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800854 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
855 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700856 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e112005-04-17 15:04:54 -0500857}