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