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