root/drivers/scsi/lpfc/lpfc_attr.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. lpfc_jedec_to_ascii
  2. lpfc_drvr_version_show
  3. lpfc_enable_fip_show
  4. lpfc_nvme_info_show
  5. lpfc_scsi_stat_show
  6. lpfc_bg_info_show
  7. lpfc_bg_guard_err_show
  8. lpfc_bg_apptag_err_show
  9. lpfc_bg_reftag_err_show
  10. lpfc_info_show
  11. lpfc_serialnum_show
  12. lpfc_temp_sensor_show
  13. lpfc_modeldesc_show
  14. lpfc_modelname_show
  15. lpfc_programtype_show
  16. lpfc_mlomgmt_show
  17. lpfc_vportnum_show
  18. lpfc_fwrev_show
  19. lpfc_hdw_show
  20. lpfc_option_rom_version_show
  21. lpfc_link_state_show
  22. lpfc_sli4_protocol_show
  23. lpfc_oas_supported_show
  24. lpfc_link_state_store
  25. lpfc_num_discovered_ports_show
  26. lpfc_issue_lip
  27. lpfc_emptyq_wait
  28. lpfc_do_offline
  29. lpfc_reset_pci_bus
  30. lpfc_selective_reset
  31. lpfc_issue_reset
  32. lpfc_sli4_pdev_status_reg_wait
  33. lpfc_sli4_pdev_reg_request
  34. lpfc_nport_evt_cnt_show
  35. lpfc_set_trunking
  36. lpfc_board_mode_show
  37. lpfc_board_mode_store
  38. lpfc_get_hba_info
  39. lpfc_max_rpi_show
  40. lpfc_used_rpi_show
  41. lpfc_max_xri_show
  42. lpfc_used_xri_show
  43. lpfc_max_vpi_show
  44. lpfc_used_vpi_show
  45. lpfc_npiv_info_show
  46. lpfc_poll_show
  47. lpfc_poll_store
  48. lpfc_fips_level_show
  49. lpfc_fips_rev_show
  50. lpfc_dss_show
  51. lpfc_sriov_hw_max_virtfn_show
  52. lpfc_rangecheck
  53. lpfc_enable_bbcr_set
  54. lpfc_wwn_set
  55. lpfc_soft_wwn_enable_store
  56. lpfc_soft_wwpn_show
  57. lpfc_soft_wwpn_store
  58. lpfc_soft_wwnn_show
  59. lpfc_soft_wwnn_store
  60. lpfc_oas_tgt_show
  61. lpfc_oas_tgt_store
  62. lpfc_oas_priority_show
  63. lpfc_oas_priority_store
  64. lpfc_oas_vpt_show
  65. lpfc_oas_vpt_store
  66. lpfc_oas_lun_state_show
  67. lpfc_oas_lun_state_store
  68. lpfc_oas_lun_status_show
  69. lpfc_oas_lun_state_set
  70. lpfc_oas_lun_get_next
  71. lpfc_oas_lun_state_change
  72. lpfc_oas_lun_show
  73. lpfc_oas_lun_store
  74. lpfc_iocb_hw_show
  75. lpfc_txq_hw_show
  76. lpfc_txcmplq_hw_show
  77. lpfc_nodev_tmo_show
  78. lpfc_nodev_tmo_init
  79. lpfc_update_rport_devloss_tmo
  80. lpfc_nodev_tmo_set
  81. lpfc_vport_param_store
  82. lpfc_tgt_queue_depth_set
  83. lpfc_restrict_login_init
  84. lpfc_restrict_login_set
  85. lpfc_topology_store
  86. lpfc_param_show
  87. lpfc_stat_data_ctrl_store
  88. lpfc_stat_data_ctrl_show
  89. sysfs_drvr_stat_data_read
  90. lpfc_link_speed_store
  91. lpfc_param_show
  92. lpfc_param_show
  93. lpfc_aer_cleanup_state
  94. lpfc_sriov_nr_virtfn_store
  95. lpfc_param_show
  96. lpfc_param_show
  97. lpfc_force_rscn_store
  98. lpfc_param_show
  99. lpfc_fcp_imax_store
  100. lpfc_param_show
  101. lpfc_cq_max_proc_limit_store
  102. lpfc_param_show
  103. lpfc_fcp_cpu_map_show
  104. lpfc_fcp_cpu_map_store
  105. lpfc_fcp_cpu_map_init
  106. lpfc_max_scsicmpl_time_set
  107. lpfc_sg_seg_cnt_show
  108. lpfc_sg_seg_cnt_init
  109. sysfs_ctlreg_write
  110. sysfs_ctlreg_read
  111. sysfs_mbox_write
  112. sysfs_mbox_read
  113. lpfc_alloc_sysfs_attr
  114. lpfc_free_sysfs_attr
  115. lpfc_get_host_symbolic_name
  116. lpfc_get_host_port_id
  117. lpfc_get_host_port_type
  118. lpfc_get_host_port_state
  119. lpfc_get_host_speed
  120. lpfc_get_host_fabric_name
  121. lpfc_get_stats
  122. lpfc_reset_stats
  123. lpfc_get_node_by_target
  124. lpfc_get_starget_port_id
  125. lpfc_get_starget_node_name
  126. lpfc_get_starget_port_name
  127. lpfc_set_rport_loss_tmo
  128. lpfc_set_vport_symbolic_name
  129. lpfc_hba_log_verbose_init
  130. lpfc_get_hba_function_mode
  131. lpfc_get_cfgparam
  132. lpfc_nvme_mod_param_dep
  133. lpfc_get_vport_cfgparam

   1 /*******************************************************************
   2  * This file is part of the Emulex Linux Device Driver for         *
   3  * Fibre Channel Host Bus Adapters.                                *
   4  * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
   5  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *
   6  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
   7  * EMULEX and SLI are trademarks of Emulex.                        *
   8  * www.broadcom.com                                                *
   9  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
  10  *                                                                 *
  11  * This program is free software; you can redistribute it and/or   *
  12  * modify it under the terms of version 2 of the GNU General       *
  13  * Public License as published by the Free Software Foundation.    *
  14  * This program is distributed in the hope that it will be useful. *
  15  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
  16  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
  17  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
  18  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
  20  * more details, a copy of which can be found in the file COPYING  *
  21  * included with this package.                                     *
  22  *******************************************************************/
  23 
  24 #include <linux/ctype.h>
  25 #include <linux/delay.h>
  26 #include <linux/pci.h>
  27 #include <linux/interrupt.h>
  28 #include <linux/module.h>
  29 #include <linux/aer.h>
  30 #include <linux/gfp.h>
  31 #include <linux/kernel.h>
  32 
  33 #include <scsi/scsi.h>
  34 #include <scsi/scsi_device.h>
  35 #include <scsi/scsi_host.h>
  36 #include <scsi/scsi_tcq.h>
  37 #include <scsi/scsi_transport_fc.h>
  38 #include <scsi/fc/fc_fs.h>
  39 
  40 #include <linux/nvme-fc-driver.h>
  41 
  42 #include "lpfc_hw4.h"
  43 #include "lpfc_hw.h"
  44 #include "lpfc_sli.h"
  45 #include "lpfc_sli4.h"
  46 #include "lpfc_nl.h"
  47 #include "lpfc_disc.h"
  48 #include "lpfc.h"
  49 #include "lpfc_scsi.h"
  50 #include "lpfc_nvme.h"
  51 #include "lpfc_nvmet.h"
  52 #include "lpfc_logmsg.h"
  53 #include "lpfc_version.h"
  54 #include "lpfc_compat.h"
  55 #include "lpfc_crtn.h"
  56 #include "lpfc_vport.h"
  57 #include "lpfc_attr.h"
  58 
  59 #define LPFC_DEF_DEVLOSS_TMO    30
  60 #define LPFC_MIN_DEVLOSS_TMO    1
  61 #define LPFC_MAX_DEVLOSS_TMO    255
  62 
  63 #define LPFC_DEF_MRQ_POST       512
  64 #define LPFC_MIN_MRQ_POST       512
  65 #define LPFC_MAX_MRQ_POST       2048
  66 
  67 /*
  68  * Write key size should be multiple of 4. If write key is changed
  69  * make sure that library write key is also changed.
  70  */
  71 #define LPFC_REG_WRITE_KEY_SIZE 4
  72 #define LPFC_REG_WRITE_KEY      "EMLX"
  73 
  74 const char *const trunk_errmsg[] = {    /* map errcode */
  75         "",     /* There is no such error code at index 0*/
  76         "link negotiated speed does not match existing"
  77                 " trunk - link was \"low\" speed",
  78         "link negotiated speed does not match"
  79                 " existing trunk - link was \"middle\" speed",
  80         "link negotiated speed does not match existing"
  81                 " trunk - link was \"high\" speed",
  82         "Attached to non-trunking port - F_Port",
  83         "Attached to non-trunking port - N_Port",
  84         "FLOGI response timeout",
  85         "non-FLOGI frame received",
  86         "Invalid FLOGI response",
  87         "Trunking initialization protocol",
  88         "Trunk peer device mismatch",
  89 };
  90 
  91 /**
  92  * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
  93  * @incr: integer to convert.
  94  * @hdw: ascii string holding converted integer plus a string terminator.
  95  *
  96  * Description:
  97  * JEDEC Joint Electron Device Engineering Council.
  98  * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
  99  * character string. The string is then terminated with a NULL in byte 9.
 100  * Hex 0-9 becomes ascii '0' to '9'.
 101  * Hex a-f becomes ascii '=' to 'B' capital B.
 102  *
 103  * Notes:
 104  * Coded for 32 bit integers only.
 105  **/
 106 static void
 107 lpfc_jedec_to_ascii(int incr, char hdw[])
 108 {
 109         int i, j;
 110         for (i = 0; i < 8; i++) {
 111                 j = (incr & 0xf);
 112                 if (j <= 9)
 113                         hdw[7 - i] = 0x30 +  j;
 114                  else
 115                         hdw[7 - i] = 0x61 + j - 10;
 116                 incr = (incr >> 4);
 117         }
 118         hdw[8] = 0;
 119         return;
 120 }
 121 
 122 /**
 123  * lpfc_drvr_version_show - Return the Emulex driver string with version number
 124  * @dev: class unused variable.
 125  * @attr: device attribute, not used.
 126  * @buf: on return contains the module description text.
 127  *
 128  * Returns: size of formatted string.
 129  **/
 130 static ssize_t
 131 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
 132                        char *buf)
 133 {
 134         return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
 135 }
 136 
 137 /**
 138  * lpfc_enable_fip_show - Return the fip mode of the HBA
 139  * @dev: class unused variable.
 140  * @attr: device attribute, not used.
 141  * @buf: on return contains the module description text.
 142  *
 143  * Returns: size of formatted string.
 144  **/
 145 static ssize_t
 146 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
 147                        char *buf)
 148 {
 149         struct Scsi_Host *shost = class_to_shost(dev);
 150         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 151         struct lpfc_hba   *phba = vport->phba;
 152 
 153         if (phba->hba_flag & HBA_FIP_SUPPORT)
 154                 return scnprintf(buf, PAGE_SIZE, "1\n");
 155         else
 156                 return scnprintf(buf, PAGE_SIZE, "0\n");
 157 }
 158 
 159 static ssize_t
 160 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
 161                     char *buf)
 162 {
 163         struct Scsi_Host *shost = class_to_shost(dev);
 164         struct lpfc_vport *vport = shost_priv(shost);
 165         struct lpfc_hba   *phba = vport->phba;
 166         struct lpfc_nvmet_tgtport *tgtp;
 167         struct nvme_fc_local_port *localport;
 168         struct lpfc_nvme_lport *lport;
 169         struct lpfc_nvme_rport *rport;
 170         struct lpfc_nodelist *ndlp;
 171         struct nvme_fc_remote_port *nrport;
 172         struct lpfc_fc4_ctrl_stat *cstat;
 173         uint64_t data1, data2, data3;
 174         uint64_t totin, totout, tot;
 175         char *statep;
 176         int i;
 177         int len = 0;
 178         char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
 179         unsigned long iflags = 0;
 180 
 181         if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
 182                 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
 183                 return len;
 184         }
 185         if (phba->nvmet_support) {
 186                 if (!phba->targetport) {
 187                         len = scnprintf(buf, PAGE_SIZE,
 188                                         "NVME Target: x%llx is not allocated\n",
 189                                         wwn_to_u64(vport->fc_portname.u.wwn));
 190                         return len;
 191                 }
 192                 /* Port state is only one of two values for now. */
 193                 if (phba->targetport->port_id)
 194                         statep = "REGISTERED";
 195                 else
 196                         statep = "INIT";
 197                 scnprintf(tmp, sizeof(tmp),
 198                           "NVME Target Enabled  State %s\n",
 199                           statep);
 200                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 201                         goto buffer_done;
 202 
 203                 scnprintf(tmp, sizeof(tmp),
 204                           "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
 205                           "NVME Target: lpfc",
 206                           phba->brd_no,
 207                           wwn_to_u64(vport->fc_portname.u.wwn),
 208                           wwn_to_u64(vport->fc_nodename.u.wwn),
 209                           phba->targetport->port_id);
 210                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 211                         goto buffer_done;
 212 
 213                 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
 214                     >= PAGE_SIZE)
 215                         goto buffer_done;
 216 
 217                 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
 218                 scnprintf(tmp, sizeof(tmp),
 219                           "LS: Rcv %08x Drop %08x Abort %08x\n",
 220                           atomic_read(&tgtp->rcv_ls_req_in),
 221                           atomic_read(&tgtp->rcv_ls_req_drop),
 222                           atomic_read(&tgtp->xmt_ls_abort));
 223                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 224                         goto buffer_done;
 225 
 226                 if (atomic_read(&tgtp->rcv_ls_req_in) !=
 227                     atomic_read(&tgtp->rcv_ls_req_out)) {
 228                         scnprintf(tmp, sizeof(tmp),
 229                                   "Rcv LS: in %08x != out %08x\n",
 230                                   atomic_read(&tgtp->rcv_ls_req_in),
 231                                   atomic_read(&tgtp->rcv_ls_req_out));
 232                         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 233                                 goto buffer_done;
 234                 }
 235 
 236                 scnprintf(tmp, sizeof(tmp),
 237                           "LS: Xmt %08x Drop %08x Cmpl %08x\n",
 238                           atomic_read(&tgtp->xmt_ls_rsp),
 239                           atomic_read(&tgtp->xmt_ls_drop),
 240                           atomic_read(&tgtp->xmt_ls_rsp_cmpl));
 241                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 242                         goto buffer_done;
 243 
 244                 scnprintf(tmp, sizeof(tmp),
 245                           "LS: RSP Abort %08x xb %08x Err %08x\n",
 246                           atomic_read(&tgtp->xmt_ls_rsp_aborted),
 247                           atomic_read(&tgtp->xmt_ls_rsp_xb_set),
 248                           atomic_read(&tgtp->xmt_ls_rsp_error));
 249                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 250                         goto buffer_done;
 251 
 252                 scnprintf(tmp, sizeof(tmp),
 253                           "FCP: Rcv %08x Defer %08x Release %08x "
 254                           "Drop %08x\n",
 255                           atomic_read(&tgtp->rcv_fcp_cmd_in),
 256                           atomic_read(&tgtp->rcv_fcp_cmd_defer),
 257                           atomic_read(&tgtp->xmt_fcp_release),
 258                           atomic_read(&tgtp->rcv_fcp_cmd_drop));
 259                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 260                         goto buffer_done;
 261 
 262                 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
 263                     atomic_read(&tgtp->rcv_fcp_cmd_out)) {
 264                         scnprintf(tmp, sizeof(tmp),
 265                                   "Rcv FCP: in %08x != out %08x\n",
 266                                   atomic_read(&tgtp->rcv_fcp_cmd_in),
 267                                   atomic_read(&tgtp->rcv_fcp_cmd_out));
 268                         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 269                                 goto buffer_done;
 270                 }
 271 
 272                 scnprintf(tmp, sizeof(tmp),
 273                           "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
 274                           "drop %08x\n",
 275                           atomic_read(&tgtp->xmt_fcp_read),
 276                           atomic_read(&tgtp->xmt_fcp_read_rsp),
 277                           atomic_read(&tgtp->xmt_fcp_write),
 278                           atomic_read(&tgtp->xmt_fcp_rsp),
 279                           atomic_read(&tgtp->xmt_fcp_drop));
 280                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 281                         goto buffer_done;
 282 
 283                 scnprintf(tmp, sizeof(tmp),
 284                           "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
 285                           atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
 286                           atomic_read(&tgtp->xmt_fcp_rsp_error),
 287                           atomic_read(&tgtp->xmt_fcp_rsp_drop));
 288                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 289                         goto buffer_done;
 290 
 291                 scnprintf(tmp, sizeof(tmp),
 292                           "FCP Rsp Abort: %08x xb %08x xricqe  %08x\n",
 293                           atomic_read(&tgtp->xmt_fcp_rsp_aborted),
 294                           atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
 295                           atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
 296                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 297                         goto buffer_done;
 298 
 299                 scnprintf(tmp, sizeof(tmp),
 300                           "ABORT: Xmt %08x Cmpl %08x\n",
 301                           atomic_read(&tgtp->xmt_fcp_abort),
 302                           atomic_read(&tgtp->xmt_fcp_abort_cmpl));
 303                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 304                         goto buffer_done;
 305 
 306                 scnprintf(tmp, sizeof(tmp),
 307                           "ABORT: Sol %08x  Usol %08x Err %08x Cmpl %08x\n",
 308                           atomic_read(&tgtp->xmt_abort_sol),
 309                           atomic_read(&tgtp->xmt_abort_unsol),
 310                           atomic_read(&tgtp->xmt_abort_rsp),
 311                           atomic_read(&tgtp->xmt_abort_rsp_error));
 312                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 313                         goto buffer_done;
 314 
 315                 scnprintf(tmp, sizeof(tmp),
 316                           "DELAY: ctx %08x  fod %08x wqfull %08x\n",
 317                           atomic_read(&tgtp->defer_ctx),
 318                           atomic_read(&tgtp->defer_fod),
 319                           atomic_read(&tgtp->defer_wqfull));
 320                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 321                         goto buffer_done;
 322 
 323                 /* Calculate outstanding IOs */
 324                 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
 325                 tot += atomic_read(&tgtp->xmt_fcp_release);
 326                 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
 327 
 328                 scnprintf(tmp, sizeof(tmp),
 329                           "IO_CTX: %08x  WAIT: cur %08x tot %08x\n"
 330                           "CTX Outstanding %08llx\n\n",
 331                           phba->sli4_hba.nvmet_xri_cnt,
 332                           phba->sli4_hba.nvmet_io_wait_cnt,
 333                           phba->sli4_hba.nvmet_io_wait_total,
 334                           tot);
 335                 strlcat(buf, tmp, PAGE_SIZE);
 336                 goto buffer_done;
 337         }
 338 
 339         localport = vport->localport;
 340         if (!localport) {
 341                 len = scnprintf(buf, PAGE_SIZE,
 342                                 "NVME Initiator x%llx is not allocated\n",
 343                                 wwn_to_u64(vport->fc_portname.u.wwn));
 344                 return len;
 345         }
 346         lport = (struct lpfc_nvme_lport *)localport->private;
 347         if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
 348                 goto buffer_done;
 349 
 350         rcu_read_lock();
 351         scnprintf(tmp, sizeof(tmp),
 352                   "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
 353                   phba->brd_no,
 354                   phba->sli4_hba.max_cfg_param.max_xri,
 355                   phba->sli4_hba.io_xri_max,
 356                   lpfc_sli4_get_els_iocb_cnt(phba));
 357         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 358                 goto rcu_unlock_buf_done;
 359 
 360         /* Port state is only one of two values for now. */
 361         if (localport->port_id)
 362                 statep = "ONLINE";
 363         else
 364                 statep = "UNKNOWN ";
 365 
 366         scnprintf(tmp, sizeof(tmp),
 367                   "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
 368                   "NVME LPORT lpfc",
 369                   phba->brd_no,
 370                   wwn_to_u64(vport->fc_portname.u.wwn),
 371                   wwn_to_u64(vport->fc_nodename.u.wwn),
 372                   localport->port_id, statep);
 373         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 374                 goto rcu_unlock_buf_done;
 375 
 376         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
 377                 nrport = NULL;
 378                 spin_lock_irqsave(&vport->phba->hbalock, iflags);
 379                 rport = lpfc_ndlp_get_nrport(ndlp);
 380                 if (rport)
 381                         nrport = rport->remoteport;
 382                 spin_unlock_irqrestore(&vport->phba->hbalock, iflags);
 383                 if (!nrport)
 384                         continue;
 385 
 386                 /* Port state is only one of two values for now. */
 387                 switch (nrport->port_state) {
 388                 case FC_OBJSTATE_ONLINE:
 389                         statep = "ONLINE";
 390                         break;
 391                 case FC_OBJSTATE_UNKNOWN:
 392                         statep = "UNKNOWN ";
 393                         break;
 394                 default:
 395                         statep = "UNSUPPORTED";
 396                         break;
 397                 }
 398 
 399                 /* Tab in to show lport ownership. */
 400                 if (strlcat(buf, "NVME RPORT       ", PAGE_SIZE) >= PAGE_SIZE)
 401                         goto rcu_unlock_buf_done;
 402                 if (phba->brd_no >= 10) {
 403                         if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
 404                                 goto rcu_unlock_buf_done;
 405                 }
 406 
 407                 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
 408                           nrport->port_name);
 409                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 410                         goto rcu_unlock_buf_done;
 411 
 412                 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
 413                           nrport->node_name);
 414                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 415                         goto rcu_unlock_buf_done;
 416 
 417                 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
 418                           nrport->port_id);
 419                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 420                         goto rcu_unlock_buf_done;
 421 
 422                 /* An NVME rport can have multiple roles. */
 423                 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
 424                         if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
 425                                 goto rcu_unlock_buf_done;
 426                 }
 427                 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
 428                         if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
 429                                 goto rcu_unlock_buf_done;
 430                 }
 431                 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
 432                         if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
 433                                 goto rcu_unlock_buf_done;
 434                 }
 435                 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
 436                                           FC_PORT_ROLE_NVME_TARGET |
 437                                           FC_PORT_ROLE_NVME_DISCOVERY)) {
 438                         scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
 439                                   nrport->port_role);
 440                         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 441                                 goto rcu_unlock_buf_done;
 442                 }
 443 
 444                 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
 445                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 446                         goto rcu_unlock_buf_done;
 447         }
 448         rcu_read_unlock();
 449 
 450         if (!lport)
 451                 goto buffer_done;
 452 
 453         if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
 454                 goto buffer_done;
 455 
 456         scnprintf(tmp, sizeof(tmp),
 457                   "LS: Xmt %010x Cmpl %010x Abort %08x\n",
 458                   atomic_read(&lport->fc4NvmeLsRequests),
 459                   atomic_read(&lport->fc4NvmeLsCmpls),
 460                   atomic_read(&lport->xmt_ls_abort));
 461         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 462                 goto buffer_done;
 463 
 464         scnprintf(tmp, sizeof(tmp),
 465                   "LS XMIT: Err %08x  CMPL: xb %08x Err %08x\n",
 466                   atomic_read(&lport->xmt_ls_err),
 467                   atomic_read(&lport->cmpl_ls_xb),
 468                   atomic_read(&lport->cmpl_ls_err));
 469         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 470                 goto buffer_done;
 471 
 472         totin = 0;
 473         totout = 0;
 474         for (i = 0; i < phba->cfg_hdw_queue; i++) {
 475                 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
 476                 tot = cstat->io_cmpls;
 477                 totin += tot;
 478                 data1 = cstat->input_requests;
 479                 data2 = cstat->output_requests;
 480                 data3 = cstat->control_requests;
 481                 totout += (data1 + data2 + data3);
 482         }
 483         scnprintf(tmp, sizeof(tmp),
 484                   "Total FCP Cmpl %016llx Issue %016llx "
 485                   "OutIO %016llx\n",
 486                   totin, totout, totout - totin);
 487         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 488                 goto buffer_done;
 489 
 490         scnprintf(tmp, sizeof(tmp),
 491                   "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
 492                   "wqerr %08x err %08x\n",
 493                   atomic_read(&lport->xmt_fcp_abort),
 494                   atomic_read(&lport->xmt_fcp_noxri),
 495                   atomic_read(&lport->xmt_fcp_bad_ndlp),
 496                   atomic_read(&lport->xmt_fcp_qdepth),
 497                   atomic_read(&lport->xmt_fcp_err),
 498                   atomic_read(&lport->xmt_fcp_wqerr));
 499         if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 500                 goto buffer_done;
 501 
 502         scnprintf(tmp, sizeof(tmp),
 503                   "FCP CMPL: xb %08x Err %08x\n",
 504                   atomic_read(&lport->cmpl_fcp_xb),
 505                   atomic_read(&lport->cmpl_fcp_err));
 506         strlcat(buf, tmp, PAGE_SIZE);
 507 
 508         /* RCU is already unlocked. */
 509         goto buffer_done;
 510 
 511  rcu_unlock_buf_done:
 512         rcu_read_unlock();
 513 
 514  buffer_done:
 515         len = strnlen(buf, PAGE_SIZE);
 516 
 517         if (unlikely(len >= (PAGE_SIZE - 1))) {
 518                 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
 519                                 "6314 Catching potential buffer "
 520                                 "overflow > PAGE_SIZE = %lu bytes\n",
 521                                 PAGE_SIZE);
 522                 strlcpy(buf + PAGE_SIZE - 1 -
 523                         strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
 524                         LPFC_NVME_INFO_MORE_STR,
 525                         strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
 526                         + 1);
 527         }
 528 
 529         return len;
 530 }
 531 
 532 static ssize_t
 533 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
 534                     char *buf)
 535 {
 536         struct Scsi_Host *shost = class_to_shost(dev);
 537         struct lpfc_vport *vport = shost_priv(shost);
 538         struct lpfc_hba *phba = vport->phba;
 539         int len;
 540         struct lpfc_fc4_ctrl_stat *cstat;
 541         u64 data1, data2, data3;
 542         u64 tot, totin, totout;
 543         int i;
 544         char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
 545 
 546         if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
 547             (phba->sli_rev != LPFC_SLI_REV4))
 548                 return 0;
 549 
 550         scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
 551 
 552         totin = 0;
 553         totout = 0;
 554         for (i = 0; i < phba->cfg_hdw_queue; i++) {
 555                 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
 556                 tot = cstat->io_cmpls;
 557                 totin += tot;
 558                 data1 = cstat->input_requests;
 559                 data2 = cstat->output_requests;
 560                 data3 = cstat->control_requests;
 561                 totout += (data1 + data2 + data3);
 562 
 563                 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
 564                           "IO %016llx ", i, data1, data2, data3);
 565                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 566                         goto buffer_done;
 567 
 568                 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
 569                           tot, ((data1 + data2 + data3) - tot));
 570                 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
 571                         goto buffer_done;
 572         }
 573         scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
 574                   "OutIO %016llx\n", totin, totout, totout - totin);
 575         strlcat(buf, tmp, PAGE_SIZE);
 576 
 577 buffer_done:
 578         len = strnlen(buf, PAGE_SIZE);
 579 
 580         return len;
 581 }
 582 
 583 static ssize_t
 584 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
 585                   char *buf)
 586 {
 587         struct Scsi_Host *shost = class_to_shost(dev);
 588         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 589         struct lpfc_hba   *phba = vport->phba;
 590 
 591         if (phba->cfg_enable_bg) {
 592                 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
 593                         return scnprintf(buf, PAGE_SIZE,
 594                                         "BlockGuard Enabled\n");
 595                 else
 596                         return scnprintf(buf, PAGE_SIZE,
 597                                         "BlockGuard Not Supported\n");
 598         } else
 599                 return scnprintf(buf, PAGE_SIZE,
 600                                         "BlockGuard Disabled\n");
 601 }
 602 
 603 static ssize_t
 604 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
 605                        char *buf)
 606 {
 607         struct Scsi_Host *shost = class_to_shost(dev);
 608         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 609         struct lpfc_hba   *phba = vport->phba;
 610 
 611         return scnprintf(buf, PAGE_SIZE, "%llu\n",
 612                         (unsigned long long)phba->bg_guard_err_cnt);
 613 }
 614 
 615 static ssize_t
 616 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
 617                         char *buf)
 618 {
 619         struct Scsi_Host *shost = class_to_shost(dev);
 620         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 621         struct lpfc_hba   *phba = vport->phba;
 622 
 623         return scnprintf(buf, PAGE_SIZE, "%llu\n",
 624                         (unsigned long long)phba->bg_apptag_err_cnt);
 625 }
 626 
 627 static ssize_t
 628 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
 629                         char *buf)
 630 {
 631         struct Scsi_Host *shost = class_to_shost(dev);
 632         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 633         struct lpfc_hba   *phba = vport->phba;
 634 
 635         return scnprintf(buf, PAGE_SIZE, "%llu\n",
 636                         (unsigned long long)phba->bg_reftag_err_cnt);
 637 }
 638 
 639 /**
 640  * lpfc_info_show - Return some pci info about the host in ascii
 641  * @dev: class converted to a Scsi_host structure.
 642  * @attr: device attribute, not used.
 643  * @buf: on return contains the formatted text from lpfc_info().
 644  *
 645  * Returns: size of formatted string.
 646  **/
 647 static ssize_t
 648 lpfc_info_show(struct device *dev, struct device_attribute *attr,
 649                char *buf)
 650 {
 651         struct Scsi_Host *host = class_to_shost(dev);
 652 
 653         return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
 654 }
 655 
 656 /**
 657  * lpfc_serialnum_show - Return the hba serial number in ascii
 658  * @dev: class converted to a Scsi_host structure.
 659  * @attr: device attribute, not used.
 660  * @buf: on return contains the formatted text serial number.
 661  *
 662  * Returns: size of formatted string.
 663  **/
 664 static ssize_t
 665 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
 666                     char *buf)
 667 {
 668         struct Scsi_Host  *shost = class_to_shost(dev);
 669         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 670         struct lpfc_hba   *phba = vport->phba;
 671 
 672         return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
 673 }
 674 
 675 /**
 676  * lpfc_temp_sensor_show - Return the temperature sensor level
 677  * @dev: class converted to a Scsi_host structure.
 678  * @attr: device attribute, not used.
 679  * @buf: on return contains the formatted support level.
 680  *
 681  * Description:
 682  * Returns a number indicating the temperature sensor level currently
 683  * supported, zero or one in ascii.
 684  *
 685  * Returns: size of formatted string.
 686  **/
 687 static ssize_t
 688 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
 689                       char *buf)
 690 {
 691         struct Scsi_Host *shost = class_to_shost(dev);
 692         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 693         struct lpfc_hba   *phba = vport->phba;
 694         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
 695 }
 696 
 697 /**
 698  * lpfc_modeldesc_show - Return the model description of the hba
 699  * @dev: class converted to a Scsi_host structure.
 700  * @attr: device attribute, not used.
 701  * @buf: on return contains the scsi vpd model description.
 702  *
 703  * Returns: size of formatted string.
 704  **/
 705 static ssize_t
 706 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
 707                     char *buf)
 708 {
 709         struct Scsi_Host  *shost = class_to_shost(dev);
 710         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 711         struct lpfc_hba   *phba = vport->phba;
 712 
 713         return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
 714 }
 715 
 716 /**
 717  * lpfc_modelname_show - Return the model name of the hba
 718  * @dev: class converted to a Scsi_host structure.
 719  * @attr: device attribute, not used.
 720  * @buf: on return contains the scsi vpd model name.
 721  *
 722  * Returns: size of formatted string.
 723  **/
 724 static ssize_t
 725 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
 726                     char *buf)
 727 {
 728         struct Scsi_Host  *shost = class_to_shost(dev);
 729         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 730         struct lpfc_hba   *phba = vport->phba;
 731 
 732         return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
 733 }
 734 
 735 /**
 736  * lpfc_programtype_show - Return the program type of the hba
 737  * @dev: class converted to a Scsi_host structure.
 738  * @attr: device attribute, not used.
 739  * @buf: on return contains the scsi vpd program type.
 740  *
 741  * Returns: size of formatted string.
 742  **/
 743 static ssize_t
 744 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
 745                       char *buf)
 746 {
 747         struct Scsi_Host  *shost = class_to_shost(dev);
 748         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 749         struct lpfc_hba   *phba = vport->phba;
 750 
 751         return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
 752 }
 753 
 754 /**
 755  * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
 756  * @dev: class converted to a Scsi_host structure.
 757  * @attr: device attribute, not used.
 758  * @buf: on return contains the Menlo Maintenance sli flag.
 759  *
 760  * Returns: size of formatted string.
 761  **/
 762 static ssize_t
 763 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
 764 {
 765         struct Scsi_Host  *shost = class_to_shost(dev);
 766         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
 767         struct lpfc_hba   *phba = vport->phba;
 768 
 769         return scnprintf(buf, PAGE_SIZE, "%d\n",
 770                 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
 771 }
 772 
 773 /**
 774  * lpfc_vportnum_show - Return the port number in ascii of the hba
 775  * @dev: class converted to a Scsi_host structure.
 776  * @attr: device attribute, not used.
 777  * @buf: on return contains scsi vpd program type.
 778  *
 779  * Returns: size of formatted string.
 780  **/
 781 static ssize_t
 782 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
 783                    char *buf)
 784 {
 785         struct Scsi_Host  *shost = class_to_shost(dev);
 786         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 787         struct lpfc_hba   *phba = vport->phba;
 788 
 789         return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
 790 }
 791 
 792 /**
 793  * lpfc_fwrev_show - Return the firmware rev running in the hba
 794  * @dev: class converted to a Scsi_host structure.
 795  * @attr: device attribute, not used.
 796  * @buf: on return contains the scsi vpd program type.
 797  *
 798  * Returns: size of formatted string.
 799  **/
 800 static ssize_t
 801 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
 802                 char *buf)
 803 {
 804         struct Scsi_Host  *shost = class_to_shost(dev);
 805         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 806         struct lpfc_hba   *phba = vport->phba;
 807         uint32_t if_type;
 808         uint8_t sli_family;
 809         char fwrev[FW_REV_STR_SIZE];
 810         int len;
 811 
 812         lpfc_decode_firmware_rev(phba, fwrev, 1);
 813         if_type = phba->sli4_hba.pc_sli4_params.if_type;
 814         sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
 815 
 816         if (phba->sli_rev < LPFC_SLI_REV4)
 817                 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
 818                                fwrev, phba->sli_rev);
 819         else
 820                 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
 821                                fwrev, phba->sli_rev, if_type, sli_family);
 822 
 823         return len;
 824 }
 825 
 826 /**
 827  * lpfc_hdw_show - Return the jedec information about the hba
 828  * @dev: class converted to a Scsi_host structure.
 829  * @attr: device attribute, not used.
 830  * @buf: on return contains the scsi vpd program type.
 831  *
 832  * Returns: size of formatted string.
 833  **/
 834 static ssize_t
 835 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
 836 {
 837         char hdw[9];
 838         struct Scsi_Host  *shost = class_to_shost(dev);
 839         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 840         struct lpfc_hba   *phba = vport->phba;
 841         lpfc_vpd_t *vp = &phba->vpd;
 842 
 843         lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
 844         return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
 845                          vp->rev.smRev, vp->rev.smFwRev);
 846 }
 847 
 848 /**
 849  * lpfc_option_rom_version_show - Return the adapter ROM FCode version
 850  * @dev: class converted to a Scsi_host structure.
 851  * @attr: device attribute, not used.
 852  * @buf: on return contains the ROM and FCode ascii strings.
 853  *
 854  * Returns: size of formatted string.
 855  **/
 856 static ssize_t
 857 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
 858                              char *buf)
 859 {
 860         struct Scsi_Host  *shost = class_to_shost(dev);
 861         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 862         struct lpfc_hba   *phba = vport->phba;
 863         char fwrev[FW_REV_STR_SIZE];
 864 
 865         if (phba->sli_rev < LPFC_SLI_REV4)
 866                 return scnprintf(buf, PAGE_SIZE, "%s\n",
 867                                 phba->OptionROMVersion);
 868 
 869         lpfc_decode_firmware_rev(phba, fwrev, 1);
 870         return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
 871 }
 872 
 873 /**
 874  * lpfc_state_show - Return the link state of the port
 875  * @dev: class converted to a Scsi_host structure.
 876  * @attr: device attribute, not used.
 877  * @buf: on return contains text describing the state of the link.
 878  *
 879  * Notes:
 880  * The switch statement has no default so zero will be returned.
 881  *
 882  * Returns: size of formatted string.
 883  **/
 884 static ssize_t
 885 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
 886                      char *buf)
 887 {
 888         struct Scsi_Host  *shost = class_to_shost(dev);
 889         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 890         struct lpfc_hba   *phba = vport->phba;
 891         int  len = 0;
 892 
 893         switch (phba->link_state) {
 894         case LPFC_LINK_UNKNOWN:
 895         case LPFC_WARM_START:
 896         case LPFC_INIT_START:
 897         case LPFC_INIT_MBX_CMDS:
 898         case LPFC_LINK_DOWN:
 899         case LPFC_HBA_ERROR:
 900                 if (phba->hba_flag & LINK_DISABLED)
 901                         len += scnprintf(buf + len, PAGE_SIZE-len,
 902                                 "Link Down - User disabled\n");
 903                 else
 904                         len += scnprintf(buf + len, PAGE_SIZE-len,
 905                                 "Link Down\n");
 906                 break;
 907         case LPFC_LINK_UP:
 908         case LPFC_CLEAR_LA:
 909         case LPFC_HBA_READY:
 910                 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
 911 
 912                 switch (vport->port_state) {
 913                 case LPFC_LOCAL_CFG_LINK:
 914                         len += scnprintf(buf + len, PAGE_SIZE-len,
 915                                         "Configuring Link\n");
 916                         break;
 917                 case LPFC_FDISC:
 918                 case LPFC_FLOGI:
 919                 case LPFC_FABRIC_CFG_LINK:
 920                 case LPFC_NS_REG:
 921                 case LPFC_NS_QRY:
 922                 case LPFC_BUILD_DISC_LIST:
 923                 case LPFC_DISC_AUTH:
 924                         len += scnprintf(buf + len, PAGE_SIZE - len,
 925                                         "Discovery\n");
 926                         break;
 927                 case LPFC_VPORT_READY:
 928                         len += scnprintf(buf + len, PAGE_SIZE - len,
 929                                         "Ready\n");
 930                         break;
 931 
 932                 case LPFC_VPORT_FAILED:
 933                         len += scnprintf(buf + len, PAGE_SIZE - len,
 934                                         "Failed\n");
 935                         break;
 936 
 937                 case LPFC_VPORT_UNKNOWN:
 938                         len += scnprintf(buf + len, PAGE_SIZE - len,
 939                                         "Unknown\n");
 940                         break;
 941                 }
 942                 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
 943                         len += scnprintf(buf + len, PAGE_SIZE-len,
 944                                         "   Menlo Maint Mode\n");
 945                 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
 946                         if (vport->fc_flag & FC_PUBLIC_LOOP)
 947                                 len += scnprintf(buf + len, PAGE_SIZE-len,
 948                                                 "   Public Loop\n");
 949                         else
 950                                 len += scnprintf(buf + len, PAGE_SIZE-len,
 951                                                 "   Private Loop\n");
 952                 } else {
 953                         if (vport->fc_flag & FC_FABRIC)
 954                                 len += scnprintf(buf + len, PAGE_SIZE-len,
 955                                                 "   Fabric\n");
 956                         else
 957                                 len += scnprintf(buf + len, PAGE_SIZE-len,
 958                                                 "   Point-2-Point\n");
 959                 }
 960         }
 961 
 962         if ((phba->sli_rev == LPFC_SLI_REV4) &&
 963             ((bf_get(lpfc_sli_intf_if_type,
 964              &phba->sli4_hba.sli_intf) ==
 965              LPFC_SLI_INTF_IF_TYPE_6))) {
 966                 struct lpfc_trunk_link link = phba->trunk_link;
 967 
 968                 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
 969                         len += scnprintf(buf + len, PAGE_SIZE - len,
 970                                 "Trunk port 0: Link %s %s\n",
 971                                 (link.link0.state == LPFC_LINK_UP) ?
 972                                  "Up" : "Down. ",
 973                                 trunk_errmsg[link.link0.fault]);
 974 
 975                 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
 976                         len += scnprintf(buf + len, PAGE_SIZE - len,
 977                                 "Trunk port 1: Link %s %s\n",
 978                                 (link.link1.state == LPFC_LINK_UP) ?
 979                                  "Up" : "Down. ",
 980                                 trunk_errmsg[link.link1.fault]);
 981 
 982                 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
 983                         len += scnprintf(buf + len, PAGE_SIZE - len,
 984                                 "Trunk port 2: Link %s %s\n",
 985                                 (link.link2.state == LPFC_LINK_UP) ?
 986                                  "Up" : "Down. ",
 987                                 trunk_errmsg[link.link2.fault]);
 988 
 989                 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
 990                         len += scnprintf(buf + len, PAGE_SIZE - len,
 991                                 "Trunk port 3: Link %s %s\n",
 992                                 (link.link3.state == LPFC_LINK_UP) ?
 993                                  "Up" : "Down. ",
 994                                 trunk_errmsg[link.link3.fault]);
 995 
 996         }
 997 
 998         return len;
 999 }
