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