1 /*******************************************************************
 
   2  * This file is part of the Emulex Linux Device Driver for         *
 
   3  * Fibre Channel Host Bus Adapters.                                *
 
   4  * Copyright (C) 2004-2008 Emulex.  All rights reserved.           *
 
   5  * EMULEX and SLI are trademarks of Emulex.                        *
 
   7  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
 
   9  * This program is free software; you can redistribute it and/or   *
 
  10  * modify it under the terms of version 2 of the GNU General       *
 
  11  * Public License as published by the Free Software Foundation.    *
 
  12  * This program is distributed in the hope that it will be useful. *
 
  13  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
 
  14  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
 
  15  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
 
  16  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
 
  17  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
 
  18  * more details, a copy of which can be found in the file COPYING  *
 
  19  * included with this package.                                     *
 
  20  *******************************************************************/
 
  22 #include <linux/ctype.h>
 
  23 #include <linux/delay.h>
 
  24 #include <linux/pci.h>
 
  25 #include <linux/interrupt.h>
 
  27 #include <scsi/scsi.h>
 
  28 #include <scsi/scsi_device.h>
 
  29 #include <scsi/scsi_host.h>
 
  30 #include <scsi/scsi_tcq.h>
 
  31 #include <scsi/scsi_transport_fc.h>
 
  36 #include "lpfc_disc.h"
 
  37 #include "lpfc_scsi.h"
 
  39 #include "lpfc_logmsg.h"
 
  40 #include "lpfc_version.h"
 
  41 #include "lpfc_compat.h"
 
  42 #include "lpfc_crtn.h"
 
  43 #include "lpfc_vport.h"
 
  45 #define LPFC_DEF_DEVLOSS_TMO 30
 
  46 #define LPFC_MIN_DEVLOSS_TMO 1
 
  47 #define LPFC_MAX_DEVLOSS_TMO 255
 
  49 #define LPFC_MAX_LINK_SPEED 8
 
  50 #define LPFC_LINK_SPEED_BITMAP 0x00000117
 
  51 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
 
  54  * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
 
  55  * @incr: integer to convert.
 
  56  * @hdw: ascii string holding converted integer plus a string terminator.
 
  59  * JEDEC Joint Electron Device Engineering Council.
 
  60  * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
 
  61  * character string. The string is then terminated with a NULL in byte 9.
 
  62  * Hex 0-9 becomes ascii '0' to '9'.
 
  63  * Hex a-f becomes ascii '=' to 'B' capital B.
 
  66  * Coded for 32 bit integers only.
 
  69 lpfc_jedec_to_ascii(int incr, char hdw[])
 
  72         for (i = 0; i < 8; i++) {
 
  75                         hdw[7 - i] = 0x30 +  j;
 
  77                         hdw[7 - i] = 0x61 + j - 10;
 
  85  * lpfc_drvr_version_show: Return the Emulex driver string with version number.
 
  86  * @dev: class unused variable.
 
  87  * @attr: device attribute, not used.
 
  88  * @buf: on return contains the module description text.
 
  90  * Returns: size of formatted string.
 
  93 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
 
  96         return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
 
 100  * lpfc_info_show: Return some pci info about the host in ascii.
 
 101  * @dev: class converted to a Scsi_host structure.
 
 102  * @attr: device attribute, not used.
 
 103  * @buf: on return contains the formatted text from lpfc_info().
 
 105  * Returns: size of formatted string.
 
 108 lpfc_info_show(struct device *dev, struct device_attribute *attr,
 
 111         struct Scsi_Host *host = class_to_shost(dev);
 
 113         return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
 
 117  * lpfc_serialnum_show: Return the hba serial number in ascii.
 
 118  * @dev: class converted to a Scsi_host structure.
 
 119  * @attr: device attribute, not used.
 
 120  * @buf: on return contains the formatted text serial number.
 
 122  * Returns: size of formatted string.
 
 125 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
 
 128         struct Scsi_Host  *shost = class_to_shost(dev);
 
 129         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 130         struct lpfc_hba   *phba = vport->phba;
 
 132         return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
 
 136  * lpfc_temp_sensor_show: Return the temperature sensor level.
 
 137  * @dev: class converted to a Scsi_host structure.
 
 138  * @attr: device attribute, not used.
 
 139  * @buf: on return contains the formatted support level.
 
 142  * Returns a number indicating the temperature sensor level currently
 
 143  * supported, zero or one in ascii.
 
 145  * Returns: size of formatted string.
 
 148 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
 
 151         struct Scsi_Host *shost = class_to_shost(dev);
 
 152         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 153         struct lpfc_hba   *phba = vport->phba;
 
 154         return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
 
 158  * lpfc_modeldesc_show: Return the model description of the hba.
 
 159  * @dev: class converted to a Scsi_host structure.
 
 160  * @attr: device attribute, not used.
 
 161  * @buf: on return contains the scsi vpd model description.
 
 163  * Returns: size of formatted string.
 
 166 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
 
 169         struct Scsi_Host  *shost = class_to_shost(dev);
 
 170         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 171         struct lpfc_hba   *phba = vport->phba;
 
 173         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
 
 177  * lpfc_modelname_show: Return the model name of the hba.
 
 178  * @dev: class converted to a Scsi_host structure.
 
 179  * @attr: device attribute, not used.
 
 180  * @buf: on return contains the scsi vpd model name.
 
 182  * Returns: size of formatted string.
 
 185 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
 
 188         struct Scsi_Host  *shost = class_to_shost(dev);
 
 189         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 190         struct lpfc_hba   *phba = vport->phba;
 
 192         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
 
 196  * lpfc_programtype_show: Return the program type of the hba.
 
 197  * @dev: class converted to a Scsi_host structure.
 
 198  * @attr: device attribute, not used.
 
 199  * @buf: on return contains the scsi vpd program type.
 
 201  * Returns: size of formatted string.
 
 204 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
 
 207         struct Scsi_Host  *shost = class_to_shost(dev);
 
 208         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 209         struct lpfc_hba   *phba = vport->phba;
 
 211         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
 
 215  * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag.
 
 216  * @dev: class converted to a Scsi_host structure.
 
 217  * @attr: device attribute, not used.
 
 218  * @buf: on return contains the Menlo Maintenance sli flag.
 
 220  * Returns: size of formatted string.
 
 223 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
 
 225         struct Scsi_Host  *shost = class_to_shost(dev);
 
 226         struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
 
 227         struct lpfc_hba   *phba = vport->phba;
 
 229         return snprintf(buf, PAGE_SIZE, "%d\n",
 
 230                 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
 
 234  * lpfc_vportnum_show: Return the port number in ascii of the hba.
 
 235  * @dev: class converted to a Scsi_host structure.
 
 236  * @attr: device attribute, not used.
 
 237  * @buf: on return contains scsi vpd program type.
 
 239  * Returns: size of formatted string.
 
 242 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
 
 245         struct Scsi_Host  *shost = class_to_shost(dev);
 
 246         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 247         struct lpfc_hba   *phba = vport->phba;
 
 249         return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
 
 253  * lpfc_fwrev_show: Return the firmware rev running in the hba.
 
 254  * @dev: class converted to a Scsi_host structure.
 
 255  * @attr: device attribute, not used.
 
 256  * @buf: on return contains the scsi vpd program type.
 
 258  * Returns: size of formatted string.
 
 261 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
 
 264         struct Scsi_Host  *shost = class_to_shost(dev);
 
 265         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 266         struct lpfc_hba   *phba = vport->phba;
 
 269         lpfc_decode_firmware_rev(phba, fwrev, 1);
 
 270         return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
 
 274  * lpfc_hdw_show: Return the jedec information about the hba.
 
 275  * @dev: class converted to a Scsi_host structure.
 
 276  * @attr: device attribute, not used.
 
 277  * @buf: on return contains the scsi vpd program type.
 
 279  * Returns: size of formatted string.
 
 282 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
 
 285         struct Scsi_Host  *shost = class_to_shost(dev);
 
 286         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 287         struct lpfc_hba   *phba = vport->phba;
 
 288         lpfc_vpd_t *vp = &phba->vpd;
 
 290         lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
 
 291         return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
 
 295  * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
 
 296  * @dev: class converted to a Scsi_host structure.
 
 297  * @attr: device attribute, not used.
 
 298  * @buf: on return contains the ROM and FCode ascii strings.
 
 300  * Returns: size of formatted string.
 
 303 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
 
 306         struct Scsi_Host  *shost = class_to_shost(dev);
 
 307         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 308         struct lpfc_hba   *phba = vport->phba;
 
 310         return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
 
 314  * lpfc_state_show: Return the link state of the port.
 
 315  * @dev: class converted to a Scsi_host structure.
 
 316  * @attr: device attribute, not used.
 
 317  * @buf: on return contains text describing the state of the link.
 
 320  * The switch statement has no default so zero will be returned.
 
 322  * Returns: size of formatted string.
 
 325 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
 
 328         struct Scsi_Host  *shost = class_to_shost(dev);
 
 329         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 330         struct lpfc_hba   *phba = vport->phba;
 
 333         switch (phba->link_state) {
 
 334         case LPFC_LINK_UNKNOWN:
 
 335         case LPFC_WARM_START:
 
 336         case LPFC_INIT_START:
 
 337         case LPFC_INIT_MBX_CMDS:
 
 340                 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
 
 345                 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
 
 347                 switch (vport->port_state) {
 
 348                 case LPFC_LOCAL_CFG_LINK:
 
 349                         len += snprintf(buf + len, PAGE_SIZE-len,
 
 350                                         "Configuring Link\n");
 
 354                 case LPFC_FABRIC_CFG_LINK:
 
 357                 case LPFC_BUILD_DISC_LIST:
 
 359                         len += snprintf(buf + len, PAGE_SIZE - len,
 
 362                 case LPFC_VPORT_READY:
 
 363                         len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
 
 366                 case LPFC_VPORT_FAILED:
 
 367                         len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
 
 370                 case LPFC_VPORT_UNKNOWN:
 
 371                         len += snprintf(buf + len, PAGE_SIZE - len,
 
 375                 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
 
 376                         len += snprintf(buf + len, PAGE_SIZE-len,
 
 377                                         "   Menlo Maint Mode\n");
 
 378                 else if (phba->fc_topology == TOPOLOGY_LOOP) {
 
 379                         if (vport->fc_flag & FC_PUBLIC_LOOP)
 
 380                                 len += snprintf(buf + len, PAGE_SIZE-len,
 
 383                                 len += snprintf(buf + len, PAGE_SIZE-len,
 
 386                         if (vport->fc_flag & FC_FABRIC)
 
 387                                 len += snprintf(buf + len, PAGE_SIZE-len,
 
 390                                 len += snprintf(buf + len, PAGE_SIZE-len,
 
 399  * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
 
 400  * @dev: class device that is converted into a Scsi_host.
 
 401  * @attr: device attribute, not used.
 
 402  * @buf: on return contains the sum of fc mapped and unmapped.
 
 405  * Returns the ascii text number of the sum of the fc mapped and unmapped
 
 408  * Returns: size of formatted string.
 
 411 lpfc_num_discovered_ports_show(struct device *dev,
 
 412                                struct device_attribute *attr, char *buf)
 
 414         struct Scsi_Host  *shost = class_to_shost(dev);
 
 415         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 417         return snprintf(buf, PAGE_SIZE, "%d\n",
 
 418                         vport->fc_map_cnt + vport->fc_unmap_cnt);
 
 422  * lpfc_issue_lip: Misnomer, name carried over from long ago.
 
 423  * @shost: Scsi_Host pointer.
 
 426  * Bring the link down gracefully then re-init the link. The firmware will
 
 427  * re-init the fiber channel interface as required. Does not issue a LIP.
 
 430  * -EPERM port offline or management commands are being blocked
 
 431  * -ENOMEM cannot allocate memory for the mailbox command
 
 432  * -EIO error sending the mailbox command
 
 436 lpfc_issue_lip(struct Scsi_Host *shost)
 
 438         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 439         struct lpfc_hba   *phba = vport->phba;
 
 440         LPFC_MBOXQ_t *pmboxq;
 
 441         int mbxstatus = MBXERR_ERROR;
 
 443         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
 444             (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
 
 447         pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
 
 452         memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
 
 453         pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
 
 454         pmboxq->mb.mbxOwner = OWN_HOST;
 
 456         mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
 
 458         if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
 
 459                 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
 
 460                 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
 
 461                                phba->cfg_link_speed);
 
 462                 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
 
 466         lpfc_set_loopback_flag(phba);
 
 467         if (mbxstatus != MBX_TIMEOUT)
 
 468                 mempool_free(pmboxq, phba->mbox_mem_pool);
 
 470         if (mbxstatus == MBXERR_ERROR)
 
 477  * lpfc_do_offline: Issues a mailbox command to bring the link down.
 
 478  * @phba: lpfc_hba pointer.
 
 479  * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
 
 482  * Assumes any error from lpfc_do_offline() will be negative.
 
 483  * Can wait up to 5 seconds for the port ring buffers count
 
 484  * to reach zero, prints a warning if it is not zero and continues.
 
 485  * lpfc_workq_post_event() returns a non-zero return coce if call fails.
 
 488  * -EIO error posting the event
 
 492 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
 
 494         struct completion online_compl;
 
 495         struct lpfc_sli_ring *pring;
 
 496         struct lpfc_sli *psli;
 
 501         init_completion(&online_compl);
 
 502         lpfc_workq_post_event(phba, &status, &online_compl,
 
 503                               LPFC_EVT_OFFLINE_PREP);
 
 504         wait_for_completion(&online_compl);
 
 511         /* Wait a little for things to settle down, but not
 
 512          * long enough for dev loss timeout to expire.
 
 514         for (i = 0; i < psli->num_rings; i++) {
 
 515                 pring = &psli->ring[i];
 
 516                 while (pring->txcmplq_cnt) {
 
 518                         if (cnt++ > 500) {  /* 5 secs */
 
 519                                 lpfc_printf_log(phba,
 
 520                                         KERN_WARNING, LOG_INIT,
 
 521                                         "0466 Outstanding IO when "
 
 522                                         "bringing Adapter offline\n");
 
 528         init_completion(&online_compl);
 
 529         lpfc_workq_post_event(phba, &status, &online_compl, type);
 
 530         wait_for_completion(&online_compl);
 
 539  * lpfc_selective_reset: Offline then onlines the port.
 
 540  * @phba: lpfc_hba pointer.
 
 543  * If the port is configured to allow a reset then the hba is brought
 
 544  * offline then online.
 
 547  * Assumes any error from lpfc_do_offline() will be negative.
 
 550  * lpfc_do_offline() return code if not zero
 
 551  * -EIO reset not configured or error posting the event
 
 555 lpfc_selective_reset(struct lpfc_hba *phba)
 
 557         struct completion online_compl;
 
 560         if (!phba->cfg_enable_hba_reset)
 
 563         status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
 
 568         init_completion(&online_compl);
 
 569         lpfc_workq_post_event(phba, &status, &online_compl,
 
 571         wait_for_completion(&online_compl);
 
 580  * lpfc_issue_reset: Selectively resets an adapter.
 
 581  * @dev: class device that is converted into a Scsi_host.
 
 582  * @attr: device attribute, not used.
 
 583  * @buf: containing the string "selective".
 
 584  * @count: unused variable.
 
 587  * If the buf contains the string "selective" then lpfc_selective_reset()
 
 588  * is called to perform the reset.
 
 591  * Assumes any error from lpfc_selective_reset() will be negative.
 
 592  * If lpfc_selective_reset() returns zero then the length of the buffer
 
 593  * is returned which indicates succcess
 
 596  * -EINVAL if the buffer does not contain the string "selective"
 
 597  * length of buf if lpfc-selective_reset() if the call succeeds
 
 598  * return value of lpfc_selective_reset() if the call fails
 
 601 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
 
 602                  const char *buf, size_t count)
 
 604         struct Scsi_Host  *shost = class_to_shost(dev);
 
 605         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 606         struct lpfc_hba   *phba = vport->phba;
 
 608         int status = -EINVAL;
 
 610         if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
 
 611                 status = lpfc_selective_reset(phba);
 
 620  * lpfc_nport_evt_cnt_show: Return the number of nport events.
 
 621  * @dev: class device that is converted into a Scsi_host.
 
 622  * @attr: device attribute, not used.
 
 623  * @buf: on return contains the ascii number of nport events.
 
 625  * Returns: size of formatted string.
 
 628 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
 
 631         struct Scsi_Host  *shost = class_to_shost(dev);
 
 632         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 633         struct lpfc_hba   *phba = vport->phba;
 
 635         return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
 
 639  * lpfc_board_mode_show: Return the state of the board.
 
 640  * @dev: class device that is converted into a Scsi_host.
 
 641  * @attr: device attribute, not used.
 
 642  * @buf: on return contains the state of the adapter.
 
 644  * Returns: size of formatted string.
 
 647 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
 
 650         struct Scsi_Host  *shost = class_to_shost(dev);
 
 651         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 652         struct lpfc_hba   *phba = vport->phba;
 
 655         if (phba->link_state == LPFC_HBA_ERROR)
 
 657         else if (phba->link_state == LPFC_WARM_START)
 
 658                 state = "warm start";
 
 659         else if (phba->link_state == LPFC_INIT_START)
 
 664         return snprintf(buf, PAGE_SIZE, "%s\n", state);
 
 668  * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
 
 669  * @dev: class device that is converted into a Scsi_host.
 
 670  * @attr: device attribute, not used.
 
 671  * @buf: containing one of the strings "online", "offline", "warm" or "error".
 
 672  * @count: unused variable.
 
 675  * -EACCES if enable hba reset not enabled
 
 676  * -EINVAL if the buffer does not contain a valid string (see above)
 
 677  * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
 
 678  * buf length greater than zero indicates success
 
 681 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
 
 682                       const char *buf, size_t count)
 
 684         struct Scsi_Host  *shost = class_to_shost(dev);
 
 685         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 686         struct lpfc_hba   *phba = vport->phba;
 
 687         struct completion online_compl;
 
 690         if (!phba->cfg_enable_hba_reset)
 
 692         init_completion(&online_compl);
 
 694         if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
 
 695                 lpfc_workq_post_event(phba, &status, &online_compl,
 
 697                 wait_for_completion(&online_compl);
 
 698         } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
 
 699                 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
 
 700         else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
 
 701                 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
 
 702         else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
 
 703                 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
 
 714  * lpfc_get_hba_info: Return various bits of informaton about the adapter.
 
 715  * @phba: pointer to the adapter structure.
 
 716  * @mxri max xri count.
 
 717  * @axri available xri count.
 
 718  * @mrpi max rpi count.
 
 719  * @arpi available rpi count.
 
 720  * @mvpi max vpi count.
 
 721  * @avpi available vpi count.
 
 724  * If an integer pointer for an count is not null then the value for the
 
 732 lpfc_get_hba_info(struct lpfc_hba *phba,
 
 733                   uint32_t *mxri, uint32_t *axri,
 
 734                   uint32_t *mrpi, uint32_t *arpi,
 
 735                   uint32_t *mvpi, uint32_t *avpi)
 
 737         struct lpfc_sli   *psli = &phba->sli;
 
 738         LPFC_MBOXQ_t *pmboxq;
 
 743          * prevent udev from issuing mailbox commands until the port is
 
 746         if (phba->link_state < LPFC_LINK_DOWN ||
 
 747             !phba->mbox_mem_pool ||
 
 748             (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
 
 751         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
 
 754         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
 757         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
 
 760         pmb->mbxCommand = MBX_READ_CONFIG;
 
 761         pmb->mbxOwner = OWN_HOST;
 
 762         pmboxq->context1 = NULL;
 
 764         if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
 
 765                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
 
 766                 rc = MBX_NOT_FINISHED;
 
 768                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
 
 770         if (rc != MBX_SUCCESS) {
 
 771                 if (rc != MBX_TIMEOUT)
 
 772                         mempool_free(pmboxq, phba->mbox_mem_pool);
 
 777                 *mrpi = pmb->un.varRdConfig.max_rpi;
 
 779                 *arpi = pmb->un.varRdConfig.avail_rpi;
 
 781                 *mxri = pmb->un.varRdConfig.max_xri;
 
 783                 *axri = pmb->un.varRdConfig.avail_xri;
 
 785                 *mvpi = pmb->un.varRdConfig.max_vpi;
 
 787                 *avpi = pmb->un.varRdConfig.avail_vpi;
 
 789         mempool_free(pmboxq, phba->mbox_mem_pool);
 
 794  * lpfc_max_rpi_show: Return maximum rpi.
 
 795  * @dev: class device that is converted into a Scsi_host.
 
 796  * @attr: device attribute, not used.
 
 797  * @buf: on return contains the maximum rpi count in decimal or "Unknown".
 
 800  * Calls lpfc_get_hba_info() asking for just the mrpi count.
 
 801  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 802  * to "Unknown" and the buffer length is returned, therefore the caller
 
 803  * must check for "Unknown" in the buffer to detect a failure.
 
 805  * Returns: size of formatted string.
 
 808 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
 
 811         struct Scsi_Host  *shost = class_to_shost(dev);
 
 812         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 813         struct lpfc_hba   *phba = vport->phba;
 
 816         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
 
 817                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
 
 818         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 822  * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
 
 823  * @dev: class device that is converted into a Scsi_host.
 
 824  * @attr: device attribute, not used.
 
 825  * @buf: containing the used rpi count in decimal or "Unknown".
 
 828  * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
 
 829  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 830  * to "Unknown" and the buffer length is returned, therefore the caller
 
 831  * must check for "Unknown" in the buffer to detect a failure.
 
 833  * Returns: size of formatted string.
 
 836 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
 
 839         struct Scsi_Host  *shost = class_to_shost(dev);
 
 840         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 841         struct lpfc_hba   *phba = vport->phba;
 
 844         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
 
 845                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
 
 846         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 850  * lpfc_max_xri_show: Return maximum xri.
 
 851  * @dev: class device that is converted into a Scsi_host.
 
 852  * @attr: device attribute, not used.
 
 853  * @buf: on return contains the maximum xri count in decimal or "Unknown".
 
 856  * Calls lpfc_get_hba_info() asking for just the mrpi count.
 
 857  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 858  * to "Unknown" and the buffer length is returned, therefore the caller
 
 859  * must check for "Unknown" in the buffer to detect a failure.
 
 861  * Returns: size of formatted string.
 
 864 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
 
 867         struct Scsi_Host  *shost = class_to_shost(dev);
 
 868         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 869         struct lpfc_hba   *phba = vport->phba;
 
 872         if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
 
 873                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
 
 874         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 878  * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
 
 879  * @dev: class device that is converted into a Scsi_host.
 
 880  * @attr: device attribute, not used.
 
 881  * @buf: on return contains the used xri count in decimal or "Unknown".
 
 884  * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
 
 885  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 886  * to "Unknown" and the buffer length is returned, therefore the caller
 
 887  * must check for "Unknown" in the buffer to detect a failure.
 
 889  * Returns: size of formatted string.
 
 892 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
 
 895         struct Scsi_Host  *shost = class_to_shost(dev);
 
 896         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 897         struct lpfc_hba   *phba = vport->phba;
 
 900         if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
 
 901                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
 
 902         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 906  * lpfc_max_vpi_show: Return maximum vpi.
 
 907  * @dev: class device that is converted into a Scsi_host.
 
 908  * @attr: device attribute, not used.
 
 909  * @buf: on return contains the maximum vpi count in decimal or "Unknown".
 
 912  * Calls lpfc_get_hba_info() asking for just the mvpi count.
 
 913  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 914  * to "Unknown" and the buffer length is returned, therefore the caller
 
 915  * must check for "Unknown" in the buffer to detect a failure.
 
 917  * Returns: size of formatted string.
 
 920 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
 
 923         struct Scsi_Host  *shost = class_to_shost(dev);
 
 924         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 925         struct lpfc_hba   *phba = vport->phba;
 
 928         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
 
 929                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
 
 930         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 934  * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
 
 935  * @dev: class device that is converted into a Scsi_host.
 
 936  * @attr: device attribute, not used.
 
 937  * @buf: on return contains the used vpi count in decimal or "Unknown".
 
 940  * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
 
 941  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
 
 942  * to "Unknown" and the buffer length is returned, therefore the caller
 
 943  * must check for "Unknown" in the buffer to detect a failure.
 
 945  * Returns: size of formatted string.
 
 948 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
 
 951         struct Scsi_Host  *shost = class_to_shost(dev);
 
 952         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 953         struct lpfc_hba   *phba = vport->phba;
 
 956         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
 
 957                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
 
 958         return snprintf(buf, PAGE_SIZE, "Unknown\n");
 
 962  * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
 
 963  * @dev: class device that is converted into a Scsi_host.
 
 964  * @attr: device attribute, not used.
 
 965  * @buf: text that must be interpreted to determine if npiv is supported.
 
 968  * Buffer will contain text indicating npiv is not suppoerted on the port,
 
 969  * the port is an NPIV physical port, or it is an npiv virtual port with
 
 970  * the id of the vport.
 
 972  * Returns: size of formatted string.
 
 975 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
 
 978         struct Scsi_Host  *shost = class_to_shost(dev);
 
 979         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
 980         struct lpfc_hba   *phba = vport->phba;
 
 982         if (!(phba->max_vpi))
 
 983                 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
 
 984         if (vport->port_type == LPFC_PHYSICAL_PORT)
 
 985                 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
 
 986         return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
 
 990  * lpfc_poll_show: Return text about poll support for the adapter.
 
 991  * @dev: class device that is converted into a Scsi_host.
 
 992  * @attr: device attribute, not used.
 
 993  * @buf: on return contains the cfg_poll in hex.
 
 996  * cfg_poll should be a lpfc_polling_flags type.
 
 998  * Returns: size of formatted string.
 
1001 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
 
1004         struct Scsi_Host  *shost = class_to_shost(dev);
 
1005         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1006         struct lpfc_hba   *phba = vport->phba;
 
1008         return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
 
1012  * lpfc_poll_store: Set the value of cfg_poll for the adapter.
 
1013  * @dev: class device that is converted into a Scsi_host.
 
1014  * @attr: device attribute, not used.
 
1015  * @buf: one or more lpfc_polling_flags values.
 
1019  * buf contents converted to integer and checked for a valid value.
 
1022  * -EINVAL if the buffer connot be converted or is out of range
 
1023  * length of the buf on success
 
1026 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
 
1027                 const char *buf, size_t count)
 
1029         struct Scsi_Host  *shost = class_to_shost(dev);
 
1030         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1031         struct lpfc_hba   *phba = vport->phba;
 
1036         if (!isdigit(buf[0]))
 
1039         if (sscanf(buf, "%i", &val) != 1)
 
1042         if ((val & 0x3) != val)
 
1045         spin_lock_irq(&phba->hbalock);
 
1047         old_val = phba->cfg_poll;
 
1049         if (val & ENABLE_FCP_RING_POLLING) {
 
1050                 if ((val & DISABLE_FCP_RING_INT) &&
 
1051                     !(old_val & DISABLE_FCP_RING_INT)) {
 
1052                         creg_val = readl(phba->HCregaddr);
 
1053                         creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
 
1054                         writel(creg_val, phba->HCregaddr);
 
1055                         readl(phba->HCregaddr); /* flush */
 
1057                         lpfc_poll_start_timer(phba);
 
1059         } else if (val != 0x0) {
 
1060                 spin_unlock_irq(&phba->hbalock);
 
1064         if (!(val & DISABLE_FCP_RING_INT) &&
 
1065             (old_val & DISABLE_FCP_RING_INT))
 
1067                 spin_unlock_irq(&phba->hbalock);
 
1068                 del_timer(&phba->fcp_poll_timer);
 
1069                 spin_lock_irq(&phba->hbalock);
 
1070                 creg_val = readl(phba->HCregaddr);
 
1071                 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
 
1072                 writel(creg_val, phba->HCregaddr);
 
1073                 readl(phba->HCregaddr); /* flush */
 
1076         phba->cfg_poll = val;
 
1078         spin_unlock_irq(&phba->hbalock);
 
1084  * lpfc_param_show: Return a cfg attribute value in decimal.
 
1087  * Macro that given an attr e.g. hba_queue_depth expands
 
1088  * into a function with the name lpfc_hba_queue_depth_show.
 
1090  * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
 
1091  * @dev: class device that is converted into a Scsi_host.
 
1092  * @attr: device attribute, not used.
 
1093  * @buf: on return contains the attribute value in decimal.
 
1095  * Returns: size of formatted string.
 
1097 #define lpfc_param_show(attr)   \
 
1099 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
 
1102         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1103         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1104         struct lpfc_hba   *phba = vport->phba;\
 
1106         val = phba->cfg_##attr;\
 
1107         return snprintf(buf, PAGE_SIZE, "%d\n",\
 
1112  * lpfc_param_hex_show: Return a cfg attribute value in hex.
 
1115  * Macro that given an attr e.g. hba_queue_depth expands
 
1116  * into a function with the name lpfc_hba_queue_depth_show
 
1118  * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
 
1119  * @dev: class device that is converted into a Scsi_host.
 
1120  * @attr: device attribute, not used.
 
1121  * @buf: on return contains the attribute value in hexidecimal.
 
1123  * Returns: size of formatted string.
 
1125 #define lpfc_param_hex_show(attr)       \
 
1127 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
 
1130         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1131         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1132         struct lpfc_hba   *phba = vport->phba;\
 
1134         val = phba->cfg_##attr;\
 
1135         return snprintf(buf, PAGE_SIZE, "%#x\n",\
 
1140  * lpfc_param_init: Intializes a cfg attribute.
 
1143  * Macro that given an attr e.g. hba_queue_depth expands
 
1144  * into a function with the name lpfc_hba_queue_depth_init. The macro also
 
1145  * takes a default argument, a minimum and maximum argument.
 
1147  * lpfc_##attr##_init: Initializes an attribute.
 
1148  * @phba: pointer the the adapter structure.
 
1149  * @val: integer attribute value.
 
1151  * Validates the min and max values then sets the adapter config field
 
1152  * accordingly, or uses the default if out of range and prints an error message.
 
1156  * -EINVAL if default used
 
1158 #define lpfc_param_init(attr, default, minval, maxval)  \
 
1160 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
 
1162         if (val >= minval && val <= maxval) {\
 
1163                 phba->cfg_##attr = val;\
 
1166         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
 
1167                         "0449 lpfc_"#attr" attribute cannot be set to %d, "\
 
1168                         "allowed range is ["#minval", "#maxval"]\n", val); \
 
1169         phba->cfg_##attr = default;\
 
1174  * lpfc_param_set: Set a cfg attribute value.
 
1177  * Macro that given an attr e.g. hba_queue_depth expands
 
1178  * into a function with the name lpfc_hba_queue_depth_set
 
1180  * lpfc_##attr##_set: Sets an attribute value.
 
1181  * @phba: pointer the the adapter structure.
 
1182  * @val: integer attribute value.
 
1185  * Validates the min and max values then sets the
 
1186  * adapter config field if in the valid range. prints error message
 
1187  * and does not set the parameter if invalid.
 
1191  * -EINVAL if val is invalid
 
1193 #define lpfc_param_set(attr, default, minval, maxval)   \
 
1195 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
 
1197         if (val >= minval && val <= maxval) {\
 
1198                 phba->cfg_##attr = val;\
 
1201         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
 
1202                         "0450 lpfc_"#attr" attribute cannot be set to %d, "\
 
1203                         "allowed range is ["#minval", "#maxval"]\n", val); \
 
1208  * lpfc_param_store: Set a vport attribute value.
 
1211  * Macro that given an attr e.g. hba_queue_depth expands
 
1212  * into a function with the name lpfc_hba_queue_depth_store.
 
1214  * lpfc_##attr##_store: Set an sttribute value.
 
1215  * @dev: class device that is converted into a Scsi_host.
 
1216  * @attr: device attribute, not used.
 
1217  * @buf: contains the attribute value in ascii.
 
1221  * Convert the ascii text number to an integer, then
 
1222  * use the lpfc_##attr##_set function to set the value.
 
1225  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
 
1226  * length of buffer upon success.
 
1228 #define lpfc_param_store(attr)  \
 
1230 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
 
1231                     const char *buf, size_t count) \
 
1233         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1234         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1235         struct lpfc_hba   *phba = vport->phba;\
 
1237         if (!isdigit(buf[0]))\
 
1239         if (sscanf(buf, "%i", &val) != 1)\
 
1241         if (lpfc_##attr##_set(phba, val) == 0) \
 
1242                 return strlen(buf);\
 
1248  * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
 
1251  * Macro that given an attr e.g. hba_queue_depth expands
 
1252  * into a function with the name lpfc_hba_queue_depth_show
 
1254  * lpfc_##attr##_show: prints the attribute value in decimal.
 
1255  * @dev: class device that is converted into a Scsi_host.
 
1256  * @attr: device attribute, not used.
 
1257  * @buf: on return contains the attribute value in decimal.
 
1259  * Returns: length of formatted string.
 
1261 #define lpfc_vport_param_show(attr)     \
 
1263 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
 
1266         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1267         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1269         val = vport->cfg_##attr;\
 
1270         return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
 
1274  * lpfc_vport_param_hex_show: Return hex formatted attribute value.
 
1277  * Macro that given an attr e.g.
 
1278  * hba_queue_depth expands into a function with the name
 
1279  * lpfc_hba_queue_depth_show
 
1281  * lpfc_##attr##_show: prints the attribute value in hexidecimal.
 
1282  * @dev: class device that is converted into a Scsi_host.
 
1283  * @attr: device attribute, not used.
 
1284  * @buf: on return contains the attribute value in hexidecimal.
 
1286  * Returns: length of formatted string.
 
1288 #define lpfc_vport_param_hex_show(attr) \
 
1290 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
 
1293         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1294         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1296         val = vport->cfg_##attr;\
 
1297         return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
 
1301  * lpfc_vport_param_init: Initialize a vport cfg attribute.
 
1304  * Macro that given an attr e.g. hba_queue_depth expands
 
1305  * into a function with the name lpfc_hba_queue_depth_init. The macro also
 
1306  * takes a default argument, a minimum and maximum argument.
 
1308  * lpfc_##attr##_init: validates the min and max values then sets the
 
1309  * adapter config field accordingly, or uses the default if out of range
 
1310  * and prints an error message.
 
1311  * @phba: pointer the the adapter structure.
 
1312  * @val: integer attribute value.
 
1316  * -EINVAL if default used
 
1318 #define lpfc_vport_param_init(attr, default, minval, maxval)    \
 
1320 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
 
1322         if (val >= minval && val <= maxval) {\
 
1323                 vport->cfg_##attr = val;\
 
1326         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
 
1327                          "0423 lpfc_"#attr" attribute cannot be set to %d, "\
 
1328                          "allowed range is ["#minval", "#maxval"]\n", val); \
 
1329         vport->cfg_##attr = default;\
 
1334  * lpfc_vport_param_set: Set a vport cfg attribute.
 
1337  * Macro that given an attr e.g. hba_queue_depth expands
 
1338  * into a function with the name lpfc_hba_queue_depth_set
 
1340  * lpfc_##attr##_set: validates the min and max values then sets the
 
1341  * adapter config field if in the valid range. prints error message
 
1342  * and does not set the parameter if invalid.
 
1343  * @phba: pointer the the adapter structure.
 
1344  * @val:        integer attribute value.
 
1348  * -EINVAL if val is invalid
 
1350 #define lpfc_vport_param_set(attr, default, minval, maxval)     \
 
1352 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
 
1354         if (val >= minval && val <= maxval) {\
 
1355                 vport->cfg_##attr = val;\
 
1358         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
 
1359                          "0424 lpfc_"#attr" attribute cannot be set to %d, "\
 
1360                          "allowed range is ["#minval", "#maxval"]\n", val); \
 
1365  * lpfc_vport_param_store: Set a vport attribute.
 
1368  * Macro that given an attr e.g. hba_queue_depth
 
1369  * expands into a function with the name lpfc_hba_queue_depth_store
 
1371  * lpfc_##attr##_store: convert the ascii text number to an integer, then
 
1372  * use the lpfc_##attr##_set function to set the value.
 
1373  * @cdev: class device that is converted into a Scsi_host.
 
1374  * @buf:        contains the attribute value in decimal.
 
1378  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
 
1379  * length of buffer upon success.
 
1381 #define lpfc_vport_param_store(attr)    \
 
1383 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
 
1384                     const char *buf, size_t count) \
 
1386         struct Scsi_Host  *shost = class_to_shost(dev);\
 
1387         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
 
1389         if (!isdigit(buf[0]))\
 
1391         if (sscanf(buf, "%i", &val) != 1)\
 
1393         if (lpfc_##attr##_set(vport, val) == 0) \
 
1394                 return strlen(buf);\
 
1400 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
 
1401 static int lpfc_##name = defval;\
 
1402 module_param(lpfc_##name, int, 0);\
 
1403 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1404 lpfc_param_init(name, defval, minval, maxval)
 
1406 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
 
1407 static int lpfc_##name = defval;\
 
1408 module_param(lpfc_##name, int, 0);\
 
1409 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1410 lpfc_param_show(name)\
 
1411 lpfc_param_init(name, defval, minval, maxval)\
 
1412 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
 
1414 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
 
1415 static int lpfc_##name = defval;\
 
1416 module_param(lpfc_##name, int, 0);\
 
1417 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1418 lpfc_param_show(name)\
 
1419 lpfc_param_init(name, defval, minval, maxval)\
 
1420 lpfc_param_set(name, defval, minval, maxval)\
 
1421 lpfc_param_store(name)\
 
1422 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
 
1423                    lpfc_##name##_show, lpfc_##name##_store)
 
1425 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
 
1426 static int lpfc_##name = defval;\
 
1427 module_param(lpfc_##name, int, 0);\
 
1428 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1429 lpfc_param_hex_show(name)\
 
1430 lpfc_param_init(name, defval, minval, maxval)\
 
1431 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
 
1433 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
 
1434 static int lpfc_##name = defval;\
 
1435 module_param(lpfc_##name, int, 0);\
 
1436 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1437 lpfc_param_hex_show(name)\
 
1438 lpfc_param_init(name, defval, minval, maxval)\
 
1439 lpfc_param_set(name, defval, minval, maxval)\
 
1440 lpfc_param_store(name)\
 
1441 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
 
1442                    lpfc_##name##_show, lpfc_##name##_store)
 
1444 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
 
1445 static int lpfc_##name = defval;\
 
1446 module_param(lpfc_##name, int, 0);\
 
1447 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1448 lpfc_vport_param_init(name, defval, minval, maxval)
 
1450 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
 
1451 static int lpfc_##name = defval;\
 
1452 module_param(lpfc_##name, int, 0);\
 
1453 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1454 lpfc_vport_param_show(name)\
 
1455 lpfc_vport_param_init(name, defval, minval, maxval)\
 
1456 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
 
1458 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
 
1459 static int lpfc_##name = defval;\
 
1460 module_param(lpfc_##name, int, 0);\
 
1461 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1462 lpfc_vport_param_show(name)\
 
1463 lpfc_vport_param_init(name, defval, minval, maxval)\
 
1464 lpfc_vport_param_set(name, defval, minval, maxval)\
 
1465 lpfc_vport_param_store(name)\
 
1466 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
 
1467                    lpfc_##name##_show, lpfc_##name##_store)
 
1469 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
 
1470 static int lpfc_##name = defval;\
 
1471 module_param(lpfc_##name, int, 0);\
 
1472 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1473 lpfc_vport_param_hex_show(name)\
 
1474 lpfc_vport_param_init(name, defval, minval, maxval)\
 
1475 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
 
1477 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
 
1478 static int lpfc_##name = defval;\
 
1479 module_param(lpfc_##name, int, 0);\
 
1480 MODULE_PARM_DESC(lpfc_##name, desc);\
 
1481 lpfc_vport_param_hex_show(name)\
 
1482 lpfc_vport_param_init(name, defval, minval, maxval)\
 
1483 lpfc_vport_param_set(name, defval, minval, maxval)\
 
1484 lpfc_vport_param_store(name)\
 
1485 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
 
1486                    lpfc_##name##_show, lpfc_##name##_store)
 
1488 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
 
1489 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
 
1490 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
 
1491 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
 
1492 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
 
1493 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
 
1494 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
 
1495 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
 
1496 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
 
1497 static DEVICE_ATTR(option_rom_version, S_IRUGO,
 
1498                    lpfc_option_rom_version_show, NULL);
 
1499 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
 
1500                    lpfc_num_discovered_ports_show, NULL);
 
1501 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
 
1502 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
 
1503 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
 
1504 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
 
1505                    lpfc_board_mode_show, lpfc_board_mode_store);
 
1506 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
 
1507 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
 
1508 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
 
1509 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
 
1510 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
 
1511 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
 
1512 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
 
1513 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
 
1514 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
 
1517 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
 
1520  * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
 
1521  * @dev: class device that is converted into a Scsi_host.
 
1522  * @attr: device attribute, not used.
 
1523  * @buf: containing the string lpfc_soft_wwn_key.
 
1524  * @count: must be size of lpfc_soft_wwn_key.
 
1527  * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
 
1528  * length of buf indicates success
 
1531 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
 
1532                            const char *buf, size_t count)
 
1534         struct Scsi_Host  *shost = class_to_shost(dev);
 
1535         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1536         struct lpfc_hba   *phba = vport->phba;
 
1537         unsigned int cnt = count;
 
1540          * We're doing a simple sanity check for soft_wwpn setting.
 
1541          * We require that the user write a specific key to enable
 
1542          * the soft_wwpn attribute to be settable. Once the attribute
 
1543          * is written, the enable key resets. If further updates are
 
1544          * desired, the key must be written again to re-enable the
 
1547          * The "key" is not secret - it is a hardcoded string shown
 
1548          * here. The intent is to protect against the random user or
 
1549          * application that is just writing attributes.
 
1552         /* count may include a LF at end of string */
 
1553         if (buf[cnt-1] == '\n')
 
1556         if ((cnt != strlen(lpfc_soft_wwn_key)) ||
 
1557             (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
 
1560         phba->soft_wwn_enable = 1;
 
1563 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
 
1564                    lpfc_soft_wwn_enable_store);
 
1567  * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
 
1568  * @dev: class device that is converted into a Scsi_host.
 
1569  * @attr: device attribute, not used.
 
1570  * @buf: on return contains the wwpn in hexidecimal.
 
1572  * Returns: size of formatted string.
 
1575 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
 
1578         struct Scsi_Host  *shost = class_to_shost(dev);
 
1579         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1580         struct lpfc_hba   *phba = vport->phba;
 
1582         return snprintf(buf, PAGE_SIZE, "0x%llx\n",
 
1583                         (unsigned long long)phba->cfg_soft_wwpn);
 
1587  * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
 
1588  * @dev class device that is converted into a Scsi_host.
 
1589  * @attr: device attribute, not used.
 
1590  * @buf: contains the wwpn in hexidecimal.
 
1591  * @count: number of wwpn bytes in buf
 
1594  * -EACCES hba reset not enabled, adapter over temp
 
1595  * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
 
1596  * -EIO error taking adapter offline or online
 
1597  * value of count on success
 
1600 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
 
1601                      const char *buf, size_t count)
 
1603         struct Scsi_Host  *shost = class_to_shost(dev);
 
1604         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1605         struct lpfc_hba   *phba = vport->phba;
 
1606         struct completion online_compl;
 
1607         int stat1=0, stat2=0;
 
1608         unsigned int i, j, cnt=count;
 
1611         if (!phba->cfg_enable_hba_reset)
 
1613         spin_lock_irq(&phba->hbalock);
 
1614         if (phba->over_temp_state == HBA_OVER_TEMP) {
 
1615                 spin_unlock_irq(&phba->hbalock);
 
1618         spin_unlock_irq(&phba->hbalock);
 
1619         /* count may include a LF at end of string */
 
1620         if (buf[cnt-1] == '\n')
 
1623         if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
 
1624             ((cnt == 17) && (*buf++ != 'x')) ||
 
1625             ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
 
1628         phba->soft_wwn_enable = 0;
 
1630         memset(wwpn, 0, sizeof(wwpn));
 
1632         /* Validate and store the new name */
 
1633         for (i=0, j=0; i < 16; i++) {
 
1634                 if ((*buf >= 'a') && (*buf <= 'f'))
 
1635                         j = ((j << 4) | ((*buf++ -'a') + 10));
 
1636                 else if ((*buf >= 'A') && (*buf <= 'F'))
 
1637                         j = ((j << 4) | ((*buf++ -'A') + 10));
 
1638                 else if ((*buf >= '0') && (*buf <= '9'))
 
1639                         j = ((j << 4) | (*buf++ -'0'));
 
1643                         wwpn[i/2] = j & 0xff;
 
1647         phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
 
1648         fc_host_port_name(shost) = phba->cfg_soft_wwpn;
 
1649         if (phba->cfg_soft_wwnn)
 
1650                 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
 
1652         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
 
1653                    "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
 
1655         stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
 
1657                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 
1658                                 "0463 lpfc_soft_wwpn attribute set failed to "
 
1659                                 "reinit adapter - %d\n", stat1);
 
1660         init_completion(&online_compl);
 
1661         lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
 
1662         wait_for_completion(&online_compl);
 
1664                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 
1665                                 "0464 lpfc_soft_wwpn attribute set failed to "
 
1666                                 "reinit adapter - %d\n", stat2);
 
1667         return (stat1 || stat2) ? -EIO : count;
 
1669 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
 
1670                    lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
 
1673  * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
 
1674  * @dev: class device that is converted into a Scsi_host.
 
1675  * @attr: device attribute, not used.
 
1676  * @buf: on return contains the wwnn in hexidecimal.
 
1678  * Returns: size of formatted string.
 
1681 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
 
1684         struct Scsi_Host *shost = class_to_shost(dev);
 
1685         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
1686         return snprintf(buf, PAGE_SIZE, "0x%llx\n",
 
1687                         (unsigned long long)phba->cfg_soft_wwnn);
 
1691  * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
 
1692  * @cdev: class device that is converted into a Scsi_host.
 
1693  * @buf: contains the ww node name in hexidecimal.
 
1694  * @count: number of wwnn bytes in buf.
 
1697  * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
 
1698  * value of count on success
 
1701 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
 
1702                      const char *buf, size_t count)
 
1704         struct Scsi_Host *shost = class_to_shost(dev);
 
1705         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
1706         unsigned int i, j, cnt=count;
 
1709         /* count may include a LF at end of string */
 
1710         if (buf[cnt-1] == '\n')
 
1713         if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
 
1714             ((cnt == 17) && (*buf++ != 'x')) ||
 
1715             ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
 
1719          * Allow wwnn to be set many times, as long as the enable is set.
 
1720          * However, once the wwpn is set, everything locks.
 
1723         memset(wwnn, 0, sizeof(wwnn));
 
1725         /* Validate and store the new name */
 
1726         for (i=0, j=0; i < 16; i++) {
 
1727                 if ((*buf >= 'a') && (*buf <= 'f'))
 
1728                         j = ((j << 4) | ((*buf++ -'a') + 10));
 
1729                 else if ((*buf >= 'A') && (*buf <= 'F'))
 
1730                         j = ((j << 4) | ((*buf++ -'A') + 10));
 
1731                 else if ((*buf >= '0') && (*buf <= '9'))
 
1732                         j = ((j << 4) | (*buf++ -'0'));
 
1736                         wwnn[i/2] = j & 0xff;
 
1740         phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
 
1742         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
 
1743                    "lpfc%d: soft_wwnn set. Value will take effect upon "
 
1744                    "setting of the soft_wwpn\n", phba->brd_no);
 
1748 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
 
1749                    lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
 
1752 static int lpfc_poll = 0;
 
1753 module_param(lpfc_poll, int, 0);
 
1754 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
 
1756                  " 1 - poll with interrupts enabled"
 
1757                  " 3 - poll and disable FCP ring interrupts");
 
1759 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
 
1760                    lpfc_poll_show, lpfc_poll_store);
 
1762 int  lpfc_sli_mode = 0;
 
1763 module_param(lpfc_sli_mode, int, 0);
 
1764 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
 
1765                  " 0 - auto (SLI-3 if supported),"
 
1766                  " 2 - select SLI-2 even on SLI-3 capable HBAs,"
 
1767                  " 3 - select SLI-3");
 
1769 int lpfc_enable_npiv = 0;
 
1770 module_param(lpfc_enable_npiv, int, 0);
 
1771 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
 
1772 lpfc_param_show(enable_npiv);
 
1773 lpfc_param_init(enable_npiv, 0, 0, 1);
 
1774 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
 
1775                          lpfc_enable_npiv_show, NULL);
 
1778 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
 
1779 # until the timer expires. Value range is [0,255]. Default value is 30.
 
1781 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
 
1782 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
 
1783 module_param(lpfc_nodev_tmo, int, 0);
 
1784 MODULE_PARM_DESC(lpfc_nodev_tmo,
 
1785                  "Seconds driver will hold I/O waiting "
 
1786                  "for a device to come back");
 
1789  * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
 
1790  * @dev: class converted to a Scsi_host structure.
 
1791  * @attr: device attribute, not used.
 
1792  * @buf: on return contains the dev loss timeout in decimal.
 
1794  * Returns: size of formatted string.
 
1797 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
 
1800         struct Scsi_Host  *shost = class_to_shost(dev);
 
1801         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
1803         val = vport->cfg_devloss_tmo;
 
1804         return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
 
1808  * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
 
1809  * @vport: lpfc vport structure pointer.
 
1810  * @val: contains the nodev timeout value.
 
1813  * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
 
1814  * a kernel error message is printed and zero is returned.
 
1815  * Else if val is in range then nodev tmo and devloss tmo are set to val.
 
1816  * Otherwise nodev tmo is set to the default value.
 
1819  * zero if already set or if val is in range
 
1820  * -EINVAL val out of range
 
1823 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
 
1825         if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
 
1826                 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
 
1827                 if (val != LPFC_DEF_DEVLOSS_TMO)
 
1828                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
1829                                          "0407 Ignoring nodev_tmo module "
 
1830                                          "parameter because devloss_tmo is "
 
1835         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
 
1836                 vport->cfg_nodev_tmo = val;
 
1837                 vport->cfg_devloss_tmo = val;
 
1840         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
1841                          "0400 lpfc_nodev_tmo attribute cannot be set to"
 
1842                          " %d, allowed range is [%d, %d]\n",
 
1843                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
 
1844         vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
 
1849  * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
 
1850  * @vport: lpfc vport structure pointer.
 
1853  * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
 
1856 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
 
1858         struct Scsi_Host  *shost;
 
1859         struct lpfc_nodelist  *ndlp;
 
1861         shost = lpfc_shost_from_vport(vport);
 
1862         spin_lock_irq(shost->host_lock);
 
1863         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
 
1864                 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
 
1865                         ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
 
1866         spin_unlock_irq(shost->host_lock);
 
1870  * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
 
1871  * @vport: lpfc vport structure pointer.
 
1872  * @val: contains the tmo value.
 
1875  * If the devloss tmo is already set or the vport dev loss tmo has changed
 
1876  * then a kernel error message is printed and zero is returned.
 
1877  * Else if val is in range then nodev tmo and devloss tmo are set to val.
 
1878  * Otherwise nodev tmo is set to the default value.
 
1881  * zero if already set or if val is in range
 
1882  * -EINVAL val out of range
 
1885 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
 
1887         if (vport->dev_loss_tmo_changed ||
 
1888             (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
 
1889                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
1890                                  "0401 Ignoring change to nodev_tmo "
 
1891                                  "because devloss_tmo is set.\n");
 
1894         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
 
1895                 vport->cfg_nodev_tmo = val;
 
1896                 vport->cfg_devloss_tmo = val;
 
1897                 lpfc_update_rport_devloss_tmo(vport);
 
1900         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
1901                          "0403 lpfc_nodev_tmo attribute cannot be set to"
 
1902                          "%d, allowed range is [%d, %d]\n",
 
1903                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
 
1907 lpfc_vport_param_store(nodev_tmo)
 
1909 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
 
1910                    lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
 
1913 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
 
1914 # disappear until the timer expires. Value range is [0,255]. Default
 
1917 module_param(lpfc_devloss_tmo, int, 0);
 
1918 MODULE_PARM_DESC(lpfc_devloss_tmo,
 
1919                  "Seconds driver will hold I/O waiting "
 
1920                  "for a device to come back");
 
1921 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
 
1922                       LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
 
1923 lpfc_vport_param_show(devloss_tmo)
 
1926  * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
 
1927  * @vport: lpfc vport structure pointer.
 
1928  * @val: contains the tmo value.
 
1931  * If val is in a valid range then set the vport nodev tmo,
 
1932  * devloss tmo, also set the vport dev loss tmo changed flag.
 
1933  * Else a kernel error message is printed.
 
1936  * zero if val is in range
 
1937  * -EINVAL val out of range
 
1940 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
 
1942         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
 
1943                 vport->cfg_nodev_tmo = val;
 
1944                 vport->cfg_devloss_tmo = val;
 
1945                 vport->dev_loss_tmo_changed = 1;
 
1946                 lpfc_update_rport_devloss_tmo(vport);
 
1950         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
1951                          "0404 lpfc_devloss_tmo attribute cannot be set to"
 
1952                          " %d, allowed range is [%d, %d]\n",
 
1953                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
 
1957 lpfc_vport_param_store(devloss_tmo)
 
1958 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
 
1959                    lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
 
1962 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
 
1963 # deluged with LOTS of information.
 
1964 # You can set a bit mask to record specific types of verbose messages:
 
1966 # LOG_ELS                       0x1        ELS events
 
1967 # LOG_DISCOVERY                 0x2        Link discovery events
 
1968 # LOG_MBOX                      0x4        Mailbox events
 
1969 # LOG_INIT                      0x8        Initialization events
 
1970 # LOG_LINK_EVENT                0x10       Link events
 
1971 # LOG_FCP                       0x40       FCP traffic history
 
1972 # LOG_NODE                      0x80       Node table events
 
1973 # LOG_MISC                      0x400      Miscellaneous events
 
1974 # LOG_SLI                       0x800      SLI events
 
1975 # LOG_FCP_ERROR                 0x1000     Only log FCP errors
 
1976 # LOG_LIBDFC                    0x2000     LIBDFC events
 
1977 # LOG_ALL_MSG                   0xffff     LOG all messages
 
1979 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
 
1980                        "Verbose logging bit-mask");
 
1983 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
 
1984 # objects that have been registered with the nameserver after login.
 
1986 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
 
1987                   "Deregister nameserver objects before LOGO");
 
1990 # lun_queue_depth:  This parameter is used to limit the number of outstanding
 
1991 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
 
1993 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
 
1994                   "Max number of FCP commands we can queue to a specific LUN");
 
1997 # hba_queue_depth:  This parameter is used to limit the number of outstanding
 
1998 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
 
1999 # value is greater than the maximum number of exchanges supported by the HBA,
 
2000 # then maximum number of exchanges supported by the HBA is used to determine
 
2001 # the hba_queue_depth.
 
2003 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
 
2004             "Max number of FCP commands we can queue to a lpfc HBA");
 
2007 # peer_port_login:  This parameter allows/prevents logins
 
2008 # between peer ports hosted on the same physical port.
 
2009 # When this parameter is set 0 peer ports of same physical port
 
2010 # are not allowed to login to each other.
 
2011 # When this parameter is set 1 peer ports of same physical port
 
2012 # are allowed to login to each other.
 
2013 # Default value of this parameter is 0.
 
2015 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
 
2016                   "Allow peer ports on the same physical port to login to each "
 
2020 # restrict_login:  This parameter allows/prevents logins
 
2021 # between Virtual Ports and remote initiators.
 
2022 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
 
2023 # other initiators and will attempt to PLOGI all remote ports.
 
2024 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
 
2025 # remote ports and will not attempt to PLOGI to other initiators.
 
2026 # This parameter does not restrict to the physical port.
 
2027 # This parameter does not restrict logins to Fabric resident remote ports.
 
2028 # Default value of this parameter is 1.
 
2030 static int lpfc_restrict_login = 1;
 
2031 module_param(lpfc_restrict_login, int, 0);
 
2032 MODULE_PARM_DESC(lpfc_restrict_login,
 
2033                  "Restrict virtual ports login to remote initiators.");
 
2034 lpfc_vport_param_show(restrict_login);
 
2037  * lpfc_restrict_login_init: Set the vport restrict login flag.
 
2038  * @vport: lpfc vport structure pointer.
 
2039  * @val: contains the restrict login value.
 
2042  * If val is not in a valid range then log a kernel error message and set
 
2043  * the vport restrict login to one.
 
2044  * If the port type is physical clear the restrict login flag and return.
 
2045  * Else set the restrict login flag to val.
 
2048  * zero if val is in range
 
2049  * -EINVAL val out of range
 
2052 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
 
2054         if (val < 0 || val > 1) {
 
2055                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
2056                                  "0422 lpfc_restrict_login attribute cannot "
 
2057                                  "be set to %d, allowed range is [0, 1]\n",
 
2059                 vport->cfg_restrict_login = 1;
 
2062         if (vport->port_type == LPFC_PHYSICAL_PORT) {
 
2063                 vport->cfg_restrict_login = 0;
 
2066         vport->cfg_restrict_login = val;
 
2071  * lpfc_restrict_login_set: Set the vport restrict login flag.
 
2072  * @vport: lpfc vport structure pointer.
 
2073  * @val: contains the restrict login value.
 
2076  * If val is not in a valid range then log a kernel error message and set
 
2077  * the vport restrict login to one.
 
2078  * If the port type is physical and the val is not zero log a kernel
 
2079  * error message, clear the restrict login flag and return zero.
 
2080  * Else set the restrict login flag to val.
 
2083  * zero if val is in range
 
2084  * -EINVAL val out of range
 
2087 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
 
2089         if (val < 0 || val > 1) {
 
2090                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
2091                                  "0425 lpfc_restrict_login attribute cannot "
 
2092                                  "be set to %d, allowed range is [0, 1]\n",
 
2094                 vport->cfg_restrict_login = 1;
 
2097         if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
 
2098                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
 
2099                                  "0468 lpfc_restrict_login must be 0 for "
 
2100                                  "Physical ports.\n");
 
2101                 vport->cfg_restrict_login = 0;
 
2104         vport->cfg_restrict_login = val;
 
2107 lpfc_vport_param_store(restrict_login);
 
2108 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
 
2109                    lpfc_restrict_login_show, lpfc_restrict_login_store);
 
2112 # Some disk devices have a "select ID" or "select Target" capability.
 
2113 # From a protocol standpoint "select ID" usually means select the
 
2114 # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
 
2115 # annex" which contains a table that maps a "select ID" (a number
 
2116 # between 0 and 7F) to an ALPA.  By default, for compatibility with
 
2117 # older drivers, the lpfc driver scans this table from low ALPA to high
 
2120 # Turning on the scan-down variable (on  = 1, off = 0) will
 
2121 # cause the lpfc driver to use an inverted table, effectively
 
2122 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
 
2124 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
 
2125 # and will not work across a fabric. Also this parameter will take
 
2126 # effect only in the case when ALPA map is not available.)
 
2128 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
 
2129                   "Start scanning for devices from highest ALPA to lowest");
 
2132 # lpfc_topology:  link topology for init link
 
2133 #            0x0  = attempt loop mode then point-to-point
 
2134 #            0x01 = internal loopback mode
 
2135 #            0x02 = attempt point-to-point mode only
 
2136 #            0x04 = attempt loop mode only
 
2137 #            0x06 = attempt point-to-point mode then loop
 
2138 # Set point-to-point mode if you want to run as an N_Port.
 
2139 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
 
2140 # Default value is 0.
 
2144  * lpfc_topology_set: Set the adapters topology field.
 
2145  * @phba: lpfc_hba pointer.
 
2146  * @val: topology value.
 
2149  * If val is in a valid range then set the adapter's topology field and
 
2150  * issue a lip; if the lip fails reset the topology to the old value.
 
2152  * If the value is not in range log a kernel error message and return an error.
 
2155  * zero if val is in range and lip okay
 
2156  * non-zero return value from lpfc_issue_lip()
 
2157  * -EINVAL val out of range
 
2160 lpfc_topology_set(struct lpfc_hba *phba, int val)
 
2164         if (val >= 0 && val <= 6) {
 
2165                 prev_val = phba->cfg_topology;
 
2166                 phba->cfg_topology = val;
 
2167                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
 
2169                         phba->cfg_topology = prev_val;
 
2172         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 
2173                 "%d:0467 lpfc_topology attribute cannot be set to %d, "
 
2174                 "allowed range is [0, 6]\n",
 
2178 static int lpfc_topology = 0;
 
2179 module_param(lpfc_topology, int, 0);
 
2180 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
 
2181 lpfc_param_show(topology)
 
2182 lpfc_param_init(topology, 0, 0, 6)
 
2183 lpfc_param_store(topology)
 
2184 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
 
2185                 lpfc_topology_show, lpfc_topology_store);
 
2189  * lpfc_stat_data_ctrl_store: write call back for lpfc_stat_data_ctrl
 
2191  * @dev: Pointer to class device.
 
2192  * @buf: Data buffer.
 
2193  * @count: Size of the data buffer.
 
2195  * This function get called when an user write to the lpfc_stat_data_ctrl
 
2196  * sysfs file. This function parse the command written to the sysfs file
 
2197  * and take appropriate action. These commands are used for controlling
 
2198  * driver statistical data collection.
 
2199  * Following are the command this function handles.
 
2201  *    setbucket <bucket_type> <base> <step>
 
2202  *                             = Set the latency buckets.
 
2203  *    destroybucket            = destroy all the buckets.
 
2204  *    start                    = start data collection
 
2205  *    stop                     = stop data collection
 
2206  *    reset                    = reset the collected data
 
2209 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
 
2210                           const char *buf, size_t count)
 
2212         struct Scsi_Host  *shost = class_to_shost(dev);
 
2213         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
2214         struct lpfc_hba   *phba = vport->phba;
 
2215 #define LPFC_MAX_DATA_CTRL_LEN 1024
 
2216         static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
 
2218         char *str_ptr, *token;
 
2219         struct lpfc_vport **vports;
 
2220         struct Scsi_Host *v_shost;
 
2221         char *bucket_type_str, *base_str, *step_str;
 
2222         unsigned long base, step, bucket_type;
 
2224         if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
 
2225                 if (strlen(buf) > LPFC_MAX_DATA_CTRL_LEN)
 
2228                 strcpy(bucket_data, buf);
 
2229                 str_ptr = &bucket_data[0];
 
2230                 /* Ignore this token - this is command token */
 
2231                 token = strsep(&str_ptr, "\t ");
 
2235                 bucket_type_str = strsep(&str_ptr, "\t ");
 
2236                 if (!bucket_type_str)
 
2239                 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
 
2240                         bucket_type = LPFC_LINEAR_BUCKET;
 
2241                 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
 
2242                         bucket_type = LPFC_POWER2_BUCKET;
 
2246                 base_str = strsep(&str_ptr, "\t ");
 
2249                 base = simple_strtoul(base_str, NULL, 0);
 
2251                 step_str = strsep(&str_ptr, "\t ");
 
2254                 step = simple_strtoul(step_str, NULL, 0);
 
2258                 /* Block the data collection for every vport */
 
2259                 vports = lpfc_create_vport_work_array(phba);
 
2263                 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
 
2264                         v_shost = lpfc_shost_from_vport(vports[i]);
 
2265                         spin_lock_irq(v_shost->host_lock);
 
2266                         /* Block and reset data collection */
 
2267                         vports[i]->stat_data_blocked = 1;
 
2268                         if (vports[i]->stat_data_enabled)
 
2269                                 lpfc_vport_reset_stat_data(vports[i]);
 
2270                         spin_unlock_irq(v_shost->host_lock);
 
2273                 /* Set the bucket attributes */
 
2274                 phba->bucket_type = bucket_type;
 
2275                 phba->bucket_base = base;
 
2276                 phba->bucket_step = step;
 
2278                 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
 
2279                         v_shost = lpfc_shost_from_vport(vports[i]);
 
2281                         /* Unblock data collection */
 
2282                         spin_lock_irq(v_shost->host_lock);
 
2283                         vports[i]->stat_data_blocked = 0;
 
2284                         spin_unlock_irq(v_shost->host_lock);
 
2286                 lpfc_destroy_vport_work_array(phba, vports);
 
2290         if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
 
2291                 vports = lpfc_create_vport_work_array(phba);
 
2295                 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
 
2296                         v_shost = lpfc_shost_from_vport(vports[i]);
 
2297                         spin_lock_irq(shost->host_lock);
 
2298                         vports[i]->stat_data_blocked = 1;
 
2299                         lpfc_free_bucket(vport);
 
2300                         vport->stat_data_enabled = 0;
 
2301                         vports[i]->stat_data_blocked = 0;
 
2302                         spin_unlock_irq(shost->host_lock);
 
2304                 lpfc_destroy_vport_work_array(phba, vports);
 
2305                 phba->bucket_type = LPFC_NO_BUCKET;
 
2306                 phba->bucket_base = 0;
 
2307                 phba->bucket_step = 0;
 
2311         if (!strncmp(buf, "start", strlen("start"))) {
 
2312                 /* If no buckets configured return error */
 
2313                 if (phba->bucket_type == LPFC_NO_BUCKET)
 
2315                 spin_lock_irq(shost->host_lock);
 
2316                 if (vport->stat_data_enabled) {
 
2317                         spin_unlock_irq(shost->host_lock);
 
2320                 lpfc_alloc_bucket(vport);
 
2321                 vport->stat_data_enabled = 1;
 
2322                 spin_unlock_irq(shost->host_lock);
 
2326         if (!strncmp(buf, "stop", strlen("stop"))) {
 
2327                 spin_lock_irq(shost->host_lock);
 
2328                 if (vport->stat_data_enabled == 0) {
 
2329                         spin_unlock_irq(shost->host_lock);
 
2332                 lpfc_free_bucket(vport);
 
2333                 vport->stat_data_enabled = 0;
 
2334                 spin_unlock_irq(shost->host_lock);
 
2338         if (!strncmp(buf, "reset", strlen("reset"))) {
 
2339                 if ((phba->bucket_type == LPFC_NO_BUCKET)
 
2340                         || !vport->stat_data_enabled)
 
2342                 spin_lock_irq(shost->host_lock);
 
2343                 vport->stat_data_blocked = 1;
 
2344                 lpfc_vport_reset_stat_data(vport);
 
2345                 vport->stat_data_blocked = 0;
 
2346                 spin_unlock_irq(shost->host_lock);
 
2354  * lpfc_stat_data_ctrl_show: Read callback function for
 
2355  *   lpfc_stat_data_ctrl sysfs file.
 
2356  * @dev: Pointer to class device object.
 
2357  * @buf: Data buffer.
 
2359  * This function is the read call back function for
 
2360  * lpfc_stat_data_ctrl sysfs file. This function report the
 
2361  * current statistical data collection state.
 
2364 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
 
2367         struct Scsi_Host  *shost = class_to_shost(dev);
 
2368         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
2369         struct lpfc_hba   *phba = vport->phba;
 
2373         unsigned long bucket_value;
 
2375         switch (phba->bucket_type) {
 
2376         case LPFC_LINEAR_BUCKET:
 
2377                 bucket_type = "linear";
 
2379         case LPFC_POWER2_BUCKET:
 
2380                 bucket_type = "power2";
 
2383                 bucket_type = "No Bucket";
 
2387         sprintf(&buf[index], "Statistical Data enabled :%d, "
 
2388                 "blocked :%d, Bucket type :%s, Bucket base :%d,"
 
2389                 " Bucket step :%d\nLatency Ranges :",
 
2390                 vport->stat_data_enabled, vport->stat_data_blocked,
 
2391                 bucket_type, phba->bucket_base, phba->bucket_step);
 
2392         index = strlen(buf);
 
2393         if (phba->bucket_type != LPFC_NO_BUCKET) {
 
2394                 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
 
2395                         if (phba->bucket_type == LPFC_LINEAR_BUCKET)
 
2396                                 bucket_value = phba->bucket_base +
 
2397                                         phba->bucket_step * i;
 
2399                                 bucket_value = phba->bucket_base +
 
2400                                 (1 << i) * phba->bucket_step;
 
2402                         if (index + 10 > PAGE_SIZE)
 
2404                         sprintf(&buf[index], "%08ld ", bucket_value);
 
2405                         index = strlen(buf);
 
2408         sprintf(&buf[index], "\n");
 
2413  * Sysfs attribute to control the statistical data collection.
 
2415 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
 
2416                    lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
 
2419  * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
 
2423  * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
 
2426 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
 
2427 #define MAX_STAT_DATA_SIZE_PER_TARGET \
 
2428         STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
 
2432  * sysfs_drvr_stat_data_read: Read callback function for lpfc_drvr_stat_data
 
2434  * @kobj: Pointer to the kernel object
 
2435  * @bin_attr: Attribute object
 
2436  * @buff: Buffer pointer
 
2438  * @count: Buffer size
 
2440  * This function is the read call back function for lpfc_drvr_stat_data
 
2441  * sysfs file. This function export the statistical data to user
 
2445 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
 
2446                 char *buf, loff_t off, size_t count)
 
2448         struct device *dev = container_of(kobj, struct device,
 
2450         struct Scsi_Host  *shost = class_to_shost(dev);
 
2451         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
2452         struct lpfc_hba   *phba = vport->phba;
 
2453         int i = 0, index = 0;
 
2454         unsigned long nport_index;
 
2455         struct lpfc_nodelist *ndlp = NULL;
 
2456         nport_index = (unsigned long)off /
 
2457                 MAX_STAT_DATA_SIZE_PER_TARGET;
 
2459         if (!vport->stat_data_enabled || vport->stat_data_blocked
 
2460                 || (phba->bucket_type == LPFC_NO_BUCKET))
 
2463         spin_lock_irq(shost->host_lock);
 
2464         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
 
2465                 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
 
2468                 if (nport_index > 0) {
 
2473                 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
 
2477                 if (!ndlp->lat_data)
 
2481                 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
 
2482                         ndlp->nlp_portname.u.wwn[0],
 
2483                         ndlp->nlp_portname.u.wwn[1],
 
2484                         ndlp->nlp_portname.u.wwn[2],
 
2485                         ndlp->nlp_portname.u.wwn[3],
 
2486                         ndlp->nlp_portname.u.wwn[4],
 
2487                         ndlp->nlp_portname.u.wwn[5],
 
2488                         ndlp->nlp_portname.u.wwn[6],
 
2489                         ndlp->nlp_portname.u.wwn[7]);
 
2491                 index = strlen(buf);
 
2493                 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
 
2494                         sprintf(&buf[index], "%010u,",
 
2495                                 ndlp->lat_data[i].cmd_count);
 
2496                         index = strlen(buf);
 
2498                 sprintf(&buf[index], "\n");
 
2499                 index = strlen(buf);
 
2501         spin_unlock_irq(shost->host_lock);
 
2505 static struct bin_attribute sysfs_drvr_stat_data_attr = {
 
2507                 .name = "lpfc_drvr_stat_data",
 
2509                 .owner = THIS_MODULE,
 
2511         .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
 
2512         .read = sysfs_drvr_stat_data_read,
 
2517 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
 
2519 #       0  = auto select (default)
 
2524 # Value range is [0,8]. Default value is 0.
 
2528  * lpfc_link_speed_set: Set the adapters link speed.
 
2529  * @phba: lpfc_hba pointer.
 
2530  * @val: link speed value.
 
2533  * If val is in a valid range then set the adapter's link speed field and
 
2534  * issue a lip; if the lip fails reset the link speed to the old value.
 
2537  * If the value is not in range log a kernel error message and return an error.
 
2540  * zero if val is in range and lip okay.
 
2541  * non-zero return value from lpfc_issue_lip()
 
2542  * -EINVAL val out of range
 
2545 lpfc_link_speed_set(struct lpfc_hba *phba, int val)
 
2550         if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
 
2551                 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
 
2552                 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
 
2553                 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
 
2554                 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
 
2557         if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
 
2558                 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
 
2559                 prev_val = phba->cfg_link_speed;
 
2560                 phba->cfg_link_speed = val;
 
2561                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
 
2563                         phba->cfg_link_speed = prev_val;
 
2567         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 
2568                 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
 
2569                 "allowed range is [0, 8]\n",
 
2574 static int lpfc_link_speed = 0;
 
2575 module_param(lpfc_link_speed, int, 0);
 
2576 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
 
2577 lpfc_param_show(link_speed)
 
2580  * lpfc_link_speed_init: Set the adapters link speed.
 
2581  * @phba: lpfc_hba pointer.
 
2582  * @val: link speed value.
 
2585  * If val is in a valid range then set the adapter's link speed field.
 
2588  * If the value is not in range log a kernel error message, clear the link
 
2589  * speed and return an error.
 
2592  * zero if val saved.
 
2593  * -EINVAL val out of range
 
2596 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
 
2598         if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
 
2599                 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
 
2600                 phba->cfg_link_speed = val;
 
2603         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 
2604                         "0405 lpfc_link_speed attribute cannot "
 
2605                         "be set to %d, allowed values are "
 
2606                         "["LPFC_LINK_SPEED_STRING"]\n", val);
 
2607         phba->cfg_link_speed = 0;
 
2611 lpfc_param_store(link_speed)
 
2612 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
 
2613                 lpfc_link_speed_show, lpfc_link_speed_store);
 
2616 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
 
2617 # Value range is [2,3]. Default value is 3.
 
2619 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
 
2620                   "Select Fibre Channel class of service for FCP sequences");
 
2623 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
 
2624 # is [0,1]. Default value is 0.
 
2626 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
 
2627                    "Use ADISC on rediscovery to authenticate FCP devices");
 
2630 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
 
2631 # depth. Default value is 0. When the value of this parameter is zero the
 
2632 # SCSI command completion time is not used for controlling I/O queue depth. When
 
2633 # the parameter is set to a non-zero value, the I/O queue depth is controlled
 
2634 # to limit the I/O completion time to the parameter value.
 
2635 # The value is set in milliseconds.
 
2637 static int lpfc_max_scsicmpl_time;
 
2638 module_param(lpfc_max_scsicmpl_time, int, 0);
 
2639 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
 
2640         "Use command completion time to control queue depth");
 
2641 lpfc_vport_param_show(max_scsicmpl_time);
 
2642 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
 
2644 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
 
2646         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
 
2647         struct lpfc_nodelist *ndlp, *next_ndlp;
 
2649         if (val == vport->cfg_max_scsicmpl_time)
 
2651         if ((val < 0) || (val > 60000))
 
2653         vport->cfg_max_scsicmpl_time = val;
 
2655         spin_lock_irq(shost->host_lock);
 
2656         list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
 
2657                 if (!NLP_CHK_NODE_ACT(ndlp))
 
2659                 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
 
2661                 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
 
2663         spin_unlock_irq(shost->host_lock);
 
2666 lpfc_vport_param_store(max_scsicmpl_time);
 
2667 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
 
2668                    lpfc_max_scsicmpl_time_show,
 
2669                    lpfc_max_scsicmpl_time_store);
 
2672 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
 
2673 # range is [0,1]. Default value is 0.
 
2675 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
 
2678 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
 
2679 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
 
2680 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
 
2681 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
 
2682 # cr_delay is set to 0.
 
2684 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
 
2685                 "interrupt response is generated");
 
2687 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
 
2688                 "interrupt response is generated");
 
2691 # lpfc_multi_ring_support:  Determines how many rings to spread available
 
2692 # cmd/rsp IOCB entries across.
 
2693 # Value range is [1,2]. Default value is 1.
 
2695 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
 
2696                 "SLI rings to spread IOCB entries across");
 
2699 # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this
 
2700 # identifies what rctl value to configure the additional ring for.
 
2701 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
 
2703 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
 
2704              255, "Identifies RCTL for additional ring configuration");
 
2707 # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this
 
2708 # identifies what type value to configure the additional ring for.
 
2709 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
 
2711 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
 
2712              255, "Identifies TYPE for additional ring configuration");
 
2715 # lpfc_fdmi_on: controls FDMI support.
 
2716 #       0 = no FDMI support
 
2717 #       1 = support FDMI without attribute of hostname
 
2718 #       2 = support FDMI with attribute of hostname
 
2719 # Value range [0,2]. Default value is 0.
 
2721 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
 
2724 # Specifies the maximum number of ELS cmds we can have outstanding (for
 
2725 # discovery). Value range is [1,64]. Default value = 32.
 
2727 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
 
2728                  "during discovery");
 
2731 # lpfc_max_luns: maximum allowed LUN.
 
2732 # Value range is [0,65535]. Default value is 255.
 
2733 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
 
2735 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
 
2738 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
 
2739 # Value range is [1,255], default value is 10.
 
2741 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
 
2742              "Milliseconds driver will wait between polling FCP ring");
 
2745 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
 
2746 #               support this feature
 
2749 #       2  = MSI-X enabled (default)
 
2750 # Value range is [0,2]. Default value is 2.
 
2752 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
 
2753             "MSI-X (2), if possible");
 
2756 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
 
2757 #       0  = HBA resets disabled
 
2758 #       1  = HBA resets enabled (default)
 
2759 # Value range is [0,1]. Default value is 1.
 
2761 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
 
2764 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
 
2765 #       0  = HBA Heartbeat disabled
 
2766 #       1  = HBA Heartbeat enabled (default)
 
2767 # Value range is [0,1]. Default value is 1.
 
2769 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
 
2772  * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
 
2773  * This value can be set to values between 64 and 256. The default value is
 
2774  * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
 
2775  * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
 
2777 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
 
2778             LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
 
2780 struct device_attribute *lpfc_hba_attrs[] = {
 
2782         &dev_attr_serialnum,
 
2783         &dev_attr_modeldesc,
 
2784         &dev_attr_modelname,
 
2785         &dev_attr_programtype,
 
2789         &dev_attr_option_rom_version,
 
2790         &dev_attr_link_state,
 
2791         &dev_attr_num_discovered_ports,
 
2792         &dev_attr_menlo_mgmt_mode,
 
2793         &dev_attr_lpfc_drvr_version,
 
2794         &dev_attr_lpfc_temp_sensor,
 
2795         &dev_attr_lpfc_log_verbose,
 
2796         &dev_attr_lpfc_lun_queue_depth,
 
2797         &dev_attr_lpfc_hba_queue_depth,
 
2798         &dev_attr_lpfc_peer_port_login,
 
2799         &dev_attr_lpfc_nodev_tmo,
 
2800         &dev_attr_lpfc_devloss_tmo,
 
2801         &dev_attr_lpfc_fcp_class,
 
2802         &dev_attr_lpfc_use_adisc,
 
2803         &dev_attr_lpfc_ack0,
 
2804         &dev_attr_lpfc_topology,
 
2805         &dev_attr_lpfc_scan_down,
 
2806         &dev_attr_lpfc_link_speed,
 
2807         &dev_attr_lpfc_cr_delay,
 
2808         &dev_attr_lpfc_cr_count,
 
2809         &dev_attr_lpfc_multi_ring_support,
 
2810         &dev_attr_lpfc_multi_ring_rctl,
 
2811         &dev_attr_lpfc_multi_ring_type,
 
2812         &dev_attr_lpfc_fdmi_on,
 
2813         &dev_attr_lpfc_max_luns,
 
2814         &dev_attr_lpfc_enable_npiv,
 
2815         &dev_attr_nport_evt_cnt,
 
2816         &dev_attr_board_mode,
 
2823         &dev_attr_npiv_info,
 
2824         &dev_attr_issue_reset,
 
2825         &dev_attr_lpfc_poll,
 
2826         &dev_attr_lpfc_poll_tmo,
 
2827         &dev_attr_lpfc_use_msi,
 
2828         &dev_attr_lpfc_soft_wwnn,
 
2829         &dev_attr_lpfc_soft_wwpn,
 
2830         &dev_attr_lpfc_soft_wwn_enable,
 
2831         &dev_attr_lpfc_enable_hba_reset,
 
2832         &dev_attr_lpfc_enable_hba_heartbeat,
 
2833         &dev_attr_lpfc_sg_seg_cnt,
 
2834         &dev_attr_lpfc_max_scsicmpl_time,
 
2835         &dev_attr_lpfc_stat_data_ctrl,
 
2839 struct device_attribute *lpfc_vport_attrs[] = {
 
2841         &dev_attr_link_state,
 
2842         &dev_attr_num_discovered_ports,
 
2843         &dev_attr_lpfc_drvr_version,
 
2844         &dev_attr_lpfc_log_verbose,
 
2845         &dev_attr_lpfc_lun_queue_depth,
 
2846         &dev_attr_lpfc_nodev_tmo,
 
2847         &dev_attr_lpfc_devloss_tmo,
 
2848         &dev_attr_lpfc_hba_queue_depth,
 
2849         &dev_attr_lpfc_peer_port_login,
 
2850         &dev_attr_lpfc_restrict_login,
 
2851         &dev_attr_lpfc_fcp_class,
 
2852         &dev_attr_lpfc_use_adisc,
 
2853         &dev_attr_lpfc_fdmi_on,
 
2854         &dev_attr_lpfc_max_luns,
 
2855         &dev_attr_nport_evt_cnt,
 
2856         &dev_attr_npiv_info,
 
2857         &dev_attr_lpfc_enable_da_id,
 
2858         &dev_attr_lpfc_max_scsicmpl_time,
 
2859         &dev_attr_lpfc_stat_data_ctrl,
 
2864  * sysfs_ctlreg_write: Write method for writing to ctlreg.
 
2865  * @kobj: kernel kobject that contains the kernel class device.
 
2866  * @bin_attr: kernel attributes passed to us.
 
2867  * @buf: contains the data to be written to the adapter IOREG space.
 
2868  * @off: offset into buffer to beginning of data.
 
2869  * @count: bytes to transfer.
 
2872  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
 
2873  * Uses the adapter io control registers to send buf contents to the adapter.
 
2876  * -ERANGE off and count combo out of range
 
2877  * -EINVAL off, count or buff address invalid
 
2878  * -EPERM adapter is offline
 
2879  * value of count, buf contents written
 
2882 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
 
2883                    char *buf, loff_t off, size_t count)
 
2886         struct device *dev = container_of(kobj, struct device, kobj);
 
2887         struct Scsi_Host  *shost = class_to_shost(dev);
 
2888         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
2889         struct lpfc_hba   *phba = vport->phba;
 
2891         if ((off + count) > FF_REG_AREA_SIZE)
 
2894         if (count == 0) return 0;
 
2896         if (off % 4 || count % 4 || (unsigned long)buf % 4)
 
2899         if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
 
2903         spin_lock_irq(&phba->hbalock);
 
2904         for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
 
2905                 writel(*((uint32_t *)(buf + buf_off)),
 
2906                        phba->ctrl_regs_memmap_p + off + buf_off);
 
2908         spin_unlock_irq(&phba->hbalock);
 
2914  * sysfs_ctlreg_read: Read method for reading from ctlreg.
 
2915  * @kobj: kernel kobject that contains the kernel class device.
 
2916  * @bin_attr: kernel attributes passed to us.
 
2917  * @buf: if succesful contains the data from the adapter IOREG space.
 
2918  * @off: offset into buffer to beginning of data.
 
2919  * @count: bytes to transfer.
 
2922  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
 
2923  * Uses the adapter io control registers to read data into buf.
 
2926  * -ERANGE off and count combo out of range
 
2927  * -EINVAL off, count or buff address invalid
 
2928  * value of count, buf contents read
 
2931 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
 
2932                   char *buf, loff_t off, size_t count)
 
2936         struct device *dev = container_of(kobj, struct device, kobj);
 
2937         struct Scsi_Host  *shost = class_to_shost(dev);
 
2938         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
2939         struct lpfc_hba   *phba = vport->phba;
 
2941         if (off > FF_REG_AREA_SIZE)
 
2944         if ((off + count) > FF_REG_AREA_SIZE)
 
2945                 count = FF_REG_AREA_SIZE - off;
 
2947         if (count == 0) return 0;
 
2949         if (off % 4 || count % 4 || (unsigned long)buf % 4)
 
2952         spin_lock_irq(&phba->hbalock);
 
2954         for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
 
2955                 tmp_ptr = (uint32_t *)(buf + buf_off);
 
2956                 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
 
2959         spin_unlock_irq(&phba->hbalock);
 
2964 static struct bin_attribute sysfs_ctlreg_attr = {
 
2967                 .mode = S_IRUSR | S_IWUSR,
 
2970         .read = sysfs_ctlreg_read,
 
2971         .write = sysfs_ctlreg_write,
 
2975  * sysfs_mbox_idle: frees the sysfs mailbox.
 
2976  * @phba: lpfc_hba pointer
 
2979 sysfs_mbox_idle(struct lpfc_hba *phba)
 
2981         phba->sysfs_mbox.state = SMBOX_IDLE;
 
2982         phba->sysfs_mbox.offset = 0;
 
2984         if (phba->sysfs_mbox.mbox) {
 
2985                 mempool_free(phba->sysfs_mbox.mbox,
 
2986                              phba->mbox_mem_pool);
 
2987                 phba->sysfs_mbox.mbox = NULL;
 
2992  * sysfs_mbox_write: Write method for writing information via mbox.
 
2993  * @kobj: kernel kobject that contains the kernel class device.
 
2994  * @bin_attr: kernel attributes passed to us.
 
2995  * @buf: contains the data to be written to sysfs mbox.
 
2996  * @off: offset into buffer to beginning of data.
 
2997  * @count: bytes to transfer.
 
3000  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
 
3001  * Uses the sysfs mbox to send buf contents to the adapter.
 
3004  * -ERANGE off and count combo out of range
 
3005  * -EINVAL off, count or buff address invalid
 
3006  * zero if count is zero
 
3007  * -EPERM adapter is offline
 
3008  * -ENOMEM failed to allocate memory for the mail box
 
3009  * -EAGAIN offset, state or mbox is NULL
 
3010  * count number of bytes transferred
 
3013 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
 
3014                  char *buf, loff_t off, size_t count)
 
3016         struct device *dev = container_of(kobj, struct device, kobj);
 
3017         struct Scsi_Host  *shost = class_to_shost(dev);
 
3018         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3019         struct lpfc_hba   *phba = vport->phba;
 
3020         struct lpfcMboxq  *mbox = NULL;
 
3022         if ((count + off) > MAILBOX_CMD_SIZE)
 
3025         if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
 
3032                 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
3035                 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
 
3038         spin_lock_irq(&phba->hbalock);
 
3041                 if (phba->sysfs_mbox.mbox)
 
3042                         mempool_free(mbox, phba->mbox_mem_pool);
 
3044                         phba->sysfs_mbox.mbox = mbox;
 
3045                 phba->sysfs_mbox.state = SMBOX_WRITING;
 
3047                 if (phba->sysfs_mbox.state  != SMBOX_WRITING ||
 
3048                     phba->sysfs_mbox.offset != off           ||
 
3049                     phba->sysfs_mbox.mbox   == NULL) {
 
3050                         sysfs_mbox_idle(phba);
 
3051                         spin_unlock_irq(&phba->hbalock);
 
3056         memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
 
3059         phba->sysfs_mbox.offset = off + count;
 
3061         spin_unlock_irq(&phba->hbalock);
 
3067  * sysfs_mbox_read: Read method for reading information via mbox.
 
3068  * @kobj: kernel kobject that contains the kernel class device.
 
3069  * @bin_attr: kernel attributes passed to us.
 
3070  * @buf: contains the data to be read from sysfs mbox.
 
3071  * @off: offset into buffer to beginning of data.
 
3072  * @count: bytes to transfer.
 
3075  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
 
3076  * Uses the sysfs mbox to receive data from to the adapter.
 
3079  * -ERANGE off greater than mailbox command size
 
3080  * -EINVAL off, count or buff address invalid
 
3081  * zero if off and count are zero
 
3082  * -EACCES adapter over temp
 
3083  * -EPERM garbage can value to catch a multitude of errors
 
3084  * -EAGAIN management IO not permitted, state or off error
 
3085  * -ETIME mailbox timeout
 
3086  * -ENODEV mailbox error
 
3087  * count number of bytes transferred
 
3090 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
 
3091                 char *buf, loff_t off, size_t count)
 
3093         struct device *dev = container_of(kobj, struct device, kobj);
 
3094         struct Scsi_Host  *shost = class_to_shost(dev);
 
3095         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3096         struct lpfc_hba   *phba = vport->phba;
 
3099         if (off > MAILBOX_CMD_SIZE)
 
3102         if ((count + off) > MAILBOX_CMD_SIZE)
 
3103                 count = MAILBOX_CMD_SIZE - off;
 
3105         if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
 
3108         if (off && count == 0)
 
3111         spin_lock_irq(&phba->hbalock);
 
3113         if (phba->over_temp_state == HBA_OVER_TEMP) {
 
3114                 sysfs_mbox_idle(phba);
 
3115                 spin_unlock_irq(&phba->hbalock);
 
3120             phba->sysfs_mbox.state  == SMBOX_WRITING &&
 
3121             phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
 
3123                 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
 
3127                 case MBX_CONFIG_LINK:
 
3128                 case MBX_CONFIG_RING:
 
3129                 case MBX_RESET_RING:
 
3130                 case MBX_UNREG_LOGIN:
 
3132                 case MBX_DUMP_CONTEXT:
 
3137                         if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
 
3138                                 printk(KERN_WARNING "mbox_read:Command 0x%x "
 
3139                                        "is illegal in on-line state\n",
 
3140                                        phba->sysfs_mbox.mbox->mb.mbxCommand);
 
3141                                 sysfs_mbox_idle(phba);
 
3142                                 spin_unlock_irq(&phba->hbalock);
 
3146                 case MBX_WRITE_VPARMS:
 
3149                 case MBX_READ_CONFIG:
 
3150                 case MBX_READ_RCONFIG:
 
3151                 case MBX_READ_STATUS:
 
3154                 case MBX_READ_LNK_STAT:
 
3155                 case MBX_DUMP_MEMORY:
 
3157                 case MBX_UPDATE_CFG:
 
3158                 case MBX_KILL_BOARD:
 
3160                 case MBX_LOAD_EXP_ROM:
 
3162                 case MBX_DEL_LD_ENTRY:
 
3163                 case MBX_SET_VARIABLE:
 
3165                 case MBX_PORT_CAPABILITIES:
 
3166                 case MBX_PORT_IOV_CONTROL:
 
3168                 case MBX_READ_SPARM64:
 
3172                 case MBX_REG_LOGIN64:
 
3173                 case MBX_CONFIG_PORT:
 
3174                 case MBX_RUN_BIU_DIAG:
 
3175                         printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
 
3176                                phba->sysfs_mbox.mbox->mb.mbxCommand);
 
3177                         sysfs_mbox_idle(phba);
 
3178                         spin_unlock_irq(&phba->hbalock);
 
3181                         printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
 
3182                                phba->sysfs_mbox.mbox->mb.mbxCommand);
 
3183                         sysfs_mbox_idle(phba);
 
3184                         spin_unlock_irq(&phba->hbalock);
 
3188                 /* If HBA encountered an error attention, allow only DUMP
 
3189                  * or RESTART mailbox commands until the HBA is restarted.
 
3191                 if (phba->pport->stopped &&
 
3192                     phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY &&
 
3193                     phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART &&
 
3194                     phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS &&
 
3195                     phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN)
 
3196                         lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
 
3197                                         "1259 mbox: Issued mailbox cmd "
 
3198                                         "0x%x while in stopped state.\n",
 
3199                                         phba->sysfs_mbox.mbox->mb.mbxCommand);
 
3201                 phba->sysfs_mbox.mbox->vport = vport;
 
3203                 /* Don't allow mailbox commands to be sent when blocked
 
3204                  * or when in the middle of discovery
 
3206                 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
 
3207                         sysfs_mbox_idle(phba);
 
3208                         spin_unlock_irq(&phba->hbalock);
 
3212                 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
3213                     (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
 
3215                         spin_unlock_irq(&phba->hbalock);
 
3216                         rc = lpfc_sli_issue_mbox (phba,
 
3217                                                   phba->sysfs_mbox.mbox,
 
3219                         spin_lock_irq(&phba->hbalock);
 
3222                         spin_unlock_irq(&phba->hbalock);
 
3223                         rc = lpfc_sli_issue_mbox_wait (phba,
 
3224                                                        phba->sysfs_mbox.mbox,
 
3225                                 lpfc_mbox_tmo_val(phba,
 
3226                                     phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
 
3227                         spin_lock_irq(&phba->hbalock);
 
3230                 if (rc != MBX_SUCCESS) {
 
3231                         if (rc == MBX_TIMEOUT) {
 
3232                                 phba->sysfs_mbox.mbox = NULL;
 
3234                         sysfs_mbox_idle(phba);
 
3235                         spin_unlock_irq(&phba->hbalock);
 
3236                         return  (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
 
3238                 phba->sysfs_mbox.state = SMBOX_READING;
 
3240         else if (phba->sysfs_mbox.offset != off ||
 
3241                  phba->sysfs_mbox.state  != SMBOX_READING) {
 
3242                 printk(KERN_WARNING  "mbox_read: Bad State\n");
 
3243                 sysfs_mbox_idle(phba);
 
3244                 spin_unlock_irq(&phba->hbalock);
 
3248         memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
 
3250         phba->sysfs_mbox.offset = off + count;
 
3252         if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
 
3253                 sysfs_mbox_idle(phba);
 
3255         spin_unlock_irq(&phba->hbalock);
 
3260 static struct bin_attribute sysfs_mbox_attr = {
 
3263                 .mode = S_IRUSR | S_IWUSR,
 
3265         .size = MAILBOX_CMD_SIZE,
 
3266         .read = sysfs_mbox_read,
 
3267         .write = sysfs_mbox_write,
 
3271  * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries.
 
3272  * @vport: address of lpfc vport structure.
 
3276  * error return code from sysfs_create_bin_file()
 
3279 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
 
3281         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
 
3284         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
 
3285                                       &sysfs_ctlreg_attr);
 
3289         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
 
3292                 goto out_remove_ctlreg_attr;
 
3294         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
 
3295                                       &sysfs_drvr_stat_data_attr);
 
3297                 goto out_remove_mbox_attr;
 
3300 out_remove_mbox_attr:
 
3301         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
 
3302 out_remove_ctlreg_attr:
 
3303         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
 
3309  * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries.
 
3310  * @vport: address of lpfc vport structure.
 
3313 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
 
3315         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
 
3316         sysfs_remove_bin_file(&shost->shost_dev.kobj,
 
3317                 &sysfs_drvr_stat_data_attr);
 
3318         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
 
3319         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
 
3324  * Dynamic FC Host Attributes Support
 
3328  * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
 
3329  * @shost: kernel scsi host pointer.
 
3332 lpfc_get_host_port_id(struct Scsi_Host *shost)
 
3334         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3336         /* note: fc_myDID already in cpu endianness */
 
3337         fc_host_port_id(shost) = vport->fc_myDID;
 
3341  * lpfc_get_host_port_type: Set the value of the scsi host port type.
 
3342  * @shost: kernel scsi host pointer.
 
3345 lpfc_get_host_port_type(struct Scsi_Host *shost)
 
3347         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3348         struct lpfc_hba   *phba = vport->phba;
 
3350         spin_lock_irq(shost->host_lock);
 
3352         if (vport->port_type == LPFC_NPIV_PORT) {
 
3353                 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
 
3354         } else if (lpfc_is_link_up(phba)) {
 
3355                 if (phba->fc_topology == TOPOLOGY_LOOP) {
 
3356                         if (vport->fc_flag & FC_PUBLIC_LOOP)
 
3357                                 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
 
3359                                 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
 
3361                         if (vport->fc_flag & FC_FABRIC)
 
3362                                 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
 
3364                                 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
 
3367                 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
 
3369         spin_unlock_irq(shost->host_lock);
 
3373  * lpfc_get_host_port_state: Set the value of the scsi host port state.
 
3374  * @shost: kernel scsi host pointer.
 
3377 lpfc_get_host_port_state(struct Scsi_Host *shost)
 
3379         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3380         struct lpfc_hba   *phba = vport->phba;
 
3382         spin_lock_irq(shost->host_lock);
 
3384         if (vport->fc_flag & FC_OFFLINE_MODE)
 
3385                 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
 
3387                 switch (phba->link_state) {
 
3388                 case LPFC_LINK_UNKNOWN:
 
3389                 case LPFC_LINK_DOWN:
 
3390                         fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
 
3394                 case LPFC_HBA_READY:
 
3395                         /* Links up, beyond this port_type reports state */
 
3396                         fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
 
3398                 case LPFC_HBA_ERROR:
 
3399                         fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
 
3402                         fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
 
3407         spin_unlock_irq(shost->host_lock);
 
3411  * lpfc_get_host_speed: Set the value of the scsi host speed.
 
3412  * @shost: kernel scsi host pointer.
 
3415 lpfc_get_host_speed(struct Scsi_Host *shost)
 
3417         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3418         struct lpfc_hba   *phba = vport->phba;
 
3420         spin_lock_irq(shost->host_lock);
 
3422         if (lpfc_is_link_up(phba)) {
 
3423                 switch(phba->fc_linkspeed) {
 
3425                                 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
 
3428                                 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
 
3431                                 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
 
3434                                 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
 
3437                                 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
 
3441                 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
 
3443         spin_unlock_irq(shost->host_lock);
 
3447  * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
 
3448  * @shost: kernel scsi host pointer.
 
3451 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
 
3453         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3454         struct lpfc_hba   *phba = vport->phba;
 
3457         spin_lock_irq(shost->host_lock);
 
3459         if ((vport->fc_flag & FC_FABRIC) ||
 
3460             ((phba->fc_topology == TOPOLOGY_LOOP) &&
 
3461              (vport->fc_flag & FC_PUBLIC_LOOP)))
 
3462                 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
 
3464                 /* fabric is local port if there is no F/FL_Port */
 
3467         spin_unlock_irq(shost->host_lock);
 
3469         fc_host_fabric_name(shost) = node_name;
 
3473  * lpfc_get_stats: Return statistical information about the adapter.
 
3474  * @shost: kernel scsi host pointer.
 
3477  * NULL on error for link down, no mbox pool, sli2 active,
 
3478  * management not allowed, memory allocation error, or mbox error.
 
3482  * address of the adapter host statistics
 
3484 static struct fc_host_statistics *
 
3485 lpfc_get_stats(struct Scsi_Host *shost)
 
3487         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3488         struct lpfc_hba   *phba = vport->phba;
 
3489         struct lpfc_sli   *psli = &phba->sli;
 
3490         struct fc_host_statistics *hs = &phba->link_stats;
 
3491         struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
 
3492         LPFC_MBOXQ_t *pmboxq;
 
3494         unsigned long seconds;
 
3498          * prevent udev from issuing mailbox commands until the port is
 
3501         if (phba->link_state < LPFC_LINK_DOWN ||
 
3502             !phba->mbox_mem_pool ||
 
3503             (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
 
3506         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
 
3509         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
3512         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
 
3515         pmb->mbxCommand = MBX_READ_STATUS;
 
3516         pmb->mbxOwner = OWN_HOST;
 
3517         pmboxq->context1 = NULL;
 
3518         pmboxq->vport = vport;
 
3520         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
3521                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
 
3522                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
 
3524                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
 
3526         if (rc != MBX_SUCCESS) {
 
3527                 if (rc != MBX_TIMEOUT)
 
3528                         mempool_free(pmboxq, phba->mbox_mem_pool);
 
3532         memset(hs, 0, sizeof (struct fc_host_statistics));
 
3534         hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
 
3535         hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
 
3536         hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
 
3537         hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
 
3539         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
 
3540         pmb->mbxCommand = MBX_READ_LNK_STAT;
 
3541         pmb->mbxOwner = OWN_HOST;
 
3542         pmboxq->context1 = NULL;
 
3543         pmboxq->vport = vport;
 
3545         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
3546             (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
 
3547                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
 
3549                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
 
3551         if (rc != MBX_SUCCESS) {
 
3552                 if (rc != MBX_TIMEOUT)
 
3553                         mempool_free(pmboxq, phba->mbox_mem_pool);
 
3557         hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
 
3558         hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
 
3559         hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
 
3560         hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
 
3561         hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
 
3562         hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
 
3563         hs->error_frames = pmb->un.varRdLnk.crcCnt;
 
3565         hs->link_failure_count -= lso->link_failure_count;
 
3566         hs->loss_of_sync_count -= lso->loss_of_sync_count;
 
3567         hs->loss_of_signal_count -= lso->loss_of_signal_count;
 
3568         hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
 
3569         hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
 
3570         hs->invalid_crc_count -= lso->invalid_crc_count;
 
3571         hs->error_frames -= lso->error_frames;
 
3573         if (phba->fc_topology == TOPOLOGY_LOOP) {
 
3574                 hs->lip_count = (phba->fc_eventTag >> 1);
 
3575                 hs->lip_count -= lso->link_events;
 
3579                 hs->nos_count = (phba->fc_eventTag >> 1);
 
3580                 hs->nos_count -= lso->link_events;
 
3583         hs->dumped_frames = -1;
 
3585         seconds = get_seconds();
 
3586         if (seconds < psli->stats_start)
 
3587                 hs->seconds_since_last_reset = seconds +
 
3588                                 ((unsigned long)-1 - psli->stats_start);
 
3590                 hs->seconds_since_last_reset = seconds - psli->stats_start;
 
3592         mempool_free(pmboxq, phba->mbox_mem_pool);
 
3598  * lpfc_reset_stats: Copy the adapter link stats information.
 
3599  * @shost: kernel scsi host pointer.
 
3602 lpfc_reset_stats(struct Scsi_Host *shost)
 
3604         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3605         struct lpfc_hba   *phba = vport->phba;
 
3606         struct lpfc_sli   *psli = &phba->sli;
 
3607         struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
 
3608         LPFC_MBOXQ_t *pmboxq;
 
3612         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
 
3615         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
 
3618         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
 
3621         pmb->mbxCommand = MBX_READ_STATUS;
 
3622         pmb->mbxOwner = OWN_HOST;
 
3623         pmb->un.varWords[0] = 0x1; /* reset request */
 
3624         pmboxq->context1 = NULL;
 
3625         pmboxq->vport = vport;
 
3627         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
3628                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
 
3629                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
 
3631                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
 
3633         if (rc != MBX_SUCCESS) {
 
3634                 if (rc != MBX_TIMEOUT)
 
3635                         mempool_free(pmboxq, phba->mbox_mem_pool);
 
3639         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
 
3640         pmb->mbxCommand = MBX_READ_LNK_STAT;
 
3641         pmb->mbxOwner = OWN_HOST;
 
3642         pmboxq->context1 = NULL;
 
3643         pmboxq->vport = vport;
 
3645         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
 
3646             (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
 
3647                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
 
3649                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
 
3651         if (rc != MBX_SUCCESS) {
 
3652                 if (rc != MBX_TIMEOUT)
 
3653                         mempool_free( pmboxq, phba->mbox_mem_pool);
 
3657         lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
 
3658         lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
 
3659         lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
 
3660         lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
 
3661         lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
 
3662         lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
 
3663         lso->error_frames = pmb->un.varRdLnk.crcCnt;
 
3664         lso->link_events = (phba->fc_eventTag >> 1);
 
3666         psli->stats_start = get_seconds();
 
3668         mempool_free(pmboxq, phba->mbox_mem_pool);
 
3674  * The LPFC driver treats linkdown handling as target loss events so there
 
3675  * are no sysfs handlers for link_down_tmo.
 
3679  * lpfc_get_node_by_target: Return the nodelist for a target.
 
3680  * @starget: kernel scsi target pointer.
 
3683  * address of the node list if found
 
3684  * NULL target not found
 
3686 static struct lpfc_nodelist *
 
3687 lpfc_get_node_by_target(struct scsi_target *starget)
 
3689         struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);
 
3690         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
3691         struct lpfc_nodelist *ndlp;
 
3693         spin_lock_irq(shost->host_lock);
 
3694         /* Search for this, mapped, target ID */
 
3695         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
 
3696                 if (NLP_CHK_NODE_ACT(ndlp) &&
 
3697                     ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
 
3698                     starget->id == ndlp->nlp_sid) {
 
3699                         spin_unlock_irq(shost->host_lock);
 
3703         spin_unlock_irq(shost->host_lock);
 
3708  * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
 
3709  * @starget: kernel scsi target pointer.
 
3712 lpfc_get_starget_port_id(struct scsi_target *starget)
 
3714         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
 
3716         fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
 
3720  * lpfc_get_starget_node_name: Set the target node name.
 
3721  * @starget: kernel scsi target pointer.
 
3723  * Description: Set the target node name to the ndlp node name wwn or zero.
 
3726 lpfc_get_starget_node_name(struct scsi_target *starget)
 
3728         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
 
3730         fc_starget_node_name(starget) =
 
3731                 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
 
3735  * lpfc_get_starget_port_name: Set the target port name.
 
3736  * @starget: kernel scsi target pointer.
 
3738  * Description:  set the target port name to the ndlp port name wwn or zero.
 
3741 lpfc_get_starget_port_name(struct scsi_target *starget)
 
3743         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
 
3745         fc_starget_port_name(starget) =
 
3746                 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
 
3750  * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
 
3751  * @rport: fc rport address.
 
3752  * @timeout: new value for dev loss tmo.
 
3755  * If timeout is non zero set the dev_loss_tmo to timeout, else set
 
3756  * dev_loss_tmo to one.
 
3759 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
 
3762                 rport->dev_loss_tmo = timeout;
 
3764                 rport->dev_loss_tmo = 1;
 
3768  * lpfc_rport_show_function: Return rport target information.
 
3771  * Macro that uses field to generate a function with the name lpfc_show_rport_
 
3773  * lpfc_show_rport_##field: returns the bytes formatted in buf
 
3774  * @cdev: class converted to an fc_rport.
 
3775  * @buf: on return contains the target_field or zero.
 
3777  * Returns: size of formatted string.
 
3779 #define lpfc_rport_show_function(field, format_string, sz, cast)        \
 
3781 lpfc_show_rport_##field (struct device *dev,                            \
 
3782                          struct device_attribute *attr,                 \
 
3785         struct fc_rport *rport = transport_class_to_rport(dev);         \
 
3786         struct lpfc_rport_data *rdata = rport->hostdata;                \
 
3787         return snprintf(buf, sz, format_string,                         \
 
3788                 (rdata->target) ? cast rdata->target->field : 0);       \
 
3791 #define lpfc_rport_rd_attr(field, format_string, sz)                    \
 
3792         lpfc_rport_show_function(field, format_string, sz, )            \
 
3793 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
 
3796 struct fc_function_template lpfc_transport_functions = {
 
3797         /* fixed attributes the driver supports */
 
3798         .show_host_node_name = 1,
 
3799         .show_host_port_name = 1,
 
3800         .show_host_supported_classes = 1,
 
3801         .show_host_supported_fc4s = 1,
 
3802         .show_host_supported_speeds = 1,
 
3803         .show_host_maxframe_size = 1,
 
3805         /* dynamic attributes the driver supports */
 
3806         .get_host_port_id = lpfc_get_host_port_id,
 
3807         .show_host_port_id = 1,
 
3809         .get_host_port_type = lpfc_get_host_port_type,
 
3810         .show_host_port_type = 1,
 
3812         .get_host_port_state = lpfc_get_host_port_state,
 
3813         .show_host_port_state = 1,
 
3815         /* active_fc4s is shown but doesn't change (thus no get function) */
 
3816         .show_host_active_fc4s = 1,
 
3818         .get_host_speed = lpfc_get_host_speed,
 
3819         .show_host_speed = 1,
 
3821         .get_host_fabric_name = lpfc_get_host_fabric_name,
 
3822         .show_host_fabric_name = 1,
 
3825          * The LPFC driver treats linkdown handling as target loss events
 
3826          * so there are no sysfs handlers for link_down_tmo.
 
3829         .get_fc_host_stats = lpfc_get_stats,
 
3830         .reset_fc_host_stats = lpfc_reset_stats,
 
3832         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
 
3833         .show_rport_maxframe_size = 1,
 
3834         .show_rport_supported_classes = 1,
 
3836         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
 
3837         .show_rport_dev_loss_tmo = 1,
 
3839         .get_starget_port_id  = lpfc_get_starget_port_id,
 
3840         .show_starget_port_id = 1,
 
3842         .get_starget_node_name = lpfc_get_starget_node_name,
 
3843         .show_starget_node_name = 1,
 
3845         .get_starget_port_name = lpfc_get_starget_port_name,
 
3846         .show_starget_port_name = 1,
 
3848         .issue_fc_host_lip = lpfc_issue_lip,
 
3849         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
 
3850         .terminate_rport_io = lpfc_terminate_rport_io,
 
3852         .dd_fcvport_size = sizeof(struct lpfc_vport *),
 
3855 struct fc_function_template lpfc_vport_transport_functions = {
 
3856         /* fixed attributes the driver supports */
 
3857         .show_host_node_name = 1,
 
3858         .show_host_port_name = 1,
 
3859         .show_host_supported_classes = 1,
 
3860         .show_host_supported_fc4s = 1,
 
3861         .show_host_supported_speeds = 1,
 
3862         .show_host_maxframe_size = 1,
 
3864         /* dynamic attributes the driver supports */
 
3865         .get_host_port_id = lpfc_get_host_port_id,
 
3866         .show_host_port_id = 1,
 
3868         .get_host_port_type = lpfc_get_host_port_type,
 
3869         .show_host_port_type = 1,
 
3871         .get_host_port_state = lpfc_get_host_port_state,
 
3872         .show_host_port_state = 1,
 
3874         /* active_fc4s is shown but doesn't change (thus no get function) */
 
3875         .show_host_active_fc4s = 1,
 
3877         .get_host_speed = lpfc_get_host_speed,
 
3878         .show_host_speed = 1,
 
3880         .get_host_fabric_name = lpfc_get_host_fabric_name,
 
3881         .show_host_fabric_name = 1,
 
3884          * The LPFC driver treats linkdown handling as target loss events
 
3885          * so there are no sysfs handlers for link_down_tmo.
 
3888         .get_fc_host_stats = lpfc_get_stats,
 
3889         .reset_fc_host_stats = lpfc_reset_stats,
 
3891         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
 
3892         .show_rport_maxframe_size = 1,
 
3893         .show_rport_supported_classes = 1,
 
3895         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
 
3896         .show_rport_dev_loss_tmo = 1,
 
3898         .get_starget_port_id  = lpfc_get_starget_port_id,
 
3899         .show_starget_port_id = 1,
 
3901         .get_starget_node_name = lpfc_get_starget_node_name,
 
3902         .show_starget_node_name = 1,
 
3904         .get_starget_port_name = lpfc_get_starget_port_name,
 
3905         .show_starget_port_name = 1,
 
3907         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
 
3908         .terminate_rport_io = lpfc_terminate_rport_io,
 
3910         .vport_disable = lpfc_vport_disable,
 
3914  * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
 
3915  * @phba: lpfc_hba pointer.
 
3918 lpfc_get_cfgparam(struct lpfc_hba *phba)
 
3920         lpfc_cr_delay_init(phba, lpfc_cr_delay);
 
3921         lpfc_cr_count_init(phba, lpfc_cr_count);
 
3922         lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
 
3923         lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
 
3924         lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
 
3925         lpfc_ack0_init(phba, lpfc_ack0);
 
3926         lpfc_topology_init(phba, lpfc_topology);
 
3927         lpfc_link_speed_init(phba, lpfc_link_speed);
 
3928         lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
 
3929         lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
 
3930         lpfc_use_msi_init(phba, lpfc_use_msi);
 
3931         lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
 
3932         lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
 
3933         phba->cfg_poll = lpfc_poll;
 
3934         phba->cfg_soft_wwnn = 0L;
 
3935         phba->cfg_soft_wwpn = 0L;
 
3936         lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
 
3937         /* Also reinitialize the host templates with new values. */
 
3938         lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
 
3939         lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
 
3941          * Since the sg_tablesize is module parameter, the sg_dma_buf_size
 
3942          * used to create the sg_dma_buf_pool must be dynamically calculated.
 
3943          * 2 segments are added since the IOCB needs a command and response bde.
 
3945         phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
 
3946                         sizeof(struct fcp_rsp) +
 
3947                         ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
 
3948         lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
 
3953  * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
 
3954  * @vport: lpfc_vport pointer.
 
3957 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
 
3959         lpfc_log_verbose_init(vport, lpfc_log_verbose);
 
3960         lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
 
3961         lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
 
3962         lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
 
3963         lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
 
3964         lpfc_restrict_login_init(vport, lpfc_restrict_login);
 
3965         lpfc_fcp_class_init(vport, lpfc_fcp_class);
 
3966         lpfc_use_adisc_init(vport, lpfc_use_adisc);
 
3967         lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
 
3968         lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
 
3969         lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
 
3970         lpfc_max_luns_init(vport, lpfc_max_luns);
 
3971         lpfc_scan_down_init(vport, lpfc_scan_down);
 
3972         lpfc_enable_da_id_init(vport, lpfc_enable_da_id);