[SCSI] lpfc 8.3.21: FC Discovery changes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / lpfc / lpfc_attr.c
bloba57f6c0cbbbafb65834ea001390b6b4eab85a357
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
8 * *
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/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
27 #include <linux/gfp.h>
28 #include <linux/kernel.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_hw4.h"
38 #include "lpfc_hw.h"
39 #include "lpfc_sli.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_nl.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_version.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_vport.h"
51 #define LPFC_DEF_DEVLOSS_TMO 30
52 #define LPFC_MIN_DEVLOSS_TMO 1
53 #define LPFC_MAX_DEVLOSS_TMO 255
55 /**
56 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
57 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
70 static void
71 lpfc_jedec_to_ascii(int incr, char hdw[])
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
82 hdw[8] = 0;
83 return;
86 /**
87 * lpfc_drvr_version_show - Return the Emulex driver string with version number
88 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
92 * Returns: size of formatted string.
93 **/
94 static ssize_t
95 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
107 * Returns: size of formatted string.
109 static ssize_t
110 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
123 static ssize_t
124 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
142 static ssize_t
143 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
154 static ssize_t
155 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
166 static ssize_t
167 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
179 * lpfc_info_show - Return some pci info about the host in ascii
180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
184 * Returns: size of formatted string.
186 static ssize_t
187 lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
190 struct Scsi_Host *host = class_to_shost(dev);
192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
196 * lpfc_serialnum_show - Return the hba serial number in ascii
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
201 * Returns: size of formatted string.
203 static ssize_t
204 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
207 struct Scsi_Host *shost = class_to_shost(dev);
208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
215 * lpfc_temp_sensor_show - Return the temperature sensor level
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
224 * Returns: size of formatted string.
226 static ssize_t
227 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
230 struct Scsi_Host *shost = class_to_shost(dev);
231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
237 * lpfc_modeldesc_show - Return the model description of the hba
238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
242 * Returns: size of formatted string.
244 static ssize_t
245 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
248 struct Scsi_Host *shost = class_to_shost(dev);
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
256 * lpfc_modelname_show - Return the model name of the hba
257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
261 * Returns: size of formatted string.
263 static ssize_t
264 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
267 struct Scsi_Host *shost = class_to_shost(dev);
268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
275 * lpfc_programtype_show - Return the program type of the hba
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
280 * Returns: size of formatted string.
282 static ssize_t
283 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
286 struct Scsi_Host *shost = class_to_shost(dev);
287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
299 * Returns: size of formatted string.
301 static ssize_t
302 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
313 * lpfc_vportnum_show - Return the port number in ascii of the hba
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
318 * Returns: size of formatted string.
320 static ssize_t
321 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
324 struct Scsi_Host *shost = class_to_shost(dev);
325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
332 * lpfc_fwrev_show - Return the firmware rev running in the hba
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
337 * Returns: size of formatted string.
339 static ssize_t
340 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
343 struct Scsi_Host *shost = class_to_shost(dev);
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
346 char fwrev[32];
348 lpfc_decode_firmware_rev(phba, fwrev, 1);
349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
353 * lpfc_hdw_show - Return the jedec information about the hba
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
358 * Returns: size of formatted string.
360 static ssize_t
361 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
363 char hdw[9];
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367 lpfc_vpd_t *vp = &phba->vpd;
369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
379 * Returns: size of formatted string.
381 static ssize_t
382 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
393 * lpfc_state_show - Return the link state of the port
394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
398 * Notes:
399 * The switch statement has no default so zero will be returned.
401 * Returns: size of formatted string.
403 static ssize_t
404 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
407 struct Scsi_Host *shost = class_to_shost(dev);
408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
414 case LPFC_WARM_START:
415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
418 case LPFC_HBA_ERROR:
419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
425 break;
426 case LPFC_LINK_UP:
427 case LPFC_CLEAR_LA:
428 case LPFC_HBA_READY:
429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
431 switch (vport->port_state) {
432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
434 "Configuring Link\n");
435 break;
436 case LPFC_FDISC:
437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
454 case LPFC_VPORT_UNKNOWN:
455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
463 if (vport->fc_flag & FC_PUBLIC_LOOP)
464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
470 if (vport->fc_flag & FC_FABRIC)
471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
479 return len;
483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
494 static ssize_t
495 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
502 int status = -EINVAL;
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
527 * Returns: size of formatted string.
529 static ssize_t
530 lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
533 struct Scsi_Host *shost = class_to_shost(dev);
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
541 * lpfc_issue_lip - Misnomer, name carried over from long ago
542 * @shost: Scsi_Host pointer.
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
554 static int
555 lpfc_issue_lip(struct Scsi_Host *shost)
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
564 return -EPERM;
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
568 if (!pmboxq)
569 return -ENOMEM;
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
592 lpfc_set_loopback_flag(phba);
593 if (mbxstatus != MBX_TIMEOUT)
594 mempool_free(pmboxq, phba->mbox_mem_pool);
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
599 return 0;
603 * lpfc_do_offline - Issues a mailbox command to bring the link down
604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
617 static int
618 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
626 int rc;
628 init_completion(&online_compl);
629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
630 LPFC_EVT_OFFLINE_PREP);
631 if (rc == 0)
632 return -ENOMEM;
634 wait_for_completion(&online_compl);
636 if (status != 0)
637 return -EIO;
639 psli = &phba->sli;
641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
646 while (pring->txcmplq_cnt) {
647 msleep(10);
648 if (cnt++ > 500) { /* 5 secs */
649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
653 break;
658 init_completion(&online_compl);
659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
663 wait_for_completion(&online_compl);
665 if (status != 0)
666 return -EIO;
668 return 0;
672 * lpfc_selective_reset - Offline then onlines the port
673 * @phba: lpfc_hba pointer.
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
682 * Returns:
683 * lpfc_do_offline() return code if not zero
684 * -EIO reset not configured or error posting the event
685 * zero for success
687 static int
688 lpfc_selective_reset(struct lpfc_hba *phba)
690 struct completion online_compl;
691 int status = 0;
692 int rc;
694 if (!phba->cfg_enable_hba_reset)
695 return -EIO;
697 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
699 if (status != 0)
700 return status;
702 init_completion(&online_compl);
703 rc = lpfc_workq_post_event(phba, &status, &online_compl,
704 LPFC_EVT_ONLINE);
705 if (rc == 0)
706 return -ENOMEM;
708 wait_for_completion(&online_compl);
710 if (status != 0)
711 return -EIO;
713 return 0;
717 * lpfc_issue_reset - Selectively resets an adapter
718 * @dev: class device that is converted into a Scsi_host.
719 * @attr: device attribute, not used.
720 * @buf: containing the string "selective".
721 * @count: unused variable.
723 * Description:
724 * If the buf contains the string "selective" then lpfc_selective_reset()
725 * is called to perform the reset.
727 * Notes:
728 * Assumes any error from lpfc_selective_reset() will be negative.
729 * If lpfc_selective_reset() returns zero then the length of the buffer
730 * is returned which indicates success
732 * Returns:
733 * -EINVAL if the buffer does not contain the string "selective"
734 * length of buf if lpfc-selective_reset() if the call succeeds
735 * return value of lpfc_selective_reset() if the call fails
737 static ssize_t
738 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
739 const char *buf, size_t count)
741 struct Scsi_Host *shost = class_to_shost(dev);
742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
743 struct lpfc_hba *phba = vport->phba;
745 int status = -EINVAL;
747 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
748 status = lpfc_selective_reset(phba);
750 if (status == 0)
751 return strlen(buf);
752 else
753 return status;
757 * lpfc_nport_evt_cnt_show - Return the number of nport events
758 * @dev: class device that is converted into a Scsi_host.
759 * @attr: device attribute, not used.
760 * @buf: on return contains the ascii number of nport events.
762 * Returns: size of formatted string.
764 static ssize_t
765 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
766 char *buf)
768 struct Scsi_Host *shost = class_to_shost(dev);
769 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
770 struct lpfc_hba *phba = vport->phba;
772 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
776 * lpfc_board_mode_show - Return the state of the board
777 * @dev: class device that is converted into a Scsi_host.
778 * @attr: device attribute, not used.
779 * @buf: on return contains the state of the adapter.
781 * Returns: size of formatted string.
783 static ssize_t
784 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
785 char *buf)
787 struct Scsi_Host *shost = class_to_shost(dev);
788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
789 struct lpfc_hba *phba = vport->phba;
790 char * state;
792 if (phba->link_state == LPFC_HBA_ERROR)
793 state = "error";
794 else if (phba->link_state == LPFC_WARM_START)
795 state = "warm start";
796 else if (phba->link_state == LPFC_INIT_START)
797 state = "offline";
798 else
799 state = "online";
801 return snprintf(buf, PAGE_SIZE, "%s\n", state);
805 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
806 * @dev: class device that is converted into a Scsi_host.
807 * @attr: device attribute, not used.
808 * @buf: containing one of the strings "online", "offline", "warm" or "error".
809 * @count: unused variable.
811 * Returns:
812 * -EACCES if enable hba reset not enabled
813 * -EINVAL if the buffer does not contain a valid string (see above)
814 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
815 * buf length greater than zero indicates success
817 static ssize_t
818 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
819 const char *buf, size_t count)
821 struct Scsi_Host *shost = class_to_shost(dev);
822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
823 struct lpfc_hba *phba = vport->phba;
824 struct completion online_compl;
825 int status=0;
826 int rc;
828 if (!phba->cfg_enable_hba_reset)
829 return -EACCES;
830 init_completion(&online_compl);
832 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
833 rc = lpfc_workq_post_event(phba, &status, &online_compl,
834 LPFC_EVT_ONLINE);
835 if (rc == 0)
836 return -ENOMEM;
837 wait_for_completion(&online_compl);
838 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
839 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
840 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
841 if (phba->sli_rev == LPFC_SLI_REV4)
842 return -EINVAL;
843 else
844 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
845 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
846 if (phba->sli_rev == LPFC_SLI_REV4)
847 return -EINVAL;
848 else
849 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
850 else
851 return -EINVAL;
853 if (!status)
854 return strlen(buf);
855 else
856 return -EIO;
860 * lpfc_get_hba_info - Return various bits of informaton about the adapter
861 * @phba: pointer to the adapter structure.
862 * @mxri: max xri count.
863 * @axri: available xri count.
864 * @mrpi: max rpi count.
865 * @arpi: available rpi count.
866 * @mvpi: max vpi count.
867 * @avpi: available vpi count.
869 * Description:
870 * If an integer pointer for an count is not null then the value for the
871 * count is returned.
873 * Returns:
874 * zero on error
875 * one for success
877 static int
878 lpfc_get_hba_info(struct lpfc_hba *phba,
879 uint32_t *mxri, uint32_t *axri,
880 uint32_t *mrpi, uint32_t *arpi,
881 uint32_t *mvpi, uint32_t *avpi)
883 struct lpfc_mbx_read_config *rd_config;
884 LPFC_MBOXQ_t *pmboxq;
885 MAILBOX_t *pmb;
886 int rc = 0;
887 uint32_t max_vpi;
890 * prevent udev from issuing mailbox commands until the port is
891 * configured.
893 if (phba->link_state < LPFC_LINK_DOWN ||
894 !phba->mbox_mem_pool ||
895 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
896 return 0;
898 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
899 return 0;
901 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
902 if (!pmboxq)
903 return 0;
904 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
906 pmb = &pmboxq->u.mb;
907 pmb->mbxCommand = MBX_READ_CONFIG;
908 pmb->mbxOwner = OWN_HOST;
909 pmboxq->context1 = NULL;
911 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
912 rc = MBX_NOT_FINISHED;
913 else
914 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
916 if (rc != MBX_SUCCESS) {
917 if (rc != MBX_TIMEOUT)
918 mempool_free(pmboxq, phba->mbox_mem_pool);
919 return 0;
922 if (phba->sli_rev == LPFC_SLI_REV4) {
923 rd_config = &pmboxq->u.mqe.un.rd_config;
924 if (mrpi)
925 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
926 if (arpi)
927 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
928 phba->sli4_hba.max_cfg_param.rpi_used;
929 if (mxri)
930 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
931 if (axri)
932 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
933 phba->sli4_hba.max_cfg_param.xri_used;
935 /* Account for differences with SLI-3. Get vpi count from
936 * mailbox data and subtract one for max vpi value.
938 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
939 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
941 if (mvpi)
942 *mvpi = max_vpi;
943 if (avpi)
944 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
945 } else {
946 if (mrpi)
947 *mrpi = pmb->un.varRdConfig.max_rpi;
948 if (arpi)
949 *arpi = pmb->un.varRdConfig.avail_rpi;
950 if (mxri)
951 *mxri = pmb->un.varRdConfig.max_xri;
952 if (axri)
953 *axri = pmb->un.varRdConfig.avail_xri;
954 if (mvpi)
955 *mvpi = pmb->un.varRdConfig.max_vpi;
956 if (avpi)
957 *avpi = pmb->un.varRdConfig.avail_vpi;
960 mempool_free(pmboxq, phba->mbox_mem_pool);
961 return 1;
965 * lpfc_max_rpi_show - Return maximum rpi
966 * @dev: class device that is converted into a Scsi_host.
967 * @attr: device attribute, not used.
968 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
970 * Description:
971 * Calls lpfc_get_hba_info() asking for just the mrpi count.
972 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
973 * to "Unknown" and the buffer length is returned, therefore the caller
974 * must check for "Unknown" in the buffer to detect a failure.
976 * Returns: size of formatted string.
978 static ssize_t
979 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
980 char *buf)
982 struct Scsi_Host *shost = class_to_shost(dev);
983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
984 struct lpfc_hba *phba = vport->phba;
985 uint32_t cnt;
987 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
988 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
989 return snprintf(buf, PAGE_SIZE, "Unknown\n");
993 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
994 * @dev: class device that is converted into a Scsi_host.
995 * @attr: device attribute, not used.
996 * @buf: containing the used rpi count in decimal or "Unknown".
998 * Description:
999 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1000 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1001 * to "Unknown" and the buffer length is returned, therefore the caller
1002 * must check for "Unknown" in the buffer to detect a failure.
1004 * Returns: size of formatted string.
1006 static ssize_t
1007 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1008 char *buf)
1010 struct Scsi_Host *shost = class_to_shost(dev);
1011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1012 struct lpfc_hba *phba = vport->phba;
1013 uint32_t cnt, acnt;
1015 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1016 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1017 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1021 * lpfc_max_xri_show - Return maximum xri
1022 * @dev: class device that is converted into a Scsi_host.
1023 * @attr: device attribute, not used.
1024 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1026 * Description:
1027 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1028 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1029 * to "Unknown" and the buffer length is returned, therefore the caller
1030 * must check for "Unknown" in the buffer to detect a failure.
1032 * Returns: size of formatted string.
1034 static ssize_t
1035 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1036 char *buf)
1038 struct Scsi_Host *shost = class_to_shost(dev);
1039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1040 struct lpfc_hba *phba = vport->phba;
1041 uint32_t cnt;
1043 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1044 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1045 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1049 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1050 * @dev: class device that is converted into a Scsi_host.
1051 * @attr: device attribute, not used.
1052 * @buf: on return contains the used xri count in decimal or "Unknown".
1054 * Description:
1055 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1056 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1057 * to "Unknown" and the buffer length is returned, therefore the caller
1058 * must check for "Unknown" in the buffer to detect a failure.
1060 * Returns: size of formatted string.
1062 static ssize_t
1063 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1064 char *buf)
1066 struct Scsi_Host *shost = class_to_shost(dev);
1067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1068 struct lpfc_hba *phba = vport->phba;
1069 uint32_t cnt, acnt;
1071 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1072 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1073 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1077 * lpfc_max_vpi_show - Return maximum vpi
1078 * @dev: class device that is converted into a Scsi_host.
1079 * @attr: device attribute, not used.
1080 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1082 * Description:
1083 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1084 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1085 * to "Unknown" and the buffer length is returned, therefore the caller
1086 * must check for "Unknown" in the buffer to detect a failure.
1088 * Returns: size of formatted string.
1090 static ssize_t
1091 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1092 char *buf)
1094 struct Scsi_Host *shost = class_to_shost(dev);
1095 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1096 struct lpfc_hba *phba = vport->phba;
1097 uint32_t cnt;
1099 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1100 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1101 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1105 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1106 * @dev: class device that is converted into a Scsi_host.
1107 * @attr: device attribute, not used.
1108 * @buf: on return contains the used vpi count in decimal or "Unknown".
1110 * Description:
1111 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1112 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1113 * to "Unknown" and the buffer length is returned, therefore the caller
1114 * must check for "Unknown" in the buffer to detect a failure.
1116 * Returns: size of formatted string.
1118 static ssize_t
1119 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1120 char *buf)
1122 struct Scsi_Host *shost = class_to_shost(dev);
1123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1124 struct lpfc_hba *phba = vport->phba;
1125 uint32_t cnt, acnt;
1127 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1128 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1129 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1133 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1134 * @dev: class device that is converted into a Scsi_host.
1135 * @attr: device attribute, not used.
1136 * @buf: text that must be interpreted to determine if npiv is supported.
1138 * Description:
1139 * Buffer will contain text indicating npiv is not suppoerted on the port,
1140 * the port is an NPIV physical port, or it is an npiv virtual port with
1141 * the id of the vport.
1143 * Returns: size of formatted string.
1145 static ssize_t
1146 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1147 char *buf)
1149 struct Scsi_Host *shost = class_to_shost(dev);
1150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1151 struct lpfc_hba *phba = vport->phba;
1153 if (!(phba->max_vpi))
1154 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1155 if (vport->port_type == LPFC_PHYSICAL_PORT)
1156 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1157 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1161 * lpfc_poll_show - Return text about poll support for the adapter
1162 * @dev: class device that is converted into a Scsi_host.
1163 * @attr: device attribute, not used.
1164 * @buf: on return contains the cfg_poll in hex.
1166 * Notes:
1167 * cfg_poll should be a lpfc_polling_flags type.
1169 * Returns: size of formatted string.
1171 static ssize_t
1172 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1173 char *buf)
1175 struct Scsi_Host *shost = class_to_shost(dev);
1176 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1177 struct lpfc_hba *phba = vport->phba;
1179 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1183 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1184 * @dev: class device that is converted into a Scsi_host.
1185 * @attr: device attribute, not used.
1186 * @buf: one or more lpfc_polling_flags values.
1187 * @count: not used.
1189 * Notes:
1190 * buf contents converted to integer and checked for a valid value.
1192 * Returns:
1193 * -EINVAL if the buffer connot be converted or is out of range
1194 * length of the buf on success
1196 static ssize_t
1197 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1198 const char *buf, size_t count)
1200 struct Scsi_Host *shost = class_to_shost(dev);
1201 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1202 struct lpfc_hba *phba = vport->phba;
1203 uint32_t creg_val;
1204 uint32_t old_val;
1205 int val=0;
1207 if (!isdigit(buf[0]))
1208 return -EINVAL;
1210 if (sscanf(buf, "%i", &val) != 1)
1211 return -EINVAL;
1213 if ((val & 0x3) != val)
1214 return -EINVAL;
1216 if (phba->sli_rev == LPFC_SLI_REV4)
1217 val = 0;
1219 spin_lock_irq(&phba->hbalock);
1221 old_val = phba->cfg_poll;
1223 if (val & ENABLE_FCP_RING_POLLING) {
1224 if ((val & DISABLE_FCP_RING_INT) &&
1225 !(old_val & DISABLE_FCP_RING_INT)) {
1226 creg_val = readl(phba->HCregaddr);
1227 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1228 writel(creg_val, phba->HCregaddr);
1229 readl(phba->HCregaddr); /* flush */
1231 lpfc_poll_start_timer(phba);
1233 } else if (val != 0x0) {
1234 spin_unlock_irq(&phba->hbalock);
1235 return -EINVAL;
1238 if (!(val & DISABLE_FCP_RING_INT) &&
1239 (old_val & DISABLE_FCP_RING_INT))
1241 spin_unlock_irq(&phba->hbalock);
1242 del_timer(&phba->fcp_poll_timer);
1243 spin_lock_irq(&phba->hbalock);
1244 creg_val = readl(phba->HCregaddr);
1245 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1246 writel(creg_val, phba->HCregaddr);
1247 readl(phba->HCregaddr); /* flush */
1250 phba->cfg_poll = val;
1252 spin_unlock_irq(&phba->hbalock);
1254 return strlen(buf);
1258 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1259 * @dev: class unused variable.
1260 * @attr: device attribute, not used.
1261 * @buf: on return contains the module description text.
1263 * Returns: size of formatted string.
1265 static ssize_t
1266 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1267 char *buf)
1269 struct Scsi_Host *shost = class_to_shost(dev);
1270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1271 struct lpfc_hba *phba = vport->phba;
1273 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1277 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1278 * @dev: class unused variable.
1279 * @attr: device attribute, not used.
1280 * @buf: on return contains the module description text.
1282 * Returns: size of formatted string.
1284 static ssize_t
1285 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1286 char *buf)
1288 struct Scsi_Host *shost = class_to_shost(dev);
1289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1290 struct lpfc_hba *phba = vport->phba;
1292 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1296 * lpfc_param_show - Return a cfg attribute value in decimal
1298 * Description:
1299 * Macro that given an attr e.g. hba_queue_depth expands
1300 * into a function with the name lpfc_hba_queue_depth_show.
1302 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1303 * @dev: class device that is converted into a Scsi_host.
1304 * @attr: device attribute, not used.
1305 * @buf: on return contains the attribute value in decimal.
1307 * Returns: size of formatted string.
1309 #define lpfc_param_show(attr) \
1310 static ssize_t \
1311 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1312 char *buf) \
1314 struct Scsi_Host *shost = class_to_shost(dev);\
1315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1316 struct lpfc_hba *phba = vport->phba;\
1317 uint val = 0;\
1318 val = phba->cfg_##attr;\
1319 return snprintf(buf, PAGE_SIZE, "%d\n",\
1320 phba->cfg_##attr);\
1324 * lpfc_param_hex_show - Return a cfg attribute value in hex
1326 * Description:
1327 * Macro that given an attr e.g. hba_queue_depth expands
1328 * into a function with the name lpfc_hba_queue_depth_show
1330 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1331 * @dev: class device that is converted into a Scsi_host.
1332 * @attr: device attribute, not used.
1333 * @buf: on return contains the attribute value in hexadecimal.
1335 * Returns: size of formatted string.
1337 #define lpfc_param_hex_show(attr) \
1338 static ssize_t \
1339 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1340 char *buf) \
1342 struct Scsi_Host *shost = class_to_shost(dev);\
1343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1344 struct lpfc_hba *phba = vport->phba;\
1345 uint val = 0;\
1346 val = phba->cfg_##attr;\
1347 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1348 phba->cfg_##attr);\
1352 * lpfc_param_init - Initializes a cfg attribute
1354 * Description:
1355 * Macro that given an attr e.g. hba_queue_depth expands
1356 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1357 * takes a default argument, a minimum and maximum argument.
1359 * lpfc_##attr##_init: Initializes an attribute.
1360 * @phba: pointer the the adapter structure.
1361 * @val: integer attribute value.
1363 * Validates the min and max values then sets the adapter config field
1364 * accordingly, or uses the default if out of range and prints an error message.
1366 * Returns:
1367 * zero on success
1368 * -EINVAL if default used
1370 #define lpfc_param_init(attr, default, minval, maxval) \
1371 static int \
1372 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1374 if (val >= minval && val <= maxval) {\
1375 phba->cfg_##attr = val;\
1376 return 0;\
1378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1379 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1380 "allowed range is ["#minval", "#maxval"]\n", val); \
1381 phba->cfg_##attr = default;\
1382 return -EINVAL;\
1386 * lpfc_param_set - Set a cfg attribute value
1388 * Description:
1389 * Macro that given an attr e.g. hba_queue_depth expands
1390 * into a function with the name lpfc_hba_queue_depth_set
1392 * lpfc_##attr##_set: Sets an attribute value.
1393 * @phba: pointer the the adapter structure.
1394 * @val: integer attribute value.
1396 * Description:
1397 * Validates the min and max values then sets the
1398 * adapter config field if in the valid range. prints error message
1399 * and does not set the parameter if invalid.
1401 * Returns:
1402 * zero on success
1403 * -EINVAL if val is invalid
1405 #define lpfc_param_set(attr, default, minval, maxval) \
1406 static int \
1407 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1409 if (val >= minval && val <= maxval) {\
1410 phba->cfg_##attr = val;\
1411 return 0;\
1413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1414 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1415 "allowed range is ["#minval", "#maxval"]\n", val); \
1416 return -EINVAL;\
1420 * lpfc_param_store - Set a vport attribute value
1422 * Description:
1423 * Macro that given an attr e.g. hba_queue_depth expands
1424 * into a function with the name lpfc_hba_queue_depth_store.
1426 * lpfc_##attr##_store: Set an sttribute value.
1427 * @dev: class device that is converted into a Scsi_host.
1428 * @attr: device attribute, not used.
1429 * @buf: contains the attribute value in ascii.
1430 * @count: not used.
1432 * Description:
1433 * Convert the ascii text number to an integer, then
1434 * use the lpfc_##attr##_set function to set the value.
1436 * Returns:
1437 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1438 * length of buffer upon success.
1440 #define lpfc_param_store(attr) \
1441 static ssize_t \
1442 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1443 const char *buf, size_t count) \
1445 struct Scsi_Host *shost = class_to_shost(dev);\
1446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1447 struct lpfc_hba *phba = vport->phba;\
1448 uint val = 0;\
1449 if (!isdigit(buf[0]))\
1450 return -EINVAL;\
1451 if (sscanf(buf, "%i", &val) != 1)\
1452 return -EINVAL;\
1453 if (lpfc_##attr##_set(phba, val) == 0) \
1454 return strlen(buf);\
1455 else \
1456 return -EINVAL;\
1460 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1462 * Description:
1463 * Macro that given an attr e.g. hba_queue_depth expands
1464 * into a function with the name lpfc_hba_queue_depth_show
1466 * lpfc_##attr##_show: prints the attribute value in decimal.
1467 * @dev: class device that is converted into a Scsi_host.
1468 * @attr: device attribute, not used.
1469 * @buf: on return contains the attribute value in decimal.
1471 * Returns: length of formatted string.
1473 #define lpfc_vport_param_show(attr) \
1474 static ssize_t \
1475 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1476 char *buf) \
1478 struct Scsi_Host *shost = class_to_shost(dev);\
1479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1480 uint val = 0;\
1481 val = vport->cfg_##attr;\
1482 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1486 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1488 * Description:
1489 * Macro that given an attr e.g.
1490 * hba_queue_depth expands into a function with the name
1491 * lpfc_hba_queue_depth_show
1493 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1494 * @dev: class device that is converted into a Scsi_host.
1495 * @attr: device attribute, not used.
1496 * @buf: on return contains the attribute value in hexadecimal.
1498 * Returns: length of formatted string.
1500 #define lpfc_vport_param_hex_show(attr) \
1501 static ssize_t \
1502 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1503 char *buf) \
1505 struct Scsi_Host *shost = class_to_shost(dev);\
1506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1507 uint val = 0;\
1508 val = vport->cfg_##attr;\
1509 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1513 * lpfc_vport_param_init - Initialize a vport cfg attribute
1515 * Description:
1516 * Macro that given an attr e.g. hba_queue_depth expands
1517 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1518 * takes a default argument, a minimum and maximum argument.
1520 * lpfc_##attr##_init: validates the min and max values then sets the
1521 * adapter config field accordingly, or uses the default if out of range
1522 * and prints an error message.
1523 * @phba: pointer the the adapter structure.
1524 * @val: integer attribute value.
1526 * Returns:
1527 * zero on success
1528 * -EINVAL if default used
1530 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1531 static int \
1532 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1534 if (val >= minval && val <= maxval) {\
1535 vport->cfg_##attr = val;\
1536 return 0;\
1538 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1539 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1540 "allowed range is ["#minval", "#maxval"]\n", val); \
1541 vport->cfg_##attr = default;\
1542 return -EINVAL;\
1546 * lpfc_vport_param_set - Set a vport cfg attribute
1548 * Description:
1549 * Macro that given an attr e.g. hba_queue_depth expands
1550 * into a function with the name lpfc_hba_queue_depth_set
1552 * lpfc_##attr##_set: validates the min and max values then sets the
1553 * adapter config field if in the valid range. prints error message
1554 * and does not set the parameter if invalid.
1555 * @phba: pointer the the adapter structure.
1556 * @val: integer attribute value.
1558 * Returns:
1559 * zero on success
1560 * -EINVAL if val is invalid
1562 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1563 static int \
1564 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1566 if (val >= minval && val <= maxval) {\
1567 vport->cfg_##attr = val;\
1568 return 0;\
1570 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1571 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1572 "allowed range is ["#minval", "#maxval"]\n", val); \
1573 return -EINVAL;\
1577 * lpfc_vport_param_store - Set a vport attribute
1579 * Description:
1580 * Macro that given an attr e.g. hba_queue_depth
1581 * expands into a function with the name lpfc_hba_queue_depth_store
1583 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1584 * use the lpfc_##attr##_set function to set the value.
1585 * @cdev: class device that is converted into a Scsi_host.
1586 * @buf: contains the attribute value in decimal.
1587 * @count: not used.
1589 * Returns:
1590 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1591 * length of buffer upon success.
1593 #define lpfc_vport_param_store(attr) \
1594 static ssize_t \
1595 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1596 const char *buf, size_t count) \
1598 struct Scsi_Host *shost = class_to_shost(dev);\
1599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1600 uint val = 0;\
1601 if (!isdigit(buf[0]))\
1602 return -EINVAL;\
1603 if (sscanf(buf, "%i", &val) != 1)\
1604 return -EINVAL;\
1605 if (lpfc_##attr##_set(vport, val) == 0) \
1606 return strlen(buf);\
1607 else \
1608 return -EINVAL;\
1612 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1613 static uint lpfc_##name = defval;\
1614 module_param(lpfc_##name, uint, 0);\
1615 MODULE_PARM_DESC(lpfc_##name, desc);\
1616 lpfc_param_init(name, defval, minval, maxval)
1618 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1619 static uint lpfc_##name = defval;\
1620 module_param(lpfc_##name, uint, 0);\
1621 MODULE_PARM_DESC(lpfc_##name, desc);\
1622 lpfc_param_show(name)\
1623 lpfc_param_init(name, defval, minval, maxval)\
1624 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1626 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1627 static uint lpfc_##name = defval;\
1628 module_param(lpfc_##name, uint, 0);\
1629 MODULE_PARM_DESC(lpfc_##name, desc);\
1630 lpfc_param_show(name)\
1631 lpfc_param_init(name, defval, minval, maxval)\
1632 lpfc_param_set(name, defval, minval, maxval)\
1633 lpfc_param_store(name)\
1634 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1635 lpfc_##name##_show, lpfc_##name##_store)
1637 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1638 static uint lpfc_##name = defval;\
1639 module_param(lpfc_##name, uint, 0);\
1640 MODULE_PARM_DESC(lpfc_##name, desc);\
1641 lpfc_param_hex_show(name)\
1642 lpfc_param_init(name, defval, minval, maxval)\
1643 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1645 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1646 static uint lpfc_##name = defval;\
1647 module_param(lpfc_##name, uint, 0);\
1648 MODULE_PARM_DESC(lpfc_##name, desc);\
1649 lpfc_param_hex_show(name)\
1650 lpfc_param_init(name, defval, minval, maxval)\
1651 lpfc_param_set(name, defval, minval, maxval)\
1652 lpfc_param_store(name)\
1653 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1654 lpfc_##name##_show, lpfc_##name##_store)
1656 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1657 static uint lpfc_##name = defval;\
1658 module_param(lpfc_##name, uint, 0);\
1659 MODULE_PARM_DESC(lpfc_##name, desc);\
1660 lpfc_vport_param_init(name, defval, minval, maxval)
1662 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1663 static uint lpfc_##name = defval;\
1664 module_param(lpfc_##name, uint, 0);\
1665 MODULE_PARM_DESC(lpfc_##name, desc);\
1666 lpfc_vport_param_show(name)\
1667 lpfc_vport_param_init(name, defval, minval, maxval)\
1668 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1670 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1671 static uint lpfc_##name = defval;\
1672 module_param(lpfc_##name, uint, 0);\
1673 MODULE_PARM_DESC(lpfc_##name, desc);\
1674 lpfc_vport_param_show(name)\
1675 lpfc_vport_param_init(name, defval, minval, maxval)\
1676 lpfc_vport_param_set(name, defval, minval, maxval)\
1677 lpfc_vport_param_store(name)\
1678 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1679 lpfc_##name##_show, lpfc_##name##_store)
1681 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1682 static uint lpfc_##name = defval;\
1683 module_param(lpfc_##name, uint, 0);\
1684 MODULE_PARM_DESC(lpfc_##name, desc);\
1685 lpfc_vport_param_hex_show(name)\
1686 lpfc_vport_param_init(name, defval, minval, maxval)\
1687 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1689 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1690 static uint lpfc_##name = defval;\
1691 module_param(lpfc_##name, uint, 0);\
1692 MODULE_PARM_DESC(lpfc_##name, desc);\
1693 lpfc_vport_param_hex_show(name)\
1694 lpfc_vport_param_init(name, defval, minval, maxval)\
1695 lpfc_vport_param_set(name, defval, minval, maxval)\
1696 lpfc_vport_param_store(name)\
1697 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1698 lpfc_##name##_show, lpfc_##name##_store)
1700 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1701 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1702 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1703 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1704 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1705 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1706 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1707 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1708 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1709 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1710 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1711 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1712 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1713 lpfc_link_state_store);
1714 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1715 lpfc_option_rom_version_show, NULL);
1716 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1717 lpfc_num_discovered_ports_show, NULL);
1718 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1719 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1720 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1721 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1722 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1723 lpfc_board_mode_show, lpfc_board_mode_store);
1724 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1725 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1726 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1727 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1728 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1729 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1730 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1731 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1732 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1733 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1734 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1737 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1740 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1741 * @dev: class device that is converted into a Scsi_host.
1742 * @attr: device attribute, not used.
1743 * @buf: containing the string lpfc_soft_wwn_key.
1744 * @count: must be size of lpfc_soft_wwn_key.
1746 * Returns:
1747 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1748 * length of buf indicates success
1750 static ssize_t
1751 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1752 const char *buf, size_t count)
1754 struct Scsi_Host *shost = class_to_shost(dev);
1755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1756 struct lpfc_hba *phba = vport->phba;
1757 unsigned int cnt = count;
1760 * We're doing a simple sanity check for soft_wwpn setting.
1761 * We require that the user write a specific key to enable
1762 * the soft_wwpn attribute to be settable. Once the attribute
1763 * is written, the enable key resets. If further updates are
1764 * desired, the key must be written again to re-enable the
1765 * attribute.
1767 * The "key" is not secret - it is a hardcoded string shown
1768 * here. The intent is to protect against the random user or
1769 * application that is just writing attributes.
1772 /* count may include a LF at end of string */
1773 if (buf[cnt-1] == '\n')
1774 cnt--;
1776 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1777 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1778 return -EINVAL;
1780 phba->soft_wwn_enable = 1;
1781 return count;
1783 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1784 lpfc_soft_wwn_enable_store);
1787 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1788 * @dev: class device that is converted into a Scsi_host.
1789 * @attr: device attribute, not used.
1790 * @buf: on return contains the wwpn in hexadecimal.
1792 * Returns: size of formatted string.
1794 static ssize_t
1795 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1796 char *buf)
1798 struct Scsi_Host *shost = class_to_shost(dev);
1799 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1800 struct lpfc_hba *phba = vport->phba;
1802 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1803 (unsigned long long)phba->cfg_soft_wwpn);
1807 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1808 * @dev class device that is converted into a Scsi_host.
1809 * @attr: device attribute, not used.
1810 * @buf: contains the wwpn in hexadecimal.
1811 * @count: number of wwpn bytes in buf
1813 * Returns:
1814 * -EACCES hba reset not enabled, adapter over temp
1815 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1816 * -EIO error taking adapter offline or online
1817 * value of count on success
1819 static ssize_t
1820 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1821 const char *buf, size_t count)
1823 struct Scsi_Host *shost = class_to_shost(dev);
1824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1825 struct lpfc_hba *phba = vport->phba;
1826 struct completion online_compl;
1827 int stat1=0, stat2=0;
1828 unsigned int i, j, cnt=count;
1829 u8 wwpn[8];
1830 int rc;
1832 if (!phba->cfg_enable_hba_reset)
1833 return -EACCES;
1834 spin_lock_irq(&phba->hbalock);
1835 if (phba->over_temp_state == HBA_OVER_TEMP) {
1836 spin_unlock_irq(&phba->hbalock);
1837 return -EACCES;
1839 spin_unlock_irq(&phba->hbalock);
1840 /* count may include a LF at end of string */
1841 if (buf[cnt-1] == '\n')
1842 cnt--;
1844 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1845 ((cnt == 17) && (*buf++ != 'x')) ||
1846 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1847 return -EINVAL;
1849 phba->soft_wwn_enable = 0;
1851 memset(wwpn, 0, sizeof(wwpn));
1853 /* Validate and store the new name */
1854 for (i=0, j=0; i < 16; i++) {
1855 int value;
1857 value = hex_to_bin(*buf++);
1858 if (value >= 0)
1859 j = (j << 4) | value;
1860 else
1861 return -EINVAL;
1862 if (i % 2) {
1863 wwpn[i/2] = j & 0xff;
1864 j = 0;
1867 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1868 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1869 if (phba->cfg_soft_wwnn)
1870 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1872 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1873 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1875 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1876 if (stat1)
1877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1878 "0463 lpfc_soft_wwpn attribute set failed to "
1879 "reinit adapter - %d\n", stat1);
1880 init_completion(&online_compl);
1881 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1882 LPFC_EVT_ONLINE);
1883 if (rc == 0)
1884 return -ENOMEM;
1886 wait_for_completion(&online_compl);
1887 if (stat2)
1888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1889 "0464 lpfc_soft_wwpn attribute set failed to "
1890 "reinit adapter - %d\n", stat2);
1891 return (stat1 || stat2) ? -EIO : count;
1893 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1894 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1897 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1898 * @dev: class device that is converted into a Scsi_host.
1899 * @attr: device attribute, not used.
1900 * @buf: on return contains the wwnn in hexadecimal.
1902 * Returns: size of formatted string.
1904 static ssize_t
1905 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1906 char *buf)
1908 struct Scsi_Host *shost = class_to_shost(dev);
1909 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1910 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1911 (unsigned long long)phba->cfg_soft_wwnn);
1915 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1916 * @cdev: class device that is converted into a Scsi_host.
1917 * @buf: contains the ww node name in hexadecimal.
1918 * @count: number of wwnn bytes in buf.
1920 * Returns:
1921 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1922 * value of count on success
1924 static ssize_t
1925 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1926 const char *buf, size_t count)
1928 struct Scsi_Host *shost = class_to_shost(dev);
1929 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1930 unsigned int i, j, cnt=count;
1931 u8 wwnn[8];
1933 /* count may include a LF at end of string */
1934 if (buf[cnt-1] == '\n')
1935 cnt--;
1937 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1938 ((cnt == 17) && (*buf++ != 'x')) ||
1939 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1940 return -EINVAL;
1943 * Allow wwnn to be set many times, as long as the enable is set.
1944 * However, once the wwpn is set, everything locks.
1947 memset(wwnn, 0, sizeof(wwnn));
1949 /* Validate and store the new name */
1950 for (i=0, j=0; i < 16; i++) {
1951 int value;
1953 value = hex_to_bin(*buf++);
1954 if (value >= 0)
1955 j = (j << 4) | value;
1956 else
1957 return -EINVAL;
1958 if (i % 2) {
1959 wwnn[i/2] = j & 0xff;
1960 j = 0;
1963 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1965 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1966 "lpfc%d: soft_wwnn set. Value will take effect upon "
1967 "setting of the soft_wwpn\n", phba->brd_no);
1969 return count;
1971 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1972 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1975 static int lpfc_poll = 0;
1976 module_param(lpfc_poll, int, 0);
1977 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1978 " 0 - none,"
1979 " 1 - poll with interrupts enabled"
1980 " 3 - poll and disable FCP ring interrupts");
1982 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1983 lpfc_poll_show, lpfc_poll_store);
1985 int lpfc_sli_mode = 0;
1986 module_param(lpfc_sli_mode, int, 0);
1987 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1988 " 0 - auto (SLI-3 if supported),"
1989 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1990 " 3 - select SLI-3");
1992 int lpfc_enable_npiv = 1;
1993 module_param(lpfc_enable_npiv, int, 0);
1994 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1995 lpfc_param_show(enable_npiv);
1996 lpfc_param_init(enable_npiv, 1, 0, 1);
1997 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
1999 int lpfc_enable_rrq;
2000 module_param(lpfc_enable_rrq, int, 0);
2001 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2002 lpfc_param_show(enable_rrq);
2003 lpfc_param_init(enable_rrq, 0, 0, 1);
2004 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2007 # lpfc_suppress_link_up: Bring link up at initialization
2008 # 0x0 = bring link up (issue MBX_INIT_LINK)
2009 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2010 # 0x2 = never bring up link
2011 # Default value is 0.
2013 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2014 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2015 "Suppress Link Up at initialization");
2017 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2018 # 1 - (1024)
2019 # 2 - (2048)
2020 # 3 - (3072)
2021 # 4 - (4096)
2022 # 5 - (5120)
2024 static ssize_t
2025 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2027 struct Scsi_Host *shost = class_to_shost(dev);
2028 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2030 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2033 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2034 lpfc_iocb_hw_show, NULL);
2035 static ssize_t
2036 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2038 struct Scsi_Host *shost = class_to_shost(dev);
2039 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2041 return snprintf(buf, PAGE_SIZE, "%d\n",
2042 phba->sli.ring[LPFC_ELS_RING].txq_max);
2045 static DEVICE_ATTR(txq_hw, S_IRUGO,
2046 lpfc_txq_hw_show, NULL);
2047 static ssize_t
2048 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2049 char *buf)
2051 struct Scsi_Host *shost = class_to_shost(dev);
2052 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2054 return snprintf(buf, PAGE_SIZE, "%d\n",
2055 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2058 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2059 lpfc_txcmplq_hw_show, NULL);
2061 int lpfc_iocb_cnt = 2;
2062 module_param(lpfc_iocb_cnt, int, 1);
2063 MODULE_PARM_DESC(lpfc_iocb_cnt,
2064 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2065 lpfc_param_show(iocb_cnt);
2066 lpfc_param_init(iocb_cnt, 2, 1, 5);
2067 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2068 lpfc_iocb_cnt_show, NULL);
2071 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2072 # until the timer expires. Value range is [0,255]. Default value is 30.
2074 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2075 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2076 module_param(lpfc_nodev_tmo, int, 0);
2077 MODULE_PARM_DESC(lpfc_nodev_tmo,
2078 "Seconds driver will hold I/O waiting "
2079 "for a device to come back");
2082 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2083 * @dev: class converted to a Scsi_host structure.
2084 * @attr: device attribute, not used.
2085 * @buf: on return contains the dev loss timeout in decimal.
2087 * Returns: size of formatted string.
2089 static ssize_t
2090 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2091 char *buf)
2093 struct Scsi_Host *shost = class_to_shost(dev);
2094 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2096 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2100 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2101 * @vport: lpfc vport structure pointer.
2102 * @val: contains the nodev timeout value.
2104 * Description:
2105 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2106 * a kernel error message is printed and zero is returned.
2107 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2108 * Otherwise nodev tmo is set to the default value.
2110 * Returns:
2111 * zero if already set or if val is in range
2112 * -EINVAL val out of range
2114 static int
2115 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2117 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2118 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2119 if (val != LPFC_DEF_DEVLOSS_TMO)
2120 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2121 "0407 Ignoring nodev_tmo module "
2122 "parameter because devloss_tmo is "
2123 "set.\n");
2124 return 0;
2127 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2128 vport->cfg_nodev_tmo = val;
2129 vport->cfg_devloss_tmo = val;
2130 return 0;
2132 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2133 "0400 lpfc_nodev_tmo attribute cannot be set to"
2134 " %d, allowed range is [%d, %d]\n",
2135 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2136 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2137 return -EINVAL;
2141 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2142 * @vport: lpfc vport structure pointer.
2144 * Description:
2145 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2147 static void
2148 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2150 struct Scsi_Host *shost;
2151 struct lpfc_nodelist *ndlp;
2153 shost = lpfc_shost_from_vport(vport);
2154 spin_lock_irq(shost->host_lock);
2155 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2156 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2157 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2158 spin_unlock_irq(shost->host_lock);
2162 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2163 * @vport: lpfc vport structure pointer.
2164 * @val: contains the tmo value.
2166 * Description:
2167 * If the devloss tmo is already set or the vport dev loss tmo has changed
2168 * then a kernel error message is printed and zero is returned.
2169 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2170 * Otherwise nodev tmo is set to the default value.
2172 * Returns:
2173 * zero if already set or if val is in range
2174 * -EINVAL val out of range
2176 static int
2177 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2179 if (vport->dev_loss_tmo_changed ||
2180 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2182 "0401 Ignoring change to nodev_tmo "
2183 "because devloss_tmo is set.\n");
2184 return 0;
2186 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2187 vport->cfg_nodev_tmo = val;
2188 vport->cfg_devloss_tmo = val;
2190 * For compat: set the fc_host dev loss so new rports
2191 * will get the value.
2193 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2194 lpfc_update_rport_devloss_tmo(vport);
2195 return 0;
2197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2198 "0403 lpfc_nodev_tmo attribute cannot be set to"
2199 "%d, allowed range is [%d, %d]\n",
2200 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2201 return -EINVAL;
2204 lpfc_vport_param_store(nodev_tmo)
2206 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2207 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2210 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2211 # disappear until the timer expires. Value range is [0,255]. Default
2212 # value is 30.
2214 module_param(lpfc_devloss_tmo, int, 0);
2215 MODULE_PARM_DESC(lpfc_devloss_tmo,
2216 "Seconds driver will hold I/O waiting "
2217 "for a device to come back");
2218 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2219 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2220 lpfc_vport_param_show(devloss_tmo)
2223 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2224 * @vport: lpfc vport structure pointer.
2225 * @val: contains the tmo value.
2227 * Description:
2228 * If val is in a valid range then set the vport nodev tmo,
2229 * devloss tmo, also set the vport dev loss tmo changed flag.
2230 * Else a kernel error message is printed.
2232 * Returns:
2233 * zero if val is in range
2234 * -EINVAL val out of range
2236 static int
2237 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2239 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2240 vport->cfg_nodev_tmo = val;
2241 vport->cfg_devloss_tmo = val;
2242 vport->dev_loss_tmo_changed = 1;
2243 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2244 lpfc_update_rport_devloss_tmo(vport);
2245 return 0;
2248 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2249 "0404 lpfc_devloss_tmo attribute cannot be set to"
2250 " %d, allowed range is [%d, %d]\n",
2251 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2252 return -EINVAL;
2255 lpfc_vport_param_store(devloss_tmo)
2256 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2257 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2260 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2261 # deluged with LOTS of information.
2262 # You can set a bit mask to record specific types of verbose messages:
2263 # See lpfc_logmsh.h for definitions.
2265 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2266 "Verbose logging bit-mask");
2269 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2270 # objects that have been registered with the nameserver after login.
2272 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2273 "Deregister nameserver objects before LOGO");
2276 # lun_queue_depth: This parameter is used to limit the number of outstanding
2277 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2279 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2280 "Max number of FCP commands we can queue to a specific LUN");
2283 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2284 # commands per target port. Value range is [10,65535]. Default value is 65535.
2286 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2287 "Max number of FCP commands we can queue to a specific target port");
2290 # hba_queue_depth: This parameter is used to limit the number of outstanding
2291 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2292 # value is greater than the maximum number of exchanges supported by the HBA,
2293 # then maximum number of exchanges supported by the HBA is used to determine
2294 # the hba_queue_depth.
2296 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2297 "Max number of FCP commands we can queue to a lpfc HBA");
2300 # peer_port_login: This parameter allows/prevents logins
2301 # between peer ports hosted on the same physical port.
2302 # When this parameter is set 0 peer ports of same physical port
2303 # are not allowed to login to each other.
2304 # When this parameter is set 1 peer ports of same physical port
2305 # are allowed to login to each other.
2306 # Default value of this parameter is 0.
2308 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2309 "Allow peer ports on the same physical port to login to each "
2310 "other.");
2313 # restrict_login: This parameter allows/prevents logins
2314 # between Virtual Ports and remote initiators.
2315 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2316 # other initiators and will attempt to PLOGI all remote ports.
2317 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2318 # remote ports and will not attempt to PLOGI to other initiators.
2319 # This parameter does not restrict to the physical port.
2320 # This parameter does not restrict logins to Fabric resident remote ports.
2321 # Default value of this parameter is 1.
2323 static int lpfc_restrict_login = 1;
2324 module_param(lpfc_restrict_login, int, 0);
2325 MODULE_PARM_DESC(lpfc_restrict_login,
2326 "Restrict virtual ports login to remote initiators.");
2327 lpfc_vport_param_show(restrict_login);
2330 * lpfc_restrict_login_init - Set the vport restrict login flag
2331 * @vport: lpfc vport structure pointer.
2332 * @val: contains the restrict login value.
2334 * Description:
2335 * If val is not in a valid range then log a kernel error message and set
2336 * the vport restrict login to one.
2337 * If the port type is physical clear the restrict login flag and return.
2338 * Else set the restrict login flag to val.
2340 * Returns:
2341 * zero if val is in range
2342 * -EINVAL val out of range
2344 static int
2345 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2347 if (val < 0 || val > 1) {
2348 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2349 "0422 lpfc_restrict_login attribute cannot "
2350 "be set to %d, allowed range is [0, 1]\n",
2351 val);
2352 vport->cfg_restrict_login = 1;
2353 return -EINVAL;
2355 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2356 vport->cfg_restrict_login = 0;
2357 return 0;
2359 vport->cfg_restrict_login = val;
2360 return 0;
2364 * lpfc_restrict_login_set - Set the vport restrict login flag
2365 * @vport: lpfc vport structure pointer.
2366 * @val: contains the restrict login value.
2368 * Description:
2369 * If val is not in a valid range then log a kernel error message and set
2370 * the vport restrict login to one.
2371 * If the port type is physical and the val is not zero log a kernel
2372 * error message, clear the restrict login flag and return zero.
2373 * Else set the restrict login flag to val.
2375 * Returns:
2376 * zero if val is in range
2377 * -EINVAL val out of range
2379 static int
2380 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2382 if (val < 0 || val > 1) {
2383 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2384 "0425 lpfc_restrict_login attribute cannot "
2385 "be set to %d, allowed range is [0, 1]\n",
2386 val);
2387 vport->cfg_restrict_login = 1;
2388 return -EINVAL;
2390 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2391 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2392 "0468 lpfc_restrict_login must be 0 for "
2393 "Physical ports.\n");
2394 vport->cfg_restrict_login = 0;
2395 return 0;
2397 vport->cfg_restrict_login = val;
2398 return 0;
2400 lpfc_vport_param_store(restrict_login);
2401 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2402 lpfc_restrict_login_show, lpfc_restrict_login_store);
2405 # Some disk devices have a "select ID" or "select Target" capability.
2406 # From a protocol standpoint "select ID" usually means select the
2407 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2408 # annex" which contains a table that maps a "select ID" (a number
2409 # between 0 and 7F) to an ALPA. By default, for compatibility with
2410 # older drivers, the lpfc driver scans this table from low ALPA to high
2411 # ALPA.
2413 # Turning on the scan-down variable (on = 1, off = 0) will
2414 # cause the lpfc driver to use an inverted table, effectively
2415 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2417 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2418 # and will not work across a fabric. Also this parameter will take
2419 # effect only in the case when ALPA map is not available.)
2421 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2422 "Start scanning for devices from highest ALPA to lowest");
2425 # lpfc_topology: link topology for init link
2426 # 0x0 = attempt loop mode then point-to-point
2427 # 0x01 = internal loopback mode
2428 # 0x02 = attempt point-to-point mode only
2429 # 0x04 = attempt loop mode only
2430 # 0x06 = attempt point-to-point mode then loop
2431 # Set point-to-point mode if you want to run as an N_Port.
2432 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2433 # Default value is 0.
2437 * lpfc_topology_set - Set the adapters topology field
2438 * @phba: lpfc_hba pointer.
2439 * @val: topology value.
2441 * Description:
2442 * If val is in a valid range then set the adapter's topology field and
2443 * issue a lip; if the lip fails reset the topology to the old value.
2445 * If the value is not in range log a kernel error message and return an error.
2447 * Returns:
2448 * zero if val is in range and lip okay
2449 * non-zero return value from lpfc_issue_lip()
2450 * -EINVAL val out of range
2452 static ssize_t
2453 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2454 const char *buf, size_t count)
2456 struct Scsi_Host *shost = class_to_shost(dev);
2457 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2458 struct lpfc_hba *phba = vport->phba;
2459 int val = 0;
2460 int nolip = 0;
2461 const char *val_buf = buf;
2462 int err;
2463 uint32_t prev_val;
2465 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2466 nolip = 1;
2467 val_buf = &buf[strlen("nolip ")];
2470 if (!isdigit(val_buf[0]))
2471 return -EINVAL;
2472 if (sscanf(val_buf, "%i", &val) != 1)
2473 return -EINVAL;
2475 if (val >= 0 && val <= 6) {
2476 prev_val = phba->cfg_topology;
2477 phba->cfg_topology = val;
2478 if (nolip)
2479 return strlen(buf);
2481 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2482 if (err) {
2483 phba->cfg_topology = prev_val;
2484 return -EINVAL;
2485 } else
2486 return strlen(buf);
2488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2489 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2490 "allowed range is [0, 6]\n",
2491 phba->brd_no, val);
2492 return -EINVAL;
2494 static int lpfc_topology = 0;
2495 module_param(lpfc_topology, int, 0);
2496 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2497 lpfc_param_show(topology)
2498 lpfc_param_init(topology, 0, 0, 6)
2499 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2500 lpfc_topology_show, lpfc_topology_store);
2503 * lpfc_static_vport_show: Read callback function for
2504 * lpfc_static_vport sysfs file.
2505 * @dev: Pointer to class device object.
2506 * @attr: device attribute structure.
2507 * @buf: Data buffer.
2509 * This function is the read call back function for
2510 * lpfc_static_vport sysfs file. The lpfc_static_vport
2511 * sysfs file report the mageability of the vport.
2513 static ssize_t
2514 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2515 char *buf)
2517 struct Scsi_Host *shost = class_to_shost(dev);
2518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2519 if (vport->vport_flag & STATIC_VPORT)
2520 sprintf(buf, "1\n");
2521 else
2522 sprintf(buf, "0\n");
2524 return strlen(buf);
2528 * Sysfs attribute to control the statistical data collection.
2530 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2531 lpfc_static_vport_show, NULL);
2534 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2535 * @dev: Pointer to class device.
2536 * @buf: Data buffer.
2537 * @count: Size of the data buffer.
2539 * This function get called when an user write to the lpfc_stat_data_ctrl
2540 * sysfs file. This function parse the command written to the sysfs file
2541 * and take appropriate action. These commands are used for controlling
2542 * driver statistical data collection.
2543 * Following are the command this function handles.
2545 * setbucket <bucket_type> <base> <step>
2546 * = Set the latency buckets.
2547 * destroybucket = destroy all the buckets.
2548 * start = start data collection
2549 * stop = stop data collection
2550 * reset = reset the collected data
2552 static ssize_t
2553 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2554 const char *buf, size_t count)
2556 struct Scsi_Host *shost = class_to_shost(dev);
2557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2558 struct lpfc_hba *phba = vport->phba;
2559 #define LPFC_MAX_DATA_CTRL_LEN 1024
2560 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2561 unsigned long i;
2562 char *str_ptr, *token;
2563 struct lpfc_vport **vports;
2564 struct Scsi_Host *v_shost;
2565 char *bucket_type_str, *base_str, *step_str;
2566 unsigned long base, step, bucket_type;
2568 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2569 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2570 return -EINVAL;
2572 strcpy(bucket_data, buf);
2573 str_ptr = &bucket_data[0];
2574 /* Ignore this token - this is command token */
2575 token = strsep(&str_ptr, "\t ");
2576 if (!token)
2577 return -EINVAL;
2579 bucket_type_str = strsep(&str_ptr, "\t ");
2580 if (!bucket_type_str)
2581 return -EINVAL;
2583 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2584 bucket_type = LPFC_LINEAR_BUCKET;
2585 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2586 bucket_type = LPFC_POWER2_BUCKET;
2587 else
2588 return -EINVAL;
2590 base_str = strsep(&str_ptr, "\t ");
2591 if (!base_str)
2592 return -EINVAL;
2593 base = simple_strtoul(base_str, NULL, 0);
2595 step_str = strsep(&str_ptr, "\t ");
2596 if (!step_str)
2597 return -EINVAL;
2598 step = simple_strtoul(step_str, NULL, 0);
2599 if (!step)
2600 return -EINVAL;
2602 /* Block the data collection for every vport */
2603 vports = lpfc_create_vport_work_array(phba);
2604 if (vports == NULL)
2605 return -ENOMEM;
2607 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2608 v_shost = lpfc_shost_from_vport(vports[i]);
2609 spin_lock_irq(v_shost->host_lock);
2610 /* Block and reset data collection */
2611 vports[i]->stat_data_blocked = 1;
2612 if (vports[i]->stat_data_enabled)
2613 lpfc_vport_reset_stat_data(vports[i]);
2614 spin_unlock_irq(v_shost->host_lock);
2617 /* Set the bucket attributes */
2618 phba->bucket_type = bucket_type;
2619 phba->bucket_base = base;
2620 phba->bucket_step = step;
2622 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2623 v_shost = lpfc_shost_from_vport(vports[i]);
2625 /* Unblock data collection */
2626 spin_lock_irq(v_shost->host_lock);
2627 vports[i]->stat_data_blocked = 0;
2628 spin_unlock_irq(v_shost->host_lock);
2630 lpfc_destroy_vport_work_array(phba, vports);
2631 return strlen(buf);
2634 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2635 vports = lpfc_create_vport_work_array(phba);
2636 if (vports == NULL)
2637 return -ENOMEM;
2639 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2640 v_shost = lpfc_shost_from_vport(vports[i]);
2641 spin_lock_irq(shost->host_lock);
2642 vports[i]->stat_data_blocked = 1;
2643 lpfc_free_bucket(vport);
2644 vport->stat_data_enabled = 0;
2645 vports[i]->stat_data_blocked = 0;
2646 spin_unlock_irq(shost->host_lock);
2648 lpfc_destroy_vport_work_array(phba, vports);
2649 phba->bucket_type = LPFC_NO_BUCKET;
2650 phba->bucket_base = 0;
2651 phba->bucket_step = 0;
2652 return strlen(buf);
2655 if (!strncmp(buf, "start", strlen("start"))) {
2656 /* If no buckets configured return error */
2657 if (phba->bucket_type == LPFC_NO_BUCKET)
2658 return -EINVAL;
2659 spin_lock_irq(shost->host_lock);
2660 if (vport->stat_data_enabled) {
2661 spin_unlock_irq(shost->host_lock);
2662 return strlen(buf);
2664 lpfc_alloc_bucket(vport);
2665 vport->stat_data_enabled = 1;
2666 spin_unlock_irq(shost->host_lock);
2667 return strlen(buf);
2670 if (!strncmp(buf, "stop", strlen("stop"))) {
2671 spin_lock_irq(shost->host_lock);
2672 if (vport->stat_data_enabled == 0) {
2673 spin_unlock_irq(shost->host_lock);
2674 return strlen(buf);
2676 lpfc_free_bucket(vport);
2677 vport->stat_data_enabled = 0;
2678 spin_unlock_irq(shost->host_lock);
2679 return strlen(buf);
2682 if (!strncmp(buf, "reset", strlen("reset"))) {
2683 if ((phba->bucket_type == LPFC_NO_BUCKET)
2684 || !vport->stat_data_enabled)
2685 return strlen(buf);
2686 spin_lock_irq(shost->host_lock);
2687 vport->stat_data_blocked = 1;
2688 lpfc_vport_reset_stat_data(vport);
2689 vport->stat_data_blocked = 0;
2690 spin_unlock_irq(shost->host_lock);
2691 return strlen(buf);
2693 return -EINVAL;
2698 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2699 * @dev: Pointer to class device object.
2700 * @buf: Data buffer.
2702 * This function is the read call back function for
2703 * lpfc_stat_data_ctrl sysfs file. This function report the
2704 * current statistical data collection state.
2706 static ssize_t
2707 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2708 char *buf)
2710 struct Scsi_Host *shost = class_to_shost(dev);
2711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2712 struct lpfc_hba *phba = vport->phba;
2713 int index = 0;
2714 int i;
2715 char *bucket_type;
2716 unsigned long bucket_value;
2718 switch (phba->bucket_type) {
2719 case LPFC_LINEAR_BUCKET:
2720 bucket_type = "linear";
2721 break;
2722 case LPFC_POWER2_BUCKET:
2723 bucket_type = "power2";
2724 break;
2725 default:
2726 bucket_type = "No Bucket";
2727 break;
2730 sprintf(&buf[index], "Statistical Data enabled :%d, "
2731 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2732 " Bucket step :%d\nLatency Ranges :",
2733 vport->stat_data_enabled, vport->stat_data_blocked,
2734 bucket_type, phba->bucket_base, phba->bucket_step);
2735 index = strlen(buf);
2736 if (phba->bucket_type != LPFC_NO_BUCKET) {
2737 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2738 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2739 bucket_value = phba->bucket_base +
2740 phba->bucket_step * i;
2741 else
2742 bucket_value = phba->bucket_base +
2743 (1 << i) * phba->bucket_step;
2745 if (index + 10 > PAGE_SIZE)
2746 break;
2747 sprintf(&buf[index], "%08ld ", bucket_value);
2748 index = strlen(buf);
2751 sprintf(&buf[index], "\n");
2752 return strlen(buf);
2756 * Sysfs attribute to control the statistical data collection.
2758 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2759 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2762 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2766 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2767 * for each target.
2769 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2770 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2771 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2775 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2776 * @filp: sysfs file
2777 * @kobj: Pointer to the kernel object
2778 * @bin_attr: Attribute object
2779 * @buff: Buffer pointer
2780 * @off: File offset
2781 * @count: Buffer size
2783 * This function is the read call back function for lpfc_drvr_stat_data
2784 * sysfs file. This function export the statistical data to user
2785 * applications.
2787 static ssize_t
2788 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2789 struct bin_attribute *bin_attr,
2790 char *buf, loff_t off, size_t count)
2792 struct device *dev = container_of(kobj, struct device,
2793 kobj);
2794 struct Scsi_Host *shost = class_to_shost(dev);
2795 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2796 struct lpfc_hba *phba = vport->phba;
2797 int i = 0, index = 0;
2798 unsigned long nport_index;
2799 struct lpfc_nodelist *ndlp = NULL;
2800 nport_index = (unsigned long)off /
2801 MAX_STAT_DATA_SIZE_PER_TARGET;
2803 if (!vport->stat_data_enabled || vport->stat_data_blocked
2804 || (phba->bucket_type == LPFC_NO_BUCKET))
2805 return 0;
2807 spin_lock_irq(shost->host_lock);
2808 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2809 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2810 continue;
2812 if (nport_index > 0) {
2813 nport_index--;
2814 continue;
2817 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2818 > count)
2819 break;
2821 if (!ndlp->lat_data)
2822 continue;
2824 /* Print the WWN */
2825 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2826 ndlp->nlp_portname.u.wwn[0],
2827 ndlp->nlp_portname.u.wwn[1],
2828 ndlp->nlp_portname.u.wwn[2],
2829 ndlp->nlp_portname.u.wwn[3],
2830 ndlp->nlp_portname.u.wwn[4],
2831 ndlp->nlp_portname.u.wwn[5],
2832 ndlp->nlp_portname.u.wwn[6],
2833 ndlp->nlp_portname.u.wwn[7]);
2835 index = strlen(buf);
2837 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2838 sprintf(&buf[index], "%010u,",
2839 ndlp->lat_data[i].cmd_count);
2840 index = strlen(buf);
2842 sprintf(&buf[index], "\n");
2843 index = strlen(buf);
2845 spin_unlock_irq(shost->host_lock);
2846 return index;
2849 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2850 .attr = {
2851 .name = "lpfc_drvr_stat_data",
2852 .mode = S_IRUSR,
2854 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2855 .read = sysfs_drvr_stat_data_read,
2856 .write = NULL,
2860 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2861 # connection.
2862 # Value range is [0,16]. Default value is 0.
2865 * lpfc_link_speed_set - Set the adapters link speed
2866 * @phba: lpfc_hba pointer.
2867 * @val: link speed value.
2869 * Description:
2870 * If val is in a valid range then set the adapter's link speed field and
2871 * issue a lip; if the lip fails reset the link speed to the old value.
2873 * Notes:
2874 * If the value is not in range log a kernel error message and return an error.
2876 * Returns:
2877 * zero if val is in range and lip okay.
2878 * non-zero return value from lpfc_issue_lip()
2879 * -EINVAL val out of range
2881 static ssize_t
2882 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2883 const char *buf, size_t count)
2885 struct Scsi_Host *shost = class_to_shost(dev);
2886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2887 struct lpfc_hba *phba = vport->phba;
2888 int val = LPFC_USER_LINK_SPEED_AUTO;
2889 int nolip = 0;
2890 const char *val_buf = buf;
2891 int err;
2892 uint32_t prev_val;
2894 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2895 nolip = 1;
2896 val_buf = &buf[strlen("nolip ")];
2899 if (!isdigit(val_buf[0]))
2900 return -EINVAL;
2901 if (sscanf(val_buf, "%i", &val) != 1)
2902 return -EINVAL;
2904 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2905 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2906 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2907 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2908 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2909 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2911 "2879 lpfc_link_speed attribute cannot be set "
2912 "to %d. Speed is not supported by this port.\n",
2913 val);
2914 return -EINVAL;
2916 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2917 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2918 prev_val = phba->cfg_link_speed;
2919 phba->cfg_link_speed = val;
2920 if (nolip)
2921 return strlen(buf);
2923 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2924 if (err) {
2925 phba->cfg_link_speed = prev_val;
2926 return -EINVAL;
2927 } else
2928 return strlen(buf);
2930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2931 "0469 lpfc_link_speed attribute cannot be set to %d, "
2932 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
2933 return -EINVAL;
2936 static int lpfc_link_speed = 0;
2937 module_param(lpfc_link_speed, int, 0);
2938 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2939 lpfc_param_show(link_speed)
2942 * lpfc_link_speed_init - Set the adapters link speed
2943 * @phba: lpfc_hba pointer.
2944 * @val: link speed value.
2946 * Description:
2947 * If val is in a valid range then set the adapter's link speed field.
2949 * Notes:
2950 * If the value is not in range log a kernel error message, clear the link
2951 * speed and return an error.
2953 * Returns:
2954 * zero if val saved.
2955 * -EINVAL val out of range
2957 static int
2958 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2960 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2961 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2962 phba->cfg_link_speed = val;
2963 return 0;
2965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2966 "0405 lpfc_link_speed attribute cannot "
2967 "be set to %d, allowed values are "
2968 "["LPFC_LINK_SPEED_STRING"]\n", val);
2969 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
2970 return -EINVAL;
2973 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2974 lpfc_link_speed_show, lpfc_link_speed_store);
2977 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2978 # 0 = aer disabled or not supported
2979 # 1 = aer supported and enabled (default)
2980 # Value range is [0,1]. Default value is 1.
2984 * lpfc_aer_support_store - Set the adapter for aer support
2986 * @dev: class device that is converted into a Scsi_host.
2987 * @attr: device attribute, not used.
2988 * @buf: containing the string "selective".
2989 * @count: unused variable.
2991 * Description:
2992 * If the val is 1 and currently the device's AER capability was not
2993 * enabled, invoke the kernel's enable AER helper routine, trying to
2994 * enable the device's AER capability. If the helper routine enabling
2995 * AER returns success, update the device's cfg_aer_support flag to
2996 * indicate AER is supported by the device; otherwise, if the device
2997 * AER capability is already enabled to support AER, then do nothing.
2999 * If the val is 0 and currently the device's AER support was enabled,
3000 * invoke the kernel's disable AER helper routine. After that, update
3001 * the device's cfg_aer_support flag to indicate AER is not supported
3002 * by the device; otherwise, if the device AER capability is already
3003 * disabled from supporting AER, then do nothing.
3005 * Returns:
3006 * length of the buf on success if val is in range the intended mode
3007 * is supported.
3008 * -EINVAL if val out of range or intended mode is not supported.
3010 static ssize_t
3011 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3012 const char *buf, size_t count)
3014 struct Scsi_Host *shost = class_to_shost(dev);
3015 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3016 struct lpfc_hba *phba = vport->phba;
3017 int val = 0, rc = -EINVAL;
3019 if (!isdigit(buf[0]))
3020 return -EINVAL;
3021 if (sscanf(buf, "%i", &val) != 1)
3022 return -EINVAL;
3024 switch (val) {
3025 case 0:
3026 if (phba->hba_flag & HBA_AER_ENABLED) {
3027 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3028 if (!rc) {
3029 spin_lock_irq(&phba->hbalock);
3030 phba->hba_flag &= ~HBA_AER_ENABLED;
3031 spin_unlock_irq(&phba->hbalock);
3032 phba->cfg_aer_support = 0;
3033 rc = strlen(buf);
3034 } else
3035 rc = -EPERM;
3036 } else {
3037 phba->cfg_aer_support = 0;
3038 rc = strlen(buf);
3040 break;
3041 case 1:
3042 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3043 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3044 if (!rc) {
3045 spin_lock_irq(&phba->hbalock);
3046 phba->hba_flag |= HBA_AER_ENABLED;
3047 spin_unlock_irq(&phba->hbalock);
3048 phba->cfg_aer_support = 1;
3049 rc = strlen(buf);
3050 } else
3051 rc = -EPERM;
3052 } else {
3053 phba->cfg_aer_support = 1;
3054 rc = strlen(buf);
3056 break;
3057 default:
3058 rc = -EINVAL;
3059 break;
3061 return rc;
3064 static int lpfc_aer_support = 1;
3065 module_param(lpfc_aer_support, int, 1);
3066 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3067 lpfc_param_show(aer_support)
3070 * lpfc_aer_support_init - Set the initial adapters aer support flag
3071 * @phba: lpfc_hba pointer.
3072 * @val: link speed value.
3074 * Description:
3075 * If val is in a valid range [0,1], then set the adapter's initial
3076 * cfg_aer_support field. It will be up to the driver's probe_one
3077 * routine to determine whether the device's AER support can be set
3078 * or not.
3080 * Notes:
3081 * If the value is not in range log a kernel error message, and
3082 * choose the default value of setting AER support and return.
3084 * Returns:
3085 * zero if val saved.
3086 * -EINVAL val out of range
3088 static int
3089 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3091 if (val == 0 || val == 1) {
3092 phba->cfg_aer_support = val;
3093 return 0;
3095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3096 "2712 lpfc_aer_support attribute value %d out "
3097 "of range, allowed values are 0|1, setting it "
3098 "to default value of 1\n", val);
3099 /* By default, try to enable AER on a device */
3100 phba->cfg_aer_support = 1;
3101 return -EINVAL;
3104 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3105 lpfc_aer_support_show, lpfc_aer_support_store);
3108 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3109 * @dev: class device that is converted into a Scsi_host.
3110 * @attr: device attribute, not used.
3111 * @buf: containing the string "selective".
3112 * @count: unused variable.
3114 * Description:
3115 * If the @buf contains 1 and the device currently has the AER support
3116 * enabled, then invokes the kernel AER helper routine
3117 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3118 * error status register.
3120 * Notes:
3122 * Returns:
3123 * -EINVAL if the buf does not contain the 1 or the device is not currently
3124 * enabled with the AER support.
3126 static ssize_t
3127 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3128 const char *buf, size_t count)
3130 struct Scsi_Host *shost = class_to_shost(dev);
3131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3132 struct lpfc_hba *phba = vport->phba;
3133 int val, rc = -1;
3135 if (!isdigit(buf[0]))
3136 return -EINVAL;
3137 if (sscanf(buf, "%i", &val) != 1)
3138 return -EINVAL;
3139 if (val != 1)
3140 return -EINVAL;
3142 if (phba->hba_flag & HBA_AER_ENABLED)
3143 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3145 if (rc == 0)
3146 return strlen(buf);
3147 else
3148 return -EPERM;
3151 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3152 lpfc_aer_cleanup_state);
3155 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3156 # Value range is [2,3]. Default value is 3.
3158 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3159 "Select Fibre Channel class of service for FCP sequences");
3162 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3163 # is [0,1]. Default value is 0.
3165 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3166 "Use ADISC on rediscovery to authenticate FCP devices");
3169 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3170 # depth. Default value is 0. When the value of this parameter is zero the
3171 # SCSI command completion time is not used for controlling I/O queue depth. When
3172 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3173 # to limit the I/O completion time to the parameter value.
3174 # The value is set in milliseconds.
3176 static int lpfc_max_scsicmpl_time;
3177 module_param(lpfc_max_scsicmpl_time, int, 0);
3178 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3179 "Use command completion time to control queue depth");
3180 lpfc_vport_param_show(max_scsicmpl_time);
3181 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3182 static int
3183 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3185 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3186 struct lpfc_nodelist *ndlp, *next_ndlp;
3188 if (val == vport->cfg_max_scsicmpl_time)
3189 return 0;
3190 if ((val < 0) || (val > 60000))
3191 return -EINVAL;
3192 vport->cfg_max_scsicmpl_time = val;
3194 spin_lock_irq(shost->host_lock);
3195 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3196 if (!NLP_CHK_NODE_ACT(ndlp))
3197 continue;
3198 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3199 continue;
3200 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3202 spin_unlock_irq(shost->host_lock);
3203 return 0;
3205 lpfc_vport_param_store(max_scsicmpl_time);
3206 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3207 lpfc_max_scsicmpl_time_show,
3208 lpfc_max_scsicmpl_time_store);
3211 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3212 # range is [0,1]. Default value is 0.
3214 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3217 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3218 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3219 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3220 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3221 # cr_delay is set to 0.
3223 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3224 "interrupt response is generated");
3226 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3227 "interrupt response is generated");
3230 # lpfc_multi_ring_support: Determines how many rings to spread available
3231 # cmd/rsp IOCB entries across.
3232 # Value range is [1,2]. Default value is 1.
3234 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3235 "SLI rings to spread IOCB entries across");
3238 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3239 # identifies what rctl value to configure the additional ring for.
3240 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3242 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3243 255, "Identifies RCTL for additional ring configuration");
3246 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3247 # identifies what type value to configure the additional ring for.
3248 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3250 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3251 255, "Identifies TYPE for additional ring configuration");
3254 # lpfc_fdmi_on: controls FDMI support.
3255 # 0 = no FDMI support
3256 # 1 = support FDMI without attribute of hostname
3257 # 2 = support FDMI with attribute of hostname
3258 # Value range [0,2]. Default value is 0.
3260 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3263 # Specifies the maximum number of ELS cmds we can have outstanding (for
3264 # discovery). Value range is [1,64]. Default value = 32.
3266 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3267 "during discovery");
3270 # lpfc_max_luns: maximum allowed LUN.
3271 # Value range is [0,65535]. Default value is 255.
3272 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3274 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3277 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3278 # Value range is [1,255], default value is 10.
3280 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3281 "Milliseconds driver will wait between polling FCP ring");
3284 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3285 # support this feature
3286 # 0 = MSI disabled
3287 # 1 = MSI enabled
3288 # 2 = MSI-X enabled (default)
3289 # Value range is [0,2]. Default value is 2.
3291 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3292 "MSI-X (2), if possible");
3295 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3297 # Value range is [636,651042]. Default value is 10000.
3299 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3300 "Set the maximum number of fast-path FCP interrupts per second");
3303 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3305 # Value range is [1,31]. Default value is 4.
3307 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3308 "Set the number of fast-path FCP work queues, if possible");
3311 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3313 # Value range is [1,7]. Default value is 1.
3315 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3316 "Set the number of fast-path FCP event queues, if possible");
3319 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3320 # 0 = HBA resets disabled
3321 # 1 = HBA resets enabled (default)
3322 # Value range is [0,1]. Default value is 1.
3324 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3327 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3328 # 0 = HBA Heartbeat disabled
3329 # 1 = HBA Heartbeat enabled (default)
3330 # Value range is [0,1]. Default value is 1.
3332 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3335 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3336 # 0 = BlockGuard disabled (default)
3337 # 1 = BlockGuard enabled
3338 # Value range is [0,1]. Default value is 0.
3340 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3343 # lpfc_prot_mask: i
3344 # - Bit mask of host protection capabilities used to register with the
3345 # SCSI mid-layer
3346 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3347 # - Allows you to ultimately specify which profiles to use
3348 # - Default will result in registering capabilities for all profiles.
3351 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3353 module_param(lpfc_prot_mask, uint, 0);
3354 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3357 # lpfc_prot_guard: i
3358 # - Bit mask of protection guard types to register with the SCSI mid-layer
3359 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3360 # - Allows you to ultimately specify which profiles to use
3361 # - Default will result in registering capabilities for all guard types
3364 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3365 module_param(lpfc_prot_guard, byte, 0);
3366 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3369 * Delay initial NPort discovery when Clean Address bit is cleared in
3370 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3371 * This parameter can have value 0 or 1.
3372 * When this parameter is set to 0, no delay is added to the initial
3373 * discovery.
3374 * When this parameter is set to non-zero value, initial Nport discovery is
3375 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3376 * accept and FCID/Fabric name/Fabric portname is changed.
3377 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3378 * when Clean Address bit is cleared in FLOGI/FDISC
3379 * accept and FCID/Fabric name/Fabric portname is changed.
3380 * Default value is 0.
3382 int lpfc_delay_discovery;
3383 module_param(lpfc_delay_discovery, int, 0);
3384 MODULE_PARM_DESC(lpfc_delay_discovery,
3385 "Delay NPort discovery when Clean Address bit is cleared. "
3386 "Allowed values: 0,1.");
3389 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3390 * This value can be set to values between 64 and 256. The default value is
3391 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3392 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3394 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3395 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3397 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3398 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3399 "Max Protection Scatter Gather Segment Count");
3401 struct device_attribute *lpfc_hba_attrs[] = {
3402 &dev_attr_bg_info,
3403 &dev_attr_bg_guard_err,
3404 &dev_attr_bg_apptag_err,
3405 &dev_attr_bg_reftag_err,
3406 &dev_attr_info,
3407 &dev_attr_serialnum,
3408 &dev_attr_modeldesc,
3409 &dev_attr_modelname,
3410 &dev_attr_programtype,
3411 &dev_attr_portnum,
3412 &dev_attr_fwrev,
3413 &dev_attr_hdw,
3414 &dev_attr_option_rom_version,
3415 &dev_attr_link_state,
3416 &dev_attr_num_discovered_ports,
3417 &dev_attr_menlo_mgmt_mode,
3418 &dev_attr_lpfc_drvr_version,
3419 &dev_attr_lpfc_enable_fip,
3420 &dev_attr_lpfc_temp_sensor,
3421 &dev_attr_lpfc_log_verbose,
3422 &dev_attr_lpfc_lun_queue_depth,
3423 &dev_attr_lpfc_tgt_queue_depth,
3424 &dev_attr_lpfc_hba_queue_depth,
3425 &dev_attr_lpfc_peer_port_login,
3426 &dev_attr_lpfc_nodev_tmo,
3427 &dev_attr_lpfc_devloss_tmo,
3428 &dev_attr_lpfc_fcp_class,
3429 &dev_attr_lpfc_use_adisc,
3430 &dev_attr_lpfc_ack0,
3431 &dev_attr_lpfc_topology,
3432 &dev_attr_lpfc_scan_down,
3433 &dev_attr_lpfc_link_speed,
3434 &dev_attr_lpfc_cr_delay,
3435 &dev_attr_lpfc_cr_count,
3436 &dev_attr_lpfc_multi_ring_support,
3437 &dev_attr_lpfc_multi_ring_rctl,
3438 &dev_attr_lpfc_multi_ring_type,
3439 &dev_attr_lpfc_fdmi_on,
3440 &dev_attr_lpfc_max_luns,
3441 &dev_attr_lpfc_enable_npiv,
3442 &dev_attr_lpfc_enable_rrq,
3443 &dev_attr_nport_evt_cnt,
3444 &dev_attr_board_mode,
3445 &dev_attr_max_vpi,
3446 &dev_attr_used_vpi,
3447 &dev_attr_max_rpi,
3448 &dev_attr_used_rpi,
3449 &dev_attr_max_xri,
3450 &dev_attr_used_xri,
3451 &dev_attr_npiv_info,
3452 &dev_attr_issue_reset,
3453 &dev_attr_lpfc_poll,
3454 &dev_attr_lpfc_poll_tmo,
3455 &dev_attr_lpfc_use_msi,
3456 &dev_attr_lpfc_fcp_imax,
3457 &dev_attr_lpfc_fcp_wq_count,
3458 &dev_attr_lpfc_fcp_eq_count,
3459 &dev_attr_lpfc_enable_bg,
3460 &dev_attr_lpfc_soft_wwnn,
3461 &dev_attr_lpfc_soft_wwpn,
3462 &dev_attr_lpfc_soft_wwn_enable,
3463 &dev_attr_lpfc_enable_hba_reset,
3464 &dev_attr_lpfc_enable_hba_heartbeat,
3465 &dev_attr_lpfc_sg_seg_cnt,
3466 &dev_attr_lpfc_max_scsicmpl_time,
3467 &dev_attr_lpfc_stat_data_ctrl,
3468 &dev_attr_lpfc_prot_sg_seg_cnt,
3469 &dev_attr_lpfc_aer_support,
3470 &dev_attr_lpfc_aer_state_cleanup,
3471 &dev_attr_lpfc_suppress_link_up,
3472 &dev_attr_lpfc_iocb_cnt,
3473 &dev_attr_iocb_hw,
3474 &dev_attr_txq_hw,
3475 &dev_attr_txcmplq_hw,
3476 &dev_attr_lpfc_fips_level,
3477 &dev_attr_lpfc_fips_rev,
3478 NULL,
3481 struct device_attribute *lpfc_vport_attrs[] = {
3482 &dev_attr_info,
3483 &dev_attr_link_state,
3484 &dev_attr_num_discovered_ports,
3485 &dev_attr_lpfc_drvr_version,
3486 &dev_attr_lpfc_log_verbose,
3487 &dev_attr_lpfc_lun_queue_depth,
3488 &dev_attr_lpfc_tgt_queue_depth,
3489 &dev_attr_lpfc_nodev_tmo,
3490 &dev_attr_lpfc_devloss_tmo,
3491 &dev_attr_lpfc_hba_queue_depth,
3492 &dev_attr_lpfc_peer_port_login,
3493 &dev_attr_lpfc_restrict_login,
3494 &dev_attr_lpfc_fcp_class,
3495 &dev_attr_lpfc_use_adisc,
3496 &dev_attr_lpfc_fdmi_on,
3497 &dev_attr_lpfc_max_luns,
3498 &dev_attr_nport_evt_cnt,
3499 &dev_attr_npiv_info,
3500 &dev_attr_lpfc_enable_da_id,
3501 &dev_attr_lpfc_max_scsicmpl_time,
3502 &dev_attr_lpfc_stat_data_ctrl,
3503 &dev_attr_lpfc_static_vport,
3504 &dev_attr_lpfc_fips_level,
3505 &dev_attr_lpfc_fips_rev,
3506 NULL,
3510 * sysfs_ctlreg_write - Write method for writing to ctlreg
3511 * @filp: open sysfs file
3512 * @kobj: kernel kobject that contains the kernel class device.
3513 * @bin_attr: kernel attributes passed to us.
3514 * @buf: contains the data to be written to the adapter IOREG space.
3515 * @off: offset into buffer to beginning of data.
3516 * @count: bytes to transfer.
3518 * Description:
3519 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3520 * Uses the adapter io control registers to send buf contents to the adapter.
3522 * Returns:
3523 * -ERANGE off and count combo out of range
3524 * -EINVAL off, count or buff address invalid
3525 * -EPERM adapter is offline
3526 * value of count, buf contents written
3528 static ssize_t
3529 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3530 struct bin_attribute *bin_attr,
3531 char *buf, loff_t off, size_t count)
3533 size_t buf_off;
3534 struct device *dev = container_of(kobj, struct device, kobj);
3535 struct Scsi_Host *shost = class_to_shost(dev);
3536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3537 struct lpfc_hba *phba = vport->phba;
3539 if (phba->sli_rev >= LPFC_SLI_REV4)
3540 return -EPERM;
3542 if ((off + count) > FF_REG_AREA_SIZE)
3543 return -ERANGE;
3545 if (count == 0) return 0;
3547 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3548 return -EINVAL;
3550 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3551 return -EPERM;
3554 spin_lock_irq(&phba->hbalock);
3555 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3556 writel(*((uint32_t *)(buf + buf_off)),
3557 phba->ctrl_regs_memmap_p + off + buf_off);
3559 spin_unlock_irq(&phba->hbalock);
3561 return count;
3565 * sysfs_ctlreg_read - Read method for reading from ctlreg
3566 * @filp: open sysfs file
3567 * @kobj: kernel kobject that contains the kernel class device.
3568 * @bin_attr: kernel attributes passed to us.
3569 * @buf: if successful contains the data from the adapter IOREG space.
3570 * @off: offset into buffer to beginning of data.
3571 * @count: bytes to transfer.
3573 * Description:
3574 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3575 * Uses the adapter io control registers to read data into buf.
3577 * Returns:
3578 * -ERANGE off and count combo out of range
3579 * -EINVAL off, count or buff address invalid
3580 * value of count, buf contents read
3582 static ssize_t
3583 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3584 struct bin_attribute *bin_attr,
3585 char *buf, loff_t off, size_t count)
3587 size_t buf_off;
3588 uint32_t * tmp_ptr;
3589 struct device *dev = container_of(kobj, struct device, kobj);
3590 struct Scsi_Host *shost = class_to_shost(dev);
3591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3592 struct lpfc_hba *phba = vport->phba;
3594 if (phba->sli_rev >= LPFC_SLI_REV4)
3595 return -EPERM;
3597 if (off > FF_REG_AREA_SIZE)
3598 return -ERANGE;
3600 if ((off + count) > FF_REG_AREA_SIZE)
3601 count = FF_REG_AREA_SIZE - off;
3603 if (count == 0) return 0;
3605 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3606 return -EINVAL;
3608 spin_lock_irq(&phba->hbalock);
3610 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3611 tmp_ptr = (uint32_t *)(buf + buf_off);
3612 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3615 spin_unlock_irq(&phba->hbalock);
3617 return count;
3620 static struct bin_attribute sysfs_ctlreg_attr = {
3621 .attr = {
3622 .name = "ctlreg",
3623 .mode = S_IRUSR | S_IWUSR,
3625 .size = 256,
3626 .read = sysfs_ctlreg_read,
3627 .write = sysfs_ctlreg_write,
3631 * sysfs_mbox_idle - frees the sysfs mailbox
3632 * @phba: lpfc_hba pointer
3634 static void
3635 sysfs_mbox_idle(struct lpfc_hba *phba)
3637 phba->sysfs_mbox.state = SMBOX_IDLE;
3638 phba->sysfs_mbox.offset = 0;
3640 if (phba->sysfs_mbox.mbox) {
3641 mempool_free(phba->sysfs_mbox.mbox,
3642 phba->mbox_mem_pool);
3643 phba->sysfs_mbox.mbox = NULL;
3648 * sysfs_mbox_write - Write method for writing information via mbox
3649 * @filp: open sysfs file
3650 * @kobj: kernel kobject that contains the kernel class device.
3651 * @bin_attr: kernel attributes passed to us.
3652 * @buf: contains the data to be written to sysfs mbox.
3653 * @off: offset into buffer to beginning of data.
3654 * @count: bytes to transfer.
3656 * Description:
3657 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3658 * Uses the sysfs mbox to send buf contents to the adapter.
3660 * Returns:
3661 * -ERANGE off and count combo out of range
3662 * -EINVAL off, count or buff address invalid
3663 * zero if count is zero
3664 * -EPERM adapter is offline
3665 * -ENOMEM failed to allocate memory for the mail box
3666 * -EAGAIN offset, state or mbox is NULL
3667 * count number of bytes transferred
3669 static ssize_t
3670 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3671 struct bin_attribute *bin_attr,
3672 char *buf, loff_t off, size_t count)
3674 struct device *dev = container_of(kobj, struct device, kobj);
3675 struct Scsi_Host *shost = class_to_shost(dev);
3676 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3677 struct lpfc_hba *phba = vport->phba;
3678 struct lpfcMboxq *mbox = NULL;
3680 if ((count + off) > MAILBOX_CMD_SIZE)
3681 return -ERANGE;
3683 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3684 return -EINVAL;
3686 if (count == 0)
3687 return 0;
3689 if (off == 0) {
3690 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3691 if (!mbox)
3692 return -ENOMEM;
3693 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3696 spin_lock_irq(&phba->hbalock);
3698 if (off == 0) {
3699 if (phba->sysfs_mbox.mbox)
3700 mempool_free(mbox, phba->mbox_mem_pool);
3701 else
3702 phba->sysfs_mbox.mbox = mbox;
3703 phba->sysfs_mbox.state = SMBOX_WRITING;
3704 } else {
3705 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3706 phba->sysfs_mbox.offset != off ||
3707 phba->sysfs_mbox.mbox == NULL) {
3708 sysfs_mbox_idle(phba);
3709 spin_unlock_irq(&phba->hbalock);
3710 return -EAGAIN;
3714 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3715 buf, count);
3717 phba->sysfs_mbox.offset = off + count;
3719 spin_unlock_irq(&phba->hbalock);
3721 return count;
3725 * sysfs_mbox_read - Read method for reading information via mbox
3726 * @filp: open sysfs file
3727 * @kobj: kernel kobject that contains the kernel class device.
3728 * @bin_attr: kernel attributes passed to us.
3729 * @buf: contains the data to be read from sysfs mbox.
3730 * @off: offset into buffer to beginning of data.
3731 * @count: bytes to transfer.
3733 * Description:
3734 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3735 * Uses the sysfs mbox to receive data from to the adapter.
3737 * Returns:
3738 * -ERANGE off greater than mailbox command size
3739 * -EINVAL off, count or buff address invalid
3740 * zero if off and count are zero
3741 * -EACCES adapter over temp
3742 * -EPERM garbage can value to catch a multitude of errors
3743 * -EAGAIN management IO not permitted, state or off error
3744 * -ETIME mailbox timeout
3745 * -ENODEV mailbox error
3746 * count number of bytes transferred
3748 static ssize_t
3749 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3750 struct bin_attribute *bin_attr,
3751 char *buf, loff_t off, size_t count)
3753 struct device *dev = container_of(kobj, struct device, kobj);
3754 struct Scsi_Host *shost = class_to_shost(dev);
3755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3756 struct lpfc_hba *phba = vport->phba;
3757 int rc;
3758 MAILBOX_t *pmb;
3760 if (off > MAILBOX_CMD_SIZE)
3761 return -ERANGE;
3763 if ((count + off) > MAILBOX_CMD_SIZE)
3764 count = MAILBOX_CMD_SIZE - off;
3766 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3767 return -EINVAL;
3769 if (off && count == 0)
3770 return 0;
3772 spin_lock_irq(&phba->hbalock);
3774 if (phba->over_temp_state == HBA_OVER_TEMP) {
3775 sysfs_mbox_idle(phba);
3776 spin_unlock_irq(&phba->hbalock);
3777 return -EACCES;
3780 if (off == 0 &&
3781 phba->sysfs_mbox.state == SMBOX_WRITING &&
3782 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3783 pmb = &phba->sysfs_mbox.mbox->u.mb;
3784 switch (pmb->mbxCommand) {
3785 /* Offline only */
3786 case MBX_INIT_LINK:
3787 case MBX_DOWN_LINK:
3788 case MBX_CONFIG_LINK:
3789 case MBX_CONFIG_RING:
3790 case MBX_RESET_RING:
3791 case MBX_UNREG_LOGIN:
3792 case MBX_CLEAR_LA:
3793 case MBX_DUMP_CONTEXT:
3794 case MBX_RUN_DIAGS:
3795 case MBX_RESTART:
3796 case MBX_SET_MASK:
3797 case MBX_SET_DEBUG:
3798 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3799 printk(KERN_WARNING "mbox_read:Command 0x%x "
3800 "is illegal in on-line state\n",
3801 pmb->mbxCommand);
3802 sysfs_mbox_idle(phba);
3803 spin_unlock_irq(&phba->hbalock);
3804 return -EPERM;
3806 case MBX_WRITE_NV:
3807 case MBX_WRITE_VPARMS:
3808 case MBX_LOAD_SM:
3809 case MBX_READ_NV:
3810 case MBX_READ_CONFIG:
3811 case MBX_READ_RCONFIG:
3812 case MBX_READ_STATUS:
3813 case MBX_READ_XRI:
3814 case MBX_READ_REV:
3815 case MBX_READ_LNK_STAT:
3816 case MBX_DUMP_MEMORY:
3817 case MBX_DOWN_LOAD:
3818 case MBX_UPDATE_CFG:
3819 case MBX_KILL_BOARD:
3820 case MBX_LOAD_AREA:
3821 case MBX_LOAD_EXP_ROM:
3822 case MBX_BEACON:
3823 case MBX_DEL_LD_ENTRY:
3824 case MBX_SET_VARIABLE:
3825 case MBX_WRITE_WWN:
3826 case MBX_PORT_CAPABILITIES:
3827 case MBX_PORT_IOV_CONTROL:
3828 break;
3829 case MBX_SECURITY_MGMT:
3830 case MBX_AUTH_PORT:
3831 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3832 printk(KERN_WARNING "mbox_read:Command 0x%x "
3833 "is not permitted\n", pmb->mbxCommand);
3834 sysfs_mbox_idle(phba);
3835 spin_unlock_irq(&phba->hbalock);
3836 return -EPERM;
3838 break;
3839 case MBX_READ_SPARM64:
3840 case MBX_READ_TOPOLOGY:
3841 case MBX_REG_LOGIN:
3842 case MBX_REG_LOGIN64:
3843 case MBX_CONFIG_PORT:
3844 case MBX_RUN_BIU_DIAG:
3845 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3846 pmb->mbxCommand);
3847 sysfs_mbox_idle(phba);
3848 spin_unlock_irq(&phba->hbalock);
3849 return -EPERM;
3850 default:
3851 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3852 pmb->mbxCommand);
3853 sysfs_mbox_idle(phba);
3854 spin_unlock_irq(&phba->hbalock);
3855 return -EPERM;
3858 /* If HBA encountered an error attention, allow only DUMP
3859 * or RESTART mailbox commands until the HBA is restarted.
3861 if (phba->pport->stopped &&
3862 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3863 pmb->mbxCommand != MBX_RESTART &&
3864 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3865 pmb->mbxCommand != MBX_WRITE_WWN)
3866 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3867 "1259 mbox: Issued mailbox cmd "
3868 "0x%x while in stopped state.\n",
3869 pmb->mbxCommand);
3871 phba->sysfs_mbox.mbox->vport = vport;
3873 /* Don't allow mailbox commands to be sent when blocked
3874 * or when in the middle of discovery
3876 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3877 sysfs_mbox_idle(phba);
3878 spin_unlock_irq(&phba->hbalock);
3879 return -EAGAIN;
3882 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3883 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3885 spin_unlock_irq(&phba->hbalock);
3886 rc = lpfc_sli_issue_mbox (phba,
3887 phba->sysfs_mbox.mbox,
3888 MBX_POLL);
3889 spin_lock_irq(&phba->hbalock);
3891 } else {
3892 spin_unlock_irq(&phba->hbalock);
3893 rc = lpfc_sli_issue_mbox_wait (phba,
3894 phba->sysfs_mbox.mbox,
3895 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3896 spin_lock_irq(&phba->hbalock);
3899 if (rc != MBX_SUCCESS) {
3900 if (rc == MBX_TIMEOUT) {
3901 phba->sysfs_mbox.mbox = NULL;
3903 sysfs_mbox_idle(phba);
3904 spin_unlock_irq(&phba->hbalock);
3905 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3907 phba->sysfs_mbox.state = SMBOX_READING;
3909 else if (phba->sysfs_mbox.offset != off ||
3910 phba->sysfs_mbox.state != SMBOX_READING) {
3911 printk(KERN_WARNING "mbox_read: Bad State\n");
3912 sysfs_mbox_idle(phba);
3913 spin_unlock_irq(&phba->hbalock);
3914 return -EAGAIN;
3917 memcpy(buf, (uint8_t *) &pmb + off, count);
3919 phba->sysfs_mbox.offset = off + count;
3921 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3922 sysfs_mbox_idle(phba);
3924 spin_unlock_irq(&phba->hbalock);
3926 return count;
3929 static struct bin_attribute sysfs_mbox_attr = {
3930 .attr = {
3931 .name = "mbox",
3932 .mode = S_IRUSR | S_IWUSR,
3934 .size = MAILBOX_CMD_SIZE,
3935 .read = sysfs_mbox_read,
3936 .write = sysfs_mbox_write,
3940 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3941 * @vport: address of lpfc vport structure.
3943 * Return codes:
3944 * zero on success
3945 * error return code from sysfs_create_bin_file()
3948 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3950 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3951 int error;
3953 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3954 &sysfs_drvr_stat_data_attr);
3956 /* Virtual ports do not need ctrl_reg and mbox */
3957 if (error || vport->port_type == LPFC_NPIV_PORT)
3958 goto out;
3960 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3961 &sysfs_ctlreg_attr);
3962 if (error)
3963 goto out_remove_stat_attr;
3965 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3966 &sysfs_mbox_attr);
3967 if (error)
3968 goto out_remove_ctlreg_attr;
3970 return 0;
3971 out_remove_ctlreg_attr:
3972 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3973 out_remove_stat_attr:
3974 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3975 &sysfs_drvr_stat_data_attr);
3976 out:
3977 return error;
3981 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3982 * @vport: address of lpfc vport structure.
3984 void
3985 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3987 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3988 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3989 &sysfs_drvr_stat_data_attr);
3990 /* Virtual ports do not need ctrl_reg and mbox */
3991 if (vport->port_type == LPFC_NPIV_PORT)
3992 return;
3993 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3994 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3999 * Dynamic FC Host Attributes Support
4003 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4004 * @shost: kernel scsi host pointer.
4006 static void
4007 lpfc_get_host_port_id(struct Scsi_Host *shost)
4009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4011 /* note: fc_myDID already in cpu endianness */
4012 fc_host_port_id(shost) = vport->fc_myDID;
4016 * lpfc_get_host_port_type - Set the value of the scsi host port type
4017 * @shost: kernel scsi host pointer.
4019 static void
4020 lpfc_get_host_port_type(struct Scsi_Host *shost)
4022 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4023 struct lpfc_hba *phba = vport->phba;
4025 spin_lock_irq(shost->host_lock);
4027 if (vport->port_type == LPFC_NPIV_PORT) {
4028 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4029 } else if (lpfc_is_link_up(phba)) {
4030 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4031 if (vport->fc_flag & FC_PUBLIC_LOOP)
4032 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4033 else
4034 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4035 } else {
4036 if (vport->fc_flag & FC_FABRIC)
4037 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4038 else
4039 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4041 } else
4042 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4044 spin_unlock_irq(shost->host_lock);
4048 * lpfc_get_host_port_state - Set the value of the scsi host port state
4049 * @shost: kernel scsi host pointer.
4051 static void
4052 lpfc_get_host_port_state(struct Scsi_Host *shost)
4054 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4055 struct lpfc_hba *phba = vport->phba;
4057 spin_lock_irq(shost->host_lock);
4059 if (vport->fc_flag & FC_OFFLINE_MODE)
4060 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4061 else {
4062 switch (phba->link_state) {
4063 case LPFC_LINK_UNKNOWN:
4064 case LPFC_LINK_DOWN:
4065 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4066 break;
4067 case LPFC_LINK_UP:
4068 case LPFC_CLEAR_LA:
4069 case LPFC_HBA_READY:
4070 /* Links up, beyond this port_type reports state */
4071 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4072 break;
4073 case LPFC_HBA_ERROR:
4074 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4075 break;
4076 default:
4077 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4078 break;
4082 spin_unlock_irq(shost->host_lock);
4086 * lpfc_get_host_speed - Set the value of the scsi host speed
4087 * @shost: kernel scsi host pointer.
4089 static void
4090 lpfc_get_host_speed(struct Scsi_Host *shost)
4092 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4093 struct lpfc_hba *phba = vport->phba;
4095 spin_lock_irq(shost->host_lock);
4097 if (lpfc_is_link_up(phba)) {
4098 switch(phba->fc_linkspeed) {
4099 case LPFC_LINK_SPEED_1GHZ:
4100 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4101 break;
4102 case LPFC_LINK_SPEED_2GHZ:
4103 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4104 break;
4105 case LPFC_LINK_SPEED_4GHZ:
4106 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4107 break;
4108 case LPFC_LINK_SPEED_8GHZ:
4109 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4110 break;
4111 case LPFC_LINK_SPEED_10GHZ:
4112 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4113 break;
4114 case LPFC_LINK_SPEED_16GHZ:
4115 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4116 break;
4117 default:
4118 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4119 break;
4121 } else
4122 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4124 spin_unlock_irq(shost->host_lock);
4128 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4129 * @shost: kernel scsi host pointer.
4131 static void
4132 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4135 struct lpfc_hba *phba = vport->phba;
4136 u64 node_name;
4138 spin_lock_irq(shost->host_lock);
4140 if ((vport->fc_flag & FC_FABRIC) ||
4141 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4142 (vport->fc_flag & FC_PUBLIC_LOOP)))
4143 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4144 else
4145 /* fabric is local port if there is no F/FL_Port */
4146 node_name = 0;
4148 spin_unlock_irq(shost->host_lock);
4150 fc_host_fabric_name(shost) = node_name;
4154 * lpfc_get_stats - Return statistical information about the adapter
4155 * @shost: kernel scsi host pointer.
4157 * Notes:
4158 * NULL on error for link down, no mbox pool, sli2 active,
4159 * management not allowed, memory allocation error, or mbox error.
4161 * Returns:
4162 * NULL for error
4163 * address of the adapter host statistics
4165 static struct fc_host_statistics *
4166 lpfc_get_stats(struct Scsi_Host *shost)
4168 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4169 struct lpfc_hba *phba = vport->phba;
4170 struct lpfc_sli *psli = &phba->sli;
4171 struct fc_host_statistics *hs = &phba->link_stats;
4172 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4173 LPFC_MBOXQ_t *pmboxq;
4174 MAILBOX_t *pmb;
4175 unsigned long seconds;
4176 int rc = 0;
4179 * prevent udev from issuing mailbox commands until the port is
4180 * configured.
4182 if (phba->link_state < LPFC_LINK_DOWN ||
4183 !phba->mbox_mem_pool ||
4184 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4185 return NULL;
4187 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4188 return NULL;
4190 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4191 if (!pmboxq)
4192 return NULL;
4193 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4195 pmb = &pmboxq->u.mb;
4196 pmb->mbxCommand = MBX_READ_STATUS;
4197 pmb->mbxOwner = OWN_HOST;
4198 pmboxq->context1 = NULL;
4199 pmboxq->vport = vport;
4201 if (vport->fc_flag & FC_OFFLINE_MODE)
4202 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4203 else
4204 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4206 if (rc != MBX_SUCCESS) {
4207 if (rc != MBX_TIMEOUT)
4208 mempool_free(pmboxq, phba->mbox_mem_pool);
4209 return NULL;
4212 memset(hs, 0, sizeof (struct fc_host_statistics));
4214 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4215 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4216 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4217 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4219 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4220 pmb->mbxCommand = MBX_READ_LNK_STAT;
4221 pmb->mbxOwner = OWN_HOST;
4222 pmboxq->context1 = NULL;
4223 pmboxq->vport = vport;
4225 if (vport->fc_flag & FC_OFFLINE_MODE)
4226 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4227 else
4228 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4230 if (rc != MBX_SUCCESS) {
4231 if (rc != MBX_TIMEOUT)
4232 mempool_free(pmboxq, phba->mbox_mem_pool);
4233 return NULL;
4236 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4237 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4238 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4239 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4240 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4241 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4242 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4244 hs->link_failure_count -= lso->link_failure_count;
4245 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4246 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4247 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4248 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4249 hs->invalid_crc_count -= lso->invalid_crc_count;
4250 hs->error_frames -= lso->error_frames;
4252 if (phba->hba_flag & HBA_FCOE_MODE) {
4253 hs->lip_count = -1;
4254 hs->nos_count = (phba->link_events >> 1);
4255 hs->nos_count -= lso->link_events;
4256 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4257 hs->lip_count = (phba->fc_eventTag >> 1);
4258 hs->lip_count -= lso->link_events;
4259 hs->nos_count = -1;
4260 } else {
4261 hs->lip_count = -1;
4262 hs->nos_count = (phba->fc_eventTag >> 1);
4263 hs->nos_count -= lso->link_events;
4266 hs->dumped_frames = -1;
4268 seconds = get_seconds();
4269 if (seconds < psli->stats_start)
4270 hs->seconds_since_last_reset = seconds +
4271 ((unsigned long)-1 - psli->stats_start);
4272 else
4273 hs->seconds_since_last_reset = seconds - psli->stats_start;
4275 mempool_free(pmboxq, phba->mbox_mem_pool);
4277 return hs;
4281 * lpfc_reset_stats - Copy the adapter link stats information
4282 * @shost: kernel scsi host pointer.
4284 static void
4285 lpfc_reset_stats(struct Scsi_Host *shost)
4287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4288 struct lpfc_hba *phba = vport->phba;
4289 struct lpfc_sli *psli = &phba->sli;
4290 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4291 LPFC_MBOXQ_t *pmboxq;
4292 MAILBOX_t *pmb;
4293 int rc = 0;
4295 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4296 return;
4298 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4299 if (!pmboxq)
4300 return;
4301 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4303 pmb = &pmboxq->u.mb;
4304 pmb->mbxCommand = MBX_READ_STATUS;
4305 pmb->mbxOwner = OWN_HOST;
4306 pmb->un.varWords[0] = 0x1; /* reset request */
4307 pmboxq->context1 = NULL;
4308 pmboxq->vport = vport;
4310 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4311 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4312 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4313 else
4314 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4316 if (rc != MBX_SUCCESS) {
4317 if (rc != MBX_TIMEOUT)
4318 mempool_free(pmboxq, phba->mbox_mem_pool);
4319 return;
4322 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4323 pmb->mbxCommand = MBX_READ_LNK_STAT;
4324 pmb->mbxOwner = OWN_HOST;
4325 pmboxq->context1 = NULL;
4326 pmboxq->vport = vport;
4328 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4329 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4330 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4331 else
4332 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4334 if (rc != MBX_SUCCESS) {
4335 if (rc != MBX_TIMEOUT)
4336 mempool_free( pmboxq, phba->mbox_mem_pool);
4337 return;
4340 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4341 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4342 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4343 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4344 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4345 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4346 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4347 if (phba->hba_flag & HBA_FCOE_MODE)
4348 lso->link_events = (phba->link_events >> 1);
4349 else
4350 lso->link_events = (phba->fc_eventTag >> 1);
4352 psli->stats_start = get_seconds();
4354 mempool_free(pmboxq, phba->mbox_mem_pool);
4356 return;
4360 * The LPFC driver treats linkdown handling as target loss events so there
4361 * are no sysfs handlers for link_down_tmo.
4365 * lpfc_get_node_by_target - Return the nodelist for a target
4366 * @starget: kernel scsi target pointer.
4368 * Returns:
4369 * address of the node list if found
4370 * NULL target not found
4372 static struct lpfc_nodelist *
4373 lpfc_get_node_by_target(struct scsi_target *starget)
4375 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4377 struct lpfc_nodelist *ndlp;
4379 spin_lock_irq(shost->host_lock);
4380 /* Search for this, mapped, target ID */
4381 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4382 if (NLP_CHK_NODE_ACT(ndlp) &&
4383 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4384 starget->id == ndlp->nlp_sid) {
4385 spin_unlock_irq(shost->host_lock);
4386 return ndlp;
4389 spin_unlock_irq(shost->host_lock);
4390 return NULL;
4394 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4395 * @starget: kernel scsi target pointer.
4397 static void
4398 lpfc_get_starget_port_id(struct scsi_target *starget)
4400 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4402 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4406 * lpfc_get_starget_node_name - Set the target node name
4407 * @starget: kernel scsi target pointer.
4409 * Description: Set the target node name to the ndlp node name wwn or zero.
4411 static void
4412 lpfc_get_starget_node_name(struct scsi_target *starget)
4414 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4416 fc_starget_node_name(starget) =
4417 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4421 * lpfc_get_starget_port_name - Set the target port name
4422 * @starget: kernel scsi target pointer.
4424 * Description: set the target port name to the ndlp port name wwn or zero.
4426 static void
4427 lpfc_get_starget_port_name(struct scsi_target *starget)
4429 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4431 fc_starget_port_name(starget) =
4432 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4436 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4437 * @rport: fc rport address.
4438 * @timeout: new value for dev loss tmo.
4440 * Description:
4441 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4442 * dev_loss_tmo to one.
4444 static void
4445 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4447 if (timeout)
4448 rport->dev_loss_tmo = timeout;
4449 else
4450 rport->dev_loss_tmo = 1;
4454 * lpfc_rport_show_function - Return rport target information
4456 * Description:
4457 * Macro that uses field to generate a function with the name lpfc_show_rport_
4459 * lpfc_show_rport_##field: returns the bytes formatted in buf
4460 * @cdev: class converted to an fc_rport.
4461 * @buf: on return contains the target_field or zero.
4463 * Returns: size of formatted string.
4465 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4466 static ssize_t \
4467 lpfc_show_rport_##field (struct device *dev, \
4468 struct device_attribute *attr, \
4469 char *buf) \
4471 struct fc_rport *rport = transport_class_to_rport(dev); \
4472 struct lpfc_rport_data *rdata = rport->hostdata; \
4473 return snprintf(buf, sz, format_string, \
4474 (rdata->target) ? cast rdata->target->field : 0); \
4477 #define lpfc_rport_rd_attr(field, format_string, sz) \
4478 lpfc_rport_show_function(field, format_string, sz, ) \
4479 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4482 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4483 * @fc_vport: The fc_vport who's symbolic name has been changed.
4485 * Description:
4486 * This function is called by the transport after the @fc_vport's symbolic name
4487 * has been changed. This function re-registers the symbolic name with the
4488 * switch to propogate the change into the fabric if the vport is active.
4490 static void
4491 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4493 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4495 if (vport->port_state == LPFC_VPORT_READY)
4496 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4500 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4501 * @phba: Pointer to lpfc_hba struct.
4503 * This function is called by the lpfc_get_cfgparam() routine to set the
4504 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4505 * log messsage according to the module's lpfc_log_verbose parameter setting
4506 * before hba port or vport created.
4508 static void
4509 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4511 phba->cfg_log_verbose = verbose;
4514 struct fc_function_template lpfc_transport_functions = {
4515 /* fixed attributes the driver supports */
4516 .show_host_node_name = 1,
4517 .show_host_port_name = 1,
4518 .show_host_supported_classes = 1,
4519 .show_host_supported_fc4s = 1,
4520 .show_host_supported_speeds = 1,
4521 .show_host_maxframe_size = 1,
4522 .show_host_symbolic_name = 1,
4524 /* dynamic attributes the driver supports */
4525 .get_host_port_id = lpfc_get_host_port_id,
4526 .show_host_port_id = 1,
4528 .get_host_port_type = lpfc_get_host_port_type,
4529 .show_host_port_type = 1,
4531 .get_host_port_state = lpfc_get_host_port_state,
4532 .show_host_port_state = 1,
4534 /* active_fc4s is shown but doesn't change (thus no get function) */
4535 .show_host_active_fc4s = 1,
4537 .get_host_speed = lpfc_get_host_speed,
4538 .show_host_speed = 1,
4540 .get_host_fabric_name = lpfc_get_host_fabric_name,
4541 .show_host_fabric_name = 1,
4544 * The LPFC driver treats linkdown handling as target loss events
4545 * so there are no sysfs handlers for link_down_tmo.
4548 .get_fc_host_stats = lpfc_get_stats,
4549 .reset_fc_host_stats = lpfc_reset_stats,
4551 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4552 .show_rport_maxframe_size = 1,
4553 .show_rport_supported_classes = 1,
4555 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4556 .show_rport_dev_loss_tmo = 1,
4558 .get_starget_port_id = lpfc_get_starget_port_id,
4559 .show_starget_port_id = 1,
4561 .get_starget_node_name = lpfc_get_starget_node_name,
4562 .show_starget_node_name = 1,
4564 .get_starget_port_name = lpfc_get_starget_port_name,
4565 .show_starget_port_name = 1,
4567 .issue_fc_host_lip = lpfc_issue_lip,
4568 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4569 .terminate_rport_io = lpfc_terminate_rport_io,
4571 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4573 .vport_disable = lpfc_vport_disable,
4575 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4577 .bsg_request = lpfc_bsg_request,
4578 .bsg_timeout = lpfc_bsg_timeout,
4581 struct fc_function_template lpfc_vport_transport_functions = {
4582 /* fixed attributes the driver supports */
4583 .show_host_node_name = 1,
4584 .show_host_port_name = 1,
4585 .show_host_supported_classes = 1,
4586 .show_host_supported_fc4s = 1,
4587 .show_host_supported_speeds = 1,
4588 .show_host_maxframe_size = 1,
4589 .show_host_symbolic_name = 1,
4591 /* dynamic attributes the driver supports */
4592 .get_host_port_id = lpfc_get_host_port_id,
4593 .show_host_port_id = 1,
4595 .get_host_port_type = lpfc_get_host_port_type,
4596 .show_host_port_type = 1,
4598 .get_host_port_state = lpfc_get_host_port_state,
4599 .show_host_port_state = 1,
4601 /* active_fc4s is shown but doesn't change (thus no get function) */
4602 .show_host_active_fc4s = 1,
4604 .get_host_speed = lpfc_get_host_speed,
4605 .show_host_speed = 1,
4607 .get_host_fabric_name = lpfc_get_host_fabric_name,
4608 .show_host_fabric_name = 1,
4611 * The LPFC driver treats linkdown handling as target loss events
4612 * so there are no sysfs handlers for link_down_tmo.
4615 .get_fc_host_stats = lpfc_get_stats,
4616 .reset_fc_host_stats = lpfc_reset_stats,
4618 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4619 .show_rport_maxframe_size = 1,
4620 .show_rport_supported_classes = 1,
4622 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4623 .show_rport_dev_loss_tmo = 1,
4625 .get_starget_port_id = lpfc_get_starget_port_id,
4626 .show_starget_port_id = 1,
4628 .get_starget_node_name = lpfc_get_starget_node_name,
4629 .show_starget_node_name = 1,
4631 .get_starget_port_name = lpfc_get_starget_port_name,
4632 .show_starget_port_name = 1,
4634 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4635 .terminate_rport_io = lpfc_terminate_rport_io,
4637 .vport_disable = lpfc_vport_disable,
4639 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4643 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4644 * @phba: lpfc_hba pointer.
4646 void
4647 lpfc_get_cfgparam(struct lpfc_hba *phba)
4649 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4650 lpfc_cr_count_init(phba, lpfc_cr_count);
4651 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4652 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4653 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4654 lpfc_ack0_init(phba, lpfc_ack0);
4655 lpfc_topology_init(phba, lpfc_topology);
4656 lpfc_link_speed_init(phba, lpfc_link_speed);
4657 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4658 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4659 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4660 lpfc_use_msi_init(phba, lpfc_use_msi);
4661 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4662 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4663 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4664 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4665 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4666 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4667 if (phba->sli_rev == LPFC_SLI_REV4)
4668 phba->cfg_poll = 0;
4669 else
4670 phba->cfg_poll = lpfc_poll;
4671 phba->cfg_soft_wwnn = 0L;
4672 phba->cfg_soft_wwpn = 0L;
4673 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4674 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4675 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4676 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4677 lpfc_aer_support_init(phba, lpfc_aer_support);
4678 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4679 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4680 return;
4684 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4685 * @vport: lpfc_vport pointer.
4687 void
4688 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4690 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4691 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4692 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
4693 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4694 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4695 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4696 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4697 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4698 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4699 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4700 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4701 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4702 lpfc_max_luns_init(vport, lpfc_max_luns);
4703 lpfc_scan_down_init(vport, lpfc_scan_down);
4704 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
4705 return;