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