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