1000 
1001 /**
1002  * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1003  * @dev: class unused variable.
1004  * @attr: device attribute, not used.
1005  * @buf: on return contains the module description text.
1006  *
1007  * Returns: size of formatted string.
1008  **/
1009 static ssize_t
1010 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1011                         char *buf)
1012 {
1013         struct Scsi_Host *shost = class_to_shost(dev);
1014         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1015         struct lpfc_hba *phba = vport->phba;
1016 
1017         if (phba->sli_rev < LPFC_SLI_REV4)
1018                 return scnprintf(buf, PAGE_SIZE, "fc\n");
1019 
1020         if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1021                 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1022                         return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1023                 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1024                         return scnprintf(buf, PAGE_SIZE, "fc\n");
1025         }
1026         return scnprintf(buf, PAGE_SIZE, "unknown\n");
1027 }
1028 
1029 /**
1030  * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1031  *                          (OAS) is supported.
1032  * @dev: class unused variable.
1033  * @attr: device attribute, not used.
1034  * @buf: on return contains the module description text.
1035  *
1036  * Returns: size of formatted string.
1037  **/
1038 static ssize_t
1039 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1040                         char *buf)
1041 {
1042         struct Scsi_Host *shost = class_to_shost(dev);
1043         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1044         struct lpfc_hba *phba = vport->phba;
1045 
1046         return scnprintf(buf, PAGE_SIZE, "%d\n",
1047                         phba->sli4_hba.pc_sli4_params.oas_supported);
1048 }
1049 
1050 /**
1051  * lpfc_link_state_store - Transition the link_state on an HBA port
1052  * @dev: class device that is converted into a Scsi_host.
1053  * @attr: device attribute, not used.
1054  * @buf: one or more lpfc_polling_flags values.
1055  * @count: not used.
1056  *
1057  * Returns:
1058  * -EINVAL if the buffer is not "up" or "down"
1059  * return from link state change function if non-zero
1060  * length of the buf on success
1061  **/
1062 static ssize_t
1063 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1064                 const char *buf, size_t count)
1065 {
1066         struct Scsi_Host  *shost = class_to_shost(dev);
1067         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1068         struct lpfc_hba   *phba = vport->phba;
1069 
1070         int status = -EINVAL;
1071 
1072         if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1073                         (phba->link_state == LPFC_LINK_DOWN))
1074                 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1075         else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1076                         (phba->link_state >= LPFC_LINK_UP))
1077                 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1078 
1079         if (status == 0)
1080                 return strlen(buf);
1081         else
1082                 return status;
1083 }
1084 
1085 /**
1086  * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1087  * @dev: class device that is converted into a Scsi_host.
1088  * @attr: device attribute, not used.
1089  * @buf: on return contains the sum of fc mapped and unmapped.
1090  *
1091  * Description:
1092  * Returns the ascii text number of the sum of the fc mapped and unmapped
1093  * vport counts.
1094  *
1095  * Returns: size of formatted string.
1096  **/
1097 static ssize_t
1098 lpfc_num_discovered_ports_show(struct device *dev,
1099                                struct device_attribute *attr, char *buf)
1100 {
1101         struct Scsi_Host  *shost = class_to_shost(dev);
1102         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1103 
1104         return scnprintf(buf, PAGE_SIZE, "%d\n",
1105                         vport->fc_map_cnt + vport->fc_unmap_cnt);
1106 }
1107 
1108 /**
1109  * lpfc_issue_lip - Misnomer, name carried over from long ago
1110  * @shost: Scsi_Host pointer.
1111  *
1112  * Description:
1113  * Bring the link down gracefully then re-init the link. The firmware will
1114  * re-init the fiber channel interface as required. Does not issue a LIP.
1115  *
1116  * Returns:
1117  * -EPERM port offline or management commands are being blocked
1118  * -ENOMEM cannot allocate memory for the mailbox command
1119  * -EIO error sending the mailbox command
1120  * zero for success
1121  **/
1122 static int
1123 lpfc_issue_lip(struct Scsi_Host *shost)
1124 {
1125         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1126         struct lpfc_hba   *phba = vport->phba;
1127         LPFC_MBOXQ_t *pmboxq;
1128         int mbxstatus = MBXERR_ERROR;
1129 
1130         /*
1131          * If the link is offline, disabled or BLOCK_MGMT_IO
1132          * it doesn't make any sense to allow issue_lip
1133          */
1134         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1135             (phba->hba_flag & LINK_DISABLED) ||
1136             (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1137                 return -EPERM;
1138 
1139         pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1140 
1141         if (!pmboxq)
1142                 return -ENOMEM;
1143 
1144         memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1145         pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1146         pmboxq->u.mb.mbxOwner = OWN_HOST;
1147 
1148         mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1149 
1150         if ((mbxstatus == MBX_SUCCESS) &&
1151             (pmboxq->u.mb.mbxStatus == 0 ||
1152              pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1153                 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1154                 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1155                                phba->cfg_link_speed);
1156                 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1157                                                      phba->fc_ratov * 2);
1158                 if ((mbxstatus == MBX_SUCCESS) &&
1159                     (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1160                         lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1161                                         "2859 SLI authentication is required "
1162                                         "for INIT_LINK but has not done yet\n");
1163         }
1164 
1165         lpfc_set_loopback_flag(phba);
1166         if (mbxstatus != MBX_TIMEOUT)
1167                 mempool_free(pmboxq, phba->mbox_mem_pool);
1168 
1169         if (mbxstatus == MBXERR_ERROR)
1170                 return -EIO;
1171 
1172         return 0;
1173 }
1174 
1175 int
1176 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1177 {
1178         int cnt = 0;
1179 
1180         spin_lock_irq(lock);
1181         while (!list_empty(q)) {
1182                 spin_unlock_irq(lock);
1183                 msleep(20);
1184                 if (cnt++ > 250) {  /* 5 secs */
1185                         lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1186                                         "0466 %s %s\n",
1187                                         "Outstanding IO when ",
1188                                         "bringing Adapter offline\n");
1189                                 return 0;
1190                 }
1191                 spin_lock_irq(lock);
1192         }
1193         spin_unlock_irq(lock);
1194         return 1;
1195 }
1196 
1197 /**
1198  * lpfc_do_offline - Issues a mailbox command to bring the link down
1199  * @phba: lpfc_hba pointer.
1200  * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1201  *
1202  * Notes:
1203  * Assumes any error from lpfc_do_offline() will be negative.
1204  * Can wait up to 5 seconds for the port ring buffers count
1205  * to reach zero, prints a warning if it is not zero and continues.
1206  * lpfc_workq_post_event() returns a non-zero return code if call fails.
1207  *
1208  * Returns:
1209  * -EIO error posting the event
1210  * zero for success
1211  **/
1212 static int
1213 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1214 {
1215         struct completion online_compl;
1216         struct lpfc_queue *qp = NULL;
1217         struct lpfc_sli_ring *pring;
1218         struct lpfc_sli *psli;
1219         int status = 0;
1220         int i;
1221         int rc;
1222 
1223         init_completion(&online_compl);
1224         rc = lpfc_workq_post_event(phba, &status, &online_compl,
1225                               LPFC_EVT_OFFLINE_PREP);
1226         if (rc == 0)
1227                 return -ENOMEM;
1228 
1229         wait_for_completion(&online_compl);
1230 
1231         if (status != 0)
1232                 return -EIO;
1233 
1234         psli = &phba->sli;
1235 
1236         /*
1237          * If freeing the queues have already started, don't access them.
1238          * Otherwise set FREE_WAIT to indicate that queues are being used
1239          * to hold the freeing process until we finish.
1240          */
1241         spin_lock_irq(&phba->hbalock);
1242         if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1243                 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1244         } else {
1245                 spin_unlock_irq(&phba->hbalock);
1246                 goto skip_wait;
1247         }
1248         spin_unlock_irq(&phba->hbalock);
1249 
1250         /* Wait a little for things to settle down, but not
1251          * long enough for dev loss timeout to expire.
1252          */
1253         if (phba->sli_rev != LPFC_SLI_REV4) {
1254                 for (i = 0; i < psli->num_rings; i++) {
1255                         pring = &psli->sli3_ring[i];
1256                         if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1257                                               &phba->hbalock))
1258                                 goto out;
1259                 }
1260         } else {
1261                 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1262                         pring = qp->pring;
1263                         if (!pring)
1264                                 continue;
1265                         if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1266                                               &pring->ring_lock))
1267                                 goto out;
1268                 }
1269         }
1270 out:
1271         spin_lock_irq(&phba->hbalock);
1272         psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1273         spin_unlock_irq(&phba->hbalock);
1274 
1275 skip_wait:
1276         init_completion(&online_compl);
1277         rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1278         if (rc == 0)
1279                 return -ENOMEM;
1280 
1281         wait_for_completion(&online_compl);
1282 
1283         if (status != 0)
1284                 return -EIO;
1285 
1286         return 0;
1287 }
1288 
1289 /**
1290  * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1291  * @phba: lpfc_hba pointer.
1292  *
1293  * Description:
1294  * Issues a PCI secondary bus reset for the phba->pcidev.
1295  *
1296  * Notes:
1297  * First walks the bus_list to ensure only PCI devices with Emulex
1298  * vendor id, device ids that support hot reset, only one occurrence
1299  * of function 0, and all ports on the bus are in offline mode to ensure the
1300  * hot reset only affects one valid HBA.
1301  *
1302  * Returns:
1303  * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1304  * -ENODEV,   NULL ptr to pcidev
1305  * -EBADSLT,  detected invalid device
1306  * -EBUSY,    port is not in offline state
1307  *      0,    successful
1308  */
1309 static int
1310 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1311 {
1312         struct pci_dev *pdev = phba->pcidev;
1313         struct Scsi_Host *shost = NULL;
1314         struct lpfc_hba *phba_other = NULL;
1315         struct pci_dev *ptr = NULL;
1316         int res;
1317 
1318         if (phba->cfg_enable_hba_reset != 2)
1319                 return -ENOTSUPP;
1320 
1321         if (!pdev) {
1322                 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1323                 return -ENODEV;
1324         }
1325 
1326         res = lpfc_check_pci_resettable(phba);
1327         if (res)
1328                 return res;
1329 
1330         /* Walk the list of devices on the pci_dev's bus */
1331         list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1332                 /* Check port is offline */
1333                 shost = pci_get_drvdata(ptr);
1334                 if (shost) {
1335                         phba_other =
1336                                 ((struct lpfc_vport *)shost->hostdata)->phba;
1337                         if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1338                                 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1339                                                 "8349 WWPN = 0x%02x%02x%02x%02x"
1340                                                 "%02x%02x%02x%02x is not "
1341                                                 "offline!\n",
1342                                                 phba_other->wwpn[0],
1343                                                 phba_other->wwpn[1],
1344                                                 phba_other->wwpn[2],
1345                                                 phba_other->wwpn[3],
1346                                                 phba_other->wwpn[4],
1347                                                 phba_other->wwpn[5],
1348                                                 phba_other->wwpn[6],
1349                                                 phba_other->wwpn[7]);
1350                                 return -EBUSY;
1351                         }
1352                 }
1353         }
1354 
1355         /* Issue PCI bus reset */
1356         res = pci_reset_bus(pdev);
1357         if (res) {
1358                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1359                                 "8350 PCI reset bus failed: %d\n", res);
1360         }
1361 
1362         return res;
1363 }
1364 
1365 /**
1366  * lpfc_selective_reset - Offline then onlines the port
1367  * @phba: lpfc_hba pointer.
1368  *
1369  * Description:
1370  * If the port is configured to allow a reset then the hba is brought
1371  * offline then online.
1372  *
1373  * Notes:
1374  * Assumes any error from lpfc_do_offline() will be negative.
1375  * Do not make this function static.
1376  *
1377  * Returns:
1378  * lpfc_do_offline() return code if not zero
1379  * -EIO reset not configured or error posting the event
1380  * zero for success
1381  **/
1382 int
1383 lpfc_selective_reset(struct lpfc_hba *phba)
1384 {
1385         struct completion online_compl;
1386         int status = 0;
1387         int rc;
1388 
1389         if (!phba->cfg_enable_hba_reset)
1390                 return -EACCES;
1391 
1392         if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1393                 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1394 
1395                 if (status != 0)
1396                         return status;
1397         }
1398 
1399         init_completion(&online_compl);
1400         rc = lpfc_workq_post_event(phba, &status, &online_compl,
1401                               LPFC_EVT_ONLINE);
1402         if (rc == 0)
1403                 return -ENOMEM;
1404 
1405         wait_for_completion(&online_compl);
1406 
1407         if (status != 0)
1408                 return -EIO;
1409 
1410         return 0;
1411 }
1412 
1413 /**
1414  * lpfc_issue_reset - Selectively resets an adapter
1415  * @dev: class device that is converted into a Scsi_host.
1416  * @attr: device attribute, not used.
1417  * @buf: containing the string "selective".
1418  * @count: unused variable.
1419  *
1420  * Description:
1421  * If the buf contains the string "selective" then lpfc_selective_reset()
1422  * is called to perform the reset.
1423  *
1424  * Notes:
1425  * Assumes any error from lpfc_selective_reset() will be negative.
1426  * If lpfc_selective_reset() returns zero then the length of the buffer
1427  * is returned which indicates success
1428  *
1429  * Returns:
1430  * -EINVAL if the buffer does not contain the string "selective"
1431  * length of buf if lpfc-selective_reset() if the call succeeds
1432  * return value of lpfc_selective_reset() if the call fails
1433 **/
1434 static ssize_t
1435 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1436                  const char *buf, size_t count)
1437 {
1438         struct Scsi_Host  *shost = class_to_shost(dev);
1439         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1440         struct lpfc_hba   *phba = vport->phba;
1441         int status = -EINVAL;
1442 
1443         if (!phba->cfg_enable_hba_reset)
1444                 return -EACCES;
1445 
1446         if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1447                 status = phba->lpfc_selective_reset(phba);
1448 
1449         if (status == 0)
1450                 return strlen(buf);
1451         else
1452                 return status;
1453 }
1454 
1455 /**
1456  * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1457  * @phba: lpfc_hba pointer.
1458  *
1459  * Description:
1460  * SLI4 interface type-2 device to wait on the sliport status register for
1461  * the readyness after performing a firmware reset.
1462  *
1463  * Returns:
1464  * zero for success, -EPERM when port does not have privilege to perform the
1465  * reset, -EIO when port timeout from recovering from the reset.
1466  *
1467  * Note:
1468  * As the caller will interpret the return code by value, be careful in making
1469  * change or addition to return codes.
1470  **/
1471 int
1472 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1473 {
1474         struct lpfc_register portstat_reg = {0};
1475         int i;
1476 
1477         msleep(100);
1478         lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1479                    &portstat_reg.word0);
1480 
1481         /* verify if privileged for the request operation */
1482         if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1483             !bf_get(lpfc_sliport_status_err, &portstat_reg))
1484                 return -EPERM;
1485 
1486         /* wait for the SLI port firmware ready after firmware reset */
1487         for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1488                 msleep(10);
1489                 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1490                            &portstat_reg.word0);
1491                 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1492                         continue;
1493                 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1494                         continue;
1495                 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1496                         continue;
1497                 break;
1498         }
1499 
1500         if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1501                 return 0;
1502         else
1503                 return -EIO;
1504 }
1505 
1506 /**
1507  * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1508  * @phba: lpfc_hba pointer.
1509  *
1510  * Description:
1511  * Request SLI4 interface type-2 device to perform a physical register set
1512  * access.
1513  *
1514  * Returns:
1515  * zero for success
1516  **/
1517 static ssize_t
1518 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1519 {
1520         struct completion online_compl;
1521         struct pci_dev *pdev = phba->pcidev;
1522         uint32_t before_fc_flag;
1523         uint32_t sriov_nr_virtfn;
1524         uint32_t reg_val;
1525         int status = 0, rc = 0;
1526         int job_posted = 1, sriov_err;
1527 
1528         if (!phba->cfg_enable_hba_reset)
1529                 return -EACCES;
1530 
1531         if ((phba->sli_rev < LPFC_SLI_REV4) ||
1532             (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1533              LPFC_SLI_INTF_IF_TYPE_2))
1534                 return -EPERM;
1535 
1536         /* Keep state if we need to restore back */
1537         before_fc_flag = phba->pport->fc_flag;
1538         sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1539 
1540         /* Disable SR-IOV virtual functions if enabled */
1541         if (phba->cfg_sriov_nr_virtfn) {
1542                 pci_disable_sriov(pdev);
1543                 phba->cfg_sriov_nr_virtfn = 0;
1544         }
1545 
1546         if (opcode == LPFC_FW_DUMP)
1547                 phba->hba_flag |= HBA_FW_DUMP_OP;
1548 
1549         status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1550 
1551         if (status != 0) {
1552                 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1553                 return status;
1554         }
1555 
1556         /* wait for the device to be quiesced before firmware reset */
1557         msleep(100);
1558 
1559         reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1560                         LPFC_CTL_PDEV_CTL_OFFSET);
1561 
1562         if (opcode == LPFC_FW_DUMP)
1563                 reg_val |= LPFC_FW_DUMP_REQUEST;
1564         else if (opcode == LPFC_FW_RESET)
1565                 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1566         else if (opcode == LPFC_DV_RESET)
1567                 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1568 
1569         writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1570                LPFC_CTL_PDEV_CTL_OFFSET);
1571         /* flush */
1572         readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1573 
1574         /* delay driver action following IF_TYPE_2 reset */
1575         rc = lpfc_sli4_pdev_status_reg_wait(phba);
1576 
1577         if (rc == -EPERM) {
1578                 /* no privilege for reset */
1579                 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1580                                 "3150 No privilege to perform the requested "
1581                                 "access: x%x\n", reg_val);
1582         } else if (rc == -EIO) {
1583                 /* reset failed, there is nothing more we can do */
1584                 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1585                                 "3153 Fail to perform the requested "
1586                                 "access: x%x\n", reg_val);
1587                 return rc;
1588         }
1589 
1590         /* keep the original port state */
1591         if (before_fc_flag & FC_OFFLINE_MODE)
1592                 goto out;
1593 
1594         init_completion(&online_compl);
1595         job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1596                                            LPFC_EVT_ONLINE);
1597         if (!job_posted)
1598                 goto out;
1599 
1600         wait_for_completion(&online_compl);
1601 
1602 out:
1603         /* in any case, restore the virtual functions enabled as before */
1604         if (sriov_nr_virtfn) {
1605                 sriov_err =
1606                         lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1607                 if (!sriov_err)
1608                         phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1609         }
1610 
1611         /* return proper error code */
1612         if (!rc) {
1613                 if (!job_posted)
1614                         rc = -ENOMEM;
1615                 else if (status)
1616                         rc = -EIO;
1617         }
1618         return rc;
1619 }
1620 
1621 /**
1622  * lpfc_nport_evt_cnt_show - Return the number of nport events
1623  * @dev: class device that is converted into a Scsi_host.
1624  * @attr: device attribute, not used.
1625  * @buf: on return contains the ascii number of nport events.
1626  *
1627  * Returns: size of formatted string.
1628  **/
1629 static ssize_t
1630 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1631                         char *buf)
1632 {
1633         struct Scsi_Host  *shost = class_to_shost(dev);
1634         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1635         struct lpfc_hba   *phba = vport->phba;
1636 
1637         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1638 }
1639 
1640 static int
1641 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1642 {
1643         LPFC_MBOXQ_t *mbox = NULL;
1644         unsigned long val = 0;
1645         char *pval = 0;
1646         int rc = 0;
1647 
1648         if (!strncmp("enable", buff_out,
1649                                  strlen("enable"))) {
1650                 pval = buff_out + strlen("enable") + 1;
1651                 rc = kstrtoul(pval, 0, &val);
1652                 if (rc)
1653                         return rc; /* Invalid  number */
1654         } else if (!strncmp("disable", buff_out,
1655                                  strlen("disable"))) {
1656                 val = 0;
1657         } else {
1658                 return -EINVAL;  /* Invalid command */
1659         }
1660 
1661         switch (val) {
1662         case 0:
1663                 val = 0x0; /* Disable */
1664                 break;
1665         case 2:
1666                 val = 0x1; /* Enable two port trunk */
1667                 break;
1668         case 4:
1669                 val = 0x2; /* Enable four port trunk */
1670                 break;
1671         default:
1672                 return -EINVAL;
1673         }
1674 
1675         lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1676                         "0070 Set trunk mode with val %ld ", val);
1677 
1678         mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1679         if (!mbox)
1680                 return -ENOMEM;
1681 
1682         lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1683                          LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1684                          12, LPFC_SLI4_MBX_EMBED);
1685 
1686         bf_set(lpfc_mbx_set_trunk_mode,
1687                &mbox->u.mqe.un.set_trunk_mode,
1688                val);
1689         rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1690         if (rc)
1691                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1692                                 "0071 Set trunk mode failed with status: %d",
1693                                 rc);
1694         if (rc != MBX_TIMEOUT)
1695                 mempool_free(mbox, phba->mbox_mem_pool);
1696 
1697         return 0;
1698 }
1699 
1700 /**
1701  * lpfc_board_mode_show - Return the state of the board
1702  * @dev: class device that is converted into a Scsi_host.
1703  * @attr: device attribute, not used.
1704  * @buf: on return contains the state of the adapter.
1705  *
1706  * Returns: size of formatted string.
1707  **/
1708 static ssize_t
1709 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1710                      char *buf)
1711 {
1712         struct Scsi_Host  *shost = class_to_shost(dev);
1713         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1714         struct lpfc_hba   *phba = vport->phba;
1715         char  * state;
1716 
1717         if (phba->link_state == LPFC_HBA_ERROR)
1718                 state = "error";
1719         else if (phba->link_state == LPFC_WARM_START)
1720                 state = "warm start";
1721         else if (phba->link_state == LPFC_INIT_START)
1722                 state = "offline";
1723         else
1724                 state = "online";
1725 
1726         return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1727 }
1728 
1729 /**
1730  * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1731  * @dev: class device that is converted into a Scsi_host.
1732  * @attr: device attribute, not used.
1733  * @buf: containing one of the strings "online", "offline", "warm" or "error".
1734  * @count: unused variable.
1735  *
1736  * Returns:
1737  * -EACCES if enable hba reset not enabled
1738  * -EINVAL if the buffer does not contain a valid string (see above)
1739  * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1740  * buf length greater than zero indicates success
1741  **/
1742 static ssize_t
1743 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1744                       const char *buf, size_t count)
1745 {
1746         struct Scsi_Host  *shost = class_to_shost(dev);
1747         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1748         struct lpfc_hba   *phba = vport->phba;
1749         struct completion online_compl;
1750         char *board_mode_str = NULL;
1751         int status = 0;
1752         int rc;
1753 
1754         if (!phba->cfg_enable_hba_reset) {
1755                 status = -EACCES;
1756                 goto board_mode_out;
1757         }
1758 
1759         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1760                          "3050 lpfc_board_mode set to %s\n", buf);
1761 
1762         init_completion(&online_compl);
1763 
1764         if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1765                 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1766                                       LPFC_EVT_ONLINE);
1767                 if (rc == 0) {
1768                         status = -ENOMEM;
1769                         goto board_mode_out;
1770                 }
1771                 wait_for_completion(&online_compl);
1772                 if (status)
1773                         status = -EIO;
1774         } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1775                 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1776         else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1777                 if (phba->sli_rev == LPFC_SLI_REV4)
1778                         status = -EINVAL;
1779                 else
1780                         status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1781         else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1782                 if (phba->sli_rev == LPFC_SLI_REV4)
1783                         status = -EINVAL;
1784                 else
1785                         status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1786         else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1787                 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1788         else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1789                 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1790         else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1791                 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1792         else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1793                  == 0)
1794                 status = lpfc_reset_pci_bus(phba);
1795         else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1796                 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1797         else
1798                 status = -EINVAL;
1799 
1800 board_mode_out:
1801         if (!status)
1802                 return strlen(buf);
1803         else {
1804                 board_mode_str = strchr(buf, '\n');
1805                 if (board_mode_str)
1806                         *board_mode_str = '\0';
1807                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1808                                  "3097 Failed \"%s\", status(%d), "
1809                                  "fc_flag(x%x)\n",
1810                                  buf, status, phba->pport->fc_flag);
1811                 return status;
1812         }
1813 }
1814 
1815 /**
1816  * lpfc_get_hba_info - Return various bits of informaton about the adapter
1817  * @phba: pointer to the adapter structure.
1818  * @mxri: max xri count.
1819  * @axri: available xri count.
1820  * @mrpi: max rpi count.
1821  * @arpi: available rpi count.
1822  * @mvpi: max vpi count.
1823  * @avpi: available vpi count.
1824  *
1825  * Description:
1826  * If an integer pointer for an count is not null then the value for the
1827  * count is returned.
1828  *
1829  * Returns:
1830  * zero on error
1831  * one for success
1832  **/
1833 static int
1834 lpfc_get_hba_info(struct lpfc_hba *phba,
1835                   uint32_t *mxri, uint32_t *axri,
1836                   uint32_t *mrpi, uint32_t *arpi,
1837                   uint32_t *mvpi, uint32_t *avpi)
1838 {
1839         struct lpfc_mbx_read_config *rd_config;
1840         LPFC_MBOXQ_t *pmboxq;
1841         MAILBOX_t *pmb;
1842         int rc = 0;
1843         uint32_t max_vpi;
1844 
1845         /*
1846          * prevent udev from issuing mailbox commands until the port is
1847          * configured.
1848          */
1849         if (phba->link_state < LPFC_LINK_DOWN ||
1850             !phba->mbox_mem_pool ||
1851             (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1852                 return 0;
1853 
1854         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1855                 return 0;
1856 
1857         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1858         if (!pmboxq)
1859                 return 0;
1860         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1861 
1862         pmb = &pmboxq->u.mb;
1863         pmb->mbxCommand = MBX_READ_CONFIG;
1864         pmb->mbxOwner = OWN_HOST;
1865         pmboxq->ctx_buf = NULL;
1866 
1867         if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1868                 rc = MBX_NOT_FINISHED;
1869         else
1870                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1871 
1872         if (rc != MBX_SUCCESS) {
1873                 if (rc != MBX_TIMEOUT)
1874                         mempool_free(pmboxq, phba->mbox_mem_pool);
1875                 return 0;
1876         }
1877 
1878         if (phba->sli_rev == LPFC_SLI_REV4) {
1879                 rd_config = &pmboxq->u.mqe.un.rd_config;
1880                 if (mrpi)
1881                         *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1882                 if (arpi)
1883                         *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1884                                         phba->sli4_hba.max_cfg_param.rpi_used;
1885                 if (mxri)
1886                         *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1887                 if (axri)
1888                         *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1889                                         phba->sli4_hba.max_cfg_param.xri_used;
1890 
1891                 /* Account for differences with SLI-3.  Get vpi count from
1892                  * mailbox data and subtract one for max vpi value.
1893                  */
1894                 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1895                         (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1896 
1897                 /* Limit the max we support */
1898                 if (max_vpi > LPFC_MAX_VPI)
1899                         max_vpi = LPFC_MAX_VPI;
1900                 if (mvpi)
1901                         *mvpi = max_vpi;
1902                 if (avpi)
1903                         *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1904         } else {
1905                 if (mrpi)
1906                         *mrpi = pmb->un.varRdConfig.max_rpi;
1907                 if (arpi)
1908                         *arpi = pmb->un.varRdConfig.avail_rpi;
1909                 if (mxri)
1910                         *mxri = pmb->un.varRdConfig.max_xri;
1911                 if (axri)
1912                         *axri = pmb->un.varRdConfig.avail_xri;
1913                 if (mvpi)
1914                         *mvpi = pmb->un.varRdConfig.max_vpi;
1915                 if (avpi) {
1916                         /* avail_vpi is only valid if link is up and ready */
1917                         if (phba->link_state == LPFC_HBA_READY)
1918                                 *avpi = pmb->un.varRdConfig.avail_vpi;
1919                         else
1920                                 *avpi = pmb->un.varRdConfig.max_vpi;
1921                 }
1922         }
1923 
1924         mempool_free(pmboxq, phba->mbox_mem_pool);
1925         return 1;
1926 }
1927 
1928 /**
1929  * lpfc_max_rpi_show - Return maximum rpi
1930  * @dev: class device that is converted into a Scsi_host.
1931  * @attr: device attribute, not used.
1932  * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1933  *
1934  * Description:
1935  * Calls lpfc_get_hba_info() asking for just the mrpi count.
1936  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1937  * to "Unknown" and the buffer length is returned, therefore the caller
1938  * must check for "Unknown" in the buffer to detect a failure.
1939  *
1940  * Returns: size of formatted string.
1941  **/
1942 static ssize_t
1943 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1944                   char *buf)
1945 {
1946         struct Scsi_Host  *shost = class_to_shost(dev);
1947         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1948         struct lpfc_hba   *phba = vport->phba;
1949         uint32_t cnt;
1950 
1951         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1952                 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1953         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1954 }
1955 
1956 /**
1957  * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1958  * @dev: class device that is converted into a Scsi_host.
1959  * @attr: device attribute, not used.
1960  * @buf: containing the used rpi count in decimal or "Unknown".
1961  *
1962  * Description:
1963  * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1964  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1965  * to "Unknown" and the buffer length is returned, therefore the caller
1966  * must check for "Unknown" in the buffer to detect a failure.
1967  *
1968  * Returns: size of formatted string.
1969  **/
1970 static ssize_t
1971 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1972                    char *buf)
1973 {
1974         struct Scsi_Host  *shost = class_to_shost(dev);
1975         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1976         struct lpfc_hba   *phba = vport->phba;
1977         uint32_t cnt, acnt;
1978 
1979         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1980                 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1981         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1982 }
1983 
1984 /**
1985  * lpfc_max_xri_show - Return maximum xri
1986  * @dev: class device that is converted into a Scsi_host.
1987  * @attr: device attribute, not used.
1988  * @buf: on return contains the maximum xri count in decimal or "Unknown".
1989  *
1990  * Description:
1991  * Calls lpfc_get_hba_info() asking for just the mrpi count.
1992  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1993  * to "Unknown" and the buffer length is returned, therefore the caller
1994  * must check for "Unknown" in the buffer to detect a failure.
1995  *
1996  * Returns: size of formatted string.
1997  **/
1998 static ssize_t
1999 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2000                   char *buf)
2001 {
2002         struct Scsi_Host  *shost = class_to_shost(dev);
2003         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2004         struct lpfc_hba   *phba = vport->phba;
2005         uint32_t cnt;
2006 
2007         if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2008                 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2009         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2010 }
2011 
2012 /**
2013  * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2014  * @dev: class device that is converted into a Scsi_host.
2015  * @attr: device attribute, not used.
2016  * @buf: on return contains the used xri count in decimal or "Unknown".
2017  *
2018  * Description:
2019  * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2020  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2021  * to "Unknown" and the buffer length is returned, therefore the caller
2022  * must check for "Unknown" in the buffer to detect a failure.
2023  *
2024  * Returns: size of formatted string.
2025  **/
2026 static ssize_t
2027 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2028                    char *buf)
2029 {
2030         struct Scsi_Host  *shost = class_to_shost(dev);
2031         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2032         struct lpfc_hba   *phba = vport->phba;
2033         uint32_t cnt, acnt;
2034 
2035         if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2036                 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2037         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2038 }
2039 
2040 /**
2041  * lpfc_max_vpi_show - Return maximum vpi
2042  * @dev: class device that is converted into a Scsi_host.
2043  * @attr: device attribute, not used.
2044  * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2045  *
2046  * Description:
2047  * Calls lpfc_get_hba_info() asking for just the mvpi count.
2048  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2049  * to "Unknown" and the buffer length is returned, therefore the caller
2050  * must check for "Unknown" in the buffer to detect a failure.
2051  *
2052  * Returns: size of formatted string.
2053  **/
2054 static ssize_t
2055 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2056                   char *buf)
2057 {
2058         struct Scsi_Host  *shost = class_to_shost(dev);
2059         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2060         struct lpfc_hba   *phba = vport->phba;
2061         uint32_t cnt;
2062 
2063         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2064                 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2065         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2066 }
2067 
2068 /**
2069  * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2070  * @dev: class device that is converted into a Scsi_host.
2071  * @attr: device attribute, not used.
2072  * @buf: on return contains the used vpi count in decimal or "Unknown".
2073  *
2074  * Description:
2075  * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2076  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2077  * to "Unknown" and the buffer length is returned, therefore the caller
2078  * must check for "Unknown" in the buffer to detect a failure.
2079  *
2080  * Returns: size of formatted string.
2081  **/
2082 static ssize_t
2083 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2084                    char *buf)
2085 {
2086         struct Scsi_Host  *shost = class_to_shost(dev);
2087         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2088         struct lpfc_hba   *phba = vport->phba;
2089         uint32_t cnt, acnt;
2090 
2091         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2092                 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2093         return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2094 }
2095 
2096 /**
2097  * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2098  * @dev: class device that is converted into a Scsi_host.
2099  * @attr: device attribute, not used.
2100  * @buf: text that must be interpreted to determine if npiv is supported.
2101  *
2102  * Description:
2103  * Buffer will contain text indicating npiv is not suppoerted on the port,
2104  * the port is an NPIV physical port, or it is an npiv virtual port with
2105  * the id of the vport.
2106  *
2107  * Returns: size of formatted string.
2108  **/
2109 static ssize_t
2110 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2111                     char *buf)
2112 {
2113         struct Scsi_Host  *shost = class_to_shost(dev);
2114         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2115         struct lpfc_hba   *phba = vport->phba;
2116 
2117         if (!(phba->max_vpi))
2118                 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2119         if (vport->port_type == LPFC_PHYSICAL_PORT)
2120                 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2121         return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2122 }
2123 
2124 /**
2125  * lpfc_poll_show - Return text about poll support for the adapter
2126  * @dev: class device that is converted into a Scsi_host.
2127  * @attr: device attribute, not used.
2128  * @buf: on return contains the cfg_poll in hex.
2129  *
2130  * Notes:
2131  * cfg_poll should be a lpfc_polling_flags type.
2132  *
2133  * Returns: size of formatted string.
2134  **/
2135 static ssize_t
2136 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2137                char *buf)
2138 {
2139         struct Scsi_Host  *shost = class_to_shost(dev);
2140         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2141         struct lpfc_hba   *phba = vport->phba;
2142 
2143         return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2144 }
2145 
2146 /**
2147  * lpfc_poll_store - Set the value of cfg_poll for the adapter
2148  * @dev: class device that is converted into a Scsi_host.
2149  * @attr: device attribute, not used.
2150  * @buf: one or more lpfc_polling_flags values.
2151  * @count: not used.
2152  *
2153  * Notes:
2154  * buf contents converted to integer and checked for a valid value.
2155  *
2156  * Returns:
2157  * -EINVAL if the buffer connot be converted or is out of range
2158  * length of the buf on success
2159  **/
2160 static ssize_t
2161 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2162                 const char *buf, size_t count)
2163 {
2164         struct Scsi_Host  *shost = class_to_shost(dev);
2165         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2166         struct lpfc_hba   *phba = vport->phba;
2167         uint32_t creg_val;
2168         uint32_t old_val;
2169         int val=0;
2170 
2171         if (!isdigit(buf[0]))
2172                 return -EINVAL;
2173 
2174         if (sscanf(buf, "%i", &val) != 1)
2175                 return -EINVAL;
2176 
2177         if ((val & 0x3) != val)
2178                 return -EINVAL;
2179 
2180         if (phba->sli_rev == LPFC_SLI_REV4)
2181                 val = 0;
2182 
2183         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2184                 "3051 lpfc_poll changed from %d to %d\n",
2185                 phba->cfg_poll, val);
2186 
2187         spin_lock_irq(&phba->hbalock);
2188 
2189         old_val = phba->cfg_poll;
2190 
2191         if (val & ENABLE_FCP_RING_POLLING) {
2192                 if ((val & DISABLE_FCP_RING_INT) &&
2193                     !(old_val & DISABLE_FCP_RING_INT)) {
2194                         if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2195                                 spin_unlock_irq(&phba->hbalock);
2196                                 return -EINVAL;
2197                         }
2198                         creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2199                         writel(creg_val, phba->HCregaddr);
2200                         readl(phba->HCregaddr); /* flush */
2201 
2202                         lpfc_poll_start_timer(phba);
2203                 }
2204         } else if (val != 0x0) {
2205                 spin_unlock_irq(&phba->hbalock);
2206                 return -EINVAL;
2207         }
2208 
2209         if (!(val & DISABLE_FCP_RING_INT) &&
2210             (old_val & DISABLE_FCP_RING_INT))
2211         {
2212                 spin_unlock_irq(&phba->hbalock);
2213                 del_timer(&phba->fcp_poll_timer);
2214                 spin_lock_irq(&phba->hbalock);
2215                 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2216                         spin_unlock_irq(&phba->hbalock);
2217                         return -EINVAL;
2218                 }
2219                 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2220                 writel(creg_val, phba->HCregaddr);
2221                 readl(phba->HCregaddr); /* flush */
2222         }
2223 
2224         phba->cfg_poll = val;
2225 
2226         spin_unlock_irq(&phba->hbalock);
2227 
2228         return strlen(buf);
2229 }
2230 
2231 /**
2232  * lpfc_fips_level_show - Return the current FIPS level for the HBA
2233  * @dev: class unused variable.
2234  * @attr: device attribute, not used.
2235  * @buf: on return contains the module description text.
2236  *
2237  * Returns: size of formatted string.
2238  **/
2239 static ssize_t
2240 lpfc_fips_level_show(struct device *dev,  struct device_attribute *attr,
2241                      char *buf)
2242 {
2243         struct Scsi_Host  *shost = class_to_shost(dev);
2244         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2245         struct lpfc_hba   *phba = vport->phba;
2246 
2247         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
2248 }
2249 
2250 /**
2251  * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
2252  * @dev: class unused variable.
2253  * @attr: device attribute, not used.
2254  * @buf: on return contains the module description text.
2255  *
2256  * Returns: size of formatted string.
2257  **/
2258 static ssize_t
2259 lpfc_fips_rev_show(struct device *dev,  struct device_attribute *attr,
2260                    char *buf)
2261 {
2262         struct Scsi_Host  *shost = class_to_shost(dev);
2263         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2264         struct lpfc_hba   *phba = vport->phba;
2265 
2266         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2267 }
2268 
2269 /**
2270  * lpfc_dss_show - Return the current state of dss and the configured state
2271  * @dev: class converted to a Scsi_host structure.
2272  * @attr: device attribute, not used.
2273  * @buf: on return contains the formatted text.
2274  *
2275  * Returns: size of formatted string.
2276  **/
2277 static ssize_t
2278 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2279               char *buf)
2280 {
2281         struct Scsi_Host *shost = class_to_shost(dev);
2282         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2283         struct lpfc_hba   *phba = vport->phba;
2284 
2285         return scnprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2286                         (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2287                         (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2288                                 "" : "Not ");
2289 }
2290 
2291 /**
2292  * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2293  * @dev: class converted to a Scsi_host structure.
2294  * @attr: device attribute, not used.
2295  * @buf: on return contains the formatted support level.
2296  *
2297  * Description:
2298  * Returns the maximum number of virtual functions a physical function can
2299  * support, 0 will be returned if called on virtual function.
2300  *
2301  * Returns: size of formatted string.
2302  **/
2303 static ssize_t
2304 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2305                               struct device_attribute *attr,
2306                               char *buf)
2307 {
2308         struct Scsi_Host *shost = class_to_shost(dev);
2309         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2310         struct lpfc_hba *phba = vport->phba;
2311         uint16_t max_nr_virtfn;
2312 
2313         max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2314         return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2315 }
2316 
2317 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2318 {
2319         return val >= min && val <= max;
2320 }
2321 
2322 /**
2323  * lpfc_enable_bbcr_set: Sets an attribute value.
2324  * @phba: pointer the the adapter structure.
2325  * @val: integer attribute value.
2326  *
2327  * Description:
2328  * Validates the min and max values then sets the
2329  * adapter config field if in the valid range. prints error message
2330  * and does not set the parameter if invalid.
2331  *
2332  * Returns:
2333  * zero on success
2334  * -EINVAL if val is invalid
2335  */
2336 static ssize_t
2337 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2338 {
2339         if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2340                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2341                                 "3068 %s_enable_bbcr changed from %d to %d\n",
2342                                 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2343                 phba->cfg_enable_bbcr = val;
2344                 return 0;
2345         }
2346         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2347                         "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2348                         LPFC_DRIVER_NAME, val);
2349         return -EINVAL;
2350 }
2351 
2352 /**
2353  * lpfc_param_show - Return a cfg attribute value in decimal
2354  *
2355  * Description:
2356  * Macro that given an attr e.g. hba_queue_depth expands
2357  * into a function with the name lpfc_hba_queue_depth_show.
2358  *
2359  * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2360  * @dev: class device that is converted into a Scsi_host.
2361  * @attr: device attribute, not used.
2362  * @buf: on return contains the attribute value in decimal.
2363  *
2364  * Returns: size of formatted string.
2365  **/
2366 #define lpfc_param_show(attr)   \
2367 static ssize_t \
2368 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2369                    char *buf) \
2370 { \
2371         struct Scsi_Host  *shost = class_to_shost(dev);\
2372         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2373         struct lpfc_hba   *phba = vport->phba;\
2374         return scnprintf(buf, PAGE_SIZE, "%d\n",\
2375                         phba->cfg_##attr);\
2376 }
2377 
2378 /**
2379  * lpfc_param_hex_show - Return a cfg attribute value in hex
2380  *
2381  * Description:
2382  * Macro that given an attr e.g. hba_queue_depth expands
2383  * into a function with the name lpfc_hba_queue_depth_show
2384  *
2385  * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2386  * @dev: class device that is converted into a Scsi_host.
2387  * @attr: device attribute, not used.
2388  * @buf: on return contains the attribute value in hexadecimal.
2389  *
2390  * Returns: size of formatted string.
2391  **/
2392 #define lpfc_param_hex_show(attr)       \
2393 static ssize_t \
2394 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2395                    char *buf) \
2396 { \
2397         struct Scsi_Host  *shost = class_to_shost(dev);\
2398         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2399         struct lpfc_hba   *phba = vport->phba;\
2400         uint val = 0;\
2401         val = phba->cfg_##attr;\
2402         return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2403                         phba->cfg_##attr);\
2404 }
2405 
2406 /**
2407  * lpfc_param_init - Initializes a cfg attribute
2408  *
2409  * Description:
2410  * Macro that given an attr e.g. hba_queue_depth expands
2411  * into a function with the name lpfc_hba_queue_depth_init. The macro also
2412  * takes a default argument, a minimum and maximum argument.
2413  *
2414  * lpfc_##attr##_init: Initializes an attribute.
2415  * @phba: pointer the the adapter structure.
2416  * @val: integer attribute value.
2417  *
2418  * Validates the min and max values then sets the adapter config field
2419  * accordingly, or uses the default if out of range and prints an error message.
2420  *
2421  * Returns:
2422  * zero on success
2423  * -EINVAL if default used
2424  **/
2425 #define lpfc_param_init(attr, default, minval, maxval)  \
2426 static int \
2427 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2428 { \
2429         if (lpfc_rangecheck(val, minval, maxval)) {\
2430                 phba->cfg_##attr = val;\
2431                 return 0;\
2432         }\
2433         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2434                         "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2435                         "allowed range is ["#minval", "#maxval"]\n", val); \
2436         phba->cfg_##attr = default;\
2437         return -EINVAL;\
2438 }
2439 
2440 /**
2441  * lpfc_param_set - Set a cfg attribute value
2442  *
2443  * Description:
2444  * Macro that given an attr e.g. hba_queue_depth expands
2445  * into a function with the name lpfc_hba_queue_depth_set
2446  *
2447  * lpfc_##attr##_set: Sets an attribute value.
2448  * @phba: pointer the the adapter structure.
2449  * @val: integer attribute value.
2450  *
2451  * Description:
2452  * Validates the min and max values then sets the
2453  * adapter config field if in the valid range. prints error message
2454  * and does not set the parameter if invalid.
2455  *
2456  * Returns:
2457  * zero on success
2458  * -EINVAL if val is invalid
2459  **/
2460 #define lpfc_param_set(attr, default, minval, maxval)   \
2461 static int \
2462 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2463 { \
2464         if (lpfc_rangecheck(val, minval, maxval)) {\
2465                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2466                         "3052 lpfc_" #attr " changed from %d to %d\n", \
2467                         phba->cfg_##attr, val); \
2468                 phba->cfg_##attr = val;\
2469                 return 0;\
2470         }\
2471         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2472                         "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2473                         "allowed range is ["#minval", "#maxval"]\n", val); \
2474         return -EINVAL;\
2475 }
2476 
2477 /**
2478  * lpfc_param_store - Set a vport attribute value
2479  *
2480  * Description:
2481  * Macro that given an attr e.g. hba_queue_depth expands
2482  * into a function with the name lpfc_hba_queue_depth_store.
2483  *
2484  * lpfc_##attr##_store: Set an sttribute value.
2485  * @dev: class device that is converted into a Scsi_host.
2486  * @attr: device attribute, not used.
2487  * @buf: contains the attribute value in ascii.
2488  * @count: not used.
2489  *
2490  * Description:
2491  * Convert the ascii text number to an integer, then
2492  * use the lpfc_##attr##_set function to set the value.
2493  *
2494  * Returns:
2495  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2496  * length of buffer upon success.
2497  **/
2498 #define lpfc_param_store(attr)  \
2499 static ssize_t \
2500 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2501                     const char *buf, size_t count) \
2502 { \
2503         struct Scsi_Host  *shost = class_to_shost(dev);\
2504         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2505         struct lpfc_hba   *phba = vport->phba;\
2506         uint val = 0;\
2507         if (!isdigit(buf[0]))\
2508                 return -EINVAL;\
2509         if (sscanf(buf, "%i", &val) != 1)\
2510                 return -EINVAL;\
2511         if (lpfc_##attr##_set(phba, val) == 0) \
2512                 return strlen(buf);\
2513         else \
2514                 return -EINVAL;\
2515 }
2516 
2517 /**
2518  * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2519  *
2520  * Description:
2521  * Macro that given an attr e.g. hba_queue_depth expands
2522  * into a function with the name lpfc_hba_queue_depth_show
2523  *
2524  * lpfc_##attr##_show: prints the attribute value in decimal.
2525  * @dev: class device that is converted into a Scsi_host.
2526  * @attr: device attribute, not used.
2527  * @buf: on return contains the attribute value in decimal.
2528  *
2529  * Returns: length of formatted string.
2530  **/
2531 #define lpfc_vport_param_show(attr)     \
2532 static ssize_t \
2533 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2534                    char *buf) \
2535 { \
2536         struct Scsi_Host  *shost = class_to_shost(dev);\
2537         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2538         return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2539 }
2540 
2541 /**
2542  * lpfc_vport_param_hex_show - Return hex formatted attribute value
2543  *
2544  * Description:
2545  * Macro that given an attr e.g.
2546  * hba_queue_depth expands into a function with the name
2547  * lpfc_hba_queue_depth_show
2548  *
2549  * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2550  * @dev: class device that is converted into a Scsi_host.
2551  * @attr: device attribute, not used.
2552  * @buf: on return contains the attribute value in hexadecimal.
2553  *
2554  * Returns: length of formatted string.
2555  **/
2556 #define lpfc_vport_param_hex_show(attr) \
2557 static ssize_t \
2558 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2559                    char *buf) \
2560 { \
2561         struct Scsi_Host  *shost = class_to_shost(dev);\
2562         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2563         return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2564 }
2565 
2566 /**
2567  * lpfc_vport_param_init - Initialize a vport cfg attribute
2568  *
2569  * Description:
2570  * Macro that given an attr e.g. hba_queue_depth expands
2571  * into a function with the name lpfc_hba_queue_depth_init. The macro also
2572  * takes a default argument, a minimum and maximum argument.
2573  *
2574  * lpfc_##attr##_init: validates the min and max values then sets the
2575  * adapter config field accordingly, or uses the default if out of range
2576  * and prints an error message.
2577  * @phba: pointer the the adapter structure.
2578  * @val: integer attribute value.
2579  *
2580  * Returns:
2581  * zero on success
2582  * -EINVAL if default used
2583  **/
2584 #define lpfc_vport_param_init(attr, default, minval, maxval)    \
2585 static int \
2586 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2587 { \
2588         if (lpfc_rangecheck(val, minval, maxval)) {\
2589                 vport->cfg_##attr = val;\
2590                 return 0;\
2591         }\
2592         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2593                          "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2594                          "allowed range is ["#minval", "#maxval"]\n", val); \
2595         vport->cfg_##attr = default;\
2596         return -EINVAL;\
2597 }
2598 
2599 /**
2600  * lpfc_vport_param_set - Set a vport cfg attribute
2601  *
2602  * Description:
2603  * Macro that given an attr e.g. hba_queue_depth expands
2604  * into a function with the name lpfc_hba_queue_depth_set
2605  *
2606  * lpfc_##attr##_set: validates the min and max values then sets the
2607  * adapter config field if in the valid range. prints error message
2608  * and does not set the parameter if invalid.
2609  * @phba: pointer the the adapter structure.
2610  * @val:        integer attribute value.
2611  *
2612  * Returns:
2613  * zero on success
2614  * -EINVAL if val is invalid
2615  **/
2616 #define lpfc_vport_param_set(attr, default, minval, maxval)     \
2617 static int \
2618 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2619 { \
2620         if (lpfc_rangecheck(val, minval, maxval)) {\
2621                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2622                         "3053 lpfc_" #attr \
2623                         " changed from %d (x%x) to %d (x%x)\n", \
2624                         vport->cfg_##attr, vport->cfg_##attr, \
2625                         val, val); \
2626                 vport->cfg_##attr = val;\
2627                 return 0;\
2628         }\
2629         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2630                          "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2631                          "allowed range is ["#minval", "#maxval"]\n", val); \
2632         return -EINVAL;\
2633 }
2634 
2635 /**
2636  * lpfc_vport_param_store - Set a vport attribute
2637  *
2638  * Description:
2639  * Macro that given an attr e.g. hba_queue_depth
2640  * expands into a function with the name lpfc_hba_queue_depth_store
2641  *
2642  * lpfc_##attr##_store: convert the ascii text number to an integer, then
2643  * use the lpfc_##attr##_set function to set the value.
2644  * @cdev: class device that is converted into a Scsi_host.
2645  * @buf:        contains the attribute value in decimal.
2646  * @count: not used.
2647  *
2648  * Returns:
2649  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2650  * length of buffer upon success.
2651  **/
2652 #define lpfc_vport_param_store(attr)    \
2653 static ssize_t \
2654 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2655                     const char *buf, size_t count) \
2656 { \
2657         struct Scsi_Host  *shost = class_to_shost(dev);\
2658         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2659         uint val = 0;\
2660         if (!isdigit(buf[0]))\
2661                 return -EINVAL;\
2662         if (sscanf(buf, "%i", &val) != 1)\
2663                 return -EINVAL;\
2664         if (lpfc_##attr##_set(vport, val) == 0) \
2665                 return strlen(buf);\
2666         else \
2667                 return -EINVAL;\
2668 }
2669 
2670 
2671 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2672 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2673 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2674 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2675 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2676 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2677 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2678 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2679 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2680 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2681 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2682 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2683 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2684 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2685 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2686                 lpfc_link_state_store);
2687 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2688                    lpfc_option_rom_version_show, NULL);
2689 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2690                    lpfc_num_discovered_ports_show, NULL);
2691 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2692 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2693 static DEVICE_ATTR_RO(lpfc_drvr_version);
2694 static DEVICE_ATTR_RO(lpfc_enable_fip);
2695 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2696                    lpfc_board_mode_show, lpfc_board_mode_store);
2697 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2698 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2699 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2700 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2701 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2702 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2703 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2704 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2705 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2706 static DEVICE_ATTR_RO(lpfc_fips_level);
2707 static DEVICE_ATTR_RO(lpfc_fips_rev);
2708 static DEVICE_ATTR_RO(lpfc_dss);
2709 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2710 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2711 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2712                    NULL);
2713 
2714 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2715 #define WWN_SZ 8
2716 /**
2717  * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2718  * @buf: WWN string.
2719  * @cnt: Length of string.
2720  * @wwn: Array to receive converted wwn value.
2721  *
2722  * Returns:
2723  * -EINVAL if the buffer does not contain a valid wwn
2724  * 0 success
2725  **/
2726 static size_t
2727 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2728 {
2729         unsigned int i, j;
2730 
2731         /* Count may include a LF at end of string */
2732         if (buf[cnt-1] == '\n')
2733                 cnt--;
2734 
2735         if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2736             ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2737                 return -EINVAL;
2738 
2739         memset(wwn, 0, WWN_SZ);
2740 
2741         /* Validate and store the new name */
2742         for (i = 0, j = 0; i < 16; i++) {
2743                 if ((*buf >= 'a') && (*buf <= 'f'))
2744                         j = ((j << 4) | ((*buf++ - 'a') + 10));
2745                 else if ((*buf >= 'A') && (*buf <= 'F'))
2746                         j = ((j << 4) | ((*buf++ - 'A') + 10));
2747                 else if ((*buf >= '0') && (*buf <= '9'))
2748                         j = ((j << 4) | (*buf++ - '0'));
2749                 else
2750                         return -EINVAL;
2751                 if (i % 2) {
2752                         wwn[i/2] = j & 0xff;
2753                         j = 0;
2754                 }
2755         }
2756         return 0;
2757 }
2758 /**
2759  * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2760  * @dev: class device that is converted into a Scsi_host.
2761  * @attr: device attribute, not used.
2762  * @buf: containing the string lpfc_soft_wwn_key.
2763  * @count: must be size of lpfc_soft_wwn_key.
2764  *
2765  * Returns:
2766  * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2767  * length of buf indicates success
2768  **/
2769 static ssize_t
2770 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2771                            const char *buf, size_t count)
2772 {
2773         struct Scsi_Host  *shost = class_to_shost(dev);
2774         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2775         struct lpfc_hba   *phba = vport->phba;
2776         unsigned int cnt = count;
2777         uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2778         u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2779 
2780         /*
2781          * We're doing a simple sanity check for soft_wwpn setting.
2782          * We require that the user write a specific key to enable
2783          * the soft_wwpn attribute to be settable. Once the attribute
2784          * is written, the enable key resets. If further updates are
2785          * desired, the key must be written again to re-enable the
2786          * attribute.
2787          *
2788          * The "key" is not secret - it is a hardcoded string shown
2789          * here. The intent is to protect against the random user or
2790          * application that is just writing attributes.
2791          */
2792         if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2793                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2794                                  "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2795                                  " be enabled: fawwpn is enabled\n");
2796                 return -EINVAL;
2797         }
2798 
2799         /* count may include a LF at end of string */
2800         if (buf[cnt-1] == '\n')
2801                 cnt--;
2802 
2803         if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2804             (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2805                 return -EINVAL;
2806 
2807         phba->soft_wwn_enable = 1;
2808 
2809         dev_printk(KERN_WARNING, &phba->pcidev->dev,
2810                    "lpfc%d: soft_wwpn assignment has been enabled.\n",
2811                    phba->brd_no);
2812         dev_printk(KERN_WARNING, &phba->pcidev->dev,
2813                    "  The soft_wwpn feature is not supported by Broadcom.");
2814 
2815         return count;
2816 }
2817 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2818 
2819 /**
2820  * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2821  * @dev: class device that is converted into a Scsi_host.
2822  * @attr: device attribute, not used.
2823  * @buf: on return contains the wwpn in hexadecimal.
2824  *
2825  * Returns: size of formatted string.
2826  **/
2827 static ssize_t
2828 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2829                     char *buf)
2830 {
2831         struct Scsi_Host  *shost = class_to_shost(dev);
2832         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2833         struct lpfc_hba   *phba = vport->phba;
2834 
2835         return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2836                         (unsigned long long)phba->cfg_soft_wwpn);
2837 }
2838 
2839 /**
2840  * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2841  * @dev class device that is converted into a Scsi_host.
2842  * @attr: device attribute, not used.
2843  * @buf: contains the wwpn in hexadecimal.
2844  * @count: number of wwpn bytes in buf
2845  *
2846  * Returns:
2847  * -EACCES hba reset not enabled, adapter over temp
2848  * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2849  * -EIO error taking adapter offline or online
2850  * value of count on success
2851  **/
2852 static ssize_t
2853 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2854                      const char *buf, size_t count)
2855 {
2856         struct Scsi_Host  *shost = class_to_shost(dev);
2857         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2858         struct lpfc_hba   *phba = vport->phba;
2859         struct completion online_compl;
2860         int stat1 = 0, stat2 = 0;
2861         unsigned int cnt = count;
2862         u8 wwpn[WWN_SZ];
2863         int rc;
2864 
2865         if (!phba->cfg_enable_hba_reset)
2866                 return -EACCES;
2867         spin_lock_irq(&phba->hbalock);
2868         if (phba->over_temp_state == HBA_OVER_TEMP) {
2869                 spin_unlock_irq(&phba->hbalock);
2870                 return -EACCES;
2871         }
2872         spin_unlock_irq(&phba->hbalock);
2873         /* count may include a LF at end of string */
2874         if (buf[cnt-1] == '\n')
2875                 cnt--;
2876 
2877         if (!phba->soft_wwn_enable)
2878                 return -EINVAL;
2879 
2880         /* lock setting wwpn, wwnn down */
2881         phba->soft_wwn_enable = 0;
2882 
2883         rc = lpfc_wwn_set(buf, cnt, wwpn);
2884         if (rc) {
2885                 /* not able to set wwpn, unlock it */
2886                 phba->soft_wwn_enable = 1;
2887                 return rc;
2888         }
2889 
2890         phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2891         fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2892         if (phba->cfg_soft_wwnn)
2893                 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2894 
2895         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2896                    "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2897 
2898         stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2899         if (stat1)
2900                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2901                                 "0463 lpfc_soft_wwpn attribute set failed to "
2902                                 "reinit adapter - %d\n", stat1);
2903         init_completion(&online_compl);
2904         rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2905                                    LPFC_EVT_ONLINE);
2906         if (rc == 0)
2907                 return -ENOMEM;
2908 
2909         wait_for_completion(&online_compl);
2910         if (stat2)
2911                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2912                                 "0464 lpfc_soft_wwpn attribute set failed to "
2913                                 "reinit adapter - %d\n", stat2);
2914         return (stat1 || stat2) ? -EIO : count;
2915 }
2916 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2917 
2918 /**
2919  * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2920  * @dev: class device that is converted into a Scsi_host.
2921  * @attr: device attribute, not used.
2922  * @buf: on return contains the wwnn in hexadecimal.
2923  *
2924  * Returns: size of formatted string.
2925  **/
2926 static ssize_t
2927 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2928                     char *buf)
2929 {
2930         struct Scsi_Host *shost = class_to_shost(dev);
2931         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2932         return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2933                         (unsigned long long)phba->cfg_soft_wwnn);
2934 }
2935 
2936 /**
2937  * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2938  * @cdev: class device that is converted into a Scsi_host.
2939  * @buf: contains the ww node name in hexadecimal.
2940  * @count: number of wwnn bytes in buf.
2941  *
2942  * Returns:
2943  * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2944  * value of count on success
2945  **/
2946 static ssize_t
2947 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2948                      const char *buf, size_t count)
2949 {
2950         struct Scsi_Host *shost = class_to_shost(dev);
2951         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2952         unsigned int cnt = count;
2953         u8 wwnn[WWN_SZ];
2954         int rc;
2955 
2956         /* count may include a LF at end of string */
2957         if (buf[cnt-1] == '\n')
2958                 cnt--;
2959 
2960         if (!phba->soft_wwn_enable)
2961                 return -EINVAL;
2962 
2963         rc = lpfc_wwn_set(buf, cnt, wwnn);
2964         if (rc) {
2965                 /* Allow wwnn to be set many times, as long as the enable
2966                  * is set. However, once the wwpn is set, everything locks.
2967                  */
2968                 return rc;
2969         }
2970 
2971         phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2972 
2973         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2974                    "lpfc%d: soft_wwnn set. Value will take effect upon "
2975                    "setting of the soft_wwpn\n", phba->brd_no);
2976 
2977         return count;
2978 }
2979 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2980 
2981 /**
2982  * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2983  *                    Optimized Access Storage (OAS) operations.
2984  * @dev: class device that is converted into a Scsi_host.
2985  * @attr: device attribute, not used.
2986  * @buf: buffer for passing information.
2987  *
2988  * Returns:
2989  * value of count
2990  **/
2991 static ssize_t
2992 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2993                   char *buf)
2994 {
2995         struct Scsi_Host *shost = class_to_shost(dev);
2996         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2997 
2998         return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2999                         wwn_to_u64(phba->cfg_oas_tgt_wwpn));
3000 }
3001 
3002 /**
3003  * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
3004  *                    Optimized Access Storage (OAS) operations.
3005  * @dev: class device that is converted into a Scsi_host.
3006  * @attr: device attribute, not used.
3007  * @buf: buffer for passing information.
3008  * @count: Size of the data buffer.
3009  *
3010  * Returns:
3011  * -EINVAL count is invalid, invalid wwpn byte invalid
3012  * -EPERM oas is not supported by hba
3013  * value of count on success
3014  **/
3015 static ssize_t
3016 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
3017                    const char *buf, size_t count)
3018 {
3019         struct Scsi_Host *shost = class_to_shost(dev);
3020         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3021         unsigned int cnt = count;
3022         uint8_t wwpn[WWN_SZ];
3023         int rc;
3024 
3025         if (!phba->cfg_fof)
3026                 return -EPERM;
3027 
3028         /* count may include a LF at end of string */
3029         if (buf[cnt-1] == '\n')
3030                 cnt--;
3031 
3032         rc = lpfc_wwn_set(buf, cnt, wwpn);
3033         if (rc)
3034                 return rc;
3035 
3036         memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3037         memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3038         if (wwn_to_u64(wwpn) == 0)
3039                 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
3040         else
3041                 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
3042         phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3043         phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3044         return count;
3045 }
3046 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3047                    lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3048 
3049 /**
3050  * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3051  *                    Optimized Access Storage (OAS) operations.
3052  * @dev: class device that is converted into a Scsi_host.
3053  * @attr: device attribute, not used.
3054  * @buf: buffer for passing information.
3055  *
3056  * Returns:
3057  * value of count
3058  **/
3059 static ssize_t
3060 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3061                        char *buf)
3062 {
3063         struct Scsi_Host *shost = class_to_shost(dev);
3064         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3065 
3066         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3067 }
3068 
3069 /**
3070  * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3071  *                    Optimized Access Storage (OAS) operations.
3072  * @dev: class device that is converted into a Scsi_host.
3073  * @attr: device attribute, not used.
3074  * @buf: buffer for passing information.
3075  * @count: Size of the data buffer.
3076  *
3077  * Returns:
3078  * -EINVAL count is invalid, invalid wwpn byte invalid
3079  * -EPERM oas is not supported by hba
3080  * value of count on success
3081  **/
3082 static ssize_t
3083 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3084                         const char *buf, size_t count)
3085 {
3086         struct Scsi_Host *shost = class_to_shost(dev);
3087         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3088         unsigned int cnt = count;
3089         unsigned long val;
3090         int ret;
3091 
3092         if (!phba->cfg_fof)
3093                 return -EPERM;
3094 
3095         /* count may include a LF at end of string */
3096         if (buf[cnt-1] == '\n')
3097                 cnt--;
3098 
3099         ret = kstrtoul(buf, 0, &val);
3100         if (ret || (val > 0x7f))
3101                 return -EINVAL;
3102 
3103         if (val)
3104                 phba->cfg_oas_priority = (uint8_t)val;
3105         else
3106                 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3107         return count;
3108 }
3109 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3110                    lpfc_oas_priority_show, lpfc_oas_priority_store);
3111 
3112 /**
3113  * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3114  *                    for Optimized Access Storage (OAS) operations.
3115  * @dev: class device that is converted into a Scsi_host.
3116  * @attr: device attribute, not used.
3117  * @buf: buffer for passing information.
3118  *
3119  * Returns:
3120  * value of count on success
3121  **/
3122 static ssize_t
3123 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3124                   char *buf)
3125 {
3126         struct Scsi_Host *shost = class_to_shost(dev);
3127         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3128 
3129         return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3130                         wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3131 }
3132 
3133 /**
3134  * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3135  *                    for Optimized Access Storage (OAS) operations.
3136  * @dev: class device that is converted into a Scsi_host.
3137  * @attr: device attribute, not used.
3138  * @buf: buffer for passing information.
3139  * @count: Size of the data buffer.
3140  *
3141  * Returns:
3142  * -EINVAL count is invalid, invalid wwpn byte invalid
3143  * -EPERM oas is not supported by hba
3144  * value of count on success
3145  **/
3146 static ssize_t
3147 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3148                    const char *buf, size_t count)
3149 {
3150         struct Scsi_Host *shost = class_to_shost(dev);
3151         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3152         unsigned int cnt = count;
3153         uint8_t wwpn[WWN_SZ];
3154         int rc;
3155 
3156         if (!phba->cfg_fof)
3157                 return -EPERM;
3158 
3159         /* count may include a LF at end of string */
3160         if (buf[cnt-1] == '\n')
3161                 cnt--;
3162 
3163         rc = lpfc_wwn_set(buf, cnt, wwpn);
3164         if (rc)
3165                 return rc;
3166 
3167         memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3168         memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3169         if (wwn_to_u64(wwpn) == 0)
3170                 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3171         else
3172                 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3173         phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3174         if (phba->cfg_oas_priority == 0)
3175                 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3176         phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3177         return count;
3178 }
3179 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3180                    lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3181 
3182 /**
3183  * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3184  *                          of whether luns will be enabled or disabled
3185  *                          for Optimized Access Storage (OAS) operations.
3186  * @dev: class device that is converted into a Scsi_host.
3187  * @attr: device attribute, not used.
3188  * @buf: buffer for passing information.
3189  *
3190  * Returns:
3191  * size of formatted string.
3192  **/
3193 static ssize_t
3194 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3195                         char *buf)
3196 {
3197         struct Scsi_Host *shost = class_to_shost(dev);
3198         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3199 
3200         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3201 }
3202 
3203 /**
3204  * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3205  *                          of whether luns will be enabled or disabled
3206  *                          for Optimized Access Storage (OAS) operations.
3207  * @dev: class device that is converted into a Scsi_host.
3208  * @attr: device attribute, not used.
3209  * @buf: buffer for passing information.
3210  * @count: Size of the data buffer.
3211  *
3212  * Returns:
3213  * -EINVAL count is invalid, invalid wwpn byte invalid
3214  * -EPERM oas is not supported by hba
3215  * value of count on success
3216  **/
3217 static ssize_t
3218 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3219                          const char *buf, size_t count)
3220 {
3221         struct Scsi_Host *shost = class_to_shost(dev);
3222         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3223         int val = 0;
3224 
3225         if (!phba->cfg_fof)
3226                 return -EPERM;
3227 
3228         if (!isdigit(buf[0]))
3229                 return -EINVAL;
3230 
3231         if (sscanf(buf, "%i", &val) != 1)
3232                 return -EINVAL;
3233 
3234         if ((val != 0) && (val != 1))
3235                 return -EINVAL;
3236 
3237         phba->cfg_oas_lun_state = val;
3238         return strlen(buf);
3239 }
3240 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3241                    lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3242 
3243 /**
3244  * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3245  *                          Storage (OAS) lun returned by the
3246  *                          lpfc_oas_lun_show function.
3247  * @dev: class device that is converted into a Scsi_host.
3248  * @attr: device attribute, not used.
3249  * @buf: buffer for passing information.
3250  *
3251  * Returns:
3252  * size of formatted string.
3253  **/
3254 static ssize_t
3255 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3256                          char *buf)
3257 {
3258         struct Scsi_Host *shost = class_to_shost(dev);
3259         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3260 
3261         if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3262                 return -EFAULT;
3263 
3264         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3265 }
3266 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3267                    lpfc_oas_lun_status_show, NULL);
3268 
3269 
3270 /**
3271  * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3272  *                         (OAS) operations.
3273  * @phba: lpfc_hba pointer.
3274  * @ndlp: pointer to fcp target node.
3275  * @lun: the fc lun for setting oas state.
3276  * @oas_state: the oas state to be set to the lun.
3277  *
3278  * Returns:
3279  * SUCCESS : 0
3280  * -EPERM OAS is not enabled or not supported by this port.
3281  *
3282  */
3283 static size_t
3284 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3285                        uint8_t tgt_wwpn[], uint64_t lun,
3286                        uint32_t oas_state, uint8_t pri)
3287 {
3288 
3289         int rc = 0;
3290 
3291         if (!phba->cfg_fof)
3292                 return -EPERM;
3293 
3294         if (oas_state) {
3295                 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3296                                          (struct lpfc_name *)tgt_wwpn,
3297                                          lun, pri))
3298                         rc = -ENOMEM;
3299         } else {
3300                 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3301                                      (struct lpfc_name *)tgt_wwpn, lun, pri);
3302         }
3303         return rc;
3304 
3305 }
3306 
3307 /**
3308  * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3309  *                        Access Storage (OAS) operations.
3310  * @phba: lpfc_hba pointer.
3311  * @vpt_wwpn: wwpn of the vport associated with the returned lun
3312  * @tgt_wwpn: wwpn of the target associated with the returned lun
3313  * @lun_status: status of the lun returned lun
3314  *
3315  * Returns the first or next lun enabled for OAS operations for the vport/target
3316  * specified.  If a lun is found, its vport wwpn, target wwpn and status is
3317  * returned.  If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3318  *
3319  * Return:
3320  * lun that is OAS enabled for the vport/target
3321  * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3322  */
3323 static uint64_t
3324 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3325                       uint8_t tgt_wwpn[], uint32_t *lun_status,
3326                       uint32_t *lun_pri)
3327 {
3328         uint64_t found_lun;
3329 
3330         if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3331                 return NOT_OAS_ENABLED_LUN;
3332         if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3333                                    phba->sli4_hba.oas_next_vpt_wwpn,
3334                                    (struct lpfc_name *)
3335                                    phba->sli4_hba.oas_next_tgt_wwpn,
3336                                    &phba->sli4_hba.oas_next_lun,
3337                                    (struct lpfc_name *)vpt_wwpn,
3338                                    (struct lpfc_name *)tgt_wwpn,
3339                                    &found_lun, lun_status, lun_pri))
3340                 return found_lun;
3341         else
3342                 return NOT_OAS_ENABLED_LUN;
3343 }
3344 
3345 /**
3346  * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3347  * @phba: lpfc_hba pointer.
3348  * @vpt_wwpn: vport wwpn by reference.
3349  * @tgt_wwpn: target wwpn by reference.
3350  * @lun: the fc lun for setting oas state.
3351  * @oas_state: the oas state to be set to the oas_lun.
3352  *
3353  * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3354  * a lun for OAS operations.
3355  *
3356  * Return:
3357  * SUCCESS: 0
3358  * -ENOMEM: failed to enable an lun for OAS operations
3359  * -EPERM: OAS is not enabled
3360  */
3361 static ssize_t
3362 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3363                           uint8_t tgt_wwpn[], uint64_t lun,
3364                           uint32_t oas_state, uint8_t pri)
3365 {
3366 
3367         int rc;
3368 
3369         rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3370                                     oas_state, pri);
3371         return rc;
3372 }
3373 
3374 /**
3375  * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3376  * @dev: class device that is converted into a Scsi_host.
3377  * @attr: device attribute, not used.
3378  * @buf: buffer for passing information.
3379  *
3380  * This routine returns a lun enabled for OAS each time the function
3381  * is called.
3382  *
3383  * Returns:
3384  * SUCCESS: size of formatted string.
3385  * -EFAULT: target or vport wwpn was not set properly.
3386  * -EPERM: oas is not enabled.
3387  **/
3388 static ssize_t
3389 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3390                   char *buf)
3391 {
3392         struct Scsi_Host *shost = class_to_shost(dev);
3393         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3394 
3395         uint64_t oas_lun;
3396         int len = 0;
3397 
3398         if (!phba->cfg_fof)
3399                 return -EPERM;
3400 
3401         if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3402                 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3403                         return -EFAULT;
3404 
3405         if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3406                 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3407                         return -EFAULT;
3408 
3409         oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3410                                         phba->cfg_oas_tgt_wwpn,
3411                                         &phba->cfg_oas_lun_status,
3412                                         &phba->cfg_oas_priority);
3413         if (oas_lun != NOT_OAS_ENABLED_LUN)
3414                 phba->cfg_oas_flags |= OAS_LUN_VALID;
3415 
3416         len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3417 
3418         return len;
3419 }
3420 
3421 /**
3422  * lpfc_oas_lun_store - Sets the OAS state for lun
3423  * @dev: class device that is converted into a Scsi_host.
3424  * @attr: device attribute, not used.
3425  * @buf: buffer for passing information.
3426  *
3427  * This function sets the OAS state for lun.  Before this function is called,
3428  * the vport wwpn, target wwpn, and oas state need to be set.
3429  *
3430  * Returns:
3431  * SUCCESS: size of formatted string.
3432  * -EFAULT: target or vport wwpn was not set properly.
3433  * -EPERM: oas is not enabled.
3434  * size of formatted string.
3435  **/
3436 static ssize_t
3437 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3438                    const char *buf, size_t count)
3439 {
3440         struct Scsi_Host *shost = class_to_shost(dev);
3441         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3442         uint64_t scsi_lun;
3443         uint32_t pri;
3444         ssize_t rc;
3445 
3446         if (!phba->cfg_fof)
3447                 return -EPERM;
3448 
3449         if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3450                 return -EFAULT;
3451 
3452         if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3453                 return -EFAULT;
3454 
3455         if (!isdigit(buf[0]))
3456                 return -EINVAL;
3457 
3458         if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3459                 return -EINVAL;
3460 
3461         pri = phba->cfg_oas_priority;
3462         if (pri == 0)
3463                 pri = phba->cfg_XLanePriority;
3464 
3465         lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3466                         "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3467                         "priority 0x%x with oas state %d\n",
3468                         wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3469                         wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3470                         pri, phba->cfg_oas_lun_state);
3471 
3472         rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3473                                        phba->cfg_oas_tgt_wwpn, scsi_lun,
3474                                        phba->cfg_oas_lun_state, pri);
3475         if (rc)
3476                 return rc;
3477 
3478         return count;
3479 }
3480 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3481                    lpfc_oas_lun_show, lpfc_oas_lun_store);
3482 
3483 int lpfc_enable_nvmet_cnt;
3484 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3485         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3486         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3487 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3488 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3489 
3490 static int lpfc_poll = 0;
3491 module_param(lpfc_poll, int, S_IRUGO);
3492 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3493                  " 0 - none,"
3494                  " 1 - poll with interrupts enabled"
3495                  " 3 - poll and disable FCP ring interrupts");
3496 
3497 static DEVICE_ATTR_RW(lpfc_poll);
3498 
3499 int lpfc_no_hba_reset_cnt;
3500 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3501         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3502 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3503 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3504 
3505 LPFC_ATTR(sli_mode, 0, 0, 3,
3506         "SLI mode selector:"
3507         " 0 - auto (SLI-3 if supported),"
3508         " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3509         " 3 - select SLI-3");
3510 
3511 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3512         "Enable NPIV functionality");
3513 
3514 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3515         "FCF Fast failover=1 Priority failover=2");
3516 
3517 /*
3518 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3519 #       0x0 = disabled, XRI/OXID use not tracked.
3520 #       0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3521 #       0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3522 */
3523 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3524         "Enable RRQ functionality");
3525 
3526 /*
3527 # lpfc_suppress_link_up:  Bring link up at initialization
3528 #            0x0  = bring link up (issue MBX_INIT_LINK)
3529 #            0x1  = do NOT bring link up at initialization(MBX_INIT_LINK)
3530 #            0x2  = never bring up link
3531 # Default value is 0.
3532 */
3533 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3534                 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3535                 "Suppress Link Up at initialization");
3536 /*
3537 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3538 #       1 - (1024)
3539 #       2 - (2048)
3540 #       3 - (3072)
3541 #       4 - (4096)
3542 #       5 - (5120)
3543 */
3544 static ssize_t
3545 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3546 {
3547         struct Scsi_Host  *shost = class_to_shost(dev);
3548         struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3549 
3550         return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3551 }
3552 
3553 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3554                          lpfc_iocb_hw_show, NULL);
3555 static ssize_t
3556 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3557 {
3558         struct Scsi_Host  *shost = class_to_shost(dev);
3559         struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3560         struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3561 
3562         return scnprintf(buf, PAGE_SIZE, "%d\n",
3563                         pring ? pring->txq_max : 0);
3564 }
3565 
3566 static DEVICE_ATTR(txq_hw, S_IRUGO,
3567                          lpfc_txq_hw_show, NULL);
3568 static ssize_t
3569 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3570  char *buf)
3571 {
3572         struct Scsi_Host  *shost = class_to_shost(dev);
3573         struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3574         struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3575 
3576         return scnprintf(buf, PAGE_SIZE, "%d\n",
3577                         pring ? pring->txcmplq_max : 0);
3578 }
3579 
3580 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3581                          lpfc_txcmplq_hw_show, NULL);
3582 
3583 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3584         "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3585 
3586 /*
3587 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3588 # until the timer expires. Value range is [0,255]. Default value is 30.
3589 */
3590 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3591 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3592 module_param(lpfc_nodev_tmo, int, 0);
3593 MODULE_PARM_DESC(lpfc_nodev_tmo,
3594                  "Seconds driver will hold I/O waiting "
3595                  "for a device to come back");
3596 
3597 /**
3598  * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3599  * @dev: class converted to a Scsi_host structure.
3600  * @attr: device attribute, not used.
3601  * @buf: on return contains the dev loss timeout in decimal.
3602  *
3603  * Returns: size of formatted string.
3604  **/
3605 static ssize_t
3606 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3607                     char *buf)
3608 {
3609         struct Scsi_Host  *shost = class_to_shost(dev);
3610         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3611 
3612         return scnprintf(buf, PAGE_SIZE, "%d\n",        vport->cfg_devloss_tmo);
3613 }
3614 
3615 /**
3616  * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3617  * @vport: lpfc vport structure pointer.
3618  * @val: contains the nodev timeout value.
3619  *
3620  * Description:
3621  * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3622  * a kernel error message is printed and zero is returned.
3623  * Else if val is in range then nodev tmo and devloss tmo are set to val.
3624  * Otherwise nodev tmo is set to the default value.
3625  *
3626  * Returns:
3627  * zero if already set or if val is in range
3628  * -EINVAL val out of range
3629  **/
3630 static int
3631 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3632 {
3633         if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3634                 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3635                 if (val != LPFC_DEF_DEVLOSS_TMO)
3636                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3637                                          "0407 Ignoring lpfc_nodev_tmo module "
3638                                          "parameter because lpfc_devloss_tmo "
3639                                          "is set.\n");
3640                 return 0;
3641         }
3642 
3643         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3644                 vport->cfg_nodev_tmo = val;
3645                 vport->cfg_devloss_tmo = val;
3646                 return 0;
3647         }
3648         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3649                          "0400 lpfc_nodev_tmo attribute cannot be set to"
3650                          " %d, allowed range is [%d, %d]\n",
3651                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3652         vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3653         return -EINVAL;
3654 }
3655 
3656 /**
3657  * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3658  * @vport: lpfc vport structure pointer.
3659  *
3660  * Description:
3661  * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3662  **/
3663 static void
3664 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3665 {
3666         struct Scsi_Host  *shost;
3667         struct lpfc_nodelist  *ndlp;
3668 #if (IS_ENABLED(CONFIG_NVME_FC))
3669         struct lpfc_nvme_rport *rport;
3670         struct nvme_fc_remote_port *remoteport = NULL;
3671 #endif
3672 
3673         shost = lpfc_shost_from_vport(vport);
3674         spin_lock_irq(shost->host_lock);
3675         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3676                 if (!NLP_CHK_NODE_ACT(ndlp))
3677                         continue;
3678                 if (ndlp->rport)
3679                         ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3680 #if (IS_ENABLED(CONFIG_NVME_FC))
3681                 spin_lock(&vport->phba->hbalock);
3682                 rport = lpfc_ndlp_get_nrport(ndlp);
3683                 if (rport)
3684                         remoteport = rport->remoteport;
3685                 spin_unlock(&vport->phba->hbalock);
3686                 if (rport && remoteport)
3687                         nvme_fc_set_remoteport_devloss(remoteport,
3688                                                        vport->cfg_devloss_tmo);
3689 #endif
3690         }
3691         spin_unlock_irq(shost->host_lock);
3692 }
3693 
3694 /**
3695  * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3696  * @vport: lpfc vport structure pointer.
3697  * @val: contains the tmo value.
3698  *
3699  * Description:
3700  * If the devloss tmo is already set or the vport dev loss tmo has changed
3701  * then a kernel error message is printed and zero is returned.
3702  * Else if val is in range then nodev tmo and devloss tmo are set to val.
3703  * Otherwise nodev tmo is set to the default value.
3704  *
3705  * Returns:
3706  * zero if already set or if val is in range
3707  * -EINVAL val out of range
3708  **/
3709 static int
3710 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3711 {
3712         if (vport->dev_loss_tmo_changed ||
3713             (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3714                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3715                                  "0401 Ignoring change to lpfc_nodev_tmo "
3716                                  "because lpfc_devloss_tmo is set.\n");
3717                 return 0;
3718         }
3719         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3720                 vport->cfg_nodev_tmo = val;
3721                 vport->cfg_devloss_tmo = val;
3722                 /*
3723                  * For compat: set the fc_host dev loss so new rports
3724                  * will get the value.
3725                  */
3726                 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3727                 lpfc_update_rport_devloss_tmo(vport);
3728                 return 0;
3729         }
3730         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3731                          "0403 lpfc_nodev_tmo attribute cannot be set to "
3732                          "%d, allowed range is [%d, %d]\n",
3733                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3734         return -EINVAL;
3735 }
3736 
3737 lpfc_vport_param_store(nodev_tmo)
3738 
3739 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3740 
3741 /*
3742 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3743 # disappear until the timer expires. Value range is [0,255]. Default
3744 # value is 30.
3745 */
3746 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3747 MODULE_PARM_DESC(lpfc_devloss_tmo,
3748                  "Seconds driver will hold I/O waiting "
3749                  "for a device to come back");
3750 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3751                       LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3752 lpfc_vport_param_show(devloss_tmo)
3753 
3754 /**
3755  * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3756  * @vport: lpfc vport structure pointer.
3757  * @val: contains the tmo value.
3758  *
3759  * Description:
3760  * If val is in a valid range then set the vport nodev tmo,
3761  * devloss tmo, also set the vport dev loss tmo changed flag.
3762  * Else a kernel error message is printed.
3763  *
3764  * Returns:
3765  * zero if val is in range
3766  * -EINVAL val out of range
3767  **/
3768 static int
3769 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3770 {
3771         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3772                 vport->cfg_nodev_tmo = val;
3773                 vport->cfg_devloss_tmo = val;
3774                 vport->dev_loss_tmo_changed = 1;
3775                 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3776                 lpfc_update_rport_devloss_tmo(vport);
3777                 return 0;
3778         }
3779 
3780         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3781                          "0404 lpfc_devloss_tmo attribute cannot be set to "
3782                          "%d, allowed range is [%d, %d]\n",
3783                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3784         return -EINVAL;
3785 }
3786 
3787 lpfc_vport_param_store(devloss_tmo)
3788 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3789 
3790 /*
3791  * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3792  * lpfc_suppress_rsp = 0  Disable
3793  * lpfc_suppress_rsp = 1  Enable (default)
3794  *
3795  */
3796 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3797             "Enable suppress rsp feature is firmware supports it");
3798 
3799 /*
3800  * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3801  * lpfc_nvmet_mrq = 0  driver will calcualte optimal number of RQ pairs
3802  * lpfc_nvmet_mrq = 1  use a single RQ pair
3803  * lpfc_nvmet_mrq >= 2  use specified RQ pairs for MRQ
3804  *
3805  */
3806 LPFC_ATTR_R(nvmet_mrq,
3807             LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3808             "Specify number of RQ pairs for processing NVMET cmds");
3809 
3810 /*
3811  * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3812  * to each NVMET RQ. Range 64 to 2048, default is 512.
3813  */
3814 LPFC_ATTR_R(nvmet_mrq_post,
3815             LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3816             LPFC_NVMET_RQE_DEF_COUNT,
3817             "Specify number of RQ buffers to initially post");
3818 
3819 /*
3820  * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3821  * Supported Values:  1 - register just FCP
3822  *                    3 - register both FCP and NVME
3823  * Supported values are [1,3]. Default value is 3
3824  */
3825 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3826             LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3827             "Enable FC4 Protocol support - FCP / NVME");
3828 
3829 /*
3830 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3831 # deluged with LOTS of information.
3832 # You can set a bit mask to record specific types of verbose messages:
3833 # See lpfc_logmsh.h for definitions.
3834 */
3835 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3836                        "Verbose logging bit-mask");
3837 
3838 /*
3839 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3840 # objects that have been registered with the nameserver after login.
3841 */
3842 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3843                   "Deregister nameserver objects before LOGO");
3844 
3845 /*
3846 # lun_queue_depth:  This parameter is used to limit the number of outstanding
3847 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3848 # If this parameter value is greater than 1/8th the maximum number of exchanges
3849 # supported by the HBA port, then the lun queue depth will be reduced to
3850 # 1/8th the maximum number of exchanges.
3851 */
3852 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3853                   "Max number of FCP commands we can queue to a specific LUN");
3854 
3855 /*
3856 # tgt_queue_depth:  This parameter is used to limit the number of outstanding
3857 # commands per target port. Value range is [10,65535]. Default value is 65535.
3858 */
3859 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3860 module_param(lpfc_tgt_queue_depth, uint, 0444);
3861 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3862 lpfc_vport_param_show(tgt_queue_depth);
3863 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3864                       LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3865 
3866 /**
3867  * lpfc_tgt_queue_depth_store: Sets an attribute value.
3868  * @phba: pointer the the adapter structure.
3869  * @val: integer attribute value.
3870  *
3871  * Description: Sets the parameter to the new value.
3872  *
3873  * Returns:
3874  * zero on success
3875  * -EINVAL if val is invalid
3876  */
3877 static int
3878 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3879 {
3880         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3881         struct lpfc_nodelist *ndlp;
3882 
3883         if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3884                 return -EINVAL;
3885 
3886         if (val == vport->cfg_tgt_queue_depth)
3887                 return 0;
3888 
3889         spin_lock_irq(shost->host_lock);
3890         vport->cfg_tgt_queue_depth = val;
3891 
3892         /* Next loop thru nodelist and change cmd_qdepth */
3893         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3894                 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3895 
3896         spin_unlock_irq(shost->host_lock);
3897         return 0;
3898 }
3899 
3900 lpfc_vport_param_store(tgt_queue_depth);
3901 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3902 
3903 /*
3904 # hba_queue_depth:  This parameter is used to limit the number of outstanding
3905 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3906 # value is greater than the maximum number of exchanges supported by the HBA,
3907 # then maximum number of exchanges supported by the HBA is used to determine
3908 # the hba_queue_depth.
3909 */
3910 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3911             "Max number of FCP commands we can queue to a lpfc HBA");
3912 
3913 /*
3914 # peer_port_login:  This parameter allows/prevents logins
3915 # between peer ports hosted on the same physical port.
3916 # When this parameter is set 0 peer ports of same physical port
3917 # are not allowed to login to each other.
3918 # When this parameter is set 1 peer ports of same physical port
3919 # are allowed to login to each other.
3920 # Default value of this parameter is 0.
3921 */
3922 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3923                   "Allow peer ports on the same physical port to login to each "
3924                   "other.");
3925 
3926 /*
3927 # restrict_login:  This parameter allows/prevents logins
3928 # between Virtual Ports and remote initiators.
3929 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3930 # other initiators and will attempt to PLOGI all remote ports.
3931 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3932 # remote ports and will not attempt to PLOGI to other initiators.
3933 # This parameter does not restrict to the physical port.
3934 # This parameter does not restrict logins to Fabric resident remote ports.
3935 # Default value of this parameter is 1.
3936 */
3937 static int lpfc_restrict_login = 1;
3938 module_param(lpfc_restrict_login, int, S_IRUGO);
3939 MODULE_PARM_DESC(lpfc_restrict_login,
3940                  "Restrict virtual ports login to remote initiators.");
3941 lpfc_vport_param_show(restrict_login);
3942 
3943 /**
3944  * lpfc_restrict_login_init - Set the vport restrict login flag
3945  * @vport: lpfc vport structure pointer.
3946  * @val: contains the restrict login value.
3947  *
3948  * Description:
3949  * If val is not in a valid range then log a kernel error message and set
3950  * the vport restrict login to one.
3951  * If the port type is physical clear the restrict login flag and return.
3952  * Else set the restrict login flag to val.
3953  *
3954  * Returns:
3955  * zero if val is in range
3956  * -EINVAL val out of range
3957  **/
3958 static int
3959 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3960 {
3961         if (val < 0 || val > 1) {
3962                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3963                                  "0422 lpfc_restrict_login attribute cannot "
3964                                  "be set to %d, allowed range is [0, 1]\n",
3965                                  val);
3966                 vport->cfg_restrict_login = 1;
3967                 return -EINVAL;
3968         }
3969         if (vport->port_type == LPFC_PHYSICAL_PORT) {
3970                 vport->cfg_restrict_login = 0;
3971                 return 0;
3972         }
3973         vport->cfg_restrict_login = val;
3974         return 0;
3975 }
3976 
3977 /**
3978  * lpfc_restrict_login_set - Set the vport restrict login flag
3979  * @vport: lpfc vport structure pointer.
3980  * @val: contains the restrict login value.
3981  *
3982  * Description:
3983  * If val is not in a valid range then log a kernel error message and set
3984  * the vport restrict login to one.
3985  * If the port type is physical and the val is not zero log a kernel
3986  * error message, clear the restrict login flag and return zero.
3987  * Else set the restrict login flag to val.
3988  *
3989  * Returns:
3990  * zero if val is in range
3991  * -EINVAL val out of range
3992  **/
3993 static int
3994 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3995 {
3996         if (val < 0 || val > 1) {
3997                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3998                                  "0425 lpfc_restrict_login attribute cannot "
3999                                  "be set to %d, allowed range is [0, 1]\n",
4000                                  val);
4001                 vport->cfg_restrict_login = 1;
4002                 return -EINVAL;
4003         }
4004         if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
4005                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4006                                  "0468 lpfc_restrict_login must be 0 for "
4007                                  "Physical ports.\n");
4008                 vport->cfg_restrict_login = 0;
4009                 return 0;
4010         }
4011         vport->cfg_restrict_login = val;
4012         return 0;
4013 }
4014 lpfc_vport_param_store(restrict_login);
4015 static DEVICE_ATTR_RW(lpfc_restrict_login);
4016 
4017 /*
4018 # Some disk devices have a "select ID" or "select Target" capability.
4019 # From a protocol standpoint "select ID" usually means select the
4020 # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
4021 # annex" which contains a table that maps a "select ID" (a number
4022 # between 0 and 7F) to an ALPA.  By default, for compatibility with
4023 # older drivers, the lpfc driver scans this table from low ALPA to high
4024 # ALPA.
4025 #
4026 # Turning on the scan-down variable (on  = 1, off = 0) will
4027 # cause the lpfc driver to use an inverted table, effectively
4028 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4029 #
4030 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4031 # and will not work across a fabric. Also this parameter will take
4032 # effect only in the case when ALPA map is not available.)
4033 */
4034 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4035                   "Start scanning for devices from highest ALPA to lowest");
4036 
4037 /*
4038 # lpfc_topology:  link topology for init link
4039 #            0x0  = attempt loop mode then point-to-point
4040 #            0x01 = internal loopback mode
4041 #            0x02 = attempt point-to-point mode only
4042 #            0x04 = attempt loop mode only
4043 #            0x06 = attempt point-to-point mode then loop
4044 # Set point-to-point mode if you want to run as an N_Port.
4045 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4046 # Default value is 0.
4047 */
4048 LPFC_ATTR(topology, 0, 0, 6,
4049         "Select Fibre Channel topology");
4050 
4051 /**
4052  * lpfc_topology_set - Set the adapters topology field
4053  * @phba: lpfc_hba pointer.
4054  * @val: topology value.
4055  *
4056  * Description:
4057  * If val is in a valid range then set the adapter's topology field and
4058  * issue a lip; if the lip fails reset the topology to the old value.
4059  *
4060  * If the value is not in range log a kernel error message and return an error.
4061  *
4062  * Returns:
4063  * zero if val is in range and lip okay
4064  * non-zero return value from lpfc_issue_lip()
4065  * -EINVAL val out of range
4066  **/
4067 static ssize_t
4068 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4069                         const char *buf, size_t count)
4070 {
4071         struct Scsi_Host  *shost = class_to_shost(dev);
4072         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4073         struct lpfc_hba   *phba = vport->phba;
4074         int val = 0;
4075         int nolip = 0;
4076         const char *val_buf = buf;
4077         int err;
4078         uint32_t prev_val;
4079 
4080         if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4081                 nolip = 1;
4082                 val_buf = &buf[strlen("nolip ")];
4083         }
4084 
4085         if (!isdigit(val_buf[0]))
4086                 return -EINVAL;
4087         if (sscanf(val_buf, "%i", &val) != 1)
4088                 return -EINVAL;
4089 
4090         if (val >= 0 && val <= 6) {
4091                 prev_val = phba->cfg_topology;
4092                 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4093                         val == 4) {
4094                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4095                                 "3113 Loop mode not supported at speed %d\n",
4096                                 val);
4097                         return -EINVAL;
4098                 }
4099                 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4100                      phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
4101                     val == 4) {
4102                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4103                                 "3114 Loop mode not supported\n");
4104                         return -EINVAL;
4105                 }
4106                 phba->cfg_topology = val;
4107                 if (nolip)
4108                         return strlen(buf);
4109 
4110                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4111                         "3054 lpfc_topology changed from %d to %d\n",
4112                         prev_val, val);
4113                 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4114                         phba->fc_topology_changed = 1;
4115                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4116                 if (err) {
4117                         phba->cfg_topology = prev_val;
4118                         return -EINVAL;
4119                 } else
4120                         return strlen(buf);
4121         }
4122         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4123                 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4124                 "allowed range is [0, 6]\n",
4125                 phba->brd_no, val);
4126         return -EINVAL;
4127 }
4128 
4129 lpfc_param_show(topology)
4130 static DEVICE_ATTR_RW(lpfc_topology);
4131 
4132 /**
4133  * lpfc_static_vport_show: Read callback function for
4134  *   lpfc_static_vport sysfs file.
4135  * @dev: Pointer to class device object.
4136  * @attr: device attribute structure.
4137  * @buf: Data buffer.
4138  *
4139  * This function is the read call back function for
4140  * lpfc_static_vport sysfs file. The lpfc_static_vport
4141  * sysfs file report the mageability of the vport.
4142  **/
4143 static ssize_t
4144 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4145                          char *buf)
4146 {
4147         struct Scsi_Host  *shost = class_to_shost(dev);
4148         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4149         if (vport->vport_flag & STATIC_VPORT)
4150                 sprintf(buf, "1\n");
4151         else
4152                 sprintf(buf, "0\n");
4153 
4154         return strlen(buf);
4155 }
4156 
4157 /*
4158  * Sysfs attribute to control the statistical data collection.
4159  */
4160 static DEVICE_ATTR_RO(lpfc_static_vport);
4161 
4162 /**
4163  * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4164  * @dev: Pointer to class device.
4165  * @buf: Data buffer.
4166  * @count: Size of the data buffer.
4167  *
4168  * This function get called when a user write to the lpfc_stat_data_ctrl
4169  * sysfs file. This function parse the command written to the sysfs file
4170  * and take appropriate action. These commands are used for controlling
4171  * driver statistical data collection.
4172  * Following are the command this function handles.
4173  *
4174  *    setbucket <bucket_type> <base> <step>
4175  *                             = Set the latency buckets.
4176  *    destroybucket            = destroy all the buckets.
4177  *    start                    = start data collection
4178  *    stop                     = stop data collection
4179  *    reset                    = reset the collected data
4180  **/
4181 static ssize_t
4182 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4183                           const char *buf, size_t count)
4184 {
4185         struct Scsi_Host  *shost = class_to_shost(dev);
4186         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4187         struct lpfc_hba   *phba = vport->phba;
4188 #define LPFC_MAX_DATA_CTRL_LEN 1024
4189         static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4190         unsigned long i;
4191         char *str_ptr, *token;
4192         struct lpfc_vport **vports;
4193         struct Scsi_Host *v_shost;
4194         char *bucket_type_str, *base_str, *step_str;
4195         unsigned long base, step, bucket_type;
4196 
4197         if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4198                 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4199                         return -EINVAL;
4200 
4201                 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4202                 str_ptr = &bucket_data[0];
4203                 /* Ignore this token - this is command token */
4204                 token = strsep(&str_ptr, "\t ");
4205                 if (!token)
4206                         return -EINVAL;
4207 
4208                 bucket_type_str = strsep(&str_ptr, "\t ");
4209                 if (!bucket_type_str)
4210                         return -EINVAL;
4211 
4212                 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4213                         bucket_type = LPFC_LINEAR_BUCKET;
4214                 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4215                         bucket_type = LPFC_POWER2_BUCKET;
4216                 else
4217                         return -EINVAL;
4218 
4219                 base_str = strsep(&str_ptr, "\t ");
4220                 if (!base_str)
4221                         return -EINVAL;
4222                 base = simple_strtoul(base_str, NULL, 0);
4223 
4224                 step_str = strsep(&str_ptr, "\t ");
4225                 if (!step_str)
4226                         return -EINVAL;
4227                 step = simple_strtoul(step_str, NULL, 0);
4228                 if (!step)
4229                         return -EINVAL;
4230 
4231                 /* Block the data collection for every vport */
4232                 vports = lpfc_create_vport_work_array(phba);
4233                 if (vports == NULL)
4234                         return -ENOMEM;
4235 
4236                 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4237                         v_shost = lpfc_shost_from_vport(vports[i]);
4238                         spin_lock_irq(v_shost->host_lock);
4239                         /* Block and reset data collection */
4240                         vports[i]->stat_data_blocked = 1;
4241                         if (vports[i]->stat_data_enabled)
4242                                 lpfc_vport_reset_stat_data(vports[i]);
4243                         spin_unlock_irq(v_shost->host_lock);
4244                 }
4245 
4246                 /* Set the bucket attributes */
4247                 phba->bucket_type = bucket_type;
4248                 phba->bucket_base = base;
4249                 phba->bucket_step = step;
4250 
4251                 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4252                         v_shost = lpfc_shost_from_vport(vports[i]);
4253 
4254                         /* Unblock data collection */
4255                         spin_lock_irq(v_shost->host_lock);
4256                         vports[i]->stat_data_blocked = 0;
4257                         spin_unlock_irq(v_shost->host_lock);
4258                 }
4259                 lpfc_destroy_vport_work_array(phba, vports);
4260                 return strlen(buf);
4261         }
4262 
4263         if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4264                 vports = lpfc_create_vport_work_array(phba);
4265                 if (vports == NULL)
4266                         return -ENOMEM;
4267 
4268                 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4269                         v_shost = lpfc_shost_from_vport(vports[i]);
4270                         spin_lock_irq(shost->host_lock);
4271                         vports[i]->stat_data_blocked = 1;
4272                         lpfc_free_bucket(vport);
4273                         vport->stat_data_enabled = 0;
4274                         vports[i]->stat_data_blocked = 0;
4275                         spin_unlock_irq(shost->host_lock);
4276                 }
4277                 lpfc_destroy_vport_work_array(phba, vports);
4278                 phba->bucket_type = LPFC_NO_BUCKET;
4279                 phba->bucket_base = 0;
4280                 phba->bucket_step = 0;
4281                 return strlen(buf);
4282         }
4283 
4284         if (!strncmp(buf, "start", strlen("start"))) {
4285                 /* If no buckets configured return error */
4286                 if (phba->bucket_type == LPFC_NO_BUCKET)
4287                         return -EINVAL;
4288                 spin_lock_irq(shost->host_lock);
4289                 if (vport->stat_data_enabled) {
4290                         spin_unlock_irq(shost->host_lock);
4291                         return strlen(buf);
4292                 }
4293                 lpfc_alloc_bucket(vport);
4294                 vport->stat_data_enabled = 1;
4295                 spin_unlock_irq(shost->host_lock);
4296                 return strlen(buf);
4297         }
4298 
4299         if (!strncmp(buf, "stop", strlen("stop"))) {
4300                 spin_lock_irq(shost->host_lock);
4301                 if (vport->stat_data_enabled == 0) {
4302                         spin_unlock_irq(shost->host_lock);
4303                         return strlen(buf);
4304                 }
4305                 lpfc_free_bucket(vport);
4306                 vport->stat_data_enabled = 0;
4307                 spin_unlock_irq(shost->host_lock);
4308                 return strlen(buf);
4309         }
4310 
4311         if (!strncmp(buf, "reset", strlen("reset"))) {
4312                 if ((phba->bucket_type == LPFC_NO_BUCKET)
4313                         || !vport->stat_data_enabled)
4314                         return strlen(buf);
4315                 spin_lock_irq(shost->host_lock);
4316                 vport->stat_data_blocked = 1;
4317                 lpfc_vport_reset_stat_data(vport);
4318                 vport->stat_data_blocked = 0;
4319                 spin_unlock_irq(shost->host_lock);
4320                 return strlen(buf);
4321         }
4322         return -EINVAL;
4323 }
4324 
4325 
4326 /**
4327  * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4328  * @dev: Pointer to class device object.
4329  * @buf: Data buffer.
4330  *
4331  * This function is the read call back function for
4332  * lpfc_stat_data_ctrl sysfs file. This function report the
4333  * current statistical data collection state.
4334  **/
4335 static ssize_t
4336 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4337                          char *buf)
4338 {
4339         struct Scsi_Host  *shost = class_to_shost(dev);
4340         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4341         struct lpfc_hba   *phba = vport->phba;
4342         int index = 0;
4343         int i;
4344         char *bucket_type;
4345         unsigned long bucket_value;
4346 
4347         switch (phba->bucket_type) {
4348         case LPFC_LINEAR_BUCKET:
4349                 bucket_type = "linear";
4350                 break;
4351         case LPFC_POWER2_BUCKET:
4352                 bucket_type = "power2";
4353                 break;
4354         default:
4355                 bucket_type = "No Bucket";
4356                 break;
4357         }
4358 
4359         sprintf(&buf[index], "Statistical Data enabled :%d, "
4360                 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4361                 " Bucket step :%d\nLatency Ranges :",
4362                 vport->stat_data_enabled, vport->stat_data_blocked,
4363                 bucket_type, phba->bucket_base, phba->bucket_step);
4364         index = strlen(buf);
4365         if (phba->bucket_type != LPFC_NO_BUCKET) {
4366                 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4367                         if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4368                                 bucket_value = phba->bucket_base +
4369                                         phba->bucket_step * i;
4370                         else
4371                                 bucket_value = phba->bucket_base +
4372                                 (1 << i) * phba->bucket_step;
4373 
4374                         if (index + 10 > PAGE_SIZE)
4375                                 break;
4376                         sprintf(&buf[index], "%08ld ", bucket_value);
4377                         index = strlen(buf);
4378                 }
4379         }
4380         sprintf(&buf[index], "\n");
4381         return strlen(buf);
4382 }
4383 
4384 /*
4385  * Sysfs attribute to control the statistical data collection.
4386  */
4387 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4388 
4389 /*
4390  * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4391  */
4392 
4393 /*
4394  * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4395  * for each target.
4396  */
4397 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4398 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4399         STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4400 
4401 
4402 /**
4403  * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4404  * @filp: sysfs file
4405  * @kobj: Pointer to the kernel object
4406  * @bin_attr: Attribute object
4407  * @buff: Buffer pointer
4408  * @off: File offset
4409  * @count: Buffer size
4410  *
4411  * This function is the read call back function for lpfc_drvr_stat_data
4412  * sysfs file. This function export the statistical data to user
4413  * applications.
4414  **/
4415 static ssize_t
4416 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4417                 struct bin_attribute *bin_attr,
4418                 char *buf, loff_t off, size_t count)
4419 {
4420         struct device *dev = container_of(kobj, struct device,
4421                 kobj);
4422         struct Scsi_Host  *shost = class_to_shost(dev);
4423         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4424         struct lpfc_hba   *phba = vport->phba;
4425         int i = 0, index = 0;
4426         unsigned long nport_index;
4427         struct lpfc_nodelist *ndlp = NULL;
4428         nport_index = (unsigned long)off /
4429                 MAX_STAT_DATA_SIZE_PER_TARGET;
4430 
4431         if (!vport->stat_data_enabled || vport->stat_data_blocked
4432                 || (phba->bucket_type == LPFC_NO_BUCKET))
4433                 return 0;
4434 
4435         spin_lock_irq(shost->host_lock);
4436         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4437                 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4438                         continue;
4439 
4440                 if (nport_index > 0) {
4441                         nport_index--;
4442                         continue;
4443                 }
4444 
4445                 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4446                         > count)
4447                         break;
4448 
4449                 if (!ndlp->lat_data)
4450                         continue;
4451 
4452                 /* Print the WWN */
4453                 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4454                         ndlp->nlp_portname.u.wwn[0],
4455                         ndlp->nlp_portname.u.wwn[1],
4456                         ndlp->nlp_portname.u.wwn[2],
4457                         ndlp->nlp_portname.u.wwn[3],
4458                         ndlp->nlp_portname.u.wwn[4],
4459                         ndlp->nlp_portname.u.wwn[5],
4460                         ndlp->nlp_portname.u.wwn[6],
4461                         ndlp->nlp_portname.u.wwn[7]);
4462 
4463                 index = strlen(buf);
4464 
4465                 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4466                         sprintf(&buf[index], "%010u,",
4467                                 ndlp->lat_data[i].cmd_count);
4468                         index = strlen(buf);
4469                 }
4470                 sprintf(&buf[index], "\n");
4471                 index = strlen(buf);
4472         }
4473         spin_unlock_irq(shost->host_lock);
4474         return index;
4475 }
4476 
4477 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4478         .attr = {
4479                 .name = "lpfc_drvr_stat_data",
4480                 .mode = S_IRUSR,
4481         },
4482         .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4483         .read = sysfs_drvr_stat_data_read,
4484         .write = NULL,
4485 };
4486 
4487 /*
4488 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4489 # connection.
4490 # Value range is [0,16]. Default value is 0.
4491 */
4492 /**
4493  * lpfc_link_speed_set - Set the adapters link speed
4494  * @phba: lpfc_hba pointer.
4495  * @val: link speed value.
4496  *
4497  * Description:
4498  * If val is in a valid range then set the adapter's link speed field and
4499  * issue a lip; if the lip fails reset the link speed to the old value.
4500  *
4501  * Notes:
4502  * If the value is not in range log a kernel error message and return an error.
4503  *
4504  * Returns:
4505  * zero if val is in range and lip okay.
4506  * non-zero return value from lpfc_issue_lip()
4507  * -EINVAL val out of range
4508  **/
4509 static ssize_t
4510 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4511                 const char *buf, size_t count)
4512 {
4513         struct Scsi_Host  *shost = class_to_shost(dev);
4514         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4515         struct lpfc_hba   *phba = vport->phba;
4516         int val = LPFC_USER_LINK_SPEED_AUTO;
4517         int nolip = 0;
4518         const char *val_buf = buf;
4519         int err;
4520         uint32_t prev_val, if_type;
4521 
4522         if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4523         if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4524             phba->hba_flag & HBA_FORCED_LINK_SPEED)
4525                 return -EPERM;
4526 
4527         if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4528                 nolip = 1;
4529                 val_buf = &buf[strlen("nolip ")];
4530         }
4531 
4532         if (!isdigit(val_buf[0]))
4533                 return -EINVAL;
4534         if (sscanf(val_buf, "%i", &val) != 1)
4535                 return -EINVAL;
4536 
4537         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4538                 "3055 lpfc_link_speed changed from %d to %d %s\n",
4539                 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4540 
4541         if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4542             ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4543             ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4544             ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4545             ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4546             ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4547             ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4548             ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4549                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4550                                 "2879 lpfc_link_speed attribute cannot be set "
4551                                 "to %d. Speed is not supported by this port.\n",
4552                                 val);
4553                 return -EINVAL;
4554         }
4555         if (val >= LPFC_USER_LINK_SPEED_16G &&
4556             phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4557                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4558                                 "3112 lpfc_link_speed attribute cannot be set "
4559                                 "to %d. Speed is not supported in loop mode.\n",
4560                                 val);
4561                 return -EINVAL;
4562         }
4563 
4564         switch (val) {
4565         case LPFC_USER_LINK_SPEED_AUTO:
4566         case LPFC_USER_LINK_SPEED_1G:
4567         case LPFC_USER_LINK_SPEED_2G:
4568         case LPFC_USER_LINK_SPEED_4G:
4569         case LPFC_USER_LINK_SPEED_8G:
4570         case LPFC_USER_LINK_SPEED_16G:
4571         case LPFC_USER_LINK_SPEED_32G:
4572         case LPFC_USER_LINK_SPEED_64G:
4573                 prev_val = phba->cfg_link_speed;
4574                 phba->cfg_link_speed = val;
4575                 if (nolip)
4576                         return strlen(buf);
4577 
4578                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4579                 if (err) {
4580                         phba->cfg_link_speed = prev_val;
4581                         return -EINVAL;
4582                 }
4583                 return strlen(buf);
4584         default:
4585                 break;
4586         }
4587 
4588         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4589                         "0469 lpfc_link_speed attribute cannot be set to %d, "
4590                         "allowed values are [%s]\n",
4591                         val, LPFC_LINK_SPEED_STRING);
4592         return -EINVAL;
4593 
4594 }
4595 
4596 static int lpfc_link_speed = 0;
4597 module_param(lpfc_link_speed, int, S_IRUGO);
4598 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4599 lpfc_param_show(link_speed)
4600 
4601 /**
4602  * lpfc_link_speed_init - Set the adapters link speed
4603  * @phba: lpfc_hba pointer.
4604  * @val: link speed value.
4605  *
4606  * Description:
4607  * If val is in a valid range then set the adapter's link speed field.
4608  *
4609  * Notes:
4610  * If the value is not in range log a kernel error message, clear the link
4611  * speed and return an error.
4612  *
4613  * Returns:
4614  * zero if val saved.
4615  * -EINVAL val out of range
4616  **/
4617 static int
4618 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4619 {
4620         if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4621                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4622                         "3111 lpfc_link_speed of %d cannot "
4623                         "support loop mode, setting topology to default.\n",
4624                          val);
4625                 phba->cfg_topology = 0;
4626         }
4627 
4628         switch (val) {
4629         case LPFC_USER_LINK_SPEED_AUTO:
4630         case LPFC_USER_LINK_SPEED_1G:
4631         case LPFC_USER_LINK_SPEED_2G:
4632         case LPFC_USER_LINK_SPEED_4G:
4633         case LPFC_USER_LINK_SPEED_8G:
4634         case LPFC_USER_LINK_SPEED_16G:
4635         case LPFC_USER_LINK_SPEED_32G:
4636         case LPFC_USER_LINK_SPEED_64G:
4637                 phba->cfg_link_speed = val;
4638                 return 0;
4639         default:
4640                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4641                                 "0405 lpfc_link_speed attribute cannot "
4642                                 "be set to %d, allowed values are "
4643                                 "["LPFC_LINK_SPEED_STRING"]\n", val);
4644                 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4645                 return -EINVAL;
4646         }
4647 }
4648 
4649 static DEVICE_ATTR_RW(lpfc_link_speed);
4650 
4651 /*
4652 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4653 #       0  = aer disabled or not supported
4654 #       1  = aer supported and enabled (default)
4655 # Value range is [0,1]. Default value is 1.
4656 */
4657 LPFC_ATTR(aer_support, 1, 0, 1,
4658         "Enable PCIe device AER support");
4659 lpfc_param_show(aer_support)
4660 
4661 /**
4662  * lpfc_aer_support_store - Set the adapter for aer support
4663  *
4664  * @dev: class device that is converted into a Scsi_host.
4665  * @attr: device attribute, not used.
4666  * @buf: containing enable or disable aer flag.
4667  * @count: unused variable.
4668  *
4669  * Description:
4670  * If the val is 1 and currently the device's AER capability was not
4671  * enabled, invoke the kernel's enable AER helper routine, trying to
4672  * enable the device's AER capability. If the helper routine enabling
4673  * AER returns success, update the device's cfg_aer_support flag to
4674  * indicate AER is supported by the device; otherwise, if the device
4675  * AER capability is already enabled to support AER, then do nothing.
4676  *
4677  * If the val is 0 and currently the device's AER support was enabled,
4678  * invoke the kernel's disable AER helper routine. After that, update
4679  * the device's cfg_aer_support flag to indicate AER is not supported
4680  * by the device; otherwise, if the device AER capability is already
4681  * disabled from supporting AER, then do nothing.
4682  *
4683  * Returns:
4684  * length of the buf on success if val is in range the intended mode
4685  * is supported.
4686  * -EINVAL if val out of range or intended mode is not supported.
4687  **/
4688 static ssize_t
4689 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4690                        const char *buf, size_t count)
4691 {
4692         struct Scsi_Host *shost = class_to_shost(dev);
4693         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4694         struct lpfc_hba *phba = vport->phba;
4695         int val = 0, rc = -EINVAL;
4696 
4697         if (!isdigit(buf[0]))
4698                 return -EINVAL;
4699         if (sscanf(buf, "%i", &val) != 1)
4700                 return -EINVAL;
4701 
4702         switch (val) {
4703         case 0:
4704                 if (phba->hba_flag & HBA_AER_ENABLED) {
4705                         rc = pci_disable_pcie_error_reporting(phba->pcidev);
4706                         if (!rc) {
4707                                 spin_lock_irq(&phba->hbalock);
4708                                 phba->hba_flag &= ~HBA_AER_ENABLED;
4709                                 spin_unlock_irq(&phba->hbalock);
4710                                 phba->cfg_aer_support = 0;
4711                                 rc = strlen(buf);
4712                         } else
4713                                 rc = -EPERM;
4714                 } else {
4715                         phba->cfg_aer_support = 0;
4716                         rc = strlen(buf);
4717                 }
4718                 break;
4719         case 1:
4720                 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4721                         rc = pci_enable_pcie_error_reporting(phba->pcidev);
4722                         if (!rc) {
4723                                 spin_lock_irq(&phba->hbalock);
4724                                 phba->hba_flag |= HBA_AER_ENABLED;
4725                                 spin_unlock_irq(&phba->hbalock);
4726                                 phba->cfg_aer_support = 1;
4727                                 rc = strlen(buf);
4728                         } else
4729                                  rc = -EPERM;
4730                 } else {
4731                         phba->cfg_aer_support = 1;
4732                         rc = strlen(buf);
4733                 }
4734                 break;
4735         default:
4736                 rc = -EINVAL;
4737                 break;
4738         }
4739         return rc;
4740 }
4741 
4742 static DEVICE_ATTR_RW(lpfc_aer_support);
4743 
4744 /**
4745  * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4746  * @dev: class device that is converted into a Scsi_host.
4747  * @attr: device attribute, not used.
4748  * @buf: containing flag 1 for aer cleanup state.
4749  * @count: unused variable.
4750  *
4751  * Description:
4752  * If the @buf contains 1 and the device currently has the AER support
4753  * enabled, then invokes the kernel AER helper routine
4754  * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4755  * error status register.
4756  *
4757  * Notes:
4758  *
4759  * Returns:
4760  * -EINVAL if the buf does not contain the 1 or the device is not currently
4761  * enabled with the AER support.
4762  **/
4763 static ssize_t
4764 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4765                        const char *buf, size_t count)
4766 {
4767         struct Scsi_Host  *shost = class_to_shost(dev);
4768         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4769         struct lpfc_hba   *phba = vport->phba;
4770         int val, rc = -1;
4771 
4772         if (!isdigit(buf[0]))
4773                 return -EINVAL;
4774         if (sscanf(buf, "%i", &val) != 1)
4775                 return -EINVAL;
4776         if (val != 1)
4777                 return -EINVAL;
4778 
4779         if (phba->hba_flag & HBA_AER_ENABLED)
4780                 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4781 
4782         if (rc == 0)
4783                 return strlen(buf);
4784         else
4785                 return -EPERM;
4786 }
4787 
4788 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4789                    lpfc_aer_cleanup_state);
4790 
4791 /**
4792  * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4793  *
4794  * @dev: class device that is converted into a Scsi_host.
4795  * @attr: device attribute, not used.
4796  * @buf: containing the string the number of vfs to be enabled.
4797  * @count: unused variable.
4798  *
4799  * Description:
4800  * When this api is called either through user sysfs, the driver shall
4801  * try to enable or disable SR-IOV virtual functions according to the
4802  * following:
4803  *
4804  * If zero virtual function has been enabled to the physical function,
4805  * the driver shall invoke the pci enable virtual function api trying
4806  * to enable the virtual functions. If the nr_vfn provided is greater
4807  * than the maximum supported, the maximum virtual function number will
4808  * be used for invoking the api; otherwise, the nr_vfn provided shall
4809  * be used for invoking the api. If the api call returned success, the
4810  * actual number of virtual functions enabled will be set to the driver
4811  * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4812  * cfg_sriov_nr_virtfn remains zero.
4813  *
4814  * If none-zero virtual functions have already been enabled to the
4815  * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4816  * -EINVAL will be returned and the driver does nothing;
4817  *
4818  * If the nr_vfn provided is zero and none-zero virtual functions have
4819  * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4820  * disabling virtual function api shall be invoded to disable all the
4821  * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4822  * zero. Otherwise, if zero virtual function has been enabled, do
4823  * nothing.
4824  *
4825  * Returns:
4826  * length of the buf on success if val is in range the intended mode
4827  * is supported.
4828  * -EINVAL if val out of range or intended mode is not supported.
4829  **/
4830 static ssize_t
4831 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4832                          const char *buf, size_t count)
4833 {
4834         struct Scsi_Host *shost = class_to_shost(dev);
4835         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4836         struct lpfc_hba *phba = vport->phba;
4837         struct pci_dev *pdev = phba->pcidev;
4838         int val = 0, rc = -EINVAL;
4839 
4840         /* Sanity check on user data */
4841         if (!isdigit(buf[0]))
4842                 return -EINVAL;
4843         if (sscanf(buf, "%i", &val) != 1)
4844                 return -EINVAL;
4845         if (val < 0)
4846                 return -EINVAL;
4847 
4848         /* Request disabling virtual functions */
4849         if (val == 0) {
4850                 if (phba->cfg_sriov_nr_virtfn > 0) {
4851                         pci_disable_sriov(pdev);
4852                         phba->cfg_sriov_nr_virtfn = 0;
4853                 }
4854                 return strlen(buf);
4855         }
4856 
4857         /* Request enabling virtual functions */
4858         if (phba->cfg_sriov_nr_virtfn > 0) {
4859                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4860                                 "3018 There are %d virtual functions "
4861                                 "enabled on physical function.\n",
4862                                 phba->cfg_sriov_nr_virtfn);
4863                 return -EEXIST;
4864         }
4865 
4866         if (val <= LPFC_MAX_VFN_PER_PFN)
4867                 phba->cfg_sriov_nr_virtfn = val;
4868         else {
4869                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4870                                 "3019 Enabling %d virtual functions is not "
4871                                 "allowed.\n", val);
4872                 return -EINVAL;
4873         }
4874 
4875         rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4876         if (rc) {
4877                 phba->cfg_sriov_nr_virtfn = 0;
4878                 rc = -EPERM;
4879         } else
4880                 rc = strlen(buf);
4881 
4882         return rc;
4883 }
4884 
4885 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4886         "Enable PCIe device SR-IOV virtual fn");
4887 
4888 lpfc_param_show(sriov_nr_virtfn)
4889 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4890 
4891 /**
4892  * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4893  *
4894  * @dev: class device that is converted into a Scsi_host.
4895  * @attr: device attribute, not used.
4896  * @buf: containing the string the number of vfs to be enabled.
4897  * @count: unused variable.
4898  *
4899  * Description:
4900  *
4901  * Returns:
4902  * length of the buf on success if val is in range the intended mode
4903  * is supported.
4904  * -EINVAL if val out of range or intended mode is not supported.
4905  **/
4906 static ssize_t
4907 lpfc_request_firmware_upgrade_store(struct device *dev,
4908                                     struct device_attribute *attr,
4909                                     const char *buf, size_t count)
4910 {
4911         struct Scsi_Host *shost = class_to_shost(dev);
4912         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4913         struct lpfc_hba *phba = vport->phba;
4914         int val = 0, rc = -EINVAL;
4915 
4916         /* Sanity check on user data */
4917         if (!isdigit(buf[0]))
4918                 return -EINVAL;
4919         if (sscanf(buf, "%i", &val) != 1)
4920                 return -EINVAL;
4921         if (val != 1)
4922                 return -EINVAL;
4923 
4924         rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4925         if (rc)
4926                 rc = -EPERM;
4927         else
4928                 rc = strlen(buf);
4929         return rc;
4930 }
4931 
4932 static int lpfc_req_fw_upgrade;
4933 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4934 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4935 lpfc_param_show(request_firmware_upgrade)
4936 
4937 /**
4938  * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4939  * @phba: lpfc_hba pointer.
4940  * @val: 0 or 1.
4941  *
4942  * Description:
4943  * Set the initial Linux generic firmware upgrade enable or disable flag.
4944  *
4945  * Returns:
4946  * zero if val saved.
4947  * -EINVAL val out of range
4948  **/
4949 static int
4950 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4951 {
4952         if (val >= 0 && val <= 1) {
4953                 phba->cfg_request_firmware_upgrade = val;
4954                 return 0;
4955         }
4956         return -EINVAL;
4957 }
4958 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4959                    lpfc_request_firmware_upgrade_show,
4960                    lpfc_request_firmware_upgrade_store);
4961 
4962 /**
4963  * lpfc_force_rscn_store
4964  *
4965  * @dev: class device that is converted into a Scsi_host.
4966  * @attr: device attribute, not used.
4967  * @buf: unused string
4968  * @count: unused variable.
4969  *
4970  * Description:
4971  * Force the switch to send a RSCN to all other NPorts in our zone
4972  * If we are direct connect pt2pt, build the RSCN command ourself
4973  * and send to the other NPort. Not supported for private loop.
4974  *
4975  * Returns:
4976  * 0      - on success
4977  * -EIO   - if command is not sent
4978  **/
4979 static ssize_t
4980 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4981                       const char *buf, size_t count)
4982 {
4983         struct Scsi_Host *shost = class_to_shost(dev);
4984         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4985         int i;
4986 
4987         i = lpfc_issue_els_rscn(vport, 0);
4988         if (i)
4989                 return -EIO;
4990         return strlen(buf);
4991 }
4992 
4993 /*
4994  * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4995  * connected to  the HBA.
4996  *
4997  * Value range is any ascii value
4998  */
4999 static int lpfc_force_rscn;
5000 module_param(lpfc_force_rscn, int, 0644);
5001 MODULE_PARM_DESC(lpfc_force_rscn,
5002                  "Force an RSCN to be sent to all remote NPorts");
5003 lpfc_param_show(force_rscn)
5004 
5005 /**
5006  * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
5007  * @phba: lpfc_hba pointer.
5008  * @val: unused value.
5009  *
5010  * Returns:
5011  * zero if val saved.
5012  **/
5013 static int
5014 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
5015 {
5016         return 0;
5017 }
5018 static DEVICE_ATTR_RW(lpfc_force_rscn);
5019 
5020 /**
5021  * lpfc_fcp_imax_store
5022  *
5023  * @dev: class device that is converted into a Scsi_host.
5024  * @attr: device attribute, not used.
5025  * @buf: string with the number of fast-path FCP interrupts per second.
5026  * @count: unused variable.
5027  *
5028  * Description:
5029  * If val is in a valid range [636,651042], then set the adapter's
5030  * maximum number of fast-path FCP interrupts per second.
5031  *
5032  * Returns:
5033  * length of the buf on success if val is in range the intended mode
5034  * is supported.
5035  * -EINVAL if val out of range or intended mode is not supported.
5036  **/
5037 static ssize_t
5038 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
5039                          const char *buf, size_t count)
5040 {
5041         struct Scsi_Host *shost = class_to_shost(dev);
5042         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5043         struct lpfc_hba *phba = vport->phba;
5044         struct lpfc_eq_intr_info *eqi;
5045         uint32_t usdelay;
5046         int val = 0, i;
5047 
5048         /* fcp_imax is only valid for SLI4 */
5049         if (phba->sli_rev != LPFC_SLI_REV4)
5050                 return -EINVAL;
5051 
5052         /* Sanity check on user data */
5053         if (!isdigit(buf[0]))
5054                 return -EINVAL;
5055         if (sscanf(buf, "%i", &val) != 1)
5056                 return -EINVAL;
5057 
5058         /*
5059          * Value range for the HBA is [5000,5000000]
5060          * The value for each EQ depends on how many EQs are configured.
5061          * Allow value == 0
5062          */
5063         if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
5064                 return -EINVAL;
5065 
5066         phba->cfg_auto_imax = (val) ? 0 : 1;
5067         if (phba->cfg_fcp_imax && !val) {
5068                 queue_delayed_work(phba->wq, &phba->eq_delay_work,
5069                                    msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
5070 
5071                 for_each_present_cpu(i) {
5072                         eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
5073                         eqi->icnt = 0;
5074                 }
5075         }
5076 
5077         phba->cfg_fcp_imax = (uint32_t)val;
5078 
5079         if (phba->cfg_fcp_imax)
5080                 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
5081         else
5082                 usdelay = 0;
5083 
5084         for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
5085                 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
5086                                          usdelay);
5087 
5088         return strlen(buf);
5089 }
5090 
5091 /*
5092 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
5093 # for the HBA.
5094 #
5095 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
5096 */
5097 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
5098 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
5099 MODULE_PARM_DESC(lpfc_fcp_imax,
5100             "Set the maximum number of FCP interrupts per second per HBA");
5101 lpfc_param_show(fcp_imax)
5102 
5103 /**
5104  * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5105  * @phba: lpfc_hba pointer.
5106  * @val: link speed value.
5107  *
5108  * Description:
5109  * If val is in a valid range [636,651042], then initialize the adapter's
5110  * maximum number of fast-path FCP interrupts per second.
5111  *
5112  * Returns:
5113  * zero if val saved.
5114  * -EINVAL val out of range
5115  **/
5116 static int
5117 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5118 {
5119         if (phba->sli_rev != LPFC_SLI_REV4) {
5120                 phba->cfg_fcp_imax = 0;
5121                 return 0;
5122         }
5123 
5124         if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5125             (val == 0)) {
5126                 phba->cfg_fcp_imax = val;
5127                 return 0;
5128         }
5129 
5130         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5131                         "3016 lpfc_fcp_imax: %d out of range, using default\n",
5132                         val);
5133         phba->cfg_fcp_imax = LPFC_DEF_IMAX;
5134 
5135         return 0;
5136 }
5137 
5138 static DEVICE_ATTR_RW(lpfc_fcp_imax);
5139 
5140 /**
5141  * lpfc_cq_max_proc_limit_store
5142  *
5143  * @dev: class device that is converted into a Scsi_host.
5144  * @attr: device attribute, not used.
5145  * @buf: string with the cq max processing limit of cqes
5146  * @count: unused variable.
5147  *
5148  * Description:
5149  * If val is in a valid range, then set value on each cq
5150  *
5151  * Returns:
5152  * The length of the buf: if successful
5153  * -ERANGE: if val is not in the valid range
5154  * -EINVAL: if bad value format or intended mode is not supported.
5155  **/
5156 static ssize_t
5157 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5158                          const char *buf, size_t count)
5159 {
5160         struct Scsi_Host *shost = class_to_shost(dev);
5161         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5162         struct lpfc_hba *phba = vport->phba;
5163         struct lpfc_queue *eq, *cq;
5164         unsigned long val;
5165         int i;
5166 
5167         /* cq_max_proc_limit is only valid for SLI4 */
5168         if (phba->sli_rev != LPFC_SLI_REV4)
5169                 return -EINVAL;
5170 
5171         /* Sanity check on user data */
5172         if (!isdigit(buf[0]))
5173                 return -EINVAL;
5174         if (kstrtoul(buf, 0, &val))
5175                 return -EINVAL;
5176 
5177         if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5178                 return -ERANGE;
5179 
5180         phba->cfg_cq_max_proc_limit = (uint32_t)val;
5181 
5182         /* set the values on the cq's */
5183         for (i = 0; i < phba->cfg_irq_chann; i++) {
5184                 /* Get the EQ corresponding to the IRQ vector */
5185                 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
5186                 if (!eq)
5187                         continue;
5188 
5189                 list_for_each_entry(cq, &eq->child_list, list)
5190                         cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5191                                                  cq->entry_count);
5192         }
5193 
5194         return strlen(buf);
5195 }
5196 
5197 /*
5198  * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5199  *   itteration of CQ processing.
5200  */
5201 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5202 module_param(lpfc_cq_max_proc_limit, int, 0644);
5203 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5204             "Set the maximum number CQEs processed in an iteration of "
5205             "CQ processing");
5206 lpfc_param_show(cq_max_proc_limit)
5207 
5208 /*
5209  * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5210  *   single handler call which should request a polled completion rather
5211  *   than re-enabling interrupts.
5212  */
5213 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5214              LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5215              LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5216              "CQE Processing Threshold to enable Polling");
5217 
5218 /**
5219  * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5220  * @phba: lpfc_hba pointer.
5221  * @val: entry limit
5222  *
5223  * Description:
5224  * If val is in a valid range, then initialize the adapter's maximum
5225  * value.
5226  *
5227  * Returns:
5228  *  Always returns 0 for success, even if value not always set to
5229  *  requested value. If value out of range or not supported, will fall
5230  *  back to default.
5231  **/
5232 static int
5233 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5234 {
5235         phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5236 
5237         if (phba->sli_rev != LPFC_SLI_REV4)
5238                 return 0;
5239 
5240         if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5241                 phba->cfg_cq_max_proc_limit = val;
5242                 return 0;
5243         }
5244 
5245         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5246                         "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5247                         "%d out of range, using default\n",
5248                         phba->cfg_cq_max_proc_limit);
5249 
5250         return 0;
5251 }
5252 
5253 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5254 
5255 /**
5256  * lpfc_state_show - Display current driver CPU affinity
5257  * @dev: class converted to a Scsi_host structure.
5258  * @attr: device attribute, not used.
5259  * @buf: on return contains text describing the state of the link.
5260  *
5261  * Returns: size of formatted string.
5262  **/
5263 static ssize_t
5264 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5265                       char *buf)
5266 {
5267         struct Scsi_Host  *shost = class_to_shost(dev);
5268         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5269         struct lpfc_hba   *phba = vport->phba;
5270         struct lpfc_vector_map_info *cpup;
5271         int  len = 0;
5272 
5273         if ((phba->sli_rev != LPFC_SLI_REV4) ||
5274             (phba->intr_type != MSIX))
5275                 return len;
5276 
5277         switch (phba->cfg_fcp_cpu_map) {
5278         case 0:
5279                 len += scnprintf(buf + len, PAGE_SIZE-len,
5280                                 "fcp_cpu_map: No mapping (%d)\n",
5281                                 phba->cfg_fcp_cpu_map);
5282                 return len;
5283         case 1:
5284                 len += scnprintf(buf + len, PAGE_SIZE-len,
5285                                 "fcp_cpu_map: HBA centric mapping (%d): "
5286                                 "%d of %d CPUs online from %d possible CPUs\n",
5287                                 phba->cfg_fcp_cpu_map, num_online_cpus(),
5288                                 num_present_cpus(),
5289                                 phba->sli4_hba.num_possible_cpu);
5290                 break;
5291         }
5292 
5293         while (phba->sli4_hba.curr_disp_cpu <
5294                phba->sli4_hba.num_possible_cpu) {
5295                 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5296 
5297                 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5298                         len += scnprintf(buf + len, PAGE_SIZE - len,
5299                                         "CPU %02d not present\n",
5300                                         phba->sli4_hba.curr_disp_cpu);
5301                 else if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) {
5302                         if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5303                                 len += scnprintf(
5304                                         buf + len, PAGE_SIZE - len,
5305                                         "CPU %02d hdwq None "
5306                                         "physid %d coreid %d ht %d ua %d\n",
5307                                         phba->sli4_hba.curr_disp_cpu,
5308                                         cpup->phys_id, cpup->core_id,
5309                                         (cpup->flag & LPFC_CPU_MAP_HYPER),
5310                                         (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5311                         else
5312                                 len += scnprintf(
5313                                         buf + len, PAGE_SIZE - len,
5314                                         "CPU %02d EQ %04d hdwq %04d "
5315                                         "physid %d coreid %d ht %d ua %d\n",
5316                                         phba->sli4_hba.curr_disp_cpu,
5317                                         cpup->eq, cpup->hdwq, cpup->phys_id,
5318                                         cpup->core_id,
5319                                         (cpup->flag & LPFC_CPU_MAP_HYPER),
5320                                         (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5321                 } else {
5322                         if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5323                                 len += scnprintf(
5324                                         buf + len, PAGE_SIZE - len,
5325                                         "CPU %02d hdwq None "
5326                                         "physid %d coreid %d ht %d ua %d IRQ %d\n",
5327                                         phba->sli4_hba.curr_disp_cpu,
5328                                         cpup->phys_id,
5329                                         cpup->core_id,
5330                                         (cpup->flag & LPFC_CPU_MAP_HYPER),
5331                                         (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5332                                         cpup->irq);
5333                         else
5334                                 len += scnprintf(
5335                                         buf + len, PAGE_SIZE - len,
5336                                         "CPU %02d EQ %04d hdwq %04d "
5337                                         "physid %d coreid %d ht %d ua %d IRQ %d\n",
5338                                         phba->sli4_hba.curr_disp_cpu,
5339                                         cpup->eq, cpup->hdwq, cpup->phys_id,
5340                                         cpup->core_id,
5341                                         (cpup->flag & LPFC_CPU_MAP_HYPER),
5342                                         (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5343                                         cpup->irq);
5344                 }
5345 
5346                 phba->sli4_hba.curr_disp_cpu++;
5347 
5348                 /* display max number of CPUs keeping some margin */
5349                 if (phba->sli4_hba.curr_disp_cpu <
5350                                 phba->sli4_hba.num_possible_cpu &&
5351                                 (len >= (PAGE_SIZE - 64))) {
5352                         len += scnprintf(buf + len,
5353                                         PAGE_SIZE - len, "more...\n");
5354                         break;
5355                 }
5356         }
5357 
5358         if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5359                 phba->sli4_hba.curr_disp_cpu = 0;
5360 
5361         return len;
5362 }
5363 
5364 /**
5365  * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5366  * @dev: class device that is converted into a Scsi_host.
5367  * @attr: device attribute, not used.
5368  * @buf: one or more lpfc_polling_flags values.
5369  * @count: not used.
5370  *
5371  * Returns:
5372  * -EINVAL  - Not implemented yet.
5373  **/
5374 static ssize_t
5375 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5376                        const char *buf, size_t count)
5377 {
5378         int status = -EINVAL;
5379         return status;
5380 }
5381 
5382 /*
5383 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5384 # for the HBA.
5385 #
5386 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5387 #       0 - Do not affinitze IRQ vectors
5388 #       1 - Affintize HBA vectors with respect to each HBA
5389 #           (start with CPU0 for each HBA)
5390 # This also defines how Hardware Queues are mapped to specific CPUs.
5391 */
5392 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5393 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5394 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5395                  "Defines how to map CPUs to IRQ vectors per HBA");
5396 
5397 /**
5398  * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5399  * @phba: lpfc_hba pointer.
5400  * @val: link speed value.
5401  *
5402  * Description:
5403  * If val is in a valid range [0-2], then affinitze the adapter's
5404  * MSIX vectors.
5405  *
5406  * Returns:
5407  * zero if val saved.
5408  * -EINVAL val out of range
5409  **/
5410 static int
5411 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5412 {
5413         if (phba->sli_rev != LPFC_SLI_REV4) {
5414                 phba->cfg_fcp_cpu_map = 0;
5415                 return 0;
5416         }
5417 
5418         if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5419                 phba->cfg_fcp_cpu_map = val;
5420                 return 0;
5421         }
5422 
5423         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5424                         "3326 lpfc_fcp_cpu_map: %d out of range, using "
5425                         "default\n", val);
5426         phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5427 
5428         return 0;
5429 }
5430 
5431 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5432 
5433 /*
5434 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
5435 # Value range is [2,3]. Default value is 3.
5436 */
5437 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5438                   "Select Fibre Channel class of service for FCP sequences");
5439 
5440 /*
5441 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5442 # is [0,1]. Default value is 0.
5443 */
5444 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5445                    "Use ADISC on rediscovery to authenticate FCP devices");
5446 
5447 /*
5448 # lpfc_first_burst_size: First burst size to use on the NPorts
5449 # that support first burst.
5450 # Value range is [0,65536]. Default value is 0.
5451 */
5452 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5453                    "First burst size for Targets that support first burst");
5454 
5455 /*
5456 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5457 * When the driver is configured as an NVME target, this value is
5458 * communicated to the NVME initiator in the PRLI response.  It is
5459 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5460 * parameters are set and the target is sending the PRLI RSP.
5461 * Parameter supported on physical port only - no NPIV support.
5462 * Value range is [0,65536]. Default value is 0.
5463 */
5464 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5465              "NVME Target mode first burst size in 512B increments.");
5466 
5467 /*
5468  * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5469  * For the Initiator (I), enabling this parameter means that an NVMET
5470  * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5471  * processed by the initiator for subsequent NVME FCP IO.
5472  * Currently, this feature is not supported on the NVME target
5473  * Value range is [0,1]. Default value is 0 (disabled).
5474  */
5475 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5476              "Enable First Burst feature for NVME Initiator.");
5477 
5478 /*
5479 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5480 # depth. Default value is 0. When the value of this parameter is zero the
5481 # SCSI command completion time is not used for controlling I/O queue depth. When
5482 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5483 # to limit the I/O completion time to the parameter value.
5484 # The value is set in milliseconds.
5485 */
5486 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5487         "Use command completion time to control queue depth");
5488 
5489 lpfc_vport_param_show(max_scsicmpl_time);
5490 static int
5491 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5492 {
5493         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5494         struct lpfc_nodelist *ndlp, *next_ndlp;
5495 
5496         if (val == vport->cfg_max_scsicmpl_time)
5497                 return 0;
5498         if ((val < 0) || (val > 60000))
5499                 return -EINVAL;
5500         vport->cfg_max_scsicmpl_time = val;
5501 
5502         spin_lock_irq(shost->host_lock);
5503         list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5504                 if (!NLP_CHK_NODE_ACT(ndlp))
5505                         continue;
5506                 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5507                         continue;
5508                 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5509         }
5510         spin_unlock_irq(shost->host_lock);
5511         return 0;
5512 }
5513 lpfc_vport_param_store(max_scsicmpl_time);
5514 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5515 
5516 /*
5517 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5518 # range is [0,1]. Default value is 0.
5519 */
5520 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5521 
5522 /*
5523 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5524 # range is [0,1]. Default value is 1.
5525 */
5526 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5527 
5528 /*
5529  * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5530  * range is [0,1]. Default value is 0.
5531  * For [0], FCP commands are issued to Work Queues based on upper layer
5532  * hardware queue index.
5533  * For [1], FCP commands are issued to a Work Queue associated with the
5534  *          current CPU.
5535  *
5536  * LPFC_FCP_SCHED_BY_HDWQ == 0
5537  * LPFC_FCP_SCHED_BY_CPU == 1
5538  *
5539  * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5540  * affinity for FCP/NVME I/Os through Work Queues associated with the current
5541  * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5542  * through WQs will be used.
5543  */
5544 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5545              LPFC_FCP_SCHED_BY_HDWQ,
5546              LPFC_FCP_SCHED_BY_CPU,
5547              "Determine scheduling algorithm for "
5548              "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5549 
5550 /*
5551  * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5552  * range is [0,1]. Default value is 0.
5553  * For [0], GID_FT is used for NameServer queries after RSCN (default)
5554  * For [1], GID_PT is used for NameServer queries after RSCN
5555  *
5556  */
5557 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5558              LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5559              "Determine algorithm NameServer queries after RSCN "
5560              "[0] - GID_FT, [1] - GID_PT");
5561 
5562 /*
5563 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5564 # range is [0,1]. Default value is 0.
5565 # For [0], bus reset issues target reset to ALL devices
5566 # For [1], bus reset issues target reset to non-FCP2 devices
5567 */
5568 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5569              "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5570 
5571 
5572 /*
5573 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5574 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5575 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5576 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5577 # cr_delay is set to 0.
5578 */
5579 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5580                 "interrupt response is generated");
5581 
5582 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5583                 "interrupt response is generated");
5584 
5585 /*
5586 # lpfc_multi_ring_support:  Determines how many rings to spread available
5587 # cmd/rsp IOCB entries across.
5588 # Value range is [1,2]. Default value is 1.
5589 */
5590 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5591                 "SLI rings to spread IOCB entries across");
5592 
5593 /*
5594 # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this
5595 # identifies what rctl value to configure the additional ring for.
5596 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5597 */
5598 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5599              255, "Identifies RCTL for additional ring configuration");
5600 
5601 /*
5602 # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this
5603 # identifies what type value to configure the additional ring for.
5604 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5605 */
5606 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5607              255, "Identifies TYPE for additional ring configuration");
5608 
5609 /*
5610 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5611 #       0  = SmartSAN functionality disabled (default)
5612 #       1  = SmartSAN functionality enabled
5613 # This parameter will override the value of lpfc_fdmi_on module parameter.
5614 # Value range is [0,1]. Default value is 0.
5615 */
5616 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5617 
5618 /*
5619 # lpfc_fdmi_on: Controls FDMI support.
5620 #       0       No FDMI support
5621 #       1       Traditional FDMI support (default)
5622 # Traditional FDMI support means the driver will assume FDMI-2 support;
5623 # however, if that fails, it will fallback to FDMI-1.
5624 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5625 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5626 # lpfc_fdmi_on.
5627 # Value range [0,1]. Default value is 1.
5628 */
5629 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5630 
5631 /*
5632 # Specifies the maximum number of ELS cmds we can have outstanding (for
5633 # discovery). Value range is [1,64]. Default value = 32.
5634 */
5635 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5636                  "during discovery");
5637 
5638 /*
5639 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5640 #    will be scanned by the SCSI midlayer when sequential scanning is
5641 #    used; and is also the highest LUN ID allowed when the SCSI midlayer
5642 #    parses REPORT_LUN responses. The lpfc driver has no LUN count or
5643 #    LUN ID limit, but the SCSI midlayer requires this field for the uses
5644 #    above. The lpfc driver limits the default value to 255 for two reasons.
5645 #    As it bounds the sequential scan loop, scanning for thousands of luns
5646 #    on a target can take minutes of wall clock time.  Additionally,
5647 #    there are FC targets, such as JBODs, that only recognize 8-bits of
5648 #    LUN ID. When they receive a value greater than 8 bits, they chop off
5649 #    the high order bits. In other words, they see LUN IDs 0, 256, 512,
5650 #    and so on all as LUN ID 0. This causes the linux kernel, which sees
5651 #    valid responses at each of the LUN IDs, to believe there are multiple
5652 #    devices present, when in fact, there is only 1.
5653 #    A customer that is aware of their target behaviors, and the results as
5654 #    indicated above, is welcome to increase the lpfc_max_luns value.
5655 #    As mentioned, this value is not used by the lpfc driver, only the
5656 #    SCSI midlayer.
5657 # Value range is [0,65535]. Default value is 255.
5658 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5659 */
5660 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5661 
5662 /*
5663 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5664 # Value range is [1,255], default value is 10.
5665 */
5666 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5667              "Milliseconds driver will wait between polling FCP ring");
5668 
5669 /*
5670 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5671 # to complete in seconds. Value range is [5,180], default value is 60.
5672 */
5673 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5674              "Maximum time to wait for task management commands to complete");
5675 /*
5676 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5677 #               support this feature
5678 #       0  = MSI disabled
5679 #       1  = MSI enabled
5680 #       2  = MSI-X enabled (default)
5681 # Value range is [0,2]. Default value is 2.
5682 */
5683 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5684             "MSI-X (2), if possible");
5685 
5686 /*
5687  * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5688  *
5689  *      0  = NVME OAS disabled
5690  *      1  = NVME OAS enabled
5691  *
5692  * Value range is [0,1]. Default value is 0.
5693  */
5694 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5695              "Use OAS bit on NVME IOs");
5696 
5697 /*
5698  * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5699  *
5700  *      0  = Put NVME Command in SGL
5701  *      1  = Embed NVME Command in WQE (unless G7)
5702  *      2 =  Embed NVME Command in WQE (force)
5703  *
5704  * Value range is [0,2]. Default value is 1.
5705  */
5706 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5707              "Embed NVME Command in WQE");
5708 
5709 /*
5710  * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5711  * the driver will advertise it supports to the SCSI layer.
5712  *
5713  *      0    = Set nr_hw_queues by the number of CPUs or HW queues.
5714  *      1,128 = Manually specify the maximum nr_hw_queue value to be set,
5715  *
5716  * Value range is [0,256]. Default value is 8.
5717  */
5718 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5719             LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5720             "Set the number of SCSI Queues advertised");
5721 
5722 /*
5723  * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5724  * will advertise it supports to the NVME and  SCSI layers. This also
5725  * will map to the number of CQ/WQ pairs the driver will create.
5726  *
5727  * The NVME Layer will try to create this many, plus 1 administrative
5728  * hardware queue. The administrative queue will always map to WQ 0
5729  * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5730  *
5731  *      0    = Configure the number of hdw queues to the number of active CPUs.
5732  *      1,128 = Manually specify how many hdw queues to use.
5733  *
5734  * Value range is [0,128]. Default value is 0.
5735  */
5736 LPFC_ATTR_R(hdw_queue,
5737             LPFC_HBA_HDWQ_DEF,
5738             LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5739             "Set the number of I/O Hardware Queues");
5740 
5741 /*
5742  * lpfc_irq_chann: Set the number of IRQ vectors that are available
5743  * for Hardware Queues to utilize.  This also will map to the number
5744  * of EQ / MSI-X vectors the driver will create. This should never be
5745  * more than the number of Hardware Queues
5746  *
5747  *      0     = Configure number of IRQ Channels to the number of active CPUs.
5748  *      1,128 = Manually specify how many IRQ Channels to use.
5749  *
5750  * Value range is [0,128]. Default value is 0.
5751  */
5752 LPFC_ATTR_R(irq_chann,
5753             LPFC_HBA_HDWQ_DEF,
5754             LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5755             "Set the number of I/O IRQ Channels");
5756 
5757 /*
5758 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5759 #       0  = HBA resets disabled
5760 #       1  = HBA resets enabled (default)
5761 #       2  = HBA reset via PCI bus reset enabled
5762 # Value range is [0,2]. Default value is 1.
5763 */
5764 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5765 
5766 /*
5767 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5768 #       0  = HBA Heartbeat disabled
5769 #       1  = HBA Heartbeat enabled (default)
5770 # Value range is [0,1]. Default value is 1.
5771 */
5772 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5773 
5774 /*
5775 # lpfc_EnableXLane: Enable Express Lane Feature
5776 #      0x0   Express Lane Feature disabled
5777 #      0x1   Express Lane Feature enabled
5778 # Value range is [0,1]. Default value is 0.
5779 */
5780 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5781 
5782 /*
5783 # lpfc_XLanePriority:  Define CS_CTL priority for Express Lane Feature
5784 #       0x0 - 0x7f  = CS_CTL field in FC header (high 7 bits)
5785 # Value range is [0x0,0x7f]. Default value is 0
5786 */
5787 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5788 
5789 /*
5790 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5791 #       0  = BlockGuard disabled (default)
5792 #       1  = BlockGuard enabled
5793 # Value range is [0,1]. Default value is 0.
5794 */
5795 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5796 
5797 /*
5798 # lpfc_prot_mask: i
5799 #       - Bit mask of host protection capabilities used to register with the
5800 #         SCSI mid-layer
5801 #       - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5802 #       - Allows you to ultimately specify which profiles to use
5803 #       - Default will result in registering capabilities for all profiles.
5804 #       - SHOST_DIF_TYPE1_PROTECTION    1
5805 #               HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5806 #       - SHOST_DIX_TYPE0_PROTECTION    8
5807 #               HBA supports DIX Type 0: Host to HBA protection only
5808 #       - SHOST_DIX_TYPE1_PROTECTION    16
5809 #               HBA supports DIX Type 1: Host to HBA  Type 1 protection
5810 #
5811 */
5812 LPFC_ATTR(prot_mask,
5813         (SHOST_DIF_TYPE1_PROTECTION |
5814         SHOST_DIX_TYPE0_PROTECTION |
5815         SHOST_DIX_TYPE1_PROTECTION),
5816         0,
5817         (SHOST_DIF_TYPE1_PROTECTION |
5818         SHOST_DIX_TYPE0_PROTECTION |
5819         SHOST_DIX_TYPE1_PROTECTION),
5820         "T10-DIF host protection capabilities mask");
5821 
5822 /*
5823 # lpfc_prot_guard: i
5824 #       - Bit mask of protection guard types to register with the SCSI mid-layer
5825 #       - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5826 #       - Allows you to ultimately specify which profiles to use
5827 #       - Default will result in registering capabilities for all guard types
5828 #
5829 */
5830 LPFC_ATTR(prot_guard,
5831         SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5832         "T10-DIF host protection guard type");
5833 
5834 /*
5835  * Delay initial NPort discovery when Clean Address bit is cleared in
5836  * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5837  * This parameter can have value 0 or 1.
5838  * When this parameter is set to 0, no delay is added to the initial
5839  * discovery.
5840  * When this parameter is set to non-zero value, initial Nport discovery is
5841  * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5842  * accept and FCID/Fabric name/Fabric portname is changed.
5843  * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5844  * when Clean Address bit is cleared in FLOGI/FDISC
5845  * accept and FCID/Fabric name/Fabric portname is changed.
5846  * Default value is 0.
5847  */
5848 LPFC_ATTR(delay_discovery, 0, 0, 1,
5849         "Delay NPort discovery when Clean Address bit is cleared.");
5850 
5851 /*
5852  * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5853  * This value can be set to values between 64 and 4096. The default value
5854  * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5855  * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5856  * Because of the additional overhead involved in setting up T10-DIF,
5857  * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5858  * and will be limited to 512 if BlockGuard is enabled under SLI3.
5859  */
5860 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5861 module_param(lpfc_sg_seg_cnt, uint, 0444);
5862 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5863 
5864 /**
5865  * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5866  *    configured for the adapter
5867  * @dev: class converted to a Scsi_host structure.
5868  * @attr: device attribute, not used.
5869  * @buf: on return contains a string with the list sizes
5870  *
5871  * Returns: size of formatted string.
5872  **/
5873 static ssize_t
5874 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5875                      char *buf)
5876 {
5877         struct Scsi_Host  *shost = class_to_shost(dev);
5878         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5879         struct lpfc_hba   *phba = vport->phba;
5880         int len;
5881 
5882         len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d  total SGEs: %d\n",
5883                        phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5884 
5885         len += scnprintf(buf + len, PAGE_SIZE, "Cfg: %d  SCSI: %d  NVME: %d\n",
5886                         phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5887                         phba->cfg_nvme_seg_cnt);
5888         return len;
5889 }
5890 
5891 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5892 
5893 /**
5894  * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5895  * @phba: lpfc_hba pointer.
5896  * @val: contains the initial value
5897  *
5898  * Description:
5899  * Validates the initial value is within range and assigns it to the
5900  * adapter. If not in range, an error message is posted and the
5901  * default value is assigned.
5902  *
5903  * Returns:
5904  * zero if value is in range and is set
5905  * -EINVAL if value was out of range
5906  **/
5907 static int
5908 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5909 {
5910         if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5911                 phba->cfg_sg_seg_cnt = val;
5912                 return 0;
5913         }
5914         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5915                         "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5916                         "be set to %d, allowed range is [%d, %d]\n",
5917                         val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5918         phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5919         return -EINVAL;
5920 }
5921 
5922 /*
5923  * lpfc_enable_mds_diags: Enable MDS Diagnostics
5924  *       0  = MDS Diagnostics disabled (default)
5925  *       1  = MDS Diagnostics enabled
5926  * Value range is [0,1]. Default value is 0.
5927  */
5928 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5929 
5930 /*
5931  * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5932  *      0 = Disable firmware logging (default)
5933  *      [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5934  * Value range [0..4]. Default value is 0
5935  */
5936 LPFC_ATTR_RW(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5937 
5938 /*
5939  * lpfc_ras_fwlog_level: Firmware logging verbosity level
5940  * Valid only if firmware logging is enabled
5941  * 0(Least Verbosity) 4 (most verbosity)
5942  * Value range is [0..4]. Default value is 0
5943  */
5944 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5945 
5946 /*
5947  * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5948  * Default function which has RAS support : 0
5949  * Value Range is [0..7].
5950  * FW logging is a global action and enablement is via a specific
5951  * port.
5952  */
5953 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5954 
5955 /*
5956  * lpfc_enable_bbcr: Enable BB Credit Recovery
5957  *       0  = BB Credit Recovery disabled
5958  *       1  = BB Credit Recovery enabled (default)
5959  * Value range is [0,1]. Default value is 1.
5960  */
5961 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5962 
5963 /*
5964  * lpfc_enable_dpp: Enable DPP on G7
5965  *       0  = DPP on G7 disabled
5966  *       1  = DPP on G7 enabled (default)
5967  * Value range is [0,1]. Default value is 1.
5968  */
5969 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5970 
5971 struct device_attribute *lpfc_hba_attrs[] = {
5972         &dev_attr_nvme_info,
5973         &dev_attr_scsi_stat,
5974         &dev_attr_bg_info,
5975         &dev_attr_bg_guard_err,
5976         &dev_attr_bg_apptag_err,
5977         &dev_attr_bg_reftag_err,
5978         &dev_attr_info,
5979         &dev_attr_serialnum,
5980         &dev_attr_modeldesc,
5981         &dev_attr_modelname,
5982         &dev_attr_programtype,
5983         &dev_attr_portnum,
5984         &dev_attr_fwrev,
5985         &dev_attr_hdw,
5986         &dev_attr_option_rom_version,
5987         &dev_attr_link_state,
5988         &dev_attr_num_discovered_ports,
5989         &dev_attr_menlo_mgmt_mode,
5990         &dev_attr_lpfc_drvr_version,
5991         &dev_attr_lpfc_enable_fip,
5992         &dev_attr_lpfc_temp_sensor,
5993         &dev_attr_lpfc_log_verbose,
5994         &dev_attr_lpfc_lun_queue_depth,
5995         &dev_attr_lpfc_tgt_queue_depth,
5996         &dev_attr_lpfc_hba_queue_depth,
5997         &dev_attr_lpfc_peer_port_login,
5998         &dev_attr_lpfc_nodev_tmo,
5999         &dev_attr_lpfc_devloss_tmo,
6000         &dev_attr_lpfc_enable_fc4_type,
6001         &dev_attr_lpfc_fcp_class,
6002         &dev_attr_lpfc_use_adisc,
6003         &dev_attr_lpfc_first_burst_size,
6004         &dev_attr_lpfc_ack0,
6005         &dev_attr_lpfc_xri_rebalancing,
6006         &dev_attr_lpfc_topology,
6007         &dev_attr_lpfc_scan_down,
6008         &dev_attr_lpfc_link_speed,
6009         &dev_attr_lpfc_fcp_io_sched,
6010         &dev_attr_lpfc_ns_query,
6011         &dev_attr_lpfc_fcp2_no_tgt_reset,
6012         &dev_attr_lpfc_cr_delay,
6013         &dev_attr_lpfc_cr_count,
6014         &dev_attr_lpfc_multi_ring_support,
6015         &dev_attr_lpfc_multi_ring_rctl,
6016         &dev_attr_lpfc_multi_ring_type,
6017         &dev_attr_lpfc_fdmi_on,
6018         &dev_attr_lpfc_enable_SmartSAN,
6019         &dev_attr_lpfc_max_luns,
6020         &dev_attr_lpfc_enable_npiv,
6021         &dev_attr_lpfc_fcf_failover_policy,
6022         &dev_attr_lpfc_enable_rrq,
6023         &dev_attr_nport_evt_cnt,
6024         &dev_attr_board_mode,
6025         &dev_attr_max_vpi,
6026         &dev_attr_used_vpi,
6027         &dev_attr_max_rpi,
6028         &dev_attr_used_rpi,
6029         &dev_attr_max_xri,
6030         &dev_attr_used_xri,
6031         &dev_attr_npiv_info,
6032         &dev_attr_issue_reset,
6033         &dev_attr_lpfc_poll,
6034         &dev_attr_lpfc_poll_tmo,
6035         &dev_attr_lpfc_task_mgmt_tmo,
6036         &dev_attr_lpfc_use_msi,
6037         &dev_attr_lpfc_nvme_oas,
6038         &dev_attr_lpfc_nvme_embed_cmd,
6039         &dev_attr_lpfc_fcp_imax,
6040         &dev_attr_lpfc_force_rscn,
6041         &dev_attr_lpfc_cq_poll_threshold,
6042         &dev_attr_lpfc_cq_max_proc_limit,
6043         &dev_attr_lpfc_fcp_cpu_map,
6044         &dev_attr_lpfc_fcp_mq_threshold,
6045         &dev_attr_lpfc_hdw_queue,
6046         &dev_attr_lpfc_irq_chann,
6047         &dev_attr_lpfc_suppress_rsp,
6048         &dev_attr_lpfc_nvmet_mrq,
6049         &dev_attr_lpfc_nvmet_mrq_post,
6050         &dev_attr_lpfc_nvme_enable_fb,
6051         &dev_attr_lpfc_nvmet_fb_size,
6052         &dev_attr_lpfc_enable_bg,
6053         &dev_attr_lpfc_soft_wwnn,
6054         &dev_attr_lpfc_soft_wwpn,
6055         &dev_attr_lpfc_soft_wwn_enable,
6056         &dev_attr_lpfc_enable_hba_reset,
6057         &dev_attr_lpfc_enable_hba_heartbeat,
6058         &dev_attr_lpfc_EnableXLane,
6059         &dev_attr_lpfc_XLanePriority,
6060         &dev_attr_lpfc_xlane_lun,
6061         &dev_attr_lpfc_xlane_tgt,
6062         &dev_attr_lpfc_xlane_vpt,
6063         &dev_attr_lpfc_xlane_lun_state,
6064         &dev_attr_lpfc_xlane_lun_status,
6065         &dev_attr_lpfc_xlane_priority,
6066         &dev_attr_lpfc_sg_seg_cnt,
6067         &dev_attr_lpfc_max_scsicmpl_time,
6068         &dev_attr_lpfc_stat_data_ctrl,
6069         &dev_attr_lpfc_aer_support,
6070         &dev_attr_lpfc_aer_state_cleanup,
6071         &dev_attr_lpfc_sriov_nr_virtfn,
6072         &dev_attr_lpfc_req_fw_upgrade,
6073         &dev_attr_lpfc_suppress_link_up,
6074         &dev_attr_lpfc_iocb_cnt,
6075         &dev_attr_iocb_hw,
6076         &dev_attr_txq_hw,
6077         &dev_attr_txcmplq_hw,
6078         &dev_attr_lpfc_fips_level,
6079         &dev_attr_lpfc_fips_rev,
6080         &dev_attr_lpfc_dss,
6081         &dev_attr_lpfc_sriov_hw_max_virtfn,
6082         &dev_attr_protocol,
6083         &dev_attr_lpfc_xlane_supported,
6084         &dev_attr_lpfc_enable_mds_diags,
6085         &dev_attr_lpfc_ras_fwlog_buffsize,
6086         &dev_attr_lpfc_ras_fwlog_level,
6087         &dev_attr_lpfc_ras_fwlog_func,
6088         &dev_attr_lpfc_enable_bbcr,
6089         &dev_attr_lpfc_enable_dpp,
6090         NULL,
6091 };
6092 
6093 struct device_attribute *lpfc_vport_attrs[] = {
6094         &dev_attr_info,
6095         &dev_attr_link_state,
6096         &dev_attr_num_discovered_ports,
6097         &dev_attr_lpfc_drvr_version,
6098         &dev_attr_lpfc_log_verbose,
6099         &dev_attr_lpfc_lun_queue_depth,
6100         &dev_attr_lpfc_tgt_queue_depth,
6101         &dev_attr_lpfc_nodev_tmo,
6102         &dev_attr_lpfc_devloss_tmo,
6103         &dev_attr_lpfc_hba_queue_depth,
6104         &dev_attr_lpfc_peer_port_login,
6105         &dev_attr_lpfc_restrict_login,
6106         &dev_attr_lpfc_fcp_class,
6107         &dev_attr_lpfc_use_adisc,
6108         &dev_attr_lpfc_first_burst_size,
6109         &dev_attr_lpfc_max_luns,
6110         &dev_attr_nport_evt_cnt,
6111         &dev_attr_npiv_info,
6112         &dev_attr_lpfc_enable_da_id,
6113         &dev_attr_lpfc_max_scsicmpl_time,
6114         &dev_attr_lpfc_stat_data_ctrl,
6115         &dev_attr_lpfc_static_vport,
6116         &dev_attr_lpfc_fips_level,
6117         &dev_attr_lpfc_fips_rev,
6118         NULL,
6119 };
6120 
6121 /**
6122  * sysfs_ctlreg_write - Write method for writing to ctlreg
6123  * @filp: open sysfs file
6124  * @kobj: kernel kobject that contains the kernel class device.
6125  * @bin_attr: kernel attributes passed to us.
6126  * @buf: contains the data to be written to the adapter IOREG space.
6127  * @off: offset into buffer to beginning of data.
6128  * @count: bytes to transfer.
6129  *
6130  * Description:
6131  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6132  * Uses the adapter io control registers to send buf contents to the adapter.
6133  *
6134  * Returns:
6135  * -ERANGE off and count combo out of range
6136  * -EINVAL off, count or buff address invalid
6137  * -EPERM adapter is offline
6138  * value of count, buf contents written
6139  **/
6140 static ssize_t
6141 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6142                    struct bin_attribute *bin_attr,
6143                    char *buf, loff_t off, size_t count)
6144 {
6145         size_t buf_off;
6146         struct device *dev = container_of(kobj, struct device, kobj);
6147         struct Scsi_Host  *shost = class_to_shost(dev);
6148         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6149         struct lpfc_hba   *phba = vport->phba;
6150 
6151         if (phba->sli_rev >= LPFC_SLI_REV4)
6152                 return -EPERM;
6153 
6154         if ((off + count) > FF_REG_AREA_SIZE)
6155                 return -ERANGE;
6156 
6157         if (count <= LPFC_REG_WRITE_KEY_SIZE)
6158                 return 0;
6159 
6160         if (off % 4 || count % 4 || (unsigned long)buf % 4)
6161                 return -EINVAL;
6162 
6163         /* This is to protect HBA registers from accidental writes. */
6164         if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6165                 return -EINVAL;
6166 
6167         if (!(vport->fc_flag & FC_OFFLINE_MODE))
6168                 return -EPERM;
6169 
6170         spin_lock_irq(&phba->hbalock);
6171         for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6172                         buf_off += sizeof(uint32_t))
6173                 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6174                        phba->ctrl_regs_memmap_p + off + buf_off);
6175 
6176         spin_unlock_irq(&phba->hbalock);
6177 
6178         return count;
6179 }
6180 
6181 /**
6182  * sysfs_ctlreg_read - Read method for reading from ctlreg
6183  * @filp: open sysfs file
6184  * @kobj: kernel kobject that contains the kernel class device.
6185  * @bin_attr: kernel attributes passed to us.
6186  * @buf: if successful contains the data from the adapter IOREG space.
6187  * @off: offset into buffer to beginning of data.
6188  * @count: bytes to transfer.
6189  *
6190  * Description:
6191  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6192  * Uses the adapter io control registers to read data into buf.
6193  *
6194  * Returns:
6195  * -ERANGE off and count combo out of range
6196  * -EINVAL off, count or buff address invalid
6197  * value of count, buf contents read
6198  **/
6199 static ssize_t
6200 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6201                   struct bin_attribute *bin_attr,
6202                   char *buf, loff_t off, size_t count)
6203 {
6204         size_t buf_off;
6205         uint32_t * tmp_ptr;
6206         struct device *dev = container_of(kobj, struct device, kobj);
6207         struct Scsi_Host  *shost = class_to_shost(dev);
6208         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6209         struct lpfc_hba   *phba = vport->phba;
6210 
6211         if (phba->sli_rev >= LPFC_SLI_REV4)
6212                 return -EPERM;
6213 
6214         if (off > FF_REG_AREA_SIZE)
6215                 return -ERANGE;
6216 
6217         if ((off + count) > FF_REG_AREA_SIZE)
6218                 count = FF_REG_AREA_SIZE - off;
6219 
6220         if (count == 0) return 0;
6221 
6222         if (off % 4 || count % 4 || (unsigned long)buf % 4)
6223                 return -EINVAL;
6224 
6225         spin_lock_irq(&phba->hbalock);
6226 
6227         for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6228                 tmp_ptr = (uint32_t *)(buf + buf_off);
6229                 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6230         }
6231 
6232         spin_unlock_irq(&phba->hbalock);
6233 
6234         return count;
6235 }
6236 
6237 static struct bin_attribute sysfs_ctlreg_attr = {
6238         .attr = {
6239                 .name = "ctlreg",
6240                 .mode = S_IRUSR | S_IWUSR,
6241         },
6242         .size = 256,
6243         .read = sysfs_ctlreg_read,
6244         .write = sysfs_ctlreg_write,
6245 };
6246 
6247 /**
6248  * sysfs_mbox_write - Write method for writing information via mbox
6249  * @filp: open sysfs file
6250  * @kobj: kernel kobject that contains the kernel class device.
6251  * @bin_attr: kernel attributes passed to us.
6252  * @buf: contains the data to be written to sysfs mbox.
6253  * @off: offset into buffer to beginning of data.
6254  * @count: bytes to transfer.
6255  *
6256  * Description:
6257  * Deprecated function. All mailbox access from user space is performed via the
6258  * bsg interface.
6259  *
6260  * Returns:
6261  * -EPERM operation not permitted
6262  **/
6263 static ssize_t
6264 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6265                  struct bin_attribute *bin_attr,
6266                  char *buf, loff_t off, size_t count)
6267 {
6268         return -EPERM;
6269 }
6270 
6271 /**
6272  * sysfs_mbox_read - Read method for reading information via mbox
6273  * @filp: open sysfs file
6274  * @kobj: kernel kobject that contains the kernel class device.
6275  * @bin_attr: kernel attributes passed to us.
6276  * @buf: contains the data to be read from sysfs mbox.
6277  * @off: offset into buffer to beginning of data.
6278  * @count: bytes to transfer.
6279  *
6280  * Description:
6281  * Deprecated function. All mailbox access from user space is performed via the
6282  * bsg interface.
6283  *
6284  * Returns:
6285  * -EPERM operation not permitted
6286  **/
6287 static ssize_t
6288 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6289                 struct bin_attribute *bin_attr,
6290                 char *buf, loff_t off, size_t count)
6291 {
6292         return -EPERM;
6293 }
6294 
6295 static struct bin_attribute sysfs_mbox_attr = {
6296         .attr = {
6297                 .name = "mbox",
6298                 .mode = S_IRUSR | S_IWUSR,
6299         },
6300         .size = MAILBOX_SYSFS_MAX,
6301         .read = sysfs_mbox_read,
6302         .write = sysfs_mbox_write,
6303 };
6304 
6305 /**
6306  * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6307  * @vport: address of lpfc vport structure.
6308  *
6309  * Return codes:
6310  * zero on success
6311  * error return code from sysfs_create_bin_file()
6312  **/
6313 int
6314 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6315 {
6316         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6317         int error;
6318 
6319         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6320                                       &sysfs_drvr_stat_data_attr);
6321 
6322         /* Virtual ports do not need ctrl_reg and mbox */
6323         if (error || vport->port_type == LPFC_NPIV_PORT)
6324                 goto out;
6325 
6326         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6327                                       &sysfs_ctlreg_attr);
6328         if (error)
6329                 goto out_remove_stat_attr;
6330 
6331         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6332                                       &sysfs_mbox_attr);
6333         if (error)
6334                 goto out_remove_ctlreg_attr;
6335 
6336         return 0;
6337 out_remove_ctlreg_attr:
6338         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6339 out_remove_stat_attr:
6340         sysfs_remove_bin_file(&shost->shost_dev.kobj,
6341                         &sysfs_drvr_stat_data_attr);
6342 out:
6343         return error;
6344 }
6345 
6346 /**
6347  * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6348  * @vport: address of lpfc vport structure.
6349  **/
6350 void
6351 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6352 {
6353         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6354         sysfs_remove_bin_file(&shost->shost_dev.kobj,
6355                 &sysfs_drvr_stat_data_attr);
6356         /* Virtual ports do not need ctrl_reg and mbox */
6357         if (vport->port_type == LPFC_NPIV_PORT)
6358                 return;
6359         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6360         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6361 }
6362 
6363 /*
6364  * Dynamic FC Host Attributes Support
6365  */
6366 
6367 /**
6368  * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6369  * @shost: kernel scsi host pointer.
6370  **/
6371 static void
6372 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6373 {
6374         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6375 
6376         lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6377                                       sizeof fc_host_symbolic_name(shost));
6378 }
6379 
6380 /**
6381  * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6382  * @shost: kernel scsi host pointer.
6383  **/
6384 static void
6385 lpfc_get_host_port_id(struct Scsi_Host *shost)
6386 {
6387         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6388 
6389         /* note: fc_myDID already in cpu endianness */
6390         fc_host_port_id(shost) = vport->fc_myDID;
6391 }
6392 
6393 /**
6394  * lpfc_get_host_port_type - Set the value of the scsi host port type
6395  * @shost: kernel scsi host pointer.
6396  **/
6397 static void
6398 lpfc_get_host_port_type(struct Scsi_Host *shost)
6399 {
6400         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6401         struct lpfc_hba   *phba = vport->phba;
6402 
6403         spin_lock_irq(shost->host_lock);
6404 
6405         if (vport->port_type == LPFC_NPIV_PORT) {
6406                 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6407         } else if (lpfc_is_link_up(phba)) {
6408                 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6409                         if (vport->fc_flag & FC_PUBLIC_LOOP)
6410                                 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6411                         else
6412                                 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6413                 } else {
6414                         if (vport->fc_flag & FC_FABRIC)
6415                                 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6416                         else
6417                                 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6418                 }
6419         } else
6420                 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6421 
6422         spin_unlock_irq(shost->host_lock);
6423 }
6424 
6425 /**
6426  * lpfc_get_host_port_state - Set the value of the scsi host port state
6427  * @shost: kernel scsi host pointer.
6428  **/
6429 static void
6430 lpfc_get_host_port_state(struct Scsi_Host *shost)
6431 {
6432         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6433         struct lpfc_hba   *phba = vport->phba;
6434 
6435         spin_lock_irq(shost->host_lock);
6436 
6437         if (vport->fc_flag & FC_OFFLINE_MODE)
6438                 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6439         else {
6440                 switch (phba->link_state) {
6441                 case LPFC_LINK_UNKNOWN:
6442                 case LPFC_LINK_DOWN:
6443                         fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6444                         break;
6445                 case LPFC_LINK_UP:
6446                 case LPFC_CLEAR_LA:
6447                 case LPFC_HBA_READY:
6448                         /* Links up, reports port state accordingly */
6449                         if (vport->port_state < LPFC_VPORT_READY)
6450                                 fc_host_port_state(shost) =
6451                                                         FC_PORTSTATE_BYPASSED;
6452                         else
6453                                 fc_host_port_state(shost) =
6454                                                         FC_PORTSTATE_ONLINE;
6455                         break;
6456                 case LPFC_HBA_ERROR:
6457                         fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6458                         break;
6459                 default:
6460                         fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6461                         break;
6462                 }
6463         }
6464 
6465         spin_unlock_irq(shost->host_lock);
6466 }
6467 
6468 /**
6469  * lpfc_get_host_speed - Set the value of the scsi host speed
6470  * @shost: kernel scsi host pointer.
6471  **/
6472 static void
6473 lpfc_get_host_speed(struct Scsi_Host *shost)
6474 {
6475         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6476         struct lpfc_hba   *phba = vport->phba;
6477 
6478         spin_lock_irq(shost->host_lock);
6479 
6480         if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6481                 switch(phba->fc_linkspeed) {
6482                 case LPFC_LINK_SPEED_1GHZ:
6483                         fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6484                         break;
6485                 case LPFC_LINK_SPEED_2GHZ:
6486                         fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6487                         break;
6488                 case LPFC_LINK_SPEED_4GHZ:
6489                         fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6490                         break;
6491                 case LPFC_LINK_SPEED_8GHZ:
6492                         fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6493                         break;
6494                 case LPFC_LINK_SPEED_10GHZ:
6495                         fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6496                         break;
6497                 case LPFC_LINK_SPEED_16GHZ:
6498                         fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6499                         break;
6500                 case LPFC_LINK_SPEED_32GHZ:
6501                         fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6502                         break;
6503                 case LPFC_LINK_SPEED_64GHZ:
6504                         fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6505                         break;
6506                 case LPFC_LINK_SPEED_128GHZ:
6507                         fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6508                         break;
6509                 default:
6510                         fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6511                         break;
6512                 }
6513         } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6514                 switch (phba->fc_linkspeed) {
6515                 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6516                         fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6517                         break;
6518                 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6519                         fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6520                         break;
6521                 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6522                         fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6523                         break;
6524                 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6525                         fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6526                         break;
6527                 default:
6528                         fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6529                         break;
6530                 }
6531         } else
6532                 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6533 
6534         spin_unlock_irq(shost->host_lock);
6535 }
6536 
6537 /**
6538  * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6539  * @shost: kernel scsi host pointer.
6540  **/
6541 static void
6542 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6543 {
6544         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6545         struct lpfc_hba   *phba = vport->phba;
6546         u64 node_name;
6547 
6548         spin_lock_irq(shost->host_lock);
6549 
6550         if ((vport->port_state > LPFC_FLOGI) &&
6551             ((vport->fc_flag & FC_FABRIC) ||
6552              ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6553               (vport->fc_flag & FC_PUBLIC_LOOP))))
6554                 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6555         else
6556                 /* fabric is local port if there is no F/FL_Port */
6557                 node_name = 0;
6558 
6559         spin_unlock_irq(shost->host_lock);
6560 
6561         fc_host_fabric_name(shost) = node_name;
6562 }
6563 
6564 /**
6565  * lpfc_get_stats - Return statistical information about the adapter
6566  * @shost: kernel scsi host pointer.
6567  *
6568  * Notes:
6569  * NULL on error for link down, no mbox pool, sli2 active,
6570  * management not allowed, memory allocation error, or mbox error.
6571  *
6572  * Returns:
6573  * NULL for error
6574  * address of the adapter host statistics
6575  **/
6576 static struct fc_host_statistics *
6577 lpfc_get_stats(struct Scsi_Host *shost)
6578 {
6579         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6580         struct lpfc_hba   *phba = vport->phba;
6581         struct lpfc_sli   *psli = &phba->sli;
6582         struct fc_host_statistics *hs = &phba->link_stats;
6583         struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6584         LPFC_MBOXQ_t *pmboxq;
6585         MAILBOX_t *pmb;
6586         int rc = 0;
6587 
6588         /*
6589          * prevent udev from issuing mailbox commands until the port is
6590          * configured.
6591          */
6592         if (phba->link_state < LPFC_LINK_DOWN ||
6593             !phba->mbox_mem_pool ||
6594             (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6595                 return NULL;
6596 
6597         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6598                 return NULL;
6599 
6600         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6601         if (!pmboxq)
6602                 return NULL;
6603         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6604 
6605         pmb = &pmboxq->u.mb;
6606         pmb->mbxCommand = MBX_READ_STATUS;
6607         pmb->mbxOwner = OWN_HOST;
6608         pmboxq->ctx_buf = NULL;
6609         pmboxq->vport = vport;
6610 
6611         if (vport->fc_flag & FC_OFFLINE_MODE)
6612                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6613         else
6614                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6615 
6616         if (rc != MBX_SUCCESS) {
6617                 if (rc != MBX_TIMEOUT)
6618                         mempool_free(pmboxq, phba->mbox_mem_pool);
6619                 return NULL;
6620         }
6621 
6622         memset(hs, 0, sizeof (struct fc_host_statistics));
6623 
6624         hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6625         /*
6626          * The MBX_READ_STATUS returns tx_k_bytes which has to
6627          * converted to words
6628          */
6629         hs->tx_words = (uint64_t)
6630                         ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6631                         * (uint64_t)256);
6632         hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6633         hs->rx_words = (uint64_t)
6634                         ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6635                          * (uint64_t)256);
6636 
6637         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6638         pmb->mbxCommand = MBX_READ_LNK_STAT;
6639         pmb->mbxOwner = OWN_HOST;
6640         pmboxq->ctx_buf = NULL;
6641         pmboxq->vport = vport;
6642 
6643         if (vport->fc_flag & FC_OFFLINE_MODE)
6644                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6645         else
6646                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6647 
6648         if (rc != MBX_SUCCESS) {
6649                 if (rc != MBX_TIMEOUT)
6650                         mempool_free(pmboxq, phba->mbox_mem_pool);
6651                 return NULL;
6652         }
6653 
6654         hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6655         hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6656         hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6657         hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6658         hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6659         hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6660         hs->error_frames = pmb->un.varRdLnk.crcCnt;
6661 
6662         hs->link_failure_count -= lso->link_failure_count;
6663         hs->loss_of_sync_count -= lso->loss_of_sync_count;
6664         hs->loss_of_signal_count -= lso->loss_of_signal_count;
6665         hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6666         hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6667         hs->invalid_crc_count -= lso->invalid_crc_count;
6668         hs->error_frames -= lso->error_frames;
6669 
6670         if (phba->hba_flag & HBA_FCOE_MODE) {
6671                 hs->lip_count = -1;
6672                 hs->nos_count = (phba->link_events >> 1);
6673                 hs->nos_count -= lso->link_events;
6674         } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6675                 hs->lip_count = (phba->fc_eventTag >> 1);
6676                 hs->lip_count -= lso->link_events;
6677                 hs->nos_count = -1;
6678         } else {
6679                 hs->lip_count = -1;
6680                 hs->nos_count = (phba->fc_eventTag >> 1);
6681                 hs->nos_count -= lso->link_events;
6682         }
6683 
6684         hs->dumped_frames = -1;
6685 
6686         hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6687 
6688         mempool_free(pmboxq, phba->mbox_mem_pool);
6689 
6690         return hs;
6691 }
6692 
6693 /**
6694  * lpfc_reset_stats - Copy the adapter link stats information
6695  * @shost: kernel scsi host pointer.
6696  **/
6697 static void
6698 lpfc_reset_stats(struct Scsi_Host *shost)
6699 {
6700         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6701         struct lpfc_hba   *phba = vport->phba;
6702         struct lpfc_sli   *psli = &phba->sli;
6703         struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6704         LPFC_MBOXQ_t *pmboxq;
6705         MAILBOX_t *pmb;
6706         int rc = 0;
6707 
6708         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6709                 return;
6710 
6711         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6712         if (!pmboxq)
6713                 return;
6714         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6715 
6716         pmb = &pmboxq->u.mb;
6717         pmb->mbxCommand = MBX_READ_STATUS;
6718         pmb->mbxOwner = OWN_HOST;
6719         pmb->un.varWords[0] = 0x1; /* reset request */
6720         pmboxq->ctx_buf = NULL;
6721         pmboxq->vport = vport;
6722 
6723         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6724                 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6725                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6726         else
6727                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6728 
6729         if (rc != MBX_SUCCESS) {
6730                 if (rc != MBX_TIMEOUT)
6731                         mempool_free(pmboxq, phba->mbox_mem_pool);
6732                 return;
6733         }
6734 
6735         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6736         pmb->mbxCommand = MBX_READ_LNK_STAT;
6737         pmb->mbxOwner = OWN_HOST;
6738         pmboxq->ctx_buf = NULL;
6739         pmboxq->vport = vport;
6740 
6741         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6742             (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6743                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6744         else
6745                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6746 
6747         if (rc != MBX_SUCCESS) {
6748                 if (rc != MBX_TIMEOUT)
6749                         mempool_free( pmboxq, phba->mbox_mem_pool);
6750                 return;
6751         }
6752 
6753         lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6754         lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6755         lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6756         lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6757         lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6758         lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6759         lso->error_frames = pmb->un.varRdLnk.crcCnt;
6760         if (phba->hba_flag & HBA_FCOE_MODE)
6761                 lso->link_events = (phba->link_events >> 1);
6762         else
6763                 lso->link_events = (phba->fc_eventTag >> 1);
6764 
6765         psli->stats_start = ktime_get_seconds();
6766 
6767         mempool_free(pmboxq, phba->mbox_mem_pool);
6768 
6769         return;
6770 }
6771 
6772 /*
6773  * The LPFC driver treats linkdown handling as target loss events so there
6774  * are no sysfs handlers for link_down_tmo.
6775  */
6776 
6777 /**
6778  * lpfc_get_node_by_target - Return the nodelist for a target
6779  * @starget: kernel scsi target pointer.
6780  *
6781  * Returns:
6782  * address of the node list if found
6783  * NULL target not found
6784  **/
6785 static struct lpfc_nodelist *
6786 lpfc_get_node_by_target(struct scsi_target *starget)
6787 {
6788         struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);
6789         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6790         struct lpfc_nodelist *ndlp;
6791 
6792         spin_lock_irq(shost->host_lock);
6793         /* Search for this, mapped, target ID */
6794         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6795                 if (NLP_CHK_NODE_ACT(ndlp) &&
6796                     ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6797                     starget->id == ndlp->nlp_sid) {
6798                         spin_unlock_irq(shost->host_lock);
6799                         return ndlp;
6800                 }
6801         }
6802         spin_unlock_irq(shost->host_lock);
6803         return NULL;
6804 }
6805 
6806 /**
6807  * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6808  * @starget: kernel scsi target pointer.
6809  **/
6810 static void
6811 lpfc_get_starget_port_id(struct scsi_target *starget)
6812 {
6813         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6814 
6815         fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6816 }
6817 
6818 /**
6819  * lpfc_get_starget_node_name - Set the target node name
6820  * @starget: kernel scsi target pointer.
6821  *
6822  * Description: Set the target node name to the ndlp node name wwn or zero.
6823  **/
6824 static void
6825 lpfc_get_starget_node_name(struct scsi_target *starget)
6826 {
6827         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6828 
6829         fc_starget_node_name(starget) =
6830                 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6831 }
6832 
6833 /**
6834  * lpfc_get_starget_port_name - Set the target port name
6835  * @starget: kernel scsi target pointer.
6836  *
6837  * Description:  set the target port name to the ndlp port name wwn or zero.
6838  **/
6839 static void
6840 lpfc_get_starget_port_name(struct scsi_target *starget)
6841 {
6842         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6843 
6844         fc_starget_port_name(starget) =
6845                 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6846 }
6847 
6848 /**
6849  * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6850  * @rport: fc rport address.
6851  * @timeout: new value for dev loss tmo.
6852  *
6853  * Description:
6854  * If timeout is non zero set the dev_loss_tmo to timeout, else set
6855  * dev_loss_tmo to one.
6856  **/
6857 static void
6858 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6859 {
6860         struct lpfc_rport_data *rdata = rport->dd_data;
6861         struct lpfc_nodelist *ndlp = rdata->pnode;
6862 #if (IS_ENABLED(CONFIG_NVME_FC))
6863         struct lpfc_nvme_rport *nrport = NULL;
6864 #endif
6865 
6866         if (timeout)
6867                 rport->dev_loss_tmo = timeout;
6868         else
6869                 rport->dev_loss_tmo = 1;
6870 
6871         if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
6872                 dev_info(&rport->dev, "Cannot find remote node to "
6873                                       "set rport dev loss tmo, port_id x%x\n",
6874                                       rport->port_id);
6875                 return;
6876         }
6877 
6878 #if (IS_ENABLED(CONFIG_NVME_FC))
6879         nrport = lpfc_ndlp_get_nrport(ndlp);
6880 
6881         if (nrport && nrport->remoteport)
6882                 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6883                                                rport->dev_loss_tmo);
6884 #endif
6885 }
6886 
6887 /**
6888  * lpfc_rport_show_function - Return rport target information
6889  *
6890  * Description:
6891  * Macro that uses field to generate a function with the name lpfc_show_rport_
6892  *
6893  * lpfc_show_rport_##field: returns the bytes formatted in buf
6894  * @cdev: class converted to an fc_rport.
6895  * @buf: on return contains the target_field or zero.
6896  *
6897  * Returns: size of formatted string.
6898  **/
6899 #define lpfc_rport_show_function(field, format_string, sz, cast)        \
6900 static ssize_t                                                          \
6901 lpfc_show_rport_##field (struct device *dev,                            \
6902                          struct device_attribute *attr,                 \
6903                          char *buf)                                     \
6904 {                                                                       \
6905         struct fc_rport *rport = transport_class_to_rport(dev);         \
6906         struct lpfc_rport_data *rdata = rport->hostdata;                \
6907         return scnprintf(buf, sz, format_string,                        \
6908                 (rdata->target) ? cast rdata->target->field : 0);       \
6909 }
6910 
6911 #define lpfc_rport_rd_attr(field, format_string, sz)                    \
6912         lpfc_rport_show_function(field, format_string, sz, )            \
6913 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6914 
6915 /**
6916  * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6917  * @fc_vport: The fc_vport who's symbolic name has been changed.
6918  *
6919  * Description:
6920  * This function is called by the transport after the @fc_vport's symbolic name
6921  * has been changed. This function re-registers the symbolic name with the
6922  * switch to propagate the change into the fabric if the vport is active.
6923  **/
6924 static void
6925 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6926 {
6927         struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6928 
6929         if (vport->port_state == LPFC_VPORT_READY)
6930                 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6931 }
6932 
6933 /**
6934  * lpfc_hba_log_verbose_init - Set hba's log verbose level
6935  * @phba: Pointer to lpfc_hba struct.
6936  *
6937  * This function is called by the lpfc_get_cfgparam() routine to set the
6938  * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6939  * log message according to the module's lpfc_log_verbose parameter setting
6940  * before hba port or vport created.
6941  **/
6942 static void
6943 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6944 {
6945         phba->cfg_log_verbose = verbose;
6946 }
6947 
6948 struct fc_function_template lpfc_transport_functions = {
6949         /* fixed attributes the driver supports */
6950         .show_host_node_name = 1,
6951         .show_host_port_name = 1,
6952         .show_host_supported_classes = 1,
6953         .show_host_supported_fc4s = 1,
6954         .show_host_supported_speeds = 1,
6955         .show_host_maxframe_size = 1,
6956 
6957         .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6958         .show_host_symbolic_name = 1,
6959 
6960         /* dynamic attributes the driver supports */
6961         .get_host_port_id = lpfc_get_host_port_id,
6962         .show_host_port_id = 1,
6963 
6964         .get_host_port_type = lpfc_get_host_port_type,
6965         .show_host_port_type = 1,
6966 
6967         .get_host_port_state = lpfc_get_host_port_state,
6968         .show_host_port_state = 1,
6969 
6970         /* active_fc4s is shown but doesn't change (thus no get function) */
6971         .show_host_active_fc4s = 1,
6972 
6973         .get_host_speed = lpfc_get_host_speed,
6974         .show_host_speed = 1,
6975 
6976         .get_host_fabric_name = lpfc_get_host_fabric_name,
6977         .show_host_fabric_name = 1,
6978 
6979         /*
6980          * The LPFC driver treats linkdown handling as target loss events
6981          * so there are no sysfs handlers for link_down_tmo.
6982          */
6983 
6984         .get_fc_host_stats = lpfc_get_stats,
6985         .reset_fc_host_stats = lpfc_reset_stats,
6986 
6987         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6988         .show_rport_maxframe_size = 1,
6989         .show_rport_supported_classes = 1,
6990 
6991         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6992         .show_rport_dev_loss_tmo = 1,
6993 
6994         .get_starget_port_id  = lpfc_get_starget_port_id,
6995         .show_starget_port_id = 1,
6996 
6997         .get_starget_node_name = lpfc_get_starget_node_name,
6998         .show_starget_node_name = 1,
6999 
7000         .get_starget_port_name = lpfc_get_starget_port_name,
7001         .show_starget_port_name = 1,
7002 
7003         .issue_fc_host_lip = lpfc_issue_lip,
7004         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7005         .terminate_rport_io = lpfc_terminate_rport_io,
7006 
7007         .dd_fcvport_size = sizeof(struct lpfc_vport *),
7008 
7009         .vport_disable = lpfc_vport_disable,
7010 
7011         .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7012 
7013         .bsg_request = lpfc_bsg_request,
7014         .bsg_timeout = lpfc_bsg_timeout,
7015 };
7016 
7017 struct fc_function_template lpfc_vport_transport_functions = {
7018         /* fixed attributes the driver supports */
7019         .show_host_node_name = 1,
7020         .show_host_port_name = 1,
7021         .show_host_supported_classes = 1,
7022         .show_host_supported_fc4s = 1,
7023         .show_host_supported_speeds = 1,
7024         .show_host_maxframe_size = 1,
7025 
7026         .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7027         .show_host_symbolic_name = 1,
7028 
7029         /* dynamic attributes the driver supports */
7030         .get_host_port_id = lpfc_get_host_port_id,
7031         .show_host_port_id = 1,
7032 
7033         .get_host_port_type = lpfc_get_host_port_type,
7034         .show_host_port_type = 1,
7035 
7036         .get_host_port_state = lpfc_get_host_port_state,
7037         .show_host_port_state = 1,
7038 
7039         /* active_fc4s is shown but doesn't change (thus no get function) */
7040         .show_host_active_fc4s = 1,
7041 
7042         .get_host_speed = lpfc_get_host_speed,
7043         .show_host_speed = 1,
7044 
7045         .get_host_fabric_name = lpfc_get_host_fabric_name,
7046         .show_host_fabric_name = 1,
7047 
7048         /*
7049          * The LPFC driver treats linkdown handling as target loss events
7050          * so there are no sysfs handlers for link_down_tmo.
7051          */
7052 
7053         .get_fc_host_stats = lpfc_get_stats,
7054         .reset_fc_host_stats = lpfc_reset_stats,
7055 
7056         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7057         .show_rport_maxframe_size = 1,
7058         .show_rport_supported_classes = 1,
7059 
7060         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7061         .show_rport_dev_loss_tmo = 1,
7062 
7063         .get_starget_port_id  = lpfc_get_starget_port_id,
7064         .show_starget_port_id = 1,
7065 
7066         .get_starget_node_name = lpfc_get_starget_node_name,
7067         .show_starget_node_name = 1,
7068 
7069         .get_starget_port_name = lpfc_get_starget_port_name,
7070         .show_starget_port_name = 1,
7071 
7072         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7073         .terminate_rport_io = lpfc_terminate_rport_io,
7074 
7075         .vport_disable = lpfc_vport_disable,
7076 
7077         .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7078 };
7079 
7080 /**
7081  * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7082  * Mode
7083  * @phba: lpfc_hba pointer.
7084  **/
7085 static void
7086 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7087 {
7088         /* If it's a SkyHawk FCoE adapter */
7089         if (phba->pcidev->device == PCI_DEVICE_ID_SKYHAWK)
7090                 phba->hba_flag |= HBA_FCOE_MODE;
7091         else
7092                 phba->hba_flag &= ~HBA_FCOE_MODE;
7093 }
7094 
7095 /**
7096  * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7097  * @phba: lpfc_hba pointer.
7098  **/
7099 void
7100 lpfc_get_cfgparam(struct lpfc_hba *phba)
7101 {
7102         lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7103         lpfc_ns_query_init(phba, lpfc_ns_query);
7104         lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7105         lpfc_cr_delay_init(phba, lpfc_cr_delay);
7106         lpfc_cr_count_init(phba, lpfc_cr_count);
7107         lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7108         lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7109         lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7110         lpfc_ack0_init(phba, lpfc_ack0);
7111         lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7112         lpfc_topology_init(phba, lpfc_topology);
7113         lpfc_link_speed_init(phba, lpfc_link_speed);
7114         lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7115         lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7116         lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7117         lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7118         lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7119         lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7120         lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7121         lpfc_use_msi_init(phba, lpfc_use_msi);
7122         lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7123         lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7124         lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7125         lpfc_force_rscn_init(phba, lpfc_force_rscn);
7126         lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7127         lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7128         lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7129         lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7130         lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7131 
7132         lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7133         if (phba->sli_rev != LPFC_SLI_REV4)
7134                 phba->cfg_EnableXLane = 0;
7135         lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7136 
7137         memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7138         memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7139         phba->cfg_oas_lun_state = 0;
7140         phba->cfg_oas_lun_status = 0;
7141         phba->cfg_oas_flags = 0;
7142         phba->cfg_oas_priority = 0;
7143         lpfc_enable_bg_init(phba, lpfc_enable_bg);
7144         lpfc_prot_mask_init(phba, lpfc_prot_mask);
7145         lpfc_prot_guard_init(phba, lpfc_prot_guard);
7146         if (phba->sli_rev == LPFC_SLI_REV4)
7147                 phba->cfg_poll = 0;
7148         else
7149                 phba->cfg_poll = lpfc_poll;
7150 
7151         /* Get the function mode */
7152         lpfc_get_hba_function_mode(phba);
7153 
7154         /* BlockGuard allowed for FC only. */
7155         if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7156                 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7157                                 "0581 BlockGuard feature not supported\n");
7158                 /* If set, clear the BlockGuard support param */
7159                 phba->cfg_enable_bg = 0;
7160         } else if (phba->cfg_enable_bg) {
7161                 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7162         }
7163 
7164         lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7165 
7166         lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7167         lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7168         lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7169 
7170         /* Initialize first burst. Target vs Initiator are different. */
7171         lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7172         lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7173         lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7174         lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7175         lpfc_irq_chann_init(phba, lpfc_irq_chann);
7176         lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7177         lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7178 
7179         if (phba->sli_rev != LPFC_SLI_REV4) {
7180                 /* NVME only supported on SLI4 */
7181                 phba->nvmet_support = 0;
7182                 phba->cfg_nvmet_mrq = 0;
7183                 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7184                 phba->cfg_enable_bbcr = 0;
7185                 phba->cfg_xri_rebalancing = 0;
7186         } else {
7187                 /* We MUST have FCP support */
7188                 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7189                         phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7190         }
7191 
7192         phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7193 
7194         phba->cfg_enable_pbde = 0;
7195 
7196         /* A value of 0 means use the number of CPUs found in the system */
7197         if (phba->cfg_hdw_queue == 0)
7198                 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7199         if (phba->cfg_irq_chann == 0)
7200                 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7201         if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7202                 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7203 
7204         phba->cfg_soft_wwnn = 0L;
7205         phba->cfg_soft_wwpn = 0L;
7206         lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7207         lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7208         lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7209         lpfc_aer_support_init(phba, lpfc_aer_support);
7210         lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7211         lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7212         lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7213         lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
7214         lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7215         lpfc_sli_mode_init(phba, lpfc_sli_mode);
7216         phba->cfg_enable_dss = 1;
7217         lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7218         lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7219         lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7220         lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7221 
7222         return;
7223 }
7224 
7225 /**
7226  * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7227  * dependencies between protocols and roles.
7228  * @phba: lpfc_hba pointer.
7229  **/
7230 void
7231 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7232 {
7233         if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
7234                 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7235         if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu)
7236                 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7237         if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7238                 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7239 
7240         if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7241             phba->nvmet_support) {
7242                 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7243 
7244                 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7245                                 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7246                                 "NVME Target PRLI ACC enable_fb ",
7247                                 phba->cfg_nvme_enable_fb,
7248                                 phba->cfg_nvmet_fb_size,
7249                                 LPFC_NVMET_FB_SZ_MAX);
7250 
7251                 if (phba->cfg_nvme_enable_fb == 0)
7252                         phba->cfg_nvmet_fb_size = 0;
7253                 else {
7254                         if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7255                                 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7256                 }
7257 
7258                 if (!phba->cfg_nvmet_mrq)
7259                         phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
7260 
7261                 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7262                 if (phba->cfg_nvmet_mrq > phba->cfg_irq_chann) {
7263                         phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
7264                         lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7265                                         "6018 Adjust lpfc_nvmet_mrq to %d\n",
7266                                         phba->cfg_nvmet_mrq);
7267                 }
7268                 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7269                         phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7270 
7271         } else {
7272                 /* Not NVME Target mode.  Turn off Target parameters. */
7273                 phba->nvmet_support = 0;
7274                 phba->cfg_nvmet_mrq = 0;
7275                 phba->cfg_nvmet_fb_size = 0;
7276         }
7277 }
7278 
7279 /**
7280  * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7281  * @vport: lpfc_vport pointer.
7282  **/
7283 void
7284 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7285 {
7286         lpfc_log_verbose_init(vport, lpfc_log_verbose);
7287         lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7288         lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7289         lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7290         lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7291         lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7292         lpfc_restrict_login_init(vport, lpfc_restrict_login);
7293         lpfc_fcp_class_init(vport, lpfc_fcp_class);
7294         lpfc_use_adisc_init(vport, lpfc_use_adisc);
7295         lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7296         lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7297         lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7298         lpfc_max_luns_init(vport, lpfc_max_luns);
7299         lpfc_scan_down_init(vport, lpfc_scan_down);
7300         lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
7301         return;
7302 }

/* [<][>][^][v][top][bottom][index][help] */