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