blob: 488b3d16427bc5af9140df6b9e77ee73120f5805 [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,
49 "Firmware dump cleared on (%ld).\n",
50 ha->host_no);
51
52 vfree(ha->fw_dump_buffer);
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -080053 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
Andrew Vasquezfca29702005-07-06 10:31:47 -070054 free_pages((unsigned long)ha->fw_dump,
55 ha->fw_dump_order);
8482e112005-04-17 15:04:54 -050056
57 ha->fw_dump_reading = 0;
58 ha->fw_dump_buffer = NULL;
59 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -070060 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050061 }
62 break;
63 case 1:
Andrew Vasquezfca29702005-07-06 10:31:47 -070064 if ((ha->fw_dump || ha->fw_dumped) && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050065 ha->fw_dump_reading = 1;
66
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -080067 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquezfca29702005-07-06 10:31:47 -070068 dump_size = FW_DUMP_SIZE_24XX;
69 else {
70 dump_size = FW_DUMP_SIZE_1M;
71 if (ha->fw_memory_size < 0x20000)
72 dump_size = FW_DUMP_SIZE_128K;
73 else if (ha->fw_memory_size < 0x80000)
74 dump_size = FW_DUMP_SIZE_512K;
75 }
8482e112005-04-17 15:04:54 -050076 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
77 if (ha->fw_dump_buffer == NULL) {
78 qla_printk(KERN_WARNING, ha,
79 "Unable to allocate memory for firmware "
80 "dump buffer (%d).\n", dump_size);
81
82 ha->fw_dump_reading = 0;
83 return (count);
84 }
85 qla_printk(KERN_INFO, ha,
86 "Firmware dump ready for read on (%ld).\n",
87 ha->host_no);
88 memset(ha->fw_dump_buffer, 0, dump_size);
Andrew Vasquezabbd8872005-07-06 10:30:05 -070089 ha->isp_ops.ascii_fw_dump(ha);
8482e112005-04-17 15:04:54 -050090 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
91 }
92 break;
93 }
94 return (count);
95}
96
97static struct bin_attribute sysfs_fw_dump_attr = {
98 .attr = {
99 .name = "fw_dump",
100 .mode = S_IRUSR | S_IWUSR,
101 .owner = THIS_MODULE,
102 },
103 .size = 0,
104 .read = qla2x00_sysfs_read_fw_dump,
105 .write = qla2x00_sysfs_write_fw_dump,
106};
107
108static ssize_t
109qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
110 size_t count)
111{
112 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
113 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500114 unsigned long flags;
8482e112005-04-17 15:04:54 -0500115
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800116 if (!capable(CAP_SYS_ADMIN) || off != 0)
8482e112005-04-17 15:04:54 -0500117 return 0;
118
119 /* Read NVRAM. */
120 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700121 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
122 ha->nvram_size);
8482e112005-04-17 15:04:54 -0500123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
124
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800125 return ha->nvram_size;
8482e112005-04-17 15:04:54 -0500126}
127
128static ssize_t
129qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
130 size_t count)
131{
132 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
133 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500134 unsigned long flags;
135 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500136
Andrew Vasquez459c5372005-07-06 10:31:07 -0700137 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500138 return 0;
139
140 /* Checksum NVRAM. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800141 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700142 uint32_t *iter;
143 uint32_t chksum;
144
145 iter = (uint32_t *)buf;
146 chksum = 0;
147 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
148 chksum += le32_to_cpu(*iter++);
149 chksum = ~chksum + 1;
150 *iter = cpu_to_le32(chksum);
151 } else {
152 uint8_t *iter;
153 uint8_t chksum;
154
155 iter = (uint8_t *)buf;
156 chksum = 0;
157 for (cnt = 0; cnt < count - 1; cnt++)
158 chksum += *iter++;
159 chksum = ~chksum + 1;
160 *iter = chksum;
161 }
8482e112005-04-17 15:04:54 -0500162
163 /* Write NVRAM. */
164 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700165 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
8482e112005-04-17 15:04:54 -0500166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
167
168 return (count);
169}
170
171static struct bin_attribute sysfs_nvram_attr = {
172 .attr = {
173 .name = "nvram",
174 .mode = S_IRUSR | S_IWUSR,
175 .owner = THIS_MODULE,
176 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800177 .size = 512,
8482e112005-04-17 15:04:54 -0500178 .read = qla2x00_sysfs_read_nvram,
179 .write = qla2x00_sysfs_write_nvram,
180};
181
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800182static ssize_t
183qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
184 size_t count)
185{
186 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
187 struct device, kobj)));
188
189 if (ha->optrom_state != QLA_SREADING)
190 return 0;
191 if (off > ha->optrom_size)
192 return 0;
193 if (off + count > ha->optrom_size)
194 count = ha->optrom_size - off;
195
196 memcpy(buf, &ha->optrom_buffer[off], count);
197
198 return count;
199}
200
201static ssize_t
202qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off,
203 size_t count)
204{
205 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
206 struct device, kobj)));
207
208 if (ha->optrom_state != QLA_SWRITING)
209 return -EINVAL;
210 if (off > ha->optrom_size)
211 return -ERANGE;
212 if (off + count > ha->optrom_size)
213 count = ha->optrom_size - off;
214
215 memcpy(&ha->optrom_buffer[off], buf, count);
216
217 return count;
218}
219
220static struct bin_attribute sysfs_optrom_attr = {
221 .attr = {
222 .name = "optrom",
223 .mode = S_IRUSR | S_IWUSR,
224 .owner = THIS_MODULE,
225 },
226 .size = OPTROM_SIZE_24XX,
227 .read = qla2x00_sysfs_read_optrom,
228 .write = qla2x00_sysfs_write_optrom,
229};
230
231static ssize_t
232qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
233 size_t count)
234{
235 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
236 struct device, kobj)));
237 int val;
238
239 if (off)
240 return 0;
241
242 if (sscanf(buf, "%d", &val) != 1)
243 return -EINVAL;
244
245 switch (val) {
246 case 0:
247 if (ha->optrom_state != QLA_SREADING &&
248 ha->optrom_state != QLA_SWRITING)
249 break;
250
251 ha->optrom_state = QLA_SWAITING;
252 vfree(ha->optrom_buffer);
253 ha->optrom_buffer = NULL;
254 break;
255 case 1:
256 if (ha->optrom_state != QLA_SWAITING)
257 break;
258
259 ha->optrom_state = QLA_SREADING;
260 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
261 if (ha->optrom_buffer == NULL) {
262 qla_printk(KERN_WARNING, ha,
263 "Unable to allocate memory for optrom retrieval "
264 "(%x).\n", ha->optrom_size);
265
266 ha->optrom_state = QLA_SWAITING;
267 return count;
268 }
269
270 memset(ha->optrom_buffer, 0, ha->optrom_size);
271 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
272 ha->optrom_size);
273 break;
274 case 2:
275 if (ha->optrom_state != QLA_SWAITING)
276 break;
277
278 ha->optrom_state = QLA_SWRITING;
279 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
280 if (ha->optrom_buffer == NULL) {
281 qla_printk(KERN_WARNING, ha,
282 "Unable to allocate memory for optrom update "
283 "(%x).\n", ha->optrom_size);
284
285 ha->optrom_state = QLA_SWAITING;
286 return count;
287 }
288 memset(ha->optrom_buffer, 0, ha->optrom_size);
289 break;
290 case 3:
291 if (ha->optrom_state != QLA_SWRITING)
292 break;
293
294 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
295 ha->optrom_size);
296 break;
297 }
298 return count;
299}
300
301static struct bin_attribute sysfs_optrom_ctl_attr = {
302 .attr = {
303 .name = "optrom_ctl",
304 .mode = S_IWUSR,
305 .owner = THIS_MODULE,
306 },
307 .size = 0,
308 .write = qla2x00_sysfs_write_optrom_ctl,
309};
310
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800311static ssize_t
312qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
313 size_t count)
314{
315 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
316 struct device, kobj)));
317 unsigned long flags;
318
319 if (!capable(CAP_SYS_ADMIN) || off != 0)
320 return 0;
321
322 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
323 return -ENOTSUPP;
324
325 /* Read NVRAM. */
326 spin_lock_irqsave(&ha->hardware_lock, flags);
327 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
328 spin_unlock_irqrestore(&ha->hardware_lock, flags);
329
330 return ha->vpd_size;
331}
332
333static ssize_t
334qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
335 size_t count)
336{
337 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
338 struct device, kobj)));
339 unsigned long flags;
340
341 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
342 return 0;
343
344 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
345 return -ENOTSUPP;
346
347 /* Write NVRAM. */
348 spin_lock_irqsave(&ha->hardware_lock, flags);
349 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
350 spin_unlock_irqrestore(&ha->hardware_lock, flags);
351
352 return count;
353}
354
355static struct bin_attribute sysfs_vpd_attr = {
356 .attr = {
357 .name = "vpd",
358 .mode = S_IRUSR | S_IWUSR,
359 .owner = THIS_MODULE,
360 },
361 .size = 0,
362 .read = qla2x00_sysfs_read_vpd,
363 .write = qla2x00_sysfs_write_vpd,
364};
365
8482e112005-04-17 15:04:54 -0500366void
367qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
368{
369 struct Scsi_Host *host = ha->host;
370
371 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
372 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800373 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
374 sysfs_create_bin_file(&host->shost_gendev.kobj,
375 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800376 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
8482e112005-04-17 15:04:54 -0500377}
378
379void
380qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
381{
382 struct Scsi_Host *host = ha->host;
383
384 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
385 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800386 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
387 sysfs_remove_bin_file(&host->shost_gendev.kobj,
388 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800389 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800390
391 if (ha->beacon_blink_led == 1)
392 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500393}
394
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700395/* Scsi_Host attributes. */
396
397static ssize_t
398qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
399{
400 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
401}
402
403static ssize_t
404qla2x00_fw_version_show(struct class_device *cdev, char *buf)
405{
406 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
407 char fw_str[30];
408
409 return snprintf(buf, PAGE_SIZE, "%s\n",
410 ha->isp_ops.fw_version_str(ha, fw_str));
411}
412
413static ssize_t
414qla2x00_serial_num_show(struct class_device *cdev, char *buf)
415{
416 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
417 uint32_t sn;
418
419 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
420 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
421 sn % 100000);
422}
423
424static ssize_t
425qla2x00_isp_name_show(struct class_device *cdev, char *buf)
426{
427 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800428 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700429}
430
431static ssize_t
432qla2x00_isp_id_show(struct class_device *cdev, char *buf)
433{
434 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
435 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
436 ha->product_id[0], ha->product_id[1], ha->product_id[2],
437 ha->product_id[3]);
438}
439
440static ssize_t
441qla2x00_model_name_show(struct class_device *cdev, char *buf)
442{
443 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
444 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
445}
446
447static ssize_t
448qla2x00_model_desc_show(struct class_device *cdev, char *buf)
449{
450 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
451 return snprintf(buf, PAGE_SIZE, "%s\n",
452 ha->model_desc ? ha->model_desc: "");
453}
454
455static ssize_t
456qla2x00_pci_info_show(struct class_device *cdev, char *buf)
457{
458 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
459 char pci_info[30];
460
461 return snprintf(buf, PAGE_SIZE, "%s\n",
462 ha->isp_ops.pci_info_str(ha, pci_info));
463}
464
465static ssize_t
466qla2x00_state_show(struct class_device *cdev, char *buf)
467{
468 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
469 int len = 0;
470
471 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
472 atomic_read(&ha->loop_state) == LOOP_DEAD)
473 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
474 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
475 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
476 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
477 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
478 else {
479 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
480
481 switch (ha->current_topology) {
482 case ISP_CFG_NL:
483 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
484 break;
485 case ISP_CFG_FL:
486 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
487 break;
488 case ISP_CFG_N:
489 len += snprintf(buf + len, PAGE_SIZE-len,
490 "N_Port to N_Port\n");
491 break;
492 case ISP_CFG_F:
493 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
494 break;
495 default:
496 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
497 break;
498 }
499 }
500 return len;
501}
502
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700503static ssize_t
504qla2x00_zio_show(struct class_device *cdev, char *buf)
505{
506 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
507 int len = 0;
508
509 switch (ha->zio_mode) {
510 case QLA_ZIO_MODE_5:
511 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
512 break;
513 case QLA_ZIO_MODE_6:
514 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
515 break;
516 case QLA_ZIO_DISABLED:
517 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
518 break;
519 }
520 return len;
521}
522
523static ssize_t
524qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
525{
526 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
527 int val = 0;
528 uint16_t zio_mode;
529
530 if (sscanf(buf, "%d", &val) != 1)
531 return -EINVAL;
532
533 switch (val) {
534 case 1:
535 zio_mode = QLA_ZIO_MODE_5;
536 break;
537 case 2:
538 zio_mode = QLA_ZIO_MODE_6;
539 break;
540 default:
541 zio_mode = QLA_ZIO_DISABLED;
542 break;
543 }
544
545 /* Update per-hba values and queue a reset. */
546 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
547 ha->zio_mode = zio_mode;
548 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
549 }
550 return strlen(buf);
551}
552
553static ssize_t
554qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
555{
556 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
557
558 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
559}
560
561static ssize_t
562qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
563 size_t count)
564{
565 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
566 int val = 0;
567 uint16_t zio_timer;
568
569 if (sscanf(buf, "%d", &val) != 1)
570 return -EINVAL;
571 if (val > 25500 || val < 100)
572 return -ERANGE;
573
574 zio_timer = (uint16_t)(val / 100);
575 ha->zio_timer = zio_timer;
576
577 return strlen(buf);
578}
579
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800580static ssize_t
581qla2x00_beacon_show(struct class_device *cdev, char *buf)
582{
583 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
584 int len = 0;
585
586 if (ha->beacon_blink_led)
587 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
588 else
589 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
590 return len;
591}
592
593static ssize_t
594qla2x00_beacon_store(struct class_device *cdev, const char *buf,
595 size_t count)
596{
597 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
598 int val = 0;
599 int rval;
600
601 if (IS_QLA2100(ha) || IS_QLA2200(ha))
602 return -EPERM;
603
604 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
605 qla_printk(KERN_WARNING, ha,
606 "Abort ISP active -- ignoring beacon request.\n");
607 return -EBUSY;
608 }
609
610 if (sscanf(buf, "%d", &val) != 1)
611 return -EINVAL;
612
613 if (val)
614 rval = ha->isp_ops.beacon_on(ha);
615 else
616 rval = ha->isp_ops.beacon_off(ha);
617
618 if (rval != QLA_SUCCESS)
619 count = 0;
620
621 return count;
622}
623
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700624static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
625 NULL);
626static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
627static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
628static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
629static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
630static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
631static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
632static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
633static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700634static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
635 qla2x00_zio_store);
636static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
637 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800638static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
639 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700640
641struct class_device_attribute *qla2x00_host_attrs[] = {
642 &class_device_attr_driver_version,
643 &class_device_attr_fw_version,
644 &class_device_attr_serial_num,
645 &class_device_attr_isp_name,
646 &class_device_attr_isp_id,
647 &class_device_attr_model_name,
648 &class_device_attr_model_desc,
649 &class_device_attr_pci_info,
650 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700651 &class_device_attr_zio,
652 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800653 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700654 NULL,
655};
656
8482e112005-04-17 15:04:54 -0500657/* Host attributes. */
658
659static void
660qla2x00_get_host_port_id(struct Scsi_Host *shost)
661{
662 scsi_qla_host_t *ha = to_qla_host(shost);
663
664 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
665 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
666}
667
668static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800669qla2x00_get_host_speed(struct Scsi_Host *shost)
670{
671 scsi_qla_host_t *ha = to_qla_host(shost);
672 uint32_t speed = 0;
673
674 switch (ha->link_data_rate) {
675 case LDR_1GB:
676 speed = 1;
677 break;
678 case LDR_2GB:
679 speed = 2;
680 break;
681 case LDR_4GB:
682 speed = 4;
683 break;
684 }
685 fc_host_speed(shost) = speed;
686}
687
688static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800689qla2x00_get_host_port_type(struct Scsi_Host *shost)
690{
691 scsi_qla_host_t *ha = to_qla_host(shost);
692 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
693
694 switch (ha->current_topology) {
695 case ISP_CFG_NL:
696 port_type = FC_PORTTYPE_LPORT;
697 break;
698 case ISP_CFG_FL:
699 port_type = FC_PORTTYPE_NLPORT;
700 break;
701 case ISP_CFG_N:
702 port_type = FC_PORTTYPE_PTP;
703 break;
704 case ISP_CFG_F:
705 port_type = FC_PORTTYPE_NPORT;
706 break;
707 }
708 fc_host_port_type(shost) = port_type;
709}
710
711static void
8482e112005-04-17 15:04:54 -0500712qla2x00_get_starget_node_name(struct scsi_target *starget)
713{
714 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
715 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500716 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700717 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500718
bdf79622005-04-17 15:06:53 -0500719 list_for_each_entry(fcport, &ha->fcports, list) {
720 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700721 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500722 break;
723 }
724 }
725
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700726 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500727}
728
729static void
730qla2x00_get_starget_port_name(struct scsi_target *starget)
731{
732 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
733 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500734 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700735 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500736
bdf79622005-04-17 15:06:53 -0500737 list_for_each_entry(fcport, &ha->fcports, list) {
738 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700739 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500740 break;
741 }
742 }
743
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700744 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500745}
746
747static void
748qla2x00_get_starget_port_id(struct scsi_target *starget)
749{
750 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
751 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500752 fc_port_t *fcport;
753 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500754
bdf79622005-04-17 15:06:53 -0500755 list_for_each_entry(fcport, &ha->fcports, list) {
756 if (starget->id == fcport->os_target_id) {
757 port_id = fcport->d_id.b.domain << 16 |
758 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
759 break;
760 }
761 }
762
8482e112005-04-17 15:04:54 -0500763 fc_starget_port_id(starget) = port_id;
764}
765
766static void
767qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
768{
bdf79622005-04-17 15:06:53 -0500769 struct Scsi_Host *host = rport_to_shost(rport);
770 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500771
772 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
773}
774
775static void
776qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
777{
bdf79622005-04-17 15:06:53 -0500778 struct Scsi_Host *host = rport_to_shost(rport);
779 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500780
781 if (timeout)
782 ha->port_down_retry_count = timeout;
783 else
784 ha->port_down_retry_count = 1;
785
786 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
787}
788
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700789static int
790qla2x00_issue_lip(struct Scsi_Host *shost)
791{
792 scsi_qla_host_t *ha = to_qla_host(shost);
793
794 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
795 return 0;
796}
797
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800798static struct fc_host_statistics *
799qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
800{
801 scsi_qla_host_t *ha = to_qla_host(shost);
802 int rval;
803 uint16_t mb_stat[1];
804 link_stat_t stat_buf;
805 struct fc_host_statistics *pfc_host_stat;
806
807 pfc_host_stat = &ha->fc_host_stat;
808 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
809
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800810 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800811 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
812 sizeof(stat_buf) / 4, mb_stat);
813 } else {
814 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
815 mb_stat);
816 }
817 if (rval != 0) {
818 qla_printk(KERN_WARNING, ha,
819 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
820 return pfc_host_stat;
821 }
822
823 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
824 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
825 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
826 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
827 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
828 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
829
830 return pfc_host_stat;
831}
832
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400833struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -0500834
835 .show_host_node_name = 1,
836 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700837 .show_host_supported_classes = 1,
838
8482e112005-04-17 15:04:54 -0500839 .get_host_port_id = qla2x00_get_host_port_id,
840 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800841 .get_host_speed = qla2x00_get_host_speed,
842 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800843 .get_host_port_type = qla2x00_get_host_port_type,
844 .show_host_port_type = 1,
8482e112005-04-17 15:04:54 -0500845
bdf79622005-04-17 15:06:53 -0500846 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700847 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -0500848
849 .get_starget_node_name = qla2x00_get_starget_node_name,
850 .show_starget_node_name = 1,
851 .get_starget_port_name = qla2x00_get_starget_port_name,
852 .show_starget_port_name = 1,
853 .get_starget_port_id = qla2x00_get_starget_port_id,
854 .show_starget_port_id = 1,
855
856 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
857 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
858 .show_rport_dev_loss_tmo = 1,
859
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700860 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800861 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -0500862};
863
8482e112005-04-17 15:04:54 -0500864void
865qla2x00_init_host_attr(scsi_qla_host_t *ha)
866{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800867 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
868 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700869 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e112005-04-17 15:04:54 -0500870}