Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpfc_attr.c
Go to the documentation of this file.
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for *
3  * Fibre Channel Host Bus Adapters. *
4  * Copyright (C) 2004-2012 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  *******************************************************************/
21 
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/aer.h>
28 #include <linux/gfp.h>
29 #include <linux/kernel.h>
30 
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
37 
38 #include "lpfc_hw4.h"
39 #include "lpfc_hw.h"
40 #include "lpfc_sli.h"
41 #include "lpfc_sli4.h"
42 #include "lpfc_nl.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 
52 #define LPFC_DEF_DEVLOSS_TMO 30
53 #define LPFC_MIN_DEVLOSS_TMO 1
54 #define LPFC_MAX_DEVLOSS_TMO 255
55 
56 /*
57  * Write key size should be multiple of 4. If write key is changed
58  * make sure that library write key is also changed.
59  */
60 #define LPFC_REG_WRITE_KEY_SIZE 4
61 #define LPFC_REG_WRITE_KEY "EMLX"
62 
78 static void
79 lpfc_jedec_to_ascii(int incr, char hdw[])
80 {
81  int i, j;
82  for (i = 0; i < 8; i++) {
83  j = (incr & 0xf);
84  if (j <= 9)
85  hdw[7 - i] = 0x30 + j;
86  else
87  hdw[7 - i] = 0x61 + j - 10;
88  incr = (incr >> 4);
89  }
90  hdw[8] = 0;
91  return;
92 }
93 
102 static ssize_t
103 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104  char *buf)
105 {
106  return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107 }
108 
117 static ssize_t
118 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119  char *buf)
120 {
121  struct Scsi_Host *shost = class_to_shost(dev);
122  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123  struct lpfc_hba *phba = vport->phba;
124 
125  if (phba->hba_flag & HBA_FIP_SUPPORT)
126  return snprintf(buf, PAGE_SIZE, "1\n");
127  else
128  return snprintf(buf, PAGE_SIZE, "0\n");
129 }
130 
131 static ssize_t
132 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133  char *buf)
134 {
135  struct Scsi_Host *shost = class_to_shost(dev);
136  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137  struct lpfc_hba *phba = vport->phba;
138 
139  if (phba->cfg_enable_bg)
140  if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141  return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142  else
143  return snprintf(buf, PAGE_SIZE,
144  "BlockGuard Not Supported\n");
145  else
146  return snprintf(buf, PAGE_SIZE,
147  "BlockGuard Disabled\n");
148 }
149 
150 static ssize_t
151 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152  char *buf)
153 {
154  struct Scsi_Host *shost = class_to_shost(dev);
155  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156  struct lpfc_hba *phba = vport->phba;
157 
158  return snprintf(buf, PAGE_SIZE, "%llu\n",
159  (unsigned long long)phba->bg_guard_err_cnt);
160 }
161 
162 static ssize_t
163 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164  char *buf)
165 {
166  struct Scsi_Host *shost = class_to_shost(dev);
167  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168  struct lpfc_hba *phba = vport->phba;
169 
170  return snprintf(buf, PAGE_SIZE, "%llu\n",
171  (unsigned long long)phba->bg_apptag_err_cnt);
172 }
173 
174 static ssize_t
175 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176  char *buf)
177 {
178  struct Scsi_Host *shost = class_to_shost(dev);
179  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180  struct lpfc_hba *phba = vport->phba;
181 
182  return snprintf(buf, PAGE_SIZE, "%llu\n",
183  (unsigned long long)phba->bg_reftag_err_cnt);
184 }
185 
194 static ssize_t
195 lpfc_info_show(struct device *dev, struct device_attribute *attr,
196  char *buf)
197 {
198  struct Scsi_Host *host = class_to_shost(dev);
199 
200  return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201 }
202 
211 static ssize_t
212 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213  char *buf)
214 {
215  struct Scsi_Host *shost = class_to_shost(dev);
216  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217  struct lpfc_hba *phba = vport->phba;
218 
219  return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220 }
221 
234 static ssize_t
235 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236  char *buf)
237 {
238  struct Scsi_Host *shost = class_to_shost(dev);
239  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240  struct lpfc_hba *phba = vport->phba;
241  return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242 }
243 
252 static ssize_t
253 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254  char *buf)
255 {
256  struct Scsi_Host *shost = class_to_shost(dev);
257  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258  struct lpfc_hba *phba = vport->phba;
259 
260  return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261 }
262 
271 static ssize_t
272 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273  char *buf)
274 {
275  struct Scsi_Host *shost = class_to_shost(dev);
276  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277  struct lpfc_hba *phba = vport->phba;
278 
279  return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280 }
281 
290 static ssize_t
291 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292  char *buf)
293 {
294  struct Scsi_Host *shost = class_to_shost(dev);
295  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296  struct lpfc_hba *phba = vport->phba;
297 
298  return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299 }
300 
309 static ssize_t
310 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311 {
312  struct Scsi_Host *shost = class_to_shost(dev);
313  struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314  struct lpfc_hba *phba = vport->phba;
315 
316  return snprintf(buf, PAGE_SIZE, "%d\n",
317  (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318 }
319 
328 static ssize_t
329 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330  char *buf)
331 {
332  struct Scsi_Host *shost = class_to_shost(dev);
333  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334  struct lpfc_hba *phba = vport->phba;
335 
336  return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337 }
338 
347 static ssize_t
348 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349  char *buf)
350 {
351  struct Scsi_Host *shost = class_to_shost(dev);
352  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353  struct lpfc_hba *phba = vport->phba;
354  uint32_t if_type;
355  uint8_t sli_family;
356  char fwrev[FW_REV_STR_SIZE];
357  int len;
358 
359  lpfc_decode_firmware_rev(phba, fwrev, 1);
360  if_type = phba->sli4_hba.pc_sli4_params.if_type;
361  sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362 
363  if (phba->sli_rev < LPFC_SLI_REV4)
364  len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365  fwrev, phba->sli_rev);
366  else
367  len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368  fwrev, phba->sli_rev, if_type, sli_family);
369 
370  return len;
371 }
372 
381 static ssize_t
382 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
383 {
384  char hdw[9];
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;
388  lpfc_vpd_t *vp = &phba->vpd;
389 
390  lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391  return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392 }
393 
402 static ssize_t
403 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404  char *buf)
405 {
406  struct Scsi_Host *shost = class_to_shost(dev);
407  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408  struct lpfc_hba *phba = vport->phba;
409 
410  return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
411 }
412 
424 static ssize_t
425 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
426  char *buf)
427 {
428  struct Scsi_Host *shost = class_to_shost(dev);
429  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
430  struct lpfc_hba *phba = vport->phba;
431  int len = 0;
432 
433  switch (phba->link_state) {
434  case LPFC_LINK_UNKNOWN:
435  case LPFC_WARM_START:
436  case LPFC_INIT_START:
437  case LPFC_INIT_MBX_CMDS:
438  case LPFC_LINK_DOWN:
439  case LPFC_HBA_ERROR:
440  if (phba->hba_flag & LINK_DISABLED)
441  len += snprintf(buf + len, PAGE_SIZE-len,
442  "Link Down - User disabled\n");
443  else
444  len += snprintf(buf + len, PAGE_SIZE-len,
445  "Link Down\n");
446  break;
447  case LPFC_LINK_UP:
448  case LPFC_CLEAR_LA:
449  case LPFC_HBA_READY:
450  len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
451 
452  switch (vport->port_state) {
453  case LPFC_LOCAL_CFG_LINK:
454  len += snprintf(buf + len, PAGE_SIZE-len,
455  "Configuring Link\n");
456  break;
457  case LPFC_FDISC:
458  case LPFC_FLOGI:
460  case LPFC_NS_REG:
461  case LPFC_NS_QRY:
463  case LPFC_DISC_AUTH:
464  len += snprintf(buf + len, PAGE_SIZE - len,
465  "Discovery\n");
466  break;
467  case LPFC_VPORT_READY:
468  len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
469  break;
470 
471  case LPFC_VPORT_FAILED:
472  len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
473  break;
474 
475  case LPFC_VPORT_UNKNOWN:
476  len += snprintf(buf + len, PAGE_SIZE - len,
477  "Unknown\n");
478  break;
479  }
480  if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
481  len += snprintf(buf + len, PAGE_SIZE-len,
482  " Menlo Maint Mode\n");
483  else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
484  if (vport->fc_flag & FC_PUBLIC_LOOP)
485  len += snprintf(buf + len, PAGE_SIZE-len,
486  " Public Loop\n");
487  else
488  len += snprintf(buf + len, PAGE_SIZE-len,
489  " Private Loop\n");
490  } else {
491  if (vport->fc_flag & FC_FABRIC)
492  len += snprintf(buf + len, PAGE_SIZE-len,
493  " Fabric\n");
494  else
495  len += snprintf(buf + len, PAGE_SIZE-len,
496  " Point-2-Point\n");
497  }
498  }
499 
500  return len;
501 }
502 
511 static ssize_t
512 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
513  char *buf)
514 {
515  struct Scsi_Host *shost = class_to_shost(dev);
516  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517  struct lpfc_hba *phba = vport->phba;
518 
519  if (phba->sli_rev < LPFC_SLI_REV4)
520  return snprintf(buf, PAGE_SIZE, "fc\n");
521 
522  if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
523  if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
524  return snprintf(buf, PAGE_SIZE, "fcoe\n");
525  if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
526  return snprintf(buf, PAGE_SIZE, "fc\n");
527  }
528  return snprintf(buf, PAGE_SIZE, "unknown\n");
529 }
530 
543 static ssize_t
544 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
545  const char *buf, size_t count)
546 {
547  struct Scsi_Host *shost = class_to_shost(dev);
548  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
549  struct lpfc_hba *phba = vport->phba;
550 
551  int status = -EINVAL;
552 
553  if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
554  (phba->link_state == LPFC_LINK_DOWN))
555  status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
556  else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
557  (phba->link_state >= LPFC_LINK_UP))
558  status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
559 
560  if (status == 0)
561  return strlen(buf);
562  else
563  return status;
564 }
565 
578 static ssize_t
579 lpfc_num_discovered_ports_show(struct device *dev,
580  struct device_attribute *attr, char *buf)
581 {
582  struct Scsi_Host *shost = class_to_shost(dev);
583  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 
585  return snprintf(buf, PAGE_SIZE, "%d\n",
586  vport->fc_map_cnt + vport->fc_unmap_cnt);
587 }
588 
603 static int
604 lpfc_issue_lip(struct Scsi_Host *shost)
605 {
606  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
607  struct lpfc_hba *phba = vport->phba;
608  LPFC_MBOXQ_t *pmboxq;
609  int mbxstatus = MBXERR_ERROR;
610 
611  if ((vport->fc_flag & FC_OFFLINE_MODE) ||
612  (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
613  return -EPERM;
614 
615  pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
616 
617  if (!pmboxq)
618  return -ENOMEM;
619 
620  memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
621  pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
622  pmboxq->u.mb.mbxOwner = OWN_HOST;
623 
624  mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
625 
626  if ((mbxstatus == MBX_SUCCESS) &&
627  (pmboxq->u.mb.mbxStatus == 0 ||
628  pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
629  memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
630  lpfc_init_link(phba, pmboxq, phba->cfg_topology,
631  phba->cfg_link_speed);
632  mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
633  phba->fc_ratov * 2);
634  if ((mbxstatus == MBX_SUCCESS) &&
635  (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
637  "2859 SLI authentication is required "
638  "for INIT_LINK but has not done yet\n");
639  }
640 
641  lpfc_set_loopback_flag(phba);
642  if (mbxstatus != MBX_TIMEOUT)
643  mempool_free(pmboxq, phba->mbox_mem_pool);
644 
645  if (mbxstatus == MBXERR_ERROR)
646  return -EIO;
647 
648  return 0;
649 }
650 
666 static int
667 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
668 {
669  struct completion online_compl;
670  struct lpfc_sli_ring *pring;
671  struct lpfc_sli *psli;
672  int status = 0;
673  int cnt = 0;
674  int i;
675  int rc;
676 
677  init_completion(&online_compl);
678  rc = lpfc_workq_post_event(phba, &status, &online_compl,
680  if (rc == 0)
681  return -ENOMEM;
682 
683  wait_for_completion(&online_compl);
684 
685  if (status != 0)
686  return -EIO;
687 
688  psli = &phba->sli;
689 
690  /* Wait a little for things to settle down, but not
691  * long enough for dev loss timeout to expire.
692  */
693  for (i = 0; i < psli->num_rings; i++) {
694  pring = &psli->ring[i];
695  while (pring->txcmplq_cnt) {
696  msleep(10);
697  if (cnt++ > 500) { /* 5 secs */
698  lpfc_printf_log(phba,
700  "0466 Outstanding IO when "
701  "bringing Adapter offline\n");
702  break;
703  }
704  }
705  }
706 
707  init_completion(&online_compl);
708  rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
709  if (rc == 0)
710  return -ENOMEM;
711 
712  wait_for_completion(&online_compl);
713 
714  if (status != 0)
715  return -EIO;
716 
717  return 0;
718 }
719 
737 int
739 {
740  struct completion online_compl;
741  int status = 0;
742  int rc;
743 
744  if (!phba->cfg_enable_hba_reset)
745  return -EACCES;
746 
747  status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
748 
749  if (status != 0)
750  return status;
751 
752  init_completion(&online_compl);
753  rc = lpfc_workq_post_event(phba, &status, &online_compl,
755  if (rc == 0)
756  return -ENOMEM;
757 
758  wait_for_completion(&online_compl);
759 
760  if (status != 0)
761  return -EIO;
762 
763  return 0;
764 }
765 
787 static ssize_t
788 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
789  const char *buf, size_t count)
790 {
791  struct Scsi_Host *shost = class_to_shost(dev);
792  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
793  struct lpfc_hba *phba = vport->phba;
794  int status = -EINVAL;
795 
796  if (!phba->cfg_enable_hba_reset)
797  return -EACCES;
798 
799  if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
800  status = phba->lpfc_selective_reset(phba);
801 
802  if (status == 0)
803  return strlen(buf);
804  else
805  return status;
806 }
807 
824 int
826 {
827  struct lpfc_register portstat_reg = {0};
828  int i;
829 
830  msleep(100);
831  lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
832  &portstat_reg.word0);
833 
834  /* verify if privilaged for the request operation */
835  if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
836  !bf_get(lpfc_sliport_status_err, &portstat_reg))
837  return -EPERM;
838 
839  /* wait for the SLI port firmware ready after firmware reset */
840  for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
841  msleep(10);
842  lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
843  &portstat_reg.word0);
844  if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
845  continue;
846  if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
847  continue;
848  if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
849  continue;
850  break;
851  }
852 
853  if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
854  return 0;
855  else
856  return -EIO;
857 }
858 
870 static ssize_t
871 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
872 {
873  struct completion online_compl;
874  struct pci_dev *pdev = phba->pcidev;
875  uint32_t before_fc_flag;
876  uint32_t sriov_nr_virtfn;
878  int status = 0, rc = 0;
879  int job_posted = 1, sriov_err;
880 
881  if (!phba->cfg_enable_hba_reset)
882  return -EACCES;
883 
884  if ((phba->sli_rev < LPFC_SLI_REV4) ||
885  (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
887  return -EPERM;
888 
889  /* Keep state if we need to restore back */
890  before_fc_flag = phba->pport->fc_flag;
891  sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
892 
893  /* Disable SR-IOV virtual functions if enabled */
894  if (phba->cfg_sriov_nr_virtfn) {
895  pci_disable_sriov(pdev);
896  phba->cfg_sriov_nr_virtfn = 0;
897  }
898  status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
899 
900  if (status != 0)
901  return status;
902 
903  /* wait for the device to be quiesced before firmware reset */
904  msleep(100);
905 
906  reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
908 
909  if (opcode == LPFC_FW_DUMP)
910  reg_val |= LPFC_FW_DUMP_REQUEST;
911  else if (opcode == LPFC_FW_RESET)
912  reg_val |= LPFC_CTL_PDEV_CTL_FRST;
913  else if (opcode == LPFC_DV_RESET)
914  reg_val |= LPFC_CTL_PDEV_CTL_DRST;
915 
916  writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
918  /* flush */
919  readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
920 
921  /* delay driver action following IF_TYPE_2 reset */
923 
924  if (rc == -EPERM) {
925  /* no privilage for reset */
927  "3150 No privilage to perform the requested "
928  "access: x%x\n", reg_val);
929  } else if (rc == -EIO) {
930  /* reset failed, there is nothing more we can do */
932  "3153 Fail to perform the requested "
933  "access: x%x\n", reg_val);
934  return rc;
935  }
936 
937  /* keep the original port state */
938  if (before_fc_flag & FC_OFFLINE_MODE)
939  goto out;
940 
941  init_completion(&online_compl);
942  job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
944  if (!job_posted)
945  goto out;
946 
947  wait_for_completion(&online_compl);
948 
949 out:
950  /* in any case, restore the virtual functions enabled as before */
951  if (sriov_nr_virtfn) {
952  sriov_err =
953  lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
954  if (!sriov_err)
955  phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
956  }
957 
958  /* return proper error code */
959  if (!rc) {
960  if (!job_posted)
961  rc = -ENOMEM;
962  else if (status)
963  rc = -EIO;
964  }
965  return rc;
966 }
967 
976 static ssize_t
977 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
978  char *buf)
979 {
980  struct Scsi_Host *shost = class_to_shost(dev);
981  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
982  struct lpfc_hba *phba = vport->phba;
983 
984  return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
985 }
986 
995 static ssize_t
996 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
997  char *buf)
998 {
999  struct Scsi_Host *shost = class_to_shost(dev);
1000  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1001  struct lpfc_hba *phba = vport->phba;
1002  char * state;
1003 
1004  if (phba->link_state == LPFC_HBA_ERROR)
1005  state = "error";
1006  else if (phba->link_state == LPFC_WARM_START)
1007  state = "warm start";
1008  else if (phba->link_state == LPFC_INIT_START)
1009  state = "offline";
1010  else
1011  state = "online";
1012 
1013  return snprintf(buf, PAGE_SIZE, "%s\n", state);
1014 }
1015 
1029 static ssize_t
1030 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1031  const char *buf, size_t count)
1032 {
1033  struct Scsi_Host *shost = class_to_shost(dev);
1034  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1035  struct lpfc_hba *phba = vport->phba;
1036  struct completion online_compl;
1037  char *board_mode_str = NULL;
1038  int status = 0;
1039  int rc;
1040 
1041  if (!phba->cfg_enable_hba_reset) {
1042  status = -EACCES;
1043  goto board_mode_out;
1044  }
1045 
1047  "3050 lpfc_board_mode set to %s\n", buf);
1048 
1049  init_completion(&online_compl);
1050 
1051  if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1052  rc = lpfc_workq_post_event(phba, &status, &online_compl,
1053  LPFC_EVT_ONLINE);
1054  if (rc == 0) {
1055  status = -ENOMEM;
1056  goto board_mode_out;
1057  }
1058  wait_for_completion(&online_compl);
1059  } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1060  status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1061  else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1062  if (phba->sli_rev == LPFC_SLI_REV4)
1063  status = -EINVAL;
1064  else
1065  status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1066  else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1067  if (phba->sli_rev == LPFC_SLI_REV4)
1068  status = -EINVAL;
1069  else
1070  status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1071  else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1072  status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1073  else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1074  status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1075  else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1076  status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1077  else
1078  status = -EINVAL;
1079 
1080 board_mode_out:
1081  if (!status)
1082  return strlen(buf);
1083  else {
1084  board_mode_str = strchr(buf, '\n');
1085  if (board_mode_str)
1086  *board_mode_str = '\0';
1088  "3097 Failed \"%s\", status(%d), "
1089  "fc_flag(x%x)\n",
1090  buf, status, phba->pport->fc_flag);
1091  return status;
1092  }
1093 }
1094 
1113 static int
1114 lpfc_get_hba_info(struct lpfc_hba *phba,
1115  uint32_t *mxri, uint32_t *axri,
1116  uint32_t *mrpi, uint32_t *arpi,
1117  uint32_t *mvpi, uint32_t *avpi)
1118 {
1119  struct lpfc_mbx_read_config *rd_config;
1120  LPFC_MBOXQ_t *pmboxq;
1121  MAILBOX_t *pmb;
1122  int rc = 0;
1123  uint32_t max_vpi;
1124 
1125  /*
1126  * prevent udev from issuing mailbox commands until the port is
1127  * configured.
1128  */
1129  if (phba->link_state < LPFC_LINK_DOWN ||
1130  !phba->mbox_mem_pool ||
1131  (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1132  return 0;
1133 
1134  if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1135  return 0;
1136 
1137  pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1138  if (!pmboxq)
1139  return 0;
1140  memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1141 
1142  pmb = &pmboxq->u.mb;
1143  pmb->mbxCommand = MBX_READ_CONFIG;
1144  pmb->mbxOwner = OWN_HOST;
1145  pmboxq->context1 = NULL;
1146 
1147  if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1148  rc = MBX_NOT_FINISHED;
1149  else
1150  rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1151 
1152  if (rc != MBX_SUCCESS) {
1153  if (rc != MBX_TIMEOUT)
1154  mempool_free(pmboxq, phba->mbox_mem_pool);
1155  return 0;
1156  }
1157 
1158  if (phba->sli_rev == LPFC_SLI_REV4) {
1159  rd_config = &pmboxq->u.mqe.un.rd_config;
1160  if (mrpi)
1161  *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1162  if (arpi)
1163  *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1164  phba->sli4_hba.max_cfg_param.rpi_used;
1165  if (mxri)
1166  *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1167  if (axri)
1168  *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1169  phba->sli4_hba.max_cfg_param.xri_used;
1170 
1171  /* Account for differences with SLI-3. Get vpi count from
1172  * mailbox data and subtract one for max vpi value.
1173  */
1174  max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1175  (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1176 
1177  if (mvpi)
1178  *mvpi = max_vpi;
1179  if (avpi)
1180  *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1181  } else {
1182  if (mrpi)
1183  *mrpi = pmb->un.varRdConfig.max_rpi;
1184  if (arpi)
1185  *arpi = pmb->un.varRdConfig.avail_rpi;
1186  if (mxri)
1187  *mxri = pmb->un.varRdConfig.max_xri;
1188  if (axri)
1189  *axri = pmb->un.varRdConfig.avail_xri;
1190  if (mvpi)
1191  *mvpi = pmb->un.varRdConfig.max_vpi;
1192  if (avpi)
1193  *avpi = pmb->un.varRdConfig.avail_vpi;
1194  }
1195 
1196  mempool_free(pmboxq, phba->mbox_mem_pool);
1197  return 1;
1198 }
1199 
1214 static ssize_t
1215 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1216  char *buf)
1217 {
1218  struct Scsi_Host *shost = class_to_shost(dev);
1219  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1220  struct lpfc_hba *phba = vport->phba;
1221  uint32_t cnt;
1222 
1223  if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1224  return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1225  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1226 }
1227 
1242 static ssize_t
1243 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1244  char *buf)
1245 {
1246  struct Scsi_Host *shost = class_to_shost(dev);
1247  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1248  struct lpfc_hba *phba = vport->phba;
1249  uint32_t cnt, acnt;
1250 
1251  if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1252  return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1253  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1254 }
1255 
1270 static ssize_t
1271 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1272  char *buf)
1273 {
1274  struct Scsi_Host *shost = class_to_shost(dev);
1275  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1276  struct lpfc_hba *phba = vport->phba;
1277  uint32_t cnt;
1278 
1279  if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1280  return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1281  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1282 }
1283 
1298 static ssize_t
1299 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1300  char *buf)
1301 {
1302  struct Scsi_Host *shost = class_to_shost(dev);
1303  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1304  struct lpfc_hba *phba = vport->phba;
1305  uint32_t cnt, acnt;
1306 
1307  if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1308  return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1309  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1310 }
1311 
1326 static ssize_t
1327 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1328  char *buf)
1329 {
1330  struct Scsi_Host *shost = class_to_shost(dev);
1331  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1332  struct lpfc_hba *phba = vport->phba;
1333  uint32_t cnt;
1334 
1335  if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1336  return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1337  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1338 }
1339 
1354 static ssize_t
1355 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1356  char *buf)
1357 {
1358  struct Scsi_Host *shost = class_to_shost(dev);
1359  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1360  struct lpfc_hba *phba = vport->phba;
1361  uint32_t cnt, acnt;
1362 
1363  if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1364  return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1365  return snprintf(buf, PAGE_SIZE, "Unknown\n");
1366 }
1367 
1381 static ssize_t
1382 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1383  char *buf)
1384 {
1385  struct Scsi_Host *shost = class_to_shost(dev);
1386  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1387  struct lpfc_hba *phba = vport->phba;
1388 
1389  if (!(phba->max_vpi))
1390  return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1391  if (vport->port_type == LPFC_PHYSICAL_PORT)
1392  return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1393  return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1394 }
1395 
1407 static ssize_t
1408 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1409  char *buf)
1410 {
1411  struct Scsi_Host *shost = class_to_shost(dev);
1412  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1413  struct lpfc_hba *phba = vport->phba;
1414 
1415  return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1416 }
1417 
1432 static ssize_t
1433 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1434  const char *buf, size_t count)
1435 {
1436  struct Scsi_Host *shost = class_to_shost(dev);
1437  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1438  struct lpfc_hba *phba = vport->phba;
1439  uint32_t creg_val;
1440  uint32_t old_val;
1441  int val=0;
1442 
1443  if (!isdigit(buf[0]))
1444  return -EINVAL;
1445 
1446  if (sscanf(buf, "%i", &val) != 1)
1447  return -EINVAL;
1448 
1449  if ((val & 0x3) != val)
1450  return -EINVAL;
1451 
1452  if (phba->sli_rev == LPFC_SLI_REV4)
1453  val = 0;
1454 
1456  "3051 lpfc_poll changed from %d to %d\n",
1457  phba->cfg_poll, val);
1458 
1459  spin_lock_irq(&phba->hbalock);
1460 
1461  old_val = phba->cfg_poll;
1462 
1463  if (val & ENABLE_FCP_RING_POLLING) {
1464  if ((val & DISABLE_FCP_RING_INT) &&
1465  !(old_val & DISABLE_FCP_RING_INT)) {
1466  if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1467  spin_unlock_irq(&phba->hbalock);
1468  return -EINVAL;
1469  }
1470  creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1471  writel(creg_val, phba->HCregaddr);
1472  readl(phba->HCregaddr); /* flush */
1473 
1474  lpfc_poll_start_timer(phba);
1475  }
1476  } else if (val != 0x0) {
1477  spin_unlock_irq(&phba->hbalock);
1478  return -EINVAL;
1479  }
1480 
1481  if (!(val & DISABLE_FCP_RING_INT) &&
1482  (old_val & DISABLE_FCP_RING_INT))
1483  {
1484  spin_unlock_irq(&phba->hbalock);
1485  del_timer(&phba->fcp_poll_timer);
1486  spin_lock_irq(&phba->hbalock);
1487  if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1488  spin_unlock_irq(&phba->hbalock);
1489  return -EINVAL;
1490  }
1491  creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1492  writel(creg_val, phba->HCregaddr);
1493  readl(phba->HCregaddr); /* flush */
1494  }
1495 
1496  phba->cfg_poll = val;
1497 
1498  spin_unlock_irq(&phba->hbalock);
1499 
1500  return strlen(buf);
1501 }
1502 
1511 static ssize_t
1512 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1513  char *buf)
1514 {
1515  struct Scsi_Host *shost = class_to_shost(dev);
1516  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1517  struct lpfc_hba *phba = vport->phba;
1518 
1519  return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1520 }
1521 
1530 static ssize_t
1531 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1532  char *buf)
1533 {
1534  struct Scsi_Host *shost = class_to_shost(dev);
1535  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1536  struct lpfc_hba *phba = vport->phba;
1537 
1538  return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1539 }
1540 
1549 static ssize_t
1550 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1551  char *buf)
1552 {
1553  struct Scsi_Host *shost = class_to_shost(dev);
1554  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1555  struct lpfc_hba *phba = vport->phba;
1556 
1557  return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1558  (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1560  "" : "Not ");
1561 }
1562 
1575 static ssize_t
1576 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1577  struct device_attribute *attr,
1578  char *buf)
1579 {
1580  struct Scsi_Host *shost = class_to_shost(dev);
1581  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1582  struct lpfc_hba *phba = vport->phba;
1583  uint16_t max_nr_virtfn;
1584 
1585  max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1586  return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1587 }
1588 
1603 #define lpfc_param_show(attr) \
1604 static ssize_t \
1605 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1606  char *buf) \
1607 { \
1608  struct Scsi_Host *shost = class_to_shost(dev);\
1609  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1610  struct lpfc_hba *phba = vport->phba;\
1611  uint val = 0;\
1612  val = phba->cfg_##attr;\
1613  return snprintf(buf, PAGE_SIZE, "%d\n",\
1614  phba->cfg_##attr);\
1615 }
1616 
1631 #define lpfc_param_hex_show(attr) \
1632 static ssize_t \
1633 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1634  char *buf) \
1635 { \
1636  struct Scsi_Host *shost = class_to_shost(dev);\
1637  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1638  struct lpfc_hba *phba = vport->phba;\
1639  uint val = 0;\
1640  val = phba->cfg_##attr;\
1641  return snprintf(buf, PAGE_SIZE, "%#x\n",\
1642  phba->cfg_##attr);\
1643 }
1644 
1664 #define lpfc_param_init(attr, default, minval, maxval) \
1665 static int \
1666 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1667 { \
1668  if (val >= minval && val <= maxval) {\
1669  phba->cfg_##attr = val;\
1670  return 0;\
1671  }\
1672  lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1673  "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1674  "allowed range is ["#minval", "#maxval"]\n", val); \
1675  phba->cfg_##attr = default;\
1676  return -EINVAL;\
1677 }
1678 
1699 #define lpfc_param_set(attr, default, minval, maxval) \
1700 static int \
1701 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1702 { \
1703  if (val >= minval && val <= maxval) {\
1704  lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1705  "3052 lpfc_" #attr " changed from %d to %d\n", \
1706  phba->cfg_##attr, val); \
1707  phba->cfg_##attr = val;\
1708  return 0;\
1709  }\
1710  lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1711  "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1712  "allowed range is ["#minval", "#maxval"]\n", val); \
1713  return -EINVAL;\
1714 }
1715 
1737 #define lpfc_param_store(attr) \
1738 static ssize_t \
1739 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1740  const char *buf, size_t count) \
1741 { \
1742  struct Scsi_Host *shost = class_to_shost(dev);\
1743  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1744  struct lpfc_hba *phba = vport->phba;\
1745  uint val = 0;\
1746  if (!isdigit(buf[0]))\
1747  return -EINVAL;\
1748  if (sscanf(buf, "%i", &val) != 1)\
1749  return -EINVAL;\
1750  if (lpfc_##attr##_set(phba, val) == 0) \
1751  return strlen(buf);\
1752  else \
1753  return -EINVAL;\
1754 }
1755 
1770 #define lpfc_vport_param_show(attr) \
1771 static ssize_t \
1772 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1773  char *buf) \
1774 { \
1775  struct Scsi_Host *shost = class_to_shost(dev);\
1776  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1777  uint val = 0;\
1778  val = vport->cfg_##attr;\
1779  return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1780 }
1781 
1797 #define lpfc_vport_param_hex_show(attr) \
1798 static ssize_t \
1799 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1800  char *buf) \
1801 { \
1802  struct Scsi_Host *shost = class_to_shost(dev);\
1803  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1804  uint val = 0;\
1805  val = vport->cfg_##attr;\
1806  return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1807 }
1808 
1827 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1828 static int \
1829 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1830 { \
1831  if (val >= minval && val <= maxval) {\
1832  vport->cfg_##attr = val;\
1833  return 0;\
1834  }\
1835  lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1836  "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1837  "allowed range is ["#minval", "#maxval"]\n", val); \
1838  vport->cfg_##attr = default;\
1839  return -EINVAL;\
1840 }
1841 
1859 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1860 static int \
1861 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1862 { \
1863  if (val >= minval && val <= maxval) {\
1864  lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1865  "3053 lpfc_" #attr " changed from %d to %d\n", \
1866  vport->cfg_##attr, val); \
1867  vport->cfg_##attr = val;\
1868  return 0;\
1869  }\
1870  lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1871  "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1872  "allowed range is ["#minval", "#maxval"]\n", val); \
1873  return -EINVAL;\
1874 }
1875 
1893 #define lpfc_vport_param_store(attr) \
1894 static ssize_t \
1895 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1896  const char *buf, size_t count) \
1897 { \
1898  struct Scsi_Host *shost = class_to_shost(dev);\
1899  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1900  uint val = 0;\
1901  if (!isdigit(buf[0]))\
1902  return -EINVAL;\
1903  if (sscanf(buf, "%i", &val) != 1)\
1904  return -EINVAL;\
1905  if (lpfc_##attr##_set(vport, val) == 0) \
1906  return strlen(buf);\
1907  else \
1908  return -EINVAL;\
1909 }
1910 
1911 
1912 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1913 static uint lpfc_##name = defval;\
1914 module_param(lpfc_##name, uint, S_IRUGO);\
1915 MODULE_PARM_DESC(lpfc_##name, desc);\
1916 lpfc_param_init(name, defval, minval, maxval)
1917 
1918 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1919 static uint lpfc_##name = defval;\
1920 module_param(lpfc_##name, uint, S_IRUGO);\
1921 MODULE_PARM_DESC(lpfc_##name, desc);\
1922 lpfc_param_show(name)\
1923 lpfc_param_init(name, defval, minval, maxval)\
1924 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1925 
1926 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1927 static uint lpfc_##name = defval;\
1928 module_param(lpfc_##name, uint, S_IRUGO);\
1929 MODULE_PARM_DESC(lpfc_##name, desc);\
1930 lpfc_param_show(name)\
1931 lpfc_param_init(name, defval, minval, maxval)\
1932 lpfc_param_set(name, defval, minval, maxval)\
1933 lpfc_param_store(name)\
1934 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1935  lpfc_##name##_show, lpfc_##name##_store)
1936 
1937 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1938 static uint lpfc_##name = defval;\
1939 module_param(lpfc_##name, uint, S_IRUGO);\
1940 MODULE_PARM_DESC(lpfc_##name, desc);\
1941 lpfc_param_hex_show(name)\
1942 lpfc_param_init(name, defval, minval, maxval)\
1943 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1944 
1945 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1946 static uint lpfc_##name = defval;\
1947 module_param(lpfc_##name, uint, S_IRUGO);\
1948 MODULE_PARM_DESC(lpfc_##name, desc);\
1949 lpfc_param_hex_show(name)\
1950 lpfc_param_init(name, defval, minval, maxval)\
1951 lpfc_param_set(name, defval, minval, maxval)\
1952 lpfc_param_store(name)\
1953 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1954  lpfc_##name##_show, lpfc_##name##_store)
1955 
1956 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1957 static uint lpfc_##name = defval;\
1958 module_param(lpfc_##name, uint, S_IRUGO);\
1959 MODULE_PARM_DESC(lpfc_##name, desc);\
1960 lpfc_vport_param_init(name, defval, minval, maxval)
1961 
1962 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1963 static uint lpfc_##name = defval;\
1964 module_param(lpfc_##name, uint, S_IRUGO);\
1965 MODULE_PARM_DESC(lpfc_##name, desc);\
1966 lpfc_vport_param_show(name)\
1967 lpfc_vport_param_init(name, defval, minval, maxval)\
1968 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1969 
1970 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1971 static uint lpfc_##name = defval;\
1972 module_param(lpfc_##name, uint, S_IRUGO);\
1973 MODULE_PARM_DESC(lpfc_##name, desc);\
1974 lpfc_vport_param_show(name)\
1975 lpfc_vport_param_init(name, defval, minval, maxval)\
1976 lpfc_vport_param_set(name, defval, minval, maxval)\
1977 lpfc_vport_param_store(name)\
1978 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1979  lpfc_##name##_show, lpfc_##name##_store)
1980 
1981 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1982 static uint lpfc_##name = defval;\
1983 module_param(lpfc_##name, uint, S_IRUGO);\
1984 MODULE_PARM_DESC(lpfc_##name, desc);\
1985 lpfc_vport_param_hex_show(name)\
1986 lpfc_vport_param_init(name, defval, minval, maxval)\
1987 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1988 
1989 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1990 static uint lpfc_##name = defval;\
1991 module_param(lpfc_##name, uint, S_IRUGO);\
1992 MODULE_PARM_DESC(lpfc_##name, desc);\
1993 lpfc_vport_param_hex_show(name)\
1994 lpfc_vport_param_init(name, defval, minval, maxval)\
1995 lpfc_vport_param_set(name, defval, minval, maxval)\
1996 lpfc_vport_param_store(name)\
1997 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1998  lpfc_##name##_show, lpfc_##name##_store)
1999 
2000 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2001 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2002 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2003 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2004 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2005 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2006 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2007 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2008 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2009 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2010 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2011 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2012 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2013  lpfc_link_state_store);
2014 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2015  lpfc_option_rom_version_show, NULL);
2016 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2017  lpfc_num_discovered_ports_show, NULL);
2018 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2019 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2020 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2021 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2022 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2023  lpfc_board_mode_show, lpfc_board_mode_store);
2024 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2025 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2026 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2027 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2028 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2029 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2030 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2031 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2032 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2033 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2034 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2035 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2036 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2037  lpfc_sriov_hw_max_virtfn_show, NULL);
2038 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2039 
2040 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2041 
2053 static ssize_t
2054 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2055  const char *buf, size_t count)
2056 {
2057  struct Scsi_Host *shost = class_to_shost(dev);
2058  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2059  struct lpfc_hba *phba = vport->phba;
2060  unsigned int cnt = count;
2061 
2062  /*
2063  * We're doing a simple sanity check for soft_wwpn setting.
2064  * We require that the user write a specific key to enable
2065  * the soft_wwpn attribute to be settable. Once the attribute
2066  * is written, the enable key resets. If further updates are
2067  * desired, the key must be written again to re-enable the
2068  * attribute.
2069  *
2070  * The "key" is not secret - it is a hardcoded string shown
2071  * here. The intent is to protect against the random user or
2072  * application that is just writing attributes.
2073  */
2074 
2075  /* count may include a LF at end of string */
2076  if (buf[cnt-1] == '\n')
2077  cnt--;
2078 
2079  if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2080  (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2081  return -EINVAL;
2082 
2083  phba->soft_wwn_enable = 1;
2084  return count;
2085 }
2086 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2087  lpfc_soft_wwn_enable_store);
2088 
2097 static ssize_t
2098 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2099  char *buf)
2100 {
2101  struct Scsi_Host *shost = class_to_shost(dev);
2102  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2103  struct lpfc_hba *phba = vport->phba;
2104 
2105  return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2106  (unsigned long long)phba->cfg_soft_wwpn);
2107 }
2108 
2122 static ssize_t
2123 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2124  const char *buf, size_t count)
2125 {
2126  struct Scsi_Host *shost = class_to_shost(dev);
2127  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2128  struct lpfc_hba *phba = vport->phba;
2129  struct completion online_compl;
2130  int stat1=0, stat2=0;
2131  unsigned int i, j, cnt=count;
2132  u8 wwpn[8];
2133  int rc;
2134 
2135  if (!phba->cfg_enable_hba_reset)
2136  return -EACCES;
2137  spin_lock_irq(&phba->hbalock);
2138  if (phba->over_temp_state == HBA_OVER_TEMP) {
2139  spin_unlock_irq(&phba->hbalock);
2140  return -EACCES;
2141  }
2142  spin_unlock_irq(&phba->hbalock);
2143  /* count may include a LF at end of string */
2144  if (buf[cnt-1] == '\n')
2145  cnt--;
2146 
2147  if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2148  ((cnt == 17) && (*buf++ != 'x')) ||
2149  ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2150  return -EINVAL;
2151 
2152  phba->soft_wwn_enable = 0;
2153 
2154  memset(wwpn, 0, sizeof(wwpn));
2155 
2156  /* Validate and store the new name */
2157  for (i=0, j=0; i < 16; i++) {
2158  int value;
2159 
2160  value = hex_to_bin(*buf++);
2161  if (value >= 0)
2162  j = (j << 4) | value;
2163  else
2164  return -EINVAL;
2165  if (i % 2) {
2166  wwpn[i/2] = j & 0xff;
2167  j = 0;
2168  }
2169  }
2170  phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2171  fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2172  if (phba->cfg_soft_wwnn)
2173  fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2174 
2175  dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2176  "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2177 
2178  stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2179  if (stat1)
2181  "0463 lpfc_soft_wwpn attribute set failed to "
2182  "reinit adapter - %d\n", stat1);
2183  init_completion(&online_compl);
2184  rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2185  LPFC_EVT_ONLINE);
2186  if (rc == 0)
2187  return -ENOMEM;
2188 
2189  wait_for_completion(&online_compl);
2190  if (stat2)
2192  "0464 lpfc_soft_wwpn attribute set failed to "
2193  "reinit adapter - %d\n", stat2);
2194  return (stat1 || stat2) ? -EIO : count;
2195 }
2196 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2197  lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2198 
2207 static ssize_t
2208 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2209  char *buf)
2210 {
2211  struct Scsi_Host *shost = class_to_shost(dev);
2212  struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2213  return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2214  (unsigned long long)phba->cfg_soft_wwnn);
2215 }
2216 
2227 static ssize_t
2228 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2229  const char *buf, size_t count)
2230 {
2231  struct Scsi_Host *shost = class_to_shost(dev);
2232  struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2233  unsigned int i, j, cnt=count;
2234  u8 wwnn[8];
2235 
2236  /* count may include a LF at end of string */
2237  if (buf[cnt-1] == '\n')
2238  cnt--;
2239 
2240  if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2241  ((cnt == 17) && (*buf++ != 'x')) ||
2242  ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2243  return -EINVAL;
2244 
2245  /*
2246  * Allow wwnn to be set many times, as long as the enable is set.
2247  * However, once the wwpn is set, everything locks.
2248  */
2249 
2250  memset(wwnn, 0, sizeof(wwnn));
2251 
2252  /* Validate and store the new name */
2253  for (i=0, j=0; i < 16; i++) {
2254  int value;
2255 
2256  value = hex_to_bin(*buf++);
2257  if (value >= 0)
2258  j = (j << 4) | value;
2259  else
2260  return -EINVAL;
2261  if (i % 2) {
2262  wwnn[i/2] = j & 0xff;
2263  j = 0;
2264  }
2265  }
2266  phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2267 
2268  dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2269  "lpfc%d: soft_wwnn set. Value will take effect upon "
2270  "setting of the soft_wwpn\n", phba->brd_no);
2271 
2272  return count;
2273 }
2274 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2275  lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2276 
2277 
2278 static int lpfc_poll = 0;
2279 module_param(lpfc_poll, int, S_IRUGO);
2280 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2281  " 0 - none,"
2282  " 1 - poll with interrupts enabled"
2283  " 3 - poll and disable FCP ring interrupts");
2284 
2285 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2286  lpfc_poll_show, lpfc_poll_store);
2287 
2289 module_param(lpfc_sli_mode, int, S_IRUGO);
2290 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2291  " 0 - auto (SLI-3 if supported),"
2292  " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2293  " 3 - select SLI-3");
2294 
2296 module_param(lpfc_enable_npiv, int, S_IRUGO);
2297 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2298 lpfc_param_show(enable_npiv);
2299 lpfc_param_init(enable_npiv, 1, 0, 1);
2300 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2301 
2302 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2303  "FCF Fast failover=1 Priority failover=2");
2304 
2306 module_param(lpfc_enable_rrq, int, S_IRUGO);
2307 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2308 lpfc_param_show(enable_rrq);
2309 lpfc_param_init(enable_rrq, 0, 0, 1);
2310 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2311 
2312 /*
2313 # lpfc_suppress_link_up: Bring link up at initialization
2314 # 0x0 = bring link up (issue MBX_INIT_LINK)
2315 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2316 # 0x2 = never bring up link
2317 # Default value is 0.
2318 */
2321  "Suppress Link Up at initialization");
2322 /*
2323 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2324 # 1 - (1024)
2325 # 2 - (2048)
2326 # 3 - (3072)
2327 # 4 - (4096)
2328 # 5 - (5120)
2329 */
2330 static ssize_t
2331 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2332 {
2333  struct Scsi_Host *shost = class_to_shost(dev);
2334  struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2335 
2336  return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2337 }
2338 
2339 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2340  lpfc_iocb_hw_show, NULL);
2341 static ssize_t
2342 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2343 {
2344  struct Scsi_Host *shost = class_to_shost(dev);
2345  struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2346 
2347  return snprintf(buf, PAGE_SIZE, "%d\n",
2348  phba->sli.ring[LPFC_ELS_RING].txq_max);
2349 }
2350 
2351 static DEVICE_ATTR(txq_hw, S_IRUGO,
2352  lpfc_txq_hw_show, NULL);
2353 static ssize_t
2354 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2355  char *buf)
2356 {
2357  struct Scsi_Host *shost = class_to_shost(dev);
2358  struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2359 
2360  return snprintf(buf, PAGE_SIZE, "%d\n",
2361  phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2362 }
2363 
2364 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2365  lpfc_txcmplq_hw_show, NULL);
2366 
2368 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2369 MODULE_PARM_DESC(lpfc_iocb_cnt,
2370  "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2371 lpfc_param_show(iocb_cnt);
2372 lpfc_param_init(iocb_cnt, 2, 1, 5);
2373 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2374  lpfc_iocb_cnt_show, NULL);
2375 
2376 /*
2377 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2378 # until the timer expires. Value range is [0,255]. Default value is 30.
2379 */
2380 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2381 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2382 module_param(lpfc_nodev_tmo, int, 0);
2383 MODULE_PARM_DESC(lpfc_nodev_tmo,
2384  "Seconds driver will hold I/O waiting "
2385  "for a device to come back");
2386 
2395 static ssize_t
2396 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2397  char *buf)
2398 {
2399  struct Scsi_Host *shost = class_to_shost(dev);
2400  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2401 
2402  return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2403 }
2404 
2420 static int
2421 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2422 {
2423  if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2424  vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2425  if (val != LPFC_DEF_DEVLOSS_TMO)
2427  "0407 Ignoring nodev_tmo module "
2428  "parameter because devloss_tmo is "
2429  "set.\n");
2430  return 0;
2431  }
2432 
2433  if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2434  vport->cfg_nodev_tmo = val;
2435  vport->cfg_devloss_tmo = val;
2436  return 0;
2437  }
2439  "0400 lpfc_nodev_tmo attribute cannot be set to"
2440  " %d, allowed range is [%d, %d]\n",
2443  return -EINVAL;
2444 }
2445 
2453 static void
2454 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2455 {
2456  struct Scsi_Host *shost;
2457  struct lpfc_nodelist *ndlp;
2458 
2459  shost = lpfc_shost_from_vport(vport);
2460  spin_lock_irq(shost->host_lock);
2461  list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2462  if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2463  ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2464  spin_unlock_irq(shost->host_lock);
2465 }
2466 
2482 static int
2483 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2484 {
2485  if (vport->dev_loss_tmo_changed ||
2486  (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2488  "0401 Ignoring change to nodev_tmo "
2489  "because devloss_tmo is set.\n");
2490  return 0;
2491  }
2492  if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2493  vport->cfg_nodev_tmo = val;
2494  vport->cfg_devloss_tmo = val;
2495  /*
2496  * For compat: set the fc_host dev loss so new rports
2497  * will get the value.
2498  */
2499  fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2500  lpfc_update_rport_devloss_tmo(vport);
2501  return 0;
2502  }
2504  "0403 lpfc_nodev_tmo attribute cannot be set to"
2505  "%d, allowed range is [%d, %d]\n",
2507  return -EINVAL;
2508 }
2509 
2511 
2512 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2513  lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2514 
2515 /*
2516 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2517 # disappear until the timer expires. Value range is [0,255]. Default
2518 # value is 30.
2519 */
2520 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2521 MODULE_PARM_DESC(lpfc_devloss_tmo,
2522  "Seconds driver will hold I/O waiting "
2523  "for a device to come back");
2526 lpfc_vport_param_show(devloss_tmo)
2527 
2542 static int
2543 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2544 {
2545  if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2546  vport->cfg_nodev_tmo = val;
2547  vport->cfg_devloss_tmo = val;
2548  vport->dev_loss_tmo_changed = 1;
2549  fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2550  lpfc_update_rport_devloss_tmo(vport);
2551  return 0;
2552  }
2553 
2555  "0404 lpfc_devloss_tmo attribute cannot be set to"
2556  " %d, allowed range is [%d, %d]\n",
2557  val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2558  return -EINVAL;
2559 }
2560 
2562 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2563  lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2564 
2565 /*
2566 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2567 # deluged with LOTS of information.
2568 # You can set a bit mask to record specific types of verbose messages:
2569 # See lpfc_logmsh.h for definitions.
2570 */
2571 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2572  "Verbose logging bit-mask");
2573 
2574 /*
2575 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2576 # objects that have been registered with the nameserver after login.
2577 */
2578 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
2579  "Deregister nameserver objects before LOGO");
2580 
2581 /*
2582 # lun_queue_depth: This parameter is used to limit the number of outstanding
2583 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2584 */
2585 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2586  "Max number of FCP commands we can queue to a specific LUN");
2587 
2588 /*
2589 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2590 # commands per target port. Value range is [10,65535]. Default value is 65535.
2591 */
2592 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2593  "Max number of FCP commands we can queue to a specific target port");
2594 
2595 /*
2596 # hba_queue_depth: This parameter is used to limit the number of outstanding
2597 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2598 # value is greater than the maximum number of exchanges supported by the HBA,
2599 # then maximum number of exchanges supported by the HBA is used to determine
2600 # the hba_queue_depth.
2601 */
2602 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2603  "Max number of FCP commands we can queue to a lpfc HBA");
2604 
2605 /*
2606 # peer_port_login: This parameter allows/prevents logins
2607 # between peer ports hosted on the same physical port.
2608 # When this parameter is set 0 peer ports of same physical port
2609 # are not allowed to login to each other.
2610 # When this parameter is set 1 peer ports of same physical port
2611 # are allowed to login to each other.
2612 # Default value of this parameter is 0.
2613 */
2614 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2615  "Allow peer ports on the same physical port to login to each "
2616  "other.");
2617 
2618 /*
2619 # restrict_login: This parameter allows/prevents logins
2620 # between Virtual Ports and remote initiators.
2621 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2622 # other initiators and will attempt to PLOGI all remote ports.
2623 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2624 # remote ports and will not attempt to PLOGI to other initiators.
2625 # This parameter does not restrict to the physical port.
2626 # This parameter does not restrict logins to Fabric resident remote ports.
2627 # Default value of this parameter is 1.
2628 */
2629 static int lpfc_restrict_login = 1;
2630 module_param(lpfc_restrict_login, int, S_IRUGO);
2631 MODULE_PARM_DESC(lpfc_restrict_login,
2632  "Restrict virtual ports login to remote initiators.");
2633 lpfc_vport_param_show(restrict_login);
2634 
2650 static int
2651 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2652 {
2653  if (val < 0 || val > 1) {
2655  "0422 lpfc_restrict_login attribute cannot "
2656  "be set to %d, allowed range is [0, 1]\n",
2657  val);
2658  vport->cfg_restrict_login = 1;
2659  return -EINVAL;
2660  }
2661  if (vport->port_type == LPFC_PHYSICAL_PORT) {
2662  vport->cfg_restrict_login = 0;
2663  return 0;
2664  }
2665  vport->cfg_restrict_login = val;
2666  return 0;
2667 }
2668 
2685 static int
2686 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2687 {
2688  if (val < 0 || val > 1) {
2690  "0425 lpfc_restrict_login attribute cannot "
2691  "be set to %d, allowed range is [0, 1]\n",
2692  val);
2693  vport->cfg_restrict_login = 1;
2694  return -EINVAL;
2695  }
2696  if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2698  "0468 lpfc_restrict_login must be 0 for "
2699  "Physical ports.\n");
2700  vport->cfg_restrict_login = 0;
2701  return 0;
2702  }
2703  vport->cfg_restrict_login = val;
2704  return 0;
2705 }
2706 lpfc_vport_param_store(restrict_login);
2707 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2708  lpfc_restrict_login_show, lpfc_restrict_login_store);
2709 
2710 /*
2711 # Some disk devices have a "select ID" or "select Target" capability.
2712 # From a protocol standpoint "select ID" usually means select the
2713 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2714 # annex" which contains a table that maps a "select ID" (a number
2715 # between 0 and 7F) to an ALPA. By default, for compatibility with
2716 # older drivers, the lpfc driver scans this table from low ALPA to high
2717 # ALPA.
2718 #
2719 # Turning on the scan-down variable (on = 1, off = 0) will
2720 # cause the lpfc driver to use an inverted table, effectively
2721 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2722 #
2723 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2724 # and will not work across a fabric. Also this parameter will take
2725 # effect only in the case when ALPA map is not available.)
2726 */
2727 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2728  "Start scanning for devices from highest ALPA to lowest");
2729 
2730 /*
2731 # lpfc_topology: link topology for init link
2732 # 0x0 = attempt loop mode then point-to-point
2733 # 0x01 = internal loopback mode
2734 # 0x02 = attempt point-to-point mode only
2735 # 0x04 = attempt loop mode only
2736 # 0x06 = attempt point-to-point mode then loop
2737 # Set point-to-point mode if you want to run as an N_Port.
2738 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2739 # Default value is 0.
2740 */
2741 
2758 static ssize_t
2759 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2760  const char *buf, size_t count)
2761 {
2762  struct Scsi_Host *shost = class_to_shost(dev);
2763  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2764  struct lpfc_hba *phba = vport->phba;
2765  int val = 0;
2766  int nolip = 0;
2767  const char *val_buf = buf;
2768  int err;
2769  uint32_t prev_val;
2770 
2771  if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2772  nolip = 1;
2773  val_buf = &buf[strlen("nolip ")];
2774  }
2775 
2776  if (!isdigit(val_buf[0]))
2777  return -EINVAL;
2778  if (sscanf(val_buf, "%i", &val) != 1)
2779  return -EINVAL;
2780 
2781  if (val >= 0 && val <= 6) {
2782  prev_val = phba->cfg_topology;
2783  phba->cfg_topology = val;
2785  val == 4) {
2787  "3113 Loop mode not supported at speed %d\n",
2788  phba->cfg_link_speed);
2789  phba->cfg_topology = prev_val;
2790  return -EINVAL;
2791  }
2792  if (nolip)
2793  return strlen(buf);
2794 
2796  "3054 lpfc_topology changed from %d to %d\n",
2797  prev_val, val);
2798  err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2799  if (err) {
2800  phba->cfg_topology = prev_val;
2801  return -EINVAL;
2802  } else
2803  return strlen(buf);
2804  }
2806  "%d:0467 lpfc_topology attribute cannot be set to %d, "
2807  "allowed range is [0, 6]\n",
2808  phba->brd_no, val);
2809  return -EINVAL;
2810 }
2811 static int lpfc_topology = 0;
2812 module_param(lpfc_topology, int, S_IRUGO);
2813 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2815 lpfc_param_init(topology, 0, 0, 6)
2816 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2817  lpfc_topology_show, lpfc_topology_store);
2818 
2830 static ssize_t
2831 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2832  char *buf)
2833 {
2834  struct Scsi_Host *shost = class_to_shost(dev);
2835  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2836  if (vport->vport_flag & STATIC_VPORT)
2837  sprintf(buf, "1\n");
2838  else
2839  sprintf(buf, "0\n");
2840 
2841  return strlen(buf);
2842 }
2843 
2844 /*
2845  * Sysfs attribute to control the statistical data collection.
2846  */
2847 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2848  lpfc_static_vport_show, NULL);
2849 
2869 static ssize_t
2870 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2871  const char *buf, size_t count)
2872 {
2873  struct Scsi_Host *shost = class_to_shost(dev);
2874  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2875  struct lpfc_hba *phba = vport->phba;
2876 #define LPFC_MAX_DATA_CTRL_LEN 1024
2877  static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2878  unsigned long i;
2879  char *str_ptr, *token;
2880  struct lpfc_vport **vports;
2881  struct Scsi_Host *v_shost;
2882  char *bucket_type_str, *base_str, *step_str;
2883  unsigned long base, step, bucket_type;
2884 
2885  if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2886  if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2887  return -EINVAL;
2888 
2889  strcpy(bucket_data, buf);
2890  str_ptr = &bucket_data[0];
2891  /* Ignore this token - this is command token */
2892  token = strsep(&str_ptr, "\t ");
2893  if (!token)
2894  return -EINVAL;
2895 
2896  bucket_type_str = strsep(&str_ptr, "\t ");
2897  if (!bucket_type_str)
2898  return -EINVAL;
2899 
2900  if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2901  bucket_type = LPFC_LINEAR_BUCKET;
2902  else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2903  bucket_type = LPFC_POWER2_BUCKET;
2904  else
2905  return -EINVAL;
2906 
2907  base_str = strsep(&str_ptr, "\t ");
2908  if (!base_str)
2909  return -EINVAL;
2910  base = simple_strtoul(base_str, NULL, 0);
2911 
2912  step_str = strsep(&str_ptr, "\t ");
2913  if (!step_str)
2914  return -EINVAL;
2915  step = simple_strtoul(step_str, NULL, 0);
2916  if (!step)
2917  return -EINVAL;
2918 
2919  /* Block the data collection for every vport */
2920  vports = lpfc_create_vport_work_array(phba);
2921  if (vports == NULL)
2922  return -ENOMEM;
2923 
2924  for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2925  v_shost = lpfc_shost_from_vport(vports[i]);
2926  spin_lock_irq(v_shost->host_lock);
2927  /* Block and reset data collection */
2928  vports[i]->stat_data_blocked = 1;
2929  if (vports[i]->stat_data_enabled)
2930  lpfc_vport_reset_stat_data(vports[i]);
2931  spin_unlock_irq(v_shost->host_lock);
2932  }
2933 
2934  /* Set the bucket attributes */
2935  phba->bucket_type = bucket_type;
2936  phba->bucket_base = base;
2937  phba->bucket_step = step;
2938 
2939  for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2940  v_shost = lpfc_shost_from_vport(vports[i]);
2941 
2942  /* Unblock data collection */
2943  spin_lock_irq(v_shost->host_lock);
2944  vports[i]->stat_data_blocked = 0;
2945  spin_unlock_irq(v_shost->host_lock);
2946  }
2947  lpfc_destroy_vport_work_array(phba, vports);
2948  return strlen(buf);
2949  }
2950 
2951  if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2952  vports = lpfc_create_vport_work_array(phba);
2953  if (vports == NULL)
2954  return -ENOMEM;
2955 
2956  for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2957  v_shost = lpfc_shost_from_vport(vports[i]);
2958  spin_lock_irq(shost->host_lock);
2959  vports[i]->stat_data_blocked = 1;
2960  lpfc_free_bucket(vport);
2961  vport->stat_data_enabled = 0;
2962  vports[i]->stat_data_blocked = 0;
2963  spin_unlock_irq(shost->host_lock);
2964  }
2965  lpfc_destroy_vport_work_array(phba, vports);
2966  phba->bucket_type = LPFC_NO_BUCKET;
2967  phba->bucket_base = 0;
2968  phba->bucket_step = 0;
2969  return strlen(buf);
2970  }
2971 
2972  if (!strncmp(buf, "start", strlen("start"))) {
2973  /* If no buckets configured return error */
2974  if (phba->bucket_type == LPFC_NO_BUCKET)
2975  return -EINVAL;
2976  spin_lock_irq(shost->host_lock);
2977  if (vport->stat_data_enabled) {
2978  spin_unlock_irq(shost->host_lock);
2979  return strlen(buf);
2980  }
2981  lpfc_alloc_bucket(vport);
2982  vport->stat_data_enabled = 1;
2983  spin_unlock_irq(shost->host_lock);
2984  return strlen(buf);
2985  }
2986 
2987  if (!strncmp(buf, "stop", strlen("stop"))) {
2988  spin_lock_irq(shost->host_lock);
2989  if (vport->stat_data_enabled == 0) {
2990  spin_unlock_irq(shost->host_lock);
2991  return strlen(buf);
2992  }
2993  lpfc_free_bucket(vport);
2994  vport->stat_data_enabled = 0;
2995  spin_unlock_irq(shost->host_lock);
2996  return strlen(buf);
2997  }
2998 
2999  if (!strncmp(buf, "reset", strlen("reset"))) {
3000  if ((phba->bucket_type == LPFC_NO_BUCKET)
3001  || !vport->stat_data_enabled)
3002  return strlen(buf);
3003  spin_lock_irq(shost->host_lock);
3004  vport->stat_data_blocked = 1;
3006  vport->stat_data_blocked = 0;
3007  spin_unlock_irq(shost->host_lock);
3008  return strlen(buf);
3009  }
3010  return -EINVAL;
3011 }
3012 
3013 
3023 static ssize_t
3024 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3025  char *buf)
3026 {
3027  struct Scsi_Host *shost = class_to_shost(dev);
3028  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3029  struct lpfc_hba *phba = vport->phba;
3030  int index = 0;
3031  int i;
3032  char *bucket_type;
3033  unsigned long bucket_value;
3034 
3035  switch (phba->bucket_type) {
3036  case LPFC_LINEAR_BUCKET:
3037  bucket_type = "linear";
3038  break;
3039  case LPFC_POWER2_BUCKET:
3040  bucket_type = "power2";
3041  break;
3042  default:
3043  bucket_type = "No Bucket";
3044  break;
3045  }
3046 
3047  sprintf(&buf[index], "Statistical Data enabled :%d, "
3048  "blocked :%d, Bucket type :%s, Bucket base :%d,"
3049  " Bucket step :%d\nLatency Ranges :",
3050  vport->stat_data_enabled, vport->stat_data_blocked,
3051  bucket_type, phba->bucket_base, phba->bucket_step);
3052  index = strlen(buf);
3053  if (phba->bucket_type != LPFC_NO_BUCKET) {
3054  for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3055  if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3056  bucket_value = phba->bucket_base +
3057  phba->bucket_step * i;
3058  else
3059  bucket_value = phba->bucket_base +
3060  (1 << i) * phba->bucket_step;
3061 
3062  if (index + 10 > PAGE_SIZE)
3063  break;
3064  sprintf(&buf[index], "%08ld ", bucket_value);
3065  index = strlen(buf);
3066  }
3067  }
3068  sprintf(&buf[index], "\n");
3069  return strlen(buf);
3070 }
3071 
3072 /*
3073  * Sysfs attribute to control the statistical data collection.
3074  */
3075 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3076  lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3077 
3078 /*
3079  * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3080  */
3081 
3082 /*
3083  * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3084  * for each target.
3085  */
3086 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3087 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3088  STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3089 
3090 
3104 static ssize_t
3105 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3106  struct bin_attribute *bin_attr,
3107  char *buf, loff_t off, size_t count)
3108 {
3109  struct device *dev = container_of(kobj, struct device,
3110  kobj);
3111  struct Scsi_Host *shost = class_to_shost(dev);
3112  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3113  struct lpfc_hba *phba = vport->phba;
3114  int i = 0, index = 0;
3115  unsigned long nport_index;
3116  struct lpfc_nodelist *ndlp = NULL;
3117  nport_index = (unsigned long)off /
3119 
3120  if (!vport->stat_data_enabled || vport->stat_data_blocked
3121  || (phba->bucket_type == LPFC_NO_BUCKET))
3122  return 0;
3123 
3124  spin_lock_irq(shost->host_lock);
3125  list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3126  if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3127  continue;
3128 
3129  if (nport_index > 0) {
3130  nport_index--;
3131  continue;
3132  }
3133 
3135  > count)
3136  break;
3137 
3138  if (!ndlp->lat_data)
3139  continue;
3140 
3141  /* Print the WWN */
3142  sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3143  ndlp->nlp_portname.u.wwn[0],
3144  ndlp->nlp_portname.u.wwn[1],
3145  ndlp->nlp_portname.u.wwn[2],
3146  ndlp->nlp_portname.u.wwn[3],
3147  ndlp->nlp_portname.u.wwn[4],
3148  ndlp->nlp_portname.u.wwn[5],
3149  ndlp->nlp_portname.u.wwn[6],
3150  ndlp->nlp_portname.u.wwn[7]);
3151 
3152  index = strlen(buf);
3153 
3154  for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3155  sprintf(&buf[index], "%010u,",
3156  ndlp->lat_data[i].cmd_count);
3157  index = strlen(buf);
3158  }
3159  sprintf(&buf[index], "\n");
3160  index = strlen(buf);
3161  }
3162  spin_unlock_irq(shost->host_lock);
3163  return index;
3164 }
3165 
3166 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3167  .attr = {
3168  .name = "lpfc_drvr_stat_data",
3169  .mode = S_IRUSR,
3170  },
3172  .read = sysfs_drvr_stat_data_read,
3173  .write = NULL,
3174 };
3175 
3176 /*
3177 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3178 # connection.
3179 # Value range is [0,16]. Default value is 0.
3180 */
3198 static ssize_t
3199 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3200  const char *buf, size_t count)
3201 {
3202  struct Scsi_Host *shost = class_to_shost(dev);
3203  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3204  struct lpfc_hba *phba = vport->phba;
3205  int val = LPFC_USER_LINK_SPEED_AUTO;
3206  int nolip = 0;
3207  const char *val_buf = buf;
3208  int err;
3209  uint32_t prev_val;
3210 
3211  if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3212  nolip = 1;
3213  val_buf = &buf[strlen("nolip ")];
3214  }
3215 
3216  if (!isdigit(val_buf[0]))
3217  return -EINVAL;
3218  if (sscanf(val_buf, "%i", &val) != 1)
3219  return -EINVAL;
3220 
3222  "3055 lpfc_link_speed changed from %d to %d %s\n",
3223  phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3224 
3225  if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3226  ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3227  ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3228  ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3229  ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3230  ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3232  "2879 lpfc_link_speed attribute cannot be set "
3233  "to %d. Speed is not supported by this port.\n",
3234  val);
3235  return -EINVAL;
3236  }
3237  if (val == LPFC_USER_LINK_SPEED_16G &&
3238  phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3240  "3112 lpfc_link_speed attribute cannot be set "
3241  "to %d. Speed is not supported in loop mode.\n",
3242  val);
3243  return -EINVAL;
3244  }
3245  if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3246  (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3247  prev_val = phba->cfg_link_speed;
3248  phba->cfg_link_speed = val;
3249  if (nolip)
3250  return strlen(buf);
3251 
3252  err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3253  if (err) {
3254  phba->cfg_link_speed = prev_val;
3255  return -EINVAL;
3256  } else
3257  return strlen(buf);
3258  }
3260  "0469 lpfc_link_speed attribute cannot be set to %d, "
3261  "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3262  return -EINVAL;
3263 }
3264 
3265 static int lpfc_link_speed = 0;
3266 module_param(lpfc_link_speed, int, S_IRUGO);
3267 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3269 
3270 
3286 static int
3287 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3288 {
3289  if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3291  "3111 lpfc_link_speed of %d cannot "
3292  "support loop mode, setting topology to default.\n",
3293  val);
3294  phba->cfg_topology = 0;
3295  }
3296  if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3297  (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3298  phba->cfg_link_speed = val;
3299  return 0;
3300  }
3302  "0405 lpfc_link_speed attribute cannot "
3303  "be set to %d, allowed values are "
3304  "["LPFC_LINK_SPEED_STRING"]\n", val);
3305  phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3306  return -EINVAL;
3307 }
3308 
3309 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3310  lpfc_link_speed_show, lpfc_link_speed_store);
3311 
3312 /*
3313 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3314 # 0 = aer disabled or not supported
3315 # 1 = aer supported and enabled (default)
3316 # Value range is [0,1]. Default value is 1.
3317 */
3318 
3346 static ssize_t
3347 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3348  const char *buf, size_t count)
3349 {
3350  struct Scsi_Host *shost = class_to_shost(dev);
3351  struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3352  struct lpfc_hba *phba = vport->phba;
3353  int val = 0, rc = -EINVAL;
3354 
3355  if (!isdigit(buf[0]))
3356  return -EINVAL;
3357  if (sscanf(buf, "%i", &val) != 1)
3358  return -EINVAL;
3359 
3360  switch (val) {
3361  case 0:
3362  if (phba->hba_flag & HBA_AER_ENABLED) {
3364  if (!rc) {
3365  spin_lock_irq(&phba->hbalock);
3366  phba->hba_flag &= ~HBA_AER_ENABLED;
3367  spin_unlock_irq(&phba->hbalock);
3368  phba->cfg_aer_support = 0;
3369  rc = strlen(buf);
3370  } else
3371  rc = -EPERM;
3372  } else {
3373  phba->cfg_aer_support = 0;
3374  rc = strlen(buf);
3375  }
3376  break;
3377  case 1:
3378  if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3380  if (!rc) {
3381  spin_lock_irq(&phba->hbalock);
3382  phba->hba_flag |= HBA_AER_ENABLED;
3383  spin_unlock_irq(&phba->hbalock);
3384  phba->cfg_aer_support = 1;
3385  rc = strlen(buf);
3386  } else
3387  rc = -EPERM;
3388  } else {
3389  phba->cfg_aer_support = 1;
3390  rc = strlen(buf);
3391  }
3392  break;
3393  default:
3394  rc = -EINVAL;
3395  break;
3396  }
3397  return rc;
3398 }
3399 
3400 static int lpfc_aer_support = 1;
3401 module_param(lpfc_aer_support, int, S_IRUGO);
3402 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3403 lpfc_param_show(aer_support)
3404 
3405 
3424 static int
3425 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3426 {
3427  if (val == 0 || val == 1) {
3428  phba->cfg_aer_support = val;
3429  return 0;
3430  }
3432  "2712 lpfc_aer_support attribute value %d out "
3433  "of range, allowed values are 0|1, setting it "
3434  "to default value of 1\n", val);
3435  /* By default, try to enable AER on a device */
3436  phba->cfg_aer_support = 1;
3437  return -EINVAL;
3438 }
3439 
3440 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3441  lpfc_aer_support_show, lpfc_aer_support_store);
3442 
3462 static ssize_t
3463 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3464  const char *buf, size_t count)
3465 {
3466  struct Scsi_Host *shost = class_to_shost(dev);
3467  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3468  struct lpfc_hba *phba = vport->phba;
3469  int val, rc = -1;
3470 
3471  if (!isdigit(buf[0]))
3472  return -EINVAL;
3473  if (sscanf(buf, "%i", &val) != 1)
3474  return -EINVAL;
3475  if (val != 1)
3476  return -EINVAL;
3477 
3478  if (phba->hba_flag & HBA_AER_ENABLED)
3480 
3481  if (rc == 0)
3482  return strlen(buf);
3483  else
3484  return -EPERM;
3485 }
3486 
3487 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3488  lpfc_aer_cleanup_state);
3489 
3529 static ssize_t
3530 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3531  const char *buf, size_t count)
3532 {
3533  struct Scsi_Host *shost = class_to_shost(dev);
3534  struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3535  struct lpfc_hba *phba = vport->phba;
3536  struct pci_dev *pdev = phba->pcidev;
3537  int val = 0, rc = -EINVAL;
3538 
3539  /* Sanity check on user data */
3540  if (!isdigit(buf[0]))
3541  return -EINVAL;
3542  if (sscanf(buf, "%i", &val) != 1)
3543  return -EINVAL;
3544  if (val < 0)
3545  return -EINVAL;
3546 
3547  /* Request disabling virtual functions */
3548  if (val == 0) {
3549  if (phba->cfg_sriov_nr_virtfn > 0) {
3550  pci_disable_sriov(pdev);
3551  phba->cfg_sriov_nr_virtfn = 0;
3552  }
3553  return strlen(buf);
3554  }
3555 
3556  /* Request enabling virtual functions */
3557  if (phba->cfg_sriov_nr_virtfn > 0) {
3559  "3018 There are %d virtual functions "
3560  "enabled on physical function.\n",
3561  phba->cfg_sriov_nr_virtfn);
3562  return -EEXIST;
3563  }
3564 
3565  if (val <= LPFC_MAX_VFN_PER_PFN)
3566  phba->cfg_sriov_nr_virtfn = val;
3567  else {
3569  "3019 Enabling %d virtual functions is not "
3570  "allowed.\n", val);
3571  return -EINVAL;
3572  }
3573 
3575  if (rc) {
3576  phba->cfg_sriov_nr_virtfn = 0;
3577  rc = -EPERM;
3578  } else
3579  rc = strlen(buf);
3580 
3581  return rc;
3582 }
3583 
3584 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3585 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3586 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3587 lpfc_param_show(sriov_nr_virtfn)
3588 
3589 
3604 static int
3605 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3606 {
3607  if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3608  phba->cfg_sriov_nr_virtfn = val;
3609  return 0;
3610  }
3611 
3613  "3017 Enabling %d virtual functions is not "
3614  "allowed.\n", val);
3615  return -EINVAL;
3616 }
3617 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3618  lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3619 
3637 static ssize_t
3638 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3639  const char *buf, size_t count)
3640 {
3641  struct Scsi_Host *shost = class_to_shost(dev);
3642  struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3643  struct lpfc_hba *phba = vport->phba;
3644  int val = 0, i;
3645 
3646  /* fcp_imax is only valid for SLI4 */
3647  if (phba->sli_rev != LPFC_SLI_REV4)
3648  return -EINVAL;
3649 
3650  /* Sanity check on user data */
3651  if (!isdigit(buf[0]))
3652  return -EINVAL;
3653  if (sscanf(buf, "%i", &val) != 1)
3654  return -EINVAL;
3655 
3656  /*
3657  * Value range for the HBA is [5000,5000000]
3658  * The value for each EQ depends on how many EQs are configured.
3659  */
3660  if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
3661  return -EINVAL;
3662 
3663  phba->cfg_fcp_imax = (uint32_t)val;
3664  for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
3665  lpfc_modify_fcp_eq_delay(phba, i);
3666 
3667  return strlen(buf);
3668 }
3669 
3670 /*
3671 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
3672 # for the HBA.
3673 #
3674 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
3675 */
3676 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
3677 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3678 MODULE_PARM_DESC(lpfc_fcp_imax,
3679  "Set the maximum number of FCP interrupts per second per HBA");
3681 
3682 
3695 static int
3696 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3697 {
3698  if (phba->sli_rev != LPFC_SLI_REV4) {
3699  phba->cfg_fcp_imax = 0;
3700  return 0;
3701  }
3702 
3703  if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
3704  phba->cfg_fcp_imax = val;
3705  return 0;
3706  }
3707 
3709  "3016 fcp_imax: %d out of range, using default\n", val);
3710  phba->cfg_fcp_imax = LPFC_DEF_IMAX;
3711 
3712  return 0;
3713 }
3714 
3715 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3716  lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3717 
3718 /*
3719 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3720 # Value range is [2,3]. Default value is 3.
3721 */
3722 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3723  "Select Fibre Channel class of service for FCP sequences");
3724 
3725 /*
3726 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3727 # is [0,1]. Default value is 0.
3728 */
3729 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3730  "Use ADISC on rediscovery to authenticate FCP devices");
3731 
3732 /*
3733 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3734 # depth. Default value is 0. When the value of this parameter is zero the
3735 # SCSI command completion time is not used for controlling I/O queue depth. When
3736 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3737 # to limit the I/O completion time to the parameter value.
3738 # The value is set in milliseconds.
3739 */
3740 static int lpfc_max_scsicmpl_time;
3741 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3742 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3743  "Use command completion time to control queue depth");
3744 lpfc_vport_param_show(max_scsicmpl_time);
3745 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3746 static int
3747 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3748 {
3749  struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3750  struct lpfc_nodelist *ndlp, *next_ndlp;
3751 
3752  if (val == vport->cfg_max_scsicmpl_time)
3753  return 0;
3754  if ((val < 0) || (val > 60000))
3755  return -EINVAL;
3756  vport->cfg_max_scsicmpl_time = val;
3757 
3758  spin_lock_irq(shost->host_lock);
3759  list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3760  if (!NLP_CHK_NODE_ACT(ndlp))
3761  continue;
3762  if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3763  continue;
3764  ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3765  }
3766  spin_unlock_irq(shost->host_lock);
3767  return 0;
3768 }
3769 lpfc_vport_param_store(max_scsicmpl_time);
3770 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3771  lpfc_max_scsicmpl_time_show,
3772  lpfc_max_scsicmpl_time_store);
3773 
3774 /*
3775 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3776 # range is [0,1]. Default value is 0.
3777 */
3778 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3779 
3780 /*
3781 # lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
3782 # range is [0,1]. Default value is 0.
3783 # For [0], FCP commands are issued to Work Queues ina round robin fashion.
3784 # For [1], FCP commands are issued to a Work Queue associated with the
3785 # current CPU.
3786 */
3787 LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algrithmn for "
3788  "issuing commands [0] - Round Robin, [1] - Current CPU");
3789 
3790 /*
3791 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3792 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3793 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3794 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3795 # cr_delay is set to 0.
3796 */
3797 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3798  "interrupt response is generated");
3799 
3800 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3801  "interrupt response is generated");
3802 
3803 /*
3804 # lpfc_multi_ring_support: Determines how many rings to spread available
3805 # cmd/rsp IOCB entries across.
3806 # Value range is [1,2]. Default value is 1.
3807 */
3808 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3809  "SLI rings to spread IOCB entries across");
3810 
3811 /*
3812 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3813 # identifies what rctl value to configure the additional ring for.
3814 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3815 */
3816 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3817  255, "Identifies RCTL for additional ring configuration");
3818 
3819 /*
3820 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3821 # identifies what type value to configure the additional ring for.
3822 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3823 */
3824 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3825  255, "Identifies TYPE for additional ring configuration");
3826 
3827 /*
3828 # lpfc_fdmi_on: controls FDMI support.
3829 # 0 = no FDMI support
3830 # 1 = support FDMI without attribute of hostname
3831 # 2 = support FDMI with attribute of hostname
3832 # Value range [0,2]. Default value is 0.
3833 */
3834 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3835 
3836 /*
3837 # Specifies the maximum number of ELS cmds we can have outstanding (for
3838 # discovery). Value range is [1,64]. Default value = 32.
3839 */
3840 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3841  "during discovery");
3842 
3843 /*
3844 # lpfc_max_luns: maximum allowed LUN.
3845 # Value range is [0,65535]. Default value is 255.
3846 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3847 */
3848 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3849 
3850 /*
3851 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3852 # Value range is [1,255], default value is 10.
3853 */
3854 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3855  "Milliseconds driver will wait between polling FCP ring");
3856 
3857 /*
3858 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3859 # support this feature
3860 # 0 = MSI disabled
3861 # 1 = MSI enabled
3862 # 2 = MSI-X enabled (default)
3863 # Value range is [0,2]. Default value is 2.
3864 */
3865 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3866  "MSI-X (2), if possible");
3867 
3868 /*
3869 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3870 # This parameter is ignored and will eventually be depricated
3871 #
3872 # Value range is [1,7]. Default value is 4.
3873 */
3876  "Set the number of fast-path FCP work queues, if possible");
3877 
3878 /*
3879 # lpfc_fcp_eq_count: Set the number of FCP EQ/CQ/WQ IO channels
3880 #
3881 # Value range is [1,7]. Default value is 4.
3882 */
3885  "Set the number of fast-path FCP event queues, if possible");
3886 
3887 /*
3888 # lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
3889 #
3890 # Value range is [1,7]. Default value is 4.
3891 */
3894  "Set the number of FCP I/O channels");
3895 
3896 /*
3897 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3898 # 0 = HBA resets disabled
3899 # 1 = HBA resets enabled (default)
3900 # Value range is [0,1]. Default value is 1.
3901 */
3902 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3903 
3904 /*
3905 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3906 # 0 = HBA Heartbeat disabled
3907 # 1 = HBA Heartbeat enabled (default)
3908 # Value range is [0,1]. Default value is 1.
3909 */
3910 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3911 
3912 /*
3913 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3914 # 0 = BlockGuard disabled (default)
3915 # 1 = BlockGuard enabled
3916 # Value range is [0,1]. Default value is 0.
3917 */
3918 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3919 
3920 /*
3921 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
3922 # 0 = disabled (default)
3923 # 1 = enabled
3924 # Value range is [0,1]. Default value is 0.
3925 */
3927 
3928 module_param(lpfc_fcp_look_ahead, uint, S_IRUGO);
3929 MODULE_PARM_DESC(lpfc_fcp_look_ahead, "Look ahead for completions");
3930 
3931 /*
3932 # lpfc_prot_mask: i
3933 # - Bit mask of host protection capabilities used to register with the
3934 # SCSI mid-layer
3935 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3936 # - Allows you to ultimately specify which profiles to use
3937 # - Default will result in registering capabilities for all profiles.
3938 # - SHOST_DIF_TYPE1_PROTECTION 1
3939 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
3940 # - SHOST_DIX_TYPE0_PROTECTION 8
3941 # HBA supports DIX Type 0: Host to HBA protection only
3942 # - SHOST_DIX_TYPE1_PROTECTION 16
3943 # HBA supports DIX Type 1: Host to HBA Type 1 protection
3944 #
3945 */
3949 
3950 module_param(lpfc_prot_mask, uint, S_IRUGO);
3951 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3952 
3953 /*
3954 # lpfc_prot_guard: i
3955 # - Bit mask of protection guard types to register with the SCSI mid-layer
3956 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
3957 # - Allows you to ultimately specify which profiles to use
3958 # - Default will result in registering capabilities for all guard types
3959 #
3960 */
3962 module_param(lpfc_prot_guard, byte, S_IRUGO);
3963 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3964 
3965 /*
3966  * Delay initial NPort discovery when Clean Address bit is cleared in
3967  * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3968  * This parameter can have value 0 or 1.
3969  * When this parameter is set to 0, no delay is added to the initial
3970  * discovery.
3971  * When this parameter is set to non-zero value, initial Nport discovery is
3972  * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3973  * accept and FCID/Fabric name/Fabric portname is changed.
3974  * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3975  * when Clean Address bit is cleared in FLOGI/FDISC
3976  * accept and FCID/Fabric name/Fabric portname is changed.
3977  * Default value is 0.
3978  */
3980 module_param(lpfc_delay_discovery, int, S_IRUGO);
3981 MODULE_PARM_DESC(lpfc_delay_discovery,
3982  "Delay NPort discovery when Clean Address bit is cleared. "
3983  "Allowed values: 0,1.");
3984 
3985 /*
3986  * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3987  * This value can be set to values between 64 and 256. The default value is
3988  * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3989  * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3990  */
3992  LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3993 
3994 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3996  "Max Protection Scatter Gather Segment Count");
3997 
3999  &dev_attr_bg_info,
4000  &dev_attr_bg_guard_err,
4001  &dev_attr_bg_apptag_err,
4002  &dev_attr_bg_reftag_err,
4003  &dev_attr_info,
4004  &dev_attr_serialnum,
4005  &dev_attr_modeldesc,
4006  &dev_attr_modelname,
4007  &dev_attr_programtype,
4008  &dev_attr_portnum,
4009  &dev_attr_fwrev,
4010  &dev_attr_hdw,
4011  &dev_attr_option_rom_version,
4012  &dev_attr_link_state,
4013  &dev_attr_num_discovered_ports,
4014  &dev_attr_menlo_mgmt_mode,
4015  &dev_attr_lpfc_drvr_version,
4016  &dev_attr_lpfc_enable_fip,
4017  &dev_attr_lpfc_temp_sensor,
4018  &dev_attr_lpfc_log_verbose,
4019  &dev_attr_lpfc_lun_queue_depth,
4020  &dev_attr_lpfc_tgt_queue_depth,
4021  &dev_attr_lpfc_hba_queue_depth,
4022  &dev_attr_lpfc_peer_port_login,
4023  &dev_attr_lpfc_nodev_tmo,
4024  &dev_attr_lpfc_devloss_tmo,
4025  &dev_attr_lpfc_fcp_class,
4026  &dev_attr_lpfc_use_adisc,
4027  &dev_attr_lpfc_ack0,
4028  &dev_attr_lpfc_topology,
4029  &dev_attr_lpfc_scan_down,
4030  &dev_attr_lpfc_link_speed,
4031  &dev_attr_lpfc_fcp_io_sched,
4032  &dev_attr_lpfc_cr_delay,
4033  &dev_attr_lpfc_cr_count,
4034  &dev_attr_lpfc_multi_ring_support,
4035  &dev_attr_lpfc_multi_ring_rctl,
4036  &dev_attr_lpfc_multi_ring_type,
4037  &dev_attr_lpfc_fdmi_on,
4038  &dev_attr_lpfc_max_luns,
4039  &dev_attr_lpfc_enable_npiv,
4040  &dev_attr_lpfc_fcf_failover_policy,
4041  &dev_attr_lpfc_enable_rrq,
4042  &dev_attr_nport_evt_cnt,
4043  &dev_attr_board_mode,
4044  &dev_attr_max_vpi,
4045  &dev_attr_used_vpi,
4046  &dev_attr_max_rpi,
4047  &dev_attr_used_rpi,
4048  &dev_attr_max_xri,
4049  &dev_attr_used_xri,
4050  &dev_attr_npiv_info,
4051  &dev_attr_issue_reset,
4052  &dev_attr_lpfc_poll,
4053  &dev_attr_lpfc_poll_tmo,
4054  &dev_attr_lpfc_use_msi,
4055  &dev_attr_lpfc_fcp_imax,
4056  &dev_attr_lpfc_fcp_wq_count,
4057  &dev_attr_lpfc_fcp_eq_count,
4058  &dev_attr_lpfc_fcp_io_channel,
4059  &dev_attr_lpfc_enable_bg,
4060  &dev_attr_lpfc_soft_wwnn,
4061  &dev_attr_lpfc_soft_wwpn,
4062  &dev_attr_lpfc_soft_wwn_enable,
4063  &dev_attr_lpfc_enable_hba_reset,
4064  &dev_attr_lpfc_enable_hba_heartbeat,
4065  &dev_attr_lpfc_sg_seg_cnt,
4066  &dev_attr_lpfc_max_scsicmpl_time,
4067  &dev_attr_lpfc_stat_data_ctrl,
4068  &dev_attr_lpfc_prot_sg_seg_cnt,
4069  &dev_attr_lpfc_aer_support,
4070  &dev_attr_lpfc_aer_state_cleanup,
4071  &dev_attr_lpfc_sriov_nr_virtfn,
4072  &dev_attr_lpfc_suppress_link_up,
4073  &dev_attr_lpfc_iocb_cnt,
4074  &dev_attr_iocb_hw,
4075  &dev_attr_txq_hw,
4076  &dev_attr_txcmplq_hw,
4077  &dev_attr_lpfc_fips_level,
4078  &dev_attr_lpfc_fips_rev,
4079  &dev_attr_lpfc_dss,
4080  &dev_attr_lpfc_sriov_hw_max_virtfn,
4081  &dev_attr_protocol,
4082  NULL,
4083 };
4084 
4086  &dev_attr_info,
4087  &dev_attr_link_state,
4088  &dev_attr_num_discovered_ports,
4089  &dev_attr_lpfc_drvr_version,
4090  &dev_attr_lpfc_log_verbose,
4091  &dev_attr_lpfc_lun_queue_depth,
4092  &dev_attr_lpfc_tgt_queue_depth,
4093  &dev_attr_lpfc_nodev_tmo,
4094  &dev_attr_lpfc_devloss_tmo,
4095  &dev_attr_lpfc_hba_queue_depth,
4096  &dev_attr_lpfc_peer_port_login,
4097  &dev_attr_lpfc_restrict_login,
4098  &dev_attr_lpfc_fcp_class,
4099  &dev_attr_lpfc_use_adisc,
4100  &dev_attr_lpfc_fdmi_on,
4101  &dev_attr_lpfc_max_luns,
4102  &dev_attr_nport_evt_cnt,
4103  &dev_attr_npiv_info,
4104  &dev_attr_lpfc_enable_da_id,
4105  &dev_attr_lpfc_max_scsicmpl_time,
4106  &dev_attr_lpfc_stat_data_ctrl,
4107  &dev_attr_lpfc_static_vport,
4108  &dev_attr_lpfc_fips_level,
4109  &dev_attr_lpfc_fips_rev,
4110  NULL,
4111 };
4112 
4132 static ssize_t
4133 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4134  struct bin_attribute *bin_attr,
4135  char *buf, loff_t off, size_t count)
4136 {
4137  size_t buf_off;
4138  struct device *dev = container_of(kobj, struct device, kobj);
4139  struct Scsi_Host *shost = class_to_shost(dev);
4140  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4141  struct lpfc_hba *phba = vport->phba;
4142 
4143  if (phba->sli_rev >= LPFC_SLI_REV4)
4144  return -EPERM;
4145 
4146  if ((off + count) > FF_REG_AREA_SIZE)
4147  return -ERANGE;
4148 
4149  if (count <= LPFC_REG_WRITE_KEY_SIZE)
4150  return 0;
4151 
4152  if (off % 4 || count % 4 || (unsigned long)buf % 4)
4153  return -EINVAL;
4154 
4155  /* This is to protect HBA registers from accidental writes. */
4157  return -EINVAL;
4158 
4159  if (!(vport->fc_flag & FC_OFFLINE_MODE))
4160  return -EPERM;
4161 
4162  spin_lock_irq(&phba->hbalock);
4163  for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4164  buf_off += sizeof(uint32_t))
4165  writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
4166  phba->ctrl_regs_memmap_p + off + buf_off);
4167 
4168  spin_unlock_irq(&phba->hbalock);
4169 
4170  return count;
4171 }
4172 
4191 static ssize_t
4192 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4193  struct bin_attribute *bin_attr,
4194  char *buf, loff_t off, size_t count)
4195 {
4196  size_t buf_off;
4197  uint32_t * tmp_ptr;
4198  struct device *dev = container_of(kobj, struct device, kobj);
4199  struct Scsi_Host *shost = class_to_shost(dev);
4200  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4201  struct lpfc_hba *phba = vport->phba;
4202 
4203  if (phba->sli_rev >= LPFC_SLI_REV4)
4204  return -EPERM;
4205 
4206  if (off > FF_REG_AREA_SIZE)
4207  return -ERANGE;
4208 
4209  if ((off + count) > FF_REG_AREA_SIZE)
4210  count = FF_REG_AREA_SIZE - off;
4211 
4212  if (count == 0) return 0;
4213 
4214  if (off % 4 || count % 4 || (unsigned long)buf % 4)
4215  return -EINVAL;
4216 
4217  spin_lock_irq(&phba->hbalock);
4218 
4219  for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4220  tmp_ptr = (uint32_t *)(buf + buf_off);
4221  *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4222  }
4223 
4224  spin_unlock_irq(&phba->hbalock);
4225 
4226  return count;
4227 }
4228 
4229 static struct bin_attribute sysfs_ctlreg_attr = {
4230  .attr = {
4231  .name = "ctlreg",
4232  .mode = S_IRUSR | S_IWUSR,
4233  },
4234  .size = 256,
4235  .read = sysfs_ctlreg_read,
4236  .write = sysfs_ctlreg_write,
4237 };
4238 
4255 static ssize_t
4256 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4257  struct bin_attribute *bin_attr,
4258  char *buf, loff_t off, size_t count)
4259 {
4260  return -EPERM;
4261 }
4262 
4279 static ssize_t
4280 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4281  struct bin_attribute *bin_attr,
4282  char *buf, loff_t off, size_t count)
4283 {
4284  return -EPERM;
4285 }
4286 
4287 static struct bin_attribute sysfs_mbox_attr = {
4288  .attr = {
4289  .name = "mbox",
4290  .mode = S_IRUSR | S_IWUSR,
4291  },
4292  .size = MAILBOX_SYSFS_MAX,
4293  .read = sysfs_mbox_read,
4294  .write = sysfs_mbox_write,
4295 };
4296 
4305 int
4307 {
4308  struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4309  int error;
4310 
4311  error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4312  &sysfs_drvr_stat_data_attr);
4313 
4314  /* Virtual ports do not need ctrl_reg and mbox */
4315  if (error || vport->port_type == LPFC_NPIV_PORT)
4316  goto out;
4317 
4318  error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4319  &sysfs_ctlreg_attr);
4320  if (error)
4321  goto out_remove_stat_attr;
4322 
4323  error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4324  &sysfs_mbox_attr);
4325  if (error)
4326  goto out_remove_ctlreg_attr;
4327 
4328  return 0;
4329 out_remove_ctlreg_attr:
4330  sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4331 out_remove_stat_attr:
4332  sysfs_remove_bin_file(&shost->shost_dev.kobj,
4333  &sysfs_drvr_stat_data_attr);
4334 out:
4335  return error;
4336 }
4337 
4342 void
4344 {
4345  struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4346  sysfs_remove_bin_file(&shost->shost_dev.kobj,
4347  &sysfs_drvr_stat_data_attr);
4348  /* Virtual ports do not need ctrl_reg and mbox */
4349  if (vport->port_type == LPFC_NPIV_PORT)
4350  return;
4351  sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4352  sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4353 }
4354 
4355 
4356 /*
4357  * Dynamic FC Host Attributes Support
4358  */
4359 
4364 static void
4365 lpfc_get_host_port_id(struct Scsi_Host *shost)
4366 {
4367  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4368 
4369  /* note: fc_myDID already in cpu endianness */
4370  fc_host_port_id(shost) = vport->fc_myDID;
4371 }
4372 
4377 static void
4378 lpfc_get_host_port_type(struct Scsi_Host *shost)
4379 {
4380  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4381  struct lpfc_hba *phba = vport->phba;
4382 
4383  spin_lock_irq(shost->host_lock);
4384 
4385  if (vport->port_type == LPFC_NPIV_PORT) {
4387  } else if (lpfc_is_link_up(phba)) {
4388  if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4389  if (vport->fc_flag & FC_PUBLIC_LOOP)
4391  else
4393  } else {
4394  if (vport->fc_flag & FC_FABRIC)
4396  else
4398  }
4399  } else
4401 
4402  spin_unlock_irq(shost->host_lock);
4403 }
4404 
4409 static void
4410 lpfc_get_host_port_state(struct Scsi_Host *shost)
4411 {
4412  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4413  struct lpfc_hba *phba = vport->phba;
4414 
4415  spin_lock_irq(shost->host_lock);
4416 
4417  if (vport->fc_flag & FC_OFFLINE_MODE)
4419  else {
4420  switch (phba->link_state) {
4421  case LPFC_LINK_UNKNOWN:
4422  case LPFC_LINK_DOWN:
4424  break;
4425  case LPFC_LINK_UP:
4426  case LPFC_CLEAR_LA:
4427  case LPFC_HBA_READY:
4428  /* Links up, reports port state accordingly */
4429  if (vport->port_state < LPFC_VPORT_READY)
4430  fc_host_port_state(shost) =
4432  else
4433  fc_host_port_state(shost) =
4435  break;
4436  case LPFC_HBA_ERROR:
4438  break;
4439  default:
4441  break;
4442  }
4443  }
4444 
4445  spin_unlock_irq(shost->host_lock);
4446 }
4447 
4452 static void
4453 lpfc_get_host_speed(struct Scsi_Host *shost)
4454 {
4455  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4456  struct lpfc_hba *phba = vport->phba;
4457 
4458  spin_lock_irq(shost->host_lock);
4459 
4460  if (lpfc_is_link_up(phba)) {
4461  switch(phba->fc_linkspeed) {
4462  case LPFC_LINK_SPEED_1GHZ:
4464  break;
4465  case LPFC_LINK_SPEED_2GHZ:
4467  break;
4468  case LPFC_LINK_SPEED_4GHZ:
4470  break;
4471  case LPFC_LINK_SPEED_8GHZ:
4473  break;
4474  case LPFC_LINK_SPEED_10GHZ:
4476  break;
4477  case LPFC_LINK_SPEED_16GHZ:
4479  break;
4480  default:
4482  break;
4483  }
4484  } else
4486 
4487  spin_unlock_irq(shost->host_lock);
4488 }
4489 
4494 static void
4495 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4496 {
4497  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4498  struct lpfc_hba *phba = vport->phba;
4499  u64 node_name;
4500 
4501  spin_lock_irq(shost->host_lock);
4502 
4503  if ((vport->port_state > LPFC_FLOGI) &&
4504  ((vport->fc_flag & FC_FABRIC) ||
4505  ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4506  (vport->fc_flag & FC_PUBLIC_LOOP))))
4507  node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4508  else
4509  /* fabric is local port if there is no F/FL_Port */
4510  node_name = 0;
4511 
4512  spin_unlock_irq(shost->host_lock);
4513 
4514  fc_host_fabric_name(shost) = node_name;
4515 }
4516 
4529 static struct fc_host_statistics *
4530 lpfc_get_stats(struct Scsi_Host *shost)
4531 {
4532  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4533  struct lpfc_hba *phba = vport->phba;
4534  struct lpfc_sli *psli = &phba->sli;
4535  struct fc_host_statistics *hs = &phba->link_stats;
4536  struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4537  LPFC_MBOXQ_t *pmboxq;
4538  MAILBOX_t *pmb;
4539  unsigned long seconds;
4540  int rc = 0;
4541 
4542  /*
4543  * prevent udev from issuing mailbox commands until the port is
4544  * configured.
4545  */
4546  if (phba->link_state < LPFC_LINK_DOWN ||
4547  !phba->mbox_mem_pool ||
4548  (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4549  return NULL;
4550 
4551  if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4552  return NULL;
4553 
4554  pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4555  if (!pmboxq)
4556  return NULL;
4557  memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4558 
4559  pmb = &pmboxq->u.mb;
4560  pmb->mbxCommand = MBX_READ_STATUS;
4561  pmb->mbxOwner = OWN_HOST;
4562  pmboxq->context1 = NULL;
4563  pmboxq->vport = vport;
4564 
4565  if (vport->fc_flag & FC_OFFLINE_MODE)
4566  rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4567  else
4568  rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4569 
4570  if (rc != MBX_SUCCESS) {
4571  if (rc != MBX_TIMEOUT)
4572  mempool_free(pmboxq, phba->mbox_mem_pool);
4573  return NULL;
4574  }
4575 
4576  memset(hs, 0, sizeof (struct fc_host_statistics));
4577 
4578  hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4579  /*
4580  * The MBX_READ_STATUS returns tx_k_bytes which has to
4581  * converted to words
4582  */
4583  hs->tx_words = (uint64_t)
4585  * (uint64_t)256);
4586  hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4587  hs->rx_words = (uint64_t)
4589  * (uint64_t)256);
4590 
4591  memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4593  pmb->mbxOwner = OWN_HOST;
4594  pmboxq->context1 = NULL;
4595  pmboxq->vport = vport;
4596 
4597  if (vport->fc_flag & FC_OFFLINE_MODE)
4598  rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4599  else
4600  rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4601 
4602  if (rc != MBX_SUCCESS) {
4603  if (rc != MBX_TIMEOUT)
4604  mempool_free(pmboxq, phba->mbox_mem_pool);
4605  return NULL;
4606  }
4607 
4608  hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4609  hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4610  hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4611  hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4612  hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4613  hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4614  hs->error_frames = pmb->un.varRdLnk.crcCnt;
4615 
4616  hs->link_failure_count -= lso->link_failure_count;
4617  hs->loss_of_sync_count -= lso->loss_of_sync_count;
4618  hs->loss_of_signal_count -= lso->loss_of_signal_count;
4619  hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4620  hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4621  hs->invalid_crc_count -= lso->invalid_crc_count;
4622  hs->error_frames -= lso->error_frames;
4623 
4624  if (phba->hba_flag & HBA_FCOE_MODE) {
4625  hs->lip_count = -1;
4626  hs->nos_count = (phba->link_events >> 1);
4627  hs->nos_count -= lso->link_events;
4628  } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4629  hs->lip_count = (phba->fc_eventTag >> 1);
4630  hs->lip_count -= lso->link_events;
4631  hs->nos_count = -1;
4632  } else {
4633  hs->lip_count = -1;
4634  hs->nos_count = (phba->fc_eventTag >> 1);
4635  hs->nos_count -= lso->link_events;
4636  }
4637 
4638  hs->dumped_frames = -1;
4639 
4640  seconds = get_seconds();
4641  if (seconds < psli->stats_start)
4642  hs->seconds_since_last_reset = seconds +
4643  ((unsigned long)-1 - psli->stats_start);
4644  else
4645  hs->seconds_since_last_reset = seconds - psli->stats_start;
4646 
4647  mempool_free(pmboxq, phba->mbox_mem_pool);
4648 
4649  return hs;
4650 }
4651 
4656 static void
4657 lpfc_reset_stats(struct Scsi_Host *shost)
4658 {
4659  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4660  struct lpfc_hba *phba = vport->phba;
4661  struct lpfc_sli *psli = &phba->sli;
4662  struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4663  LPFC_MBOXQ_t *pmboxq;
4664  MAILBOX_t *pmb;
4665  int rc = 0;
4666 
4667  if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4668  return;
4669 
4670  pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4671  if (!pmboxq)
4672  return;
4673  memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4674 
4675  pmb = &pmboxq->u.mb;
4676  pmb->mbxCommand = MBX_READ_STATUS;
4677  pmb->mbxOwner = OWN_HOST;
4678  pmb->un.varWords[0] = 0x1; /* reset request */
4679  pmboxq->context1 = NULL;
4680  pmboxq->vport = vport;
4681 
4682  if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4683  (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4684  rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4685  else
4686  rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4687 
4688  if (rc != MBX_SUCCESS) {
4689  if (rc != MBX_TIMEOUT)
4690  mempool_free(pmboxq, phba->mbox_mem_pool);
4691  return;
4692  }
4693 
4694  memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4696  pmb->mbxOwner = OWN_HOST;
4697  pmboxq->context1 = NULL;
4698  pmboxq->vport = vport;
4699 
4700  if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4701  (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4702  rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4703  else
4704  rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4705 
4706  if (rc != MBX_SUCCESS) {
4707  if (rc != MBX_TIMEOUT)
4708  mempool_free( pmboxq, phba->mbox_mem_pool);
4709  return;
4710  }
4711 
4712  lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4713  lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4714  lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4715  lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4716  lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4717  lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4718  lso->error_frames = pmb->un.varRdLnk.crcCnt;
4719  if (phba->hba_flag & HBA_FCOE_MODE)
4720  lso->link_events = (phba->link_events >> 1);
4721  else
4722  lso->link_events = (phba->fc_eventTag >> 1);
4723 
4724  psli->stats_start = get_seconds();
4725 
4726  mempool_free(pmboxq, phba->mbox_mem_pool);
4727 
4728  return;
4729 }
4730 
4731 /*
4732  * The LPFC driver treats linkdown handling as target loss events so there
4733  * are no sysfs handlers for link_down_tmo.
4734  */
4735 
4744 static struct lpfc_nodelist *
4745 lpfc_get_node_by_target(struct scsi_target *starget)
4746 {
4747  struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4748  struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4749  struct lpfc_nodelist *ndlp;
4750 
4751  spin_lock_irq(shost->host_lock);
4752  /* Search for this, mapped, target ID */
4753  list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4754  if (NLP_CHK_NODE_ACT(ndlp) &&
4755  ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4756  starget->id == ndlp->nlp_sid) {
4757  spin_unlock_irq(shost->host_lock);
4758  return ndlp;
4759  }
4760  }
4761  spin_unlock_irq(shost->host_lock);
4762  return NULL;
4763 }
4764 
4769 static void
4770 lpfc_get_starget_port_id(struct scsi_target *starget)
4771 {
4772  struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4773 
4774  fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4775 }
4776 
4783 static void
4784 lpfc_get_starget_node_name(struct scsi_target *starget)
4785 {
4786  struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4787 
4788  fc_starget_node_name(starget) =
4789  ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4790 }
4791 
4798 static void
4799 lpfc_get_starget_port_name(struct scsi_target *starget)
4800 {
4801  struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4802 
4803  fc_starget_port_name(starget) =
4804  ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4805 }
4806 
4816 static void
4817 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4818 {
4819  if (timeout)
4820  rport->dev_loss_tmo = timeout;
4821  else
4822  rport->dev_loss_tmo = 1;
4823 }
4824 
4837 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4838 static ssize_t \
4839 lpfc_show_rport_##field (struct device *dev, \
4840  struct device_attribute *attr, \
4841  char *buf) \
4842 { \
4843  struct fc_rport *rport = transport_class_to_rport(dev); \
4844  struct lpfc_rport_data *rdata = rport->hostdata; \
4845  return snprintf(buf, sz, format_string, \
4846  (rdata->target) ? cast rdata->target->field : 0); \
4847 }
4848 
4849 #define lpfc_rport_rd_attr(field, format_string, sz) \
4850  lpfc_rport_show_function(field, format_string, sz, ) \
4851 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4852 
4862 static void
4863 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4864 {
4865  struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4866 
4867  if (vport->port_state == LPFC_VPORT_READY)
4868  lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4869 }
4870 
4880 static void
4881 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4882 {
4883  phba->cfg_log_verbose = verbose;
4884 }
4885 
4887  /* fixed attributes the driver supports */
4888  .show_host_node_name = 1,
4889  .show_host_port_name = 1,
4890  .show_host_supported_classes = 1,
4891  .show_host_supported_fc4s = 1,
4892  .show_host_supported_speeds = 1,
4893  .show_host_maxframe_size = 1,
4894  .show_host_symbolic_name = 1,
4895 
4896  /* dynamic attributes the driver supports */
4897  .get_host_port_id = lpfc_get_host_port_id,
4898  .show_host_port_id = 1,
4899 
4900  .get_host_port_type = lpfc_get_host_port_type,
4901  .show_host_port_type = 1,
4902 
4903  .get_host_port_state = lpfc_get_host_port_state,
4904  .show_host_port_state = 1,
4905 
4906  /* active_fc4s is shown but doesn't change (thus no get function) */
4907  .show_host_active_fc4s = 1,
4908 
4909  .get_host_speed = lpfc_get_host_speed,
4910  .show_host_speed = 1,
4911 
4912  .get_host_fabric_name = lpfc_get_host_fabric_name,
4913  .show_host_fabric_name = 1,
4914 
4915  /*
4916  * The LPFC driver treats linkdown handling as target loss events
4917  * so there are no sysfs handlers for link_down_tmo.
4918  */
4919 
4920  .get_fc_host_stats = lpfc_get_stats,
4921  .reset_fc_host_stats = lpfc_reset_stats,
4922 
4923  .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4924  .show_rport_maxframe_size = 1,
4925  .show_rport_supported_classes = 1,
4926 
4927  .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4928  .show_rport_dev_loss_tmo = 1,
4929 
4930  .get_starget_port_id = lpfc_get_starget_port_id,
4931  .show_starget_port_id = 1,
4932 
4933  .get_starget_node_name = lpfc_get_starget_node_name,
4934  .show_starget_node_name = 1,
4935 
4936  .get_starget_port_name = lpfc_get_starget_port_name,
4937  .show_starget_port_name = 1,
4938 
4939  .issue_fc_host_lip = lpfc_issue_lip,
4940  .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4941  .terminate_rport_io = lpfc_terminate_rport_io,
4942 
4943  .dd_fcvport_size = sizeof(struct lpfc_vport *),
4944 
4945  .vport_disable = lpfc_vport_disable,
4946 
4947  .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4948 
4949  .bsg_request = lpfc_bsg_request,
4950  .bsg_timeout = lpfc_bsg_timeout,
4951 };
4952 
4954  /* fixed attributes the driver supports */
4955  .show_host_node_name = 1,
4956  .show_host_port_name = 1,
4957  .show_host_supported_classes = 1,
4958  .show_host_supported_fc4s = 1,
4959  .show_host_supported_speeds = 1,
4960  .show_host_maxframe_size = 1,
4961  .show_host_symbolic_name = 1,
4962 
4963  /* dynamic attributes the driver supports */
4964  .get_host_port_id = lpfc_get_host_port_id,
4965  .show_host_port_id = 1,
4966 
4967  .get_host_port_type = lpfc_get_host_port_type,
4968  .show_host_port_type = 1,
4969 
4970  .get_host_port_state = lpfc_get_host_port_state,
4971  .show_host_port_state = 1,
4972 
4973  /* active_fc4s is shown but doesn't change (thus no get function) */
4974  .show_host_active_fc4s = 1,
4975 
4976  .get_host_speed = lpfc_get_host_speed,
4977  .show_host_speed = 1,
4978 
4979  .get_host_fabric_name = lpfc_get_host_fabric_name,
4980  .show_host_fabric_name = 1,
4981 
4982  /*
4983  * The LPFC driver treats linkdown handling as target loss events
4984  * so there are no sysfs handlers for link_down_tmo.
4985  */
4986 
4987  .get_fc_host_stats = lpfc_get_stats,
4988  .reset_fc_host_stats = lpfc_reset_stats,
4989 
4990  .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4991  .show_rport_maxframe_size = 1,
4992  .show_rport_supported_classes = 1,
4993 
4994  .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4995  .show_rport_dev_loss_tmo = 1,
4996 
4997  .get_starget_port_id = lpfc_get_starget_port_id,
4998  .show_starget_port_id = 1,
4999 
5000  .get_starget_node_name = lpfc_get_starget_node_name,
5001  .show_starget_node_name = 1,
5002 
5003  .get_starget_port_name = lpfc_get_starget_port_name,
5004  .show_starget_port_name = 1,
5005 
5006  .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5007  .terminate_rport_io = lpfc_terminate_rport_io,
5008 
5009  .vport_disable = lpfc_vport_disable,
5010 
5011  .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5012 };
5013 
5018 void
5020 {
5021  lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
5022  lpfc_cr_delay_init(phba, lpfc_cr_delay);
5023  lpfc_cr_count_init(phba, lpfc_cr_count);
5024  lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5025  lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5026  lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5027  lpfc_ack0_init(phba, lpfc_ack0);
5028  lpfc_topology_init(phba, lpfc_topology);
5029  lpfc_link_speed_init(phba, lpfc_link_speed);
5030  lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5031  lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5032  lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5033  lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5034  lpfc_use_msi_init(phba, lpfc_use_msi);
5035  lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5036  lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5037  lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5038  lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
5039  lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5040  lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5041  lpfc_enable_bg_init(phba, lpfc_enable_bg);
5042  if (phba->sli_rev == LPFC_SLI_REV4)
5043  phba->cfg_poll = 0;
5044  else
5045  phba->cfg_poll = lpfc_poll;
5046  phba->cfg_soft_wwnn = 0L;
5047  phba->cfg_soft_wwpn = 0L;
5048  lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5049  lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5050  lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5051  lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5052  lpfc_aer_support_init(phba, lpfc_aer_support);
5053  lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5054  lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5055  lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5056  phba->cfg_enable_dss = 1;
5057  return;
5058 }
5059 
5064 void
5066 {
5067  lpfc_log_verbose_init(vport, lpfc_log_verbose);
5068  lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5069  lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5070  lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5071  lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5072  lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5073  lpfc_restrict_login_init(vport, lpfc_restrict_login);
5074  lpfc_fcp_class_init(vport, lpfc_fcp_class);
5075  lpfc_use_adisc_init(vport, lpfc_use_adisc);
5076  lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5077  lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5078  lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5079  lpfc_max_luns_init(vport, lpfc_max_luns);
5080  lpfc_scan_down_init(vport, lpfc_scan_down);
5081  lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
5082  return;
5083 }