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