blob: 8dcbf8fff673d6412f13420e8482eba841dee9e8 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070028#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050029
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_version.h"
47#include "lpfc_compat.h"
48#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050049#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050050
James Smartc01f3202006-08-18 17:47:08 -040051#define LPFC_DEF_DEVLOSS_TMO 30
52#define LPFC_MIN_DEVLOSS_TMO 1
53#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050054
James Smarte59058c2008-08-24 21:49:00 -040055/**
James Smart3621a712009-04-06 18:47:14 -040056 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040057 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea31012005-04-17 16:05:31 -050070static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
James Smarte59058c2008-08-24 21:49:00 -040086/**
James Smart3621a712009-04-06 18:47:14 -040087 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040088 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea31012005-04-17 16:05:31 -050094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010095lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea31012005-04-17 16:05:31 -050097{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
James Smart45ed1192009-10-02 15:17:02 -0400101/**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109static ssize_t
110lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112{
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121}
122
James Smart81301a92008-12-04 22:39:46 -0500123static ssize_t
124lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140}
141
142static ssize_t
143lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
James Smart87b5c322008-12-16 10:34:09 -0500150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500152}
153
154static ssize_t
155lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157{
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
James Smart87b5c322008-12-16 10:34:09 -0500162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500164}
165
166static ssize_t
167lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169{
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
James Smart87b5c322008-12-16 10:34:09 -0500174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500176}
177
James Smarte59058c2008-08-24 21:49:00 -0400178/**
James Smart3621a712009-04-06 18:47:14 -0400179 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
dea31012005-04-17 16:05:31 -0500186static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100187lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
dea31012005-04-17 16:05:31 -0500189{
Tony Jonesee959b02008-02-22 00:13:36 +0100190 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500191
dea31012005-04-17 16:05:31 -0500192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193}
194
James Smarte59058c2008-08-24 21:49:00 -0400195/**
James Smart3621a712009-04-06 18:47:14 -0400196 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
dea31012005-04-17 16:05:31 -0500203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100204lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea31012005-04-17 16:05:31 -0500206{
Tony Jonesee959b02008-02-22 00:13:36 +0100207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea31012005-04-17 16:05:31 -0500211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart3621a712009-04-06 18:47:14 -0400215 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
dea31012005-04-17 16:05:31 -0500226static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100227lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400229{
Tony Jonesee959b02008-02-22 00:13:36 +0100230 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234}
235
James Smarte59058c2008-08-24 21:49:00 -0400236/**
James Smart3621a712009-04-06 18:47:14 -0400237 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
James Smart57127f12007-10-27 13:37:05 -0400244static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100245lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
dea31012005-04-17 16:05:31 -0500247{
Tony Jonesee959b02008-02-22 00:13:36 +0100248 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
dea31012005-04-17 16:05:31 -0500252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253}
254
James Smarte59058c2008-08-24 21:49:00 -0400255/**
James Smart3621a712009-04-06 18:47:14 -0400256 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
dea31012005-04-17 16:05:31 -0500263static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100264lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
dea31012005-04-17 16:05:31 -0500266{
Tony Jonesee959b02008-02-22 00:13:36 +0100267 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
dea31012005-04-17 16:05:31 -0500271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272}
273
James Smarte59058c2008-08-24 21:49:00 -0400274/**
James Smart3621a712009-04-06 18:47:14 -0400275 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
dea31012005-04-17 16:05:31 -0500282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100283lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea31012005-04-17 16:05:31 -0500285{
Tony Jonesee959b02008-02-22 00:13:36 +0100286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea31012005-04-17 16:05:31 -0500290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291}
292
James Smarte59058c2008-08-24 21:49:00 -0400293/**
James Smart3621a712009-04-06 18:47:14 -0400294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301static ssize_t
302lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303{
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310}
311
312/**
James Smart3621a712009-04-06 18:47:14 -0400313 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
dea31012005-04-17 16:05:31 -0500320static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100321lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
dea31012005-04-17 16:05:31 -0500323{
Tony Jonesee959b02008-02-22 00:13:36 +0100324 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
dea31012005-04-17 16:05:31 -0500328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329}
330
James Smarte59058c2008-08-24 21:49:00 -0400331/**
James Smart3621a712009-04-06 18:47:14 -0400332 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea31012005-04-17 16:05:31 -0500339static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100340lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
dea31012005-04-17 16:05:31 -0500342{
Tony Jonesee959b02008-02-22 00:13:36 +0100343 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500346 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500347
dea31012005-04-17 16:05:31 -0500348 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500350}
351
James Smarte59058c2008-08-24 21:49:00 -0400352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
dea31012005-04-17 16:05:31 -0500360static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100361lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500362{
363 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100364 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500367 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500368
dea31012005-04-17 16:05:31 -0500369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371}
James Smarte59058c2008-08-24 21:49:00 -0400372
373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
dea31012005-04-17 16:05:31 -0500381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea31012005-04-17 16:05:31 -0500384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390}
James Smarte59058c2008-08-24 21:49:00 -0400391
392/**
James Smart3621a712009-04-06 18:47:14 -0400393 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
dea31012005-04-17 16:05:31 -0500403static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100404lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea31012005-04-17 16:05:31 -0500406{
Tony Jonesee959b02008-02-22 00:13:36 +0100407 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500414 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500418 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
dea31012005-04-17 16:05:31 -0500425 break;
426 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500427 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500428 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500430
431 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500434 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500435 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500436 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
James Smart92d7f7b2007-06-17 19:56:38 -0500450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
James Smart84774a42008-08-24 21:50:06 -0400459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500463 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500470 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
James Smart2e0fef82007-06-17 19:56:36 -0500478
dea31012005-04-17 16:05:31 -0500479 return len;
480}
481
James Smarte59058c2008-08-24 21:49:00 -0400482/**
James Smart84d1b002010-02-12 14:42:33 -0500483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494static ssize_t
495lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515}
516
517/**
James Smart3621a712009-04-06 18:47:14 -0400518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
dea31012005-04-17 16:05:31 -0500529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700554static int
James Smart2e0fef82007-06-17 19:56:36 -0500555lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500556{
James Smart2e0fef82007-06-17 19:56:36 -0500557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
James Smart2e0fef82007-06-17 19:56:36 -0500562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400574
James Smart33ccf8d2006-08-17 11:57:58 -0400575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500576
James Smart04c68492009-05-22 14:52:52 -0400577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400590 }
591
James Smart5b8bd0c2007-04-25 09:52:49 -0400592 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500593 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400594 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700599 return 0;
dea31012005-04-17 16:05:31 -0500600}
601
James Smarte59058c2008-08-24 21:49:00 -0400602/**
James Smart3621a712009-04-06 18:47:14 -0400603 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
James Smart40496f02006-07-06 15:50:22 -0400617static int
James Smart46fa3112007-04-25 09:51:45 -0400618lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
619{
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500626 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400627
628 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400630 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500631 if (rc == 0)
632 return -ENOMEM;
633
James Smart46fa3112007-04-25 09:51:45 -0400634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
James Smart09372822008-01-11 01:52:54 -0500641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
James Smart46fa3112007-04-25 09:51:45 -0400644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400646 while (pring->txcmplq_cnt) {
647 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500648 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
James Smart46fa3112007-04-25 09:51:45 -0400663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669}
670
James Smarte59058c2008-08-24 21:49:00 -0400671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500681 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400682 *
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
687 **/
James Smart7f860592011-03-11 16:05:52 -0500688int
James Smart40496f02006-07-06 15:50:22 -0400689lpfc_selective_reset(struct lpfc_hba *phba)
690{
691 struct completion online_compl;
692 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500693 int rc;
James Smart40496f02006-07-06 15:50:22 -0400694
James Smart13815c82008-01-11 01:52:48 -0500695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
697
James Smart46fa3112007-04-25 09:51:45 -0400698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400699
700 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400701 return status;
James Smart40496f02006-07-06 15:50:22 -0400702
703 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400705 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500706 if (rc == 0)
707 return -ENOMEM;
708
James Smart40496f02006-07-06 15:50:22 -0400709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 return 0;
715}
716
James Smarte59058c2008-08-24 21:49:00 -0400717/**
James Smart3621a712009-04-06 18:47:14 -0400718 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
723 *
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
727 *
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200731 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400732 *
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
737**/
James Smart40496f02006-07-06 15:50:22 -0400738static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100739lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400741{
Tony Jonesee959b02008-02-22 00:13:36 +0100742 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
745
James Smart40496f02006-07-06 15:50:22 -0400746 int status = -EINVAL;
747
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500749 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400750
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
755}
756
James Smarte59058c2008-08-24 21:49:00 -0400757/**
James Smart3621a712009-04-06 18:47:14 -0400758 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400759 * @dev: class device that is converted into a Scsi_host.
760 * @attr: device attribute, not used.
761 * @buf: on return contains the ascii number of nport events.
762 *
763 * Returns: size of formatted string.
764 **/
dea31012005-04-17 16:05:31 -0500765static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100766lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
767 char *buf)
dea31012005-04-17 16:05:31 -0500768{
Tony Jonesee959b02008-02-22 00:13:36 +0100769 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
771 struct lpfc_hba *phba = vport->phba;
772
dea31012005-04-17 16:05:31 -0500773 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
774}
775
James Smarte59058c2008-08-24 21:49:00 -0400776/**
James Smart3621a712009-04-06 18:47:14 -0400777 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400778 * @dev: class device that is converted into a Scsi_host.
779 * @attr: device attribute, not used.
780 * @buf: on return contains the state of the adapter.
781 *
782 * Returns: size of formatted string.
783 **/
dea31012005-04-17 16:05:31 -0500784static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100785lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
786 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500787{
Tony Jonesee959b02008-02-22 00:13:36 +0100788 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
790 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500791 char * state;
792
James Smart2e0fef82007-06-17 19:56:36 -0500793 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500794 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500795 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500796 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500797 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500798 state = "offline";
799 else
800 state = "online";
801
802 return snprintf(buf, PAGE_SIZE, "%s\n", state);
803}
804
James Smarte59058c2008-08-24 21:49:00 -0400805/**
James Smart3621a712009-04-06 18:47:14 -0400806 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400807 * @dev: class device that is converted into a Scsi_host.
808 * @attr: device attribute, not used.
809 * @buf: containing one of the strings "online", "offline", "warm" or "error".
810 * @count: unused variable.
811 *
812 * Returns:
813 * -EACCES if enable hba reset not enabled
814 * -EINVAL if the buffer does not contain a valid string (see above)
815 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
816 * buf length greater than zero indicates success
817 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500818static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100819lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
820 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500821{
Tony Jonesee959b02008-02-22 00:13:36 +0100822 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
824 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500825 struct completion online_compl;
826 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500827 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500828
James Smart13815c82008-01-11 01:52:48 -0500829 if (!phba->cfg_enable_hba_reset)
830 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500831 init_completion(&online_compl);
832
James Smart46fa3112007-04-25 09:51:45 -0400833 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500834 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500835 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500836 if (rc == 0)
837 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400838 wait_for_completion(&online_compl);
839 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
840 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500841 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400842 if (phba->sli_rev == LPFC_SLI_REV4)
843 return -EINVAL;
844 else
845 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400846 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400847 if (phba->sli_rev == LPFC_SLI_REV4)
848 return -EINVAL;
849 else
850 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500851 else
852 return -EINVAL;
853
Jamie Wellnitz41415862006-02-28 19:25:27 -0500854 if (!status)
855 return strlen(buf);
856 else
857 return -EIO;
858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart3621a712009-04-06 18:47:14 -0400861 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400862 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400863 * @mxri: max xri count.
864 * @axri: available xri count.
865 * @mrpi: max rpi count.
866 * @arpi: available rpi count.
867 * @mvpi: max vpi count.
868 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400869 *
870 * Description:
871 * If an integer pointer for an count is not null then the value for the
872 * count is returned.
873 *
874 * Returns:
875 * zero on error
876 * one for success
877 **/
James Smart311464e2007-08-02 11:10:37 -0400878static int
James Smart858c9f62007-06-17 19:56:39 -0500879lpfc_get_hba_info(struct lpfc_hba *phba,
880 uint32_t *mxri, uint32_t *axri,
881 uint32_t *mrpi, uint32_t *arpi,
882 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500883{
James Smart04c68492009-05-22 14:52:52 -0400884 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500885 LPFC_MBOXQ_t *pmboxq;
886 MAILBOX_t *pmb;
887 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400888 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500889
890 /*
891 * prevent udev from issuing mailbox commands until the port is
892 * configured.
893 */
894 if (phba->link_state < LPFC_LINK_DOWN ||
895 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400896 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500897 return 0;
898
899 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
900 return 0;
901
902 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
903 if (!pmboxq)
904 return 0;
905 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
906
James Smart04c68492009-05-22 14:52:52 -0400907 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500908 pmb->mbxCommand = MBX_READ_CONFIG;
909 pmb->mbxOwner = OWN_HOST;
910 pmboxq->context1 = NULL;
911
James Smart75baf692010-06-08 18:31:21 -0400912 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500913 rc = MBX_NOT_FINISHED;
914 else
915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
916
917 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500918 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500919 mempool_free(pmboxq, phba->mbox_mem_pool);
920 return 0;
921 }
922
James Smartda0436e2009-05-22 14:51:39 -0400923 if (phba->sli_rev == LPFC_SLI_REV4) {
924 rd_config = &pmboxq->u.mqe.un.rd_config;
925 if (mrpi)
926 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
927 if (arpi)
928 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
929 phba->sli4_hba.max_cfg_param.rpi_used;
930 if (mxri)
931 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
932 if (axri)
933 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
934 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400935
936 /* Account for differences with SLI-3. Get vpi count from
937 * mailbox data and subtract one for max vpi value.
938 */
939 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
940 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
941
James Smartda0436e2009-05-22 14:51:39 -0400942 if (mvpi)
James Smart15672312010-04-06 14:49:03 -0400943 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -0400944 if (avpi)
James Smart15672312010-04-06 14:49:03 -0400945 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -0400946 } else {
947 if (mrpi)
948 *mrpi = pmb->un.varRdConfig.max_rpi;
949 if (arpi)
950 *arpi = pmb->un.varRdConfig.avail_rpi;
951 if (mxri)
952 *mxri = pmb->un.varRdConfig.max_xri;
953 if (axri)
954 *axri = pmb->un.varRdConfig.avail_xri;
955 if (mvpi)
956 *mvpi = pmb->un.varRdConfig.max_vpi;
957 if (avpi)
958 *avpi = pmb->un.varRdConfig.avail_vpi;
959 }
James Smart92d7f7b2007-06-17 19:56:38 -0500960
961 mempool_free(pmboxq, phba->mbox_mem_pool);
962 return 1;
963}
964
James Smarte59058c2008-08-24 21:49:00 -0400965/**
James Smart3621a712009-04-06 18:47:14 -0400966 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400967 * @dev: class device that is converted into a Scsi_host.
968 * @attr: device attribute, not used.
969 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
970 *
971 * Description:
972 * Calls lpfc_get_hba_info() asking for just the mrpi count.
973 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
974 * to "Unknown" and the buffer length is returned, therefore the caller
975 * must check for "Unknown" in the buffer to detect a failure.
976 *
977 * Returns: size of formatted string.
978 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500979static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100980lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500982{
Tony Jonesee959b02008-02-22 00:13:36 +0100983 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986 uint32_t cnt;
987
James Smart858c9f62007-06-17 19:56:39 -0500988 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500989 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
990 return snprintf(buf, PAGE_SIZE, "Unknown\n");
991}
992
James Smarte59058c2008-08-24 21:49:00 -0400993/**
James Smart3621a712009-04-06 18:47:14 -0400994 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400995 * @dev: class device that is converted into a Scsi_host.
996 * @attr: device attribute, not used.
997 * @buf: containing the used rpi count in decimal or "Unknown".
998 *
999 * Description:
1000 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1001 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1002 * to "Unknown" and the buffer length is returned, therefore the caller
1003 * must check for "Unknown" in the buffer to detect a failure.
1004 *
1005 * Returns: size of formatted string.
1006 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001007static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001008lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1009 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001010{
Tony Jonesee959b02008-02-22 00:13:36 +01001011 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 struct lpfc_hba *phba = vport->phba;
1014 uint32_t cnt, acnt;
1015
James Smart858c9f62007-06-17 19:56:39 -05001016 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001017 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1018 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1026 *
1027 * Description:
1028 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1029 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1030 * to "Unknown" and the buffer length is returned, therefore the caller
1031 * must check for "Unknown" in the buffer to detect a failure.
1032 *
1033 * Returns: size of formatted string.
1034 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001035static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001036lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1037 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001038{
Tony Jonesee959b02008-02-22 00:13:36 +01001039 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1042 uint32_t cnt;
1043
James Smart858c9f62007-06-17 19:56:39 -05001044 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001045 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1046 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1047}
1048
James Smarte59058c2008-08-24 21:49:00 -04001049/**
James Smart3621a712009-04-06 18:47:14 -04001050 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001051 * @dev: class device that is converted into a Scsi_host.
1052 * @attr: device attribute, not used.
1053 * @buf: on return contains the used xri count in decimal or "Unknown".
1054 *
1055 * Description:
1056 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1057 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1058 * to "Unknown" and the buffer length is returned, therefore the caller
1059 * must check for "Unknown" in the buffer to detect a failure.
1060 *
1061 * Returns: size of formatted string.
1062 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001063static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001064lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1065 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001066{
Tony Jonesee959b02008-02-22 00:13:36 +01001067 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
1070 uint32_t cnt, acnt;
1071
James Smart858c9f62007-06-17 19:56:39 -05001072 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1073 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1074 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1075}
1076
James Smarte59058c2008-08-24 21:49:00 -04001077/**
James Smart3621a712009-04-06 18:47:14 -04001078 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001079 * @dev: class device that is converted into a Scsi_host.
1080 * @attr: device attribute, not used.
1081 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1082 *
1083 * Description:
1084 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1085 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1086 * to "Unknown" and the buffer length is returned, therefore the caller
1087 * must check for "Unknown" in the buffer to detect a failure.
1088 *
1089 * Returns: size of formatted string.
1090 **/
James Smart858c9f62007-06-17 19:56:39 -05001091static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001092lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001094{
Tony Jonesee959b02008-02-22 00:13:36 +01001095 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1098 uint32_t cnt;
1099
1100 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1101 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1102 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1103}
1104
James Smarte59058c2008-08-24 21:49:00 -04001105/**
James Smart3621a712009-04-06 18:47:14 -04001106 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the used vpi count in decimal or "Unknown".
1110 *
1111 * Description:
1112 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1116 *
1117 * Returns: size of formatted string.
1118 **/
James Smart858c9f62007-06-17 19:56:39 -05001119static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001120lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1121 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001122{
Tony Jonesee959b02008-02-22 00:13:36 +01001123 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1125 struct lpfc_hba *phba = vport->phba;
1126 uint32_t cnt, acnt;
1127
1128 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001129 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1130 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1131}
1132
James Smarte59058c2008-08-24 21:49:00 -04001133/**
James Smart3621a712009-04-06 18:47:14 -04001134 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: text that must be interpreted to determine if npiv is supported.
1138 *
1139 * Description:
1140 * Buffer will contain text indicating npiv is not suppoerted on the port,
1141 * the port is an NPIV physical port, or it is an npiv virtual port with
1142 * the id of the vport.
1143 *
1144 * Returns: size of formatted string.
1145 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001146static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001147lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1148 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001149{
Tony Jonesee959b02008-02-22 00:13:36 +01001150 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 struct lpfc_hba *phba = vport->phba;
1153
1154 if (!(phba->max_vpi))
1155 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1156 if (vport->port_type == LPFC_PHYSICAL_PORT)
1157 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1158 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1159}
1160
James Smarte59058c2008-08-24 21:49:00 -04001161/**
James Smart3621a712009-04-06 18:47:14 -04001162 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the cfg_poll in hex.
1166 *
1167 * Notes:
1168 * cfg_poll should be a lpfc_polling_flags type.
1169 *
1170 * Returns: size of formatted string.
1171 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001172static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001173lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1174 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001175{
Tony Jonesee959b02008-02-22 00:13:36 +01001176 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1178 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001179
1180 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1181}
1182
James Smarte59058c2008-08-24 21:49:00 -04001183/**
James Smart3621a712009-04-06 18:47:14 -04001184 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001185 * @dev: class device that is converted into a Scsi_host.
1186 * @attr: device attribute, not used.
1187 * @buf: one or more lpfc_polling_flags values.
1188 * @count: not used.
1189 *
1190 * Notes:
1191 * buf contents converted to integer and checked for a valid value.
1192 *
1193 * Returns:
1194 * -EINVAL if the buffer connot be converted or is out of range
1195 * length of the buf on success
1196 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001197static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001198lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1199 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001200{
Tony Jonesee959b02008-02-22 00:13:36 +01001201 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1203 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001204 uint32_t creg_val;
1205 uint32_t old_val;
1206 int val=0;
1207
1208 if (!isdigit(buf[0]))
1209 return -EINVAL;
1210
1211 if (sscanf(buf, "%i", &val) != 1)
1212 return -EINVAL;
1213
1214 if ((val & 0x3) != val)
1215 return -EINVAL;
1216
James Smart45ed1192009-10-02 15:17:02 -04001217 if (phba->sli_rev == LPFC_SLI_REV4)
1218 val = 0;
1219
James Smart2e0fef82007-06-17 19:56:36 -05001220 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001221
1222 old_val = phba->cfg_poll;
1223
1224 if (val & ENABLE_FCP_RING_POLLING) {
1225 if ((val & DISABLE_FCP_RING_INT) &&
1226 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001227 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1228 spin_unlock_irq(&phba->hbalock);
1229 return -EINVAL;
1230 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001231 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1234
1235 lpfc_poll_start_timer(phba);
1236 }
1237 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001238 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001239 return -EINVAL;
1240 }
1241
1242 if (!(val & DISABLE_FCP_RING_INT) &&
1243 (old_val & DISABLE_FCP_RING_INT))
1244 {
James Smart2e0fef82007-06-17 19:56:36 -05001245 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001246 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001247 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001248 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1249 spin_unlock_irq(&phba->hbalock);
1250 return -EINVAL;
1251 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001252 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1253 writel(creg_val, phba->HCregaddr);
1254 readl(phba->HCregaddr); /* flush */
1255 }
1256
1257 phba->cfg_poll = val;
1258
James Smart2e0fef82007-06-17 19:56:36 -05001259 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001260
1261 return strlen(buf);
1262}
dea31012005-04-17 16:05:31 -05001263
James Smarte59058c2008-08-24 21:49:00 -04001264/**
James Smartbc739052010-08-04 16:11:18 -04001265 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1266 * @dev: class unused variable.
1267 * @attr: device attribute, not used.
1268 * @buf: on return contains the module description text.
1269 *
1270 * Returns: size of formatted string.
1271 **/
1272static ssize_t
1273lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1274 char *buf)
1275{
1276 struct Scsi_Host *shost = class_to_shost(dev);
1277 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1278 struct lpfc_hba *phba = vport->phba;
1279
1280 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1281}
1282
1283/**
1284 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1285 * @dev: class unused variable.
1286 * @attr: device attribute, not used.
1287 * @buf: on return contains the module description text.
1288 *
1289 * Returns: size of formatted string.
1290 **/
1291static ssize_t
1292lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1293 char *buf)
1294{
1295 struct Scsi_Host *shost = class_to_shost(dev);
1296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1297 struct lpfc_hba *phba = vport->phba;
1298
1299 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1300}
1301
1302/**
James Smartab56dc22011-02-16 12:39:57 -05001303 * lpfc_dss_show - Return the current state of dss and the configured state
1304 * @dev: class converted to a Scsi_host structure.
1305 * @attr: device attribute, not used.
1306 * @buf: on return contains the formatted text.
1307 *
1308 * Returns: size of formatted string.
1309 **/
1310static ssize_t
1311lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1312 char *buf)
1313{
1314 struct Scsi_Host *shost = class_to_shost(dev);
1315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1316 struct lpfc_hba *phba = vport->phba;
1317
1318 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1319 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1320 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1321 "" : "Not ");
1322}
1323
1324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001326 *
1327 * Description:
1328 * Macro that given an attr e.g. hba_queue_depth expands
1329 * into a function with the name lpfc_hba_queue_depth_show.
1330 *
1331 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1332 * @dev: class device that is converted into a Scsi_host.
1333 * @attr: device attribute, not used.
1334 * @buf: on return contains the attribute value in decimal.
1335 *
1336 * Returns: size of formatted string.
1337 **/
dea31012005-04-17 16:05:31 -05001338#define lpfc_param_show(attr) \
1339static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001340lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1341 char *buf) \
dea31012005-04-17 16:05:31 -05001342{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001343 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1345 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001346 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001347 val = phba->cfg_##attr;\
1348 return snprintf(buf, PAGE_SIZE, "%d\n",\
1349 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001350}
1351
James Smarte59058c2008-08-24 21:49:00 -04001352/**
James Smart3621a712009-04-06 18:47:14 -04001353 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001354 *
1355 * Description:
1356 * Macro that given an attr e.g. hba_queue_depth expands
1357 * into a function with the name lpfc_hba_queue_depth_show
1358 *
1359 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1360 * @dev: class device that is converted into a Scsi_host.
1361 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001362 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001363 *
1364 * Returns: size of formatted string.
1365 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001366#define lpfc_param_hex_show(attr) \
1367static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001368lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1369 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001370{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001371 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1373 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001374 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001375 val = phba->cfg_##attr;\
1376 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1377 phba->cfg_##attr);\
1378}
1379
James Smarte59058c2008-08-24 21:49:00 -04001380/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001381 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001382 *
1383 * Description:
1384 * Macro that given an attr e.g. hba_queue_depth expands
1385 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1386 * takes a default argument, a minimum and maximum argument.
1387 *
1388 * lpfc_##attr##_init: Initializes an attribute.
1389 * @phba: pointer the the adapter structure.
1390 * @val: integer attribute value.
1391 *
1392 * Validates the min and max values then sets the adapter config field
1393 * accordingly, or uses the default if out of range and prints an error message.
1394 *
1395 * Returns:
1396 * zero on success
1397 * -EINVAL if default used
1398 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001399#define lpfc_param_init(attr, default, minval, maxval) \
1400static int \
James Smart84d1b002010-02-12 14:42:33 -05001401lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001402{ \
1403 if (val >= minval && val <= maxval) {\
1404 phba->cfg_##attr = val;\
1405 return 0;\
1406 }\
1407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001408 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1409 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001410 phba->cfg_##attr = default;\
1411 return -EINVAL;\
1412}
1413
James Smarte59058c2008-08-24 21:49:00 -04001414/**
James Smart3621a712009-04-06 18:47:14 -04001415 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001416 *
1417 * Description:
1418 * Macro that given an attr e.g. hba_queue_depth expands
1419 * into a function with the name lpfc_hba_queue_depth_set
1420 *
1421 * lpfc_##attr##_set: Sets an attribute value.
1422 * @phba: pointer the the adapter structure.
1423 * @val: integer attribute value.
1424 *
1425 * Description:
1426 * Validates the min and max values then sets the
1427 * adapter config field if in the valid range. prints error message
1428 * and does not set the parameter if invalid.
1429 *
1430 * Returns:
1431 * zero on success
1432 * -EINVAL if val is invalid
1433 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001434#define lpfc_param_set(attr, default, minval, maxval) \
1435static int \
James Smart84d1b002010-02-12 14:42:33 -05001436lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001437{ \
1438 if (val >= minval && val <= maxval) {\
1439 phba->cfg_##attr = val;\
1440 return 0;\
1441 }\
1442 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001443 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1444 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001445 return -EINVAL;\
1446}
1447
James Smarte59058c2008-08-24 21:49:00 -04001448/**
James Smart3621a712009-04-06 18:47:14 -04001449 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001450 *
1451 * Description:
1452 * Macro that given an attr e.g. hba_queue_depth expands
1453 * into a function with the name lpfc_hba_queue_depth_store.
1454 *
1455 * lpfc_##attr##_store: Set an sttribute value.
1456 * @dev: class device that is converted into a Scsi_host.
1457 * @attr: device attribute, not used.
1458 * @buf: contains the attribute value in ascii.
1459 * @count: not used.
1460 *
1461 * Description:
1462 * Convert the ascii text number to an integer, then
1463 * use the lpfc_##attr##_set function to set the value.
1464 *
1465 * Returns:
1466 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1467 * length of buffer upon success.
1468 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001469#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001470static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001471lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1472 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001473{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001474 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001475 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1476 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001477 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001478 if (!isdigit(buf[0]))\
1479 return -EINVAL;\
1480 if (sscanf(buf, "%i", &val) != 1)\
1481 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001482 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001483 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001484 else \
1485 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001486}
1487
James Smarte59058c2008-08-24 21:49:00 -04001488/**
James Smart3621a712009-04-06 18:47:14 -04001489 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001490 *
1491 * Description:
1492 * Macro that given an attr e.g. hba_queue_depth expands
1493 * into a function with the name lpfc_hba_queue_depth_show
1494 *
1495 * lpfc_##attr##_show: prints the attribute value in decimal.
1496 * @dev: class device that is converted into a Scsi_host.
1497 * @attr: device attribute, not used.
1498 * @buf: on return contains the attribute value in decimal.
1499 *
1500 * Returns: length of formatted string.
1501 **/
James Smart3de2a652007-08-02 11:09:59 -04001502#define lpfc_vport_param_show(attr) \
1503static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001504lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1505 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001506{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001507 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001509 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001510 val = vport->cfg_##attr;\
1511 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1512}
1513
James Smarte59058c2008-08-24 21:49:00 -04001514/**
James Smart3621a712009-04-06 18:47:14 -04001515 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001516 *
1517 * Description:
1518 * Macro that given an attr e.g.
1519 * hba_queue_depth expands into a function with the name
1520 * lpfc_hba_queue_depth_show
1521 *
James Smart3621a712009-04-06 18:47:14 -04001522 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001523 * @dev: class device that is converted into a Scsi_host.
1524 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001525 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001526 *
1527 * Returns: length of formatted string.
1528 **/
James Smart3de2a652007-08-02 11:09:59 -04001529#define lpfc_vport_param_hex_show(attr) \
1530static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001531lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1532 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001533{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001534 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001536 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001537 val = vport->cfg_##attr;\
1538 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1539}
1540
James Smarte59058c2008-08-24 21:49:00 -04001541/**
James Smart3621a712009-04-06 18:47:14 -04001542 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001543 *
1544 * Description:
1545 * Macro that given an attr e.g. hba_queue_depth expands
1546 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1547 * takes a default argument, a minimum and maximum argument.
1548 *
1549 * lpfc_##attr##_init: validates the min and max values then sets the
1550 * adapter config field accordingly, or uses the default if out of range
1551 * and prints an error message.
1552 * @phba: pointer the the adapter structure.
1553 * @val: integer attribute value.
1554 *
1555 * Returns:
1556 * zero on success
1557 * -EINVAL if default used
1558 **/
James Smart3de2a652007-08-02 11:09:59 -04001559#define lpfc_vport_param_init(attr, default, minval, maxval) \
1560static int \
James Smart84d1b002010-02-12 14:42:33 -05001561lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001562{ \
1563 if (val >= minval && val <= maxval) {\
1564 vport->cfg_##attr = val;\
1565 return 0;\
1566 }\
James Smarte8b62012007-08-02 11:10:09 -04001567 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001568 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001569 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001570 vport->cfg_##attr = default;\
1571 return -EINVAL;\
1572}
1573
James Smarte59058c2008-08-24 21:49:00 -04001574/**
James Smart3621a712009-04-06 18:47:14 -04001575 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001576 *
1577 * Description:
1578 * Macro that given an attr e.g. hba_queue_depth expands
1579 * into a function with the name lpfc_hba_queue_depth_set
1580 *
1581 * lpfc_##attr##_set: validates the min and max values then sets the
1582 * adapter config field if in the valid range. prints error message
1583 * and does not set the parameter if invalid.
1584 * @phba: pointer the the adapter structure.
1585 * @val: integer attribute value.
1586 *
1587 * Returns:
1588 * zero on success
1589 * -EINVAL if val is invalid
1590 **/
James Smart3de2a652007-08-02 11:09:59 -04001591#define lpfc_vport_param_set(attr, default, minval, maxval) \
1592static int \
James Smart84d1b002010-02-12 14:42:33 -05001593lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001594{ \
1595 if (val >= minval && val <= maxval) {\
1596 vport->cfg_##attr = val;\
1597 return 0;\
1598 }\
James Smarte8b62012007-08-02 11:10:09 -04001599 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001600 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001601 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001602 return -EINVAL;\
1603}
1604
James Smarte59058c2008-08-24 21:49:00 -04001605/**
James Smart3621a712009-04-06 18:47:14 -04001606 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001607 *
1608 * Description:
1609 * Macro that given an attr e.g. hba_queue_depth
1610 * expands into a function with the name lpfc_hba_queue_depth_store
1611 *
1612 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1613 * use the lpfc_##attr##_set function to set the value.
1614 * @cdev: class device that is converted into a Scsi_host.
1615 * @buf: contains the attribute value in decimal.
1616 * @count: not used.
1617 *
1618 * Returns:
1619 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1620 * length of buffer upon success.
1621 **/
James Smart3de2a652007-08-02 11:09:59 -04001622#define lpfc_vport_param_store(attr) \
1623static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001624lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1625 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001626{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001627 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001629 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001630 if (!isdigit(buf[0]))\
1631 return -EINVAL;\
1632 if (sscanf(buf, "%i", &val) != 1)\
1633 return -EINVAL;\
1634 if (lpfc_##attr##_set(vport, val) == 0) \
1635 return strlen(buf);\
1636 else \
1637 return -EINVAL;\
1638}
1639
1640
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001641#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001642static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001643module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001644MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001645lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001646
1647#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001648static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001649module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001650MODULE_PARM_DESC(lpfc_##name, desc);\
1651lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001652lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001653static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001654
1655#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001656static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001657module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001658MODULE_PARM_DESC(lpfc_##name, desc);\
1659lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001660lpfc_param_init(name, defval, minval, maxval)\
1661lpfc_param_set(name, defval, minval, maxval)\
1662lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001663static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1664 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001665
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001666#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001667static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001668module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001669MODULE_PARM_DESC(lpfc_##name, desc);\
1670lpfc_param_hex_show(name)\
1671lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001672static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001673
1674#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001675static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001676module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001677MODULE_PARM_DESC(lpfc_##name, desc);\
1678lpfc_param_hex_show(name)\
1679lpfc_param_init(name, defval, minval, maxval)\
1680lpfc_param_set(name, defval, minval, maxval)\
1681lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001682static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1683 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001684
James Smart3de2a652007-08-02 11:09:59 -04001685#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001686static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001687module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001688MODULE_PARM_DESC(lpfc_##name, desc);\
1689lpfc_vport_param_init(name, defval, minval, maxval)
1690
1691#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001692static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001693module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001694MODULE_PARM_DESC(lpfc_##name, desc);\
1695lpfc_vport_param_show(name)\
1696lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001697static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001698
1699#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001700static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001701module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001702MODULE_PARM_DESC(lpfc_##name, desc);\
1703lpfc_vport_param_show(name)\
1704lpfc_vport_param_init(name, defval, minval, maxval)\
1705lpfc_vport_param_set(name, defval, minval, maxval)\
1706lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001707static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1708 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001709
1710#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001711static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001712module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001713MODULE_PARM_DESC(lpfc_##name, desc);\
1714lpfc_vport_param_hex_show(name)\
1715lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001716static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001717
1718#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001719static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001720module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001721MODULE_PARM_DESC(lpfc_##name, desc);\
1722lpfc_vport_param_hex_show(name)\
1723lpfc_vport_param_init(name, defval, minval, maxval)\
1724lpfc_vport_param_set(name, defval, minval, maxval)\
1725lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001726static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1727 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001728
James Smart81301a92008-12-04 22:39:46 -05001729static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1730static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1731static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1732static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001733static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1734static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1735static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1736static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1737static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1738static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1739static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1740static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001741static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1742 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001743static DEVICE_ATTR(option_rom_version, S_IRUGO,
1744 lpfc_option_rom_version_show, NULL);
1745static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1746 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001747static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001748static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1749static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001750static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001751static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1752 lpfc_board_mode_show, lpfc_board_mode_store);
1753static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1754static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1755static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1756static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1757static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1758static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1759static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1760static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1761static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001762static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1763static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001764static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001765
James Smarta12e07b2006-12-02 13:35:30 -05001766static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001767
James Smarte59058c2008-08-24 21:49:00 -04001768/**
James Smart3621a712009-04-06 18:47:14 -04001769 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001770 * @dev: class device that is converted into a Scsi_host.
1771 * @attr: device attribute, not used.
1772 * @buf: containing the string lpfc_soft_wwn_key.
1773 * @count: must be size of lpfc_soft_wwn_key.
1774 *
1775 * Returns:
1776 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1777 * length of buf indicates success
1778 **/
James Smartc3f28af2006-08-18 17:47:18 -04001779static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001780lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1781 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001782{
Tony Jonesee959b02008-02-22 00:13:36 +01001783 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1785 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001786 unsigned int cnt = count;
1787
1788 /*
1789 * We're doing a simple sanity check for soft_wwpn setting.
1790 * We require that the user write a specific key to enable
1791 * the soft_wwpn attribute to be settable. Once the attribute
1792 * is written, the enable key resets. If further updates are
1793 * desired, the key must be written again to re-enable the
1794 * attribute.
1795 *
1796 * The "key" is not secret - it is a hardcoded string shown
1797 * here. The intent is to protect against the random user or
1798 * application that is just writing attributes.
1799 */
1800
1801 /* count may include a LF at end of string */
1802 if (buf[cnt-1] == '\n')
1803 cnt--;
1804
James Smarta12e07b2006-12-02 13:35:30 -05001805 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1806 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001807 return -EINVAL;
1808
James Smarta12e07b2006-12-02 13:35:30 -05001809 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001810 return count;
1811}
Tony Jonesee959b02008-02-22 00:13:36 +01001812static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1813 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001814
James Smarte59058c2008-08-24 21:49:00 -04001815/**
James Smart3621a712009-04-06 18:47:14 -04001816 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001817 * @dev: class device that is converted into a Scsi_host.
1818 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001819 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001820 *
1821 * Returns: size of formatted string.
1822 **/
James Smartc3f28af2006-08-18 17:47:18 -04001823static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001824lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1825 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001826{
Tony Jonesee959b02008-02-22 00:13:36 +01001827 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001828 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1829 struct lpfc_hba *phba = vport->phba;
1830
Randy Dunlapafc071e62006-10-23 21:47:13 -07001831 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1832 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001833}
1834
James Smarte59058c2008-08-24 21:49:00 -04001835/**
James Smart3621a712009-04-06 18:47:14 -04001836 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001837 * @dev class device that is converted into a Scsi_host.
1838 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001839 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001840 * @count: number of wwpn bytes in buf
1841 *
1842 * Returns:
1843 * -EACCES hba reset not enabled, adapter over temp
1844 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1845 * -EIO error taking adapter offline or online
1846 * value of count on success
1847 **/
James Smartc3f28af2006-08-18 17:47:18 -04001848static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001849lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1850 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001851{
Tony Jonesee959b02008-02-22 00:13:36 +01001852 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001855 struct completion online_compl;
1856 int stat1=0, stat2=0;
1857 unsigned int i, j, cnt=count;
1858 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05001859 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04001860
James Smart13815c82008-01-11 01:52:48 -05001861 if (!phba->cfg_enable_hba_reset)
1862 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001863 spin_lock_irq(&phba->hbalock);
1864 if (phba->over_temp_state == HBA_OVER_TEMP) {
1865 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001866 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001867 }
1868 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001869 /* count may include a LF at end of string */
1870 if (buf[cnt-1] == '\n')
1871 cnt--;
1872
James Smarta12e07b2006-12-02 13:35:30 -05001873 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001874 ((cnt == 17) && (*buf++ != 'x')) ||
1875 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1876 return -EINVAL;
1877
James Smarta12e07b2006-12-02 13:35:30 -05001878 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001879
1880 memset(wwpn, 0, sizeof(wwpn));
1881
1882 /* Validate and store the new name */
1883 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001884 int value;
1885
1886 value = hex_to_bin(*buf++);
1887 if (value >= 0)
1888 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04001889 else
1890 return -EINVAL;
1891 if (i % 2) {
1892 wwpn[i/2] = j & 0xff;
1893 j = 0;
1894 }
1895 }
1896 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001897 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001898 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001899 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001900
1901 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1902 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1903
James Smart46fa3112007-04-25 09:51:45 -04001904 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001905 if (stat1)
1906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001907 "0463 lpfc_soft_wwpn attribute set failed to "
1908 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001909 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001910 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1911 LPFC_EVT_ONLINE);
1912 if (rc == 0)
1913 return -ENOMEM;
1914
James Smartc3f28af2006-08-18 17:47:18 -04001915 wait_for_completion(&online_compl);
1916 if (stat2)
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001918 "0464 lpfc_soft_wwpn attribute set failed to "
1919 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001920 return (stat1 || stat2) ? -EIO : count;
1921}
Tony Jonesee959b02008-02-22 00:13:36 +01001922static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1923 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001924
James Smarte59058c2008-08-24 21:49:00 -04001925/**
James Smart3621a712009-04-06 18:47:14 -04001926 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001927 * @dev: class device that is converted into a Scsi_host.
1928 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001929 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001930 *
1931 * Returns: size of formatted string.
1932 **/
James Smarta12e07b2006-12-02 13:35:30 -05001933static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001934lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1935 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001936{
Tony Jonesee959b02008-02-22 00:13:36 +01001937 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001938 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001939 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1940 (unsigned long long)phba->cfg_soft_wwnn);
1941}
1942
James Smarte59058c2008-08-24 21:49:00 -04001943/**
James Smart3621a712009-04-06 18:47:14 -04001944 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001945 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001946 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001947 * @count: number of wwnn bytes in buf.
1948 *
1949 * Returns:
1950 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1951 * value of count on success
1952 **/
James Smarta12e07b2006-12-02 13:35:30 -05001953static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001954lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1955 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001956{
Tony Jonesee959b02008-02-22 00:13:36 +01001957 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001958 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001959 unsigned int i, j, cnt=count;
1960 u8 wwnn[8];
1961
1962 /* count may include a LF at end of string */
1963 if (buf[cnt-1] == '\n')
1964 cnt--;
1965
1966 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1967 ((cnt == 17) && (*buf++ != 'x')) ||
1968 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1969 return -EINVAL;
1970
1971 /*
1972 * Allow wwnn to be set many times, as long as the enable is set.
1973 * However, once the wwpn is set, everything locks.
1974 */
1975
1976 memset(wwnn, 0, sizeof(wwnn));
1977
1978 /* Validate and store the new name */
1979 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001980 int value;
1981
1982 value = hex_to_bin(*buf++);
1983 if (value >= 0)
1984 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05001985 else
1986 return -EINVAL;
1987 if (i % 2) {
1988 wwnn[i/2] = j & 0xff;
1989 j = 0;
1990 }
1991 }
1992 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1993
1994 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1995 "lpfc%d: soft_wwnn set. Value will take effect upon "
1996 "setting of the soft_wwpn\n", phba->brd_no);
1997
1998 return count;
1999}
Tony Jonesee959b02008-02-22 00:13:36 +01002000static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2001 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002002
James Smartc3f28af2006-08-18 17:47:18 -04002003
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002004static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002005module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002006MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2007 " 0 - none,"
2008 " 1 - poll with interrupts enabled"
2009 " 3 - poll and disable FCP ring interrupts");
2010
Tony Jonesee959b02008-02-22 00:13:36 +01002011static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2012 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002013
James Smart92d7f7b2007-06-17 19:56:38 -05002014int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002015module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002016MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2017 " 0 - auto (SLI-3 if supported),"
2018 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2019 " 3 - select SLI-3");
2020
James Smart15672312010-04-06 14:49:03 -04002021int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002022module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002023MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2024lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002025lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002026static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002027
James Smart19ca7602010-11-20 23:11:55 -05002028int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002029module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002030MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2031lpfc_param_show(enable_rrq);
2032lpfc_param_init(enable_rrq, 0, 0, 1);
2033static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2034
dea31012005-04-17 16:05:31 -05002035/*
James Smart84d1b002010-02-12 14:42:33 -05002036# lpfc_suppress_link_up: Bring link up at initialization
2037# 0x0 = bring link up (issue MBX_INIT_LINK)
2038# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2039# 0x2 = never bring up link
2040# Default value is 0.
2041*/
James Smarte40a02c2010-02-26 14:13:54 -05002042LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2043 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2044 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002045/*
2046# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2047# 1 - (1024)
2048# 2 - (2048)
2049# 3 - (3072)
2050# 4 - (4096)
2051# 5 - (5120)
2052*/
2053static ssize_t
2054lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2055{
2056 struct Scsi_Host *shost = class_to_shost(dev);
2057 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2058
2059 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2060}
2061
2062static DEVICE_ATTR(iocb_hw, S_IRUGO,
2063 lpfc_iocb_hw_show, NULL);
2064static ssize_t
2065lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2066{
2067 struct Scsi_Host *shost = class_to_shost(dev);
2068 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2069
2070 return snprintf(buf, PAGE_SIZE, "%d\n",
2071 phba->sli.ring[LPFC_ELS_RING].txq_max);
2072}
2073
2074static DEVICE_ATTR(txq_hw, S_IRUGO,
2075 lpfc_txq_hw_show, NULL);
2076static ssize_t
2077lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2078 char *buf)
2079{
2080 struct Scsi_Host *shost = class_to_shost(dev);
2081 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2082
2083 return snprintf(buf, PAGE_SIZE, "%d\n",
2084 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2085}
2086
2087static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2088 lpfc_txcmplq_hw_show, NULL);
2089
2090int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002091module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002092MODULE_PARM_DESC(lpfc_iocb_cnt,
2093 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2094lpfc_param_show(iocb_cnt);
2095lpfc_param_init(iocb_cnt, 2, 1, 5);
2096static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2097 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002098
2099/*
James Smartc01f3202006-08-18 17:47:08 -04002100# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2101# until the timer expires. Value range is [0,255]. Default value is 30.
2102*/
2103static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2104static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2105module_param(lpfc_nodev_tmo, int, 0);
2106MODULE_PARM_DESC(lpfc_nodev_tmo,
2107 "Seconds driver will hold I/O waiting "
2108 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002109
2110/**
James Smart3621a712009-04-06 18:47:14 -04002111 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002112 * @dev: class converted to a Scsi_host structure.
2113 * @attr: device attribute, not used.
2114 * @buf: on return contains the dev loss timeout in decimal.
2115 *
2116 * Returns: size of formatted string.
2117 **/
James Smartc01f3202006-08-18 17:47:08 -04002118static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002119lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2120 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002121{
Tony Jonesee959b02008-02-22 00:13:36 +01002122 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002124
James Smart3de2a652007-08-02 11:09:59 -04002125 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002126}
2127
James Smarte59058c2008-08-24 21:49:00 -04002128/**
James Smart3621a712009-04-06 18:47:14 -04002129 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002130 * @vport: lpfc vport structure pointer.
2131 * @val: contains the nodev timeout value.
2132 *
2133 * Description:
2134 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2135 * a kernel error message is printed and zero is returned.
2136 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2137 * Otherwise nodev tmo is set to the default value.
2138 *
2139 * Returns:
2140 * zero if already set or if val is in range
2141 * -EINVAL val out of range
2142 **/
James Smartc01f3202006-08-18 17:47:08 -04002143static int
James Smart3de2a652007-08-02 11:09:59 -04002144lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002145{
James Smart3de2a652007-08-02 11:09:59 -04002146 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2147 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2148 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002150 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002151 "parameter because devloss_tmo is "
2152 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002153 return 0;
2154 }
2155
2156 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002157 vport->cfg_nodev_tmo = val;
2158 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002159 return 0;
2160 }
James Smarte8b62012007-08-02 11:10:09 -04002161 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2162 "0400 lpfc_nodev_tmo attribute cannot be set to"
2163 " %d, allowed range is [%d, %d]\n",
2164 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002165 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002166 return -EINVAL;
2167}
2168
James Smarte59058c2008-08-24 21:49:00 -04002169/**
James Smart3621a712009-04-06 18:47:14 -04002170 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002171 * @vport: lpfc vport structure pointer.
2172 *
2173 * Description:
2174 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2175 **/
James Smart7054a602007-04-25 09:52:34 -04002176static void
James Smart3de2a652007-08-02 11:09:59 -04002177lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002178{
James Smart858c9f62007-06-17 19:56:39 -05002179 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002180 struct lpfc_nodelist *ndlp;
2181
James Smart51ef4c22007-08-02 11:10:31 -04002182 shost = lpfc_shost_from_vport(vport);
2183 spin_lock_irq(shost->host_lock);
2184 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002185 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002186 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2187 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002188}
2189
James Smarte59058c2008-08-24 21:49:00 -04002190/**
James Smart3621a712009-04-06 18:47:14 -04002191 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002192 * @vport: lpfc vport structure pointer.
2193 * @val: contains the tmo value.
2194 *
2195 * Description:
2196 * If the devloss tmo is already set or the vport dev loss tmo has changed
2197 * then a kernel error message is printed and zero is returned.
2198 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2199 * Otherwise nodev tmo is set to the default value.
2200 *
2201 * Returns:
2202 * zero if already set or if val is in range
2203 * -EINVAL val out of range
2204 **/
James Smartc01f3202006-08-18 17:47:08 -04002205static int
James Smart3de2a652007-08-02 11:09:59 -04002206lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002207{
James Smart3de2a652007-08-02 11:09:59 -04002208 if (vport->dev_loss_tmo_changed ||
2209 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2211 "0401 Ignoring change to nodev_tmo "
2212 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002213 return 0;
2214 }
James Smartc01f3202006-08-18 17:47:08 -04002215 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002216 vport->cfg_nodev_tmo = val;
2217 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002218 /*
2219 * For compat: set the fc_host dev loss so new rports
2220 * will get the value.
2221 */
2222 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002223 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002224 return 0;
2225 }
James Smarte8b62012007-08-02 11:10:09 -04002226 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2227 "0403 lpfc_nodev_tmo attribute cannot be set to"
2228 "%d, allowed range is [%d, %d]\n",
2229 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002230 return -EINVAL;
2231}
2232
James Smart3de2a652007-08-02 11:09:59 -04002233lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002234
Tony Jonesee959b02008-02-22 00:13:36 +01002235static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2236 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002237
2238/*
2239# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2240# disappear until the timer expires. Value range is [0,255]. Default
2241# value is 30.
2242*/
James Smartab56dc22011-02-16 12:39:57 -05002243module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002244MODULE_PARM_DESC(lpfc_devloss_tmo,
2245 "Seconds driver will hold I/O waiting "
2246 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002247lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2248 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2249lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002250
2251/**
James Smart3621a712009-04-06 18:47:14 -04002252 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002253 * @vport: lpfc vport structure pointer.
2254 * @val: contains the tmo value.
2255 *
2256 * Description:
2257 * If val is in a valid range then set the vport nodev tmo,
2258 * devloss tmo, also set the vport dev loss tmo changed flag.
2259 * Else a kernel error message is printed.
2260 *
2261 * Returns:
2262 * zero if val is in range
2263 * -EINVAL val out of range
2264 **/
James Smartc01f3202006-08-18 17:47:08 -04002265static int
James Smart3de2a652007-08-02 11:09:59 -04002266lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002267{
2268 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002269 vport->cfg_nodev_tmo = val;
2270 vport->cfg_devloss_tmo = val;
2271 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002272 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002273 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002274 return 0;
2275 }
2276
James Smarte8b62012007-08-02 11:10:09 -04002277 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2278 "0404 lpfc_devloss_tmo attribute cannot be set to"
2279 " %d, allowed range is [%d, %d]\n",
2280 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002281 return -EINVAL;
2282}
2283
James Smart3de2a652007-08-02 11:09:59 -04002284lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002285static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2286 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002287
2288/*
dea31012005-04-17 16:05:31 -05002289# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2290# deluged with LOTS of information.
2291# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002292# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002293*/
James Smartf4b4c682009-05-22 14:53:12 -04002294LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002295 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002296
2297/*
James Smart7ee5d432007-10-27 13:37:17 -04002298# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2299# objects that have been registered with the nameserver after login.
2300*/
2301LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2302 "Deregister nameserver objects before LOGO");
2303
2304/*
dea31012005-04-17 16:05:31 -05002305# lun_queue_depth: This parameter is used to limit the number of outstanding
2306# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2307*/
James Smart3de2a652007-08-02 11:09:59 -04002308LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2309 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002310
2311/*
James Smart7dc517d2010-07-14 15:32:10 -04002312# tgt_queue_depth: This parameter is used to limit the number of outstanding
2313# commands per target port. Value range is [10,65535]. Default value is 65535.
2314*/
2315LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2316 "Max number of FCP commands we can queue to a specific target port");
2317
2318/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002319# hba_queue_depth: This parameter is used to limit the number of outstanding
2320# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2321# value is greater than the maximum number of exchanges supported by the HBA,
2322# then maximum number of exchanges supported by the HBA is used to determine
2323# the hba_queue_depth.
2324*/
2325LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2326 "Max number of FCP commands we can queue to a lpfc HBA");
2327
2328/*
James Smart92d7f7b2007-06-17 19:56:38 -05002329# peer_port_login: This parameter allows/prevents logins
2330# between peer ports hosted on the same physical port.
2331# When this parameter is set 0 peer ports of same physical port
2332# are not allowed to login to each other.
2333# When this parameter is set 1 peer ports of same physical port
2334# are allowed to login to each other.
2335# Default value of this parameter is 0.
2336*/
James Smart3de2a652007-08-02 11:09:59 -04002337LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2338 "Allow peer ports on the same physical port to login to each "
2339 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002340
2341/*
James Smart3de2a652007-08-02 11:09:59 -04002342# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002343# between Virtual Ports and remote initiators.
2344# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2345# other initiators and will attempt to PLOGI all remote ports.
2346# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2347# remote ports and will not attempt to PLOGI to other initiators.
2348# This parameter does not restrict to the physical port.
2349# This parameter does not restrict logins to Fabric resident remote ports.
2350# Default value of this parameter is 1.
2351*/
James Smart3de2a652007-08-02 11:09:59 -04002352static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002353module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002354MODULE_PARM_DESC(lpfc_restrict_login,
2355 "Restrict virtual ports login to remote initiators.");
2356lpfc_vport_param_show(restrict_login);
2357
James Smarte59058c2008-08-24 21:49:00 -04002358/**
James Smart3621a712009-04-06 18:47:14 -04002359 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002360 * @vport: lpfc vport structure pointer.
2361 * @val: contains the restrict login value.
2362 *
2363 * Description:
2364 * If val is not in a valid range then log a kernel error message and set
2365 * the vport restrict login to one.
2366 * If the port type is physical clear the restrict login flag and return.
2367 * Else set the restrict login flag to val.
2368 *
2369 * Returns:
2370 * zero if val is in range
2371 * -EINVAL val out of range
2372 **/
James Smart3de2a652007-08-02 11:09:59 -04002373static int
2374lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2375{
2376 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002378 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002379 "be set to %d, allowed range is [0, 1]\n",
2380 val);
James Smart3de2a652007-08-02 11:09:59 -04002381 vport->cfg_restrict_login = 1;
2382 return -EINVAL;
2383 }
2384 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2385 vport->cfg_restrict_login = 0;
2386 return 0;
2387 }
2388 vport->cfg_restrict_login = val;
2389 return 0;
2390}
2391
James Smarte59058c2008-08-24 21:49:00 -04002392/**
James Smart3621a712009-04-06 18:47:14 -04002393 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002394 * @vport: lpfc vport structure pointer.
2395 * @val: contains the restrict login value.
2396 *
2397 * Description:
2398 * If val is not in a valid range then log a kernel error message and set
2399 * the vport restrict login to one.
2400 * If the port type is physical and the val is not zero log a kernel
2401 * error message, clear the restrict login flag and return zero.
2402 * Else set the restrict login flag to val.
2403 *
2404 * Returns:
2405 * zero if val is in range
2406 * -EINVAL val out of range
2407 **/
James Smart3de2a652007-08-02 11:09:59 -04002408static int
2409lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2410{
2411 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002412 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002413 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002414 "be set to %d, allowed range is [0, 1]\n",
2415 val);
James Smart3de2a652007-08-02 11:09:59 -04002416 vport->cfg_restrict_login = 1;
2417 return -EINVAL;
2418 }
2419 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002420 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2421 "0468 lpfc_restrict_login must be 0 for "
2422 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002423 vport->cfg_restrict_login = 0;
2424 return 0;
2425 }
2426 vport->cfg_restrict_login = val;
2427 return 0;
2428}
2429lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002430static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2431 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002432
2433/*
dea31012005-04-17 16:05:31 -05002434# Some disk devices have a "select ID" or "select Target" capability.
2435# From a protocol standpoint "select ID" usually means select the
2436# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2437# annex" which contains a table that maps a "select ID" (a number
2438# between 0 and 7F) to an ALPA. By default, for compatibility with
2439# older drivers, the lpfc driver scans this table from low ALPA to high
2440# ALPA.
2441#
2442# Turning on the scan-down variable (on = 1, off = 0) will
2443# cause the lpfc driver to use an inverted table, effectively
2444# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2445#
2446# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2447# and will not work across a fabric. Also this parameter will take
2448# effect only in the case when ALPA map is not available.)
2449*/
James Smart3de2a652007-08-02 11:09:59 -04002450LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2451 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002452
2453/*
dea31012005-04-17 16:05:31 -05002454# lpfc_topology: link topology for init link
2455# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002456# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002457# 0x02 = attempt point-to-point mode only
2458# 0x04 = attempt loop mode only
2459# 0x06 = attempt point-to-point mode then loop
2460# Set point-to-point mode if you want to run as an N_Port.
2461# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2462# Default value is 0.
2463*/
James Smarte59058c2008-08-24 21:49:00 -04002464
2465/**
James Smart3621a712009-04-06 18:47:14 -04002466 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002467 * @phba: lpfc_hba pointer.
2468 * @val: topology value.
2469 *
2470 * Description:
2471 * If val is in a valid range then set the adapter's topology field and
2472 * issue a lip; if the lip fails reset the topology to the old value.
2473 *
2474 * If the value is not in range log a kernel error message and return an error.
2475 *
2476 * Returns:
2477 * zero if val is in range and lip okay
2478 * non-zero return value from lpfc_issue_lip()
2479 * -EINVAL val out of range
2480 **/
James Smarta257bf92009-04-06 18:48:10 -04002481static ssize_t
2482lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2483 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002484{
James Smarta257bf92009-04-06 18:48:10 -04002485 struct Scsi_Host *shost = class_to_shost(dev);
2486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2487 struct lpfc_hba *phba = vport->phba;
2488 int val = 0;
2489 int nolip = 0;
2490 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002491 int err;
2492 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002493
2494 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2495 nolip = 1;
2496 val_buf = &buf[strlen("nolip ")];
2497 }
2498
2499 if (!isdigit(val_buf[0]))
2500 return -EINVAL;
2501 if (sscanf(val_buf, "%i", &val) != 1)
2502 return -EINVAL;
2503
James Smart83108bd2008-01-11 01:53:09 -05002504 if (val >= 0 && val <= 6) {
2505 prev_val = phba->cfg_topology;
2506 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002507 if (nolip)
2508 return strlen(buf);
2509
James Smart83108bd2008-01-11 01:53:09 -05002510 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002511 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002512 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002513 return -EINVAL;
2514 } else
2515 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002516 }
2517 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2518 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2519 "allowed range is [0, 6]\n",
2520 phba->brd_no, val);
2521 return -EINVAL;
2522}
2523static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002524module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002525MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2526lpfc_param_show(topology)
2527lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002528static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002529 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002530
James Smart21e9a0a2009-05-22 14:53:21 -04002531/**
2532 * lpfc_static_vport_show: Read callback function for
2533 * lpfc_static_vport sysfs file.
2534 * @dev: Pointer to class device object.
2535 * @attr: device attribute structure.
2536 * @buf: Data buffer.
2537 *
2538 * This function is the read call back function for
2539 * lpfc_static_vport sysfs file. The lpfc_static_vport
2540 * sysfs file report the mageability of the vport.
2541 **/
2542static ssize_t
2543lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2544 char *buf)
2545{
2546 struct Scsi_Host *shost = class_to_shost(dev);
2547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2548 if (vport->vport_flag & STATIC_VPORT)
2549 sprintf(buf, "1\n");
2550 else
2551 sprintf(buf, "0\n");
2552
2553 return strlen(buf);
2554}
2555
2556/*
2557 * Sysfs attribute to control the statistical data collection.
2558 */
2559static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2560 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002561
2562/**
James Smart3621a712009-04-06 18:47:14 -04002563 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002564 * @dev: Pointer to class device.
2565 * @buf: Data buffer.
2566 * @count: Size of the data buffer.
2567 *
2568 * This function get called when an user write to the lpfc_stat_data_ctrl
2569 * sysfs file. This function parse the command written to the sysfs file
2570 * and take appropriate action. These commands are used for controlling
2571 * driver statistical data collection.
2572 * Following are the command this function handles.
2573 *
2574 * setbucket <bucket_type> <base> <step>
2575 * = Set the latency buckets.
2576 * destroybucket = destroy all the buckets.
2577 * start = start data collection
2578 * stop = stop data collection
2579 * reset = reset the collected data
2580 **/
2581static ssize_t
2582lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2583 const char *buf, size_t count)
2584{
2585 struct Scsi_Host *shost = class_to_shost(dev);
2586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2587 struct lpfc_hba *phba = vport->phba;
2588#define LPFC_MAX_DATA_CTRL_LEN 1024
2589 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2590 unsigned long i;
2591 char *str_ptr, *token;
2592 struct lpfc_vport **vports;
2593 struct Scsi_Host *v_shost;
2594 char *bucket_type_str, *base_str, *step_str;
2595 unsigned long base, step, bucket_type;
2596
2597 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002598 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002599 return -EINVAL;
2600
2601 strcpy(bucket_data, buf);
2602 str_ptr = &bucket_data[0];
2603 /* Ignore this token - this is command token */
2604 token = strsep(&str_ptr, "\t ");
2605 if (!token)
2606 return -EINVAL;
2607
2608 bucket_type_str = strsep(&str_ptr, "\t ");
2609 if (!bucket_type_str)
2610 return -EINVAL;
2611
2612 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2613 bucket_type = LPFC_LINEAR_BUCKET;
2614 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2615 bucket_type = LPFC_POWER2_BUCKET;
2616 else
2617 return -EINVAL;
2618
2619 base_str = strsep(&str_ptr, "\t ");
2620 if (!base_str)
2621 return -EINVAL;
2622 base = simple_strtoul(base_str, NULL, 0);
2623
2624 step_str = strsep(&str_ptr, "\t ");
2625 if (!step_str)
2626 return -EINVAL;
2627 step = simple_strtoul(step_str, NULL, 0);
2628 if (!step)
2629 return -EINVAL;
2630
2631 /* Block the data collection for every vport */
2632 vports = lpfc_create_vport_work_array(phba);
2633 if (vports == NULL)
2634 return -ENOMEM;
2635
James Smartf4b4c682009-05-22 14:53:12 -04002636 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002637 v_shost = lpfc_shost_from_vport(vports[i]);
2638 spin_lock_irq(v_shost->host_lock);
2639 /* Block and reset data collection */
2640 vports[i]->stat_data_blocked = 1;
2641 if (vports[i]->stat_data_enabled)
2642 lpfc_vport_reset_stat_data(vports[i]);
2643 spin_unlock_irq(v_shost->host_lock);
2644 }
2645
2646 /* Set the bucket attributes */
2647 phba->bucket_type = bucket_type;
2648 phba->bucket_base = base;
2649 phba->bucket_step = step;
2650
James Smartf4b4c682009-05-22 14:53:12 -04002651 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002652 v_shost = lpfc_shost_from_vport(vports[i]);
2653
2654 /* Unblock data collection */
2655 spin_lock_irq(v_shost->host_lock);
2656 vports[i]->stat_data_blocked = 0;
2657 spin_unlock_irq(v_shost->host_lock);
2658 }
2659 lpfc_destroy_vport_work_array(phba, vports);
2660 return strlen(buf);
2661 }
2662
2663 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2664 vports = lpfc_create_vport_work_array(phba);
2665 if (vports == NULL)
2666 return -ENOMEM;
2667
James Smartf4b4c682009-05-22 14:53:12 -04002668 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002669 v_shost = lpfc_shost_from_vport(vports[i]);
2670 spin_lock_irq(shost->host_lock);
2671 vports[i]->stat_data_blocked = 1;
2672 lpfc_free_bucket(vport);
2673 vport->stat_data_enabled = 0;
2674 vports[i]->stat_data_blocked = 0;
2675 spin_unlock_irq(shost->host_lock);
2676 }
2677 lpfc_destroy_vport_work_array(phba, vports);
2678 phba->bucket_type = LPFC_NO_BUCKET;
2679 phba->bucket_base = 0;
2680 phba->bucket_step = 0;
2681 return strlen(buf);
2682 }
2683
2684 if (!strncmp(buf, "start", strlen("start"))) {
2685 /* If no buckets configured return error */
2686 if (phba->bucket_type == LPFC_NO_BUCKET)
2687 return -EINVAL;
2688 spin_lock_irq(shost->host_lock);
2689 if (vport->stat_data_enabled) {
2690 spin_unlock_irq(shost->host_lock);
2691 return strlen(buf);
2692 }
2693 lpfc_alloc_bucket(vport);
2694 vport->stat_data_enabled = 1;
2695 spin_unlock_irq(shost->host_lock);
2696 return strlen(buf);
2697 }
2698
2699 if (!strncmp(buf, "stop", strlen("stop"))) {
2700 spin_lock_irq(shost->host_lock);
2701 if (vport->stat_data_enabled == 0) {
2702 spin_unlock_irq(shost->host_lock);
2703 return strlen(buf);
2704 }
2705 lpfc_free_bucket(vport);
2706 vport->stat_data_enabled = 0;
2707 spin_unlock_irq(shost->host_lock);
2708 return strlen(buf);
2709 }
2710
2711 if (!strncmp(buf, "reset", strlen("reset"))) {
2712 if ((phba->bucket_type == LPFC_NO_BUCKET)
2713 || !vport->stat_data_enabled)
2714 return strlen(buf);
2715 spin_lock_irq(shost->host_lock);
2716 vport->stat_data_blocked = 1;
2717 lpfc_vport_reset_stat_data(vport);
2718 vport->stat_data_blocked = 0;
2719 spin_unlock_irq(shost->host_lock);
2720 return strlen(buf);
2721 }
2722 return -EINVAL;
2723}
2724
2725
2726/**
James Smart3621a712009-04-06 18:47:14 -04002727 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002728 * @dev: Pointer to class device object.
2729 * @buf: Data buffer.
2730 *
2731 * This function is the read call back function for
2732 * lpfc_stat_data_ctrl sysfs file. This function report the
2733 * current statistical data collection state.
2734 **/
2735static ssize_t
2736lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2737 char *buf)
2738{
2739 struct Scsi_Host *shost = class_to_shost(dev);
2740 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2741 struct lpfc_hba *phba = vport->phba;
2742 int index = 0;
2743 int i;
2744 char *bucket_type;
2745 unsigned long bucket_value;
2746
2747 switch (phba->bucket_type) {
2748 case LPFC_LINEAR_BUCKET:
2749 bucket_type = "linear";
2750 break;
2751 case LPFC_POWER2_BUCKET:
2752 bucket_type = "power2";
2753 break;
2754 default:
2755 bucket_type = "No Bucket";
2756 break;
2757 }
2758
2759 sprintf(&buf[index], "Statistical Data enabled :%d, "
2760 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2761 " Bucket step :%d\nLatency Ranges :",
2762 vport->stat_data_enabled, vport->stat_data_blocked,
2763 bucket_type, phba->bucket_base, phba->bucket_step);
2764 index = strlen(buf);
2765 if (phba->bucket_type != LPFC_NO_BUCKET) {
2766 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2767 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2768 bucket_value = phba->bucket_base +
2769 phba->bucket_step * i;
2770 else
2771 bucket_value = phba->bucket_base +
2772 (1 << i) * phba->bucket_step;
2773
2774 if (index + 10 > PAGE_SIZE)
2775 break;
2776 sprintf(&buf[index], "%08ld ", bucket_value);
2777 index = strlen(buf);
2778 }
2779 }
2780 sprintf(&buf[index], "\n");
2781 return strlen(buf);
2782}
2783
2784/*
2785 * Sysfs attribute to control the statistical data collection.
2786 */
2787static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2788 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2789
2790/*
2791 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2792 */
2793
2794/*
2795 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2796 * for each target.
2797 */
2798#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2799#define MAX_STAT_DATA_SIZE_PER_TARGET \
2800 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2801
2802
2803/**
James Smart3621a712009-04-06 18:47:14 -04002804 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002805 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002806 * @kobj: Pointer to the kernel object
2807 * @bin_attr: Attribute object
2808 * @buff: Buffer pointer
2809 * @off: File offset
2810 * @count: Buffer size
2811 *
2812 * This function is the read call back function for lpfc_drvr_stat_data
2813 * sysfs file. This function export the statistical data to user
2814 * applications.
2815 **/
2816static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002817sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2818 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002819 char *buf, loff_t off, size_t count)
2820{
2821 struct device *dev = container_of(kobj, struct device,
2822 kobj);
2823 struct Scsi_Host *shost = class_to_shost(dev);
2824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2825 struct lpfc_hba *phba = vport->phba;
2826 int i = 0, index = 0;
2827 unsigned long nport_index;
2828 struct lpfc_nodelist *ndlp = NULL;
2829 nport_index = (unsigned long)off /
2830 MAX_STAT_DATA_SIZE_PER_TARGET;
2831
2832 if (!vport->stat_data_enabled || vport->stat_data_blocked
2833 || (phba->bucket_type == LPFC_NO_BUCKET))
2834 return 0;
2835
2836 spin_lock_irq(shost->host_lock);
2837 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2838 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2839 continue;
2840
2841 if (nport_index > 0) {
2842 nport_index--;
2843 continue;
2844 }
2845
2846 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2847 > count)
2848 break;
2849
2850 if (!ndlp->lat_data)
2851 continue;
2852
2853 /* Print the WWN */
2854 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2855 ndlp->nlp_portname.u.wwn[0],
2856 ndlp->nlp_portname.u.wwn[1],
2857 ndlp->nlp_portname.u.wwn[2],
2858 ndlp->nlp_portname.u.wwn[3],
2859 ndlp->nlp_portname.u.wwn[4],
2860 ndlp->nlp_portname.u.wwn[5],
2861 ndlp->nlp_portname.u.wwn[6],
2862 ndlp->nlp_portname.u.wwn[7]);
2863
2864 index = strlen(buf);
2865
2866 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2867 sprintf(&buf[index], "%010u,",
2868 ndlp->lat_data[i].cmd_count);
2869 index = strlen(buf);
2870 }
2871 sprintf(&buf[index], "\n");
2872 index = strlen(buf);
2873 }
2874 spin_unlock_irq(shost->host_lock);
2875 return index;
2876}
2877
2878static struct bin_attribute sysfs_drvr_stat_data_attr = {
2879 .attr = {
2880 .name = "lpfc_drvr_stat_data",
2881 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002882 },
2883 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2884 .read = sysfs_drvr_stat_data_read,
2885 .write = NULL,
2886};
2887
dea31012005-04-17 16:05:31 -05002888/*
2889# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2890# connection.
James Smart76a95d72010-11-20 23:11:48 -05002891# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002892*/
James Smarte59058c2008-08-24 21:49:00 -04002893/**
James Smart3621a712009-04-06 18:47:14 -04002894 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002895 * @phba: lpfc_hba pointer.
2896 * @val: link speed value.
2897 *
2898 * Description:
2899 * If val is in a valid range then set the adapter's link speed field and
2900 * issue a lip; if the lip fails reset the link speed to the old value.
2901 *
2902 * Notes:
2903 * If the value is not in range log a kernel error message and return an error.
2904 *
2905 * Returns:
2906 * zero if val is in range and lip okay.
2907 * non-zero return value from lpfc_issue_lip()
2908 * -EINVAL val out of range
2909 **/
James Smarta257bf92009-04-06 18:48:10 -04002910static ssize_t
2911lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2912 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002913{
James Smarta257bf92009-04-06 18:48:10 -04002914 struct Scsi_Host *shost = class_to_shost(dev);
2915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2916 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002917 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002918 int nolip = 0;
2919 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002920 int err;
2921 uint32_t prev_val;
2922
James Smarta257bf92009-04-06 18:48:10 -04002923 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2924 nolip = 1;
2925 val_buf = &buf[strlen("nolip ")];
2926 }
2927
2928 if (!isdigit(val_buf[0]))
2929 return -EINVAL;
2930 if (sscanf(val_buf, "%i", &val) != 1)
2931 return -EINVAL;
2932
James Smart76a95d72010-11-20 23:11:48 -05002933 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2934 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2935 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2936 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2937 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2938 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2940 "2879 lpfc_link_speed attribute cannot be set "
2941 "to %d. Speed is not supported by this port.\n",
2942 val);
James Smart83108bd2008-01-11 01:53:09 -05002943 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05002944 }
2945 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2946 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002947 prev_val = phba->cfg_link_speed;
2948 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002949 if (nolip)
2950 return strlen(buf);
2951
James Smart83108bd2008-01-11 01:53:09 -05002952 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002953 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002954 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002955 return -EINVAL;
2956 } else
2957 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002958 }
James Smart83108bd2008-01-11 01:53:09 -05002959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05002960 "0469 lpfc_link_speed attribute cannot be set to %d, "
2961 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05002962 return -EINVAL;
2963}
2964
2965static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05002966module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002967MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2968lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002969
2970/**
James Smart3621a712009-04-06 18:47:14 -04002971 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002972 * @phba: lpfc_hba pointer.
2973 * @val: link speed value.
2974 *
2975 * Description:
2976 * If val is in a valid range then set the adapter's link speed field.
2977 *
2978 * Notes:
2979 * If the value is not in range log a kernel error message, clear the link
2980 * speed and return an error.
2981 *
2982 * Returns:
2983 * zero if val saved.
2984 * -EINVAL val out of range
2985 **/
James Smart83108bd2008-01-11 01:53:09 -05002986static int
2987lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2988{
James Smart76a95d72010-11-20 23:11:48 -05002989 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2990 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05002991 phba->cfg_link_speed = val;
2992 return 0;
2993 }
2994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002995 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002996 "be set to %d, allowed values are "
2997 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05002998 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05002999 return -EINVAL;
3000}
3001
Tony Jonesee959b02008-02-22 00:13:36 +01003002static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003003 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003004
3005/*
James Smart0d878412009-10-02 15:16:56 -04003006# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3007# 0 = aer disabled or not supported
3008# 1 = aer supported and enabled (default)
3009# Value range is [0,1]. Default value is 1.
3010*/
3011
3012/**
3013 * lpfc_aer_support_store - Set the adapter for aer support
3014 *
3015 * @dev: class device that is converted into a Scsi_host.
3016 * @attr: device attribute, not used.
3017 * @buf: containing the string "selective".
3018 * @count: unused variable.
3019 *
3020 * Description:
3021 * If the val is 1 and currently the device's AER capability was not
3022 * enabled, invoke the kernel's enable AER helper routine, trying to
3023 * enable the device's AER capability. If the helper routine enabling
3024 * AER returns success, update the device's cfg_aer_support flag to
3025 * indicate AER is supported by the device; otherwise, if the device
3026 * AER capability is already enabled to support AER, then do nothing.
3027 *
3028 * If the val is 0 and currently the device's AER support was enabled,
3029 * invoke the kernel's disable AER helper routine. After that, update
3030 * the device's cfg_aer_support flag to indicate AER is not supported
3031 * by the device; otherwise, if the device AER capability is already
3032 * disabled from supporting AER, then do nothing.
3033 *
3034 * Returns:
3035 * length of the buf on success if val is in range the intended mode
3036 * is supported.
3037 * -EINVAL if val out of range or intended mode is not supported.
3038 **/
3039static ssize_t
3040lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3041 const char *buf, size_t count)
3042{
3043 struct Scsi_Host *shost = class_to_shost(dev);
3044 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3045 struct lpfc_hba *phba = vport->phba;
3046 int val = 0, rc = -EINVAL;
3047
3048 if (!isdigit(buf[0]))
3049 return -EINVAL;
3050 if (sscanf(buf, "%i", &val) != 1)
3051 return -EINVAL;
3052
3053 switch (val) {
3054 case 0:
3055 if (phba->hba_flag & HBA_AER_ENABLED) {
3056 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3057 if (!rc) {
3058 spin_lock_irq(&phba->hbalock);
3059 phba->hba_flag &= ~HBA_AER_ENABLED;
3060 spin_unlock_irq(&phba->hbalock);
3061 phba->cfg_aer_support = 0;
3062 rc = strlen(buf);
3063 } else
James Smart891478a2009-11-18 15:40:23 -05003064 rc = -EPERM;
3065 } else {
James Smart0d878412009-10-02 15:16:56 -04003066 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003067 rc = strlen(buf);
3068 }
James Smart0d878412009-10-02 15:16:56 -04003069 break;
3070 case 1:
3071 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3072 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3073 if (!rc) {
3074 spin_lock_irq(&phba->hbalock);
3075 phba->hba_flag |= HBA_AER_ENABLED;
3076 spin_unlock_irq(&phba->hbalock);
3077 phba->cfg_aer_support = 1;
3078 rc = strlen(buf);
3079 } else
James Smart891478a2009-11-18 15:40:23 -05003080 rc = -EPERM;
3081 } else {
James Smart0d878412009-10-02 15:16:56 -04003082 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003083 rc = strlen(buf);
3084 }
James Smart0d878412009-10-02 15:16:56 -04003085 break;
3086 default:
3087 rc = -EINVAL;
3088 break;
3089 }
3090 return rc;
3091}
3092
3093static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003094module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003095MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3096lpfc_param_show(aer_support)
3097
3098/**
3099 * lpfc_aer_support_init - Set the initial adapters aer support flag
3100 * @phba: lpfc_hba pointer.
3101 * @val: link speed value.
3102 *
3103 * Description:
3104 * If val is in a valid range [0,1], then set the adapter's initial
3105 * cfg_aer_support field. It will be up to the driver's probe_one
3106 * routine to determine whether the device's AER support can be set
3107 * or not.
3108 *
3109 * Notes:
3110 * If the value is not in range log a kernel error message, and
3111 * choose the default value of setting AER support and return.
3112 *
3113 * Returns:
3114 * zero if val saved.
3115 * -EINVAL val out of range
3116 **/
3117static int
3118lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3119{
3120 if (val == 0 || val == 1) {
3121 phba->cfg_aer_support = val;
3122 return 0;
3123 }
3124 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3125 "2712 lpfc_aer_support attribute value %d out "
3126 "of range, allowed values are 0|1, setting it "
3127 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003128 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003129 phba->cfg_aer_support = 1;
3130 return -EINVAL;
3131}
3132
3133static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3134 lpfc_aer_support_show, lpfc_aer_support_store);
3135
3136/**
3137 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3138 * @dev: class device that is converted into a Scsi_host.
3139 * @attr: device attribute, not used.
3140 * @buf: containing the string "selective".
3141 * @count: unused variable.
3142 *
3143 * Description:
3144 * If the @buf contains 1 and the device currently has the AER support
3145 * enabled, then invokes the kernel AER helper routine
3146 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3147 * error status register.
3148 *
3149 * Notes:
3150 *
3151 * Returns:
3152 * -EINVAL if the buf does not contain the 1 or the device is not currently
3153 * enabled with the AER support.
3154 **/
3155static ssize_t
3156lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3157 const char *buf, size_t count)
3158{
3159 struct Scsi_Host *shost = class_to_shost(dev);
3160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3161 struct lpfc_hba *phba = vport->phba;
3162 int val, rc = -1;
3163
3164 if (!isdigit(buf[0]))
3165 return -EINVAL;
3166 if (sscanf(buf, "%i", &val) != 1)
3167 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003168 if (val != 1)
3169 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003170
James Smart891478a2009-11-18 15:40:23 -05003171 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003172 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3173
3174 if (rc == 0)
3175 return strlen(buf);
3176 else
James Smart891478a2009-11-18 15:40:23 -05003177 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003178}
3179
3180static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3181 lpfc_aer_cleanup_state);
3182
3183/*
dea31012005-04-17 16:05:31 -05003184# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3185# Value range is [2,3]. Default value is 3.
3186*/
James Smart3de2a652007-08-02 11:09:59 -04003187LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3188 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003189
3190/*
3191# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3192# is [0,1]. Default value is 0.
3193*/
James Smart3de2a652007-08-02 11:09:59 -04003194LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3195 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003196
3197/*
James Smart977b5a02008-09-07 11:52:04 -04003198# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3199# depth. Default value is 0. When the value of this parameter is zero the
3200# SCSI command completion time is not used for controlling I/O queue depth. When
3201# the parameter is set to a non-zero value, the I/O queue depth is controlled
3202# to limit the I/O completion time to the parameter value.
3203# The value is set in milliseconds.
3204*/
3205static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003206module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003207MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3208 "Use command completion time to control queue depth");
3209lpfc_vport_param_show(max_scsicmpl_time);
3210lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3211static int
3212lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3213{
3214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3215 struct lpfc_nodelist *ndlp, *next_ndlp;
3216
3217 if (val == vport->cfg_max_scsicmpl_time)
3218 return 0;
3219 if ((val < 0) || (val > 60000))
3220 return -EINVAL;
3221 vport->cfg_max_scsicmpl_time = val;
3222
3223 spin_lock_irq(shost->host_lock);
3224 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3225 if (!NLP_CHK_NODE_ACT(ndlp))
3226 continue;
3227 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3228 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003229 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003230 }
3231 spin_unlock_irq(shost->host_lock);
3232 return 0;
3233}
3234lpfc_vport_param_store(max_scsicmpl_time);
3235static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3236 lpfc_max_scsicmpl_time_show,
3237 lpfc_max_scsicmpl_time_store);
3238
3239/*
dea31012005-04-17 16:05:31 -05003240# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3241# range is [0,1]. Default value is 0.
3242*/
3243LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3244
3245/*
3246# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3247# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003248# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003249# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3250# cr_delay is set to 0.
3251*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003252LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003253 "interrupt response is generated");
3254
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003255LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003256 "interrupt response is generated");
3257
3258/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003259# lpfc_multi_ring_support: Determines how many rings to spread available
3260# cmd/rsp IOCB entries across.
3261# Value range is [1,2]. Default value is 1.
3262*/
3263LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3264 "SLI rings to spread IOCB entries across");
3265
3266/*
James Smarta4bc3372006-12-02 13:34:16 -05003267# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3268# identifies what rctl value to configure the additional ring for.
3269# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3270*/
James Smart6a9c52c2009-10-02 15:16:51 -04003271LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003272 255, "Identifies RCTL for additional ring configuration");
3273
3274/*
3275# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3276# identifies what type value to configure the additional ring for.
3277# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3278*/
James Smart6a9c52c2009-10-02 15:16:51 -04003279LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003280 255, "Identifies TYPE for additional ring configuration");
3281
3282/*
dea31012005-04-17 16:05:31 -05003283# lpfc_fdmi_on: controls FDMI support.
3284# 0 = no FDMI support
3285# 1 = support FDMI without attribute of hostname
3286# 2 = support FDMI with attribute of hostname
3287# Value range [0,2]. Default value is 0.
3288*/
James Smart3de2a652007-08-02 11:09:59 -04003289LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003290
3291/*
3292# Specifies the maximum number of ELS cmds we can have outstanding (for
3293# discovery). Value range is [1,64]. Default value = 32.
3294*/
James Smart3de2a652007-08-02 11:09:59 -04003295LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003296 "during discovery");
3297
3298/*
James Smart65a29c12006-07-06 15:50:50 -04003299# lpfc_max_luns: maximum allowed LUN.
3300# Value range is [0,65535]. Default value is 255.
3301# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003302*/
James Smart3de2a652007-08-02 11:09:59 -04003303LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003304
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003305/*
3306# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3307# Value range is [1,255], default value is 10.
3308*/
3309LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3310 "Milliseconds driver will wait between polling FCP ring");
3311
James Smart4ff43242006-12-02 13:34:56 -05003312/*
3313# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3314# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003315# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003316# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003317# 2 = MSI-X enabled (default)
3318# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003319*/
George Kadianakis8605c462010-01-17 21:19:31 +02003320LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003321 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003322
James Smart13815c82008-01-11 01:52:48 -05003323/*
James Smartda0436e2009-05-22 14:51:39 -04003324# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3325#
3326# Value range is [636,651042]. Default value is 10000.
3327*/
3328LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3329 "Set the maximum number of fast-path FCP interrupts per second");
3330
3331/*
3332# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3333#
3334# Value range is [1,31]. Default value is 4.
3335*/
3336LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3337 "Set the number of fast-path FCP work queues, if possible");
3338
3339/*
3340# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3341#
3342# Value range is [1,7]. Default value is 1.
3343*/
3344LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3345 "Set the number of fast-path FCP event queues, if possible");
3346
3347/*
James Smart13815c82008-01-11 01:52:48 -05003348# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3349# 0 = HBA resets disabled
3350# 1 = HBA resets enabled (default)
3351# Value range is [0,1]. Default value is 1.
3352*/
3353LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003354
James Smart13815c82008-01-11 01:52:48 -05003355/*
James Smarteb7a3392010-11-20 23:12:02 -05003356# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003357# 0 = HBA Heartbeat disabled
3358# 1 = HBA Heartbeat enabled (default)
3359# Value range is [0,1]. Default value is 1.
3360*/
James Smarteb7a3392010-11-20 23:12:02 -05003361LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003362
James Smart83108bd2008-01-11 01:53:09 -05003363/*
James Smart81301a92008-12-04 22:39:46 -05003364# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3365# 0 = BlockGuard disabled (default)
3366# 1 = BlockGuard enabled
3367# Value range is [0,1]. Default value is 0.
3368*/
3369LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3370
James Smart6fb120a2009-05-22 14:52:59 -04003371/*
James Smart81301a92008-12-04 22:39:46 -05003372# lpfc_prot_mask: i
3373# - Bit mask of host protection capabilities used to register with the
3374# SCSI mid-layer
3375# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3376# - Allows you to ultimately specify which profiles to use
3377# - Default will result in registering capabilities for all profiles.
3378#
3379*/
James Smartbc739052010-08-04 16:11:18 -04003380unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003381
James Smartab56dc22011-02-16 12:39:57 -05003382module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003383MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3384
3385/*
3386# lpfc_prot_guard: i
3387# - Bit mask of protection guard types to register with the SCSI mid-layer
3388# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3389# - Allows you to ultimately specify which profiles to use
3390# - Default will result in registering capabilities for all guard types
3391#
3392*/
3393unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003394module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003395MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3396
James Smart92494142011-02-16 12:39:44 -05003397/*
3398 * Delay initial NPort discovery when Clean Address bit is cleared in
3399 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3400 * This parameter can have value 0 or 1.
3401 * When this parameter is set to 0, no delay is added to the initial
3402 * discovery.
3403 * When this parameter is set to non-zero value, initial Nport discovery is
3404 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3405 * accept and FCID/Fabric name/Fabric portname is changed.
3406 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3407 * when Clean Address bit is cleared in FLOGI/FDISC
3408 * accept and FCID/Fabric name/Fabric portname is changed.
3409 * Default value is 0.
3410 */
3411int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003412module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003413MODULE_PARM_DESC(lpfc_delay_discovery,
3414 "Delay NPort discovery when Clean Address bit is cleared. "
3415 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003416
3417/*
James Smart3621a712009-04-06 18:47:14 -04003418 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003419 * This value can be set to values between 64 and 256. The default value is
3420 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3421 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3422 */
3423LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3424 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3425
James Smart81301a92008-12-04 22:39:46 -05003426LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3427 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3428 "Max Protection Scatter Gather Segment Count");
3429
Tony Jonesee959b02008-02-22 00:13:36 +01003430struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003431 &dev_attr_bg_info,
3432 &dev_attr_bg_guard_err,
3433 &dev_attr_bg_apptag_err,
3434 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003435 &dev_attr_info,
3436 &dev_attr_serialnum,
3437 &dev_attr_modeldesc,
3438 &dev_attr_modelname,
3439 &dev_attr_programtype,
3440 &dev_attr_portnum,
3441 &dev_attr_fwrev,
3442 &dev_attr_hdw,
3443 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003444 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003445 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003446 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003447 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003448 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003449 &dev_attr_lpfc_temp_sensor,
3450 &dev_attr_lpfc_log_verbose,
3451 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003452 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003453 &dev_attr_lpfc_hba_queue_depth,
3454 &dev_attr_lpfc_peer_port_login,
3455 &dev_attr_lpfc_nodev_tmo,
3456 &dev_attr_lpfc_devloss_tmo,
3457 &dev_attr_lpfc_fcp_class,
3458 &dev_attr_lpfc_use_adisc,
3459 &dev_attr_lpfc_ack0,
3460 &dev_attr_lpfc_topology,
3461 &dev_attr_lpfc_scan_down,
3462 &dev_attr_lpfc_link_speed,
3463 &dev_attr_lpfc_cr_delay,
3464 &dev_attr_lpfc_cr_count,
3465 &dev_attr_lpfc_multi_ring_support,
3466 &dev_attr_lpfc_multi_ring_rctl,
3467 &dev_attr_lpfc_multi_ring_type,
3468 &dev_attr_lpfc_fdmi_on,
3469 &dev_attr_lpfc_max_luns,
3470 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003471 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003472 &dev_attr_nport_evt_cnt,
3473 &dev_attr_board_mode,
3474 &dev_attr_max_vpi,
3475 &dev_attr_used_vpi,
3476 &dev_attr_max_rpi,
3477 &dev_attr_used_rpi,
3478 &dev_attr_max_xri,
3479 &dev_attr_used_xri,
3480 &dev_attr_npiv_info,
3481 &dev_attr_issue_reset,
3482 &dev_attr_lpfc_poll,
3483 &dev_attr_lpfc_poll_tmo,
3484 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003485 &dev_attr_lpfc_fcp_imax,
3486 &dev_attr_lpfc_fcp_wq_count,
3487 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003488 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003489 &dev_attr_lpfc_soft_wwnn,
3490 &dev_attr_lpfc_soft_wwpn,
3491 &dev_attr_lpfc_soft_wwn_enable,
3492 &dev_attr_lpfc_enable_hba_reset,
3493 &dev_attr_lpfc_enable_hba_heartbeat,
3494 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003495 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003496 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003497 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003498 &dev_attr_lpfc_aer_support,
3499 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003500 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003501 &dev_attr_lpfc_iocb_cnt,
3502 &dev_attr_iocb_hw,
3503 &dev_attr_txq_hw,
3504 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003505 &dev_attr_lpfc_fips_level,
3506 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003507 &dev_attr_lpfc_dss,
dea31012005-04-17 16:05:31 -05003508 NULL,
3509};
3510
Tony Jonesee959b02008-02-22 00:13:36 +01003511struct device_attribute *lpfc_vport_attrs[] = {
3512 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003513 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003514 &dev_attr_num_discovered_ports,
3515 &dev_attr_lpfc_drvr_version,
3516 &dev_attr_lpfc_log_verbose,
3517 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003518 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003519 &dev_attr_lpfc_nodev_tmo,
3520 &dev_attr_lpfc_devloss_tmo,
3521 &dev_attr_lpfc_hba_queue_depth,
3522 &dev_attr_lpfc_peer_port_login,
3523 &dev_attr_lpfc_restrict_login,
3524 &dev_attr_lpfc_fcp_class,
3525 &dev_attr_lpfc_use_adisc,
3526 &dev_attr_lpfc_fdmi_on,
3527 &dev_attr_lpfc_max_luns,
3528 &dev_attr_nport_evt_cnt,
3529 &dev_attr_npiv_info,
3530 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003531 &dev_attr_lpfc_max_scsicmpl_time,
3532 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003533 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003534 &dev_attr_lpfc_fips_level,
3535 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003536 NULL,
3537};
3538
James Smarte59058c2008-08-24 21:49:00 -04003539/**
James Smart3621a712009-04-06 18:47:14 -04003540 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003541 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003542 * @kobj: kernel kobject that contains the kernel class device.
3543 * @bin_attr: kernel attributes passed to us.
3544 * @buf: contains the data to be written to the adapter IOREG space.
3545 * @off: offset into buffer to beginning of data.
3546 * @count: bytes to transfer.
3547 *
3548 * Description:
3549 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3550 * Uses the adapter io control registers to send buf contents to the adapter.
3551 *
3552 * Returns:
3553 * -ERANGE off and count combo out of range
3554 * -EINVAL off, count or buff address invalid
3555 * -EPERM adapter is offline
3556 * value of count, buf contents written
3557 **/
dea31012005-04-17 16:05:31 -05003558static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003559sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3560 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003561 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003562{
3563 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003564 struct device *dev = container_of(kobj, struct device, kobj);
3565 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3567 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003568
James Smartf1126682009-06-10 17:22:44 -04003569 if (phba->sli_rev >= LPFC_SLI_REV4)
3570 return -EPERM;
3571
dea31012005-04-17 16:05:31 -05003572 if ((off + count) > FF_REG_AREA_SIZE)
3573 return -ERANGE;
3574
3575 if (count == 0) return 0;
3576
3577 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3578 return -EINVAL;
3579
James Smart2e0fef82007-06-17 19:56:36 -05003580 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003581 return -EPERM;
3582 }
3583
James Smart2e0fef82007-06-17 19:56:36 -05003584 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003585 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3586 writel(*((uint32_t *)(buf + buf_off)),
3587 phba->ctrl_regs_memmap_p + off + buf_off);
3588
James Smart2e0fef82007-06-17 19:56:36 -05003589 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003590
3591 return count;
3592}
3593
James Smarte59058c2008-08-24 21:49:00 -04003594/**
James Smart3621a712009-04-06 18:47:14 -04003595 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003596 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003597 * @kobj: kernel kobject that contains the kernel class device.
3598 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003599 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003600 * @off: offset into buffer to beginning of data.
3601 * @count: bytes to transfer.
3602 *
3603 * Description:
3604 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3605 * Uses the adapter io control registers to read data into buf.
3606 *
3607 * Returns:
3608 * -ERANGE off and count combo out of range
3609 * -EINVAL off, count or buff address invalid
3610 * value of count, buf contents read
3611 **/
dea31012005-04-17 16:05:31 -05003612static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003613sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3614 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003615 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003616{
3617 size_t buf_off;
3618 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003619 struct device *dev = container_of(kobj, struct device, kobj);
3620 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3622 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003623
James Smartf1126682009-06-10 17:22:44 -04003624 if (phba->sli_rev >= LPFC_SLI_REV4)
3625 return -EPERM;
3626
dea31012005-04-17 16:05:31 -05003627 if (off > FF_REG_AREA_SIZE)
3628 return -ERANGE;
3629
3630 if ((off + count) > FF_REG_AREA_SIZE)
3631 count = FF_REG_AREA_SIZE - off;
3632
3633 if (count == 0) return 0;
3634
3635 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3636 return -EINVAL;
3637
James Smart2e0fef82007-06-17 19:56:36 -05003638 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003639
3640 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3641 tmp_ptr = (uint32_t *)(buf + buf_off);
3642 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3643 }
3644
James Smart2e0fef82007-06-17 19:56:36 -05003645 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003646
3647 return count;
3648}
3649
3650static struct bin_attribute sysfs_ctlreg_attr = {
3651 .attr = {
3652 .name = "ctlreg",
3653 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003654 },
3655 .size = 256,
3656 .read = sysfs_ctlreg_read,
3657 .write = sysfs_ctlreg_write,
3658};
3659
James Smarte59058c2008-08-24 21:49:00 -04003660/**
James Smart3621a712009-04-06 18:47:14 -04003661 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003662 * @phba: lpfc_hba pointer
3663 **/
dea31012005-04-17 16:05:31 -05003664static void
James Smart2e0fef82007-06-17 19:56:36 -05003665sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003666{
3667 phba->sysfs_mbox.state = SMBOX_IDLE;
3668 phba->sysfs_mbox.offset = 0;
3669
3670 if (phba->sysfs_mbox.mbox) {
3671 mempool_free(phba->sysfs_mbox.mbox,
3672 phba->mbox_mem_pool);
3673 phba->sysfs_mbox.mbox = NULL;
3674 }
3675}
3676
James Smarte59058c2008-08-24 21:49:00 -04003677/**
James Smart3621a712009-04-06 18:47:14 -04003678 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003679 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003680 * @kobj: kernel kobject that contains the kernel class device.
3681 * @bin_attr: kernel attributes passed to us.
3682 * @buf: contains the data to be written to sysfs mbox.
3683 * @off: offset into buffer to beginning of data.
3684 * @count: bytes to transfer.
3685 *
3686 * Description:
3687 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3688 * Uses the sysfs mbox to send buf contents to the adapter.
3689 *
3690 * Returns:
3691 * -ERANGE off and count combo out of range
3692 * -EINVAL off, count or buff address invalid
3693 * zero if count is zero
3694 * -EPERM adapter is offline
3695 * -ENOMEM failed to allocate memory for the mail box
3696 * -EAGAIN offset, state or mbox is NULL
3697 * count number of bytes transferred
3698 **/
dea31012005-04-17 16:05:31 -05003699static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003700sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3701 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003702 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003703{
Tony Jonesee959b02008-02-22 00:13:36 +01003704 struct device *dev = container_of(kobj, struct device, kobj);
3705 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003706 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3707 struct lpfc_hba *phba = vport->phba;
3708 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003709
3710 if ((count + off) > MAILBOX_CMD_SIZE)
3711 return -ERANGE;
3712
3713 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3714 return -EINVAL;
3715
3716 if (count == 0)
3717 return 0;
3718
3719 if (off == 0) {
3720 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3721 if (!mbox)
3722 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003723 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003724 }
3725
James Smart2e0fef82007-06-17 19:56:36 -05003726 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003727
3728 if (off == 0) {
3729 if (phba->sysfs_mbox.mbox)
3730 mempool_free(mbox, phba->mbox_mem_pool);
3731 else
3732 phba->sysfs_mbox.mbox = mbox;
3733 phba->sysfs_mbox.state = SMBOX_WRITING;
3734 } else {
3735 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3736 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003737 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003738 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003739 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003740 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003741 }
3742 }
3743
James Smart04c68492009-05-22 14:52:52 -04003744 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003745 buf, count);
3746
3747 phba->sysfs_mbox.offset = off + count;
3748
James Smart2e0fef82007-06-17 19:56:36 -05003749 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003750
3751 return count;
3752}
3753
James Smarte59058c2008-08-24 21:49:00 -04003754/**
James Smart3621a712009-04-06 18:47:14 -04003755 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003756 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003757 * @kobj: kernel kobject that contains the kernel class device.
3758 * @bin_attr: kernel attributes passed to us.
3759 * @buf: contains the data to be read from sysfs mbox.
3760 * @off: offset into buffer to beginning of data.
3761 * @count: bytes to transfer.
3762 *
3763 * Description:
3764 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3765 * Uses the sysfs mbox to receive data from to the adapter.
3766 *
3767 * Returns:
3768 * -ERANGE off greater than mailbox command size
3769 * -EINVAL off, count or buff address invalid
3770 * zero if off and count are zero
3771 * -EACCES adapter over temp
3772 * -EPERM garbage can value to catch a multitude of errors
3773 * -EAGAIN management IO not permitted, state or off error
3774 * -ETIME mailbox timeout
3775 * -ENODEV mailbox error
3776 * count number of bytes transferred
3777 **/
dea31012005-04-17 16:05:31 -05003778static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003779sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3780 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003781 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003782{
Tony Jonesee959b02008-02-22 00:13:36 +01003783 struct device *dev = container_of(kobj, struct device, kobj);
3784 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003785 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3786 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003787 int rc;
James Smart04c68492009-05-22 14:52:52 -04003788 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003789
James Smart1dcb58e2007-04-25 09:51:30 -04003790 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003791 return -ERANGE;
3792
James Smart1dcb58e2007-04-25 09:51:30 -04003793 if ((count + off) > MAILBOX_CMD_SIZE)
3794 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003795
3796 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3797 return -EINVAL;
3798
3799 if (off && count == 0)
3800 return 0;
3801
James Smart2e0fef82007-06-17 19:56:36 -05003802 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003803
James Smart7af67052007-10-27 13:38:11 -04003804 if (phba->over_temp_state == HBA_OVER_TEMP) {
3805 sysfs_mbox_idle(phba);
3806 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003807 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003808 }
3809
dea31012005-04-17 16:05:31 -05003810 if (off == 0 &&
3811 phba->sysfs_mbox.state == SMBOX_WRITING &&
3812 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003813 pmb = &phba->sysfs_mbox.mbox->u.mb;
3814 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003815 /* Offline only */
dea31012005-04-17 16:05:31 -05003816 case MBX_INIT_LINK:
3817 case MBX_DOWN_LINK:
3818 case MBX_CONFIG_LINK:
3819 case MBX_CONFIG_RING:
3820 case MBX_RESET_RING:
3821 case MBX_UNREG_LOGIN:
3822 case MBX_CLEAR_LA:
3823 case MBX_DUMP_CONTEXT:
3824 case MBX_RUN_DIAGS:
3825 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003826 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003827 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003828 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003829 printk(KERN_WARNING "mbox_read:Command 0x%x "
3830 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003831 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003832 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003833 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003834 return -EPERM;
3835 }
James Smarta8adb832007-10-27 13:37:53 -04003836 case MBX_WRITE_NV:
3837 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003838 case MBX_LOAD_SM:
3839 case MBX_READ_NV:
3840 case MBX_READ_CONFIG:
3841 case MBX_READ_RCONFIG:
3842 case MBX_READ_STATUS:
3843 case MBX_READ_XRI:
3844 case MBX_READ_REV:
3845 case MBX_READ_LNK_STAT:
3846 case MBX_DUMP_MEMORY:
3847 case MBX_DOWN_LOAD:
3848 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003849 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003850 case MBX_LOAD_AREA:
3851 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003852 case MBX_BEACON:
3853 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003854 case MBX_SET_VARIABLE:
3855 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003856 case MBX_PORT_CAPABILITIES:
3857 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003858 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003859 case MBX_SECURITY_MGMT:
3860 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003861 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3862 printk(KERN_WARNING "mbox_read:Command 0x%x "
3863 "is not permitted\n", pmb->mbxCommand);
3864 sysfs_mbox_idle(phba);
3865 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003866 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003867 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003868 break;
dea31012005-04-17 16:05:31 -05003869 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003870 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003871 case MBX_REG_LOGIN:
3872 case MBX_REG_LOGIN64:
3873 case MBX_CONFIG_PORT:
3874 case MBX_RUN_BIU_DIAG:
3875 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003876 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003877 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003878 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003879 return -EPERM;
3880 default:
3881 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003882 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003883 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003884 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003885 return -EPERM;
3886 }
3887
James Smart09372822008-01-11 01:52:54 -05003888 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003889 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003890 */
James Smartd7c255b2008-08-24 21:50:00 -04003891 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003892 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3893 pmb->mbxCommand != MBX_RESTART &&
3894 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3895 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003896 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3897 "1259 mbox: Issued mailbox cmd "
3898 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003899 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003900
James Smart92d7f7b2007-06-17 19:56:38 -05003901 phba->sysfs_mbox.mbox->vport = vport;
3902
James Smart58da1ff2008-04-07 10:15:56 -04003903 /* Don't allow mailbox commands to be sent when blocked
3904 * or when in the middle of discovery
3905 */
James Smart495a7142008-06-14 22:52:59 -04003906 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003907 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003908 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003909 return -EAGAIN;
3910 }
3911
James Smart2e0fef82007-06-17 19:56:36 -05003912 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003913 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003914
James Smart2e0fef82007-06-17 19:56:36 -05003915 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003916 rc = lpfc_sli_issue_mbox (phba,
3917 phba->sysfs_mbox.mbox,
3918 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003919 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003920
3921 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003922 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003923 rc = lpfc_sli_issue_mbox_wait (phba,
3924 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003925 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003926 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003927 }
3928
3929 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003930 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003931 phba->sysfs_mbox.mbox = NULL;
3932 }
dea31012005-04-17 16:05:31 -05003933 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003934 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003935 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003936 }
3937 phba->sysfs_mbox.state = SMBOX_READING;
3938 }
3939 else if (phba->sysfs_mbox.offset != off ||
3940 phba->sysfs_mbox.state != SMBOX_READING) {
3941 printk(KERN_WARNING "mbox_read: Bad State\n");
3942 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003943 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003944 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003945 }
3946
James Smart04c68492009-05-22 14:52:52 -04003947 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003948
3949 phba->sysfs_mbox.offset = off + count;
3950
James Smart1dcb58e2007-04-25 09:51:30 -04003951 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003952 sysfs_mbox_idle(phba);
3953
James Smart2e0fef82007-06-17 19:56:36 -05003954 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003955
3956 return count;
3957}
3958
3959static struct bin_attribute sysfs_mbox_attr = {
3960 .attr = {
3961 .name = "mbox",
3962 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003963 },
James Smart1dcb58e2007-04-25 09:51:30 -04003964 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003965 .read = sysfs_mbox_read,
3966 .write = sysfs_mbox_write,
3967};
3968
James Smarte59058c2008-08-24 21:49:00 -04003969/**
James Smart3621a712009-04-06 18:47:14 -04003970 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003971 * @vport: address of lpfc vport structure.
3972 *
3973 * Return codes:
3974 * zero on success
3975 * error return code from sysfs_create_bin_file()
3976 **/
dea31012005-04-17 16:05:31 -05003977int
James Smart2e0fef82007-06-17 19:56:36 -05003978lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003979{
James Smart2e0fef82007-06-17 19:56:36 -05003980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003981 int error;
3982
Tony Jonesee959b02008-02-22 00:13:36 +01003983 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003984 &sysfs_drvr_stat_data_attr);
3985
3986 /* Virtual ports do not need ctrl_reg and mbox */
3987 if (error || vport->port_type == LPFC_NPIV_PORT)
3988 goto out;
3989
3990 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003991 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003992 if (error)
James Smarteada2722008-12-04 22:39:13 -05003993 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003994
Tony Jonesee959b02008-02-22 00:13:36 +01003995 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003996 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003997 if (error)
3998 goto out_remove_ctlreg_attr;
3999
4000 return 0;
4001out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004002 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004003out_remove_stat_attr:
4004 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4005 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004006out:
4007 return error;
4008}
4009
James Smarte59058c2008-08-24 21:49:00 -04004010/**
James Smart3621a712009-04-06 18:47:14 -04004011 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004012 * @vport: address of lpfc vport structure.
4013 **/
dea31012005-04-17 16:05:31 -05004014void
James Smart2e0fef82007-06-17 19:56:36 -05004015lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004016{
James Smart2e0fef82007-06-17 19:56:36 -05004017 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004018 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4019 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004020 /* Virtual ports do not need ctrl_reg and mbox */
4021 if (vport->port_type == LPFC_NPIV_PORT)
4022 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004023 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4024 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004025}
4026
4027
4028/*
4029 * Dynamic FC Host Attributes Support
4030 */
4031
James Smarte59058c2008-08-24 21:49:00 -04004032/**
James Smart3621a712009-04-06 18:47:14 -04004033 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004034 * @shost: kernel scsi host pointer.
4035 **/
dea31012005-04-17 16:05:31 -05004036static void
4037lpfc_get_host_port_id(struct Scsi_Host *shost)
4038{
James Smart2e0fef82007-06-17 19:56:36 -05004039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4040
dea31012005-04-17 16:05:31 -05004041 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004042 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004043}
4044
James Smarte59058c2008-08-24 21:49:00 -04004045/**
James Smart3621a712009-04-06 18:47:14 -04004046 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004047 * @shost: kernel scsi host pointer.
4048 **/
dea31012005-04-17 16:05:31 -05004049static void
4050lpfc_get_host_port_type(struct Scsi_Host *shost)
4051{
James Smart2e0fef82007-06-17 19:56:36 -05004052 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4053 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004054
4055 spin_lock_irq(shost->host_lock);
4056
James Smart92d7f7b2007-06-17 19:56:38 -05004057 if (vport->port_type == LPFC_NPIV_PORT) {
4058 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4059 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004060 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004061 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004062 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4063 else
4064 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4065 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004066 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004067 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4068 else
4069 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4070 }
4071 } else
4072 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4073
4074 spin_unlock_irq(shost->host_lock);
4075}
4076
James Smarte59058c2008-08-24 21:49:00 -04004077/**
James Smart3621a712009-04-06 18:47:14 -04004078 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004079 * @shost: kernel scsi host pointer.
4080 **/
dea31012005-04-17 16:05:31 -05004081static void
4082lpfc_get_host_port_state(struct Scsi_Host *shost)
4083{
James Smart2e0fef82007-06-17 19:56:36 -05004084 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4085 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004086
4087 spin_lock_irq(shost->host_lock);
4088
James Smart2e0fef82007-06-17 19:56:36 -05004089 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004090 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4091 else {
James Smart2e0fef82007-06-17 19:56:36 -05004092 switch (phba->link_state) {
4093 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004094 case LPFC_LINK_DOWN:
4095 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4096 break;
4097 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004098 case LPFC_CLEAR_LA:
4099 case LPFC_HBA_READY:
4100 /* Links up, beyond this port_type reports state */
4101 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4102 break;
4103 case LPFC_HBA_ERROR:
4104 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4105 break;
4106 default:
4107 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4108 break;
4109 }
4110 }
4111
4112 spin_unlock_irq(shost->host_lock);
4113}
4114
James Smarte59058c2008-08-24 21:49:00 -04004115/**
James Smart3621a712009-04-06 18:47:14 -04004116 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004117 * @shost: kernel scsi host pointer.
4118 **/
dea31012005-04-17 16:05:31 -05004119static void
4120lpfc_get_host_speed(struct Scsi_Host *shost)
4121{
James Smart2e0fef82007-06-17 19:56:36 -05004122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4123 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004124
4125 spin_lock_irq(shost->host_lock);
4126
James Smart2e0fef82007-06-17 19:56:36 -05004127 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004128 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004129 case LPFC_LINK_SPEED_1GHZ:
4130 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004131 break;
James Smart76a95d72010-11-20 23:11:48 -05004132 case LPFC_LINK_SPEED_2GHZ:
4133 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004134 break;
James Smart76a95d72010-11-20 23:11:48 -05004135 case LPFC_LINK_SPEED_4GHZ:
4136 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004137 break;
James Smart76a95d72010-11-20 23:11:48 -05004138 case LPFC_LINK_SPEED_8GHZ:
4139 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004140 break;
James Smart76a95d72010-11-20 23:11:48 -05004141 case LPFC_LINK_SPEED_10GHZ:
4142 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004143 break;
James Smart76a95d72010-11-20 23:11:48 -05004144 case LPFC_LINK_SPEED_16GHZ:
4145 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4146 break;
4147 default:
4148 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004149 break;
4150 }
James Smart09372822008-01-11 01:52:54 -05004151 } else
4152 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004153
4154 spin_unlock_irq(shost->host_lock);
4155}
4156
James Smarte59058c2008-08-24 21:49:00 -04004157/**
James Smart3621a712009-04-06 18:47:14 -04004158 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004159 * @shost: kernel scsi host pointer.
4160 **/
dea31012005-04-17 16:05:31 -05004161static void
4162lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4163{
James Smart2e0fef82007-06-17 19:56:36 -05004164 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4165 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004166 u64 node_name;
dea31012005-04-17 16:05:31 -05004167
4168 spin_lock_irq(shost->host_lock);
4169
James Smart2e0fef82007-06-17 19:56:36 -05004170 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004171 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004172 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004173 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004174 else
4175 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004176 node_name = 0;
dea31012005-04-17 16:05:31 -05004177
4178 spin_unlock_irq(shost->host_lock);
4179
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004180 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004181}
4182
James Smarte59058c2008-08-24 21:49:00 -04004183/**
James Smart3621a712009-04-06 18:47:14 -04004184 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004185 * @shost: kernel scsi host pointer.
4186 *
4187 * Notes:
4188 * NULL on error for link down, no mbox pool, sli2 active,
4189 * management not allowed, memory allocation error, or mbox error.
4190 *
4191 * Returns:
4192 * NULL for error
4193 * address of the adapter host statistics
4194 **/
dea31012005-04-17 16:05:31 -05004195static struct fc_host_statistics *
4196lpfc_get_stats(struct Scsi_Host *shost)
4197{
James Smart2e0fef82007-06-17 19:56:36 -05004198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4199 struct lpfc_hba *phba = vport->phba;
4200 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004201 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004202 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004203 LPFC_MBOXQ_t *pmboxq;
4204 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004205 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004206 int rc = 0;
dea31012005-04-17 16:05:31 -05004207
James Smart92d7f7b2007-06-17 19:56:38 -05004208 /*
4209 * prevent udev from issuing mailbox commands until the port is
4210 * configured.
4211 */
James Smart2e0fef82007-06-17 19:56:36 -05004212 if (phba->link_state < LPFC_LINK_DOWN ||
4213 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004214 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004215 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004216
4217 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004218 return NULL;
4219
dea31012005-04-17 16:05:31 -05004220 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4221 if (!pmboxq)
4222 return NULL;
4223 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4224
James Smart04c68492009-05-22 14:52:52 -04004225 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004226 pmb->mbxCommand = MBX_READ_STATUS;
4227 pmb->mbxOwner = OWN_HOST;
4228 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004229 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004230
James Smart75baf692010-06-08 18:31:21 -04004231 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004232 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004233 else
dea31012005-04-17 16:05:31 -05004234 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4235
4236 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004237 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004238 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004239 return NULL;
4240 }
4241
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004242 memset(hs, 0, sizeof (struct fc_host_statistics));
4243
dea31012005-04-17 16:05:31 -05004244 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4245 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4246 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4247 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4248
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004249 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004250 pmb->mbxCommand = MBX_READ_LNK_STAT;
4251 pmb->mbxOwner = OWN_HOST;
4252 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004253 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004254
James Smart75baf692010-06-08 18:31:21 -04004255 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004256 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004257 else
dea31012005-04-17 16:05:31 -05004258 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4259
4260 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004261 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004262 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004263 return NULL;
4264 }
4265
4266 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4267 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4268 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4269 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4270 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4271 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4272 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4273
James Smart64ba8812006-08-02 15:24:34 -04004274 hs->link_failure_count -= lso->link_failure_count;
4275 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4276 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4277 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4278 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4279 hs->invalid_crc_count -= lso->invalid_crc_count;
4280 hs->error_frames -= lso->error_frames;
4281
James Smart76a95d72010-11-20 23:11:48 -05004282 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004283 hs->lip_count = -1;
4284 hs->nos_count = (phba->link_events >> 1);
4285 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004286 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004287 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004288 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004289 hs->nos_count = -1;
4290 } else {
4291 hs->lip_count = -1;
4292 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004293 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004294 }
4295
4296 hs->dumped_frames = -1;
4297
James Smart64ba8812006-08-02 15:24:34 -04004298 seconds = get_seconds();
4299 if (seconds < psli->stats_start)
4300 hs->seconds_since_last_reset = seconds +
4301 ((unsigned long)-1 - psli->stats_start);
4302 else
4303 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004304
James Smart1dcb58e2007-04-25 09:51:30 -04004305 mempool_free(pmboxq, phba->mbox_mem_pool);
4306
dea31012005-04-17 16:05:31 -05004307 return hs;
4308}
4309
James Smarte59058c2008-08-24 21:49:00 -04004310/**
James Smart3621a712009-04-06 18:47:14 -04004311 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004312 * @shost: kernel scsi host pointer.
4313 **/
James Smart64ba8812006-08-02 15:24:34 -04004314static void
4315lpfc_reset_stats(struct Scsi_Host *shost)
4316{
James Smart2e0fef82007-06-17 19:56:36 -05004317 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4318 struct lpfc_hba *phba = vport->phba;
4319 struct lpfc_sli *psli = &phba->sli;
4320 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004321 LPFC_MBOXQ_t *pmboxq;
4322 MAILBOX_t *pmb;
4323 int rc = 0;
4324
James Smart2e0fef82007-06-17 19:56:36 -05004325 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004326 return;
4327
James Smart64ba8812006-08-02 15:24:34 -04004328 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4329 if (!pmboxq)
4330 return;
4331 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4332
James Smart04c68492009-05-22 14:52:52 -04004333 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004334 pmb->mbxCommand = MBX_READ_STATUS;
4335 pmb->mbxOwner = OWN_HOST;
4336 pmb->un.varWords[0] = 0x1; /* reset request */
4337 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004338 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004339
James Smart2e0fef82007-06-17 19:56:36 -05004340 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004341 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004342 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4343 else
4344 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4345
4346 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004347 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004348 mempool_free(pmboxq, phba->mbox_mem_pool);
4349 return;
4350 }
4351
4352 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4353 pmb->mbxCommand = MBX_READ_LNK_STAT;
4354 pmb->mbxOwner = OWN_HOST;
4355 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004356 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004357
James Smart2e0fef82007-06-17 19:56:36 -05004358 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004359 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004360 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4361 else
4362 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4363
4364 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004365 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004366 mempool_free( pmboxq, phba->mbox_mem_pool);
4367 return;
4368 }
4369
4370 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4371 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4372 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4373 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4374 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4375 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4376 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004377 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004378 lso->link_events = (phba->link_events >> 1);
4379 else
4380 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004381
4382 psli->stats_start = get_seconds();
4383
James Smart1dcb58e2007-04-25 09:51:30 -04004384 mempool_free(pmboxq, phba->mbox_mem_pool);
4385
James Smart64ba8812006-08-02 15:24:34 -04004386 return;
4387}
dea31012005-04-17 16:05:31 -05004388
4389/*
4390 * The LPFC driver treats linkdown handling as target loss events so there
4391 * are no sysfs handlers for link_down_tmo.
4392 */
James Smart685f0bf2007-04-25 09:53:08 -04004393
James Smarte59058c2008-08-24 21:49:00 -04004394/**
James Smart3621a712009-04-06 18:47:14 -04004395 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004396 * @starget: kernel scsi target pointer.
4397 *
4398 * Returns:
4399 * address of the node list if found
4400 * NULL target not found
4401 **/
James Smart685f0bf2007-04-25 09:53:08 -04004402static struct lpfc_nodelist *
4403lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004404{
James Smart2e0fef82007-06-17 19:56:36 -05004405 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004407 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004408
4409 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004410 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004411 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004412 if (NLP_CHK_NODE_ACT(ndlp) &&
4413 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004414 starget->id == ndlp->nlp_sid) {
4415 spin_unlock_irq(shost->host_lock);
4416 return ndlp;
dea31012005-04-17 16:05:31 -05004417 }
4418 }
4419 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004420 return NULL;
4421}
dea31012005-04-17 16:05:31 -05004422
James Smarte59058c2008-08-24 21:49:00 -04004423/**
James Smart3621a712009-04-06 18:47:14 -04004424 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004425 * @starget: kernel scsi target pointer.
4426 **/
James Smart685f0bf2007-04-25 09:53:08 -04004427static void
4428lpfc_get_starget_port_id(struct scsi_target *starget)
4429{
4430 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4431
4432 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004433}
4434
James Smarte59058c2008-08-24 21:49:00 -04004435/**
James Smart3621a712009-04-06 18:47:14 -04004436 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004437 * @starget: kernel scsi target pointer.
4438 *
4439 * Description: Set the target node name to the ndlp node name wwn or zero.
4440 **/
dea31012005-04-17 16:05:31 -05004441static void
4442lpfc_get_starget_node_name(struct scsi_target *starget)
4443{
James Smart685f0bf2007-04-25 09:53:08 -04004444 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004445
James Smart685f0bf2007-04-25 09:53:08 -04004446 fc_starget_node_name(starget) =
4447 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004448}
4449
James Smarte59058c2008-08-24 21:49:00 -04004450/**
James Smart3621a712009-04-06 18:47:14 -04004451 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004452 * @starget: kernel scsi target pointer.
4453 *
4454 * Description: set the target port name to the ndlp port name wwn or zero.
4455 **/
dea31012005-04-17 16:05:31 -05004456static void
4457lpfc_get_starget_port_name(struct scsi_target *starget)
4458{
James Smart685f0bf2007-04-25 09:53:08 -04004459 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004460
James Smart685f0bf2007-04-25 09:53:08 -04004461 fc_starget_port_name(starget) =
4462 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004463}
4464
James Smarte59058c2008-08-24 21:49:00 -04004465/**
James Smart3621a712009-04-06 18:47:14 -04004466 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004467 * @rport: fc rport address.
4468 * @timeout: new value for dev loss tmo.
4469 *
4470 * Description:
4471 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4472 * dev_loss_tmo to one.
4473 **/
dea31012005-04-17 16:05:31 -05004474static void
dea31012005-04-17 16:05:31 -05004475lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4476{
dea31012005-04-17 16:05:31 -05004477 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004478 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004479 else
James Smartc01f3202006-08-18 17:47:08 -04004480 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004481}
4482
James Smarte59058c2008-08-24 21:49:00 -04004483/**
James Smart3621a712009-04-06 18:47:14 -04004484 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004485 *
4486 * Description:
4487 * Macro that uses field to generate a function with the name lpfc_show_rport_
4488 *
4489 * lpfc_show_rport_##field: returns the bytes formatted in buf
4490 * @cdev: class converted to an fc_rport.
4491 * @buf: on return contains the target_field or zero.
4492 *
4493 * Returns: size of formatted string.
4494 **/
dea31012005-04-17 16:05:31 -05004495#define lpfc_rport_show_function(field, format_string, sz, cast) \
4496static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004497lpfc_show_rport_##field (struct device *dev, \
4498 struct device_attribute *attr, \
4499 char *buf) \
dea31012005-04-17 16:05:31 -05004500{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004501 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004502 struct lpfc_rport_data *rdata = rport->hostdata; \
4503 return snprintf(buf, sz, format_string, \
4504 (rdata->target) ? cast rdata->target->field : 0); \
4505}
4506
4507#define lpfc_rport_rd_attr(field, format_string, sz) \
4508 lpfc_rport_show_function(field, format_string, sz, ) \
4509static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4510
James Smarteada2722008-12-04 22:39:13 -05004511/**
James Smart3621a712009-04-06 18:47:14 -04004512 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004513 * @fc_vport: The fc_vport who's symbolic name has been changed.
4514 *
4515 * Description:
4516 * This function is called by the transport after the @fc_vport's symbolic name
4517 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004518 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004519 **/
4520static void
4521lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4522{
4523 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4524
4525 if (vport->port_state == LPFC_VPORT_READY)
4526 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4527}
dea31012005-04-17 16:05:31 -05004528
James Smartf4b4c682009-05-22 14:53:12 -04004529/**
4530 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4531 * @phba: Pointer to lpfc_hba struct.
4532 *
4533 * This function is called by the lpfc_get_cfgparam() routine to set the
4534 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004535 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004536 * before hba port or vport created.
4537 **/
4538static void
4539lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4540{
4541 phba->cfg_log_verbose = verbose;
4542}
4543
dea31012005-04-17 16:05:31 -05004544struct fc_function_template lpfc_transport_functions = {
4545 /* fixed attributes the driver supports */
4546 .show_host_node_name = 1,
4547 .show_host_port_name = 1,
4548 .show_host_supported_classes = 1,
4549 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004550 .show_host_supported_speeds = 1,
4551 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004552 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004553
4554 /* dynamic attributes the driver supports */
4555 .get_host_port_id = lpfc_get_host_port_id,
4556 .show_host_port_id = 1,
4557
4558 .get_host_port_type = lpfc_get_host_port_type,
4559 .show_host_port_type = 1,
4560
4561 .get_host_port_state = lpfc_get_host_port_state,
4562 .show_host_port_state = 1,
4563
4564 /* active_fc4s is shown but doesn't change (thus no get function) */
4565 .show_host_active_fc4s = 1,
4566
4567 .get_host_speed = lpfc_get_host_speed,
4568 .show_host_speed = 1,
4569
4570 .get_host_fabric_name = lpfc_get_host_fabric_name,
4571 .show_host_fabric_name = 1,
4572
4573 /*
4574 * The LPFC driver treats linkdown handling as target loss events
4575 * so there are no sysfs handlers for link_down_tmo.
4576 */
4577
4578 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004579 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004580
4581 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4582 .show_rport_maxframe_size = 1,
4583 .show_rport_supported_classes = 1,
4584
dea31012005-04-17 16:05:31 -05004585 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4586 .show_rport_dev_loss_tmo = 1,
4587
4588 .get_starget_port_id = lpfc_get_starget_port_id,
4589 .show_starget_port_id = 1,
4590
4591 .get_starget_node_name = lpfc_get_starget_node_name,
4592 .show_starget_node_name = 1,
4593
4594 .get_starget_port_name = lpfc_get_starget_port_name,
4595 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004596
4597 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004598 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4599 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004600
James Smart92d7f7b2007-06-17 19:56:38 -05004601 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004602
4603 .vport_disable = lpfc_vport_disable,
4604
4605 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004606
4607 .bsg_request = lpfc_bsg_request,
4608 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004609};
4610
James Smart98c9ea52007-10-27 13:37:33 -04004611struct fc_function_template lpfc_vport_transport_functions = {
4612 /* fixed attributes the driver supports */
4613 .show_host_node_name = 1,
4614 .show_host_port_name = 1,
4615 .show_host_supported_classes = 1,
4616 .show_host_supported_fc4s = 1,
4617 .show_host_supported_speeds = 1,
4618 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004619 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004620
4621 /* dynamic attributes the driver supports */
4622 .get_host_port_id = lpfc_get_host_port_id,
4623 .show_host_port_id = 1,
4624
4625 .get_host_port_type = lpfc_get_host_port_type,
4626 .show_host_port_type = 1,
4627
4628 .get_host_port_state = lpfc_get_host_port_state,
4629 .show_host_port_state = 1,
4630
4631 /* active_fc4s is shown but doesn't change (thus no get function) */
4632 .show_host_active_fc4s = 1,
4633
4634 .get_host_speed = lpfc_get_host_speed,
4635 .show_host_speed = 1,
4636
4637 .get_host_fabric_name = lpfc_get_host_fabric_name,
4638 .show_host_fabric_name = 1,
4639
4640 /*
4641 * The LPFC driver treats linkdown handling as target loss events
4642 * so there are no sysfs handlers for link_down_tmo.
4643 */
4644
4645 .get_fc_host_stats = lpfc_get_stats,
4646 .reset_fc_host_stats = lpfc_reset_stats,
4647
4648 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4649 .show_rport_maxframe_size = 1,
4650 .show_rport_supported_classes = 1,
4651
4652 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4653 .show_rport_dev_loss_tmo = 1,
4654
4655 .get_starget_port_id = lpfc_get_starget_port_id,
4656 .show_starget_port_id = 1,
4657
4658 .get_starget_node_name = lpfc_get_starget_node_name,
4659 .show_starget_node_name = 1,
4660
4661 .get_starget_port_name = lpfc_get_starget_port_name,
4662 .show_starget_port_name = 1,
4663
4664 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4665 .terminate_rport_io = lpfc_terminate_rport_io,
4666
4667 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004668
4669 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004670};
4671
James Smarte59058c2008-08-24 21:49:00 -04004672/**
James Smart3621a712009-04-06 18:47:14 -04004673 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004674 * @phba: lpfc_hba pointer.
4675 **/
dea31012005-04-17 16:05:31 -05004676void
4677lpfc_get_cfgparam(struct lpfc_hba *phba)
4678{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004679 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4680 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004681 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004682 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4683 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004684 lpfc_ack0_init(phba, lpfc_ack0);
4685 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004686 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004687 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004688 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004689 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004690 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004691 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4692 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4693 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004694 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4695 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004696 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004697 if (phba->sli_rev == LPFC_SLI_REV4)
4698 phba->cfg_poll = 0;
4699 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004700 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004701 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004702 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004703 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004704 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004705 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004706 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004707 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004708 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004709 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05004710 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04004711 return;
4712}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004713
James Smarte59058c2008-08-24 21:49:00 -04004714/**
James Smart3621a712009-04-06 18:47:14 -04004715 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004716 * @vport: lpfc_vport pointer.
4717 **/
James Smart3de2a652007-08-02 11:09:59 -04004718void
4719lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4720{
James Smarte8b62012007-08-02 11:10:09 -04004721 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004722 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004723 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004724 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4725 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4726 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4727 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4728 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4729 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004730 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004731 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4732 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4733 lpfc_max_luns_init(vport, lpfc_max_luns);
4734 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004735 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004736 return;
4737}