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