blob: 92b3e13e9061d8b00d869d5c1ac07afcf30ff50d [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 Vasquezfca29702005-07-06 10:31:47 -070053 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
54 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 Vasquezfca29702005-07-06 10:31:47 -070067 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
68 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 Vasquez459c5372005-07-06 10:31:07 -0700141 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
142 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
8482e112005-04-17 15:04:54 -0500311void
312qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
313{
314 struct Scsi_Host *host = ha->host;
315
316 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
317 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800318 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
319 sysfs_create_bin_file(&host->shost_gendev.kobj,
320 &sysfs_optrom_ctl_attr);
8482e112005-04-17 15:04:54 -0500321}
322
323void
324qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
325{
326 struct Scsi_Host *host = ha->host;
327
328 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
329 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800330 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
331 sysfs_remove_bin_file(&host->shost_gendev.kobj,
332 &sysfs_optrom_ctl_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800333
334 if (ha->beacon_blink_led == 1)
335 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500336}
337
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700338/* Scsi_Host attributes. */
339
340static ssize_t
341qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
342{
343 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
344}
345
346static ssize_t
347qla2x00_fw_version_show(struct class_device *cdev, char *buf)
348{
349 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
350 char fw_str[30];
351
352 return snprintf(buf, PAGE_SIZE, "%s\n",
353 ha->isp_ops.fw_version_str(ha, fw_str));
354}
355
356static ssize_t
357qla2x00_serial_num_show(struct class_device *cdev, char *buf)
358{
359 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
360 uint32_t sn;
361
362 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
363 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
364 sn % 100000);
365}
366
367static ssize_t
368qla2x00_isp_name_show(struct class_device *cdev, char *buf)
369{
370 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800371 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700372}
373
374static ssize_t
375qla2x00_isp_id_show(struct class_device *cdev, char *buf)
376{
377 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
378 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
379 ha->product_id[0], ha->product_id[1], ha->product_id[2],
380 ha->product_id[3]);
381}
382
383static ssize_t
384qla2x00_model_name_show(struct class_device *cdev, char *buf)
385{
386 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
387 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
388}
389
390static ssize_t
391qla2x00_model_desc_show(struct class_device *cdev, char *buf)
392{
393 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
394 return snprintf(buf, PAGE_SIZE, "%s\n",
395 ha->model_desc ? ha->model_desc: "");
396}
397
398static ssize_t
399qla2x00_pci_info_show(struct class_device *cdev, char *buf)
400{
401 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
402 char pci_info[30];
403
404 return snprintf(buf, PAGE_SIZE, "%s\n",
405 ha->isp_ops.pci_info_str(ha, pci_info));
406}
407
408static ssize_t
409qla2x00_state_show(struct class_device *cdev, char *buf)
410{
411 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
412 int len = 0;
413
414 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
415 atomic_read(&ha->loop_state) == LOOP_DEAD)
416 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
417 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
418 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
419 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
420 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
421 else {
422 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
423
424 switch (ha->current_topology) {
425 case ISP_CFG_NL:
426 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
427 break;
428 case ISP_CFG_FL:
429 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
430 break;
431 case ISP_CFG_N:
432 len += snprintf(buf + len, PAGE_SIZE-len,
433 "N_Port to N_Port\n");
434 break;
435 case ISP_CFG_F:
436 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
437 break;
438 default:
439 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
440 break;
441 }
442 }
443 return len;
444}
445
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700446static ssize_t
447qla2x00_zio_show(struct class_device *cdev, char *buf)
448{
449 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
450 int len = 0;
451
452 switch (ha->zio_mode) {
453 case QLA_ZIO_MODE_5:
454 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
455 break;
456 case QLA_ZIO_MODE_6:
457 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
458 break;
459 case QLA_ZIO_DISABLED:
460 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
461 break;
462 }
463 return len;
464}
465
466static ssize_t
467qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
468{
469 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
470 int val = 0;
471 uint16_t zio_mode;
472
473 if (sscanf(buf, "%d", &val) != 1)
474 return -EINVAL;
475
476 switch (val) {
477 case 1:
478 zio_mode = QLA_ZIO_MODE_5;
479 break;
480 case 2:
481 zio_mode = QLA_ZIO_MODE_6;
482 break;
483 default:
484 zio_mode = QLA_ZIO_DISABLED;
485 break;
486 }
487
488 /* Update per-hba values and queue a reset. */
489 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
490 ha->zio_mode = zio_mode;
491 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
492 }
493 return strlen(buf);
494}
495
496static ssize_t
497qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
498{
499 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
500
501 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
502}
503
504static ssize_t
505qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
506 size_t count)
507{
508 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
509 int val = 0;
510 uint16_t zio_timer;
511
512 if (sscanf(buf, "%d", &val) != 1)
513 return -EINVAL;
514 if (val > 25500 || val < 100)
515 return -ERANGE;
516
517 zio_timer = (uint16_t)(val / 100);
518 ha->zio_timer = zio_timer;
519
520 return strlen(buf);
521}
522
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800523static ssize_t
524qla2x00_beacon_show(struct class_device *cdev, char *buf)
525{
526 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
527 int len = 0;
528
529 if (ha->beacon_blink_led)
530 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
531 else
532 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
533 return len;
534}
535
536static ssize_t
537qla2x00_beacon_store(struct class_device *cdev, const char *buf,
538 size_t count)
539{
540 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
541 int val = 0;
542 int rval;
543
544 if (IS_QLA2100(ha) || IS_QLA2200(ha))
545 return -EPERM;
546
547 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
548 qla_printk(KERN_WARNING, ha,
549 "Abort ISP active -- ignoring beacon request.\n");
550 return -EBUSY;
551 }
552
553 if (sscanf(buf, "%d", &val) != 1)
554 return -EINVAL;
555
556 if (val)
557 rval = ha->isp_ops.beacon_on(ha);
558 else
559 rval = ha->isp_ops.beacon_off(ha);
560
561 if (rval != QLA_SUCCESS)
562 count = 0;
563
564 return count;
565}
566
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700567static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
568 NULL);
569static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
570static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
571static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
572static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
573static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
574static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
575static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
576static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700577static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
578 qla2x00_zio_store);
579static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
580 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800581static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
582 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700583
584struct class_device_attribute *qla2x00_host_attrs[] = {
585 &class_device_attr_driver_version,
586 &class_device_attr_fw_version,
587 &class_device_attr_serial_num,
588 &class_device_attr_isp_name,
589 &class_device_attr_isp_id,
590 &class_device_attr_model_name,
591 &class_device_attr_model_desc,
592 &class_device_attr_pci_info,
593 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700594 &class_device_attr_zio,
595 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800596 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700597 NULL,
598};
599
8482e112005-04-17 15:04:54 -0500600/* Host attributes. */
601
602static void
603qla2x00_get_host_port_id(struct Scsi_Host *shost)
604{
605 scsi_qla_host_t *ha = to_qla_host(shost);
606
607 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
608 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
609}
610
611static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800612qla2x00_get_host_speed(struct Scsi_Host *shost)
613{
614 scsi_qla_host_t *ha = to_qla_host(shost);
615 uint32_t speed = 0;
616
617 switch (ha->link_data_rate) {
618 case LDR_1GB:
619 speed = 1;
620 break;
621 case LDR_2GB:
622 speed = 2;
623 break;
624 case LDR_4GB:
625 speed = 4;
626 break;
627 }
628 fc_host_speed(shost) = speed;
629}
630
631static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800632qla2x00_get_host_port_type(struct Scsi_Host *shost)
633{
634 scsi_qla_host_t *ha = to_qla_host(shost);
635 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
636
637 switch (ha->current_topology) {
638 case ISP_CFG_NL:
639 port_type = FC_PORTTYPE_LPORT;
640 break;
641 case ISP_CFG_FL:
642 port_type = FC_PORTTYPE_NLPORT;
643 break;
644 case ISP_CFG_N:
645 port_type = FC_PORTTYPE_PTP;
646 break;
647 case ISP_CFG_F:
648 port_type = FC_PORTTYPE_NPORT;
649 break;
650 }
651 fc_host_port_type(shost) = port_type;
652}
653
654static void
8482e112005-04-17 15:04:54 -0500655qla2x00_get_starget_node_name(struct scsi_target *starget)
656{
657 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
658 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500659 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700660 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500661
bdf79622005-04-17 15:06:53 -0500662 list_for_each_entry(fcport, &ha->fcports, list) {
663 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700664 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500665 break;
666 }
667 }
668
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700669 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500670}
671
672static void
673qla2x00_get_starget_port_name(struct scsi_target *starget)
674{
675 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
676 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500677 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700678 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500679
bdf79622005-04-17 15:06:53 -0500680 list_for_each_entry(fcport, &ha->fcports, list) {
681 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700682 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500683 break;
684 }
685 }
686
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700687 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500688}
689
690static void
691qla2x00_get_starget_port_id(struct scsi_target *starget)
692{
693 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
694 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500695 fc_port_t *fcport;
696 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500697
bdf79622005-04-17 15:06:53 -0500698 list_for_each_entry(fcport, &ha->fcports, list) {
699 if (starget->id == fcport->os_target_id) {
700 port_id = fcport->d_id.b.domain << 16 |
701 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
702 break;
703 }
704 }
705
8482e112005-04-17 15:04:54 -0500706 fc_starget_port_id(starget) = port_id;
707}
708
709static void
710qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
711{
bdf79622005-04-17 15:06:53 -0500712 struct Scsi_Host *host = rport_to_shost(rport);
713 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500714
715 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
716}
717
718static void
719qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
720{
bdf79622005-04-17 15:06:53 -0500721 struct Scsi_Host *host = rport_to_shost(rport);
722 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500723
724 if (timeout)
725 ha->port_down_retry_count = timeout;
726 else
727 ha->port_down_retry_count = 1;
728
729 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
730}
731
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700732static int
733qla2x00_issue_lip(struct Scsi_Host *shost)
734{
735 scsi_qla_host_t *ha = to_qla_host(shost);
736
737 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
738 return 0;
739}
740
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800741static struct fc_host_statistics *
742qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
743{
744 scsi_qla_host_t *ha = to_qla_host(shost);
745 int rval;
746 uint16_t mb_stat[1];
747 link_stat_t stat_buf;
748 struct fc_host_statistics *pfc_host_stat;
749
750 pfc_host_stat = &ha->fc_host_stat;
751 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
752
753 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
754 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
755 sizeof(stat_buf) / 4, mb_stat);
756 } else {
757 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
758 mb_stat);
759 }
760 if (rval != 0) {
761 qla_printk(KERN_WARNING, ha,
762 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
763 return pfc_host_stat;
764 }
765
766 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
767 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
768 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
769 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
770 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
771 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
772
773 return pfc_host_stat;
774}
775
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400776struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -0500777
778 .show_host_node_name = 1,
779 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700780 .show_host_supported_classes = 1,
781
8482e112005-04-17 15:04:54 -0500782 .get_host_port_id = qla2x00_get_host_port_id,
783 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800784 .get_host_speed = qla2x00_get_host_speed,
785 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800786 .get_host_port_type = qla2x00_get_host_port_type,
787 .show_host_port_type = 1,
8482e112005-04-17 15:04:54 -0500788
bdf79622005-04-17 15:06:53 -0500789 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700790 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -0500791
792 .get_starget_node_name = qla2x00_get_starget_node_name,
793 .show_starget_node_name = 1,
794 .get_starget_port_name = qla2x00_get_starget_port_name,
795 .show_starget_port_name = 1,
796 .get_starget_port_id = qla2x00_get_starget_port_id,
797 .show_starget_port_id = 1,
798
799 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
800 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
801 .show_rport_dev_loss_tmo = 1,
802
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700803 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800804 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -0500805};
806
8482e112005-04-17 15:04:54 -0500807void
808qla2x00_init_host_attr(scsi_qla_host_t *ha)
809{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800810 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
811 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700812 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e112005-04-17 15:04:54 -0500813}