blob: 44816be4d724e3ac6dde4738f061b98264123f7d [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 Smartc0c11512011-05-24 11:41:34 -0400758 * lpfc_sli4_fw_dump_request - Request firmware to perform a firmware dump
759 * @phba: lpfc_hba pointer.
760 *
761 * Description:
762 * Request SLI4 interface type-2 device to perform a dump of firmware dump
763 * object into it's /dbg directory of the flash file system.
764 *
765 * Returns:
766 * zero for success
767 **/
768static ssize_t
769lpfc_sli4_fw_dump_request(struct lpfc_hba *phba)
770{
771 struct completion online_compl;
772 uint32_t reg_val;
773 int status = 0;
774 int rc;
775
776 if (!phba->cfg_enable_hba_reset)
777 return -EIO;
778
779 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
780
781 if (status != 0)
782 return status;
783
784 /* wait for the device to be quiesced before firmware reset */
785 msleep(100);
786
787 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
788 LPFC_CTL_PDEV_CTL_OFFSET);
789 reg_val |= LPFC_FW_DUMP_REQUEST;
790 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
791 LPFC_CTL_PDEV_CTL_OFFSET);
792 /* flush */
793 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
794
795 /* delay driver action following IF_TYPE_2 reset */
796 msleep(100);
797
798 init_completion(&online_compl);
799 rc = lpfc_workq_post_event(phba, &status, &online_compl,
800 LPFC_EVT_ONLINE);
801 if (rc == 0)
802 return -ENOMEM;
803
804 wait_for_completion(&online_compl);
805
806 if (status != 0)
807 return -EIO;
808
809 return 0;
810}
811
812/**
James Smart3621a712009-04-06 18:47:14 -0400813 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400814 * @dev: class device that is converted into a Scsi_host.
815 * @attr: device attribute, not used.
816 * @buf: on return contains the ascii number of nport events.
817 *
818 * Returns: size of formatted string.
819 **/
dea31012005-04-17 16:05:31 -0500820static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100821lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
822 char *buf)
dea31012005-04-17 16:05:31 -0500823{
Tony Jonesee959b02008-02-22 00:13:36 +0100824 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
826 struct lpfc_hba *phba = vport->phba;
827
dea31012005-04-17 16:05:31 -0500828 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400833 * @dev: class device that is converted into a Scsi_host.
834 * @attr: device attribute, not used.
835 * @buf: on return contains the state of the adapter.
836 *
837 * Returns: size of formatted string.
838 **/
dea31012005-04-17 16:05:31 -0500839static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100840lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
841 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500842{
Tony Jonesee959b02008-02-22 00:13:36 +0100843 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
845 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500846 char * state;
847
James Smart2e0fef82007-06-17 19:56:36 -0500848 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500849 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500850 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500851 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500852 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500853 state = "offline";
854 else
855 state = "online";
856
857 return snprintf(buf, PAGE_SIZE, "%s\n", state);
858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart3621a712009-04-06 18:47:14 -0400861 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400862 * @dev: class device that is converted into a Scsi_host.
863 * @attr: device attribute, not used.
864 * @buf: containing one of the strings "online", "offline", "warm" or "error".
865 * @count: unused variable.
866 *
867 * Returns:
868 * -EACCES if enable hba reset not enabled
869 * -EINVAL if the buffer does not contain a valid string (see above)
870 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
871 * buf length greater than zero indicates success
872 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500873static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100874lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
875 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500876{
Tony Jonesee959b02008-02-22 00:13:36 +0100877 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500878 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
879 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500880 struct completion online_compl;
881 int status=0;
James Smartfedd3b72011-02-16 12:39:24 -0500882 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500883
James Smart13815c82008-01-11 01:52:48 -0500884 if (!phba->cfg_enable_hba_reset)
885 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500886 init_completion(&online_compl);
887
James Smart46fa3112007-04-25 09:51:45 -0400888 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -0500889 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500890 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500891 if (rc == 0)
892 return -ENOMEM;
James Smart46fa3112007-04-25 09:51:45 -0400893 wait_for_completion(&online_compl);
894 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
895 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500896 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400897 if (phba->sli_rev == LPFC_SLI_REV4)
898 return -EINVAL;
899 else
900 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400901 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400902 if (phba->sli_rev == LPFC_SLI_REV4)
903 return -EINVAL;
904 else
905 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -0400906 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
907 if ((phba->sli_rev < LPFC_SLI_REV4) ||
908 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
909 LPFC_SLI_INTF_IF_TYPE_2))
910 return -EPERM;
911 else
912 status = lpfc_sli4_fw_dump_request(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500913 else
914 return -EINVAL;
915
Jamie Wellnitz41415862006-02-28 19:25:27 -0500916 if (!status)
917 return strlen(buf);
918 else
919 return -EIO;
920}
921
James Smarte59058c2008-08-24 21:49:00 -0400922/**
James Smart3621a712009-04-06 18:47:14 -0400923 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400924 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400925 * @mxri: max xri count.
926 * @axri: available xri count.
927 * @mrpi: max rpi count.
928 * @arpi: available rpi count.
929 * @mvpi: max vpi count.
930 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400931 *
932 * Description:
933 * If an integer pointer for an count is not null then the value for the
934 * count is returned.
935 *
936 * Returns:
937 * zero on error
938 * one for success
939 **/
James Smart311464e2007-08-02 11:10:37 -0400940static int
James Smart858c9f62007-06-17 19:56:39 -0500941lpfc_get_hba_info(struct lpfc_hba *phba,
942 uint32_t *mxri, uint32_t *axri,
943 uint32_t *mrpi, uint32_t *arpi,
944 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500945{
James Smart04c68492009-05-22 14:52:52 -0400946 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500947 LPFC_MBOXQ_t *pmboxq;
948 MAILBOX_t *pmb;
949 int rc = 0;
James Smart15672312010-04-06 14:49:03 -0400950 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500951
952 /*
953 * prevent udev from issuing mailbox commands until the port is
954 * configured.
955 */
956 if (phba->link_state < LPFC_LINK_DOWN ||
957 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400958 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500959 return 0;
960
961 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
962 return 0;
963
964 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
965 if (!pmboxq)
966 return 0;
967 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
968
James Smart04c68492009-05-22 14:52:52 -0400969 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500970 pmb->mbxCommand = MBX_READ_CONFIG;
971 pmb->mbxOwner = OWN_HOST;
972 pmboxq->context1 = NULL;
973
James Smart75baf692010-06-08 18:31:21 -0400974 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -0500975 rc = MBX_NOT_FINISHED;
976 else
977 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
978
979 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500980 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500981 mempool_free(pmboxq, phba->mbox_mem_pool);
982 return 0;
983 }
984
James Smartda0436e2009-05-22 14:51:39 -0400985 if (phba->sli_rev == LPFC_SLI_REV4) {
986 rd_config = &pmboxq->u.mqe.un.rd_config;
987 if (mrpi)
988 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
989 if (arpi)
990 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
991 phba->sli4_hba.max_cfg_param.rpi_used;
992 if (mxri)
993 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
994 if (axri)
995 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
996 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -0400997
998 /* Account for differences with SLI-3. Get vpi count from
999 * mailbox data and subtract one for max vpi value.
1000 */
1001 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1002 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1003
James Smartda0436e2009-05-22 14:51:39 -04001004 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001005 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001006 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001007 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001008 } else {
1009 if (mrpi)
1010 *mrpi = pmb->un.varRdConfig.max_rpi;
1011 if (arpi)
1012 *arpi = pmb->un.varRdConfig.avail_rpi;
1013 if (mxri)
1014 *mxri = pmb->un.varRdConfig.max_xri;
1015 if (axri)
1016 *axri = pmb->un.varRdConfig.avail_xri;
1017 if (mvpi)
1018 *mvpi = pmb->un.varRdConfig.max_vpi;
1019 if (avpi)
1020 *avpi = pmb->un.varRdConfig.avail_vpi;
1021 }
James Smart92d7f7b2007-06-17 19:56:38 -05001022
1023 mempool_free(pmboxq, phba->mbox_mem_pool);
1024 return 1;
1025}
1026
James Smarte59058c2008-08-24 21:49:00 -04001027/**
James Smart3621a712009-04-06 18:47:14 -04001028 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001029 * @dev: class device that is converted into a Scsi_host.
1030 * @attr: device attribute, not used.
1031 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1032 *
1033 * Description:
1034 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1035 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1036 * to "Unknown" and the buffer length is returned, therefore the caller
1037 * must check for "Unknown" in the buffer to detect a failure.
1038 *
1039 * Returns: size of formatted string.
1040 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001041static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001042lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1043 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001044{
Tony Jonesee959b02008-02-22 00:13:36 +01001045 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1047 struct lpfc_hba *phba = vport->phba;
1048 uint32_t cnt;
1049
James Smart858c9f62007-06-17 19:56:39 -05001050 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001051 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1052 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1053}
1054
James Smarte59058c2008-08-24 21:49:00 -04001055/**
James Smart3621a712009-04-06 18:47:14 -04001056 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001057 * @dev: class device that is converted into a Scsi_host.
1058 * @attr: device attribute, not used.
1059 * @buf: containing the used rpi count in decimal or "Unknown".
1060 *
1061 * Description:
1062 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1063 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1064 * to "Unknown" and the buffer length is returned, therefore the caller
1065 * must check for "Unknown" in the buffer to detect a failure.
1066 *
1067 * Returns: size of formatted string.
1068 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001069static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001070lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1071 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001072{
Tony Jonesee959b02008-02-22 00:13:36 +01001073 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1075 struct lpfc_hba *phba = vport->phba;
1076 uint32_t cnt, acnt;
1077
James Smart858c9f62007-06-17 19:56:39 -05001078 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001079 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1080 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1081}
1082
James Smarte59058c2008-08-24 21:49:00 -04001083/**
James Smart3621a712009-04-06 18:47:14 -04001084 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001085 * @dev: class device that is converted into a Scsi_host.
1086 * @attr: device attribute, not used.
1087 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1088 *
1089 * Description:
1090 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1091 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1092 * to "Unknown" and the buffer length is returned, therefore the caller
1093 * must check for "Unknown" in the buffer to detect a failure.
1094 *
1095 * Returns: size of formatted string.
1096 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001098lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1099 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001100{
Tony Jonesee959b02008-02-22 00:13:36 +01001101 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1103 struct lpfc_hba *phba = vport->phba;
1104 uint32_t cnt;
1105
James Smart858c9f62007-06-17 19:56:39 -05001106 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001107 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1108 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1109}
1110
James Smarte59058c2008-08-24 21:49:00 -04001111/**
James Smart3621a712009-04-06 18:47:14 -04001112 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001113 * @dev: class device that is converted into a Scsi_host.
1114 * @attr: device attribute, not used.
1115 * @buf: on return contains the used xri count in decimal or "Unknown".
1116 *
1117 * Description:
1118 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1119 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1120 * to "Unknown" and the buffer length is returned, therefore the caller
1121 * must check for "Unknown" in the buffer to detect a failure.
1122 *
1123 * Returns: size of formatted string.
1124 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001125static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001126lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1127 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001128{
Tony Jonesee959b02008-02-22 00:13:36 +01001129 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1131 struct lpfc_hba *phba = vport->phba;
1132 uint32_t cnt, acnt;
1133
James Smart858c9f62007-06-17 19:56:39 -05001134 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1135 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1136 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1137}
1138
James Smarte59058c2008-08-24 21:49:00 -04001139/**
James Smart3621a712009-04-06 18:47:14 -04001140 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001141 * @dev: class device that is converted into a Scsi_host.
1142 * @attr: device attribute, not used.
1143 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1144 *
1145 * Description:
1146 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1147 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1148 * to "Unknown" and the buffer length is returned, therefore the caller
1149 * must check for "Unknown" in the buffer to detect a failure.
1150 *
1151 * Returns: size of formatted string.
1152 **/
James Smart858c9f62007-06-17 19:56:39 -05001153static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001154lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1155 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001156{
Tony Jonesee959b02008-02-22 00:13:36 +01001157 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1159 struct lpfc_hba *phba = vport->phba;
1160 uint32_t cnt;
1161
1162 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1163 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1164 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001169 * @dev: class device that is converted into a Scsi_host.
1170 * @attr: device attribute, not used.
1171 * @buf: on return contains the used vpi count in decimal or "Unknown".
1172 *
1173 * Description:
1174 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1175 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1176 * to "Unknown" and the buffer length is returned, therefore the caller
1177 * must check for "Unknown" in the buffer to detect a failure.
1178 *
1179 * Returns: size of formatted string.
1180 **/
James Smart858c9f62007-06-17 19:56:39 -05001181static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001182lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1183 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001184{
Tony Jonesee959b02008-02-22 00:13:36 +01001185 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1187 struct lpfc_hba *phba = vport->phba;
1188 uint32_t cnt, acnt;
1189
1190 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001191 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1192 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1193}
1194
James Smarte59058c2008-08-24 21:49:00 -04001195/**
James Smart3621a712009-04-06 18:47:14 -04001196 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001197 * @dev: class device that is converted into a Scsi_host.
1198 * @attr: device attribute, not used.
1199 * @buf: text that must be interpreted to determine if npiv is supported.
1200 *
1201 * Description:
1202 * Buffer will contain text indicating npiv is not suppoerted on the port,
1203 * the port is an NPIV physical port, or it is an npiv virtual port with
1204 * the id of the vport.
1205 *
1206 * Returns: size of formatted string.
1207 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001208static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001209lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1210 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001211{
Tony Jonesee959b02008-02-22 00:13:36 +01001212 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1214 struct lpfc_hba *phba = vport->phba;
1215
1216 if (!(phba->max_vpi))
1217 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1218 if (vport->port_type == LPFC_PHYSICAL_PORT)
1219 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1220 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1221}
1222
James Smarte59058c2008-08-24 21:49:00 -04001223/**
James Smart3621a712009-04-06 18:47:14 -04001224 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001225 * @dev: class device that is converted into a Scsi_host.
1226 * @attr: device attribute, not used.
1227 * @buf: on return contains the cfg_poll in hex.
1228 *
1229 * Notes:
1230 * cfg_poll should be a lpfc_polling_flags type.
1231 *
1232 * Returns: size of formatted string.
1233 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001234static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001235lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1236 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001237{
Tony Jonesee959b02008-02-22 00:13:36 +01001238 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1240 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001241
1242 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1243}
1244
James Smarte59058c2008-08-24 21:49:00 -04001245/**
James Smart3621a712009-04-06 18:47:14 -04001246 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001247 * @dev: class device that is converted into a Scsi_host.
1248 * @attr: device attribute, not used.
1249 * @buf: one or more lpfc_polling_flags values.
1250 * @count: not used.
1251 *
1252 * Notes:
1253 * buf contents converted to integer and checked for a valid value.
1254 *
1255 * Returns:
1256 * -EINVAL if the buffer connot be converted or is out of range
1257 * length of the buf on success
1258 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001259static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001260lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1261 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001262{
Tony Jonesee959b02008-02-22 00:13:36 +01001263 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1265 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001266 uint32_t creg_val;
1267 uint32_t old_val;
1268 int val=0;
1269
1270 if (!isdigit(buf[0]))
1271 return -EINVAL;
1272
1273 if (sscanf(buf, "%i", &val) != 1)
1274 return -EINVAL;
1275
1276 if ((val & 0x3) != val)
1277 return -EINVAL;
1278
James Smart45ed1192009-10-02 15:17:02 -04001279 if (phba->sli_rev == LPFC_SLI_REV4)
1280 val = 0;
1281
James Smart2e0fef82007-06-17 19:56:36 -05001282 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001283
1284 old_val = phba->cfg_poll;
1285
1286 if (val & ENABLE_FCP_RING_POLLING) {
1287 if ((val & DISABLE_FCP_RING_INT) &&
1288 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001289 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1290 spin_unlock_irq(&phba->hbalock);
1291 return -EINVAL;
1292 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001293 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1294 writel(creg_val, phba->HCregaddr);
1295 readl(phba->HCregaddr); /* flush */
1296
1297 lpfc_poll_start_timer(phba);
1298 }
1299 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001300 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001301 return -EINVAL;
1302 }
1303
1304 if (!(val & DISABLE_FCP_RING_INT) &&
1305 (old_val & DISABLE_FCP_RING_INT))
1306 {
James Smart2e0fef82007-06-17 19:56:36 -05001307 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001308 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001309 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001310 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1311 spin_unlock_irq(&phba->hbalock);
1312 return -EINVAL;
1313 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001314 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1315 writel(creg_val, phba->HCregaddr);
1316 readl(phba->HCregaddr); /* flush */
1317 }
1318
1319 phba->cfg_poll = val;
1320
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001322
1323 return strlen(buf);
1324}
dea31012005-04-17 16:05:31 -05001325
James Smarte59058c2008-08-24 21:49:00 -04001326/**
James Smartbc739052010-08-04 16:11:18 -04001327 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1328 * @dev: class unused variable.
1329 * @attr: device attribute, not used.
1330 * @buf: on return contains the module description text.
1331 *
1332 * Returns: size of formatted string.
1333 **/
1334static ssize_t
1335lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1336 char *buf)
1337{
1338 struct Scsi_Host *shost = class_to_shost(dev);
1339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1340 struct lpfc_hba *phba = vport->phba;
1341
1342 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1343}
1344
1345/**
1346 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1347 * @dev: class unused variable.
1348 * @attr: device attribute, not used.
1349 * @buf: on return contains the module description text.
1350 *
1351 * Returns: size of formatted string.
1352 **/
1353static ssize_t
1354lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1355 char *buf)
1356{
1357 struct Scsi_Host *shost = class_to_shost(dev);
1358 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1359 struct lpfc_hba *phba = vport->phba;
1360
1361 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1362}
1363
1364/**
James Smartab56dc22011-02-16 12:39:57 -05001365 * lpfc_dss_show - Return the current state of dss and the configured state
1366 * @dev: class converted to a Scsi_host structure.
1367 * @attr: device attribute, not used.
1368 * @buf: on return contains the formatted text.
1369 *
1370 * Returns: size of formatted string.
1371 **/
1372static ssize_t
1373lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1374 char *buf)
1375{
1376 struct Scsi_Host *shost = class_to_shost(dev);
1377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1378 struct lpfc_hba *phba = vport->phba;
1379
1380 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1381 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1382 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1383 "" : "Not ");
1384}
1385
1386/**
James Smart3621a712009-04-06 18:47:14 -04001387 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001388 *
1389 * Description:
1390 * Macro that given an attr e.g. hba_queue_depth expands
1391 * into a function with the name lpfc_hba_queue_depth_show.
1392 *
1393 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1394 * @dev: class device that is converted into a Scsi_host.
1395 * @attr: device attribute, not used.
1396 * @buf: on return contains the attribute value in decimal.
1397 *
1398 * Returns: size of formatted string.
1399 **/
dea31012005-04-17 16:05:31 -05001400#define lpfc_param_show(attr) \
1401static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001402lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1403 char *buf) \
dea31012005-04-17 16:05:31 -05001404{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001405 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1407 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001408 uint val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001409 val = phba->cfg_##attr;\
1410 return snprintf(buf, PAGE_SIZE, "%d\n",\
1411 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001412}
1413
James Smarte59058c2008-08-24 21:49:00 -04001414/**
James Smart3621a712009-04-06 18:47:14 -04001415 * lpfc_param_hex_show - Return a cfg attribute value in hex
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_show
1420 *
1421 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1422 * @dev: class device that is converted into a Scsi_host.
1423 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001424 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001425 *
1426 * Returns: size of formatted string.
1427 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001428#define lpfc_param_hex_show(attr) \
1429static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001430lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1431 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001432{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001433 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1435 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001436 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001437 val = phba->cfg_##attr;\
1438 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1439 phba->cfg_##attr);\
1440}
1441
James Smarte59058c2008-08-24 21:49:00 -04001442/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001443 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001444 *
1445 * Description:
1446 * Macro that given an attr e.g. hba_queue_depth expands
1447 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1448 * takes a default argument, a minimum and maximum argument.
1449 *
1450 * lpfc_##attr##_init: Initializes an attribute.
1451 * @phba: pointer the the adapter structure.
1452 * @val: integer attribute value.
1453 *
1454 * Validates the min and max values then sets the adapter config field
1455 * accordingly, or uses the default if out of range and prints an error message.
1456 *
1457 * Returns:
1458 * zero on success
1459 * -EINVAL if default used
1460 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001461#define lpfc_param_init(attr, default, minval, maxval) \
1462static int \
James Smart84d1b002010-02-12 14:42:33 -05001463lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001464{ \
1465 if (val >= minval && val <= maxval) {\
1466 phba->cfg_##attr = val;\
1467 return 0;\
1468 }\
1469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001470 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1471 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001472 phba->cfg_##attr = default;\
1473 return -EINVAL;\
1474}
1475
James Smarte59058c2008-08-24 21:49:00 -04001476/**
James Smart3621a712009-04-06 18:47:14 -04001477 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001478 *
1479 * Description:
1480 * Macro that given an attr e.g. hba_queue_depth expands
1481 * into a function with the name lpfc_hba_queue_depth_set
1482 *
1483 * lpfc_##attr##_set: Sets an attribute value.
1484 * @phba: pointer the the adapter structure.
1485 * @val: integer attribute value.
1486 *
1487 * Description:
1488 * Validates the min and max values then sets the
1489 * adapter config field if in the valid range. prints error message
1490 * and does not set the parameter if invalid.
1491 *
1492 * Returns:
1493 * zero on success
1494 * -EINVAL if val is invalid
1495 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001496#define lpfc_param_set(attr, default, minval, maxval) \
1497static int \
James Smart84d1b002010-02-12 14:42:33 -05001498lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001499{ \
1500 if (val >= minval && val <= maxval) {\
1501 phba->cfg_##attr = val;\
1502 return 0;\
1503 }\
1504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001505 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1506 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001507 return -EINVAL;\
1508}
1509
James Smarte59058c2008-08-24 21:49:00 -04001510/**
James Smart3621a712009-04-06 18:47:14 -04001511 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001512 *
1513 * Description:
1514 * Macro that given an attr e.g. hba_queue_depth expands
1515 * into a function with the name lpfc_hba_queue_depth_store.
1516 *
1517 * lpfc_##attr##_store: Set an sttribute value.
1518 * @dev: class device that is converted into a Scsi_host.
1519 * @attr: device attribute, not used.
1520 * @buf: contains the attribute value in ascii.
1521 * @count: not used.
1522 *
1523 * Description:
1524 * Convert the ascii text number to an integer, then
1525 * use the lpfc_##attr##_set function to set the value.
1526 *
1527 * Returns:
1528 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1529 * length of buffer upon success.
1530 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001531#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001532static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001533lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1534 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001535{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001536 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001537 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1538 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001539 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001540 if (!isdigit(buf[0]))\
1541 return -EINVAL;\
1542 if (sscanf(buf, "%i", &val) != 1)\
1543 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001544 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001545 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001546 else \
1547 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001548}
1549
James Smarte59058c2008-08-24 21:49:00 -04001550/**
James Smart3621a712009-04-06 18:47:14 -04001551 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001552 *
1553 * Description:
1554 * Macro that given an attr e.g. hba_queue_depth expands
1555 * into a function with the name lpfc_hba_queue_depth_show
1556 *
1557 * lpfc_##attr##_show: prints the attribute value in decimal.
1558 * @dev: class device that is converted into a Scsi_host.
1559 * @attr: device attribute, not used.
1560 * @buf: on return contains the attribute value in decimal.
1561 *
1562 * Returns: length of formatted string.
1563 **/
James Smart3de2a652007-08-02 11:09:59 -04001564#define lpfc_vport_param_show(attr) \
1565static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001566lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1567 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001568{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001569 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001571 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001572 val = vport->cfg_##attr;\
1573 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1574}
1575
James Smarte59058c2008-08-24 21:49:00 -04001576/**
James Smart3621a712009-04-06 18:47:14 -04001577 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001578 *
1579 * Description:
1580 * Macro that given an attr e.g.
1581 * hba_queue_depth expands into a function with the name
1582 * lpfc_hba_queue_depth_show
1583 *
James Smart3621a712009-04-06 18:47:14 -04001584 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001585 * @dev: class device that is converted into a Scsi_host.
1586 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001587 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001588 *
1589 * Returns: length of formatted string.
1590 **/
James Smart3de2a652007-08-02 11:09:59 -04001591#define lpfc_vport_param_hex_show(attr) \
1592static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001593lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1594 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001595{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001596 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001597 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001598 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001599 val = vport->cfg_##attr;\
1600 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1601}
1602
James Smarte59058c2008-08-24 21:49:00 -04001603/**
James Smart3621a712009-04-06 18:47:14 -04001604 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001605 *
1606 * Description:
1607 * Macro that given an attr e.g. hba_queue_depth expands
1608 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1609 * takes a default argument, a minimum and maximum argument.
1610 *
1611 * lpfc_##attr##_init: validates the min and max values then sets the
1612 * adapter config field accordingly, or uses the default if out of range
1613 * and prints an error message.
1614 * @phba: pointer the the adapter structure.
1615 * @val: integer attribute value.
1616 *
1617 * Returns:
1618 * zero on success
1619 * -EINVAL if default used
1620 **/
James Smart3de2a652007-08-02 11:09:59 -04001621#define lpfc_vport_param_init(attr, default, minval, maxval) \
1622static int \
James Smart84d1b002010-02-12 14:42:33 -05001623lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001624{ \
1625 if (val >= minval && val <= maxval) {\
1626 vport->cfg_##attr = val;\
1627 return 0;\
1628 }\
James Smarte8b62012007-08-02 11:10:09 -04001629 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001630 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001631 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001632 vport->cfg_##attr = default;\
1633 return -EINVAL;\
1634}
1635
James Smarte59058c2008-08-24 21:49:00 -04001636/**
James Smart3621a712009-04-06 18:47:14 -04001637 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001638 *
1639 * Description:
1640 * Macro that given an attr e.g. hba_queue_depth expands
1641 * into a function with the name lpfc_hba_queue_depth_set
1642 *
1643 * lpfc_##attr##_set: validates the min and max values then sets the
1644 * adapter config field if in the valid range. prints error message
1645 * and does not set the parameter if invalid.
1646 * @phba: pointer the the adapter structure.
1647 * @val: integer attribute value.
1648 *
1649 * Returns:
1650 * zero on success
1651 * -EINVAL if val is invalid
1652 **/
James Smart3de2a652007-08-02 11:09:59 -04001653#define lpfc_vport_param_set(attr, default, minval, maxval) \
1654static int \
James Smart84d1b002010-02-12 14:42:33 -05001655lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04001656{ \
1657 if (val >= minval && val <= maxval) {\
1658 vport->cfg_##attr = val;\
1659 return 0;\
1660 }\
James Smarte8b62012007-08-02 11:10:09 -04001661 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001662 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001663 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001664 return -EINVAL;\
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001669 *
1670 * Description:
1671 * Macro that given an attr e.g. hba_queue_depth
1672 * expands into a function with the name lpfc_hba_queue_depth_store
1673 *
1674 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1675 * use the lpfc_##attr##_set function to set the value.
1676 * @cdev: class device that is converted into a Scsi_host.
1677 * @buf: contains the attribute value in decimal.
1678 * @count: not used.
1679 *
1680 * Returns:
1681 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1682 * length of buffer upon success.
1683 **/
James Smart3de2a652007-08-02 11:09:59 -04001684#define lpfc_vport_param_store(attr) \
1685static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001686lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1687 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001688{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001689 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001690 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05001691 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04001692 if (!isdigit(buf[0]))\
1693 return -EINVAL;\
1694 if (sscanf(buf, "%i", &val) != 1)\
1695 return -EINVAL;\
1696 if (lpfc_##attr##_set(vport, val) == 0) \
1697 return strlen(buf);\
1698 else \
1699 return -EINVAL;\
1700}
1701
1702
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001703#define LPFC_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001704static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001705module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001706MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001707lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001708
1709#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001710static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001711module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001712MODULE_PARM_DESC(lpfc_##name, desc);\
1713lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001714lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001715static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001716
1717#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001718static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001719module_param(lpfc_##name, uint, S_IRUGO);\
dea31012005-04-17 16:05:31 -05001720MODULE_PARM_DESC(lpfc_##name, desc);\
1721lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001722lpfc_param_init(name, defval, minval, maxval)\
1723lpfc_param_set(name, defval, minval, maxval)\
1724lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001725static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1726 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001727
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001728#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001729static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001730module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001731MODULE_PARM_DESC(lpfc_##name, desc);\
1732lpfc_param_hex_show(name)\
1733lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001734static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001735
1736#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001737static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001738module_param(lpfc_##name, uint, S_IRUGO);\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001739MODULE_PARM_DESC(lpfc_##name, desc);\
1740lpfc_param_hex_show(name)\
1741lpfc_param_init(name, defval, minval, maxval)\
1742lpfc_param_set(name, defval, minval, maxval)\
1743lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001744static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1745 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001746
James Smart3de2a652007-08-02 11:09:59 -04001747#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001748static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001749module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001750MODULE_PARM_DESC(lpfc_##name, desc);\
1751lpfc_vport_param_init(name, defval, minval, maxval)
1752
1753#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001754static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001755module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001756MODULE_PARM_DESC(lpfc_##name, desc);\
1757lpfc_vport_param_show(name)\
1758lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001759static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001760
1761#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001762static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001763module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001764MODULE_PARM_DESC(lpfc_##name, desc);\
1765lpfc_vport_param_show(name)\
1766lpfc_vport_param_init(name, defval, minval, maxval)\
1767lpfc_vport_param_set(name, defval, minval, maxval)\
1768lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001769static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1770 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001771
1772#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001773static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001774module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001775MODULE_PARM_DESC(lpfc_##name, desc);\
1776lpfc_vport_param_hex_show(name)\
1777lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001778static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001779
1780#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
James Smart84d1b002010-02-12 14:42:33 -05001781static uint lpfc_##name = defval;\
James Smartab56dc22011-02-16 12:39:57 -05001782module_param(lpfc_##name, uint, S_IRUGO);\
James Smart3de2a652007-08-02 11:09:59 -04001783MODULE_PARM_DESC(lpfc_##name, desc);\
1784lpfc_vport_param_hex_show(name)\
1785lpfc_vport_param_init(name, defval, minval, maxval)\
1786lpfc_vport_param_set(name, defval, minval, maxval)\
1787lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001788static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1789 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001790
James Smart81301a92008-12-04 22:39:46 -05001791static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1792static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1793static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1794static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001795static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1796static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1797static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1798static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1799static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1800static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1801static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1802static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05001803static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1804 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01001805static DEVICE_ATTR(option_rom_version, S_IRUGO,
1806 lpfc_option_rom_version_show, NULL);
1807static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1808 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001809static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001810static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1811static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04001812static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001813static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1814 lpfc_board_mode_show, lpfc_board_mode_store);
1815static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1816static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1817static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1818static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1819static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1820static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1821static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1822static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1823static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04001824static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1825static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05001826static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smartc3f28af2006-08-18 17:47:18 -04001827
James Smarta12e07b2006-12-02 13:35:30 -05001828static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001829
James Smarte59058c2008-08-24 21:49:00 -04001830/**
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001832 * @dev: class device that is converted into a Scsi_host.
1833 * @attr: device attribute, not used.
1834 * @buf: containing the string lpfc_soft_wwn_key.
1835 * @count: must be size of lpfc_soft_wwn_key.
1836 *
1837 * Returns:
1838 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1839 * length of buf indicates success
1840 **/
James Smartc3f28af2006-08-18 17:47:18 -04001841static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001842lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1843 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001844{
Tony Jonesee959b02008-02-22 00:13:36 +01001845 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1847 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001848 unsigned int cnt = count;
1849
1850 /*
1851 * We're doing a simple sanity check for soft_wwpn setting.
1852 * We require that the user write a specific key to enable
1853 * the soft_wwpn attribute to be settable. Once the attribute
1854 * is written, the enable key resets. If further updates are
1855 * desired, the key must be written again to re-enable the
1856 * attribute.
1857 *
1858 * The "key" is not secret - it is a hardcoded string shown
1859 * here. The intent is to protect against the random user or
1860 * application that is just writing attributes.
1861 */
1862
1863 /* count may include a LF at end of string */
1864 if (buf[cnt-1] == '\n')
1865 cnt--;
1866
James Smarta12e07b2006-12-02 13:35:30 -05001867 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1868 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001869 return -EINVAL;
1870
James Smarta12e07b2006-12-02 13:35:30 -05001871 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001872 return count;
1873}
Tony Jonesee959b02008-02-22 00:13:36 +01001874static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1875 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001876
James Smarte59058c2008-08-24 21:49:00 -04001877/**
James Smart3621a712009-04-06 18:47:14 -04001878 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001879 * @dev: class device that is converted into a Scsi_host.
1880 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001881 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001882 *
1883 * Returns: size of formatted string.
1884 **/
James Smartc3f28af2006-08-18 17:47:18 -04001885static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001886lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1887 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001888{
Tony Jonesee959b02008-02-22 00:13:36 +01001889 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1891 struct lpfc_hba *phba = vport->phba;
1892
Randy Dunlapafc071e2006-10-23 21:47:13 -07001893 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1894 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001895}
1896
James Smarte59058c2008-08-24 21:49:00 -04001897/**
James Smart3621a712009-04-06 18:47:14 -04001898 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001899 * @dev class device that is converted into a Scsi_host.
1900 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001901 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001902 * @count: number of wwpn bytes in buf
1903 *
1904 * Returns:
1905 * -EACCES hba reset not enabled, adapter over temp
1906 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1907 * -EIO error taking adapter offline or online
1908 * value of count on success
1909 **/
James Smartc3f28af2006-08-18 17:47:18 -04001910static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001911lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1912 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001913{
Tony Jonesee959b02008-02-22 00:13:36 +01001914 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1916 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001917 struct completion online_compl;
1918 int stat1=0, stat2=0;
1919 unsigned int i, j, cnt=count;
1920 u8 wwpn[8];
James Smartfedd3b72011-02-16 12:39:24 -05001921 int rc;
James Smartc3f28af2006-08-18 17:47:18 -04001922
James Smart13815c82008-01-11 01:52:48 -05001923 if (!phba->cfg_enable_hba_reset)
1924 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001925 spin_lock_irq(&phba->hbalock);
1926 if (phba->over_temp_state == HBA_OVER_TEMP) {
1927 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001928 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001929 }
1930 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001931 /* count may include a LF at end of string */
1932 if (buf[cnt-1] == '\n')
1933 cnt--;
1934
James Smarta12e07b2006-12-02 13:35:30 -05001935 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001936 ((cnt == 17) && (*buf++ != 'x')) ||
1937 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1938 return -EINVAL;
1939
James Smarta12e07b2006-12-02 13:35:30 -05001940 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001941
1942 memset(wwpn, 0, sizeof(wwpn));
1943
1944 /* Validate and store the new name */
1945 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07001946 int value;
1947
1948 value = hex_to_bin(*buf++);
1949 if (value >= 0)
1950 j = (j << 4) | value;
James Smartc3f28af2006-08-18 17:47:18 -04001951 else
1952 return -EINVAL;
1953 if (i % 2) {
1954 wwpn[i/2] = j & 0xff;
1955 j = 0;
1956 }
1957 }
1958 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001959 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001960 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001961 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001962
1963 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1964 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1965
James Smart46fa3112007-04-25 09:51:45 -04001966 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001967 if (stat1)
1968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001969 "0463 lpfc_soft_wwpn attribute set failed to "
1970 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001971 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001972 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1973 LPFC_EVT_ONLINE);
1974 if (rc == 0)
1975 return -ENOMEM;
1976
James Smartc3f28af2006-08-18 17:47:18 -04001977 wait_for_completion(&online_compl);
1978 if (stat2)
1979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001980 "0464 lpfc_soft_wwpn attribute set failed to "
1981 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001982 return (stat1 || stat2) ? -EIO : count;
1983}
Tony Jonesee959b02008-02-22 00:13:36 +01001984static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1985 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001986
James Smarte59058c2008-08-24 21:49:00 -04001987/**
James Smart3621a712009-04-06 18:47:14 -04001988 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001989 * @dev: class device that is converted into a Scsi_host.
1990 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001991 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001992 *
1993 * Returns: size of formatted string.
1994 **/
James Smarta12e07b2006-12-02 13:35:30 -05001995static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001996lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1997 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001998{
Tony Jonesee959b02008-02-22 00:13:36 +01001999 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002000 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002001 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2002 (unsigned long long)phba->cfg_soft_wwnn);
2003}
2004
James Smarte59058c2008-08-24 21:49:00 -04002005/**
James Smart3621a712009-04-06 18:47:14 -04002006 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04002007 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04002008 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002009 * @count: number of wwnn bytes in buf.
2010 *
2011 * Returns:
2012 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2013 * value of count on success
2014 **/
James Smarta12e07b2006-12-02 13:35:30 -05002015static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002016lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2017 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05002018{
Tony Jonesee959b02008-02-22 00:13:36 +01002019 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04002020 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05002021 unsigned int i, j, cnt=count;
2022 u8 wwnn[8];
2023
2024 /* count may include a LF at end of string */
2025 if (buf[cnt-1] == '\n')
2026 cnt--;
2027
2028 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2029 ((cnt == 17) && (*buf++ != 'x')) ||
2030 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2031 return -EINVAL;
2032
2033 /*
2034 * Allow wwnn to be set many times, as long as the enable is set.
2035 * However, once the wwpn is set, everything locks.
2036 */
2037
2038 memset(wwnn, 0, sizeof(wwnn));
2039
2040 /* Validate and store the new name */
2041 for (i=0, j=0; i < 16; i++) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -07002042 int value;
2043
2044 value = hex_to_bin(*buf++);
2045 if (value >= 0)
2046 j = (j << 4) | value;
James Smarta12e07b2006-12-02 13:35:30 -05002047 else
2048 return -EINVAL;
2049 if (i % 2) {
2050 wwnn[i/2] = j & 0xff;
2051 j = 0;
2052 }
2053 }
2054 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2055
2056 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2057 "lpfc%d: soft_wwnn set. Value will take effect upon "
2058 "setting of the soft_wwpn\n", phba->brd_no);
2059
2060 return count;
2061}
Tony Jonesee959b02008-02-22 00:13:36 +01002062static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2063 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002064
James Smartc3f28af2006-08-18 17:47:18 -04002065
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002066static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002067module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002068MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2069 " 0 - none,"
2070 " 1 - poll with interrupts enabled"
2071 " 3 - poll and disable FCP ring interrupts");
2072
Tony Jonesee959b02008-02-22 00:13:36 +01002073static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2074 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002075
James Smart92d7f7b2007-06-17 19:56:38 -05002076int lpfc_sli_mode = 0;
James Smartab56dc22011-02-16 12:39:57 -05002077module_param(lpfc_sli_mode, int, S_IRUGO);
James Smart92d7f7b2007-06-17 19:56:38 -05002078MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2079 " 0 - auto (SLI-3 if supported),"
2080 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2081 " 3 - select SLI-3");
2082
James Smart15672312010-04-06 14:49:03 -04002083int lpfc_enable_npiv = 1;
James Smartab56dc22011-02-16 12:39:57 -05002084module_param(lpfc_enable_npiv, int, S_IRUGO);
James Smart7ee5d432007-10-27 13:37:17 -04002085MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2086lpfc_param_show(enable_npiv);
James Smart4b40c592010-03-15 11:25:44 -04002087lpfc_param_init(enable_npiv, 1, 0, 1);
James Smart15672312010-04-06 14:49:03 -04002088static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002089
James Smart19ca7602010-11-20 23:11:55 -05002090int lpfc_enable_rrq;
James Smartab56dc22011-02-16 12:39:57 -05002091module_param(lpfc_enable_rrq, int, S_IRUGO);
James Smart19ca7602010-11-20 23:11:55 -05002092MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2093lpfc_param_show(enable_rrq);
2094lpfc_param_init(enable_rrq, 0, 0, 1);
2095static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2096
dea31012005-04-17 16:05:31 -05002097/*
James Smart84d1b002010-02-12 14:42:33 -05002098# lpfc_suppress_link_up: Bring link up at initialization
2099# 0x0 = bring link up (issue MBX_INIT_LINK)
2100# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2101# 0x2 = never bring up link
2102# Default value is 0.
2103*/
James Smarte40a02c2010-02-26 14:13:54 -05002104LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2105 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2106 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002107/*
2108# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2109# 1 - (1024)
2110# 2 - (2048)
2111# 3 - (3072)
2112# 4 - (4096)
2113# 5 - (5120)
2114*/
2115static ssize_t
2116lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2117{
2118 struct Scsi_Host *shost = class_to_shost(dev);
2119 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2120
2121 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2122}
2123
2124static DEVICE_ATTR(iocb_hw, S_IRUGO,
2125 lpfc_iocb_hw_show, NULL);
2126static ssize_t
2127lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2128{
2129 struct Scsi_Host *shost = class_to_shost(dev);
2130 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2131
2132 return snprintf(buf, PAGE_SIZE, "%d\n",
2133 phba->sli.ring[LPFC_ELS_RING].txq_max);
2134}
2135
2136static DEVICE_ATTR(txq_hw, S_IRUGO,
2137 lpfc_txq_hw_show, NULL);
2138static ssize_t
2139lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2140 char *buf)
2141{
2142 struct Scsi_Host *shost = class_to_shost(dev);
2143 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2144
2145 return snprintf(buf, PAGE_SIZE, "%d\n",
2146 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2147}
2148
2149static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2150 lpfc_txcmplq_hw_show, NULL);
2151
2152int lpfc_iocb_cnt = 2;
James Smartab56dc22011-02-16 12:39:57 -05002153module_param(lpfc_iocb_cnt, int, S_IRUGO);
James Smart2a9bf3d2010-06-07 15:24:45 -04002154MODULE_PARM_DESC(lpfc_iocb_cnt,
2155 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2156lpfc_param_show(iocb_cnt);
2157lpfc_param_init(iocb_cnt, 2, 1, 5);
2158static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2159 lpfc_iocb_cnt_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002160
2161/*
James Smartc01f3202006-08-18 17:47:08 -04002162# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2163# until the timer expires. Value range is [0,255]. Default value is 30.
2164*/
2165static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2166static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2167module_param(lpfc_nodev_tmo, int, 0);
2168MODULE_PARM_DESC(lpfc_nodev_tmo,
2169 "Seconds driver will hold I/O waiting "
2170 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04002171
2172/**
James Smart3621a712009-04-06 18:47:14 -04002173 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04002174 * @dev: class converted to a Scsi_host structure.
2175 * @attr: device attribute, not used.
2176 * @buf: on return contains the dev loss timeout in decimal.
2177 *
2178 * Returns: size of formatted string.
2179 **/
James Smartc01f3202006-08-18 17:47:08 -04002180static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002181lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2182 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04002183{
Tony Jonesee959b02008-02-22 00:13:36 +01002184 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05002186
James Smart3de2a652007-08-02 11:09:59 -04002187 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04002188}
2189
James Smarte59058c2008-08-24 21:49:00 -04002190/**
James Smart3621a712009-04-06 18:47:14 -04002191 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04002192 * @vport: lpfc vport structure pointer.
2193 * @val: contains the nodev timeout value.
2194 *
2195 * Description:
2196 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2197 * 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_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002207{
James Smart3de2a652007-08-02 11:09:59 -04002208 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2209 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2210 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04002211 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002212 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04002213 "parameter because devloss_tmo is "
2214 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002215 return 0;
2216 }
2217
2218 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002219 vport->cfg_nodev_tmo = val;
2220 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04002221 return 0;
2222 }
James Smarte8b62012007-08-02 11:10:09 -04002223 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2224 "0400 lpfc_nodev_tmo attribute cannot be set to"
2225 " %d, allowed range is [%d, %d]\n",
2226 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04002227 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04002228 return -EINVAL;
2229}
2230
James Smarte59058c2008-08-24 21:49:00 -04002231/**
James Smart3621a712009-04-06 18:47:14 -04002232 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04002233 * @vport: lpfc vport structure pointer.
2234 *
2235 * Description:
2236 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2237 **/
James Smart7054a602007-04-25 09:52:34 -04002238static void
James Smart3de2a652007-08-02 11:09:59 -04002239lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04002240{
James Smart858c9f62007-06-17 19:56:39 -05002241 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04002242 struct lpfc_nodelist *ndlp;
2243
James Smart51ef4c22007-08-02 11:10:31 -04002244 shost = lpfc_shost_from_vport(vport);
2245 spin_lock_irq(shost->host_lock);
2246 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05002247 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04002248 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2249 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04002250}
2251
James Smarte59058c2008-08-24 21:49:00 -04002252/**
James Smart3621a712009-04-06 18:47:14 -04002253 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04002254 * @vport: lpfc vport structure pointer.
2255 * @val: contains the tmo value.
2256 *
2257 * Description:
2258 * If the devloss tmo is already set or the vport dev loss tmo has changed
2259 * then a kernel error message is printed and zero is returned.
2260 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2261 * Otherwise nodev tmo is set to the default value.
2262 *
2263 * Returns:
2264 * zero if already set or if val is in range
2265 * -EINVAL val out of range
2266 **/
James Smartc01f3202006-08-18 17:47:08 -04002267static int
James Smart3de2a652007-08-02 11:09:59 -04002268lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002269{
James Smart3de2a652007-08-02 11:09:59 -04002270 if (vport->dev_loss_tmo_changed ||
2271 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04002272 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2273 "0401 Ignoring change to nodev_tmo "
2274 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04002275 return 0;
2276 }
James Smartc01f3202006-08-18 17:47:08 -04002277 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002278 vport->cfg_nodev_tmo = val;
2279 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05002280 /*
2281 * For compat: set the fc_host dev loss so new rports
2282 * will get the value.
2283 */
2284 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002285 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002286 return 0;
2287 }
James Smarte8b62012007-08-02 11:10:09 -04002288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2289 "0403 lpfc_nodev_tmo attribute cannot be set to"
2290 "%d, allowed range is [%d, %d]\n",
2291 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002292 return -EINVAL;
2293}
2294
James Smart3de2a652007-08-02 11:09:59 -04002295lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002296
Tony Jonesee959b02008-02-22 00:13:36 +01002297static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2298 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002299
2300/*
2301# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2302# disappear until the timer expires. Value range is [0,255]. Default
2303# value is 30.
2304*/
James Smartab56dc22011-02-16 12:39:57 -05002305module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04002306MODULE_PARM_DESC(lpfc_devloss_tmo,
2307 "Seconds driver will hold I/O waiting "
2308 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002309lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2310 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2311lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002312
2313/**
James Smart3621a712009-04-06 18:47:14 -04002314 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002315 * @vport: lpfc vport structure pointer.
2316 * @val: contains the tmo value.
2317 *
2318 * Description:
2319 * If val is in a valid range then set the vport nodev tmo,
2320 * devloss tmo, also set the vport dev loss tmo changed flag.
2321 * Else a kernel error message is printed.
2322 *
2323 * Returns:
2324 * zero if val is in range
2325 * -EINVAL val out of range
2326 **/
James Smartc01f3202006-08-18 17:47:08 -04002327static int
James Smart3de2a652007-08-02 11:09:59 -04002328lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002329{
2330 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002331 vport->cfg_nodev_tmo = val;
2332 vport->cfg_devloss_tmo = val;
2333 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05002334 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04002335 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002336 return 0;
2337 }
2338
James Smarte8b62012007-08-02 11:10:09 -04002339 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2340 "0404 lpfc_devloss_tmo attribute cannot be set to"
2341 " %d, allowed range is [%d, %d]\n",
2342 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002343 return -EINVAL;
2344}
2345
James Smart3de2a652007-08-02 11:09:59 -04002346lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002347static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2348 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002349
2350/*
dea31012005-04-17 16:05:31 -05002351# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2352# deluged with LOTS of information.
2353# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002354# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002355*/
James Smartf4b4c682009-05-22 14:53:12 -04002356LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002357 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002358
2359/*
James Smart7ee5d432007-10-27 13:37:17 -04002360# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2361# objects that have been registered with the nameserver after login.
2362*/
2363LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2364 "Deregister nameserver objects before LOGO");
2365
2366/*
dea31012005-04-17 16:05:31 -05002367# lun_queue_depth: This parameter is used to limit the number of outstanding
2368# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2369*/
James Smart3de2a652007-08-02 11:09:59 -04002370LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2371 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002372
2373/*
James Smart7dc517d2010-07-14 15:32:10 -04002374# tgt_queue_depth: This parameter is used to limit the number of outstanding
2375# commands per target port. Value range is [10,65535]. Default value is 65535.
2376*/
2377LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2378 "Max number of FCP commands we can queue to a specific target port");
2379
2380/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002381# hba_queue_depth: This parameter is used to limit the number of outstanding
2382# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2383# value is greater than the maximum number of exchanges supported by the HBA,
2384# then maximum number of exchanges supported by the HBA is used to determine
2385# the hba_queue_depth.
2386*/
2387LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2388 "Max number of FCP commands we can queue to a lpfc HBA");
2389
2390/*
James Smart92d7f7b2007-06-17 19:56:38 -05002391# peer_port_login: This parameter allows/prevents logins
2392# between peer ports hosted on the same physical port.
2393# When this parameter is set 0 peer ports of same physical port
2394# are not allowed to login to each other.
2395# When this parameter is set 1 peer ports of same physical port
2396# are allowed to login to each other.
2397# Default value of this parameter is 0.
2398*/
James Smart3de2a652007-08-02 11:09:59 -04002399LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2400 "Allow peer ports on the same physical port to login to each "
2401 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002402
2403/*
James Smart3de2a652007-08-02 11:09:59 -04002404# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002405# between Virtual Ports and remote initiators.
2406# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2407# other initiators and will attempt to PLOGI all remote ports.
2408# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2409# remote ports and will not attempt to PLOGI to other initiators.
2410# This parameter does not restrict to the physical port.
2411# This parameter does not restrict logins to Fabric resident remote ports.
2412# Default value of this parameter is 1.
2413*/
James Smart3de2a652007-08-02 11:09:59 -04002414static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05002415module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04002416MODULE_PARM_DESC(lpfc_restrict_login,
2417 "Restrict virtual ports login to remote initiators.");
2418lpfc_vport_param_show(restrict_login);
2419
James Smarte59058c2008-08-24 21:49:00 -04002420/**
James Smart3621a712009-04-06 18:47:14 -04002421 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002422 * @vport: lpfc vport structure pointer.
2423 * @val: contains the restrict login value.
2424 *
2425 * Description:
2426 * If val is not in a valid range then log a kernel error message and set
2427 * the vport restrict login to one.
2428 * If the port type is physical clear the restrict login flag and return.
2429 * Else set the restrict login flag to val.
2430 *
2431 * Returns:
2432 * zero if val is in range
2433 * -EINVAL val out of range
2434 **/
James Smart3de2a652007-08-02 11:09:59 -04002435static int
2436lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2437{
2438 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002439 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002440 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002441 "be set to %d, allowed range is [0, 1]\n",
2442 val);
James Smart3de2a652007-08-02 11:09:59 -04002443 vport->cfg_restrict_login = 1;
2444 return -EINVAL;
2445 }
2446 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2447 vport->cfg_restrict_login = 0;
2448 return 0;
2449 }
2450 vport->cfg_restrict_login = val;
2451 return 0;
2452}
2453
James Smarte59058c2008-08-24 21:49:00 -04002454/**
James Smart3621a712009-04-06 18:47:14 -04002455 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002456 * @vport: lpfc vport structure pointer.
2457 * @val: contains the restrict login value.
2458 *
2459 * Description:
2460 * If val is not in a valid range then log a kernel error message and set
2461 * the vport restrict login to one.
2462 * If the port type is physical and the val is not zero log a kernel
2463 * error message, clear the restrict login flag and return zero.
2464 * Else set the restrict login flag to val.
2465 *
2466 * Returns:
2467 * zero if val is in range
2468 * -EINVAL val out of range
2469 **/
James Smart3de2a652007-08-02 11:09:59 -04002470static int
2471lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2472{
2473 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002474 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002475 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002476 "be set to %d, allowed range is [0, 1]\n",
2477 val);
James Smart3de2a652007-08-02 11:09:59 -04002478 vport->cfg_restrict_login = 1;
2479 return -EINVAL;
2480 }
2481 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002482 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2483 "0468 lpfc_restrict_login must be 0 for "
2484 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002485 vport->cfg_restrict_login = 0;
2486 return 0;
2487 }
2488 vport->cfg_restrict_login = val;
2489 return 0;
2490}
2491lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002492static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2493 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002494
2495/*
dea31012005-04-17 16:05:31 -05002496# Some disk devices have a "select ID" or "select Target" capability.
2497# From a protocol standpoint "select ID" usually means select the
2498# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2499# annex" which contains a table that maps a "select ID" (a number
2500# between 0 and 7F) to an ALPA. By default, for compatibility with
2501# older drivers, the lpfc driver scans this table from low ALPA to high
2502# ALPA.
2503#
2504# Turning on the scan-down variable (on = 1, off = 0) will
2505# cause the lpfc driver to use an inverted table, effectively
2506# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2507#
2508# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2509# and will not work across a fabric. Also this parameter will take
2510# effect only in the case when ALPA map is not available.)
2511*/
James Smart3de2a652007-08-02 11:09:59 -04002512LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2513 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002514
2515/*
dea31012005-04-17 16:05:31 -05002516# lpfc_topology: link topology for init link
2517# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002518# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002519# 0x02 = attempt point-to-point mode only
2520# 0x04 = attempt loop mode only
2521# 0x06 = attempt point-to-point mode then loop
2522# Set point-to-point mode if you want to run as an N_Port.
2523# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2524# Default value is 0.
2525*/
James Smarte59058c2008-08-24 21:49:00 -04002526
2527/**
James Smart3621a712009-04-06 18:47:14 -04002528 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002529 * @phba: lpfc_hba pointer.
2530 * @val: topology value.
2531 *
2532 * Description:
2533 * If val is in a valid range then set the adapter's topology field and
2534 * issue a lip; if the lip fails reset the topology to the old value.
2535 *
2536 * If the value is not in range log a kernel error message and return an error.
2537 *
2538 * Returns:
2539 * zero if val is in range and lip okay
2540 * non-zero return value from lpfc_issue_lip()
2541 * -EINVAL val out of range
2542 **/
James Smarta257bf92009-04-06 18:48:10 -04002543static ssize_t
2544lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2545 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002546{
James Smarta257bf92009-04-06 18:48:10 -04002547 struct Scsi_Host *shost = class_to_shost(dev);
2548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2549 struct lpfc_hba *phba = vport->phba;
2550 int val = 0;
2551 int nolip = 0;
2552 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002553 int err;
2554 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002555
2556 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2557 nolip = 1;
2558 val_buf = &buf[strlen("nolip ")];
2559 }
2560
2561 if (!isdigit(val_buf[0]))
2562 return -EINVAL;
2563 if (sscanf(val_buf, "%i", &val) != 1)
2564 return -EINVAL;
2565
James Smart83108bd2008-01-11 01:53:09 -05002566 if (val >= 0 && val <= 6) {
2567 prev_val = phba->cfg_topology;
2568 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002569 if (nolip)
2570 return strlen(buf);
2571
James Smart83108bd2008-01-11 01:53:09 -05002572 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002573 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002574 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002575 return -EINVAL;
2576 } else
2577 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002578 }
2579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2580 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2581 "allowed range is [0, 6]\n",
2582 phba->brd_no, val);
2583 return -EINVAL;
2584}
2585static int lpfc_topology = 0;
James Smartab56dc22011-02-16 12:39:57 -05002586module_param(lpfc_topology, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05002587MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2588lpfc_param_show(topology)
2589lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002590static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002591 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002592
James Smart21e9a0a2009-05-22 14:53:21 -04002593/**
2594 * lpfc_static_vport_show: Read callback function for
2595 * lpfc_static_vport sysfs file.
2596 * @dev: Pointer to class device object.
2597 * @attr: device attribute structure.
2598 * @buf: Data buffer.
2599 *
2600 * This function is the read call back function for
2601 * lpfc_static_vport sysfs file. The lpfc_static_vport
2602 * sysfs file report the mageability of the vport.
2603 **/
2604static ssize_t
2605lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2606 char *buf)
2607{
2608 struct Scsi_Host *shost = class_to_shost(dev);
2609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2610 if (vport->vport_flag & STATIC_VPORT)
2611 sprintf(buf, "1\n");
2612 else
2613 sprintf(buf, "0\n");
2614
2615 return strlen(buf);
2616}
2617
2618/*
2619 * Sysfs attribute to control the statistical data collection.
2620 */
2621static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2622 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002623
2624/**
James Smart3621a712009-04-06 18:47:14 -04002625 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002626 * @dev: Pointer to class device.
2627 * @buf: Data buffer.
2628 * @count: Size of the data buffer.
2629 *
2630 * This function get called when an user write to the lpfc_stat_data_ctrl
2631 * sysfs file. This function parse the command written to the sysfs file
2632 * and take appropriate action. These commands are used for controlling
2633 * driver statistical data collection.
2634 * Following are the command this function handles.
2635 *
2636 * setbucket <bucket_type> <base> <step>
2637 * = Set the latency buckets.
2638 * destroybucket = destroy all the buckets.
2639 * start = start data collection
2640 * stop = stop data collection
2641 * reset = reset the collected data
2642 **/
2643static ssize_t
2644lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2645 const char *buf, size_t count)
2646{
2647 struct Scsi_Host *shost = class_to_shost(dev);
2648 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2649 struct lpfc_hba *phba = vport->phba;
2650#define LPFC_MAX_DATA_CTRL_LEN 1024
2651 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2652 unsigned long i;
2653 char *str_ptr, *token;
2654 struct lpfc_vport **vports;
2655 struct Scsi_Host *v_shost;
2656 char *bucket_type_str, *base_str, *step_str;
2657 unsigned long base, step, bucket_type;
2658
2659 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002660 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002661 return -EINVAL;
2662
2663 strcpy(bucket_data, buf);
2664 str_ptr = &bucket_data[0];
2665 /* Ignore this token - this is command token */
2666 token = strsep(&str_ptr, "\t ");
2667 if (!token)
2668 return -EINVAL;
2669
2670 bucket_type_str = strsep(&str_ptr, "\t ");
2671 if (!bucket_type_str)
2672 return -EINVAL;
2673
2674 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2675 bucket_type = LPFC_LINEAR_BUCKET;
2676 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2677 bucket_type = LPFC_POWER2_BUCKET;
2678 else
2679 return -EINVAL;
2680
2681 base_str = strsep(&str_ptr, "\t ");
2682 if (!base_str)
2683 return -EINVAL;
2684 base = simple_strtoul(base_str, NULL, 0);
2685
2686 step_str = strsep(&str_ptr, "\t ");
2687 if (!step_str)
2688 return -EINVAL;
2689 step = simple_strtoul(step_str, NULL, 0);
2690 if (!step)
2691 return -EINVAL;
2692
2693 /* Block the data collection for every vport */
2694 vports = lpfc_create_vport_work_array(phba);
2695 if (vports == NULL)
2696 return -ENOMEM;
2697
James Smartf4b4c682009-05-22 14:53:12 -04002698 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002699 v_shost = lpfc_shost_from_vport(vports[i]);
2700 spin_lock_irq(v_shost->host_lock);
2701 /* Block and reset data collection */
2702 vports[i]->stat_data_blocked = 1;
2703 if (vports[i]->stat_data_enabled)
2704 lpfc_vport_reset_stat_data(vports[i]);
2705 spin_unlock_irq(v_shost->host_lock);
2706 }
2707
2708 /* Set the bucket attributes */
2709 phba->bucket_type = bucket_type;
2710 phba->bucket_base = base;
2711 phba->bucket_step = step;
2712
James Smartf4b4c682009-05-22 14:53:12 -04002713 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002714 v_shost = lpfc_shost_from_vport(vports[i]);
2715
2716 /* Unblock data collection */
2717 spin_lock_irq(v_shost->host_lock);
2718 vports[i]->stat_data_blocked = 0;
2719 spin_unlock_irq(v_shost->host_lock);
2720 }
2721 lpfc_destroy_vport_work_array(phba, vports);
2722 return strlen(buf);
2723 }
2724
2725 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2726 vports = lpfc_create_vport_work_array(phba);
2727 if (vports == NULL)
2728 return -ENOMEM;
2729
James Smartf4b4c682009-05-22 14:53:12 -04002730 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002731 v_shost = lpfc_shost_from_vport(vports[i]);
2732 spin_lock_irq(shost->host_lock);
2733 vports[i]->stat_data_blocked = 1;
2734 lpfc_free_bucket(vport);
2735 vport->stat_data_enabled = 0;
2736 vports[i]->stat_data_blocked = 0;
2737 spin_unlock_irq(shost->host_lock);
2738 }
2739 lpfc_destroy_vport_work_array(phba, vports);
2740 phba->bucket_type = LPFC_NO_BUCKET;
2741 phba->bucket_base = 0;
2742 phba->bucket_step = 0;
2743 return strlen(buf);
2744 }
2745
2746 if (!strncmp(buf, "start", strlen("start"))) {
2747 /* If no buckets configured return error */
2748 if (phba->bucket_type == LPFC_NO_BUCKET)
2749 return -EINVAL;
2750 spin_lock_irq(shost->host_lock);
2751 if (vport->stat_data_enabled) {
2752 spin_unlock_irq(shost->host_lock);
2753 return strlen(buf);
2754 }
2755 lpfc_alloc_bucket(vport);
2756 vport->stat_data_enabled = 1;
2757 spin_unlock_irq(shost->host_lock);
2758 return strlen(buf);
2759 }
2760
2761 if (!strncmp(buf, "stop", strlen("stop"))) {
2762 spin_lock_irq(shost->host_lock);
2763 if (vport->stat_data_enabled == 0) {
2764 spin_unlock_irq(shost->host_lock);
2765 return strlen(buf);
2766 }
2767 lpfc_free_bucket(vport);
2768 vport->stat_data_enabled = 0;
2769 spin_unlock_irq(shost->host_lock);
2770 return strlen(buf);
2771 }
2772
2773 if (!strncmp(buf, "reset", strlen("reset"))) {
2774 if ((phba->bucket_type == LPFC_NO_BUCKET)
2775 || !vport->stat_data_enabled)
2776 return strlen(buf);
2777 spin_lock_irq(shost->host_lock);
2778 vport->stat_data_blocked = 1;
2779 lpfc_vport_reset_stat_data(vport);
2780 vport->stat_data_blocked = 0;
2781 spin_unlock_irq(shost->host_lock);
2782 return strlen(buf);
2783 }
2784 return -EINVAL;
2785}
2786
2787
2788/**
James Smart3621a712009-04-06 18:47:14 -04002789 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002790 * @dev: Pointer to class device object.
2791 * @buf: Data buffer.
2792 *
2793 * This function is the read call back function for
2794 * lpfc_stat_data_ctrl sysfs file. This function report the
2795 * current statistical data collection state.
2796 **/
2797static ssize_t
2798lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2799 char *buf)
2800{
2801 struct Scsi_Host *shost = class_to_shost(dev);
2802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2803 struct lpfc_hba *phba = vport->phba;
2804 int index = 0;
2805 int i;
2806 char *bucket_type;
2807 unsigned long bucket_value;
2808
2809 switch (phba->bucket_type) {
2810 case LPFC_LINEAR_BUCKET:
2811 bucket_type = "linear";
2812 break;
2813 case LPFC_POWER2_BUCKET:
2814 bucket_type = "power2";
2815 break;
2816 default:
2817 bucket_type = "No Bucket";
2818 break;
2819 }
2820
2821 sprintf(&buf[index], "Statistical Data enabled :%d, "
2822 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2823 " Bucket step :%d\nLatency Ranges :",
2824 vport->stat_data_enabled, vport->stat_data_blocked,
2825 bucket_type, phba->bucket_base, phba->bucket_step);
2826 index = strlen(buf);
2827 if (phba->bucket_type != LPFC_NO_BUCKET) {
2828 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2829 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2830 bucket_value = phba->bucket_base +
2831 phba->bucket_step * i;
2832 else
2833 bucket_value = phba->bucket_base +
2834 (1 << i) * phba->bucket_step;
2835
2836 if (index + 10 > PAGE_SIZE)
2837 break;
2838 sprintf(&buf[index], "%08ld ", bucket_value);
2839 index = strlen(buf);
2840 }
2841 }
2842 sprintf(&buf[index], "\n");
2843 return strlen(buf);
2844}
2845
2846/*
2847 * Sysfs attribute to control the statistical data collection.
2848 */
2849static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2850 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2851
2852/*
2853 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2854 */
2855
2856/*
2857 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2858 * for each target.
2859 */
2860#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2861#define MAX_STAT_DATA_SIZE_PER_TARGET \
2862 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2863
2864
2865/**
James Smart3621a712009-04-06 18:47:14 -04002866 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07002867 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002868 * @kobj: Pointer to the kernel object
2869 * @bin_attr: Attribute object
2870 * @buff: Buffer pointer
2871 * @off: File offset
2872 * @count: Buffer size
2873 *
2874 * This function is the read call back function for lpfc_drvr_stat_data
2875 * sysfs file. This function export the statistical data to user
2876 * applications.
2877 **/
2878static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07002879sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2880 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04002881 char *buf, loff_t off, size_t count)
2882{
2883 struct device *dev = container_of(kobj, struct device,
2884 kobj);
2885 struct Scsi_Host *shost = class_to_shost(dev);
2886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2887 struct lpfc_hba *phba = vport->phba;
2888 int i = 0, index = 0;
2889 unsigned long nport_index;
2890 struct lpfc_nodelist *ndlp = NULL;
2891 nport_index = (unsigned long)off /
2892 MAX_STAT_DATA_SIZE_PER_TARGET;
2893
2894 if (!vport->stat_data_enabled || vport->stat_data_blocked
2895 || (phba->bucket_type == LPFC_NO_BUCKET))
2896 return 0;
2897
2898 spin_lock_irq(shost->host_lock);
2899 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2900 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2901 continue;
2902
2903 if (nport_index > 0) {
2904 nport_index--;
2905 continue;
2906 }
2907
2908 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2909 > count)
2910 break;
2911
2912 if (!ndlp->lat_data)
2913 continue;
2914
2915 /* Print the WWN */
2916 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2917 ndlp->nlp_portname.u.wwn[0],
2918 ndlp->nlp_portname.u.wwn[1],
2919 ndlp->nlp_portname.u.wwn[2],
2920 ndlp->nlp_portname.u.wwn[3],
2921 ndlp->nlp_portname.u.wwn[4],
2922 ndlp->nlp_portname.u.wwn[5],
2923 ndlp->nlp_portname.u.wwn[6],
2924 ndlp->nlp_portname.u.wwn[7]);
2925
2926 index = strlen(buf);
2927
2928 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2929 sprintf(&buf[index], "%010u,",
2930 ndlp->lat_data[i].cmd_count);
2931 index = strlen(buf);
2932 }
2933 sprintf(&buf[index], "\n");
2934 index = strlen(buf);
2935 }
2936 spin_unlock_irq(shost->host_lock);
2937 return index;
2938}
2939
2940static struct bin_attribute sysfs_drvr_stat_data_attr = {
2941 .attr = {
2942 .name = "lpfc_drvr_stat_data",
2943 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04002944 },
2945 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2946 .read = sysfs_drvr_stat_data_read,
2947 .write = NULL,
2948};
2949
dea31012005-04-17 16:05:31 -05002950/*
2951# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2952# connection.
James Smart76a95d72010-11-20 23:11:48 -05002953# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05002954*/
James Smarte59058c2008-08-24 21:49:00 -04002955/**
James Smart3621a712009-04-06 18:47:14 -04002956 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002957 * @phba: lpfc_hba pointer.
2958 * @val: link speed value.
2959 *
2960 * Description:
2961 * If val is in a valid range then set the adapter's link speed field and
2962 * issue a lip; if the lip fails reset the link speed to the old value.
2963 *
2964 * Notes:
2965 * If the value is not in range log a kernel error message and return an error.
2966 *
2967 * Returns:
2968 * zero if val is in range and lip okay.
2969 * non-zero return value from lpfc_issue_lip()
2970 * -EINVAL val out of range
2971 **/
James Smarta257bf92009-04-06 18:48:10 -04002972static ssize_t
2973lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2974 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002975{
James Smarta257bf92009-04-06 18:48:10 -04002976 struct Scsi_Host *shost = class_to_shost(dev);
2977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2978 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05002979 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04002980 int nolip = 0;
2981 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002982 int err;
2983 uint32_t prev_val;
2984
James Smarta257bf92009-04-06 18:48:10 -04002985 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2986 nolip = 1;
2987 val_buf = &buf[strlen("nolip ")];
2988 }
2989
2990 if (!isdigit(val_buf[0]))
2991 return -EINVAL;
2992 if (sscanf(val_buf, "%i", &val) != 1)
2993 return -EINVAL;
2994
James Smart76a95d72010-11-20 23:11:48 -05002995 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2996 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2997 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2998 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2999 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3000 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3002 "2879 lpfc_link_speed attribute cannot be set "
3003 "to %d. Speed is not supported by this port.\n",
3004 val);
James Smart83108bd2008-01-11 01:53:09 -05003005 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003006 }
3007 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3008 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003009 prev_val = phba->cfg_link_speed;
3010 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003011 if (nolip)
3012 return strlen(buf);
3013
James Smart83108bd2008-01-11 01:53:09 -05003014 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003015 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003016 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003017 return -EINVAL;
3018 } else
3019 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003020 }
James Smart83108bd2008-01-11 01:53:09 -05003021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003022 "0469 lpfc_link_speed attribute cannot be set to %d, "
3023 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003024 return -EINVAL;
3025}
3026
3027static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003028module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003029MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3030lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003031
3032/**
James Smart3621a712009-04-06 18:47:14 -04003033 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003034 * @phba: lpfc_hba pointer.
3035 * @val: link speed value.
3036 *
3037 * Description:
3038 * If val is in a valid range then set the adapter's link speed field.
3039 *
3040 * Notes:
3041 * If the value is not in range log a kernel error message, clear the link
3042 * speed and return an error.
3043 *
3044 * Returns:
3045 * zero if val saved.
3046 * -EINVAL val out of range
3047 **/
James Smart83108bd2008-01-11 01:53:09 -05003048static int
3049lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3050{
James Smart76a95d72010-11-20 23:11:48 -05003051 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3052 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003053 phba->cfg_link_speed = val;
3054 return 0;
3055 }
3056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003057 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003058 "be set to %d, allowed values are "
3059 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003060 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003061 return -EINVAL;
3062}
3063
Tony Jonesee959b02008-02-22 00:13:36 +01003064static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003065 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003066
3067/*
James Smart0d878412009-10-02 15:16:56 -04003068# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3069# 0 = aer disabled or not supported
3070# 1 = aer supported and enabled (default)
3071# Value range is [0,1]. Default value is 1.
3072*/
3073
3074/**
3075 * lpfc_aer_support_store - Set the adapter for aer support
3076 *
3077 * @dev: class device that is converted into a Scsi_host.
3078 * @attr: device attribute, not used.
3079 * @buf: containing the string "selective".
3080 * @count: unused variable.
3081 *
3082 * Description:
3083 * If the val is 1 and currently the device's AER capability was not
3084 * enabled, invoke the kernel's enable AER helper routine, trying to
3085 * enable the device's AER capability. If the helper routine enabling
3086 * AER returns success, update the device's cfg_aer_support flag to
3087 * indicate AER is supported by the device; otherwise, if the device
3088 * AER capability is already enabled to support AER, then do nothing.
3089 *
3090 * If the val is 0 and currently the device's AER support was enabled,
3091 * invoke the kernel's disable AER helper routine. After that, update
3092 * the device's cfg_aer_support flag to indicate AER is not supported
3093 * by the device; otherwise, if the device AER capability is already
3094 * disabled from supporting AER, then do nothing.
3095 *
3096 * Returns:
3097 * length of the buf on success if val is in range the intended mode
3098 * is supported.
3099 * -EINVAL if val out of range or intended mode is not supported.
3100 **/
3101static ssize_t
3102lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3103 const char *buf, size_t count)
3104{
3105 struct Scsi_Host *shost = class_to_shost(dev);
3106 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3107 struct lpfc_hba *phba = vport->phba;
3108 int val = 0, rc = -EINVAL;
3109
3110 if (!isdigit(buf[0]))
3111 return -EINVAL;
3112 if (sscanf(buf, "%i", &val) != 1)
3113 return -EINVAL;
3114
3115 switch (val) {
3116 case 0:
3117 if (phba->hba_flag & HBA_AER_ENABLED) {
3118 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3119 if (!rc) {
3120 spin_lock_irq(&phba->hbalock);
3121 phba->hba_flag &= ~HBA_AER_ENABLED;
3122 spin_unlock_irq(&phba->hbalock);
3123 phba->cfg_aer_support = 0;
3124 rc = strlen(buf);
3125 } else
James Smart891478a2009-11-18 15:40:23 -05003126 rc = -EPERM;
3127 } else {
James Smart0d878412009-10-02 15:16:56 -04003128 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05003129 rc = strlen(buf);
3130 }
James Smart0d878412009-10-02 15:16:56 -04003131 break;
3132 case 1:
3133 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3134 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3135 if (!rc) {
3136 spin_lock_irq(&phba->hbalock);
3137 phba->hba_flag |= HBA_AER_ENABLED;
3138 spin_unlock_irq(&phba->hbalock);
3139 phba->cfg_aer_support = 1;
3140 rc = strlen(buf);
3141 } else
James Smart891478a2009-11-18 15:40:23 -05003142 rc = -EPERM;
3143 } else {
James Smart0d878412009-10-02 15:16:56 -04003144 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05003145 rc = strlen(buf);
3146 }
James Smart0d878412009-10-02 15:16:56 -04003147 break;
3148 default:
3149 rc = -EINVAL;
3150 break;
3151 }
3152 return rc;
3153}
3154
3155static int lpfc_aer_support = 1;
James Smartab56dc22011-02-16 12:39:57 -05003156module_param(lpfc_aer_support, int, S_IRUGO);
James Smart0d878412009-10-02 15:16:56 -04003157MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3158lpfc_param_show(aer_support)
3159
3160/**
3161 * lpfc_aer_support_init - Set the initial adapters aer support flag
3162 * @phba: lpfc_hba pointer.
3163 * @val: link speed value.
3164 *
3165 * Description:
3166 * If val is in a valid range [0,1], then set the adapter's initial
3167 * cfg_aer_support field. It will be up to the driver's probe_one
3168 * routine to determine whether the device's AER support can be set
3169 * or not.
3170 *
3171 * Notes:
3172 * If the value is not in range log a kernel error message, and
3173 * choose the default value of setting AER support and return.
3174 *
3175 * Returns:
3176 * zero if val saved.
3177 * -EINVAL val out of range
3178 **/
3179static int
3180lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3181{
3182 if (val == 0 || val == 1) {
3183 phba->cfg_aer_support = val;
3184 return 0;
3185 }
3186 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3187 "2712 lpfc_aer_support attribute value %d out "
3188 "of range, allowed values are 0|1, setting it "
3189 "to default value of 1\n", val);
James Smart891478a2009-11-18 15:40:23 -05003190 /* By default, try to enable AER on a device */
James Smart0d878412009-10-02 15:16:56 -04003191 phba->cfg_aer_support = 1;
3192 return -EINVAL;
3193}
3194
3195static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3196 lpfc_aer_support_show, lpfc_aer_support_store);
3197
3198/**
3199 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3200 * @dev: class device that is converted into a Scsi_host.
3201 * @attr: device attribute, not used.
3202 * @buf: containing the string "selective".
3203 * @count: unused variable.
3204 *
3205 * Description:
3206 * If the @buf contains 1 and the device currently has the AER support
3207 * enabled, then invokes the kernel AER helper routine
3208 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3209 * error status register.
3210 *
3211 * Notes:
3212 *
3213 * Returns:
3214 * -EINVAL if the buf does not contain the 1 or the device is not currently
3215 * enabled with the AER support.
3216 **/
3217static ssize_t
3218lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3219 const char *buf, size_t count)
3220{
3221 struct Scsi_Host *shost = class_to_shost(dev);
3222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3223 struct lpfc_hba *phba = vport->phba;
3224 int val, rc = -1;
3225
3226 if (!isdigit(buf[0]))
3227 return -EINVAL;
3228 if (sscanf(buf, "%i", &val) != 1)
3229 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05003230 if (val != 1)
3231 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04003232
James Smart891478a2009-11-18 15:40:23 -05003233 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04003234 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3235
3236 if (rc == 0)
3237 return strlen(buf);
3238 else
James Smart891478a2009-11-18 15:40:23 -05003239 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04003240}
3241
3242static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3243 lpfc_aer_cleanup_state);
3244
3245/*
dea31012005-04-17 16:05:31 -05003246# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3247# Value range is [2,3]. Default value is 3.
3248*/
James Smart3de2a652007-08-02 11:09:59 -04003249LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3250 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05003251
3252/*
3253# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3254# is [0,1]. Default value is 0.
3255*/
James Smart3de2a652007-08-02 11:09:59 -04003256LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3257 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05003258
3259/*
James Smart977b5a02008-09-07 11:52:04 -04003260# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3261# depth. Default value is 0. When the value of this parameter is zero the
3262# SCSI command completion time is not used for controlling I/O queue depth. When
3263# the parameter is set to a non-zero value, the I/O queue depth is controlled
3264# to limit the I/O completion time to the parameter value.
3265# The value is set in milliseconds.
3266*/
3267static int lpfc_max_scsicmpl_time;
James Smartab56dc22011-02-16 12:39:57 -05003268module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
James Smart977b5a02008-09-07 11:52:04 -04003269MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3270 "Use command completion time to control queue depth");
3271lpfc_vport_param_show(max_scsicmpl_time);
3272lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3273static int
3274lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3275{
3276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3277 struct lpfc_nodelist *ndlp, *next_ndlp;
3278
3279 if (val == vport->cfg_max_scsicmpl_time)
3280 return 0;
3281 if ((val < 0) || (val > 60000))
3282 return -EINVAL;
3283 vport->cfg_max_scsicmpl_time = val;
3284
3285 spin_lock_irq(shost->host_lock);
3286 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3287 if (!NLP_CHK_NODE_ACT(ndlp))
3288 continue;
3289 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3290 continue;
James Smart7dc517d2010-07-14 15:32:10 -04003291 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04003292 }
3293 spin_unlock_irq(shost->host_lock);
3294 return 0;
3295}
3296lpfc_vport_param_store(max_scsicmpl_time);
3297static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3298 lpfc_max_scsicmpl_time_show,
3299 lpfc_max_scsicmpl_time_store);
3300
3301/*
dea31012005-04-17 16:05:31 -05003302# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3303# range is [0,1]. Default value is 0.
3304*/
3305LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3306
3307/*
3308# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3309# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003310# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003311# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3312# cr_delay is set to 0.
3313*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003314LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003315 "interrupt response is generated");
3316
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003317LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003318 "interrupt response is generated");
3319
3320/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003321# lpfc_multi_ring_support: Determines how many rings to spread available
3322# cmd/rsp IOCB entries across.
3323# Value range is [1,2]. Default value is 1.
3324*/
3325LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3326 "SLI rings to spread IOCB entries across");
3327
3328/*
James Smarta4bc3372006-12-02 13:34:16 -05003329# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3330# identifies what rctl value to configure the additional ring for.
3331# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3332*/
James Smart6a9c52c2009-10-02 15:16:51 -04003333LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003334 255, "Identifies RCTL for additional ring configuration");
3335
3336/*
3337# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3338# identifies what type value to configure the additional ring for.
3339# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3340*/
James Smart6a9c52c2009-10-02 15:16:51 -04003341LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003342 255, "Identifies TYPE for additional ring configuration");
3343
3344/*
dea31012005-04-17 16:05:31 -05003345# lpfc_fdmi_on: controls FDMI support.
3346# 0 = no FDMI support
3347# 1 = support FDMI without attribute of hostname
3348# 2 = support FDMI with attribute of hostname
3349# Value range [0,2]. Default value is 0.
3350*/
James Smart3de2a652007-08-02 11:09:59 -04003351LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003352
3353/*
3354# Specifies the maximum number of ELS cmds we can have outstanding (for
3355# discovery). Value range is [1,64]. Default value = 32.
3356*/
James Smart3de2a652007-08-02 11:09:59 -04003357LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003358 "during discovery");
3359
3360/*
James Smart65a29c12006-07-06 15:50:50 -04003361# lpfc_max_luns: maximum allowed LUN.
3362# Value range is [0,65535]. Default value is 255.
3363# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003364*/
James Smart3de2a652007-08-02 11:09:59 -04003365LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003366
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003367/*
3368# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3369# Value range is [1,255], default value is 10.
3370*/
3371LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3372 "Milliseconds driver will wait between polling FCP ring");
3373
James Smart4ff43242006-12-02 13:34:56 -05003374/*
3375# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3376# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02003377# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05003378# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02003379# 2 = MSI-X enabled (default)
3380# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05003381*/
George Kadianakis8605c462010-01-17 21:19:31 +02003382LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003383 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003384
James Smart13815c82008-01-11 01:52:48 -05003385/*
James Smartda0436e2009-05-22 14:51:39 -04003386# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3387#
3388# Value range is [636,651042]. Default value is 10000.
3389*/
3390LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3391 "Set the maximum number of fast-path FCP interrupts per second");
3392
3393/*
3394# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3395#
3396# Value range is [1,31]. Default value is 4.
3397*/
3398LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3399 "Set the number of fast-path FCP work queues, if possible");
3400
3401/*
3402# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3403#
3404# Value range is [1,7]. Default value is 1.
3405*/
3406LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3407 "Set the number of fast-path FCP event queues, if possible");
3408
3409/*
James Smart13815c82008-01-11 01:52:48 -05003410# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3411# 0 = HBA resets disabled
3412# 1 = HBA resets enabled (default)
3413# Value range is [0,1]. Default value is 1.
3414*/
3415LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003416
James Smart13815c82008-01-11 01:52:48 -05003417/*
James Smarteb7a3392010-11-20 23:12:02 -05003418# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05003419# 0 = HBA Heartbeat disabled
3420# 1 = HBA Heartbeat enabled (default)
3421# Value range is [0,1]. Default value is 1.
3422*/
James Smarteb7a3392010-11-20 23:12:02 -05003423LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003424
James Smart83108bd2008-01-11 01:53:09 -05003425/*
James Smart81301a92008-12-04 22:39:46 -05003426# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3427# 0 = BlockGuard disabled (default)
3428# 1 = BlockGuard enabled
3429# Value range is [0,1]. Default value is 0.
3430*/
3431LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3432
James Smart6fb120a2009-05-22 14:52:59 -04003433/*
James Smart81301a92008-12-04 22:39:46 -05003434# lpfc_prot_mask: i
3435# - Bit mask of host protection capabilities used to register with the
3436# SCSI mid-layer
3437# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3438# - Allows you to ultimately specify which profiles to use
3439# - Default will result in registering capabilities for all profiles.
3440#
3441*/
James Smartbc739052010-08-04 16:11:18 -04003442unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
James Smart81301a92008-12-04 22:39:46 -05003443
James Smartab56dc22011-02-16 12:39:57 -05003444module_param(lpfc_prot_mask, uint, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003445MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3446
3447/*
3448# lpfc_prot_guard: i
3449# - Bit mask of protection guard types to register with the SCSI mid-layer
3450# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3451# - Allows you to ultimately specify which profiles to use
3452# - Default will result in registering capabilities for all guard types
3453#
3454*/
3455unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
James Smartab56dc22011-02-16 12:39:57 -05003456module_param(lpfc_prot_guard, byte, S_IRUGO);
James Smart81301a92008-12-04 22:39:46 -05003457MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3458
James Smart92494142011-02-16 12:39:44 -05003459/*
3460 * Delay initial NPort discovery when Clean Address bit is cleared in
3461 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3462 * This parameter can have value 0 or 1.
3463 * When this parameter is set to 0, no delay is added to the initial
3464 * discovery.
3465 * When this parameter is set to non-zero value, initial Nport discovery is
3466 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3467 * accept and FCID/Fabric name/Fabric portname is changed.
3468 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3469 * when Clean Address bit is cleared in FLOGI/FDISC
3470 * accept and FCID/Fabric name/Fabric portname is changed.
3471 * Default value is 0.
3472 */
3473int lpfc_delay_discovery;
James Smartab56dc22011-02-16 12:39:57 -05003474module_param(lpfc_delay_discovery, int, S_IRUGO);
James Smart92494142011-02-16 12:39:44 -05003475MODULE_PARM_DESC(lpfc_delay_discovery,
3476 "Delay NPort discovery when Clean Address bit is cleared. "
3477 "Allowed values: 0,1.");
James Smart81301a92008-12-04 22:39:46 -05003478
3479/*
James Smart3621a712009-04-06 18:47:14 -04003480 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003481 * This value can be set to values between 64 and 256. The default value is
3482 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3483 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3484 */
3485LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3486 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3487
James Smart81301a92008-12-04 22:39:46 -05003488LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3489 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3490 "Max Protection Scatter Gather Segment Count");
3491
Tony Jonesee959b02008-02-22 00:13:36 +01003492struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003493 &dev_attr_bg_info,
3494 &dev_attr_bg_guard_err,
3495 &dev_attr_bg_apptag_err,
3496 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003497 &dev_attr_info,
3498 &dev_attr_serialnum,
3499 &dev_attr_modeldesc,
3500 &dev_attr_modelname,
3501 &dev_attr_programtype,
3502 &dev_attr_portnum,
3503 &dev_attr_fwrev,
3504 &dev_attr_hdw,
3505 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003506 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003507 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003508 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003509 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04003510 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003511 &dev_attr_lpfc_temp_sensor,
3512 &dev_attr_lpfc_log_verbose,
3513 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003514 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003515 &dev_attr_lpfc_hba_queue_depth,
3516 &dev_attr_lpfc_peer_port_login,
3517 &dev_attr_lpfc_nodev_tmo,
3518 &dev_attr_lpfc_devloss_tmo,
3519 &dev_attr_lpfc_fcp_class,
3520 &dev_attr_lpfc_use_adisc,
3521 &dev_attr_lpfc_ack0,
3522 &dev_attr_lpfc_topology,
3523 &dev_attr_lpfc_scan_down,
3524 &dev_attr_lpfc_link_speed,
3525 &dev_attr_lpfc_cr_delay,
3526 &dev_attr_lpfc_cr_count,
3527 &dev_attr_lpfc_multi_ring_support,
3528 &dev_attr_lpfc_multi_ring_rctl,
3529 &dev_attr_lpfc_multi_ring_type,
3530 &dev_attr_lpfc_fdmi_on,
3531 &dev_attr_lpfc_max_luns,
3532 &dev_attr_lpfc_enable_npiv,
James Smart19ca7602010-11-20 23:11:55 -05003533 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01003534 &dev_attr_nport_evt_cnt,
3535 &dev_attr_board_mode,
3536 &dev_attr_max_vpi,
3537 &dev_attr_used_vpi,
3538 &dev_attr_max_rpi,
3539 &dev_attr_used_rpi,
3540 &dev_attr_max_xri,
3541 &dev_attr_used_xri,
3542 &dev_attr_npiv_info,
3543 &dev_attr_issue_reset,
3544 &dev_attr_lpfc_poll,
3545 &dev_attr_lpfc_poll_tmo,
3546 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003547 &dev_attr_lpfc_fcp_imax,
3548 &dev_attr_lpfc_fcp_wq_count,
3549 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003550 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003551 &dev_attr_lpfc_soft_wwnn,
3552 &dev_attr_lpfc_soft_wwpn,
3553 &dev_attr_lpfc_soft_wwn_enable,
3554 &dev_attr_lpfc_enable_hba_reset,
3555 &dev_attr_lpfc_enable_hba_heartbeat,
3556 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003557 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003558 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003559 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003560 &dev_attr_lpfc_aer_support,
3561 &dev_attr_lpfc_aer_state_cleanup,
James Smart84d1b002010-02-12 14:42:33 -05003562 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04003563 &dev_attr_lpfc_iocb_cnt,
3564 &dev_attr_iocb_hw,
3565 &dev_attr_txq_hw,
3566 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04003567 &dev_attr_lpfc_fips_level,
3568 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05003569 &dev_attr_lpfc_dss,
dea31012005-04-17 16:05:31 -05003570 NULL,
3571};
3572
Tony Jonesee959b02008-02-22 00:13:36 +01003573struct device_attribute *lpfc_vport_attrs[] = {
3574 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003575 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003576 &dev_attr_num_discovered_ports,
3577 &dev_attr_lpfc_drvr_version,
3578 &dev_attr_lpfc_log_verbose,
3579 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04003580 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01003581 &dev_attr_lpfc_nodev_tmo,
3582 &dev_attr_lpfc_devloss_tmo,
3583 &dev_attr_lpfc_hba_queue_depth,
3584 &dev_attr_lpfc_peer_port_login,
3585 &dev_attr_lpfc_restrict_login,
3586 &dev_attr_lpfc_fcp_class,
3587 &dev_attr_lpfc_use_adisc,
3588 &dev_attr_lpfc_fdmi_on,
3589 &dev_attr_lpfc_max_luns,
3590 &dev_attr_nport_evt_cnt,
3591 &dev_attr_npiv_info,
3592 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003593 &dev_attr_lpfc_max_scsicmpl_time,
3594 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003595 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04003596 &dev_attr_lpfc_fips_level,
3597 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04003598 NULL,
3599};
3600
James Smarte59058c2008-08-24 21:49:00 -04003601/**
James Smart3621a712009-04-06 18:47:14 -04003602 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003603 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003604 * @kobj: kernel kobject that contains the kernel class device.
3605 * @bin_attr: kernel attributes passed to us.
3606 * @buf: contains the data to be written to the adapter IOREG space.
3607 * @off: offset into buffer to beginning of data.
3608 * @count: bytes to transfer.
3609 *
3610 * Description:
3611 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3612 * Uses the adapter io control registers to send buf contents to the adapter.
3613 *
3614 * Returns:
3615 * -ERANGE off and count combo out of range
3616 * -EINVAL off, count or buff address invalid
3617 * -EPERM adapter is offline
3618 * value of count, buf contents written
3619 **/
dea31012005-04-17 16:05:31 -05003620static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003621sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3622 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003623 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003624{
3625 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003626 struct device *dev = container_of(kobj, struct device, kobj);
3627 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003630
James Smartf1126682009-06-10 17:22:44 -04003631 if (phba->sli_rev >= LPFC_SLI_REV4)
3632 return -EPERM;
3633
dea31012005-04-17 16:05:31 -05003634 if ((off + count) > FF_REG_AREA_SIZE)
3635 return -ERANGE;
3636
3637 if (count == 0) return 0;
3638
3639 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3640 return -EINVAL;
3641
James Smart2e0fef82007-06-17 19:56:36 -05003642 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003643 return -EPERM;
3644 }
3645
James Smart2e0fef82007-06-17 19:56:36 -05003646 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003647 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3648 writel(*((uint32_t *)(buf + buf_off)),
3649 phba->ctrl_regs_memmap_p + off + buf_off);
3650
James Smart2e0fef82007-06-17 19:56:36 -05003651 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003652
3653 return count;
3654}
3655
James Smarte59058c2008-08-24 21:49:00 -04003656/**
James Smart3621a712009-04-06 18:47:14 -04003657 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07003658 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003659 * @kobj: kernel kobject that contains the kernel class device.
3660 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003661 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04003662 * @off: offset into buffer to beginning of data.
3663 * @count: bytes to transfer.
3664 *
3665 * Description:
3666 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3667 * Uses the adapter io control registers to read data into buf.
3668 *
3669 * Returns:
3670 * -ERANGE off and count combo out of range
3671 * -EINVAL off, count or buff address invalid
3672 * value of count, buf contents read
3673 **/
dea31012005-04-17 16:05:31 -05003674static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003675sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3676 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003677 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003678{
3679 size_t buf_off;
3680 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003681 struct device *dev = container_of(kobj, struct device, kobj);
3682 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3684 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003685
James Smartf1126682009-06-10 17:22:44 -04003686 if (phba->sli_rev >= LPFC_SLI_REV4)
3687 return -EPERM;
3688
dea31012005-04-17 16:05:31 -05003689 if (off > FF_REG_AREA_SIZE)
3690 return -ERANGE;
3691
3692 if ((off + count) > FF_REG_AREA_SIZE)
3693 count = FF_REG_AREA_SIZE - off;
3694
3695 if (count == 0) return 0;
3696
3697 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3698 return -EINVAL;
3699
James Smart2e0fef82007-06-17 19:56:36 -05003700 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003701
3702 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3703 tmp_ptr = (uint32_t *)(buf + buf_off);
3704 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3705 }
3706
James Smart2e0fef82007-06-17 19:56:36 -05003707 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003708
3709 return count;
3710}
3711
3712static struct bin_attribute sysfs_ctlreg_attr = {
3713 .attr = {
3714 .name = "ctlreg",
3715 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003716 },
3717 .size = 256,
3718 .read = sysfs_ctlreg_read,
3719 .write = sysfs_ctlreg_write,
3720};
3721
James Smarte59058c2008-08-24 21:49:00 -04003722/**
James Smart3621a712009-04-06 18:47:14 -04003723 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003724 * @phba: lpfc_hba pointer
3725 **/
dea31012005-04-17 16:05:31 -05003726static void
James Smart2e0fef82007-06-17 19:56:36 -05003727sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003728{
3729 phba->sysfs_mbox.state = SMBOX_IDLE;
3730 phba->sysfs_mbox.offset = 0;
3731
3732 if (phba->sysfs_mbox.mbox) {
3733 mempool_free(phba->sysfs_mbox.mbox,
3734 phba->mbox_mem_pool);
3735 phba->sysfs_mbox.mbox = NULL;
3736 }
3737}
3738
James Smarte59058c2008-08-24 21:49:00 -04003739/**
James Smart3621a712009-04-06 18:47:14 -04003740 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003741 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003742 * @kobj: kernel kobject that contains the kernel class device.
3743 * @bin_attr: kernel attributes passed to us.
3744 * @buf: contains the data to be written to sysfs mbox.
3745 * @off: offset into buffer to beginning of data.
3746 * @count: bytes to transfer.
3747 *
3748 * Description:
3749 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3750 * Uses the sysfs mbox to send buf contents to the adapter.
3751 *
3752 * Returns:
3753 * -ERANGE off and count combo out of range
3754 * -EINVAL off, count or buff address invalid
3755 * zero if count is zero
3756 * -EPERM adapter is offline
3757 * -ENOMEM failed to allocate memory for the mail box
3758 * -EAGAIN offset, state or mbox is NULL
3759 * count number of bytes transferred
3760 **/
dea31012005-04-17 16:05:31 -05003761static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003762sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3763 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003764 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003765{
Tony Jonesee959b02008-02-22 00:13:36 +01003766 struct device *dev = container_of(kobj, struct device, kobj);
3767 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3769 struct lpfc_hba *phba = vport->phba;
3770 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003771
3772 if ((count + off) > MAILBOX_CMD_SIZE)
3773 return -ERANGE;
3774
3775 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3776 return -EINVAL;
3777
3778 if (count == 0)
3779 return 0;
3780
3781 if (off == 0) {
3782 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3783 if (!mbox)
3784 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003785 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003786 }
3787
James Smart2e0fef82007-06-17 19:56:36 -05003788 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003789
3790 if (off == 0) {
3791 if (phba->sysfs_mbox.mbox)
3792 mempool_free(mbox, phba->mbox_mem_pool);
3793 else
3794 phba->sysfs_mbox.mbox = mbox;
3795 phba->sysfs_mbox.state = SMBOX_WRITING;
3796 } else {
3797 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3798 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003799 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003800 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003801 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003802 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003803 }
3804 }
3805
James Smart04c68492009-05-22 14:52:52 -04003806 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003807 buf, count);
3808
3809 phba->sysfs_mbox.offset = off + count;
3810
James Smart2e0fef82007-06-17 19:56:36 -05003811 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003812
3813 return count;
3814}
3815
James Smarte59058c2008-08-24 21:49:00 -04003816/**
James Smart3621a712009-04-06 18:47:14 -04003817 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07003818 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04003819 * @kobj: kernel kobject that contains the kernel class device.
3820 * @bin_attr: kernel attributes passed to us.
3821 * @buf: contains the data to be read from sysfs mbox.
3822 * @off: offset into buffer to beginning of data.
3823 * @count: bytes to transfer.
3824 *
3825 * Description:
3826 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3827 * Uses the sysfs mbox to receive data from to the adapter.
3828 *
3829 * Returns:
3830 * -ERANGE off greater than mailbox command size
3831 * -EINVAL off, count or buff address invalid
3832 * zero if off and count are zero
3833 * -EACCES adapter over temp
3834 * -EPERM garbage can value to catch a multitude of errors
3835 * -EAGAIN management IO not permitted, state or off error
3836 * -ETIME mailbox timeout
3837 * -ENODEV mailbox error
3838 * count number of bytes transferred
3839 **/
dea31012005-04-17 16:05:31 -05003840static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003841sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3842 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08003843 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003844{
Tony Jonesee959b02008-02-22 00:13:36 +01003845 struct device *dev = container_of(kobj, struct device, kobj);
3846 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003847 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3848 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003849 int rc;
James Smart04c68492009-05-22 14:52:52 -04003850 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003851
James Smart1dcb58e2007-04-25 09:51:30 -04003852 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003853 return -ERANGE;
3854
James Smart1dcb58e2007-04-25 09:51:30 -04003855 if ((count + off) > MAILBOX_CMD_SIZE)
3856 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003857
3858 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3859 return -EINVAL;
3860
3861 if (off && count == 0)
3862 return 0;
3863
James Smart2e0fef82007-06-17 19:56:36 -05003864 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003865
James Smart7af67052007-10-27 13:38:11 -04003866 if (phba->over_temp_state == HBA_OVER_TEMP) {
3867 sysfs_mbox_idle(phba);
3868 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003869 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003870 }
3871
dea31012005-04-17 16:05:31 -05003872 if (off == 0 &&
3873 phba->sysfs_mbox.state == SMBOX_WRITING &&
3874 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003875 pmb = &phba->sysfs_mbox.mbox->u.mb;
3876 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003877 /* Offline only */
dea31012005-04-17 16:05:31 -05003878 case MBX_INIT_LINK:
3879 case MBX_DOWN_LINK:
3880 case MBX_CONFIG_LINK:
3881 case MBX_CONFIG_RING:
3882 case MBX_RESET_RING:
3883 case MBX_UNREG_LOGIN:
3884 case MBX_CLEAR_LA:
3885 case MBX_DUMP_CONTEXT:
3886 case MBX_RUN_DIAGS:
3887 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003888 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003889 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003890 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003891 printk(KERN_WARNING "mbox_read:Command 0x%x "
3892 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003893 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003894 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003895 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003896 return -EPERM;
3897 }
James Smarta8adb832007-10-27 13:37:53 -04003898 case MBX_WRITE_NV:
3899 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003900 case MBX_LOAD_SM:
3901 case MBX_READ_NV:
3902 case MBX_READ_CONFIG:
3903 case MBX_READ_RCONFIG:
3904 case MBX_READ_STATUS:
3905 case MBX_READ_XRI:
3906 case MBX_READ_REV:
3907 case MBX_READ_LNK_STAT:
3908 case MBX_DUMP_MEMORY:
3909 case MBX_DOWN_LOAD:
3910 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003911 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003912 case MBX_LOAD_AREA:
3913 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003914 case MBX_BEACON:
3915 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003916 case MBX_SET_VARIABLE:
3917 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003918 case MBX_PORT_CAPABILITIES:
3919 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003920 break;
James Smartdcf2a4e2010-09-29 11:18:53 -04003921 case MBX_SECURITY_MGMT:
3922 case MBX_AUTH_PORT:
James Smart5989b8d2010-10-22 11:06:56 -04003923 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3924 printk(KERN_WARNING "mbox_read:Command 0x%x "
3925 "is not permitted\n", pmb->mbxCommand);
3926 sysfs_mbox_idle(phba);
3927 spin_unlock_irq(&phba->hbalock);
James Smartdcf2a4e2010-09-29 11:18:53 -04003928 return -EPERM;
James Smart5989b8d2010-10-22 11:06:56 -04003929 }
James Smartdcf2a4e2010-09-29 11:18:53 -04003930 break;
dea31012005-04-17 16:05:31 -05003931 case MBX_READ_SPARM64:
James Smart76a95d72010-11-20 23:11:48 -05003932 case MBX_READ_TOPOLOGY:
dea31012005-04-17 16:05:31 -05003933 case MBX_REG_LOGIN:
3934 case MBX_REG_LOGIN64:
3935 case MBX_CONFIG_PORT:
3936 case MBX_RUN_BIU_DIAG:
3937 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003938 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003939 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003940 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003941 return -EPERM;
3942 default:
3943 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003944 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003945 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003946 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003947 return -EPERM;
3948 }
3949
James Smart09372822008-01-11 01:52:54 -05003950 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003951 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003952 */
James Smartd7c255b2008-08-24 21:50:00 -04003953 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003954 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3955 pmb->mbxCommand != MBX_RESTART &&
3956 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3957 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003958 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3959 "1259 mbox: Issued mailbox cmd "
3960 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003961 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003962
James Smart92d7f7b2007-06-17 19:56:38 -05003963 phba->sysfs_mbox.mbox->vport = vport;
3964
James Smart58da1ff2008-04-07 10:15:56 -04003965 /* Don't allow mailbox commands to be sent when blocked
3966 * or when in the middle of discovery
3967 */
James Smart495a7142008-06-14 22:52:59 -04003968 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003969 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003970 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003971 return -EAGAIN;
3972 }
3973
James Smart2e0fef82007-06-17 19:56:36 -05003974 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003975 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003976
James Smart2e0fef82007-06-17 19:56:36 -05003977 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003978 rc = lpfc_sli_issue_mbox (phba,
3979 phba->sysfs_mbox.mbox,
3980 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003981 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003982
3983 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003984 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003985 rc = lpfc_sli_issue_mbox_wait (phba,
3986 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003987 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003988 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003989 }
3990
3991 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003992 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003993 phba->sysfs_mbox.mbox = NULL;
3994 }
dea31012005-04-17 16:05:31 -05003995 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003996 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003997 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003998 }
3999 phba->sysfs_mbox.state = SMBOX_READING;
4000 }
4001 else if (phba->sysfs_mbox.offset != off ||
4002 phba->sysfs_mbox.state != SMBOX_READING) {
4003 printk(KERN_WARNING "mbox_read: Bad State\n");
4004 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05004005 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04004006 return -EAGAIN;
dea31012005-04-17 16:05:31 -05004007 }
4008
James Smart04c68492009-05-22 14:52:52 -04004009 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05004010
4011 phba->sysfs_mbox.offset = off + count;
4012
James Smart1dcb58e2007-04-25 09:51:30 -04004013 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05004014 sysfs_mbox_idle(phba);
4015
James Smart2e0fef82007-06-17 19:56:36 -05004016 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004017
4018 return count;
4019}
4020
4021static struct bin_attribute sysfs_mbox_attr = {
4022 .attr = {
4023 .name = "mbox",
4024 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05004025 },
James Smartc0c11512011-05-24 11:41:34 -04004026 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05004027 .read = sysfs_mbox_read,
4028 .write = sysfs_mbox_write,
4029};
4030
James Smarte59058c2008-08-24 21:49:00 -04004031/**
James Smart3621a712009-04-06 18:47:14 -04004032 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004033 * @vport: address of lpfc vport structure.
4034 *
4035 * Return codes:
4036 * zero on success
4037 * error return code from sysfs_create_bin_file()
4038 **/
dea31012005-04-17 16:05:31 -05004039int
James Smart2e0fef82007-06-17 19:56:36 -05004040lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004041{
James Smart2e0fef82007-06-17 19:56:36 -05004042 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004043 int error;
4044
Tony Jonesee959b02008-02-22 00:13:36 +01004045 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05004046 &sysfs_drvr_stat_data_attr);
4047
4048 /* Virtual ports do not need ctrl_reg and mbox */
4049 if (error || vport->port_type == LPFC_NPIV_PORT)
4050 goto out;
4051
4052 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004053 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004054 if (error)
James Smarteada2722008-12-04 22:39:13 -05004055 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05004056
Tony Jonesee959b02008-02-22 00:13:36 +01004057 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05004058 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05004059 if (error)
4060 goto out_remove_ctlreg_attr;
4061
4062 return 0;
4063out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01004064 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05004065out_remove_stat_attr:
4066 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4067 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05004068out:
4069 return error;
4070}
4071
James Smarte59058c2008-08-24 21:49:00 -04004072/**
James Smart3621a712009-04-06 18:47:14 -04004073 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04004074 * @vport: address of lpfc vport structure.
4075 **/
dea31012005-04-17 16:05:31 -05004076void
James Smart2e0fef82007-06-17 19:56:36 -05004077lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004078{
James Smart2e0fef82007-06-17 19:56:36 -05004079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04004080 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4081 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05004082 /* Virtual ports do not need ctrl_reg and mbox */
4083 if (vport->port_type == LPFC_NPIV_PORT)
4084 return;
Tony Jonesee959b02008-02-22 00:13:36 +01004085 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4086 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05004087}
4088
4089
4090/*
4091 * Dynamic FC Host Attributes Support
4092 */
4093
James Smarte59058c2008-08-24 21:49:00 -04004094/**
James Smart3621a712009-04-06 18:47:14 -04004095 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04004096 * @shost: kernel scsi host pointer.
4097 **/
dea31012005-04-17 16:05:31 -05004098static void
4099lpfc_get_host_port_id(struct Scsi_Host *shost)
4100{
James Smart2e0fef82007-06-17 19:56:36 -05004101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4102
dea31012005-04-17 16:05:31 -05004103 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05004104 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004105}
4106
James Smarte59058c2008-08-24 21:49:00 -04004107/**
James Smart3621a712009-04-06 18:47:14 -04004108 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04004109 * @shost: kernel scsi host pointer.
4110 **/
dea31012005-04-17 16:05:31 -05004111static void
4112lpfc_get_host_port_type(struct Scsi_Host *shost)
4113{
James Smart2e0fef82007-06-17 19:56:36 -05004114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004116
4117 spin_lock_irq(shost->host_lock);
4118
James Smart92d7f7b2007-06-17 19:56:38 -05004119 if (vport->port_type == LPFC_NPIV_PORT) {
4120 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4121 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05004122 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05004123 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05004124 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4125 else
4126 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4127 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004128 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05004129 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4130 else
4131 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4132 }
4133 } else
4134 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4135
4136 spin_unlock_irq(shost->host_lock);
4137}
4138
James Smarte59058c2008-08-24 21:49:00 -04004139/**
James Smart3621a712009-04-06 18:47:14 -04004140 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04004141 * @shost: kernel scsi host pointer.
4142 **/
dea31012005-04-17 16:05:31 -05004143static void
4144lpfc_get_host_port_state(struct Scsi_Host *shost)
4145{
James Smart2e0fef82007-06-17 19:56:36 -05004146 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4147 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004148
4149 spin_lock_irq(shost->host_lock);
4150
James Smart2e0fef82007-06-17 19:56:36 -05004151 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004152 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4153 else {
James Smart2e0fef82007-06-17 19:56:36 -05004154 switch (phba->link_state) {
4155 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05004156 case LPFC_LINK_DOWN:
4157 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4158 break;
4159 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05004160 case LPFC_CLEAR_LA:
4161 case LPFC_HBA_READY:
4162 /* Links up, beyond this port_type reports state */
4163 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4164 break;
4165 case LPFC_HBA_ERROR:
4166 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4167 break;
4168 default:
4169 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4170 break;
4171 }
4172 }
4173
4174 spin_unlock_irq(shost->host_lock);
4175}
4176
James Smarte59058c2008-08-24 21:49:00 -04004177/**
James Smart3621a712009-04-06 18:47:14 -04004178 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04004179 * @shost: kernel scsi host pointer.
4180 **/
dea31012005-04-17 16:05:31 -05004181static void
4182lpfc_get_host_speed(struct Scsi_Host *shost)
4183{
James Smart2e0fef82007-06-17 19:56:36 -05004184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4185 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004186
4187 spin_lock_irq(shost->host_lock);
4188
James Smart2e0fef82007-06-17 19:56:36 -05004189 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05004190 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05004191 case LPFC_LINK_SPEED_1GHZ:
4192 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05004193 break;
James Smart76a95d72010-11-20 23:11:48 -05004194 case LPFC_LINK_SPEED_2GHZ:
4195 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05004196 break;
James Smart76a95d72010-11-20 23:11:48 -05004197 case LPFC_LINK_SPEED_4GHZ:
4198 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05004199 break;
James Smart76a95d72010-11-20 23:11:48 -05004200 case LPFC_LINK_SPEED_8GHZ:
4201 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04004202 break;
James Smart76a95d72010-11-20 23:11:48 -05004203 case LPFC_LINK_SPEED_10GHZ:
4204 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04004205 break;
James Smart76a95d72010-11-20 23:11:48 -05004206 case LPFC_LINK_SPEED_16GHZ:
4207 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4208 break;
4209 default:
4210 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004211 break;
4212 }
James Smart09372822008-01-11 01:52:54 -05004213 } else
4214 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05004215
4216 spin_unlock_irq(shost->host_lock);
4217}
4218
James Smarte59058c2008-08-24 21:49:00 -04004219/**
James Smart3621a712009-04-06 18:47:14 -04004220 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04004221 * @shost: kernel scsi host pointer.
4222 **/
dea31012005-04-17 16:05:31 -05004223static void
4224lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4225{
James Smart2e0fef82007-06-17 19:56:36 -05004226 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4227 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004228 u64 node_name;
dea31012005-04-17 16:05:31 -05004229
4230 spin_lock_irq(shost->host_lock);
4231
James Smart2e0fef82007-06-17 19:56:36 -05004232 if ((vport->fc_flag & FC_FABRIC) ||
James Smart76a95d72010-11-20 23:11:48 -05004233 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05004234 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004235 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05004236 else
4237 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05004238 node_name = 0;
dea31012005-04-17 16:05:31 -05004239
4240 spin_unlock_irq(shost->host_lock);
4241
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07004242 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05004243}
4244
James Smarte59058c2008-08-24 21:49:00 -04004245/**
James Smart3621a712009-04-06 18:47:14 -04004246 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04004247 * @shost: kernel scsi host pointer.
4248 *
4249 * Notes:
4250 * NULL on error for link down, no mbox pool, sli2 active,
4251 * management not allowed, memory allocation error, or mbox error.
4252 *
4253 * Returns:
4254 * NULL for error
4255 * address of the adapter host statistics
4256 **/
dea31012005-04-17 16:05:31 -05004257static struct fc_host_statistics *
4258lpfc_get_stats(struct Scsi_Host *shost)
4259{
James Smart2e0fef82007-06-17 19:56:36 -05004260 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4261 struct lpfc_hba *phba = vport->phba;
4262 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004263 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04004264 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05004265 LPFC_MBOXQ_t *pmboxq;
4266 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04004267 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004268 int rc = 0;
dea31012005-04-17 16:05:31 -05004269
James Smart92d7f7b2007-06-17 19:56:38 -05004270 /*
4271 * prevent udev from issuing mailbox commands until the port is
4272 * configured.
4273 */
James Smart2e0fef82007-06-17 19:56:36 -05004274 if (phba->link_state < LPFC_LINK_DOWN ||
4275 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04004276 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004277 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004278
4279 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004280 return NULL;
4281
dea31012005-04-17 16:05:31 -05004282 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4283 if (!pmboxq)
4284 return NULL;
4285 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4286
James Smart04c68492009-05-22 14:52:52 -04004287 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05004288 pmb->mbxCommand = MBX_READ_STATUS;
4289 pmb->mbxOwner = OWN_HOST;
4290 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004291 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004292
James Smart75baf692010-06-08 18:31:21 -04004293 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004294 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004295 else
dea31012005-04-17 16:05:31 -05004296 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4297
4298 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004299 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004300 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004301 return NULL;
4302 }
4303
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04004304 memset(hs, 0, sizeof (struct fc_host_statistics));
4305
dea31012005-04-17 16:05:31 -05004306 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4307 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4308 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4309 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4310
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004311 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05004312 pmb->mbxCommand = MBX_READ_LNK_STAT;
4313 pmb->mbxOwner = OWN_HOST;
4314 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004315 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05004316
James Smart75baf692010-06-08 18:31:21 -04004317 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05004318 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04004319 else
dea31012005-04-17 16:05:31 -05004320 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4321
4322 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004323 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004324 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004325 return NULL;
4326 }
4327
4328 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4329 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4330 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4331 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4332 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4333 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4334 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4335
James Smart64ba8812006-08-02 15:24:34 -04004336 hs->link_failure_count -= lso->link_failure_count;
4337 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4338 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4339 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4340 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4341 hs->invalid_crc_count -= lso->invalid_crc_count;
4342 hs->error_frames -= lso->error_frames;
4343
James Smart76a95d72010-11-20 23:11:48 -05004344 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04004345 hs->lip_count = -1;
4346 hs->nos_count = (phba->link_events >> 1);
4347 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05004348 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004349 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004350 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004351 hs->nos_count = -1;
4352 } else {
4353 hs->lip_count = -1;
4354 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004355 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004356 }
4357
4358 hs->dumped_frames = -1;
4359
James Smart64ba8812006-08-02 15:24:34 -04004360 seconds = get_seconds();
4361 if (seconds < psli->stats_start)
4362 hs->seconds_since_last_reset = seconds +
4363 ((unsigned long)-1 - psli->stats_start);
4364 else
4365 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004366
James Smart1dcb58e2007-04-25 09:51:30 -04004367 mempool_free(pmboxq, phba->mbox_mem_pool);
4368
dea31012005-04-17 16:05:31 -05004369 return hs;
4370}
4371
James Smarte59058c2008-08-24 21:49:00 -04004372/**
James Smart3621a712009-04-06 18:47:14 -04004373 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004374 * @shost: kernel scsi host pointer.
4375 **/
James Smart64ba8812006-08-02 15:24:34 -04004376static void
4377lpfc_reset_stats(struct Scsi_Host *shost)
4378{
James Smart2e0fef82007-06-17 19:56:36 -05004379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4380 struct lpfc_hba *phba = vport->phba;
4381 struct lpfc_sli *psli = &phba->sli;
4382 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004383 LPFC_MBOXQ_t *pmboxq;
4384 MAILBOX_t *pmb;
4385 int rc = 0;
4386
James Smart2e0fef82007-06-17 19:56:36 -05004387 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004388 return;
4389
James Smart64ba8812006-08-02 15:24:34 -04004390 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4391 if (!pmboxq)
4392 return;
4393 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4394
James Smart04c68492009-05-22 14:52:52 -04004395 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004396 pmb->mbxCommand = MBX_READ_STATUS;
4397 pmb->mbxOwner = OWN_HOST;
4398 pmb->un.varWords[0] = 0x1; /* reset request */
4399 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004400 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004401
James Smart2e0fef82007-06-17 19:56:36 -05004402 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004403 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004404 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4405 else
4406 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4407
4408 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004409 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004410 mempool_free(pmboxq, phba->mbox_mem_pool);
4411 return;
4412 }
4413
4414 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4415 pmb->mbxCommand = MBX_READ_LNK_STAT;
4416 pmb->mbxOwner = OWN_HOST;
4417 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004418 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004419
James Smart2e0fef82007-06-17 19:56:36 -05004420 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004421 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004422 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4423 else
4424 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4425
4426 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004427 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004428 mempool_free( pmboxq, phba->mbox_mem_pool);
4429 return;
4430 }
4431
4432 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4433 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4434 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4435 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4436 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4437 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4438 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05004439 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04004440 lso->link_events = (phba->link_events >> 1);
4441 else
4442 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004443
4444 psli->stats_start = get_seconds();
4445
James Smart1dcb58e2007-04-25 09:51:30 -04004446 mempool_free(pmboxq, phba->mbox_mem_pool);
4447
James Smart64ba8812006-08-02 15:24:34 -04004448 return;
4449}
dea31012005-04-17 16:05:31 -05004450
4451/*
4452 * The LPFC driver treats linkdown handling as target loss events so there
4453 * are no sysfs handlers for link_down_tmo.
4454 */
James Smart685f0bf2007-04-25 09:53:08 -04004455
James Smarte59058c2008-08-24 21:49:00 -04004456/**
James Smart3621a712009-04-06 18:47:14 -04004457 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004458 * @starget: kernel scsi target pointer.
4459 *
4460 * Returns:
4461 * address of the node list if found
4462 * NULL target not found
4463 **/
James Smart685f0bf2007-04-25 09:53:08 -04004464static struct lpfc_nodelist *
4465lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004466{
James Smart2e0fef82007-06-17 19:56:36 -05004467 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4468 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004469 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004470
4471 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004472 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004473 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004474 if (NLP_CHK_NODE_ACT(ndlp) &&
4475 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004476 starget->id == ndlp->nlp_sid) {
4477 spin_unlock_irq(shost->host_lock);
4478 return ndlp;
dea31012005-04-17 16:05:31 -05004479 }
4480 }
4481 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004482 return NULL;
4483}
dea31012005-04-17 16:05:31 -05004484
James Smarte59058c2008-08-24 21:49:00 -04004485/**
James Smart3621a712009-04-06 18:47:14 -04004486 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004487 * @starget: kernel scsi target pointer.
4488 **/
James Smart685f0bf2007-04-25 09:53:08 -04004489static void
4490lpfc_get_starget_port_id(struct scsi_target *starget)
4491{
4492 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4493
4494 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004495}
4496
James Smarte59058c2008-08-24 21:49:00 -04004497/**
James Smart3621a712009-04-06 18:47:14 -04004498 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004499 * @starget: kernel scsi target pointer.
4500 *
4501 * Description: Set the target node name to the ndlp node name wwn or zero.
4502 **/
dea31012005-04-17 16:05:31 -05004503static void
4504lpfc_get_starget_node_name(struct scsi_target *starget)
4505{
James Smart685f0bf2007-04-25 09:53:08 -04004506 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004507
James Smart685f0bf2007-04-25 09:53:08 -04004508 fc_starget_node_name(starget) =
4509 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004510}
4511
James Smarte59058c2008-08-24 21:49:00 -04004512/**
James Smart3621a712009-04-06 18:47:14 -04004513 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004514 * @starget: kernel scsi target pointer.
4515 *
4516 * Description: set the target port name to the ndlp port name wwn or zero.
4517 **/
dea31012005-04-17 16:05:31 -05004518static void
4519lpfc_get_starget_port_name(struct scsi_target *starget)
4520{
James Smart685f0bf2007-04-25 09:53:08 -04004521 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004522
James Smart685f0bf2007-04-25 09:53:08 -04004523 fc_starget_port_name(starget) =
4524 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004525}
4526
James Smarte59058c2008-08-24 21:49:00 -04004527/**
James Smart3621a712009-04-06 18:47:14 -04004528 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004529 * @rport: fc rport address.
4530 * @timeout: new value for dev loss tmo.
4531 *
4532 * Description:
4533 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4534 * dev_loss_tmo to one.
4535 **/
dea31012005-04-17 16:05:31 -05004536static void
dea31012005-04-17 16:05:31 -05004537lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4538{
dea31012005-04-17 16:05:31 -05004539 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004540 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004541 else
James Smartc01f3202006-08-18 17:47:08 -04004542 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004543}
4544
James Smarte59058c2008-08-24 21:49:00 -04004545/**
James Smart3621a712009-04-06 18:47:14 -04004546 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004547 *
4548 * Description:
4549 * Macro that uses field to generate a function with the name lpfc_show_rport_
4550 *
4551 * lpfc_show_rport_##field: returns the bytes formatted in buf
4552 * @cdev: class converted to an fc_rport.
4553 * @buf: on return contains the target_field or zero.
4554 *
4555 * Returns: size of formatted string.
4556 **/
dea31012005-04-17 16:05:31 -05004557#define lpfc_rport_show_function(field, format_string, sz, cast) \
4558static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004559lpfc_show_rport_##field (struct device *dev, \
4560 struct device_attribute *attr, \
4561 char *buf) \
dea31012005-04-17 16:05:31 -05004562{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004563 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004564 struct lpfc_rport_data *rdata = rport->hostdata; \
4565 return snprintf(buf, sz, format_string, \
4566 (rdata->target) ? cast rdata->target->field : 0); \
4567}
4568
4569#define lpfc_rport_rd_attr(field, format_string, sz) \
4570 lpfc_rport_show_function(field, format_string, sz, ) \
4571static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4572
James Smarteada2722008-12-04 22:39:13 -05004573/**
James Smart3621a712009-04-06 18:47:14 -04004574 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004575 * @fc_vport: The fc_vport who's symbolic name has been changed.
4576 *
4577 * Description:
4578 * This function is called by the transport after the @fc_vport's symbolic name
4579 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004580 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05004581 **/
4582static void
4583lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4584{
4585 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4586
4587 if (vport->port_state == LPFC_VPORT_READY)
4588 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4589}
dea31012005-04-17 16:05:31 -05004590
James Smartf4b4c682009-05-22 14:53:12 -04004591/**
4592 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4593 * @phba: Pointer to lpfc_hba struct.
4594 *
4595 * This function is called by the lpfc_get_cfgparam() routine to set the
4596 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02004597 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04004598 * before hba port or vport created.
4599 **/
4600static void
4601lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4602{
4603 phba->cfg_log_verbose = verbose;
4604}
4605
dea31012005-04-17 16:05:31 -05004606struct fc_function_template lpfc_transport_functions = {
4607 /* fixed attributes the driver supports */
4608 .show_host_node_name = 1,
4609 .show_host_port_name = 1,
4610 .show_host_supported_classes = 1,
4611 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004612 .show_host_supported_speeds = 1,
4613 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004614 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004615
4616 /* dynamic attributes the driver supports */
4617 .get_host_port_id = lpfc_get_host_port_id,
4618 .show_host_port_id = 1,
4619
4620 .get_host_port_type = lpfc_get_host_port_type,
4621 .show_host_port_type = 1,
4622
4623 .get_host_port_state = lpfc_get_host_port_state,
4624 .show_host_port_state = 1,
4625
4626 /* active_fc4s is shown but doesn't change (thus no get function) */
4627 .show_host_active_fc4s = 1,
4628
4629 .get_host_speed = lpfc_get_host_speed,
4630 .show_host_speed = 1,
4631
4632 .get_host_fabric_name = lpfc_get_host_fabric_name,
4633 .show_host_fabric_name = 1,
4634
4635 /*
4636 * The LPFC driver treats linkdown handling as target loss events
4637 * so there are no sysfs handlers for link_down_tmo.
4638 */
4639
4640 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004641 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004642
4643 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4644 .show_rport_maxframe_size = 1,
4645 .show_rport_supported_classes = 1,
4646
dea31012005-04-17 16:05:31 -05004647 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4648 .show_rport_dev_loss_tmo = 1,
4649
4650 .get_starget_port_id = lpfc_get_starget_port_id,
4651 .show_starget_port_id = 1,
4652
4653 .get_starget_node_name = lpfc_get_starget_node_name,
4654 .show_starget_node_name = 1,
4655
4656 .get_starget_port_name = lpfc_get_starget_port_name,
4657 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004658
4659 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004660 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4661 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004662
James Smart92d7f7b2007-06-17 19:56:38 -05004663 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004664
4665 .vport_disable = lpfc_vport_disable,
4666
4667 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004668
4669 .bsg_request = lpfc_bsg_request,
4670 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004671};
4672
James Smart98c9ea52007-10-27 13:37:33 -04004673struct fc_function_template lpfc_vport_transport_functions = {
4674 /* fixed attributes the driver supports */
4675 .show_host_node_name = 1,
4676 .show_host_port_name = 1,
4677 .show_host_supported_classes = 1,
4678 .show_host_supported_fc4s = 1,
4679 .show_host_supported_speeds = 1,
4680 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004681 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004682
4683 /* dynamic attributes the driver supports */
4684 .get_host_port_id = lpfc_get_host_port_id,
4685 .show_host_port_id = 1,
4686
4687 .get_host_port_type = lpfc_get_host_port_type,
4688 .show_host_port_type = 1,
4689
4690 .get_host_port_state = lpfc_get_host_port_state,
4691 .show_host_port_state = 1,
4692
4693 /* active_fc4s is shown but doesn't change (thus no get function) */
4694 .show_host_active_fc4s = 1,
4695
4696 .get_host_speed = lpfc_get_host_speed,
4697 .show_host_speed = 1,
4698
4699 .get_host_fabric_name = lpfc_get_host_fabric_name,
4700 .show_host_fabric_name = 1,
4701
4702 /*
4703 * The LPFC driver treats linkdown handling as target loss events
4704 * so there are no sysfs handlers for link_down_tmo.
4705 */
4706
4707 .get_fc_host_stats = lpfc_get_stats,
4708 .reset_fc_host_stats = lpfc_reset_stats,
4709
4710 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4711 .show_rport_maxframe_size = 1,
4712 .show_rport_supported_classes = 1,
4713
4714 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4715 .show_rport_dev_loss_tmo = 1,
4716
4717 .get_starget_port_id = lpfc_get_starget_port_id,
4718 .show_starget_port_id = 1,
4719
4720 .get_starget_node_name = lpfc_get_starget_node_name,
4721 .show_starget_node_name = 1,
4722
4723 .get_starget_port_name = lpfc_get_starget_port_name,
4724 .show_starget_port_name = 1,
4725
4726 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4727 .terminate_rport_io = lpfc_terminate_rport_io,
4728
4729 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004730
4731 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004732};
4733
James Smarte59058c2008-08-24 21:49:00 -04004734/**
James Smart3621a712009-04-06 18:47:14 -04004735 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004736 * @phba: lpfc_hba pointer.
4737 **/
dea31012005-04-17 16:05:31 -05004738void
4739lpfc_get_cfgparam(struct lpfc_hba *phba)
4740{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004741 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4742 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004743 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004744 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4745 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004746 lpfc_ack0_init(phba, lpfc_ack0);
4747 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004748 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004749 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004750 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart19ca7602010-11-20 23:11:55 -05004751 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4ff43242006-12-02 13:34:56 -05004752 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004753 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4754 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4755 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004756 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4757 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004758 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smart45ed1192009-10-02 15:17:02 -04004759 if (phba->sli_rev == LPFC_SLI_REV4)
4760 phba->cfg_poll = 0;
4761 else
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004762 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004763 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004764 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004765 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004766 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004767 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004768 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004769 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart84d1b002010-02-12 14:42:33 -05004770 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04004771 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smartab56dc22011-02-16 12:39:57 -05004772 phba->cfg_enable_dss = 1;
James Smart3de2a652007-08-02 11:09:59 -04004773 return;
4774}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004775
James Smarte59058c2008-08-24 21:49:00 -04004776/**
James Smart3621a712009-04-06 18:47:14 -04004777 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004778 * @vport: lpfc_vport pointer.
4779 **/
James Smart3de2a652007-08-02 11:09:59 -04004780void
4781lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4782{
James Smarte8b62012007-08-02 11:10:09 -04004783 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004784 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04004785 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04004786 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4787 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4788 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4789 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4790 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4791 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004792 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004793 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4794 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4795 lpfc_max_luns_init(vport, lpfc_max_luns);
4796 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004797 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004798 return;
4799}