|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* | 
|  | 2 | * This file is part of the Emulex Linux Device Driver for         * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters.                                * | 
| James Smart | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 Emulex.  All rights reserved.           * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex.                        * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com                                                  * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig              * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | *                                                                 * | 
|  | 9 | * This program is free software; you can redistribute it and/or   * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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.                                     * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ | 
|  | 21 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/ctype.h> | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/pci.h> | 
|  | 25 | #include <linux/interrupt.h> | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 26 | #include <linux/aer.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/gfp.h> | 
| Andy Shevchenko | ecc3099 | 2010-08-10 18:01:27 -0700 | [diff] [blame] | 28 | #include <linux/kernel.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 29 |  | 
| James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 30 | #include <scsi/scsi.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | #include <scsi/scsi_device.h> | 
|  | 32 | #include <scsi/scsi_host.h> | 
|  | 33 | #include <scsi/scsi_tcq.h> | 
|  | 34 | #include <scsi/scsi_transport_fc.h> | 
| James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 35 | #include <scsi/fc/fc_fs.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 |  | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include "lpfc_hw4.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | #include "lpfc_hw.h" | 
|  | 39 | #include "lpfc_sli.h" | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 40 | #include "lpfc_sli4.h" | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 41 | #include "lpfc_nl.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_disc.h" | 
|  | 43 | #include "lpfc_scsi.h" | 
|  | 44 | #include "lpfc.h" | 
|  | 45 | #include "lpfc_logmsg.h" | 
|  | 46 | #include "lpfc_version.h" | 
|  | 47 | #include "lpfc_compat.h" | 
|  | 48 | #include "lpfc_crtn.h" | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 49 | #include "lpfc_vport.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 |  | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 51 | #define LPFC_DEF_DEVLOSS_TMO 30 | 
|  | 52 | #define LPFC_MIN_DEVLOSS_TMO 1 | 
|  | 53 | #define LPFC_MAX_DEVLOSS_TMO 255 | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 55 | #define LPFC_MAX_LINK_SPEED 8 | 
|  | 56 | #define LPFC_LINK_SPEED_BITMAP 0x00000117 | 
|  | 57 | #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8" | 
|  | 58 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 59 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 60 | * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | * @incr: integer to convert. | 
|  | 62 | * @hdw: ascii string holding converted integer plus a string terminator. | 
|  | 63 | * | 
|  | 64 | * Description: | 
|  | 65 | * JEDEC Joint Electron Device Engineering Council. | 
|  | 66 | * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii | 
|  | 67 | * character string. The string is then terminated with a NULL in byte 9. | 
|  | 68 | * Hex 0-9 becomes ascii '0' to '9'. | 
|  | 69 | * Hex a-f becomes ascii '=' to 'B' capital B. | 
|  | 70 | * | 
|  | 71 | * Notes: | 
|  | 72 | * Coded for 32 bit integers only. | 
|  | 73 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 74 | static void | 
|  | 75 | lpfc_jedec_to_ascii(int incr, char hdw[]) | 
|  | 76 | { | 
|  | 77 | int i, j; | 
|  | 78 | for (i = 0; i < 8; i++) { | 
|  | 79 | j = (incr & 0xf); | 
|  | 80 | if (j <= 9) | 
|  | 81 | hdw[7 - i] = 0x30 +  j; | 
|  | 82 | else | 
|  | 83 | hdw[7 - i] = 0x61 + j - 10; | 
|  | 84 | incr = (incr >> 4); | 
|  | 85 | } | 
|  | 86 | hdw[8] = 0; | 
|  | 87 | return; | 
|  | 88 | } | 
|  | 89 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 90 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 91 | * lpfc_drvr_version_show - Return the Emulex driver string with version number | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 92 | * @dev: class unused variable. | 
|  | 93 | * @attr: device attribute, not used. | 
|  | 94 | * @buf: on return contains the module description text. | 
|  | 95 | * | 
|  | 96 | * Returns: size of formatted string. | 
|  | 97 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 98 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 99 | lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, | 
|  | 100 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | { | 
|  | 102 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | 
|  | 103 | } | 
|  | 104 |  | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 105 | /** | 
|  | 106 | * lpfc_enable_fip_show - Return the fip mode of the HBA | 
|  | 107 | * @dev: class unused variable. | 
|  | 108 | * @attr: device attribute, not used. | 
|  | 109 | * @buf: on return contains the module description text. | 
|  | 110 | * | 
|  | 111 | * Returns: size of formatted string. | 
|  | 112 | **/ | 
|  | 113 | static ssize_t | 
|  | 114 | lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr, | 
|  | 115 | char *buf) | 
|  | 116 | { | 
|  | 117 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 118 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 119 | struct lpfc_hba   *phba = vport->phba; | 
|  | 120 |  | 
|  | 121 | if (phba->hba_flag & HBA_FIP_SUPPORT) | 
|  | 122 | return snprintf(buf, PAGE_SIZE, "1\n"); | 
|  | 123 | else | 
|  | 124 | return snprintf(buf, PAGE_SIZE, "0\n"); | 
|  | 125 | } | 
|  | 126 |  | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 127 | static ssize_t | 
|  | 128 | lpfc_bg_info_show(struct device *dev, struct device_attribute *attr, | 
|  | 129 | char *buf) | 
|  | 130 | { | 
|  | 131 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 132 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 133 | struct lpfc_hba   *phba = vport->phba; | 
|  | 134 |  | 
|  | 135 | if (phba->cfg_enable_bg) | 
|  | 136 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | 
|  | 137 | return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n"); | 
|  | 138 | else | 
|  | 139 | return snprintf(buf, PAGE_SIZE, | 
|  | 140 | "BlockGuard Not Supported\n"); | 
|  | 141 | else | 
|  | 142 | return snprintf(buf, PAGE_SIZE, | 
|  | 143 | "BlockGuard Disabled\n"); | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | static ssize_t | 
|  | 147 | lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr, | 
|  | 148 | char *buf) | 
|  | 149 | { | 
|  | 150 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 151 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 152 | struct lpfc_hba   *phba = vport->phba; | 
|  | 153 |  | 
| James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 154 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 
|  | 155 | (unsigned long long)phba->bg_guard_err_cnt); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | static ssize_t | 
|  | 159 | lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr, | 
|  | 160 | char *buf) | 
|  | 161 | { | 
|  | 162 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 163 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 164 | struct lpfc_hba   *phba = vport->phba; | 
|  | 165 |  | 
| James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 166 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 
|  | 167 | (unsigned long long)phba->bg_apptag_err_cnt); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 168 | } | 
|  | 169 |  | 
|  | 170 | static ssize_t | 
|  | 171 | lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr, | 
|  | 172 | char *buf) | 
|  | 173 | { | 
|  | 174 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 175 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 176 | struct lpfc_hba   *phba = vport->phba; | 
|  | 177 |  | 
| James Smart | 87b5c32 | 2008-12-16 10:34:09 -0500 | [diff] [blame] | 178 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 
|  | 179 | (unsigned long long)phba->bg_reftag_err_cnt); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 182 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 183 | * lpfc_info_show - Return some pci info about the host in ascii | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 184 | * @dev: class converted to a Scsi_host structure. | 
|  | 185 | * @attr: device attribute, not used. | 
|  | 186 | * @buf: on return contains the formatted text from lpfc_info(). | 
|  | 187 | * | 
|  | 188 | * Returns: size of formatted string. | 
|  | 189 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 191 | lpfc_info_show(struct device *dev, struct device_attribute *attr, | 
|  | 192 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 194 | struct Scsi_Host *host = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 195 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); | 
|  | 197 | } | 
|  | 198 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 199 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 200 | * lpfc_serialnum_show - Return the hba serial number in ascii | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 201 | * @dev: class converted to a Scsi_host structure. | 
|  | 202 | * @attr: device attribute, not used. | 
|  | 203 | * @buf: on return contains the formatted text serial number. | 
|  | 204 | * | 
|  | 205 | * Returns: size of formatted string. | 
|  | 206 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 208 | lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, | 
|  | 209 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 211 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 212 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 213 | struct lpfc_hba   *phba = vport->phba; | 
|  | 214 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); | 
|  | 216 | } | 
|  | 217 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 218 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 219 | * lpfc_temp_sensor_show - Return the temperature sensor level | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 220 | * @dev: class converted to a Scsi_host structure. | 
|  | 221 | * @attr: device attribute, not used. | 
|  | 222 | * @buf: on return contains the formatted support level. | 
|  | 223 | * | 
|  | 224 | * Description: | 
|  | 225 | * Returns a number indicating the temperature sensor level currently | 
|  | 226 | * supported, zero or one in ascii. | 
|  | 227 | * | 
|  | 228 | * Returns: size of formatted string. | 
|  | 229 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 231 | lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, | 
|  | 232 | char *buf) | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 233 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 234 | struct Scsi_Host *shost = class_to_shost(dev); | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 235 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 236 | struct lpfc_hba   *phba = vport->phba; | 
|  | 237 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); | 
|  | 238 | } | 
|  | 239 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 240 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 241 | * lpfc_modeldesc_show - Return the model description of the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 242 | * @dev: class converted to a Scsi_host structure. | 
|  | 243 | * @attr: device attribute, not used. | 
|  | 244 | * @buf: on return contains the scsi vpd model description. | 
|  | 245 | * | 
|  | 246 | * Returns: size of formatted string. | 
|  | 247 | **/ | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 248 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 249 | lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, | 
|  | 250 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 252 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 253 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 254 | struct lpfc_hba   *phba = vport->phba; | 
|  | 255 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); | 
|  | 257 | } | 
|  | 258 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 259 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 260 | * lpfc_modelname_show - Return the model name of the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 261 | * @dev: class converted to a Scsi_host structure. | 
|  | 262 | * @attr: device attribute, not used. | 
|  | 263 | * @buf: on return contains the scsi vpd model name. | 
|  | 264 | * | 
|  | 265 | * Returns: size of formatted string. | 
|  | 266 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 268 | lpfc_modelname_show(struct device *dev, struct device_attribute *attr, | 
|  | 269 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 271 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 272 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 273 | struct lpfc_hba   *phba = vport->phba; | 
|  | 274 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); | 
|  | 276 | } | 
|  | 277 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 278 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 279 | * lpfc_programtype_show - Return the program type of the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 280 | * @dev: class converted to a Scsi_host structure. | 
|  | 281 | * @attr: device attribute, not used. | 
|  | 282 | * @buf: on return contains the scsi vpd program type. | 
|  | 283 | * | 
|  | 284 | * Returns: size of formatted string. | 
|  | 285 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 287 | lpfc_programtype_show(struct device *dev, struct device_attribute *attr, | 
|  | 288 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 290 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 291 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 292 | struct lpfc_hba   *phba = vport->phba; | 
|  | 293 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); | 
|  | 295 | } | 
|  | 296 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 297 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 298 | * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 299 | * @dev: class converted to a Scsi_host structure. | 
|  | 300 | * @attr: device attribute, not used. | 
|  | 301 | * @buf: on return contains the Menlo Maintenance sli flag. | 
|  | 302 | * | 
|  | 303 | * Returns: size of formatted string. | 
|  | 304 | **/ | 
|  | 305 | static ssize_t | 
|  | 306 | lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 307 | { | 
|  | 308 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 309 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | 
|  | 310 | struct lpfc_hba   *phba = vport->phba; | 
|  | 311 |  | 
|  | 312 | return snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 313 | (phba->sli.sli_flag & LPFC_MENLO_MAINT)); | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 317 | * lpfc_vportnum_show - Return the port number in ascii of the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 318 | * @dev: class converted to a Scsi_host structure. | 
|  | 319 | * @attr: device attribute, not used. | 
|  | 320 | * @buf: on return contains scsi vpd program type. | 
|  | 321 | * | 
|  | 322 | * Returns: size of formatted string. | 
|  | 323 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 325 | lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, | 
|  | 326 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 328 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 329 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 330 | struct lpfc_hba   *phba = vport->phba; | 
|  | 331 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 332 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); | 
|  | 333 | } | 
|  | 334 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 335 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 336 | * lpfc_fwrev_show - Return the firmware rev running in the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 337 | * @dev: class converted to a Scsi_host structure. | 
|  | 338 | * @attr: device attribute, not used. | 
|  | 339 | * @buf: on return contains the scsi vpd program type. | 
|  | 340 | * | 
|  | 341 | * Returns: size of formatted string. | 
|  | 342 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 343 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 344 | lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, | 
|  | 345 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 346 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 347 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 348 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 349 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 350 | char fwrev[32]; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 351 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | lpfc_decode_firmware_rev(phba, fwrev, 1); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 353 | return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 354 | } | 
|  | 355 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 356 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 357 | * lpfc_hdw_show - Return the jedec information about the hba | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 358 | * @dev: class converted to a Scsi_host structure. | 
|  | 359 | * @attr: device attribute, not used. | 
|  | 360 | * @buf: on return contains the scsi vpd program type. | 
|  | 361 | * | 
|  | 362 | * Returns: size of formatted string. | 
|  | 363 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 364 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 365 | lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 366 | { | 
|  | 367 | char hdw[9]; | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 368 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 369 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 370 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 371 | lpfc_vpd_t *vp = &phba->vpd; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 372 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); | 
|  | 374 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | 
|  | 375 | } | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 376 |  | 
|  | 377 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 378 | * lpfc_option_rom_version_show - Return the adapter ROM FCode version | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 379 | * @dev: class converted to a Scsi_host structure. | 
|  | 380 | * @attr: device attribute, not used. | 
|  | 381 | * @buf: on return contains the ROM and FCode ascii strings. | 
|  | 382 | * | 
|  | 383 | * Returns: size of formatted string. | 
|  | 384 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 386 | lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, | 
|  | 387 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 389 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 390 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 391 | struct lpfc_hba   *phba = vport->phba; | 
|  | 392 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 393 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); | 
|  | 394 | } | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 395 |  | 
|  | 396 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 397 | * lpfc_state_show - Return the link state of the port | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 398 | * @dev: class converted to a Scsi_host structure. | 
|  | 399 | * @attr: device attribute, not used. | 
|  | 400 | * @buf: on return contains text describing the state of the link. | 
|  | 401 | * | 
|  | 402 | * Notes: | 
|  | 403 | * The switch statement has no default so zero will be returned. | 
|  | 404 | * | 
|  | 405 | * Returns: size of formatted string. | 
|  | 406 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | static ssize_t | 
| Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 408 | lpfc_link_state_show(struct device *dev, struct device_attribute *attr, | 
|  | 409 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 411 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 413 | struct lpfc_hba   *phba = vport->phba; | 
|  | 414 | int  len = 0; | 
|  | 415 |  | 
|  | 416 | switch (phba->link_state) { | 
|  | 417 | case LPFC_LINK_UNKNOWN: | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 418 | case LPFC_WARM_START: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 419 | case LPFC_INIT_START: | 
|  | 420 | case LPFC_INIT_MBX_CMDS: | 
|  | 421 | case LPFC_LINK_DOWN: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 422 | case LPFC_HBA_ERROR: | 
| James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 423 | if (phba->hba_flag & LINK_DISABLED) | 
|  | 424 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 425 | "Link Down - User disabled\n"); | 
|  | 426 | else | 
|  | 427 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 428 | "Link Down\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 429 | break; | 
|  | 430 | case LPFC_LINK_UP: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | case LPFC_CLEAR_LA: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | case LPFC_HBA_READY: | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 433 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 |  | 
|  | 435 | switch (vport->port_state) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 436 | case LPFC_LOCAL_CFG_LINK: | 
|  | 437 | len += snprintf(buf + len, PAGE_SIZE-len, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 438 | "Configuring Link\n"); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | break; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 440 | case LPFC_FDISC: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 441 | case LPFC_FLOGI: | 
|  | 442 | case LPFC_FABRIC_CFG_LINK: | 
|  | 443 | case LPFC_NS_REG: | 
|  | 444 | case LPFC_NS_QRY: | 
|  | 445 | case LPFC_BUILD_DISC_LIST: | 
|  | 446 | case LPFC_DISC_AUTH: | 
|  | 447 | len += snprintf(buf + len, PAGE_SIZE - len, | 
|  | 448 | "Discovery\n"); | 
|  | 449 | break; | 
|  | 450 | case LPFC_VPORT_READY: | 
|  | 451 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); | 
|  | 452 | break; | 
|  | 453 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 454 | case LPFC_VPORT_FAILED: | 
|  | 455 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); | 
|  | 456 | break; | 
|  | 457 |  | 
|  | 458 | case LPFC_VPORT_UNKNOWN: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | len += snprintf(buf + len, PAGE_SIZE - len, | 
|  | 460 | "Unknown\n"); | 
|  | 461 | break; | 
|  | 462 | } | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 463 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) | 
|  | 464 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 465 | "   Menlo Maint Mode\n"); | 
|  | 466 | else if (phba->fc_topology == TOPOLOGY_LOOP) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 467 | if (vport->fc_flag & FC_PUBLIC_LOOP) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 468 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 469 | "   Public Loop\n"); | 
|  | 470 | else | 
|  | 471 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 472 | "   Private Loop\n"); | 
|  | 473 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 474 | if (vport->fc_flag & FC_FABRIC) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 475 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 476 | "   Fabric\n"); | 
|  | 477 | else | 
|  | 478 | len += snprintf(buf + len, PAGE_SIZE-len, | 
|  | 479 | "   Point-2-Point\n"); | 
|  | 480 | } | 
|  | 481 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 482 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 483 | return len; | 
|  | 484 | } | 
|  | 485 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 486 | /** | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 487 | * lpfc_link_state_store - Transition the link_state on an HBA port | 
|  | 488 | * @dev: class device that is converted into a Scsi_host. | 
|  | 489 | * @attr: device attribute, not used. | 
|  | 490 | * @buf: one or more lpfc_polling_flags values. | 
|  | 491 | * @count: not used. | 
|  | 492 | * | 
|  | 493 | * Returns: | 
|  | 494 | * -EINVAL if the buffer is not "up" or "down" | 
|  | 495 | * return from link state change function if non-zero | 
|  | 496 | * length of the buf on success | 
|  | 497 | **/ | 
|  | 498 | static ssize_t | 
|  | 499 | lpfc_link_state_store(struct device *dev, struct device_attribute *attr, | 
|  | 500 | const char *buf, size_t count) | 
|  | 501 | { | 
|  | 502 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 503 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 504 | struct lpfc_hba   *phba = vport->phba; | 
|  | 505 |  | 
|  | 506 | int status = -EINVAL; | 
|  | 507 |  | 
|  | 508 | if ((strncmp(buf, "up", sizeof("up") - 1) == 0) && | 
|  | 509 | (phba->link_state == LPFC_LINK_DOWN)) | 
| James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 510 | status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 511 | else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) && | 
|  | 512 | (phba->link_state >= LPFC_LINK_UP)) | 
| James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 513 | status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT); | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 514 |  | 
|  | 515 | if (status == 0) | 
|  | 516 | return strlen(buf); | 
|  | 517 | else | 
|  | 518 | return status; | 
|  | 519 | } | 
|  | 520 |  | 
|  | 521 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 522 | * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 523 | * @dev: class device that is converted into a Scsi_host. | 
|  | 524 | * @attr: device attribute, not used. | 
|  | 525 | * @buf: on return contains the sum of fc mapped and unmapped. | 
|  | 526 | * | 
|  | 527 | * Description: | 
|  | 528 | * Returns the ascii text number of the sum of the fc mapped and unmapped | 
|  | 529 | * vport counts. | 
|  | 530 | * | 
|  | 531 | * Returns: size of formatted string. | 
|  | 532 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 533 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 534 | lpfc_num_discovered_ports_show(struct device *dev, | 
|  | 535 | struct device_attribute *attr, char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 537 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 538 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 539 |  | 
|  | 540 | return snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 541 | vport->fc_map_cnt + vport->fc_unmap_cnt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | } | 
|  | 543 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 544 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 545 | * lpfc_issue_lip - Misnomer, name carried over from long ago | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 546 | * @shost: Scsi_Host pointer. | 
|  | 547 | * | 
|  | 548 | * Description: | 
|  | 549 | * Bring the link down gracefully then re-init the link. The firmware will | 
|  | 550 | * re-init the fiber channel interface as required. Does not issue a LIP. | 
|  | 551 | * | 
|  | 552 | * Returns: | 
|  | 553 | * -EPERM port offline or management commands are being blocked | 
|  | 554 | * -ENOMEM cannot allocate memory for the mailbox command | 
|  | 555 | * -EIO error sending the mailbox command | 
|  | 556 | * zero for success | 
|  | 557 | **/ | 
| Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 558 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 559 | lpfc_issue_lip(struct Scsi_Host *shost) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 560 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 561 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 562 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 563 | LPFC_MBOXQ_t *pmboxq; | 
|  | 564 | int mbxstatus = MBXERR_ERROR; | 
|  | 565 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 566 | if ((vport->fc_flag & FC_OFFLINE_MODE) || | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 567 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 568 | return -EPERM; | 
|  | 569 |  | 
|  | 570 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | 
|  | 571 |  | 
|  | 572 | if (!pmboxq) | 
|  | 573 | return -ENOMEM; | 
|  | 574 |  | 
|  | 575 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 576 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; | 
|  | 577 | pmboxq->u.mb.mbxOwner = OWN_HOST; | 
| James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 578 |  | 
| James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 579 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 581 | if ((mbxstatus == MBX_SUCCESS) && | 
|  | 582 | (pmboxq->u.mb.mbxStatus == 0 || | 
|  | 583 | pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) { | 
| James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 584 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | 
|  | 585 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, | 
|  | 586 | phba->cfg_link_speed); | 
|  | 587 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | 
|  | 588 | phba->fc_ratov * 2); | 
| James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 589 | if ((mbxstatus == MBX_SUCCESS) && | 
|  | 590 | (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | 
|  | 591 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | 
|  | 592 | "2859 SLI authentication is required " | 
|  | 593 | "for INIT_LINK but has not done yet\n"); | 
| James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 596 | lpfc_set_loopback_flag(phba); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 597 | if (mbxstatus != MBX_TIMEOUT) | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 598 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 |  | 
|  | 600 | if (mbxstatus == MBXERR_ERROR) | 
|  | 601 | return -EIO; | 
|  | 602 |  | 
| Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 603 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 604 | } | 
|  | 605 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 606 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 607 | * lpfc_do_offline - Issues a mailbox command to bring the link down | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 608 | * @phba: lpfc_hba pointer. | 
|  | 609 | * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. | 
|  | 610 | * | 
|  | 611 | * Notes: | 
|  | 612 | * Assumes any error from lpfc_do_offline() will be negative. | 
|  | 613 | * Can wait up to 5 seconds for the port ring buffers count | 
|  | 614 | * to reach zero, prints a warning if it is not zero and continues. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 615 | * lpfc_workq_post_event() returns a non-zero return code if call fails. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 616 | * | 
|  | 617 | * Returns: | 
|  | 618 | * -EIO error posting the event | 
|  | 619 | * zero for success | 
|  | 620 | **/ | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 621 | static int | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 622 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) | 
|  | 623 | { | 
|  | 624 | struct completion online_compl; | 
|  | 625 | struct lpfc_sli_ring *pring; | 
|  | 626 | struct lpfc_sli *psli; | 
|  | 627 | int status = 0; | 
|  | 628 | int cnt = 0; | 
|  | 629 | int i; | 
|  | 630 |  | 
|  | 631 | init_completion(&online_compl); | 
|  | 632 | lpfc_workq_post_event(phba, &status, &online_compl, | 
|  | 633 | LPFC_EVT_OFFLINE_PREP); | 
|  | 634 | wait_for_completion(&online_compl); | 
|  | 635 |  | 
|  | 636 | if (status != 0) | 
|  | 637 | return -EIO; | 
|  | 638 |  | 
|  | 639 | psli = &phba->sli; | 
|  | 640 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 641 | /* Wait a little for things to settle down, but not | 
|  | 642 | * long enough for dev loss timeout to expire. | 
|  | 643 | */ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 644 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 645 | pring = &psli->ring[i]; | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 646 | while (pring->txcmplq_cnt) { | 
|  | 647 | msleep(10); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 648 | if (cnt++ > 500) {  /* 5 secs */ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 649 | lpfc_printf_log(phba, | 
|  | 650 | KERN_WARNING, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 651 | "0466 Outstanding IO when " | 
|  | 652 | "bringing Adapter offline\n"); | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 653 | break; | 
|  | 654 | } | 
|  | 655 | } | 
|  | 656 | } | 
|  | 657 |  | 
|  | 658 | init_completion(&online_compl); | 
|  | 659 | lpfc_workq_post_event(phba, &status, &online_compl, type); | 
|  | 660 | wait_for_completion(&online_compl); | 
|  | 661 |  | 
|  | 662 | if (status != 0) | 
|  | 663 | return -EIO; | 
|  | 664 |  | 
|  | 665 | return 0; | 
|  | 666 | } | 
|  | 667 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 668 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 669 | * lpfc_selective_reset - Offline then onlines the port | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 670 | * @phba: lpfc_hba pointer. | 
|  | 671 | * | 
|  | 672 | * Description: | 
|  | 673 | * If the port is configured to allow a reset then the hba is brought | 
|  | 674 | * offline then online. | 
|  | 675 | * | 
|  | 676 | * Notes: | 
|  | 677 | * Assumes any error from lpfc_do_offline() will be negative. | 
|  | 678 | * | 
|  | 679 | * Returns: | 
|  | 680 | * lpfc_do_offline() return code if not zero | 
|  | 681 | * -EIO reset not configured or error posting the event | 
|  | 682 | * zero for success | 
|  | 683 | **/ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 684 | static int | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 685 | lpfc_selective_reset(struct lpfc_hba *phba) | 
|  | 686 | { | 
|  | 687 | struct completion online_compl; | 
|  | 688 | int status = 0; | 
|  | 689 |  | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 690 | if (!phba->cfg_enable_hba_reset) | 
|  | 691 | return -EIO; | 
|  | 692 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 693 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 694 |  | 
|  | 695 | if (status != 0) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 696 | return status; | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 697 |  | 
|  | 698 | init_completion(&online_compl); | 
|  | 699 | lpfc_workq_post_event(phba, &status, &online_compl, | 
|  | 700 | LPFC_EVT_ONLINE); | 
|  | 701 | wait_for_completion(&online_compl); | 
|  | 702 |  | 
|  | 703 | if (status != 0) | 
|  | 704 | return -EIO; | 
|  | 705 |  | 
|  | 706 | return 0; | 
|  | 707 | } | 
|  | 708 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 709 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 710 | * lpfc_issue_reset - Selectively resets an adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 711 | * @dev: class device that is converted into a Scsi_host. | 
|  | 712 | * @attr: device attribute, not used. | 
|  | 713 | * @buf: containing the string "selective". | 
|  | 714 | * @count: unused variable. | 
|  | 715 | * | 
|  | 716 | * Description: | 
|  | 717 | * If the buf contains the string "selective" then lpfc_selective_reset() | 
|  | 718 | * is called to perform the reset. | 
|  | 719 | * | 
|  | 720 | * Notes: | 
|  | 721 | * Assumes any error from lpfc_selective_reset() will be negative. | 
|  | 722 | * If lpfc_selective_reset() returns zero then the length of the buffer | 
| André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 723 | * is returned which indicates success | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 724 | * | 
|  | 725 | * Returns: | 
|  | 726 | * -EINVAL if the buffer does not contain the string "selective" | 
|  | 727 | * length of buf if lpfc-selective_reset() if the call succeeds | 
|  | 728 | * return value of lpfc_selective_reset() if the call fails | 
|  | 729 | **/ | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 730 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 731 | lpfc_issue_reset(struct device *dev, struct device_attribute *attr, | 
|  | 732 | const char *buf, size_t count) | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 733 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 734 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 736 | struct lpfc_hba   *phba = vport->phba; | 
|  | 737 |  | 
| James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 738 | int status = -EINVAL; | 
|  | 739 |  | 
|  | 740 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) | 
|  | 741 | status = lpfc_selective_reset(phba); | 
|  | 742 |  | 
|  | 743 | if (status == 0) | 
|  | 744 | return strlen(buf); | 
|  | 745 | else | 
|  | 746 | return status; | 
|  | 747 | } | 
|  | 748 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 749 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 750 | * lpfc_nport_evt_cnt_show - Return the number of nport events | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 751 | * @dev: class device that is converted into a Scsi_host. | 
|  | 752 | * @attr: device attribute, not used. | 
|  | 753 | * @buf: on return contains the ascii number of nport events. | 
|  | 754 | * | 
|  | 755 | * Returns: size of formatted string. | 
|  | 756 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 757 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 758 | lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, | 
|  | 759 | char *buf) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 760 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 761 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 762 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 763 | struct lpfc_hba   *phba = vport->phba; | 
|  | 764 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); | 
|  | 766 | } | 
|  | 767 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 768 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 769 | * lpfc_board_mode_show - Return the state of the board | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 770 | * @dev: class device that is converted into a Scsi_host. | 
|  | 771 | * @attr: device attribute, not used. | 
|  | 772 | * @buf: on return contains the state of the adapter. | 
|  | 773 | * | 
|  | 774 | * Returns: size of formatted string. | 
|  | 775 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 777 | lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, | 
|  | 778 | char *buf) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 779 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 780 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 781 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 782 | struct lpfc_hba   *phba = vport->phba; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 783 | char  * state; | 
|  | 784 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 785 | if (phba->link_state == LPFC_HBA_ERROR) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 786 | state = "error"; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 787 | else if (phba->link_state == LPFC_WARM_START) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 788 | state = "warm start"; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 789 | else if (phba->link_state == LPFC_INIT_START) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 790 | state = "offline"; | 
|  | 791 | else | 
|  | 792 | state = "online"; | 
|  | 793 |  | 
|  | 794 | return snprintf(buf, PAGE_SIZE, "%s\n", state); | 
|  | 795 | } | 
|  | 796 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 797 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 798 | * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 799 | * @dev: class device that is converted into a Scsi_host. | 
|  | 800 | * @attr: device attribute, not used. | 
|  | 801 | * @buf: containing one of the strings "online", "offline", "warm" or "error". | 
|  | 802 | * @count: unused variable. | 
|  | 803 | * | 
|  | 804 | * Returns: | 
|  | 805 | * -EACCES if enable hba reset not enabled | 
|  | 806 | * -EINVAL if the buffer does not contain a valid string (see above) | 
|  | 807 | * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails | 
|  | 808 | * buf length greater than zero indicates success | 
|  | 809 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 810 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 811 | lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, | 
|  | 812 | const char *buf, size_t count) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 813 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 814 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 815 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 816 | struct lpfc_hba   *phba = vport->phba; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 817 | struct completion online_compl; | 
|  | 818 | int status=0; | 
|  | 819 |  | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 820 | if (!phba->cfg_enable_hba_reset) | 
|  | 821 | return -EACCES; | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 822 | init_completion(&online_compl); | 
|  | 823 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 824 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 825 | lpfc_workq_post_event(phba, &status, &online_compl, | 
|  | 826 | LPFC_EVT_ONLINE); | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 827 | wait_for_completion(&online_compl); | 
|  | 828 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) | 
|  | 829 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 830 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) | 
| James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 831 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 832 | return -EINVAL; | 
|  | 833 | else | 
|  | 834 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 835 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) | 
| James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 836 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 837 | return -EINVAL; | 
|  | 838 | else | 
|  | 839 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 840 | else | 
|  | 841 | return -EINVAL; | 
|  | 842 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 843 | if (!status) | 
|  | 844 | return strlen(buf); | 
|  | 845 | else | 
|  | 846 | return -EIO; | 
|  | 847 | } | 
|  | 848 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 849 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 850 | * lpfc_get_hba_info - Return various bits of informaton about the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 851 | * @phba: pointer to the adapter structure. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 852 | * @mxri: max xri count. | 
|  | 853 | * @axri: available xri count. | 
|  | 854 | * @mrpi: max rpi count. | 
|  | 855 | * @arpi: available rpi count. | 
|  | 856 | * @mvpi: max vpi count. | 
|  | 857 | * @avpi: available vpi count. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 858 | * | 
|  | 859 | * Description: | 
|  | 860 | * If an integer pointer for an count is not null then the value for the | 
|  | 861 | * count is returned. | 
|  | 862 | * | 
|  | 863 | * Returns: | 
|  | 864 | * zero on error | 
|  | 865 | * one for success | 
|  | 866 | **/ | 
| James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 867 | static int | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 868 | lpfc_get_hba_info(struct lpfc_hba *phba, | 
|  | 869 | uint32_t *mxri, uint32_t *axri, | 
|  | 870 | uint32_t *mrpi, uint32_t *arpi, | 
|  | 871 | uint32_t *mvpi, uint32_t *avpi) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | { | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 873 | struct lpfc_mbx_read_config *rd_config; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 874 | LPFC_MBOXQ_t *pmboxq; | 
|  | 875 | MAILBOX_t *pmb; | 
|  | 876 | int rc = 0; | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 877 | uint32_t max_vpi; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 878 |  | 
|  | 879 | /* | 
|  | 880 | * prevent udev from issuing mailbox commands until the port is | 
|  | 881 | * configured. | 
|  | 882 | */ | 
|  | 883 | if (phba->link_state < LPFC_LINK_DOWN || | 
|  | 884 | !phba->mbox_mem_pool || | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 885 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 886 | return 0; | 
|  | 887 |  | 
|  | 888 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | 
|  | 889 | return 0; | 
|  | 890 |  | 
|  | 891 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 892 | if (!pmboxq) | 
|  | 893 | return 0; | 
|  | 894 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | 
|  | 895 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 896 | pmb = &pmboxq->u.mb; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 897 | pmb->mbxCommand = MBX_READ_CONFIG; | 
|  | 898 | pmb->mbxOwner = OWN_HOST; | 
|  | 899 | pmboxq->context1 = NULL; | 
|  | 900 |  | 
| James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 901 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 902 | rc = MBX_NOT_FINISHED; | 
|  | 903 | else | 
|  | 904 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | 
|  | 905 |  | 
|  | 906 | if (rc != MBX_SUCCESS) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 907 | if (rc != MBX_TIMEOUT) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 908 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 909 | return 0; | 
|  | 910 | } | 
|  | 911 |  | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 912 | if (phba->sli_rev == LPFC_SLI_REV4) { | 
|  | 913 | rd_config = &pmboxq->u.mqe.un.rd_config; | 
|  | 914 | if (mrpi) | 
|  | 915 | *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | 
|  | 916 | if (arpi) | 
|  | 917 | *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - | 
|  | 918 | phba->sli4_hba.max_cfg_param.rpi_used; | 
|  | 919 | if (mxri) | 
|  | 920 | *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | 
|  | 921 | if (axri) | 
|  | 922 | *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - | 
|  | 923 | phba->sli4_hba.max_cfg_param.xri_used; | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 924 |  | 
|  | 925 | /* Account for differences with SLI-3.  Get vpi count from | 
|  | 926 | * mailbox data and subtract one for max vpi value. | 
|  | 927 | */ | 
|  | 928 | max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? | 
|  | 929 | (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; | 
|  | 930 |  | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 931 | if (mvpi) | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 932 | *mvpi = max_vpi; | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 933 | if (avpi) | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 934 | *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 935 | } else { | 
|  | 936 | if (mrpi) | 
|  | 937 | *mrpi = pmb->un.varRdConfig.max_rpi; | 
|  | 938 | if (arpi) | 
|  | 939 | *arpi = pmb->un.varRdConfig.avail_rpi; | 
|  | 940 | if (mxri) | 
|  | 941 | *mxri = pmb->un.varRdConfig.max_xri; | 
|  | 942 | if (axri) | 
|  | 943 | *axri = pmb->un.varRdConfig.avail_xri; | 
|  | 944 | if (mvpi) | 
|  | 945 | *mvpi = pmb->un.varRdConfig.max_vpi; | 
|  | 946 | if (avpi) | 
|  | 947 | *avpi = pmb->un.varRdConfig.avail_vpi; | 
|  | 948 | } | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 949 |  | 
|  | 950 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 951 | return 1; | 
|  | 952 | } | 
|  | 953 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 954 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 955 | * lpfc_max_rpi_show - Return maximum rpi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 956 | * @dev: class device that is converted into a Scsi_host. | 
|  | 957 | * @attr: device attribute, not used. | 
|  | 958 | * @buf: on return contains the maximum rpi count in decimal or "Unknown". | 
|  | 959 | * | 
|  | 960 | * Description: | 
|  | 961 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | 
|  | 962 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 963 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 964 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 965 | * | 
|  | 966 | * Returns: size of formatted string. | 
|  | 967 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 969 | lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, | 
|  | 970 | char *buf) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 971 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 972 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 973 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 974 | struct lpfc_hba   *phba = vport->phba; | 
|  | 975 | uint32_t cnt; | 
|  | 976 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 977 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 978 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | 
|  | 979 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 980 | } | 
|  | 981 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 982 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 983 | * lpfc_used_rpi_show - Return maximum rpi minus available rpi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 984 | * @dev: class device that is converted into a Scsi_host. | 
|  | 985 | * @attr: device attribute, not used. | 
|  | 986 | * @buf: containing the used rpi count in decimal or "Unknown". | 
|  | 987 | * | 
|  | 988 | * Description: | 
|  | 989 | * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. | 
|  | 990 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 991 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 992 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 993 | * | 
|  | 994 | * Returns: size of formatted string. | 
|  | 995 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 996 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 997 | lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, | 
|  | 998 | char *buf) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 999 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1000 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1001 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1002 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1003 | uint32_t cnt, acnt; | 
|  | 1004 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1005 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1006 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | 
|  | 1007 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 1008 | } | 
|  | 1009 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1010 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1011 | * lpfc_max_xri_show - Return maximum xri | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1012 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1013 | * @attr: device attribute, not used. | 
|  | 1014 | * @buf: on return contains the maximum xri count in decimal or "Unknown". | 
|  | 1015 | * | 
|  | 1016 | * Description: | 
|  | 1017 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | 
|  | 1018 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 1019 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 1020 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 1021 | * | 
|  | 1022 | * Returns: size of formatted string. | 
|  | 1023 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1024 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1025 | lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, | 
|  | 1026 | char *buf) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1027 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1028 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1029 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1030 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1031 | uint32_t cnt; | 
|  | 1032 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1033 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1034 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | 
|  | 1035 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 1036 | } | 
|  | 1037 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1038 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1039 | * lpfc_used_xri_show - Return maximum xpi minus the available xpi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1040 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1041 | * @attr: device attribute, not used. | 
|  | 1042 | * @buf: on return contains the used xri count in decimal or "Unknown". | 
|  | 1043 | * | 
|  | 1044 | * Description: | 
|  | 1045 | * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. | 
|  | 1046 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 1047 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 1048 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 1049 | * | 
|  | 1050 | * Returns: size of formatted string. | 
|  | 1051 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1052 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1053 | lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, | 
|  | 1054 | char *buf) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1055 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1056 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1057 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1058 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1059 | uint32_t cnt, acnt; | 
|  | 1060 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1061 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) | 
|  | 1062 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | 
|  | 1063 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 1064 | } | 
|  | 1065 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1066 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1067 | * lpfc_max_vpi_show - Return maximum vpi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1068 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1069 | * @attr: device attribute, not used. | 
|  | 1070 | * @buf: on return contains the maximum vpi count in decimal or "Unknown". | 
|  | 1071 | * | 
|  | 1072 | * Description: | 
|  | 1073 | * Calls lpfc_get_hba_info() asking for just the mvpi count. | 
|  | 1074 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 1075 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 1076 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 1077 | * | 
|  | 1078 | * Returns: size of formatted string. | 
|  | 1079 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1080 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1081 | lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, | 
|  | 1082 | char *buf) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1083 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1084 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1085 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1086 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1087 | uint32_t cnt; | 
|  | 1088 |  | 
|  | 1089 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) | 
|  | 1090 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | 
|  | 1091 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 1092 | } | 
|  | 1093 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1094 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1095 | * lpfc_used_vpi_show - Return maximum vpi minus the available vpi | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1096 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1097 | * @attr: device attribute, not used. | 
|  | 1098 | * @buf: on return contains the used vpi count in decimal or "Unknown". | 
|  | 1099 | * | 
|  | 1100 | * Description: | 
|  | 1101 | * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. | 
|  | 1102 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | 
|  | 1103 | * to "Unknown" and the buffer length is returned, therefore the caller | 
|  | 1104 | * must check for "Unknown" in the buffer to detect a failure. | 
|  | 1105 | * | 
|  | 1106 | * Returns: size of formatted string. | 
|  | 1107 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1108 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1109 | lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, | 
|  | 1110 | char *buf) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1111 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1112 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1113 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1114 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1115 | uint32_t cnt, acnt; | 
|  | 1116 |  | 
|  | 1117 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1118 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | 
|  | 1119 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | 
|  | 1120 | } | 
|  | 1121 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1122 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1123 | * lpfc_npiv_info_show - Return text about NPIV support for the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1124 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1125 | * @attr: device attribute, not used. | 
|  | 1126 | * @buf: text that must be interpreted to determine if npiv is supported. | 
|  | 1127 | * | 
|  | 1128 | * Description: | 
|  | 1129 | * Buffer will contain text indicating npiv is not suppoerted on the port, | 
|  | 1130 | * the port is an NPIV physical port, or it is an npiv virtual port with | 
|  | 1131 | * the id of the vport. | 
|  | 1132 | * | 
|  | 1133 | * Returns: size of formatted string. | 
|  | 1134 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1135 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1136 | lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, | 
|  | 1137 | char *buf) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1138 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1139 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1140 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1141 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1142 |  | 
|  | 1143 | if (!(phba->max_vpi)) | 
|  | 1144 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); | 
|  | 1145 | if (vport->port_type == LPFC_PHYSICAL_PORT) | 
|  | 1146 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); | 
|  | 1147 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); | 
|  | 1148 | } | 
|  | 1149 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1150 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1151 | * lpfc_poll_show - Return text about poll support for the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1152 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1153 | * @attr: device attribute, not used. | 
|  | 1154 | * @buf: on return contains the cfg_poll in hex. | 
|  | 1155 | * | 
|  | 1156 | * Notes: | 
|  | 1157 | * cfg_poll should be a lpfc_polling_flags type. | 
|  | 1158 | * | 
|  | 1159 | * Returns: size of formatted string. | 
|  | 1160 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1161 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1162 | lpfc_poll_show(struct device *dev, struct device_attribute *attr, | 
|  | 1163 | char *buf) | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1164 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1165 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1166 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1167 | struct lpfc_hba   *phba = vport->phba; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1168 |  | 
|  | 1169 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); | 
|  | 1170 | } | 
|  | 1171 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1172 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1173 | * lpfc_poll_store - Set the value of cfg_poll for the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1174 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1175 | * @attr: device attribute, not used. | 
|  | 1176 | * @buf: one or more lpfc_polling_flags values. | 
|  | 1177 | * @count: not used. | 
|  | 1178 | * | 
|  | 1179 | * Notes: | 
|  | 1180 | * buf contents converted to integer and checked for a valid value. | 
|  | 1181 | * | 
|  | 1182 | * Returns: | 
|  | 1183 | * -EINVAL if the buffer connot be converted or is out of range | 
|  | 1184 | * length of the buf on success | 
|  | 1185 | **/ | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1186 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1187 | lpfc_poll_store(struct device *dev, struct device_attribute *attr, | 
|  | 1188 | const char *buf, size_t count) | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1189 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1190 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1191 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1192 | struct lpfc_hba   *phba = vport->phba; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1193 | uint32_t creg_val; | 
|  | 1194 | uint32_t old_val; | 
|  | 1195 | int val=0; | 
|  | 1196 |  | 
|  | 1197 | if (!isdigit(buf[0])) | 
|  | 1198 | return -EINVAL; | 
|  | 1199 |  | 
|  | 1200 | if (sscanf(buf, "%i", &val) != 1) | 
|  | 1201 | return -EINVAL; | 
|  | 1202 |  | 
|  | 1203 | if ((val & 0x3) != val) | 
|  | 1204 | return -EINVAL; | 
|  | 1205 |  | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1206 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 1207 | val = 0; | 
|  | 1208 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1209 | spin_lock_irq(&phba->hbalock); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1210 |  | 
|  | 1211 | old_val = phba->cfg_poll; | 
|  | 1212 |  | 
|  | 1213 | if (val & ENABLE_FCP_RING_POLLING) { | 
|  | 1214 | if ((val & DISABLE_FCP_RING_INT) && | 
|  | 1215 | !(old_val & DISABLE_FCP_RING_INT)) { | 
|  | 1216 | creg_val = readl(phba->HCregaddr); | 
|  | 1217 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | 
|  | 1218 | writel(creg_val, phba->HCregaddr); | 
|  | 1219 | readl(phba->HCregaddr); /* flush */ | 
|  | 1220 |  | 
|  | 1221 | lpfc_poll_start_timer(phba); | 
|  | 1222 | } | 
|  | 1223 | } else if (val != 0x0) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | spin_unlock_irq(&phba->hbalock); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1225 | return -EINVAL; | 
|  | 1226 | } | 
|  | 1227 |  | 
|  | 1228 | if (!(val & DISABLE_FCP_RING_INT) && | 
|  | 1229 | (old_val & DISABLE_FCP_RING_INT)) | 
|  | 1230 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1231 | spin_unlock_irq(&phba->hbalock); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1232 | del_timer(&phba->fcp_poll_timer); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | spin_lock_irq(&phba->hbalock); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1234 | creg_val = readl(phba->HCregaddr); | 
|  | 1235 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | 
|  | 1236 | writel(creg_val, phba->HCregaddr); | 
|  | 1237 | readl(phba->HCregaddr); /* flush */ | 
|  | 1238 | } | 
|  | 1239 |  | 
|  | 1240 | phba->cfg_poll = val; | 
|  | 1241 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1242 | spin_unlock_irq(&phba->hbalock); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1243 |  | 
|  | 1244 | return strlen(buf); | 
|  | 1245 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1246 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1247 | /** | 
| James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1248 | * lpfc_fips_level_show - Return the current FIPS level for the HBA | 
|  | 1249 | * @dev: class unused variable. | 
|  | 1250 | * @attr: device attribute, not used. | 
|  | 1251 | * @buf: on return contains the module description text. | 
|  | 1252 | * | 
|  | 1253 | * Returns: size of formatted string. | 
|  | 1254 | **/ | 
|  | 1255 | static ssize_t | 
|  | 1256 | lpfc_fips_level_show(struct device *dev,  struct device_attribute *attr, | 
|  | 1257 | char *buf) | 
|  | 1258 | { | 
|  | 1259 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 1260 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1261 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1262 |  | 
|  | 1263 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level); | 
|  | 1264 | } | 
|  | 1265 |  | 
|  | 1266 | /** | 
|  | 1267 | * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA | 
|  | 1268 | * @dev: class unused variable. | 
|  | 1269 | * @attr: device attribute, not used. | 
|  | 1270 | * @buf: on return contains the module description text. | 
|  | 1271 | * | 
|  | 1272 | * Returns: size of formatted string. | 
|  | 1273 | **/ | 
|  | 1274 | static ssize_t | 
|  | 1275 | lpfc_fips_rev_show(struct device *dev,  struct device_attribute *attr, | 
|  | 1276 | char *buf) | 
|  | 1277 | { | 
|  | 1278 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 1279 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1280 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1281 |  | 
|  | 1282 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev); | 
|  | 1283 | } | 
|  | 1284 |  | 
|  | 1285 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1286 | * lpfc_param_show - Return a cfg attribute value in decimal | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1287 | * | 
|  | 1288 | * Description: | 
|  | 1289 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1290 | * into a function with the name lpfc_hba_queue_depth_show. | 
|  | 1291 | * | 
|  | 1292 | * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. | 
|  | 1293 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1294 | * @attr: device attribute, not used. | 
|  | 1295 | * @buf: on return contains the attribute value in decimal. | 
|  | 1296 | * | 
|  | 1297 | * Returns: size of formatted string. | 
|  | 1298 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1299 | #define lpfc_param_show(attr)	\ | 
|  | 1300 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1301 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ | 
|  | 1302 | char *buf) \ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1303 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1304 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1305 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
|  | 1306 | struct lpfc_hba   *phba = vport->phba;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1307 | uint val = 0;\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1308 | val = phba->cfg_##attr;\ | 
|  | 1309 | return snprintf(buf, PAGE_SIZE, "%d\n",\ | 
|  | 1310 | phba->cfg_##attr);\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | } | 
|  | 1312 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1313 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1314 | * lpfc_param_hex_show - Return a cfg attribute value in hex | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * | 
|  | 1316 | * Description: | 
|  | 1317 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1318 | * into a function with the name lpfc_hba_queue_depth_show | 
|  | 1319 | * | 
|  | 1320 | * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. | 
|  | 1321 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1322 | * @attr: device attribute, not used. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1323 | * @buf: on return contains the attribute value in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1324 | * | 
|  | 1325 | * Returns: size of formatted string. | 
|  | 1326 | **/ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1327 | #define lpfc_param_hex_show(attr)	\ | 
|  | 1328 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1329 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ | 
|  | 1330 | char *buf) \ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1331 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1332 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
|  | 1334 | struct lpfc_hba   *phba = vport->phba;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1335 | uint val = 0;\ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1336 | val = phba->cfg_##attr;\ | 
|  | 1337 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ | 
|  | 1338 | phba->cfg_##attr);\ | 
|  | 1339 | } | 
|  | 1340 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1341 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1342 | * lpfc_param_init - Intializes a cfg attribute | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1343 | * | 
|  | 1344 | * Description: | 
|  | 1345 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1346 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | 
|  | 1347 | * takes a default argument, a minimum and maximum argument. | 
|  | 1348 | * | 
|  | 1349 | * lpfc_##attr##_init: Initializes an attribute. | 
|  | 1350 | * @phba: pointer the the adapter structure. | 
|  | 1351 | * @val: integer attribute value. | 
|  | 1352 | * | 
|  | 1353 | * Validates the min and max values then sets the adapter config field | 
|  | 1354 | * accordingly, or uses the default if out of range and prints an error message. | 
|  | 1355 | * | 
|  | 1356 | * Returns: | 
|  | 1357 | * zero on success | 
|  | 1358 | * -EINVAL if default used | 
|  | 1359 | **/ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1360 | #define lpfc_param_init(attr, default, minval, maxval)	\ | 
|  | 1361 | static int \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1362 | lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1363 | { \ | 
|  | 1364 | if (val >= minval && val <= maxval) {\ | 
|  | 1365 | phba->cfg_##attr = val;\ | 
|  | 1366 | return 0;\ | 
|  | 1367 | }\ | 
|  | 1368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1369 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ | 
|  | 1370 | "allowed range is ["#minval", "#maxval"]\n", val); \ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1371 | phba->cfg_##attr = default;\ | 
|  | 1372 | return -EINVAL;\ | 
|  | 1373 | } | 
|  | 1374 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1375 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1376 | * lpfc_param_set - Set a cfg attribute value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1377 | * | 
|  | 1378 | * Description: | 
|  | 1379 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1380 | * into a function with the name lpfc_hba_queue_depth_set | 
|  | 1381 | * | 
|  | 1382 | * lpfc_##attr##_set: Sets an attribute value. | 
|  | 1383 | * @phba: pointer the the adapter structure. | 
|  | 1384 | * @val: integer attribute value. | 
|  | 1385 | * | 
|  | 1386 | * Description: | 
|  | 1387 | * Validates the min and max values then sets the | 
|  | 1388 | * adapter config field if in the valid range. prints error message | 
|  | 1389 | * and does not set the parameter if invalid. | 
|  | 1390 | * | 
|  | 1391 | * Returns: | 
|  | 1392 | * zero on success | 
|  | 1393 | * -EINVAL if val is invalid | 
|  | 1394 | **/ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1395 | #define lpfc_param_set(attr, default, minval, maxval)	\ | 
|  | 1396 | static int \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1397 | lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1398 | { \ | 
|  | 1399 | if (val >= minval && val <= maxval) {\ | 
|  | 1400 | phba->cfg_##attr = val;\ | 
|  | 1401 | return 0;\ | 
|  | 1402 | }\ | 
|  | 1403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1404 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ | 
|  | 1405 | "allowed range is ["#minval", "#maxval"]\n", val); \ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1406 | return -EINVAL;\ | 
|  | 1407 | } | 
|  | 1408 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1409 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1410 | * lpfc_param_store - Set a vport attribute value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1411 | * | 
|  | 1412 | * Description: | 
|  | 1413 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1414 | * into a function with the name lpfc_hba_queue_depth_store. | 
|  | 1415 | * | 
|  | 1416 | * lpfc_##attr##_store: Set an sttribute value. | 
|  | 1417 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1418 | * @attr: device attribute, not used. | 
|  | 1419 | * @buf: contains the attribute value in ascii. | 
|  | 1420 | * @count: not used. | 
|  | 1421 | * | 
|  | 1422 | * Description: | 
|  | 1423 | * Convert the ascii text number to an integer, then | 
|  | 1424 | * use the lpfc_##attr##_set function to set the value. | 
|  | 1425 | * | 
|  | 1426 | * Returns: | 
|  | 1427 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | 
|  | 1428 | * length of buffer upon success. | 
|  | 1429 | **/ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1430 | #define lpfc_param_store(attr)	\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1432 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ | 
|  | 1433 | const char *buf, size_t count) \ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1435 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1436 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
|  | 1437 | struct lpfc_hba   *phba = vport->phba;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1438 | uint val = 0;\ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1439 | if (!isdigit(buf[0]))\ | 
|  | 1440 | return -EINVAL;\ | 
|  | 1441 | if (sscanf(buf, "%i", &val) != 1)\ | 
|  | 1442 | return -EINVAL;\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1443 | if (lpfc_##attr##_set(phba, val) == 0) \ | 
| James.Smart@Emulex.Com | 755c0d0 | 2005-10-28 20:29:06 -0400 | [diff] [blame] | 1444 | return strlen(buf);\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1445 | else \ | 
|  | 1446 | return -EINVAL;\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | } | 
|  | 1448 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1449 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1450 | * lpfc_vport_param_show - Return decimal formatted cfg attribute value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1451 | * | 
|  | 1452 | * Description: | 
|  | 1453 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1454 | * into a function with the name lpfc_hba_queue_depth_show | 
|  | 1455 | * | 
|  | 1456 | * lpfc_##attr##_show: prints the attribute value in decimal. | 
|  | 1457 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1458 | * @attr: device attribute, not used. | 
|  | 1459 | * @buf: on return contains the attribute value in decimal. | 
|  | 1460 | * | 
|  | 1461 | * Returns: length of formatted string. | 
|  | 1462 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1463 | #define lpfc_vport_param_show(attr)	\ | 
|  | 1464 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1465 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ | 
|  | 1466 | char *buf) \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1467 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1468 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1469 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1470 | uint val = 0;\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1471 | val = vport->cfg_##attr;\ | 
|  | 1472 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ | 
|  | 1473 | } | 
|  | 1474 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1475 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1476 | * lpfc_vport_param_hex_show - Return hex formatted attribute value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1477 | * | 
|  | 1478 | * Description: | 
|  | 1479 | * Macro that given an attr e.g. | 
|  | 1480 | * hba_queue_depth expands into a function with the name | 
|  | 1481 | * lpfc_hba_queue_depth_show | 
|  | 1482 | * | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1483 | * lpfc_##attr##_show: prints the attribute value in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1484 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1485 | * @attr: device attribute, not used. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1486 | * @buf: on return contains the attribute value in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1487 | * | 
|  | 1488 | * Returns: length of formatted string. | 
|  | 1489 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1490 | #define lpfc_vport_param_hex_show(attr)	\ | 
|  | 1491 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1492 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ | 
|  | 1493 | char *buf) \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1494 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1495 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1496 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1497 | uint val = 0;\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1498 | val = vport->cfg_##attr;\ | 
|  | 1499 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ | 
|  | 1500 | } | 
|  | 1501 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1502 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1503 | * lpfc_vport_param_init - Initialize a vport cfg attribute | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1504 | * | 
|  | 1505 | * Description: | 
|  | 1506 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1507 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | 
|  | 1508 | * takes a default argument, a minimum and maximum argument. | 
|  | 1509 | * | 
|  | 1510 | * lpfc_##attr##_init: validates the min and max values then sets the | 
|  | 1511 | * adapter config field accordingly, or uses the default if out of range | 
|  | 1512 | * and prints an error message. | 
|  | 1513 | * @phba: pointer the the adapter structure. | 
|  | 1514 | * @val: integer attribute value. | 
|  | 1515 | * | 
|  | 1516 | * Returns: | 
|  | 1517 | * zero on success | 
|  | 1518 | * -EINVAL if default used | 
|  | 1519 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1520 | #define lpfc_vport_param_init(attr, default, minval, maxval)	\ | 
|  | 1521 | static int \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1522 | lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1523 | { \ | 
|  | 1524 | if (val >= minval && val <= maxval) {\ | 
|  | 1525 | vport->cfg_##attr = val;\ | 
|  | 1526 | return 0;\ | 
|  | 1527 | }\ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1528 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1529 | "0423 lpfc_"#attr" attribute cannot be set to %d, "\ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1530 | "allowed range is ["#minval", "#maxval"]\n", val); \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1531 | vport->cfg_##attr = default;\ | 
|  | 1532 | return -EINVAL;\ | 
|  | 1533 | } | 
|  | 1534 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1535 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1536 | * lpfc_vport_param_set - Set a vport cfg attribute | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1537 | * | 
|  | 1538 | * Description: | 
|  | 1539 | * Macro that given an attr e.g. hba_queue_depth expands | 
|  | 1540 | * into a function with the name lpfc_hba_queue_depth_set | 
|  | 1541 | * | 
|  | 1542 | * lpfc_##attr##_set: validates the min and max values then sets the | 
|  | 1543 | * adapter config field if in the valid range. prints error message | 
|  | 1544 | * and does not set the parameter if invalid. | 
|  | 1545 | * @phba: pointer the the adapter structure. | 
|  | 1546 | * @val:	integer attribute value. | 
|  | 1547 | * | 
|  | 1548 | * Returns: | 
|  | 1549 | * zero on success | 
|  | 1550 | * -EINVAL if val is invalid | 
|  | 1551 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1552 | #define lpfc_vport_param_set(attr, default, minval, maxval)	\ | 
|  | 1553 | static int \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1554 | lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1555 | { \ | 
|  | 1556 | if (val >= minval && val <= maxval) {\ | 
|  | 1557 | vport->cfg_##attr = val;\ | 
|  | 1558 | return 0;\ | 
|  | 1559 | }\ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1560 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1561 | "0424 lpfc_"#attr" attribute cannot be set to %d, "\ | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1562 | "allowed range is ["#minval", "#maxval"]\n", val); \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1563 | return -EINVAL;\ | 
|  | 1564 | } | 
|  | 1565 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1566 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1567 | * lpfc_vport_param_store - Set a vport attribute | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1568 | * | 
|  | 1569 | * Description: | 
|  | 1570 | * Macro that given an attr e.g. hba_queue_depth | 
|  | 1571 | * expands into a function with the name lpfc_hba_queue_depth_store | 
|  | 1572 | * | 
|  | 1573 | * lpfc_##attr##_store: convert the ascii text number to an integer, then | 
|  | 1574 | * use the lpfc_##attr##_set function to set the value. | 
|  | 1575 | * @cdev: class device that is converted into a Scsi_host. | 
|  | 1576 | * @buf:	contains the attribute value in decimal. | 
|  | 1577 | * @count: not used. | 
|  | 1578 | * | 
|  | 1579 | * Returns: | 
|  | 1580 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | 
|  | 1581 | * length of buffer upon success. | 
|  | 1582 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1583 | #define lpfc_vport_param_store(attr)	\ | 
|  | 1584 | static ssize_t \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1585 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ | 
|  | 1586 | const char *buf, size_t count) \ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1587 | { \ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1588 | struct Scsi_Host  *shost = class_to_shost(dev);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1589 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1590 | uint val = 0;\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1591 | if (!isdigit(buf[0]))\ | 
|  | 1592 | return -EINVAL;\ | 
|  | 1593 | if (sscanf(buf, "%i", &val) != 1)\ | 
|  | 1594 | return -EINVAL;\ | 
|  | 1595 | if (lpfc_##attr##_set(vport, val) == 0) \ | 
|  | 1596 | return strlen(buf);\ | 
|  | 1597 | else \ | 
|  | 1598 | return -EINVAL;\ | 
|  | 1599 | } | 
|  | 1600 |  | 
|  | 1601 |  | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1602 | #define LPFC_ATTR(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1603 | static uint lpfc_##name = defval;\ | 
|  | 1604 | module_param(lpfc_##name, uint, 0);\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1606 | lpfc_param_init(name, defval, minval, maxval) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 |  | 
|  | 1608 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1609 | static uint lpfc_##name = defval;\ | 
|  | 1610 | module_param(lpfc_##name, uint, 0);\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1612 | lpfc_param_show(name)\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1613 | lpfc_param_init(name, defval, minval, maxval)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1614 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1615 |  | 
|  | 1616 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1617 | static uint lpfc_##name = defval;\ | 
|  | 1618 | module_param(lpfc_##name, uint, 0);\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1620 | lpfc_param_show(name)\ | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1621 | lpfc_param_init(name, defval, minval, maxval)\ | 
|  | 1622 | lpfc_param_set(name, defval, minval, maxval)\ | 
|  | 1623 | lpfc_param_store(name)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1624 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ | 
|  | 1625 | lpfc_##name##_show, lpfc_##name##_store) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 |  | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1627 | #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1628 | static uint lpfc_##name = defval;\ | 
|  | 1629 | module_param(lpfc_##name, uint, 0);\ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1630 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1631 | lpfc_param_hex_show(name)\ | 
|  | 1632 | lpfc_param_init(name, defval, minval, maxval)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1633 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1634 |  | 
|  | 1635 | #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1636 | static uint lpfc_##name = defval;\ | 
|  | 1637 | module_param(lpfc_##name, uint, 0);\ | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1638 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1639 | lpfc_param_hex_show(name)\ | 
|  | 1640 | lpfc_param_init(name, defval, minval, maxval)\ | 
|  | 1641 | lpfc_param_set(name, defval, minval, maxval)\ | 
|  | 1642 | lpfc_param_store(name)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1643 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ | 
|  | 1644 | lpfc_##name##_show, lpfc_##name##_store) | 
| James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 1645 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1646 | #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1647 | static uint lpfc_##name = defval;\ | 
|  | 1648 | module_param(lpfc_##name, uint, 0);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1649 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1650 | lpfc_vport_param_init(name, defval, minval, maxval) | 
|  | 1651 |  | 
|  | 1652 | #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1653 | static uint lpfc_##name = defval;\ | 
|  | 1654 | module_param(lpfc_##name, uint, 0);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1655 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1656 | lpfc_vport_param_show(name)\ | 
|  | 1657 | lpfc_vport_param_init(name, defval, minval, maxval)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1658 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1659 |  | 
|  | 1660 | #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1661 | static uint lpfc_##name = defval;\ | 
|  | 1662 | module_param(lpfc_##name, uint, 0);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1663 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1664 | lpfc_vport_param_show(name)\ | 
|  | 1665 | lpfc_vport_param_init(name, defval, minval, maxval)\ | 
|  | 1666 | lpfc_vport_param_set(name, defval, minval, maxval)\ | 
|  | 1667 | lpfc_vport_param_store(name)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1668 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ | 
|  | 1669 | lpfc_##name##_show, lpfc_##name##_store) | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1670 |  | 
|  | 1671 | #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1672 | static uint lpfc_##name = defval;\ | 
|  | 1673 | module_param(lpfc_##name, uint, 0);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1674 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1675 | lpfc_vport_param_hex_show(name)\ | 
|  | 1676 | lpfc_vport_param_init(name, defval, minval, maxval)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1677 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1678 |  | 
|  | 1679 | #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1680 | static uint lpfc_##name = defval;\ | 
|  | 1681 | module_param(lpfc_##name, uint, 0);\ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1682 | MODULE_PARM_DESC(lpfc_##name, desc);\ | 
|  | 1683 | lpfc_vport_param_hex_show(name)\ | 
|  | 1684 | lpfc_vport_param_init(name, defval, minval, maxval)\ | 
|  | 1685 | lpfc_vport_param_set(name, defval, minval, maxval)\ | 
|  | 1686 | lpfc_vport_param_store(name)\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1687 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ | 
|  | 1688 | lpfc_##name##_show, lpfc_##name##_store) | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1689 |  | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 1690 | static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL); | 
|  | 1691 | static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL); | 
|  | 1692 | static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL); | 
|  | 1693 | static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL); | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1694 | static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); | 
|  | 1695 | static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | 
|  | 1696 | static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | 
|  | 1697 | static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | 
|  | 1698 | static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | 
|  | 1699 | static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); | 
|  | 1700 | static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | 
|  | 1701 | static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1702 | static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show, | 
|  | 1703 | lpfc_link_state_store); | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1704 | static DEVICE_ATTR(option_rom_version, S_IRUGO, | 
|  | 1705 | lpfc_option_rom_version_show, NULL); | 
|  | 1706 | static DEVICE_ATTR(num_discovered_ports, S_IRUGO, | 
|  | 1707 | lpfc_num_discovered_ports_show, NULL); | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1708 | static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1709 | static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); | 
|  | 1710 | static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1711 | static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL); | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1712 | static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, | 
|  | 1713 | lpfc_board_mode_show, lpfc_board_mode_store); | 
|  | 1714 | static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); | 
|  | 1715 | static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); | 
|  | 1716 | static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); | 
|  | 1717 | static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); | 
|  | 1718 | static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); | 
|  | 1719 | static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); | 
|  | 1720 | static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); | 
|  | 1721 | static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); | 
|  | 1722 | static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); | 
| James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1723 | static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL); | 
|  | 1724 | static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 |  | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1726 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1727 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1728 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1729 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1730 | * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1731 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1732 | * @attr: device attribute, not used. | 
|  | 1733 | * @buf: containing the string lpfc_soft_wwn_key. | 
|  | 1734 | * @count: must be size of lpfc_soft_wwn_key. | 
|  | 1735 | * | 
|  | 1736 | * Returns: | 
|  | 1737 | * -EINVAL if the buffer does not contain lpfc_soft_wwn_key | 
|  | 1738 | * length of buf indicates success | 
|  | 1739 | **/ | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1740 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1741 | lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, | 
|  | 1742 | const char *buf, size_t count) | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1743 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1744 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1746 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1747 | unsigned int cnt = count; | 
|  | 1748 |  | 
|  | 1749 | /* | 
|  | 1750 | * We're doing a simple sanity check for soft_wwpn setting. | 
|  | 1751 | * We require that the user write a specific key to enable | 
|  | 1752 | * the soft_wwpn attribute to be settable. Once the attribute | 
|  | 1753 | * is written, the enable key resets. If further updates are | 
|  | 1754 | * desired, the key must be written again to re-enable the | 
|  | 1755 | * attribute. | 
|  | 1756 | * | 
|  | 1757 | * The "key" is not secret - it is a hardcoded string shown | 
|  | 1758 | * here. The intent is to protect against the random user or | 
|  | 1759 | * application that is just writing attributes. | 
|  | 1760 | */ | 
|  | 1761 |  | 
|  | 1762 | /* count may include a LF at end of string */ | 
|  | 1763 | if (buf[cnt-1] == '\n') | 
|  | 1764 | cnt--; | 
|  | 1765 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1766 | if ((cnt != strlen(lpfc_soft_wwn_key)) || | 
|  | 1767 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1768 | return -EINVAL; | 
|  | 1769 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1770 | phba->soft_wwn_enable = 1; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1771 | return count; | 
|  | 1772 | } | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1773 | static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, | 
|  | 1774 | lpfc_soft_wwn_enable_store); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1775 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1776 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1777 | * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1778 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1779 | * @attr: device attribute, not used. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1780 | * @buf: on return contains the wwpn in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1781 | * | 
|  | 1782 | * Returns: size of formatted string. | 
|  | 1783 | **/ | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1784 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1785 | lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, | 
|  | 1786 | char *buf) | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1787 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1788 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1789 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1790 | struct lpfc_hba   *phba = vport->phba; | 
|  | 1791 |  | 
| Randy Dunlap | afc071e | 2006-10-23 21:47:13 -0700 | [diff] [blame] | 1792 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | 
|  | 1793 | (unsigned long long)phba->cfg_soft_wwpn); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1794 | } | 
|  | 1795 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1796 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1797 | * lpfc_soft_wwpn_store - Set the ww port name of the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1798 | * @dev class device that is converted into a Scsi_host. | 
|  | 1799 | * @attr: device attribute, not used. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1800 | * @buf: contains the wwpn in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1801 | * @count: number of wwpn bytes in buf | 
|  | 1802 | * | 
|  | 1803 | * Returns: | 
|  | 1804 | * -EACCES hba reset not enabled, adapter over temp | 
|  | 1805 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid | 
|  | 1806 | * -EIO error taking adapter offline or online | 
|  | 1807 | * value of count on success | 
|  | 1808 | **/ | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1809 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1810 | lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, | 
|  | 1811 | const char *buf, size_t count) | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1812 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1813 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1814 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 1815 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1816 | struct completion online_compl; | 
|  | 1817 | int stat1=0, stat2=0; | 
|  | 1818 | unsigned int i, j, cnt=count; | 
|  | 1819 | u8 wwpn[8]; | 
|  | 1820 |  | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1821 | if (!phba->cfg_enable_hba_reset) | 
|  | 1822 | return -EACCES; | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1823 | spin_lock_irq(&phba->hbalock); | 
|  | 1824 | if (phba->over_temp_state == HBA_OVER_TEMP) { | 
|  | 1825 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1826 | return -EACCES; | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1827 | } | 
|  | 1828 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1829 | /* count may include a LF at end of string */ | 
|  | 1830 | if (buf[cnt-1] == '\n') | 
|  | 1831 | cnt--; | 
|  | 1832 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1833 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1834 | ((cnt == 17) && (*buf++ != 'x')) || | 
|  | 1835 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | 
|  | 1836 | return -EINVAL; | 
|  | 1837 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1838 | phba->soft_wwn_enable = 0; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1839 |  | 
|  | 1840 | memset(wwpn, 0, sizeof(wwpn)); | 
|  | 1841 |  | 
|  | 1842 | /* Validate and store the new name */ | 
|  | 1843 | for (i=0, j=0; i < 16; i++) { | 
| Andy Shevchenko | ecc3099 | 2010-08-10 18:01:27 -0700 | [diff] [blame] | 1844 | int value; | 
|  | 1845 |  | 
|  | 1846 | value = hex_to_bin(*buf++); | 
|  | 1847 | if (value >= 0) | 
|  | 1848 | j = (j << 4) | value; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1849 | else | 
|  | 1850 | return -EINVAL; | 
|  | 1851 | if (i % 2) { | 
|  | 1852 | wwpn[i/2] = j & 0xff; | 
|  | 1853 | j = 0; | 
|  | 1854 | } | 
|  | 1855 | } | 
|  | 1856 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1857 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1858 | if (phba->cfg_soft_wwnn) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1859 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1860 |  | 
|  | 1861 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | 
|  | 1862 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); | 
|  | 1863 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1864 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1865 | if (stat1) | 
|  | 1866 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1867 | "0463 lpfc_soft_wwpn attribute set failed to " | 
|  | 1868 | "reinit adapter - %d\n", stat1); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1869 | init_completion(&online_compl); | 
|  | 1870 | lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE); | 
|  | 1871 | wait_for_completion(&online_compl); | 
|  | 1872 | if (stat2) | 
|  | 1873 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1874 | "0464 lpfc_soft_wwpn attribute set failed to " | 
|  | 1875 | "reinit adapter - %d\n", stat2); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1876 | return (stat1 || stat2) ? -EIO : count; | 
|  | 1877 | } | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1878 | static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ | 
|  | 1879 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1880 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1882 | * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | * @dev: class device that is converted into a Scsi_host. | 
|  | 1884 | * @attr: device attribute, not used. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1885 | * @buf: on return contains the wwnn in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1886 | * | 
|  | 1887 | * Returns: size of formatted string. | 
|  | 1888 | **/ | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1889 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1890 | lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, | 
|  | 1891 | char *buf) | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1892 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1893 | struct Scsi_Host *shost = class_to_shost(dev); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1894 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1895 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | 
|  | 1896 | (unsigned long long)phba->cfg_soft_wwnn); | 
|  | 1897 | } | 
|  | 1898 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1899 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1900 | * lpfc_soft_wwnn_store - sets the ww node name of the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1901 | * @cdev: class device that is converted into a Scsi_host. | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1902 | * @buf: contains the ww node name in hexadecimal. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1903 | * @count: number of wwnn bytes in buf. | 
|  | 1904 | * | 
|  | 1905 | * Returns: | 
|  | 1906 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid | 
|  | 1907 | * value of count on success | 
|  | 1908 | **/ | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1909 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1910 | lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, | 
|  | 1911 | const char *buf, size_t count) | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1912 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1913 | struct Scsi_Host *shost = class_to_shost(dev); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1914 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1915 | unsigned int i, j, cnt=count; | 
|  | 1916 | u8 wwnn[8]; | 
|  | 1917 |  | 
|  | 1918 | /* count may include a LF at end of string */ | 
|  | 1919 | if (buf[cnt-1] == '\n') | 
|  | 1920 | cnt--; | 
|  | 1921 |  | 
|  | 1922 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || | 
|  | 1923 | ((cnt == 17) && (*buf++ != 'x')) || | 
|  | 1924 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | 
|  | 1925 | return -EINVAL; | 
|  | 1926 |  | 
|  | 1927 | /* | 
|  | 1928 | * Allow wwnn to be set many times, as long as the enable is set. | 
|  | 1929 | * However, once the wwpn is set, everything locks. | 
|  | 1930 | */ | 
|  | 1931 |  | 
|  | 1932 | memset(wwnn, 0, sizeof(wwnn)); | 
|  | 1933 |  | 
|  | 1934 | /* Validate and store the new name */ | 
|  | 1935 | for (i=0, j=0; i < 16; i++) { | 
| Andy Shevchenko | ecc3099 | 2010-08-10 18:01:27 -0700 | [diff] [blame] | 1936 | int value; | 
|  | 1937 |  | 
|  | 1938 | value = hex_to_bin(*buf++); | 
|  | 1939 | if (value >= 0) | 
|  | 1940 | j = (j << 4) | value; | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1941 | else | 
|  | 1942 | return -EINVAL; | 
|  | 1943 | if (i % 2) { | 
|  | 1944 | wwnn[i/2] = j & 0xff; | 
|  | 1945 | j = 0; | 
|  | 1946 | } | 
|  | 1947 | } | 
|  | 1948 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); | 
|  | 1949 |  | 
|  | 1950 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | 
|  | 1951 | "lpfc%d: soft_wwnn set. Value will take effect upon " | 
|  | 1952 | "setting of the soft_wwpn\n", phba->brd_no); | 
|  | 1953 |  | 
|  | 1954 | return count; | 
|  | 1955 | } | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1956 | static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\ | 
|  | 1957 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1958 |  | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1959 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1960 | static int lpfc_poll = 0; | 
|  | 1961 | module_param(lpfc_poll, int, 0); | 
|  | 1962 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" | 
|  | 1963 | " 0 - none," | 
|  | 1964 | " 1 - poll with interrupts enabled" | 
|  | 1965 | " 3 - poll and disable FCP ring interrupts"); | 
|  | 1966 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1967 | static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, | 
|  | 1968 | lpfc_poll_show, lpfc_poll_store); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1970 | int  lpfc_sli_mode = 0; | 
|  | 1971 | module_param(lpfc_sli_mode, int, 0); | 
|  | 1972 | MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" | 
|  | 1973 | " 0 - auto (SLI-3 if supported)," | 
|  | 1974 | " 2 - select SLI-2 even on SLI-3 capable HBAs," | 
|  | 1975 | " 3 - select SLI-3"); | 
|  | 1976 |  | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 1977 | int lpfc_enable_npiv = 1; | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1978 | module_param(lpfc_enable_npiv, int, 0); | 
|  | 1979 | MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); | 
|  | 1980 | lpfc_param_show(enable_npiv); | 
| James Smart | 4b40c59 | 2010-03-15 11:25:44 -0400 | [diff] [blame] | 1981 | lpfc_param_init(enable_npiv, 1, 0, 1); | 
| James Smart | 1567231 | 2010-04-06 14:49:03 -0400 | [diff] [blame] | 1982 | static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1983 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | /* | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 1985 | # lpfc_suppress_link_up:  Bring link up at initialization | 
|  | 1986 | #            0x0  = bring link up (issue MBX_INIT_LINK) | 
|  | 1987 | #            0x1  = do NOT bring link up at initialization(MBX_INIT_LINK) | 
|  | 1988 | #            0x2  = never bring up link | 
|  | 1989 | # Default value is 0. | 
|  | 1990 | */ | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 1991 | LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK, | 
|  | 1992 | LPFC_DELAY_INIT_LINK_INDEFINITELY, | 
|  | 1993 | "Suppress Link Up at initialization"); | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1994 | /* | 
|  | 1995 | # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS | 
|  | 1996 | #       1 - (1024) | 
|  | 1997 | #       2 - (2048) | 
|  | 1998 | #       3 - (3072) | 
|  | 1999 | #       4 - (4096) | 
|  | 2000 | #       5 - (5120) | 
|  | 2001 | */ | 
|  | 2002 | static ssize_t | 
|  | 2003 | lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 2004 | { | 
|  | 2005 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2006 | struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | 
|  | 2007 |  | 
|  | 2008 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max); | 
|  | 2009 | } | 
|  | 2010 |  | 
|  | 2011 | static DEVICE_ATTR(iocb_hw, S_IRUGO, | 
|  | 2012 | lpfc_iocb_hw_show, NULL); | 
|  | 2013 | static ssize_t | 
|  | 2014 | lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 2015 | { | 
|  | 2016 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2017 | struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | 
|  | 2018 |  | 
|  | 2019 | return snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 2020 | phba->sli.ring[LPFC_ELS_RING].txq_max); | 
|  | 2021 | } | 
|  | 2022 |  | 
|  | 2023 | static DEVICE_ATTR(txq_hw, S_IRUGO, | 
|  | 2024 | lpfc_txq_hw_show, NULL); | 
|  | 2025 | static ssize_t | 
|  | 2026 | lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr, | 
|  | 2027 | char *buf) | 
|  | 2028 | { | 
|  | 2029 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2030 | struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | 
|  | 2031 |  | 
|  | 2032 | return snprintf(buf, PAGE_SIZE, "%d\n", | 
|  | 2033 | phba->sli.ring[LPFC_ELS_RING].txcmplq_max); | 
|  | 2034 | } | 
|  | 2035 |  | 
|  | 2036 | static DEVICE_ATTR(txcmplq_hw, S_IRUGO, | 
|  | 2037 | lpfc_txcmplq_hw_show, NULL); | 
|  | 2038 |  | 
|  | 2039 | int lpfc_iocb_cnt = 2; | 
|  | 2040 | module_param(lpfc_iocb_cnt, int, 1); | 
|  | 2041 | MODULE_PARM_DESC(lpfc_iocb_cnt, | 
|  | 2042 | "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); | 
|  | 2043 | lpfc_param_show(iocb_cnt); | 
|  | 2044 | lpfc_param_init(iocb_cnt, 2, 1, 5); | 
|  | 2045 | static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO, | 
|  | 2046 | lpfc_iocb_cnt_show, NULL); | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 2047 |  | 
|  | 2048 | /* | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2049 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | 
|  | 2050 | # until the timer expires. Value range is [0,255]. Default value is 30. | 
|  | 2051 | */ | 
|  | 2052 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | 
|  | 2053 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; | 
|  | 2054 | module_param(lpfc_nodev_tmo, int, 0); | 
|  | 2055 | MODULE_PARM_DESC(lpfc_nodev_tmo, | 
|  | 2056 | "Seconds driver will hold I/O waiting " | 
|  | 2057 | "for a device to come back"); | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2058 |  | 
|  | 2059 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2060 | * lpfc_nodev_tmo_show - Return the hba dev loss timeout value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2061 | * @dev: class converted to a Scsi_host structure. | 
|  | 2062 | * @attr: device attribute, not used. | 
|  | 2063 | * @buf: on return contains the dev loss timeout in decimal. | 
|  | 2064 | * | 
|  | 2065 | * Returns: size of formatted string. | 
|  | 2066 | **/ | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2067 | static ssize_t | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2068 | lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, | 
|  | 2069 | char *buf) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2070 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2071 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2072 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
| James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 2073 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2074 | return snprintf(buf, PAGE_SIZE, "%d\n",	vport->cfg_devloss_tmo); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2075 | } | 
|  | 2076 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2077 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2078 | * lpfc_nodev_tmo_init - Set the hba nodev timeout value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2079 | * @vport: lpfc vport structure pointer. | 
|  | 2080 | * @val: contains the nodev timeout value. | 
|  | 2081 | * | 
|  | 2082 | * Description: | 
|  | 2083 | * If the devloss tmo is already set then nodev tmo is set to devloss tmo, | 
|  | 2084 | * a kernel error message is printed and zero is returned. | 
|  | 2085 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | 
|  | 2086 | * Otherwise nodev tmo is set to the default value. | 
|  | 2087 | * | 
|  | 2088 | * Returns: | 
|  | 2089 | * zero if already set or if val is in range | 
|  | 2090 | * -EINVAL val out of range | 
|  | 2091 | **/ | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2092 | static int | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2093 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2094 | { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2095 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { | 
|  | 2096 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; | 
|  | 2097 | if (val != LPFC_DEF_DEVLOSS_TMO) | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2098 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2099 | "0407 Ignoring nodev_tmo module " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2100 | "parameter because devloss_tmo is " | 
|  | 2101 | "set.\n"); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2102 | return 0; | 
|  | 2103 | } | 
|  | 2104 |  | 
|  | 2105 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2106 | vport->cfg_nodev_tmo = val; | 
|  | 2107 | vport->cfg_devloss_tmo = val; | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2108 | return 0; | 
|  | 2109 | } | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2110 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
|  | 2111 | "0400 lpfc_nodev_tmo attribute cannot be set to" | 
|  | 2112 | " %d, allowed range is [%d, %d]\n", | 
|  | 2113 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2114 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2115 | return -EINVAL; | 
|  | 2116 | } | 
|  | 2117 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2119 | * lpfc_update_rport_devloss_tmo - Update dev loss tmo value | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2120 | * @vport: lpfc vport structure pointer. | 
|  | 2121 | * | 
|  | 2122 | * Description: | 
|  | 2123 | * Update all the ndlp's dev loss tmo with the vport devloss tmo value. | 
|  | 2124 | **/ | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2125 | static void | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2126 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2127 | { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2128 | struct Scsi_Host  *shost; | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2129 | struct lpfc_nodelist  *ndlp; | 
|  | 2130 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2131 | shost = lpfc_shost_from_vport(vport); | 
|  | 2132 | spin_lock_irq(shost->host_lock); | 
|  | 2133 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2134 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2135 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; | 
|  | 2136 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2137 | } | 
|  | 2138 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2139 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2140 | * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2141 | * @vport: lpfc vport structure pointer. | 
|  | 2142 | * @val: contains the tmo value. | 
|  | 2143 | * | 
|  | 2144 | * Description: | 
|  | 2145 | * If the devloss tmo is already set or the vport dev loss tmo has changed | 
|  | 2146 | * then a kernel error message is printed and zero is returned. | 
|  | 2147 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | 
|  | 2148 | * Otherwise nodev tmo is set to the default value. | 
|  | 2149 | * | 
|  | 2150 | * Returns: | 
|  | 2151 | * zero if already set or if val is in range | 
|  | 2152 | * -EINVAL val out of range | 
|  | 2153 | **/ | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2154 | static int | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2155 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2156 | { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2157 | if (vport->dev_loss_tmo_changed || | 
|  | 2158 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2159 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
|  | 2160 | "0401 Ignoring change to nodev_tmo " | 
|  | 2161 | "because devloss_tmo is set.\n"); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2162 | return 0; | 
|  | 2163 | } | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2164 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2165 | vport->cfg_nodev_tmo = val; | 
|  | 2166 | vport->cfg_devloss_tmo = val; | 
| Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 2167 | /* | 
|  | 2168 | * For compat: set the fc_host dev loss so new rports | 
|  | 2169 | * will get the value. | 
|  | 2170 | */ | 
|  | 2171 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2172 | lpfc_update_rport_devloss_tmo(vport); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2173 | return 0; | 
|  | 2174 | } | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2175 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
|  | 2176 | "0403 lpfc_nodev_tmo attribute cannot be set to" | 
|  | 2177 | "%d, allowed range is [%d, %d]\n", | 
|  | 2178 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2179 | return -EINVAL; | 
|  | 2180 | } | 
|  | 2181 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2182 | lpfc_vport_param_store(nodev_tmo) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2183 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2184 | static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, | 
|  | 2185 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2186 |  | 
|  | 2187 | /* | 
|  | 2188 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that | 
|  | 2189 | # disappear until the timer expires. Value range is [0,255]. Default | 
|  | 2190 | # value is 30. | 
|  | 2191 | */ | 
|  | 2192 | module_param(lpfc_devloss_tmo, int, 0); | 
|  | 2193 | MODULE_PARM_DESC(lpfc_devloss_tmo, | 
|  | 2194 | "Seconds driver will hold I/O waiting " | 
|  | 2195 | "for a device to come back"); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2196 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, | 
|  | 2197 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) | 
|  | 2198 | lpfc_vport_param_show(devloss_tmo) | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2199 |  | 
|  | 2200 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2201 | * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2202 | * @vport: lpfc vport structure pointer. | 
|  | 2203 | * @val: contains the tmo value. | 
|  | 2204 | * | 
|  | 2205 | * Description: | 
|  | 2206 | * If val is in a valid range then set the vport nodev tmo, | 
|  | 2207 | * devloss tmo, also set the vport dev loss tmo changed flag. | 
|  | 2208 | * Else a kernel error message is printed. | 
|  | 2209 | * | 
|  | 2210 | * Returns: | 
|  | 2211 | * zero if val is in range | 
|  | 2212 | * -EINVAL val out of range | 
|  | 2213 | **/ | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2214 | static int | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2215 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2216 | { | 
|  | 2217 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2218 | vport->cfg_nodev_tmo = val; | 
|  | 2219 | vport->cfg_devloss_tmo = val; | 
|  | 2220 | vport->dev_loss_tmo_changed = 1; | 
| Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 2221 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2222 | lpfc_update_rport_devloss_tmo(vport); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2223 | return 0; | 
|  | 2224 | } | 
|  | 2225 |  | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2226 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
|  | 2227 | "0404 lpfc_devloss_tmo attribute cannot be set to" | 
|  | 2228 | " %d, allowed range is [%d, %d]\n", | 
|  | 2229 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2230 | return -EINVAL; | 
|  | 2231 | } | 
|  | 2232 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2233 | lpfc_vport_param_store(devloss_tmo) | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2234 | static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, | 
|  | 2235 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2236 |  | 
|  | 2237 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | 
|  | 2239 | # deluged with LOTS of information. | 
|  | 2240 | # You can set a bit mask to record specific types of verbose messages: | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2241 | # See lpfc_logmsh.h for definitions. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | */ | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2243 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2244 | "Verbose logging bit-mask"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 |  | 
|  | 2246 | /* | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2247 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters | 
|  | 2248 | # objects that have been registered with the nameserver after login. | 
|  | 2249 | */ | 
|  | 2250 | LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1, | 
|  | 2251 | "Deregister nameserver objects before LOGO"); | 
|  | 2252 |  | 
|  | 2253 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2254 | # lun_queue_depth:  This parameter is used to limit the number of outstanding | 
|  | 2255 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. | 
|  | 2256 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2257 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128, | 
|  | 2258 | "Max number of FCP commands we can queue to a specific LUN"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 |  | 
|  | 2260 | /* | 
| James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 2261 | # tgt_queue_depth:  This parameter is used to limit the number of outstanding | 
|  | 2262 | # commands per target port. Value range is [10,65535]. Default value is 65535. | 
|  | 2263 | */ | 
|  | 2264 | LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535, | 
|  | 2265 | "Max number of FCP commands we can queue to a specific target port"); | 
|  | 2266 |  | 
|  | 2267 | /* | 
| Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 2268 | # hba_queue_depth:  This parameter is used to limit the number of outstanding | 
|  | 2269 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter | 
|  | 2270 | # value is greater than the maximum number of exchanges supported by the HBA, | 
|  | 2271 | # then maximum number of exchanges supported by the HBA is used to determine | 
|  | 2272 | # the hba_queue_depth. | 
|  | 2273 | */ | 
|  | 2274 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, | 
|  | 2275 | "Max number of FCP commands we can queue to a lpfc HBA"); | 
|  | 2276 |  | 
|  | 2277 | /* | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2278 | # peer_port_login:  This parameter allows/prevents logins | 
|  | 2279 | # between peer ports hosted on the same physical port. | 
|  | 2280 | # When this parameter is set 0 peer ports of same physical port | 
|  | 2281 | # are not allowed to login to each other. | 
|  | 2282 | # When this parameter is set 1 peer ports of same physical port | 
|  | 2283 | # are allowed to login to each other. | 
|  | 2284 | # Default value of this parameter is 0. | 
|  | 2285 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2286 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, | 
|  | 2287 | "Allow peer ports on the same physical port to login to each " | 
|  | 2288 | "other."); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 |  | 
|  | 2290 | /* | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2291 | # restrict_login:  This parameter allows/prevents logins | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | # between Virtual Ports and remote initiators. | 
|  | 2293 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from | 
|  | 2294 | # other initiators and will attempt to PLOGI all remote ports. | 
|  | 2295 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from | 
|  | 2296 | # remote ports and will not attempt to PLOGI to other initiators. | 
|  | 2297 | # This parameter does not restrict to the physical port. | 
|  | 2298 | # This parameter does not restrict logins to Fabric resident remote ports. | 
|  | 2299 | # Default value of this parameter is 1. | 
|  | 2300 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2301 | static int lpfc_restrict_login = 1; | 
|  | 2302 | module_param(lpfc_restrict_login, int, 0); | 
|  | 2303 | MODULE_PARM_DESC(lpfc_restrict_login, | 
|  | 2304 | "Restrict virtual ports login to remote initiators."); | 
|  | 2305 | lpfc_vport_param_show(restrict_login); | 
|  | 2306 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2307 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2308 | * lpfc_restrict_login_init - Set the vport restrict login flag | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2309 | * @vport: lpfc vport structure pointer. | 
|  | 2310 | * @val: contains the restrict login value. | 
|  | 2311 | * | 
|  | 2312 | * Description: | 
|  | 2313 | * If val is not in a valid range then log a kernel error message and set | 
|  | 2314 | * the vport restrict login to one. | 
|  | 2315 | * If the port type is physical clear the restrict login flag and return. | 
|  | 2316 | * Else set the restrict login flag to val. | 
|  | 2317 | * | 
|  | 2318 | * Returns: | 
|  | 2319 | * zero if val is in range | 
|  | 2320 | * -EINVAL val out of range | 
|  | 2321 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2322 | static int | 
|  | 2323 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) | 
|  | 2324 | { | 
|  | 2325 | if (val < 0 || val > 1) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2326 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2327 | "0422 lpfc_restrict_login attribute cannot " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2328 | "be set to %d, allowed range is [0, 1]\n", | 
|  | 2329 | val); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2330 | vport->cfg_restrict_login = 1; | 
|  | 2331 | return -EINVAL; | 
|  | 2332 | } | 
|  | 2333 | if (vport->port_type == LPFC_PHYSICAL_PORT) { | 
|  | 2334 | vport->cfg_restrict_login = 0; | 
|  | 2335 | return 0; | 
|  | 2336 | } | 
|  | 2337 | vport->cfg_restrict_login = val; | 
|  | 2338 | return 0; | 
|  | 2339 | } | 
|  | 2340 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2341 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2342 | * lpfc_restrict_login_set - Set the vport restrict login flag | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2343 | * @vport: lpfc vport structure pointer. | 
|  | 2344 | * @val: contains the restrict login value. | 
|  | 2345 | * | 
|  | 2346 | * Description: | 
|  | 2347 | * If val is not in a valid range then log a kernel error message and set | 
|  | 2348 | * the vport restrict login to one. | 
|  | 2349 | * If the port type is physical and the val is not zero log a kernel | 
|  | 2350 | * error message, clear the restrict login flag and return zero. | 
|  | 2351 | * Else set the restrict login flag to val. | 
|  | 2352 | * | 
|  | 2353 | * Returns: | 
|  | 2354 | * zero if val is in range | 
|  | 2355 | * -EINVAL val out of range | 
|  | 2356 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2357 | static int | 
|  | 2358 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) | 
|  | 2359 | { | 
|  | 2360 | if (val < 0 || val > 1) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2361 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2362 | "0425 lpfc_restrict_login attribute cannot " | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2363 | "be set to %d, allowed range is [0, 1]\n", | 
|  | 2364 | val); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2365 | vport->cfg_restrict_login = 1; | 
|  | 2366 | return -EINVAL; | 
|  | 2367 | } | 
|  | 2368 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2369 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | 
|  | 2370 | "0468 lpfc_restrict_login must be 0 for " | 
|  | 2371 | "Physical ports.\n"); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2372 | vport->cfg_restrict_login = 0; | 
|  | 2373 | return 0; | 
|  | 2374 | } | 
|  | 2375 | vport->cfg_restrict_login = val; | 
|  | 2376 | return 0; | 
|  | 2377 | } | 
|  | 2378 | lpfc_vport_param_store(restrict_login); | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2379 | static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, | 
|  | 2380 | lpfc_restrict_login_show, lpfc_restrict_login_store); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2381 |  | 
|  | 2382 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | # Some disk devices have a "select ID" or "select Target" capability. | 
|  | 2384 | # From a protocol standpoint "select ID" usually means select the | 
|  | 2385 | # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative | 
|  | 2386 | # annex" which contains a table that maps a "select ID" (a number | 
|  | 2387 | # between 0 and 7F) to an ALPA.  By default, for compatibility with | 
|  | 2388 | # older drivers, the lpfc driver scans this table from low ALPA to high | 
|  | 2389 | # ALPA. | 
|  | 2390 | # | 
|  | 2391 | # Turning on the scan-down variable (on  = 1, off = 0) will | 
|  | 2392 | # cause the lpfc driver to use an inverted table, effectively | 
|  | 2393 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | 
|  | 2394 | # | 
|  | 2395 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | 
|  | 2396 | # and will not work across a fabric. Also this parameter will take | 
|  | 2397 | # effect only in the case when ALPA map is not available.) | 
|  | 2398 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2399 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, | 
|  | 2400 | "Start scanning for devices from highest ALPA to lowest"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 |  | 
|  | 2402 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | # lpfc_topology:  link topology for init link | 
|  | 2404 | #            0x0  = attempt loop mode then point-to-point | 
| Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 2405 | #            0x01 = internal loopback mode | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | #            0x02 = attempt point-to-point mode only | 
|  | 2407 | #            0x04 = attempt loop mode only | 
|  | 2408 | #            0x06 = attempt point-to-point mode then loop | 
|  | 2409 | # Set point-to-point mode if you want to run as an N_Port. | 
|  | 2410 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | 
|  | 2411 | # Default value is 0. | 
|  | 2412 | */ | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2413 |  | 
|  | 2414 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2415 | * lpfc_topology_set - Set the adapters topology field | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2416 | * @phba: lpfc_hba pointer. | 
|  | 2417 | * @val: topology value. | 
|  | 2418 | * | 
|  | 2419 | * Description: | 
|  | 2420 | * If val is in a valid range then set the adapter's topology field and | 
|  | 2421 | * issue a lip; if the lip fails reset the topology to the old value. | 
|  | 2422 | * | 
|  | 2423 | * If the value is not in range log a kernel error message and return an error. | 
|  | 2424 | * | 
|  | 2425 | * Returns: | 
|  | 2426 | * zero if val is in range and lip okay | 
|  | 2427 | * non-zero return value from lpfc_issue_lip() | 
|  | 2428 | * -EINVAL val out of range | 
|  | 2429 | **/ | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2430 | static ssize_t | 
|  | 2431 | lpfc_topology_store(struct device *dev, struct device_attribute *attr, | 
|  | 2432 | const char *buf, size_t count) | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2433 | { | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2434 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2435 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2436 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2437 | int val = 0; | 
|  | 2438 | int nolip = 0; | 
|  | 2439 | const char *val_buf = buf; | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2440 | int err; | 
|  | 2441 | uint32_t prev_val; | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2442 |  | 
|  | 2443 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { | 
|  | 2444 | nolip = 1; | 
|  | 2445 | val_buf = &buf[strlen("nolip ")]; | 
|  | 2446 | } | 
|  | 2447 |  | 
|  | 2448 | if (!isdigit(val_buf[0])) | 
|  | 2449 | return -EINVAL; | 
|  | 2450 | if (sscanf(val_buf, "%i", &val) != 1) | 
|  | 2451 | return -EINVAL; | 
|  | 2452 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2453 | if (val >= 0 && val <= 6) { | 
|  | 2454 | prev_val = phba->cfg_topology; | 
|  | 2455 | phba->cfg_topology = val; | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2456 | if (nolip) | 
|  | 2457 | return strlen(buf); | 
|  | 2458 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2459 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2460 | if (err) { | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2461 | phba->cfg_topology = prev_val; | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2462 | return -EINVAL; | 
|  | 2463 | } else | 
|  | 2464 | return strlen(buf); | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2465 | } | 
|  | 2466 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2467 | "%d:0467 lpfc_topology attribute cannot be set to %d, " | 
|  | 2468 | "allowed range is [0, 6]\n", | 
|  | 2469 | phba->brd_no, val); | 
|  | 2470 | return -EINVAL; | 
|  | 2471 | } | 
|  | 2472 | static int lpfc_topology = 0; | 
|  | 2473 | module_param(lpfc_topology, int, 0); | 
|  | 2474 | MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology"); | 
|  | 2475 | lpfc_param_show(topology) | 
|  | 2476 | lpfc_param_init(topology, 0, 0, 6) | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2477 | static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2478 | lpfc_topology_show, lpfc_topology_store); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 |  | 
| James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 2480 | /** | 
|  | 2481 | * lpfc_static_vport_show: Read callback function for | 
|  | 2482 | *   lpfc_static_vport sysfs file. | 
|  | 2483 | * @dev: Pointer to class device object. | 
|  | 2484 | * @attr: device attribute structure. | 
|  | 2485 | * @buf: Data buffer. | 
|  | 2486 | * | 
|  | 2487 | * This function is the read call back function for | 
|  | 2488 | * lpfc_static_vport sysfs file. The lpfc_static_vport | 
|  | 2489 | * sysfs file report the mageability of the vport. | 
|  | 2490 | **/ | 
|  | 2491 | static ssize_t | 
|  | 2492 | lpfc_static_vport_show(struct device *dev, struct device_attribute *attr, | 
|  | 2493 | char *buf) | 
|  | 2494 | { | 
|  | 2495 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2496 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2497 | if (vport->vport_flag & STATIC_VPORT) | 
|  | 2498 | sprintf(buf, "1\n"); | 
|  | 2499 | else | 
|  | 2500 | sprintf(buf, "0\n"); | 
|  | 2501 |  | 
|  | 2502 | return strlen(buf); | 
|  | 2503 | } | 
|  | 2504 |  | 
|  | 2505 | /* | 
|  | 2506 | * Sysfs attribute to control the statistical data collection. | 
|  | 2507 | */ | 
|  | 2508 | static DEVICE_ATTR(lpfc_static_vport, S_IRUGO, | 
|  | 2509 | lpfc_static_vport_show, NULL); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2510 |  | 
|  | 2511 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2512 | * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2513 | * @dev: Pointer to class device. | 
|  | 2514 | * @buf: Data buffer. | 
|  | 2515 | * @count: Size of the data buffer. | 
|  | 2516 | * | 
|  | 2517 | * This function get called when an user write to the lpfc_stat_data_ctrl | 
|  | 2518 | * sysfs file. This function parse the command written to the sysfs file | 
|  | 2519 | * and take appropriate action. These commands are used for controlling | 
|  | 2520 | * driver statistical data collection. | 
|  | 2521 | * Following are the command this function handles. | 
|  | 2522 | * | 
|  | 2523 | *    setbucket <bucket_type> <base> <step> | 
|  | 2524 | *			       = Set the latency buckets. | 
|  | 2525 | *    destroybucket            = destroy all the buckets. | 
|  | 2526 | *    start                    = start data collection | 
|  | 2527 | *    stop                     = stop data collection | 
|  | 2528 | *    reset                    = reset the collected data | 
|  | 2529 | **/ | 
|  | 2530 | static ssize_t | 
|  | 2531 | lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, | 
|  | 2532 | const char *buf, size_t count) | 
|  | 2533 | { | 
|  | 2534 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2535 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2536 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2537 | #define LPFC_MAX_DATA_CTRL_LEN 1024 | 
|  | 2538 | static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; | 
|  | 2539 | unsigned long i; | 
|  | 2540 | char *str_ptr, *token; | 
|  | 2541 | struct lpfc_vport **vports; | 
|  | 2542 | struct Scsi_Host *v_shost; | 
|  | 2543 | char *bucket_type_str, *base_str, *step_str; | 
|  | 2544 | unsigned long base, step, bucket_type; | 
|  | 2545 |  | 
|  | 2546 | if (!strncmp(buf, "setbucket", strlen("setbucket"))) { | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2547 | if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1)) | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2548 | return -EINVAL; | 
|  | 2549 |  | 
|  | 2550 | strcpy(bucket_data, buf); | 
|  | 2551 | str_ptr = &bucket_data[0]; | 
|  | 2552 | /* Ignore this token - this is command token */ | 
|  | 2553 | token = strsep(&str_ptr, "\t "); | 
|  | 2554 | if (!token) | 
|  | 2555 | return -EINVAL; | 
|  | 2556 |  | 
|  | 2557 | bucket_type_str = strsep(&str_ptr, "\t "); | 
|  | 2558 | if (!bucket_type_str) | 
|  | 2559 | return -EINVAL; | 
|  | 2560 |  | 
|  | 2561 | if (!strncmp(bucket_type_str, "linear", strlen("linear"))) | 
|  | 2562 | bucket_type = LPFC_LINEAR_BUCKET; | 
|  | 2563 | else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) | 
|  | 2564 | bucket_type = LPFC_POWER2_BUCKET; | 
|  | 2565 | else | 
|  | 2566 | return -EINVAL; | 
|  | 2567 |  | 
|  | 2568 | base_str = strsep(&str_ptr, "\t "); | 
|  | 2569 | if (!base_str) | 
|  | 2570 | return -EINVAL; | 
|  | 2571 | base = simple_strtoul(base_str, NULL, 0); | 
|  | 2572 |  | 
|  | 2573 | step_str = strsep(&str_ptr, "\t "); | 
|  | 2574 | if (!step_str) | 
|  | 2575 | return -EINVAL; | 
|  | 2576 | step = simple_strtoul(step_str, NULL, 0); | 
|  | 2577 | if (!step) | 
|  | 2578 | return -EINVAL; | 
|  | 2579 |  | 
|  | 2580 | /* Block the data collection for every vport */ | 
|  | 2581 | vports = lpfc_create_vport_work_array(phba); | 
|  | 2582 | if (vports == NULL) | 
|  | 2583 | return -ENOMEM; | 
|  | 2584 |  | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2585 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2586 | v_shost = lpfc_shost_from_vport(vports[i]); | 
|  | 2587 | spin_lock_irq(v_shost->host_lock); | 
|  | 2588 | /* Block and reset data collection */ | 
|  | 2589 | vports[i]->stat_data_blocked = 1; | 
|  | 2590 | if (vports[i]->stat_data_enabled) | 
|  | 2591 | lpfc_vport_reset_stat_data(vports[i]); | 
|  | 2592 | spin_unlock_irq(v_shost->host_lock); | 
|  | 2593 | } | 
|  | 2594 |  | 
|  | 2595 | /* Set the bucket attributes */ | 
|  | 2596 | phba->bucket_type = bucket_type; | 
|  | 2597 | phba->bucket_base = base; | 
|  | 2598 | phba->bucket_step = step; | 
|  | 2599 |  | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2600 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2601 | v_shost = lpfc_shost_from_vport(vports[i]); | 
|  | 2602 |  | 
|  | 2603 | /* Unblock data collection */ | 
|  | 2604 | spin_lock_irq(v_shost->host_lock); | 
|  | 2605 | vports[i]->stat_data_blocked = 0; | 
|  | 2606 | spin_unlock_irq(v_shost->host_lock); | 
|  | 2607 | } | 
|  | 2608 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | 2609 | return strlen(buf); | 
|  | 2610 | } | 
|  | 2611 |  | 
|  | 2612 | if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { | 
|  | 2613 | vports = lpfc_create_vport_work_array(phba); | 
|  | 2614 | if (vports == NULL) | 
|  | 2615 | return -ENOMEM; | 
|  | 2616 |  | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2617 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2618 | v_shost = lpfc_shost_from_vport(vports[i]); | 
|  | 2619 | spin_lock_irq(shost->host_lock); | 
|  | 2620 | vports[i]->stat_data_blocked = 1; | 
|  | 2621 | lpfc_free_bucket(vport); | 
|  | 2622 | vport->stat_data_enabled = 0; | 
|  | 2623 | vports[i]->stat_data_blocked = 0; | 
|  | 2624 | spin_unlock_irq(shost->host_lock); | 
|  | 2625 | } | 
|  | 2626 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | 2627 | phba->bucket_type = LPFC_NO_BUCKET; | 
|  | 2628 | phba->bucket_base = 0; | 
|  | 2629 | phba->bucket_step = 0; | 
|  | 2630 | return strlen(buf); | 
|  | 2631 | } | 
|  | 2632 |  | 
|  | 2633 | if (!strncmp(buf, "start", strlen("start"))) { | 
|  | 2634 | /* If no buckets configured return error */ | 
|  | 2635 | if (phba->bucket_type == LPFC_NO_BUCKET) | 
|  | 2636 | return -EINVAL; | 
|  | 2637 | spin_lock_irq(shost->host_lock); | 
|  | 2638 | if (vport->stat_data_enabled) { | 
|  | 2639 | spin_unlock_irq(shost->host_lock); | 
|  | 2640 | return strlen(buf); | 
|  | 2641 | } | 
|  | 2642 | lpfc_alloc_bucket(vport); | 
|  | 2643 | vport->stat_data_enabled = 1; | 
|  | 2644 | spin_unlock_irq(shost->host_lock); | 
|  | 2645 | return strlen(buf); | 
|  | 2646 | } | 
|  | 2647 |  | 
|  | 2648 | if (!strncmp(buf, "stop", strlen("stop"))) { | 
|  | 2649 | spin_lock_irq(shost->host_lock); | 
|  | 2650 | if (vport->stat_data_enabled == 0) { | 
|  | 2651 | spin_unlock_irq(shost->host_lock); | 
|  | 2652 | return strlen(buf); | 
|  | 2653 | } | 
|  | 2654 | lpfc_free_bucket(vport); | 
|  | 2655 | vport->stat_data_enabled = 0; | 
|  | 2656 | spin_unlock_irq(shost->host_lock); | 
|  | 2657 | return strlen(buf); | 
|  | 2658 | } | 
|  | 2659 |  | 
|  | 2660 | if (!strncmp(buf, "reset", strlen("reset"))) { | 
|  | 2661 | if ((phba->bucket_type == LPFC_NO_BUCKET) | 
|  | 2662 | || !vport->stat_data_enabled) | 
|  | 2663 | return strlen(buf); | 
|  | 2664 | spin_lock_irq(shost->host_lock); | 
|  | 2665 | vport->stat_data_blocked = 1; | 
|  | 2666 | lpfc_vport_reset_stat_data(vport); | 
|  | 2667 | vport->stat_data_blocked = 0; | 
|  | 2668 | spin_unlock_irq(shost->host_lock); | 
|  | 2669 | return strlen(buf); | 
|  | 2670 | } | 
|  | 2671 | return -EINVAL; | 
|  | 2672 | } | 
|  | 2673 |  | 
|  | 2674 |  | 
|  | 2675 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2676 | * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2677 | * @dev: Pointer to class device object. | 
|  | 2678 | * @buf: Data buffer. | 
|  | 2679 | * | 
|  | 2680 | * This function is the read call back function for | 
|  | 2681 | * lpfc_stat_data_ctrl sysfs file. This function report the | 
|  | 2682 | * current statistical data collection state. | 
|  | 2683 | **/ | 
|  | 2684 | static ssize_t | 
|  | 2685 | lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, | 
|  | 2686 | char *buf) | 
|  | 2687 | { | 
|  | 2688 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2689 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2690 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2691 | int index = 0; | 
|  | 2692 | int i; | 
|  | 2693 | char *bucket_type; | 
|  | 2694 | unsigned long bucket_value; | 
|  | 2695 |  | 
|  | 2696 | switch (phba->bucket_type) { | 
|  | 2697 | case LPFC_LINEAR_BUCKET: | 
|  | 2698 | bucket_type = "linear"; | 
|  | 2699 | break; | 
|  | 2700 | case LPFC_POWER2_BUCKET: | 
|  | 2701 | bucket_type = "power2"; | 
|  | 2702 | break; | 
|  | 2703 | default: | 
|  | 2704 | bucket_type = "No Bucket"; | 
|  | 2705 | break; | 
|  | 2706 | } | 
|  | 2707 |  | 
|  | 2708 | sprintf(&buf[index], "Statistical Data enabled :%d, " | 
|  | 2709 | "blocked :%d, Bucket type :%s, Bucket base :%d," | 
|  | 2710 | " Bucket step :%d\nLatency Ranges :", | 
|  | 2711 | vport->stat_data_enabled, vport->stat_data_blocked, | 
|  | 2712 | bucket_type, phba->bucket_base, phba->bucket_step); | 
|  | 2713 | index = strlen(buf); | 
|  | 2714 | if (phba->bucket_type != LPFC_NO_BUCKET) { | 
|  | 2715 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | 
|  | 2716 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) | 
|  | 2717 | bucket_value = phba->bucket_base + | 
|  | 2718 | phba->bucket_step * i; | 
|  | 2719 | else | 
|  | 2720 | bucket_value = phba->bucket_base + | 
|  | 2721 | (1 << i) * phba->bucket_step; | 
|  | 2722 |  | 
|  | 2723 | if (index + 10 > PAGE_SIZE) | 
|  | 2724 | break; | 
|  | 2725 | sprintf(&buf[index], "%08ld ", bucket_value); | 
|  | 2726 | index = strlen(buf); | 
|  | 2727 | } | 
|  | 2728 | } | 
|  | 2729 | sprintf(&buf[index], "\n"); | 
|  | 2730 | return strlen(buf); | 
|  | 2731 | } | 
|  | 2732 |  | 
|  | 2733 | /* | 
|  | 2734 | * Sysfs attribute to control the statistical data collection. | 
|  | 2735 | */ | 
|  | 2736 | static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR, | 
|  | 2737 | lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store); | 
|  | 2738 |  | 
|  | 2739 | /* | 
|  | 2740 | * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. | 
|  | 2741 | */ | 
|  | 2742 |  | 
|  | 2743 | /* | 
|  | 2744 | * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN | 
|  | 2745 | * for each target. | 
|  | 2746 | */ | 
|  | 2747 | #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) | 
|  | 2748 | #define MAX_STAT_DATA_SIZE_PER_TARGET \ | 
|  | 2749 | STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) | 
|  | 2750 |  | 
|  | 2751 |  | 
|  | 2752 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2753 | * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2754 | * @filp: sysfs file | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2755 | * @kobj: Pointer to the kernel object | 
|  | 2756 | * @bin_attr: Attribute object | 
|  | 2757 | * @buff: Buffer pointer | 
|  | 2758 | * @off: File offset | 
|  | 2759 | * @count: Buffer size | 
|  | 2760 | * | 
|  | 2761 | * This function is the read call back function for lpfc_drvr_stat_data | 
|  | 2762 | * sysfs file. This function export the statistical data to user | 
|  | 2763 | * applications. | 
|  | 2764 | **/ | 
|  | 2765 | static ssize_t | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2766 | sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj, | 
|  | 2767 | struct bin_attribute *bin_attr, | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2768 | char *buf, loff_t off, size_t count) | 
|  | 2769 | { | 
|  | 2770 | struct device *dev = container_of(kobj, struct device, | 
|  | 2771 | kobj); | 
|  | 2772 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2773 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2774 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2775 | int i = 0, index = 0; | 
|  | 2776 | unsigned long nport_index; | 
|  | 2777 | struct lpfc_nodelist *ndlp = NULL; | 
|  | 2778 | nport_index = (unsigned long)off / | 
|  | 2779 | MAX_STAT_DATA_SIZE_PER_TARGET; | 
|  | 2780 |  | 
|  | 2781 | if (!vport->stat_data_enabled || vport->stat_data_blocked | 
|  | 2782 | || (phba->bucket_type == LPFC_NO_BUCKET)) | 
|  | 2783 | return 0; | 
|  | 2784 |  | 
|  | 2785 | spin_lock_irq(shost->host_lock); | 
|  | 2786 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | 
|  | 2787 | if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) | 
|  | 2788 | continue; | 
|  | 2789 |  | 
|  | 2790 | if (nport_index > 0) { | 
|  | 2791 | nport_index--; | 
|  | 2792 | continue; | 
|  | 2793 | } | 
|  | 2794 |  | 
|  | 2795 | if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) | 
|  | 2796 | > count) | 
|  | 2797 | break; | 
|  | 2798 |  | 
|  | 2799 | if (!ndlp->lat_data) | 
|  | 2800 | continue; | 
|  | 2801 |  | 
|  | 2802 | /* Print the WWN */ | 
|  | 2803 | sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", | 
|  | 2804 | ndlp->nlp_portname.u.wwn[0], | 
|  | 2805 | ndlp->nlp_portname.u.wwn[1], | 
|  | 2806 | ndlp->nlp_portname.u.wwn[2], | 
|  | 2807 | ndlp->nlp_portname.u.wwn[3], | 
|  | 2808 | ndlp->nlp_portname.u.wwn[4], | 
|  | 2809 | ndlp->nlp_portname.u.wwn[5], | 
|  | 2810 | ndlp->nlp_portname.u.wwn[6], | 
|  | 2811 | ndlp->nlp_portname.u.wwn[7]); | 
|  | 2812 |  | 
|  | 2813 | index = strlen(buf); | 
|  | 2814 |  | 
|  | 2815 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | 
|  | 2816 | sprintf(&buf[index], "%010u,", | 
|  | 2817 | ndlp->lat_data[i].cmd_count); | 
|  | 2818 | index = strlen(buf); | 
|  | 2819 | } | 
|  | 2820 | sprintf(&buf[index], "\n"); | 
|  | 2821 | index = strlen(buf); | 
|  | 2822 | } | 
|  | 2823 | spin_unlock_irq(shost->host_lock); | 
|  | 2824 | return index; | 
|  | 2825 | } | 
|  | 2826 |  | 
|  | 2827 | static struct bin_attribute sysfs_drvr_stat_data_attr = { | 
|  | 2828 | .attr = { | 
|  | 2829 | .name = "lpfc_drvr_stat_data", | 
|  | 2830 | .mode = S_IRUSR, | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2831 | }, | 
|  | 2832 | .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, | 
|  | 2833 | .read = sysfs_drvr_stat_data_read, | 
|  | 2834 | .write = NULL, | 
|  | 2835 | }; | 
|  | 2836 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2837 | /* | 
|  | 2838 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | 
|  | 2839 | # connection. | 
|  | 2840 | #       0  = auto select (default) | 
|  | 2841 | #       1  = 1 Gigabaud | 
|  | 2842 | #       2  = 2 Gigabaud | 
|  | 2843 | #       4  = 4 Gigabaud | 
| James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2844 | #       8  = 8 Gigabaud | 
|  | 2845 | # Value range is [0,8]. Default value is 0. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | */ | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2847 |  | 
|  | 2848 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2849 | * lpfc_link_speed_set - Set the adapters link speed | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2850 | * @phba: lpfc_hba pointer. | 
|  | 2851 | * @val: link speed value. | 
|  | 2852 | * | 
|  | 2853 | * Description: | 
|  | 2854 | * If val is in a valid range then set the adapter's link speed field and | 
|  | 2855 | * issue a lip; if the lip fails reset the link speed to the old value. | 
|  | 2856 | * | 
|  | 2857 | * Notes: | 
|  | 2858 | * If the value is not in range log a kernel error message and return an error. | 
|  | 2859 | * | 
|  | 2860 | * Returns: | 
|  | 2861 | * zero if val is in range and lip okay. | 
|  | 2862 | * non-zero return value from lpfc_issue_lip() | 
|  | 2863 | * -EINVAL val out of range | 
|  | 2864 | **/ | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2865 | static ssize_t | 
|  | 2866 | lpfc_link_speed_store(struct device *dev, struct device_attribute *attr, | 
|  | 2867 | const char *buf, size_t count) | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2868 | { | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2869 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 2870 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2871 | struct lpfc_hba   *phba = vport->phba; | 
|  | 2872 | int val = 0; | 
|  | 2873 | int nolip = 0; | 
|  | 2874 | const char *val_buf = buf; | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2875 | int err; | 
|  | 2876 | uint32_t prev_val; | 
|  | 2877 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2878 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { | 
|  | 2879 | nolip = 1; | 
|  | 2880 | val_buf = &buf[strlen("nolip ")]; | 
|  | 2881 | } | 
|  | 2882 |  | 
|  | 2883 | if (!isdigit(val_buf[0])) | 
|  | 2884 | return -EINVAL; | 
|  | 2885 | if (sscanf(val_buf, "%i", &val) != 1) | 
|  | 2886 | return -EINVAL; | 
|  | 2887 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2888 | if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || | 
|  | 2889 | ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || | 
|  | 2890 | ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || | 
|  | 2891 | ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || | 
|  | 2892 | ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb))) | 
|  | 2893 | return -EINVAL; | 
|  | 2894 |  | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2895 | if ((val >= 0 && val <= 8) | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2896 | && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { | 
|  | 2897 | prev_val = phba->cfg_link_speed; | 
|  | 2898 | phba->cfg_link_speed = val; | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2899 | if (nolip) | 
|  | 2900 | return strlen(buf); | 
|  | 2901 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2902 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2903 | if (err) { | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2904 | phba->cfg_link_speed = prev_val; | 
| James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2905 | return -EINVAL; | 
|  | 2906 | } else | 
|  | 2907 | return strlen(buf); | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2908 | } | 
|  | 2909 |  | 
|  | 2910 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2911 | "%d:0469 lpfc_link_speed attribute cannot be set to %d, " | 
|  | 2912 | "allowed range is [0, 8]\n", | 
|  | 2913 | phba->brd_no, val); | 
|  | 2914 | return -EINVAL; | 
|  | 2915 | } | 
|  | 2916 |  | 
|  | 2917 | static int lpfc_link_speed = 0; | 
|  | 2918 | module_param(lpfc_link_speed, int, 0); | 
|  | 2919 | MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); | 
|  | 2920 | lpfc_param_show(link_speed) | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2921 |  | 
|  | 2922 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2923 | * lpfc_link_speed_init - Set the adapters link speed | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2924 | * @phba: lpfc_hba pointer. | 
|  | 2925 | * @val: link speed value. | 
|  | 2926 | * | 
|  | 2927 | * Description: | 
|  | 2928 | * If val is in a valid range then set the adapter's link speed field. | 
|  | 2929 | * | 
|  | 2930 | * Notes: | 
|  | 2931 | * If the value is not in range log a kernel error message, clear the link | 
|  | 2932 | * speed and return an error. | 
|  | 2933 | * | 
|  | 2934 | * Returns: | 
|  | 2935 | * zero if val saved. | 
|  | 2936 | * -EINVAL val out of range | 
|  | 2937 | **/ | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2938 | static int | 
|  | 2939 | lpfc_link_speed_init(struct lpfc_hba *phba, int val) | 
|  | 2940 | { | 
|  | 2941 | if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED) | 
|  | 2942 | && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { | 
|  | 2943 | phba->cfg_link_speed = val; | 
|  | 2944 | return 0; | 
|  | 2945 | } | 
|  | 2946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2947 | "0405 lpfc_link_speed attribute cannot " | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2948 | "be set to %d, allowed values are " | 
|  | 2949 | "["LPFC_LINK_SPEED_STRING"]\n", val); | 
|  | 2950 | phba->cfg_link_speed = 0; | 
|  | 2951 | return -EINVAL; | 
|  | 2952 | } | 
|  | 2953 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2954 | static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 2955 | lpfc_link_speed_show, lpfc_link_speed_store); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 |  | 
|  | 2957 | /* | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 2958 | # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER) | 
|  | 2959 | #       0  = aer disabled or not supported | 
|  | 2960 | #       1  = aer supported and enabled (default) | 
|  | 2961 | # Value range is [0,1]. Default value is 1. | 
|  | 2962 | */ | 
|  | 2963 |  | 
|  | 2964 | /** | 
|  | 2965 | * lpfc_aer_support_store - Set the adapter for aer support | 
|  | 2966 | * | 
|  | 2967 | * @dev: class device that is converted into a Scsi_host. | 
|  | 2968 | * @attr: device attribute, not used. | 
|  | 2969 | * @buf: containing the string "selective". | 
|  | 2970 | * @count: unused variable. | 
|  | 2971 | * | 
|  | 2972 | * Description: | 
|  | 2973 | * If the val is 1 and currently the device's AER capability was not | 
|  | 2974 | * enabled, invoke the kernel's enable AER helper routine, trying to | 
|  | 2975 | * enable the device's AER capability. If the helper routine enabling | 
|  | 2976 | * AER returns success, update the device's cfg_aer_support flag to | 
|  | 2977 | * indicate AER is supported by the device; otherwise, if the device | 
|  | 2978 | * AER capability is already enabled to support AER, then do nothing. | 
|  | 2979 | * | 
|  | 2980 | * If the val is 0 and currently the device's AER support was enabled, | 
|  | 2981 | * invoke the kernel's disable AER helper routine. After that, update | 
|  | 2982 | * the device's cfg_aer_support flag to indicate AER is not supported | 
|  | 2983 | * by the device; otherwise, if the device AER capability is already | 
|  | 2984 | * disabled from supporting AER, then do nothing. | 
|  | 2985 | * | 
|  | 2986 | * Returns: | 
|  | 2987 | * length of the buf on success if val is in range the intended mode | 
|  | 2988 | * is supported. | 
|  | 2989 | * -EINVAL if val out of range or intended mode is not supported. | 
|  | 2990 | **/ | 
|  | 2991 | static ssize_t | 
|  | 2992 | lpfc_aer_support_store(struct device *dev, struct device_attribute *attr, | 
|  | 2993 | const char *buf, size_t count) | 
|  | 2994 | { | 
|  | 2995 | struct Scsi_Host *shost = class_to_shost(dev); | 
|  | 2996 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | 
|  | 2997 | struct lpfc_hba *phba = vport->phba; | 
|  | 2998 | int val = 0, rc = -EINVAL; | 
|  | 2999 |  | 
|  | 3000 | if (!isdigit(buf[0])) | 
|  | 3001 | return -EINVAL; | 
|  | 3002 | if (sscanf(buf, "%i", &val) != 1) | 
|  | 3003 | return -EINVAL; | 
|  | 3004 |  | 
|  | 3005 | switch (val) { | 
|  | 3006 | case 0: | 
|  | 3007 | if (phba->hba_flag & HBA_AER_ENABLED) { | 
|  | 3008 | rc = pci_disable_pcie_error_reporting(phba->pcidev); | 
|  | 3009 | if (!rc) { | 
|  | 3010 | spin_lock_irq(&phba->hbalock); | 
|  | 3011 | phba->hba_flag &= ~HBA_AER_ENABLED; | 
|  | 3012 | spin_unlock_irq(&phba->hbalock); | 
|  | 3013 | phba->cfg_aer_support = 0; | 
|  | 3014 | rc = strlen(buf); | 
|  | 3015 | } else | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3016 | rc = -EPERM; | 
|  | 3017 | } else { | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3018 | phba->cfg_aer_support = 0; | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3019 | rc = strlen(buf); | 
|  | 3020 | } | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3021 | break; | 
|  | 3022 | case 1: | 
|  | 3023 | if (!(phba->hba_flag & HBA_AER_ENABLED)) { | 
|  | 3024 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | 
|  | 3025 | if (!rc) { | 
|  | 3026 | spin_lock_irq(&phba->hbalock); | 
|  | 3027 | phba->hba_flag |= HBA_AER_ENABLED; | 
|  | 3028 | spin_unlock_irq(&phba->hbalock); | 
|  | 3029 | phba->cfg_aer_support = 1; | 
|  | 3030 | rc = strlen(buf); | 
|  | 3031 | } else | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3032 | rc = -EPERM; | 
|  | 3033 | } else { | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3034 | phba->cfg_aer_support = 1; | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3035 | rc = strlen(buf); | 
|  | 3036 | } | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3037 | break; | 
|  | 3038 | default: | 
|  | 3039 | rc = -EINVAL; | 
|  | 3040 | break; | 
|  | 3041 | } | 
|  | 3042 | return rc; | 
|  | 3043 | } | 
|  | 3044 |  | 
|  | 3045 | static int lpfc_aer_support = 1; | 
|  | 3046 | module_param(lpfc_aer_support, int, 1); | 
|  | 3047 | MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support"); | 
|  | 3048 | lpfc_param_show(aer_support) | 
|  | 3049 |  | 
|  | 3050 | /** | 
|  | 3051 | * lpfc_aer_support_init - Set the initial adapters aer support flag | 
|  | 3052 | * @phba: lpfc_hba pointer. | 
|  | 3053 | * @val: link speed value. | 
|  | 3054 | * | 
|  | 3055 | * Description: | 
|  | 3056 | * If val is in a valid range [0,1], then set the adapter's initial | 
|  | 3057 | * cfg_aer_support field. It will be up to the driver's probe_one | 
|  | 3058 | * routine to determine whether the device's AER support can be set | 
|  | 3059 | * or not. | 
|  | 3060 | * | 
|  | 3061 | * Notes: | 
|  | 3062 | * If the value is not in range log a kernel error message, and | 
|  | 3063 | * choose the default value of setting AER support and return. | 
|  | 3064 | * | 
|  | 3065 | * Returns: | 
|  | 3066 | * zero if val saved. | 
|  | 3067 | * -EINVAL val out of range | 
|  | 3068 | **/ | 
|  | 3069 | static int | 
|  | 3070 | lpfc_aer_support_init(struct lpfc_hba *phba, int val) | 
|  | 3071 | { | 
|  | 3072 | if (val == 0 || val == 1) { | 
|  | 3073 | phba->cfg_aer_support = val; | 
|  | 3074 | return 0; | 
|  | 3075 | } | 
|  | 3076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 3077 | "2712 lpfc_aer_support attribute value %d out " | 
|  | 3078 | "of range, allowed values are 0|1, setting it " | 
|  | 3079 | "to default value of 1\n", val); | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3080 | /* By default, try to enable AER on a device */ | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3081 | phba->cfg_aer_support = 1; | 
|  | 3082 | return -EINVAL; | 
|  | 3083 | } | 
|  | 3084 |  | 
|  | 3085 | static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR, | 
|  | 3086 | lpfc_aer_support_show, lpfc_aer_support_store); | 
|  | 3087 |  | 
|  | 3088 | /** | 
|  | 3089 | * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device | 
|  | 3090 | * @dev: class device that is converted into a Scsi_host. | 
|  | 3091 | * @attr: device attribute, not used. | 
|  | 3092 | * @buf: containing the string "selective". | 
|  | 3093 | * @count: unused variable. | 
|  | 3094 | * | 
|  | 3095 | * Description: | 
|  | 3096 | * If the @buf contains 1 and the device currently has the AER support | 
|  | 3097 | * enabled, then invokes the kernel AER helper routine | 
|  | 3098 | * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable | 
|  | 3099 | * error status register. | 
|  | 3100 | * | 
|  | 3101 | * Notes: | 
|  | 3102 | * | 
|  | 3103 | * Returns: | 
|  | 3104 | * -EINVAL if the buf does not contain the 1 or the device is not currently | 
|  | 3105 | * enabled with the AER support. | 
|  | 3106 | **/ | 
|  | 3107 | static ssize_t | 
|  | 3108 | lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr, | 
|  | 3109 | const char *buf, size_t count) | 
|  | 3110 | { | 
|  | 3111 | struct Scsi_Host  *shost = class_to_shost(dev); | 
|  | 3112 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3113 | struct lpfc_hba   *phba = vport->phba; | 
|  | 3114 | int val, rc = -1; | 
|  | 3115 |  | 
|  | 3116 | if (!isdigit(buf[0])) | 
|  | 3117 | return -EINVAL; | 
|  | 3118 | if (sscanf(buf, "%i", &val) != 1) | 
|  | 3119 | return -EINVAL; | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3120 | if (val != 1) | 
|  | 3121 | return -EINVAL; | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3122 |  | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3123 | if (phba->hba_flag & HBA_AER_ENABLED) | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3124 | rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev); | 
|  | 3125 |  | 
|  | 3126 | if (rc == 0) | 
|  | 3127 | return strlen(buf); | 
|  | 3128 | else | 
| James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 3129 | return -EPERM; | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3130 | } | 
|  | 3131 |  | 
|  | 3132 | static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL, | 
|  | 3133 | lpfc_aer_cleanup_state); | 
|  | 3134 |  | 
|  | 3135 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | # lpfc_fcp_class:  Determines FC class to use for the FCP protocol. | 
|  | 3137 | # Value range is [2,3]. Default value is 3. | 
|  | 3138 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3139 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, | 
|  | 3140 | "Select Fibre Channel class of service for FCP sequences"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 |  | 
|  | 3142 | /* | 
|  | 3143 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | 
|  | 3144 | # is [0,1]. Default value is 0. | 
|  | 3145 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3146 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, | 
|  | 3147 | "Use ADISC on rediscovery to authenticate FCP devices"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3148 |  | 
|  | 3149 | /* | 
| James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3150 | # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue | 
|  | 3151 | # depth. Default value is 0. When the value of this parameter is zero the | 
|  | 3152 | # SCSI command completion time is not used for controlling I/O queue depth. When | 
|  | 3153 | # the parameter is set to a non-zero value, the I/O queue depth is controlled | 
|  | 3154 | # to limit the I/O completion time to the parameter value. | 
|  | 3155 | # The value is set in milliseconds. | 
|  | 3156 | */ | 
|  | 3157 | static int lpfc_max_scsicmpl_time; | 
|  | 3158 | module_param(lpfc_max_scsicmpl_time, int, 0); | 
|  | 3159 | MODULE_PARM_DESC(lpfc_max_scsicmpl_time, | 
|  | 3160 | "Use command completion time to control queue depth"); | 
|  | 3161 | lpfc_vport_param_show(max_scsicmpl_time); | 
|  | 3162 | lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000); | 
|  | 3163 | static int | 
|  | 3164 | lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) | 
|  | 3165 | { | 
|  | 3166 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 3167 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
|  | 3168 |  | 
|  | 3169 | if (val == vport->cfg_max_scsicmpl_time) | 
|  | 3170 | return 0; | 
|  | 3171 | if ((val < 0) || (val > 60000)) | 
|  | 3172 | return -EINVAL; | 
|  | 3173 | vport->cfg_max_scsicmpl_time = val; | 
|  | 3174 |  | 
|  | 3175 | spin_lock_irq(shost->host_lock); | 
|  | 3176 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | 
|  | 3177 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 3178 | continue; | 
|  | 3179 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | 
|  | 3180 | continue; | 
| James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3181 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; | 
| James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3182 | } | 
|  | 3183 | spin_unlock_irq(shost->host_lock); | 
|  | 3184 | return 0; | 
|  | 3185 | } | 
|  | 3186 | lpfc_vport_param_store(max_scsicmpl_time); | 
|  | 3187 | static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR, | 
|  | 3188 | lpfc_max_scsicmpl_time_show, | 
|  | 3189 | lpfc_max_scsicmpl_time_store); | 
|  | 3190 |  | 
|  | 3191 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | 
|  | 3193 | # range is [0,1]. Default value is 0. | 
|  | 3194 | */ | 
|  | 3195 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | 
|  | 3196 |  | 
|  | 3197 | /* | 
|  | 3198 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | 
|  | 3199 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3200 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if | 
|  | 3202 | # cr_delay is set to 0. | 
|  | 3203 | */ | 
| Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 3204 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | "interrupt response is generated"); | 
|  | 3206 |  | 
| Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 3207 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3208 | "interrupt response is generated"); | 
|  | 3209 |  | 
|  | 3210 | /* | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 3211 | # lpfc_multi_ring_support:  Determines how many rings to spread available | 
|  | 3212 | # cmd/rsp IOCB entries across. | 
|  | 3213 | # Value range is [1,2]. Default value is 1. | 
|  | 3214 | */ | 
|  | 3215 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " | 
|  | 3216 | "SLI rings to spread IOCB entries across"); | 
|  | 3217 |  | 
|  | 3218 | /* | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3219 | # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this | 
|  | 3220 | # identifies what rctl value to configure the additional ring for. | 
|  | 3221 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). | 
|  | 3222 | */ | 
| James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3223 | LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1, | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3224 | 255, "Identifies RCTL for additional ring configuration"); | 
|  | 3225 |  | 
|  | 3226 | /* | 
|  | 3227 | # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this | 
|  | 3228 | # identifies what type value to configure the additional ring for. | 
|  | 3229 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). | 
|  | 3230 | */ | 
| James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3231 | LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1, | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3232 | 255, "Identifies TYPE for additional ring configuration"); | 
|  | 3233 |  | 
|  | 3234 | /* | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3235 | # lpfc_fdmi_on: controls FDMI support. | 
|  | 3236 | #       0 = no FDMI support | 
|  | 3237 | #       1 = support FDMI without attribute of hostname | 
|  | 3238 | #       2 = support FDMI with attribute of hostname | 
|  | 3239 | # Value range [0,2]. Default value is 0. | 
|  | 3240 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3241 | LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 |  | 
|  | 3243 | /* | 
|  | 3244 | # Specifies the maximum number of ELS cmds we can have outstanding (for | 
|  | 3245 | # discovery). Value range is [1,64]. Default value = 32. | 
|  | 3246 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3247 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | "during discovery"); | 
|  | 3249 |  | 
|  | 3250 | /* | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3251 | # lpfc_max_luns: maximum allowed LUN. | 
|  | 3252 | # Value range is [0,65535]. Default value is 255. | 
|  | 3253 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3254 | */ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3255 | LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3256 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3257 | /* | 
|  | 3258 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. | 
|  | 3259 | # Value range is [1,255], default value is 10. | 
|  | 3260 | */ | 
|  | 3261 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, | 
|  | 3262 | "Milliseconds driver will wait between polling FCP ring"); | 
|  | 3263 |  | 
| James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 3264 | /* | 
|  | 3265 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that | 
|  | 3266 | #		support this feature | 
| George Kadianakis | 8605c46 | 2010-01-17 21:19:31 +0200 | [diff] [blame] | 3267 | #       0  = MSI disabled | 
| James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 3268 | #       1  = MSI enabled | 
| George Kadianakis | 8605c46 | 2010-01-17 21:19:31 +0200 | [diff] [blame] | 3269 | #       2  = MSI-X enabled (default) | 
|  | 3270 | # Value range is [0,2]. Default value is 2. | 
| James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 3271 | */ | 
| George Kadianakis | 8605c46 | 2010-01-17 21:19:31 +0200 | [diff] [blame] | 3272 | LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3273 | "MSI-X (2), if possible"); | 
| James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 3274 |  | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3275 | /* | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3276 | # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second | 
|  | 3277 | # | 
|  | 3278 | # Value range is [636,651042]. Default value is 10000. | 
|  | 3279 | */ | 
|  | 3280 | LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST, | 
|  | 3281 | "Set the maximum number of fast-path FCP interrupts per second"); | 
|  | 3282 |  | 
|  | 3283 | /* | 
|  | 3284 | # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues | 
|  | 3285 | # | 
|  | 3286 | # Value range is [1,31]. Default value is 4. | 
|  | 3287 | */ | 
|  | 3288 | LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX, | 
|  | 3289 | "Set the number of fast-path FCP work queues, if possible"); | 
|  | 3290 |  | 
|  | 3291 | /* | 
|  | 3292 | # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues | 
|  | 3293 | # | 
|  | 3294 | # Value range is [1,7]. Default value is 1. | 
|  | 3295 | */ | 
|  | 3296 | LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX, | 
|  | 3297 | "Set the number of fast-path FCP event queues, if possible"); | 
|  | 3298 |  | 
|  | 3299 | /* | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3300 | # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. | 
|  | 3301 | #       0  = HBA resets disabled | 
|  | 3302 | #       1  = HBA resets enabled (default) | 
|  | 3303 | # Value range is [0,1]. Default value is 1. | 
|  | 3304 | */ | 
|  | 3305 | LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 3306 |  | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 3307 | /* | 
|  | 3308 | # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer.. | 
|  | 3309 | #       0  = HBA Heartbeat disabled | 
|  | 3310 | #       1  = HBA Heartbeat enabled (default) | 
|  | 3311 | # Value range is [0,1]. Default value is 1. | 
|  | 3312 | */ | 
|  | 3313 | LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat."); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3314 |  | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 3315 | /* | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3316 | # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF) | 
|  | 3317 | #       0  = BlockGuard disabled (default) | 
|  | 3318 | #       1  = BlockGuard enabled | 
|  | 3319 | # Value range is [0,1]. Default value is 0. | 
|  | 3320 | */ | 
|  | 3321 | LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support"); | 
|  | 3322 |  | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 3323 | /* | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3324 | # lpfc_prot_mask: i | 
|  | 3325 | #	- Bit mask of host protection capabilities used to register with the | 
|  | 3326 | #	  SCSI mid-layer | 
|  | 3327 | # 	- Only meaningful if BG is turned on (lpfc_enable_bg=1). | 
|  | 3328 | #	- Allows you to ultimately specify which profiles to use | 
|  | 3329 | #	- Default will result in registering capabilities for all profiles. | 
|  | 3330 | # | 
|  | 3331 | */ | 
| James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 3332 | unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION; | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3333 |  | 
|  | 3334 | module_param(lpfc_prot_mask, uint, 0); | 
|  | 3335 | MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask"); | 
|  | 3336 |  | 
|  | 3337 | /* | 
|  | 3338 | # lpfc_prot_guard: i | 
|  | 3339 | #	- Bit mask of protection guard types to register with the SCSI mid-layer | 
|  | 3340 | # 	- Guard types are currently either 1) IP checksum 2) T10-DIF CRC | 
|  | 3341 | #	- Allows you to ultimately specify which profiles to use | 
|  | 3342 | #	- Default will result in registering capabilities for all guard types | 
|  | 3343 | # | 
|  | 3344 | */ | 
|  | 3345 | unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP; | 
|  | 3346 | module_param(lpfc_prot_guard, byte, 0); | 
|  | 3347 | MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type"); | 
|  | 3348 |  | 
|  | 3349 |  | 
|  | 3350 | /* | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3351 | * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 3352 | * This value can be set to values between 64 and 256. The default value is | 
|  | 3353 | * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer | 
|  | 3354 | * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). | 
|  | 3355 | */ | 
|  | 3356 | LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, | 
|  | 3357 | LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); | 
|  | 3358 |  | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3359 | LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT, | 
|  | 3360 | LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT, | 
|  | 3361 | "Max Protection Scatter Gather Segment Count"); | 
|  | 3362 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3363 | struct device_attribute *lpfc_hba_attrs[] = { | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3364 | &dev_attr_bg_info, | 
|  | 3365 | &dev_attr_bg_guard_err, | 
|  | 3366 | &dev_attr_bg_apptag_err, | 
|  | 3367 | &dev_attr_bg_reftag_err, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3368 | &dev_attr_info, | 
|  | 3369 | &dev_attr_serialnum, | 
|  | 3370 | &dev_attr_modeldesc, | 
|  | 3371 | &dev_attr_modelname, | 
|  | 3372 | &dev_attr_programtype, | 
|  | 3373 | &dev_attr_portnum, | 
|  | 3374 | &dev_attr_fwrev, | 
|  | 3375 | &dev_attr_hdw, | 
|  | 3376 | &dev_attr_option_rom_version, | 
| Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 3377 | &dev_attr_link_state, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3378 | &dev_attr_num_discovered_ports, | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3379 | &dev_attr_menlo_mgmt_mode, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3380 | &dev_attr_lpfc_drvr_version, | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3381 | &dev_attr_lpfc_enable_fip, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3382 | &dev_attr_lpfc_temp_sensor, | 
|  | 3383 | &dev_attr_lpfc_log_verbose, | 
|  | 3384 | &dev_attr_lpfc_lun_queue_depth, | 
| James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3385 | &dev_attr_lpfc_tgt_queue_depth, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3386 | &dev_attr_lpfc_hba_queue_depth, | 
|  | 3387 | &dev_attr_lpfc_peer_port_login, | 
|  | 3388 | &dev_attr_lpfc_nodev_tmo, | 
|  | 3389 | &dev_attr_lpfc_devloss_tmo, | 
|  | 3390 | &dev_attr_lpfc_fcp_class, | 
|  | 3391 | &dev_attr_lpfc_use_adisc, | 
|  | 3392 | &dev_attr_lpfc_ack0, | 
|  | 3393 | &dev_attr_lpfc_topology, | 
|  | 3394 | &dev_attr_lpfc_scan_down, | 
|  | 3395 | &dev_attr_lpfc_link_speed, | 
|  | 3396 | &dev_attr_lpfc_cr_delay, | 
|  | 3397 | &dev_attr_lpfc_cr_count, | 
|  | 3398 | &dev_attr_lpfc_multi_ring_support, | 
|  | 3399 | &dev_attr_lpfc_multi_ring_rctl, | 
|  | 3400 | &dev_attr_lpfc_multi_ring_type, | 
|  | 3401 | &dev_attr_lpfc_fdmi_on, | 
|  | 3402 | &dev_attr_lpfc_max_luns, | 
|  | 3403 | &dev_attr_lpfc_enable_npiv, | 
|  | 3404 | &dev_attr_nport_evt_cnt, | 
|  | 3405 | &dev_attr_board_mode, | 
|  | 3406 | &dev_attr_max_vpi, | 
|  | 3407 | &dev_attr_used_vpi, | 
|  | 3408 | &dev_attr_max_rpi, | 
|  | 3409 | &dev_attr_used_rpi, | 
|  | 3410 | &dev_attr_max_xri, | 
|  | 3411 | &dev_attr_used_xri, | 
|  | 3412 | &dev_attr_npiv_info, | 
|  | 3413 | &dev_attr_issue_reset, | 
|  | 3414 | &dev_attr_lpfc_poll, | 
|  | 3415 | &dev_attr_lpfc_poll_tmo, | 
|  | 3416 | &dev_attr_lpfc_use_msi, | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3417 | &dev_attr_lpfc_fcp_imax, | 
|  | 3418 | &dev_attr_lpfc_fcp_wq_count, | 
|  | 3419 | &dev_attr_lpfc_fcp_eq_count, | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3420 | &dev_attr_lpfc_enable_bg, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3421 | &dev_attr_lpfc_soft_wwnn, | 
|  | 3422 | &dev_attr_lpfc_soft_wwpn, | 
|  | 3423 | &dev_attr_lpfc_soft_wwn_enable, | 
|  | 3424 | &dev_attr_lpfc_enable_hba_reset, | 
|  | 3425 | &dev_attr_lpfc_enable_hba_heartbeat, | 
|  | 3426 | &dev_attr_lpfc_sg_seg_cnt, | 
| James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 3427 | &dev_attr_lpfc_max_scsicmpl_time, | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3428 | &dev_attr_lpfc_stat_data_ctrl, | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3429 | &dev_attr_lpfc_prot_sg_seg_cnt, | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 3430 | &dev_attr_lpfc_aer_support, | 
|  | 3431 | &dev_attr_lpfc_aer_state_cleanup, | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 3432 | &dev_attr_lpfc_suppress_link_up, | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3433 | &dev_attr_lpfc_iocb_cnt, | 
|  | 3434 | &dev_attr_iocb_hw, | 
|  | 3435 | &dev_attr_txq_hw, | 
|  | 3436 | &dev_attr_txcmplq_hw, | 
| James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 3437 | &dev_attr_lpfc_fips_level, | 
|  | 3438 | &dev_attr_lpfc_fips_rev, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | NULL, | 
|  | 3440 | }; | 
|  | 3441 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3442 | struct device_attribute *lpfc_vport_attrs[] = { | 
|  | 3443 | &dev_attr_info, | 
| Hannes Reinecke | bbd1ae4 | 2008-03-18 14:32:28 +0100 | [diff] [blame] | 3444 | &dev_attr_link_state, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3445 | &dev_attr_num_discovered_ports, | 
|  | 3446 | &dev_attr_lpfc_drvr_version, | 
|  | 3447 | &dev_attr_lpfc_log_verbose, | 
|  | 3448 | &dev_attr_lpfc_lun_queue_depth, | 
| James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 3449 | &dev_attr_lpfc_tgt_queue_depth, | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3450 | &dev_attr_lpfc_nodev_tmo, | 
|  | 3451 | &dev_attr_lpfc_devloss_tmo, | 
|  | 3452 | &dev_attr_lpfc_hba_queue_depth, | 
|  | 3453 | &dev_attr_lpfc_peer_port_login, | 
|  | 3454 | &dev_attr_lpfc_restrict_login, | 
|  | 3455 | &dev_attr_lpfc_fcp_class, | 
|  | 3456 | &dev_attr_lpfc_use_adisc, | 
|  | 3457 | &dev_attr_lpfc_fdmi_on, | 
|  | 3458 | &dev_attr_lpfc_max_luns, | 
|  | 3459 | &dev_attr_nport_evt_cnt, | 
|  | 3460 | &dev_attr_npiv_info, | 
|  | 3461 | &dev_attr_lpfc_enable_da_id, | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3462 | &dev_attr_lpfc_max_scsicmpl_time, | 
|  | 3463 | &dev_attr_lpfc_stat_data_ctrl, | 
| James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 3464 | &dev_attr_lpfc_static_vport, | 
| James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 3465 | &dev_attr_lpfc_fips_level, | 
|  | 3466 | &dev_attr_lpfc_fips_rev, | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3467 | NULL, | 
|  | 3468 | }; | 
|  | 3469 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3470 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3471 | * sysfs_ctlreg_write - Write method for writing to ctlreg | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3472 | * @filp: open sysfs file | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3473 | * @kobj: kernel kobject that contains the kernel class device. | 
|  | 3474 | * @bin_attr: kernel attributes passed to us. | 
|  | 3475 | * @buf: contains the data to be written to the adapter IOREG space. | 
|  | 3476 | * @off: offset into buffer to beginning of data. | 
|  | 3477 | * @count: bytes to transfer. | 
|  | 3478 | * | 
|  | 3479 | * Description: | 
|  | 3480 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | 
|  | 3481 | * Uses the adapter io control registers to send buf contents to the adapter. | 
|  | 3482 | * | 
|  | 3483 | * Returns: | 
|  | 3484 | * -ERANGE off and count combo out of range | 
|  | 3485 | * -EINVAL off, count or buff address invalid | 
|  | 3486 | * -EPERM adapter is offline | 
|  | 3487 | * value of count, buf contents written | 
|  | 3488 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3489 | static ssize_t | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3490 | sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, | 
|  | 3491 | struct bin_attribute *bin_attr, | 
| Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 3492 | char *buf, loff_t off, size_t count) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | { | 
|  | 3494 | size_t buf_off; | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3495 | struct device *dev = container_of(kobj, struct device, kobj); | 
|  | 3496 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3498 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 |  | 
| James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3500 | if (phba->sli_rev >= LPFC_SLI_REV4) | 
|  | 3501 | return -EPERM; | 
|  | 3502 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3503 | if ((off + count) > FF_REG_AREA_SIZE) | 
|  | 3504 | return -ERANGE; | 
|  | 3505 |  | 
|  | 3506 | if (count == 0) return 0; | 
|  | 3507 |  | 
|  | 3508 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | 
|  | 3509 | return -EINVAL; | 
|  | 3510 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | return -EPERM; | 
|  | 3513 | } | 
|  | 3514 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3515 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3516 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) | 
|  | 3517 | writel(*((uint32_t *)(buf + buf_off)), | 
|  | 3518 | phba->ctrl_regs_memmap_p + off + buf_off); | 
|  | 3519 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3520 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3521 |  | 
|  | 3522 | return count; | 
|  | 3523 | } | 
|  | 3524 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3525 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3526 | * sysfs_ctlreg_read - Read method for reading from ctlreg | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3527 | * @filp: open sysfs file | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3528 | * @kobj: kernel kobject that contains the kernel class device. | 
|  | 3529 | * @bin_attr: kernel attributes passed to us. | 
| André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 3530 | * @buf: if successful contains the data from the adapter IOREG space. | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3531 | * @off: offset into buffer to beginning of data. | 
|  | 3532 | * @count: bytes to transfer. | 
|  | 3533 | * | 
|  | 3534 | * Description: | 
|  | 3535 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | 
|  | 3536 | * Uses the adapter io control registers to read data into buf. | 
|  | 3537 | * | 
|  | 3538 | * Returns: | 
|  | 3539 | * -ERANGE off and count combo out of range | 
|  | 3540 | * -EINVAL off, count or buff address invalid | 
|  | 3541 | * value of count, buf contents read | 
|  | 3542 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3543 | static ssize_t | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3544 | sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, | 
|  | 3545 | struct bin_attribute *bin_attr, | 
| Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 3546 | char *buf, loff_t off, size_t count) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | { | 
|  | 3548 | size_t buf_off; | 
|  | 3549 | uint32_t * tmp_ptr; | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3550 | struct device *dev = container_of(kobj, struct device, kobj); | 
|  | 3551 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3552 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3553 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3554 |  | 
| James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 3555 | if (phba->sli_rev >= LPFC_SLI_REV4) | 
|  | 3556 | return -EPERM; | 
|  | 3557 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3558 | if (off > FF_REG_AREA_SIZE) | 
|  | 3559 | return -ERANGE; | 
|  | 3560 |  | 
|  | 3561 | if ((off + count) > FF_REG_AREA_SIZE) | 
|  | 3562 | count = FF_REG_AREA_SIZE - off; | 
|  | 3563 |  | 
|  | 3564 | if (count == 0) return 0; | 
|  | 3565 |  | 
|  | 3566 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | 
|  | 3567 | return -EINVAL; | 
|  | 3568 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3569 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3570 |  | 
|  | 3571 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | 
|  | 3572 | tmp_ptr = (uint32_t *)(buf + buf_off); | 
|  | 3573 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | 
|  | 3574 | } | 
|  | 3575 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3576 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 |  | 
|  | 3578 | return count; | 
|  | 3579 | } | 
|  | 3580 |  | 
|  | 3581 | static struct bin_attribute sysfs_ctlreg_attr = { | 
|  | 3582 | .attr = { | 
|  | 3583 | .name = "ctlreg", | 
|  | 3584 | .mode = S_IRUSR | S_IWUSR, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | }, | 
|  | 3586 | .size = 256, | 
|  | 3587 | .read = sysfs_ctlreg_read, | 
|  | 3588 | .write = sysfs_ctlreg_write, | 
|  | 3589 | }; | 
|  | 3590 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3591 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3592 | * sysfs_mbox_idle - frees the sysfs mailbox | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3593 | * @phba: lpfc_hba pointer | 
|  | 3594 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3595 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3596 | sysfs_mbox_idle(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3597 | { | 
|  | 3598 | phba->sysfs_mbox.state = SMBOX_IDLE; | 
|  | 3599 | phba->sysfs_mbox.offset = 0; | 
|  | 3600 |  | 
|  | 3601 | if (phba->sysfs_mbox.mbox) { | 
|  | 3602 | mempool_free(phba->sysfs_mbox.mbox, | 
|  | 3603 | phba->mbox_mem_pool); | 
|  | 3604 | phba->sysfs_mbox.mbox = NULL; | 
|  | 3605 | } | 
|  | 3606 | } | 
|  | 3607 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3608 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3609 | * sysfs_mbox_write - Write method for writing information via mbox | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3610 | * @filp: open sysfs file | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3611 | * @kobj: kernel kobject that contains the kernel class device. | 
|  | 3612 | * @bin_attr: kernel attributes passed to us. | 
|  | 3613 | * @buf: contains the data to be written to sysfs mbox. | 
|  | 3614 | * @off: offset into buffer to beginning of data. | 
|  | 3615 | * @count: bytes to transfer. | 
|  | 3616 | * | 
|  | 3617 | * Description: | 
|  | 3618 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | 
|  | 3619 | * Uses the sysfs mbox to send buf contents to the adapter. | 
|  | 3620 | * | 
|  | 3621 | * Returns: | 
|  | 3622 | * -ERANGE off and count combo out of range | 
|  | 3623 | * -EINVAL off, count or buff address invalid | 
|  | 3624 | * zero if count is zero | 
|  | 3625 | * -EPERM adapter is offline | 
|  | 3626 | * -ENOMEM failed to allocate memory for the mail box | 
|  | 3627 | * -EAGAIN offset, state or mbox is NULL | 
|  | 3628 | * count number of bytes transferred | 
|  | 3629 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3630 | static ssize_t | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3631 | sysfs_mbox_write(struct file *filp, struct kobject *kobj, | 
|  | 3632 | struct bin_attribute *bin_attr, | 
| Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 3633 | char *buf, loff_t off, size_t count) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3635 | struct device *dev = container_of(kobj, struct device, kobj); | 
|  | 3636 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3637 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3638 | struct lpfc_hba   *phba = vport->phba; | 
|  | 3639 | struct lpfcMboxq  *mbox = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 |  | 
|  | 3641 | if ((count + off) > MAILBOX_CMD_SIZE) | 
|  | 3642 | return -ERANGE; | 
|  | 3643 |  | 
|  | 3644 | if (off % 4 ||  count % 4 || (unsigned long)buf % 4) | 
|  | 3645 | return -EINVAL; | 
|  | 3646 |  | 
|  | 3647 | if (count == 0) | 
|  | 3648 | return 0; | 
|  | 3649 |  | 
|  | 3650 | if (off == 0) { | 
|  | 3651 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 3652 | if (!mbox) | 
|  | 3653 | return -ENOMEM; | 
| James Smart | fc6c12b | 2006-03-07 15:04:19 -0500 | [diff] [blame] | 3654 | memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3655 | } | 
|  | 3656 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3657 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 |  | 
|  | 3659 | if (off == 0) { | 
|  | 3660 | if (phba->sysfs_mbox.mbox) | 
|  | 3661 | mempool_free(mbox, phba->mbox_mem_pool); | 
|  | 3662 | else | 
|  | 3663 | phba->sysfs_mbox.mbox = mbox; | 
|  | 3664 | phba->sysfs_mbox.state = SMBOX_WRITING; | 
|  | 3665 | } else { | 
|  | 3666 | if (phba->sysfs_mbox.state  != SMBOX_WRITING || | 
|  | 3667 | phba->sysfs_mbox.offset != off           || | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3668 | phba->sysfs_mbox.mbox   == NULL) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3669 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3670 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 3671 | return -EAGAIN; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | } | 
|  | 3673 | } | 
|  | 3674 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3675 | memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | buf, count); | 
|  | 3677 |  | 
|  | 3678 | phba->sysfs_mbox.offset = off + count; | 
|  | 3679 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3680 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 |  | 
|  | 3682 | return count; | 
|  | 3683 | } | 
|  | 3684 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3685 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3686 | * sysfs_mbox_read - Read method for reading information via mbox | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3687 | * @filp: open sysfs file | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3688 | * @kobj: kernel kobject that contains the kernel class device. | 
|  | 3689 | * @bin_attr: kernel attributes passed to us. | 
|  | 3690 | * @buf: contains the data to be read from sysfs mbox. | 
|  | 3691 | * @off: offset into buffer to beginning of data. | 
|  | 3692 | * @count: bytes to transfer. | 
|  | 3693 | * | 
|  | 3694 | * Description: | 
|  | 3695 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | 
|  | 3696 | * Uses the sysfs mbox to receive data from to the adapter. | 
|  | 3697 | * | 
|  | 3698 | * Returns: | 
|  | 3699 | * -ERANGE off greater than mailbox command size | 
|  | 3700 | * -EINVAL off, count or buff address invalid | 
|  | 3701 | * zero if off and count are zero | 
|  | 3702 | * -EACCES adapter over temp | 
|  | 3703 | * -EPERM garbage can value to catch a multitude of errors | 
|  | 3704 | * -EAGAIN management IO not permitted, state or off error | 
|  | 3705 | * -ETIME mailbox timeout | 
|  | 3706 | * -ENODEV mailbox error | 
|  | 3707 | * count number of bytes transferred | 
|  | 3708 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3709 | static ssize_t | 
| Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3710 | sysfs_mbox_read(struct file *filp, struct kobject *kobj, | 
|  | 3711 | struct bin_attribute *bin_attr, | 
| Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 3712 | char *buf, loff_t off, size_t count) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | { | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3714 | struct device *dev = container_of(kobj, struct device, kobj); | 
|  | 3715 | struct Scsi_Host  *shost = class_to_shost(dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3716 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3717 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3718 | int rc; | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3719 | MAILBOX_t *pmb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3721 | if (off > MAILBOX_CMD_SIZE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3722 | return -ERANGE; | 
|  | 3723 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3724 | if ((count + off) > MAILBOX_CMD_SIZE) | 
|  | 3725 | count = MAILBOX_CMD_SIZE - off; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3726 |  | 
|  | 3727 | if (off % 4 ||  count % 4 || (unsigned long)buf % 4) | 
|  | 3728 | return -EINVAL; | 
|  | 3729 |  | 
|  | 3730 | if (off && count == 0) | 
|  | 3731 | return 0; | 
|  | 3732 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3733 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 |  | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 3735 | if (phba->over_temp_state == HBA_OVER_TEMP) { | 
|  | 3736 | sysfs_mbox_idle(phba); | 
|  | 3737 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3738 | return  -EACCES; | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 3739 | } | 
|  | 3740 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3741 | if (off == 0 && | 
|  | 3742 | phba->sysfs_mbox.state  == SMBOX_WRITING && | 
|  | 3743 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3744 | pmb = &phba->sysfs_mbox.mbox->u.mb; | 
|  | 3745 | switch (pmb->mbxCommand) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | /* Offline only */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | case MBX_INIT_LINK: | 
|  | 3748 | case MBX_DOWN_LINK: | 
|  | 3749 | case MBX_CONFIG_LINK: | 
|  | 3750 | case MBX_CONFIG_RING: | 
|  | 3751 | case MBX_RESET_RING: | 
|  | 3752 | case MBX_UNREG_LOGIN: | 
|  | 3753 | case MBX_CLEAR_LA: | 
|  | 3754 | case MBX_DUMP_CONTEXT: | 
|  | 3755 | case MBX_RUN_DIAGS: | 
|  | 3756 | case MBX_RESTART: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3757 | case MBX_SET_MASK: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3758 | case MBX_SET_DEBUG: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3759 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3760 | printk(KERN_WARNING "mbox_read:Command 0x%x " | 
|  | 3761 | "is illegal in on-line state\n", | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3762 | pmb->mbxCommand); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3764 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3765 | return -EPERM; | 
|  | 3766 | } | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3767 | case MBX_WRITE_NV: | 
|  | 3768 | case MBX_WRITE_VPARMS: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | case MBX_LOAD_SM: | 
|  | 3770 | case MBX_READ_NV: | 
|  | 3771 | case MBX_READ_CONFIG: | 
|  | 3772 | case MBX_READ_RCONFIG: | 
|  | 3773 | case MBX_READ_STATUS: | 
|  | 3774 | case MBX_READ_XRI: | 
|  | 3775 | case MBX_READ_REV: | 
|  | 3776 | case MBX_READ_LNK_STAT: | 
|  | 3777 | case MBX_DUMP_MEMORY: | 
|  | 3778 | case MBX_DOWN_LOAD: | 
|  | 3779 | case MBX_UPDATE_CFG: | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3780 | case MBX_KILL_BOARD: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3781 | case MBX_LOAD_AREA: | 
|  | 3782 | case MBX_LOAD_EXP_ROM: | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3783 | case MBX_BEACON: | 
|  | 3784 | case MBX_DEL_LD_ENTRY: | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3785 | case MBX_SET_VARIABLE: | 
|  | 3786 | case MBX_WRITE_WWN: | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3787 | case MBX_PORT_CAPABILITIES: | 
|  | 3788 | case MBX_PORT_IOV_CONTROL: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | break; | 
| James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 3790 | case MBX_SECURITY_MGMT: | 
|  | 3791 | case MBX_AUTH_PORT: | 
| James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3792 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { | 
|  | 3793 | printk(KERN_WARNING "mbox_read:Command 0x%x " | 
|  | 3794 | "is not permitted\n", pmb->mbxCommand); | 
|  | 3795 | sysfs_mbox_idle(phba); | 
|  | 3796 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 3797 | return -EPERM; | 
| James Smart | 5989b8d | 2010-10-22 11:06:56 -0400 | [diff] [blame] | 3798 | } | 
| James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 3799 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | case MBX_READ_SPARM64: | 
|  | 3801 | case MBX_READ_LA: | 
|  | 3802 | case MBX_READ_LA64: | 
|  | 3803 | case MBX_REG_LOGIN: | 
|  | 3804 | case MBX_REG_LOGIN64: | 
|  | 3805 | case MBX_CONFIG_PORT: | 
|  | 3806 | case MBX_RUN_BIU_DIAG: | 
|  | 3807 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3808 | pmb->mbxCommand); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3809 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | return -EPERM; | 
|  | 3812 | default: | 
|  | 3813 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3814 | pmb->mbxCommand); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3815 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3816 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | return -EPERM; | 
|  | 3818 | } | 
|  | 3819 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3820 | /* If HBA encountered an error attention, allow only DUMP | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 3821 | * or RESTART mailbox commands until the HBA is restarted. | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3822 | */ | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3823 | if (phba->pport->stopped && | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3824 | pmb->mbxCommand != MBX_DUMP_MEMORY && | 
|  | 3825 | pmb->mbxCommand != MBX_RESTART && | 
|  | 3826 | pmb->mbxCommand != MBX_WRITE_VPARMS && | 
|  | 3827 | pmb->mbxCommand != MBX_WRITE_WWN) | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3828 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | 
|  | 3829 | "1259 mbox: Issued mailbox cmd " | 
|  | 3830 | "0x%x while in stopped state.\n", | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3831 | pmb->mbxCommand); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3832 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3833 | phba->sysfs_mbox.mbox->vport = vport; | 
|  | 3834 |  | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3835 | /* Don't allow mailbox commands to be sent when blocked | 
|  | 3836 | * or when in the middle of discovery | 
|  | 3837 | */ | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 3838 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3839 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3840 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3841 | return  -EAGAIN; | 
|  | 3842 | } | 
|  | 3843 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | if ((vport->fc_flag & FC_OFFLINE_MODE) || | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 3845 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3846 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3847 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | rc = lpfc_sli_issue_mbox (phba, | 
|  | 3849 | phba->sysfs_mbox.mbox, | 
|  | 3850 | MBX_POLL); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3851 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3852 |  | 
|  | 3853 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3854 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3855 | rc = lpfc_sli_issue_mbox_wait (phba, | 
|  | 3856 | phba->sysfs_mbox.mbox, | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3857 | lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | } | 
|  | 3860 |  | 
|  | 3861 | if (rc != MBX_SUCCESS) { | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3862 | if (rc == MBX_TIMEOUT) { | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3863 | phba->sysfs_mbox.mbox = NULL; | 
|  | 3864 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3865 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3866 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 3867 | return  (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3868 | } | 
|  | 3869 | phba->sysfs_mbox.state = SMBOX_READING; | 
|  | 3870 | } | 
|  | 3871 | else if (phba->sysfs_mbox.offset != off || | 
|  | 3872 | phba->sysfs_mbox.state  != SMBOX_READING) { | 
|  | 3873 | printk(KERN_WARNING  "mbox_read: Bad State\n"); | 
|  | 3874 | sysfs_mbox_idle(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3875 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 3876 | return -EAGAIN; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3877 | } | 
|  | 3878 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 3879 | memcpy(buf, (uint8_t *) &pmb + off, count); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 |  | 
|  | 3881 | phba->sysfs_mbox.offset = off + count; | 
|  | 3882 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3883 | if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | sysfs_mbox_idle(phba); | 
|  | 3885 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3886 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3887 |  | 
|  | 3888 | return count; | 
|  | 3889 | } | 
|  | 3890 |  | 
|  | 3891 | static struct bin_attribute sysfs_mbox_attr = { | 
|  | 3892 | .attr = { | 
|  | 3893 | .name = "mbox", | 
|  | 3894 | .mode = S_IRUSR | S_IWUSR, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3895 | }, | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3896 | .size = MAILBOX_CMD_SIZE, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | .read = sysfs_mbox_read, | 
|  | 3898 | .write = sysfs_mbox_write, | 
|  | 3899 | }; | 
|  | 3900 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3901 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3902 | * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3903 | * @vport: address of lpfc vport structure. | 
|  | 3904 | * | 
|  | 3905 | * Return codes: | 
|  | 3906 | * zero on success | 
|  | 3907 | * error return code from sysfs_create_bin_file() | 
|  | 3908 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3910 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3911 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3912 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3913 | int error; | 
|  | 3914 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3915 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3916 | &sysfs_drvr_stat_data_attr); | 
|  | 3917 |  | 
|  | 3918 | /* Virtual ports do not need ctrl_reg and mbox */ | 
|  | 3919 | if (error || vport->port_type == LPFC_NPIV_PORT) | 
|  | 3920 | goto out; | 
|  | 3921 |  | 
|  | 3922 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3923 | &sysfs_ctlreg_attr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | if (error) | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3925 | goto out_remove_stat_attr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 |  | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3927 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3928 | &sysfs_mbox_attr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | if (error) | 
|  | 3930 | goto out_remove_ctlreg_attr; | 
|  | 3931 |  | 
|  | 3932 | return 0; | 
|  | 3933 | out_remove_ctlreg_attr: | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3934 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3935 | out_remove_stat_attr: | 
|  | 3936 | sysfs_remove_bin_file(&shost->shost_dev.kobj, | 
|  | 3937 | &sysfs_drvr_stat_data_attr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | out: | 
|  | 3939 | return error; | 
|  | 3940 | } | 
|  | 3941 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3942 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3943 | * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3944 | * @vport: address of lpfc vport structure. | 
|  | 3945 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3946 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3947 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3948 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3949 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3950 | sysfs_remove_bin_file(&shost->shost_dev.kobj, | 
|  | 3951 | &sysfs_drvr_stat_data_attr); | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3952 | /* Virtual ports do not need ctrl_reg and mbox */ | 
|  | 3953 | if (vport->port_type == LPFC_NPIV_PORT) | 
|  | 3954 | return; | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 3955 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); | 
|  | 3956 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | } | 
|  | 3958 |  | 
|  | 3959 |  | 
|  | 3960 | /* | 
|  | 3961 | * Dynamic FC Host Attributes Support | 
|  | 3962 | */ | 
|  | 3963 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3964 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3965 | * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3966 | * @shost: kernel scsi host pointer. | 
|  | 3967 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3968 | static void | 
|  | 3969 | lpfc_get_host_port_id(struct Scsi_Host *shost) | 
|  | 3970 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3971 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3972 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3973 | /* note: fc_myDID already in cpu endianness */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3974 | fc_host_port_id(shost) = vport->fc_myDID; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | } | 
|  | 3976 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3977 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3978 | * lpfc_get_host_port_type - Set the value of the scsi host port type | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3979 | * @shost: kernel scsi host pointer. | 
|  | 3980 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3981 | static void | 
|  | 3982 | lpfc_get_host_port_type(struct Scsi_Host *shost) | 
|  | 3983 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3984 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 3985 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3986 |  | 
|  | 3987 | spin_lock_irq(shost->host_lock); | 
|  | 3988 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3989 | if (vport->port_type == LPFC_NPIV_PORT) { | 
|  | 3990 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | 
|  | 3991 | } else if (lpfc_is_link_up(phba)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | if (phba->fc_topology == TOPOLOGY_LOOP) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3993 | if (vport->fc_flag & FC_PUBLIC_LOOP) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; | 
|  | 3995 | else | 
|  | 3996 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | 
|  | 3997 | } else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3998 | if (vport->fc_flag & FC_FABRIC) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; | 
|  | 4000 | else | 
|  | 4001 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | 
|  | 4002 | } | 
|  | 4003 | } else | 
|  | 4004 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | 
|  | 4005 |  | 
|  | 4006 | spin_unlock_irq(shost->host_lock); | 
|  | 4007 | } | 
|  | 4008 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4009 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4010 | * lpfc_get_host_port_state - Set the value of the scsi host port state | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4011 | * @shost: kernel scsi host pointer. | 
|  | 4012 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4013 | static void | 
|  | 4014 | lpfc_get_host_port_state(struct Scsi_Host *shost) | 
|  | 4015 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4016 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 4017 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4018 |  | 
|  | 4019 | spin_lock_irq(shost->host_lock); | 
|  | 4020 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4021 | if (vport->fc_flag & FC_OFFLINE_MODE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4022 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | 
|  | 4023 | else { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | switch (phba->link_state) { | 
|  | 4025 | case LPFC_LINK_UNKNOWN: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4026 | case LPFC_LINK_DOWN: | 
|  | 4027 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | 
|  | 4028 | break; | 
|  | 4029 | case LPFC_LINK_UP: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4030 | case LPFC_CLEAR_LA: | 
|  | 4031 | case LPFC_HBA_READY: | 
|  | 4032 | /* Links up, beyond this port_type reports state */ | 
|  | 4033 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | 
|  | 4034 | break; | 
|  | 4035 | case LPFC_HBA_ERROR: | 
|  | 4036 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | 
|  | 4037 | break; | 
|  | 4038 | default: | 
|  | 4039 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | 
|  | 4040 | break; | 
|  | 4041 | } | 
|  | 4042 | } | 
|  | 4043 |  | 
|  | 4044 | spin_unlock_irq(shost->host_lock); | 
|  | 4045 | } | 
|  | 4046 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4047 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4048 | * lpfc_get_host_speed - Set the value of the scsi host speed | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4049 | * @shost: kernel scsi host pointer. | 
|  | 4050 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4051 | static void | 
|  | 4052 | lpfc_get_host_speed(struct Scsi_Host *shost) | 
|  | 4053 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4054 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 4055 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4056 |  | 
|  | 4057 | spin_lock_irq(shost->host_lock); | 
|  | 4058 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4059 | if (lpfc_is_link_up(phba)) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4060 | switch(phba->fc_linkspeed) { | 
|  | 4061 | case LA_1GHZ_LINK: | 
|  | 4062 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | 
|  | 4063 | break; | 
|  | 4064 | case LA_2GHZ_LINK: | 
|  | 4065 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | 
|  | 4066 | break; | 
|  | 4067 | case LA_4GHZ_LINK: | 
|  | 4068 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | 
|  | 4069 | break; | 
| James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 4070 | case LA_8GHZ_LINK: | 
|  | 4071 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | 
|  | 4072 | break; | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4073 | case LA_10GHZ_LINK: | 
|  | 4074 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | 
|  | 4075 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4076 | default: | 
|  | 4077 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | 
|  | 4078 | break; | 
|  | 4079 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4080 | } else | 
|  | 4081 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 |  | 
|  | 4083 | spin_unlock_irq(shost->host_lock); | 
|  | 4084 | } | 
|  | 4085 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4086 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4087 | * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4088 | * @shost: kernel scsi host pointer. | 
|  | 4089 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | static void | 
|  | 4091 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | 
|  | 4092 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4093 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 4094 | struct lpfc_hba   *phba = vport->phba; | 
| Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 4095 | u64 node_name; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4096 |  | 
|  | 4097 | spin_lock_irq(shost->host_lock); | 
|  | 4098 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4099 | if ((vport->fc_flag & FC_FABRIC) || | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | ((phba->fc_topology == TOPOLOGY_LOOP) && | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4101 | (vport->fc_flag & FC_PUBLIC_LOOP))) | 
| Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 4102 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | else | 
|  | 4104 | /* fabric is local port if there is no F/FL_Port */ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4105 | node_name = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4106 |  | 
|  | 4107 | spin_unlock_irq(shost->host_lock); | 
|  | 4108 |  | 
| Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 4109 | fc_host_fabric_name(shost) = node_name; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4110 | } | 
|  | 4111 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4112 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4113 | * lpfc_get_stats - Return statistical information about the adapter | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4114 | * @shost: kernel scsi host pointer. | 
|  | 4115 | * | 
|  | 4116 | * Notes: | 
|  | 4117 | * NULL on error for link down, no mbox pool, sli2 active, | 
|  | 4118 | * management not allowed, memory allocation error, or mbox error. | 
|  | 4119 | * | 
|  | 4120 | * Returns: | 
|  | 4121 | * NULL for error | 
|  | 4122 | * address of the adapter host statistics | 
|  | 4123 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | static struct fc_host_statistics * | 
|  | 4125 | lpfc_get_stats(struct Scsi_Host *shost) | 
|  | 4126 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4127 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 4128 | struct lpfc_hba   *phba = vport->phba; | 
|  | 4129 | struct lpfc_sli   *psli = &phba->sli; | 
| James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 4130 | struct fc_host_statistics *hs = &phba->link_stats; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4131 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4132 | LPFC_MBOXQ_t *pmboxq; | 
|  | 4133 | MAILBOX_t *pmb; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4134 | unsigned long seconds; | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 4135 | int rc = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4136 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4137 | /* | 
|  | 4138 | * prevent udev from issuing mailbox commands until the port is | 
|  | 4139 | * configured. | 
|  | 4140 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4141 | if (phba->link_state < LPFC_LINK_DOWN || | 
|  | 4142 | !phba->mbox_mem_pool || | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4143 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4144 | return NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 |  | 
|  | 4146 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 4147 | return NULL; | 
|  | 4148 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4149 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 4150 | if (!pmboxq) | 
|  | 4151 | return NULL; | 
|  | 4152 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | 
|  | 4153 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4154 | pmb = &pmboxq->u.mb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | pmb->mbxCommand = MBX_READ_STATUS; | 
|  | 4156 | pmb->mbxOwner = OWN_HOST; | 
|  | 4157 | pmboxq->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4158 | pmboxq->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 |  | 
| James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4160 | if (vport->fc_flag & FC_OFFLINE_MODE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4161 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 4162 | else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | 
|  | 4164 |  | 
|  | 4165 | if (rc != MBX_SUCCESS) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4166 | if (rc != MBX_TIMEOUT) | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 4167 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4168 | return NULL; | 
|  | 4169 | } | 
|  | 4170 |  | 
| James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 4171 | memset(hs, 0, sizeof (struct fc_host_statistics)); | 
|  | 4172 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; | 
|  | 4174 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); | 
|  | 4175 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; | 
|  | 4176 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); | 
|  | 4177 |  | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 4178 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4179 | pmb->mbxCommand = MBX_READ_LNK_STAT; | 
|  | 4180 | pmb->mbxOwner = OWN_HOST; | 
|  | 4181 | pmboxq->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4182 | pmboxq->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 |  | 
| James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4184 | if (vport->fc_flag & FC_OFFLINE_MODE) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4185 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | 
| James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 4186 | else | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4187 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | 
|  | 4188 |  | 
|  | 4189 | if (rc != MBX_SUCCESS) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4190 | if (rc != MBX_TIMEOUT) | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4191 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4192 | return NULL; | 
|  | 4193 | } | 
|  | 4194 |  | 
|  | 4195 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | 
|  | 4196 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | 
|  | 4197 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | 
|  | 4198 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | 
|  | 4199 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | 
|  | 4200 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | 
|  | 4201 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | 
|  | 4202 |  | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4203 | hs->link_failure_count -= lso->link_failure_count; | 
|  | 4204 | hs->loss_of_sync_count -= lso->loss_of_sync_count; | 
|  | 4205 | hs->loss_of_signal_count -= lso->loss_of_signal_count; | 
|  | 4206 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; | 
|  | 4207 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; | 
|  | 4208 | hs->invalid_crc_count -= lso->invalid_crc_count; | 
|  | 4209 | hs->error_frames -= lso->error_frames; | 
|  | 4210 |  | 
| James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4211 | if (phba->hba_flag & HBA_FCOE_SUPPORT) { | 
|  | 4212 | hs->lip_count = -1; | 
|  | 4213 | hs->nos_count = (phba->link_events >> 1); | 
|  | 4214 | hs->nos_count -= lso->link_events; | 
|  | 4215 | } else if (phba->fc_topology == TOPOLOGY_LOOP) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4216 | hs->lip_count = (phba->fc_eventTag >> 1); | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4217 | hs->lip_count -= lso->link_events; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4218 | hs->nos_count = -1; | 
|  | 4219 | } else { | 
|  | 4220 | hs->lip_count = -1; | 
|  | 4221 | hs->nos_count = (phba->fc_eventTag >> 1); | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4222 | hs->nos_count -= lso->link_events; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | } | 
|  | 4224 |  | 
|  | 4225 | hs->dumped_frames = -1; | 
|  | 4226 |  | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4227 | seconds = get_seconds(); | 
|  | 4228 | if (seconds < psli->stats_start) | 
|  | 4229 | hs->seconds_since_last_reset = seconds + | 
|  | 4230 | ((unsigned long)-1 - psli->stats_start); | 
|  | 4231 | else | 
|  | 4232 | hs->seconds_since_last_reset = seconds - psli->stats_start; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4233 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4234 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 4235 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | return hs; | 
|  | 4237 | } | 
|  | 4238 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4239 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4240 | * lpfc_reset_stats - Copy the adapter link stats information | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4241 | * @shost: kernel scsi host pointer. | 
|  | 4242 | **/ | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4243 | static void | 
|  | 4244 | lpfc_reset_stats(struct Scsi_Host *shost) | 
|  | 4245 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4246 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 4247 | struct lpfc_hba   *phba = vport->phba; | 
|  | 4248 | struct lpfc_sli   *psli = &phba->sli; | 
|  | 4249 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4250 | LPFC_MBOXQ_t *pmboxq; | 
|  | 4251 | MAILBOX_t *pmb; | 
|  | 4252 | int rc = 0; | 
|  | 4253 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 4255 | return; | 
|  | 4256 |  | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4257 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 4258 | if (!pmboxq) | 
|  | 4259 | return; | 
|  | 4260 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | 
|  | 4261 |  | 
| James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4262 | pmb = &pmboxq->u.mb; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4263 | pmb->mbxCommand = MBX_READ_STATUS; | 
|  | 4264 | pmb->mbxOwner = OWN_HOST; | 
|  | 4265 | pmb->un.varWords[0] = 0x1; /* reset request */ | 
|  | 4266 | pmboxq->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4267 | pmboxq->vport = vport; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4268 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4269 | if ((vport->fc_flag & FC_OFFLINE_MODE) || | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4270 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4271 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | 
|  | 4272 | else | 
|  | 4273 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | 
|  | 4274 |  | 
|  | 4275 | if (rc != MBX_SUCCESS) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4276 | if (rc != MBX_TIMEOUT) | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4277 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 4278 | return; | 
|  | 4279 | } | 
|  | 4280 |  | 
|  | 4281 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | 
|  | 4282 | pmb->mbxCommand = MBX_READ_LNK_STAT; | 
|  | 4283 | pmb->mbxOwner = OWN_HOST; | 
|  | 4284 | pmboxq->context1 = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4285 | pmboxq->vport = vport; | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4286 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | if ((vport->fc_flag & FC_OFFLINE_MODE) || | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4288 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4289 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | 
|  | 4290 | else | 
|  | 4291 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | 
|  | 4292 |  | 
|  | 4293 | if (rc != MBX_SUCCESS) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4294 | if (rc != MBX_TIMEOUT) | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4295 | mempool_free( pmboxq, phba->mbox_mem_pool); | 
|  | 4296 | return; | 
|  | 4297 | } | 
|  | 4298 |  | 
|  | 4299 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | 
|  | 4300 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | 
|  | 4301 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | 
|  | 4302 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | 
|  | 4303 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | 
|  | 4304 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | 
|  | 4305 | lso->error_frames = pmb->un.varRdLnk.crcCnt; | 
| James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4306 | if (phba->hba_flag & HBA_FCOE_SUPPORT) | 
|  | 4307 | lso->link_events = (phba->link_events >> 1); | 
|  | 4308 | else | 
|  | 4309 | lso->link_events = (phba->fc_eventTag >> 1); | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4310 |  | 
|  | 4311 | psli->stats_start = get_seconds(); | 
|  | 4312 |  | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 4313 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 4314 |  | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4315 | return; | 
|  | 4316 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4317 |  | 
|  | 4318 | /* | 
|  | 4319 | * The LPFC driver treats linkdown handling as target loss events so there | 
|  | 4320 | * are no sysfs handlers for link_down_tmo. | 
|  | 4321 | */ | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4322 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4323 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4324 | * lpfc_get_node_by_target - Return the nodelist for a target | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4325 | * @starget: kernel scsi target pointer. | 
|  | 4326 | * | 
|  | 4327 | * Returns: | 
|  | 4328 | * address of the node list if found | 
|  | 4329 | * NULL target not found | 
|  | 4330 | **/ | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4331 | static struct lpfc_nodelist * | 
|  | 4332 | lpfc_get_node_by_target(struct scsi_target *starget) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent); | 
|  | 4335 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4336 | struct lpfc_nodelist *ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4337 |  | 
|  | 4338 | spin_lock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4339 | /* Search for this, mapped, target ID */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4341 | if (NLP_CHK_NODE_ACT(ndlp) && | 
|  | 4342 | ndlp->nlp_state == NLP_STE_MAPPED_NODE && | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4343 | starget->id == ndlp->nlp_sid) { | 
|  | 4344 | spin_unlock_irq(shost->host_lock); | 
|  | 4345 | return ndlp; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4346 | } | 
|  | 4347 | } | 
|  | 4348 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4349 | return NULL; | 
|  | 4350 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4351 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4352 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4353 | * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1 | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4354 | * @starget: kernel scsi target pointer. | 
|  | 4355 | **/ | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4356 | static void | 
|  | 4357 | lpfc_get_starget_port_id(struct scsi_target *starget) | 
|  | 4358 | { | 
|  | 4359 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | 
|  | 4360 |  | 
|  | 4361 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4362 | } | 
|  | 4363 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4364 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4365 | * lpfc_get_starget_node_name - Set the target node name | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4366 | * @starget: kernel scsi target pointer. | 
|  | 4367 | * | 
|  | 4368 | * Description: Set the target node name to the ndlp node name wwn or zero. | 
|  | 4369 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | static void | 
|  | 4371 | lpfc_get_starget_node_name(struct scsi_target *starget) | 
|  | 4372 | { | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4373 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4374 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4375 | fc_starget_node_name(starget) = | 
|  | 4376 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4377 | } | 
|  | 4378 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4379 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4380 | * lpfc_get_starget_port_name - Set the target port name | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4381 | * @starget: kernel scsi target pointer. | 
|  | 4382 | * | 
|  | 4383 | * Description:  set the target port name to the ndlp port name wwn or zero. | 
|  | 4384 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4385 | static void | 
|  | 4386 | lpfc_get_starget_port_name(struct scsi_target *starget) | 
|  | 4387 | { | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4388 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4389 |  | 
| James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 4390 | fc_starget_port_name(starget) = | 
|  | 4391 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4392 | } | 
|  | 4393 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4394 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4395 | * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4396 | * @rport: fc rport address. | 
|  | 4397 | * @timeout: new value for dev loss tmo. | 
|  | 4398 | * | 
|  | 4399 | * Description: | 
|  | 4400 | * If timeout is non zero set the dev_loss_tmo to timeout, else set | 
|  | 4401 | * dev_loss_tmo to one. | 
|  | 4402 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4403 | static void | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | 
|  | 4405 | { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | if (timeout) | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4407 | rport->dev_loss_tmo = timeout; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4408 | else | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4409 | rport->dev_loss_tmo = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4410 | } | 
|  | 4411 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4412 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4413 | * lpfc_rport_show_function - Return rport target information | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | * | 
|  | 4415 | * Description: | 
|  | 4416 | * Macro that uses field to generate a function with the name lpfc_show_rport_ | 
|  | 4417 | * | 
|  | 4418 | * lpfc_show_rport_##field: returns the bytes formatted in buf | 
|  | 4419 | * @cdev: class converted to an fc_rport. | 
|  | 4420 | * @buf: on return contains the target_field or zero. | 
|  | 4421 | * | 
|  | 4422 | * Returns: size of formatted string. | 
|  | 4423 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | #define lpfc_rport_show_function(field, format_string, sz, cast)	\ | 
|  | 4425 | static ssize_t								\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4426 | lpfc_show_rport_##field (struct device *dev,				\ | 
|  | 4427 | struct device_attribute *attr,			\ | 
|  | 4428 | char *buf)					\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4429 | {									\ | 
| Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 4430 | struct fc_rport *rport = transport_class_to_rport(dev);		\ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4431 | struct lpfc_rport_data *rdata = rport->hostdata;		\ | 
|  | 4432 | return snprintf(buf, sz, format_string,				\ | 
|  | 4433 | (rdata->target) ? cast rdata->target->field : 0);	\ | 
|  | 4434 | } | 
|  | 4435 |  | 
|  | 4436 | #define lpfc_rport_rd_attr(field, format_string, sz)			\ | 
|  | 4437 | lpfc_rport_show_function(field, format_string, sz, )		\ | 
|  | 4438 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | 
|  | 4439 |  | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4440 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4441 | * lpfc_set_vport_symbolic_name - Set the vport's symbolic name | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4442 | * @fc_vport: The fc_vport who's symbolic name has been changed. | 
|  | 4443 | * | 
|  | 4444 | * Description: | 
|  | 4445 | * This function is called by the transport after the @fc_vport's symbolic name | 
|  | 4446 | * has been changed. This function re-registers the symbolic name with the | 
|  | 4447 | * switch to propogate the change into the fabric if the vport is active. | 
|  | 4448 | **/ | 
|  | 4449 | static void | 
|  | 4450 | lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport) | 
|  | 4451 | { | 
|  | 4452 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; | 
|  | 4453 |  | 
|  | 4454 | if (vport->port_state == LPFC_VPORT_READY) | 
|  | 4455 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); | 
|  | 4456 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 |  | 
| James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4458 | /** | 
|  | 4459 | * lpfc_hba_log_verbose_init - Set hba's log verbose level | 
|  | 4460 | * @phba: Pointer to lpfc_hba struct. | 
|  | 4461 | * | 
|  | 4462 | * This function is called by the lpfc_get_cfgparam() routine to set the | 
|  | 4463 | * module lpfc_log_verbose into the @phba cfg_log_verbose for use with | 
|  | 4464 | * log messsage according to the module's lpfc_log_verbose parameter setting | 
|  | 4465 | * before hba port or vport created. | 
|  | 4466 | **/ | 
|  | 4467 | static void | 
|  | 4468 | lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose) | 
|  | 4469 | { | 
|  | 4470 | phba->cfg_log_verbose = verbose; | 
|  | 4471 | } | 
|  | 4472 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | struct fc_function_template lpfc_transport_functions = { | 
|  | 4474 | /* fixed attributes the driver supports */ | 
|  | 4475 | .show_host_node_name = 1, | 
|  | 4476 | .show_host_port_name = 1, | 
|  | 4477 | .show_host_supported_classes = 1, | 
|  | 4478 | .show_host_supported_fc4s = 1, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4479 | .show_host_supported_speeds = 1, | 
|  | 4480 | .show_host_maxframe_size = 1, | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4481 | .show_host_symbolic_name = 1, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4482 |  | 
|  | 4483 | /* dynamic attributes the driver supports */ | 
|  | 4484 | .get_host_port_id = lpfc_get_host_port_id, | 
|  | 4485 | .show_host_port_id = 1, | 
|  | 4486 |  | 
|  | 4487 | .get_host_port_type = lpfc_get_host_port_type, | 
|  | 4488 | .show_host_port_type = 1, | 
|  | 4489 |  | 
|  | 4490 | .get_host_port_state = lpfc_get_host_port_state, | 
|  | 4491 | .show_host_port_state = 1, | 
|  | 4492 |  | 
|  | 4493 | /* active_fc4s is shown but doesn't change (thus no get function) */ | 
|  | 4494 | .show_host_active_fc4s = 1, | 
|  | 4495 |  | 
|  | 4496 | .get_host_speed = lpfc_get_host_speed, | 
|  | 4497 | .show_host_speed = 1, | 
|  | 4498 |  | 
|  | 4499 | .get_host_fabric_name = lpfc_get_host_fabric_name, | 
|  | 4500 | .show_host_fabric_name = 1, | 
|  | 4501 |  | 
|  | 4502 | /* | 
|  | 4503 | * The LPFC driver treats linkdown handling as target loss events | 
|  | 4504 | * so there are no sysfs handlers for link_down_tmo. | 
|  | 4505 | */ | 
|  | 4506 |  | 
|  | 4507 | .get_fc_host_stats = lpfc_get_stats, | 
| James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4508 | .reset_fc_host_stats = lpfc_reset_stats, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4509 |  | 
|  | 4510 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | 
|  | 4511 | .show_rport_maxframe_size = 1, | 
|  | 4512 | .show_rport_supported_classes = 1, | 
|  | 4513 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4514 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | 
|  | 4515 | .show_rport_dev_loss_tmo = 1, | 
|  | 4516 |  | 
|  | 4517 | .get_starget_port_id  = lpfc_get_starget_port_id, | 
|  | 4518 | .show_starget_port_id = 1, | 
|  | 4519 |  | 
|  | 4520 | .get_starget_node_name = lpfc_get_starget_node_name, | 
|  | 4521 | .show_starget_node_name = 1, | 
|  | 4522 |  | 
|  | 4523 | .get_starget_port_name = lpfc_get_starget_port_name, | 
|  | 4524 | .show_starget_port_name = 1, | 
| Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 4525 |  | 
|  | 4526 | .issue_fc_host_lip = lpfc_issue_lip, | 
| James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 4527 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | 
|  | 4528 | .terminate_rport_io = lpfc_terminate_rport_io, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4529 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4530 | .dd_fcvport_size = sizeof(struct lpfc_vport *), | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4531 |  | 
|  | 4532 | .vport_disable = lpfc_vport_disable, | 
|  | 4533 |  | 
|  | 4534 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | 
| James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 4535 |  | 
|  | 4536 | .bsg_request = lpfc_bsg_request, | 
|  | 4537 | .bsg_timeout = lpfc_bsg_timeout, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4538 | }; | 
|  | 4539 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4540 | struct fc_function_template lpfc_vport_transport_functions = { | 
|  | 4541 | /* fixed attributes the driver supports */ | 
|  | 4542 | .show_host_node_name = 1, | 
|  | 4543 | .show_host_port_name = 1, | 
|  | 4544 | .show_host_supported_classes = 1, | 
|  | 4545 | .show_host_supported_fc4s = 1, | 
|  | 4546 | .show_host_supported_speeds = 1, | 
|  | 4547 | .show_host_maxframe_size = 1, | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4548 | .show_host_symbolic_name = 1, | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4549 |  | 
|  | 4550 | /* dynamic attributes the driver supports */ | 
|  | 4551 | .get_host_port_id = lpfc_get_host_port_id, | 
|  | 4552 | .show_host_port_id = 1, | 
|  | 4553 |  | 
|  | 4554 | .get_host_port_type = lpfc_get_host_port_type, | 
|  | 4555 | .show_host_port_type = 1, | 
|  | 4556 |  | 
|  | 4557 | .get_host_port_state = lpfc_get_host_port_state, | 
|  | 4558 | .show_host_port_state = 1, | 
|  | 4559 |  | 
|  | 4560 | /* active_fc4s is shown but doesn't change (thus no get function) */ | 
|  | 4561 | .show_host_active_fc4s = 1, | 
|  | 4562 |  | 
|  | 4563 | .get_host_speed = lpfc_get_host_speed, | 
|  | 4564 | .show_host_speed = 1, | 
|  | 4565 |  | 
|  | 4566 | .get_host_fabric_name = lpfc_get_host_fabric_name, | 
|  | 4567 | .show_host_fabric_name = 1, | 
|  | 4568 |  | 
|  | 4569 | /* | 
|  | 4570 | * The LPFC driver treats linkdown handling as target loss events | 
|  | 4571 | * so there are no sysfs handlers for link_down_tmo. | 
|  | 4572 | */ | 
|  | 4573 |  | 
|  | 4574 | .get_fc_host_stats = lpfc_get_stats, | 
|  | 4575 | .reset_fc_host_stats = lpfc_reset_stats, | 
|  | 4576 |  | 
|  | 4577 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | 
|  | 4578 | .show_rport_maxframe_size = 1, | 
|  | 4579 | .show_rport_supported_classes = 1, | 
|  | 4580 |  | 
|  | 4581 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | 
|  | 4582 | .show_rport_dev_loss_tmo = 1, | 
|  | 4583 |  | 
|  | 4584 | .get_starget_port_id  = lpfc_get_starget_port_id, | 
|  | 4585 | .show_starget_port_id = 1, | 
|  | 4586 |  | 
|  | 4587 | .get_starget_node_name = lpfc_get_starget_node_name, | 
|  | 4588 | .show_starget_node_name = 1, | 
|  | 4589 |  | 
|  | 4590 | .get_starget_port_name = lpfc_get_starget_port_name, | 
|  | 4591 | .show_starget_port_name = 1, | 
|  | 4592 |  | 
|  | 4593 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | 
|  | 4594 | .terminate_rport_io = lpfc_terminate_rport_io, | 
|  | 4595 |  | 
|  | 4596 | .vport_disable = lpfc_vport_disable, | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 4597 |  | 
|  | 4598 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4599 | }; | 
|  | 4600 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4601 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4602 | * lpfc_get_cfgparam - Used during probe_one to init the adapter structure | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4603 | * @phba: lpfc_hba pointer. | 
|  | 4604 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4605 | void | 
|  | 4606 | lpfc_get_cfgparam(struct lpfc_hba *phba) | 
|  | 4607 | { | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 4608 | lpfc_cr_delay_init(phba, lpfc_cr_delay); | 
|  | 4609 | lpfc_cr_count_init(phba, lpfc_cr_count); | 
| Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 4610 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 4611 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); | 
|  | 4612 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 4613 | lpfc_ack0_init(phba, lpfc_ack0); | 
|  | 4614 | lpfc_topology_init(phba, lpfc_topology); | 
| James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 4615 | lpfc_link_speed_init(phba, lpfc_link_speed); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4616 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); | 
| James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4617 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); | 
| James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 4618 | lpfc_use_msi_init(phba, lpfc_use_msi); | 
| James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4619 | lpfc_fcp_imax_init(phba, lpfc_fcp_imax); | 
|  | 4620 | lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count); | 
|  | 4621 | lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count); | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 4622 | lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); | 
|  | 4623 | lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4624 | lpfc_enable_bg_init(phba, lpfc_enable_bg); | 
| James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4625 | if (phba->sli_rev == LPFC_SLI_REV4) | 
|  | 4626 | phba->cfg_poll = 0; | 
|  | 4627 | else | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 4628 | phba->cfg_poll = lpfc_poll; | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 4629 | phba->cfg_soft_wwnn = 0L; | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 4630 | phba->cfg_soft_wwpn = 0L; | 
| James Smart | 83108bd | 2008-01-11 01:53:09 -0500 | [diff] [blame] | 4631 | lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4632 | lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt); | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 4633 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); | 
| James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 4634 | lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); | 
| James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4635 | lpfc_aer_support_init(phba, lpfc_aer_support); | 
| James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4636 | lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); | 
| James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 4637 | lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4638 | return; | 
|  | 4639 | } | 
| Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 4640 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4641 | /** | 
| James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4642 | * lpfc_get_vport_cfgparam - Used during port create, init the vport structure | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4643 | * @vport: lpfc_vport pointer. | 
|  | 4644 | **/ | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4645 | void | 
|  | 4646 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) | 
|  | 4647 | { | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4648 | lpfc_log_verbose_init(vport, lpfc_log_verbose); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4649 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); | 
| James Smart | 7dc517d | 2010-07-14 15:32:10 -0400 | [diff] [blame] | 4650 | lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4651 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); | 
|  | 4652 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); | 
|  | 4653 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); | 
|  | 4654 | lpfc_restrict_login_init(vport, lpfc_restrict_login); | 
|  | 4655 | lpfc_fcp_class_init(vport, lpfc_fcp_class); | 
|  | 4656 | lpfc_use_adisc_init(vport, lpfc_use_adisc); | 
| James Smart | 977b5a0 | 2008-09-07 11:52:04 -0400 | [diff] [blame] | 4657 | lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4658 | lpfc_fdmi_on_init(vport, lpfc_fdmi_on); | 
|  | 4659 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); | 
|  | 4660 | lpfc_max_luns_init(vport, lpfc_max_luns); | 
|  | 4661 | lpfc_scan_down_init(vport, lpfc_scan_down); | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 4662 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4663 | return; | 
|  | 4664 | } |