1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
30 #include <scsi/scsi_transport_fc.h>
34 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_version.h"
39 #include "lpfc_compat.h"
40 #include "lpfc_crtn.h"
44 lpfc_jedec_to_ascii(int incr
, char hdw
[])
47 for (i
= 0; i
< 8; i
++) {
50 hdw
[7 - i
] = 0x30 + j
;
52 hdw
[7 - i
] = 0x61 + j
- 10;
60 lpfc_drvr_version_show(struct class_device
*cdev
, char *buf
)
62 return snprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
66 management_version_show(struct class_device
*cdev
, char *buf
)
68 return snprintf(buf
, PAGE_SIZE
, DFC_API_VERSION
"\n");
72 lpfc_info_show(struct class_device
*cdev
, char *buf
)
74 struct Scsi_Host
*host
= class_to_shost(cdev
);
75 return snprintf(buf
, PAGE_SIZE
, "%s\n",lpfc_info(host
));
79 lpfc_serialnum_show(struct class_device
*cdev
, char *buf
)
81 struct Scsi_Host
*host
= class_to_shost(cdev
);
82 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
83 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->SerialNumber
);
87 lpfc_modeldesc_show(struct class_device
*cdev
, char *buf
)
89 struct Scsi_Host
*host
= class_to_shost(cdev
);
90 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
91 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelDesc
);
95 lpfc_modelname_show(struct class_device
*cdev
, char *buf
)
97 struct Scsi_Host
*host
= class_to_shost(cdev
);
98 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
99 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelName
);
103 lpfc_programtype_show(struct class_device
*cdev
, char *buf
)
105 struct Scsi_Host
*host
= class_to_shost(cdev
);
106 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
107 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ProgramType
);
111 lpfc_portnum_show(struct class_device
*cdev
, char *buf
)
113 struct Scsi_Host
*host
= class_to_shost(cdev
);
114 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
115 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->Port
);
119 lpfc_fwrev_show(struct class_device
*cdev
, char *buf
)
121 struct Scsi_Host
*host
= class_to_shost(cdev
);
122 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
124 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
125 return snprintf(buf
, PAGE_SIZE
, "%s\n",fwrev
);
129 lpfc_hdw_show(struct class_device
*cdev
, char *buf
)
132 struct Scsi_Host
*host
= class_to_shost(cdev
);
133 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
134 lpfc_vpd_t
*vp
= &phba
->vpd
;
135 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
136 return snprintf(buf
, PAGE_SIZE
, "%s\n", hdw
);
139 lpfc_option_rom_version_show(struct class_device
*cdev
, char *buf
)
141 struct Scsi_Host
*host
= class_to_shost(cdev
);
142 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
143 return snprintf(buf
, PAGE_SIZE
, "%s\n", phba
->OptionROMVersion
);
146 lpfc_state_show(struct class_device
*cdev
, char *buf
)
148 struct Scsi_Host
*host
= class_to_shost(cdev
);
149 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
151 switch (phba
->hba_state
) {
152 case LPFC_STATE_UNKNOWN
:
153 case LPFC_WARM_START
:
154 case LPFC_INIT_START
:
155 case LPFC_INIT_MBX_CMDS
:
157 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Down\n");
160 case LPFC_LOCAL_CFG_LINK
:
161 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up\n");
164 case LPFC_FABRIC_CFG_LINK
:
167 case LPFC_BUILD_DISC_LIST
:
170 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
171 "Link Up - Discovery\n");
174 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
175 "Link Up - Ready:\n");
176 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
177 if (phba
->fc_flag
& FC_PUBLIC_LOOP
)
178 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
181 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
184 if (phba
->fc_flag
& FC_FABRIC
)
185 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
188 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
196 lpfc_num_discovered_ports_show(struct class_device
*cdev
, char *buf
)
198 struct Scsi_Host
*host
= class_to_shost(cdev
);
199 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
200 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->fc_map_cnt
+
206 lpfc_issue_lip(struct Scsi_Host
*host
)
208 struct lpfc_hba
*phba
= (struct lpfc_hba
*) host
->hostdata
;
209 LPFC_MBOXQ_t
*pmboxq
;
210 int mbxstatus
= MBXERR_ERROR
;
212 if ((phba
->fc_flag
& FC_OFFLINE_MODE
) ||
213 (phba
->hba_state
!= LPFC_HBA_READY
))
216 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
221 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
222 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
, phba
->cfg_link_speed
);
223 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
225 if (mbxstatus
== MBX_TIMEOUT
)
226 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
228 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
230 if (mbxstatus
== MBXERR_ERROR
)
237 lpfc_nport_evt_cnt_show(struct class_device
*cdev
, char *buf
)
239 struct Scsi_Host
*host
= class_to_shost(cdev
);
240 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
241 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
245 lpfc_board_online_show(struct class_device
*cdev
, char *buf
)
247 struct Scsi_Host
*host
= class_to_shost(cdev
);
248 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
250 if (phba
->fc_flag
& FC_OFFLINE_MODE
)
251 return snprintf(buf
, PAGE_SIZE
, "0\n");
253 return snprintf(buf
, PAGE_SIZE
, "1\n");
257 lpfc_board_online_store(struct class_device
*cdev
, const char *buf
,
260 struct Scsi_Host
*host
= class_to_shost(cdev
);
261 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
262 struct completion online_compl
;
265 if (sscanf(buf
, "%d", &val
) != 1)
268 init_completion(&online_compl
);
271 lpfc_workq_post_event(phba
, &status
, &online_compl
,
274 lpfc_workq_post_event(phba
, &status
, &online_compl
,
276 wait_for_completion(&online_compl
);
284 lpfc_board_mode_show(struct class_device
*cdev
, char *buf
)
286 struct Scsi_Host
*host
= class_to_shost(cdev
);
287 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
290 if (phba
->hba_state
== LPFC_HBA_ERROR
)
292 else if (phba
->hba_state
== LPFC_WARM_START
)
293 state
= "warm start";
294 else if (phba
->hba_state
== LPFC_INIT_START
)
299 return snprintf(buf
, PAGE_SIZE
, "%s\n", state
);
303 lpfc_board_mode_store(struct class_device
*cdev
, const char *buf
, size_t count
)
305 struct Scsi_Host
*host
= class_to_shost(cdev
);
306 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
307 struct completion online_compl
;
310 init_completion(&online_compl
);
312 if(strncmp(buf
, "online", sizeof("online") - 1) == 0)
313 lpfc_workq_post_event(phba
, &status
, &online_compl
,
315 else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
316 lpfc_workq_post_event(phba
, &status
, &online_compl
,
318 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
319 lpfc_workq_post_event(phba
, &status
, &online_compl
,
320 LPFC_EVT_WARM_START
);
321 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
322 lpfc_workq_post_event(phba
, &status
, &online_compl
,
327 wait_for_completion(&online_compl
);
336 lpfc_poll_show(struct class_device
*cdev
, char *buf
)
338 struct Scsi_Host
*host
= class_to_shost(cdev
);
339 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
341 return snprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
345 lpfc_poll_store(struct class_device
*cdev
, const char *buf
,
348 struct Scsi_Host
*host
= class_to_shost(cdev
);
349 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
354 if (!isdigit(buf
[0]))
357 if (sscanf(buf
, "%i", &val
) != 1)
360 if ((val
& 0x3) != val
)
363 spin_lock_irq(phba
->host
->host_lock
);
365 old_val
= phba
->cfg_poll
;
367 if (val
& ENABLE_FCP_RING_POLLING
) {
368 if ((val
& DISABLE_FCP_RING_INT
) &&
369 !(old_val
& DISABLE_FCP_RING_INT
)) {
370 creg_val
= readl(phba
->HCregaddr
);
371 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
372 writel(creg_val
, phba
->HCregaddr
);
373 readl(phba
->HCregaddr
); /* flush */
375 lpfc_poll_start_timer(phba
);
377 } else if (val
!= 0x0) {
378 spin_unlock_irq(phba
->host
->host_lock
);
382 if (!(val
& DISABLE_FCP_RING_INT
) &&
383 (old_val
& DISABLE_FCP_RING_INT
))
385 spin_unlock_irq(phba
->host
->host_lock
);
386 del_timer(&phba
->fcp_poll_timer
);
387 spin_lock_irq(phba
->host
->host_lock
);
388 creg_val
= readl(phba
->HCregaddr
);
389 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
390 writel(creg_val
, phba
->HCregaddr
);
391 readl(phba
->HCregaddr
); /* flush */
394 phba
->cfg_poll
= val
;
396 spin_unlock_irq(phba
->host
->host_lock
);
401 #define lpfc_param_show(attr) \
403 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
405 struct Scsi_Host *host = class_to_shost(cdev);\
406 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
408 val = phba->cfg_##attr;\
409 return snprintf(buf, PAGE_SIZE, "%d\n",\
413 #define lpfc_param_hex_show(attr) \
415 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
417 struct Scsi_Host *host = class_to_shost(cdev);\
418 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
420 val = phba->cfg_##attr;\
421 return snprintf(buf, PAGE_SIZE, "%#x\n",\
425 #define lpfc_param_init(attr, default, minval, maxval) \
427 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
429 if (val >= minval && val <= maxval) {\
430 phba->cfg_##attr = val;\
433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
434 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
435 "allowed range is ["#minval", "#maxval"]\n", \
436 phba->brd_no, val); \
437 phba->cfg_##attr = default;\
441 #define lpfc_param_set(attr, default, minval, maxval) \
443 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
445 if (val >= minval && val <= maxval) {\
446 phba->cfg_##attr = val;\
449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
450 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
451 "allowed range is ["#minval", "#maxval"]\n", \
452 phba->brd_no, val); \
456 #define lpfc_param_store(attr) \
458 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
460 struct Scsi_Host *host = class_to_shost(cdev);\
461 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
463 if (!isdigit(buf[0]))\
465 if (sscanf(buf, "%i", &val) != 1)\
467 if (lpfc_##attr##_set(phba, val) == 0) \
473 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
474 static int lpfc_##name = defval;\
475 module_param(lpfc_##name, int, 0);\
476 MODULE_PARM_DESC(lpfc_##name, desc);\
477 lpfc_param_init(name, defval, minval, maxval)
479 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
480 static int lpfc_##name = defval;\
481 module_param(lpfc_##name, int, 0);\
482 MODULE_PARM_DESC(lpfc_##name, desc);\
483 lpfc_param_show(name)\
484 lpfc_param_init(name, defval, minval, maxval)\
485 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
487 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
488 static int lpfc_##name = defval;\
489 module_param(lpfc_##name, int, 0);\
490 MODULE_PARM_DESC(lpfc_##name, desc);\
491 lpfc_param_show(name)\
492 lpfc_param_init(name, defval, minval, maxval)\
493 lpfc_param_set(name, defval, minval, maxval)\
494 lpfc_param_store(name)\
495 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
496 lpfc_##name##_show, lpfc_##name##_store)
498 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
499 static int lpfc_##name = defval;\
500 module_param(lpfc_##name, int, 0);\
501 MODULE_PARM_DESC(lpfc_##name, desc);\
502 lpfc_param_hex_show(name)\
503 lpfc_param_init(name, defval, minval, maxval)\
504 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
506 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
507 static int lpfc_##name = defval;\
508 module_param(lpfc_##name, int, 0);\
509 MODULE_PARM_DESC(lpfc_##name, desc);\
510 lpfc_param_hex_show(name)\
511 lpfc_param_init(name, defval, minval, maxval)\
512 lpfc_param_set(name, defval, minval, maxval)\
513 lpfc_param_store(name)\
514 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
515 lpfc_##name##_show, lpfc_##name##_store)
517 static CLASS_DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
518 static CLASS_DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
519 static CLASS_DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
520 static CLASS_DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
521 static CLASS_DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
522 static CLASS_DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_portnum_show
, NULL
);
523 static CLASS_DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
524 static CLASS_DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
525 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, lpfc_state_show
, NULL
);
526 static CLASS_DEVICE_ATTR(option_rom_version
, S_IRUGO
,
527 lpfc_option_rom_version_show
, NULL
);
528 static CLASS_DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
529 lpfc_num_discovered_ports_show
, NULL
);
530 static CLASS_DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
531 static CLASS_DEVICE_ATTR(lpfc_drvr_version
, S_IRUGO
, lpfc_drvr_version_show
,
533 static CLASS_DEVICE_ATTR(management_version
, S_IRUGO
, management_version_show
,
535 static CLASS_DEVICE_ATTR(board_online
, S_IRUGO
| S_IWUSR
,
536 lpfc_board_online_show
, lpfc_board_online_store
);
537 static CLASS_DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
538 lpfc_board_mode_show
, lpfc_board_mode_store
);
540 static int lpfc_poll
= 0;
541 module_param(lpfc_poll
, int, 0);
542 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
544 " 1 - poll with interrupts enabled"
545 " 3 - poll and disable FCP ring interrupts");
547 static CLASS_DEVICE_ATTR(lpfc_poll
, S_IRUGO
| S_IWUSR
,
548 lpfc_poll_show
, lpfc_poll_store
);
551 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
552 # deluged with LOTS of information.
553 # You can set a bit mask to record specific types of verbose messages:
555 # LOG_ELS 0x1 ELS events
556 # LOG_DISCOVERY 0x2 Link discovery events
557 # LOG_MBOX 0x4 Mailbox events
558 # LOG_INIT 0x8 Initialization events
559 # LOG_LINK_EVENT 0x10 Link events
560 # LOG_IP 0x20 IP traffic history
561 # LOG_FCP 0x40 FCP traffic history
562 # LOG_NODE 0x80 Node table events
563 # LOG_MISC 0x400 Miscellaneous events
564 # LOG_SLI 0x800 SLI events
565 # LOG_CHK_COND 0x1000 FCP Check condition flag
566 # LOG_LIBDFC 0x2000 LIBDFC events
567 # LOG_ALL_MSG 0xffff LOG all messages
569 LPFC_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
572 # lun_queue_depth: This parameter is used to limit the number of outstanding
573 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
575 LPFC_ATTR_R(lun_queue_depth
, 30, 1, 128,
576 "Max number of FCP commands we can queue to a specific LUN");
579 # hba_queue_depth: This parameter is used to limit the number of outstanding
580 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
581 # value is greater than the maximum number of exchanges supported by the HBA,
582 # then maximum number of exchanges supported by the HBA is used to determine
583 # the hba_queue_depth.
585 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
586 "Max number of FCP commands we can queue to a lpfc HBA");
589 # Some disk devices have a "select ID" or "select Target" capability.
590 # From a protocol standpoint "select ID" usually means select the
591 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
592 # annex" which contains a table that maps a "select ID" (a number
593 # between 0 and 7F) to an ALPA. By default, for compatibility with
594 # older drivers, the lpfc driver scans this table from low ALPA to high
597 # Turning on the scan-down variable (on = 1, off = 0) will
598 # cause the lpfc driver to use an inverted table, effectively
599 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
601 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
602 # and will not work across a fabric. Also this parameter will take
603 # effect only in the case when ALPA map is not available.)
605 LPFC_ATTR_R(scan_down
, 1, 0, 1,
606 "Start scanning for devices from highest ALPA to lowest");
609 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
610 # until the timer expires. Value range is [0,255]. Default value is 30.
611 # NOTE: this MUST be less then the SCSI Layer command timeout - 1.
613 LPFC_ATTR_RW(nodev_tmo
, 30, 0, 255,
614 "Seconds driver will hold I/O waiting for a device to come back");
617 # lpfc_topology: link topology for init link
618 # 0x0 = attempt loop mode then point-to-point
619 # 0x01 = internal loopback mode
620 # 0x02 = attempt point-to-point mode only
621 # 0x04 = attempt loop mode only
622 # 0x06 = attempt point-to-point mode then loop
623 # Set point-to-point mode if you want to run as an N_Port.
624 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
625 # Default value is 0.
627 LPFC_ATTR_RW(topology
, 0, 0, 6, "Select Fibre Channel topology");
630 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
632 # 0 = auto select (default)
636 # Value range is [0,4]. Default value is 0.
638 LPFC_ATTR_R(link_speed
, 0, 0, 4, "Select link speed");
641 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
642 # Value range is [2,3]. Default value is 3.
644 LPFC_ATTR_R(fcp_class
, 3, 2, 3,
645 "Select Fibre Channel class of service for FCP sequences");
648 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
649 # is [0,1]. Default value is 0.
651 LPFC_ATTR_RW(use_adisc
, 0, 0, 1,
652 "Use ADISC on rediscovery to authenticate FCP devices");
655 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
656 # range is [0,1]. Default value is 0.
658 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
661 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
662 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
663 # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
664 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
665 # cr_delay is set to 0.
667 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
668 "interrupt response is generated");
670 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
671 "interrupt response is generated");
674 # lpfc_multi_ring_support: Determines how many rings to spread available
675 # cmd/rsp IOCB entries across.
676 # Value range is [1,2]. Default value is 1.
678 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
679 "SLI rings to spread IOCB entries across");
682 # lpfc_fdmi_on: controls FDMI support.
683 # 0 = no FDMI support
684 # 1 = support FDMI without attribute of hostname
685 # 2 = support FDMI with attribute of hostname
686 # Value range [0,2]. Default value is 0.
688 LPFC_ATTR_RW(fdmi_on
, 0, 0, 2, "Enable FDMI support");
691 # Specifies the maximum number of ELS cmds we can have outstanding (for
692 # discovery). Value range is [1,64]. Default value = 32.
694 LPFC_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
698 # lpfc_max_luns: maximum number of LUNs per target driver will support
699 # Value range is [1,32768]. Default value is 256.
700 # NOTE: The SCSI layer will scan each target for this many luns
702 LPFC_ATTR_R(max_luns
, 256, 1, 32768,
703 "Maximum number of LUNs per target driver will support");
706 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
707 # Value range is [1,255], default value is 10.
709 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
710 "Milliseconds driver will wait between polling FCP ring");
712 struct class_device_attribute
*lpfc_host_attrs
[] = {
713 &class_device_attr_info
,
714 &class_device_attr_serialnum
,
715 &class_device_attr_modeldesc
,
716 &class_device_attr_modelname
,
717 &class_device_attr_programtype
,
718 &class_device_attr_portnum
,
719 &class_device_attr_fwrev
,
720 &class_device_attr_hdw
,
721 &class_device_attr_option_rom_version
,
722 &class_device_attr_state
,
723 &class_device_attr_num_discovered_ports
,
724 &class_device_attr_lpfc_drvr_version
,
725 &class_device_attr_lpfc_log_verbose
,
726 &class_device_attr_lpfc_lun_queue_depth
,
727 &class_device_attr_lpfc_hba_queue_depth
,
728 &class_device_attr_lpfc_nodev_tmo
,
729 &class_device_attr_lpfc_fcp_class
,
730 &class_device_attr_lpfc_use_adisc
,
731 &class_device_attr_lpfc_ack0
,
732 &class_device_attr_lpfc_topology
,
733 &class_device_attr_lpfc_scan_down
,
734 &class_device_attr_lpfc_link_speed
,
735 &class_device_attr_lpfc_cr_delay
,
736 &class_device_attr_lpfc_cr_count
,
737 &class_device_attr_lpfc_multi_ring_support
,
738 &class_device_attr_lpfc_fdmi_on
,
739 &class_device_attr_lpfc_max_luns
,
740 &class_device_attr_nport_evt_cnt
,
741 &class_device_attr_management_version
,
742 &class_device_attr_board_online
,
743 &class_device_attr_board_mode
,
744 &class_device_attr_lpfc_poll
,
745 &class_device_attr_lpfc_poll_tmo
,
750 sysfs_ctlreg_write(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
753 struct Scsi_Host
*host
= class_to_shost(container_of(kobj
,
754 struct class_device
, kobj
));
755 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
757 if ((off
+ count
) > FF_REG_AREA_SIZE
)
760 if (count
== 0) return 0;
762 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
765 spin_lock_irq(phba
->host
->host_lock
);
767 if (!(phba
->fc_flag
& FC_OFFLINE_MODE
)) {
768 spin_unlock_irq(phba
->host
->host_lock
);
772 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t))
773 writel(*((uint32_t *)(buf
+ buf_off
)),
774 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
776 spin_unlock_irq(phba
->host
->host_lock
);
782 sysfs_ctlreg_read(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
786 struct Scsi_Host
*host
= class_to_shost(container_of(kobj
,
787 struct class_device
, kobj
));
788 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
790 if (off
> FF_REG_AREA_SIZE
)
793 if ((off
+ count
) > FF_REG_AREA_SIZE
)
794 count
= FF_REG_AREA_SIZE
- off
;
796 if (count
== 0) return 0;
798 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
801 spin_lock_irq(phba
->host
->host_lock
);
803 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
804 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
805 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
808 spin_unlock_irq(phba
->host
->host_lock
);
813 static struct bin_attribute sysfs_ctlreg_attr
= {
816 .mode
= S_IRUSR
| S_IWUSR
,
817 .owner
= THIS_MODULE
,
820 .read
= sysfs_ctlreg_read
,
821 .write
= sysfs_ctlreg_write
,
826 sysfs_mbox_idle (struct lpfc_hba
* phba
)
828 phba
->sysfs_mbox
.state
= SMBOX_IDLE
;
829 phba
->sysfs_mbox
.offset
= 0;
831 if (phba
->sysfs_mbox
.mbox
) {
832 mempool_free(phba
->sysfs_mbox
.mbox
,
833 phba
->mbox_mem_pool
);
834 phba
->sysfs_mbox
.mbox
= NULL
;
839 sysfs_mbox_write(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
841 struct Scsi_Host
* host
=
842 class_to_shost(container_of(kobj
, struct class_device
, kobj
));
843 struct lpfc_hba
* phba
= (struct lpfc_hba
*)host
->hostdata
;
844 struct lpfcMboxq
* mbox
= NULL
;
846 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
849 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
856 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
859 memset(mbox
, 0, sizeof (LPFC_MBOXQ_t
));
862 spin_lock_irq(host
->host_lock
);
865 if (phba
->sysfs_mbox
.mbox
)
866 mempool_free(mbox
, phba
->mbox_mem_pool
);
868 phba
->sysfs_mbox
.mbox
= mbox
;
869 phba
->sysfs_mbox
.state
= SMBOX_WRITING
;
871 if (phba
->sysfs_mbox
.state
!= SMBOX_WRITING
||
872 phba
->sysfs_mbox
.offset
!= off
||
873 phba
->sysfs_mbox
.mbox
== NULL
) {
874 sysfs_mbox_idle(phba
);
875 spin_unlock_irq(host
->host_lock
);
880 memcpy((uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
,
883 phba
->sysfs_mbox
.offset
= off
+ count
;
885 spin_unlock_irq(host
->host_lock
);
891 sysfs_mbox_read(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
893 struct Scsi_Host
*host
=
894 class_to_shost(container_of(kobj
, struct class_device
,
896 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
899 if (off
> sizeof(MAILBOX_t
))
902 if ((count
+ off
) > sizeof(MAILBOX_t
))
903 count
= sizeof(MAILBOX_t
) - off
;
905 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
908 if (off
&& count
== 0)
911 spin_lock_irq(phba
->host
->host_lock
);
914 phba
->sysfs_mbox
.state
== SMBOX_WRITING
&&
915 phba
->sysfs_mbox
.offset
>= 2 * sizeof(uint32_t)) {
917 switch (phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
) {
922 case MBX_CONFIG_LINK
:
923 case MBX_CONFIG_RING
:
925 case MBX_UNREG_LOGIN
:
927 case MBX_DUMP_CONTEXT
:
930 case MBX_FLASH_WR_ULA
:
934 if (!(phba
->fc_flag
& FC_OFFLINE_MODE
)) {
935 printk(KERN_WARNING
"mbox_read:Command 0x%x "
936 "is illegal in on-line state\n",
937 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
938 sysfs_mbox_idle(phba
);
939 spin_unlock_irq(phba
->host
->host_lock
);
944 case MBX_READ_CONFIG
:
945 case MBX_READ_RCONFIG
:
946 case MBX_READ_STATUS
:
949 case MBX_READ_LNK_STAT
:
950 case MBX_DUMP_MEMORY
:
955 case MBX_LOAD_EXP_ROM
:
957 case MBX_DEL_LD_ENTRY
:
959 case MBX_READ_SPARM64
:
963 case MBX_REG_LOGIN64
:
964 case MBX_CONFIG_PORT
:
965 case MBX_RUN_BIU_DIAG
:
966 printk(KERN_WARNING
"mbox_read: Illegal Command 0x%x\n",
967 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
968 sysfs_mbox_idle(phba
);
969 spin_unlock_irq(phba
->host
->host_lock
);
972 printk(KERN_WARNING
"mbox_read: Unknown Command 0x%x\n",
973 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
974 sysfs_mbox_idle(phba
);
975 spin_unlock_irq(phba
->host
->host_lock
);
979 if ((phba
->fc_flag
& FC_OFFLINE_MODE
) ||
980 (!(phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
))){
982 spin_unlock_irq(phba
->host
->host_lock
);
983 rc
= lpfc_sli_issue_mbox (phba
,
984 phba
->sysfs_mbox
.mbox
,
986 spin_lock_irq(phba
->host
->host_lock
);
989 spin_unlock_irq(phba
->host
->host_lock
);
990 rc
= lpfc_sli_issue_mbox_wait (phba
,
991 phba
->sysfs_mbox
.mbox
,
993 spin_lock_irq(phba
->host
->host_lock
);
996 if (rc
!= MBX_SUCCESS
) {
997 sysfs_mbox_idle(phba
);
998 spin_unlock_irq(host
->host_lock
);
1001 phba
->sysfs_mbox
.state
= SMBOX_READING
;
1003 else if (phba
->sysfs_mbox
.offset
!= off
||
1004 phba
->sysfs_mbox
.state
!= SMBOX_READING
) {
1005 printk(KERN_WARNING
"mbox_read: Bad State\n");
1006 sysfs_mbox_idle(phba
);
1007 spin_unlock_irq(host
->host_lock
);
1011 memcpy(buf
, (uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
, count
);
1013 phba
->sysfs_mbox
.offset
= off
+ count
;
1015 if (phba
->sysfs_mbox
.offset
== sizeof(MAILBOX_t
))
1016 sysfs_mbox_idle(phba
);
1018 spin_unlock_irq(phba
->host
->host_lock
);
1023 static struct bin_attribute sysfs_mbox_attr
= {
1026 .mode
= S_IRUSR
| S_IWUSR
,
1027 .owner
= THIS_MODULE
,
1029 .size
= sizeof(MAILBOX_t
),
1030 .read
= sysfs_mbox_read
,
1031 .write
= sysfs_mbox_write
,
1035 lpfc_alloc_sysfs_attr(struct lpfc_hba
*phba
)
1037 struct Scsi_Host
*host
= phba
->host
;
1040 error
= sysfs_create_bin_file(&host
->shost_classdev
.kobj
,
1041 &sysfs_ctlreg_attr
);
1045 error
= sysfs_create_bin_file(&host
->shost_classdev
.kobj
,
1048 goto out_remove_ctlreg_attr
;
1051 out_remove_ctlreg_attr
:
1052 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &sysfs_ctlreg_attr
);
1058 lpfc_free_sysfs_attr(struct lpfc_hba
*phba
)
1060 struct Scsi_Host
*host
= phba
->host
;
1062 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &sysfs_mbox_attr
);
1063 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &sysfs_ctlreg_attr
);
1068 * Dynamic FC Host Attributes Support
1072 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
1074 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1075 /* note: fc_myDID already in cpu endianness */
1076 fc_host_port_id(shost
) = phba
->fc_myDID
;
1080 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
1082 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1084 spin_lock_irq(shost
->host_lock
);
1086 if (phba
->hba_state
== LPFC_HBA_READY
) {
1087 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1088 if (phba
->fc_flag
& FC_PUBLIC_LOOP
)
1089 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
1091 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
1093 if (phba
->fc_flag
& FC_FABRIC
)
1094 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
1096 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
1099 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
1101 spin_unlock_irq(shost
->host_lock
);
1105 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
1107 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1109 spin_lock_irq(shost
->host_lock
);
1111 if (phba
->fc_flag
& FC_OFFLINE_MODE
)
1112 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
1114 switch (phba
->hba_state
) {
1115 case LPFC_STATE_UNKNOWN
:
1116 case LPFC_WARM_START
:
1117 case LPFC_INIT_START
:
1118 case LPFC_INIT_MBX_CMDS
:
1119 case LPFC_LINK_DOWN
:
1120 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1123 case LPFC_LOCAL_CFG_LINK
:
1125 case LPFC_FABRIC_CFG_LINK
:
1128 case LPFC_BUILD_DISC_LIST
:
1129 case LPFC_DISC_AUTH
:
1131 case LPFC_HBA_READY
:
1132 /* Links up, beyond this port_type reports state */
1133 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
1135 case LPFC_HBA_ERROR
:
1136 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
1139 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
1144 spin_unlock_irq(shost
->host_lock
);
1148 lpfc_get_host_speed(struct Scsi_Host
*shost
)
1150 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1152 spin_lock_irq(shost
->host_lock
);
1154 if (phba
->hba_state
== LPFC_HBA_READY
) {
1155 switch(phba
->fc_linkspeed
) {
1157 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
1160 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
1163 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
1166 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
1171 spin_unlock_irq(shost
->host_lock
);
1175 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
1177 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1180 spin_lock_irq(shost
->host_lock
);
1182 if ((phba
->fc_flag
& FC_FABRIC
) ||
1183 ((phba
->fc_topology
== TOPOLOGY_LOOP
) &&
1184 (phba
->fc_flag
& FC_PUBLIC_LOOP
)))
1185 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
1187 /* fabric is local port if there is no F/FL_Port */
1188 node_name
= wwn_to_u64(phba
->fc_nodename
.u
.wwn
);
1190 spin_unlock_irq(shost
->host_lock
);
1192 fc_host_fabric_name(shost
) = node_name
;
1196 static struct fc_host_statistics
*
1197 lpfc_get_stats(struct Scsi_Host
*shost
)
1199 struct lpfc_hba
*phba
= (struct lpfc_hba
*)shost
->hostdata
;
1200 struct lpfc_sli
*psli
= &phba
->sli
;
1201 struct fc_host_statistics
*hs
= &phba
->link_stats
;
1202 LPFC_MBOXQ_t
*pmboxq
;
1206 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1209 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1212 pmb
->mbxCommand
= MBX_READ_STATUS
;
1213 pmb
->mbxOwner
= OWN_HOST
;
1214 pmboxq
->context1
= NULL
;
1216 if ((phba
->fc_flag
& FC_OFFLINE_MODE
) ||
1217 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
1218 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
1220 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1222 if (rc
!= MBX_SUCCESS
) {
1223 if (rc
== MBX_TIMEOUT
)
1224 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1226 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1230 memset(hs
, 0, sizeof (struct fc_host_statistics
));
1232 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
1233 hs
->tx_words
= (pmb
->un
.varRdStatus
.xmitByteCnt
* 256);
1234 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
1235 hs
->rx_words
= (pmb
->un
.varRdStatus
.rcvByteCnt
* 256);
1237 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1238 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
1239 pmb
->mbxOwner
= OWN_HOST
;
1240 pmboxq
->context1
= NULL
;
1242 if ((phba
->fc_flag
& FC_OFFLINE_MODE
) ||
1243 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
1244 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
1246 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1248 if (rc
!= MBX_SUCCESS
) {
1249 if (rc
== MBX_TIMEOUT
)
1250 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1252 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
1256 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
1257 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
1258 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
1259 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
1260 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
1261 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
1262 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
1264 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1265 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
1269 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
1272 hs
->dumped_frames
= -1;
1275 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1282 * The LPFC driver treats linkdown handling as target loss events so there
1283 * are no sysfs handlers for link_down_tmo.
1286 lpfc_get_starget_port_id(struct scsi_target
*starget
)
1288 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1289 struct lpfc_hba
*phba
= (struct lpfc_hba
*) shost
->hostdata
;
1291 struct lpfc_nodelist
*ndlp
= NULL
;
1293 spin_lock_irq(shost
->host_lock
);
1294 /* Search the mapped list for this target ID */
1295 list_for_each_entry(ndlp
, &phba
->fc_nlpmap_list
, nlp_listp
) {
1296 if (starget
->id
== ndlp
->nlp_sid
) {
1297 did
= ndlp
->nlp_DID
;
1301 spin_unlock_irq(shost
->host_lock
);
1303 fc_starget_port_id(starget
) = did
;
1307 lpfc_get_starget_node_name(struct scsi_target
*starget
)
1309 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1310 struct lpfc_hba
*phba
= (struct lpfc_hba
*) shost
->hostdata
;
1312 struct lpfc_nodelist
*ndlp
= NULL
;
1314 spin_lock_irq(shost
->host_lock
);
1315 /* Search the mapped list for this target ID */
1316 list_for_each_entry(ndlp
, &phba
->fc_nlpmap_list
, nlp_listp
) {
1317 if (starget
->id
== ndlp
->nlp_sid
) {
1318 node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
1322 spin_unlock_irq(shost
->host_lock
);
1324 fc_starget_node_name(starget
) = node_name
;
1328 lpfc_get_starget_port_name(struct scsi_target
*starget
)
1330 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
1331 struct lpfc_hba
*phba
= (struct lpfc_hba
*) shost
->hostdata
;
1333 struct lpfc_nodelist
*ndlp
= NULL
;
1335 spin_lock_irq(shost
->host_lock
);
1336 /* Search the mapped list for this target ID */
1337 list_for_each_entry(ndlp
, &phba
->fc_nlpmap_list
, nlp_listp
) {
1338 if (starget
->id
== ndlp
->nlp_sid
) {
1339 port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
1343 spin_unlock_irq(shost
->host_lock
);
1345 fc_starget_port_name(starget
) = port_name
;
1349 lpfc_get_rport_loss_tmo(struct fc_rport
*rport
)
1352 * Return the driver's global value for device loss timeout plus
1353 * five seconds to allow the driver's nodev timer to run.
1355 rport
->dev_loss_tmo
= lpfc_nodev_tmo
+ 5;
1359 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
1362 * The driver doesn't have a per-target timeout setting. Set
1363 * this value globally. lpfc_nodev_tmo should be greater then 0.
1366 lpfc_nodev_tmo
= timeout
;
1369 rport
->dev_loss_tmo
= lpfc_nodev_tmo
+ 5;
1373 #define lpfc_rport_show_function(field, format_string, sz, cast) \
1375 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1377 struct fc_rport *rport = transport_class_to_rport(cdev); \
1378 struct lpfc_rport_data *rdata = rport->hostdata; \
1379 return snprintf(buf, sz, format_string, \
1380 (rdata->target) ? cast rdata->target->field : 0); \
1383 #define lpfc_rport_rd_attr(field, format_string, sz) \
1384 lpfc_rport_show_function(field, format_string, sz, ) \
1385 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1388 struct fc_function_template lpfc_transport_functions
= {
1389 /* fixed attributes the driver supports */
1390 .show_host_node_name
= 1,
1391 .show_host_port_name
= 1,
1392 .show_host_supported_classes
= 1,
1393 .show_host_supported_fc4s
= 1,
1394 .show_host_symbolic_name
= 1,
1395 .show_host_supported_speeds
= 1,
1396 .show_host_maxframe_size
= 1,
1398 /* dynamic attributes the driver supports */
1399 .get_host_port_id
= lpfc_get_host_port_id
,
1400 .show_host_port_id
= 1,
1402 .get_host_port_type
= lpfc_get_host_port_type
,
1403 .show_host_port_type
= 1,
1405 .get_host_port_state
= lpfc_get_host_port_state
,
1406 .show_host_port_state
= 1,
1408 /* active_fc4s is shown but doesn't change (thus no get function) */
1409 .show_host_active_fc4s
= 1,
1411 .get_host_speed
= lpfc_get_host_speed
,
1412 .show_host_speed
= 1,
1414 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
1415 .show_host_fabric_name
= 1,
1418 * The LPFC driver treats linkdown handling as target loss events
1419 * so there are no sysfs handlers for link_down_tmo.
1422 .get_fc_host_stats
= lpfc_get_stats
,
1424 /* the LPFC driver doesn't support resetting stats yet */
1426 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
1427 .show_rport_maxframe_size
= 1,
1428 .show_rport_supported_classes
= 1,
1430 .get_rport_dev_loss_tmo
= lpfc_get_rport_loss_tmo
,
1431 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
1432 .show_rport_dev_loss_tmo
= 1,
1434 .get_starget_port_id
= lpfc_get_starget_port_id
,
1435 .show_starget_port_id
= 1,
1437 .get_starget_node_name
= lpfc_get_starget_node_name
,
1438 .show_starget_node_name
= 1,
1440 .get_starget_port_name
= lpfc_get_starget_port_name
,
1441 .show_starget_port_name
= 1,
1443 .issue_fc_host_lip
= lpfc_issue_lip
,
1447 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
1449 lpfc_log_verbose_init(phba
, lpfc_log_verbose
);
1450 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
1451 lpfc_cr_count_init(phba
, lpfc_cr_count
);
1452 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
1453 lpfc_lun_queue_depth_init(phba
, lpfc_lun_queue_depth
);
1454 lpfc_fcp_class_init(phba
, lpfc_fcp_class
);
1455 lpfc_use_adisc_init(phba
, lpfc_use_adisc
);
1456 lpfc_ack0_init(phba
, lpfc_ack0
);
1457 lpfc_topology_init(phba
, lpfc_topology
);
1458 lpfc_scan_down_init(phba
, lpfc_scan_down
);
1459 lpfc_nodev_tmo_init(phba
, lpfc_nodev_tmo
);
1460 lpfc_link_speed_init(phba
, lpfc_link_speed
);
1461 lpfc_fdmi_on_init(phba
, lpfc_fdmi_on
);
1462 lpfc_discovery_threads_init(phba
, lpfc_discovery_threads
);
1463 lpfc_max_luns_init(phba
, lpfc_max_luns
);
1464 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
1466 phba
->cfg_poll
= lpfc_poll
;
1469 * The total number of segments is the configuration value plus 2
1470 * since the IOCB need a command and response bde.
1472 phba
->cfg_sg_seg_cnt
= LPFC_SG_SEG_CNT
+ 2;
1475 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1476 * used to create the sg_dma_buf_pool must be dynamically calculated
1478 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
1479 sizeof(struct fcp_rsp
) +
1480 (phba
->cfg_sg_seg_cnt
* sizeof(struct ulp_bde64
));
1482 switch (phba
->pcidev
->device
) {
1483 case PCI_DEVICE_ID_LP101
:
1484 case PCI_DEVICE_ID_BSMB
:
1485 case PCI_DEVICE_ID_ZSMB
:
1486 phba
->cfg_hba_queue_depth
= LPFC_LP101_HBA_Q_DEPTH
;
1488 case PCI_DEVICE_ID_RFLY
:
1489 case PCI_DEVICE_ID_PFLY
:
1490 case PCI_DEVICE_ID_BMID
:
1491 case PCI_DEVICE_ID_ZMID
:
1492 case PCI_DEVICE_ID_TFLY
:
1493 phba
->cfg_hba_queue_depth
= LPFC_LC_HBA_Q_DEPTH
;
1496 phba
->cfg_hba_queue_depth
= LPFC_DFT_HBA_Q_DEPTH
;
1499 if (phba
->cfg_hba_queue_depth
> lpfc_hba_queue_depth
)
1500 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);