blob: 049e5cf1af7f30c6e107ffa1739f29624bf140c3 [file] [log] [blame]
8482e1182005-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
8482e1182005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e1182005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
7aaef272005-04-17 16:32:42 -05009#include <linux/vmalloc.h>
8482e1182005-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);
8482e1182005-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;
8482e1182005-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) {
8482e1182005-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 }
8482e1182005-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);
8482e1182005-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)));
8482e1182005-04-17 15:04:54 -0500114 unsigned long flags;
8482e1182005-04-17 15:04:54 -0500115
Andrew Vasquez459c5372005-07-06 10:31:07 -0700116 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e1182005-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);
8482e1182005-04-17 15:04:54 -0500123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
124
125 return (count);
126}
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)));
8482e1182005-04-17 15:04:54 -0500134 unsigned long flags;
135 uint16_t cnt;
8482e1182005-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)
8482e1182005-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 }
8482e1182005-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);
8482e1182005-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 Vasquez459c5372005-07-06 10:31:07 -0700177 .size = 0,
8482e1182005-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);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700188 sysfs_nvram_attr.size = ha->nvram_size;
8482e1182005-04-17 15:04:54 -0500189 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
190}
191
192void
193qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
194{
195 struct Scsi_Host *host = ha->host;
196
197 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
198 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800199
200 if (ha->beacon_blink_led == 1)
201 ha->isp_ops.beacon_off(ha);
8482e1182005-04-17 15:04:54 -0500202}
203
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700204/* Scsi_Host attributes. */
205
206static ssize_t
207qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
208{
209 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
210}
211
212static ssize_t
213qla2x00_fw_version_show(struct class_device *cdev, char *buf)
214{
215 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
216 char fw_str[30];
217
218 return snprintf(buf, PAGE_SIZE, "%s\n",
219 ha->isp_ops.fw_version_str(ha, fw_str));
220}
221
222static ssize_t
223qla2x00_serial_num_show(struct class_device *cdev, char *buf)
224{
225 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
226 uint32_t sn;
227
228 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
229 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
230 sn % 100000);
231}
232
233static ssize_t
234qla2x00_isp_name_show(struct class_device *cdev, char *buf)
235{
236 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800237 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700238}
239
240static ssize_t
241qla2x00_isp_id_show(struct class_device *cdev, char *buf)
242{
243 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
244 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
245 ha->product_id[0], ha->product_id[1], ha->product_id[2],
246 ha->product_id[3]);
247}
248
249static ssize_t
250qla2x00_model_name_show(struct class_device *cdev, char *buf)
251{
252 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
253 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
254}
255
256static ssize_t
257qla2x00_model_desc_show(struct class_device *cdev, char *buf)
258{
259 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
260 return snprintf(buf, PAGE_SIZE, "%s\n",
261 ha->model_desc ? ha->model_desc: "");
262}
263
264static ssize_t
265qla2x00_pci_info_show(struct class_device *cdev, char *buf)
266{
267 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
268 char pci_info[30];
269
270 return snprintf(buf, PAGE_SIZE, "%s\n",
271 ha->isp_ops.pci_info_str(ha, pci_info));
272}
273
274static ssize_t
275qla2x00_state_show(struct class_device *cdev, char *buf)
276{
277 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
278 int len = 0;
279
280 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
281 atomic_read(&ha->loop_state) == LOOP_DEAD)
282 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
283 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
284 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
285 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
286 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
287 else {
288 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
289
290 switch (ha->current_topology) {
291 case ISP_CFG_NL:
292 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
293 break;
294 case ISP_CFG_FL:
295 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
296 break;
297 case ISP_CFG_N:
298 len += snprintf(buf + len, PAGE_SIZE-len,
299 "N_Port to N_Port\n");
300 break;
301 case ISP_CFG_F:
302 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
303 break;
304 default:
305 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
306 break;
307 }
308 }
309 return len;
310}
311
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700312static ssize_t
313qla2x00_zio_show(struct class_device *cdev, char *buf)
314{
315 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
316 int len = 0;
317
318 switch (ha->zio_mode) {
319 case QLA_ZIO_MODE_5:
320 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
321 break;
322 case QLA_ZIO_MODE_6:
323 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
324 break;
325 case QLA_ZIO_DISABLED:
326 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
327 break;
328 }
329 return len;
330}
331
332static ssize_t
333qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
334{
335 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
336 int val = 0;
337 uint16_t zio_mode;
338
339 if (sscanf(buf, "%d", &val) != 1)
340 return -EINVAL;
341
342 switch (val) {
343 case 1:
344 zio_mode = QLA_ZIO_MODE_5;
345 break;
346 case 2:
347 zio_mode = QLA_ZIO_MODE_6;
348 break;
349 default:
350 zio_mode = QLA_ZIO_DISABLED;
351 break;
352 }
353
354 /* Update per-hba values and queue a reset. */
355 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
356 ha->zio_mode = zio_mode;
357 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
358 }
359 return strlen(buf);
360}
361
362static ssize_t
363qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
364{
365 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
366
367 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
368}
369
370static ssize_t
371qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
372 size_t count)
373{
374 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
375 int val = 0;
376 uint16_t zio_timer;
377
378 if (sscanf(buf, "%d", &val) != 1)
379 return -EINVAL;
380 if (val > 25500 || val < 100)
381 return -ERANGE;
382
383 zio_timer = (uint16_t)(val / 100);
384 ha->zio_timer = zio_timer;
385
386 return strlen(buf);
387}
388
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800389static ssize_t
390qla2x00_beacon_show(struct class_device *cdev, char *buf)
391{
392 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
393 int len = 0;
394
395 if (ha->beacon_blink_led)
396 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
397 else
398 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
399 return len;
400}
401
402static ssize_t
403qla2x00_beacon_store(struct class_device *cdev, const char *buf,
404 size_t count)
405{
406 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
407 int val = 0;
408 int rval;
409
410 if (IS_QLA2100(ha) || IS_QLA2200(ha))
411 return -EPERM;
412
413 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
414 qla_printk(KERN_WARNING, ha,
415 "Abort ISP active -- ignoring beacon request.\n");
416 return -EBUSY;
417 }
418
419 if (sscanf(buf, "%d", &val) != 1)
420 return -EINVAL;
421
422 if (val)
423 rval = ha->isp_ops.beacon_on(ha);
424 else
425 rval = ha->isp_ops.beacon_off(ha);
426
427 if (rval != QLA_SUCCESS)
428 count = 0;
429
430 return count;
431}
432
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700433static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
434 NULL);
435static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
436static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
437static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
438static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
439static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
440static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
441static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
442static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700443static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
444 qla2x00_zio_store);
445static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
446 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800447static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
448 qla2x00_beacon_store);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700449
450struct class_device_attribute *qla2x00_host_attrs[] = {
451 &class_device_attr_driver_version,
452 &class_device_attr_fw_version,
453 &class_device_attr_serial_num,
454 &class_device_attr_isp_name,
455 &class_device_attr_isp_id,
456 &class_device_attr_model_name,
457 &class_device_attr_model_desc,
458 &class_device_attr_pci_info,
459 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700460 &class_device_attr_zio,
461 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800462 &class_device_attr_beacon,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700463 NULL,
464};
465
8482e1182005-04-17 15:04:54 -0500466/* Host attributes. */
467
468static void
469qla2x00_get_host_port_id(struct Scsi_Host *shost)
470{
471 scsi_qla_host_t *ha = to_qla_host(shost);
472
473 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
474 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
475}
476
477static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800478qla2x00_get_host_speed(struct Scsi_Host *shost)
479{
480 scsi_qla_host_t *ha = to_qla_host(shost);
481 uint32_t speed = 0;
482
483 switch (ha->link_data_rate) {
484 case LDR_1GB:
485 speed = 1;
486 break;
487 case LDR_2GB:
488 speed = 2;
489 break;
490 case LDR_4GB:
491 speed = 4;
492 break;
493 }
494 fc_host_speed(shost) = speed;
495}
496
497static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800498qla2x00_get_host_port_type(struct Scsi_Host *shost)
499{
500 scsi_qla_host_t *ha = to_qla_host(shost);
501 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
502
503 switch (ha->current_topology) {
504 case ISP_CFG_NL:
505 port_type = FC_PORTTYPE_LPORT;
506 break;
507 case ISP_CFG_FL:
508 port_type = FC_PORTTYPE_NLPORT;
509 break;
510 case ISP_CFG_N:
511 port_type = FC_PORTTYPE_PTP;
512 break;
513 case ISP_CFG_F:
514 port_type = FC_PORTTYPE_NPORT;
515 break;
516 }
517 fc_host_port_type(shost) = port_type;
518}
519
520static void
8482e1182005-04-17 15:04:54 -0500521qla2x00_get_starget_node_name(struct scsi_target *starget)
522{
523 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
524 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500525 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700526 u64 node_name = 0;
8482e1182005-04-17 15:04:54 -0500527
bdf79622005-04-17 15:06:53 -0500528 list_for_each_entry(fcport, &ha->fcports, list) {
529 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700530 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500531 break;
532 }
533 }
534
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700535 fc_starget_node_name(starget) = node_name;
8482e1182005-04-17 15:04:54 -0500536}
537
538static void
539qla2x00_get_starget_port_name(struct scsi_target *starget)
540{
541 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
542 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500543 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700544 u64 port_name = 0;
8482e1182005-04-17 15:04:54 -0500545
bdf79622005-04-17 15:06:53 -0500546 list_for_each_entry(fcport, &ha->fcports, list) {
547 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700548 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500549 break;
550 }
551 }
552
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700553 fc_starget_port_name(starget) = port_name;
8482e1182005-04-17 15:04:54 -0500554}
555
556static void
557qla2x00_get_starget_port_id(struct scsi_target *starget)
558{
559 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
560 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500561 fc_port_t *fcport;
562 uint32_t port_id = ~0U;
8482e1182005-04-17 15:04:54 -0500563
bdf79622005-04-17 15:06:53 -0500564 list_for_each_entry(fcport, &ha->fcports, list) {
565 if (starget->id == fcport->os_target_id) {
566 port_id = fcport->d_id.b.domain << 16 |
567 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
568 break;
569 }
570 }
571
8482e1182005-04-17 15:04:54 -0500572 fc_starget_port_id(starget) = port_id;
573}
574
575static void
576qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
577{
bdf79622005-04-17 15:06:53 -0500578 struct Scsi_Host *host = rport_to_shost(rport);
579 scsi_qla_host_t *ha = to_qla_host(host);
8482e1182005-04-17 15:04:54 -0500580
581 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
582}
583
584static void
585qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
586{
bdf79622005-04-17 15:06:53 -0500587 struct Scsi_Host *host = rport_to_shost(rport);
588 scsi_qla_host_t *ha = to_qla_host(host);
8482e1182005-04-17 15:04:54 -0500589
590 if (timeout)
591 ha->port_down_retry_count = timeout;
592 else
593 ha->port_down_retry_count = 1;
594
595 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
596}
597
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700598static int
599qla2x00_issue_lip(struct Scsi_Host *shost)
600{
601 scsi_qla_host_t *ha = to_qla_host(shost);
602
603 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
604 return 0;
605}
606
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800607static struct fc_host_statistics *
608qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
609{
610 scsi_qla_host_t *ha = to_qla_host(shost);
611 int rval;
612 uint16_t mb_stat[1];
613 link_stat_t stat_buf;
614 struct fc_host_statistics *pfc_host_stat;
615
616 pfc_host_stat = &ha->fc_host_stat;
617 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
618
619 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
620 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
621 sizeof(stat_buf) / 4, mb_stat);
622 } else {
623 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
624 mb_stat);
625 }
626 if (rval != 0) {
627 qla_printk(KERN_WARNING, ha,
628 "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
629 return pfc_host_stat;
630 }
631
632 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
633 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
634 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
635 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
636 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
637 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
638
639 return pfc_host_stat;
640}
641
Andrew Vasquez1c97a122005-04-21 16:13:36 -0400642struct fc_function_template qla2xxx_transport_functions = {
8482e1182005-04-17 15:04:54 -0500643
644 .show_host_node_name = 1,
645 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700646 .show_host_supported_classes = 1,
647
8482e1182005-04-17 15:04:54 -0500648 .get_host_port_id = qla2x00_get_host_port_id,
649 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800650 .get_host_speed = qla2x00_get_host_speed,
651 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800652 .get_host_port_type = qla2x00_get_host_port_type,
653 .show_host_port_type = 1,
8482e1182005-04-17 15:04:54 -0500654
bdf79622005-04-17 15:06:53 -0500655 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700656 .show_rport_supported_classes = 1,
8482e1182005-04-17 15:04:54 -0500657
658 .get_starget_node_name = qla2x00_get_starget_node_name,
659 .show_starget_node_name = 1,
660 .get_starget_port_name = qla2x00_get_starget_port_name,
661 .show_starget_port_name = 1,
662 .get_starget_port_id = qla2x00_get_starget_port_id,
663 .show_starget_port_id = 1,
664
665 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
666 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
667 .show_rport_dev_loss_tmo = 1,
668
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700669 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800670 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e1182005-04-17 15:04:54 -0500671};
672
8482e1182005-04-17 15:04:54 -0500673void
674qla2x00_init_host_attr(scsi_qla_host_t *ha)
675{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -0800676 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
677 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -0700678 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
8482e1182005-04-17 15:04:54 -0500679}