blob: 78eec6799343330b90a2b24a8379d90a647775e3 [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)));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070019 char *rbuf = (char *)ha->fw_dump;
8482e112005-04-17 15:04:54 -050020
21 if (ha->fw_dump_reading == 0)
22 return 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070023 if (off > ha->fw_dump_len)
24 return 0;
25 if (off + count > ha->fw_dump_len)
26 count = ha->fw_dump_len - off;
8482e112005-04-17 15:04:54 -050027
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070028 memcpy(buf, &rbuf[off], count);
8482e112005-04-17 15:04:54 -050029
30 return (count);
31}
32
33static ssize_t
34qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
35 size_t count)
36{
37 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
38 struct device, kobj)));
39 int reading;
8482e112005-04-17 15:04:54 -050040
41 if (off != 0)
42 return (0);
43
44 reading = simple_strtol(buf, NULL, 10);
45 switch (reading) {
46 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070047 if (!ha->fw_dump_reading)
48 break;
8482e112005-04-17 15:04:54 -050049
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070050 qla_printk(KERN_INFO, ha,
51 "Firmware dump cleared on (%ld).\n", ha->host_no);
52
53 ha->fw_dump_reading = 0;
54 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050055 break;
56 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070057 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050058 ha->fw_dump_reading = 1;
59
8482e112005-04-17 15:04:54 -050060 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070061 "Raw firmware dump ready for read on (%ld).\n",
8482e112005-04-17 15:04:54 -050062 ha->host_no);
8482e112005-04-17 15:04:54 -050063 }
64 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070065 case 2:
66 qla2x00_alloc_fw_dump(ha);
67 break;
8482e112005-04-17 15:04:54 -050068 }
69 return (count);
70}
71
72static struct bin_attribute sysfs_fw_dump_attr = {
73 .attr = {
74 .name = "fw_dump",
75 .mode = S_IRUSR | S_IWUSR,
76 .owner = THIS_MODULE,
77 },
78 .size = 0,
79 .read = qla2x00_sysfs_read_fw_dump,
80 .write = qla2x00_sysfs_write_fw_dump,
81};
82
83static ssize_t
84qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
85 size_t count)
86{
87 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
88 struct device, kobj)));
8482e112005-04-17 15:04:54 -050089 unsigned long flags;
8482e112005-04-17 15:04:54 -050090
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -080091 if (!capable(CAP_SYS_ADMIN) || off != 0)
8482e112005-04-17 15:04:54 -050092 return 0;
93
94 /* Read NVRAM. */
95 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -070096 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
97 ha->nvram_size);
8482e112005-04-17 15:04:54 -050098 spin_unlock_irqrestore(&ha->hardware_lock, flags);
99
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800100 return ha->nvram_size;
8482e112005-04-17 15:04:54 -0500101}
102
103static ssize_t
104qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
105 size_t count)
106{
107 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
108 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500109 unsigned long flags;
110 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500111
Andrew Vasquez459c5372005-07-06 10:31:07 -0700112 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500113 return 0;
114
115 /* Checksum NVRAM. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800116 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700117 uint32_t *iter;
118 uint32_t chksum;
119
120 iter = (uint32_t *)buf;
121 chksum = 0;
122 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
123 chksum += le32_to_cpu(*iter++);
124 chksum = ~chksum + 1;
125 *iter = cpu_to_le32(chksum);
126 } else {
127 uint8_t *iter;
128 uint8_t chksum;
129
130 iter = (uint8_t *)buf;
131 chksum = 0;
132 for (cnt = 0; cnt < count - 1; cnt++)
133 chksum += *iter++;
134 chksum = ~chksum + 1;
135 *iter = chksum;
136 }
8482e112005-04-17 15:04:54 -0500137
138 /* Write NVRAM. */
139 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700140 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
8482e112005-04-17 15:04:54 -0500141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142
143 return (count);
144}
145
146static struct bin_attribute sysfs_nvram_attr = {
147 .attr = {
148 .name = "nvram",
149 .mode = S_IRUSR | S_IWUSR,
150 .owner = THIS_MODULE,
151 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800152 .size = 512,
8482e112005-04-17 15:04:54 -0500153 .read = qla2x00_sysfs_read_nvram,
154 .write = qla2x00_sysfs_write_nvram,
155};
156
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800157static ssize_t
158qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
159 size_t count)
160{
161 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
162 struct device, kobj)));
163
164 if (ha->optrom_state != QLA_SREADING)
165 return 0;
166 if (off > ha->optrom_size)
167 return 0;
168 if (off + count > ha->optrom_size)
169 count = ha->optrom_size - off;
170
171 memcpy(buf, &ha->optrom_buffer[off], count);
172
173 return count;
174}
175
176static ssize_t
177qla2x00_sysfs_write_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_SWRITING)
184 return -EINVAL;
185 if (off > ha->optrom_size)
186 return -ERANGE;
187 if (off + count > ha->optrom_size)
188 count = ha->optrom_size - off;
189
190 memcpy(&ha->optrom_buffer[off], buf, count);
191
192 return count;
193}
194
195static struct bin_attribute sysfs_optrom_attr = {
196 .attr = {
197 .name = "optrom",
198 .mode = S_IRUSR | S_IWUSR,
199 .owner = THIS_MODULE,
200 },
201 .size = OPTROM_SIZE_24XX,
202 .read = qla2x00_sysfs_read_optrom,
203 .write = qla2x00_sysfs_write_optrom,
204};
205
206static ssize_t
207qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
208 size_t count)
209{
210 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
211 struct device, kobj)));
212 int val;
213
214 if (off)
215 return 0;
216
217 if (sscanf(buf, "%d", &val) != 1)
218 return -EINVAL;
219
220 switch (val) {
221 case 0:
222 if (ha->optrom_state != QLA_SREADING &&
223 ha->optrom_state != QLA_SWRITING)
224 break;
225
226 ha->optrom_state = QLA_SWAITING;
227 vfree(ha->optrom_buffer);
228 ha->optrom_buffer = NULL;
229 break;
230 case 1:
231 if (ha->optrom_state != QLA_SWAITING)
232 break;
233
234 ha->optrom_state = QLA_SREADING;
235 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
236 if (ha->optrom_buffer == NULL) {
237 qla_printk(KERN_WARNING, ha,
238 "Unable to allocate memory for optrom retrieval "
239 "(%x).\n", ha->optrom_size);
240
241 ha->optrom_state = QLA_SWAITING;
242 return count;
243 }
244
245 memset(ha->optrom_buffer, 0, ha->optrom_size);
246 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
247 ha->optrom_size);
248 break;
249 case 2:
250 if (ha->optrom_state != QLA_SWAITING)
251 break;
252
253 ha->optrom_state = QLA_SWRITING;
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 update "
258 "(%x).\n", ha->optrom_size);
259
260 ha->optrom_state = QLA_SWAITING;
261 return count;
262 }
263 memset(ha->optrom_buffer, 0, ha->optrom_size);
264 break;
265 case 3:
266 if (ha->optrom_state != QLA_SWRITING)
267 break;
268
269 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
270 ha->optrom_size);
271 break;
272 }
273 return count;
274}
275
276static struct bin_attribute sysfs_optrom_ctl_attr = {
277 .attr = {
278 .name = "optrom_ctl",
279 .mode = S_IWUSR,
280 .owner = THIS_MODULE,
281 },
282 .size = 0,
283 .write = qla2x00_sysfs_write_optrom_ctl,
284};
285
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800286static ssize_t
287qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
288 size_t count)
289{
290 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
291 struct device, kobj)));
292 unsigned long flags;
293
294 if (!capable(CAP_SYS_ADMIN) || off != 0)
295 return 0;
296
297 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
298 return -ENOTSUPP;
299
300 /* Read NVRAM. */
301 spin_lock_irqsave(&ha->hardware_lock, flags);
302 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
303 spin_unlock_irqrestore(&ha->hardware_lock, flags);
304
305 return ha->vpd_size;
306}
307
308static ssize_t
309qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
310 size_t count)
311{
312 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
313 struct device, kobj)));
314 unsigned long flags;
315
316 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
317 return 0;
318
319 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
320 return -ENOTSUPP;
321
322 /* Write NVRAM. */
323 spin_lock_irqsave(&ha->hardware_lock, flags);
324 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
326
327 return count;
328}
329
330static struct bin_attribute sysfs_vpd_attr = {
331 .attr = {
332 .name = "vpd",
333 .mode = S_IRUSR | S_IWUSR,
334 .owner = THIS_MODULE,
335 },
336 .size = 0,
337 .read = qla2x00_sysfs_read_vpd,
338 .write = qla2x00_sysfs_write_vpd,
339};
340
8482e112005-04-17 15:04:54 -0500341void
342qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
343{
344 struct Scsi_Host *host = ha->host;
345
346 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
347 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800348 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
349 sysfs_create_bin_file(&host->shost_gendev.kobj,
350 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800351 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
8482e112005-04-17 15:04:54 -0500352}
353
354void
355qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
356{
357 struct Scsi_Host *host = ha->host;
358
359 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
360 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800361 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
362 sysfs_remove_bin_file(&host->shost_gendev.kobj,
363 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800364 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800365
366 if (ha->beacon_blink_led == 1)
367 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500368}
369
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700370/* Scsi_Host attributes. */
371
372static ssize_t
373qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
374{
375 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
376}
377
378static ssize_t
379qla2x00_fw_version_show(struct class_device *cdev, char *buf)
380{
381 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
382 char fw_str[30];
383
384 return snprintf(buf, PAGE_SIZE, "%s\n",
385 ha->isp_ops.fw_version_str(ha, fw_str));
386}
387
388static ssize_t
389qla2x00_serial_num_show(struct class_device *cdev, char *buf)
390{
391 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
392 uint32_t sn;
393
394 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
395 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
396 sn % 100000);
397}
398
399static ssize_t
400qla2x00_isp_name_show(struct class_device *cdev, char *buf)
401{
402 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800403 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700404}
405
406static ssize_t
407qla2x00_isp_id_show(struct class_device *cdev, char *buf)
408{
409 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
410 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
411 ha->product_id[0], ha->product_id[1], ha->product_id[2],
412 ha->product_id[3]);
413}
414
415static ssize_t
416qla2x00_model_name_show(struct class_device *cdev, char *buf)
417{
418 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
419 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
420}
421
422static ssize_t
423qla2x00_model_desc_show(struct class_device *cdev, char *buf)
424{
425 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
426 return snprintf(buf, PAGE_SIZE, "%s\n",
427 ha->model_desc ? ha->model_desc: "");
428}
429
430static ssize_t
431qla2x00_pci_info_show(struct class_device *cdev, char *buf)
432{
433 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
434 char pci_info[30];
435
436 return snprintf(buf, PAGE_SIZE, "%s\n",
437 ha->isp_ops.pci_info_str(ha, pci_info));
438}
439
440static ssize_t
441qla2x00_state_show(struct class_device *cdev, char *buf)
442{
443 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
444 int len = 0;
445
446 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
447 atomic_read(&ha->loop_state) == LOOP_DEAD)
448 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
449 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
450 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
451 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
452 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
453 else {
454 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
455
456 switch (ha->current_topology) {
457 case ISP_CFG_NL:
458 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
459 break;
460 case ISP_CFG_FL:
461 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
462 break;
463 case ISP_CFG_N:
464 len += snprintf(buf + len, PAGE_SIZE-len,
465 "N_Port to N_Port\n");
466 break;
467 case ISP_CFG_F:
468 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
469 break;
470 default:
471 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
472 break;
473 }
474 }
475 return len;
476}
477
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700478static ssize_t
479qla2x00_zio_show(struct class_device *cdev, char *buf)
480{
481 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
482 int len = 0;
483
484 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700485 case QLA_ZIO_MODE_6:
486 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
487 break;
488 case QLA_ZIO_DISABLED:
489 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
490 break;
491 }
492 return len;
493}
494
495static ssize_t
496qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
497{
498 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
499 int val = 0;
500 uint16_t zio_mode;
501
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800502 if (!IS_ZIO_SUPPORTED(ha))
503 return -ENOTSUPP;
504
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700505 if (sscanf(buf, "%d", &val) != 1)
506 return -EINVAL;
507
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800508 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700509 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800510 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700511 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700512
513 /* Update per-hba values and queue a reset. */
514 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
515 ha->zio_mode = zio_mode;
516 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
517 }
518 return strlen(buf);
519}
520
521static ssize_t
522qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
523{
524 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
525
526 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
527}
528
529static ssize_t
530qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
531 size_t count)
532{
533 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
534 int val = 0;
535 uint16_t zio_timer;
536
537 if (sscanf(buf, "%d", &val) != 1)
538 return -EINVAL;
539 if (val > 25500 || val < 100)
540 return -ERANGE;
541
542 zio_timer = (uint16_t)(val / 100);
543 ha->zio_timer = zio_timer;
544
545 return strlen(buf);
546}
547
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800548static ssize_t
549qla2x00_beacon_show(struct class_device *cdev, char *buf)
550{
551 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
552 int len = 0;
553
554 if (ha->beacon_blink_led)
555 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
556 else
557 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
558 return len;
559}
560
561static ssize_t
562qla2x00_beacon_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 int rval;
568
569 if (IS_QLA2100(ha) || IS_QLA2200(ha))
570 return -EPERM;
571
572 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
573 qla_printk(KERN_WARNING, ha,
574 "Abort ISP active -- ignoring beacon request.\n");
575 return -EBUSY;
576 }
577
578 if (sscanf(buf, "%d", &val) != 1)
579 return -EINVAL;
580
581 if (val)
582 rval = ha->isp_ops.beacon_on(ha);
583 else
584 rval = ha->isp_ops.beacon_off(ha);
585
586 if (rval != QLA_SUCCESS)
587 count = 0;
588
589 return count;
590}
591
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700592static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
593 NULL);
594static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
595static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
596static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
597static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
598static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
599static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
600static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
601static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700602static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
603 qla2x00_zio_store);
604static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
605 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800606static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
607 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700608
609struct class_device_attribute *qla2x00_host_attrs[] = {
610 &class_device_attr_driver_version,
611 &class_device_attr_fw_version,
612 &class_device_attr_serial_num,
613 &class_device_attr_isp_name,
614 &class_device_attr_isp_id,
615 &class_device_attr_model_name,
616 &class_device_attr_model_desc,
617 &class_device_attr_pci_info,
618 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700619 &class_device_attr_zio,
620 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800621 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700622 NULL,
623};
624
8482e112005-04-17 15:04:54 -0500625/* Host attributes. */
626
627static void
628qla2x00_get_host_port_id(struct Scsi_Host *shost)
629{
630 scsi_qla_host_t *ha = to_qla_host(shost);
631
632 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
633 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
634}
635
636static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800637qla2x00_get_host_speed(struct Scsi_Host *shost)
638{
639 scsi_qla_host_t *ha = to_qla_host(shost);
640 uint32_t speed = 0;
641
642 switch (ha->link_data_rate) {
643 case LDR_1GB:
644 speed = 1;
645 break;
646 case LDR_2GB:
647 speed = 2;
648 break;
649 case LDR_4GB:
650 speed = 4;
651 break;
652 }
653 fc_host_speed(shost) = speed;
654}
655
656static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800657qla2x00_get_host_port_type(struct Scsi_Host *shost)
658{
659 scsi_qla_host_t *ha = to_qla_host(shost);
660 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
661
662 switch (ha->current_topology) {
663 case ISP_CFG_NL:
664 port_type = FC_PORTTYPE_LPORT;
665 break;
666 case ISP_CFG_FL:
667 port_type = FC_PORTTYPE_NLPORT;
668 break;
669 case ISP_CFG_N:
670 port_type = FC_PORTTYPE_PTP;
671 break;
672 case ISP_CFG_F:
673 port_type = FC_PORTTYPE_NPORT;
674 break;
675 }
676 fc_host_port_type(shost) = port_type;
677}
678
679static void
8482e112005-04-17 15:04:54 -0500680qla2x00_get_starget_node_name(struct scsi_target *starget)
681{
682 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
683 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500684 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700685 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500686
bdf79622005-04-17 15:06:53 -0500687 list_for_each_entry(fcport, &ha->fcports, list) {
688 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700689 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500690 break;
691 }
692 }
693
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700694 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500695}
696
697static void
698qla2x00_get_starget_port_name(struct scsi_target *starget)
699{
700 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
701 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500702 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700703 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500704
bdf79622005-04-17 15:06:53 -0500705 list_for_each_entry(fcport, &ha->fcports, list) {
706 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700707 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500708 break;
709 }
710 }
711
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700712 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500713}
714
715static void
716qla2x00_get_starget_port_id(struct scsi_target *starget)
717{
718 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
719 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500720 fc_port_t *fcport;
721 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500722
bdf79622005-04-17 15:06:53 -0500723 list_for_each_entry(fcport, &ha->fcports, list) {
724 if (starget->id == fcport->os_target_id) {
725 port_id = fcport->d_id.b.domain << 16 |
726 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
727 break;
728 }
729 }
730
8482e112005-04-17 15:04:54 -0500731 fc_starget_port_id(starget) = port_id;
732}
733
734static void
735qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
736{
bdf79622005-04-17 15:06:53 -0500737 struct Scsi_Host *host = rport_to_shost(rport);
738 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500739
740 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
741}
742
743static void
744qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
745{
bdf79622005-04-17 15:06:53 -0500746 struct Scsi_Host *host = rport_to_shost(rport);
747 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500748
749 if (timeout)
750 ha->port_down_retry_count = timeout;
751 else
752 ha->port_down_retry_count = 1;
753
754 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
755}
756
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700757static int
758qla2x00_issue_lip(struct Scsi_Host *shost)
759{
760 scsi_qla_host_t *ha = to_qla_host(shost);
761
762 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
763 return 0;
764}
765
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800766static struct fc_host_statistics *
767qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
768{
769 scsi_qla_host_t *ha = to_qla_host(shost);
770 int rval;
771 uint16_t mb_stat[1];
772 link_stat_t stat_buf;
773 struct fc_host_statistics *pfc_host_stat;
774
775 pfc_host_stat = &ha->fc_host_stat;
776 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
777
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800778 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800779 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
780 sizeof(stat_buf) / 4, mb_stat);
781 } else {
782 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
783 mb_stat);
784 }
785 if (rval != 0) {
786 qla_printk(KERN_WARNING, ha,
787 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
788 return pfc_host_stat;
789 }
790
791 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
792 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
793 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
794 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
795 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
796 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
797
798 return pfc_host_stat;
799}
800
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400801struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -0500802
803 .show_host_node_name = 1,
804 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700805 .show_host_supported_classes = 1,
806
8482e112005-04-17 15:04:54 -0500807 .get_host_port_id = qla2x00_get_host_port_id,
808 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800809 .get_host_speed = qla2x00_get_host_speed,
810 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800811 .get_host_port_type = qla2x00_get_host_port_type,
812 .show_host_port_type = 1,
8482e112005-04-17 15:04:54 -0500813
bdf79622005-04-17 15:06:53 -0500814 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700815 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -0500816
817 .get_starget_node_name = qla2x00_get_starget_node_name,
818 .show_starget_node_name = 1,
819 .get_starget_port_name = qla2x00_get_starget_port_name,
820 .show_starget_port_name = 1,
821 .get_starget_port_id = qla2x00_get_starget_port_id,
822 .show_starget_port_id = 1,
823
824 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
825 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
826 .show_rport_dev_loss_tmo = 1,
827
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700828 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800829 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -0500830};
831
8482e112005-04-17 15:04:54 -0500832void
833qla2x00_init_host_attr(scsi_qla_host_t *ha)
834{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800835 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
836 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700837 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e112005-04-17 15:04:54 -0500838}