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