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