blob: 73d10b35091ee2db51a28fe3604fcc89c56b06ae [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
182void
183qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
184{
185 struct Scsi_Host *host = ha->host;
186
187 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
188 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
189}
190
191void
192qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
193{
194 struct Scsi_Host *host = ha->host;
195
196 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
197 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800198
199 if (ha->beacon_blink_led == 1)
200 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500201}
202
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700203/* Scsi_Host attributes. */
204
205static ssize_t
206qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
207{
208 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
209}
210
211static ssize_t
212qla2x00_fw_version_show(struct class_device *cdev, char *buf)
213{
214 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
215 char fw_str[30];
216
217 return snprintf(buf, PAGE_SIZE, "%s\n",
218 ha->isp_ops.fw_version_str(ha, fw_str));
219}
220
221static ssize_t
222qla2x00_serial_num_show(struct class_device *cdev, char *buf)
223{
224 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
225 uint32_t sn;
226
227 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
228 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
229 sn % 100000);
230}
231
232static ssize_t
233qla2x00_isp_name_show(struct class_device *cdev, char *buf)
234{
235 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800236 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700237}
238
239static ssize_t
240qla2x00_isp_id_show(struct class_device *cdev, char *buf)
241{
242 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
243 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
244 ha->product_id[0], ha->product_id[1], ha->product_id[2],
245 ha->product_id[3]);
246}
247
248static ssize_t
249qla2x00_model_name_show(struct class_device *cdev, char *buf)
250{
251 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
252 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
253}
254
255static ssize_t
256qla2x00_model_desc_show(struct class_device *cdev, char *buf)
257{
258 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
259 return snprintf(buf, PAGE_SIZE, "%s\n",
260 ha->model_desc ? ha->model_desc: "");
261}
262
263static ssize_t
264qla2x00_pci_info_show(struct class_device *cdev, char *buf)
265{
266 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
267 char pci_info[30];
268
269 return snprintf(buf, PAGE_SIZE, "%s\n",
270 ha->isp_ops.pci_info_str(ha, pci_info));
271}
272
273static ssize_t
274qla2x00_state_show(struct class_device *cdev, char *buf)
275{
276 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
277 int len = 0;
278
279 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
280 atomic_read(&ha->loop_state) == LOOP_DEAD)
281 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
282 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
283 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
284 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
285 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
286 else {
287 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
288
289 switch (ha->current_topology) {
290 case ISP_CFG_NL:
291 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
292 break;
293 case ISP_CFG_FL:
294 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
295 break;
296 case ISP_CFG_N:
297 len += snprintf(buf + len, PAGE_SIZE-len,
298 "N_Port to N_Port\n");
299 break;
300 case ISP_CFG_F:
301 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
302 break;
303 default:
304 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
305 break;
306 }
307 }
308 return len;
309}
310
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700311static ssize_t
312qla2x00_zio_show(struct class_device *cdev, char *buf)
313{
314 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
315 int len = 0;
316
317 switch (ha->zio_mode) {
318 case QLA_ZIO_MODE_5:
319 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
320 break;
321 case QLA_ZIO_MODE_6:
322 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
323 break;
324 case QLA_ZIO_DISABLED:
325 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
326 break;
327 }
328 return len;
329}
330
331static ssize_t
332qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
333{
334 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
335 int val = 0;
336 uint16_t zio_mode;
337
338 if (sscanf(buf, "%d", &val) != 1)
339 return -EINVAL;
340
341 switch (val) {
342 case 1:
343 zio_mode = QLA_ZIO_MODE_5;
344 break;
345 case 2:
346 zio_mode = QLA_ZIO_MODE_6;
347 break;
348 default:
349 zio_mode = QLA_ZIO_DISABLED;
350 break;
351 }
352
353 /* Update per-hba values and queue a reset. */
354 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
355 ha->zio_mode = zio_mode;
356 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
357 }
358 return strlen(buf);
359}
360
361static ssize_t
362qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
363{
364 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
365
366 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
367}
368
369static ssize_t
370qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
371 size_t count)
372{
373 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
374 int val = 0;
375 uint16_t zio_timer;
376
377 if (sscanf(buf, "%d", &val) != 1)
378 return -EINVAL;
379 if (val > 25500 || val < 100)
380 return -ERANGE;
381
382 zio_timer = (uint16_t)(val / 100);
383 ha->zio_timer = zio_timer;
384
385 return strlen(buf);
386}
387
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800388static ssize_t
389qla2x00_beacon_show(struct class_device *cdev, char *buf)
390{
391 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
392 int len = 0;
393
394 if (ha->beacon_blink_led)
395 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
396 else
397 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
398 return len;
399}
400
401static ssize_t
402qla2x00_beacon_store(struct class_device *cdev, const char *buf,
403 size_t count)
404{
405 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
406 int val = 0;
407 int rval;
408
409 if (IS_QLA2100(ha) || IS_QLA2200(ha))
410 return -EPERM;
411
412 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
413 qla_printk(KERN_WARNING, ha,
414 "Abort ISP active -- ignoring beacon request.\n");
415 return -EBUSY;
416 }
417
418 if (sscanf(buf, "%d", &val) != 1)
419 return -EINVAL;
420
421 if (val)
422 rval = ha->isp_ops.beacon_on(ha);
423 else
424 rval = ha->isp_ops.beacon_off(ha);
425
426 if (rval != QLA_SUCCESS)
427 count = 0;
428
429 return count;
430}
431
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700432static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
433 NULL);
434static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
435static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
436static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
437static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
438static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
439static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
440static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
441static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700442static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
443 qla2x00_zio_store);
444static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
445 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800446static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
447 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700448
449struct class_device_attribute *qla2x00_host_attrs[] = {
450 &class_device_attr_driver_version,
451 &class_device_attr_fw_version,
452 &class_device_attr_serial_num,
453 &class_device_attr_isp_name,
454 &class_device_attr_isp_id,
455 &class_device_attr_model_name,
456 &class_device_attr_model_desc,
457 &class_device_attr_pci_info,
458 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700459 &class_device_attr_zio,
460 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800461 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700462 NULL,
463};
464
8482e112005-04-17 15:04:54 -0500465/* Host attributes. */
466
467static void
468qla2x00_get_host_port_id(struct Scsi_Host *shost)
469{
470 scsi_qla_host_t *ha = to_qla_host(shost);
471
472 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
473 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
474}
475
476static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800477qla2x00_get_host_speed(struct Scsi_Host *shost)
478{
479 scsi_qla_host_t *ha = to_qla_host(shost);
480 uint32_t speed = 0;
481
482 switch (ha->link_data_rate) {
483 case LDR_1GB:
484 speed = 1;
485 break;
486 case LDR_2GB:
487 speed = 2;
488 break;
489 case LDR_4GB:
490 speed = 4;
491 break;
492 }
493 fc_host_speed(shost) = speed;
494}
495
496static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800497qla2x00_get_host_port_type(struct Scsi_Host *shost)
498{
499 scsi_qla_host_t *ha = to_qla_host(shost);
500 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
501
502 switch (ha->current_topology) {
503 case ISP_CFG_NL:
504 port_type = FC_PORTTYPE_LPORT;
505 break;
506 case ISP_CFG_FL:
507 port_type = FC_PORTTYPE_NLPORT;
508 break;
509 case ISP_CFG_N:
510 port_type = FC_PORTTYPE_PTP;
511 break;
512 case ISP_CFG_F:
513 port_type = FC_PORTTYPE_NPORT;
514 break;
515 }
516 fc_host_port_type(shost) = port_type;
517}
518
519static void
8482e112005-04-17 15:04:54 -0500520qla2x00_get_starget_node_name(struct scsi_target *starget)
521{
522 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
523 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500524 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700525 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500526
bdf79622005-04-17 15:06:53 -0500527 list_for_each_entry(fcport, &ha->fcports, list) {
528 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700529 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500530 break;
531 }
532 }
533
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700534 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500535}
536
537static void
538qla2x00_get_starget_port_name(struct scsi_target *starget)
539{
540 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
541 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500542 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700543 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500544
bdf79622005-04-17 15:06:53 -0500545 list_for_each_entry(fcport, &ha->fcports, list) {
546 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700547 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500548 break;
549 }
550 }
551
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700552 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500553}
554
555static void
556qla2x00_get_starget_port_id(struct scsi_target *starget)
557{
558 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
559 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500560 fc_port_t *fcport;
561 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500562
bdf79622005-04-17 15:06:53 -0500563 list_for_each_entry(fcport, &ha->fcports, list) {
564 if (starget->id == fcport->os_target_id) {
565 port_id = fcport->d_id.b.domain << 16 |
566 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
567 break;
568 }
569 }
570
8482e112005-04-17 15:04:54 -0500571 fc_starget_port_id(starget) = port_id;
572}
573
574static void
575qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
576{
bdf79622005-04-17 15:06:53 -0500577 struct Scsi_Host *host = rport_to_shost(rport);
578 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500579
580 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
581}
582
583static void
584qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
585{
bdf79622005-04-17 15:06:53 -0500586 struct Scsi_Host *host = rport_to_shost(rport);
587 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500588
589 if (timeout)
590 ha->port_down_retry_count = timeout;
591 else
592 ha->port_down_retry_count = 1;
593
594 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
595}
596
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700597static int
598qla2x00_issue_lip(struct Scsi_Host *shost)
599{
600 scsi_qla_host_t *ha = to_qla_host(shost);
601
602 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
603 return 0;
604}
605
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800606static struct fc_host_statistics *
607qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
608{
609 scsi_qla_host_t *ha = to_qla_host(shost);
610 int rval;
611 uint16_t mb_stat[1];
612 link_stat_t stat_buf;
613 struct fc_host_statistics *pfc_host_stat;
614
615 pfc_host_stat = &ha->fc_host_stat;
616 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
617
618 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
619 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
620 sizeof(stat_buf) / 4, mb_stat);
621 } else {
622 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
623 mb_stat);
624 }
625 if (rval != 0) {
626 qla_printk(KERN_WARNING, ha,
627 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
628 return pfc_host_stat;
629 }
630
631 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
632 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
633 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
634 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
635 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
636 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
637
638 return pfc_host_stat;
639}
640
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400641struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -0500642
643 .show_host_node_name = 1,
644 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700645 .show_host_supported_classes = 1,
646
8482e112005-04-17 15:04:54 -0500647 .get_host_port_id = qla2x00_get_host_port_id,
648 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800649 .get_host_speed = qla2x00_get_host_speed,
650 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800651 .get_host_port_type = qla2x00_get_host_port_type,
652 .show_host_port_type = 1,
8482e112005-04-17 15:04:54 -0500653
bdf79622005-04-17 15:06:53 -0500654 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700655 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -0500656
657 .get_starget_node_name = qla2x00_get_starget_node_name,
658 .show_starget_node_name = 1,
659 .get_starget_port_name = qla2x00_get_starget_port_name,
660 .show_starget_port_name = 1,
661 .get_starget_port_id = qla2x00_get_starget_port_id,
662 .show_starget_port_id = 1,
663
664 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
665 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
666 .show_rport_dev_loss_tmo = 1,
667
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700668 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800669 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -0500670};
671
8482e112005-04-17 15:04:54 -0500672void
673qla2x00_init_host_attr(scsi_qla_host_t *ha)
674{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800675 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
676 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700677 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e112005-04-17 15:04:54 -0500678}