ARM: omap: update GPIO chained IRQ handler to use entry/exit functions
[linux-2.6/cjktty.git] / drivers / scsi / lpfc / lpfc_attr.c
blob17d789325f4014b39aa3807de7c1d7f1b47bf333
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.
681 * Do not make this function static.
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
689 lpfc_selective_reset(struct lpfc_hba *phba)
691 struct completion online_compl;
692 int status = 0;
693 int rc;
695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
700 if (status != 0)
701 return status;
703 init_completion(&online_compl);
704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
705 LPFC_EVT_ONLINE);
706 if (rc == 0)
707 return -ENOMEM;
709 wait_for_completion(&online_compl);
711 if (status != 0)
712 return -EIO;
714 return 0;
718 * lpfc_issue_reset - Selectively resets an adapter
719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
731 * is returned which indicates success
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
738 static ssize_t
739 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
742 struct Scsi_Host *shost = class_to_shost(dev);
743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
746 int status = -EINVAL;
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
749 status = phba->lpfc_selective_reset(phba);
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
758 * lpfc_nport_evt_cnt_show - Return the number of nport events
759 * @dev: class device that is converted into a Scsi_host.
760 * @attr: device attribute, not used.
761 * @buf: on return contains the ascii number of nport events.
763 * Returns: size of formatted string.
765 static ssize_t
766 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
767 char *buf)
769 struct Scsi_Host *shost = class_to_shost(dev);
770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
771 struct lpfc_hba *phba = vport->phba;
773 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
777 * lpfc_board_mode_show - Return the state of the board
778 * @dev: class device that is converted into a Scsi_host.
779 * @attr: device attribute, not used.
780 * @buf: on return contains the state of the adapter.
782 * Returns: size of formatted string.
784 static ssize_t
785 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
786 char *buf)
788 struct Scsi_Host *shost = class_to_shost(dev);
789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
790 struct lpfc_hba *phba = vport->phba;
791 char * state;
793 if (phba->link_state == LPFC_HBA_ERROR)
794 state = "error";
795 else if (phba->link_state == LPFC_WARM_START)
796 state = "warm start";
797 else if (phba->link_state == LPFC_INIT_START)
798 state = "offline";
799 else
800 state = "online";
802 return snprintf(buf, PAGE_SIZE, "%s\n", state);
806 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
807 * @dev: class device that is converted into a Scsi_host.
808 * @attr: device attribute, not used.
809 * @buf: containing one of the strings "online", "offline", "warm" or "error".
810 * @count: unused variable.
812 * Returns:
813 * -EACCES if enable hba reset not enabled
814 * -EINVAL if the buffer does not contain a valid string (see above)
815 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
816 * buf length greater than zero indicates success
818 static ssize_t
819 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
820 const char *buf, size_t count)
822 struct Scsi_Host *shost = class_to_shost(dev);
823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
824 struct lpfc_hba *phba = vport->phba;
825 struct completion online_compl;
826 int status=0;
827 int rc;
829 if (!phba->cfg_enable_hba_reset)
830 return -EACCES;
831 init_completion(&online_compl);
833 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
834 rc = lpfc_workq_post_event(phba, &status, &online_compl,
835 LPFC_EVT_ONLINE);
836 if (rc == 0)
837 return -ENOMEM;
838 wait_for_completion(&online_compl);
839 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
840 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
841 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
842 if (phba->sli_rev == LPFC_SLI_REV4)
843 return -EINVAL;
844 else
845 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
846 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
847 if (phba->sli_rev == LPFC_SLI_REV4)
848 return -EINVAL;
849 else
850 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
851 else
852 return -EINVAL;
854 if (!status)
855 return strlen(buf);
856 else
857 return -EIO;
861 * lpfc_get_hba_info - Return various bits of informaton about the adapter
862 * @phba: pointer to the adapter structure.
863 * @mxri: max xri count.
864 * @axri: available xri count.
865 * @mrpi: max rpi count.
866 * @arpi: available rpi count.
867 * @mvpi: max vpi count.
868 * @avpi: available vpi count.
870 * Description:
871 * If an integer pointer for an count is not null then the value for the
872 * count is returned.
874 * Returns:
875 * zero on error
876 * one for success
878 static int
879 lpfc_get_hba_info(struct lpfc_hba *phba,
880 uint32_t *mxri, uint32_t *axri,
881 uint32_t *mrpi, uint32_t *arpi,
882 uint32_t *mvpi, uint32_t *avpi)
884 struct lpfc_mbx_read_config *rd_config;
885 LPFC_MBOXQ_t *pmboxq;
886 MAILBOX_t *pmb;
887 int rc = 0;
888 uint32_t max_vpi;
891 * prevent udev from issuing mailbox commands until the port is
892 * configured.
894 if (phba->link_state < LPFC_LINK_DOWN ||
895 !phba->mbox_mem_pool ||
896 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
897 return 0;
899 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
900 return 0;
902 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
903 if (!pmboxq)
904 return 0;
905 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
907 pmb = &pmboxq->u.mb;
908 pmb->mbxCommand = MBX_READ_CONFIG;
909 pmb->mbxOwner = OWN_HOST;
910 pmboxq->context1 = NULL;
912 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
913 rc = MBX_NOT_FINISHED;
914 else
915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
917 if (rc != MBX_SUCCESS) {
918 if (rc != MBX_TIMEOUT)
919 mempool_free(pmboxq, phba->mbox_mem_pool);
920 return 0;
923 if (phba->sli_rev == LPFC_SLI_REV4) {
924 rd_config = &pmboxq->u.mqe.un.rd_config;
925 if (mrpi)
926 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
927 if (arpi)
928 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
929 phba->sli4_hba.max_cfg_param.rpi_used;
930 if (mxri)
931 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
932 if (axri)
933 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
934 phba->sli4_hba.max_cfg_param.xri_used;
936 /* Account for differences with SLI-3. Get vpi count from
937 * mailbox data and subtract one for max vpi value.
939 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
940 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
942 if (mvpi)
943 *mvpi = max_vpi;
944 if (avpi)
945 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
946 } else {
947 if (mrpi)
948 *mrpi = pmb->un.varRdConfig.max_rpi;
949 if (arpi)
950 *arpi = pmb->un.varRdConfig.avail_rpi;
951 if (mxri)
952 *mxri = pmb->un.varRdConfig.max_xri;
953 if (axri)
954 *axri = pmb->un.varRdConfig.avail_xri;
955 if (mvpi)
956 *mvpi = pmb->un.varRdConfig.max_vpi;
957 if (avpi)
958 *avpi = pmb->un.varRdConfig.avail_vpi;
961 mempool_free(pmboxq, phba->mbox_mem_pool);
962 return 1;
966 * lpfc_max_rpi_show - Return maximum rpi
967 * @dev: class device that is converted into a Scsi_host.
968 * @attr: device attribute, not used.
969 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
971 * Description:
972 * Calls lpfc_get_hba_info() asking for just the mrpi count.
973 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
974 * to "Unknown" and the buffer length is returned, therefore the caller
975 * must check for "Unknown" in the buffer to detect a failure.
977 * Returns: size of formatted string.
979 static ssize_t
980 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
983 struct Scsi_Host *shost = class_to_shost(dev);
984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986 uint32_t cnt;
988 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
989 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
990 return snprintf(buf, PAGE_SIZE, "Unknown\n");
994 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
995 * @dev: class device that is converted into a Scsi_host.
996 * @attr: device attribute, not used.
997 * @buf: containing the used rpi count in decimal or "Unknown".
999 * Description:
1000 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1001 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1002 * to "Unknown" and the buffer length is returned, therefore the caller
1003 * must check for "Unknown" in the buffer to detect a failure.
1005 * Returns: size of formatted string.
1007 static ssize_t
1008 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1009 char *buf)
1011 struct Scsi_Host *shost = class_to_shost(dev);
1012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 struct lpfc_hba *phba = vport->phba;
1014 uint32_t cnt, acnt;
1016 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1017 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1018 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1022 * lpfc_max_xri_show - Return maximum xri
1023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1027 * Description:
1028 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1029 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1030 * to "Unknown" and the buffer length is returned, therefore the caller
1031 * must check for "Unknown" in the buffer to detect a failure.
1033 * Returns: size of formatted string.
1035 static ssize_t
1036 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1037 char *buf)
1039 struct Scsi_Host *shost = class_to_shost(dev);
1040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1042 uint32_t cnt;
1044 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1045 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1046 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1050 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1051 * @dev: class device that is converted into a Scsi_host.
1052 * @attr: device attribute, not used.
1053 * @buf: on return contains the used xri count in decimal or "Unknown".
1055 * Description:
1056 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1057 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1058 * to "Unknown" and the buffer length is returned, therefore the caller
1059 * must check for "Unknown" in the buffer to detect a failure.
1061 * Returns: size of formatted string.
1063 static ssize_t
1064 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1065 char *buf)
1067 struct Scsi_Host *shost = class_to_shost(dev);
1068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
1070 uint32_t cnt, acnt;
1072 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1073 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1074 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1078 * lpfc_max_vpi_show - Return maximum vpi
1079 * @dev: class device that is converted into a Scsi_host.
1080 * @attr: device attribute, not used.
1081 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1083 * Description:
1084 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1085 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1086 * to "Unknown" and the buffer length is returned, therefore the caller
1087 * must check for "Unknown" in the buffer to detect a failure.
1089 * Returns: size of formatted string.
1091 static ssize_t
1092 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
1095 struct Scsi_Host *shost = class_to_shost(dev);
1096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1098 uint32_t cnt;
1100 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1101 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1102 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1106 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the used vpi count in decimal or "Unknown".
1111 * Description:
1112 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1117 * Returns: size of formatted string.
1119 static ssize_t
1120 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1121 char *buf)
1123 struct Scsi_Host *shost = class_to_shost(dev);
1124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1125 struct lpfc_hba *phba = vport->phba;
1126 uint32_t cnt, acnt;
1128 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1129 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1130 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1134 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: text that must be interpreted to determine if npiv is supported.
1139 * Description:
1140 * Buffer will contain text indicating npiv is not suppoerted on the port,
1141 * the port is an NPIV physical port, or it is an npiv virtual port with
1142 * the id of the vport.
1144 * Returns: size of formatted string.
1146 static ssize_t
1147 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1148 char *buf)
1150 struct Scsi_Host *shost = class_to_shost(dev);
1151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 struct lpfc_hba *phba = vport->phba;
1154 if (!(phba->max_vpi))
1155 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1156 if (vport->port_type == LPFC_PHYSICAL_PORT)
1157 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1158 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1162 * lpfc_poll_show - Return text about poll support for the adapter
1163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the cfg_poll in hex.
1167 * Notes:
1168 * cfg_poll should be a lpfc_polling_flags type.
1170 * Returns: size of formatted string.
1172 static ssize_t
1173 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1174 char *buf)
1176 struct Scsi_Host *shost = class_to_shost(dev);
1177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1178 struct lpfc_hba *phba = vport->phba;
1180 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1184 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1185 * @dev: class device that is converted into a Scsi_host.
1186 * @attr: device attribute, not used.
1187 * @buf: one or more lpfc_polling_flags values.
1188 * @count: not used.
1190 * Notes:
1191 * buf contents converted to integer and checked for a valid value.
1193 * Returns:
1194 * -EINVAL if the buffer connot be converted or is out of range
1195 * length of the buf on success
1197 static ssize_t
1198 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1199 const char *buf, size_t count)
1201 struct Scsi_Host *shost = class_to_shost(dev);
1202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1203 struct lpfc_hba *phba = vport->phba;
1204 uint32_t creg_val;
1205 uint32_t old_val;
1206 int val=0;
1208 if (!isdigit(buf[0]))
1209 return -EINVAL;
1211 if (sscanf(buf, "%i", &val) != 1)
1212 return -EINVAL;
1214 if ((val & 0x3) != val)
1215 return -EINVAL;
1217 if (phba->sli_rev == LPFC_SLI_REV4)
1218 val = 0;
1220 spin_lock_irq(&phba->hbalock);
1222 old_val = phba->cfg_poll;
1224 if (val & ENABLE_FCP_RING_POLLING) {
1225 if ((val & DISABLE_FCP_RING_INT) &&
1226 !(old_val & DISABLE_FCP_RING_INT)) {
1227 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1228 spin_unlock_irq(&phba->hbalock);
1229 return -EINVAL;
1231 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1235 lpfc_poll_start_timer(phba);
1237 } else if (val != 0x0) {
1238 spin_unlock_irq(&phba->hbalock);
1239 return -EINVAL;
1242 if (!(val & DISABLE_FCP_RING_INT) &&
1243 (old_val & DISABLE_FCP_RING_INT))
1245 spin_unlock_irq(&phba->hbalock);
1246 del_timer(&phba->fcp_poll_timer);
1247 spin_lock_irq(&phba->hbalock);
1248 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1249 spin_unlock_irq(&phba->hbalock);
1250 return -EINVAL;
1252 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1253 writel(creg_val, phba->HCregaddr);
1254 readl(phba->HCregaddr); /* flush */
1257 phba->cfg_poll = val;
1259 spin_unlock_irq(&phba->hbalock);
1261 return strlen(buf);
1265 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1266 * @dev: class unused variable.
1267 * @attr: device attribute, not used.
1268 * @buf: on return contains the module description text.
1270 * Returns: size of formatted string.
1272 static ssize_t
1273 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1274 char *buf)
1276 struct Scsi_Host *shost = class_to_shost(dev);
1277 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1278 struct lpfc_hba *phba = vport->phba;
1280 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1284 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1285 * @dev: class unused variable.
1286 * @attr: device attribute, not used.
1287 * @buf: on return contains the module description text.
1289 * Returns: size of formatted string.
1291 static ssize_t
1292 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1293 char *buf)
1295 struct Scsi_Host *shost = class_to_shost(dev);
1296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1297 struct lpfc_hba *phba = vport->phba;
1299 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1303 * lpfc_dss_show - Return the current state of dss and the configured state
1304 * @dev: class converted to a Scsi_host structure.
1305 * @attr: device attribute, not used.
1306 * @buf: on return contains the formatted text.
1308 * Returns: size of formatted string.
1310 static ssize_t
1311 lpfc_dss_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;
1318 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1319 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1320 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1321 "" : "Not ");
1325 * lpfc_param_show - Return a cfg attribute value in decimal
1327 * Description:
1328 * Macro that given an attr e.g. hba_queue_depth expands
1329 * into a function with the name lpfc_hba_queue_depth_show.
1331 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1332 * @dev: class device that is converted into a Scsi_host.
1333 * @attr: device attribute, not used.
1334 * @buf: on return contains the attribute value in decimal.
1336 * Returns: size of formatted string.
1338 #define lpfc_param_show(attr) \
1339 static ssize_t \
1340 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1341 char *buf) \
1343 struct Scsi_Host *shost = class_to_shost(dev);\
1344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1345 struct lpfc_hba *phba = vport->phba;\
1346 uint val = 0;\
1347 val = phba->cfg_##attr;\
1348 return snprintf(buf, PAGE_SIZE, "%d\n",\
1349 phba->cfg_##attr);\
1353 * lpfc_param_hex_show - Return a cfg attribute value in hex
1355 * Description:
1356 * Macro that given an attr e.g. hba_queue_depth expands
1357 * into a function with the name lpfc_hba_queue_depth_show
1359 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1360 * @dev: class device that is converted into a Scsi_host.
1361 * @attr: device attribute, not used.
1362 * @buf: on return contains the attribute value in hexadecimal.
1364 * Returns: size of formatted string.
1366 #define lpfc_param_hex_show(attr) \
1367 static ssize_t \
1368 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1369 char *buf) \
1371 struct Scsi_Host *shost = class_to_shost(dev);\
1372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1373 struct lpfc_hba *phba = vport->phba;\
1374 uint val = 0;\
1375 val = phba->cfg_##attr;\
1376 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1377 phba->cfg_##attr);\
1381 * lpfc_param_init - Initializes a cfg attribute
1383 * Description:
1384 * Macro that given an attr e.g. hba_queue_depth expands
1385 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1386 * takes a default argument, a minimum and maximum argument.
1388 * lpfc_##attr##_init: Initializes an attribute.
1389 * @phba: pointer the the adapter structure.
1390 * @val: integer attribute value.
1392 * Validates the min and max values then sets the adapter config field
1393 * accordingly, or uses the default if out of range and prints an error message.
1395 * Returns:
1396 * zero on success
1397 * -EINVAL if default used
1399 #define lpfc_param_init(attr, default, minval, maxval) \
1400 static int \
1401 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1403 if (val >= minval && val <= maxval) {\
1404 phba->cfg_##attr = val;\
1405 return 0;\
1407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1408 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1409 "allowed range is ["#minval", "#maxval"]\n", val); \
1410 phba->cfg_##attr = default;\
1411 return -EINVAL;\
1415 * lpfc_param_set - Set a cfg attribute value
1417 * Description:
1418 * Macro that given an attr e.g. hba_queue_depth expands
1419 * into a function with the name lpfc_hba_queue_depth_set
1421 * lpfc_##attr##_set: Sets an attribute value.
1422 * @phba: pointer the the adapter structure.
1423 * @val: integer attribute value.
1425 * Description:
1426 * Validates the min and max values then sets the
1427 * adapter config field if in the valid range. prints error message
1428 * and does not set the parameter if invalid.
1430 * Returns:
1431 * zero on success
1432 * -EINVAL if val is invalid
1434 #define lpfc_param_set(attr, default, minval, maxval) \
1435 static int \
1436 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1438 if (val >= minval && val <= maxval) {\
1439 phba->cfg_##attr = val;\
1440 return 0;\
1442 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1443 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1444 "allowed range is ["#minval", "#maxval"]\n", val); \
1445 return -EINVAL;\
1449 * lpfc_param_store - Set a vport attribute value
1451 * Description:
1452 * Macro that given an attr e.g. hba_queue_depth expands
1453 * into a function with the name lpfc_hba_queue_depth_store.
1455 * lpfc_##attr##_store: Set an sttribute value.
1456 * @dev: class device that is converted into a Scsi_host.
1457 * @attr: device attribute, not used.
1458 * @buf: contains the attribute value in ascii.
1459 * @count: not used.
1461 * Description:
1462 * Convert the ascii text number to an integer, then
1463 * use the lpfc_##attr##_set function to set the value.
1465 * Returns:
1466 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1467 * length of buffer upon success.
1469 #define lpfc_param_store(attr) \
1470 static ssize_t \
1471 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1472 const char *buf, size_t count) \
1474 struct Scsi_Host *shost = class_to_shost(dev);\
1475 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1476 struct lpfc_hba *phba = vport->phba;\
1477 uint val = 0;\
1478 if (!isdigit(buf[0]))\
1479 return -EINVAL;\
1480 if (sscanf(buf, "%i", &val) != 1)\
1481 return -EINVAL;\
1482 if (lpfc_##attr##_set(phba, val) == 0) \
1483 return strlen(buf);\
1484 else \
1485 return -EINVAL;\
1489 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1491 * Description:
1492 * Macro that given an attr e.g. hba_queue_depth expands
1493 * into a function with the name lpfc_hba_queue_depth_show
1495 * lpfc_##attr##_show: prints the attribute value in decimal.
1496 * @dev: class device that is converted into a Scsi_host.
1497 * @attr: device attribute, not used.
1498 * @buf: on return contains the attribute value in decimal.
1500 * Returns: length of formatted string.
1502 #define lpfc_vport_param_show(attr) \
1503 static ssize_t \
1504 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1505 char *buf) \
1507 struct Scsi_Host *shost = class_to_shost(dev);\
1508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1509 uint val = 0;\
1510 val = vport->cfg_##attr;\
1511 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1515 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1517 * Description:
1518 * Macro that given an attr e.g.
1519 * hba_queue_depth expands into a function with the name
1520 * lpfc_hba_queue_depth_show
1522 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1523 * @dev: class device that is converted into a Scsi_host.
1524 * @attr: device attribute, not used.
1525 * @buf: on return contains the attribute value in hexadecimal.
1527 * Returns: length of formatted string.
1529 #define lpfc_vport_param_hex_show(attr) \
1530 static ssize_t \
1531 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1532 char *buf) \
1534 struct Scsi_Host *shost = class_to_shost(dev);\
1535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1536 uint val = 0;\
1537 val = vport->cfg_##attr;\
1538 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1542 * lpfc_vport_param_init - Initialize a vport cfg attribute
1544 * Description:
1545 * Macro that given an attr e.g. hba_queue_depth expands
1546 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1547 * takes a default argument, a minimum and maximum argument.
1549 * lpfc_##attr##_init: validates the min and max values then sets the
1550 * adapter config field accordingly, or uses the default if out of range
1551 * and prints an error message.
1552 * @phba: pointer the the adapter structure.
1553 * @val: integer attribute value.
1555 * Returns:
1556 * zero on success
1557 * -EINVAL if default used
1559 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1560 static int \
1561 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1563 if (val >= minval && val <= maxval) {\
1564 vport->cfg_##attr = val;\
1565 return 0;\
1567 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1568 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1569 "allowed range is ["#minval", "#maxval"]\n", val); \
1570 vport->cfg_##attr = default;\
1571 return -EINVAL;\
1575 * lpfc_vport_param_set - Set a vport cfg attribute
1577 * Description:
1578 * Macro that given an attr e.g. hba_queue_depth expands
1579 * into a function with the name lpfc_hba_queue_depth_set
1581 * lpfc_##attr##_set: validates the min and max values then sets the
1582 * adapter config field if in the valid range. prints error message
1583 * and does not set the parameter if invalid.
1584 * @phba: pointer the the adapter structure.
1585 * @val: integer attribute value.
1587 * Returns:
1588 * zero on success
1589 * -EINVAL if val is invalid
1591 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1592 static int \
1593 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1595 if (val >= minval && val <= maxval) {\
1596 vport->cfg_##attr = val;\
1597 return 0;\
1599 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1600 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1601 "allowed range is ["#minval", "#maxval"]\n", val); \
1602 return -EINVAL;\
1606 * lpfc_vport_param_store - Set a vport attribute
1608 * Description:
1609 * Macro that given an attr e.g. hba_queue_depth
1610 * expands into a function with the name lpfc_hba_queue_depth_store
1612 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1613 * use the lpfc_##attr##_set function to set the value.
1614 * @cdev: class device that is converted into a Scsi_host.
1615 * @buf: contains the attribute value in decimal.
1616 * @count: not used.
1618 * Returns:
1619 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1620 * length of buffer upon success.
1622 #define lpfc_vport_param_store(attr) \
1623 static ssize_t \
1624 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1625 const char *buf, size_t count) \
1627 struct Scsi_Host *shost = class_to_shost(dev);\
1628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1629 uint val = 0;\
1630 if (!isdigit(buf[0]))\
1631 return -EINVAL;\
1632 if (sscanf(buf, "%i", &val) != 1)\
1633 return -EINVAL;\
1634 if (lpfc_##attr##_set(vport, val) == 0) \
1635 return strlen(buf);\
1636 else \
1637 return -EINVAL;\
1641 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1642 static uint lpfc_##name = defval;\
1643 module_param(lpfc_##name, uint, S_IRUGO);\
1644 MODULE_PARM_DESC(lpfc_##name, desc);\
1645 lpfc_param_init(name, defval, minval, maxval)
1647 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1648 static uint lpfc_##name = defval;\
1649 module_param(lpfc_##name, uint, S_IRUGO);\
1650 MODULE_PARM_DESC(lpfc_##name, desc);\
1651 lpfc_param_show(name)\
1652 lpfc_param_init(name, defval, minval, maxval)\
1653 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1655 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1656 static uint lpfc_##name = defval;\
1657 module_param(lpfc_##name, uint, S_IRUGO);\
1658 MODULE_PARM_DESC(lpfc_##name, desc);\
1659 lpfc_param_show(name)\
1660 lpfc_param_init(name, defval, minval, maxval)\
1661 lpfc_param_set(name, defval, minval, maxval)\
1662 lpfc_param_store(name)\
1663 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1664 lpfc_##name##_show, lpfc_##name##_store)
1666 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1667 static uint lpfc_##name = defval;\
1668 module_param(lpfc_##name, uint, S_IRUGO);\
1669 MODULE_PARM_DESC(lpfc_##name, desc);\
1670 lpfc_param_hex_show(name)\
1671 lpfc_param_init(name, defval, minval, maxval)\
1672 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1674 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1675 static uint lpfc_##name = defval;\
1676 module_param(lpfc_##name, uint, S_IRUGO);\
1677 MODULE_PARM_DESC(lpfc_##name, desc);\
1678 lpfc_param_hex_show(name)\
1679 lpfc_param_init(name, defval, minval, maxval)\
1680 lpfc_param_set(name, defval, minval, maxval)\
1681 lpfc_param_store(name)\
1682 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1683 lpfc_##name##_show, lpfc_##name##_store)
1685 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1686 static uint lpfc_##name = defval;\
1687 module_param(lpfc_##name, uint, S_IRUGO);\
1688 MODULE_PARM_DESC(lpfc_##name, desc);\
1689 lpfc_vport_param_init(name, defval, minval, maxval)
1691 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1692 static uint lpfc_##name = defval;\
1693 module_param(lpfc_##name, uint, S_IRUGO);\
1694 MODULE_PARM_DESC(lpfc_##name, desc);\
1695 lpfc_vport_param_show(name)\
1696 lpfc_vport_param_init(name, defval, minval, maxval)\
1697 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1699 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1700 static uint lpfc_##name = defval;\
1701 module_param(lpfc_##name, uint, S_IRUGO);\
1702 MODULE_PARM_DESC(lpfc_##name, desc);\
1703 lpfc_vport_param_show(name)\
1704 lpfc_vport_param_init(name, defval, minval, maxval)\
1705 lpfc_vport_param_set(name, defval, minval, maxval)\
1706 lpfc_vport_param_store(name)\
1707 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1708 lpfc_##name##_show, lpfc_##name##_store)
1710 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1711 static uint lpfc_##name = defval;\
1712 module_param(lpfc_##name, uint, S_IRUGO);\
1713 MODULE_PARM_DESC(lpfc_##name, desc);\
1714 lpfc_vport_param_hex_show(name)\
1715 lpfc_vport_param_init(name, defval, minval, maxval)\
1716 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1718 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1719 static uint lpfc_##name = defval;\
1720 module_param(lpfc_##name, uint, S_IRUGO);\
1721 MODULE_PARM_DESC(lpfc_##name, desc);\
1722 lpfc_vport_param_hex_show(name)\
1723 lpfc_vport_param_init(name, defval, minval, maxval)\
1724 lpfc_vport_param_set(name, defval, minval, maxval)\
1725 lpfc_vport_param_store(name)\
1726 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1727 lpfc_##name##_show, lpfc_##name##_store)
1729 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1730 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1731 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1732 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1733 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1734 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1735 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1736 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1737 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1738 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1739 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1740 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1741 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1742 lpfc_link_state_store);
1743 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1744 lpfc_option_rom_version_show, NULL);
1745 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1746 lpfc_num_discovered_ports_show, NULL);
1747 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1748 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1749 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1750 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1751 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1752 lpfc_board_mode_show, lpfc_board_mode_store);
1753 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1754 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1755 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1756 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1757 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1758 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1759 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1760 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1761 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1762 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1763 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1764 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1766 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1769 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1770 * @dev: class device that is converted into a Scsi_host.
1771 * @attr: device attribute, not used.
1772 * @buf: containing the string lpfc_soft_wwn_key.
1773 * @count: must be size of lpfc_soft_wwn_key.
1775 * Returns:
1776 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1777 * length of buf indicates success
1779 static ssize_t
1780 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1781 const char *buf, size_t count)
1783 struct Scsi_Host *shost = class_to_shost(dev);
1784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1785 struct lpfc_hba *phba = vport->phba;
1786 unsigned int cnt = count;
1789 * We're doing a simple sanity check for soft_wwpn setting.
1790 * We require that the user write a specific key to enable
1791 * the soft_wwpn attribute to be settable. Once the attribute
1792 * is written, the enable key resets. If further updates are
1793 * desired, the key must be written again to re-enable the
1794 * attribute.
1796 * The "key" is not secret - it is a hardcoded string shown
1797 * here. The intent is to protect against the random user or
1798 * application that is just writing attributes.
1801 /* count may include a LF at end of string */
1802 if (buf[cnt-1] == '\n')
1803 cnt--;
1805 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1806 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1807 return -EINVAL;
1809 phba->soft_wwn_enable = 1;
1810 return count;
1812 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1813 lpfc_soft_wwn_enable_store);
1816 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1817 * @dev: class device that is converted into a Scsi_host.
1818 * @attr: device attribute, not used.
1819 * @buf: on return contains the wwpn in hexadecimal.
1821 * Returns: size of formatted string.
1823 static ssize_t
1824 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1825 char *buf)
1827 struct Scsi_Host *shost = class_to_shost(dev);
1828 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1829 struct lpfc_hba *phba = vport->phba;
1831 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1832 (unsigned long long)phba->cfg_soft_wwpn);
1836 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1837 * @dev class device that is converted into a Scsi_host.
1838 * @attr: device attribute, not used.
1839 * @buf: contains the wwpn in hexadecimal.
1840 * @count: number of wwpn bytes in buf
1842 * Returns:
1843 * -EACCES hba reset not enabled, adapter over temp
1844 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1845 * -EIO error taking adapter offline or online
1846 * value of count on success
1848 static ssize_t
1849 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1850 const char *buf, size_t count)
1852 struct Scsi_Host *shost = class_to_shost(dev);
1853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
1855 struct completion online_compl;
1856 int stat1=0, stat2=0;
1857 unsigned int i, j, cnt=count;
1858 u8 wwpn[8];
1859 int rc;
1861 if (!phba->cfg_enable_hba_reset)
1862 return -EACCES;
1863 spin_lock_irq(&phba->hbalock);
1864 if (phba->over_temp_state == HBA_OVER_TEMP) {
1865 spin_unlock_irq(&phba->hbalock);
1866 return -EACCES;
1868 spin_unlock_irq(&phba->hbalock);
1869 /* count may include a LF at end of string */
1870 if (buf[cnt-1] == '\n')
1871 cnt--;
1873 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1874 ((cnt == 17) && (*buf++ != 'x')) ||
1875 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1876 return -EINVAL;
1878 phba->soft_wwn_enable = 0;
1880 memset(wwpn, 0, sizeof(wwpn));
1882 /* Validate and store the new name */
1883 for (i=0, j=0; i < 16; i++) {
1884 int value;
1886 value = hex_to_bin(*buf++);
1887 if (value >= 0)
1888 j = (j << 4) | value;
1889 else
1890 return -EINVAL;
1891 if (i % 2) {
1892 wwpn[i/2] = j & 0xff;
1893 j = 0;
1896 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1897 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1898 if (phba->cfg_soft_wwnn)
1899 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1901 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1902 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1904 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1905 if (stat1)
1906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1907 "0463 lpfc_soft_wwpn attribute set failed to "
1908 "reinit adapter - %d\n", stat1);
1909 init_completion(&online_compl);
1910 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1911 LPFC_EVT_ONLINE);
1912 if (rc == 0)
1913 return -ENOMEM;
1915 wait_for_completion(&online_compl);
1916 if (stat2)
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "0464 lpfc_soft_wwpn attribute set failed to "
1919 "reinit adapter - %d\n", stat2);
1920 return (stat1 || stat2) ? -EIO : count;
1922 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1923 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1926 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1927 * @dev: class device that is converted into a Scsi_host.
1928 * @attr: device attribute, not used.
1929 * @buf: on return contains the wwnn in hexadecimal.
1931 * Returns: size of formatted string.
1933 static ssize_t
1934 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1935 char *buf)
1937 struct Scsi_Host *shost = class_to_shost(dev);
1938 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1939 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1940 (unsigned long long)phba->cfg_soft_wwnn);
1944 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1945 * @cdev: class device that is converted into a Scsi_host.
1946 * @buf: contains the ww node name in hexadecimal.
1947 * @count: number of wwnn bytes in buf.
1949 * Returns:
1950 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1951 * value of count on success
1953 static ssize_t
1954 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1955 const char *buf, size_t count)
1957 struct Scsi_Host *shost = class_to_shost(dev);
1958 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1959 unsigned int i, j, cnt=count;
1960 u8 wwnn[8];
1962 /* count may include a LF at end of string */
1963 if (buf[cnt-1] == '\n')
1964 cnt--;
1966 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1967 ((cnt == 17) && (*buf++ != 'x')) ||
1968 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1969 return -EINVAL;
1972 * Allow wwnn to be set many times, as long as the enable is set.
1973 * However, once the wwpn is set, everything locks.
1976 memset(wwnn, 0, sizeof(wwnn));
1978 /* Validate and store the new name */
1979 for (i=0, j=0; i < 16; i++) {
1980 int value;
1982 value = hex_to_bin(*buf++);
1983 if (value >= 0)
1984 j = (j << 4) | value;
1985 else
1986 return -EINVAL;
1987 if (i % 2) {
1988 wwnn[i/2] = j & 0xff;
1989 j = 0;
1992 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1994 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1995 "lpfc%d: soft_wwnn set. Value will take effect upon "
1996 "setting of the soft_wwpn\n", phba->brd_no);
1998 return count;
2000 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2001 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2004 static int lpfc_poll = 0;
2005 module_param(lpfc_poll, int, S_IRUGO);
2006 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2007 " 0 - none,"
2008 " 1 - poll with interrupts enabled"
2009 " 3 - poll and disable FCP ring interrupts");
2011 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2012 lpfc_poll_show, lpfc_poll_store);
2014 int lpfc_sli_mode = 0;
2015 module_param(lpfc_sli_mode, int, S_IRUGO);
2016 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2017 " 0 - auto (SLI-3 if supported),"
2018 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2019 " 3 - select SLI-3");
2021 int lpfc_enable_npiv = 1;
2022 module_param(lpfc_enable_npiv, int, S_IRUGO);
2023 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2024 lpfc_param_show(enable_npiv);
2025 lpfc_param_init(enable_npiv, 1, 0, 1);
2026 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2028 int lpfc_enable_rrq;
2029 module_param(lpfc_enable_rrq, int, S_IRUGO);
2030 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2031 lpfc_param_show(enable_rrq);
2032 lpfc_param_init(enable_rrq, 0, 0, 1);
2033 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2036 # lpfc_suppress_link_up: Bring link up at initialization
2037 # 0x0 = bring link up (issue MBX_INIT_LINK)
2038 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2039 # 0x2 = never bring up link
2040 # Default value is 0.
2042 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2043 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2044 "Suppress Link Up at initialization");
2046 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2047 # 1 - (1024)
2048 # 2 - (2048)
2049 # 3 - (3072)
2050 # 4 - (4096)
2051 # 5 - (5120)
2053 static ssize_t
2054 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2056 struct Scsi_Host *shost = class_to_shost(dev);
2057 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2059 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2062 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2063 lpfc_iocb_hw_show, NULL);
2064 static ssize_t
2065 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2067 struct Scsi_Host *shost = class_to_shost(dev);
2068 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2070 return snprintf(buf, PAGE_SIZE, "%d\n",
2071 phba->sli.ring[LPFC_ELS_RING].txq_max);
2074 static DEVICE_ATTR(txq_hw, S_IRUGO,
2075 lpfc_txq_hw_show, NULL);
2076 static ssize_t
2077 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2078 char *buf)
2080 struct Scsi_Host *shost = class_to_shost(dev);
2081 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2083 return snprintf(buf, PAGE_SIZE, "%d\n",
2084 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2087 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2088 lpfc_txcmplq_hw_show, NULL);
2090 int lpfc_iocb_cnt = 2;
2091 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2092 MODULE_PARM_DESC(lpfc_iocb_cnt,
2093 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2094 lpfc_param_show(iocb_cnt);
2095 lpfc_param_init(iocb_cnt, 2, 1, 5);
2096 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2097 lpfc_iocb_cnt_show, NULL);
2100 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2101 # until the timer expires. Value range is [0,255]. Default value is 30.
2103 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2104 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2105 module_param(lpfc_nodev_tmo, int, 0);
2106 MODULE_PARM_DESC(lpfc_nodev_tmo,
2107 "Seconds driver will hold I/O waiting "
2108 "for a device to come back");
2111 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2112 * @dev: class converted to a Scsi_host structure.
2113 * @attr: device attribute, not used.
2114 * @buf: on return contains the dev loss timeout in decimal.
2116 * Returns: size of formatted string.
2118 static ssize_t
2119 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2120 char *buf)
2122 struct Scsi_Host *shost = class_to_shost(dev);
2123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2125 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2129 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2130 * @vport: lpfc vport structure pointer.
2131 * @val: contains the nodev timeout value.
2133 * Description:
2134 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2135 * a kernel error message is printed and zero is returned.
2136 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2137 * Otherwise nodev tmo is set to the default value.
2139 * Returns:
2140 * zero if already set or if val is in range
2141 * -EINVAL val out of range
2143 static int
2144 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2146 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2147 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2148 if (val != LPFC_DEF_DEVLOSS_TMO)
2149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2150 "0407 Ignoring nodev_tmo module "
2151 "parameter because devloss_tmo is "
2152 "set.\n");
2153 return 0;
2156 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2157 vport->cfg_nodev_tmo = val;
2158 vport->cfg_devloss_tmo = val;
2159 return 0;
2161 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2162 "0400 lpfc_nodev_tmo attribute cannot be set to"
2163 " %d, allowed range is [%d, %d]\n",
2164 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2165 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2166 return -EINVAL;
2170 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2171 * @vport: lpfc vport structure pointer.
2173 * Description:
2174 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2176 static void
2177 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2179 struct Scsi_Host *shost;
2180 struct lpfc_nodelist *ndlp;
2182 shost = lpfc_shost_from_vport(vport);
2183 spin_lock_irq(shost->host_lock);
2184 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2185 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2186 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2187 spin_unlock_irq(shost->host_lock);
2191 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2192 * @vport: lpfc vport structure pointer.
2193 * @val: contains the tmo value.
2195 * Description:
2196 * If the devloss tmo is already set or the vport dev loss tmo has changed
2197 * then a kernel error message is printed and zero is returned.
2198 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2199 * Otherwise nodev tmo is set to the default value.
2201 * Returns:
2202 * zero if already set or if val is in range
2203 * -EINVAL val out of range
2205 static int
2206 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2208 if (vport->dev_loss_tmo_changed ||
2209 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2211 "0401 Ignoring change to nodev_tmo "
2212 "because devloss_tmo is set.\n");
2213 return 0;
2215 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2216 vport->cfg_nodev_tmo = val;
2217 vport->cfg_devloss_tmo = val;
2219 * For compat: set the fc_host dev loss so new rports
2220 * will get the value.
2222 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2223 lpfc_update_rport_devloss_tmo(vport);
2224 return 0;
2226 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2227 "0403 lpfc_nodev_tmo attribute cannot be set to"
2228 "%d, allowed range is [%d, %d]\n",
2229 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2230 return -EINVAL;
2233 lpfc_vport_param_store(nodev_tmo)
2235 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2236 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2239 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2240 # disappear until the timer expires. Value range is [0,255]. Default
2241 # value is 30.
2243 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2244 MODULE_PARM_DESC(lpfc_devloss_tmo,
2245 "Seconds driver will hold I/O waiting "
2246 "for a device to come back");
2247 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2248 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2249 lpfc_vport_param_show(devloss_tmo)
2252 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2253 * @vport: lpfc vport structure pointer.
2254 * @val: contains the tmo value.
2256 * Description:
2257 * If val is in a valid range then set the vport nodev tmo,
2258 * devloss tmo, also set the vport dev loss tmo changed flag.
2259 * Else a kernel error message is printed.
2261 * Returns:
2262 * zero if val is in range
2263 * -EINVAL val out of range
2265 static int
2266 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2268 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2269 vport->cfg_nodev_tmo = val;
2270 vport->cfg_devloss_tmo = val;
2271 vport->dev_loss_tmo_changed = 1;
2272 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2273 lpfc_update_rport_devloss_tmo(vport);
2274 return 0;
2277 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2278 "0404 lpfc_devloss_tmo attribute cannot be set to"
2279 " %d, allowed range is [%d, %d]\n",
2280 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2281 return -EINVAL;
2284 lpfc_vport_param_store(devloss_tmo)
2285 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2286 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2289 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2290 # deluged with LOTS of information.
2291 # You can set a bit mask to record specific types of verbose messages:
2292 # See lpfc_logmsh.h for definitions.
2294 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2295 "Verbose logging bit-mask");
2298 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2299 # objects that have been registered with the nameserver after login.
2301 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2302 "Deregister nameserver objects before LOGO");
2305 # lun_queue_depth: This parameter is used to limit the number of outstanding
2306 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2308 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2309 "Max number of FCP commands we can queue to a specific LUN");
2312 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2313 # commands per target port. Value range is [10,65535]. Default value is 65535.
2315 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2316 "Max number of FCP commands we can queue to a specific target port");
2319 # hba_queue_depth: This parameter is used to limit the number of outstanding
2320 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2321 # value is greater than the maximum number of exchanges supported by the HBA,
2322 # then maximum number of exchanges supported by the HBA is used to determine
2323 # the hba_queue_depth.
2325 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2326 "Max number of FCP commands we can queue to a lpfc HBA");
2329 # peer_port_login: This parameter allows/prevents logins
2330 # between peer ports hosted on the same physical port.
2331 # When this parameter is set 0 peer ports of same physical port
2332 # are not allowed to login to each other.
2333 # When this parameter is set 1 peer ports of same physical port
2334 # are allowed to login to each other.
2335 # Default value of this parameter is 0.
2337 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2338 "Allow peer ports on the same physical port to login to each "
2339 "other.");
2342 # restrict_login: This parameter allows/prevents logins
2343 # between Virtual Ports and remote initiators.
2344 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2345 # other initiators and will attempt to PLOGI all remote ports.
2346 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2347 # remote ports and will not attempt to PLOGI to other initiators.
2348 # This parameter does not restrict to the physical port.
2349 # This parameter does not restrict logins to Fabric resident remote ports.
2350 # Default value of this parameter is 1.
2352 static int lpfc_restrict_login = 1;
2353 module_param(lpfc_restrict_login, int, S_IRUGO);
2354 MODULE_PARM_DESC(lpfc_restrict_login,
2355 "Restrict virtual ports login to remote initiators.");
2356 lpfc_vport_param_show(restrict_login);
2359 * lpfc_restrict_login_init - Set the vport restrict login flag
2360 * @vport: lpfc vport structure pointer.
2361 * @val: contains the restrict login value.
2363 * Description:
2364 * If val is not in a valid range then log a kernel error message and set
2365 * the vport restrict login to one.
2366 * If the port type is physical clear the restrict login flag and return.
2367 * Else set the restrict login flag to val.
2369 * Returns:
2370 * zero if val is in range
2371 * -EINVAL val out of range
2373 static int
2374 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2376 if (val < 0 || val > 1) {
2377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2378 "0422 lpfc_restrict_login attribute cannot "
2379 "be set to %d, allowed range is [0, 1]\n",
2380 val);
2381 vport->cfg_restrict_login = 1;
2382 return -EINVAL;
2384 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2385 vport->cfg_restrict_login = 0;
2386 return 0;
2388 vport->cfg_restrict_login = val;
2389 return 0;
2393 * lpfc_restrict_login_set - Set the vport restrict login flag
2394 * @vport: lpfc vport structure pointer.
2395 * @val: contains the restrict login value.
2397 * Description:
2398 * If val is not in a valid range then log a kernel error message and set
2399 * the vport restrict login to one.
2400 * If the port type is physical and the val is not zero log a kernel
2401 * error message, clear the restrict login flag and return zero.
2402 * Else set the restrict login flag to val.
2404 * Returns:
2405 * zero if val is in range
2406 * -EINVAL val out of range
2408 static int
2409 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2411 if (val < 0 || val > 1) {
2412 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2413 "0425 lpfc_restrict_login attribute cannot "
2414 "be set to %d, allowed range is [0, 1]\n",
2415 val);
2416 vport->cfg_restrict_login = 1;
2417 return -EINVAL;
2419 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2420 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2421 "0468 lpfc_restrict_login must be 0 for "
2422 "Physical ports.\n");
2423 vport->cfg_restrict_login = 0;
2424 return 0;
2426 vport->cfg_restrict_login = val;
2427 return 0;
2429 lpfc_vport_param_store(restrict_login);
2430 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2431 lpfc_restrict_login_show, lpfc_restrict_login_store);
2434 # Some disk devices have a "select ID" or "select Target" capability.
2435 # From a protocol standpoint "select ID" usually means select the
2436 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2437 # annex" which contains a table that maps a "select ID" (a number
2438 # between 0 and 7F) to an ALPA. By default, for compatibility with
2439 # older drivers, the lpfc driver scans this table from low ALPA to high
2440 # ALPA.
2442 # Turning on the scan-down variable (on = 1, off = 0) will
2443 # cause the lpfc driver to use an inverted table, effectively
2444 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2446 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2447 # and will not work across a fabric. Also this parameter will take
2448 # effect only in the case when ALPA map is not available.)
2450 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2451 "Start scanning for devices from highest ALPA to lowest");
2454 # lpfc_topology: link topology for init link
2455 # 0x0 = attempt loop mode then point-to-point
2456 # 0x01 = internal loopback mode
2457 # 0x02 = attempt point-to-point mode only
2458 # 0x04 = attempt loop mode only
2459 # 0x06 = attempt point-to-point mode then loop
2460 # Set point-to-point mode if you want to run as an N_Port.
2461 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2462 # Default value is 0.
2466 * lpfc_topology_set - Set the adapters topology field
2467 * @phba: lpfc_hba pointer.
2468 * @val: topology value.
2470 * Description:
2471 * If val is in a valid range then set the adapter's topology field and
2472 * issue a lip; if the lip fails reset the topology to the old value.
2474 * If the value is not in range log a kernel error message and return an error.
2476 * Returns:
2477 * zero if val is in range and lip okay
2478 * non-zero return value from lpfc_issue_lip()
2479 * -EINVAL val out of range
2481 static ssize_t
2482 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2483 const char *buf, size_t count)
2485 struct Scsi_Host *shost = class_to_shost(dev);
2486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2487 struct lpfc_hba *phba = vport->phba;
2488 int val = 0;
2489 int nolip = 0;
2490 const char *val_buf = buf;
2491 int err;
2492 uint32_t prev_val;
2494 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2495 nolip = 1;
2496 val_buf = &buf[strlen("nolip ")];
2499 if (!isdigit(val_buf[0]))
2500 return -EINVAL;
2501 if (sscanf(val_buf, "%i", &val) != 1)
2502 return -EINVAL;
2504 if (val >= 0 && val <= 6) {
2505 prev_val = phba->cfg_topology;
2506 phba->cfg_topology = val;
2507 if (nolip)
2508 return strlen(buf);
2510 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2511 if (err) {
2512 phba->cfg_topology = prev_val;
2513 return -EINVAL;
2514 } else
2515 return strlen(buf);
2517 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2518 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2519 "allowed range is [0, 6]\n",
2520 phba->brd_no, val);
2521 return -EINVAL;
2523 static int lpfc_topology = 0;
2524 module_param(lpfc_topology, int, S_IRUGO);
2525 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2526 lpfc_param_show(topology)
2527 lpfc_param_init(topology, 0, 0, 6)
2528 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2529 lpfc_topology_show, lpfc_topology_store);
2532 * lpfc_static_vport_show: Read callback function for
2533 * lpfc_static_vport sysfs file.
2534 * @dev: Pointer to class device object.
2535 * @attr: device attribute structure.
2536 * @buf: Data buffer.
2538 * This function is the read call back function for
2539 * lpfc_static_vport sysfs file. The lpfc_static_vport
2540 * sysfs file report the mageability of the vport.
2542 static ssize_t
2543 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2544 char *buf)
2546 struct Scsi_Host *shost = class_to_shost(dev);
2547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2548 if (vport->vport_flag & STATIC_VPORT)
2549 sprintf(buf, "1\n");
2550 else
2551 sprintf(buf, "0\n");
2553 return strlen(buf);
2557 * Sysfs attribute to control the statistical data collection.
2559 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2560 lpfc_static_vport_show, NULL);
2563 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2564 * @dev: Pointer to class device.
2565 * @buf: Data buffer.
2566 * @count: Size of the data buffer.
2568 * This function get called when an user write to the lpfc_stat_data_ctrl
2569 * sysfs file. This function parse the command written to the sysfs file
2570 * and take appropriate action. These commands are used for controlling
2571 * driver statistical data collection.
2572 * Following are the command this function handles.
2574 * setbucket <bucket_type> <base> <step>
2575 * = Set the latency buckets.
2576 * destroybucket = destroy all the buckets.
2577 * start = start data collection
2578 * stop = stop data collection
2579 * reset = reset the collected data
2581 static ssize_t
2582 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2583 const char *buf, size_t count)
2585 struct Scsi_Host *shost = class_to_shost(dev);
2586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2587 struct lpfc_hba *phba = vport->phba;
2588 #define LPFC_MAX_DATA_CTRL_LEN 1024
2589 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2590 unsigned long i;
2591 char *str_ptr, *token;
2592 struct lpfc_vport **vports;
2593 struct Scsi_Host *v_shost;
2594 char *bucket_type_str, *base_str, *step_str;
2595 unsigned long base, step, bucket_type;
2597 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2598 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2599 return -EINVAL;
2601 strcpy(bucket_data, buf);
2602 str_ptr = &bucket_data[0];
2603 /* Ignore this token - this is command token */
2604 token = strsep(&str_ptr, "\t ");
2605 if (!token)
2606 return -EINVAL;
2608 bucket_type_str = strsep(&str_ptr, "\t ");
2609 if (!bucket_type_str)
2610 return -EINVAL;
2612 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2613 bucket_type = LPFC_LINEAR_BUCKET;
2614 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2615 bucket_type = LPFC_POWER2_BUCKET;
2616 else
2617 return -EINVAL;
2619 base_str = strsep(&str_ptr, "\t ");
2620 if (!base_str)
2621 return -EINVAL;
2622 base = simple_strtoul(base_str, NULL, 0);
2624 step_str = strsep(&str_ptr, "\t ");
2625 if (!step_str)
2626 return -EINVAL;
2627 step = simple_strtoul(step_str, NULL, 0);
2628 if (!step)
2629 return -EINVAL;
2631 /* Block the data collection for every vport */
2632 vports = lpfc_create_vport_work_array(phba);
2633 if (vports == NULL)
2634 return -ENOMEM;
2636 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2637 v_shost = lpfc_shost_from_vport(vports[i]);
2638 spin_lock_irq(v_shost->host_lock);
2639 /* Block and reset data collection */
2640 vports[i]->stat_data_blocked = 1;
2641 if (vports[i]->stat_data_enabled)
2642 lpfc_vport_reset_stat_data(vports[i]);
2643 spin_unlock_irq(v_shost->host_lock);
2646 /* Set the bucket attributes */
2647 phba->bucket_type = bucket_type;
2648 phba->bucket_base = base;
2649 phba->bucket_step = step;
2651 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2652 v_shost = lpfc_shost_from_vport(vports[i]);
2654 /* Unblock data collection */
2655 spin_lock_irq(v_shost->host_lock);
2656 vports[i]->stat_data_blocked = 0;
2657 spin_unlock_irq(v_shost->host_lock);
2659 lpfc_destroy_vport_work_array(phba, vports);
2660 return strlen(buf);
2663 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2664 vports = lpfc_create_vport_work_array(phba);
2665 if (vports == NULL)
2666 return -ENOMEM;
2668 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2669 v_shost = lpfc_shost_from_vport(vports[i]);
2670 spin_lock_irq(shost->host_lock);
2671 vports[i]->stat_data_blocked = 1;
2672 lpfc_free_bucket(vport);
2673 vport->stat_data_enabled = 0;
2674 vports[i]->stat_data_blocked = 0;
2675 spin_unlock_irq(shost->host_lock);
2677 lpfc_destroy_vport_work_array(phba, vports);
2678 phba->bucket_type = LPFC_NO_BUCKET;
2679 phba->bucket_base = 0;
2680 phba->bucket_step = 0;
2681 return strlen(buf);
2684 if (!strncmp(buf, "start", strlen("start"))) {
2685 /* If no buckets configured return error */
2686 if (phba->bucket_type == LPFC_NO_BUCKET)
2687 return -EINVAL;
2688 spin_lock_irq(shost->host_lock);
2689 if (vport->stat_data_enabled) {
2690 spin_unlock_irq(shost->host_lock);
2691 return strlen(buf);
2693 lpfc_alloc_bucket(vport);
2694 vport->stat_data_enabled = 1;
2695 spin_unlock_irq(shost->host_lock);
2696 return strlen(buf);
2699 if (!strncmp(buf, "stop", strlen("stop"))) {
2700 spin_lock_irq(shost->host_lock);
2701 if (vport->stat_data_enabled == 0) {
2702 spin_unlock_irq(shost->host_lock);
2703 return strlen(buf);
2705 lpfc_free_bucket(vport);
2706 vport->stat_data_enabled = 0;
2707 spin_unlock_irq(shost->host_lock);
2708 return strlen(buf);
2711 if (!strncmp(buf, "reset", strlen("reset"))) {
2712 if ((phba->bucket_type == LPFC_NO_BUCKET)
2713 || !vport->stat_data_enabled)
2714 return strlen(buf);
2715 spin_lock_irq(shost->host_lock);
2716 vport->stat_data_blocked = 1;
2717 lpfc_vport_reset_stat_data(vport);
2718 vport->stat_data_blocked = 0;
2719 spin_unlock_irq(shost->host_lock);
2720 return strlen(buf);
2722 return -EINVAL;
2727 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2728 * @dev: Pointer to class device object.
2729 * @buf: Data buffer.
2731 * This function is the read call back function for
2732 * lpfc_stat_data_ctrl sysfs file. This function report the
2733 * current statistical data collection state.
2735 static ssize_t
2736 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2737 char *buf)
2739 struct Scsi_Host *shost = class_to_shost(dev);
2740 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2741 struct lpfc_hba *phba = vport->phba;
2742 int index = 0;
2743 int i;
2744 char *bucket_type;
2745 unsigned long bucket_value;
2747 switch (phba->bucket_type) {
2748 case LPFC_LINEAR_BUCKET:
2749 bucket_type = "linear";
2750 break;
2751 case LPFC_POWER2_BUCKET:
2752 bucket_type = "power2";
2753 break;
2754 default:
2755 bucket_type = "No Bucket";
2756 break;
2759 sprintf(&buf[index], "Statistical Data enabled :%d, "
2760 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2761 " Bucket step :%d\nLatency Ranges :",
2762 vport->stat_data_enabled, vport->stat_data_blocked,
2763 bucket_type, phba->bucket_base, phba->bucket_step);
2764 index = strlen(buf);
2765 if (phba->bucket_type != LPFC_NO_BUCKET) {
2766 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2767 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2768 bucket_value = phba->bucket_base +
2769 phba->bucket_step * i;
2770 else
2771 bucket_value = phba->bucket_base +
2772 (1 << i) * phba->bucket_step;
2774 if (index + 10 > PAGE_SIZE)
2775 break;
2776 sprintf(&buf[index], "%08ld ", bucket_value);
2777 index = strlen(buf);
2780 sprintf(&buf[index], "\n");
2781 return strlen(buf);
2785 * Sysfs attribute to control the statistical data collection.
2787 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2788 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2791 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2795 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2796 * for each target.
2798 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2799 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2800 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2804 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2805 * @filp: sysfs file
2806 * @kobj: Pointer to the kernel object
2807 * @bin_attr: Attribute object
2808 * @buff: Buffer pointer
2809 * @off: File offset
2810 * @count: Buffer size
2812 * This function is the read call back function for lpfc_drvr_stat_data
2813 * sysfs file. This function export the statistical data to user
2814 * applications.
2816 static ssize_t
2817 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2818 struct bin_attribute *bin_attr,
2819 char *buf, loff_t off, size_t count)
2821 struct device *dev = container_of(kobj, struct device,
2822 kobj);
2823 struct Scsi_Host *shost = class_to_shost(dev);
2824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2825 struct lpfc_hba *phba = vport->phba;
2826 int i = 0, index = 0;
2827 unsigned long nport_index;
2828 struct lpfc_nodelist *ndlp = NULL;
2829 nport_index = (unsigned long)off /
2830 MAX_STAT_DATA_SIZE_PER_TARGET;
2832 if (!vport->stat_data_enabled || vport->stat_data_blocked
2833 || (phba->bucket_type == LPFC_NO_BUCKET))
2834 return 0;
2836 spin_lock_irq(shost->host_lock);
2837 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2838 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2839 continue;
2841 if (nport_index > 0) {
2842 nport_index--;
2843 continue;
2846 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2847 > count)
2848 break;
2850 if (!ndlp->lat_data)
2851 continue;
2853 /* Print the WWN */
2854 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2855 ndlp->nlp_portname.u.wwn[0],
2856 ndlp->nlp_portname.u.wwn[1],
2857 ndlp->nlp_portname.u.wwn[2],
2858 ndlp->nlp_portname.u.wwn[3],
2859 ndlp->nlp_portname.u.wwn[4],
2860 ndlp->nlp_portname.u.wwn[5],
2861 ndlp->nlp_portname.u.wwn[6],
2862 ndlp->nlp_portname.u.wwn[7]);
2864 index = strlen(buf);
2866 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2867 sprintf(&buf[index], "%010u,",
2868 ndlp->lat_data[i].cmd_count);
2869 index = strlen(buf);
2871 sprintf(&buf[index], "\n");
2872 index = strlen(buf);
2874 spin_unlock_irq(shost->host_lock);
2875 return index;
2878 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2879 .attr = {
2880 .name = "lpfc_drvr_stat_data",
2881 .mode = S_IRUSR,
2883 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2884 .read = sysfs_drvr_stat_data_read,
2885 .write = NULL,
2889 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2890 # connection.
2891 # Value range is [0,16]. Default value is 0.
2894 * lpfc_link_speed_set - Set the adapters link speed
2895 * @phba: lpfc_hba pointer.
2896 * @val: link speed value.
2898 * Description:
2899 * If val is in a valid range then set the adapter's link speed field and
2900 * issue a lip; if the lip fails reset the link speed to the old value.
2902 * Notes:
2903 * If the value is not in range log a kernel error message and return an error.
2905 * Returns:
2906 * zero if val is in range and lip okay.
2907 * non-zero return value from lpfc_issue_lip()
2908 * -EINVAL val out of range
2910 static ssize_t
2911 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2912 const char *buf, size_t count)
2914 struct Scsi_Host *shost = class_to_shost(dev);
2915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2916 struct lpfc_hba *phba = vport->phba;
2917 int val = LPFC_USER_LINK_SPEED_AUTO;
2918 int nolip = 0;
2919 const char *val_buf = buf;
2920 int err;
2921 uint32_t prev_val;
2923 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2924 nolip = 1;
2925 val_buf = &buf[strlen("nolip ")];
2928 if (!isdigit(val_buf[0]))
2929 return -EINVAL;
2930 if (sscanf(val_buf, "%i", &val) != 1)
2931 return -EINVAL;
2933 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2934 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2935 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2936 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2937 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2938 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2940 "2879 lpfc_link_speed attribute cannot be set "
2941 "to %d. Speed is not supported by this port.\n",
2942 val);
2943 return -EINVAL;
2945 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2946 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2947 prev_val = phba->cfg_link_speed;
2948 phba->cfg_link_speed = val;
2949 if (nolip)
2950 return strlen(buf);
2952 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2953 if (err) {
2954 phba->cfg_link_speed = prev_val;
2955 return -EINVAL;
2956 } else
2957 return strlen(buf);
2959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2960 "0469 lpfc_link_speed attribute cannot be set to %d, "
2961 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
2962 return -EINVAL;
2965 static int lpfc_link_speed = 0;
2966 module_param(lpfc_link_speed, int, S_IRUGO);
2967 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2968 lpfc_param_show(link_speed)
2971 * lpfc_link_speed_init - Set the adapters link speed
2972 * @phba: lpfc_hba pointer.
2973 * @val: link speed value.
2975 * Description:
2976 * If val is in a valid range then set the adapter's link speed field.
2978 * Notes:
2979 * If the value is not in range log a kernel error message, clear the link
2980 * speed and return an error.
2982 * Returns:
2983 * zero if val saved.
2984 * -EINVAL val out of range
2986 static int
2987 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2989 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2990 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2991 phba->cfg_link_speed = val;
2992 return 0;
2994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2995 "0405 lpfc_link_speed attribute cannot "
2996 "be set to %d, allowed values are "
2997 "["LPFC_LINK_SPEED_STRING"]\n", val);
2998 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
2999 return -EINVAL;
3002 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3003 lpfc_link_speed_show, lpfc_link_speed_store);
3006 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3007 # 0 = aer disabled or not supported
3008 # 1 = aer supported and enabled (default)
3009 # Value range is [0,1]. Default value is 1.
3013 * lpfc_aer_support_store - Set the adapter for aer support
3015 * @dev: class device that is converted into a Scsi_host.
3016 * @attr: device attribute, not used.
3017 * @buf: containing the string "selective".
3018 * @count: unused variable.
3020 * Description:
3021 * If the val is 1 and currently the device's AER capability was not
3022 * enabled, invoke the kernel's enable AER helper routine, trying to
3023 * enable the device's AER capability. If the helper routine enabling
3024 * AER returns success, update the device's cfg_aer_support flag to
3025 * indicate AER is supported by the device; otherwise, if the device
3026 * AER capability is already enabled to support AER, then do nothing.
3028 * If the val is 0 and currently the device's AER support was enabled,
3029 * invoke the kernel's disable AER helper routine. After that, update
3030 * the device's cfg_aer_support flag to indicate AER is not supported
3031 * by the device; otherwise, if the device AER capability is already
3032 * disabled from supporting AER, then do nothing.
3034 * Returns:
3035 * length of the buf on success if val is in range the intended mode
3036 * is supported.
3037 * -EINVAL if val out of range or intended mode is not supported.
3039 static ssize_t
3040 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3041 const char *buf, size_t count)
3043 struct Scsi_Host *shost = class_to_shost(dev);
3044 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3045 struct lpfc_hba *phba = vport->phba;
3046 int val = 0, rc = -EINVAL;
3048 if (!isdigit(buf[0]))
3049 return -EINVAL;
3050 if (sscanf(buf, "%i", &val) != 1)
3051 return -EINVAL;
3053 switch (val) {
3054 case 0:
3055 if (phba->hba_flag & HBA_AER_ENABLED) {
3056 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3057 if (!rc) {
3058 spin_lock_irq(&phba->hbalock);
3059 phba->hba_flag &= ~HBA_AER_ENABLED;
3060 spin_unlock_irq(&phba->hbalock);
3061 phba->cfg_aer_support = 0;
3062 rc = strlen(buf);
3063 } else
3064 rc = -EPERM;
3065 } else {
3066 phba->cfg_aer_support = 0;
3067 rc = strlen(buf);
3069 break;
3070 case 1:
3071 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3072 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3073 if (!rc) {
3074 spin_lock_irq(&phba->hbalock);
3075 phba->hba_flag |= HBA_AER_ENABLED;
3076 spin_unlock_irq(&phba->hbalock);
3077 phba->cfg_aer_support = 1;
3078 rc = strlen(buf);
3079 } else
3080 rc = -EPERM;
3081 } else {
3082 phba->cfg_aer_support = 1;
3083 rc = strlen(buf);
3085 break;
3086 default:
3087 rc = -EINVAL;
3088 break;
3090 return rc;
3093 static int lpfc_aer_support = 1;
3094 module_param(lpfc_aer_support, int, S_IRUGO);
3095 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3096 lpfc_param_show(aer_support)
3099 * lpfc_aer_support_init - Set the initial adapters aer support flag
3100 * @phba: lpfc_hba pointer.
3101 * @val: link speed value.
3103 * Description:
3104 * If val is in a valid range [0,1], then set the adapter's initial
3105 * cfg_aer_support field. It will be up to the driver's probe_one
3106 * routine to determine whether the device's AER support can be set
3107 * or not.
3109 * Notes:
3110 * If the value is not in range log a kernel error message, and
3111 * choose the default value of setting AER support and return.
3113 * Returns:
3114 * zero if val saved.
3115 * -EINVAL val out of range
3117 static int
3118 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3120 if (val == 0 || val == 1) {
3121 phba->cfg_aer_support = val;
3122 return 0;
3124 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3125 "2712 lpfc_aer_support attribute value %d out "
3126 "of range, allowed values are 0|1, setting it "
3127 "to default value of 1\n", val);
3128 /* By default, try to enable AER on a device */
3129 phba->cfg_aer_support = 1;
3130 return -EINVAL;
3133 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3134 lpfc_aer_support_show, lpfc_aer_support_store);
3137 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3138 * @dev: class device that is converted into a Scsi_host.
3139 * @attr: device attribute, not used.
3140 * @buf: containing the string "selective".
3141 * @count: unused variable.
3143 * Description:
3144 * If the @buf contains 1 and the device currently has the AER support
3145 * enabled, then invokes the kernel AER helper routine
3146 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3147 * error status register.
3149 * Notes:
3151 * Returns:
3152 * -EINVAL if the buf does not contain the 1 or the device is not currently
3153 * enabled with the AER support.
3155 static ssize_t
3156 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3157 const char *buf, size_t count)
3159 struct Scsi_Host *shost = class_to_shost(dev);
3160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3161 struct lpfc_hba *phba = vport->phba;
3162 int val, rc = -1;
3164 if (!isdigit(buf[0]))
3165 return -EINVAL;
3166 if (sscanf(buf, "%i", &val) != 1)
3167 return -EINVAL;
3168 if (val != 1)
3169 return -EINVAL;
3171 if (phba->hba_flag & HBA_AER_ENABLED)
3172 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3174 if (rc == 0)
3175 return strlen(buf);
3176 else
3177 return -EPERM;
3180 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3181 lpfc_aer_cleanup_state);
3184 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3185 # Value range is [2,3]. Default value is 3.
3187 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3188 "Select Fibre Channel class of service for FCP sequences");
3191 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3192 # is [0,1]. Default value is 0.
3194 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3195 "Use ADISC on rediscovery to authenticate FCP devices");
3198 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3199 # depth. Default value is 0. When the value of this parameter is zero the
3200 # SCSI command completion time is not used for controlling I/O queue depth. When
3201 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3202 # to limit the I/O completion time to the parameter value.
3203 # The value is set in milliseconds.
3205 static int lpfc_max_scsicmpl_time;
3206 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3207 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3208 "Use command completion time to control queue depth");
3209 lpfc_vport_param_show(max_scsicmpl_time);
3210 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3211 static int
3212 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3215 struct lpfc_nodelist *ndlp, *next_ndlp;
3217 if (val == vport->cfg_max_scsicmpl_time)
3218 return 0;
3219 if ((val < 0) || (val > 60000))
3220 return -EINVAL;
3221 vport->cfg_max_scsicmpl_time = val;
3223 spin_lock_irq(shost->host_lock);
3224 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3225 if (!NLP_CHK_NODE_ACT(ndlp))
3226 continue;
3227 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3228 continue;
3229 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3231 spin_unlock_irq(shost->host_lock);
3232 return 0;
3234 lpfc_vport_param_store(max_scsicmpl_time);
3235 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3236 lpfc_max_scsicmpl_time_show,
3237 lpfc_max_scsicmpl_time_store);
3240 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3241 # range is [0,1]. Default value is 0.
3243 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3246 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3247 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3248 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3249 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3250 # cr_delay is set to 0.
3252 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3253 "interrupt response is generated");
3255 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3256 "interrupt response is generated");
3259 # lpfc_multi_ring_support: Determines how many rings to spread available
3260 # cmd/rsp IOCB entries across.
3261 # Value range is [1,2]. Default value is 1.
3263 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3264 "SLI rings to spread IOCB entries across");
3267 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3268 # identifies what rctl value to configure the additional ring for.
3269 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3271 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3272 255, "Identifies RCTL for additional ring configuration");
3275 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3276 # identifies what type value to configure the additional ring for.
3277 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3279 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3280 255, "Identifies TYPE for additional ring configuration");
3283 # lpfc_fdmi_on: controls FDMI support.
3284 # 0 = no FDMI support
3285 # 1 = support FDMI without attribute of hostname
3286 # 2 = support FDMI with attribute of hostname
3287 # Value range [0,2]. Default value is 0.
3289 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3292 # Specifies the maximum number of ELS cmds we can have outstanding (for
3293 # discovery). Value range is [1,64]. Default value = 32.
3295 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3296 "during discovery");
3299 # lpfc_max_luns: maximum allowed LUN.
3300 # Value range is [0,65535]. Default value is 255.
3301 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3303 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3306 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3307 # Value range is [1,255], default value is 10.
3309 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3310 "Milliseconds driver will wait between polling FCP ring");
3313 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3314 # support this feature
3315 # 0 = MSI disabled
3316 # 1 = MSI enabled
3317 # 2 = MSI-X enabled (default)
3318 # Value range is [0,2]. Default value is 2.
3320 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3321 "MSI-X (2), if possible");
3324 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3326 # Value range is [636,651042]. Default value is 10000.
3328 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3329 "Set the maximum number of fast-path FCP interrupts per second");
3332 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3334 # Value range is [1,31]. Default value is 4.
3336 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3337 "Set the number of fast-path FCP work queues, if possible");
3340 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3342 # Value range is [1,7]. Default value is 1.
3344 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3345 "Set the number of fast-path FCP event queues, if possible");
3348 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3349 # 0 = HBA resets disabled
3350 # 1 = HBA resets enabled (default)
3351 # Value range is [0,1]. Default value is 1.
3353 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3356 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3357 # 0 = HBA Heartbeat disabled
3358 # 1 = HBA Heartbeat enabled (default)
3359 # Value range is [0,1]. Default value is 1.
3361 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3364 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3365 # 0 = BlockGuard disabled (default)
3366 # 1 = BlockGuard enabled
3367 # Value range is [0,1]. Default value is 0.
3369 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3372 # lpfc_prot_mask: i
3373 # - Bit mask of host protection capabilities used to register with the
3374 # SCSI mid-layer
3375 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3376 # - Allows you to ultimately specify which profiles to use
3377 # - Default will result in registering capabilities for all profiles.
3380 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3382 module_param(lpfc_prot_mask, uint, S_IRUGO);
3383 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3386 # lpfc_prot_guard: i
3387 # - Bit mask of protection guard types to register with the SCSI mid-layer
3388 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3389 # - Allows you to ultimately specify which profiles to use
3390 # - Default will result in registering capabilities for all guard types
3393 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3394 module_param(lpfc_prot_guard, byte, S_IRUGO);
3395 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3398 * Delay initial NPort discovery when Clean Address bit is cleared in
3399 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3400 * This parameter can have value 0 or 1.
3401 * When this parameter is set to 0, no delay is added to the initial
3402 * discovery.
3403 * When this parameter is set to non-zero value, initial Nport discovery is
3404 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3405 * accept and FCID/Fabric name/Fabric portname is changed.
3406 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3407 * when Clean Address bit is cleared in FLOGI/FDISC
3408 * accept and FCID/Fabric name/Fabric portname is changed.
3409 * Default value is 0.
3411 int lpfc_delay_discovery;
3412 module_param(lpfc_delay_discovery, int, S_IRUGO);
3413 MODULE_PARM_DESC(lpfc_delay_discovery,
3414 "Delay NPort discovery when Clean Address bit is cleared. "
3415 "Allowed values: 0,1.");
3418 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3419 * This value can be set to values between 64 and 256. The default value is
3420 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3421 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3423 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3424 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3426 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3427 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3428 "Max Protection Scatter Gather Segment Count");
3430 struct device_attribute *lpfc_hba_attrs[] = {
3431 &dev_attr_bg_info,
3432 &dev_attr_bg_guard_err,
3433 &dev_attr_bg_apptag_err,
3434 &dev_attr_bg_reftag_err,
3435 &dev_attr_info,
3436 &dev_attr_serialnum,
3437 &dev_attr_modeldesc,
3438 &dev_attr_modelname,
3439 &dev_attr_programtype,
3440 &dev_attr_portnum,
3441 &dev_attr_fwrev,
3442 &dev_attr_hdw,
3443 &dev_attr_option_rom_version,
3444 &dev_attr_link_state,
3445 &dev_attr_num_discovered_ports,
3446 &dev_attr_menlo_mgmt_mode,
3447 &dev_attr_lpfc_drvr_version,
3448 &dev_attr_lpfc_enable_fip,
3449 &dev_attr_lpfc_temp_sensor,
3450 &dev_attr_lpfc_log_verbose,
3451 &dev_attr_lpfc_lun_queue_depth,
3452 &dev_attr_lpfc_tgt_queue_depth,
3453 &dev_attr_lpfc_hba_queue_depth,
3454 &dev_attr_lpfc_peer_port_login,
3455 &dev_attr_lpfc_nodev_tmo,
3456 &dev_attr_lpfc_devloss_tmo,
3457 &dev_attr_lpfc_fcp_class,
3458 &dev_attr_lpfc_use_adisc,
3459 &dev_attr_lpfc_ack0,
3460 &dev_attr_lpfc_topology,
3461 &dev_attr_lpfc_scan_down,
3462 &dev_attr_lpfc_link_speed,
3463 &dev_attr_lpfc_cr_delay,
3464 &dev_attr_lpfc_cr_count,
3465 &dev_attr_lpfc_multi_ring_support,
3466 &dev_attr_lpfc_multi_ring_rctl,
3467 &dev_attr_lpfc_multi_ring_type,
3468 &dev_attr_lpfc_fdmi_on,
3469 &dev_attr_lpfc_max_luns,
3470 &dev_attr_lpfc_enable_npiv,
3471 &dev_attr_lpfc_enable_rrq,
3472 &dev_attr_nport_evt_cnt,
3473 &dev_attr_board_mode,
3474 &dev_attr_max_vpi,
3475 &dev_attr_used_vpi,
3476 &dev_attr_max_rpi,
3477 &dev_attr_used_rpi,
3478 &dev_attr_max_xri,
3479 &dev_attr_used_xri,
3480 &dev_attr_npiv_info,
3481 &dev_attr_issue_reset,
3482 &dev_attr_lpfc_poll,
3483 &dev_attr_lpfc_poll_tmo,
3484 &dev_attr_lpfc_use_msi,
3485 &dev_attr_lpfc_fcp_imax,
3486 &dev_attr_lpfc_fcp_wq_count,
3487 &dev_attr_lpfc_fcp_eq_count,
3488 &dev_attr_lpfc_enable_bg,
3489 &dev_attr_lpfc_soft_wwnn,
3490 &dev_attr_lpfc_soft_wwpn,
3491 &dev_attr_lpfc_soft_wwn_enable,
3492 &dev_attr_lpfc_enable_hba_reset,
3493 &dev_attr_lpfc_enable_hba_heartbeat,
3494 &dev_attr_lpfc_sg_seg_cnt,
3495 &dev_attr_lpfc_max_scsicmpl_time,
3496 &dev_attr_lpfc_stat_data_ctrl,
3497 &dev_attr_lpfc_prot_sg_seg_cnt,
3498 &dev_attr_lpfc_aer_support,
3499 &dev_attr_lpfc_aer_state_cleanup,
3500 &dev_attr_lpfc_suppress_link_up,
3501 &dev_attr_lpfc_iocb_cnt,
3502 &dev_attr_iocb_hw,
3503 &dev_attr_txq_hw,
3504 &dev_attr_txcmplq_hw,
3505 &dev_attr_lpfc_fips_level,
3506 &dev_attr_lpfc_fips_rev,
3507 &dev_attr_lpfc_dss,
3508 NULL,
3511 struct device_attribute *lpfc_vport_attrs[] = {
3512 &dev_attr_info,
3513 &dev_attr_link_state,
3514 &dev_attr_num_discovered_ports,
3515 &dev_attr_lpfc_drvr_version,
3516 &dev_attr_lpfc_log_verbose,
3517 &dev_attr_lpfc_lun_queue_depth,
3518 &dev_attr_lpfc_tgt_queue_depth,
3519 &dev_attr_lpfc_nodev_tmo,
3520 &dev_attr_lpfc_devloss_tmo,
3521 &dev_attr_lpfc_hba_queue_depth,
3522 &dev_attr_lpfc_peer_port_login,
3523 &dev_attr_lpfc_restrict_login,
3524 &dev_attr_lpfc_fcp_class,
3525 &dev_attr_lpfc_use_adisc,
3526 &dev_attr_lpfc_fdmi_on,
3527 &dev_attr_lpfc_max_luns,
3528 &dev_attr_nport_evt_cnt,
3529 &dev_attr_npiv_info,
3530 &dev_attr_lpfc_enable_da_id,
3531 &dev_attr_lpfc_max_scsicmpl_time,
3532 &dev_attr_lpfc_stat_data_ctrl,
3533 &dev_attr_lpfc_static_vport,
3534 &dev_attr_lpfc_fips_level,
3535 &dev_attr_lpfc_fips_rev,
3536 NULL,
3540 * sysfs_ctlreg_write - Write method for writing to ctlreg
3541 * @filp: open sysfs file
3542 * @kobj: kernel kobject that contains the kernel class device.
3543 * @bin_attr: kernel attributes passed to us.
3544 * @buf: contains the data to be written to the adapter IOREG space.
3545 * @off: offset into buffer to beginning of data.
3546 * @count: bytes to transfer.
3548 * Description:
3549 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3550 * Uses the adapter io control registers to send buf contents to the adapter.
3552 * Returns:
3553 * -ERANGE off and count combo out of range
3554 * -EINVAL off, count or buff address invalid
3555 * -EPERM adapter is offline
3556 * value of count, buf contents written
3558 static ssize_t
3559 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3560 struct bin_attribute *bin_attr,
3561 char *buf, loff_t off, size_t count)
3563 size_t buf_off;
3564 struct device *dev = container_of(kobj, struct device, kobj);
3565 struct Scsi_Host *shost = class_to_shost(dev);
3566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3567 struct lpfc_hba *phba = vport->phba;
3569 if (phba->sli_rev >= LPFC_SLI_REV4)
3570 return -EPERM;
3572 if ((off + count) > FF_REG_AREA_SIZE)
3573 return -ERANGE;
3575 if (count == 0) return 0;
3577 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3578 return -EINVAL;
3580 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3581 return -EPERM;
3584 spin_lock_irq(&phba->hbalock);
3585 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3586 writel(*((uint32_t *)(buf + buf_off)),
3587 phba->ctrl_regs_memmap_p + off + buf_off);
3589 spin_unlock_irq(&phba->hbalock);
3591 return count;
3595 * sysfs_ctlreg_read - Read method for reading from ctlreg
3596 * @filp: open sysfs file
3597 * @kobj: kernel kobject that contains the kernel class device.
3598 * @bin_attr: kernel attributes passed to us.
3599 * @buf: if successful contains the data from the adapter IOREG space.
3600 * @off: offset into buffer to beginning of data.
3601 * @count: bytes to transfer.
3603 * Description:
3604 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3605 * Uses the adapter io control registers to read data into buf.
3607 * Returns:
3608 * -ERANGE off and count combo out of range
3609 * -EINVAL off, count or buff address invalid
3610 * value of count, buf contents read
3612 static ssize_t
3613 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3614 struct bin_attribute *bin_attr,
3615 char *buf, loff_t off, size_t count)
3617 size_t buf_off;
3618 uint32_t * tmp_ptr;
3619 struct device *dev = container_of(kobj, struct device, kobj);
3620 struct Scsi_Host *shost = class_to_shost(dev);
3621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3622 struct lpfc_hba *phba = vport->phba;
3624 if (phba->sli_rev >= LPFC_SLI_REV4)
3625 return -EPERM;
3627 if (off > FF_REG_AREA_SIZE)
3628 return -ERANGE;
3630 if ((off + count) > FF_REG_AREA_SIZE)
3631 count = FF_REG_AREA_SIZE - off;
3633 if (count == 0) return 0;
3635 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3636 return -EINVAL;
3638 spin_lock_irq(&phba->hbalock);
3640 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3641 tmp_ptr = (uint32_t *)(buf + buf_off);
3642 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3645 spin_unlock_irq(&phba->hbalock);
3647 return count;
3650 static struct bin_attribute sysfs_ctlreg_attr = {
3651 .attr = {
3652 .name = "ctlreg",
3653 .mode = S_IRUSR | S_IWUSR,
3655 .size = 256,
3656 .read = sysfs_ctlreg_read,
3657 .write = sysfs_ctlreg_write,
3661 * sysfs_mbox_idle - frees the sysfs mailbox
3662 * @phba: lpfc_hba pointer
3664 static void
3665 sysfs_mbox_idle(struct lpfc_hba *phba)
3667 phba->sysfs_mbox.state = SMBOX_IDLE;
3668 phba->sysfs_mbox.offset = 0;
3670 if (phba->sysfs_mbox.mbox) {
3671 mempool_free(phba->sysfs_mbox.mbox,
3672 phba->mbox_mem_pool);
3673 phba->sysfs_mbox.mbox = NULL;
3678 * sysfs_mbox_write - Write method for writing information via mbox
3679 * @filp: open sysfs file
3680 * @kobj: kernel kobject that contains the kernel class device.
3681 * @bin_attr: kernel attributes passed to us.
3682 * @buf: contains the data to be written to sysfs mbox.
3683 * @off: offset into buffer to beginning of data.
3684 * @count: bytes to transfer.
3686 * Description:
3687 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3688 * Uses the sysfs mbox to send buf contents to the adapter.
3690 * Returns:
3691 * -ERANGE off and count combo out of range
3692 * -EINVAL off, count or buff address invalid
3693 * zero if count is zero
3694 * -EPERM adapter is offline
3695 * -ENOMEM failed to allocate memory for the mail box
3696 * -EAGAIN offset, state or mbox is NULL
3697 * count number of bytes transferred
3699 static ssize_t
3700 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3701 struct bin_attribute *bin_attr,
3702 char *buf, loff_t off, size_t count)
3704 struct device *dev = container_of(kobj, struct device, kobj);
3705 struct Scsi_Host *shost = class_to_shost(dev);
3706 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3707 struct lpfc_hba *phba = vport->phba;
3708 struct lpfcMboxq *mbox = NULL;
3710 if ((count + off) > MAILBOX_CMD_SIZE)
3711 return -ERANGE;
3713 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3714 return -EINVAL;
3716 if (count == 0)
3717 return 0;
3719 if (off == 0) {
3720 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3721 if (!mbox)
3722 return -ENOMEM;
3723 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3726 spin_lock_irq(&phba->hbalock);
3728 if (off == 0) {
3729 if (phba->sysfs_mbox.mbox)
3730 mempool_free(mbox, phba->mbox_mem_pool);
3731 else
3732 phba->sysfs_mbox.mbox = mbox;
3733 phba->sysfs_mbox.state = SMBOX_WRITING;
3734 } else {
3735 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3736 phba->sysfs_mbox.offset != off ||
3737 phba->sysfs_mbox.mbox == NULL) {
3738 sysfs_mbox_idle(phba);
3739 spin_unlock_irq(&phba->hbalock);
3740 return -EAGAIN;
3744 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3745 buf, count);
3747 phba->sysfs_mbox.offset = off + count;
3749 spin_unlock_irq(&phba->hbalock);
3751 return count;
3755 * sysfs_mbox_read - Read method for reading information via mbox
3756 * @filp: open sysfs file
3757 * @kobj: kernel kobject that contains the kernel class device.
3758 * @bin_attr: kernel attributes passed to us.
3759 * @buf: contains the data to be read from sysfs mbox.
3760 * @off: offset into buffer to beginning of data.
3761 * @count: bytes to transfer.
3763 * Description:
3764 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3765 * Uses the sysfs mbox to receive data from to the adapter.
3767 * Returns:
3768 * -ERANGE off greater than mailbox command size
3769 * -EINVAL off, count or buff address invalid
3770 * zero if off and count are zero
3771 * -EACCES adapter over temp
3772 * -EPERM garbage can value to catch a multitude of errors
3773 * -EAGAIN management IO not permitted, state or off error
3774 * -ETIME mailbox timeout
3775 * -ENODEV mailbox error
3776 * count number of bytes transferred
3778 static ssize_t
3779 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3780 struct bin_attribute *bin_attr,
3781 char *buf, loff_t off, size_t count)
3783 struct device *dev = container_of(kobj, struct device, kobj);
3784 struct Scsi_Host *shost = class_to_shost(dev);
3785 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3786 struct lpfc_hba *phba = vport->phba;
3787 int rc;
3788 MAILBOX_t *pmb;
3790 if (off > MAILBOX_CMD_SIZE)
3791 return -ERANGE;
3793 if ((count + off) > MAILBOX_CMD_SIZE)
3794 count = MAILBOX_CMD_SIZE - off;
3796 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3797 return -EINVAL;
3799 if (off && count == 0)
3800 return 0;
3802 spin_lock_irq(&phba->hbalock);
3804 if (phba->over_temp_state == HBA_OVER_TEMP) {
3805 sysfs_mbox_idle(phba);
3806 spin_unlock_irq(&phba->hbalock);
3807 return -EACCES;
3810 if (off == 0 &&
3811 phba->sysfs_mbox.state == SMBOX_WRITING &&
3812 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3813 pmb = &phba->sysfs_mbox.mbox->u.mb;
3814 switch (pmb->mbxCommand) {
3815 /* Offline only */
3816 case MBX_INIT_LINK:
3817 case MBX_DOWN_LINK:
3818 case MBX_CONFIG_LINK:
3819 case MBX_CONFIG_RING:
3820 case MBX_RESET_RING:
3821 case MBX_UNREG_LOGIN:
3822 case MBX_CLEAR_LA:
3823 case MBX_DUMP_CONTEXT:
3824 case MBX_RUN_DIAGS:
3825 case MBX_RESTART:
3826 case MBX_SET_MASK:
3827 case MBX_SET_DEBUG:
3828 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3829 printk(KERN_WARNING "mbox_read:Command 0x%x "
3830 "is illegal in on-line state\n",
3831 pmb->mbxCommand);
3832 sysfs_mbox_idle(phba);
3833 spin_unlock_irq(&phba->hbalock);
3834 return -EPERM;
3836 case MBX_WRITE_NV:
3837 case MBX_WRITE_VPARMS:
3838 case MBX_LOAD_SM:
3839 case MBX_READ_NV:
3840 case MBX_READ_CONFIG:
3841 case MBX_READ_RCONFIG:
3842 case MBX_READ_STATUS:
3843 case MBX_READ_XRI:
3844 case MBX_READ_REV:
3845 case MBX_READ_LNK_STAT:
3846 case MBX_DUMP_MEMORY:
3847 case MBX_DOWN_LOAD:
3848 case MBX_UPDATE_CFG:
3849 case MBX_KILL_BOARD:
3850 case MBX_LOAD_AREA:
3851 case MBX_LOAD_EXP_ROM:
3852 case MBX_BEACON:
3853 case MBX_DEL_LD_ENTRY:
3854 case MBX_SET_VARIABLE:
3855 case MBX_WRITE_WWN:
3856 case MBX_PORT_CAPABILITIES:
3857 case MBX_PORT_IOV_CONTROL:
3858 break;
3859 case MBX_SECURITY_MGMT:
3860 case MBX_AUTH_PORT:
3861 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3862 printk(KERN_WARNING "mbox_read:Command 0x%x "
3863 "is not permitted\n", pmb->mbxCommand);
3864 sysfs_mbox_idle(phba);
3865 spin_unlock_irq(&phba->hbalock);
3866 return -EPERM;
3868 break;
3869 case MBX_READ_SPARM64:
3870 case MBX_READ_TOPOLOGY:
3871 case MBX_REG_LOGIN:
3872 case MBX_REG_LOGIN64:
3873 case MBX_CONFIG_PORT:
3874 case MBX_RUN_BIU_DIAG:
3875 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3876 pmb->mbxCommand);
3877 sysfs_mbox_idle(phba);
3878 spin_unlock_irq(&phba->hbalock);
3879 return -EPERM;
3880 default:
3881 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3882 pmb->mbxCommand);
3883 sysfs_mbox_idle(phba);
3884 spin_unlock_irq(&phba->hbalock);
3885 return -EPERM;
3888 /* If HBA encountered an error attention, allow only DUMP
3889 * or RESTART mailbox commands until the HBA is restarted.
3891 if (phba->pport->stopped &&
3892 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3893 pmb->mbxCommand != MBX_RESTART &&
3894 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3895 pmb->mbxCommand != MBX_WRITE_WWN)
3896 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3897 "1259 mbox: Issued mailbox cmd "
3898 "0x%x while in stopped state.\n",
3899 pmb->mbxCommand);
3901 phba->sysfs_mbox.mbox->vport = vport;
3903 /* Don't allow mailbox commands to be sent when blocked
3904 * or when in the middle of discovery
3906 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3907 sysfs_mbox_idle(phba);
3908 spin_unlock_irq(&phba->hbalock);
3909 return -EAGAIN;
3912 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3913 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3915 spin_unlock_irq(&phba->hbalock);
3916 rc = lpfc_sli_issue_mbox (phba,
3917 phba->sysfs_mbox.mbox,
3918 MBX_POLL);
3919 spin_lock_irq(&phba->hbalock);
3921 } else {
3922 spin_unlock_irq(&phba->hbalock);
3923 rc = lpfc_sli_issue_mbox_wait (phba,
3924 phba->sysfs_mbox.mbox,
3925 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3926 spin_lock_irq(&phba->hbalock);
3929 if (rc != MBX_SUCCESS) {
3930 if (rc == MBX_TIMEOUT) {
3931 phba->sysfs_mbox.mbox = NULL;
3933 sysfs_mbox_idle(phba);
3934 spin_unlock_irq(&phba->hbalock);
3935 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3937 phba->sysfs_mbox.state = SMBOX_READING;
3939 else if (phba->sysfs_mbox.offset != off ||
3940 phba->sysfs_mbox.state != SMBOX_READING) {
3941 printk(KERN_WARNING "mbox_read: Bad State\n");
3942 sysfs_mbox_idle(phba);
3943 spin_unlock_irq(&phba->hbalock);
3944 return -EAGAIN;
3947 memcpy(buf, (uint8_t *) &pmb + off, count);
3949 phba->sysfs_mbox.offset = off + count;
3951 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3952 sysfs_mbox_idle(phba);
3954 spin_unlock_irq(&phba->hbalock);
3956 return count;
3959 static struct bin_attribute sysfs_mbox_attr = {
3960 .attr = {
3961 .name = "mbox",
3962 .mode = S_IRUSR | S_IWUSR,
3964 .size = MAILBOX_CMD_SIZE,
3965 .read = sysfs_mbox_read,
3966 .write = sysfs_mbox_write,
3970 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3971 * @vport: address of lpfc vport structure.
3973 * Return codes:
3974 * zero on success
3975 * error return code from sysfs_create_bin_file()
3978 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3981 int error;
3983 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3984 &sysfs_drvr_stat_data_attr);
3986 /* Virtual ports do not need ctrl_reg and mbox */
3987 if (error || vport->port_type == LPFC_NPIV_PORT)
3988 goto out;
3990 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3991 &sysfs_ctlreg_attr);
3992 if (error)
3993 goto out_remove_stat_attr;
3995 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3996 &sysfs_mbox_attr);
3997 if (error)
3998 goto out_remove_ctlreg_attr;
4000 return 0;
4001 out_remove_ctlreg_attr:
4002 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4003 out_remove_stat_attr:
4004 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4005 &sysfs_drvr_stat_data_attr);
4006 out:
4007 return error;
4011 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4012 * @vport: address of lpfc vport structure.
4014 void
4015 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4017 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4018 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4019 &sysfs_drvr_stat_data_attr);
4020 /* Virtual ports do not need ctrl_reg and mbox */
4021 if (vport->port_type == LPFC_NPIV_PORT)
4022 return;
4023 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4024 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4029 * Dynamic FC Host Attributes Support
4033 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4034 * @shost: kernel scsi host pointer.
4036 static void
4037 lpfc_get_host_port_id(struct Scsi_Host *shost)
4039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4041 /* note: fc_myDID already in cpu endianness */
4042 fc_host_port_id(shost) = vport->fc_myDID;
4046 * lpfc_get_host_port_type - Set the value of the scsi host port type
4047 * @shost: kernel scsi host pointer.
4049 static void
4050 lpfc_get_host_port_type(struct Scsi_Host *shost)
4052 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4053 struct lpfc_hba *phba = vport->phba;
4055 spin_lock_irq(shost->host_lock);
4057 if (vport->port_type == LPFC_NPIV_PORT) {
4058 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4059 } else if (lpfc_is_link_up(phba)) {
4060 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4061 if (vport->fc_flag & FC_PUBLIC_LOOP)
4062 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4063 else
4064 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4065 } else {
4066 if (vport->fc_flag & FC_FABRIC)
4067 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4068 else
4069 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4071 } else
4072 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4074 spin_unlock_irq(shost->host_lock);
4078 * lpfc_get_host_port_state - Set the value of the scsi host port state
4079 * @shost: kernel scsi host pointer.
4081 static void
4082 lpfc_get_host_port_state(struct Scsi_Host *shost)
4084 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4085 struct lpfc_hba *phba = vport->phba;
4087 spin_lock_irq(shost->host_lock);
4089 if (vport->fc_flag & FC_OFFLINE_MODE)
4090 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4091 else {
4092 switch (phba->link_state) {
4093 case LPFC_LINK_UNKNOWN:
4094 case LPFC_LINK_DOWN:
4095 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4096 break;
4097 case LPFC_LINK_UP:
4098 case LPFC_CLEAR_LA:
4099 case LPFC_HBA_READY:
4100 /* Links up, beyond this port_type reports state */
4101 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4102 break;
4103 case LPFC_HBA_ERROR:
4104 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4105 break;
4106 default:
4107 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4108 break;
4112 spin_unlock_irq(shost->host_lock);
4116 * lpfc_get_host_speed - Set the value of the scsi host speed
4117 * @shost: kernel scsi host pointer.
4119 static void
4120 lpfc_get_host_speed(struct Scsi_Host *shost)
4122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4123 struct lpfc_hba *phba = vport->phba;
4125 spin_lock_irq(shost->host_lock);
4127 if (lpfc_is_link_up(phba)) {
4128 switch(phba->fc_linkspeed) {
4129 case LPFC_LINK_SPEED_1GHZ:
4130 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4131 break;
4132 case LPFC_LINK_SPEED_2GHZ:
4133 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4134 break;
4135 case LPFC_LINK_SPEED_4GHZ:
4136 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4137 break;
4138 case LPFC_LINK_SPEED_8GHZ:
4139 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4140 break;
4141 case LPFC_LINK_SPEED_10GHZ:
4142 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4143 break;
4144 case LPFC_LINK_SPEED_16GHZ:
4145 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4146 break;
4147 default:
4148 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4149 break;
4151 } else
4152 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4154 spin_unlock_irq(shost->host_lock);
4158 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4159 * @shost: kernel scsi host pointer.
4161 static void
4162 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4164 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4165 struct lpfc_hba *phba = vport->phba;
4166 u64 node_name;
4168 spin_lock_irq(shost->host_lock);
4170 if ((vport->fc_flag & FC_FABRIC) ||
4171 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4172 (vport->fc_flag & FC_PUBLIC_LOOP)))
4173 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4174 else
4175 /* fabric is local port if there is no F/FL_Port */
4176 node_name = 0;
4178 spin_unlock_irq(shost->host_lock);
4180 fc_host_fabric_name(shost) = node_name;
4184 * lpfc_get_stats - Return statistical information about the adapter
4185 * @shost: kernel scsi host pointer.
4187 * Notes:
4188 * NULL on error for link down, no mbox pool, sli2 active,
4189 * management not allowed, memory allocation error, or mbox error.
4191 * Returns:
4192 * NULL for error
4193 * address of the adapter host statistics
4195 static struct fc_host_statistics *
4196 lpfc_get_stats(struct Scsi_Host *shost)
4198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4199 struct lpfc_hba *phba = vport->phba;
4200 struct lpfc_sli *psli = &phba->sli;
4201 struct fc_host_statistics *hs = &phba->link_stats;
4202 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4203 LPFC_MBOXQ_t *pmboxq;
4204 MAILBOX_t *pmb;
4205 unsigned long seconds;
4206 int rc = 0;
4209 * prevent udev from issuing mailbox commands until the port is
4210 * configured.
4212 if (phba->link_state < LPFC_LINK_DOWN ||
4213 !phba->mbox_mem_pool ||
4214 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4215 return NULL;
4217 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4218 return NULL;
4220 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4221 if (!pmboxq)
4222 return NULL;
4223 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4225 pmb = &pmboxq->u.mb;
4226 pmb->mbxCommand = MBX_READ_STATUS;
4227 pmb->mbxOwner = OWN_HOST;
4228 pmboxq->context1 = NULL;
4229 pmboxq->vport = vport;
4231 if (vport->fc_flag & FC_OFFLINE_MODE)
4232 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4233 else
4234 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4236 if (rc != MBX_SUCCESS) {
4237 if (rc != MBX_TIMEOUT)
4238 mempool_free(pmboxq, phba->mbox_mem_pool);
4239 return NULL;
4242 memset(hs, 0, sizeof (struct fc_host_statistics));
4244 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4245 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4246 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4247 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4249 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4250 pmb->mbxCommand = MBX_READ_LNK_STAT;
4251 pmb->mbxOwner = OWN_HOST;
4252 pmboxq->context1 = NULL;
4253 pmboxq->vport = vport;
4255 if (vport->fc_flag & FC_OFFLINE_MODE)
4256 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4257 else
4258 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4260 if (rc != MBX_SUCCESS) {
4261 if (rc != MBX_TIMEOUT)
4262 mempool_free(pmboxq, phba->mbox_mem_pool);
4263 return NULL;
4266 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4267 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4268 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4269 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4270 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4271 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4272 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4274 hs->link_failure_count -= lso->link_failure_count;
4275 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4276 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4277 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4278 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4279 hs->invalid_crc_count -= lso->invalid_crc_count;
4280 hs->error_frames -= lso->error_frames;
4282 if (phba->hba_flag & HBA_FCOE_MODE) {
4283 hs->lip_count = -1;
4284 hs->nos_count = (phba->link_events >> 1);
4285 hs->nos_count -= lso->link_events;
4286 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4287 hs->lip_count = (phba->fc_eventTag >> 1);
4288 hs->lip_count -= lso->link_events;
4289 hs->nos_count = -1;
4290 } else {
4291 hs->lip_count = -1;
4292 hs->nos_count = (phba->fc_eventTag >> 1);
4293 hs->nos_count -= lso->link_events;
4296 hs->dumped_frames = -1;
4298 seconds = get_seconds();
4299 if (seconds < psli->stats_start)
4300 hs->seconds_since_last_reset = seconds +
4301 ((unsigned long)-1 - psli->stats_start);
4302 else
4303 hs->seconds_since_last_reset = seconds - psli->stats_start;
4305 mempool_free(pmboxq, phba->mbox_mem_pool);
4307 return hs;
4311 * lpfc_reset_stats - Copy the adapter link stats information
4312 * @shost: kernel scsi host pointer.
4314 static void
4315 lpfc_reset_stats(struct Scsi_Host *shost)
4317 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4318 struct lpfc_hba *phba = vport->phba;
4319 struct lpfc_sli *psli = &phba->sli;
4320 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4321 LPFC_MBOXQ_t *pmboxq;
4322 MAILBOX_t *pmb;
4323 int rc = 0;
4325 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4326 return;
4328 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4329 if (!pmboxq)
4330 return;
4331 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4333 pmb = &pmboxq->u.mb;
4334 pmb->mbxCommand = MBX_READ_STATUS;
4335 pmb->mbxOwner = OWN_HOST;
4336 pmb->un.varWords[0] = 0x1; /* reset request */
4337 pmboxq->context1 = NULL;
4338 pmboxq->vport = vport;
4340 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4341 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4342 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4343 else
4344 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4346 if (rc != MBX_SUCCESS) {
4347 if (rc != MBX_TIMEOUT)
4348 mempool_free(pmboxq, phba->mbox_mem_pool);
4349 return;
4352 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4353 pmb->mbxCommand = MBX_READ_LNK_STAT;
4354 pmb->mbxOwner = OWN_HOST;
4355 pmboxq->context1 = NULL;
4356 pmboxq->vport = vport;
4358 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4359 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4360 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4361 else
4362 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4364 if (rc != MBX_SUCCESS) {
4365 if (rc != MBX_TIMEOUT)
4366 mempool_free( pmboxq, phba->mbox_mem_pool);
4367 return;
4370 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4371 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4372 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4373 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4374 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4375 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4376 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4377 if (phba->hba_flag & HBA_FCOE_MODE)
4378 lso->link_events = (phba->link_events >> 1);
4379 else
4380 lso->link_events = (phba->fc_eventTag >> 1);
4382 psli->stats_start = get_seconds();
4384 mempool_free(pmboxq, phba->mbox_mem_pool);
4386 return;
4390 * The LPFC driver treats linkdown handling as target loss events so there
4391 * are no sysfs handlers for link_down_tmo.
4395 * lpfc_get_node_by_target - Return the nodelist for a target
4396 * @starget: kernel scsi target pointer.
4398 * Returns:
4399 * address of the node list if found
4400 * NULL target not found
4402 static struct lpfc_nodelist *
4403 lpfc_get_node_by_target(struct scsi_target *starget)
4405 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4407 struct lpfc_nodelist *ndlp;
4409 spin_lock_irq(shost->host_lock);
4410 /* Search for this, mapped, target ID */
4411 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4412 if (NLP_CHK_NODE_ACT(ndlp) &&
4413 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4414 starget->id == ndlp->nlp_sid) {
4415 spin_unlock_irq(shost->host_lock);
4416 return ndlp;
4419 spin_unlock_irq(shost->host_lock);
4420 return NULL;
4424 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4425 * @starget: kernel scsi target pointer.
4427 static void
4428 lpfc_get_starget_port_id(struct scsi_target *starget)
4430 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4432 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4436 * lpfc_get_starget_node_name - Set the target node name
4437 * @starget: kernel scsi target pointer.
4439 * Description: Set the target node name to the ndlp node name wwn or zero.
4441 static void
4442 lpfc_get_starget_node_name(struct scsi_target *starget)
4444 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4446 fc_starget_node_name(starget) =
4447 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4451 * lpfc_get_starget_port_name - Set the target port name
4452 * @starget: kernel scsi target pointer.
4454 * Description: set the target port name to the ndlp port name wwn or zero.
4456 static void
4457 lpfc_get_starget_port_name(struct scsi_target *starget)
4459 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4461 fc_starget_port_name(starget) =
4462 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4466 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4467 * @rport: fc rport address.
4468 * @timeout: new value for dev loss tmo.
4470 * Description:
4471 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4472 * dev_loss_tmo to one.
4474 static void
4475 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4477 if (timeout)
4478 rport->dev_loss_tmo = timeout;
4479 else
4480 rport->dev_loss_tmo = 1;
4484 * lpfc_rport_show_function - Return rport target information
4486 * Description:
4487 * Macro that uses field to generate a function with the name lpfc_show_rport_
4489 * lpfc_show_rport_##field: returns the bytes formatted in buf
4490 * @cdev: class converted to an fc_rport.
4491 * @buf: on return contains the target_field or zero.
4493 * Returns: size of formatted string.
4495 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4496 static ssize_t \
4497 lpfc_show_rport_##field (struct device *dev, \
4498 struct device_attribute *attr, \
4499 char *buf) \
4501 struct fc_rport *rport = transport_class_to_rport(dev); \
4502 struct lpfc_rport_data *rdata = rport->hostdata; \
4503 return snprintf(buf, sz, format_string, \
4504 (rdata->target) ? cast rdata->target->field : 0); \
4507 #define lpfc_rport_rd_attr(field, format_string, sz) \
4508 lpfc_rport_show_function(field, format_string, sz, ) \
4509 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4512 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4513 * @fc_vport: The fc_vport who's symbolic name has been changed.
4515 * Description:
4516 * This function is called by the transport after the @fc_vport's symbolic name
4517 * has been changed. This function re-registers the symbolic name with the
4518 * switch to propagate the change into the fabric if the vport is active.
4520 static void
4521 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4523 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4525 if (vport->port_state == LPFC_VPORT_READY)
4526 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4530 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4531 * @phba: Pointer to lpfc_hba struct.
4533 * This function is called by the lpfc_get_cfgparam() routine to set the
4534 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4535 * log messsage according to the module's lpfc_log_verbose parameter setting
4536 * before hba port or vport created.
4538 static void
4539 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4541 phba->cfg_log_verbose = verbose;
4544 struct fc_function_template lpfc_transport_functions = {
4545 /* fixed attributes the driver supports */
4546 .show_host_node_name = 1,
4547 .show_host_port_name = 1,
4548 .show_host_supported_classes = 1,
4549 .show_host_supported_fc4s = 1,
4550 .show_host_supported_speeds = 1,
4551 .show_host_maxframe_size = 1,
4552 .show_host_symbolic_name = 1,
4554 /* dynamic attributes the driver supports */
4555 .get_host_port_id = lpfc_get_host_port_id,
4556 .show_host_port_id = 1,
4558 .get_host_port_type = lpfc_get_host_port_type,
4559 .show_host_port_type = 1,
4561 .get_host_port_state = lpfc_get_host_port_state,
4562 .show_host_port_state = 1,
4564 /* active_fc4s is shown but doesn't change (thus no get function) */
4565 .show_host_active_fc4s = 1,
4567 .get_host_speed = lpfc_get_host_speed,
4568 .show_host_speed = 1,
4570 .get_host_fabric_name = lpfc_get_host_fabric_name,
4571 .show_host_fabric_name = 1,
4574 * The LPFC driver treats linkdown handling as target loss events
4575 * so there are no sysfs handlers for link_down_tmo.
4578 .get_fc_host_stats = lpfc_get_stats,
4579 .reset_fc_host_stats = lpfc_reset_stats,
4581 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4582 .show_rport_maxframe_size = 1,
4583 .show_rport_supported_classes = 1,
4585 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4586 .show_rport_dev_loss_tmo = 1,
4588 .get_starget_port_id = lpfc_get_starget_port_id,
4589 .show_starget_port_id = 1,
4591 .get_starget_node_name = lpfc_get_starget_node_name,
4592 .show_starget_node_name = 1,
4594 .get_starget_port_name = lpfc_get_starget_port_name,
4595 .show_starget_port_name = 1,
4597 .issue_fc_host_lip = lpfc_issue_lip,
4598 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4599 .terminate_rport_io = lpfc_terminate_rport_io,
4601 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4603 .vport_disable = lpfc_vport_disable,
4605 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4607 .bsg_request = lpfc_bsg_request,
4608 .bsg_timeout = lpfc_bsg_timeout,
4611 struct fc_function_template lpfc_vport_transport_functions = {
4612 /* fixed attributes the driver supports */
4613 .show_host_node_name = 1,
4614 .show_host_port_name = 1,
4615 .show_host_supported_classes = 1,
4616 .show_host_supported_fc4s = 1,
4617 .show_host_supported_speeds = 1,
4618 .show_host_maxframe_size = 1,
4619 .show_host_symbolic_name = 1,
4621 /* dynamic attributes the driver supports */
4622 .get_host_port_id = lpfc_get_host_port_id,
4623 .show_host_port_id = 1,
4625 .get_host_port_type = lpfc_get_host_port_type,
4626 .show_host_port_type = 1,
4628 .get_host_port_state = lpfc_get_host_port_state,
4629 .show_host_port_state = 1,
4631 /* active_fc4s is shown but doesn't change (thus no get function) */
4632 .show_host_active_fc4s = 1,
4634 .get_host_speed = lpfc_get_host_speed,
4635 .show_host_speed = 1,
4637 .get_host_fabric_name = lpfc_get_host_fabric_name,
4638 .show_host_fabric_name = 1,
4641 * The LPFC driver treats linkdown handling as target loss events
4642 * so there are no sysfs handlers for link_down_tmo.
4645 .get_fc_host_stats = lpfc_get_stats,
4646 .reset_fc_host_stats = lpfc_reset_stats,
4648 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4649 .show_rport_maxframe_size = 1,
4650 .show_rport_supported_classes = 1,
4652 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4653 .show_rport_dev_loss_tmo = 1,
4655 .get_starget_port_id = lpfc_get_starget_port_id,
4656 .show_starget_port_id = 1,
4658 .get_starget_node_name = lpfc_get_starget_node_name,
4659 .show_starget_node_name = 1,
4661 .get_starget_port_name = lpfc_get_starget_port_name,
4662 .show_starget_port_name = 1,
4664 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4665 .terminate_rport_io = lpfc_terminate_rport_io,
4667 .vport_disable = lpfc_vport_disable,
4669 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4673 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4674 * @phba: lpfc_hba pointer.
4676 void
4677 lpfc_get_cfgparam(struct lpfc_hba *phba)
4679 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4680 lpfc_cr_count_init(phba, lpfc_cr_count);
4681 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4682 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4683 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4684 lpfc_ack0_init(phba, lpfc_ack0);
4685 lpfc_topology_init(phba, lpfc_topology);
4686 lpfc_link_speed_init(phba, lpfc_link_speed);
4687 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4688 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4689 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4690 lpfc_use_msi_init(phba, lpfc_use_msi);
4691 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4692 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4693 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4694 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4695 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4696 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4697 if (phba->sli_rev == LPFC_SLI_REV4)
4698 phba->cfg_poll = 0;
4699 else
4700 phba->cfg_poll = lpfc_poll;
4701 phba->cfg_soft_wwnn = 0L;
4702 phba->cfg_soft_wwpn = 0L;
4703 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4704 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4705 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4706 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4707 lpfc_aer_support_init(phba, lpfc_aer_support);
4708 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4709 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4710 phba->cfg_enable_dss = 1;
4711 return;
4715 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4716 * @vport: lpfc_vport pointer.
4718 void
4719 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4721 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4722 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4723 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
4724 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4725 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4726 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4727 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4728 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4729 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4730 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4731 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4732 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4733 lpfc_max_luns_init(vport, lpfc_max_luns);
4734 lpfc_scan_down_init(vport, lpfc_scan_down);
4735 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
4736 return;