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