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